FA-15771 / Numerics / Open access
Montgomery residue product: wide product retention · case 01
The exact montgomery residue product result violates the stated contract at wide product retention.
ROOT CAUSE
The wide product retention step uses (a*b)%R instead of a*b.
THE FAILURE
The wide product retention step uses (a*b)%R instead of a*b.
Unsuccessful approach: The partial repair a+b still violates the wide product retention invariant.
Case contract
Input [a,b,m,R], odd modulus m<R and R power of2, 0<=a,b<m; return a*b*R^-1 modulo m using Montgomery reduction.
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,b,m,R=x
nprime=(-pow(m,-1,R))%R
t=(a*b)%R
u=(t*nprime)%R
v=(t+u*m)//R
if v>=m:v-=m
return v
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([2, 4, 5, 8], 1), ([0, 1, 3, 8], 0), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([0, 2, 3, 8], 0), ([1, 0, 3, 8], 0), ([1, 1, 3, 8], 2), ([1, 2, 3, 8], 1)], [([3, 3, 5, 8], 3), ([1, 1, 3, 8], 2), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([1, 3, 5, 8], 1), ([1, 4, 5, 8], 3), ([2, 0, 5, 8], 0), ([2, 1, 5, 8], 4)], [([3, 4, 5, 8], 4), ([2, 1, 3, 8], 1), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([0, 0, 7, 8], 0), ([0, 1, 7, 8], 0), ([0, 2, 7, 8], 0), ([0, 3, 7, 8], 0)], [([4, 2, 5, 8], 1), ([0, 3, 5, 8], 0), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([2, 3, 7, 8], 6), ([2, 4, 7, 8], 1), ([2, 5, 7, 8], 3), ([2, 6, 7, 8], 5)], [([4, 3, 5, 8], 4), ([1, 1, 5, 8], 2), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([4, 6, 7, 8], 3), ([5, 0, 7, 8], 0), ([5, 1, 7, 8], 5), ([5, 2, 7, 8], 3)]]
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 | 1 | Failed |
| explicit oracle 1 | 0 | 0 | Passed |
| explicit oracle 2 | 0 | 0 | Passed |
| explicit oracle 3 | 4 | 1 | Failed |
| explicit oracle 4 | 0 | 0 | Passed |
| explicit oracle 5 | 0 | 0 | Passed |
| explicit oracle 6 | 2 | 2 | Passed |
| explicit oracle 7 | 1 | 1 | Passed |
SHA-256 / 7e305c92d3ebb4ad0dd13ae1e4fd5a229eccbadc8a210bf24cda8e949a7d7635
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,b,m,R=x
nprime=(-pow(m,-1,R))%R
t=a+b
u=(t*nprime)%R
v=(t+u*m)//R
if v>=m:v-=m
return v
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([2, 4, 5, 8], 1), ([0, 1, 3, 8], 0), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([0, 2, 3, 8], 0), ([1, 0, 3, 8], 0), ([1, 1, 3, 8], 2), ([1, 2, 3, 8], 1)], [([3, 3, 5, 8], 3), ([1, 1, 3, 8], 2), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([1, 3, 5, 8], 1), ([1, 4, 5, 8], 3), ([2, 0, 5, 8], 0), ([2, 1, 5, 8], 4)], [([3, 4, 5, 8], 4), ([2, 1, 3, 8], 1), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([0, 0, 7, 8], 0), ([0, 1, 7, 8], 0), ([0, 2, 7, 8], 0), ([0, 3, 7, 8], 0)], [([4, 2, 5, 8], 1), ([0, 3, 5, 8], 0), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([2, 3, 7, 8], 6), ([2, 4, 7, 8], 1), ([2, 5, 7, 8], 3), ([2, 6, 7, 8], 5)], [([4, 3, 5, 8], 4), ([1, 1, 5, 8], 2), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([4, 6, 7, 8], 3), ([5, 0, 7, 8], 0), ([5, 1, 7, 8], 5), ([5, 2, 7, 8], 3)]]
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 | 2 | 1 | Failed |
| explicit oracle 1 | 2 | 0 | Failed |
| explicit oracle 2 | 0 | 0 | Passed |
| explicit oracle 3 | 29 | 1 | Failed |
| explicit oracle 4 | 1 | 0 | Failed |
| explicit oracle 5 | 2 | 0 | Failed |
| explicit oracle 6 | 1 | 2 | Failed |
| explicit oracle 7 | 0 | 1 | Failed |
SHA-256 / c44c31cfe18933b7f712fd75013988d36c1b6be21f81bb6c79fafea09645557a
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.117271+00:00.
Case digest / 1850dfd7f2e22766106a9eef377875f724fbb1585cc30c5b93f131ad8c8fe80e