broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(agi, exempt_interest, benefits, status):
    b1, b2 = {'single': (25000, 34000), 'mfj': (32000, 44000), 'mfs': (0, 0)}[status]
    B = Fraction(benefits)
    pi = agi + exempt_interest + B / 2
    if pi <= b1: t = Fraction(0)
    elif pi <= b2: t = min(B / 2, (pi - b1) / 2)
    else: t = min(B * 10, (pi - b2) * 85 / 100 + min(B / 2, Fraction(b2 - b1, 2)))
    return int(t)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression eighty-five-cap 1', (150000, 5000, 40000, 'mfj'), 34000),
  ('regression eighty-five-cap 2', (5000, 0, 8000, 'mfs'), 6800),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500)],
 [('regression eighty-five-cap 1', (40000, 0, 20000, 'single'), 17000),
  ('regression eighty-five-cap 2', (90000, 0, 20000, 'single'), 17000),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000)],
 [('regression eighty-five-cap 1', (10000, 0, 2000, 'mfs'), 1700),
  ('regression eighty-five-cap 2', (16953, 1000, 8000, 'mfs'), 6800),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000),
  ('control: below base', (10000, 0, 10000, 'single'), 0)],
 [('regression eighty-five-cap 1', (90000, 0, 20000, 'mfj'), 17000),
  ('regression eighty-five-cap 2', (90000, 1000, 20000, 'mfs'), 17000),
  ('partial repair guard 1', (45000, 0, 30934, 'mfj'), 19996),
  ('partial repair guard 2', (30000, 1000, 8000, 'single'), 4850),
  ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000)],
 [('regression eighty-five-cap 1', (30000, 0, 20000, 'mfs'), 17000),
  ('regression eighty-five-cap 2', (57417, 0, 20000, 'mfs'), 17000),
  ('partial repair guard 1', (90000, 0, 20000, 'mfj'), 17000),
  ('partial repair guard 2', (90000, 1000, 20000, 'mfs'), 17000),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000)]]
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(agi, exempt_interest, benefits, status):
    b1, b2 = {'single': (25000, 34000), 'mfj': (32000, 44000), 'mfs': (0, 0)}[status]
    B = Fraction(benefits)
    pi = agi + exempt_interest + B / 2
    if pi <= b1: t = Fraction(0)
    elif pi <= b2: t = min(B / 2, (pi - b1) / 2)
    else: t = min(B / 2, (pi - b2) * 85 / 100 + min(B / 2, Fraction(b2 - b1, 2)))
    return int(t)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression eighty-five-cap 1', (150000, 5000, 40000, 'mfj'), 34000),
  ('regression eighty-five-cap 2', (5000, 0, 8000, 'mfs'), 6800),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500)],
 [('regression eighty-five-cap 1', (40000, 0, 20000, 'single'), 17000),
  ('regression eighty-five-cap 2', (90000, 0, 20000, 'single'), 17000),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000)],
 [('regression eighty-five-cap 1', (10000, 0, 2000, 'mfs'), 1700),
  ('regression eighty-five-cap 2', (16953, 1000, 8000, 'mfs'), 6800),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000),
  ('control: below base', (10000, 0, 10000, 'single'), 0)],
 [('regression eighty-five-cap 1', (90000, 0, 20000, 'mfj'), 17000),
  ('regression eighty-five-cap 2', (90000, 1000, 20000, 'mfs'), 17000),
  ('partial repair guard 1', (45000, 0, 30934, 'mfj'), 19996),
  ('partial repair guard 2', (30000, 1000, 8000, 'single'), 4850),
  ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000)],
 [('regression eighty-five-cap 1', (30000, 0, 20000, 'mfs'), 17000),
  ('regression eighty-five-cap 2', (57417, 0, 20000, 'mfs'), 17000),
  ('partial repair guard 1', (90000, 0, 20000, 'mfj'), 17000),
  ('partial repair guard 2', (90000, 1000, 20000, 'mfs'), 17000),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000)]]
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:
High-income retirees include more than 85% of their benefits.

