FAILURE MAP
← Case archive

FA-14591 / Numerics / Open access

Polynomial long division: quotient degree displacement · case 01

The exact polynomial long division result violates the stated contract at quotient degree displacement.

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

ROOT CAUSE

The quotient degree displacement step uses len(r)-1 instead of len(r)-len(b).

VERIFIED REPAIR

Use len(r)-len(b) at the quotient degree displacement step.

Unsuccessful approach: The partial repair len(r)-len(b)+1 still violates the quotient degree displacement 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)-1
     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 0None[[[0, 1], [1, 1]], [[-1, 1]]]Failed
explicit oracle 1None[[[3, 2], [2, 1]], [[-1, 2]]]Failed
explicit oracle 2None[[[-2, 1], [-1, 1]], [[-3, 1]]]Failed
explicit oracle 3None[[[-3, 4], [-1, 2]], [[-7, 4]]]Failed
explicit oracle 4None[[[1, 1], [1, 1]], [[-1, 1]]]Failed
explicit oracle 5None[[[-1, 1], [-1, 1]], [[-1, 1]]]Failed
explicit oracle 6None[[[-1, 2], [-1, 2]], [[-1, 1]]]Failed
explicit oracle 7None[[[2, 1], [1, 1]], [[-3, 1]]]Failed

SHA-256 / ddafbd52c27fab33394dbfe722f457872aa4a5714cfc852efa59756455b16271

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

SHA-256 / 3dedc1bdcfca65cbc8a85e26b74bc60ea72b7b6438c8fdb602391731fc45ed20

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

Case digest / a672ec25c2000b80a9ce779e3e40c761e24313837883bee7d50ee358154ab198