FAILURE MAP
← Case archive

FA-15786 / Numerics / Open access

Montgomery residue product: final conditional subtraction · case 01

The exact montgomery residue product result violates the stated contract at final conditional subtraction.

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

ROOT CAUSE

The final conditional subtraction step uses v>m instead of v>=m.

THE FAILURE

The final conditional subtraction step uses v>m instead of v>=m.

Unsuccessful approach: The partial repair v>0 still violates the final conditional subtraction 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 = [[([3, 3, 9, 16], 0), ([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)], [([3, 6, 9, 16], 0), ([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)], [([6, 3, 9, 16], 0), ([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)], [([6, 6, 9, 16], 0), ([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)], [([3, 5, 15, 16], 0), ([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 090Failed
explicit oracle 122Passed
explicit oracle 200Passed
explicit oracle 311Passed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 600Passed
explicit oracle 711Passed

SHA-256 / 6a5d9226c44056ef8079b0365a60bde9888a6a16f4f784f66d9bb09437a00dc4

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>0:v-=m
    return v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([3, 3, 9, 16], 0), ([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)], [([3, 6, 9, 16], 0), ([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)], [([6, 3, 9, 16], 0), ([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)], [([6, 6, 9, 16], 0), ([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)], [([3, 5, 15, 16], 0), ([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 000Passed
explicit oracle 1-12Failed
explicit oracle 200Passed
explicit oracle 311Passed
explicit oracle 400Passed
explicit oracle 500Passed
explicit oracle 600Passed
explicit oracle 7-21Failed

SHA-256 / a48f5b396b0db57b36a35b92b36fe05b03f0999ce37e941810dc048f496122d9

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

Case digest / f9df1342ea84db29a7f5249a67493a09dd572f5d80f5ad19578e0fbcdcff6ee1