FAILURE MAP
← Case archive

FA-15006 / Numerics / Open access

Best bounded rational: rational distance · case 01

The exact best bounded rational result violates the stated contract at rational distance.

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

ROOT CAUSE

The rational distance step uses r-target instead of abs(r-target).

VERIFIED REPAIR

Use abs(r-target) at the rational distance step.

Unsuccessful approach: The partial repair abs(Fraction(n-p,d)) still violates the rational distance invariant.

Case contract

Input [p,q,B], q>0 B>0; nearest rational to p/q with denominator<=B, ties choose smaller rational then denominator.

Why this case matters

Exact discrete arithmetic with observable algorithmic state; no floating point approximation is used.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import itertools
from fractions import Fraction
N = 1
observations = []
def solve(x):
    p,q,B=x;target=Fraction(p,q);candidates=[]
    for d in range(1,B+1):
     a=(p*d)//q
     for n in (a,a+1):
      r=Fraction(n,d)
      candidates.append((r-target,r,d))
    if not candidates:return None
    best=min(candidates)
    r=best[1]
    return [r.numerator,r.denominator]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([-12, 5, 1], [-2, 1]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 1, 2], [-12, 1]), ([-12, 1, 3], [-12, 1]), ([-12, 1, 4], [-12, 1]), ([-12, 1, 5], [-12, 1]), ([-12, 1, 6], [-12, 1])], [([-12, 5, 2], [-5, 2]), ([-12, 7, 2], [-3, 2]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 3, 4], [-4, 1]), ([-12, 3, 5], [-4, 1]), ([-12, 3, 6], [-4, 1]), ([-12, 3, 7], [-4, 1])], [([-12, 5, 3], [-7, 3]), ([-12, 7, 6], [-7, 4]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 5, 7], [-12, 5]), ([-12, 6, 1], [-2, 1]), ([-12, 6, 2], [-2, 1]), ([-12, 6, 3], [-2, 1])], [([-12, 5, 4], [-7, 3]), ([-12, 8, 7], [-3, 2]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 8, 3], [-3, 2]), ([-12, 8, 4], [-3, 2]), ([-12, 8, 5], [-3, 2]), ([-12, 8, 6], [-3, 2])], [([-12, 5, 5], [-12, 5]), ([-12, 9, 5], [-4, 3]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 10, 6], [-6, 5]), ([-12, 10, 7], [-6, 5]), ([-12, 11, 1], [-1, 1]), ([-12, 11, 2], [-1, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("explicit oracle %d" % i, solve(args), expected)
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
explicit oracle 0[-3, 1][-2, 1]Failed
explicit oracle 1[-12, 1][-12, 1]Passed
explicit oracle 2[1, 1][8, 7]Failed
explicit oracle 3[-12, 1][-12, 1]Passed
explicit oracle 4[-12, 1][-12, 1]Passed
explicit oracle 5[-12, 1][-12, 1]Passed
explicit oracle 6[-12, 1][-12, 1]Passed
explicit oracle 7[-12, 1][-12, 1]Passed

SHA-256 / 5ae4117e767653acc6dbb16bfbfa32a620d0e9b26b1cc92d3b8a989ba480f992

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import itertools
from fractions import Fraction
N = 1
observations = []
def solve(x):
    p,q,B=x;target=Fraction(p,q);candidates=[]
    for d in range(1,B+1):
     a=(p*d)//q
     for n in (a,a+1):
      r=Fraction(n,d)
      candidates.append((abs(Fraction(n-p,d)),r,d))
    if not candidates:return None
    best=min(candidates)
    r=best[1]
    return [r.numerator,r.denominator]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([-12, 5, 1], [-2, 1]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 1, 2], [-12, 1]), ([-12, 1, 3], [-12, 1]), ([-12, 1, 4], [-12, 1]), ([-12, 1, 5], [-12, 1]), ([-12, 1, 6], [-12, 1])], [([-12, 5, 2], [-5, 2]), ([-12, 7, 2], [-3, 2]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 3, 4], [-4, 1]), ([-12, 3, 5], [-4, 1]), ([-12, 3, 6], [-4, 1]), ([-12, 3, 7], [-4, 1])], [([-12, 5, 3], [-7, 3]), ([-12, 7, 6], [-7, 4]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 5, 7], [-12, 5]), ([-12, 6, 1], [-2, 1]), ([-12, 6, 2], [-2, 1]), ([-12, 6, 3], [-2, 1])], [([-12, 5, 4], [-7, 3]), ([-12, 8, 7], [-3, 2]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 8, 3], [-3, 2]), ([-12, 8, 4], [-3, 2]), ([-12, 8, 5], [-3, 2]), ([-12, 8, 6], [-3, 2])], [([-12, 5, 5], [-12, 5]), ([-12, 9, 5], [-4, 3]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 10, 6], [-6, 5]), ([-12, 10, 7], [-6, 5]), ([-12, 11, 1], [-1, 1]), ([-12, 11, 2], [-1, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("explicit oracle %d" % i, solve(args), expected)
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
explicit oracle 0[-3, 1][-2, 1]Failed
explicit oracle 1[-12, 1][-12, 1]Passed
explicit oracle 2[8, 7][8, 7]Passed
explicit oracle 3[-12, 1][-12, 1]Passed
explicit oracle 4[-12, 1][-12, 1]Passed
explicit oracle 5[-12, 1][-12, 1]Passed
explicit oracle 6[-12, 1][-12, 1]Passed
explicit oracle 7[-12, 1][-12, 1]Passed

SHA-256 / 7d3e4c0580b2e6f30da2197512e818441f7c1cec528cfad01f3f7d76d7cc2be1

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import itertools
from fractions import Fraction
N = 1
observations = []
def solve(x):
    p,q,B=x;target=Fraction(p,q);candidates=[]
    for d in range(1,B+1):
     a=(p*d)//q
     for n in (a,a+1):
      r=Fraction(n,d)
      candidates.append((abs(r-target),r,d))
    if not candidates:return None
    best=min(candidates)
    r=best[1]
    return [r.numerator,r.denominator]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([-12, 5, 1], [-2, 1]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 1, 2], [-12, 1]), ([-12, 1, 3], [-12, 1]), ([-12, 1, 4], [-12, 1]), ([-12, 1, 5], [-12, 1]), ([-12, 1, 6], [-12, 1])], [([-12, 5, 2], [-5, 2]), ([-12, 7, 2], [-3, 2]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 3, 4], [-4, 1]), ([-12, 3, 5], [-4, 1]), ([-12, 3, 6], [-4, 1]), ([-12, 3, 7], [-4, 1])], [([-12, 5, 3], [-7, 3]), ([-12, 7, 6], [-7, 4]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 5, 7], [-12, 5]), ([-12, 6, 1], [-2, 1]), ([-12, 6, 2], [-2, 1]), ([-12, 6, 3], [-2, 1])], [([-12, 5, 4], [-7, 3]), ([-12, 8, 7], [-3, 2]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 8, 3], [-3, 2]), ([-12, 8, 4], [-3, 2]), ([-12, 8, 5], [-3, 2]), ([-12, 8, 6], [-3, 2])], [([-12, 5, 5], [-12, 5]), ([-12, 9, 5], [-4, 3]), ([-12, 1, 1], [-12, 1]), ([12, 11, 7], [8, 7]), ([-12, 10, 6], [-6, 5]), ([-12, 10, 7], [-6, 5]), ([-12, 11, 1], [-1, 1]), ([-12, 11, 2], [-1, 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("explicit oracle %d" % i, solve(args), expected)
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
explicit oracle 0[-2, 1][-2, 1]Passed
explicit oracle 1[-12, 1][-12, 1]Passed
explicit oracle 2[8, 7][8, 7]Passed
explicit oracle 3[-12, 1][-12, 1]Passed
explicit oracle 4[-12, 1][-12, 1]Passed
explicit oracle 5[-12, 1][-12, 1]Passed
explicit oracle 6[-12, 1][-12, 1]Passed
explicit oracle 7[-12, 1][-12, 1]Passed

SHA-256 / 722414ba03c013653d3d329e7293e435f76124df7f7136081158d6d046120354

Verification & scope

A deterministic bounded teaching model. Inputs are restricted to the explicit contract; this is not a production algebra library. 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:22.514076+00:00.

Case digest / 7e8b73fe5730b0bb538aa1cfa139219844c49b9356c0a16f03bbb6537bef5042