solve(agi, exempt_interest, benefits, status): stipulated benefit inclusion. Provisional income PI = agi + exempt_interest + benefits/2. Base amounts (b1, b2): single (25000, 34000), mfj (32000, 44000), mfs (0, 0). If PI <= b1 nothing is included; if PI <= b2, include min(benefits/2, (PI - b1)/2); otherwise include min(0.85*benefits, 0.85*(PI - b2) + min(benefits/2, (b2 - b1)/2)). Return the included amount rounded down to whole dollars.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(agi, exempt_interest, benefits, status):
    b1, b2 = {'single': (25000, 34000), 'mfj': (32000, 44000), 'mfs': (0, 0)}[status]
    B = Fraction(benefits)
    pi = agi + exempt_interest + B / 2
    if pi <= b1: t = Fraction(0)
    elif pi <= b2: t = (pi - b1) / 2
    else: t = min(B * 85 / 100, (pi - b2) * 85 / 100 + min(B / 2, Fraction(b2 - b1, 2)))
    return int(t)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression first-tier-cap 1', (28000, 0, 2000, 'single'), 1000),
  ('regression first-tier-cap 2', (30000, 0, 1000, 'single'), 500),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500)],
 [('regression first-tier-cap 1', (30000, 0, 2000, 'single'), 1000),
  ('regression first-tier-cap 2', (30000, 5000, 0, 'mfj'), 0),
  ('partial repair guard 2', (30000, 1000, 2000, 'single'), 1000),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000)],
 [('regression first-tier-cap 1', (30000, 0, 0, 'single'), 0),
  ('regression first-tier-cap 2', (30000, 1000, 0, 'single'), 0),
  ('partial repair guard 1', (30000, 0, 8000, 'single'), 4000),
  ('partial repair guard 2', (30000, 0, 1687, 'single'), 843),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000),
  ('control: below base', (10000, 0, 10000, 'single'), 0)],
 [('regression first-tier-cap 1', (30000, 1000, 2000, 'single'), 1000),
  ('regression first-tier-cap 2', (30000, 0, 8000, 'single'), 4000),
  ('partial repair guard 1', (28000, 0, 2000, 'single'), 1000),
  ('partial repair guard 2', (30000, 0, 1000, 'single'), 500), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000)],
 [('regression first-tier-cap 1', (30000, 0, 1687, 'single'), 843),
  ('regression first-tier-cap 2', (28000, 0, 2000, 'single'), 1000),
  ('partial repair guard 1', (30000, 0, 2000, 'single'), 1000),
  ('partial repair guard 2', (30000, 1000, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000),
  ('control: below base', (10000, 0, 10000, 'single'), 0)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(agi, exempt_interest, benefits, status):
    b1, b2 = {'single': (25000, 34000), 'mfj': (32000, 44000), 'mfs': (0, 0)}[status]
    B = Fraction(benefits)
    pi = agi + exempt_interest + B / 2
    if pi <= b1: t = Fraction(0)
    elif pi <= b2: t = min(B, (pi - b1) / 2)
    else: t = min(B * 85 / 100, (pi - b2) * 85 / 100 + min(B / 2, Fraction(b2 - b1, 2)))
    return int(t)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression first-tier-cap 1', (28000, 0, 2000, 'single'), 1000),
  ('regression first-tier-cap 2', (30000, 0, 1000, 'single'), 500),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500)],
 [('regression first-tier-cap 1', (30000, 0, 2000, 'single'), 1000),
  ('regression first-tier-cap 2', (30000, 5000, 0, 'mfj'), 0),
  ('partial repair guard 2', (30000, 1000, 2000, 'single'), 1000),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000)],
 [('regression first-tier-cap 1', (30000, 0, 0, 'single'), 0),
  ('regression first-tier-cap 2', (30000, 1000, 0, 'single'), 0),
  ('partial repair guard 1', (30000, 0, 8000, 'single'), 4000),
  ('partial repair guard 2', (30000, 0, 1687, 'single'), 843),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000),
  ('control: below base', (10000, 0, 10000, 'single'), 0)],
 [('regression first-tier-cap 1', (30000, 1000, 2000, 'single'), 1000),
  ('regression first-tier-cap 2', (30000, 0, 8000, 'single'), 4000),
  ('partial repair guard 1', (28000, 0, 2000, 'single'), 1000),
  ('partial repair guard 2', (30000, 0, 1000, 'single'), 500), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000)],
 [('regression first-tier-cap 1', (30000, 0, 1687, 'single'), 843),
  ('regression first-tier-cap 2', (28000, 0, 2000, 'single'), 1000),
  ('partial repair guard 1', (30000, 0, 2000, 'single'), 1000),
  ('partial repair guard 2', (30000, 1000, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000),
  ('control: below base', (10000, 0, 10000, 'single'), 0)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Small benefits are included beyond half their amount between the base amounts.

solve(agi, exempt_interest, benefits, status): stipulated benefit inclusion. Provisional income PI = agi + exempt_interest + benefits/2. Base amounts (b1, b2): single (25000, 34000), mfj (32000, 44000), mfs (0, 0). If PI <= b1 nothing is included; if PI <= b2, include min(benefits/2, (PI - b1)/2); otherwise include min(0.85*benefits, 0.85*(PI - b2) + min(benefits/2, (b2 - b1)/2)). Return the included amount rounded down to whole dollars.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(agi, exempt_interest, benefits, status):
    b1, b2 = {'single': (25000, 34000), 'mfj': (32000, 44000), 'mfs': (25000, 34000)}[status]
    B = Fraction(benefits)
    pi = agi + exempt_interest + B / 2
    if pi <= b1: t = Fraction(0)
    elif pi <= b2: t = min(B / 2, (pi - b1) / 2)
    else: t = min(B * 85 / 100, (pi - b2) * 85 / 100 + min(B / 2, Fraction(b2 - b1, 2)))
    return int(t)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression separate-filer-base 1', (5000, 0, 8000, 'mfs'), 6800),
  ('regression separate-filer-base 2', (15000, 0, 8000, 'mfs'), 6800),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500)],
 [('regression separate-filer-base 1', (10000, 0, 2000, 'mfs'), 1700),
  ('regression separate-filer-base 2', (16953, 1000, 8000, 'mfs'), 6800),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000)],
 [('regression separate-filer-base 1', (30000, 0, 20000, 'mfs'), 17000),
  ('regression separate-filer-base 2', (10000, 1000, 8000, 'mfs'), 6800),
  ('partial repair guard 2', (0, 1000, 20000, 'mfs'), 9350),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000),
  ('control: below base', (10000, 0, 10000, 'single'), 0)],
 [('regression separate-filer-base 1', (0, 1000, 20000, 'mfs'), 9350),
  ('regression separate-filer-base 2', (0, 0, 20000, 'mfs'), 8500),
  ('partial repair guard 2', (0, 5000, 20000, 'mfs'), 12750), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000)],
 [('regression separate-filer-base 1', (0, 5000, 20000, 'mfs'), 12750),
  ('regression separate-filer-base 2', (0, 0, 8000, 'mfs'), 3400),
  ('partial repair guard 2', (20000, 0, 20000, 'mfs'), 17000),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000)]]
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(agi, exempt_interest, benefits, status):
    b1, b2 = {'single': (25000, 34000), 'mfj': (32000, 44000), 'mfs': (12500, 17000)}[status]
    B = Fraction(benefits)
    pi = agi + exempt_interest + B / 2
    if pi <= b1: t = Fraction(0)
    elif pi <= b2: t = min(B / 2, (pi - b1) / 2)
    else: t = min(B * 85 / 100, (pi - b2) * 85 / 100 + min(B / 2, Fraction(b2 - b1, 2)))
    return int(t)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression separate-filer-base 1', (5000, 0, 8000, 'mfs'), 6800),
  ('regression separate-filer-base 2', (15000, 0, 8000, 'mfs'), 6800),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500)],
 [('regression separate-filer-base 1', (10000, 0, 2000, 'mfs'), 1700),
  ('regression separate-filer-base 2', (16953, 1000, 8000, 'mfs'), 6800),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000)],
 [('regression separate-filer-base 1', (30000, 0, 20000, 'mfs'), 17000),
  ('regression separate-filer-base 2', (10000, 1000, 8000, 'mfs'), 6800),
  ('partial repair guard 2', (0, 1000, 20000, 'mfs'), 9350),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000),
  ('control: below base', (10000, 0, 10000, 'single'), 0)],
 [('regression separate-filer-base 1', (0, 1000, 20000, 'mfs'), 9350),
  ('regression separate-filer-base 2', (0, 0, 20000, 'mfs'), 8500),
  ('partial repair guard 2', (0, 5000, 20000, 'mfs'), 12750), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: joint with exempt interest', (30000, 1000, 20000, 'mfj'), 4500),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000)],
 [('regression separate-filer-base 1', (0, 5000, 20000, 'mfs'), 12750),
  ('regression separate-filer-base 2', (0, 0, 8000, 'mfs'), 3400),
  ('partial repair guard 2', (20000, 0, 20000, 'mfs'), 17000),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000),
  ('control: large income', (150000, 5000, 40000, 'mfj'), 34000),
  ('control: first tier', (20000, 0, 12000, 'single'), 500),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000)]]
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:
Separate filers include nothing below 25000 of provisional income.

