FAILURE MAP
← Case archive

FA-14901 / Numerics / Open access

Quadratic surd period: partial quotient computation · case 01

The exact quadratic surd period result violates the stated contract at partial quotient computation.

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

ROOT CAUSE

The partial quotient computation step uses a0+m//d instead of (a0+m)//d.

VERIFIED REPAIR

Use (a0+m)//d at the partial quotient computation step.

Unsuccessful approach: The partial repair (a0-m)//d still violates the partial quotient computation invariant.

Case contract

Input positive nonsquare D; return [floor(sqrt(D)), repeating continued fraction coefficients]. Bounds: 2<=D<=99.

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):
    D=x
    a0=math.isqrt(D);m=0;d=1;a=a0;out=[]
    for _ in range(100):
     m=d*a-m
     top=D-m*m
     if d==0:return None
     d=top//d
     if d==0:return None
     a=a0+m//d
     out.append(a)
     if a==2*a0:break
    return [a0,out]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(6, [2, [2, 4]]), (2, [1, [2]]), (99, [9, [1, 18]]), (3, [1, [1, 2]]), (5, [2, [4]]), (7, [2, [1, 1, 1, 4]]), (8, [2, [1, 4]]), (10, [3, [6]])], [(7, [2, [1, 1, 1, 4]]), (6, [2, [2, 4]]), (2, [1, [2]]), (99, [9, [1, 18]]), (22, [4, [1, 2, 4, 2, 1, 8]]), (23, [4, [1, 3, 1, 8]]), (24, [4, [1, 8]]), (26, [5, [10]])], [(8, [2, [1, 4]]), (10, [3, [6]]), (2, [1, [2]]), (99, [9, [1, 18]]), (41, [6, [2, 2, 12]]), (42, [6, [2, 12]]), (43, [6, [1, 1, 3, 1, 5, 1, 3, 1, 1, 12]]), (44, [6, [1, 1, 1, 2, 1, 1, 1, 12]])], [(11, [3, [3, 6]]), (13, [3, [1, 1, 1, 1, 6]]), (2, [1, [2]]), (99, [9, [1, 18]]), (59, [7, [1, 2, 7, 2, 1, 14]]), (60, [7, [1, 2, 1, 14]]), (61, [7, [1, 4, 3, 1, 2, 2, 1, 3, 4, 1, 14]]), (62, [7, [1, 6, 1, 14]])], [(12, [3, [2, 6]]), (17, [4, [8]]), (2, [1, [2]]), (99, [9, [1, 18]]), (77, [8, [1, 3, 2, 3, 1, 16]]), (78, [8, [1, 4, 1, 16]]), (79, [8, [1, 7, 1, 16]]), (80, [8, [1, 16]])]]
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[2, [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]][2, [2, 4]]Failed
explicit oracle 1[1, [2]][1, [2]]Passed
explicit oracle 2[9, [9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]][9, [1, 18]]Failed
explicit oracle 3[1, [1, 2]][1, [1, 2]]Passed
explicit oracle 4[2, [4]][2, [4]]Passed
explicit oracle 5[2, [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]][2, [1, 1, 1, 4]]Failed
explicit oracle 6[2, [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]][2, [1, 4]]Failed
explicit oracle 7[3, [6]][3, [6]]Passed

