Repository navigation
Test a Form 4952 election with section 911(f) stacking end to end - #9800
Merged
Merged
Conversation
Neither the Form 4952 line 4g election test (#9781) nor the section 911(f) stacking test (#9761) covered households with both. The new Hypothesis tests check, on generated households with an election and an exclusion: - closed forms for net capital gain and the section 911 amounts after the election (min(D, N), min(N, T), min(D, N, T)); - that the Schedule D Tax Worksheet route and the section 1(h) route give the same capital gain excess and reduced amounts, regular tax and AMT; - that a zero election or exclusion matches the situation without that input, bit for bit; - monotonicity in both amounts, with the intended 12%/15% overlap exception in the election bounded from the parameters; - the regular tax and AMT against the transcribed 2025 Schedule D Tax Worksheet, Foreign Earned Income Tax Worksheet and Form 6251. The election and the exclusion can change taxable income through the choice to itemize (an AMT filer may itemize below the standard deduction), so amounts that depend on taxable income are compared only where that choice holds; income_tax, which it minimizes, is compared across it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Gains and worksheet lines 6-10 do not depend on taxable income, so they are checked exactly for every whole-dollar household, itemizers with fractional taxable income included (property 5 as stated). - The AMT capital gain excess has one route; check it once against its closed form instead of against itself. - Correct the wages in the 12%/15% overlap example and an inverted grid comment; say the zero-input test guards against leakage between households. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Hand-off to the US + core hub.
|
Contributor
Author
|
Landed by the US + core hub, after session 0b809666 handed it off, at head Gates:
The two pre-existing bugs these tests surfaced ( |
MaxGhenis
added a commit
that referenced
this pull request
Oct 6, 2026
…worksheets - rate_gain_with_form_4952_election.yaml: the reproducer (no taxable income; taxable income below the gain; half and all of a collectibles gain elected; no election) and an election above the 24% bracket that leaves 28% on line 9 only, with Schedule D Tax Worksheet lines. - test_section_1h_regular_tax.py: for every household and year (2018 to 2030) with elections and both gains, the regular tax is at most line 46 figured from the rate parameters, exactly zero with no taxable income, and not negative; and electing more lowers it by at most the 12/15 rate overlap plus 3% of the smaller of the extra amount elected and the unrecaptured section 1250 gain. Pins the intended exception where an election moves gain from 28 to 25 percent (section 1(h)(1)(E)(ii) measures its excess with net capital gain, which section 1(h)(2) reduces): $68,874 to $67,374 on $50,000 elected. A 2025 differential compares Form 6251 Part III and line 11 after an election with nonzero Schedule D lines 18 and 19. - test_form_6251_part_iii.py: the Schedule D Tax Worksheet transcription takes amounts, Form 4952 lines 4g and 4e, and the Foreign Earned Income Tax Worksheet footnote's four modifications. - test_section_911_tax_stacking.py and test_form_4952_section_911_interaction.py: households with 28-percent rate and unrecaptured section 1250 gain are now compared with the forms (through the Schedule D Tax Worksheet and Form 6251 Part III with the AMT capital gain excess), including rows that reach modification 4, and kept in the monotonicity properties, with the corrected election bound in place of #9800's overlap-only bound. - Harris, Biden 2025 budget and additional tax bracket reforms: a case each where the line 47 limit binds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis
added a commit
that referenced
this pull request
Oct 6, 2026
…worksheets - rate_gain_with_form_4952_election.yaml: the reproducer (no taxable income; taxable income below the gain; half and all of a collectibles gain elected; no election) and an election above the 24% bracket that leaves 28% on line 9 only, with Schedule D Tax Worksheet lines. - test_section_1h_regular_tax.py: for every household and year (2018 to 2030) with elections and both gains, the regular tax is at most line 46 figured from the rate parameters, exactly zero with no taxable income, and not negative; and electing more lowers it by at most the 12/15 rate overlap plus 3% of the smaller of the extra amount elected and the unrecaptured section 1250 gain. Pins the intended exception where an election moves gain from 28 to 25 percent (section 1(h)(1)(E)(ii) measures its excess with net capital gain, which section 1(h)(2) reduces): $68,874 to $67,374 on $50,000 elected. A 2025 differential compares Form 6251 Part III and line 11 after an election with nonzero Schedule D lines 18 and 19. - test_form_6251_part_iii.py: the Schedule D Tax Worksheet transcription takes amounts, Form 4952 lines 4g and 4e, and the Foreign Earned Income Tax Worksheet footnote's four modifications. - test_section_911_tax_stacking.py and test_form_4952_section_911_interaction.py: households with 28-percent rate and unrecaptured section 1250 gain are now compared with the forms (through the Schedule D Tax Worksheet and Form 6251 Part III with the AMT capital gain excess), including rows that reach modification 4, and kept in the monotonicity properties, with the corrected election bound in place of #9800's overlap-only bound. - Harris, Biden 2025 budget and additional tax bracket reforms: a case each where the line 47 limit binds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis
added a commit
that referenced
this pull request
Oct 6, 2026
…worksheets - rate_gain_with_form_4952_election.yaml: the reproducer (no taxable income; taxable income below the gain; half and all of a collectibles gain elected; no election) and an election above the 24% bracket that leaves 28% on line 9 only, with Schedule D Tax Worksheet lines. - test_section_1h_regular_tax.py: for every household and year (2018 to 2030) with elections and both gains, the regular tax is at most line 46 figured from the rate parameters, exactly zero with no taxable income, and not negative; and electing more lowers it by at most the 12/15 rate overlap plus 3% of the smaller of the extra amount elected and the unrecaptured section 1250 gain. Pins the intended exception where an election moves gain from 28 to 25 percent (section 1(h)(1)(E)(ii) measures its excess with net capital gain, which section 1(h)(2) reduces): $68,874 to $67,374 on $50,000 elected. A 2025 differential compares Form 6251 Part III and line 11 after an election with nonzero Schedule D lines 18 and 19. - test_form_6251_part_iii.py: the Schedule D Tax Worksheet transcription takes amounts, Form 4952 lines 4g and 4e, and the Foreign Earned Income Tax Worksheet footnote's four modifications. - test_section_911_tax_stacking.py and test_form_4952_section_911_interaction.py: households with 28-percent rate and unrecaptured section 1250 gain are now compared with the forms (through the Schedule D Tax Worksheet and Form 6251 Part III with the AMT capital gain excess), including rows that reach modification 4, and kept in the monotonicity properties, with the corrected election bound in place of #9800's overlap-only bound. - Harris, Biden 2025 budget and additional tax bracket reforms: a case each where the line 47 limit binds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis
added a commit
that referenced
this pull request
Oct 6, 2026
…worksheets - rate_gain_with_form_4952_election.yaml: the reproducer (no taxable income; taxable income below the gain; half and all of a collectibles gain elected; no election) and an election above the 24% bracket that leaves 28% on line 9 only, with Schedule D Tax Worksheet lines. - test_section_1h_regular_tax.py: for every household and year (2018 to 2030) with elections and both gains, the regular tax is at most line 46 figured from the rate parameters, exactly zero with no taxable income, and not negative; and electing more lowers it by at most the 12/15 rate overlap plus 3% of the smaller of the extra amount elected and the unrecaptured section 1250 gain. Pins the intended exception where an election moves gain from 28 to 25 percent (section 1(h)(1)(E)(ii) measures its excess with net capital gain, which section 1(h)(2) reduces): $68,874 to $67,374 on $50,000 elected. A 2025 differential compares Form 6251 Part III and line 11 after an election with nonzero Schedule D lines 18 and 19. - test_form_6251_part_iii.py: the Schedule D Tax Worksheet transcription takes amounts, Form 4952 lines 4g and 4e, and the Foreign Earned Income Tax Worksheet footnote's four modifications. - test_section_911_tax_stacking.py and test_form_4952_section_911_interaction.py: households with 28-percent rate and unrecaptured section 1250 gain are now compared with the forms (through the Schedule D Tax Worksheet and Form 6251 Part III with the AMT capital gain excess), including rows that reach modification 4, and kept in the monotonicity properties, with the corrected election bound in place of #9800's overlap-only bound. - Harris, Biden 2025 budget and additional tax bracket reforms: a case each where the line 47 limit binds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis
added a commit
that referenced
this pull request
Oct 7, 2026
…worksheets (#9893) * Cap the regular tax at the tax on all taxable income and use it on Form 6251 line 10 26 U.S.C. 1(h)(1) says the tax "shall not exceed" the sum of the subparagraph (A) to (F) amounts, and Schedule D Tax Worksheet line 47 takes the smaller of line 45 and line 46 (the tax on all of line 1). capital_gains_tax now stops at tax_on_taxable_income_at_main_rates (new, line 46) less income_tax_main_rates. The cap binds where gain taxed at 15 percent falls in the 12 percent bracket: up to $3.75 single and $7.50 joint in 2025, and $28.50 and $57 in 2026. The Biden and Harris capital gains reforms apply the same limit, and the additional_tax_bracket reform figures line 46 on its own schedule. regular_tax_before_credits was a second Schedule D Tax Worksheet (2017 numbering) whose result was min(worksheet tax including the gains, income_tax_main_rates excluding them). Form 6251 line 10 then added capital_gains_tax. Whenever the worksheet path fell below the main-rates path, line 10 understated the regular tax: before #9781 that happened for 18 dataset tax units in 2025 ($328M weighted), because dwks10 ignored the Form 4952 line 4g election and because the worksheet took line 28 as min(line 21, line 22) instead of their sum. regular_tax_before_credits is now income_tax_main_rates plus capital_gains_tax, the regular tax income_tax_before_credits charges, and Form 6251 line 10 uses it alone. Tests: real-unit regression cases for tax units 1101624, 1004930, 1156248 and 1032460; line 45/46 boundary cases for 2025 and 2026 (single, joint, head of household, Form 2555); the existing worksheet property tests now compare with line 47 and Foreign Earned Income Tax Worksheet line 25 exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Cite Rev. Proc. 2025-32 section 4 for 2026 amounts Section 3 of Rev. Proc. 2025-32 modifies 2025 items (only .01, the standard deduction, and .02, section 179); the 2026 adjusted items are section 4. The 2026 AMT breakpoints are section 4.10 (PDF page 16) and the 2026 additional standard deduction for the aged or blind is section 4.14(3) (PDF page 18). Also give the dependent standard deduction citation its section number (4.14(2)). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Add property and differential tests for the regular tax and the line 47 limit test_regular_tax_before_credits.py transcribes the 2025 Schedule D Tax Worksheet, lines 1 to 47, with every skip instruction, the Form 4952 election, capital gain distributions, short-term losses and Schedule D lines 18 and 19. The regular rates come from the 2025 Tax Computation Worksheet rows. 2026 runs on Rev. Proc. 2025-32's tables and capital gains amounts. The model matches lines 10, 13, 14, 21, 44, 46 and 47 for a grid, households at the 0 percent amount, and Hypothesis draws. Properties, 2018 to 2035: - 0 <= regular tax <= line 46; - 0 <= capital_gains_tax <= line 46 - income_tax_main_rates; - regular_tax_before_credits = main rates + capital gains tax; - income_tax_before_credits = regular + AMT; - the AMT is line 9 less line 10; - without net capital gain, the regular tax is line 46; - the worksheet lines (dwks10, dwks13, line 18 <= 21 <= 14); - the tax is monotone in wages, gains and dividends; - results are independent of batch order. The limit binds at the top of the 12 percent bracket in every year and filing status, with the published band widths for 2018 to 2026. The monotonicity check sets aside households with capital gain distributions and a Schedule D net loss, a known defect it found. Gross income adds non_sch_d_capital_gains outside the loss limit, while net_capital_gain nets them (a 2018 single filer's tax falls $0.12 with $1 more gain). No dataset tax unit has both. It is left for a follow-up. Also adds 2026 joint, separate and non-binding line 45/46 YAML cases, from the same Rev. Proc. 2025-32 figures as the Axiom companion tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Align the merged tests with main: #9831's reform variables and #9788's netting - test_additional_tax_bracket_unset_bracket.py (#9831) listed regular_tax_before_credits among the variables the reform replaces. On this branch the reform replaces tax_on_taxable_income_at_main_rates instead, and regular_tax_before_credits is income_tax_main_rates plus capital_gains_tax. The default-system leak check now covers the three replaced variables, and the finite and monotone checks cover the reform's three taxes: income_tax_main_rates, tax_on_taxable_income_at_main_rates and regular_tax_before_credits. - test_regular_tax_before_credits.py set aside households with capital gain distributions and a Schedule D net loss in the monotonicity property. #9788 nets the distributions inside the capital loss limit in AGI, so the property now holds for every household. The exclusion is gone, and the minimized counterexample (2018 single, $50,000 of distributions, a $40,273 short-term loss, $1 more long-term gain) is an explicit example; it failed before #9788 (the regular tax fell by $0.12) and passes now. Both files pass after the merge: 9 and 6 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Say in the changelog that regular_tax_before_credits now includes the capital gains tax PolicyEngine/salt-amt-calculator's API reads regular_tax_before_credits as its regular tax, so the meaning change belongs in the release note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Point three Rev. Proc. 2025-32 links at the pages with their 2026 amounts Three links pointed into the wrong section of Rev. Proc. 2025-32: - the capital gains rate thresholds linked page 12, which is section 4.02 (kiddie tax). Section 4.03 and its 2026 amounts (49,450, 98,900, 66,200, 545,500, 613,700, 579,600 and 306,850) are on page 13; - the child tax credit amount ($2,200) and refundable maximum ($1,700) linked page 13, which holds sections 4.03 and 4.04. Section 4.05 and its amounts are on page 14. The other parameter links to the Rev. Proc. land on the page that has the 2026 amounts or on the page where their section starts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Test 28-percent rate gain with a Form 4952 election against the 2025 worksheets - rate_gain_with_form_4952_election.yaml: the reproducer (no taxable income; taxable income below the gain; half and all of a collectibles gain elected; no election) and an election above the 24% bracket that leaves 28% on line 9 only, with Schedule D Tax Worksheet lines. - test_section_1h_regular_tax.py: for every household and year (2018 to 2030) with elections and both gains, the regular tax is at most line 46 figured from the rate parameters, exactly zero with no taxable income, and not negative; and electing more lowers it by at most the 12/15 rate overlap plus 3% of the smaller of the extra amount elected and the unrecaptured section 1250 gain. Pins the intended exception where an election moves gain from 28 to 25 percent (section 1(h)(1)(E)(ii) measures its excess with net capital gain, which section 1(h)(2) reduces): $68,874 to $67,374 on $50,000 elected. A 2025 differential compares Form 6251 Part III and line 11 after an election with nonzero Schedule D lines 18 and 19. - test_form_6251_part_iii.py: the Schedule D Tax Worksheet transcription takes amounts, Form 4952 lines 4g and 4e, and the Foreign Earned Income Tax Worksheet footnote's four modifications. - test_section_911_tax_stacking.py and test_form_4952_section_911_interaction.py: households with 28-percent rate and unrecaptured section 1250 gain are now compared with the forms (through the Schedule D Tax Worksheet and Form 6251 Part III with the AMT capital gain excess), including rows that reach modification 4, and kept in the monotonicity properties, with the corrected election bound in place of #9800's overlap-only bound. - Harris, Biden 2025 budget and additional tax bracket reforms: a case each where the line 47 limit binds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Tighten reach assertions and fix a stale docstring (hard-tier review) - test_section_1h_regular_tax.py: the grid reaches 28% tax after an election only if some elected household has a positive Schedule D Tax Worksheet line 42; a positive capital gains tax could be all at 25%. - test_section_911_tax_stacking.py, test_form_4952_section_911_interaction.py: floor the unrecaptured section 1250 gain after modification 4 at zero, so a household whose line 9 the excess exhausts does not count as reaching it. - test_form_6251_part_iii.py: the transcription, not the model, leaves out the short-term loss netting (#9841 added it to the model). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
policyengine_us/tests/test_form_4952_section_911_interaction.py, an end-to-end property test of a Form 4952 line 4g election (#9781) together with section 911(f) stacking (#9761) on generated households. Until now,test_form_4952_election_worksheet.pytested elections without an exclusion, andtest_section_911_tax_stacking.pytested exclusions without an election. The only combined check was a YAML case with supplied excess values (low finding 2 of the #9781 delta review).Test-only. No formula, parameter or expected output changes.
How it checks the interaction
On a return the two meet in the Schedule D Tax Worksheet. A filer with an amount on Form 4952 line 4g must use it (2025 Instructions for Schedule D, p. 15). The Foreign Earned Income Tax Worksheet measures the capital gain excess from worksheet line 10 and takes it from line 9 before line 6 (2025 Instructions for Form 1040, p. 37). The AMT does the same from Form 6251 line 6 (2025 Instructions for Form 6251, Part III, "Form 2555").
The model reaches these amounts by two routes:
dwks09,dwks10andschedule_d_tax_worksheet_after_capital_gain_excess;net_capital_gainand thesection_911_*variables.The test reuses the existing transcriptions instead of copying them: the Schedule D Tax Worksheet lines 2–10 from the #9781 test, and the Foreign Earned Income Tax Worksheet, Qualified Dividends and Capital Gain Tax Worksheet and Form 6251 from the #9761 test. I read the 2025 Schedule D Tax Worksheet before relying on that. With Schedule D lines 18 and 19 zero, its lines 14–47 match the QDCG worksheet line for line, with worksheet line 6 as line 2 and line 9 as line 3. Form 6251 line 27 (worksheet line 21) then equals line 20 (worksheet line 14).
Invariants
Notation: G is the section 1222(11) gain (capital gain distributions included), D qualified dividends, E the election, X the exclusion, T taxable income, and N = max(0, G − E) + max(0, D − max(0, E − G)).
net_capital_gain=dwks10= N.section_911_net_capital_gainis min(N, T) andsection_911_qualified_dividend_incomeis min(D, N, T).section_911_qualified_dividend_income= min(D,net_capital_gain), bit for bit.section_911_net_capital_gain(§911(f)(2)(A)(i)–(ii) ordering).net_capital_gainanddwks10never rise, and net capital gain falls by at most the extra amount elected.income_tax_before_creditsnever fall as X rises, and stacking never lowers them.income_tax, the amount the itemization choice minimizes, never falls as X rises, even when the choice flips, for households without dependents.dwks10==net_capital_gain, exactly for whole dollars and within single-precision rounding with cents. The model's lines 6, 9 and 10 equal the Apply the Form 4952 election in Schedule D Tax Worksheet lines 3-10 #9781 transcription.Found by the test: the election and the exclusion can change taxable income, through the itemization choice.
tax_unit_itemizespicks whichever choice gives the lowerincome_tax. A filer in the AMT can lower the tax by itemizing deductions smaller than the standard deduction, because they reduce AMTI. Minimized example (2025, single, Texas, $971,091 long-term gain, $1 charitable gift):income_tax_before_creditsstill rises, from $159,912.70 to $159,912.89.This is the model working as designed, but it means a "taxable income never changes" assertion is too strong. #9761's test makes that assertion across exclusion variants, so it may be latently fragile for itemizers near the AMT. Property 4 compares amounts that depend on taxable income only between variants with the same itemization choice. It checks
income_taxacross a flip, for households without dependents. For them no credit applies except the EITC. Neither the EITC (eitc_relevant_investment_income) nor the net investment income tax (net_investment_income,niit_magi) reads the election or the itemization choice, and today neither reads the exclusion. The property still holds if the exclusion later denies the EITC or raises NIIT MAGI. This example and a joint filer with split cents dividends are pinned as@hypothesis.examples.Intended exception, not a bug: the tax is not monotone in the election. From the 0% capital gains threshold to the top of the 12% bracket (2025: $48,350 to $48,475 single), gain is taxed at 15% and ordinary income at 12%. Electing a dollar there lowers the tax by 3 cents, on the return as in the model.
test_election_can_lower_the_tax_where_15_percent_exceeds_12shows $125 more elected lowering both the model's tax and the worksheet's line 47 by exactly $3.75, with and without an exclusion. The property test asserts the bound instead: the tax falls by at most (15% − 12%) × the overlap width, whichrate_overlapcomputes from the parameters ($3.75 single, $7.50 joint, $3.00 head of household in 2025). The same bound replaces #9761's fixed $7.50 allowance for the omitted worksheet line 47 cap.Scope
The tax comparisons (4 and 6) use households without 28-percent rate or unrecaptured §1250 gain, as in #9761's test. The gain-level properties (1–3, 5) include them.
While writing this I confirmed a pre-existing bug, which this PR does not fix.
capital_gains_taxtaxes 28-percent rate gain at 28% in full, even where it exceeds taxable income or the gain an election leaves; Schedule D Tax Worksheet line 12 limits it to line 9. Examples (2025, single):income_taxThe fix is tracked as a separate follow-up.
Tests
derandomize=True, like Apply the Form 4952 election in Schedule D Tax Worksheet lines 3-10 #9781's test): invariants over 2018, 2022, 2025 and 2026; the 2025 forms differential; and the zero-input bitwise check. Strategies target elections at G and G + D, and include cents and itemizers.remainingRest group.axiom: n/a: test-only change; no policy logic modified
🤖 Generated with Claude Code