solve(agi, exempt_interest, benefits, status): stipulated benefit inclusion. Provisional income PI = agi + exempt_interest + benefits/2. Base amounts (b1, b2): single (25000, 34000), mfj (32000, 44000), mfs (0, 0). If PI <= b1 nothing is included; if PI <= b2, include min(benefits/2, (PI - b1)/2); otherwise include min(0.85*benefits, 0.85*(PI - b2) + min(benefits/2, (b2 - b1)/2)). Return the included amount rounded down to whole dollars.

split: open-access


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

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest > 11600: return 0
    rin, cap, mx, rout, start = P[min(children, 3)]
    if mfj: start += 6920
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = earned
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(max(0, credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression phaseout-income 1', (12000, 30000, 1, False, 0), 264629),
  ('regression phaseout-income 2', (10000, 30000, 0, False, 11600), 0),
  ('partial repair guard 1', (30000, 10000, 2, False, 0), 482654),
  ('partial repair guard 2', (16510, 0, 0, False, 0), 8669), ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250)],
 [('regression phaseout-income 1', (5000, 71254, 2, True, 0), 0),
  ('regression phaseout-income 2', (16510, 30000, 1, True, 11600), 375210),
  ('partial repair guard 1', (30678, 10000, 5, False, 11600), 550975),
  ('partial repair guard 2', (40000, 10000, 5, True, 11600), 500389),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression phaseout-income 1', (10000, 30000, 5, False, 0), 272254),
  ('regression phaseout-income 2', (5000, 30000, 1, True, 0), 145710),
  ('partial repair guard 1', (40000, 0, 0, False, 0), 0),
  ('partial repair guard 2', (25000, 10000, 1, False, 11600), 344529),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression phaseout-income 1', (10000, 26004, 0, False, 0), 0),
  ('regression phaseout-income 2', (5000, 30000, 2, False, 11600), 22254),
  ('partial repair guard 1', (25000, 10000, 2, False, 0), 587954),
  ('partial repair guard 2', (39928, 0, 3, False, 0), 356170),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression phaseout-income 1', (10000, 30000, 5, False, 11600), 272254),
  ('regression phaseout-income 2', (5000, 30000, 1, False, 0), 35129),
  ('partial repair guard 1', (40000, 30000, 3, False, 11600), 354654),
  ('partial repair guard 2', (10000, 0, 0, False, 0), 58470),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest > 11600: return 0
    rin, cap, mx, rout, start = P[min(children, 3)]
    if mfj: start += 6920
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = agi
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(max(0, credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression phaseout-income 1', (12000, 30000, 1, False, 0), 264629),
  ('regression phaseout-income 2', (10000, 30000, 0, False, 11600), 0),
  ('partial repair guard 1', (30000, 10000, 2, False, 0), 482654),
  ('partial repair guard 2', (16510, 0, 0, False, 0), 8669), ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250)],
 [('regression phaseout-income 1', (5000, 71254, 2, True, 0), 0),
  ('regression phaseout-income 2', (16510, 30000, 1, True, 11600), 375210),
  ('partial repair guard 1', (30678, 10000, 5, False, 11600), 550975),
  ('partial repair guard 2', (40000, 10000, 5, True, 11600), 500389),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression phaseout-income 1', (10000, 30000, 5, False, 0), 272254),
  ('regression phaseout-income 2', (5000, 30000, 1, True, 0), 145710),
  ('partial repair guard 1', (40000, 0, 0, False, 0), 0),
  ('partial repair guard 2', (25000, 10000, 1, False, 11600), 344529),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression phaseout-income 1', (10000, 26004, 0, False, 0), 0),
  ('regression phaseout-income 2', (5000, 30000, 2, False, 11600), 22254),
  ('partial repair guard 1', (25000, 10000, 2, False, 0), 587954),
  ('partial repair guard 2', (39928, 0, 3, False, 0), 356170),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression phaseout-income 1', (10000, 30000, 5, False, 11600), 272254),
  ('regression phaseout-income 2', (5000, 30000, 1, False, 0), 35129),
  ('partial repair guard 1', (40000, 30000, 3, False, 11600), 354654),
  ('partial repair guard 2', (10000, 0, 0, False, 0), 58470),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A filer with large investment-free non-wage income keeps the full credit.

solve(earned, agi, children, mfj, invest): stipulated earned-income credit, whole dollars. Investment income above 11600 disqualifies (0). Parameters by min(children, 3): phase-in rate %, max credit, phase-out rate %, phase-out start (0: 7.65, 600, 7.65, 9800; 1: 34, 3995, 15.98, 21560; 2: 40, 6604, 21.06, 21560; 3+: 45, 7430, 21.06, 21560); joint filers add 6920 to the start. Credit = min(rate_in*earned, max) reduced by rate_out*(max(earned, agi) - start) when positive, floored at 0. Return 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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest > 11600: return 0
    rin, cap, mx, rout, start = P[min(children, 3)]
    pass
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = max(earned, agi)
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(max(0, credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression joint-offset 1', (30000, 30000, 2, True, 0), 628389),
  ('regression joint-offset 2', (12000, 12000, 0, True, 0), 60000),
  ('partial repair guard 2', (10000, 0, 0, True, 0), 60000), ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression joint-offset 1', (16510, 30000, 1, True, 11600), 375210),
  ('regression joint-offset 2', (5000, 30000, 1, True, 0), 145710),
  ('partial repair guard 1', (10000, 0, 0, True, 11600), 60000),
  ('partial repair guard 2', (12000, 12000, 0, True, 0), 60000),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression joint-offset 1', (40000, 10000, 5, True, 11600), 500389),
  ('regression joint-offset 2', (5000, 30000, 5, True, 0), 192989),
  ('partial repair guard 1', (10000, 0, 0, True, 0), 60000),
  ('partial repair guard 2', (10000, 0, 0, True, 11600), 60000),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression joint-offset 1', (5000, 30000, 3, True, 0), 192989),
  ('regression joint-offset 2', (23681, 10000, 5, True, 11600), 743000),
  ('partial repair guard 1', (12000, 12000, 0, True, 0), 60000),
  ('partial repair guard 2', (10000, 0, 0, True, 0), 60000), ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression joint-offset 1', (25000, 0, 2, True, 11600), 660400),
  ('regression joint-offset 2', (40000, 30000, 2, True, 11600), 417789),
  ('partial repair guard 1', (10000, 0, 0, True, 11600), 60000),
  ('partial repair guard 2', (12000, 12000, 0, True, 0), 60000),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest > 11600: return 0
    rin, cap, mx, rout, start = P[min(children, 3)]
    if mfj and children: start += 6920
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = max(earned, agi)
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(max(0, credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression joint-offset 1', (30000, 30000, 2, True, 0), 628389),
  ('regression joint-offset 2', (12000, 12000, 0, True, 0), 60000),
  ('partial repair guard 2', (10000, 0, 0, True, 0), 60000), ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression joint-offset 1', (16510, 30000, 1, True, 11600), 375210),
  ('regression joint-offset 2', (5000, 30000, 1, True, 0), 145710),
  ('partial repair guard 1', (10000, 0, 0, True, 11600), 60000),
  ('partial repair guard 2', (12000, 12000, 0, True, 0), 60000),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression joint-offset 1', (40000, 10000, 5, True, 11600), 500389),
  ('regression joint-offset 2', (5000, 30000, 5, True, 0), 192989),
  ('partial repair guard 1', (10000, 0, 0, True, 0), 60000),
  ('partial repair guard 2', (10000, 0, 0, True, 11600), 60000),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression joint-offset 1', (5000, 30000, 3, True, 0), 192989),
  ('regression joint-offset 2', (23681, 10000, 5, True, 11600), 743000),
  ('partial repair guard 1', (12000, 12000, 0, True, 0), 60000),
  ('partial repair guard 2', (10000, 0, 0, True, 0), 60000), ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression joint-offset 1', (25000, 0, 2, True, 11600), 660400),
  ('regression joint-offset 2', (40000, 30000, 2, True, 11600), 417789),
  ('partial repair guard 1', (10000, 0, 0, True, 11600), 60000),
  ('partial repair guard 2', (12000, 12000, 0, True, 0), 60000),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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 lose credit earlier than stipulated.

solve(earned, agi, children, mfj, invest): stipulated earned-income credit, whole dollars. Investment income above 11600 disqualifies (0). Parameters by min(children, 3): phase-in rate %, max credit, phase-out rate %, phase-out start (0: 7.65, 600, 7.65, 9800; 1: 34, 3995, 15.98, 21560; 2: 40, 6604, 21.06, 21560; 3+: 45, 7430, 21.06, 21560); joint filers add 6920 to the start. Credit = min(rate_in*earned, max) reduced by rate_out*(max(earned, agi) - start) when positive, floored at 0. Return 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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    pass
    rin, cap, mx, rout, start = P[min(children, 3)]
    if mfj: start += 6920
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = max(earned, agi)
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(max(0, credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression investment-disqualification 1', (20000, 20000, 1, False, 11601), 0),
  ('regression investment-disqualification 2', (5000, 28763, 3, False, 20000), 0),
  ('partial repair guard 1', (15000, 15000, 3, True, 11600), 675000),
  ('partial repair guard 2', (16510, 30000, 1, True, 11600), 375210),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: no children', (5000, 5000, 0, False, 0), 38250)],
 [('regression investment-disqualification 1', (25000, 10000, 3, False, 11601), 0),
  ('regression investment-disqualification 2', (40000, 10000, 1, True, 20000), 0),
  ('partial repair guard 1', (5000, 0, 0, False, 11600), 38250),
  ('partial repair guard 2', (30678, 10000, 5, False, 11600), 550975),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression investment-disqualification 1', (10000, 0, 4, True, 20000), 0),
  ('regression investment-disqualification 2', (25000, 30000, 3, False, 11601), 0),
  ('partial repair guard 1', (40000, 10000, 5, True, 11600), 500389),
  ('partial repair guard 2', (5000, 30000, 2, False, 11600), 22254),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression investment-disqualification 1', (5000, 30000, 4, False, 20000), 0),
  ('regression investment-disqualification 2', (5000, 4110, 0, False, 11601), 0),
  ('partial repair guard 1', (10000, 30000, 5, False, 11600), 272254),
  ('partial repair guard 2', (25000, 10000, 1, False, 11600), 344529),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression investment-disqualification 1', (5000, 30000, 4, True, 11601), 0),
  ('regression investment-disqualification 2', (10000, 0, 5, True, 20000), 0),
  ('partial repair guard 1', (40000, 30000, 3, False, 11600), 354654),
  ('partial repair guard 2', (10000, 0, 5, True, 11600), 450000),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest >= 11600: return 0
    rin, cap, mx, rout, start = P[min(children, 3)]
    if mfj: start += 6920
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = max(earned, agi)
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(max(0, credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression investment-disqualification 1', (20000, 20000, 1, False, 11601), 0),
  ('regression investment-disqualification 2', (5000, 28763, 3, False, 20000), 0),
  ('partial repair guard 1', (15000, 15000, 3, True, 11600), 675000),
  ('partial repair guard 2', (16510, 30000, 1, True, 11600), 375210),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: no children', (5000, 5000, 0, False, 0), 38250)],
 [('regression investment-disqualification 1', (25000, 10000, 3, False, 11601), 0),
  ('regression investment-disqualification 2', (40000, 10000, 1, True, 20000), 0),
  ('partial repair guard 1', (5000, 0, 0, False, 11600), 38250),
  ('partial repair guard 2', (30678, 10000, 5, False, 11600), 550975),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression investment-disqualification 1', (10000, 0, 4, True, 20000), 0),
  ('regression investment-disqualification 2', (25000, 30000, 3, False, 11601), 0),
  ('partial repair guard 1', (40000, 10000, 5, True, 11600), 500389),
  ('partial repair guard 2', (5000, 30000, 2, False, 11600), 22254),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression investment-disqualification 1', (5000, 30000, 4, False, 20000), 0),
  ('regression investment-disqualification 2', (5000, 4110, 0, False, 11601), 0),
  ('partial repair guard 1', (10000, 30000, 5, False, 11600), 272254),
  ('partial repair guard 2', (25000, 10000, 1, False, 11600), 344529),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression investment-disqualification 1', (5000, 30000, 4, True, 11601), 0),
  ('regression investment-disqualification 2', (10000, 0, 5, True, 20000), 0),
  ('partial repair guard 1', (40000, 30000, 3, False, 11600), 354654),
  ('partial repair guard 2', (10000, 0, 5, True, 11600), 450000),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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:
Filers with investment income over the limit still receive most of the credit.

solve(earned, agi, children, mfj, invest): stipulated earned-income credit, whole dollars. Investment income above 11600 disqualifies (0). Parameters by min(children, 3): phase-in rate %, max credit, phase-out rate %, phase-out start (0: 7.65, 600, 7.65, 9800; 1: 34, 3995, 15.98, 21560; 2: 40, 6604, 21.06, 21560; 3+: 45, 7430, 21.06, 21560); joint filers add 6920 to the start. Credit = min(rate_in*earned, max) reduced by rate_out*(max(earned, agi) - start) when positive, floored at 0. Return 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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest > 11600: return 0
    rin, cap, mx, rout, start = P[min(children, 2)]
    if mfj: start += 6920
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = max(earned, agi)
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(max(0, credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression children-cap 1', (15000, 15000, 4, False, 0), 675000),
  ('regression children-cap 2', (15000, 15000, 3, False, 0), 675000),
  ('partial repair guard 2', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression children-cap 1', (15000, 15000, 3, True, 11600), 675000),
  ('regression children-cap 2', (10000, 30000, 5, False, 0), 272254),
  ('partial repair guard 1', (39928, 0, 3, False, 0), 356170),
  ('partial repair guard 2', (40000, 30000, 3, False, 11600), 354654),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression children-cap 1', (30678, 10000, 5, False, 11600), 550975),
  ('regression children-cap 2', (40000, 10000, 5, True, 11600), 500389),
  ('partial repair guard 1', (31680, 0, 3, False, 11600), 529873),
  ('partial repair guard 2', (5000, 30000, 3, True, 0), 192989),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression children-cap 1', (10000, 30000, 5, False, 11600), 272254),
  ('regression children-cap 2', (5000, 10000, 4, True, 0), 225000),
  ('partial repair guard 1', (40000, 0, 3, True, 0), 500389),
  ('partial repair guard 2', (5000, 0, 3, False, 0), 225000), ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression children-cap 1', (39928, 0, 3, False, 0), 356170),
  ('regression children-cap 2', (40000, 30000, 3, False, 11600), 354654),
  ('partial repair guard 1', (5000, 30000, 3, False, 0), 47254),
  ('partial repair guard 2', (40000, 17532, 3, False, 0), 354654),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest > 11600: return 0
    rin, cap, mx, rout, start = (P[3] if children >= 4 else P[min(children, 2)])
    if mfj: start += 6920
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = max(earned, agi)
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(max(0, credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression children-cap 1', (15000, 15000, 4, False, 0), 675000),
  ('regression children-cap 2', (15000, 15000, 3, False, 0), 675000),
  ('partial repair guard 2', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression children-cap 1', (15000, 15000, 3, True, 11600), 675000),
  ('regression children-cap 2', (10000, 30000, 5, False, 0), 272254),
  ('partial repair guard 1', (39928, 0, 3, False, 0), 356170),
  ('partial repair guard 2', (40000, 30000, 3, False, 11600), 354654),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression children-cap 1', (30678, 10000, 5, False, 11600), 550975),
  ('regression children-cap 2', (40000, 10000, 5, True, 11600), 500389),
  ('partial repair guard 1', (31680, 0, 3, False, 11600), 529873),
  ('partial repair guard 2', (5000, 30000, 3, True, 0), 192989),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression children-cap 1', (10000, 30000, 5, False, 11600), 272254),
  ('regression children-cap 2', (5000, 10000, 4, True, 0), 225000),
  ('partial repair guard 1', (40000, 0, 3, True, 0), 500389),
  ('partial repair guard 2', (5000, 0, 3, False, 0), 225000), ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression children-cap 1', (39928, 0, 3, False, 0), 356170),
  ('regression children-cap 2', (40000, 30000, 3, False, 11600), 354654),
  ('partial repair guard 1', (5000, 30000, 3, False, 0), 47254),
  ('partial repair guard 2', (40000, 17532, 3, False, 0), 354654),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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:
Larger families get the two-child maximum credit.

solve(earned, agi, children, mfj, invest): stipulated earned-income credit, whole dollars. Investment income above 11600 disqualifies (0). Parameters by min(children, 3): phase-in rate %, max credit, phase-out rate %, phase-out start (0: 7.65, 600, 7.65, 9800; 1: 34, 3995, 15.98, 21560; 2: 40, 6604, 21.06, 21560; 3+: 45, 7430, 21.06, 21560); joint filers add 6920 to the start. Credit = min(rate_in*earned, max) reduced by rate_out*(max(earned, agi) - start) when positive, floored at 0. Return 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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest > 11600: return 0
    rin, cap, mx, rout, start = P[min(children, 3)]
    if mfj: start += 6920
    credit = min(Fraction(rin) * earned / 100, Fraction(mx))
    income = max(earned, agi)
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(credit)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression credit-floor 1', (60000, 60000, 1, False, 0), 0),
  ('regression credit-floor 2', (10000, 30000, 0, False, 11600), 0),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression credit-floor 1', (0, 30000, 4, False, 0), 0),
  ('regression credit-floor 2', (5000, 71254, 2, True, 0), 0),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression credit-floor 1', (10000, 26004, 0, False, 0), 0),
  ('regression credit-floor 2', (0, 30000, 1, True, 0), 0),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression credit-floor 1', (40000, 0, 0, False, 0), 0),
  ('regression credit-floor 2', (31037, 58565, 4, False, 0), 0),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression credit-floor 1', (40000, 10000, 0, True, 11600), 0),
  ('regression credit-floor 2', (16510, 30000, 0, True, 11600), 0),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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(earned, agi, children, mfj, invest):
    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))

    P = {0: ['7.65', 7840, 600, '7.65', 9800], 1: ['34', 11750, 3995, '15.98', 21560], 2: ['40', 16510, 6604, '21.06', 21560], 3: ['45', 16510, 7430, '21.06', 21560]}
    if invest > 11600: return 0
    rin, cap, mx, rout, start = P[min(children, 3)]
    if mfj: start += 6920
    credit = max(0, min(Fraction(rin) * earned / 100, Fraction(mx)))
    income = max(earned, agi)
    if income > start: credit -= Fraction(rout) * (income - start) / 100
    return cents(credit)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression credit-floor 1', (60000, 60000, 1, False, 0), 0),
  ('regression credit-floor 2', (10000, 30000, 0, False, 11600), 0),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression credit-floor 1', (0, 30000, 4, False, 0), 0),
  ('regression credit-floor 2', (5000, 71254, 2, True, 0), 0),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)],
 [('regression credit-floor 1', (10000, 26004, 0, False, 0), 0),
  ('regression credit-floor 2', (0, 30000, 1, True, 0), 0),
  ('control: four children', (15000, 15000, 4, False, 0), 675000),
  ('control: phased to zero', (60000, 60000, 1, False, 0), 0),
  ('control: investment at limit', (15000, 15000, 3, True, 11600), 675000),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000)],
 [('regression credit-floor 1', (40000, 0, 0, False, 0), 0),
  ('regression credit-floor 2', (31037, 58565, 4, False, 0), 0),
  ('control: plateau', (10000, 10000, 1, False, 0), 340000),
  ('control: phase-out two children', (30000, 30000, 2, False, 0), 482654),
  ('control: agi drives phase-out', (12000, 30000, 1, False, 0), 264629),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0)],
 [('regression credit-floor 1', (40000, 10000, 0, True, 11600), 0),
  ('regression credit-floor 2', (16510, 30000, 0, True, 11600), 0),
  ('control: investment limit', (20000, 20000, 1, False, 11601), 0),
  ('control: no children', (5000, 5000, 0, False, 0), 38250), ('control: joint', (30000, 30000, 2, True, 0), 628389),
  ('control: four children', (15000, 15000, 4, False, 0), 675000)]]
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:
High earners claiming the credit see an additional tax.

solve(earned, agi, children, mfj, invest): stipulated earned-income credit, whole dollars. Investment income above 11600 disqualifies (0). Parameters by min(children, 3): phase-in rate %, max credit, phase-out rate %, phase-out start (0: 7.65, 600, 7.65, 9800; 1: 34, 3995, 15.98, 21560; 2: 40, 6604, 21.06, 21560; 3+: 45, 7430, 21.06, 21560); joint filers add 6920 to the start. Credit = min(rate_in*earned, max) reduced by rate_out*(max(earned, agi) - start) when positive, floored at 0. Return 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(income_tax, joint):
    thr = 1813000 * (2 if joint else 1)
    if income_tax <= thr: return 0
    soli = min(income_tax * Fraction(55, 1000), income_tax * Fraction(119, 1000))
    return int(soli)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression glide-base 1', (1900000, False), 10353), ('regression glide-base 2', (3700000, True), 8806),
  ('partial repair guard 1', (5000000, False), 275000), ('partial repair guard 2', (3626001, False), 199430),
  ('control: at limit', (1813000, False), 0), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953)],
 [('regression glide-base 1', (3300000, False), 176953), ('regression glide-base 2', (1813009, False), 1),
  ('partial repair guard 1', (3835420, False), 210948), ('partial repair guard 2', (3974588, False), 218602),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353)],
 [('regression glide-base 1', (1983210, False), 20254), ('regression glide-base 2', (1813001, False), 0),
  ('partial repair guard 1', (3508965, False), 192993), ('partial repair guard 2', (3491244, False), 192018),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)],
 [('regression glide-base 1', (3626001, True), 0), ('regression glide-base 2', (4499538, True), 103951),
  ('partial repair guard 1', (3409571, False), 187526), ('partial repair guard 2', (4398816, False), 241934),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953), ('control: at limit', (1813000, False), 0)],
 [('regression glide-base 1', (3256603, False), 171788), ('regression glide-base 2', (2115665, False), 36017),
  ('partial repair guard 1', (5112893, False), 281209), ('partial repair guard 2', (4374325, False), 240587),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income_tax, joint):
    thr = 1813000 * (2 if joint else 1)
    if income_tax <= thr: return 0
    soli = (income_tax - thr) * Fraction(119, 1000)
    return int(soli)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression glide-base 1', (1900000, False), 10353), ('regression glide-base 2', (3700000, True), 8806),
  ('partial repair guard 1', (5000000, False), 275000), ('partial repair guard 2', (3626001, False), 199430),
  ('control: at limit', (1813000, False), 0), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953)],
 [('regression glide-base 1', (3300000, False), 176953), ('regression glide-base 2', (1813009, False), 1),
  ('partial repair guard 1', (3835420, False), 210948), ('partial repair guard 2', (3974588, False), 218602),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353)],
 [('regression glide-base 1', (1983210, False), 20254), ('regression glide-base 2', (1813001, False), 0),
  ('partial repair guard 1', (3508965, False), 192993), ('partial repair guard 2', (3491244, False), 192018),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)],
 [('regression glide-base 1', (3626001, True), 0), ('regression glide-base 2', (4499538, True), 103951),
  ('partial repair guard 1', (3409571, False), 187526), ('partial repair guard 2', (4398816, False), 241934),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953), ('control: at limit', (1813000, False), 0)],
 [('regression glide-base 1', (3256603, False), 171788), ('regression glide-base 2', (2115665, False), 36017),
  ('partial repair guard 1', (5112893, False), 281209), ('partial repair guard 2', (4374325, False), 240587),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)]]
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:
Filers just above the limit pay the full 5.5% surcharge.

