broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1550
    base = std[status]
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + extra * conditions
    if status == 'mfs' and spouse_itemizes: s = 0
    d = max(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression additional-amount-by-status 1', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('regression additional-amount-by-status 2', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('partial repair guard 2', ('hoh', 53357, 900, 0, 2, False, False), [25800, 27557]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0])],
 [('regression additional-amount-by-status 1', ('hoh', 53357, 900, 0, 2, False, False), [25800, 27557]),
  ('regression additional-amount-by-status 2', ('single', 45837, 500, 15000, 1, False, False), [16550, 29287]),
  ('partial repair guard 1', ('hoh', 22188, 500, 0, 1, True, True), [3250, 18938]),
  ('partial repair guard 2', ('hoh', 124688, 900, 0, 1, False, False), [23850, 100838]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression additional-amount-by-status 1', ('single', 111058, 500, 3000, 1, False, False), [16550, 94508]),
  ('regression additional-amount-by-status 2', ('hoh', 22188, 500, 0, 1, True, True), [3250, 18938]),
  ('partial repair guard 1', ('hoh', 72381, 20000, 25000, 2, False, True), [25800, 46581]),
  ('partial repair guard 2', ('hoh', 146977, 14000, 0, 2, False, False), [25800, 121177]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression additional-amount-by-status 1', ('single', 85478, 500, 0, 2, False, False), [18500, 66978]),
  ('regression additional-amount-by-status 2', ('hoh', 124688, 900, 0, 1, False, False), [23850, 100838]),
  ('partial repair guard 1', ('hoh', 39678, 500, 0, 1, True, True), [3250, 36428]),
  ('partial repair guard 2', ('hoh', 59881, 14101, 0, 1, False, False), [23850, 36031]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression additional-amount-by-status 1', ('hoh', 72381, 20000, 25000, 2, False, True), [25800, 46581]),
  ('regression additional-amount-by-status 2', ('single', 51379, 14000, 15000, 2, False, False), [18500, 32879]),
  ('partial repair guard 1', ('hoh', 124418, 2000, 3000, 2, False, False), [25800, 98618]),
  ('partial repair guard 2', ('hoh', 100490, 14000, 0, 2, False, False), [25800, 74690]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status == 'single' else 1550
    base = std[status]
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + extra * conditions
    if status == 'mfs' and spouse_itemizes: s = 0
    d = max(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression additional-amount-by-status 1', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('regression additional-amount-by-status 2', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('partial repair guard 2', ('hoh', 53357, 900, 0, 2, False, False), [25800, 27557]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0])],
 [('regression additional-amount-by-status 1', ('hoh', 53357, 900, 0, 2, False, False), [25800, 27557]),
  ('regression additional-amount-by-status 2', ('single', 45837, 500, 15000, 1, False, False), [16550, 29287]),
  ('partial repair guard 1', ('hoh', 22188, 500, 0, 1, True, True), [3250, 18938]),
  ('partial repair guard 2', ('hoh', 124688, 900, 0, 1, False, False), [23850, 100838]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression additional-amount-by-status 1', ('single', 111058, 500, 3000, 1, False, False), [16550, 94508]),
  ('regression additional-amount-by-status 2', ('hoh', 22188, 500, 0, 1, True, True), [3250, 18938]),
  ('partial repair guard 1', ('hoh', 72381, 20000, 25000, 2, False, True), [25800, 46581]),
  ('partial repair guard 2', ('hoh', 146977, 14000, 0, 2, False, False), [25800, 121177]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression additional-amount-by-status 1', ('single', 85478, 500, 0, 2, False, False), [18500, 66978]),
  ('regression additional-amount-by-status 2', ('hoh', 124688, 900, 0, 1, False, False), [23850, 100838]),
  ('partial repair guard 1', ('hoh', 39678, 500, 0, 1, True, True), [3250, 36428]),
  ('partial repair guard 2', ('hoh', 59881, 14101, 0, 1, False, False), [23850, 36031]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression additional-amount-by-status 1', ('hoh', 72381, 20000, 25000, 2, False, True), [25800, 46581]),
  ('regression additional-amount-by-status 2', ('single', 51379, 14000, 15000, 2, False, False), [18500, 32879]),
  ('partial repair guard 1', ('hoh', 124418, 2000, 3000, 2, False, False), [25800, 98618]),
  ('partial repair guard 2', ('hoh', 100490, 14000, 0, 2, False, False), [25800, 74690]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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:
An elderly head of household deducts 400 less than entitled.

solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes): stipulated deduction rules. Base standard deduction: single 14600, mfj 29200, mfs 14600, hoh 21900 (other statuses 'ERR:status'). A dependent's base is min(base, max(1300, earned + 450)). Then add 1950 per age/blindness condition for single or hoh, 1550 per condition for married statuses. If status is mfs and the spouse itemizes, the standard deduction is 0. The deduction is the larger of standard and itemized; taxable = max(0, gross - deduction). Return [deduction, taxable].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if dependent: base = max(1300, earned + 450)
    s = base + extra * conditions
    if status == 'mfs' and spouse_itemizes: s = 0
    d = max(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression dependent-limit 1', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('regression dependent-limit 2', ('mfs', 54568, 20000, 3000, 0, True, False), [14600, 39968]),
  ('partial repair guard 1', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('partial repair guard 2', ('hoh', 22188, 500, 0, 1, True, True), [3250, 18938]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression dependent-limit 1', ('hoh', 50974, 29634, 0, 0, True, True), [21900, 29074]),
  ('regression dependent-limit 2', ('mfs', 89760, 20000, 0, 0, True, False), [14600, 75160]),
  ('partial repair guard 1', ('single', 97749, 500, 3000, 2, True, False), [5200, 92549]),
  ('partial repair guard 2', ('hoh', 39678, 500, 0, 1, True, True), [3250, 36428]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression dependent-limit 1', ('single', 122829, 25958, 25000, 2, True, False), [25000, 97829]),
  ('regression dependent-limit 2', ('single', 98864, 35923, 25000, 0, True, False), [25000, 73864]),
  ('partial repair guard 1', ('single', 6251, 500, 0, 0, True, False), [1300, 4951]),
  ('partial repair guard 2', ('hoh', 111017, 500, 3000, 1, True, False), [3250, 107767]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression dependent-limit 1', ('single', 68311, 20000, 0, 2, True, False), [18500, 49811]),
  ('regression dependent-limit 2', ('mfs', 120508, 35036, 0, 0, True, False), [14600, 105908]),
  ('partial repair guard 1', ('hoh', 85892, 0, 0, 2, True, True), [5200, 80692]),
  ('partial repair guard 2', ('mfj', 42614, 500, 0, 0, True, True), [1300, 41314]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression dependent-limit 1', ('mfs', 104697, 20000, 15000, 0, True, False), [15000, 89697]),
  ('regression dependent-limit 2', ('mfs', 26507, 38557, 15000, 0, True, False), [15000, 11507]),
  ('partial repair guard 1', ('mfj', 30569, 500, 0, 0, True, True), [1300, 29269]),
  ('partial repair guard 2', ('mfj', 145593, 500, 0, 0, True, False), [1300, 144293]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if dependent: base = min(base, earned + 450)
    s = base + extra * conditions
    if status == 'mfs' and spouse_itemizes: s = 0
    d = max(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression dependent-limit 1', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('regression dependent-limit 2', ('mfs', 54568, 20000, 3000, 0, True, False), [14600, 39968]),
  ('partial repair guard 1', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('partial repair guard 2', ('hoh', 22188, 500, 0, 1, True, True), [3250, 18938]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression dependent-limit 1', ('hoh', 50974, 29634, 0, 0, True, True), [21900, 29074]),
  ('regression dependent-limit 2', ('mfs', 89760, 20000, 0, 0, True, False), [14600, 75160]),
  ('partial repair guard 1', ('single', 97749, 500, 3000, 2, True, False), [5200, 92549]),
  ('partial repair guard 2', ('hoh', 39678, 500, 0, 1, True, True), [3250, 36428]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression dependent-limit 1', ('single', 122829, 25958, 25000, 2, True, False), [25000, 97829]),
  ('regression dependent-limit 2', ('single', 98864, 35923, 25000, 0, True, False), [25000, 73864]),
  ('partial repair guard 1', ('single', 6251, 500, 0, 0, True, False), [1300, 4951]),
  ('partial repair guard 2', ('hoh', 111017, 500, 3000, 1, True, False), [3250, 107767]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression dependent-limit 1', ('single', 68311, 20000, 0, 2, True, False), [18500, 49811]),
  ('regression dependent-limit 2', ('mfs', 120508, 35036, 0, 0, True, False), [14600, 105908]),
  ('partial repair guard 1', ('hoh', 85892, 0, 0, 2, True, True), [5200, 80692]),
  ('partial repair guard 2', ('mfj', 42614, 500, 0, 0, True, True), [1300, 41314]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression dependent-limit 1', ('mfs', 104697, 20000, 15000, 0, True, False), [15000, 89697]),
  ('regression dependent-limit 2', ('mfs', 26507, 38557, 15000, 0, True, False), [15000, 11507]),
  ('partial repair guard 1', ('mfj', 30569, 500, 0, 0, True, True), [1300, 29269]),
  ('partial repair guard 2', ('mfj', 145593, 500, 0, 0, True, False), [1300, 144293]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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 dependent with high earnings deducts more than the regular standard deduction.

solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes): stipulated deduction rules. Base standard deduction: single 14600, mfj 29200, mfs 14600, hoh 21900 (other statuses 'ERR:status'). A dependent's base is min(base, max(1300, earned + 450)). Then add 1950 per age/blindness condition for single or hoh, 1550 per condition for married statuses. If status is mfs and the spouse itemizes, the standard deduction is 0. The deduction is the larger of standard and itemized; taxable = max(0, gross - deduction). Return [deduction, taxable].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + extra * conditions
    pass
    d = max(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression mfs-spouse-itemizes 1', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 40000, 40000, 0, 0, False, True), [0, 40000]),
  ('partial repair guard 2', ('mfs', 118666, 5538, 0, 1, True, True), [0, 118666]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0])],
 [('regression mfs-spouse-itemizes 1', ('mfs', 118666, 5538, 0, 1, True, True), [0, 118666]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 29019, 900, 0, 2, False, True), [0, 29019]),
  ('partial repair guard 2', ('mfs', 60365, 500, 0, 1, True, True), [0, 60365]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression mfs-spouse-itemizes 1', ('mfs', 68513, 500, 0, 0, False, True), [0, 68513]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 76535, 900, 0, 0, False, True), [0, 76535]),
  ('partial repair guard 1', ('mfs', 23561, 14000, 0, 2, False, True), [0, 23561]),
  ('partial repair guard 2', ('mfs', 142325, 500, 0, 2, True, True), [0, 142325]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression mfs-spouse-itemizes 1', ('mfs', 60365, 500, 0, 1, True, True), [0, 60365]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 28199, 2000, 3000, 1, False, True), [3000, 25199]),
  ('partial repair guard 1', ('mfs', 97884, 0, 0, 2, True, True), [0, 97884]),
  ('partial repair guard 2', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0])],
 [('regression mfs-spouse-itemizes 1', ('mfs', 9614, 500, 0, 0, False, True), [0, 9614]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 23561, 14000, 0, 2, False, True), [0, 23561]),
  ('partial repair guard 1', ('mfs', 118666, 5538, 0, 1, True, True), [0, 118666]),
  ('partial repair guard 2', ('mfs', 29019, 900, 0, 2, False, True), [0, 29019]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if status == 'mfs' and spouse_itemizes: base = 0
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + extra * conditions
    pass
    d = max(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression mfs-spouse-itemizes 1', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 40000, 40000, 0, 0, False, True), [0, 40000]),
  ('partial repair guard 2', ('mfs', 118666, 5538, 0, 1, True, True), [0, 118666]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0])],
 [('regression mfs-spouse-itemizes 1', ('mfs', 118666, 5538, 0, 1, True, True), [0, 118666]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 29019, 900, 0, 2, False, True), [0, 29019]),
  ('partial repair guard 2', ('mfs', 60365, 500, 0, 1, True, True), [0, 60365]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression mfs-spouse-itemizes 1', ('mfs', 68513, 500, 0, 0, False, True), [0, 68513]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 76535, 900, 0, 0, False, True), [0, 76535]),
  ('partial repair guard 1', ('mfs', 23561, 14000, 0, 2, False, True), [0, 23561]),
  ('partial repair guard 2', ('mfs', 142325, 500, 0, 2, True, True), [0, 142325]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression mfs-spouse-itemizes 1', ('mfs', 60365, 500, 0, 1, True, True), [0, 60365]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 28199, 2000, 3000, 1, False, True), [3000, 25199]),
  ('partial repair guard 1', ('mfs', 97884, 0, 0, 2, True, True), [0, 97884]),
  ('partial repair guard 2', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0])],
 [('regression mfs-spouse-itemizes 1', ('mfs', 9614, 500, 0, 0, False, True), [0, 9614]),
  ('regression mfs-spouse-itemizes 2', ('mfs', 23561, 14000, 0, 2, False, True), [0, 23561]),
  ('partial repair guard 1', ('mfs', 118666, 5538, 0, 1, True, True), [0, 118666]),
  ('partial repair guard 2', ('mfs', 29019, 900, 0, 2, False, True), [0, 29019]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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 claim a standard deduction the rules deny.

solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes): stipulated deduction rules. Base standard deduction: single 14600, mfj 29200, mfs 14600, hoh 21900 (other statuses 'ERR:status'). A dependent's base is min(base, max(1300, earned + 450)). Then add 1950 per age/blindness condition for single or hoh, 1550 per condition for married statuses. If status is mfs and the spouse itemizes, the standard deduction is 0. The deduction is the larger of standard and itemized; taxable = max(0, gross - deduction). Return [deduction, taxable].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    base += extra * conditions
    if dependent: base = min(base, max(1300, earned + 450))
    s = base
    if status == 'mfs' and spouse_itemizes: s = 0
    d = max(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression additional-before-dependent-cap 1', ('single', 5000, 2000, 0, 1, True, False), [4400, 600]),
  ('regression additional-before-dependent-cap 2', ('mfj', 100718, 20000, 0, 1, True, True), [22000, 78718]),
  ('partial repair guard 1', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression additional-before-dependent-cap 1', ('hoh', 22188, 500, 0, 1, True, True), [3250, 18938]),
  ('regression additional-before-dependent-cap 2', ('single', 97749, 500, 3000, 2, True, False), [5200, 92549]),
  ('partial repair guard 1', ('mfj', 100718, 20000, 0, 1, True, True), [22000, 78718]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression additional-before-dependent-cap 1', ('mfj', 41032, 28549, 3000, 1, True, False), [30549, 10483]),
  ('regression additional-before-dependent-cap 2', ('hoh', 39678, 500, 0, 1, True, True), [3250, 36428]),
  ('partial repair guard 1', ('single', 97749, 500, 3000, 2, True, False), [5200, 92549]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression additional-before-dependent-cap 1', ('hoh', 50678, 2000, 0, 2, True, True), [6350, 44328]),
  ('regression additional-before-dependent-cap 2', ('hoh', 111017, 500, 3000, 1, True, False), [3250, 107767]),
  ('partial repair guard 1', ('single', 68311, 20000, 0, 2, True, False), [18500, 49811]),
  ('partial repair guard 2', ('hoh', 39678, 500, 0, 1, True, True), [3250, 36428]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression additional-before-dependent-cap 1', ('hoh', 85892, 0, 0, 2, True, True), [5200, 80692]),
  ('regression additional-before-dependent-cap 2', ('mfj', 105604, 2000, 0, 2, True, False), [5550, 100054]),
  ('partial repair guard 1', ('hoh', 50678, 2000, 0, 2, True, True), [6350, 44328]),
  ('partial repair guard 2', ('hoh', 111017, 500, 3000, 1, True, False), [3250, 107767]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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

N = 1
observations = []
def solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes):
    std = {'single': 14600, 'mfj': 29200, 'mfs': 14600, 'hoh': 21900}
    if status not in std: return 'ERR:status'
    extra = 1950 if status in ('single', 'hoh') else 1550
    base = std[status]
    if dependent: base = min(base, max(1300, earned + 450))
    s = base + (0 if dependent else extra * conditions)
    if status == 'mfs' and spouse_itemizes: s = 0
    d = max(s, itemized)
    return [d, max(0, gross - d)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression additional-before-dependent-cap 1', ('single', 5000, 2000, 0, 1, True, False), [4400, 600]),
  ('regression additional-before-dependent-cap 2', ('mfj', 100718, 20000, 0, 1, True, True), [22000, 78718]),
  ('partial repair guard 1', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression additional-before-dependent-cap 1', ('hoh', 22188, 500, 0, 1, True, True), [3250, 18938]),
  ('regression additional-before-dependent-cap 2', ('single', 97749, 500, 3000, 2, True, False), [5200, 92549]),
  ('partial repair guard 1', ('mfj', 100718, 20000, 0, 1, True, True), [22000, 78718]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])],
 [('regression additional-before-dependent-cap 1', ('mfj', 41032, 28549, 3000, 1, True, False), [30549, 10483]),
  ('regression additional-before-dependent-cap 2', ('hoh', 39678, 500, 0, 1, True, True), [3250, 36428]),
  ('partial repair guard 1', ('single', 97749, 500, 3000, 2, True, False), [5200, 92549]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000]),
  ('control: bad status', ('widow', 1, 1, 0, 0, False, False), 'ERR:status'),
  ('control: dependent no earnings', ('single', 3000, 0, 0, 0, True, False), [1300, 1700]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400])],
 [('regression additional-before-dependent-cap 1', ('hoh', 50678, 2000, 0, 2, True, True), [6350, 44328]),
  ('regression additional-before-dependent-cap 2', ('hoh', 111017, 500, 3000, 1, True, False), [3250, 107767]),
  ('partial repair guard 1', ('single', 68311, 20000, 0, 2, True, False), [18500, 49811]),
  ('partial repair guard 2', ('hoh', 39678, 500, 0, 1, True, True), [3250, 36428]),
  ('control: single standard', ('single', 50000, 50000, 0, 0, False, False), [14600, 35400]),
  ('control: hoh with age', ('hoh', 30000, 30000, 0, 1, False, False), [23850, 6150]),
  ('control: dependent', ('single', 5000, 2000, 0, 0, True, False), [2450, 2550]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000])],
 [('regression additional-before-dependent-cap 1', ('hoh', 85892, 0, 0, 2, True, True), [5200, 80692]),
  ('regression additional-before-dependent-cap 2', ('mfj', 105604, 2000, 0, 2, True, False), [5550, 100054]),
  ('partial repair guard 1', ('hoh', 50678, 2000, 0, 2, True, True), [6350, 44328]),
  ('partial repair guard 2', ('hoh', 111017, 500, 3000, 1, True, False), [3250, 107767]),
  ('control: mfs spouse itemizes', ('mfs', 40000, 40000, 3000, 2, False, True), [3000, 37000]),
  ('control: mfj below deduction', ('mfj', 20000, 20000, 0, 2, False, False), [32300, 0]),
  ('control: high-earning dependent', ('single', 9000, 20000, 0, 1, True, False), [16550, 0]),
  ('control: itemizer', ('mfj', 120000, 120000, 35000, 0, False, False), [35000, 85000])]]
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:
An elderly dependent loses the additional standard deduction.

solve(status, gross, earned, itemized, conditions, dependent, spouse_itemizes): stipulated deduction rules. Base standard deduction: single 14600, mfj 29200, mfs 14600, hoh 21900 (other statuses 'ERR:status'). A dependent's base is min(base, max(1300, earned + 450)). Then add 1950 per age/blindness condition for single or hoh, 1550 per condition for married statuses. If status is mfs and the spouse itemizes, the standard deduction is 0. The deduction is the larger of standard and itemized; taxable = max(0, gross - deduction). Return [deduction, taxable].

split: open-access


prompt:
After a few years thresholds lag the published cumulative indexation.

solve(base, factors): base is a list of statutory thresholds; factors are yearly inflation factors (decimal strings). For every year, a threshold is the base times the cumulative product of factors so far, rounded DOWN to a multiple of 50 (indexing always starts again from the unrounded base, never from a previously rounded value). A threshold may never fall below its previous year's value. Return the final-year thresholds.

split: open-access


prompt:
Some thresholds are 50 higher than the published figure.

solve(base, factors): base is a list of statutory thresholds; factors are yearly inflation factors (decimal strings). For every year, a threshold is the base times the cumulative product of factors so far, rounded DOWN to a multiple of 50 (indexing always starts again from the unrounded base, never from a previously rounded value). A threshold may never fall below its previous year's value. Return the final-year thresholds.

split: open-access


prompt:
A factor below one reduces thresholds, raising real tax.

solve(base, factors): base is a list of statutory thresholds; factors are yearly inflation factors (decimal strings). For every year, a threshold is the base times the cumulative product of factors so far, rounded DOWN to a multiple of 50 (indexing always starts again from the unrounded base, never from a previously rounded value). A threshold may never fall below its previous year's value. Return the final-year thresholds.

split: open-access


prompt:
Thresholds reflect one year of inflation after several years of indexing.

solve(base, factors): base is a list of statutory thresholds; factors are yearly inflation factors (decimal strings). For every year, a threshold is the base times the cumulative product of factors so far, rounded DOWN to a multiple of 50 (indexing always starts again from the unrounded base, never from a previously rounded value). A threshold may never fall below its previous year's value. Return the final-year thresholds.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = 0, pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression stacking-base 1', (40000, 0, 20000, 'single'), 651425),
  ('regression stacking-base 2', (500000, 0, 100000, 'mfj'), 13156200),
  ('partial repair guard 1', (10000, 47183, 20000, 'single'), 1063326),
  ('partial repair guard 2', (90000, 8845, 100000, 'mfj'), 2685190),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600)],
 [('regression stacking-base 1', (100000, -8000, 20000, 'mfj'), 1390600),
  ('regression stacking-base 2', (90000, 33485, 348500, 'single'), 7495390),
  ('partial repair guard 1', (10000, 37165, 20000, 'single'), 842930),
  ('partial repair guard 2', (40000, 55863, 100000, 'mfj'), 2619586),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0)],
 [('regression stacking-base 1', (550000, -8000, 135896, 'single'), 18845395),
  ('regression stacking-base 2', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 1', (248298, 5000, 305030, 'single'), 10675495),
  ('partial repair guard 2', (90000, 5000, 346946, 'mfj'), 6304790),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression stacking-base 1', (90000, 5000, 137466, 'single'), 3657290),
  ('regression stacking-base 2', (90000, 0, 20000, 'mfj'), 1272850),
  ('partial repair guard 1', (40000, 5000, 100000, 'mfj'), 1257850),
  ('partial repair guard 2', (550000, 5000, 100000, 'mfj'), 15356200),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression stacking-base 1', (9947, -13667, 100000, 'single'), 838295),
  ('regression stacking-base 2', (550000, 0, 10215, 'single'), 16491775),
  ('partial repair guard 1', (10000, 5000, 303831, 'mfj'), 3521715),
  ('partial repair guard 2', (10000, 41057, 100000, 'single'), 2128554),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ordinary, ordinary + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression stacking-base 1', (40000, 0, 20000, 'single'), 651425),
  ('regression stacking-base 2', (500000, 0, 100000, 'mfj'), 13156200),
  ('partial repair guard 1', (10000, 47183, 20000, 'single'), 1063326),
  ('partial repair guard 2', (90000, 8845, 100000, 'mfj'), 2685190),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600)],
 [('regression stacking-base 1', (100000, -8000, 20000, 'mfj'), 1390600),
  ('regression stacking-base 2', (90000, 33485, 348500, 'single'), 7495390),
  ('partial repair guard 1', (10000, 37165, 20000, 'single'), 842930),
  ('partial repair guard 2', (40000, 55863, 100000, 'mfj'), 2619586),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0)],
 [('regression stacking-base 1', (550000, -8000, 135896, 'single'), 18845395),
  ('regression stacking-base 2', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 1', (248298, 5000, 305030, 'single'), 10675495),
  ('partial repair guard 2', (90000, 5000, 346946, 'mfj'), 6304790),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression stacking-base 1', (90000, 5000, 137466, 'single'), 3657290),
  ('regression stacking-base 2', (90000, 0, 20000, 'mfj'), 1272850),
  ('partial repair guard 1', (40000, 5000, 100000, 'mfj'), 1257850),
  ('partial repair guard 2', (550000, 5000, 100000, 'mfj'), 15356200),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression stacking-base 1', (9947, -13667, 100000, 'single'), 838295),
  ('regression stacking-base 2', (550000, 0, 10215, 'single'), 16491775),
  ('partial repair guard 1', (10000, 5000, 303831, 'mfj'), 3521715),
  ('partial repair guard 2', (10000, 41057, 100000, 'single'), 2128554),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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 high earner's long-term gains fall into the 0% band.

solve(ordinary, stcg, ltcg, status): stipulated two-schedule computation for status 'single' or 'mfj'. Net short- and long-term results against each other first. If the combined capital result is a loss, up to 3000 of it reduces ordinary income (floored at 0) and nothing is preferential. Otherwise positive net short-term gain is ordinary income, and net long-term gain is preferential. Ordinary income uses the status bracket table. Preferential gain is stacked on top of ordinary income: 0% up to T1, 15% up to T2, 20% above (single T1 47025, T2 518900; mfj 94050, 583750). Return total tax in integer cents (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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary, lt + st
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression short-term-character 1', (30000, 10000, 5000, 'single'), 456800),
  ('regression short-term-character 2', (80000, 12000, -4000, 'single'), 1441300),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200)],
 [('regression short-term-character 1', (40000, 5000, 0, 'single'), 516800),
  ('regression short-term-character 2', (200000, 35000, -3000, 'single'), 5192650),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression short-term-character 1', (90000, 33485, 348500, 'single'), 7495390),
  ('regression short-term-character 2', (550000, 5000, 0, 'mfj'), 13499950),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression short-term-character 1', (90000, 5000, 137466, 'single'), 3657290),
  ('regression short-term-character 2', (550000, 6898, 0, 'single'), 16528905),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression short-term-character 1', (550000, 5000, -3000, 'mfj'), 13394950),
  ('regression short-term-character 2', (10000, 47183, 20000, 'single'), 1063326),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt + st
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression short-term-character 1', (30000, 10000, 5000, 'single'), 456800),
  ('regression short-term-character 2', (80000, 12000, -4000, 'single'), 1441300),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200)],
 [('regression short-term-character 1', (40000, 5000, 0, 'single'), 516800),
  ('regression short-term-character 2', (200000, 35000, -3000, 'single'), 5192650),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression short-term-character 1', (90000, 33485, 348500, 'single'), 7495390),
  ('regression short-term-character 2', (550000, 5000, 0, 'mfj'), 13499950),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression short-term-character 1', (90000, 5000, 137466, 'single'), 3657290),
  ('regression short-term-character 2', (550000, 6898, 0, 'single'), 16528905),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression short-term-character 1', (550000, 5000, -3000, 'mfj'), 13394950),
  ('regression short-term-character 2', (10000, 47183, 20000, 'single'), 1063326),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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:
Short-term trading profits enjoy the 0/15% long-term rates.

solve(ordinary, stcg, ltcg, status): stipulated two-schedule computation for status 'single' or 'mfj'. Net short- and long-term results against each other first. If the combined capital result is a loss, up to 3000 of it reduces ordinary income (floored at 0) and nothing is preferential. Otherwise positive net short-term gain is ordinary income, and net long-term gain is preferential. Ordinary income uses the status bracket table. Preferential gain is stacked on top of ordinary income: 0% up to T1, 15% up to T2, 20% above (single T1 47025, T2 518900; mfj 94050, 583750). Return total tax in integer cents (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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: ordinary, st = ordinary - min(3000, -st), 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cross-netting 1', (100000, -8000, 20000, 'mfj'), 1390600),
  ('regression cross-netting 2', (60000, -2000, 9000, 'single'), 930300),
  ('partial repair guard 2', (550000, -8000, 135896, 'single'), 18845395),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200)],
 [('regression cross-netting 1', (550000, -8000, 135896, 'single'), 18845395),
  ('regression cross-netting 2', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 1', (9947, -13667, 100000, 'single'), 838295),
  ('partial repair guard 2', (173496, -15585, 20000, 'single'), 3534379),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression cross-netting 1', (9947, -13667, 100000, 'single'), 838295),
  ('regression cross-netting 2', (173496, -15585, 20000, 'single'), 3534379),
  ('partial repair guard 1', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 2', (40000, -6055, 100000, 'mfj'), 1032025),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression cross-netting 1', (40000, -8000, 20000, 'mfj'), 433600),
  ('regression cross-netting 2', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 1', (550000, -8000, 100000, 'single'), 18127475),
  ('partial repair guard 2', (0, -13215, 100000, 'mfj'), 0), ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression cross-netting 1', (40000, -6055, 100000, 'mfj'), 1032025),
  ('regression cross-netting 2', (90000, -1500, 259301, 'single'), 5352315),
  ('partial repair guard 1', (200000, -8000, 100000, 'single'), 5548650),
  ('partial repair guard 2', (200000, -18032, 100000, 'mfj'), 4640120),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt - min(3000, -st), 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cross-netting 1', (100000, -8000, 20000, 'mfj'), 1390600),
  ('regression cross-netting 2', (60000, -2000, 9000, 'single'), 930300),
  ('partial repair guard 2', (550000, -8000, 135896, 'single'), 18845395),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200)],
 [('regression cross-netting 1', (550000, -8000, 135896, 'single'), 18845395),
  ('regression cross-netting 2', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 1', (9947, -13667, 100000, 'single'), 838295),
  ('partial repair guard 2', (173496, -15585, 20000, 'single'), 3534379),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression cross-netting 1', (9947, -13667, 100000, 'single'), 838295),
  ('regression cross-netting 2', (173496, -15585, 20000, 'single'), 3534379),
  ('partial repair guard 1', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 2', (40000, -6055, 100000, 'mfj'), 1032025),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression cross-netting 1', (40000, -8000, 20000, 'mfj'), 433600),
  ('regression cross-netting 2', (0, -8000, 100000, 'single'), 674625),
  ('partial repair guard 1', (550000, -8000, 100000, 'single'), 18127475),
  ('partial repair guard 2', (0, -13215, 100000, 'mfj'), 0), ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression cross-netting 1', (40000, -6055, 100000, 'mfj'), 1032025),
  ('regression cross-netting 2', (90000, -1500, 259301, 'single'), 5352315),
  ('partial repair guard 1', (200000, -8000, 100000, 'single'), 5548650),
  ('partial repair guard 2', (200000, -18032, 100000, 'mfj'), 4640120),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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 short-term loss saves ordinary-rate tax although it should first absorb long-term gain.

solve(ordinary, stcg, ltcg, status): stipulated two-schedule computation for status 'single' or 'mfj'. Net short- and long-term results against each other first. If the combined capital result is a loss, up to 3000 of it reduces ordinary income (floored at 0) and nothing is preferential. Otherwise positive net short-term gain is ordinary income, and net long-term gain is preferential. Ordinary income uses the status bracket table. Preferential gain is stacked on top of ordinary income: 0% up to T1, 15% up to T2, 20% above (single T1 47025, T2 518900; mfj 94050, 583750). Return total tax in integer cents (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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - -(st + lt)), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression loss-limit 1', (60000, -5000, -5000, 'single'), 759300),
  ('regression loss-limit 2', (60000, -5000, 1000, 'single'), 759300),
  ('partial repair guard 2', (550000, -8000, -3000, 'mfj'), 13219950),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625), ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression loss-limit 1', (550000, -8000, -3000, 'mfj'), 13219950),
  ('regression loss-limit 2', (10000, -8000, 0, 'single'), 70000),
  ('partial repair guard 1', (524248, -16451, -3000, 'single'), 15281155),
  ('partial repair guard 2', (10000, -1500, -3000, 'single'), 70000),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression loss-limit 1', (524248, -16451, -3000, 'single'), 15281155),
  ('regression loss-limit 2', (10000, -1500, -3000, 'single'), 70000),
  ('partial repair guard 1', (200000, -1500, -3000, 'single'), 4072650),
  ('partial repair guard 2', (40000, -14459, -3000, 'single'), 420800),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression loss-limit 1', (90000, -8000, 0, 'single'), 1419300),
  ('regression loss-limit 2', (200000, -10458, 0, 'single'), 4072650),
  ('partial repair guard 1', (200000, 0, -3000, 'mfj'), 3344600),
  ('partial repair guard 2', (200000, 0, -3000, 'single'), 4072650),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression loss-limit 1', (200000, -1500, -3000, 'single'), 4072650),
  ('regression loss-limit 2', (40000, -14459, -3000, 'single'), 420800),
  ('partial repair guard 1', (0, 0, -3000, 'single'), 0),
  ('partial repair guard 2', (29587, -1500, -3000, 'single'), 295844),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 583750)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, max(0, -st)) + min(3000, max(0, -lt))), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression loss-limit 1', (60000, -5000, -5000, 'single'), 759300),
  ('regression loss-limit 2', (60000, -5000, 1000, 'single'), 759300),
  ('partial repair guard 2', (550000, -8000, -3000, 'mfj'), 13219950),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625), ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression loss-limit 1', (550000, -8000, -3000, 'mfj'), 13219950),
  ('regression loss-limit 2', (10000, -8000, 0, 'single'), 70000),
  ('partial repair guard 1', (524248, -16451, -3000, 'single'), 15281155),
  ('partial repair guard 2', (10000, -1500, -3000, 'single'), 70000),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression loss-limit 1', (524248, -16451, -3000, 'single'), 15281155),
  ('regression loss-limit 2', (10000, -1500, -3000, 'single'), 70000),
  ('partial repair guard 1', (200000, -1500, -3000, 'single'), 4072650),
  ('partial repair guard 2', (40000, -14459, -3000, 'single'), 420800),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression loss-limit 1', (90000, -8000, 0, 'single'), 1419300),
  ('regression loss-limit 2', (200000, -10458, 0, 'single'), 4072650),
  ('partial repair guard 1', (200000, 0, -3000, 'mfj'), 3344600),
  ('partial repair guard 2', (200000, 0, -3000, 'single'), 4072650),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression loss-limit 1', (200000, -1500, -3000, 'single'), 4072650),
  ('regression loss-limit 2', (40000, -14459, -3000, 'single'), 420800),
  ('partial repair guard 1', (0, 0, -3000, 'single'), 0),
  ('partial repair guard 2', (29587, -1500, -3000, 'single'), 295844),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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 10,000 capital loss wipes out 10,000 of wages.

solve(ordinary, stcg, ltcg, status): stipulated two-schedule computation for status 'single' or 'mfj'. Net short- and long-term results against each other first. If the combined capital result is a loss, up to 3000 of it reduces ordinary income (floored at 0) and nothing is preferential. Otherwise positive net short-term gain is ordinary income, and net long-term gain is preferential. Ordinary income uses the status bracket table. Preferential gain is stacked on top of ordinary income: 0% up to T1, 15% up to T2, 20% above (single T1 47025, T2 518900; mfj 94050, 583750). Return total tax in integer cents (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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (94050, 1037800)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression joint-band-thresholds 1', (500000, 0, 100000, 'mfj'), 13156200),
  ('regression joint-band-thresholds 2', (560000, 0, 60000, 'mfj'), 14756200),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression joint-band-thresholds 1', (550000, 0, 320650, 'mfj'), 19569200),
  ('regression joint-band-thresholds 2', (550000, 5000, 100000, 'mfj'), 15356200),
  ('partial repair guard 1', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 2', (90000, 0, 20000, 'mfj'), 1272850),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression joint-band-thresholds 1', (588832, 0, 373196, 'mfj'), 22147990),
  ('regression joint-band-thresholds 2', (550000, 0, 243937, 'mfj'), 18034940),
  ('partial repair guard 1', (40000, -8000, 20000, 'mfj'), 433600),
  ('partial repair guard 2', (550000, 0, 320650, 'mfj'), 19569200),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression joint-band-thresholds 1', (550000, 0, 100000, 'mfj'), 15156200),
  ('regression joint-band-thresholds 2', (561699, 0, 328035, 'mfj'), 20184860),
  ('partial repair guard 1', (10000, 0, 100000, 'mfj'), 339250),
  ('partial repair guard 2', (40000, -6055, 100000, 'mfj'), 1032025),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression joint-band-thresholds 1', (550000, -1500, 270123, 'mfj'), 18528660),
  ('regression joint-band-thresholds 2', (583930, 45863, 100000, 'mfj'), 18117705),
  ('partial repair guard 1', (550000, 0, 20000, 'mfj'), 13624950),
  ('partial repair guard 2', (40000, 5000, 100000, 'mfj'), 1257850),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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(ordinary, stcg, ltcg, status):
    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))

    brs = {'single': [[11600, '10'], [47150, '12'], [100525, '22'], [191950, '24'], [243725, '32'], [609350, '35'], [None, '37']], 'mfj': [[23200, '10'], [94300, '12'], [201050, '22'], [383900, '24'], [487450, '32'], [731200, '35'], [None, '37']]}
    bands = {'single': (47025, 518900), 'mfj': (47025, 518900)}
    t1, t2 = bands[status]
    st, lt = stcg, ltcg
    if st + lt < 0:
        ord_inc, pref = max(0, ordinary - min(3000, -(st + lt))), 0
    else:
        if st < 0: lt, st = lt + st, 0
        if lt < 0: st, lt = st + lt, 0
        ord_inc, pref = ordinary + st, lt
    lo, hi = ord_inc, ord_inc + pref
    fifteen = max(0, min(hi, t2) - max(lo, t1))
    twenty = max(0, hi - max(lo, t2))
    tax = prog(ord_inc, brs[status]) + Fraction(15, 100) * fifteen + Fraction(20, 100) * twenty
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression joint-band-thresholds 1', (500000, 0, 100000, 'mfj'), 13156200),
  ('regression joint-band-thresholds 2', (560000, 0, 60000, 'mfj'), 14756200),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression joint-band-thresholds 1', (550000, 0, 320650, 'mfj'), 19569200),
  ('regression joint-band-thresholds 2', (550000, 5000, 100000, 'mfj'), 15356200),
  ('partial repair guard 1', (430707, -1500, 100000, 'mfj'), 10797424),
  ('partial repair guard 2', (90000, 0, 20000, 'mfj'), 1272850),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300)],
 [('regression joint-band-thresholds 1', (588832, 0, 373196, 'mfj'), 22147990),
  ('regression joint-band-thresholds 2', (550000, 0, 243937, 'mfj'), 18034940),
  ('partial repair guard 1', (40000, -8000, 20000, 'mfj'), 433600),
  ('partial repair guard 2', (550000, 0, 320650, 'mfj'), 19569200),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 0),
  ('control: stacked partly in zero band', (40000, 0, 20000, 'single'), 651425),
  ('control: gain only', (0, 0, 50000, 'single'), 44625)],
 [('regression joint-band-thresholds 1', (550000, 0, 100000, 'mfj'), 15156200),
  ('regression joint-band-thresholds 2', (561699, 0, 328035, 'mfj'), 20184860),
  ('partial repair guard 1', (10000, 0, 100000, 'mfj'), 339250),
  ('partial repair guard 2', (40000, -6055, 100000, 'mfj'), 1032025),
  ('control: gain only', (0, 0, 50000, 'single'), 44625),
  ('control: net capital loss', (60000, -5000, 1000, 'single'), 759300),
  ('control: high mfj', (500000, 0, 100000, 'mfj'), 13156200),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800)],
 [('regression joint-band-thresholds 1', (550000, -1500, 270123, 'mfj'), 18528660),
  ('regression joint-band-thresholds 2', (583930, 45863, 100000, 'mfj'), 18117705),
  ('partial repair guard 1', (550000, 0, 20000, 'mfj'), 13624950),
  ('partial repair guard 2', (40000, 5000, 100000, 'mfj'), 1257850),
  ('control: short-term gain', (30000, 10000, 5000, 'single'), 456800),
  ('control: short loss offsets long', (100000, -8000, 20000, 'mfj'), 1390600),
  ('control: long loss offsets short', (80000, 12000, -4000, 'single'), 1441300),
  ('control: big loss capped', (2000, -9000, -1000, 'mfj'), 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 couples with large gains pay 15% where the joint schedule charges 20%.

solve(ordinary, stcg, ltcg, status): stipulated two-schedule computation for status 'single' or 'mfj'. Net short- and long-term results against each other first. If the combined capital result is a loss, up to 3000 of it reduces ordinary income (floored at 0) and nothing is preferential. Otherwise positive net short-term gain is ordinary income, and net long-term gain is preferential. Ordinary income uses the status bracket table. Preferential gain is stacked on top of ordinary income: 0% up to T1, 15% up to T2, 20% above (single T1 47025, T2 518900; mfj 94050, 583750). Return total tax in integer cents (half-up).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(income, pension):
    ani = income - pension
    allow = 12570
    if ani > 100000: allow = max(0, allow - (ani - 100000))
    taxable = max(0, ani - allow)
    basic = min(taxable, 37700)
    higher = max(0, min(taxable, 125140) - 37700)
    additional = max(0, taxable - 125140)
    return basic * 20 + higher * 40 + additional * 45
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression taper-ratio 1', (110001, 0), 3343240), ('regression taper-ratio 2', (110000, 0), 3343200),
  ('partial repair guard 2', (100003, 0), 2743360), ('control: basic and higher', (50000, 0), 748600),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300),
  ('control: allowance exhausted exactly', (125140, 0), 4251600)],
 [('regression taper-ratio 1', (130000, 5000), 4243200), ('regression taper-ratio 2', (100003, 0), 2743360),
  ('partial repair guard 1', (112519, 0), 3494320), ('partial repair guard 2', (113902, 1), 3577240),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)],
 [('regression taper-ratio 1', (112519, 0), 3494320), ('regression taper-ratio 2', (125142, 20000), 3051720),
  ('partial repair guard 1', (125141, 5000), 3951640), ('partial repair guard 2', (100001, 0), 2743240),
  ('control: below allowance', (9000, 0), 0), ('control: large pension', (160000, 60000), 2743200),
  ('control: mid taper', (140000, 0), 4920300), ('control: basic and higher', (50000, 0), 748600)],
 [('regression taper-ratio 1', (100003, 1), 2743320), ('regression taper-ratio 2', (102064, 0), 2867040),
  ('partial repair guard 1', (122175, 0), 4073680), ('partial repair guard 2', (120569, 0), 3977320),
  ('control: basic and higher', (50000, 0), 748600), ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300)],
 [('regression taper-ratio 1', (113902, 1), 3577240), ('regression taper-ratio 2', (105360, 0), 3064800),
  ('partial repair guard 1', (114809, 5000), 3331720), ('partial repair guard 2', (106705, 5000), 2845480),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 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

N = 1
observations = []
def solve(income, pension):
    ani = income - pension
    allow = 12570
    if ani > 100000: allow = max(0, allow - -(-(ani - 100000) // 2))
    taxable = max(0, ani - allow)
    basic = min(taxable, 37700)
    higher = max(0, min(taxable, 125140) - 37700)
    additional = max(0, taxable - 125140)
    return basic * 20 + higher * 40 + additional * 45
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression taper-ratio 1', (110001, 0), 3343240), ('regression taper-ratio 2', (110000, 0), 3343200),
  ('partial repair guard 2', (100003, 0), 2743360), ('control: basic and higher', (50000, 0), 748600),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300),
  ('control: allowance exhausted exactly', (125140, 0), 4251600)],
 [('regression taper-ratio 1', (130000, 5000), 4243200), ('regression taper-ratio 2', (100003, 0), 2743360),
  ('partial repair guard 1', (112519, 0), 3494320), ('partial repair guard 2', (113902, 1), 3577240),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)],
 [('regression taper-ratio 1', (112519, 0), 3494320), ('regression taper-ratio 2', (125142, 20000), 3051720),
  ('partial repair guard 1', (125141, 5000), 3951640), ('partial repair guard 2', (100001, 0), 2743240),
  ('control: below allowance', (9000, 0), 0), ('control: large pension', (160000, 60000), 2743200),
  ('control: mid taper', (140000, 0), 4920300), ('control: basic and higher', (50000, 0), 748600)],
 [('regression taper-ratio 1', (100003, 1), 2743320), ('regression taper-ratio 2', (102064, 0), 2867040),
  ('partial repair guard 1', (122175, 0), 4073680), ('partial repair guard 2', (120569, 0), 3977320),
  ('control: basic and higher', (50000, 0), 748600), ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300)],
 [('regression taper-ratio 1', (113902, 1), 3577240), ('regression taper-ratio 2', (105360, 0), 3064800),
  ('partial repair guard 1', (114809, 5000), 3331720), ('partial repair guard 2', (106705, 5000), 2845480),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 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:
The allowance vanishes at 112570 instead of 125140.

solve(income, pension): stipulated allowance taper in whole pounds. Adjusted net income ani = income - pension. The personal allowance 12570 is reduced by 1 for every 2 whole pounds of ani above 100000 (floor of half the excess), never below 0. Taxable = max(0, ani - allowance). Taxable income is taxed 20% up to 37700, 40% from 37700 to 125140, 45% above 125140. Return tax in integer pence.

split: open-access