broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(gross, deduction, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    taxable = max(0, gross - deduction)
    tax = prog(taxable, brackets)
    if False:
        marginal = '0'
    else:
        marginal = next(rate for upper, rate in brackets if upper is None or taxable <= upper)
    eff = cents(tax * 100 / gross) if gross > 0 else 0
    return [marginal, eff]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression unused-deduction-marginal 1', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('regression unused-deduction-marginal 2',
   (0, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('partial repair guard 2',
   (10000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression unused-deduction-marginal 1',
   (10000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('regression unused-deduction-marginal 2', (1000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('partial repair guard 2',
   (13000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression unused-deduction-marginal 1',
   (13000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('regression unused-deduction-marginal 2',
   (1000, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('partial repair guard 2', (13000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360])],
 [('regression unused-deduction-marginal 1', (13000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('regression unused-deduction-marginal 2', (1000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('partial repair guard 2',
   (1000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression unused-deduction-marginal 1',
   (1000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('regression unused-deduction-marginal 2', (0, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('partial repair guard 1', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('partial repair guard 2',
   (10000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(gross, deduction, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    taxable = max(0, gross - deduction)
    tax = prog(taxable, brackets)
    if gross == 0 and deduction > 0:
        marginal = '0'
    else:
        marginal = next(rate for upper, rate in brackets if upper is None or taxable <= upper)
    eff = cents(tax * 100 / gross) if gross > 0 else 0
    return [marginal, eff]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression unused-deduction-marginal 1', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('regression unused-deduction-marginal 2',
   (0, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('partial repair guard 2',
   (10000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression unused-deduction-marginal 1',
   (10000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('regression unused-deduction-marginal 2', (1000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('partial repair guard 2',
   (13000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression unused-deduction-marginal 1',
   (13000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('regression unused-deduction-marginal 2',
   (1000, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('partial repair guard 2', (13000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360])],
 [('regression unused-deduction-marginal 1', (13000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('regression unused-deduction-marginal 2', (1000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('partial repair guard 2',
   (1000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression unused-deduction-marginal 1',
   (1000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('regression unused-deduction-marginal 2', (0, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('partial repair guard 1', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('partial repair guard 2',
   (10000, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])]]
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)

prompt:
A filer earning below the deduction is told the next dollar is taxed at 10%.

solve(gross, deduction, brackets): taxable = max(0, gross - deduction); tax uses the progressive slices. The marginal rate is the rate of the bracket containing taxable income with (lower, upper] semantics (income exactly at a threshold is in the lower bracket), and is '0' when gross < deduction (unused deduction absorbs the next dollar; at gross == deduction the next dollar is taxed at the first rate). The effective rate is tax / gross in basis points rounded half-up (0 when gross <= 0). Return [marginal_rate_string, effective_bps].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    if income < 5: return 0
    if income >= 100000: return cents(prog(income, brackets))
    w = 25 if income < 3000 else 50
    lo = income // w * w
    mid = lo
    return int(prog(mid, brackets) + Fraction(1, 2)) * 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression band-midpoint 1', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('regression band-midpoint 2', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('partial repair guard 2', (24, [[None, '10']]), 100),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100)],
 [('regression band-midpoint 1', (24, [[None, '10']]), 100),
  ('regression band-midpoint 2', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 1', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('partial repair guard 2', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024)],
 [('regression band-midpoint 1', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('regression band-midpoint 2', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('partial repair guard 1', (603, [[10000, '10'], [40000, '12'], [None, '22']]), 6100),
  ('partial repair guard 2', (5, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 100),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024),
  ('control: band edge', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300)],
 [('regression band-midpoint 1', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('regression band-midpoint 2', (61548, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   884300),
  ('partial repair guard 1', (2999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   29900),
  ('partial repair guard 2', (1821, [[10000, '10'], [40000, '12'], [None, '22']]), 18100),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000)],
 [('regression band-midpoint 1', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('regression band-midpoint 2', (603, [[10000, '10'], [40000, '12'], [None, '22']]), 6100),
  ('partial repair guard 1', (1428, [[10000, '10'], [40000, '12'], [None, '22']]), 14400),
  ('partial repair guard 2', (12, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    if income < 5: return 0
    if income >= 100000: return cents(prog(income, brackets))
    w = 25 if income < 3000 else 50
    lo = income // w * w
    mid = lo + 25
    return int(prog(mid, brackets) + Fraction(1, 2)) * 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression band-midpoint 1', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('regression band-midpoint 2', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('partial repair guard 2', (24, [[None, '10']]), 100),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100)],
 [('regression band-midpoint 1', (24, [[None, '10']]), 100),
  ('regression band-midpoint 2', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 1', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('partial repair guard 2', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024)],
 [('regression band-midpoint 1', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('regression band-midpoint 2', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('partial repair guard 1', (603, [[10000, '10'], [40000, '12'], [None, '22']]), 6100),
  ('partial repair guard 2', (5, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 100),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024),
  ('control: band edge', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300)],
 [('regression band-midpoint 1', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('regression band-midpoint 2', (61548, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   884300),
  ('partial repair guard 1', (2999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   29900),
  ('partial repair guard 2', (1821, [[10000, '10'], [40000, '12'], [None, '22']]), 18100),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000)],
 [('regression band-midpoint 1', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('regression band-midpoint 2', (603, [[10000, '10'], [40000, '12'], [None, '22']]), 6100),
  ('partial repair guard 1', (1428, [[10000, '10'], [40000, '12'], [None, '22']]), 14400),
  ('partial repair guard 2', (12, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)]]
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)

prompt:
Tax-table amounts are systematically a few dollars low.

solve(income, brackets): stipulated tax-table lookup. income < 0 returns 0 and incomes below 5 have zero tax. For income < 100000 the tax is the progressive tax on the midpoint of the income's band, rounded half-up to whole dollars: bands are 25 wide below 3000 ([0,25), [25,50), ...) and 50 wide from 3000 ([3000,3050), ...). Incomes of 100000 or more use the exact progressive tax rounded half-up to cents. Return integer cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    if income < 5: return 0
    if income >= 100000: return cents(prog(income, brackets))
    w = 50
    lo = income // w * w
    mid = lo + Fraction(w, 2)
    return int(prog(mid, brackets) + Fraction(1, 2)) * 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression band-width-switch 1', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('regression band-width-switch 2', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)],
 [('regression band-width-switch 1', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('regression band-width-switch 2', (603, [[10000, '10'], [40000, '12'], [None, '22']]), 6100),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)],
 [('regression band-width-switch 1', (5, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   100),
  ('regression band-width-switch 2',
   (2999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 29900),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024),
  ('control: band edge', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900)],
 [('regression band-width-switch 1', (1821, [[10000, '10'], [40000, '12'], [None, '22']]), 18100),
  ('regression band-width-switch 2', (1428, [[10000, '10'], [40000, '12'], [None, '22']]), 14400),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression band-width-switch 1', (12, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('regression band-width-switch 2', (1103, [[10000, '10'], [40000, '12'], [None, '22']]), 11100),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    if income < 5: return 0
    if income >= 100000: return cents(prog(income, brackets))
    w = 25 if income <= 3000 else 50
    lo = income // w * w
    mid = lo + Fraction(w, 2)
    return int(prog(mid, brackets) + Fraction(1, 2)) * 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression band-width-switch 1', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('regression band-width-switch 2', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)],
 [('regression band-width-switch 1', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('regression band-width-switch 2', (603, [[10000, '10'], [40000, '12'], [None, '22']]), 6100),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)],
 [('regression band-width-switch 1', (5, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   100),
  ('regression band-width-switch 2',
   (2999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 29900),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024),
  ('control: band edge', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900)],
 [('regression band-width-switch 1', (1821, [[10000, '10'], [40000, '12'], [None, '22']]), 18100),
  ('regression band-width-switch 2', (1428, [[10000, '10'], [40000, '12'], [None, '22']]), 14400),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0)],
 [('regression band-width-switch 1', (12, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('regression band-width-switch 2', (1103, [[10000, '10'], [40000, '12'], [None, '22']]), 11100),
  ('partial repair guard 1', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)]]
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)

prompt:
Low incomes are looked up in 50-dollar bands.

solve(income, brackets): stipulated tax-table lookup. income < 0 returns 0 and incomes below 5 have zero tax. For income < 100000 the tax is the progressive tax on the midpoint of the income's band, rounded half-up to whole dollars: bands are 25 wide below 3000 ([0,25), [25,50), ...) and 50 wide from 3000 ([3000,3050), ...). Incomes of 100000 or more use the exact progressive tax rounded half-up to cents. Return integer cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    if income < 5: return 0
    if income >= 100000: return cents(prog(income, brackets))
    w = 25 if income < 3000 else 50
    lo = income // w * w
    mid = lo + Fraction(w, 2)
    return cents(prog(mid, brackets))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression table-dollar-rounding 1', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('regression table-dollar-rounding 2', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100)],
 [('regression table-dollar-rounding 1', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('regression table-dollar-rounding 2', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('partial repair guard 2', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024)],
 [('regression table-dollar-rounding 1', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('regression table-dollar-rounding 2', (603, [[10000, '10'], [40000, '12'], [None, '22']]), 6100),
  ('partial repair guard 1', (99999, [[10000, '10'], [40000, '12'], [None, '22']]), 1779500),
  ('partial repair guard 2', (2999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   29900),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024),
  ('control: band edge', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900)],
 [('regression table-dollar-rounding 1',
   (5, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 100),
  ('regression table-dollar-rounding 2', (99999, [[10000, '10'], [40000, '12'], [None, '22']]), 1779500),
  ('partial repair guard 1', (99975, [[10000, '10'], [40000, '12'], [None, '22']]), 1779500),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000)],
 [('regression table-dollar-rounding 1',
   (2999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 29900),
  ('regression table-dollar-rounding 2', (99975, [[10000, '10'], [40000, '12'], [None, '22']]), 1779500),
  ('partial repair guard 1', (3024, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (1428, [[10000, '10'], [40000, '12'], [None, '22']]), 14400),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    if income < 5: return 0
    if income >= 100000: return cents(prog(income, brackets))
    w = 25 if income < 3000 else 50
    lo = income // w * w
    mid = lo + Fraction(w, 2)
    return int(prog(mid, brackets)) * 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression table-dollar-rounding 1', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('regression table-dollar-rounding 2', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100)],
 [('regression table-dollar-rounding 1', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('regression table-dollar-rounding 2', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('partial repair guard 2', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024)],
 [('regression table-dollar-rounding 1', (576, [[10000, '10'], [40000, '12'], [None, '22']]), 5900),
  ('regression table-dollar-rounding 2', (603, [[10000, '10'], [40000, '12'], [None, '22']]), 6100),
  ('partial repair guard 1', (99999, [[10000, '10'], [40000, '12'], [None, '22']]), 1779500),
  ('partial repair guard 2', (2999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   29900),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024),
  ('control: band edge', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900)],
 [('regression table-dollar-rounding 1',
   (5, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 100),
  ('regression table-dollar-rounding 2', (99999, [[10000, '10'], [40000, '12'], [None, '22']]), 1779500),
  ('partial repair guard 1', (99975, [[10000, '10'], [40000, '12'], [None, '22']]), 1779500),
  ('partial repair guard 2', (3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   30300),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000)],
 [('regression table-dollar-rounding 1',
   (2999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), 29900),
  ('regression table-dollar-rounding 2', (99975, [[10000, '10'], [40000, '12'], [None, '22']]), 1779500),
  ('partial repair guard 1', (3024, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('partial repair guard 2', (1428, [[10000, '10'], [40000, '12'], [None, '22']]), 14400),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: tiny', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400)]]
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)

prompt:
Table lookups report cents although the table is in whole dollars.

solve(income, brackets): stipulated tax-table lookup. income < 0 returns 0 and incomes below 5 have zero tax. For income < 100000 the tax is the progressive tax on the midpoint of the income's band, rounded half-up to whole dollars: bands are 25 wide below 3000 ([0,25), [25,50), ...) and 50 wide from 3000 ([3000,3050), ...). Incomes of 100000 or more use the exact progressive tax rounded half-up to cents. Return integer cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    if income < 0: return 0
    if income >= 100000: return cents(prog(income, brackets))
    w = 25 if income < 3000 else 50
    lo = income // w * w
    mid = lo + Fraction(w, 2)
    return int(prog(mid, brackets) + Fraction(1, 2)) * 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000)],
 [('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024)],
 [('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024),
  ('control: band edge', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900)],
 [('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000)],
 [('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    if income <= 0: return 0
    if income >= 100000: return cents(prog(income, brackets))
    w = 25 if income < 3000 else 50
    lo = income // w * w
    mid = lo + Fraction(w, 2)
    return int(prog(mid, brackets) + Fraction(1, 2)) * 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000)],
 [('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024)],
 [('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024),
  ('control: band edge', (40050, [[10000, '10'], [40000, '12'], [None, '22']]), 461700),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900)],
 [('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: last narrow band', (2999, [[10000, '10'], [40000, '12'], [None, '22']]), 29900),
  ('control: first wide band', (3000, [[10000, '10'], [40000, '12'], [None, '22']]), 30300),
  ('control: ordinary', (12345, [[10000, '10'], [40000, '12'], [None, '22']]), 127900),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000)],
 [('regression minimum-taxable 1', (4, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('regression minimum-taxable 2', (1, [[10000, '10'], [40000, '12'], [None, '22']]), 0),
  ('control: table cutoff', (100000, [[10000, '10'], [40000, '12'], [None, '22']]), 1780000),
  ('control: small', (24, [[10000, '10'], [40000, '12'], [None, '22']]), 100),
  ('control: just under cutoff', (99999, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1739400),
  ('control: above cutoff', (100001, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]),
   1740024)]]
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)

prompt:
A filer with 3 dollars of taxable income owes 1 dollar.

solve(income, brackets): stipulated tax-table lookup. income < 0 returns 0 and incomes below 5 have zero tax. For income < 100000 the tax is the progressive tax on the midpoint of the income's band, rounded half-up to whole dollars: bands are 25 wide below 3000 ([0,25), [25,50), ...) and 50 wide from 3000 ([3000,3050), ...). Incomes of 100000 or more use the exact progressive tax rounded half-up to cents. Return integer cents.

split: open-access


prompt:
The exemption disappears for filers barely over the threshold.

solve(amti, regular_cents, status): stipulated AMT, whole dollars. Exemption: single 85700 (phase-out threshold 609350), mfj 133300 (threshold 1218700). The exemption is reduced by 25% of AMTI above the threshold, with the reduction rounded down to whole dollars, never below 0. Base = max(0, amti - exemption). Tentative minimum tax = 26% of base up to 232600 plus 28% of base above 232600 (in cents: dollars times percent). AMT = max(0, TMT - regular tax). Return [exemption, tmt_cents, amt_cents].

split: open-access


prompt:
Very high AMTI yields a base larger than AMTI itself.

solve(amti, regular_cents, status): stipulated AMT, whole dollars. Exemption: single 85700 (phase-out threshold 609350), mfj 133300 (threshold 1218700). The exemption is reduced by 25% of AMTI above the threshold, with the reduction rounded down to whole dollars, never below 0. Base = max(0, amti - exemption). Tentative minimum tax = 26% of base up to 232600 plus 28% of base above 232600 (in cents: dollars times percent). AMT = max(0, TMT - regular tax). Return [exemption, tmt_cents, amt_cents].

split: open-access


prompt:
Crossing the 232600 break raises the tax on the entire base by two points.

solve(amti, regular_cents, status): stipulated AMT, whole dollars. Exemption: single 85700 (phase-out threshold 609350), mfj 133300 (threshold 1218700). The exemption is reduced by 25% of AMTI above the threshold, with the reduction rounded down to whole dollars, never below 0. Base = max(0, amti - exemption). Tentative minimum tax = 26% of base up to 232600 plus 28% of base above 232600 (in cents: dollars times percent). AMT = max(0, TMT - regular tax). Return [exemption, tmt_cents, amt_cents].

split: open-access


prompt:
Filers with high regular tax receive a negative AMT that reduces their total.

solve(amti, regular_cents, status): stipulated AMT, whole dollars. Exemption: single 85700 (phase-out threshold 609350), mfj 133300 (threshold 1218700). The exemption is reduced by 25% of AMTI above the threshold, with the reduction rounded down to whole dollars, never below 0. Base = max(0, amti - exemption). Tentative minimum tax = 26% of base up to 232600 plus 28% of base above 232600 (in cents: dollars times percent). AMT = max(0, TMT - regular tax). Return [exemption, tmt_cents, amt_cents].

split: open-access


prompt:
The exemption is a dollar lower than stipulated for some excess amounts.

solve(amti, regular_cents, status): stipulated AMT, whole dollars. Exemption: single 85700 (phase-out threshold 609350), mfj 133300 (threshold 1218700). The exemption is reduced by 25% of AMTI above the threshold, with the reduction rounded down to whole dollars, never below 0. Base = max(0, amti - exemption). Tentative minimum tax = 26% of base up to 232600 plus 28% of base above 232600 (in cents: dollars times percent). AMT = max(0, TMT - regular tax). Return [exemption, tmt_cents, amt_cents].

split: open-access


prompt:
Married couples pay AMT computed with the single exemption.

solve(amti, regular_cents, status): stipulated AMT, whole dollars. Exemption: single 85700 (phase-out threshold 609350), mfj 133300 (threshold 1218700). The exemption is reduced by 25% of AMTI above the threshold, with the reduction rounded down to whole dollars, never below 0. Base = max(0, amti - exemption). Tentative minimum tax = 26% of base up to 232600 plus 28% of base above 232600 (in cents: dollars times percent). AMT = max(0, TMT - regular tax). Return [exemption, tmt_cents, amt_cents].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(nii, magi, status):
    thr = {'single': 200000, 'mfj': 250000, 'mfs': 125000}[status]
    base = max(0, max(nii, magi - thr))
    return int(base * Fraction(38, 10) + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression lesser-of 1', (20000, 300000, 'mfj'), 76000),
  ('regression lesser-of 2', (50000, 230000, 'single'), 114000),
  ('partial repair guard 2', (5001, 130000, 'mfs'), 19000), ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27)],
 [('regression lesser-of 1', (5001, 130000, 'mfs'), 19000), ('regression lesser-of 2', (-4000, 400000, 'single'), 0),
  ('partial repair guard 1', (10000, 190000, 'single'), 0), ('partial repair guard 2', (42884, 250001, 'mfj'), 4),
  ('control: odd dollars', (7, 400000, 'mfj'), 27), ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000)],
 [('regression lesser-of 1', (10000, 190000, 'single'), 0), ('regression lesser-of 2', (7, 400000, 'mfj'), 27),
  ('partial repair guard 1', (13, 125001, 'single'), 0), ('partial repair guard 2', (7, 200001, 'single'), 4),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 0)],
 [('regression lesser-of 1', (13, 250001, 'single'), 49), ('regression lesser-of 2', (42884, 250001, 'mfj'), 4),
  ('partial repair guard 1', (13, 250001, 'mfj'), 4), ('partial repair guard 2', (13, 200001, 'mfj'), 0),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression lesser-of 1', (0, 200001, 'mfs'), 0), ('regression lesser-of 2', (13, 125001, 'single'), 0),
  ('partial repair guard 1', (13, 125001, 'mfs'), 4), ('partial repair guard 2', (16055, 250001, 'mfj'), 4),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(nii, magi, status):
    thr = {'single': 200000, 'mfj': 250000, 'mfs': 125000}[status]
    base = max(0, min(nii, magi))
    return int(base * Fraction(38, 10) + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression lesser-of 1', (20000, 300000, 'mfj'), 76000),
  ('regression lesser-of 2', (50000, 230000, 'single'), 114000),
  ('partial repair guard 2', (5001, 130000, 'mfs'), 19000), ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27)],
 [('regression lesser-of 1', (5001, 130000, 'mfs'), 19000), ('regression lesser-of 2', (-4000, 400000, 'single'), 0),
  ('partial repair guard 1', (10000, 190000, 'single'), 0), ('partial repair guard 2', (42884, 250001, 'mfj'), 4),
  ('control: odd dollars', (7, 400000, 'mfj'), 27), ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000)],
 [('regression lesser-of 1', (10000, 190000, 'single'), 0), ('regression lesser-of 2', (7, 400000, 'mfj'), 27),
  ('partial repair guard 1', (13, 125001, 'single'), 0), ('partial repair guard 2', (7, 200001, 'single'), 4),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 0)],
 [('regression lesser-of 1', (13, 250001, 'single'), 49), ('regression lesser-of 2', (42884, 250001, 'mfj'), 4),
  ('partial repair guard 1', (13, 250001, 'mfj'), 4), ('partial repair guard 2', (13, 200001, 'mfj'), 0),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression lesser-of 1', (0, 200001, 'mfs'), 0), ('regression lesser-of 2', (13, 125001, 'single'), 0),
  ('partial repair guard 1', (13, 125001, 'mfs'), 4), ('partial repair guard 2', (16055, 250001, 'mfj'), 4),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 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)

prompt:
A filer with small investment income pays surtax on their wages above the threshold.

solve(nii, magi, status): stipulated 3.8% surtax on the lesser of net investment income and MAGI above the status threshold (single 200000, mfj 250000, mfs 125000), where neither amount counts below zero. Amounts are whole dollars; return the surtax in integer cents rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(nii, magi, status):
    thr = {'single': 200000, 'mfj': 250000, 'mfs': 250000}[status]
    base = max(0, min(nii, magi - thr))
    return int(base * Fraction(38, 10) + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression status-threshold 1', (5001, 130000, 'mfs'), 19000),
  ('regression status-threshold 2', (13, 125001, 'mfs'), 4),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0)],
 [('regression status-threshold 1', (7, 250001, 'mfs'), 27), ('regression status-threshold 2', (13, 250001, 'mfs'), 49),
  ('partial repair guard 1', (7, 200001, 'mfs'), 27), ('partial repair guard 2', (34287, 200001, 'mfs'), 130291),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression status-threshold 1', (7, 200001, 'mfs'), 27),
  ('regression status-threshold 2', (34287, 200001, 'mfs'), 130291),
  ('partial repair guard 1', (13, 166865, 'mfs'), 49), ('partial repair guard 2', (13, 200001, 'mfs'), 49),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 0)],
 [('regression status-threshold 1', (13, 166865, 'mfs'), 49),
  ('regression status-threshold 2', (13, 200001, 'mfs'), 49),
  ('partial repair guard 1', (119220, 200001, 'mfs'), 285004), ('partial repair guard 2', (7, 169672, 'mfs'), 27),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression status-threshold 1', (119220, 200001, 'mfs'), 285004),
  ('regression status-threshold 2', (7, 169672, 'mfs'), 27),
  ('partial repair guard 1', (177822, 250001, 'mfs'), 475004), ('partial repair guard 2', (158618, 125001, 'mfs'), 4),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(nii, magi, status):
    thr = {'single': 200000, 'mfj': 250000, 'mfs': 200000}[status]
    base = max(0, min(nii, magi - thr))
    return int(base * Fraction(38, 10) + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression status-threshold 1', (5001, 130000, 'mfs'), 19000),
  ('regression status-threshold 2', (13, 125001, 'mfs'), 4),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0)],
 [('regression status-threshold 1', (7, 250001, 'mfs'), 27), ('regression status-threshold 2', (13, 250001, 'mfs'), 49),
  ('partial repair guard 1', (7, 200001, 'mfs'), 27), ('partial repair guard 2', (34287, 200001, 'mfs'), 130291),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression status-threshold 1', (7, 200001, 'mfs'), 27),
  ('regression status-threshold 2', (34287, 200001, 'mfs'), 130291),
  ('partial repair guard 1', (13, 166865, 'mfs'), 49), ('partial repair guard 2', (13, 200001, 'mfs'), 49),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 0)],
 [('regression status-threshold 1', (13, 166865, 'mfs'), 49),
  ('regression status-threshold 2', (13, 200001, 'mfs'), 49),
  ('partial repair guard 1', (119220, 200001, 'mfs'), 285004), ('partial repair guard 2', (7, 169672, 'mfs'), 27),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression status-threshold 1', (119220, 200001, 'mfs'), 285004),
  ('regression status-threshold 2', (7, 169672, 'mfs'), 27),
  ('partial repair guard 1', (177822, 250001, 'mfs'), 475004), ('partial repair guard 2', (158618, 125001, 'mfs'), 4),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 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)

prompt:
Married-filing-separately returns escape the surtax up to 250000.

solve(nii, magi, status): stipulated 3.8% surtax on the lesser of net investment income and MAGI above the status threshold (single 200000, mfj 250000, mfs 125000), where neither amount counts below zero. Amounts are whole dollars; return the surtax in integer cents rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(nii, magi, status):
    thr = {'single': 200000, 'mfj': 250000, 'mfs': 125000}[status]
    base = min(nii, magi - thr)
    return int(base * Fraction(38, 10) + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-components 1', (-4000, 400000, 'single'), 0),
  ('regression negative-components 2', (10000, 190000, 'single'), 0),
  ('partial repair guard 2', (0, 125001, 'single'), 0), ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: odd dollars', (7, 400000, 'mfj'), 27)],
 [('regression negative-components 1', (0, 125001, 'single'), 0),
  ('regression negative-components 2', (0, 105501, 'mfj'), 0), ('partial repair guard 2', (13, 125001, 'single'), 0),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression negative-components 1', (13, 125001, 'single'), 0),
  ('regression negative-components 2', (13, 200001, 'mfj'), 0), ('partial repair guard 2', (0, 125001, 'mfj'), 0),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 0)],
 [('regression negative-components 1', (0, 125001, 'mfj'), 0),
  ('regression negative-components 2', (0, 200001, 'mfj'), 0), ('partial repair guard 2', (0, 123762, 'single'), 0),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression negative-components 1', (0, 123762, 'single'), 0),
  ('regression negative-components 2', (7, 125001, 'mfj'), 0), ('partial repair guard 2', (31498, 125001, 'single'), 0),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(nii, magi, status):
    thr = {'single': 200000, 'mfj': 250000, 'mfs': 125000}[status]
    base = min(max(0, nii), magi - thr)
    return int(base * Fraction(38, 10) + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-components 1', (-4000, 400000, 'single'), 0),
  ('regression negative-components 2', (10000, 190000, 'single'), 0),
  ('partial repair guard 2', (0, 125001, 'single'), 0), ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: odd dollars', (7, 400000, 'mfj'), 27)],
 [('regression negative-components 1', (0, 125001, 'single'), 0),
  ('regression negative-components 2', (0, 105501, 'mfj'), 0), ('partial repair guard 2', (13, 125001, 'single'), 0),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression negative-components 1', (13, 125001, 'single'), 0),
  ('regression negative-components 2', (13, 200001, 'mfj'), 0), ('partial repair guard 2', (0, 125001, 'mfj'), 0),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 0)],
 [('regression negative-components 1', (0, 125001, 'mfj'), 0),
  ('regression negative-components 2', (0, 200001, 'mfj'), 0), ('partial repair guard 2', (0, 123762, 'single'), 0),
  ('control: investment loss', (-4000, 400000, 'single'), 0),
  ('control: below threshold', (10000, 190000, 'single'), 0), ('control: odd dollars', (7, 400000, 'mfj'), 27),
  ('control: excess binding', (50000, 230000, 'single'), 114000)],
 [('regression negative-components 1', (0, 123762, 'single'), 0),
  ('regression negative-components 2', (7, 125001, 'mfj'), 0), ('partial repair guard 2', (31498, 125001, 'single'), 0),
  ('control: excess binding', (50000, 230000, 'single'), 114000),
  ('control: nii binding', (20000, 300000, 'mfj'), 76000), ('control: separate filer', (5001, 130000, 'mfs'), 19000),
  ('control: investment loss', (-4000, 400000, 'single'), 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)

prompt:
A net investment loss reduces other tax through a negative surtax.

solve(nii, magi, status): stipulated 3.8% surtax on the lesser of net investment income and MAGI above the status threshold (single 200000, mfj 250000, mfs 125000), where neither amount counts below zero. Amounts are whole dollars; return the surtax in integer cents rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(profits, dividends, associates, days):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    div = associates + 1
    L = Fraction(50000 * days, 365 * div)
    U = Fraction(250000 * days, 365 * div)
    A = profits + dividends
    N = Fraction(profits)
    if A <= L: tax = N * 19 / 100
    elif A >= U: tax = N * 25 / 100
    else: tax = N * 25 / 100 - Fraction(3, 200) * (A - L) * N / A
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression relief-distance 1', (100000, 0, 0, 365), 2275000),
  ('regression relief-distance 2', (60000, 0, 1, 365), 1402500), ('control: small profits', (40000, 0, 0, 365), 760000),
  ('control: main rate', (300000, 0, 0, 365), 7500000), ('control: with dividends', (100000, 25000, 0, 365), 2350000),
  ('control: short period', (30000, 0, 0, 181), 609041)],
 [('regression relief-distance 1', (100000, 25000, 0, 365), 2350000),
  ('regression relief-distance 2', (30000, 0, 0, 181), 609041),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000)],
 [('regression relief-distance 1', (100000, 5000, 1, 365), 2471429),
  ('regression relief-distance 2', (50000, 25000, 0, 365), 1075000),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000)],
 [('regression relief-distance 1', (100000, 5000, 0, 300), 2356458),
  ('regression relief-distance 2', (50000, 60000, 0, 365), 1154545),
  ('control: relief zone', (100000, 0, 0, 365), 2275000), ('control: main rate', (300000, 0, 0, 365), 7500000),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression relief-distance 1', (30000, 5000, 0, 200), 618875),
  ('regression relief-distance 2', (50000, 0, 1, 300), 1170890),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(profits, dividends, associates, days):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    div = associates + 1
    L = Fraction(50000 * days, 365 * div)
    U = Fraction(250000 * days, 365 * div)
    A = profits + dividends
    N = Fraction(profits)
    if A <= L: tax = N * 19 / 100
    elif A >= U: tax = N * 25 / 100
    else: tax = N * 25 / 100 - Fraction(3, 200) * (U - L) * N / A
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression relief-distance 1', (100000, 0, 0, 365), 2275000),
  ('regression relief-distance 2', (60000, 0, 1, 365), 1402500), ('control: small profits', (40000, 0, 0, 365), 760000),
  ('control: main rate', (300000, 0, 0, 365), 7500000), ('control: with dividends', (100000, 25000, 0, 365), 2350000),
  ('control: short period', (30000, 0, 0, 181), 609041)],
 [('regression relief-distance 1', (100000, 25000, 0, 365), 2350000),
  ('regression relief-distance 2', (30000, 0, 0, 181), 609041),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000)],
 [('regression relief-distance 1', (100000, 5000, 1, 365), 2471429),
  ('regression relief-distance 2', (50000, 25000, 0, 365), 1075000),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000)],
 [('regression relief-distance 1', (100000, 5000, 0, 300), 2356458),
  ('regression relief-distance 2', (50000, 60000, 0, 365), 1154545),
  ('control: relief zone', (100000, 0, 0, 365), 2275000), ('control: main rate', (300000, 0, 0, 365), 7500000),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression relief-distance 1', (30000, 5000, 0, 200), 618875),
  ('regression relief-distance 2', (50000, 0, 1, 300), 1170890),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000)]]
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)

prompt:
Relief grows as profits rise, so companies near the upper limit pay less than at the lower limit.

solve(profits, dividends, associates, days): stipulated small-profits relief. Limits L = 50000 and U = 250000 are divided by (associates + 1) and prorated by days/365 (exact fractions). Augmented profits A = profits + dividends decide the band: A <= L taxes profits N at 19%; A >= U at 25%; otherwise tax = 25% of N minus 3/200 * (U - A) * N / A. Return integer cents rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(profits, dividends, associates, days):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    div = 1
    L = Fraction(50000 * days, 365 * div)
    U = Fraction(250000 * days, 365 * div)
    A = profits + dividends
    N = Fraction(profits)
    if A <= L: tax = N * 19 / 100
    elif A >= U: tax = N * 25 / 100
    else: tax = N * 25 / 100 - Fraction(3, 200) * (U - A) * N / A
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression associated-divisor 1', (60000, 0, 1, 365), 1402500),
  ('regression associated-divisor 2', (70000, 5000, 2, 200), 1750000),
  ('partial repair guard 1', (30000, 0, 1, 365), 607500), ('partial repair guard 2', (30000, 0, 4, 300), 733356),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000),
  ('control: main rate', (300000, 0, 0, 365), 7500000), ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression associated-divisor 1', (100000, 5000, 1, 365), 2471429),
  ('regression associated-divisor 2', (100000, 0, 4, 300), 2500000),
  ('partial repair guard 1', (30000, 0, 2, 365), 670000), ('partial repair guard 2', (50000, 0, 4, 365), 1250000),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000)],
 [('regression associated-divisor 1', (180000, 25000, 2, 300), 4500000),
  ('regression associated-divisor 2', (180000, 0, 4, 365), 4500000),
  ('partial repair guard 1', (50000, 0, 1, 365), 1137500), ('partial repair guard 2', (50000, 0, 2, 365), 1200000),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000)],
 [('regression associated-divisor 1', (30000, 25000, 4, 365), 750000),
  ('regression associated-divisor 2', (50000, 0, 2, 181), 1250000),
  ('partial repair guard 1', (30000, 0, 2, 300), 692260), ('partial repair guard 2', (30000, 5000, 1, 365), 634286),
  ('control: relief zone', (100000, 0, 0, 365), 2275000), ('control: main rate', (300000, 0, 0, 365), 7500000),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression associated-divisor 1', (50000, 0, 2, 90), 1250000),
  ('regression associated-divisor 2', (50000, 0, 1, 300), 1170890),
  ('partial repair guard 1', (30000, 0, 1, 365), 607500), ('partial repair guard 2', (30000, 0, 4, 300), 733356),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(profits, dividends, associates, days):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    div = associates + 1
    L = Fraction(50000 * days, 365)
    U = Fraction(250000 * days, 365 * div)
    A = profits + dividends
    N = Fraction(profits)
    if A <= L: tax = N * 19 / 100
    elif A >= U: tax = N * 25 / 100
    else: tax = N * 25 / 100 - Fraction(3, 200) * (U - A) * N / A
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression associated-divisor 1', (60000, 0, 1, 365), 1402500),
  ('regression associated-divisor 2', (70000, 5000, 2, 200), 1750000),
  ('partial repair guard 1', (30000, 0, 1, 365), 607500), ('partial repair guard 2', (30000, 0, 4, 300), 733356),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000),
  ('control: main rate', (300000, 0, 0, 365), 7500000), ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression associated-divisor 1', (100000, 5000, 1, 365), 2471429),
  ('regression associated-divisor 2', (100000, 0, 4, 300), 2500000),
  ('partial repair guard 1', (30000, 0, 2, 365), 670000), ('partial repair guard 2', (50000, 0, 4, 365), 1250000),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000)],
 [('regression associated-divisor 1', (180000, 25000, 2, 300), 4500000),
  ('regression associated-divisor 2', (180000, 0, 4, 365), 4500000),
  ('partial repair guard 1', (50000, 0, 1, 365), 1137500), ('partial repair guard 2', (50000, 0, 2, 365), 1200000),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000)],
 [('regression associated-divisor 1', (30000, 25000, 4, 365), 750000),
  ('regression associated-divisor 2', (50000, 0, 2, 181), 1250000),
  ('partial repair guard 1', (30000, 0, 2, 300), 692260), ('partial repair guard 2', (30000, 5000, 1, 365), 634286),
  ('control: relief zone', (100000, 0, 0, 365), 2275000), ('control: main rate', (300000, 0, 0, 365), 7500000),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression associated-divisor 1', (50000, 0, 2, 90), 1250000),
  ('regression associated-divisor 2', (50000, 0, 1, 300), 1170890),
  ('partial repair guard 1', (30000, 0, 1, 365), 607500), ('partial repair guard 2', (30000, 0, 4, 300), 733356),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000)]]
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)

prompt:
Each company in a group gets the full small-profits limit.

solve(profits, dividends, associates, days): stipulated small-profits relief. Limits L = 50000 and U = 250000 are divided by (associates + 1) and prorated by days/365 (exact fractions). Augmented profits A = profits + dividends decide the band: A <= L taxes profits N at 19%; A >= U at 25%; otherwise tax = 25% of N minus 3/200 * (U - A) * N / A. Return integer cents rounded half-up.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(profits, dividends, associates, days):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    div = associates + 1
    L = Fraction(50000, div)
    U = Fraction(250000, div)
    A = profits + dividends
    N = Fraction(profits)
    if A <= L: tax = N * 19 / 100
    elif A >= U: tax = N * 25 / 100
    else: tax = N * 25 / 100 - Fraction(3, 200) * (U - A) * N / A
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression period-proration 1', (30000, 0, 0, 181), 609041),
  ('regression period-proration 2', (70000, 5000, 2, 200), 1750000),
  ('partial repair guard 2', (100000, 0, 0, 365), 2275000), ('control: small profits', (40000, 0, 0, 365), 760000),
  ('control: main rate', (300000, 0, 0, 365), 7500000), ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression period-proration 1', (100000, 5000, 0, 90), 2500000),
  ('regression period-proration 2', (100000, 5000, 0, 300), 2356458),
  ('partial repair guard 1', (60000, 0, 1, 365), 1402500), ('partial repair guard 2', (100000, 25000, 0, 365), 2350000),
  ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000)],
 [('regression period-proration 1', (180000, 25000, 0, 181), 4500000),
  ('regression period-proration 2', (30000, 5000, 0, 200), 618875),
  ('partial repair guard 1', (200000, 60000, 0, 365), 5000000),
  ('partial repair guard 2', (100000, 5000, 1, 365), 2471429),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000),
  ('control: main rate', (300000, 0, 0, 365), 7500000)],
 [('regression period-proration 1', (50000, 0, 2, 181), 1250000),
  ('regression period-proration 2', (50000, 60000, 0, 90), 1250000),
  ('partial repair guard 1', (50000, 25000, 0, 365), 1075000),
  ('partial repair guard 2', (100000, 5000, 0, 300), 2356458), ('control: relief zone', (100000, 0, 0, 365), 2275000),
  ('control: main rate', (300000, 0, 0, 365), 7500000), ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression period-proration 1', (50000, 0, 2, 90), 1250000),
  ('regression period-proration 2', (50000, 0, 1, 300), 1170890),
  ('partial repair guard 1', (50000, 60000, 0, 365), 1154545),
  ('partial repair guard 2', (30000, 5000, 0, 200), 618875),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000)]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(profits, dividends, associates, days):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            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 tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    div = associates + 1
    L = Fraction(50000 * ((days + 29) // 30), 12 * div)
    U = Fraction(250000 * ((days + 29) // 30), 12 * div)
    A = profits + dividends
    N = Fraction(profits)
    if A <= L: tax = N * 19 / 100
    elif A >= U: tax = N * 25 / 100
    else: tax = N * 25 / 100 - Fraction(3, 200) * (U - A) * N / A
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression period-proration 1', (30000, 0, 0, 181), 609041),
  ('regression period-proration 2', (70000, 5000, 2, 200), 1750000),
  ('partial repair guard 2', (100000, 0, 0, 365), 2275000), ('control: small profits', (40000, 0, 0, 365), 760000),
  ('control: main rate', (300000, 0, 0, 365), 7500000), ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression period-proration 1', (100000, 5000, 0, 90), 2500000),
  ('regression period-proration 2', (100000, 5000, 0, 300), 2356458),
  ('partial repair guard 1', (60000, 0, 1, 365), 1402500), ('partial repair guard 2', (100000, 25000, 0, 365), 2350000),
  ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000)],
 [('regression period-proration 1', (180000, 25000, 0, 181), 4500000),
  ('regression period-proration 2', (30000, 5000, 0, 200), 618875),
  ('partial repair guard 1', (200000, 60000, 0, 365), 5000000),
  ('partial repair guard 2', (100000, 5000, 1, 365), 2471429),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000),
  ('control: main rate', (300000, 0, 0, 365), 7500000)],
 [('regression period-proration 1', (50000, 0, 2, 181), 1250000),
  ('regression period-proration 2', (50000, 60000, 0, 90), 1250000),
  ('partial repair guard 1', (50000, 25000, 0, 365), 1075000),
  ('partial repair guard 2', (100000, 5000, 0, 300), 2356458), ('control: relief zone', (100000, 0, 0, 365), 2275000),
  ('control: main rate', (300000, 0, 0, 365), 7500000), ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression period-proration 1', (50000, 0, 2, 90), 1250000),
  ('regression period-proration 2', (50000, 0, 1, 300), 1170890),
  ('partial repair guard 1', (50000, 60000, 0, 365), 1154545),
  ('partial repair guard 2', (30000, 5000, 0, 200), 618875),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000)]]
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)

prompt:
A six-month period enjoys the full annual small-profits limit.

solve(profits, dividends, associates, days): stipulated small-profits relief. Limits L = 50000 and U = 250000 are divided by (associates + 1) and prorated by days/365 (exact fractions). Augmented profits A = profits + dividends decide the band: A <= L taxes profits N at 19%; A >= U at 25%; otherwise tax = 25% of N minus 3/200 * (U - A) * N / A. Return integer cents rounded half-up.

split: open-access