solve(income_tax, joint): stipulated surcharge on income tax, in integer cents. The exemption limit is 1813000 (doubled for joint assessment). At or below it the surcharge is 0; above it the surcharge is the lesser of 5.5% of the income tax and 11.9% of the excess over the limit (a gliding zone), rounded down to cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income_tax, joint):
    thr = 1813000 * (2 if joint else 1)
    if income_tax <= thr: return 0
    soli = max(income_tax * Fraction(55, 1000), (income_tax - thr) * Fraction(119, 1000))
    return int(soli)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression lesser-of 1', (5000000, False), 275000), ('regression lesser-of 2', (1900000, False), 10353),
  ('control: at limit', (1813000, False), 0), ('control: joint glide', (3700000, True), 8806),
  ('control: joint below', (3000000, True), 0), ('control: glide edge', (3300000, False), 176953)],
 [('regression lesser-of 1', (3700000, True), 8806), ('regression lesser-of 2', (3300000, False), 176953),
  ('control: joint below', (3000000, True), 0), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000)],
 [('regression lesser-of 1', (3626001, False), 199430), ('regression lesser-of 2', (1813009, False), 1),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)],
 [('regression lesser-of 1', (1983210, False), 20254), ('regression lesser-of 2', (1813001, False), 0),
  ('partial repair guard 2', (4499538, True), 103951), ('control: joint glide', (3700000, True), 8806),
  ('control: joint below', (3000000, True), 0), ('control: glide edge', (3300000, False), 176953),
  ('control: at limit', (1813000, False), 0)],
 [('regression lesser-of 1', (3626001, True), 0), ('regression lesser-of 2', (4499538, True), 103951),
  ('partial repair guard 1', (3835420, False), 210948), ('partial repair guard 2', (3256603, False), 171788),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income_tax, joint):
    thr = 1813000 * (2 if joint else 1)
    if income_tax <= thr: return 0
    soli = (income_tax - thr) * Fraction(55, 1000)
    return int(soli)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression lesser-of 1', (5000000, False), 275000), ('regression lesser-of 2', (1900000, False), 10353),
  ('control: at limit', (1813000, False), 0), ('control: joint glide', (3700000, True), 8806),
  ('control: joint below', (3000000, True), 0), ('control: glide edge', (3300000, False), 176953)],
 [('regression lesser-of 1', (3700000, True), 8806), ('regression lesser-of 2', (3300000, False), 176953),
  ('control: joint below', (3000000, True), 0), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000)],
 [('regression lesser-of 1', (3626001, False), 199430), ('regression lesser-of 2', (1813009, False), 1),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)],
 [('regression lesser-of 1', (1983210, False), 20254), ('regression lesser-of 2', (1813001, False), 0),
  ('partial repair guard 2', (4499538, True), 103951), ('control: joint glide', (3700000, True), 8806),
  ('control: joint below', (3000000, True), 0), ('control: glide edge', (3300000, False), 176953),
  ('control: at limit', (1813000, False), 0)],
 [('regression lesser-of 1', (3626001, True), 0), ('regression lesser-of 2', (4499538, True), 103951),
  ('partial repair guard 1', (3835420, False), 210948), ('partial repair guard 2', (3256603, False), 171788),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)]]
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:
High incomes pay 11.9% of the excess instead of 5.5% of the tax.

