FAILURE MAP
← Case archive

FA-16131 / Floating-point arithmetic / Open access

Complementary log exponentials subtract near unity · case 01

Complementary log exponentials subtract near unity.

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

ROOT CAUSE

Complementary log exponentials subtract near unity. The faulty expression is result=math.log(1-math.exp(x)).

VERIFIED REPAIR

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

Unsuccessful approach: The attempted local correction result=math.log(max(1-math.exp(x),1e-300)) 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.log1p(-math.exp(x))
        else:
            result=math.log(1-math.exp(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 zeroarithmetic-error-41.588830834Failed
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 / a89acd20866d09f18263cf6109b19df77d4b72ff9078fe7156f6675c1bafda78

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=math.log1p(-math.exp(x))
        else:
            result=math.log(max(1-math.exp(x),1e-300))
        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-690.7755279-41.588830834Failed
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 / 8fe424071b269c55338348a4068d8b9aab49e72b0500330230bcf74911d09026

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.389995+00:00.

Case digest / bc562a0346400af46bc8a9b5b6127549ea7c69bac0a7bcf9f2a68822fee813aa