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

    sched = [[10000, '18'], [20000, '20'], [40000, '22'], [60000, '24'], [80000, '26'], [100000, '28'], [150000, '30'], [250000, '32'], [500000, '34'], [750000, '37'], [1000000, '39'], [None, '40']]
    T = lambda x: prog(x, sched)
    credit = T(13610000)
    tent = T(estate + gifts)
    gift_credit = max(0, T(gifts) - credit)
    return cents(max(0, tent - gift_credit - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression ported-exclusion 1', (20000000, 0, 5000000), 55600000),
  ('regression ported-exclusion 2', (867406, 15000000, 5000000), 0),
  ('partial repair guard 2', (13610000, 5000000, 2000000), 120000000),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000)],
 [('regression ported-exclusion 1', (13610000, 5000000, 2000000), 120000000),
  ('regression ported-exclusion 2', (27783445, 500000, 5000000), 386937800),
  ('partial repair guard 2', (22327855, 5000000, 2000000), 468714200),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression ported-exclusion 1', (22327855, 5000000, 2000000), 468714200),
  ('regression ported-exclusion 2', (13610000, 5000000, 5000000), 0),
  ('partial repair guard 1', (24200909, 15000000, 2000000), 943636360),
  ('partial repair guard 2', (28075997, 5000000, 5000000), 578639880),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)],
 [('regression ported-exclusion 1', (24200909, 15000000, 2000000), 943636360),
  ('regression ported-exclusion 2', (28075997, 5000000, 5000000), 578639880),
  ('partial repair guard 1', (21824496, 5000000, 5000000), 328579840),
  ('partial repair guard 2', (19264731, 0, 2000000), 146189240),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression ported-exclusion 1', (21824496, 5000000, 5000000), 328579840),
  ('regression ported-exclusion 2', (19264731, 0, 2000000), 146189240),
  ('partial repair guard 1', (29904698, 15000000, 2000000), 1171787920),
  ('partial repair guard 2', (9658783, 13906347, 2000000), 318205200),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)]]
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(estate, gifts, dsue):
    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))

    sched = [[10000, '18'], [20000, '20'], [40000, '22'], [60000, '24'], [80000, '26'], [100000, '28'], [150000, '30'], [250000, '32'], [500000, '34'], [750000, '37'], [1000000, '39'], [None, '40']]
    T = lambda x: prog(x, sched)
    credit = T(13610000) + dsue
    tent = T(estate + gifts)
    gift_credit = max(0, T(gifts) - credit)
    return cents(max(0, tent - gift_credit - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression ported-exclusion 1', (20000000, 0, 5000000), 55600000),
  ('regression ported-exclusion 2', (867406, 15000000, 5000000), 0),
  ('partial repair guard 2', (13610000, 5000000, 2000000), 120000000),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000)],
 [('regression ported-exclusion 1', (13610000, 5000000, 2000000), 120000000),
  ('regression ported-exclusion 2', (27783445, 500000, 5000000), 386937800),
  ('partial repair guard 2', (22327855, 5000000, 2000000), 468714200),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression ported-exclusion 1', (22327855, 5000000, 2000000), 468714200),
  ('regression ported-exclusion 2', (13610000, 5000000, 5000000), 0),
  ('partial repair guard 1', (24200909, 15000000, 2000000), 943636360),
  ('partial repair guard 2', (28075997, 5000000, 5000000), 578639880),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)],
 [('regression ported-exclusion 1', (24200909, 15000000, 2000000), 943636360),
  ('regression ported-exclusion 2', (28075997, 5000000, 5000000), 578639880),
  ('partial repair guard 1', (21824496, 5000000, 5000000), 328579840),
  ('partial repair guard 2', (19264731, 0, 2000000), 146189240),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression ported-exclusion 1', (21824496, 5000000, 5000000), 328579840),
  ('regression ported-exclusion 2', (19264731, 0, 2000000), 146189240),
  ('partial repair guard 1', (29904698, 15000000, 2000000), 1171787920),
  ('partial repair guard 2', (9658783, 13906347, 2000000), 318205200),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)]]
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 surviving spouse's estate pays tax as if no exclusion had been ported.

solve(estate, gifts, dsue): stipulated unified transfer tax in whole dollars. T is the progressive schedule 18% to 10000 rising to 40% above 1000000. The exclusion is 13610000 + dsue; the unified credit is T(exclusion). Tentative tax = T(estate + gifts). Gift credit = max(0, T(gifts) - unified credit). Tax = max(0, tentative - gift credit - unified credit), returned in integer cents.

split: open-access


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

    sched = [[10000, '18'], [20000, '20'], [40000, '22'], [60000, '24'], [80000, '26'], [100000, '28'], [150000, '30'], [250000, '32'], [500000, '34'], [750000, '37'], [1000000, '39'], [None, '40']]
    T = lambda x: prog(x, sched)
    credit = T(13610000 + dsue)
    tent = T(estate + gifts)
    gift_credit = T(gifts) - credit
    return cents(max(0, tent - gift_credit - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression gift-credit-floor 1', (10000000, 5000000, 0), 55600000),
  ('regression gift-credit-floor 2', (20000000, 15000000, 5000000), 655600000),
  ('partial repair guard 2', (788866, 18885032, 2000000), 31554640),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000)],
 [('regression gift-credit-floor 1', (20000000, 0, 0), 255600000),
  ('regression gift-credit-floor 2', (10000000, 0, 0), 0),
  ('partial repair guard 1', (24200909, 15000000, 2000000), 943636360),
  ('partial repair guard 2', (29904698, 15000000, 2000000), 1171787920),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000)],
 [('regression gift-credit-floor 1', (20000000, 0, 5000000), 55600000),
  ('regression gift-credit-floor 2', (1500000, 200000, 0), 0),
  ('partial repair guard 1', (9658783, 13906347, 2000000), 318205200),
  ('partial repair guard 2', (4581029, 15000000, 2000000), 158841160),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000)],
 [('regression gift-credit-floor 1', (8632782, 5000000, 0), 911280),
  ('regression gift-credit-floor 2', (867406, 15000000, 5000000), 0),
  ('partial repair guard 1', (9508183, 15052168, 2000000), 358014040),
  ('partial repair guard 2', (13610000, 15000000, 2000000), 520000000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression gift-credit-floor 1', (13610000, 0, 5000000), 0),
  ('regression gift-credit-floor 2', (13610000, 0, 2000000), 0),
  ('partial repair guard 1', (11491956, 15200265, 5000000), 323288840),
  ('partial repair guard 2', (13610000, 16727076, 2000000), 544400000),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)]]
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(estate, gifts, dsue):
    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))

    sched = [[10000, '18'], [20000, '20'], [40000, '22'], [60000, '24'], [80000, '26'], [100000, '28'], [150000, '30'], [250000, '32'], [500000, '34'], [750000, '37'], [1000000, '39'], [None, '40']]
    T = lambda x: prog(x, sched)
    credit = T(13610000 + dsue)
    tent = T(estate + gifts)
    gift_credit = max(0, T(gifts) - T(13610000))
    return cents(max(0, tent - gift_credit - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression gift-credit-floor 1', (10000000, 5000000, 0), 55600000),
  ('regression gift-credit-floor 2', (20000000, 15000000, 5000000), 655600000),
  ('partial repair guard 2', (788866, 18885032, 2000000), 31554640),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000)],
 [('regression gift-credit-floor 1', (20000000, 0, 0), 255600000),
  ('regression gift-credit-floor 2', (10000000, 0, 0), 0),
  ('partial repair guard 1', (24200909, 15000000, 2000000), 943636360),
  ('partial repair guard 2', (29904698, 15000000, 2000000), 1171787920),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000)],
 [('regression gift-credit-floor 1', (20000000, 0, 5000000), 55600000),
  ('regression gift-credit-floor 2', (1500000, 200000, 0), 0),
  ('partial repair guard 1', (9658783, 13906347, 2000000), 318205200),
  ('partial repair guard 2', (4581029, 15000000, 2000000), 158841160),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000)],
 [('regression gift-credit-floor 1', (8632782, 5000000, 0), 911280),
  ('regression gift-credit-floor 2', (867406, 15000000, 5000000), 0),
  ('partial repair guard 1', (9508183, 15052168, 2000000), 358014040),
  ('partial repair guard 2', (13610000, 15000000, 2000000), 520000000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression gift-credit-floor 1', (13610000, 0, 5000000), 0),
  ('regression gift-credit-floor 2', (13610000, 0, 2000000), 0),
  ('partial repair guard 1', (11491956, 15200265, 5000000), 323288840),
  ('partial repair guard 2', (13610000, 16727076, 2000000), 544400000),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)]]
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:
Estates with modest prior gifts are charged extra tax.