solve(income_tax, joint): stipulated surcharge on income tax, in integer cents. The exemption limit is 1813000 (doubled for joint assessment). At or below it the surcharge is 0; above it the surcharge is the lesser of 5.5% of the income tax and 11.9% of the excess over the limit (a gliding zone), rounded down to cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income_tax, joint):
    thr = 1813000
    if income_tax <= thr: return 0
    soli = min(income_tax * Fraction(55, 1000), (income_tax - thr) * Fraction(119, 1000))
    return int(soli)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression joint-limit 1', (3700000, True), 8806), ('regression joint-limit 2', (3000000, True), 0),
  ('partial repair guard 2', (3626001, True), 0), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000),
  ('control: glide edge', (3300000, False), 176953)],
 [('regression joint-limit 1', (1813009, True), 0), ('regression joint-limit 2', (3626001, True), 0),
  ('partial repair guard 1', (4499538, True), 103951), ('partial repair guard 2', (4442992, True), 97222),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953), ('control: at limit', (1813000, False), 0)],
 [('regression joint-limit 1', (4499538, True), 103951), ('regression joint-limit 2', (2007148, True), 0),
  ('partial repair guard 1', (3675221, True), 5857), ('partial repair guard 2', (5462037, True), 218488),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)],
 [('regression joint-limit 1', (2212099, True), 0), ('regression joint-limit 2', (3158865, True), 0),
  ('partial repair guard 1', (5229138, True), 190773), ('partial repair guard 2', (5134546, True), 179516),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953), ('control: at limit', (1813000, False), 0)],
 [('regression joint-limit 1', (2685272, True), 0), ('regression joint-limit 2', (2964428, True), 0),
  ('partial repair guard 1', (4465171, True), 99861), ('partial repair guard 2', (3657037, True), 3693),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income_tax, joint):
    thr = 1813000
    if income_tax <= thr * (2 if joint else 1): return 0
    soli = min(income_tax * Fraction(55, 1000), (income_tax - thr) * Fraction(119, 1000))
    return int(soli)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression joint-limit 1', (3700000, True), 8806), ('regression joint-limit 2', (3000000, True), 0),
  ('partial repair guard 2', (3626001, True), 0), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000),
  ('control: glide edge', (3300000, False), 176953)],
 [('regression joint-limit 1', (1813009, True), 0), ('regression joint-limit 2', (3626001, True), 0),
  ('partial repair guard 1', (4499538, True), 103951), ('partial repair guard 2', (4442992, True), 97222),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953), ('control: at limit', (1813000, False), 0)],
 [('regression joint-limit 1', (4499538, True), 103951), ('regression joint-limit 2', (2007148, True), 0),
  ('partial repair guard 1', (3675221, True), 5857), ('partial repair guard 2', (5462037, True), 218488),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)],
 [('regression joint-limit 1', (2212099, True), 0), ('regression joint-limit 2', (3158865, True), 0),
  ('partial repair guard 1', (5229138, True), 190773), ('partial repair guard 2', (5134546, True), 179516),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953), ('control: at limit', (1813000, False), 0)],
 [('regression joint-limit 1', (2685272, True), 0), ('regression joint-limit 2', (2964428, True), 0),
  ('partial repair guard 1', (4465171, True), 99861), ('partial repair guard 2', (3657037, True), 3693),
  ('control: at limit', (1813000, False), 0), ('control: gliding zone', (1900000, False), 10353),
  ('control: full rate', (5000000, False), 275000), ('control: joint glide', (3700000, True), 8806)]]
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:
Couples pay the surcharge from half the stipulated joint limit.

