FAILURE MAP
← Case archive

FA-16316 / Floating-point arithmetic / Open access

Relative logarithm loses tiny increments before the log · case 01

Relative logarithm loses tiny increments before the log.

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

ROOT CAUSE

Relative logarithm loses tiny increments before the log. The faulty expression is result=math.log(1+x)/x.

VERIFIED REPAIR

Apply the contract at this fault site using result=1-x/2+x*x/3.

Unsuccessful approach: The attempted local correction result=math.log(max(1+x,1))/x still violates the explicit regression fixtures.

Case contract

Evaluate log1p(x)/x on x>-1 with continuous value one at zero. 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<=-1: return 'domain'
        if x==0: return '1'
        if abs(x)<1e-8:
            result=math.log(1+x)/x
        else:
            result=math.log1p(x)/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('zero', solve(0.0), "1")
check('tiny', solve(N*1e-10), render(1-N*1e-10/2))
check('negative tiny', solve(-N*1e-10), render(1+N*1e-10/2))
check('normal', solve(float(N)), render(math.log1p(N)/N))
check('negative normal', solve(-0.125*N), render(math.log1p(-0.125*N)/(-0.125*N)))
check('domain', solve(-1.0), "domain")
check('transition', solve(1e-7), render(math.log1p(1e-7)/1e-7))
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
zero11Passed
tiny1.00000008270.99999999995Failed
negative tiny1.00000008281.0000000001Failed
normal0.693147180560.69314718056Passed
negative normal1.0682511411.068251141Passed
domaindomaindomainPassed
transition0.999999950.99999995Passed

SHA-256 / b6fdb873ad04414a1a44e9b49c88bf75e7b396d0495b598ed4c24ec97c5463b8

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<=-1: return 'domain'
        if x==0: return '1'
        if abs(x)<1e-8:
            result=math.log(max(1+x,1))/x
        else:
            result=math.log1p(x)/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('zero', solve(0.0), "1")
check('tiny', solve(N*1e-10), render(1-N*1e-10/2))
check('negative tiny', solve(-N*1e-10), render(1+N*1e-10/2))
check('normal', solve(float(N)), render(math.log1p(N)/N))
check('negative normal', solve(-0.125*N), render(math.log1p(-0.125*N)/(-0.125*N)))
check('domain', solve(-1.0), "domain")
check('transition', solve(1e-7), render(math.log1p(1e-7)/1e-7))
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
zero11Passed
tiny1.00000008270.99999999995Failed
negative tiny-01.0000000001Failed
normal0.693147180560.69314718056Passed
negative normal1.0682511411.068251141Passed
domaindomaindomainPassed
transition0.999999950.99999995Passed

SHA-256 / 39f11e7392fab871c1d6fd29a7e467c06c3a0ecc02bb7b477dd9c25e967a8a32

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<=-1: return 'domain'
        if x==0: return '1'
        if abs(x)<1e-8:
            result=1-x/2+x*x/3
        else:
            result=math.log1p(x)/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('zero', solve(0.0), "1")
check('tiny', solve(N*1e-10), render(1-N*1e-10/2))
check('negative tiny', solve(-N*1e-10), render(1+N*1e-10/2))
check('normal', solve(float(N)), render(math.log1p(N)/N))
check('negative normal', solve(-0.125*N), render(math.log1p(-0.125*N)/(-0.125*N)))
check('domain', solve(-1.0), "domain")
check('transition', solve(1e-7), render(math.log1p(1e-7)/1e-7))
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
zero11Passed
tiny0.999999999950.99999999995Passed
negative tiny1.00000000011.0000000001Passed
normal0.693147180560.69314718056Passed
negative normal1.0682511411.068251141Passed
domaindomaindomainPassed
transition0.999999950.99999995Passed

SHA-256 / 8cdf294e4d867d3fece3560f491c51db6f01b504f8845db06852eaa3c46a0a40

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

Case digest / 9bd460477ee3be10d02e1adea9306d0f7a226ddffb5199e6e0891ad7f38ae663