solve(estate, gifts, dsue): stipulated unified transfer tax in whole dollars. T is the progressive schedule 18% to 10000 rising to 40% above 1000000. The exclusion is 13610000 + dsue; the unified credit is T(exclusion). Tentative tax = T(estate + gifts). Gift credit = max(0, T(gifts) - unified credit). Tax = max(0, tentative - gift credit - unified credit), returned in integer cents.

split: open-access


prompt:
Filers with large nonrefundable credits pay local surtax on tax they never owed.

solve(state, nonref, ref, pct): amounts in integer cents; pct a decimal percentage string. State tax after nonrefundable credits is max(0, state - nonref). The local surtax is pct% of that amount, rounded half-up to cents. Refundable credits then apply to the combined total in full (a negative total is a refund). Return [local, total].

split: open-access


prompt:
Credits larger than the state tax produce a negative local surtax and an extra refund.

solve(state, nonref, ref, pct): amounts in integer cents; pct a decimal percentage string. State tax after nonrefundable credits is max(0, state - nonref). The local surtax is pct% of that amount, rounded half-up to cents. Refundable credits then apply to the combined total in full (a negative total is a refund). Return [local, total].

split: open-access


prompt:
Half-cent surtax amounts are dropped.

solve(state, nonref, ref, pct): amounts in integer cents; pct a decimal percentage string. State tax after nonrefundable credits is max(0, state - nonref). The local surtax is pct% of that amount, rounded half-up to cents. Refundable credits then apply to the combined total in full (a negative total is a refund). Return [local, total].

split: open-access


prompt:
Filers entitled to a refund receive zero.

solve(state, nonref, ref, pct): amounts in integer cents; pct a decimal percentage string. State tax after nonrefundable credits is max(0, state - nonref). The local surtax is pct% of that amount, rounded half-up to cents. Refundable credits then apply to the combined total in full (a negative total is a refund). Return [local, total].

split: open-access


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

    br = [[55867, '15'], [111733, '20.5'], [173205, '26'], [246752, '29'], [None, '33']]
    g_e = elig * Fraction(138, 100)
    g_n = nonelig * Fraction(115, 100)
    taxable = other + g_e + g_n
    credit = elig * Fraction(150198, 1000000) + nonelig * Fraction(90301, 1000000)
    return cents(max(0, prog(taxable, br) - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression credit-base 1', (40000, 0, 20000), 776539), ('regression credit-base 2', (100000, 10000, 0), 1829727),
  ('partial repair guard 2', (80000, 15000, 15000), 1678221), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: high income', (250000, 50000, 10000), 7337865)],
 [('regression credit-base 1', (0, 10000, 0), 0), ('regression credit-base 2', (80000, 15000, 15000), 1678221),
  ('partial repair guard 1', (250000, 50000, 10000), 7337865), ('partial repair guard 2', (20000, 78584, 5000), 886535),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539), ('control: wages only', (50000, 0, 0), 750000),
  ('control: mixed', (100000, 10000, 0), 1829727)],
 [('regression credit-base 1', (250000, 50000, 10000), 7337865), ('regression credit-base 2', (50000, 3936, 0), 749892),
  ('partial repair guard 1', (0, 0, 16293), 111858), ('partial repair guard 2', (100000, 0, 5000), 1808683),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)],
 [('regression credit-base 1', (0, 50000, 0), 70865), ('regression credit-base 2', (100000, 997, 0), 1750271),
  ('partial repair guard 1', (0, 10000, 5000), 34054), ('partial repair guard 2', (0, 50000, 49145), 794917),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression credit-base 1', (20000, 78584, 5000), 886535), ('regression credit-base 2', (0, 0, 16293), 111858),
  ('partial repair guard 1', (20000, 1000, 5000), 334300), ('partial repair guard 2', (10606, 50000, 20000), 552096),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)]]
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(other, elig, nonelig):
    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))

    br = [[55867, '15'], [111733, '20.5'], [173205, '26'], [246752, '29'], [None, '33']]
    g_e = elig * Fraction(138, 100)
    g_n = nonelig * Fraction(115, 100)
    taxable = other + g_e + g_n
    credit = g_e * Fraction(150198, 1000000) + nonelig * Fraction(90301, 1000000)
    return cents(max(0, prog(taxable, br) - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression credit-base 1', (40000, 0, 20000), 776539), ('regression credit-base 2', (100000, 10000, 0), 1829727),
  ('partial repair guard 2', (80000, 15000, 15000), 1678221), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: high income', (250000, 50000, 10000), 7337865)],
 [('regression credit-base 1', (0, 10000, 0), 0), ('regression credit-base 2', (80000, 15000, 15000), 1678221),
  ('partial repair guard 1', (250000, 50000, 10000), 7337865), ('partial repair guard 2', (20000, 78584, 5000), 886535),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539), ('control: wages only', (50000, 0, 0), 750000),
  ('control: mixed', (100000, 10000, 0), 1829727)],
 [('regression credit-base 1', (250000, 50000, 10000), 7337865), ('regression credit-base 2', (50000, 3936, 0), 749892),
  ('partial repair guard 1', (0, 0, 16293), 111858), ('partial repair guard 2', (100000, 0, 5000), 1808683),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)],
 [('regression credit-base 1', (0, 50000, 0), 70865), ('regression credit-base 2', (100000, 997, 0), 1750271),
  ('partial repair guard 1', (0, 10000, 5000), 34054), ('partial repair guard 2', (0, 50000, 49145), 794917),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression credit-base 1', (20000, 78584, 5000), 886535), ('regression credit-base 2', (0, 0, 16293), 111858),
  ('partial repair guard 1', (20000, 1000, 5000), 334300), ('partial repair guard 2', (10606, 50000, 20000), 552096),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)]]
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:
Dividend recipients receive a smaller credit than the integration rules provide.

