FAILURE MAP
← Case archive

FA-17046 / Floating-point arithmetic / Open access

Log ratio reverses the distant logarithm difference · case 01

Log ratio reverses the distant logarithm difference.

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

ROOT CAUSE

Log ratio reverses the distant logarithm difference. The faulty expression is result=math.log(b)-math.log(a).

THE FAILURE

Log ratio reverses the distant logarithm difference. The faulty expression is result=math.log(b)-math.log(a).

Unsuccessful approach: The attempted local correction result=abs(math.log(a)-math.log(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.log1p(r)
        else:
            result=math.log(b)-math.log(a)
        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 quotient-1381.55105581381.5510558Failed
underflowing quotient1381.5510558-1381.5510558Failed
nearby moderate0.117783035660.11778303566Passed
nearby large1.9426688922e-161.9426688922e-16Passed
normal-0.693147180560.69314718056Failed
reverse0.69314718056-0.69314718056Failed
equal00Passed
invaliddomaindomainPassed

SHA-256 / c071ecec491fe3523546a35363fb9b701a3ad2ff235e432b2d6c5c28d15f4b2c

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.log1p(r)
        else:
            result=abs(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 quotient1381.5510558-1381.5510558Failed
nearby moderate0.117783035660.11778303566Passed
nearby large1.9426688922e-161.9426688922e-16Passed
normal0.693147180560.69314718056Passed
reverse0.69314718056-0.69314718056Failed
equal00Passed
invaliddomaindomainPassed

SHA-256 / d3fd28f26c25c1367afd469a541bc227e62a5f149fcfa79beae871fd39ec27bd

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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

Case digest / fb0e2702cc58c9c8d9afeac1b80d40b67b2adfaecb0db259ac14d9b268ac7138