FAILURE MAP
← Case archive

FA-14891 / Numerics / Open access

Quadratic surd period: surd numerator recurrence · case 01

The exact quadratic surd period result violates the stated contract at surd numerator recurrence.

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

ROOT CAUSE

The surd numerator recurrence step uses d*a+m instead of d*a-m.

VERIFIED REPAIR

Use d*a-m at the surd numerator recurrence step.

Unsuccessful approach: The partial repair a-m still violates the surd numerator recurrence 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 = [[(3, [1, [1, 2]]), (2, [1, [2]]), (99, [9, [1, 18]]), (5, [2, [4]]), (6, [2, [2, 4]]), (7, [2, [1, 1, 1, 4]]), (8, [2, [1, 4]]), (10, [3, [6]])], [(6, [2, [2, 4]]), (8, [2, [1, 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]])], [(7, [2, [1, 1, 1, 4]]), (13, [3, [1, 1, 1, 1, 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]])], [(8, [2, [1, 4]]), (18, [4, [4, 8]]), (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]])], [(11, [3, [3, 6]]), (21, [4, [1, 1, 2, 1, 1, 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[1, [1, -2, 0, -4, 0, -8, 0, -16, 0, -32, 0, -64, 0, -128, 0, -256, 0, -512, 0, -1024, 0, -2048, 0, -4096, 0, -8192, 0, -16384, 0, -32768, 0, -65536, 0, -131072, 0, -262144, 0, -524288, 0, -1048576, 0, -2097152, 0, -4194304, 0, -8388608, 0, -16777216, 0, -33554432, 0, -67108864, 0, -134217728, 0, -268435456, 0, -536870912, 0, -1073741824, 0, -2147483648, 0, -4294967296, 0, -8589934592, 0, -17179869184, 0, -34359738368, 0, -68719476736, 0, -137438953472, 0, -274877906944, 0, -549755813888, 0, -1099511627776, 0, -2199023255552, 0, -4398046511104, 0, -8796093022208, 0, -17592186044416, 0, -35184372088832, 0, -70368744177664, 0, -140737488355328, 0, -281474976710656, 0, -562949953421312, 0, -1125899906842624]][1, [1, 2]]Failed
explicit oracle 1[1, [2]][1, [2]]Passed
explicit oracle 2[9, [1, -2, 0, -4, 0, -8, 0, -16, 0, -32, 0, -64, 0, -128, 0, -256, 0, -512, 0, -1024, 0, -2048, 0, -4096, 0, -8192, 0, -16384, 0, -32768, 0, -65536, 0, -131072, 0, -262144, 0, -524288, 0, -1048576, 0, -2097152, 0, -4194304, 0, -8388608, 0, -16777216, 0, -33554432, 0, -67108864, 0, -134217728, 0, -268435456, 0, -536870912, 0, -1073741824, 0, -2147483648, 0, -4294967296, 0, -8589934592, 0, -17179869184, 0, -34359738368, 0, -68719476736, 0, -137438953472, 0, -274877906944, 0, -549755813888, 0, -1099511627776, 0, -2199023255552, 0, -4398046511104, 0, -8796093022208, 0, -17592186044416, 0, -35184372088832, 0, -70368744177664, 0, -140737488355328, 0, -281474976710656, 0, -562949953421312, 0, -1125899906842624]][9, [1, 18]]Failed
explicit oracle 3[2, [4]][2, [4]]Passed
explicit oracle 4[2, [2, -1, 0, -2, 0, -4, 0, -8, 0, -16, 0, -32, 0, -64, 0, -128, 0, -256, 0, -512, 0, -1024, 0, -2048, 0, -4096, 0, -8192, 0, -16384, 0, -32768, 0, -65536, 0, -131072, 0, -262144, 0, -524288, 0, -1048576, 0, -2097152, 0, -4194304, 0, -8388608, 0, -16777216, 0, -33554432, 0, -67108864, 0, -134217728, 0, -268435456, 0, -536870912, 0, -1073741824, 0, -2147483648, 0, -4294967296, 0, -8589934592, 0, -17179869184, 0, -34359738368, 0, -68719476736, 0, -137438953472, 0, -274877906944, 0, -549755813888, 0, -1099511627776, 0, -2199023255552, 0, -4398046511104, 0, -8796093022208, 0, -17592186044416, 0, -35184372088832, 0, -70368744177664, 0, -140737488355328, 0, -281474976710656, 0, -562949953421312]][2, [2, 4]]Failed
explicit oracle 5[2, [1, -2, 0, -4, 0, -8, 0, -16, 0, -32, 0, -64, 0, -128, 0, -256, 0, -512, 0, -1024, 0, -2048, 0, -4096, 0, -8192, 0, -16384, 0, -32768, 0, -65536, 0, -131072, 0, -262144, 0, -524288, 0, -1048576, 0, -2097152, 0, -4194304, 0, -8388608, 0, -16777216, 0, -33554432, 0, -67108864, 0, -134217728, 0, -268435456, 0, -536870912, 0, -1073741824, 0, -2147483648, 0, -4294967296, 0, -8589934592, 0, -17179869184, 0, -34359738368, 0, -68719476736, 0, -137438953472, 0, -274877906944, 0, -549755813888, 0, -1099511627776, 0, -2199023255552, 0, -4398046511104, 0, -8796093022208, 0, -17592186044416, 0, -35184372088832, 0, -70368744177664, 0, -140737488355328, 0, -281474976710656, 0, -562949953421312, 0, -1125899906842624]][2, [1, 1, 1, 4]]Failed
explicit oracle 6[2, [1, -2, 0, -4, 0, -8, 0, -16, 0, -32, 0, -64, 0, -128, 0, -256, 0, -512, 0, -1024, 0, -2048, 0, -4096, 0, -8192, 0, -16384, 0, -32768, 0, -65536, 0, -131072, 0, -262144, 0, -524288, 0, -1048576, 0, -2097152, 0, -4194304, 0, -8388608, 0, -16777216, 0, -33554432, 0, -67108864, 0, -134217728, 0, -268435456, 0, -536870912, 0, -1073741824, 0, -2147483648, 0, -4294967296, 0, -8589934592, 0, -17179869184, 0, -34359738368, 0, -68719476736, 0, -137438953472, 0, -274877906944, 0, -549755813888, 0, -1099511627776, 0, -2199023255552, 0, -4398046511104, 0, -8796093022208, 0, -17592186044416, 0, -35184372088832, 0, -70368744177664, 0, -140737488355328, 0, -281474976710656, 0, -562949953421312, 0, -1125899906842624]][2, [1, 4]]Failed
explicit oracle 7[3, [6]][3, [6]]Passed

SHA-256 / 7e8b8f88b4c42e1b72fde88369cceb94b35fd2490e4df84d9dde7fa26f15f425

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=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 = [[(3, [1, [1, 2]]), (2, [1, [2]]), (99, [9, [1, 18]]), (5, [2, [4]]), (6, [2, [2, 4]]), (7, [2, [1, 1, 1, 4]]), (8, [2, [1, 4]]), (10, [3, [6]])], [(6, [2, [2, 4]]), (8, [2, [1, 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]])], [(7, [2, [1, 1, 1, 4]]), (13, [3, [1, 1, 1, 1, 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]])], [(8, [2, [1, 4]]), (18, [4, [4, 8]]), (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]])], [(11, [3, [3, 6]]), (21, [4, [1, 1, 2, 1, 1, 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[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, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]][2, [1, 1, 1, 4]]Failed
explicit oracle 6[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, 1]][2, [1, 4]]Failed
explicit oracle 7[3, [6]][3, [6]]Passed

SHA-256 / 88c69c9f74b1af25da49ae1430b1e7e6da9f62f99076dbae1b11d22ca44a9a79

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 = [[(3, [1, [1, 2]]), (2, [1, [2]]), (99, [9, [1, 18]]), (5, [2, [4]]), (6, [2, [2, 4]]), (7, [2, [1, 1, 1, 4]]), (8, [2, [1, 4]]), (10, [3, [6]])], [(6, [2, [2, 4]]), (8, [2, [1, 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]])], [(7, [2, [1, 1, 1, 4]]), (13, [3, [1, 1, 1, 1, 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]])], [(8, [2, [1, 4]]), (18, [4, [4, 8]]), (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]])], [(11, [3, [3, 6]]), (21, [4, [1, 1, 2, 1, 1, 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[1, [1, 2]][1, [1, 2]]Passed
explicit oracle 1[1, [2]][1, [2]]Passed
explicit oracle 2[9, [1, 18]][9, [1, 18]]Passed
explicit oracle 3[2, [4]][2, [4]]Passed
explicit oracle 4[2, [2, 4]][2, [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 / 7deef2cc4daa1f15f12c31c2a77f7605d4ce5d2d9312327f2b6457aff8384cec

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

Case digest / c02525e7497feb9ce883919c9ebc2ceb47d35956b7ad139126d649871a7228a1