solve(other, elig, nonelig): stipulated dividend integration, whole dollars. Eligible dividends are grossed up by 38% and non-eligible by 15%; taxable income is other income plus both grossed-up amounts, taxed with slices 15% to 55867, 20.5% to 111733, 26% to 173205, 29% to 246752, 33% above. The nonrefundable dividend credit is 15.0198% of the grossed-up eligible amount plus 9.0301% of the grossed-up non-eligible amount. Tax = max(0, slice tax - credit), returned 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(other, elig, nonelig):
    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))

    br = [[55867, '15'], [111733, '20.5'], [173205, '26'], [246752, '29'], [None, '33']]
    g_e = elig * Fraction(115, 100)
    g_n = nonelig * Fraction(138, 100)
    taxable = other + g_e + g_n
    credit = g_e * Fraction(150198, 1000000) + g_n * Fraction(90301, 1000000)
    return cents(max(0, prog(taxable, br) - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression grossup-rates 1', (40000, 0, 20000), 776539),
  ('regression grossup-rates 2', (80000, 15000, 15000), 1678221), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: mixed', (100000, 10000, 0), 1829727),
  ('control: high income', (250000, 50000, 10000), 7337865)],
 [('regression grossup-rates 1', (100000, 10000, 0), 1829727),
  ('regression grossup-rates 2', (250000, 50000, 10000), 7337865),
  ('partial repair guard 2', (20000, 78584, 5000), 886535),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0)],
 [('regression grossup-rates 1', (50000, 3936, 0), 749892), ('regression grossup-rates 2', (0, 50000, 0), 70865),
  ('partial repair guard 1', (0, 0, 16293), 111858), ('partial repair guard 2', (100000, 0, 5000), 1808683),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)],
 [('regression grossup-rates 1', (100000, 997, 0), 1750271),
  ('regression grossup-rates 2', (20000, 78584, 5000), 886535), ('partial repair guard 1', (0, 10000, 5000), 34054),
  ('partial repair guard 2', (0, 50000, 49145), 794917), ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression grossup-rates 1', (0, 0, 16293), 111858), ('regression grossup-rates 2', (100000, 0, 5000), 1808683),
  ('partial repair guard 1', (20000, 1000, 5000), 334300), ('partial repair guard 2', (10606, 50000, 20000), 552096),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)]]
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(other, elig, nonelig):
    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))

    br = [[55867, '15'], [111733, '20.5'], [173205, '26'], [246752, '29'], [None, '33']]
    g_e = elig * Fraction(138, 100)
    g_n = nonelig * Fraction(138, 100)
    taxable = other + g_e + g_n
    credit = g_e * Fraction(150198, 1000000) + g_n * Fraction(90301, 1000000)
    return cents(max(0, prog(taxable, br) - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression grossup-rates 1', (40000, 0, 20000), 776539),
  ('regression grossup-rates 2', (80000, 15000, 15000), 1678221), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: mixed', (100000, 10000, 0), 1829727),
  ('control: high income', (250000, 50000, 10000), 7337865)],
 [('regression grossup-rates 1', (100000, 10000, 0), 1829727),
  ('regression grossup-rates 2', (250000, 50000, 10000), 7337865),
  ('partial repair guard 2', (20000, 78584, 5000), 886535),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0)],
 [('regression grossup-rates 1', (50000, 3936, 0), 749892), ('regression grossup-rates 2', (0, 50000, 0), 70865),
  ('partial repair guard 1', (0, 0, 16293), 111858), ('partial repair guard 2', (100000, 0, 5000), 1808683),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)],
 [('regression grossup-rates 1', (100000, 997, 0), 1750271),
  ('regression grossup-rates 2', (20000, 78584, 5000), 886535), ('partial repair guard 1', (0, 10000, 5000), 34054),
  ('partial repair guard 2', (0, 50000, 49145), 794917), ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression grossup-rates 1', (0, 0, 16293), 111858), ('regression grossup-rates 2', (100000, 0, 5000), 1808683),
  ('partial repair guard 1', (20000, 1000, 5000), 334300), ('partial repair guard 2', (10606, 50000, 20000), 552096),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)]]
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:
Eligible dividends are grossed up by 15% and non-eligible by 38%.

