FAILURE MAP
← Case archive

FA-15536 / Numerics / Open access

Lucas binomial residue: base prime digit shift · case 01

The exact lucas binomial residue result violates the stated contract at base prime digit shift.

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

ROOT CAUSE

The base prime digit shift step uses n%p,k%p instead of n//p,k//p.

THE FAILURE

The base prime digit shift step uses n%p,k%p instead of n//p,k//p.

Unsuccessful approach: The partial repair n//p,k%p still violates the base prime digit shift 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 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, 2, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 1, 2], 0), ([0, 3, 2], 0), ([0, 4, 2], 0), ([0, 5, 2], 0), ([0, 6, 2], 0)], [([0, 4, 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, 6, 2], 0), ([0, 14, 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, 8, 2], 0), ([0, 20, 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, 10, 2], 0), ([0, 26, 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 fixtureActualExpectedOutcome
explicit oracle 010Failed
explicit oracle 111Passed
explicit oracle 210Failed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 510Failed
explicit oracle 600Passed
explicit oracle 710Failed

SHA-256 / 84f19e8ea86388295716dab7aedab0c7406a9fc4b4802193eceb20a8f2b77457

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==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, 2, 2], 0), ([0, 0, 2], 1), ([34, 37, 7], 0), ([0, 1, 2], 0), ([0, 3, 2], 0), ([0, 4, 2], 0), ([0, 5, 2], 0), ([0, 6, 2], 0)], [([0, 4, 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, 6, 2], 0), ([0, 14, 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, 8, 2], 0), ([0, 20, 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, 10, 2], 0), ([0, 26, 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 fixtureActualExpectedOutcome
explicit oracle 010Failed
explicit oracle 111Passed
explicit oracle 200Passed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 510Failed
explicit oracle 600Passed
explicit oracle 710Failed

SHA-256 / 9fbe0417c5f45d986be72df8d86724dd9a55903a422b78e03baf7999457df8fd

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

Case digest / 9cb70fd8a1144c9013d3fefbe2cfae16d8148daaf5933eb162aa39c2d699c954