solve(income_tax, joint): stipulated surcharge on income tax, in integer cents. The exemption limit is 1813000 (doubled for joint assessment). At or below it the surcharge is 0; above it the surcharge is the lesser of 5.5% of the income tax and 11.9% of the excess over the limit (a gliding zone), rounded down to cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income_tax, joint):
    thr = 1813000 * (2 if joint else 1)
    if income_tax <= thr: return 0
    soli = min(income_tax * Fraction(55, 1000), (income_tax - thr) * Fraction(119, 1000))
    return int(soli + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression round-down-cents 1', (1983210, False), 20254),
  ('regression round-down-cents 2', (3256603, False), 171788), ('partial repair guard 1', (1813009, False), 1),
  ('partial repair guard 2', (3626001, False), 199430), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000),
  ('control: joint glide', (3700000, True), 8806)],
 [('regression round-down-cents 1', (1891730, False), 9368), ('regression round-down-cents 2', (2031073, False), 25950),
  ('partial repair guard 1', (1983210, False), 20254), ('partial repair guard 2', (1813001, False), 0),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953), ('control: at limit', (1813000, False), 0)],
 [('regression round-down-cents 1', (2429991, False), 73421),
  ('regression round-down-cents 2', (2042226, False), 27277), ('partial repair guard 1', (3626001, True), 0),
  ('partial repair guard 2', (4499538, True), 103951), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000),
  ('control: joint glide', (3700000, True), 8806)],
 [('regression round-down-cents 1', (2561678, False), 89092),
  ('regression round-down-cents 2', (4398816, False), 241934), ('partial repair guard 1', (3835420, False), 210948),
  ('partial repair guard 2', (3256603, False), 171788), ('control: joint glide', (3700000, True), 8806),
  ('control: joint below', (3000000, True), 0), ('control: glide edge', (3300000, False), 176953),
  ('control: at limit', (1813000, False), 0)],
 [('regression round-down-cents 1', (3091013, False), 152083),
  ('regression round-down-cents 2', (5134546, True), 179516), ('partial repair guard 1', (3974588, False), 218602),
  ('partial repair guard 2', (2115665, False), 36017), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000),
  ('control: joint glide', (3700000, True), 8806)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income_tax, joint):
    thr = 1813000 * (2 if joint else 1)
    if income_tax <= thr: return 0
    soli = min(income_tax * Fraction(55, 1000), (income_tax - thr) * Fraction(119, 1000))
    return -int(-soli // 1)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression round-down-cents 1', (1983210, False), 20254),
  ('regression round-down-cents 2', (3256603, False), 171788), ('partial repair guard 1', (1813009, False), 1),
  ('partial repair guard 2', (3626001, False), 199430), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000),
  ('control: joint glide', (3700000, True), 8806)],
 [('regression round-down-cents 1', (1891730, False), 9368), ('regression round-down-cents 2', (2031073, False), 25950),
  ('partial repair guard 1', (1983210, False), 20254), ('partial repair guard 2', (1813001, False), 0),
  ('control: joint glide', (3700000, True), 8806), ('control: joint below', (3000000, True), 0),
  ('control: glide edge', (3300000, False), 176953), ('control: at limit', (1813000, False), 0)],
 [('regression round-down-cents 1', (2429991, False), 73421),
  ('regression round-down-cents 2', (2042226, False), 27277), ('partial repair guard 1', (3626001, True), 0),
  ('partial repair guard 2', (4499538, True), 103951), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000),
  ('control: joint glide', (3700000, True), 8806)],
 [('regression round-down-cents 1', (2561678, False), 89092),
  ('regression round-down-cents 2', (4398816, False), 241934), ('partial repair guard 1', (3835420, False), 210948),
  ('partial repair guard 2', (3256603, False), 171788), ('control: joint glide', (3700000, True), 8806),
  ('control: joint below', (3000000, True), 0), ('control: glide edge', (3300000, False), 176953),
  ('control: at limit', (1813000, False), 0)],
 [('regression round-down-cents 1', (3091013, False), 152083),
  ('regression round-down-cents 2', (5134546, True), 179516), ('partial repair guard 1', (3974588, False), 218602),
  ('partial repair guard 2', (2115665, False), 36017), ('control: at limit', (1813000, False), 0),
  ('control: gliding zone', (1900000, False), 10353), ('control: full rate', (5000000, False), 275000),
  ('control: joint glide', (3700000, True), 8806)]]
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:
Some surcharges are one cent higher than stipulated.

