FAILURE MAP
← Case archive

FA-14996 / Numerics / Open access

Best bounded rational: scaled numerator floor · case 01

The exact best bounded rational result violates the stated contract at scaled numerator floor.

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

ROOT CAUSE

The scaled numerator floor step uses p//q instead of (p*d)//q.

THE FAILURE

The scaled numerator floor step uses p//q instead of (p*d)//q.

Unsuccessful approach: The partial repair abs(p*d)//q still violates the scaled numerator floor 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//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, 2], [-5, 2]), ([-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, 1, 4], [-12, 1]), ([-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, 1, 7], [-12, 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, 5, 5], [-12, 5]), ([-12, 2, 3], [-6, 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, 5, 6], [-12, 5]), ([-12, 2, 6], [-6, 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 fixtureActualExpectedOutcome
explicit oracle 0[-2, 1][-5, 2]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 / 17e4bd657325f6cc9715f1d1906846b0d555db956694e0641b86db959f83b776

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=abs(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, 2], [-5, 2]), ([-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, 1, 4], [-12, 1]), ([-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, 1, 7], [-12, 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, 5, 5], [-12, 5]), ([-12, 2, 3], [-6, 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, 5, 6], [-12, 5]), ([-12, 2, 6], [-6, 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 fixtureActualExpectedOutcome
explicit oracle 0[2, 1][-5, 2]Failed
explicit oracle 1[12, 1][-12, 1]Failed
explicit oracle 2[8, 7][8, 7]Passed
explicit oracle 3[12, 1][-12, 1]Failed
explicit oracle 4[12, 1][-12, 1]Failed
explicit oracle 5[12, 1][-12, 1]Failed
explicit oracle 6[12, 1][-12, 1]Failed
explicit oracle 7[12, 1][-12, 1]Failed

SHA-256 / 4cf13d9ae89039dc14d22291f58f5221748bc1526a87f5912408b418560d856f

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

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

Case digest / 85a7408c61d44cf11150d25352b726eb250d66c83c12ea200ac40f9bf7fd2aba