FA-14611 / Numerics / Open access
Polynomial long division: remainder degree trimming · case 01
The exact polynomial long division result violates the stated contract at remainder degree trimming.
ROOT CAUSE
The remainder degree trimming step uses r[0]==0 instead of r[-1]==0.
VERIFIED REPAIR
Use r[-1]==0 at the remainder degree trimming step.
Unsuccessful approach: The partial repair r[-1]<=0 still violates the remainder degree trimming invariant.
Case contract
Input [A,B] integer ascending coefficients, B nonzero canonical; return rational quotient/remainder coefficient pairs; zero polynomial is []. Bounds: len(A)<=4 and 1<=len(B)<=4.
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=x
r=list(map(Fraction,A));b=list(map(Fraction,B))
while r and r[-1]==0:r.pop()
q=[Fraction(0)]*max(0,len(r)-len(b)+1)
for _ in range(20):
if len(r)<len(b):break
k=len(r)-len(b)
if k<0 or k>=len(q):return None
c=r[-1]/b[-1]
q[k]=q[k]+c
for j in range(len(b)):
if j+k>=len(r):return None
r[j+k]=r[j+k]-c*b[j]
while r and r[0]==0:r.pop()
while q and q[-1]==0:q.pop()
return [[[v.numerator,v.denominator] for v in z] for z in (q,r)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, -1], [-1, 1]], [[[-2, 1], [-1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [-1, 2]], [[[-3, 4], [-1, 2]], [[-7, 4]]]), ([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [0, 1]], [[[-1, 1], [-1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [0, 2]], [[[-1, 2], [-1, 2]], [[-1, 1]]]), ([[-1, -1, -1], [1, -1]], [[[2, 1], [1, 1]], [[-3, 1]]])], [([[-1, -1, -1], [-1, 1]], [[[-2, 1], [-1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, 0], [0, 2]], [[[-1, 2]], [[-1, 1]]]), ([[-1, -1, 0], [1, -1]], [[[1, 1]], [[-2, 1]]]), ([[-1, -1, 0], [1, 1]], [[[-1, 1]], []]), ([[-1, -1, 0], [1, 2]], [[[-1, 2]], [[-1, 2]]])], [([[-1, -1, -1], [-1, 2]], [[[-3, 4], [-1, 2]], [[-7, 4]]]), ([[-1, -1, -1], [1, -1]], [[[2, 1], [1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, 1], [2, 1]], [[[-3, 1], [1, 1]], [[5, 1]]]), ([[-1, -1, 1], [2, 2]], [[[-1, 1], [1, 2]], [[1, 1]]]), ([[-1, -1, 2], [-1, -1]], [[[3, 1], [-2, 1]], [[2, 1]]]), ([[-1, -1, 2], [-1, 1]], [[[1, 1], [2, 1]], []])], [([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [2, -1]], [[[3, 1], [1, 1]], [[-7, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, 0, -1], [0, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[-1, 0, -1], [0, 1]], [[[0, 1], [-1, 1]], [[-1, 1]]]), ([[-1, 0, -1], [0, 2]], [[[0, 1], [-1, 2]], [[-1, 1]]]), ([[-1, 0, -1], [1, -1]], [[[1, 1], [1, 1]], [[-2, 1]]])], [([[-1, -1, -1], [0, 1]], [[[-1, 1], [-1, 1]], [[-1, 1]]]), ([[-1, -1, 0], [-1, 1]], [[[-1, 1]], [[-2, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, 0, 0], [1, 2]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, -1]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, 1]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, 2]], [[], [[-1, 1]]])]]
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], [1, 1]], [[-1, 1], [0, 1], [0, 1]]] | [[[0, 1], [1, 1]], [[-1, 1]]] | Failed |
| explicit oracle 1 | [[[0, 1], [2, 1]], [[1, 1], [0, 1], [3, 1], [0, 1]]] | [[[3, 2], [2, 1]], [[-1, 2]]] | Failed |
| explicit oracle 2 | [[[0, 1], [-1, 1]], [[-1, 1], [-2, 1], [0, 1]]] | [[[-2, 1], [-1, 1]], [[-3, 1]]] | Failed |
| explicit oracle 3 | [[[0, 1], [-1, 2]], [[-1, 1], [-3, 2], [0, 1]]] | [[[-3, 4], [-1, 2]], [[-7, 4]]] | Failed |
| explicit oracle 4 | [[[0, 1], [1, 1]], [[-1, 1], [-1, 1], [0, 1]]] | [[[1, 1], [1, 1]], [[-1, 1]]] | Failed |
| explicit oracle 5 | [[[0, 1], [-1, 1]], [[-1, 1], [-1, 1], [0, 1]]] | [[[-1, 1], [-1, 1]], [[-1, 1]]] | Failed |
| explicit oracle 6 | [[[0, 1], [-1, 2]], [[-1, 1], [-1, 1], [0, 1]]] | [[[-1, 2], [-1, 2]], [[-1, 1]]] | Failed |
| explicit oracle 7 | [[[0, 1], [1, 1]], [[-1, 1], [-2, 1], [0, 1]]] | [[[2, 1], [1, 1]], [[-3, 1]]] | Failed |
SHA-256 / de7d05a62a6564c94869b34b826b5aa232b5959c08baf3e5a6f2ccbb5c2dfc68
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=x
r=list(map(Fraction,A));b=list(map(Fraction,B))
while r and r[-1]==0:r.pop()
q=[Fraction(0)]*max(0,len(r)-len(b)+1)
for _ in range(20):
if len(r)<len(b):break
k=len(r)-len(b)
if k<0 or k>=len(q):return None
c=r[-1]/b[-1]
q[k]=q[k]+c
for j in range(len(b)):
if j+k>=len(r):return None
r[j+k]=r[j+k]-c*b[j]
while r and r[-1]<=0:r.pop()
while q and q[-1]==0:q.pop()
return [[[v.numerator,v.denominator] for v in z] for z in (q,r)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, -1], [-1, 1]], [[[-2, 1], [-1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [-1, 2]], [[[-3, 4], [-1, 2]], [[-7, 4]]]), ([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [0, 1]], [[[-1, 1], [-1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [0, 2]], [[[-1, 2], [-1, 2]], [[-1, 1]]]), ([[-1, -1, -1], [1, -1]], [[[2, 1], [1, 1]], [[-3, 1]]])], [([[-1, -1, -1], [-1, 1]], [[[-2, 1], [-1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, 0], [0, 2]], [[[-1, 2]], [[-1, 1]]]), ([[-1, -1, 0], [1, -1]], [[[1, 1]], [[-2, 1]]]), ([[-1, -1, 0], [1, 1]], [[[-1, 1]], []]), ([[-1, -1, 0], [1, 2]], [[[-1, 2]], [[-1, 2]]])], [([[-1, -1, -1], [-1, 2]], [[[-3, 4], [-1, 2]], [[-7, 4]]]), ([[-1, -1, -1], [1, -1]], [[[2, 1], [1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, 1], [2, 1]], [[[-3, 1], [1, 1]], [[5, 1]]]), ([[-1, -1, 1], [2, 2]], [[[-1, 1], [1, 2]], [[1, 1]]]), ([[-1, -1, 2], [-1, -1]], [[[3, 1], [-2, 1]], [[2, 1]]]), ([[-1, -1, 2], [-1, 1]], [[[1, 1], [2, 1]], []])], [([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [2, -1]], [[[3, 1], [1, 1]], [[-7, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, 0, -1], [0, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[-1, 0, -1], [0, 1]], [[[0, 1], [-1, 1]], [[-1, 1]]]), ([[-1, 0, -1], [0, 2]], [[[0, 1], [-1, 2]], [[-1, 1]]]), ([[-1, 0, -1], [1, -1]], [[[1, 1], [1, 1]], [[-2, 1]]])], [([[-1, -1, -1], [0, 1]], [[[-1, 1], [-1, 1]], [[-1, 1]]]), ([[-1, -1, 0], [-1, 1]], [[[-1, 1]], [[-2, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, 0, 0], [1, 2]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, -1]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, 1]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, 2]], [[], [[-1, 1]]])]]
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], [1, 1]], []] | [[[0, 1], [1, 1]], [[-1, 1]]] | Failed |
| explicit oracle 1 | [[[3, 2], [2, 1]], []] | [[[3, 2], [2, 1]], [[-1, 2]]] | Failed |
| explicit oracle 2 | [[[0, 1], [-1, 1]], []] | [[[-2, 1], [-1, 1]], [[-3, 1]]] | Failed |
| explicit oracle 3 | [[[0, 1], [-1, 2]], []] | [[[-3, 4], [-1, 2]], [[-7, 4]]] | Failed |
| explicit oracle 4 | [[[0, 1], [1, 1]], []] | [[[1, 1], [1, 1]], [[-1, 1]]] | Failed |
| explicit oracle 5 | [[[0, 1], [-1, 1]], []] | [[[-1, 1], [-1, 1]], [[-1, 1]]] | Failed |
| explicit oracle 6 | [[[0, 1], [-1, 2]], []] | [[[-1, 2], [-1, 2]], [[-1, 1]]] | Failed |
| explicit oracle 7 | [[[0, 1], [1, 1]], []] | [[[2, 1], [1, 1]], [[-3, 1]]] | Failed |
SHA-256 / 3cd7445108e38a2b976db3e14dcc56c5f0f0e39de0959824e0f48b54ce93416a
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=x
r=list(map(Fraction,A));b=list(map(Fraction,B))
while r and r[-1]==0:r.pop()
q=[Fraction(0)]*max(0,len(r)-len(b)+1)
for _ in range(20):
if len(r)<len(b):break
k=len(r)-len(b)
if k<0 or k>=len(q):return None
c=r[-1]/b[-1]
q[k]=q[k]+c
for j in range(len(b)):
if j+k>=len(r):return None
r[j+k]=r[j+k]-c*b[j]
while r and r[-1]==0:r.pop()
while q and q[-1]==0:q.pop()
return [[[v.numerator,v.denominator] for v in z] for z in (q,r)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, -1], [-1, 1]], [[[-2, 1], [-1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [-1, 2]], [[[-3, 4], [-1, 2]], [[-7, 4]]]), ([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [0, 1]], [[[-1, 1], [-1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [0, 2]], [[[-1, 2], [-1, 2]], [[-1, 1]]]), ([[-1, -1, -1], [1, -1]], [[[2, 1], [1, 1]], [[-3, 1]]])], [([[-1, -1, -1], [-1, 1]], [[[-2, 1], [-1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, 0], [0, 2]], [[[-1, 2]], [[-1, 1]]]), ([[-1, -1, 0], [1, -1]], [[[1, 1]], [[-2, 1]]]), ([[-1, -1, 0], [1, 1]], [[[-1, 1]], []]), ([[-1, -1, 0], [1, 2]], [[[-1, 2]], [[-1, 2]]])], [([[-1, -1, -1], [-1, 2]], [[[-3, 4], [-1, 2]], [[-7, 4]]]), ([[-1, -1, -1], [1, -1]], [[[2, 1], [1, 1]], [[-3, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, -1, 1], [2, 1]], [[[-3, 1], [1, 1]], [[5, 1]]]), ([[-1, -1, 1], [2, 2]], [[[-1, 1], [1, 2]], [[1, 1]]]), ([[-1, -1, 2], [-1, -1]], [[[3, 1], [-2, 1]], [[2, 1]]]), ([[-1, -1, 2], [-1, 1]], [[[1, 1], [2, 1]], []])], [([[-1, -1, -1], [0, -1]], [[[1, 1], [1, 1]], [[-1, 1]]]), ([[-1, -1, -1], [2, -1]], [[[3, 1], [1, 1]], [[-7, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, 0, -1], [0, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[-1, 0, -1], [0, 1]], [[[0, 1], [-1, 1]], [[-1, 1]]]), ([[-1, 0, -1], [0, 2]], [[[0, 1], [-1, 2]], [[-1, 1]]]), ([[-1, 0, -1], [1, -1]], [[[1, 1], [1, 1]], [[-2, 1]]])], [([[-1, -1, -1], [0, 1]], [[[-1, 1], [-1, 1]], [[-1, 1]]]), ([[-1, -1, 0], [-1, 1]], [[[-1, 1]], [[-2, 1]]]), ([[-1, -1, -1], [-1, -1]], [[[0, 1], [1, 1]], [[-1, 1]]]), ([[1, 2, 3, 4], [1, 0, 2]], [[[3, 2], [2, 1]], [[-1, 2]]]), ([[-1, 0, 0], [1, 2]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, -1]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, 1]], [[], [[-1, 1]]]), ([[-1, 0, 0], [2, 2]], [[], [[-1, 1]]])]]
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], [1, 1]], [[-1, 1]]] | [[[0, 1], [1, 1]], [[-1, 1]]] | Passed |
| explicit oracle 1 | [[[3, 2], [2, 1]], [[-1, 2]]] | [[[3, 2], [2, 1]], [[-1, 2]]] | Passed |
| explicit oracle 2 | [[[-2, 1], [-1, 1]], [[-3, 1]]] | [[[-2, 1], [-1, 1]], [[-3, 1]]] | Passed |
| explicit oracle 3 | [[[-3, 4], [-1, 2]], [[-7, 4]]] | [[[-3, 4], [-1, 2]], [[-7, 4]]] | Passed |
| explicit oracle 4 | [[[1, 1], [1, 1]], [[-1, 1]]] | [[[1, 1], [1, 1]], [[-1, 1]]] | Passed |
| explicit oracle 5 | [[[-1, 1], [-1, 1]], [[-1, 1]]] | [[[-1, 1], [-1, 1]], [[-1, 1]]] | Passed |
| explicit oracle 6 | [[[-1, 2], [-1, 2]], [[-1, 1]]] | [[[-1, 2], [-1, 2]], [[-1, 1]]] | Passed |
| explicit oracle 7 | [[[2, 1], [1, 1]], [[-3, 1]]] | [[[2, 1], [1, 1]], [[-3, 1]]] | Passed |
SHA-256 / d42494b9dfa23dae26c332cbf1b447adab42c1bf3458108f1c55703bbe10f864
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:18.577043+00:00.
Case digest / 48157aae0026210b9cf0af212e9328e0a1b6551fc6bbc152adfca006ea92f863