solve(income_tax, joint): stipulated surcharge on income tax, in integer cents. The exemption limit is 1813000 (doubled for joint assessment). At or below it the surcharge is 0; above it the surcharge is the lesser of 5.5% of the income tax and 11.9% of the excess over the limit (a gliding zone), rounded down to cents.

split: open-access


prompt:
MAGI 1 dollar over the threshold keeps the full credit.

solve(kids, others, magi, status, tax, earned): stipulated child credit, whole dollars. Credit = 2000 per child + 500 per other dependent, reduced by 50 for each 1000 or fraction thereof of MAGI above the threshold (single 200000, mfj 400000), floored at 0. The credit first offsets tax (used = min(credit, tax)); the refundable portion is min(credit - used, 1700 per child, 15% of earned income above 2500 rounded down, floored at 0). Return [credit, used, refundable].

split: open-access


prompt:
Married couples start losing the credit at 200000.

solve(kids, others, magi, status, tax, earned): stipulated child credit, whole dollars. Credit = 2000 per child + 500 per other dependent, reduced by 50 for each 1000 or fraction thereof of MAGI above the threshold (single 200000, mfj 400000), floored at 0. The credit first offsets tax (used = min(credit, tax)); the refundable portion is min(credit - used, 1700 per child, 15% of earned income above 2500 rounded down, floored at 0). Return [credit, used, refundable].

