FA-15826 / Numerics / Open access
Tonelli shanks square root: initial odd component residue · case 01
The exact tonelli shanks square root result violates the stated contract at initial odd component residue.
ROOT CAUSE
The initial odd component residue step uses a%p instead of pow(a,q,p).
THE FAILURE
The initial odd component residue step uses a%p instead of pow(a,q,p).
Unsuccessful approach: The partial repair pow(a,s,p) still violates the initial odd component residue invariant.
Case contract
Input [a,p], odd prime p and nonzero quadratic residue a; return smaller of two square roots modulo p. Bounds: p<=97.
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):
a,p=x
q=p-1;s=0
while q%2==0:q//=2;s+=1
z=2
while pow(z,(p-1)//2,p)!=p-1:z+=1
c=pow(z,q,p);r=pow(a,(q+1)//2,p);t=a%p;m=s
for _ in range(20):
if t==1:break
i=1;v=t*t%p
while i<m and v!=1:v=v*v%p;i+=1
if i>=m:return None
b=pow(c,1<<(m-i-1),p)
r=r*b%p;t=t*b*b%p;c=b*b%p;m=i
return min(r,p-r)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([2, 7], 3), ([4, 5], 2), ([1, 5], 1), ([96, 97], 22), ([1, 7], 1), ([4, 7], 2), ([1, 11], 1), ([3, 11], 5)], [([4, 7], 2), ([3, 11], 5), ([1, 5], 1), ([96, 97], 22), ([2, 17], 6), ([4, 17], 2), ([8, 17], 5), ([9, 17], 3)], [([3, 11], 5), ([9, 11], 3), ([1, 5], 1), ([96, 97], 22), ([2, 23], 5), ([3, 23], 7), ([4, 23], 2), ([6, 23], 11)], [([4, 11], 2), ([9, 13], 3), ([1, 5], 1), ([96, 97], 22), ([16, 29], 4), ([20, 29], 7), ([22, 29], 14), ([23, 29], 9)], [([5, 11], 4), ([2, 17], 6), ([1, 5], 1), ([96, 97], 22), ([18, 31], 7), ([19, 31], 9), ([20, 31], 12), ([25, 31], 5)]]
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 | None | 3 | Failed |
| explicit oracle 1 | 2 | 2 | Passed |
| explicit oracle 2 | 1 | 1 | Passed |
| explicit oracle 3 | 22 | 22 | Passed |
| explicit oracle 4 | 1 | 1 | Passed |
| explicit oracle 5 | None | 2 | Failed |
| explicit oracle 6 | 1 | 1 | Passed |
| explicit oracle 7 | None | 5 | Failed |
SHA-256 / 25400449f4cbc8792ae60c30fb2e2dbf63c53ac23ec616e183df633dc107c9ef
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):
a,p=x
q=p-1;s=0
while q%2==0:q//=2;s+=1
z=2
while pow(z,(p-1)//2,p)!=p-1:z+=1
c=pow(z,q,p);r=pow(a,(q+1)//2,p);t=pow(a,s,p);m=s
for _ in range(20):
if t==1:break
i=1;v=t*t%p
while i<m and v!=1:v=v*v%p;i+=1
if i>=m:return None
b=pow(c,1<<(m-i-1),p)
r=r*b%p;t=t*b*b%p;c=b*b%p;m=i
return min(r,p-r)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([2, 7], 3), ([4, 5], 2), ([1, 5], 1), ([96, 97], 22), ([1, 7], 1), ([4, 7], 2), ([1, 11], 1), ([3, 11], 5)], [([4, 7], 2), ([3, 11], 5), ([1, 5], 1), ([96, 97], 22), ([2, 17], 6), ([4, 17], 2), ([8, 17], 5), ([9, 17], 3)], [([3, 11], 5), ([9, 11], 3), ([1, 5], 1), ([96, 97], 22), ([2, 23], 5), ([3, 23], 7), ([4, 23], 2), ([6, 23], 11)], [([4, 11], 2), ([9, 13], 3), ([1, 5], 1), ([96, 97], 22), ([16, 29], 4), ([20, 29], 7), ([22, 29], 14), ([23, 29], 9)], [([5, 11], 4), ([2, 17], 6), ([1, 5], 1), ([96, 97], 22), ([18, 31], 7), ([19, 31], 9), ([20, 31], 12), ([25, 31], 5)]]
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 | None | 3 | Failed |
| explicit oracle 1 | 1 | 2 | Failed |
| explicit oracle 2 | 1 | 1 | Passed |
| explicit oracle 3 | 22 | 22 | Passed |
| explicit oracle 4 | 1 | 1 | Passed |
| explicit oracle 5 | None | 2 | Failed |
| explicit oracle 6 | 1 | 1 | Passed |
| explicit oracle 7 | None | 5 | Failed |
SHA-256 / ecb1740d58fe69601594e5fd5bd7f4f548f0738dd7a7b0cbe24af91515af7376
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:30.759480+00:00.
Case digest / 805cceb7b306a306ba03a8a70c42099ea4b1777f09416da7f3b1c6c9d5d1e565