solve(other, elig, nonelig): stipulated dividend integration, whole dollars. Eligible dividends are grossed up by 38% and non-eligible by 15%; taxable income is other income plus both grossed-up amounts, taxed with slices 15% to 55867, 20.5% to 111733, 26% to 173205, 29% to 246752, 33% above. The nonrefundable dividend credit is 15.0198% of the grossed-up eligible amount plus 9.0301% of the grossed-up non-eligible amount. Tax = max(0, slice tax - credit), returned 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(other, elig, nonelig):
    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))

    br = [[55867, '15'], [111733, '20.5'], [173205, '26'], [246752, '29'], [None, '33']]
    g_e = elig * Fraction(138, 100)
    g_n = nonelig * Fraction(115, 100)
    taxable = other + g_e + g_n
    credit = g_e * Fraction(150198, 1000000) + g_n * Fraction(90301, 1000000)
    return cents(prog(taxable, br) - credit)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonrefundable-floor 1', (0, 10000, 0), 0), ('regression nonrefundable-floor 2', (0, 1000, 0), 0),
  ('partial repair guard 1', (50000, 3936, 0), 749892), ('partial repair guard 2', (20000, 10000, 0), 299727),
  ('control: wages only', (50000, 0, 0), 750000), ('control: mixed', (100000, 10000, 0), 1829727),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221)],
 [('regression nonrefundable-floor 1', (0, 32901, 0), 0), ('regression nonrefundable-floor 2', (0, 10000, 0), 0),
  ('partial repair guard 1', (50000, 1000, 0), 749973), ('partial repair guard 2', (20000, 20801, 0), 299432),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression nonrefundable-floor 1', (0, 1000, 0), 0), ('regression nonrefundable-floor 2', (0, 32901, 0), 0),
  ('partial repair guard 1', (20000, 1000, 0), 299973), ('partial repair guard 2', (11723, 1000, 0), 175818),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)],
 [('regression nonrefundable-floor 1', (0, 10000, 0), 0), ('regression nonrefundable-floor 2', (0, 1000, 0), 0),
  ('partial repair guard 1', (20000, 1961, 0), 299946), ('partial repair guard 2', (33705, 10000, 0), 505302),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression nonrefundable-floor 1', (0, 32901, 0), 0), ('regression nonrefundable-floor 2', (0, 10000, 0), 0),
  ('partial repair guard 1', (50000, 951, 0), 749974), ('partial repair guard 2', (50000, 3936, 0), 749892),
  ('control: wages only', (50000, 0, 0), 750000), ('control: mixed', (100000, 10000, 0), 1829727),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221)]]
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(other, elig, nonelig):
    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))

    br = [[55867, '15'], [111733, '20.5'], [173205, '26'], [246752, '29'], [None, '33']]
    g_e = elig * Fraction(138, 100)
    g_n = nonelig * Fraction(115, 100)
    taxable = other + g_e + g_n
    credit = g_e * Fraction(150198, 1000000) + g_n * Fraction(90301, 1000000)
    return cents(prog(taxable, br) - min(credit, prog(taxable, br) - prog(other, br)))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonrefundable-floor 1', (0, 10000, 0), 0), ('regression nonrefundable-floor 2', (0, 1000, 0), 0),
  ('partial repair guard 1', (50000, 3936, 0), 749892), ('partial repair guard 2', (20000, 10000, 0), 299727),
  ('control: wages only', (50000, 0, 0), 750000), ('control: mixed', (100000, 10000, 0), 1829727),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221)],
 [('regression nonrefundable-floor 1', (0, 32901, 0), 0), ('regression nonrefundable-floor 2', (0, 10000, 0), 0),
  ('partial repair guard 1', (50000, 1000, 0), 749973), ('partial repair guard 2', (20000, 20801, 0), 299432),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression nonrefundable-floor 1', (0, 1000, 0), 0), ('regression nonrefundable-floor 2', (0, 32901, 0), 0),
  ('partial repair guard 1', (20000, 1000, 0), 299973), ('partial repair guard 2', (11723, 1000, 0), 175818),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)],
 [('regression nonrefundable-floor 1', (0, 10000, 0), 0), ('regression nonrefundable-floor 2', (0, 1000, 0), 0),
  ('partial repair guard 1', (20000, 1961, 0), 299946), ('partial repair guard 2', (33705, 10000, 0), 505302),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression nonrefundable-floor 1', (0, 32901, 0), 0), ('regression nonrefundable-floor 2', (0, 10000, 0), 0),
  ('partial repair guard 1', (50000, 951, 0), 749974), ('partial repair guard 2', (50000, 3936, 0), 749892),
  ('control: wages only', (50000, 0, 0), 750000), ('control: mixed', (100000, 10000, 0), 1829727),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221)]]
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 retiree living on eligible dividends gets a negative tax.

