FAILURE MAP
← Case archive

FA-15211 / Numerics / Open access

Dyck word ranking: balanced word rank origin · case 01

The exact dyck word ranking result violates the stated contract at balanced word rank origin.

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

ROOT CAUSE

The balanced word rank origin step uses r+1 instead of r.

VERIFIED REPAIR

Use r at the balanced word rank origin step.

Unsuccessful approach: The partial repair max(0,r-1) still violates the balanced word rank origin 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+1
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('()', 0), ('()()', 1), ('()()()()()', 41), ('(())', 0), ('((()))', 0), ('(()())', 1), ('(())()', 2), ('()(())', 3)], [('(())', 0), ('()(())', 3), ('()', 0), ('()()()()()', 41), ('()((()))', 9), ('()(()())', 10), ('()(())()', 11), ('()()(())', 12)], [('()()', 1), ('((())())', 2), ('()', 0), ('()()()()()', 41), ('((()))(())', 12), ('((()))()()', 13), ('(()((())))', 14), ('(()(()()))', 15)], [('((()))', 0), ('(()()())', 5), ('()', 0), ('()()()()()', 41), ('()((()()))', 29), ('()((())())', 30), ('()((()))()', 31), ('()(()(()))', 32)], [('(()())', 1), ('(())()()', 8), ('()', 0), ('()()()()()', 41), ('(())()', 2), ('()(())', 3), ('()()()', 4), ('(((())))', 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 010Failed
explicit oracle 121Failed
explicit oracle 24241Failed
explicit oracle 310Failed
explicit oracle 410Failed
explicit oracle 521Failed
explicit oracle 632Failed
explicit oracle 743Failed

SHA-256 / 334760c7068180ddff82effa752d73e7356c410ae0c852b2dcaa79d48758b983

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 max(0,r-1)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('()', 0), ('()()', 1), ('()()()()()', 41), ('(())', 0), ('((()))', 0), ('(()())', 1), ('(())()', 2), ('()(())', 3)], [('(())', 0), ('()(())', 3), ('()', 0), ('()()()()()', 41), ('()((()))', 9), ('()(()())', 10), ('()(())()', 11), ('()()(())', 12)], [('()()', 1), ('((())())', 2), ('()', 0), ('()()()()()', 41), ('((()))(())', 12), ('((()))()()', 13), ('(()((())))', 14), ('(()(()()))', 15)], [('((()))', 0), ('(()()())', 5), ('()', 0), ('()()()()()', 41), ('()((()()))', 29), ('()((())())', 30), ('()((()))()', 31), ('()(()(()))', 32)], [('(()())', 1), ('(())()()', 8), ('()', 0), ('()()()()()', 41), ('(())()', 2), ('()(())', 3), ('()()()', 4), ('(((())))', 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 000Passed
explicit oracle 101Failed
explicit oracle 24041Failed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 501Failed
explicit oracle 612Failed
explicit oracle 723Failed

SHA-256 / 9765a95814dc78028a1728bb538550543c29316306312e90778bc1053597e1b3

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 = [[('()', 0), ('()()', 1), ('()()()()()', 41), ('(())', 0), ('((()))', 0), ('(()())', 1), ('(())()', 2), ('()(())', 3)], [('(())', 0), ('()(())', 3), ('()', 0), ('()()()()()', 41), ('()((()))', 9), ('()(()())', 10), ('()(())()', 11), ('()()(())', 12)], [('()()', 1), ('((())())', 2), ('()', 0), ('()()()()()', 41), ('((()))(())', 12), ('((()))()()', 13), ('(()((())))', 14), ('(()(()()))', 15)], [('((()))', 0), ('(()()())', 5), ('()', 0), ('()()()()()', 41), ('()((()()))', 29), ('()((())())', 30), ('()((()))()', 31), ('()(()(()))', 32)], [('(()())', 1), ('(())()()', 8), ('()', 0), ('()()()()()', 41), ('(())()', 2), ('()(())', 3), ('()()()', 4), ('(((())))', 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 000Passed
explicit oracle 111Passed
explicit oracle 24141Passed
explicit oracle 300Passed
explicit oracle 400Passed
explicit oracle 511Passed
explicit oracle 622Passed
explicit oracle 733Passed

SHA-256 / 185802b867dfbba9c97333fab66e51024c8382d09b8395f555dc090d4c71ef66

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

Case digest / e602a064848e3ba10616974aef7d42ab894ebb3a20f450b536e92b8deb71730c