{"abstract":"The exact tonelli shanks square root result violates the stated contract at initial odd component residue.","category":"Numerics","checks":8,"contract":"Input [a,p], odd prime p and nonzero quadratic residue a; return smaller of two square roots modulo p. Bounds: p<=97.","contract_signature":"x","evaluation_group":"s3-numerics-tonelli-shanks-square-root","failed_approach":"The partial repair pow(a,s,p) still violates the initial odd component residue invariant.","family":"s3-numerics-tonelli-shanks-square-root-initial-odd-component-residue","id":"FA-15826","implementations":{"attempt":{"sha256":"ecb1740d58fe69601594e5fd5bd7f4f548f0738dd7a7b0cbe24af91515af7376","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport math\nimport itertools\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    a,p=x\n    q=p-1;s=0\n    while q%2==0:q//=2;s+=1\n    z=2\n    while pow(z,(p-1)//2,p)!=p-1:z+=1\n    c=pow(z,q,p);r=pow(a,(q+1)//2,p);t=pow(a,s,p);m=s\n    for _ in range(20):\n     if t==1:break\n     i=1;v=t*t%p\n     while i<m and v!=1:v=v*v%p;i+=1\n     if i>=m:return None\n     b=pow(c,1<<(m-i-1),p)\n     r=r*b%p;t=t*b*b%p;c=b*b%p;m=i\n    return min(r,p-r)\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[([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)]]\nfor i, (args, expected) in enumerate(fixtures[N-1]):\n    check(\"explicit oracle %d\" % i, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"25400449f4cbc8792ae60c30fb2e2dbf63c53ac23ec616e183df633dc107c9ef","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport math\nimport itertools\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    a,p=x\n    q=p-1;s=0\n    while q%2==0:q//=2;s+=1\n    z=2\n    while pow(z,(p-1)//2,p)!=p-1:z+=1\n    c=pow(z,q,p);r=pow(a,(q+1)//2,p);t=a%p;m=s\n    for _ in range(20):\n     if t==1:break\n     i=1;v=t*t%p\n     while i<m and v!=1:v=v*v%p;i+=1\n     if i>=m:return None\n     b=pow(c,1<<(m-i-1),p)\n     r=r*b%p;t=t*b*b%p;c=b*b%p;m=i\n    return min(r,p-r)\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[([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)]]\nfor i, (args, expected) in enumerate(fixtures[N-1]):\n    check(\"explicit oracle %d\" % i, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"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.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"s3-numerics-tonelli-shanks-square-root-initial-odd-component-residue","generated_at":"2026-09-29T14:39:30.759480+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Exact discrete arithmetic with observable algorithmic state; no floating point approximation is used.","root_cause":"The initial odd component residue step uses a%p instead of pow(a,q,p).","sha256":"805cceb7b306a306ba03a8a70c42099ea4b1777f09416da7f3b1c6c9d5d1e565","title":"Tonelli shanks square root: initial odd component residue · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verified":true,"visibility":"public","verification":{"attempt":{"elapsed_ms":41.812,"exit_code":1,"observations":[{"actual":null,"check":"explicit oracle 0","expected":3,"passed":false},{"actual":1,"check":"explicit oracle 1","expected":2,"passed":false},{"actual":1,"check":"explicit oracle 2","expected":1,"passed":true},{"actual":22,"check":"explicit oracle 3","expected":22,"passed":true},{"actual":1,"check":"explicit oracle 4","expected":1,"passed":true},{"actual":null,"check":"explicit oracle 5","expected":2,"passed":false},{"actual":1,"check":"explicit oracle 6","expected":1,"passed":true},{"actual":null,"check":"explicit oracle 7","expected":5,"passed":false}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"explicit oracle 0\", \"actual\": null, \"expected\": 3, \"passed\": false}, {\"check\": \"explicit oracle 1\", \"actual\": 1, \"expected\": 2, \"passed\": false}, {\"check\": \"explicit oracle 2\", \"actual\": 1, \"expected\": 1, \"passed\": true}, {\"check\": \"explicit oracle 3\", \"actual\": 22, \"expected\": 22, \"passed\": true}, {\"check\": \"explicit oracle 4\", \"actual\": 1, \"expected\": 1, \"passed\": true}, {\"check\": \"explicit oracle 5\", \"actual\": null, \"expected\": 2, \"passed\": false}, {\"check\": \"explicit oracle 6\", \"actual\": 1, \"expected\": 1, \"passed\": true}, {\"check\": \"explicit oracle 7\", \"actual\": null, \"expected\": 5, \"passed\": false}], \"passed\": false}\n"},"broken":{"elapsed_ms":41.897,"exit_code":1,"observations":[{"actual":null,"check":"explicit oracle 0","expected":3,"passed":false},{"actual":2,"check":"explicit oracle 1","expected":2,"passed":true},{"actual":1,"check":"explicit oracle 2","expected":1,"passed":true},{"actual":22,"check":"explicit oracle 3","expected":22,"passed":true},{"actual":1,"check":"explicit oracle 4","expected":1,"passed":true},{"actual":null,"check":"explicit oracle 5","expected":2,"passed":false},{"actual":1,"check":"explicit oracle 6","expected":1,"passed":true},{"actual":null,"check":"explicit oracle 7","expected":5,"passed":false}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"explicit oracle 0\", \"actual\": null, \"expected\": 3, \"passed\": false}, {\"check\": \"explicit oracle 1\", \"actual\": 2, \"expected\": 2, \"passed\": true}, {\"check\": \"explicit oracle 2\", \"actual\": 1, \"expected\": 1, \"passed\": true}, {\"check\": \"explicit oracle 3\", \"actual\": 22, \"expected\": 22, \"passed\": true}, {\"check\": \"explicit oracle 4\", \"actual\": 1, \"expected\": 1, \"passed\": true}, {\"check\": \"explicit oracle 5\", \"actual\": null, \"expected\": 2, \"passed\": false}, {\"check\": \"explicit oracle 6\", \"actual\": 1, \"expected\": 1, \"passed\": true}, {\"check\": \"explicit oracle 7\", \"actual\": null, \"expected\": 5, \"passed\": false}], \"passed\": false}\n"}},"member_only":{"stages":["fixed"],"fields":["implementations.fixed","verification.fixed","harness","repair"],"note":"The verified repair, its recorded checks, the repair description, and the scoring harness are available to members."}}