FA-80481 / Bidirectional text layout / Open access
Visual reordering by levels: pass step · case 01
Levels of one parity are never reversed as their own pass.
ROOT CAUSE
The level loop steps by two, visiting only levels of the top parity.
VERIFIED REPAIR
Visit every level from the highest down to the lowest odd level.
Unsuccessful approach: Extending the loop one level below the lowest odd level reverses whole lines.
Case contract
Input resolved levels of one line. From the highest level down to the lowest odd level on the line, reverse every maximal visual run of characters at that level or higher. Return logical indices in visual order (identity when no odd level).
Why this case matters
Mixed right-to-left and left-to-right text must resolve levels and visual order exactly, or words, numbers and carets land in the wrong place.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
levels = x
order = list(range(len(levels)))
odd = [l for l in levels if l % 2 == 1]
if not odd:
return order
hi = max(levels)
lo = min(odd)
vis = [[lv, i] for i, lv in enumerate(levels)]
for lev in range(hi, lo - 1, -2):
i = 0
while i < len(vis):
if vis[i][0] >= lev:
j = i
while j < len(vis) and vis[j][0] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return [p[1] for p in vis]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: pass step', [1, 1, 1, 1, 1, 4, 4, 4, 3, 3, 3, 3], [11, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 0]), ('partial-repair probe', [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 2, 3, 4, 5, 6, 7, 9, 8]), ('partial-repair probe', [3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0], [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [0, 0, 0, 0], [0, 1, 2, 3]), ('control layout', [0], [0])], [('regression: pass step', [1, 1, 1, 4], [3, 2, 1, 0]), ('regression: pass step', [3, 3, 3, 0, 3, 3, 0, 0, 0, 1], [2, 1, 0, 3, 5, 4, 6, 7, 8, 9]), ('regression: pass step', [2, 3, 1], [2, 0, 1]), ('partial-repair probe', [0, 0, 0, 1, 1], [0, 1, 2, 4, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7]), ('control layout', [4, 4, 4, 4, 4], [0, 1, 2, 3, 4])], [('regression: pass step', [4, 1, 3, 3, 3, 1, 2, 2, 2, 2, 2, 1], [11, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1, 0]), ('regression: pass step', [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2], [9, 10, 8, 7, 6, 3, 4, 5, 2, 1, 0]), ('regression: pass step', [2, 2, 1, 2], [3, 2, 0, 1]), ('partial-repair probe', [2, 2, 2, 3, 3], [0, 1, 2, 4, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4]), ('control layout', [0, 0, 3], [0, 1, 2])], [('regression: pass step', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('regression: pass step', [3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 1], [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10]), ('regression: pass step', [1, 2, 2, 4, 4, 2], [1, 2, 3, 4, 5, 0]), ('regression: pass step', [2, 2, 3, 3, 3, 0, 0, 0, 0, 1, 1], [0, 1, 4, 3, 2, 5, 6, 7, 8, 10, 9]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0], [0, 1, 2]), ('control layout', [0], [0])], [('regression: pass step', [0, 0, 1, 1, 1, 2], [0, 1, 5, 4, 3, 2]), ('regression: pass step', [0, 0, 0, 1, 1, 1, 1, 1, 3, 3, 2], [0, 1, 2, 9, 8, 10, 7, 6, 5, 4, 3]), ('regression: pass step', [1, 2, 3, 3], [1, 3, 2, 0]), ('regression: pass step', [1, 1, 1, 3, 3, 3, 1, 1, 2, 2, 2], [8, 9, 10, 7, 6, 5, 4, 3, 2, 1, 0]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [2, 2, 2, 4], [0, 1, 2, 3]), ('control layout', [0, 0, 3], [0, 1, 2])]]
for label, args, expected in fixtures[N - 1]:
check(label, 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| number inside RTL | [0, 1, 3, 2, 4] | [4, 2, 3, 1, 0] | Failed |
| regression: pass step | [0, 1, 2, 3, 4, 11, 10, 9, 8, 5, 6, 7] | [11, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 0] | Failed |
| partial-repair probe | [0, 1, 2, 3, 4, 5, 6, 7, 9, 8] | [0, 1, 2, 3, 4, 5, 6, 7, 9, 8] | Passed |
| partial-repair probe | [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10] | [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10] | Passed |
| all even levels | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| lowest odd is three | [0, 2, 1, 3] | [0, 2, 1, 3] | Passed |
| control layout | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / d41b47b35b710f120e2edb4b56a675ab97e777f3c4e84726e6ebf8535682fec1
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
levels = x
order = list(range(len(levels)))
odd = [l for l in levels if l % 2 == 1]
if not odd:
return order
hi = max(levels)
lo = min(odd)
vis = [[lv, i] for i, lv in enumerate(levels)]
for lev in range(hi, lo - 2, -1):
i = 0
while i < len(vis):
if vis[i][0] >= lev:
j = i
while j < len(vis) and vis[j][0] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return [p[1] for p in vis]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: pass step', [1, 1, 1, 1, 1, 4, 4, 4, 3, 3, 3, 3], [11, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 0]), ('partial-repair probe', [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 2, 3, 4, 5, 6, 7, 9, 8]), ('partial-repair probe', [3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0], [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [0, 0, 0, 0], [0, 1, 2, 3]), ('control layout', [0], [0])], [('regression: pass step', [1, 1, 1, 4], [3, 2, 1, 0]), ('regression: pass step', [3, 3, 3, 0, 3, 3, 0, 0, 0, 1], [2, 1, 0, 3, 5, 4, 6, 7, 8, 9]), ('regression: pass step', [2, 3, 1], [2, 0, 1]), ('partial-repair probe', [0, 0, 0, 1, 1], [0, 1, 2, 4, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7]), ('control layout', [4, 4, 4, 4, 4], [0, 1, 2, 3, 4])], [('regression: pass step', [4, 1, 3, 3, 3, 1, 2, 2, 2, 2, 2, 1], [11, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1, 0]), ('regression: pass step', [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2], [9, 10, 8, 7, 6, 3, 4, 5, 2, 1, 0]), ('regression: pass step', [2, 2, 1, 2], [3, 2, 0, 1]), ('partial-repair probe', [2, 2, 2, 3, 3], [0, 1, 2, 4, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4]), ('control layout', [0, 0, 3], [0, 1, 2])], [('regression: pass step', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('regression: pass step', [3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 1], [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10]), ('regression: pass step', [1, 2, 2, 4, 4, 2], [1, 2, 3, 4, 5, 0]), ('regression: pass step', [2, 2, 3, 3, 3, 0, 0, 0, 0, 1, 1], [0, 1, 4, 3, 2, 5, 6, 7, 8, 10, 9]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0], [0, 1, 2]), ('control layout', [0], [0])], [('regression: pass step', [0, 0, 1, 1, 1, 2], [0, 1, 5, 4, 3, 2]), ('regression: pass step', [0, 0, 0, 1, 1, 1, 1, 1, 3, 3, 2], [0, 1, 2, 9, 8, 10, 7, 6, 5, 4, 3]), ('regression: pass step', [1, 2, 3, 3], [1, 3, 2, 0]), ('regression: pass step', [1, 1, 1, 3, 3, 3, 1, 1, 2, 2, 2], [8, 9, 10, 7, 6, 5, 4, 3, 2, 1, 0]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [2, 2, 2, 4], [0, 1, 2, 3]), ('control layout', [0, 0, 3], [0, 1, 2])]]
for label, args, expected in fixtures[N - 1]:
check(label, 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| number inside RTL | [0, 1, 3, 2, 4] | [4, 2, 3, 1, 0] | Failed |
| regression: pass step | [0, 1, 2, 3, 4, 7, 6, 5, 8, 9, 10, 11] | [11, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 0] | Failed |
| partial-repair probe | [8, 9, 7, 6, 5, 4, 3, 2, 1, 0] | [0, 1, 2, 3, 4, 5, 6, 7, 9, 8] | Failed |
| partial-repair probe | [7, 6, 5, 4, 0, 1, 2, 3, 8, 9, 10] | [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10] | Failed |
| all even levels | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| lowest odd is three | [3, 1, 2, 0] | [0, 2, 1, 3] | Failed |
| control layout | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / 8aed712c9de4439d8daf9998f7534bf9479759d8e8da83887c412287c83db32b
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
levels = x
order = list(range(len(levels)))
odd = [l for l in levels if l % 2 == 1]
if not odd:
return order
hi = max(levels)
lo = min(odd)
vis = [[lv, i] for i, lv in enumerate(levels)]
for lev in range(hi, lo - 1, -1):
i = 0
while i < len(vis):
if vis[i][0] >= lev:
j = i
while j < len(vis) and vis[j][0] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return [p[1] for p in vis]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: pass step', [1, 1, 1, 1, 1, 4, 4, 4, 3, 3, 3, 3], [11, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 0]), ('partial-repair probe', [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 2, 3, 4, 5, 6, 7, 9, 8]), ('partial-repair probe', [3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0], [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [0, 0, 0, 0], [0, 1, 2, 3]), ('control layout', [0], [0])], [('regression: pass step', [1, 1, 1, 4], [3, 2, 1, 0]), ('regression: pass step', [3, 3, 3, 0, 3, 3, 0, 0, 0, 1], [2, 1, 0, 3, 5, 4, 6, 7, 8, 9]), ('regression: pass step', [2, 3, 1], [2, 0, 1]), ('partial-repair probe', [0, 0, 0, 1, 1], [0, 1, 2, 4, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7]), ('control layout', [4, 4, 4, 4, 4], [0, 1, 2, 3, 4])], [('regression: pass step', [4, 1, 3, 3, 3, 1, 2, 2, 2, 2, 2, 1], [11, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1, 0]), ('regression: pass step', [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2], [9, 10, 8, 7, 6, 3, 4, 5, 2, 1, 0]), ('regression: pass step', [2, 2, 1, 2], [3, 2, 0, 1]), ('partial-repair probe', [2, 2, 2, 3, 3], [0, 1, 2, 4, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4]), ('control layout', [0, 0, 3], [0, 1, 2])], [('regression: pass step', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('regression: pass step', [3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 1], [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10]), ('regression: pass step', [1, 2, 2, 4, 4, 2], [1, 2, 3, 4, 5, 0]), ('regression: pass step', [2, 2, 3, 3, 3, 0, 0, 0, 0, 1, 1], [0, 1, 4, 3, 2, 5, 6, 7, 8, 10, 9]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0], [0, 1, 2]), ('control layout', [0], [0])], [('regression: pass step', [0, 0, 1, 1, 1, 2], [0, 1, 5, 4, 3, 2]), ('regression: pass step', [0, 0, 0, 1, 1, 1, 1, 1, 3, 3, 2], [0, 1, 2, 9, 8, 10, 7, 6, 5, 4, 3]), ('regression: pass step', [1, 2, 3, 3], [1, 3, 2, 0]), ('regression: pass step', [1, 1, 1, 3, 3, 3, 1, 1, 2, 2, 2], [8, 9, 10, 7, 6, 5, 4, 3, 2, 1, 0]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [2, 2, 2, 4], [0, 1, 2, 3]), ('control layout', [0, 0, 3], [0, 1, 2])]]
for label, args, expected in fixtures[N - 1]:
check(label, 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| number inside RTL | [4, 2, 3, 1, 0] | [4, 2, 3, 1, 0] | Passed |
| regression: pass step | [11, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 0] | [11, 10, 9, 8, 5, 6, 7, 4, 3, 2, 1, 0] | Passed |
| partial-repair probe | [0, 1, 2, 3, 4, 5, 6, 7, 9, 8] | [0, 1, 2, 3, 4, 5, 6, 7, 9, 8] | Passed |
| partial-repair probe | [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10] | [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 10] | Passed |
| all even levels | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| lowest odd is three | [0, 2, 1, 3] | [0, 2, 1, 3] | Passed |
| control layout | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / bbd506ce36f2c19e763d147f1bdf113aab4dec3ba4b3abb6c0278256c5137f93
Verification & scope
A deterministic toy bidi model over stipulated class labels and integer levels; it is inspired by, but does not claim conformance to, any published algorithm. 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:49:54.195098+00:00.
Case digest / 8c063cec56055a4ca92eabc0a31d21e14f2c1555b7bc9a1e9a06b94916cc438f