FAILURE MAP
← Case archive

FA-62641 / Tax bracket computation / Open access

Carryforwards are consumed newest first · case 01

Old losses expire unused while recent losses are absorbed.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The carryforward list is iterated in reverse.

VERIFIED REPAIR

Apply the oldest carryforward first.

Unsuccessful approach: Applying the largest carryforward first is still not the stipulated oldest-first order.

Case contract

solve(years, life): years are pre-deduction incomes by year index (negative = operating loss). A loss year reports taxable 0 and creates a carryforward [origin, amount]. In an income year, carryforwards older than life years (year - origin > life) expire; the rest are applied oldest first, limited in total to floor(80% of that year's income). Return [taxable_by_year, remaining] where remaining lists [origin, amount] with amount > 0 not expired as of the final year.

Why this case matters

Tax computations hinge on which slice, threshold, ordering and rounding rule applies at each step; a misplaced boundary silently misstates liabilities.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(years, life):
    nols, out = [], []
    for y, inc in enumerate(years):
        if inc < 0:
            out.append(0)
            nols.append([y, -inc])
            continue
        nols = [n for n in nols if y - n[0] <= life]
        room = inc * 80 // 100
        for n in reversed(nols):
            use = min(n[1], room)
            n[1] -= use
            room -= use
            inc -= use
        out.append(inc)
    last = len(years) - 1
    return [out, [[o, a] for o, a in nols if a > 0 and last - o <= life]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression oldest-first 1', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, 31870, -10000], 5),
   [[0, 0, 4000, 6374, 0], [[0, 8504], [1, 10000], [4, 10000]]]),
  ('partial repair guard 1', ([5000, -3000, 4980, -1988, -10000, -10000, 20000], 5),
   [[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]),
  ('partial repair guard 2', ([60000, 0, -20645, -27117, 0, -50000, 20000], 5),
   [[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]])],
 [('regression oldest-first 1', ([5000, -3000, 4980, -1988, -10000, -10000, 20000], 5),
   [[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, -10000, 0], 20),
   [[0, 0, 4000, 0, 0], [[0, 34000], [1, 10000], [3, 10000]]]),
  ('partial repair guard 1', ([5000, 0, 20000, -3000, -33269, 5000, -10000], 5),
   [[5000, 0, 20000, 0, 0, 1000, 0], [[4, 32269], [6, 10000]]]),
  ('partial repair guard 2', ([-3000, -50000, 2641, -3000, -50000], 5),
   [[0, 0, 529, 0, 0], [[0, 888], [1, 50000], [3, 3000], [4, 50000]]]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]]),
  ('control: expiry boundary', ([-8000, 0, 5000], 2), [[0, 0, 1000], [[0, 4000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []])],
 [('regression oldest-first 1', ([60000, 0, -20645, -27117, 0, -50000, 20000], 5),
   [[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]),
  ('regression oldest-first 2', ([5000, 0, 20000, -3000, -33269, 5000, -10000], 5),
   [[5000, 0, 20000, 0, 0, 1000, 0], [[4, 32269], [6, 10000]]]),
  ('partial repair guard 1', ([30028, 20000, 20000, -10000, -36328, 5000], 3),
   [[30028, 20000, 20000, 0, 0, 1000], [[3, 6000], [4, 36328]]]),
  ('partial repair guard 2', ([-15248, -50000, -3000, -3000, 20000, -50000, 28420], 20),
   [[0, 0, 0, 0, 4000, 0, 5684], [[1, 26512], [2, 3000], [3, 3000], [5, 50000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []])],
 [('regression oldest-first 1', ([60880, -50000, -50000, 60000, -50000], 3),
   [[60880, 0, 0, 12000, 0], [[1, 2000], [2, 50000], [4, 50000]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, 5000], 20), [[0, 0, 4000, 1000], [[0, 30000], [1, 10000]]]),
  ('partial repair guard 1', ([14266, -3000, -3000, -10000, 5000], 20),
   [[14266, 0, 0, 0, 1000], [[2, 2000], [3, 10000]]]),
  ('partial repair guard 2', ([-10000, -21384, 5000], 5), [[0, 0, 1000], [[0, 6000], [1, 21384]]]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]]),
  ('control: expiry boundary', ([-8000, 0, 5000], 2), [[0, 0, 1000], [[0, 4000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]])],
 [('regression oldest-first 1', ([-50000, 0, 0, 0, -3000, 5000], 20), [[0, 0, 0, 0, 0, 1000], [[0, 46000], [4, 3000]]]),
  ('regression oldest-first 2', ([-3000, -50000, 2641, -3000, -50000], 5),
   [[0, 0, 529, 0, 0], [[0, 888], [1, 50000], [3, 3000], [4, 50000]]]),
  ('partial repair guard 1', ([60000, -3000, -10000, -10000, 20000, 0, 50091], 3),
   [[60000, 0, 0, 0, 4000, 0, 43091], []]),
  ('partial repair guard 2', ([20000, 0, -10000, -50000, 5000], 2), [[20000, 0, 0, 0, 1000], [[2, 6000], [3, 50000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []])]]
for label, args, expected in cases[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 fixtureActualExpectedOutcome
regression oldest-first 1[[10000, 0, 0, 1000, 1000], [[1, 2000]]][[10000, 0, 0, 1000, 1000], [[2, 2000]]]Failed
regression oldest-first 2[[0, 0, 4000, 6374, 0], [[0, 18504], [4, 10000]]][[0, 0, 4000, 6374, 0], [[0, 8504], [1, 10000], [4, 10000]]]Failed
partial repair guard 1[[5000, 0, 1980, 0, 0, 0, 4000], [[3, 1988], [4, 4000]]][[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]Failed
partial repair guard 2[[60000, 0, 0, 0, 0, 0, 4000], [[2, 20645], [3, 27117], [5, 34000]]][[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]Failed
control: fifo two years[[0, 1000, 14000], []][[0, 1000, 14000], []]Passed
control: two losses[[0, 0, 2000], []][[0, 0, 2000], []]Passed
control: expired[[0, 0, 0, 10000], []][[0, 0, 0, 10000], []]Passed
control: odd cap[[0, 2001], [[0, 42000]]][[0, 2001], [[0, 42000]]]Passed

SHA-256 / 6d68e6476544573b0e355ece8ba5a359a4b93e43b812abac6409895bae5831e2

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(years, life):
    nols, out = [], []
    for y, inc in enumerate(years):
        if inc < 0:
            out.append(0)
            nols.append([y, -inc])
            continue
        nols = [n for n in nols if y - n[0] <= life]
        room = inc * 80 // 100
        for n in sorted(nols, key=lambda n: -n[1]):
            use = min(n[1], room)
            n[1] -= use
            room -= use
            inc -= use
        out.append(inc)
    last = len(years) - 1
    return [out, [[o, a] for o, a in nols if a > 0 and last - o <= life]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression oldest-first 1', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, 31870, -10000], 5),
   [[0, 0, 4000, 6374, 0], [[0, 8504], [1, 10000], [4, 10000]]]),
  ('partial repair guard 1', ([5000, -3000, 4980, -1988, -10000, -10000, 20000], 5),
   [[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]),
  ('partial repair guard 2', ([60000, 0, -20645, -27117, 0, -50000, 20000], 5),
   [[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]])],
 [('regression oldest-first 1', ([5000, -3000, 4980, -1988, -10000, -10000, 20000], 5),
   [[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, -10000, 0], 20),
   [[0, 0, 4000, 0, 0], [[0, 34000], [1, 10000], [3, 10000]]]),
  ('partial repair guard 1', ([5000, 0, 20000, -3000, -33269, 5000, -10000], 5),
   [[5000, 0, 20000, 0, 0, 1000, 0], [[4, 32269], [6, 10000]]]),
  ('partial repair guard 2', ([-3000, -50000, 2641, -3000, -50000], 5),
   [[0, 0, 529, 0, 0], [[0, 888], [1, 50000], [3, 3000], [4, 50000]]]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]]),
  ('control: expiry boundary', ([-8000, 0, 5000], 2), [[0, 0, 1000], [[0, 4000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []])],
 [('regression oldest-first 1', ([60000, 0, -20645, -27117, 0, -50000, 20000], 5),
   [[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]),
  ('regression oldest-first 2', ([5000, 0, 20000, -3000, -33269, 5000, -10000], 5),
   [[5000, 0, 20000, 0, 0, 1000, 0], [[4, 32269], [6, 10000]]]),
  ('partial repair guard 1', ([30028, 20000, 20000, -10000, -36328, 5000], 3),
   [[30028, 20000, 20000, 0, 0, 1000], [[3, 6000], [4, 36328]]]),
  ('partial repair guard 2', ([-15248, -50000, -3000, -3000, 20000, -50000, 28420], 20),
   [[0, 0, 0, 0, 4000, 0, 5684], [[1, 26512], [2, 3000], [3, 3000], [5, 50000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []])],
 [('regression oldest-first 1', ([60880, -50000, -50000, 60000, -50000], 3),
   [[60880, 0, 0, 12000, 0], [[1, 2000], [2, 50000], [4, 50000]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, 5000], 20), [[0, 0, 4000, 1000], [[0, 30000], [1, 10000]]]),
  ('partial repair guard 1', ([14266, -3000, -3000, -10000, 5000], 20),
   [[14266, 0, 0, 0, 1000], [[2, 2000], [3, 10000]]]),
  ('partial repair guard 2', ([-10000, -21384, 5000], 5), [[0, 0, 1000], [[0, 6000], [1, 21384]]]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]]),
  ('control: expiry boundary', ([-8000, 0, 5000], 2), [[0, 0, 1000], [[0, 4000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]])],
 [('regression oldest-first 1', ([-50000, 0, 0, 0, -3000, 5000], 20), [[0, 0, 0, 0, 0, 1000], [[0, 46000], [4, 3000]]]),
  ('regression oldest-first 2', ([-3000, -50000, 2641, -3000, -50000], 5),
   [[0, 0, 529, 0, 0], [[0, 888], [1, 50000], [3, 3000], [4, 50000]]]),
  ('partial repair guard 1', ([60000, -3000, -10000, -10000, 20000, 0, 50091], 3),
   [[60000, 0, 0, 0, 4000, 0, 43091], []]),
  ('partial repair guard 2', ([20000, 0, -10000, -50000, 5000], 2), [[20000, 0, 0, 0, 1000], [[2, 6000], [3, 50000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []])]]
for label, args, expected in cases[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 fixtureActualExpectedOutcome
regression oldest-first 1[[10000, 0, 0, 1000, 1000], [[2, 2000]]][[10000, 0, 0, 1000, 1000], [[2, 2000]]]Passed
regression oldest-first 2[[0, 0, 4000, 6374, 0], [[0, 8504], [1, 10000], [4, 10000]]][[0, 0, 4000, 6374, 0], [[0, 8504], [1, 10000], [4, 10000]]]Passed
partial repair guard 1[[5000, 0, 1980, 0, 0, 0, 4000], [[3, 1988], [5, 4000]]][[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]Failed
partial repair guard 2[[60000, 0, 0, 0, 0, 0, 4000], [[2, 20645], [3, 27117], [5, 34000]]][[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]Failed
control: fifo two years[[0, 1000, 14000], []][[0, 1000, 14000], []]Passed
control: two losses[[0, 0, 2000], []][[0, 0, 2000], []]Passed
control: expired[[0, 0, 0, 10000], []][[0, 0, 0, 10000], []]Passed
control: odd cap[[0, 2001], [[0, 42000]]][[0, 2001], [[0, 42000]]]Passed

SHA-256 / 6bccd352b4956372ec39c1a0185d7cc38c833beee90d5cbb0accffa818461dbb

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(years, life):
    nols, out = [], []
    for y, inc in enumerate(years):
        if inc < 0:
            out.append(0)
            nols.append([y, -inc])
            continue
        nols = [n for n in nols if y - n[0] <= life]
        room = inc * 80 // 100
        for n in nols:
            use = min(n[1], room)
            n[1] -= use
            room -= use
            inc -= use
        out.append(inc)
    last = len(years) - 1
    return [out, [[o, a] for o, a in nols if a > 0 and last - o <= life]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression oldest-first 1', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, 31870, -10000], 5),
   [[0, 0, 4000, 6374, 0], [[0, 8504], [1, 10000], [4, 10000]]]),
  ('partial repair guard 1', ([5000, -3000, 4980, -1988, -10000, -10000, 20000], 5),
   [[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]),
  ('partial repair guard 2', ([60000, 0, -20645, -27117, 0, -50000, 20000], 5),
   [[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]])],
 [('regression oldest-first 1', ([5000, -3000, 4980, -1988, -10000, -10000, 20000], 5),
   [[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, -10000, 0], 20),
   [[0, 0, 4000, 0, 0], [[0, 34000], [1, 10000], [3, 10000]]]),
  ('partial repair guard 1', ([5000, 0, 20000, -3000, -33269, 5000, -10000], 5),
   [[5000, 0, 20000, 0, 0, 1000, 0], [[4, 32269], [6, 10000]]]),
  ('partial repair guard 2', ([-3000, -50000, 2641, -3000, -50000], 5),
   [[0, 0, 529, 0, 0], [[0, 888], [1, 50000], [3, 3000], [4, 50000]]]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]]),
  ('control: expiry boundary', ([-8000, 0, 5000], 2), [[0, 0, 1000], [[0, 4000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []])],
 [('regression oldest-first 1', ([60000, 0, -20645, -27117, 0, -50000, 20000], 5),
   [[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]),
  ('regression oldest-first 2', ([5000, 0, 20000, -3000, -33269, 5000, -10000], 5),
   [[5000, 0, 20000, 0, 0, 1000, 0], [[4, 32269], [6, 10000]]]),
  ('partial repair guard 1', ([30028, 20000, 20000, -10000, -36328, 5000], 3),
   [[30028, 20000, 20000, 0, 0, 1000], [[3, 6000], [4, 36328]]]),
  ('partial repair guard 2', ([-15248, -50000, -3000, -3000, 20000, -50000, 28420], 20),
   [[0, 0, 0, 0, 4000, 0, 5684], [[1, 26512], [2, 3000], [3, 3000], [5, 50000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []])],
 [('regression oldest-first 1', ([60880, -50000, -50000, 60000, -50000], 3),
   [[60880, 0, 0, 12000, 0], [[1, 2000], [2, 50000], [4, 50000]]]),
  ('regression oldest-first 2', ([-50000, -10000, 20000, 5000], 20), [[0, 0, 4000, 1000], [[0, 30000], [1, 10000]]]),
  ('partial repair guard 1', ([14266, -3000, -3000, -10000, 5000], 20),
   [[14266, 0, 0, 0, 1000], [[2, 2000], [3, 10000]]]),
  ('partial repair guard 2', ([-10000, -21384, 5000], 5), [[0, 0, 1000], [[0, 6000], [1, 21384]]]),
  ('control: expired', ([-10000, 0, 0, 10000], 2), [[0, 0, 0, 10000], []]),
  ('control: odd cap', ([-50000, 10001], 5), [[0, 2001], [[0, 42000]]]),
  ('control: expiry boundary', ([-8000, 0, 5000], 2), [[0, 0, 1000], [[0, 4000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]])],
 [('regression oldest-first 1', ([-50000, 0, 0, 0, -3000, 5000], 20), [[0, 0, 0, 0, 0, 1000], [[0, 46000], [4, 3000]]]),
  ('regression oldest-first 2', ([-3000, -50000, 2641, -3000, -50000], 5),
   [[0, 0, 529, 0, 0], [[0, 888], [1, 50000], [3, 3000], [4, 50000]]]),
  ('partial repair guard 1', ([60000, -3000, -10000, -10000, 20000, 0, 50091], 3),
   [[60000, 0, 0, 0, 4000, 0, 43091], []]),
  ('partial repair guard 2', ([20000, 0, -10000, -50000, 5000], 2), [[20000, 0, 0, 0, 1000], [[2, 6000], [3, 50000]]]),
  ('control: losses after income', ([10000, -4000, -6000, 5000, 5000], 3), [[10000, 0, 0, 1000, 1000], [[2, 2000]]]),
  ('control: no losses', ([1000, 2000], 1), [[1000, 2000], []]),
  ('control: fifo two years', ([-10000, 5000, 20000], 5), [[0, 1000, 14000], []]),
  ('control: two losses', ([-5000, -3000, 10000], 5), [[0, 0, 2000], []])]]
for label, args, expected in cases[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 fixtureActualExpectedOutcome
regression oldest-first 1[[10000, 0, 0, 1000, 1000], [[2, 2000]]][[10000, 0, 0, 1000, 1000], [[2, 2000]]]Passed
regression oldest-first 2[[0, 0, 4000, 6374, 0], [[0, 8504], [1, 10000], [4, 10000]]][[0, 0, 4000, 6374, 0], [[0, 8504], [1, 10000], [4, 10000]]]Passed
partial repair guard 1[[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]][[5000, 0, 1980, 0, 0, 0, 4000], [[5, 5988]]]Passed
partial repair guard 2[[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]][[60000, 0, 0, 0, 0, 0, 4000], [[2, 4645], [3, 27117], [5, 50000]]]Passed
control: fifo two years[[0, 1000, 14000], []][[0, 1000, 14000], []]Passed
control: two losses[[0, 0, 2000], []][[0, 0, 2000], []]Passed
control: expired[[0, 0, 0, 10000], []][[0, 0, 0, 10000], []]Passed
control: odd cap[[0, 2001], [[0, 42000]]][[0, 2001], [[0, 42000]]]Passed

SHA-256 / 5d31eae7ec584cb9f686195eb4ffa4625a4183520d9467267b67d5d2a3935914

Verification & scope

A deterministic, bounded teaching model with a stipulated toy contract; it makes no claim of conformance to any real regulation, standard, or institution's rules. 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:47:06.611985+00:00.

Case digest / 81e0b3fa4fde0937beae0e107db077745eaf8fa8cebee1c12933fb6b1909051e