FAILURE MAP
← Case archive

FA-15781 / Numerics / Open access

Montgomery residue product: radix cancellation quotient · case 01

The exact montgomery residue product result violates the stated contract at radix cancellation quotient.

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

ROOT CAUSE

The radix cancellation quotient step uses (t-u*m)//R instead of (t+u*m)//R.

VERIFIED REPAIR

Use (t+u*m)//R at the radix cancellation quotient step.

Unsuccessful approach: The partial repair (t+u*m)%R still violates the radix cancellation quotient 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
    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 = [[([1, 1, 3, 8], 2), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([0, 1, 3, 8], 0), ([0, 2, 3, 8], 0), ([1, 0, 3, 8], 0), ([1, 2, 3, 8], 1), ([2, 0, 3, 8], 0)], [([1, 2, 3, 8], 1), ([2, 2, 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)], [([2, 1, 3, 8], 1), ([1, 3, 5, 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)], [([2, 2, 3, 8], 2), ([2, 2, 5, 8], 3), ([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)], [([1, 1, 5, 8], 2), ([3, 1, 5, 8], 1), ([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 fixtureActualExpectedOutcome
explicit oracle 0-22Failed
explicit oracle 100Passed
explicit oracle 2241Failed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 6-11Failed
explicit oracle 700Passed

SHA-256 / 5dc54bbaaab87d6df8ce64ff761b11d7394f7884374586237f469b34e2a92584

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 = [[([1, 1, 3, 8], 2), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([0, 1, 3, 8], 0), ([0, 2, 3, 8], 0), ([1, 0, 3, 8], 0), ([1, 2, 3, 8], 1), ([2, 0, 3, 8], 0)], [([1, 2, 3, 8], 1), ([2, 2, 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)], [([2, 1, 3, 8], 1), ([1, 3, 5, 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)], [([2, 2, 3, 8], 2), ([2, 2, 5, 8], 3), ([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)], [([1, 1, 5, 8], 2), ([3, 1, 5, 8], 1), ([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 fixtureActualExpectedOutcome
explicit oracle 002Failed
explicit oracle 100Passed
explicit oracle 201Failed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 601Failed
explicit oracle 700Passed

SHA-256 / 46ea31de849e00f4bfe9253040d3230cfca0f71f9fcdc91e9f185c18fbc07283

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):
    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 = [[([1, 1, 3, 8], 2), ([0, 0, 3, 8], 0), ([30, 30, 31, 32], 1), ([0, 1, 3, 8], 0), ([0, 2, 3, 8], 0), ([1, 0, 3, 8], 0), ([1, 2, 3, 8], 1), ([2, 0, 3, 8], 0)], [([1, 2, 3, 8], 1), ([2, 2, 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)], [([2, 1, 3, 8], 1), ([1, 3, 5, 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)], [([2, 2, 3, 8], 2), ([2, 2, 5, 8], 3), ([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)], [([1, 1, 5, 8], 2), ([3, 1, 5, 8], 1), ([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 fixtureActualExpectedOutcome
explicit oracle 022Passed
explicit oracle 100Passed
explicit oracle 211Passed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 611Passed
explicit oracle 700Passed

SHA-256 / c33b21376ad0f6ca2c5047e24b1574d54e121496e96f05c791dd2e735e721228

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

Case digest / 3939d267826dbd2002edb0aee0fad4b0c5770d7736452d9ac2baa2c8acaf2340