solve(other, elig, nonelig): stipulated dividend integration, whole dollars. Eligible dividends are grossed up by 38% and non-eligible by 15%; taxable income is other income plus both grossed-up amounts, taxed with slices 15% to 55867, 20.5% to 111733, 26% to 173205, 29% to 246752, 33% above. The nonrefundable dividend credit is 15.0198% of the grossed-up eligible amount plus 9.0301% of the grossed-up non-eligible amount. Tax = max(0, slice tax - credit), returned 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(other, elig, nonelig):
    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))

    br = [[55867, '15'], [111733, '20.5'], [173205, '26'], [246752, '29'], [None, '33']]
    g_e = elig * Fraction(138, 100)
    g_n = nonelig * Fraction(115, 100)
    taxable = other + elig + nonelig
    credit = g_e * Fraction(150198, 1000000) + g_n * Fraction(90301, 1000000)
    return cents(max(0, prog(taxable, br) - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression taxable-inclusion 1', (40000, 0, 20000), 776539),
  ('regression taxable-inclusion 2', (100000, 10000, 0), 1829727),
  ('partial repair guard 2', (80000, 15000, 15000), 1678221), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: high income', (250000, 50000, 10000), 7337865)],
 [('regression taxable-inclusion 1', (80000, 15000, 15000), 1678221),
  ('regression taxable-inclusion 2', (250000, 50000, 10000), 7337865),
  ('partial repair guard 2', (20000, 78584, 5000), 886535),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: mixed', (100000, 10000, 0), 1829727)],
 [('regression taxable-inclusion 1', (50000, 3936, 0), 749892),
  ('regression taxable-inclusion 2', (0, 50000, 0), 70865), ('partial repair guard 1', (0, 0, 16293), 111858),
  ('partial repair guard 2', (100000, 0, 5000), 1808683), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: mixed', (100000, 10000, 0), 1829727),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539)],
 [('regression taxable-inclusion 1', (100000, 997, 0), 1750271),
  ('regression taxable-inclusion 2', (20000, 78584, 5000), 886535), ('partial repair guard 1', (0, 10000, 5000), 34054),
  ('partial repair guard 2', (0, 50000, 49145), 794917), ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression taxable-inclusion 1', (0, 0, 16293), 111858),
  ('regression taxable-inclusion 2', (100000, 0, 5000), 1808683),
  ('partial repair guard 1', (20000, 1000, 5000), 334300), ('partial repair guard 2', (10606, 50000, 20000), 552096),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)]]
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(other, elig, nonelig):
    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))

    br = [[55867, '15'], [111733, '20.5'], [173205, '26'], [246752, '29'], [None, '33']]
    g_e = elig * Fraction(138, 100)
    g_n = nonelig * Fraction(115, 100)
    taxable = other + g_e + nonelig
    credit = g_e * Fraction(150198, 1000000) + g_n * Fraction(90301, 1000000)
    return cents(max(0, prog(taxable, br) - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression taxable-inclusion 1', (40000, 0, 20000), 776539),
  ('regression taxable-inclusion 2', (100000, 10000, 0), 1829727),
  ('partial repair guard 2', (80000, 15000, 15000), 1678221), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: high income', (250000, 50000, 10000), 7337865)],
 [('regression taxable-inclusion 1', (80000, 15000, 15000), 1678221),
  ('regression taxable-inclusion 2', (250000, 50000, 10000), 7337865),
  ('partial repair guard 2', (20000, 78584, 5000), 886535),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: mixed', (100000, 10000, 0), 1829727)],
 [('regression taxable-inclusion 1', (50000, 3936, 0), 749892),
  ('regression taxable-inclusion 2', (0, 50000, 0), 70865), ('partial repair guard 1', (0, 0, 16293), 111858),
  ('partial repair guard 2', (100000, 0, 5000), 1808683), ('control: wages only', (50000, 0, 0), 750000),
  ('control: eligible dividends only', (0, 10000, 0), 0), ('control: mixed', (100000, 10000, 0), 1829727),
  ('control: non-eligible dividends', (40000, 0, 20000), 776539)],
 [('regression taxable-inclusion 1', (100000, 997, 0), 1750271),
  ('regression taxable-inclusion 2', (20000, 78584, 5000), 886535), ('partial repair guard 1', (0, 10000, 5000), 34054),
  ('partial repair guard 2', (0, 50000, 49145), 794917), ('control: non-eligible dividends', (40000, 0, 20000), 776539),
  ('control: both kinds', (80000, 15000, 15000), 1678221), ('control: high income', (250000, 50000, 10000), 7337865),
  ('control: wages only', (50000, 0, 0), 750000)],
 [('regression taxable-inclusion 1', (0, 0, 16293), 111858),
  ('regression taxable-inclusion 2', (100000, 0, 5000), 1808683),
  ('partial repair guard 1', (20000, 1000, 5000), 334300), ('partial repair guard 2', (10606, 50000, 20000), 552096),
  ('control: wages only', (50000, 0, 0), 750000), ('control: eligible dividends only', (0, 10000, 0), 0),
  ('control: mixed', (100000, 10000, 0), 1829727), ('control: non-eligible dividends', (40000, 0, 20000), 776539)]]
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:
Taxable income is understated while the credit is still based on the gross-up.

solve(other, elig, nonelig): stipulated dividend integration, whole dollars. Eligible dividends are grossed up by 38% and non-eligible by 15%; taxable income is other income plus both grossed-up amounts, taxed with slices 15% to 55867, 20.5% to 111733, 26% to 173205, 29% to 246752, 33% above. The nonrefundable dividend credit is 15.0198% of the grossed-up eligible amount plus 9.0301% of the grossed-up non-eligible amount. Tax = max(0, slice tax - credit), returned 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(earned, unearned, parent_rate):
    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))

    std = min(14600, max(1300, earned + 450))
    taxable = max(0, earned + unearned - std)
    net_unearned = max(0, unearned - 1300)
    at_parent = min(net_unearned, taxable)
    tax = at_parent * Fraction(parent_rate) / 100 + (taxable - at_parent) * Fraction(10, 100)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression parent-rate-threshold 1', (0, 5000, '32'), 89800),
  ('regression parent-rate-threshold 2', (20000, 5000, '24'), 137600),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0)],
 [('regression parent-rate-threshold 1', (0, 2000, '32'), 7000),
  ('regression parent-rate-threshold 2', (3000, 3000, '35'), 35500),
  ('partial repair guard 2', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: working teen', (20000, 5000, '24'), 137600)],
 [('regression parent-rate-threshold 1', (0, 60000, '37'), 2136800),
  ('regression parent-rate-threshold 2', (0, 2600, '22'), 13000), ('partial repair guard 2', (8000, 5662, '22'), 88864),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: below threshold', (0, 2000, '32'), 7000),
  ('control: working teen', (20000, 5000, '24'), 137600), ('control: mixed small', (3000, 3000, '35'), 35500)],
 [('regression parent-rate-threshold 1', (8000, 5662, '22'), 88864),
  ('regression parent-rate-threshold 2', (1000, 60000, '22'), 1284300),
  ('partial repair guard 2', (3000, 5000, '32'), 98300), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: unearned only', (0, 5000, '32'), 89800)],
 [('regression parent-rate-threshold 1', (3000, 5000, '32'), 98300),
  ('regression parent-rate-threshold 2', (8000, 5000, '24'), 79100),
  ('partial repair guard 2', (20000, 5000, '35'), 164000), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600),
  ('control: mixed small', (3000, 3000, '35'), 35500)]]
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, unearned, parent_rate):
    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))

    std = min(14600, max(1300, earned + 450))
    taxable = max(0, earned + unearned - std)
    net_unearned = max(0, unearned - 2500)
    at_parent = min(net_unearned, taxable)
    tax = at_parent * Fraction(parent_rate) / 100 + (taxable - at_parent) * Fraction(10, 100)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression parent-rate-threshold 1', (0, 5000, '32'), 89800),
  ('regression parent-rate-threshold 2', (20000, 5000, '24'), 137600),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0)],
 [('regression parent-rate-threshold 1', (0, 2000, '32'), 7000),
  ('regression parent-rate-threshold 2', (3000, 3000, '35'), 35500),
  ('partial repair guard 2', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: working teen', (20000, 5000, '24'), 137600)],
 [('regression parent-rate-threshold 1', (0, 60000, '37'), 2136800),
  ('regression parent-rate-threshold 2', (0, 2600, '22'), 13000), ('partial repair guard 2', (8000, 5662, '22'), 88864),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: below threshold', (0, 2000, '32'), 7000),
  ('control: working teen', (20000, 5000, '24'), 137600), ('control: mixed small', (3000, 3000, '35'), 35500)],
 [('regression parent-rate-threshold 1', (8000, 5662, '22'), 88864),
  ('regression parent-rate-threshold 2', (1000, 60000, '22'), 1284300),
  ('partial repair guard 2', (3000, 5000, '32'), 98300), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: unearned only', (0, 5000, '32'), 89800)],
 [('regression parent-rate-threshold 1', (3000, 5000, '32'), 98300),
  ('regression parent-rate-threshold 2', (8000, 5000, '24'), 79100),
  ('partial repair guard 2', (20000, 5000, '35'), 164000), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600),
  ('control: mixed small', (3000, 3000, '35'), 35500)]]
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:
Unearned income between 1300 and 2600 is taxed at the parent's rate instead of the child's.

solve(earned, unearned, parent_rate): stipulated child unearned-income rule, whole dollars. Standard deduction = min(14600, max(1300, earned + 450)); taxable = max(0, earned + unearned - std). Net unearned income = max(0, unearned - 2600); the part of taxable income taxed at the parent's rate (percent string) is min(net unearned, taxable); the rest is taxed at 10%. 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, unearned, parent_rate):
    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))

    std = min(14600, max(1300, earned + 450))
    taxable = max(0, earned + unearned - std)
    net_unearned = max(0, earned + unearned - 2600)
    at_parent = min(net_unearned, taxable)
    tax = at_parent * Fraction(parent_rate) / 100 + (taxable - at_parent) * Fraction(10, 100)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression earned-excluded 1', (20000, 5000, '24'), 137600),
  ('regression earned-excluded 2', (3000, 3000, '35'), 35500), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: large trust income', (0, 60000, '37'), 2136800),
  ('control: earned only', (8000, 0, '22'), 0)],
 [('regression earned-excluded 1', (16766, 0, '32'), 21660),
  ('regression earned-excluded 2', (8000, 5662, '22'), 88864), ('partial repair guard 1', (0, 5000, '32'), 89800),
  ('partial repair guard 2', (0, 2000, '32'), 7000), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: working teen', (20000, 5000, '24'), 137600)],
 [('regression earned-excluded 1', (1000, 60000, '22'), 1284300),
  ('regression earned-excluded 2', (3000, 5000, '32'), 98300), ('partial repair guard 1', (0, 60000, '37'), 2136800),
  ('partial repair guard 2', (0, 2600, '22'), 13000), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600),
  ('control: mixed small', (3000, 3000, '35'), 35500)],
 [('regression earned-excluded 1', (3000, 1300, '24'), 8500),
  ('regression earned-excluded 2', (8000, 5000, '24'), 79100), ('partial repair guard 1', (8000, 5662, '22'), 88864),
  ('partial repair guard 2', (1000, 60000, '22'), 1284300), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: unearned only', (0, 5000, '32'), 89800)],
 [('regression earned-excluded 1', (20000, 5000, '35'), 164000),
  ('regression earned-excluded 2', (3000, 2601, '22'), 21522), ('partial repair guard 1', (3000, 5000, '32'), 98300),
  ('partial repair guard 2', (8000, 5000, '24'), 79100), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600),
  ('control: mixed small', (3000, 3000, '35'), 35500)]]
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, unearned, parent_rate):
    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))

    std = min(14600, max(1300, earned + 450))
    taxable = max(0, earned + unearned - std)
    net_unearned = max(0, unearned - std)
    at_parent = min(net_unearned, taxable)
    tax = at_parent * Fraction(parent_rate) / 100 + (taxable - at_parent) * Fraction(10, 100)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression earned-excluded 1', (20000, 5000, '24'), 137600),
  ('regression earned-excluded 2', (3000, 3000, '35'), 35500), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: large trust income', (0, 60000, '37'), 2136800),
  ('control: earned only', (8000, 0, '22'), 0)],
 [('regression earned-excluded 1', (16766, 0, '32'), 21660),
  ('regression earned-excluded 2', (8000, 5662, '22'), 88864), ('partial repair guard 1', (0, 5000, '32'), 89800),
  ('partial repair guard 2', (0, 2000, '32'), 7000), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: working teen', (20000, 5000, '24'), 137600)],
 [('regression earned-excluded 1', (1000, 60000, '22'), 1284300),
  ('regression earned-excluded 2', (3000, 5000, '32'), 98300), ('partial repair guard 1', (0, 60000, '37'), 2136800),
  ('partial repair guard 2', (0, 2600, '22'), 13000), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600),
  ('control: mixed small', (3000, 3000, '35'), 35500)],
 [('regression earned-excluded 1', (3000, 1300, '24'), 8500),
  ('regression earned-excluded 2', (8000, 5000, '24'), 79100), ('partial repair guard 1', (8000, 5662, '22'), 88864),
  ('partial repair guard 2', (1000, 60000, '22'), 1284300), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: unearned only', (0, 5000, '32'), 89800)],
 [('regression earned-excluded 1', (20000, 5000, '35'), 164000),
  ('regression earned-excluded 2', (3000, 2601, '22'), 21522), ('partial repair guard 1', (3000, 5000, '32'), 98300),
  ('partial repair guard 2', (8000, 5000, '24'), 79100), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600),
  ('control: mixed small', (3000, 3000, '35'), 35500)]]
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 working teenager's wages are taxed at the parent's rate.