SHA-256 / 9e30e3f2f5a1a90382c3c30f323b58b1cf1a93829ca620fed782678102e074a0

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):
    D=x
    a0=math.isqrt(D);m=0;d=1;a=a0;out=[]
    for _ in range(100):
     m=d*a-m
     top=D-m*m
     if d==0:return None
     d=top//d
     if d==0:return None
     a=(a0-m)//d
     out.append(a)
     if a==2*a0:break
    return [a0,out]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(6, [2, [2, 4]]), (2, [1, [2]]), (99, [9, [1, 18]]), (3, [1, [1, 2]]), (5, [2, [4]]), (7, [2, [1, 1, 1, 4]]), (8, [2, [1, 4]]), (10, [3, [6]])], [(7, [2, [1, 1, 1, 4]]), (6, [2, [2, 4]]), (2, [1, [2]]), (99, [9, [1, 18]]), (22, [4, [1, 2, 4, 2, 1, 8]]), (23, [4, [1, 3, 1, 8]]), (24, [4, [1, 8]]), (26, [5, [10]])], [(8, [2, [1, 4]]), (10, [3, [6]]), (2, [1, [2]]), (99, [9, [1, 18]]), (41, [6, [2, 2, 12]]), (42, [6, [2, 12]]), (43, [6, [1, 1, 3, 1, 5, 1, 3, 1, 1, 12]]), (44, [6, [1, 1, 1, 2, 1, 1, 1, 12]])], [(11, [3, [3, 6]]), (13, [3, [1, 1, 1, 1, 6]]), (2, [1, [2]]), (99, [9, [1, 18]]), (59, [7, [1, 2, 7, 2, 1, 14]]), (60, [7, [1, 2, 1, 14]]), (61, [7, [1, 4, 3, 1, 2, 2, 1, 3, 4, 1, 14]]), (62, [7, [1, 6, 1, 14]])], [(12, [3, [2, 6]]), (17, [4, [8]]), (2, [1, [2]]), (99, [9, [1, 18]]), (77, [8, [1, 3, 2, 3, 1, 16]]), (78, [8, [1, 4, 1, 16]]), (79, [8, [1, 7, 1, 16]]), (80, [8, [1, 16]])]]
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[2, [0, 4]][2, [2, 4]]Failed
explicit oracle 1[1, [0, 2]][1, [2]]Failed
explicit oracle 2[9, [0, 18]][9, [1, 18]]Failed
explicit oracle 3[1, [0, 2]][1, [1, 2]]Failed
explicit oracle 4[2, [0, 4]][2, [4]]Failed
explicit oracle 5[2, [0, 4]][2, [1, 1, 1, 4]]Failed
explicit oracle 6[2, [0, 4]][2, [1, 4]]Failed
explicit oracle 7[3, [0, 6]][3, [6]]Failed

SHA-256 / 30b2a745c957a7d57d81eb8465245e3f01af8c40bc540e0e3457c2c2bae08ee9

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):
    D=x
    a0=math.isqrt(D);m=0;d=1;a=a0;out=[]
    for _ in range(100):
     m=d*a-m
     top=D-m*m
     if d==0:return None
     d=top//d
     if d==0:return None
     a=(a0+m)//d
     out.append(a)
     if a==2*a0:break
    return [a0,out]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[(6, [2, [2, 4]]), (2, [1, [2]]), (99, [9, [1, 18]]), (3, [1, [1, 2]]), (5, [2, [4]]), (7, [2, [1, 1, 1, 4]]), (8, [2, [1, 4]]), (10, [3, [6]])], [(7, [2, [1, 1, 1, 4]]), (6, [2, [2, 4]]), (2, [1, [2]]), (99, [9, [1, 18]]), (22, [4, [1, 2, 4, 2, 1, 8]]), (23, [4, [1, 3, 1, 8]]), (24, [4, [1, 8]]), (26, [5, [10]])], [(8, [2, [1, 4]]), (10, [3, [6]]), (2, [1, [2]]), (99, [9, [1, 18]]), (41, [6, [2, 2, 12]]), (42, [6, [2, 12]]), (43, [6, [1, 1, 3, 1, 5, 1, 3, 1, 1, 12]]), (44, [6, [1, 1, 1, 2, 1, 1, 1, 12]])], [(11, [3, [3, 6]]), (13, [3, [1, 1, 1, 1, 6]]), (2, [1, [2]]), (99, [9, [1, 18]]), (59, [7, [1, 2, 7, 2, 1, 14]]), (60, [7, [1, 2, 1, 14]]), (61, [7, [1, 4, 3, 1, 2, 2, 1, 3, 4, 1, 14]]), (62, [7, [1, 6, 1, 14]])], [(12, [3, [2, 6]]), (17, [4, [8]]), (2, [1, [2]]), (99, [9, [1, 18]]), (77, [8, [1, 3, 2, 3, 1, 16]]), (78, [8, [1, 4, 1, 16]]), (79, [8, [1, 7, 1, 16]]), (80, [8, [1, 16]])]]
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[2, [2, 4]][2, [2, 4]]Passed
explicit oracle 1[1, [2]][1, [2]]Passed
explicit oracle 2[9, [1, 18]][9, [1, 18]]Passed
explicit oracle 3[1, [1, 2]][1, [1, 2]]Passed
explicit oracle 4[2, [4]][2, [4]]Passed
explicit oracle 5[2, [1, 1, 1, 4]][2, [1, 1, 1, 4]]Passed
explicit oracle 6[2, [1, 4]][2, [1, 4]]Passed
explicit oracle 7[3, [6]][3, [6]]Passed

SHA-256 / c79d20b7fc92d01265f602ba4ae6483976040eb665968732a36fece7117cb286

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

Case digest / 7a57579673d032497266064de9c38b6c162118f956a8aae5f1f78e2416c3259a