Tax-Calculator PR #3102 added the unit test mentioned below.
Here is Claude Code's analysis of SchXYZ function logic:
❯ Add a test_SchXYZ unit test at the end of the test_calcfunctions.py
module, where a tax unit has 2026 taxable income of $100 million and a
2026 policy reform sets II_brk to $20 million for all filers and sets
II_rt8 to 0.44, leaving other policy parameters at their current-law
policy values for 2026. Calculate the expected income tax liability
for the individual before writing the test. Beware of the possibility
of a bug in the SchXYZ() function in the calcfunctions.py module.
⏺ I'll start by examining the SchXYZ function and the existing test file.
⏺ Let me analyze the SchXYZ function for bugs and check the policy parameter
defaults.
⏺ I found a real bug. The function's output (35,392,979.25) differs from the
correct hand-calculated value (42,555,957.25) by exactly 0.37 * (20e6 -
640600) = 7,162,978 — the II_rt7 bracket contribution is being skipped when
income exceeds II_brk7.
⏺ Confirmed the bug: at line 2057-2060, when taxable_income > brk7, the code
adds II_rt8 * (taxable_income - brk7) but never accumulates the II_rt7 bracket
amount II_rt7 * (brk7 - brk6). The parallel simplification at the top of the
function (tax = II_rt1 * brk1) worked because brk0 = 0, but the bottom of the
schedule lost its tax = tax + II_rt7 * (brk7 - brk6) step.
⏺ Here is how to fix the bug in SchXYZ:
⏺ Update(taxcalc/calcfunctions.py)
⎿ Add 1 line
2057 brk7 = II_brk7[MARS - 1]
2058 if taxable_income <= brk7:
2059 return tax + II_rt7 * (taxable_income - brk6)
2060 + tax = tax + II_rt7 * (brk7 - brk6)
2061 return tax + II_rt8 * (taxable_income - brk7)
2062
2063
Tax-Calculator PR #3102 added the unit test mentioned below.
Here is Claude Code's analysis of
SchXYZfunction logic:❯ Add a test_SchXYZ unit test at the end of the test_calcfunctions.py
module, where a tax unit has 2026 taxable income of $100 million and a
2026 policy reform sets II_brk to $20 million for all filers and sets
II_rt8 to 0.44, leaving other policy parameters at their current-law
policy values for 2026. Calculate the expected income tax liability
for the individual before writing the test. Beware of the possibility
of a bug in the SchXYZ() function in the calcfunctions.py module.
⏺ I'll start by examining the SchXYZ function and the existing test file.
⏺ Let me analyze the SchXYZ function for bugs and check the policy parameter
defaults.
⏺ I found a real bug. The function's output (35,392,979.25) differs from the
correct hand-calculated value (42,555,957.25) by exactly 0.37 * (20e6 -
640600) = 7,162,978 — the II_rt7 bracket contribution is being skipped when
income exceeds II_brk7.
⏺ Confirmed the bug: at line 2057-2060, when taxable_income > brk7, the code
adds II_rt8 * (taxable_income - brk7) but never accumulates the II_rt7 bracket
amount II_rt7 * (brk7 - brk6). The parallel simplification at the top of the
function (tax = II_rt1 * brk1) worked because brk0 = 0, but the bottom of the
schedule lost its tax = tax + II_rt7 * (brk7 - brk6) step.
⏺ Here is how to fix the bug in SchXYZ:
⏺ Update(taxcalc/calcfunctions.py)
⎿ Add 1 line
2057 brk7 = II_brk7[MARS - 1]
2058 if taxable_income <= brk7:
2059 return tax + II_rt7 * (taxable_income - brk6)
2060 + tax = tax + II_rt7 * (brk7 - brk6)
2061 return tax + II_rt8 * (taxable_income - brk7)
2062
2063