solve(earned, unearned, parent_rate): stipulated child unearned-income rule, whole dollars. Standard deduction = min(14600, max(1300, earned + 450)); taxable = max(0, earned + unearned - std). Net unearned income = max(0, unearned - 2600); the part of taxable income taxed at the parent's rate (percent string) is min(net unearned, taxable); the rest is taxed at 10%. 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, unearned, parent_rate):
    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))

    std = 14600
    taxable = max(0, earned + unearned - std)
    net_unearned = max(0, unearned - 2600)
    at_parent = min(net_unearned, taxable)
    tax = at_parent * Fraction(parent_rate) / 100 + (taxable - at_parent) * Fraction(10, 100)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression dependent-deduction 1', (0, 5000, '32'), 89800),
  ('regression dependent-deduction 2', (0, 2000, '32'), 7000), ('partial repair guard 1', (20000, 5000, '24'), 137600),
  ('partial repair guard 2', (16766, 0, '32'), 21660), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0)],
 [('regression dependent-deduction 1', (3000, 3000, '35'), 35500),
  ('regression dependent-deduction 2', (0, 60000, '37'), 2136800),
  ('partial repair guard 1', (20000, 5000, '35'), 164000), ('partial repair guard 2', (20000, 2601, '35'), 80035),
  ('control: earned only', (8000, 0, '22'), 0), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600)],
 [('regression dependent-deduction 1', (0, 2600, '22'), 13000),
  ('regression dependent-deduction 2', (8000, 5662, '22'), 88864),
  ('partial repair guard 1', (20000, 5000, '37'), 168800), ('partial repair guard 2', (15034, 2600, '24'), 30340),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: below threshold', (0, 2000, '32'), 7000),
  ('control: working teen', (20000, 5000, '24'), 137600), ('control: mixed small', (3000, 3000, '35'), 35500)],
 [('regression dependent-deduction 1', (1000, 60000, '22'), 1284300),
  ('regression dependent-deduction 2', (3000, 5000, '32'), 98300),
  ('partial repair guard 1', (23068, 60000, '37'), 2234480), ('partial repair guard 2', (20000, 60000, '32'), 1916800),
  ('control: mixed small', (3000, 3000, '35'), 35500), ('control: large trust income', (0, 60000, '37'), 2136800),
  ('control: earned only', (8000, 0, '22'), 0), ('control: unearned only', (0, 5000, '32'), 89800)],
 [('regression dependent-deduction 1', (3000, 1300, '24'), 8500),
  ('regression dependent-deduction 2', (8000, 5000, '24'), 79100),
  ('partial repair guard 1', (21025, 60000, '24'), 1467850), ('partial repair guard 2', (22321, 0, '22'), 77210),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: below threshold', (0, 2000, '32'), 7000),
  ('control: working teen', (20000, 5000, '24'), 137600), ('control: mixed small', (3000, 3000, '35'), 35500)]]
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, unearned, parent_rate):
    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))

    std = max(1300, earned + 450)
    taxable = max(0, earned + unearned - std)
    net_unearned = max(0, unearned - 2600)
    at_parent = min(net_unearned, taxable)
    tax = at_parent * Fraction(parent_rate) / 100 + (taxable - at_parent) * Fraction(10, 100)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression dependent-deduction 1', (0, 5000, '32'), 89800),
  ('regression dependent-deduction 2', (0, 2000, '32'), 7000), ('partial repair guard 1', (20000, 5000, '24'), 137600),
  ('partial repair guard 2', (16766, 0, '32'), 21660), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0)],
 [('regression dependent-deduction 1', (3000, 3000, '35'), 35500),
  ('regression dependent-deduction 2', (0, 60000, '37'), 2136800),
  ('partial repair guard 1', (20000, 5000, '35'), 164000), ('partial repair guard 2', (20000, 2601, '35'), 80035),
  ('control: earned only', (8000, 0, '22'), 0), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600)],
 [('regression dependent-deduction 1', (0, 2600, '22'), 13000),
  ('regression dependent-deduction 2', (8000, 5662, '22'), 88864),
  ('partial repair guard 1', (20000, 5000, '37'), 168800), ('partial repair guard 2', (15034, 2600, '24'), 30340),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: below threshold', (0, 2000, '32'), 7000),
  ('control: working teen', (20000, 5000, '24'), 137600), ('control: mixed small', (3000, 3000, '35'), 35500)],
 [('regression dependent-deduction 1', (1000, 60000, '22'), 1284300),
  ('regression dependent-deduction 2', (3000, 5000, '32'), 98300),
  ('partial repair guard 1', (23068, 60000, '37'), 2234480), ('partial repair guard 2', (20000, 60000, '32'), 1916800),
  ('control: mixed small', (3000, 3000, '35'), 35500), ('control: large trust income', (0, 60000, '37'), 2136800),
  ('control: earned only', (8000, 0, '22'), 0), ('control: unearned only', (0, 5000, '32'), 89800)],
 [('regression dependent-deduction 1', (3000, 1300, '24'), 8500),
  ('regression dependent-deduction 2', (8000, 5000, '24'), 79100),
  ('partial repair guard 1', (21025, 60000, '24'), 1467850), ('partial repair guard 2', (22321, 0, '22'), 77210),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: below threshold', (0, 2000, '32'), 7000),
  ('control: working teen', (20000, 5000, '24'), 137600), ('control: mixed small', (3000, 3000, '35'), 35500)]]
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:
Unearned income of a child is sheltered by the full 14600 deduction.

