FAILURE MAP
← Case archive

FA-62466 / Tax bracket computation / Open access

Carryforward credits are consumed before ordinary nonrefundable credits · case 01

Expiring nonrefundable credits are wasted while carryable credits are used up.

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

ROOT CAUSE

The carry credits are applied first, leaving less tax for credits that cannot be carried.

VERIFIED REPAIR

Apply nonref credits first, then carry credits.

Unsuccessful approach: Applying refundable credits first leaves no tax for the nonrefundable credits to reduce.

Case contract

solve(tax, credits): tax is integer cents >= 0; credits is a list of [kind, cents] with kind 'nonref' (nonrefundable, unused part lost), 'carry' (nonrefundable, unused part carried forward) or 'ref' (refundable). Unknown kinds return 'ERR:kind'. Apply all nonref credits first (limited to the remaining tax), then carry credits (limited to what remains), then refundable credits in full (a negative result is a refund). Return [final_tax, carryforward].

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(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    use_n = min(n, t)
    t -= use_n
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonref-before-carry 1', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('regression nonref-before-carry 2', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('partial repair guard 2', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'), ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (1467, [['nonref', 0], ['carry', 50], ['nonref', 2387]]), [0, 50]),
  ('regression nonref-before-carry 2', (1000, [['carry', 300], ['nonref', 100], ['nonref', 100], ['nonref', 765]]),
   [0, 265]),
  ('partial repair guard 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('partial repair guard 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (100, [['carry', 300], ['nonref', 300], ['carry', 50], ['nonref', 2635]]),
   [0, 350]),
  ('regression nonref-before-carry 2', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 1', (500, [['ref', 300], ['carry', 2443]]), [-300, 1943]),
  ('partial repair guard 2', (500, [['carry', 100], ['nonref', 100], ['ref', 634], ['nonref', 100]]), [-434, 0]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression nonref-before-carry 1', (1000, [['carry', 0], ['nonref', 1810], ['carry', 123]]), [0, 123]),
  ('regression nonref-before-carry 2', (100, [['nonref', 300], ['carry', 853], ['carry', 0]]), [0, 853]),
  ('partial repair guard 1', (500, [['ref', 1249], ['ref', 300], ['carry', 300], ['carry', 1980]]), [-1549, 1780]),
  ('partial repair guard 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression nonref-before-carry 1', (100, [['nonref', 50], ['carry', 100], ['ref', 0]]), [0, 50]),
  ('regression nonref-before-carry 2', (500, [['nonref', 100], ['carry', 300], ['carry', 300]]), [0, 200]),
  ('partial repair guard 1', (100, [['ref', 50], ['nonref', 300], ['ref', 380]]), [-430, 0]),
  ('partial repair guard 2', (1000, [['ref', 2008], ['ref', 50], ['nonref', 100]]), [-1158, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
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 nonref-before-carry 1[-300, 0][-300, 200]Failed
regression nonref-before-carry 2[0, 0][0, 200]Failed
partial repair guard 2[-100, 0][-100, 0]Passed
control: refund[-200, 0][-200, 0]Passed
control: no tax carry[0, 50][0, 50]Passed
control: unknown kindERR:kindERR:kindPassed
control: empty[1234, 0][1234, 0]Passed

SHA-256 / a05e01592d3c6cc78f953ba7f0bbf119a5298ad41b2bbbd4ccd8178cc8d8fb15

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    t -= r
    use_n = min(n, max(0, t))
    t -= use_n
    use_c = min(c, max(0, t))
    t -= use_c
    cf = c - use_c
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonref-before-carry 1', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('regression nonref-before-carry 2', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('partial repair guard 2', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'), ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (1467, [['nonref', 0], ['carry', 50], ['nonref', 2387]]), [0, 50]),
  ('regression nonref-before-carry 2', (1000, [['carry', 300], ['nonref', 100], ['nonref', 100], ['nonref', 765]]),
   [0, 265]),
  ('partial repair guard 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('partial repair guard 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (100, [['carry', 300], ['nonref', 300], ['carry', 50], ['nonref', 2635]]),
   [0, 350]),
  ('regression nonref-before-carry 2', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 1', (500, [['ref', 300], ['carry', 2443]]), [-300, 1943]),
  ('partial repair guard 2', (500, [['carry', 100], ['nonref', 100], ['ref', 634], ['nonref', 100]]), [-434, 0]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression nonref-before-carry 1', (1000, [['carry', 0], ['nonref', 1810], ['carry', 123]]), [0, 123]),
  ('regression nonref-before-carry 2', (100, [['nonref', 300], ['carry', 853], ['carry', 0]]), [0, 853]),
  ('partial repair guard 1', (500, [['ref', 1249], ['ref', 300], ['carry', 300], ['carry', 1980]]), [-1549, 1780]),
  ('partial repair guard 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression nonref-before-carry 1', (100, [['nonref', 50], ['carry', 100], ['ref', 0]]), [0, 50]),
  ('regression nonref-before-carry 2', (500, [['nonref', 100], ['carry', 300], ['carry', 300]]), [0, 200]),
  ('partial repair guard 1', (100, [['ref', 50], ['nonref', 300], ['ref', 380]]), [-430, 0]),
  ('partial repair guard 2', (1000, [['ref', 2008], ['ref', 50], ['nonref', 100]]), [-1158, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
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 nonref-before-carry 1[0, 500][-300, 200]Failed
regression nonref-before-carry 2[0, 200][0, 200]Passed
partial repair guard 2[0, 0][-100, 0]Failed
control: refund[-200, 0][-200, 0]Passed
control: no tax carry[0, 50][0, 50]Passed
control: unknown kindERR:kindERR:kindPassed
control: empty[1234, 0][1234, 0]Passed

SHA-256 / 64d6ee47d54c212ec8e0d1384921c739f7e3817de89cb51b76b4d5a3b67dc169

3 / The verified repair

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

N = 1
observations = []
def solve(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = min(n, t)
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonref-before-carry 1', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('regression nonref-before-carry 2', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('partial repair guard 2', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'), ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (1467, [['nonref', 0], ['carry', 50], ['nonref', 2387]]), [0, 50]),
  ('regression nonref-before-carry 2', (1000, [['carry', 300], ['nonref', 100], ['nonref', 100], ['nonref', 765]]),
   [0, 265]),
  ('partial repair guard 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('partial repair guard 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (100, [['carry', 300], ['nonref', 300], ['carry', 50], ['nonref', 2635]]),
   [0, 350]),
  ('regression nonref-before-carry 2', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 1', (500, [['ref', 300], ['carry', 2443]]), [-300, 1943]),
  ('partial repair guard 2', (500, [['carry', 100], ['nonref', 100], ['ref', 634], ['nonref', 100]]), [-434, 0]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression nonref-before-carry 1', (1000, [['carry', 0], ['nonref', 1810], ['carry', 123]]), [0, 123]),
  ('regression nonref-before-carry 2', (100, [['nonref', 300], ['carry', 853], ['carry', 0]]), [0, 853]),
  ('partial repair guard 1', (500, [['ref', 1249], ['ref', 300], ['carry', 300], ['carry', 1980]]), [-1549, 1780]),
  ('partial repair guard 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression nonref-before-carry 1', (100, [['nonref', 50], ['carry', 100], ['ref', 0]]), [0, 50]),
  ('regression nonref-before-carry 2', (500, [['nonref', 100], ['carry', 300], ['carry', 300]]), [0, 200]),
  ('partial repair guard 1', (100, [['ref', 50], ['nonref', 300], ['ref', 380]]), [-430, 0]),
  ('partial repair guard 2', (1000, [['ref', 2008], ['ref', 50], ['nonref', 100]]), [-1158, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
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 nonref-before-carry 1[-300, 200][-300, 200]Passed
regression nonref-before-carry 2[0, 200][0, 200]Passed
partial repair guard 2[-100, 0][-100, 0]Passed
control: refund[-200, 0][-200, 0]Passed
control: no tax carry[0, 50][0, 50]Passed
control: unknown kindERR:kindERR:kindPassed
control: empty[1234, 0][1234, 0]Passed

SHA-256 / c8bd0344c2ac9f90cecc833ad13fab8c8c198e0bef52ba730ea7b20470694e0d

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:04.947475+00:00.

Case digest / fd0c3d2bf29a235533a1f299063de2759f2520c1b9883095df48d7f91860659c