FA-80381 / Bidirectional text layout / Open access
Weak type resolution: Arabic context tracking · case 01
Numbers after Arabic letters stay European.
ROOT CAUSE
W2 tracks only L and R as strong, never recording AL.
THE FAILURE
W2 tracks only L and R as strong, never recording AL.
Unsuccessful approach: Tracking L and AL but not R leaves stale Arabic context after Hebrew letters.
Case contract
Input [classes of one isolating run sequence, sos]. W1 NSM takes the previous type (sos at start; ON after LRI/RLI/FSI/PDI). W2 EN after the last strong AL becomes AN. W3 AL->R. W4 a single ES between EN and EN -> EN; a single CS between two numbers of the same type takes that type. W5 a run of ET adjacent to EN -> EN. W6 remaining ES/ET/CS -> ON. W7 EN whose last strong (sos at start) is L -> L. Return resolved classes.
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):
types, sos = x
t = list(types)
n = len(t)
prev = sos
for i in range(n):
if t[i] == 'NSM':
t[i] = 'ON' if prev in ('LRI', 'RLI', 'FSI', 'PDI') else prev
prev = t[i]
last_strong = sos
for i in range(n):
if t[i] in ('L', 'R'):
last_strong = t[i]
elif t[i] == 'EN' and last_strong == 'AL':
t[i] = 'AN'
t = ['R' if c == 'AL' else c for c in t]
for i in range(1, n - 1):
if t[i] == 'ES' and t[i - 1] == 'EN' and t[i + 1] == 'EN':
t[i] = 'EN'
elif t[i] == 'CS' and t[i - 1] == t[i + 1] and t[i - 1] in ('EN', 'AN'):
t[i] = t[i - 1]
i = 0
while i < n:
if t[i] == 'ET':
j = i
while j < n and t[j] == 'ET':
j += 1
if (i > 0 and t[i - 1] == 'EN') or (j < n and t[j] == 'EN'):
for k in range(i, j):
t[k] = 'EN'
i = j
else:
i += 1
t = ['ON' if c in ('ES', 'ET', 'CS') else c for c in t]
strong = sos
for i in range(n):
if t[i] in ('L', 'R'):
strong = t[i]
elif t[i] == 'EN' and strong == 'L':
t[i] = 'L'
return t
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('Arabic number context', [['AL', 'EN', 'CS', 'EN'], 'L'], ['R', 'AN', 'AN', 'AN']), ('regression: Arabic context tracking', [['EN', 'R', 'R', 'L', 'AL', 'EN', 'AL', 'ES'], 'R'], ['EN', 'R', 'R', 'L', 'R', 'AN', 'R', 'ON']), ('partial-repair probe', [['NSM', 'AL', 'ON', 'ON', 'ES', 'R', 'ES', 'EN', 'PDI', 'AN'], 'R'], ['R', 'R', 'ON', 'ON', 'ON', 'R', 'ON', 'EN', 'PDI', 'AN']), ('regression: Arabic context tracking', [['AL', 'EN', 'NSM', 'R', 'NSM', 'EN', 'CS', 'AN', 'EN'], 'L'], ['R', 'AN', 'AN', 'R', 'R', 'EN', 'ON', 'AN', 'EN']), ('plus between numbers', [['EN', 'ES', 'EN', 'R'], 'R'], ['EN', 'EN', 'EN', 'R']), ('NSM after isolate initiator', [['LRI', 'NSM', 'L', 'PDI'], 'R'], ['LRI', 'ON', 'L', 'PDI']), ('control layout', [['WS', 'ES', 'R', 'L'], 'L'], ['WS', 'ON', 'R', 'L']), ('control layout', [['ET', 'R'], 'L'], ['ON', 'R'])], [('regression: Arabic context tracking', [['NSM', 'AL', 'WS', 'EN', 'CS', 'ON', 'ON', 'AL', 'PDI', 'AL'], 'L'], ['L', 'R', 'WS', 'AN', 'ON', 'ON', 'ON', 'R', 'PDI', 'R']), ('regression: Arabic context tracking', [['AL', 'R', 'CS', 'AN', 'AL', 'ES', 'EN', 'R', 'LRI', 'WS'], 'R'], ['R', 'R', 'ON', 'AN', 'R', 'ON', 'AN', 'R', 'LRI', 'WS']), ('partial-repair probe', [['PDI', 'NSM', 'AN', 'WS', 'WS', 'ET', 'AL', 'R', 'EN', 'ON', 'AN'], 'R'], ['PDI', 'ON', 'AN', 'WS', 'WS', 'ON', 'R', 'R', 'EN', 'ON', 'AN']), ('regression: Arabic context tracking', [['ET', 'AL', 'AN', 'EN', 'R', 'ET', 'EN', 'AN', 'EN'], 'L'], ['ON', 'R', 'AN', 'AN', 'R', 'EN', 'EN', 'AN', 'EN']), ('NSM chain after R', [['R', 'NSM', 'NSM', 'EN'], 'L'], ['R', 'R', 'R', 'EN']), ('NSM after isolate initiator', [['LRI', 'NSM', 'L', 'PDI'], 'R'], ['LRI', 'ON', 'L', 'PDI']), ('control layout', [['ES', 'EN', 'PDI'], 'L'], ['ON', 'L', 'PDI']), ('control layout', [['NSM', 'NSM', 'R', 'AL', 'AN', 'ON', 'L'], 'R'], ['R', 'R', 'R', 'R', 'AN', 'ON', 'L'])], [('regression: Arabic context tracking', [['L', 'AL', 'WS', 'EN', 'PDI', 'R', 'NSM'], 'R'], ['L', 'R', 'WS', 'AN', 'PDI', 'R', 'R']), ('regression: Arabic context tracking', [['AL', 'EN', 'NSM', 'R', 'NSM', 'EN', 'CS', 'AN', 'EN'], 'L'], ['R', 'AN', 'AN', 'R', 'R', 'EN', 'ON', 'AN', 'EN']), ('partial-repair probe', [['ON', 'PDI', 'AL', 'R', 'ON', 'CS', 'WS', 'EN'], 'R'], ['ON', 'PDI', 'R', 'R', 'ON', 'ON', 'WS', 'EN']), ('partial-repair probe', [['AL', 'ET', 'LRI', 'ES', 'NSM', 'R', 'LRI', 'ES', 'R', 'EN'], 'L'], ['R', 'ON', 'LRI', 'ON', 'ON', 'R', 'LRI', 'ON', 'R', 'EN']), ('NSM after isolate initiator', [['LRI', 'NSM', 'L', 'PDI'], 'R'], ['LRI', 'ON', 'L', 'PDI']), ('plus between numbers', [['EN', 'ES', 'EN', 'R'], 'R'], ['EN', 'EN', 'EN', 'R']), ('control layout', [['AL', 'AL', 'R'], 'L'], ['R', 'R', 'R']), ('control layout', [['R', 'ET', 'L'], 'L'], ['R', 'ON', 'L'])], [('regression: Arabic context tracking', [['ES', 'R', 'AL', 'EN', 'AL'], 'R'], ['ON', 'R', 'R', 'AN', 'R']), ('regression: Arabic context tracking', [['L', 'EN', 'AL', 'EN', 'ET'], 'L'], ['L', 'L', 'R', 'AN', 'ON']), ('regression: Arabic context tracking', [['AL', 'EN', 'EN', 'LRI', 'R', 'CS', 'AN', 'EN', 'EN'], 'R'], ['R', 'AN', 'AN', 'LRI', 'R', 'ON', 'AN', 'EN', 'EN']), ('partial-repair probe', [['ES', 'ET', 'EN', 'AN', 'EN', 'AL', 'R', 'ON', 'LRI', 'ES', 'EN'], 'R'], ['ON', 'EN', 'EN', 'AN', 'EN', 'R', 'R', 'ON', 'LRI', 'ON', 'EN']), ('percent after number', [['EN', 'ET', 'ET', 'L'], 'R'], ['EN', 'EN', 'EN', 'L']), ('plus between numbers', [['EN', 'ES', 'EN', 'R'], 'R'], ['EN', 'EN', 'EN', 'R']), ('control layout', [['WS', 'NSM', 'L', 'NSM', 'PDI'], 'R'], ['WS', 'WS', 'L', 'L', 'PDI']), ('control layout', [['AN', 'R', 'AL', 'PDI', 'PDI', 'AL', 'AN', 'WS', 'AL', 'PDI', 'NSM'], 'R'], ['AN', 'R', 'R', 'PDI', 'PDI', 'R', 'AN', 'WS', 'R', 'PDI', 'ON'])], [('regression: Arabic context tracking', [['AL', 'ES', 'ON', 'AL', 'ON', 'CS', 'AN', 'EN', 'AL', 'NSM', 'ES'], 'R'], ['R', 'ON', 'ON', 'R', 'ON', 'ON', 'AN', 'AN', 'R', 'R', 'ON']), ('regression: Arabic context tracking', [['CS', 'ES', 'ES', 'AL', 'EN', 'NSM', 'AN'], 'L'], ['ON', 'ON', 'ON', 'R', 'AN', 'AN', 'AN']), ('partial-repair probe', [['NSM', 'AL', 'ON', 'ON', 'ES', 'R', 'ES', 'EN', 'PDI', 'AN'], 'R'], ['R', 'R', 'ON', 'ON', 'ON', 'R', 'ON', 'EN', 'PDI', 'AN']), ('partial-repair probe', [['AN', 'CS', 'AL', 'R', 'AN', 'CS', 'ON', 'EN'], 'L'], ['AN', 'ON', 'R', 'R', 'AN', 'ON', 'ON', 'EN']), ('plus between numbers', [['EN', 'ES', 'EN', 'R'], 'R'], ['EN', 'EN', 'EN', 'R']), ('Arabic number context', [['AL', 'EN', 'CS', 'EN'], 'L'], ['R', 'AN', 'AN', 'AN']), ('control layout', [['ET', 'CS', 'R', 'L', 'CS', 'PDI', 'AL', 'R', 'LRI', 'AL', 'CS'], 'R'], ['ON', 'ON', 'R', 'L', 'ON', 'PDI', 'R', 'R', 'LRI', 'R', 'ON']), ('control layout', [['AN', 'ET', 'AL'], 'L'], ['AN', 'ON', 'R'])]]
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 |
|---|---|---|---|
| Arabic number context | ['R', 'EN', 'EN', 'EN'] | ['R', 'AN', 'AN', 'AN'] | Failed |
| regression: Arabic context tracking | ['EN', 'R', 'R', 'L', 'R', 'EN', 'R', 'ON'] | ['EN', 'R', 'R', 'L', 'R', 'AN', 'R', 'ON'] | Failed |
| partial-repair probe | ['R', 'R', 'ON', 'ON', 'ON', 'R', 'ON', 'EN', 'PDI', 'AN'] | ['R', 'R', 'ON', 'ON', 'ON', 'R', 'ON', 'EN', 'PDI', 'AN'] | Passed |
| regression: Arabic context tracking | ['R', 'EN', 'EN', 'R', 'R', 'EN', 'ON', 'AN', 'EN'] | ['R', 'AN', 'AN', 'R', 'R', 'EN', 'ON', 'AN', 'EN'] | Failed |
| plus between numbers | ['EN', 'EN', 'EN', 'R'] | ['EN', 'EN', 'EN', 'R'] | Passed |
| NSM after isolate initiator | ['LRI', 'ON', 'L', 'PDI'] | ['LRI', 'ON', 'L', 'PDI'] | Passed |
| control layout | ['WS', 'ON', 'R', 'L'] | ['WS', 'ON', 'R', 'L'] | Passed |
| control layout | ['ON', 'R'] | ['ON', 'R'] | Passed |
SHA-256 / 17e181dfe219d0c37dfe5be561ac34043380708ae2e3db55143af3e597f2432e
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
types, sos = x
t = list(types)
n = len(t)
prev = sos
for i in range(n):
if t[i] == 'NSM':
t[i] = 'ON' if prev in ('LRI', 'RLI', 'FSI', 'PDI') else prev
prev = t[i]
last_strong = sos
for i in range(n):
if t[i] in ('L', 'AL'):
last_strong = t[i]
elif t[i] == 'EN' and last_strong == 'AL':
t[i] = 'AN'
t = ['R' if c == 'AL' else c for c in t]
for i in range(1, n - 1):
if t[i] == 'ES' and t[i - 1] == 'EN' and t[i + 1] == 'EN':
t[i] = 'EN'
elif t[i] == 'CS' and t[i - 1] == t[i + 1] and t[i - 1] in ('EN', 'AN'):
t[i] = t[i - 1]
i = 0
while i < n:
if t[i] == 'ET':
j = i
while j < n and t[j] == 'ET':
j += 1
if (i > 0 and t[i - 1] == 'EN') or (j < n and t[j] == 'EN'):
for k in range(i, j):
t[k] = 'EN'
i = j
else:
i += 1
t = ['ON' if c in ('ES', 'ET', 'CS') else c for c in t]
strong = sos
for i in range(n):
if t[i] in ('L', 'R'):
strong = t[i]
elif t[i] == 'EN' and strong == 'L':
t[i] = 'L'
return t
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('Arabic number context', [['AL', 'EN', 'CS', 'EN'], 'L'], ['R', 'AN', 'AN', 'AN']), ('regression: Arabic context tracking', [['EN', 'R', 'R', 'L', 'AL', 'EN', 'AL', 'ES'], 'R'], ['EN', 'R', 'R', 'L', 'R', 'AN', 'R', 'ON']), ('partial-repair probe', [['NSM', 'AL', 'ON', 'ON', 'ES', 'R', 'ES', 'EN', 'PDI', 'AN'], 'R'], ['R', 'R', 'ON', 'ON', 'ON', 'R', 'ON', 'EN', 'PDI', 'AN']), ('regression: Arabic context tracking', [['AL', 'EN', 'NSM', 'R', 'NSM', 'EN', 'CS', 'AN', 'EN'], 'L'], ['R', 'AN', 'AN', 'R', 'R', 'EN', 'ON', 'AN', 'EN']), ('plus between numbers', [['EN', 'ES', 'EN', 'R'], 'R'], ['EN', 'EN', 'EN', 'R']), ('NSM after isolate initiator', [['LRI', 'NSM', 'L', 'PDI'], 'R'], ['LRI', 'ON', 'L', 'PDI']), ('control layout', [['WS', 'ES', 'R', 'L'], 'L'], ['WS', 'ON', 'R', 'L']), ('control layout', [['ET', 'R'], 'L'], ['ON', 'R'])], [('regression: Arabic context tracking', [['NSM', 'AL', 'WS', 'EN', 'CS', 'ON', 'ON', 'AL', 'PDI', 'AL'], 'L'], ['L', 'R', 'WS', 'AN', 'ON', 'ON', 'ON', 'R', 'PDI', 'R']), ('regression: Arabic context tracking', [['AL', 'R', 'CS', 'AN', 'AL', 'ES', 'EN', 'R', 'LRI', 'WS'], 'R'], ['R', 'R', 'ON', 'AN', 'R', 'ON', 'AN', 'R', 'LRI', 'WS']), ('partial-repair probe', [['PDI', 'NSM', 'AN', 'WS', 'WS', 'ET', 'AL', 'R', 'EN', 'ON', 'AN'], 'R'], ['PDI', 'ON', 'AN', 'WS', 'WS', 'ON', 'R', 'R', 'EN', 'ON', 'AN']), ('regression: Arabic context tracking', [['ET', 'AL', 'AN', 'EN', 'R', 'ET', 'EN', 'AN', 'EN'], 'L'], ['ON', 'R', 'AN', 'AN', 'R', 'EN', 'EN', 'AN', 'EN']), ('NSM chain after R', [['R', 'NSM', 'NSM', 'EN'], 'L'], ['R', 'R', 'R', 'EN']), ('NSM after isolate initiator', [['LRI', 'NSM', 'L', 'PDI'], 'R'], ['LRI', 'ON', 'L', 'PDI']), ('control layout', [['ES', 'EN', 'PDI'], 'L'], ['ON', 'L', 'PDI']), ('control layout', [['NSM', 'NSM', 'R', 'AL', 'AN', 'ON', 'L'], 'R'], ['R', 'R', 'R', 'R', 'AN', 'ON', 'L'])], [('regression: Arabic context tracking', [['L', 'AL', 'WS', 'EN', 'PDI', 'R', 'NSM'], 'R'], ['L', 'R', 'WS', 'AN', 'PDI', 'R', 'R']), ('regression: Arabic context tracking', [['AL', 'EN', 'NSM', 'R', 'NSM', 'EN', 'CS', 'AN', 'EN'], 'L'], ['R', 'AN', 'AN', 'R', 'R', 'EN', 'ON', 'AN', 'EN']), ('partial-repair probe', [['ON', 'PDI', 'AL', 'R', 'ON', 'CS', 'WS', 'EN'], 'R'], ['ON', 'PDI', 'R', 'R', 'ON', 'ON', 'WS', 'EN']), ('partial-repair probe', [['AL', 'ET', 'LRI', 'ES', 'NSM', 'R', 'LRI', 'ES', 'R', 'EN'], 'L'], ['R', 'ON', 'LRI', 'ON', 'ON', 'R', 'LRI', 'ON', 'R', 'EN']), ('NSM after isolate initiator', [['LRI', 'NSM', 'L', 'PDI'], 'R'], ['LRI', 'ON', 'L', 'PDI']), ('plus between numbers', [['EN', 'ES', 'EN', 'R'], 'R'], ['EN', 'EN', 'EN', 'R']), ('control layout', [['AL', 'AL', 'R'], 'L'], ['R', 'R', 'R']), ('control layout', [['R', 'ET', 'L'], 'L'], ['R', 'ON', 'L'])], [('regression: Arabic context tracking', [['ES', 'R', 'AL', 'EN', 'AL'], 'R'], ['ON', 'R', 'R', 'AN', 'R']), ('regression: Arabic context tracking', [['L', 'EN', 'AL', 'EN', 'ET'], 'L'], ['L', 'L', 'R', 'AN', 'ON']), ('regression: Arabic context tracking', [['AL', 'EN', 'EN', 'LRI', 'R', 'CS', 'AN', 'EN', 'EN'], 'R'], ['R', 'AN', 'AN', 'LRI', 'R', 'ON', 'AN', 'EN', 'EN']), ('partial-repair probe', [['ES', 'ET', 'EN', 'AN', 'EN', 'AL', 'R', 'ON', 'LRI', 'ES', 'EN'], 'R'], ['ON', 'EN', 'EN', 'AN', 'EN', 'R', 'R', 'ON', 'LRI', 'ON', 'EN']), ('percent after number', [['EN', 'ET', 'ET', 'L'], 'R'], ['EN', 'EN', 'EN', 'L']), ('plus between numbers', [['EN', 'ES', 'EN', 'R'], 'R'], ['EN', 'EN', 'EN', 'R']), ('control layout', [['WS', 'NSM', 'L', 'NSM', 'PDI'], 'R'], ['WS', 'WS', 'L', 'L', 'PDI']), ('control layout', [['AN', 'R', 'AL', 'PDI', 'PDI', 'AL', 'AN', 'WS', 'AL', 'PDI', 'NSM'], 'R'], ['AN', 'R', 'R', 'PDI', 'PDI', 'R', 'AN', 'WS', 'R', 'PDI', 'ON'])], [('regression: Arabic context tracking', [['AL', 'ES', 'ON', 'AL', 'ON', 'CS', 'AN', 'EN', 'AL', 'NSM', 'ES'], 'R'], ['R', 'ON', 'ON', 'R', 'ON', 'ON', 'AN', 'AN', 'R', 'R', 'ON']), ('regression: Arabic context tracking', [['CS', 'ES', 'ES', 'AL', 'EN', 'NSM', 'AN'], 'L'], ['ON', 'ON', 'ON', 'R', 'AN', 'AN', 'AN']), ('partial-repair probe', [['NSM', 'AL', 'ON', 'ON', 'ES', 'R', 'ES', 'EN', 'PDI', 'AN'], 'R'], ['R', 'R', 'ON', 'ON', 'ON', 'R', 'ON', 'EN', 'PDI', 'AN']), ('partial-repair probe', [['AN', 'CS', 'AL', 'R', 'AN', 'CS', 'ON', 'EN'], 'L'], ['AN', 'ON', 'R', 'R', 'AN', 'ON', 'ON', 'EN']), ('plus between numbers', [['EN', 'ES', 'EN', 'R'], 'R'], ['EN', 'EN', 'EN', 'R']), ('Arabic number context', [['AL', 'EN', 'CS', 'EN'], 'L'], ['R', 'AN', 'AN', 'AN']), ('control layout', [['ET', 'CS', 'R', 'L', 'CS', 'PDI', 'AL', 'R', 'LRI', 'AL', 'CS'], 'R'], ['ON', 'ON', 'R', 'L', 'ON', 'PDI', 'R', 'R', 'LRI', 'R', 'ON']), ('control layout', [['AN', 'ET', 'AL'], 'L'], ['AN', 'ON', 'R'])]]
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 |
|---|---|---|---|
| Arabic number context | ['R', 'AN', 'AN', 'AN'] | ['R', 'AN', 'AN', 'AN'] | Passed |
| regression: Arabic context tracking | ['EN', 'R', 'R', 'L', 'R', 'AN', 'R', 'ON'] | ['EN', 'R', 'R', 'L', 'R', 'AN', 'R', 'ON'] | Passed |
| partial-repair probe | ['R', 'R', 'ON', 'ON', 'ON', 'R', 'ON', 'AN', 'PDI', 'AN'] | ['R', 'R', 'ON', 'ON', 'ON', 'R', 'ON', 'EN', 'PDI', 'AN'] | Failed |
| regression: Arabic context tracking | ['R', 'AN', 'AN', 'R', 'R', 'AN', 'AN', 'AN', 'AN'] | ['R', 'AN', 'AN', 'R', 'R', 'EN', 'ON', 'AN', 'EN'] | Failed |
| plus between numbers | ['EN', 'EN', 'EN', 'R'] | ['EN', 'EN', 'EN', 'R'] | Passed |
| NSM after isolate initiator | ['LRI', 'ON', 'L', 'PDI'] | ['LRI', 'ON', 'L', 'PDI'] | Passed |
| control layout | ['WS', 'ON', 'R', 'L'] | ['WS', 'ON', 'R', 'L'] | Passed |
| control layout | ['ON', 'R'] | ['ON', 'R'] | Passed |
SHA-256 / a6aa1c92d2d53cf67f0c49eaf11043ace4f26380dc25de10605a1ddf42031735
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗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:53.451355+00:00.
Case digest / 7a66be31b3a7648f824b46b9df3a096ea10a951e2e7dca0e44b94a7b5faea6f9