FA-80476 / Bidirectional text layout / Open access
Visual reordering by levels: reversal loop bound · case 01
Runs at the lowest odd level stay in logical order.
ROOT CAUSE
The level loop excludes its lower bound.
VERIFIED REPAIR
Include the lowest odd level in the loop.
Unsuccessful approach: Starting one below the highest level skips the top pass.
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):
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: reversal loop bound', [3, 3, 3, 3, 1, 1, 1, 3, 3, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 3, 3, 0, 0, 0, 2, 2, 2, 2], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [1, 1, 2, 2, 3, 3, 2, 2], [2, 3, 5, 4, 6, 7, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('control layout', [2], [0])], [('regression: reversal loop bound', [1, 1, 1, 1, 1, 1], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [3, 0, 3, 3, 3, 3], [0, 1, 5, 4, 3, 2]), ('regression: reversal loop bound', [2, 2, 1, 1, 1], [4, 3, 2, 0, 1]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [2, 2, 2], [0, 1, 2]), ('control layout', [2, 2], [0, 1])], [('regression: reversal loop bound', [1, 0, 0, 0, 2, 2, 2, 0, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8]), ('regression: reversal loop bound', [2, 2, 2, 0, 0, 1, 1, 1, 1, 1], [0, 1, 2, 3, 4, 9, 8, 7, 6, 5]), ('regression: reversal loop bound', [4, 4, 4, 1, 1, 1, 2], [6, 5, 4, 3, 0, 1, 2]), ('regression: reversal loop bound', [3, 3, 2, 2, 2, 2, 1, 1, 1], [8, 7, 6, 1, 0, 2, 3, 4, 5]), ('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', [2, 2], [0, 1]), ('control layout', [4, 4], [0, 1])], [('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1, 0, 0, 0, 0, 0, 0, 1], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [0, 0, 0, 2, 0, 3, 3], [0, 1, 2, 3, 4, 6, 5]), ('regression: reversal loop bound', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('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', [1], [0]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4])], [('regression: reversal loop bound', [3, 1, 1, 2, 2], [3, 4, 2, 1, 0]), ('regression: reversal loop bound', [2, 2, 2, 2, 1, 1, 1, 1, 1], [8, 7, 6, 5, 4, 0, 1, 2, 3]), ('regression: reversal loop bound', [1, 1, 1, 3, 3, 3], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 2, 2, 2, 1, 1, 1, 4, 4, 4, 4, 1], [11, 7, 8, 9, 10, 6, 5, 4, 0, 1, 2, 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', [2], [0]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])]]
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: reversal loop bound | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] | Failed |
| regression: reversal loop bound | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | [2, 1, 0, 3, 4, 5, 6, 7, 8, 9] | Failed |
| regression: reversal loop bound | [0, 1, 7, 6, 4, 5, 3, 2] | [2, 3, 5, 4, 6, 7, 1, 0] | Failed |
| lowest odd is three | [0, 1, 2, 3] | [0, 2, 1, 3] | Failed |
| all even levels | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| control layout | [0, 1, 2, 3, 4, 5, 6, 7] | [0, 1, 2, 3, 4, 5, 6, 7] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / a9fe41627ddf3f3e197538d9b574c5a67c1eaa1cd3ae10427fdd4d6b230aed7c
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 - 1, 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: reversal loop bound', [3, 3, 3, 3, 1, 1, 1, 3, 3, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 3, 3, 0, 0, 0, 2, 2, 2, 2], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [1, 1, 2, 2, 3, 3, 2, 2], [2, 3, 5, 4, 6, 7, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('control layout', [2], [0])], [('regression: reversal loop bound', [1, 1, 1, 1, 1, 1], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [3, 0, 3, 3, 3, 3], [0, 1, 5, 4, 3, 2]), ('regression: reversal loop bound', [2, 2, 1, 1, 1], [4, 3, 2, 0, 1]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [2, 2, 2], [0, 1, 2]), ('control layout', [2, 2], [0, 1])], [('regression: reversal loop bound', [1, 0, 0, 0, 2, 2, 2, 0, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8]), ('regression: reversal loop bound', [2, 2, 2, 0, 0, 1, 1, 1, 1, 1], [0, 1, 2, 3, 4, 9, 8, 7, 6, 5]), ('regression: reversal loop bound', [4, 4, 4, 1, 1, 1, 2], [6, 5, 4, 3, 0, 1, 2]), ('regression: reversal loop bound', [3, 3, 2, 2, 2, 2, 1, 1, 1], [8, 7, 6, 1, 0, 2, 3, 4, 5]), ('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', [2, 2], [0, 1]), ('control layout', [4, 4], [0, 1])], [('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1, 0, 0, 0, 0, 0, 0, 1], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [0, 0, 0, 2, 0, 3, 3], [0, 1, 2, 3, 4, 6, 5]), ('regression: reversal loop bound', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('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', [1], [0]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4])], [('regression: reversal loop bound', [3, 1, 1, 2, 2], [3, 4, 2, 1, 0]), ('regression: reversal loop bound', [2, 2, 2, 2, 1, 1, 1, 1, 1], [8, 7, 6, 5, 4, 0, 1, 2, 3]), ('regression: reversal loop bound', [1, 1, 1, 3, 3, 3], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 2, 2, 2, 1, 1, 1, 4, 4, 4, 4, 1], [11, 7, 8, 9, 10, 6, 5, 4, 0, 1, 2, 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', [2], [0]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])]]
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, 3, 2, 1, 0] | [4, 2, 3, 1, 0] | Failed |
| regression: reversal loop bound | [7, 8, 9, 6, 5, 4, 0, 1, 2, 3] | [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] | Failed |
| regression: reversal loop bound | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | [2, 1, 0, 3, 4, 5, 6, 7, 8, 9] | Failed |
| regression: reversal loop bound | [2, 3, 4, 5, 6, 7, 1, 0] | [2, 3, 5, 4, 6, 7, 1, 0] | Failed |
| lowest odd is three | [0, 1, 2, 3] | [0, 2, 1, 3] | Failed |
| all even levels | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| control layout | [0, 1, 2, 3, 4, 5, 6, 7] | [0, 1, 2, 3, 4, 5, 6, 7] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / 5139651ec313046be82339159ca2cc5893820e5ed977cc89ab840e07f9d69ef6
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: reversal loop bound', [3, 3, 3, 3, 1, 1, 1, 3, 3, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 3, 3, 0, 0, 0, 2, 2, 2, 2], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [1, 1, 2, 2, 3, 3, 2, 2], [2, 3, 5, 4, 6, 7, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('control layout', [2], [0])], [('regression: reversal loop bound', [1, 1, 1, 1, 1, 1], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [3, 0, 3, 3, 3, 3], [0, 1, 5, 4, 3, 2]), ('regression: reversal loop bound', [2, 2, 1, 1, 1], [4, 3, 2, 0, 1]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [2, 2, 2], [0, 1, 2]), ('control layout', [2, 2], [0, 1])], [('regression: reversal loop bound', [1, 0, 0, 0, 2, 2, 2, 0, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8]), ('regression: reversal loop bound', [2, 2, 2, 0, 0, 1, 1, 1, 1, 1], [0, 1, 2, 3, 4, 9, 8, 7, 6, 5]), ('regression: reversal loop bound', [4, 4, 4, 1, 1, 1, 2], [6, 5, 4, 3, 0, 1, 2]), ('regression: reversal loop bound', [3, 3, 2, 2, 2, 2, 1, 1, 1], [8, 7, 6, 1, 0, 2, 3, 4, 5]), ('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', [2, 2], [0, 1]), ('control layout', [4, 4], [0, 1])], [('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1, 0, 0, 0, 0, 0, 0, 1], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [0, 0, 0, 2, 0, 3, 3], [0, 1, 2, 3, 4, 6, 5]), ('regression: reversal loop bound', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('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', [1], [0]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4])], [('regression: reversal loop bound', [3, 1, 1, 2, 2], [3, 4, 2, 1, 0]), ('regression: reversal loop bound', [2, 2, 2, 2, 1, 1, 1, 1, 1], [8, 7, 6, 5, 4, 0, 1, 2, 3]), ('regression: reversal loop bound', [1, 1, 1, 3, 3, 3], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 2, 2, 2, 1, 1, 1, 4, 4, 4, 4, 1], [11, 7, 8, 9, 10, 6, 5, 4, 0, 1, 2, 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', [2], [0]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])]]
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: reversal loop bound | [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] | [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] | Passed |
| regression: reversal loop bound | [2, 1, 0, 3, 4, 5, 6, 7, 8, 9] | [2, 1, 0, 3, 4, 5, 6, 7, 8, 9] | Passed |
| regression: reversal loop bound | [2, 3, 5, 4, 6, 7, 1, 0] | [2, 3, 5, 4, 6, 7, 1, 0] | Passed |
| lowest odd is three | [0, 2, 1, 3] | [0, 2, 1, 3] | Passed |
| all even levels | [0, 1, 2, 3] | [0, 1, 2, 3] | Passed |
| control layout | [0, 1, 2, 3, 4, 5, 6, 7] | [0, 1, 2, 3, 4, 5, 6, 7] | Passed |
| control layout | [0] | [0] | Passed |
SHA-256 / 7dcf205b45a5525ab0e2de7a7adcb8a29be3892fc7be9730223a294904695b8a
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.185948+00:00.
Case digest / f4894e3c05d6a060a3168f71c6e59a72efa135a829ee4ce63e9ee079cfaddd57