FA-11451 / Compiler transformation correctness / Open access
Expression numbering commutes subtraction operands · case 01
Expression numbering commutes subtraction operands.
ROOT CAUSE
Canonicalization sorts operands for every binary opcode.
VERIFIED REPAIR
Sort only operands of declared commutative integer operations.
Unsuccessful approach: Special casing subtraction still commutes division.
Case contract
Return an expression key [opcode, operand1, operand2]; add and mul commute, sub and div preserve order. Operands are integer value numbers.
Why this case matters
A deterministic miniature compiler-pass model; inputs are explicit IR facts, not a production compiler.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(op, a, b):
return [op] + sorted([a,b])
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('add canonical', solve('add',N+1,N), ['add',N,N+1])
check('multiply canonical', solve('mul',N+1,N), ['mul',N,N+1])
check('sub ordered', solve('sub',N+1,N), ['sub',N+1,N])
check('div ordered', solve('div',N+1,N), ['div',N+1,N])
check('equal operands', solve('div',N,N), ['div',N,N])
check('already canonical', solve('add',0,N), ['add',0,N])
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 |
|---|---|---|---|
| add canonical | ['add', 1, 2] | ['add', 1, 2] | Passed |
| multiply canonical | ['mul', 1, 2] | ['mul', 1, 2] | Passed |
| sub ordered | ['sub', 1, 2] | ['sub', 2, 1] | Failed |
| div ordered | ['div', 1, 2] | ['div', 2, 1] | Failed |
| equal operands | ['div', 1, 1] | ['div', 1, 1] | Passed |
| already canonical | ['add', 0, 1] | ['add', 0, 1] | Passed |
SHA-256 / ce6aa54788b5383dd9bf731b7b0f6e71d8c7af18f88d88a429ac608b0246c7f8
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(op, a, b):
return [op,a,b] if op == 'sub' else [op] + sorted([a,b])
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('add canonical', solve('add',N+1,N), ['add',N,N+1])
check('multiply canonical', solve('mul',N+1,N), ['mul',N,N+1])
check('sub ordered', solve('sub',N+1,N), ['sub',N+1,N])
check('div ordered', solve('div',N+1,N), ['div',N+1,N])
check('equal operands', solve('div',N,N), ['div',N,N])
check('already canonical', solve('add',0,N), ['add',0,N])
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 |
|---|---|---|---|
| add canonical | ['add', 1, 2] | ['add', 1, 2] | Passed |
| multiply canonical | ['mul', 1, 2] | ['mul', 1, 2] | Passed |
| sub ordered | ['sub', 2, 1] | ['sub', 2, 1] | Passed |
| div ordered | ['div', 1, 2] | ['div', 2, 1] | Failed |
| equal operands | ['div', 1, 1] | ['div', 1, 1] | Passed |
| already canonical | ['add', 0, 1] | ['add', 0, 1] | Passed |
SHA-256 / 317835bb601653acda33ba84a5ac9099e835bd0cefa9e2fcbb35cc0f1c0e20ea
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(op, a, b):
return [op] + (sorted([a,b]) if op in ('add','mul') else [a,b])
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('add canonical', solve('add',N+1,N), ['add',N,N+1])
check('multiply canonical', solve('mul',N+1,N), ['mul',N,N+1])
check('sub ordered', solve('sub',N+1,N), ['sub',N+1,N])
check('div ordered', solve('div',N+1,N), ['div',N+1,N])
check('equal operands', solve('div',N,N), ['div',N,N])
check('already canonical', solve('add',0,N), ['add',0,N])
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 |
|---|---|---|---|
| add canonical | ['add', 1, 2] | ['add', 1, 2] | Passed |
| multiply canonical | ['mul', 1, 2] | ['mul', 1, 2] | Passed |
| sub ordered | ['sub', 2, 1] | ['sub', 2, 1] | Passed |
| div ordered | ['div', 2, 1] | ['div', 2, 1] | Passed |
| equal operands | ['div', 1, 1] | ['div', 1, 1] | Passed |
| already canonical | ['add', 0, 1] | ['add', 0, 1] | Passed |
SHA-256 / c2f6b22cedaf34e8e4c239f7ef98eb38ca7c5c8ab1d4e0979d59944d3bc801d8
Verification & scope
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:38:48.066431+00:00.
Case digest / fb46ebcbdfaa12b1e63d2eeeb8188a8ec52f73bd5128f109886d4ff7cf07d78a