solve(earned, unearned, parent_rate): stipulated child unearned-income rule, whole dollars. Standard deduction = min(14600, max(1300, earned + 450)); taxable = max(0, earned + unearned - std). Net unearned income = max(0, unearned - 2600); the part of taxable income taxed at the parent's rate (percent string) is min(net unearned, taxable); the rest is taxed at 10%. 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, unearned, parent_rate):
    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))

    std = min(14600, max(1300, earned + 450))
    taxable = max(0, earned + unearned - std)
    net_unearned = max(0, unearned - 2600)
    at_parent = taxable if net_unearned > 0 else 0
    tax = at_parent * Fraction(parent_rate) / 100 + (taxable - at_parent) * Fraction(10, 100)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression parent-portion 1', (20000, 5000, '24'), 137600), ('regression parent-portion 2', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0)],
 [('regression parent-portion 1', (3000, 3000, '35'), 35500),
  ('regression parent-portion 2', (0, 60000, '37'), 2136800), ('partial repair guard 1', (0, 2000, '32'), 7000),
  ('control: earned only', (8000, 0, '22'), 0), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: working teen', (20000, 5000, '24'), 137600)],
 [('regression parent-portion 1', (8000, 5662, '22'), 88864),
  ('regression parent-portion 2', (1000, 60000, '22'), 1284300), ('partial repair guard 1', (0, 60000, '37'), 2136800),
  ('partial repair guard 2', (0, 2600, '22'), 13000), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600),
  ('control: mixed small', (3000, 3000, '35'), 35500)],
 [('regression parent-portion 1', (3000, 5000, '32'), 98300),
  ('regression parent-portion 2', (8000, 5000, '24'), 79100), ('partial repair guard 1', (8000, 5662, '22'), 88864),
  ('partial repair guard 2', (1000, 60000, '22'), 1284300), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: unearned only', (0, 5000, '32'), 89800)],
 [('regression parent-portion 1', (20000, 5000, '35'), 164000), ('regression parent-portion 2', (0, 5000, '22'), 65800),
  ('partial repair guard 1', (3000, 5000, '32'), 98300), ('partial repair guard 2', (3000, 1300, '24'), 8500),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: below threshold', (0, 2000, '32'), 7000),
  ('control: working teen', (20000, 5000, '24'), 137600), ('control: mixed small', (3000, 3000, '35'), 35500)]]
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, unearned, parent_rate):
    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))

    std = min(14600, max(1300, earned + 450))
    taxable = max(0, earned + unearned - std)
    net_unearned = max(0, unearned - 2600)
    at_parent = min(unearned, taxable)
    tax = at_parent * Fraction(parent_rate) / 100 + (taxable - at_parent) * Fraction(10, 100)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression parent-portion 1', (20000, 5000, '24'), 137600), ('regression parent-portion 2', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0)],
 [('regression parent-portion 1', (3000, 3000, '35'), 35500),
  ('regression parent-portion 2', (0, 60000, '37'), 2136800), ('partial repair guard 1', (0, 2000, '32'), 7000),
  ('control: earned only', (8000, 0, '22'), 0), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: working teen', (20000, 5000, '24'), 137600)],
 [('regression parent-portion 1', (8000, 5662, '22'), 88864),
  ('regression parent-portion 2', (1000, 60000, '22'), 1284300), ('partial repair guard 1', (0, 60000, '37'), 2136800),
  ('partial repair guard 2', (0, 2600, '22'), 13000), ('control: unearned only', (0, 5000, '32'), 89800),
  ('control: below threshold', (0, 2000, '32'), 7000), ('control: working teen', (20000, 5000, '24'), 137600),
  ('control: mixed small', (3000, 3000, '35'), 35500)],
 [('regression parent-portion 1', (3000, 5000, '32'), 98300),
  ('regression parent-portion 2', (8000, 5000, '24'), 79100), ('partial repair guard 1', (8000, 5662, '22'), 88864),
  ('partial repair guard 2', (1000, 60000, '22'), 1284300), ('control: mixed small', (3000, 3000, '35'), 35500),
  ('control: large trust income', (0, 60000, '37'), 2136800), ('control: earned only', (8000, 0, '22'), 0),
  ('control: unearned only', (0, 5000, '32'), 89800)],
 [('regression parent-portion 1', (20000, 5000, '35'), 164000), ('regression parent-portion 2', (0, 5000, '22'), 65800),
  ('partial repair guard 1', (3000, 5000, '32'), 98300), ('partial repair guard 2', (3000, 1300, '24'), 8500),
  ('control: unearned only', (0, 5000, '32'), 89800), ('control: below threshold', (0, 2000, '32'), 7000),
  ('control: working teen', (20000, 5000, '24'), 137600), ('control: mixed small', (3000, 3000, '35'), 35500)]]
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 child with 2601 of unearned income and wages pays the parent's rate on everything.

