FA-15521 / Numerics / Open access
Lucas binomial residue: remaining digit termination · case 01
The exact lucas binomial residue result violates the stated contract at remaining digit termination.
ROOT CAUSE
The remaining digit termination step uses n==0 instead of n==0 and k==0.
VERIFIED REPAIR
Use n==0 and k==0 at the remaining digit termination step.
Unsuccessful approach: The partial repair n<p and k<p still violates the remaining digit termination invariant.
Case contract
Input [n,k,p], n,k>=0 p prime; return binomial(n,k) modulo p, zero when k>n. Bounds: n,k<2^30.
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):
n,k,p=x;r=1
for _ in range(30):
if n==0:break
a,b=n%p,k%p
if b>a:return 0
r=r*math.comb(a,b)%p
n,k=n//p,k//p
return r
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 1, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 2, 2], 0), ([0, 3, 2], 0), ([0, 4, 2], 0), ([0, 5, 2], 0), ([0, 6, 2], 0)], [([0, 2, 2], 0), ([0, 8, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 17, 2], 0), ([0, 18, 2], 0), ([0, 19, 2], 0), ([0, 20, 2], 0)], [([0, 3, 2], 0), ([1, 2, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 34, 2], 0), ([0, 35, 2], 0), ([0, 36, 2], 0), ([0, 37, 2], 0)], [([0, 4, 2], 0), ([1, 5, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([1, 13, 2], 0), ([1, 14, 2], 0), ([1, 15, 2], 0), ([1, 16, 2], 0)], [([0, 5, 2], 0), ([1, 16, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([1, 30, 2], 0), ([1, 31, 2], 0), ([1, 32, 2], 0), ([1, 33, 2], 0)]]
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 | 1 | 0 | Failed |
| explicit oracle 1 | 1 | 1 | Passed |
| explicit oracle 2 | 0 | 0 | Passed |
| explicit oracle 3 | 1 | 0 | Failed |
| explicit oracle 4 | 1 | 0 | Failed |
| explicit oracle 5 | 1 | 0 | Failed |
| explicit oracle 6 | 1 | 0 | Failed |
| explicit oracle 7 | 1 | 0 | Failed |
SHA-256 / 05da410c3a0ab017f9a498e6b8ba375f97ed454d297f81fe9f606d021528e309
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):
n,k,p=x;r=1
for _ in range(30):
if n<p and k<p:break
a,b=n%p,k%p
if b>a:return 0
r=r*math.comb(a,b)%p
n,k=n//p,k//p
return r
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 1, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 2, 2], 0), ([0, 3, 2], 0), ([0, 4, 2], 0), ([0, 5, 2], 0), ([0, 6, 2], 0)], [([0, 2, 2], 0), ([0, 8, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 17, 2], 0), ([0, 18, 2], 0), ([0, 19, 2], 0), ([0, 20, 2], 0)], [([0, 3, 2], 0), ([1, 2, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 34, 2], 0), ([0, 35, 2], 0), ([0, 36, 2], 0), ([0, 37, 2], 0)], [([0, 4, 2], 0), ([1, 5, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([1, 13, 2], 0), ([1, 14, 2], 0), ([1, 15, 2], 0), ([1, 16, 2], 0)], [([0, 5, 2], 0), ([1, 16, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([1, 30, 2], 0), ([1, 31, 2], 0), ([1, 32, 2], 0), ([1, 33, 2], 0)]]
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 | 1 | 0 | Failed |
| explicit oracle 1 | 1 | 1 | Passed |
| explicit oracle 2 | 1 | 0 | Failed |
| explicit oracle 3 | 1 | 0 | Failed |
| explicit oracle 4 | 0 | 0 | Passed |
| explicit oracle 5 | 1 | 0 | Failed |
| explicit oracle 6 | 0 | 0 | Passed |
| explicit oracle 7 | 0 | 0 | Passed |
SHA-256 / 37dad6f4f22fd6a7a1bde41cd0631e85d7b19fe695d075fe0abcfd1672eb116d
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):
n,k,p=x;r=1
for _ in range(30):
if n==0 and k==0:break
a,b=n%p,k%p
if b>a:return 0
r=r*math.comb(a,b)%p
n,k=n//p,k//p
return r
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 1, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 2, 2], 0), ([0, 3, 2], 0), ([0, 4, 2], 0), ([0, 5, 2], 0), ([0, 6, 2], 0)], [([0, 2, 2], 0), ([0, 8, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 17, 2], 0), ([0, 18, 2], 0), ([0, 19, 2], 0), ([0, 20, 2], 0)], [([0, 3, 2], 0), ([1, 2, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 34, 2], 0), ([0, 35, 2], 0), ([0, 36, 2], 0), ([0, 37, 2], 0)], [([0, 4, 2], 0), ([1, 5, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([1, 13, 2], 0), ([1, 14, 2], 0), ([1, 15, 2], 0), ([1, 16, 2], 0)], [([0, 5, 2], 0), ([1, 16, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([1, 30, 2], 0), ([1, 31, 2], 0), ([1, 32, 2], 0), ([1, 33, 2], 0)]]
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 | 0 | 0 | Passed |
| explicit oracle 1 | 1 | 1 | Passed |
| explicit oracle 2 | 0 | 0 | Passed |
| explicit oracle 3 | 0 | 0 | Passed |
| explicit oracle 4 | 0 | 0 | Passed |
| explicit oracle 5 | 0 | 0 | Passed |
| explicit oracle 6 | 0 | 0 | Passed |
| explicit oracle 7 | 0 | 0 | Passed |
SHA-256 / 2672ca23eb07b18c1f4e062a8aaf54c677a94167052bc7aad70991f548cad689
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:27.492031+00:00.
Case digest / 305b7dd2cf9bae33d5900250548e69c7846bb447a64dce424de69f523384ef94