FA-71841 / Error-correcting codes / Open access
Hamming correction flips the bit after the syndrome position · case 01
Single-bit errors are moved to the neighbouring bit instead of being repaired.
ROOT CAUSE
The flip uses c[s] although syndromes are 1-based positions.
VERIFIED REPAIR
Flip c[s - 1].
Unsuccessful approach: Flipping c[n - s] mirrors the position and only works for the middle bit.
Case contract
Single-error-correcting Hamming decoder for a full or shortened code of length n >= 3 (bits 0/1, else None). Positions are 1-based; parity bits sit at powers of two. The syndrome is the XOR of the positions holding a 1. A syndrome above n points outside the shortened code and is "uncorrectable" (data None); otherwise the bit at the syndrome position is flipped. Return [status, data bits from non-power-of-two positions, syndrome].
Why this case matters
Memory and link controllers use (shortened) Hamming codes to repair single-bit upsets.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(r):
n = len(r)
if n < 3 or any(b not in (0, 1) for b in r):
return None
s = 0
for pos in range(1, n + 1):
if r[pos - 1]:
s ^= pos
if s > n:
return ['uncorrectable', None, s]
c = list(r)
if s:
c[s] ^= 1
data = [c[pos - 1] for pos in range(1, n + 1) if pos & (pos - 1)]
return ['corrected' if s else 'clean', data, s]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression [[0, 1, 1, 0, 1, 1, 1]]', [[0, 1, 1, 0, 1, 1, 1]], ['corrected', [1, 0, 1, 1], 5]], ['regression [[1, 0, 0, 1, 0, 1, 0]]', [[1, 0, 0, 1, 0, 1, 0]], ['corrected', [1, 0, 1, 0], 3]], ['partial-repair [[1, 1, 0, 1, 0, 1, 0]]', [[1, 1, 0, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0], 1]], ['control [[0, 1, 1, 0, 0, 1, 1]]', [[0, 1, 1, 0, 0, 1, 1]], ['clean', [1, 0, 1, 1], 0]], ['control [[0, 1, 0, 1, 0, 1, 0]]', [[0, 1, 0, 1, 0, 1, 0]], ['clean', [0, 0, 1, 0], 0]], ['control [[1, 0, 0, 0, 0, 1, 1]]', [[1, 0, 0, 0, 0, 1, 1]], ['clean', [0, 0, 1, 1], 0]], ['control [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]]', [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]], ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0]], ['control [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]]', [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]], ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0]]], [['regression [[1, 0, 0, 0, 1, 1, 1]]', [[1, 0, 0, 0, 1, 1, 1]], ['corrected', [0, 0, 1, 1], 5]], ['regression [[0, 1, 0, 0, 0, 1, 1]]', [[0, 1, 0, 0, 0, 1, 1]], ['corrected', [1, 0, 1, 1], 3]], ['partial-repair [[0, 1, 1, 1, 0, 1, 0]]', [[0, 1, 1, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0], 3]], ['control [[0, 0, 1, 1, 0, 0, 1, 0, 0, 0]]', [[0, 0, 1, 1, 0, 0, 1, 0, 0, 0]], ['clean', [1, 0, 0, 1, 0, 0], 0]], ['control [[0, 0, 1, 1, 1, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 1, 0, 1, 0, 1, 0]], ['uncorrectable', None, 12]], ['control [[0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['clean', [1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0], 0]], ['control [[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1]]', [[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1]], ['clean', [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1], 0]], ['control [[1, 0, 0, 0, 0, 0, 0, 1, 1]]', [[1, 0, 0, 0, 0, 0, 0, 1, 1]], ['clean', [0, 0, 0, 0, 1], 0]]], [['regression [[1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0]]', [[1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0]], ['corrected', [0, 1, 0, 0, 1, 1, 1, 0], 8]], ['regression [[0, 0, 1, 1, 0, 0, 0, 0, 0, 0]]', [[0, 0, 1, 1, 0, 0, 0, 0, 0, 0]], ['corrected', [1, 0, 0, 1, 0, 0], 7]], ['partial-repair [[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0]]', [[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0]], ['corrected', [0, 1, 1, 0, 1, 1, 1, 0], 4]], ['control [[0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0]], ['clean', [1, 0, 1, 1, 0, 1, 0, 1, 0], 0]], ['control [[0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]], ['clean', [0, 0, 1, 0, 1, 0, 1, 0], 0]], ['control [[0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1]]', [[0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1]], ['uncorrectable', None, 15]], ['control [[0, 1, 1, 1, 1, 0]]', [[0, 1, 1, 1, 1, 0]], ['clean', [1, 1, 0], 0]], ['control [[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1]]', [[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1]], ['uncorrectable', None, 13]]], [['regression [[0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1]]', [[0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1]], ['corrected', [1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1], 13]], ['regression [[1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1]]', [[1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1]], ['corrected', [0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1], 11]], ['partial-repair [[0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['corrected', [1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0], 5]], ['control [[1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['uncorrectable', None, 14]], ['control [[1, 1, 1, 1, 1, 0, 1, 1, 1, 1]]', [[1, 1, 1, 1, 1, 0, 1, 1, 1, 1]], ['uncorrectable', None, 13]], ['control [[0, 0, 1, 0, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 0, 0, 0, 1, 0, 1, 0]], ['uncorrectable', None, 13]], ['control [[1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0]]', [[1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0]], ['uncorrectable', None, 14]], ['control [[1, 1, 1, 0, 1, 0, 0, 0, 1]]', [[1, 1, 1, 0, 1, 0, 0, 0, 1]], ['uncorrectable', None, 12]]], [['regression [[0, 0, 0, 1, 0, 0, 0, 1, 1]]', [[0, 0, 0, 1, 0, 0, 0, 1, 1]], ['corrected', [0, 1, 0, 0, 1], 5]], ['regression [[0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0]], ['corrected', [1, 0, 1, 1, 0, 1, 0, 1, 0], 6]], ['partial-repair [[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]]', [[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0, 1, 0, 1, 0], 1]], ['control [[0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0]]', [[0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0]], ['uncorrectable', None, 15]], ['control [[1, 1, 1, 1, 1, 1, 1]]', [[1, 1, 1, 1, 1, 1, 1]], ['clean', [1, 1, 1, 1], 0]], ['control [[0, 1]]', [[0, 1]], None], ['control [[0, 1, 2, 0, 0, 0, 0]]', [[0, 1, 2, 0, 0, 0, 0]], None], ['control [[0, 1, 1, 0, 0, 1, 1]]', [[0, 1, 1, 0, 0, 1, 1]], ['clean', [1, 0, 1, 1], 0]]]]
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 |
|---|---|---|---|
| regression [[0, 1, 1, 0, 1, 1, 1]] | ['corrected', [1, 1, 0, 1], 5] | ['corrected', [1, 0, 1, 1], 5] | Failed |
| regression [[1, 0, 0, 1, 0, 1, 0]] | ['corrected', [0, 0, 1, 0], 3] | ['corrected', [1, 0, 1, 0], 3] | Failed |
| partial-repair [[1, 1, 0, 1, 0, 1, 0]] | ['corrected', [0, 0, 1, 0], 1] | ['corrected', [0, 0, 1, 0], 1] | Passed |
| control [[0, 1, 1, 0, 0, 1, 1]] | ['clean', [1, 0, 1, 1], 0] | ['clean', [1, 0, 1, 1], 0] | Passed |
| control [[0, 1, 0, 1, 0, 1, 0]] | ['clean', [0, 0, 1, 0], 0] | ['clean', [0, 0, 1, 0], 0] | Passed |
| control [[1, 0, 0, 0, 0, 1, 1]] | ['clean', [0, 0, 1, 1], 0] | ['clean', [0, 0, 1, 1], 0] | Passed |
| control [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]] | ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0] | ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0] | Passed |
| control [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]] | ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0] | ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0] | Passed |
SHA-256 / 227fedd090ac65cbb11cdcf7060c873c820c90cc20e21f48b4176514918908de
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(r):
n = len(r)
if n < 3 or any(b not in (0, 1) for b in r):
return None
s = 0
for pos in range(1, n + 1):
if r[pos - 1]:
s ^= pos
if s > n:
return ['uncorrectable', None, s]
c = list(r)
if s:
c[n - s] ^= 1
data = [c[pos - 1] for pos in range(1, n + 1) if pos & (pos - 1)]
return ['corrected' if s else 'clean', data, s]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression [[0, 1, 1, 0, 1, 1, 1]]', [[0, 1, 1, 0, 1, 1, 1]], ['corrected', [1, 0, 1, 1], 5]], ['regression [[1, 0, 0, 1, 0, 1, 0]]', [[1, 0, 0, 1, 0, 1, 0]], ['corrected', [1, 0, 1, 0], 3]], ['partial-repair [[1, 1, 0, 1, 0, 1, 0]]', [[1, 1, 0, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0], 1]], ['control [[0, 1, 1, 0, 0, 1, 1]]', [[0, 1, 1, 0, 0, 1, 1]], ['clean', [1, 0, 1, 1], 0]], ['control [[0, 1, 0, 1, 0, 1, 0]]', [[0, 1, 0, 1, 0, 1, 0]], ['clean', [0, 0, 1, 0], 0]], ['control [[1, 0, 0, 0, 0, 1, 1]]', [[1, 0, 0, 0, 0, 1, 1]], ['clean', [0, 0, 1, 1], 0]], ['control [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]]', [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]], ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0]], ['control [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]]', [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]], ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0]]], [['regression [[1, 0, 0, 0, 1, 1, 1]]', [[1, 0, 0, 0, 1, 1, 1]], ['corrected', [0, 0, 1, 1], 5]], ['regression [[0, 1, 0, 0, 0, 1, 1]]', [[0, 1, 0, 0, 0, 1, 1]], ['corrected', [1, 0, 1, 1], 3]], ['partial-repair [[0, 1, 1, 1, 0, 1, 0]]', [[0, 1, 1, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0], 3]], ['control [[0, 0, 1, 1, 0, 0, 1, 0, 0, 0]]', [[0, 0, 1, 1, 0, 0, 1, 0, 0, 0]], ['clean', [1, 0, 0, 1, 0, 0], 0]], ['control [[0, 0, 1, 1, 1, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 1, 0, 1, 0, 1, 0]], ['uncorrectable', None, 12]], ['control [[0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['clean', [1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0], 0]], ['control [[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1]]', [[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1]], ['clean', [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1], 0]], ['control [[1, 0, 0, 0, 0, 0, 0, 1, 1]]', [[1, 0, 0, 0, 0, 0, 0, 1, 1]], ['clean', [0, 0, 0, 0, 1], 0]]], [['regression [[1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0]]', [[1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0]], ['corrected', [0, 1, 0, 0, 1, 1, 1, 0], 8]], ['regression [[0, 0, 1, 1, 0, 0, 0, 0, 0, 0]]', [[0, 0, 1, 1, 0, 0, 0, 0, 0, 0]], ['corrected', [1, 0, 0, 1, 0, 0], 7]], ['partial-repair [[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0]]', [[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0]], ['corrected', [0, 1, 1, 0, 1, 1, 1, 0], 4]], ['control [[0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0]], ['clean', [1, 0, 1, 1, 0, 1, 0, 1, 0], 0]], ['control [[0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]], ['clean', [0, 0, 1, 0, 1, 0, 1, 0], 0]], ['control [[0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1]]', [[0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1]], ['uncorrectable', None, 15]], ['control [[0, 1, 1, 1, 1, 0]]', [[0, 1, 1, 1, 1, 0]], ['clean', [1, 1, 0], 0]], ['control [[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1]]', [[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1]], ['uncorrectable', None, 13]]], [['regression [[0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1]]', [[0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1]], ['corrected', [1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1], 13]], ['regression [[1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1]]', [[1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1]], ['corrected', [0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1], 11]], ['partial-repair [[0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['corrected', [1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0], 5]], ['control [[1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['uncorrectable', None, 14]], ['control [[1, 1, 1, 1, 1, 0, 1, 1, 1, 1]]', [[1, 1, 1, 1, 1, 0, 1, 1, 1, 1]], ['uncorrectable', None, 13]], ['control [[0, 0, 1, 0, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 0, 0, 0, 1, 0, 1, 0]], ['uncorrectable', None, 13]], ['control [[1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0]]', [[1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0]], ['uncorrectable', None, 14]], ['control [[1, 1, 1, 0, 1, 0, 0, 0, 1]]', [[1, 1, 1, 0, 1, 0, 0, 0, 1]], ['uncorrectable', None, 12]]], [['regression [[0, 0, 0, 1, 0, 0, 0, 1, 1]]', [[0, 0, 0, 1, 0, 0, 0, 1, 1]], ['corrected', [0, 1, 0, 0, 1], 5]], ['regression [[0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0]], ['corrected', [1, 0, 1, 1, 0, 1, 0, 1, 0], 6]], ['partial-repair [[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]]', [[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0, 1, 0, 1, 0], 1]], ['control [[0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0]]', [[0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0]], ['uncorrectable', None, 15]], ['control [[1, 1, 1, 1, 1, 1, 1]]', [[1, 1, 1, 1, 1, 1, 1]], ['clean', [1, 1, 1, 1], 0]], ['control [[0, 1]]', [[0, 1]], None], ['control [[0, 1, 2, 0, 0, 0, 0]]', [[0, 1, 2, 0, 0, 0, 0]], None], ['control [[0, 1, 1, 0, 0, 1, 1]]', [[0, 1, 1, 0, 0, 1, 1]], ['clean', [1, 0, 1, 1], 0]]]]
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 |
|---|---|---|---|
| regression [[0, 1, 1, 0, 1, 1, 1]] | ['corrected', [0, 1, 1, 1], 5] | ['corrected', [1, 0, 1, 1], 5] | Failed |
| regression [[1, 0, 0, 1, 0, 1, 0]] | ['corrected', [0, 1, 1, 0], 3] | ['corrected', [1, 0, 1, 0], 3] | Failed |
| partial-repair [[1, 1, 0, 1, 0, 1, 0]] | ['corrected', [0, 0, 1, 1], 1] | ['corrected', [0, 0, 1, 0], 1] | Failed |
| control [[0, 1, 1, 0, 0, 1, 1]] | ['clean', [1, 0, 1, 1], 0] | ['clean', [1, 0, 1, 1], 0] | Passed |
| control [[0, 1, 0, 1, 0, 1, 0]] | ['clean', [0, 0, 1, 0], 0] | ['clean', [0, 0, 1, 0], 0] | Passed |
| control [[1, 0, 0, 0, 0, 1, 1]] | ['clean', [0, 0, 1, 1], 0] | ['clean', [0, 0, 1, 1], 0] | Passed |
| control [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]] | ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0] | ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0] | Passed |
| control [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]] | ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0] | ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0] | Passed |
SHA-256 / 4387402966032a965d4d0f5ea5d3c270a905e647306089a1ea31833013abd03c
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(r):
n = len(r)
if n < 3 or any(b not in (0, 1) for b in r):
return None
s = 0
for pos in range(1, n + 1):
if r[pos - 1]:
s ^= pos
if s > n:
return ['uncorrectable', None, s]
c = list(r)
if s:
c[s - 1] ^= 1
data = [c[pos - 1] for pos in range(1, n + 1) if pos & (pos - 1)]
return ['corrected' if s else 'clean', data, s]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression [[0, 1, 1, 0, 1, 1, 1]]', [[0, 1, 1, 0, 1, 1, 1]], ['corrected', [1, 0, 1, 1], 5]], ['regression [[1, 0, 0, 1, 0, 1, 0]]', [[1, 0, 0, 1, 0, 1, 0]], ['corrected', [1, 0, 1, 0], 3]], ['partial-repair [[1, 1, 0, 1, 0, 1, 0]]', [[1, 1, 0, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0], 1]], ['control [[0, 1, 1, 0, 0, 1, 1]]', [[0, 1, 1, 0, 0, 1, 1]], ['clean', [1, 0, 1, 1], 0]], ['control [[0, 1, 0, 1, 0, 1, 0]]', [[0, 1, 0, 1, 0, 1, 0]], ['clean', [0, 0, 1, 0], 0]], ['control [[1, 0, 0, 0, 0, 1, 1]]', [[1, 0, 0, 0, 0, 1, 1]], ['clean', [0, 0, 1, 1], 0]], ['control [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]]', [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]], ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0]], ['control [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]]', [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]], ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0]]], [['regression [[1, 0, 0, 0, 1, 1, 1]]', [[1, 0, 0, 0, 1, 1, 1]], ['corrected', [0, 0, 1, 1], 5]], ['regression [[0, 1, 0, 0, 0, 1, 1]]', [[0, 1, 0, 0, 0, 1, 1]], ['corrected', [1, 0, 1, 1], 3]], ['partial-repair [[0, 1, 1, 1, 0, 1, 0]]', [[0, 1, 1, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0], 3]], ['control [[0, 0, 1, 1, 0, 0, 1, 0, 0, 0]]', [[0, 0, 1, 1, 0, 0, 1, 0, 0, 0]], ['clean', [1, 0, 0, 1, 0, 0], 0]], ['control [[0, 0, 1, 1, 1, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 1, 0, 1, 0, 1, 0]], ['uncorrectable', None, 12]], ['control [[0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['clean', [1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0], 0]], ['control [[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1]]', [[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1]], ['clean', [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1], 0]], ['control [[1, 0, 0, 0, 0, 0, 0, 1, 1]]', [[1, 0, 0, 0, 0, 0, 0, 1, 1]], ['clean', [0, 0, 0, 0, 1], 0]]], [['regression [[1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0]]', [[1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0]], ['corrected', [0, 1, 0, 0, 1, 1, 1, 0], 8]], ['regression [[0, 0, 1, 1, 0, 0, 0, 0, 0, 0]]', [[0, 0, 1, 1, 0, 0, 0, 0, 0, 0]], ['corrected', [1, 0, 0, 1, 0, 0], 7]], ['partial-repair [[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0]]', [[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0]], ['corrected', [0, 1, 1, 0, 1, 1, 1, 0], 4]], ['control [[0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0]], ['clean', [1, 0, 1, 1, 0, 1, 0, 1, 0], 0]], ['control [[0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]], ['clean', [0, 0, 1, 0, 1, 0, 1, 0], 0]], ['control [[0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1]]', [[0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1]], ['uncorrectable', None, 15]], ['control [[0, 1, 1, 1, 1, 0]]', [[0, 1, 1, 1, 1, 0]], ['clean', [1, 1, 0], 0]], ['control [[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1]]', [[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1]], ['uncorrectable', None, 13]]], [['regression [[0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1]]', [[0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1]], ['corrected', [1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1], 13]], ['regression [[1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1]]', [[1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1]], ['corrected', [0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1], 11]], ['partial-repair [[0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['corrected', [1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0], 5]], ['control [[1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]]', [[1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0]], ['uncorrectable', None, 14]], ['control [[1, 1, 1, 1, 1, 0, 1, 1, 1, 1]]', [[1, 1, 1, 1, 1, 0, 1, 1, 1, 1]], ['uncorrectable', None, 13]], ['control [[0, 0, 1, 0, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 0, 0, 0, 1, 0, 1, 0]], ['uncorrectable', None, 13]], ['control [[1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0]]', [[1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0]], ['uncorrectable', None, 14]], ['control [[1, 1, 1, 0, 1, 0, 0, 0, 1]]', [[1, 1, 1, 0, 1, 0, 0, 0, 1]], ['uncorrectable', None, 12]]], [['regression [[0, 0, 0, 1, 0, 0, 0, 1, 1]]', [[0, 0, 0, 1, 0, 0, 0, 1, 1]], ['corrected', [0, 1, 0, 0, 1], 5]], ['regression [[0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0]]', [[0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0]], ['corrected', [1, 0, 1, 1, 0, 1, 0, 1, 0], 6]], ['partial-repair [[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]]', [[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]], ['corrected', [0, 0, 1, 0, 1, 0, 1, 0], 1]], ['control [[0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0]]', [[0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0]], ['uncorrectable', None, 15]], ['control [[1, 1, 1, 1, 1, 1, 1]]', [[1, 1, 1, 1, 1, 1, 1]], ['clean', [1, 1, 1, 1], 0]], ['control [[0, 1]]', [[0, 1]], None], ['control [[0, 1, 2, 0, 0, 0, 0]]', [[0, 1, 2, 0, 0, 0, 0]], None], ['control [[0, 1, 1, 0, 0, 1, 1]]', [[0, 1, 1, 0, 0, 1, 1]], ['clean', [1, 0, 1, 1], 0]]]]
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 |
|---|---|---|---|
| regression [[0, 1, 1, 0, 1, 1, 1]] | ['corrected', [1, 0, 1, 1], 5] | ['corrected', [1, 0, 1, 1], 5] | Passed |
| regression [[1, 0, 0, 1, 0, 1, 0]] | ['corrected', [1, 0, 1, 0], 3] | ['corrected', [1, 0, 1, 0], 3] | Passed |
| partial-repair [[1, 1, 0, 1, 0, 1, 0]] | ['corrected', [0, 0, 1, 0], 1] | ['corrected', [0, 0, 1, 0], 1] | Passed |
| control [[0, 1, 1, 0, 0, 1, 1]] | ['clean', [1, 0, 1, 1], 0] | ['clean', [1, 0, 1, 1], 0] | Passed |
| control [[0, 1, 0, 1, 0, 1, 0]] | ['clean', [0, 0, 1, 0], 0] | ['clean', [0, 0, 1, 0], 0] | Passed |
| control [[1, 0, 0, 0, 0, 1, 1]] | ['clean', [0, 0, 1, 1], 0] | ['clean', [0, 0, 1, 1], 0] | Passed |
| control [[1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0]] | ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0] | ['clean', [0, 1, 1, 0, 1, 1, 1, 0], 0] | Passed |
| control [[1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0]] | ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0] | ['clean', [0, 1, 0, 0, 1, 1, 1, 0], 0] | Passed |
SHA-256 / d3cc911e63a22b17d6f22d2fe52706803406f39e47aed46f9d07d4cd12afcd27
Verification & scope
A deterministic, bounded teaching model of the named code under the stated contract; not a production codec. 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:48:33.202265+00:00.
Case digest / 5cfb0143b121b6c36f2a986f1eceba7804fe4a8347ed99f03db41f8644148593