FA-80556 / Bidirectional text layout / Open access
Mirrored glyph rendering: mirroring parity · case 01
Brackets inside LTR embeddings of RTL text are flipped.
ROOT CAUSE
Every non-zero level is mirrored instead of odd levels only.
VERIFIED REPAIR
Mirror only characters at odd levels.
Unsuccessful approach: Mirroring only level 1 misses deeper odd levels.
Case contract
Input [text, resolved levels]. Characters at odd levels with a mirror pair ( ) [ ] { } < > « » are replaced by their mirror, decided per logical character; then runs are reversed from the highest level to the lowest odd level. Return the visual string.
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
import itertools
N = 1
observations = []
def solve(x):
text, levels = x
M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
n = len(text)
glyphs = [M.get(ch, ch) if levels[i] > 0 else ch for i, ch in enumerate(text)]
order = list(range(n))
odd = [l for l in levels if l % 2]
if odd:
for lev in range(max(levels), min(odd) - 1, -1):
runs = []
for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
g = list(grp)
runs.extend(g[::-1] if key else g)
order = runs
return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('regression: mirroring parity', ['y)', [2, 2]], 'y)'), ('partial-repair probe', ['>a)]]a[><', [0, 0, 0, 0, 3, 3, 3, 3, 0]], '>a)]<]a[<'), ('partial-repair probe', ['<yy«<b){{a<', [1, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3]], '>a}}(b>»yy>'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y', [2]], 'y'), ('control layout', ['b<ya', [1, 1, 1, 1]], 'ay>b')], [('regression: mirroring parity', ['»»<y{aa}<y<>', [4, 4, 4, 3, 3, 4, 1, 1, 1, 1, 1, 1]], '<>y>{aa}y»»<'), ('regression: mirroring parity', ['a{»a(>}»[»»', [4, 4, 4, 4, 3, 3, 3, 1, 3, 1, 1]], '««]«{<)a{»a'), ('partial-repair probe', ['y[axy«»»)>', [1, 1, 3, 3, 3, 3, 1, 1, 1, 1]], '<(««»yxa]y'), ('regression: mirroring parity', ['()>}>])}y»(>', [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 4, 2]], '(«y{(>[<{<()'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['{', [1]], '}'), ('control layout', ['ay«', [1, 1, 1]], '»ya')], [('regression: mirroring parity', [']a>}>x)aa((', [1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1]], '))a>x)a{<a['), ('regression: mirroring parity', ['a»}[byx}{}', [1, 1, 1, 1, 0, 0, 2, 2, 0, 2]], ']{«abyx}{}'), ('partial-repair probe', ['x((a»b»ayb]', [2, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3]], 'x((a»b»[bya'), ('regression: mirroring parity', [']]{}xby<b{{', [2, 3, 3, 3, 3, 0, 0, 0, 0, 1, 1]], ']x{}[by<b}}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['[»', [0, 0]], '[»'), ('control layout', ['<yy', [0, 0, 0]], '<yy')], [('regression: mirroring parity', ['{xba', [4, 4, 4, 2]], '{xba'), ('regression: mirroring parity', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('partial-repair probe', ['{', [3]], '}'), ('partial-repair probe', ['b[<[«<}y}}x', [1, 1, 1, 0, 1, 1, 1, 3, 3, 0, 0]], '>]b[{y{>»}x'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['>>(', [0, 0, 0]], '>>('), ('control layout', ['[»', [0, 0]], '[»')], [('regression: mirroring parity', ['{xyayb}{', [2, 1, 1, 1, 1, 1, 2, 2]], '}{byayx{'), ('regression: mirroring parity', ['}>', [2, 2]], '}>'), ('partial-repair probe', ['>y[y<', [0, 0, 0, 2, 3]], '>y[y>'), ('regression: mirroring parity', ['}<y<]{y>y}«', [2, 1, 1, 3, 3, 3, 2, 2, 2, 2, 1]], '»}[>y>y}y>}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['a', [2]], 'a'), ('control layout', ['a<<[x>', [2, 0, 0, 0, 0, 0]], 'a<<[x>')]]
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 |
|---|---|---|---|
| bracket at level two | )x( | (x) | Failed |
| regression: mirroring parity | y( | y) | Failed |
| partial-repair probe | >a)]<]a[< | >a)]<]a[< | Passed |
| partial-repair probe | >a}}(b>»yy> | >a}}(b>»yy> | Passed |
| bracket in RTL run | (b)a | (b)a | Passed |
| guillemets RTL | «ba» | «ba» | Passed |
| control layout | y | y | Passed |
| control layout | ay>b | ay>b | Passed |
SHA-256 / d077347f41564e485ed3843abaa7b50afee1fad15f9a463c2f4b08395871bfd0
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
text, levels = x
M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
n = len(text)
glyphs = [M.get(ch, ch) if levels[i] == 1 else ch for i, ch in enumerate(text)]
order = list(range(n))
odd = [l for l in levels if l % 2]
if odd:
for lev in range(max(levels), min(odd) - 1, -1):
runs = []
for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
g = list(grp)
runs.extend(g[::-1] if key else g)
order = runs
return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('regression: mirroring parity', ['y)', [2, 2]], 'y)'), ('partial-repair probe', ['>a)]]a[><', [0, 0, 0, 0, 3, 3, 3, 3, 0]], '>a)]<]a[<'), ('partial-repair probe', ['<yy«<b){{a<', [1, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3]], '>a}}(b>»yy>'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y', [2]], 'y'), ('control layout', ['b<ya', [1, 1, 1, 1]], 'ay>b')], [('regression: mirroring parity', ['»»<y{aa}<y<>', [4, 4, 4, 3, 3, 4, 1, 1, 1, 1, 1, 1]], '<>y>{aa}y»»<'), ('regression: mirroring parity', ['a{»a(>}»[»»', [4, 4, 4, 4, 3, 3, 3, 1, 3, 1, 1]], '««]«{<)a{»a'), ('partial-repair probe', ['y[axy«»»)>', [1, 1, 3, 3, 3, 3, 1, 1, 1, 1]], '<(««»yxa]y'), ('regression: mirroring parity', ['()>}>])}y»(>', [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 4, 2]], '(«y{(>[<{<()'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['{', [1]], '}'), ('control layout', ['ay«', [1, 1, 1]], '»ya')], [('regression: mirroring parity', [']a>}>x)aa((', [1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1]], '))a>x)a{<a['), ('regression: mirroring parity', ['a»}[byx}{}', [1, 1, 1, 1, 0, 0, 2, 2, 0, 2]], ']{«abyx}{}'), ('partial-repair probe', ['x((a»b»ayb]', [2, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3]], 'x((a»b»[bya'), ('regression: mirroring parity', [']]{}xby<b{{', [2, 3, 3, 3, 3, 0, 0, 0, 0, 1, 1]], ']x{}[by<b}}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['[»', [0, 0]], '[»'), ('control layout', ['<yy', [0, 0, 0]], '<yy')], [('regression: mirroring parity', ['{xba', [4, 4, 4, 2]], '{xba'), ('regression: mirroring parity', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('partial-repair probe', ['{', [3]], '}'), ('partial-repair probe', ['b[<[«<}y}}x', [1, 1, 1, 0, 1, 1, 1, 3, 3, 0, 0]], '>]b[{y{>»}x'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['>>(', [0, 0, 0]], '>>('), ('control layout', ['[»', [0, 0]], '[»')], [('regression: mirroring parity', ['{xyayb}{', [2, 1, 1, 1, 1, 1, 2, 2]], '}{byayx{'), ('regression: mirroring parity', ['}>', [2, 2]], '}>'), ('partial-repair probe', ['>y[y<', [0, 0, 0, 2, 3]], '>y[y>'), ('regression: mirroring parity', ['}<y<]{y>y}«', [2, 1, 1, 3, 3, 3, 2, 2, 2, 2, 1]], '»}[>y>y}y>}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['a', [2]], 'a'), ('control layout', ['a<<[x>', [2, 0, 0, 0, 0, 0]], 'a<<[x>')]]
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 |
|---|---|---|---|
| bracket at level two | (x) | (x) | Passed |
| regression: mirroring parity | y) | y) | Passed |
| partial-repair probe | >a)]>[a]< | >a)]<]a[< | Failed |
| partial-repair probe | <a}}(b<«yy> | >a}}(b>»yy> | Failed |
| bracket in RTL run | (b)a | (b)a | Passed |
| guillemets RTL | «ba» | «ba» | Passed |
| control layout | y | y | Passed |
| control layout | ay>b | ay>b | Passed |
SHA-256 / 52980e4f47cfd8d7d4e65baa8b59620923b5fbc26fd5b1e983b96fbc2ea4f3d2
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import itertools
N = 1
observations = []
def solve(x):
text, levels = x
M = {'(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '«': '»', '»': '«'}
n = len(text)
glyphs = [M.get(ch, ch) if levels[i] % 2 == 1 else ch for i, ch in enumerate(text)]
order = list(range(n))
odd = [l for l in levels if l % 2]
if odd:
for lev in range(max(levels), min(odd) - 1, -1):
runs = []
for key, grp in itertools.groupby(order, key=lambda i: levels[i] >= lev):
g = list(grp)
runs.extend(g[::-1] if key else g)
order = runs
return ''.join(glyphs[i] for i in order)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('regression: mirroring parity', ['y)', [2, 2]], 'y)'), ('partial-repair probe', ['>a)]]a[><', [0, 0, 0, 0, 3, 3, 3, 3, 0]], '>a)]<]a[<'), ('partial-repair probe', ['<yy«<b){{a<', [1, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3]], '>a}}(b>»yy>'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['y', [2]], 'y'), ('control layout', ['b<ya', [1, 1, 1, 1]], 'ay>b')], [('regression: mirroring parity', ['»»<y{aa}<y<>', [4, 4, 4, 3, 3, 4, 1, 1, 1, 1, 1, 1]], '<>y>{aa}y»»<'), ('regression: mirroring parity', ['a{»a(>}»[»»', [4, 4, 4, 4, 3, 3, 3, 1, 3, 1, 1]], '««]«{<)a{»a'), ('partial-repair probe', ['y[axy«»»)>', [1, 1, 3, 3, 3, 3, 1, 1, 1, 1]], '<(««»yxa]y'), ('regression: mirroring parity', ['()>}>])}y»(>', [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 4, 2]], '(«y{(>[<{<()'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['{', [1]], '}'), ('control layout', ['ay«', [1, 1, 1]], '»ya')], [('regression: mirroring parity', [']a>}>x)aa((', [1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1]], '))a>x)a{<a['), ('regression: mirroring parity', ['a»}[byx}{}', [1, 1, 1, 1, 0, 0, 2, 2, 0, 2]], ']{«abyx}{}'), ('partial-repair probe', ['x((a»b»ayb]', [2, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3]], 'x((a»b»[bya'), ('regression: mirroring parity', [']]{}xby<b{{', [2, 3, 3, 3, 3, 0, 0, 0, 0, 1, 1]], ']x{}[by<b}}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['[»', [0, 0]], '[»'), ('control layout', ['<yy', [0, 0, 0]], '<yy')], [('regression: mirroring parity', ['{xba', [4, 4, 4, 2]], '{xba'), ('regression: mirroring parity', ['y«{»]<]', [2, 2, 2, 1, 1, 4, 4]], '<][«y«{'), ('partial-repair probe', ['{', [3]], '}'), ('partial-repair probe', ['b[<[«<}y}}x', [1, 1, 1, 0, 1, 1, 1, 3, 3, 0, 0]], '>]b[{y{>»}x'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('guillemets RTL', ['«ab»', [1, 1, 1, 1]], '«ba»'), ('control layout', ['>>(', [0, 0, 0]], '>>('), ('control layout', ['[»', [0, 0]], '[»')], [('regression: mirroring parity', ['{xyayb}{', [2, 1, 1, 1, 1, 1, 2, 2]], '}{byayx{'), ('regression: mirroring parity', ['}>', [2, 2]], '}>'), ('partial-repair probe', ['>y[y<', [0, 0, 0, 2, 3]], '>y[y>'), ('regression: mirroring parity', ['}<y<]{y>y}«', [2, 1, 1, 3, 3, 3, 2, 2, 2, 2, 1]], '»}[>y>y}y>}'), ('bracket in RTL run', ['a(b)', [1, 1, 1, 1]], '(b)a'), ('bracket at level two', ['(x)', [2, 2, 2]], '(x)'), ('control layout', ['a', [2]], 'a'), ('control layout', ['a<<[x>', [2, 0, 0, 0, 0, 0]], 'a<<[x>')]]
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 |
|---|---|---|---|
| bracket at level two | (x) | (x) | Passed |
| regression: mirroring parity | y) | y) | Passed |
| partial-repair probe | >a)]<]a[< | >a)]<]a[< | Passed |
| partial-repair probe | >a}}(b>»yy> | >a}}(b>»yy> | Passed |
| bracket in RTL run | (b)a | (b)a | Passed |
| guillemets RTL | «ba» | «ba» | Passed |
| control layout | y | y | Passed |
| control layout | ay>b | ay>b | Passed |
SHA-256 / 17c53795aa4fa501fc2254329e71d266547980d423a56e6e23d08ed65fb3ee3e
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.853328+00:00.
Case digest / 7ffb921459a62f3340e45c47d761529f78606df9d189a4c8b8787629f56ae313