FAILURE MAP
← Case archive

FA-62341 / Tax bracket computation / Open access

The whole income is taxed at the rate of its highest bracket · case 01

Crossing a threshold by one dollar raises tax on every dollar of income.

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

ROOT CAUSE

The bracket containing the income is located and its rate applied to the full income.

VERIFIED REPAIR

Tax each slice of income only at its own bracket rate.

Unsuccessful approach: Taxing the first bracket at its own rate and the rest at the top rate is right only for two-bracket schedules.

Case contract

solve(income, brackets): brackets is [[upper, rate_percent], ...] with strictly increasing positive uppers and a final open bracket [None, rate]; otherwise return 'ERR:brackets'. Each rate applies only to the slice of income in (previous upper, upper]. Negative income is taxed as zero. The tax is summed exactly and rounded half-up to cents once, returned as integer cents.

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
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    if any(b <= a for a, b in zip([0] + uppers, uppers)): return 'ERR:brackets'
    x = max(0, income)
    tax, lower = Fraction(0), 0
    for upper, rate in brackets:
        if upper is None or x <= upper:
            tax = x * Fraction(rate) / 100
            break
    return int(tax * 100 + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression whole-income-at-top-rate 1', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('regression whole-income-at-top-rate 2',
   (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 126140),
  ('partial repair guard 2', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets')],
 [('regression whole-income-at-top-rate 1', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('regression whole-income-at-top-rate 2',
   (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 5917183),
  ('partial repair guard 2', (232540, [[34000, '22'], [101000, '15'], [147000, '10'], [184000, '10'], [None, '30']]),
   4039200),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets')],
 [('regression whole-income-at-top-rate 1',
   (232540, [[34000, '22'], [101000, '15'], [147000, '10'], [184000, '10'], [None, '30']]), 4039200),
  ('regression whole-income-at-top-rate 2',
   (236107, [[31000, '10'], [159000, '10'], [172000, '24'], [193000, '22'], [None, '45']]), 4303815),
  ('partial repair guard 2', (221539, [[9000, '24'], [72000, '5'], [91000, '33.3'], [101000, '5'], [None, '37']]),
   5673643),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression whole-income-at-top-rate 1',
   (221539, [[9000, '24'], [72000, '5'], [91000, '33.3'], [101000, '5'], [None, '37']]), 5673643),
  ('regression whole-income-at-top-rate 2',
   (64068, [[32000, '22'], [105000, '10'], [170000, '24'], [193000, '10'], [None, '37']]), 1024680),
  ('partial repair guard 1', (161544, [[108000, '22'], [122000, '12.5'], [192000, '10'], [None, '30']]), 2946440),
  ('partial repair guard 2', (156576, [[30000, '5'], [111000, '15'], [None, '30']]), 2732280),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression whole-income-at-top-rate 1', (161544, [[108000, '22'], [122000, '12.5'], [192000, '10'], [None, '30']]),
   2946440),
  ('regression whole-income-at-top-rate 2', (84182, [[82000, '12.5'], [138000, '22'], [161000, '15'], [None, '37']]),
   1073004),
  ('partial repair guard 1', (135000, [[30000, '15'], [126000, '12.5'], [None, '30']]), 1920000),
  ('partial repair guard 2', (259309, [[57000, '24'], [175000, '5'], [None, '30']]), 4487270),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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 whole-income-at-top-rate 11100000680000Failed
regression whole-income-at-top-rate 2148140126140Failed
partial repair guard 2880022460022Failed
control: at first threshold100000100000Passed
control: zero00Passed
control: negative00Passed
control: non increasingERR:bracketsERR:bracketsPassed

SHA-256 / 6540d615120056133110b04abbda4195d53ebcfae52cd9b05560ce7073f90091

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    if any(b <= a for a, b in zip([0] + uppers, uppers)): return 'ERR:brackets'
    x = max(0, income)
    tax, lower = Fraction(0), 0
    fu, fr = brackets[0]
    for upper, rate in brackets:
        if upper is None or x <= upper:
            cut = x if fu is None else min(x, fu)
            tax = cut * Fraction(fr) / 100 + (x - cut) * Fraction(rate) / 100
            break
    return int(tax * 100 + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression whole-income-at-top-rate 1', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('regression whole-income-at-top-rate 2',
   (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 126140),
  ('partial repair guard 2', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets')],
 [('regression whole-income-at-top-rate 1', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('regression whole-income-at-top-rate 2',
   (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 5917183),
  ('partial repair guard 2', (232540, [[34000, '22'], [101000, '15'], [147000, '10'], [184000, '10'], [None, '30']]),
   4039200),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets')],
 [('regression whole-income-at-top-rate 1',
   (232540, [[34000, '22'], [101000, '15'], [147000, '10'], [184000, '10'], [None, '30']]), 4039200),
  ('regression whole-income-at-top-rate 2',
   (236107, [[31000, '10'], [159000, '10'], [172000, '24'], [193000, '22'], [None, '45']]), 4303815),
  ('partial repair guard 2', (221539, [[9000, '24'], [72000, '5'], [91000, '33.3'], [101000, '5'], [None, '37']]),
   5673643),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression whole-income-at-top-rate 1',
   (221539, [[9000, '24'], [72000, '5'], [91000, '33.3'], [101000, '5'], [None, '37']]), 5673643),
  ('regression whole-income-at-top-rate 2',
   (64068, [[32000, '22'], [105000, '10'], [170000, '24'], [193000, '10'], [None, '37']]), 1024680),
  ('partial repair guard 1', (161544, [[108000, '22'], [122000, '12.5'], [192000, '10'], [None, '30']]), 2946440),
  ('partial repair guard 2', (156576, [[30000, '5'], [111000, '15'], [None, '30']]), 2732280),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression whole-income-at-top-rate 1', (161544, [[108000, '22'], [122000, '12.5'], [192000, '10'], [None, '30']]),
   2946440),
  ('regression whole-income-at-top-rate 2', (84182, [[82000, '12.5'], [138000, '22'], [161000, '15'], [None, '37']]),
   1073004),
  ('partial repair guard 1', (135000, [[30000, '15'], [126000, '12.5'], [None, '30']]), 1920000),
  ('partial repair guard 2', (259309, [[57000, '24'], [175000, '5'], [None, '30']]), 4487270),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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 whole-income-at-top-rate 1980000680000Failed
regression whole-income-at-top-rate 2126140126140Passed
partial repair guard 2760022460022Failed
control: at first threshold100000100000Passed
control: zero00Passed
control: negative00Passed
control: non increasingERR:bracketsERR:bracketsPassed

SHA-256 / fb53132ad5c09160c5f8f71a8dddf0331eec4e9a7393083110af907945e438f9

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    if not brackets or brackets[-1][0] is not None: return 'ERR:brackets'
    uppers = [u for u, _ in brackets[:-1]]
    if any(b <= a for a, b in zip([0] + uppers, uppers)): return 'ERR:brackets'
    x = max(0, income)
    tax, lower = Fraction(0), 0
    for upper, rate in brackets:
        top = x if upper is None else min(x, upper)
        if top > lower:
            tax += (top - lower) * Fraction(rate) / 100
        if upper is None or x <= upper: break
        lower = upper
    return int(tax * 100 + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression whole-income-at-top-rate 1', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('regression whole-income-at-top-rate 2',
   (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 126140),
  ('partial repair guard 2', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets')],
 [('regression whole-income-at-top-rate 1', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('regression whole-income-at-top-rate 2',
   (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 5917183),
  ('partial repair guard 2', (232540, [[34000, '22'], [101000, '15'], [147000, '10'], [184000, '10'], [None, '30']]),
   4039200),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets')],
 [('regression whole-income-at-top-rate 1',
   (232540, [[34000, '22'], [101000, '15'], [147000, '10'], [184000, '10'], [None, '30']]), 4039200),
  ('regression whole-income-at-top-rate 2',
   (236107, [[31000, '10'], [159000, '10'], [172000, '24'], [193000, '22'], [None, '45']]), 4303815),
  ('partial repair guard 2', (221539, [[9000, '24'], [72000, '5'], [91000, '33.3'], [101000, '5'], [None, '37']]),
   5673643),
  ('control: non increasing', (10000, [[10000, '10'], [5000, '20'], [None, '30']]), 'ERR:brackets'),
  ('control: closed top', (10, [[10000, '10'], [20000, '20']]), 'ERR:brackets'),
  ('control: high earner', (250001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   5917183),
  ('control: single bracket', (777, [[None, '12.5']]), 9713)],
 [('regression whole-income-at-top-rate 1',
   (221539, [[9000, '24'], [72000, '5'], [91000, '33.3'], [101000, '5'], [None, '37']]), 5673643),
  ('regression whole-income-at-top-rate 2',
   (64068, [[32000, '22'], [105000, '10'], [170000, '24'], [193000, '10'], [None, '37']]), 1024680),
  ('partial repair guard 1', (161544, [[108000, '22'], [122000, '12.5'], [192000, '10'], [None, '30']]), 2946440),
  ('partial repair guard 2', (156576, [[30000, '5'], [111000, '15'], [None, '30']]), 2732280),
  ('control: single bracket', (777, [[None, '12.5']]), 9713),
  ('control: three brackets', (50000, [[10000, '10'], [40000, '12'], [None, '22']]), 680000),
  ('control: at first threshold', (10000, [[10000, '10'], [40000, '12'], [None, '22']]), 100000),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression whole-income-at-top-rate 1', (161544, [[108000, '22'], [122000, '12.5'], [192000, '10'], [None, '30']]),
   2946440),
  ('regression whole-income-at-top-rate 2', (84182, [[82000, '12.5'], [138000, '22'], [161000, '15'], [None, '37']]),
   1073004),
  ('partial repair guard 1', (135000, [[30000, '15'], [126000, '12.5'], [None, '30']]), 1920000),
  ('partial repair guard 2', (259309, [[57000, '24'], [175000, '5'], [None, '30']]), 4487270),
  ('control: zero', (0, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: negative', (-5, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: one over threshold', (40001, [[10000, '10'], [40000, '12'], [None, '22']]), 460022),
  ('control: fractional rate', (12345, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   126140)]]
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 whole-income-at-top-rate 1680000680000Passed
regression whole-income-at-top-rate 2126140126140Passed
partial repair guard 2460022460022Passed
control: at first threshold100000100000Passed
control: zero00Passed
control: negative00Passed
control: non increasingERR:bracketsERR:bracketsPassed

SHA-256 / e56f08472f30f6873a7642077dde7d6d396fc9729f3d2fe6486f212164e28f20

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

Case digest / 9f3038b905061285c26cf093fbf70608704359e2333fd2f408fdd0ecec5064ab