FA-15001 / Numerics / Open access
Best bounded rational: two nearest numerator candidates · case 01
The exact best bounded rational result violates the stated contract at two nearest numerator candidates.
ROOT CAUSE
The two nearest numerator candidates step uses (a,) instead of (a,a+1).
VERIFIED REPAIR
Use (a,a+1) at the two nearest numerator candidates step.
Unsuccessful approach: The partial repair (a-1,a) still violates the two nearest numerator candidates 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,):
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, 3], [-7, 3]), ([-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, 4], [-7, 3]), ([-12, 10, 1], [-1, 1]), ([-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, 7, 2], [-3, 2]), ([-12, 11, 2], [-1, 1]), ([-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, 7, 3], [-5, 3]), ([-12, 11, 5], [-1, 1]), ([-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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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 / 0a739db37a315a9f9887a77efddcbc5028c8fa169ce9a6ef4dcbf09cf467dc23
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-1,a):
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, 3], [-7, 3]), ([-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, 4], [-7, 3]), ([-12, 10, 1], [-1, 1]), ([-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, 7, 2], [-3, 2]), ([-12, 11, 2], [-1, 1]), ([-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, 7, 3], [-5, 3]), ([-12, 11, 5], [-1, 1]), ([-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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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 / 793f4f634d5495b8e5f31236514a37badc936e5c469f8fdc21aa0304ee8eeb21
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, 3], [-7, 3]), ([-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, 4], [-7, 3]), ([-12, 10, 1], [-1, 1]), ([-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, 7, 2], [-3, 2]), ([-12, 11, 2], [-1, 1]), ([-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, 7, 3], [-5, 3]), ([-12, 11, 5], [-1, 1]), ([-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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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 / e3233f405bbc9096d5193fa048bf2ac0ccb02e69ef536a95587d4e55665cff53
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.507819+00:00.
Case digest / 6e77c53940f2109e066b61cc2391fc4ce4755e7380f121364983ae932f4e49e5