FAILURE MAP
← Case archive

FA-15191 / Numerics / Open access

Dyck word ranking: prefix balance rejection · case 01

The exact dyck word ranking result violates the stated contract at prefix balance rejection.

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

ROOT CAUSE

The prefix balance rejection step uses c>=o or o>n instead of c>o or o>n.

VERIFIED REPAIR

Use c>o or o>n at the prefix balance rejection step.

Unsuccessful approach: The partial repair c>o or o>=n still violates the prefix balance rejection invariant.

Case contract

Input balanced parentheses word with every prefix nonnegative; return zero-based lexicographic rank where opening precedes closing. Bounds: at most five opening parentheses.

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):
    word=x;n=len(word)//2
    from functools import lru_cache
    @lru_cache(None)
    def count(o,c):
     if c>=o or o>n:return 0
     if o==n and c==n:return 1
     return (count(o+1,c) if o<n else 0)+(count(o,c+1) if c<o else 0)
    r=0;o=c=0
    for ch in word:
     if ch==')':
      r+=count(o+1,c)
      c=c+1
     else:o=o+1
    return r
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('()()', 1), ('()', 0), ('()()()()()', 41), ('(())', 0), ('((()))', 0), ('(()())', 1), ('(())()', 2), ('()(())', 3)], [('(()())', 1), ('()(())', 3), ('()', 0), ('()()()()()', 41), ('()((()))', 9), ('()(()())', 10), ('()(())()', 11), ('()()(())', 12)], [('(())()', 2), ('((())())', 2), ('()', 0), ('()()()()()', 41), ('((()))(())', 12), ('((()))()()', 13), ('(()((())))', 14), ('(()(()()))', 15)], [('()(())', 3), ('(()()())', 5), ('()', 0), ('()()()()()', 41), ('()((()()))', 29), ('()((())())', 30), ('()((()))()', 31), ('()(()(()))', 32)], [('()()()', 4), ('(())()()', 8), ('()', 0), ('()()()()()', 41), ('(()())', 1), ('(())()', 2), ('()(())', 3), ('(((())))', 0)]]
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 001Failed
explicit oracle 100Passed
explicit oracle 2041Failed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 501Failed
explicit oracle 602Failed
explicit oracle 703Failed

SHA-256 / e5f075a81f383ce3ef2abbf711f8ecd042f998371411a5b6ae5da48f5b1c72f2

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):
    word=x;n=len(word)//2
    from functools import lru_cache
    @lru_cache(None)
    def count(o,c):
     if c>o or o>=n:return 0
     if o==n and c==n:return 1
     return (count(o+1,c) if o<n else 0)+(count(o,c+1) if c<o else 0)
    r=0;o=c=0
    for ch in word:
     if ch==')':
      r+=count(o+1,c)
      c=c+1
     else:o=o+1
    return r
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('()()', 1), ('()', 0), ('()()()()()', 41), ('(())', 0), ('((()))', 0), ('(()())', 1), ('(())()', 2), ('()(())', 3)], [('(()())', 1), ('()(())', 3), ('()', 0), ('()()()()()', 41), ('()((()))', 9), ('()(()())', 10), ('()(())()', 11), ('()()(())', 12)], [('(())()', 2), ('((())())', 2), ('()', 0), ('()()()()()', 41), ('((()))(())', 12), ('((()))()()', 13), ('(()((())))', 14), ('(()(()()))', 15)], [('()(())', 3), ('(()()())', 5), ('()', 0), ('()()()()()', 41), ('()((()()))', 29), ('()((())())', 30), ('()((()))()', 31), ('()(()(()))', 32)], [('()()()', 4), ('(())()()', 8), ('()', 0), ('()()()()()', 41), ('(()())', 1), ('(())()', 2), ('()(())', 3), ('(((())))', 0)]]
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 001Failed
explicit oracle 100Passed
explicit oracle 2041Failed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 501Failed
explicit oracle 602Failed
explicit oracle 703Failed

SHA-256 / c2139c5c1c0e0ce1fc8ad055db8a4005dad6f29765e2515513d987ffe4c0838d

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):
    word=x;n=len(word)//2
    from functools import lru_cache
    @lru_cache(None)
    def count(o,c):
     if c>o or o>n:return 0
     if o==n and c==n:return 1
     return (count(o+1,c) if o<n else 0)+(count(o,c+1) if c<o else 0)
    r=0;o=c=0
    for ch in word:
     if ch==')':
      r+=count(o+1,c)
      c=c+1
     else:o=o+1
    return r
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('()()', 1), ('()', 0), ('()()()()()', 41), ('(())', 0), ('((()))', 0), ('(()())', 1), ('(())()', 2), ('()(())', 3)], [('(()())', 1), ('()(())', 3), ('()', 0), ('()()()()()', 41), ('()((()))', 9), ('()(()())', 10), ('()(())()', 11), ('()()(())', 12)], [('(())()', 2), ('((())())', 2), ('()', 0), ('()()()()()', 41), ('((()))(())', 12), ('((()))()()', 13), ('(()((())))', 14), ('(()(()()))', 15)], [('()(())', 3), ('(()()())', 5), ('()', 0), ('()()()()()', 41), ('()((()()))', 29), ('()((())())', 30), ('()((()))()', 31), ('()(()(()))', 32)], [('()()()', 4), ('(())()()', 8), ('()', 0), ('()()()()()', 41), ('(()())', 1), ('(())()', 2), ('()(())', 3), ('(((())))', 0)]]
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 011Passed
explicit oracle 100Passed
explicit oracle 24141Passed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 511Passed
explicit oracle 622Passed
explicit oracle 733Passed

SHA-256 / 39a8643e54f8efd5d7fd0c667ef38a59508d6aa2f25f76dfae6e148faca012bf

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

Case digest / 6da053743b6ddb2eb01095f56a547d8ca52bd7d15d8b4f7751a895eb15ff4f44