FAILURE MAP
← Case archive

FA-14601 / Numerics / Open access

Polynomial long division: quotient coefficient placement · case 01

The exact polynomial long division result violates the stated contract at quotient coefficient placement.

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

ROOT CAUSE

The quotient coefficient placement step uses c if k==0 else q[k] instead of q[k]+c.

VERIFIED REPAIR

Use q[k]+c at the quotient coefficient placement step.

Unsuccessful approach: The partial repair q[k]-c still violates the quotient coefficient placement 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]=c if k==0 else q[k]
     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]], []]), ([[-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 fixtureActualExpectedOutcome
explicit oracle 0[[], [[-1, 1]]][[[0, 1], [1, 1]], [[-1, 1]]]Failed
explicit oracle 1[[[3, 2]], [[-1, 2]]][[[3, 2], [2, 1]], [[-1, 2]]]Failed
explicit oracle 2[[[-2, 1]], [[-3, 1]]][[[-2, 1], [-1, 1]], [[-3, 1]]]Failed
explicit oracle 3[[[-3, 4]], [[-7, 4]]][[[-3, 4], [-1, 2]], [[-7, 4]]]Failed
explicit oracle 4[[[1, 1]], [[-1, 1]]][[[1, 1], [1, 1]], [[-1, 1]]]Failed
explicit oracle 5[[[-1, 1]], [[-1, 1]]][[[-1, 1], [-1, 1]], [[-1, 1]]]Failed
explicit oracle 6[[[-1, 2]], [[-1, 1]]][[[-1, 2], [-1, 2]], [[-1, 1]]]Failed
explicit oracle 7[[[2, 1]], [[-3, 1]]][[[2, 1], [1, 1]], [[-3, 1]]]Failed

SHA-256 / 45e5c934ed01391a0238d4244a0f9557bff811d84aa10dc7140e388163fae541

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]], []]), ([[-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 fixtureActualExpectedOutcome
explicit oracle 0[[[0, 1], [-1, 1]], [[-1, 1]]][[[0, 1], [1, 1]], [[-1, 1]]]Failed
explicit oracle 1[[[-3, 2], [-2, 1]], [[-1, 2]]][[[3, 2], [2, 1]], [[-1, 2]]]Failed
explicit oracle 2[[[2, 1], [1, 1]], [[-3, 1]]][[[-2, 1], [-1, 1]], [[-3, 1]]]Failed
explicit oracle 3[[[3, 4], [1, 2]], [[-7, 4]]][[[-3, 4], [-1, 2]], [[-7, 4]]]Failed
explicit oracle 4[[[-1, 1], [-1, 1]], [[-1, 1]]][[[1, 1], [1, 1]], [[-1, 1]]]Failed
explicit oracle 5[[[1, 1], [1, 1]], [[-1, 1]]][[[-1, 1], [-1, 1]], [[-1, 1]]]Failed
explicit oracle 6[[[1, 2], [1, 2]], [[-1, 1]]][[[-1, 2], [-1, 2]], [[-1, 1]]]Failed
explicit oracle 7[[[-2, 1], [-1, 1]], [[-3, 1]]][[[2, 1], [1, 1]], [[-3, 1]]]Failed

SHA-256 / 0b4c842d74615ca47e55aa1d3a0c7f6a00f1d28fd6ac7cd511a22f874bd734ec

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]], []]), ([[-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 fixtureActualExpectedOutcome
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 / a771bfa07a4c59402ec90b2cd5e089f64e04b669f1dab09a2e83ad29afb6f5c1

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

Case digest / 186b5f16e18dcd43793e7c0a9f0cd32b66673c678b5e0aa58d393bd7fe7802c3