split: open-access


prompt:
Very high earners with children report a negative credit.

solve(kids, others, magi, status, tax, earned): stipulated child credit, whole dollars. Credit = 2000 per child + 500 per other dependent, reduced by 50 for each 1000 or fraction thereof of MAGI above the threshold (single 200000, mfj 400000), floored at 0. The credit first offsets tax (used = min(credit, tax)); the refundable portion is min(credit - used, 1700 per child, 15% of earned income above 2500 rounded down, floored at 0). Return [credit, used, refundable].

split: open-access


prompt:
A filer receives a refund of credit that already reduced their tax.

solve(kids, others, magi, status, tax, earned): stipulated child credit, whole dollars. Credit = 2000 per child + 500 per other dependent, reduced by 50 for each 1000 or fraction thereof of MAGI above the threshold (single 200000, mfj 400000), floored at 0. The credit first offsets tax (used = min(credit, tax)); the refundable portion is min(credit - used, 1700 per child, 15% of earned income above 2500 rounded down, floored at 0). Return [credit, used, refundable].

split: open-access


prompt:
Families with non-child dependents receive larger refunds than stipulated.

solve(kids, others, magi, status, tax, earned): stipulated child credit, whole dollars. Credit = 2000 per child + 500 per other dependent, reduced by 50 for each 1000 or fraction thereof of MAGI above the threshold (single 200000, mfj 400000), floored at 0. The credit first offsets tax (used = min(credit, tax)); the refundable portion is min(credit - used, 1700 per child, 15% of earned income above 2500 rounded down, floored at 0). Return [credit, used, refundable].

split: open-access