FAILURE MAP
← Case archive

FA-14516 / Numerics / Open access

Stern brocot path: root termination · case 01

The exact stern brocot path result violates the stated contract at root termination.

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

ROOT CAUSE

The root termination step uses p==1 or q==1 instead of p==q.

VERIFIED REPAIR

Use p==q at the root termination step.

Unsuccessful approach: The partial repair p==1 and q==1 and len(out)>0 still violates the root termination invariant.

Case contract

Input reduced positive [p,q]; return run-expanded L/R path from 1/1. Bounds: 1<=p,q<=24.

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):
    p,q=x
    out=[]
    for _ in range(100):
     if p==1 or q==1: break
     if p<q:
      out.append('L')
      q=q-p
     else:
      out.append('R')
      p=p-q
    return ''.join(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 2], 'L'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([1, 3], 'LL'), ([1, 4], 'LLL'), ([1, 5], 'LLLL'), ([1, 6], 'LLLLL'), ([1, 7], 'LLLLLL')], [([1, 3], 'LL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([1, 18], 'LLLLLLLLLLLLLLLLL'), ([1, 19], 'LLLLLLLLLLLLLLLLLL'), ([1, 20], 'LLLLLLLLLLLLLLLLLLL'), ([1, 21], 'LLLLLLLLLLLLLLLLLLLL'), ([1, 22], 'LLLLLLLLLLLLLLLLLLLLL')], [([1, 4], 'LLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([2, 21], 'LLLLLLLLLLR'), ([2, 23], 'LLLLLLLLLLLR'), ([3, 1], 'RR'), ([3, 2], 'RL'), ([3, 4], 'LRR')], [([1, 5], 'LLLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([3, 23], 'LLLLLLLRL'), ([4, 1], 'RRR'), ([4, 3], 'RLL'), ([4, 5], 'LRRR'), ([4, 7], 'LRLL')], [([1, 6], 'LLLLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([5, 6], 'LRRRR'), ([5, 7], 'LRRL'), ([5, 8], 'LRLR'), ([5, 9], 'LRLLL'), ([5, 11], 'LLRRRR')]]
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 0LFailed
explicit oracle 1Passed
explicit oracle 2RRLLLLLLLLLLLLLLLLLLLLLLFailed
explicit oracle 3LLFailed
explicit oracle 4LLLFailed
explicit oracle 5LLLLFailed
explicit oracle 6LLLLLFailed
explicit oracle 7LLLLLLFailed

SHA-256 / 33a82428f8e39e0ab85eb56fd7d22ff381cd7bd2da8d628c8ea655473f19d3b5

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):
    p,q=x
    out=[]
    for _ in range(100):
     if p==1 and q==1 and len(out)>0: break
     if p<q:
      out.append('L')
      q=q-p
     else:
      out.append('R')
      p=p-q
    return ''.join(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 2], 'L'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([1, 3], 'LL'), ([1, 4], 'LLL'), ([1, 5], 'LLLL'), ([1, 6], 'LLLLL'), ([1, 7], 'LLLLLL')], [([1, 3], 'LL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([1, 18], 'LLLLLLLLLLLLLLLLL'), ([1, 19], 'LLLLLLLLLLLLLLLLLL'), ([1, 20], 'LLLLLLLLLLLLLLLLLLL'), ([1, 21], 'LLLLLLLLLLLLLLLLLLLL'), ([1, 22], 'LLLLLLLLLLLLLLLLLLLLL')], [([1, 4], 'LLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([2, 21], 'LLLLLLLLLLR'), ([2, 23], 'LLLLLLLLLLLR'), ([3, 1], 'RR'), ([3, 2], 'RL'), ([3, 4], 'LRR')], [([1, 5], 'LLLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([3, 23], 'LLLLLLLRL'), ([4, 1], 'RRR'), ([4, 3], 'RLL'), ([4, 5], 'LRRR'), ([4, 7], 'LRLL')], [([1, 6], 'LLLLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([5, 6], 'LRRRR'), ([5, 7], 'LRRL'), ([5, 8], 'LRLR'), ([5, 9], 'LRLLL'), ([5, 11], 'LLRRRR')]]
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 0LLPassed
explicit oracle 1RLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLFailed
explicit oracle 2RLLLLLLLLLLLLLLLLLLLLLLRLLLLLLLLLLLLLLLLLLLLLLPassed
explicit oracle 3LLLLPassed
explicit oracle 4LLLLLLPassed
explicit oracle 5LLLLLLLLPassed
explicit oracle 6LLLLLLLLLLPassed
explicit oracle 7LLLLLLLLLLLLPassed

SHA-256 / 1de9c9b036216d357e3f50d701e3b4ae1d7273d72e8ed77aa04f66b0d52a0113

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):
    p,q=x
    out=[]
    for _ in range(100):
     if p==q: break
     if p<q:
      out.append('L')
      q=q-p
     else:
      out.append('R')
      p=p-q
    return ''.join(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([1, 2], 'L'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([1, 3], 'LL'), ([1, 4], 'LLL'), ([1, 5], 'LLLL'), ([1, 6], 'LLLLL'), ([1, 7], 'LLLLLL')], [([1, 3], 'LL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([1, 18], 'LLLLLLLLLLLLLLLLL'), ([1, 19], 'LLLLLLLLLLLLLLLLLL'), ([1, 20], 'LLLLLLLLLLLLLLLLLLL'), ([1, 21], 'LLLLLLLLLLLLLLLLLLLL'), ([1, 22], 'LLLLLLLLLLLLLLLLLLLLL')], [([1, 4], 'LLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([2, 21], 'LLLLLLLLLLR'), ([2, 23], 'LLLLLLLLLLLR'), ([3, 1], 'RR'), ([3, 2], 'RL'), ([3, 4], 'LRR')], [([1, 5], 'LLLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([3, 23], 'LLLLLLLRL'), ([4, 1], 'RRR'), ([4, 3], 'RLL'), ([4, 5], 'LRRR'), ([4, 7], 'LRLL')], [([1, 6], 'LLLLL'), ([1, 1], ''), ([24, 23], 'RLLLLLLLLLLLLLLLLLLLLLL'), ([5, 6], 'LRRRR'), ([5, 7], 'LRRL'), ([5, 8], 'LRLR'), ([5, 9], 'LRLLL'), ([5, 11], 'LLRRRR')]]
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 0LLPassed
explicit oracle 1Passed
explicit oracle 2RLLLLLLLLLLLLLLLLLLLLLLRLLLLLLLLLLLLLLLLLLLLLLPassed
explicit oracle 3LLLLPassed
explicit oracle 4LLLLLLPassed
explicit oracle 5LLLLLLLLPassed
explicit oracle 6LLLLLLLLLLPassed
explicit oracle 7LLLLLLLLLLLLPassed

SHA-256 / 84bb3c89ea808859befa9e960bb49c6622392d1f3e5c5789d095bcf13241caa6

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

Case digest / f2a2fe32b7d8a1399d715708811e8b064afe7cf022ebcbe252ad2262649c5bff