FAILURE MAP
← Case archive

FA-17036 / Floating-point arithmetic / Open access

Log ratio subtracts close logarithms at large magnitude · case 01

Log ratio subtracts close logarithms at large magnitude.

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

ROOT CAUSE

Log ratio subtracts close logarithms at large magnitude. The faulty expression is result=math.log(a)-math.log(b).

VERIFIED REPAIR

Apply the contract at this fault site using result=math.log1p(r).

Unsuccessful approach: The attempted local correction result=math.log(a/b) still violates the explicit regression fixtures.

Case contract

Evaluate log(a/b) for positive finite endpoints without overflowing an intermediate quotient and without cancellation for nearby operands. 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(a,b):
    try:
        if a<=0 or b<=0: return 'domain'
        if a==b: return '0'
        r=(a-b)/b
        if abs(r)<0.5:
            result=math.log(a)-math.log(b)
        else:
            result=math.log(a)-math.log(b)
        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('overflowing quotient', solve(N*1e300,1e-300), render(math.log(N*1e300)-math.log(1e-300)))
check('underflowing quotient', solve(1e-300,N*1e300), render(math.log(1e-300)-math.log(N*1e300)))
check('nearby moderate', solve(1.125,1.0), render(math.log(1.125)))
check('nearby large', solve(math.nextafter(1e100,math.inf),1e100), render(math.log1p((math.nextafter(1e100,math.inf)-1e100)/1e100)))
check('normal', solve(float(N+1),1.0), render(math.log(N+1)))
check('reverse', solve(1.0,float(N+1)), render(-math.log(N+1)))
check('equal', solve(float(N),float(N)), "0")
check('invalid', solve(0.0,float(N)), "domain")
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
overflowing quotient1381.55105581381.5510558Passed
underflowing quotient-1381.5510558-1381.5510558Passed
nearby moderate0.117783035660.11778303566Passed
nearby large01.9426688922e-16Failed
normal0.693147180560.69314718056Passed
reverse-0.69314718056-0.69314718056Passed
equal00Passed
invaliddomaindomainPassed

SHA-256 / 918cf807f484aa9ce8ea73c80dd00b420866a26c45fe4e33e05a7a6e57ec9b95

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(a,b):
    try:
        if a<=0 or b<=0: return 'domain'
        if a==b: return '0'
        r=(a-b)/b
        if abs(r)<0.5:
            result=math.log(a/b)
        else:
            result=math.log(a)-math.log(b)
        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('overflowing quotient', solve(N*1e300,1e-300), render(math.log(N*1e300)-math.log(1e-300)))
check('underflowing quotient', solve(1e-300,N*1e300), render(math.log(1e-300)-math.log(N*1e300)))
check('nearby moderate', solve(1.125,1.0), render(math.log(1.125)))
check('nearby large', solve(math.nextafter(1e100,math.inf),1e100), render(math.log1p((math.nextafter(1e100,math.inf)-1e100)/1e100)))
check('normal', solve(float(N+1),1.0), render(math.log(N+1)))
check('reverse', solve(1.0,float(N+1)), render(-math.log(N+1)))
check('equal', solve(float(N),float(N)), "0")
check('invalid', solve(0.0,float(N)), "domain")
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
overflowing quotient1381.55105581381.5510558Passed
underflowing quotient-1381.5510558-1381.5510558Passed
nearby moderate0.117783035660.11778303566Passed
nearby large2.2204460493e-161.9426688922e-16Failed
normal0.693147180560.69314718056Passed
reverse-0.69314718056-0.69314718056Passed
equal00Passed
invaliddomaindomainPassed

SHA-256 / 3fd5f92501bcb6aca34e0d9e5e9d9601078b3bbb298f39496162eff2a4400cfb

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(a,b):
    try:
        if a<=0 or b<=0: return 'domain'
        if a==b: return '0'
        r=(a-b)/b
        if abs(r)<0.5:
            result=math.log1p(r)
        else:
            result=math.log(a)-math.log(b)
        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('overflowing quotient', solve(N*1e300,1e-300), render(math.log(N*1e300)-math.log(1e-300)))
check('underflowing quotient', solve(1e-300,N*1e300), render(math.log(1e-300)-math.log(N*1e300)))
check('nearby moderate', solve(1.125,1.0), render(math.log(1.125)))
check('nearby large', solve(math.nextafter(1e100,math.inf),1e100), render(math.log1p((math.nextafter(1e100,math.inf)-1e100)/1e100)))
check('normal', solve(float(N+1),1.0), render(math.log(N+1)))
check('reverse', solve(1.0,float(N+1)), render(-math.log(N+1)))
check('equal', solve(float(N),float(N)), "0")
check('invalid', solve(0.0,float(N)), "domain")
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
overflowing quotient1381.55105581381.5510558Passed
underflowing quotient-1381.5510558-1381.5510558Passed
nearby moderate0.117783035660.11778303566Passed
nearby large1.9426688922e-161.9426688922e-16Passed
normal0.693147180560.69314718056Passed
reverse-0.69314718056-0.69314718056Passed
equal00Passed
invaliddomaindomainPassed

SHA-256 / 7da1be31e2ee6da6c7190c7986b0341a1ff43375807b435544d6a8b7467aa487

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

Case digest / 94d79ae0b2d69e6e988dbefa1d552d9eebc9fbeb4ea44011f2d0bee91d55278e