FAILURE MAP
← Case archive

FA-16136 / Floating-point arithmetic / Open access

Complementary log exponentials lose the distant tail · case 01

Complementary log exponentials lose the distant tail.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Complementary log exponentials lose the distant tail. The faulty expression is result=math.log(1-math.exp(x)).

VERIFIED REPAIR

Apply the contract at this fault site using result=math.log1p(-math.exp(x)).

Unsuccessful approach: The attempted local correction result=0.0 if x < -40 else math.log(1-math.exp(x)) still violates the explicit regression fixtures.

Case contract

Evaluate log(1-exp(x)) for x <= 0; zero maps to negative infinity. Choose a cancellation-safe formula on either side of -log(2). Finite results are rendered to eleven significant decimal digits; modeled domain violations and arithmetic errors are explicit strings.

Why this case matters

An offline floating representation model isolates a reproducible arithmetic fault.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x):
    try:
        if x>0: return 'domain'
        if x==0: return '-infinity'
        if x < -math.log(2):
            result=math.log(1-math.exp(x))
        else:
            result=math.log(-math.expm1(x))
        return render(result)
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('near zero', solve(-N*2.0**-60), render(math.log(N*2.0**-60)))
check('far tail', solve(-50.0-N), render(-math.exp(-50.0-N)))
check('midpoint', solve(-math.log(2)), render(math.log(0.5)))
check('moderate', solve(-1.0), render(math.log1p(-math.exp(-1))))
check('boundary', solve(0.0), "-infinity")
check('invalid', solve(float(N)), "domain")
check('negative zero', solve(-0.0), "-infinity")
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
near zero-41.588830834-41.588830834Passed
far tail0-7.0954741623e-23Failed
midpoint-0.69314718056-0.69314718056Passed
moderate-0.45867514539-0.45867514539Passed
boundary-infinity-infinityPassed
invaliddomaindomainPassed
negative zero-infinity-infinityPassed

SHA-256 / 57f09f06024b32d955ac18bd2be67bec73d14ecdb7993ee668f21d696b2eb99a

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x):
    try:
        if x>0: return 'domain'
        if x==0: return '-infinity'
        if x < -math.log(2):
            result=0.0 if x < -40 else math.log(1-math.exp(x))
        else:
            result=math.log(-math.expm1(x))
        return render(result)
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('near zero', solve(-N*2.0**-60), render(math.log(N*2.0**-60)))
check('far tail', solve(-50.0-N), render(-math.exp(-50.0-N)))
check('midpoint', solve(-math.log(2)), render(math.log(0.5)))
check('moderate', solve(-1.0), render(math.log1p(-math.exp(-1))))
check('boundary', solve(0.0), "-infinity")
check('invalid', solve(float(N)), "domain")
check('negative zero', solve(-0.0), "-infinity")
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
near zero-41.588830834-41.588830834Passed
far tail0-7.0954741623e-23Failed
midpoint-0.69314718056-0.69314718056Passed
moderate-0.45867514539-0.45867514539Passed
boundary-infinity-infinityPassed
invaliddomaindomainPassed
negative zero-infinity-infinityPassed

SHA-256 / 7e59fb088c677ec557f5a74cf872e21528737e416e99ac7b1499b4334799748e

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x):
    try:
        if x>0: return 'domain'
        if x==0: return '-infinity'
        if x < -math.log(2):
            result=math.log1p(-math.exp(x))
        else:
            result=math.log(-math.expm1(x))
        return render(result)
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('near zero', solve(-N*2.0**-60), render(math.log(N*2.0**-60)))
check('far tail', solve(-50.0-N), render(-math.exp(-50.0-N)))
check('midpoint', solve(-math.log(2)), render(math.log(0.5)))
check('moderate', solve(-1.0), render(math.log1p(-math.exp(-1))))
check('boundary', solve(0.0), "-infinity")
check('invalid', solve(float(N)), "domain")
check('negative zero', solve(-0.0), "-infinity")
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
near zero-41.588830834-41.588830834Passed
far tail-7.0954741623e-23-7.0954741623e-23Passed
midpoint-0.69314718056-0.69314718056Passed
moderate-0.45867514539-0.45867514539Passed
boundary-infinity-infinityPassed
invaliddomaindomainPassed
negative zero-infinity-infinityPassed

SHA-256 / 9e8c3385fce009a483a0721ec097c0bbf8027e9adedc27f92b435b5d6d83082d

Verification & scope

Controlled binary64 or explicitly stipulated miniature format; no hardware exception flags or platform floating environment are modeled. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:39:33.387116+00:00.

Case digest / dd081326dcd4684a5b131794b991e43d4660ae92043e0acd29e75fb78622ef56