FAILURE MAP
← Case archive

FA-17041 / Floating-point arithmetic / Open access

Log ratio normalizes its difference by the numerator · case 01

Log ratio normalizes its difference by the numerator.

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

ROOT CAUSE

Log ratio normalizes its difference by the numerator. The faulty expression is r=(a-b)/a.

VERIFIED REPAIR

Apply the contract at this fault site using r=(a-b)/b.

Unsuccessful approach: The attempted local correction r=(a-b)/max(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)/a
        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.105360515660.11778303566Failed
nearby large1.9426688922e-161.9426688922e-16Passed
normal0.693147180560.69314718056Passed
reverse-0.69314718056-0.69314718056Passed
equal00Passed
invaliddomaindomainPassed

SHA-256 / 39f3ad27652d27ec10341e55dae7467114f717fa03931bb6e2317c55681f5046

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)/max(a,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.105360515660.11778303566Failed
nearby large1.9426688922e-161.9426688922e-16Passed
normal0.693147180560.69314718056Passed
reverse-0.69314718056-0.69314718056Passed
equal00Passed
invaliddomaindomainPassed

SHA-256 / 9bcc2d50a003de1d80cf52e949d1e6aa08e9ae7716d7190a1bdddfe12e85e62f

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

Case digest / 72a654cc8b5110413590f15e2607b6dc98b661a15101b5fcfc33c7a4c0f2de7e