solve(earned, unearned, parent_rate): stipulated child unearned-income rule, whole dollars. Standard deduction = min(14600, max(1300, earned + 450)); taxable = max(0, earned + unearned - std). Net unearned income = max(0, unearned - 2600); the part of taxable income taxed at the parent's rate (percent string) is min(net unearned, taxable); the rest is taxed at 10%. 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(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
    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 provisional-income 1', (20000, 0, 12000, 'single'), 500),
  ('regression provisional-income 2', (30000, 1000, 20000, 'mfj'), 4500),
  ('partial repair guard 2', (10000, 1000, 40000, 'single'), 3000),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000)],
 [('regression provisional-income 1', (10000, 1000, 40000, 'single'), 3000),
  ('regression provisional-income 2', (20000, 0, 20000, 'mfj'), 0),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (20000, 1000, 45562, 'single'), 12813),
  ('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 provisional-income 1', (0, 5000, 40000, 'mfj'), 0),
  ('regression provisional-income 2', (45000, 0, 30934, 'mfj'), 19996),
  ('partial repair guard 1', (30000, 1000, 42192, 'mfj'), 12881),
  ('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 provisional-income 1', (30000, 1000, 8000, 'single'), 4850),
  ('regression provisional-income 2', (20000, 1000, 45562, 'single'), 12813),
  ('partial repair guard 1', (45000, 1000, 40000, 'single'), 31700),
  ('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 provisional-income 1', (30000, 1000, 42192, 'mfj'), 12881),
  ('regression provisional-income 2', (20000, 0, 40000, 'mfj'), 4000),
  ('partial repair guard 1', (20000, 5000, 20000, 'mfj'), 1500),
  ('partial repair guard 2', (30000, 1000, 25710, 'single'), 12876),
  ('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 + 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 provisional-income 1', (20000, 0, 12000, 'single'), 500),
  ('regression provisional-income 2', (30000, 1000, 20000, 'mfj'), 4500),
  ('partial repair guard 2', (10000, 1000, 40000, 'single'), 3000),
  ('control: second tier', (40000, 0, 20000, 'single'), 17000), ('control: below base', (10000, 0, 10000, 'single'), 0),
  ('control: separate filer', (5000, 0, 8000, 'mfs'), 6800),
  ('control: small benefit first tier', (28000, 0, 2000, 'single'), 1000)],
 [('regression provisional-income 1', (10000, 1000, 40000, 'single'), 3000),
  ('regression provisional-income 2', (20000, 0, 20000, 'mfj'), 0),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (20000, 1000, 45562, 'single'), 12813),
  ('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 provisional-income 1', (0, 5000, 40000, 'mfj'), 0),
  ('regression provisional-income 2', (45000, 0, 30934, 'mfj'), 19996),
  ('partial repair guard 1', (30000, 1000, 42192, 'mfj'), 12881),
  ('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 provisional-income 1', (30000, 1000, 8000, 'single'), 4850),
  ('regression provisional-income 2', (20000, 1000, 45562, 'single'), 12813),
  ('partial repair guard 1', (45000, 1000, 40000, 'single'), 31700),
  ('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 provisional-income 1', (30000, 1000, 42192, 'mfj'), 12881),
  ('regression provisional-income 2', (20000, 0, 40000, 'mfj'), 4000),
  ('partial repair guard 1', (20000, 5000, 20000, 'mfj'), 1500),
  ('partial repair guard 2', (30000, 1000, 25710, 'single'), 12876),
  ('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:
Retirees cross the inclusion thresholds with far less other 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(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 * 85 / 100, (pi - b2) * 85 / 100)
    return int(t)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression second-tier-carry 1', (40000, 0, 20000, 'single'), 17000),
  ('regression second-tier-carry 2', (35000, 0, 4000, 'single'), 3400),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('control: first tier', (20000, 0, 12000, '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)],
 [('regression second-tier-carry 1', (45000, 0, 30934, 'mfj'), 19996),
  ('regression second-tier-carry 2', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('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 second-tier-carry 1', (20000, 1000, 45562, 'single'), 12813),
  ('regression second-tier-carry 2', (30000, 1000, 42192, 'mfj'), 12881),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('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 second-tier-carry 1', (30000, 0, 20000, 'single'), 9600),
  ('regression second-tier-carry 2', (45000, 1000, 40000, 'single'), 31700),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('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 second-tier-carry 1', (45000, 0, 41916, 'single'), 31664),
  ('regression second-tier-carry 2', (30000, 0, 40000, 'mfj'), 11100),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('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 * 85 / 100, (pi - b2) * 85 / 100 + 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 second-tier-carry 1', (40000, 0, 20000, 'single'), 17000),
  ('regression second-tier-carry 2', (35000, 0, 4000, 'single'), 3400),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('control: first tier', (20000, 0, 12000, '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)],
 [('regression second-tier-carry 1', (45000, 0, 30934, 'mfj'), 19996),
  ('regression second-tier-carry 2', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('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 second-tier-carry 1', (20000, 1000, 45562, 'single'), 12813),
  ('regression second-tier-carry 2', (30000, 1000, 42192, 'mfj'), 12881),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('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 second-tier-carry 1', (30000, 0, 20000, 'single'), 9600),
  ('regression second-tier-carry 2', (45000, 1000, 40000, 'single'), 31700),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('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 second-tier-carry 1', (45000, 0, 41916, 'single'), 31664),
  ('regression second-tier-carry 2', (30000, 0, 40000, 'mfj'), 11100),
  ('partial repair guard 1', (30000, 1000, 8000, 'single'), 4850),
  ('partial repair guard 2', (30775, 1000, 8000, 'single'), 5508),
  ('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:
Income above the second base amount includes less benefit than stipulated.

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