Formalizing the US Tax Code with Lean: Findings, Bugs, and New Loopholes
Quick Takeaways
- Formalizing Title 26 of the US Code in Lean revealed 138 genuine drafting mistakes and enabled a full verification of the 2025 individual income tax against IRS tables and three open‑source calculators.
- The Lean model reproduced all known loopholes and identified three novel tax benefits that are not documented in practitioner literature, IRS guidance, or tax‑software forums.
- The approach shows that a proof‑checked, version‑controlled tax code can automatically flag new drafting errors and serve as a reliable oracle for systematic loophole searches.
1. Lean Detects 138 Real Drafting Mistakes in Title 26
Conclusion: A Lean‑based test suite automatically identified 138 genuine cross‑reference errors in the official XML of the US Code, each provable in under three minutes.
- The source data are the Office of the Law Revision Counsel’s XML release (as of 3 Nov 2026), parsed to resolve every textual cross‑reference (e.g., “paragraph (2) of subsection (b)”).
- Lean checks each reference for existence, current force, and correct numbering. Failures generate a Lean certificate that links the fault to the exact XML fragment and the public law that introduced it.
- Out of 257 findings, 98 are intentional (e.g., retroactive rules), 21 are false positives from editor hyperlinks, and 138 are real faults:
Fault type Count Example Reference to repealed or moved provision 67 §1(f)(7)(A) cites a provision rewritten in the 2025 Act without updating the reference Typo or wrong subdivision 24 §1400Z‑2(f)(1) cites subsection (c)(1) instead of (d)(1) Wrong level word (paragraph vs. subsection) 8 §9818(a)(1)(A) calls a subsection a paragraph Duplicate numbering 9 §1202(b)(4) appears twice Unclosed parentheses (some footnoted, some not) 30 §165(h)(1) leaves an opening parenthesis never closed - The entire fault suite runs in ≈2.5 minutes and can be re‑executed on every new Code release, with
git blamepinpointing the responsible Act.
2. Formalizing the 2025 Federal Income Tax in Lean
Conclusion: The Lean model reproduces the 2025 Form 1040 calculations, validates against IRS tables and three independent calculators, and proves several statutory properties that hold for all incomes and filing statuses.
Construction
- Income & AGI – definitions for wages, interest, IRA contributions, etc.
- Deductions – standard vs. itemized, plus new tips, overtime, car‑loan, and senior deductions.
- Tax Computation – regular tax, Alternative Minimum Tax (AMT), and phase‑outs.
- Credits – child tax credit, Earned Income Tax Credit (EITC), saver’s credit, etc.
- AI generated the Lean translation; a second AI agent performed an adversarial review to catch “cheating” (code that passes tests without matching the statute).
- Every component is proved against the IRS‑published tables (Tax Table, EITC table, worksheets) and against three open‑source tax engines on 5,000 synthetic households.
Proven Statutory Properties
- SALT cap never increases with income for any filing status.
- Overtime and car‑loan deductions shrink monotonically as income rises, despite opposite rounding directions.
- Tax Table vs. statutory formula: Lean proves the table deviates by ‑$5 to +$6 for every taxable income under $100 k, for all filing statuses.
Surprising Code Issues Discovered
- Mixed 2025/2026 language: Six sections already embed 2025 amendments that are not effective until 2026, causing incorrect tax calculations if read verbatim.
- Rounding asymmetry: Tips/overtime deductions drop $100 per $1,000 of excess income, while the car‑loan deduction drops $200 per $1,000 “or portion thereof”, causing a $999 earlier phase‑out.
- SALT deduction advantage for separate filing: Joint returns shrink the SALT cap by 30 cents per dollar over $500 k, whereas separate returns halve the cap after shrinking, effectively 15 cents per dollar. Two spouses earning $300 k each can deduct $25 k separately vs. $10 k jointly.
- One‑dollar cliff effects: A family with three children loses the entire EITC (up to $8,046) when investment income exceeds $11,950 by just $1. The saver’s credit shows a similar $1,200 drop at a $1 increase in income.
3. Cross‑Checking Against Existing Tax Software
Conclusion: The Lean model matches three established calculators on 99.86 % of 5,000 test cases and uncovers bugs in both the external tools and its own implementation.
| Tool | Agreement with Lean | Notable Discrepancies |
|---|---|---|
| PolicyEngine‑US | 4,993/5,000 exact matches; 7 cases differ by ≤$11 (EITC rounding) | |
| Tax‑Calculator | Incorrect EITC and child‑care credits for married filing separately; missed AMT for a high‑earning separate filer | |
| UsTaxes | 14 confirmed bugs (e.g., omitted Schedule C, wrong child‑care credit, always‑pass EITC age test, spouse wages counted against Social Security cap) |
The comparison also revealed two errors in the Lean model:
- Omitted self‑employment profit from the 20 % small‑business deduction.
- Always selected the larger of standard vs. itemized deductions, whereas the law permits choosing a smaller itemized amount to reduce AMT. Both were fixed, reducing a household’s tax by $2,070.
4. Automated Search Re‑discovers Known Loopholes
Conclusion: An exhaustive search over 195,787 return permutations for 5,000 households reproduces every major tax‑planning strategy documented in the literature.
- Search space: Vary filing status, investment allocation, IRA contributions, income adjustments, and gain realization.
- Results: All high‑value strategies (e.g., filing separately to stay under §199A QBI threshold, allocating children to the lower‑earning spouse, timing gains to stay under EITC limits) matched practitioner guides from Kitces, IRS Publication 596, and Form 1040 instructions.
- Economic impact: The best discovered strategies saved $6,317 / yr (business owner filing separately) to $0.84 M over a lifetime (Roth conversions before Social Security).
5. Three Previously Undocumented Loopholes
Conclusion: The Lean search uncovered three tax benefits that are not described in any public practitioner source, IRS guidance, or tax‑software issue tracker.
- Separate filing can reduce Social Security tax for cohabiting couples – When the retiree’s benefits are $48 k and the spouse earns $60 k, joint filing yields $7,050 tax, while separate filing yields $5,568, a $1,482 saving. The effect reverses above $100 k joint wages.
- Splitting wages and investment income across separate returns lowers Net Investment Income Tax – Because the $250 k (joint) / $125 k (separate) threshold is applied per return, two spouses each earning $200 k can save $1,621 in the 3.8 % NIIT.
- Schedule 8812 over‑pays refundable child credit – The statute caps the refundable portion per qualifying child, but the form caps the combined credit, causing a refund of up to $500 per additional dependent when the taxpayer is in the phase‑out range with no tax liability. Lean proves the form’s result is never below the statutory limit and exceeds it when other dependents are present.
6. Why a Single‑Year Tax Code Yields Only Modest Gains
Conclusion: Unlike the back‑door Roth, which creates a multi‑decade, compounding advantage, the 2025 individual income tax contains only bounded cliffs; the largest swing found is a few thousand dollars per year.
- Most loopholes are single‑return thresholds (e.g., SALT cap, EITC phase‑out) that produce limited dollar savings.
- Over decades, the cumulative benefit comes from known strategies already published; the only novel combination is paying children while performing Roth conversions, adding ≈0.5 % to lifetime after‑tax wealth.
- The authors hypothesize that any substantial, unpublished loophole would involve entity‑level taxation (partnerships, S‑corps, C‑corps) rather than the individual code.
7. Toward Routine, Automated Bug‑Hunting in Tax Law
Conclusion: Once the Lean model and drafting checks are in place, most verification steps become a single command, leaving only human judgment for interpreting whether a finding is a bug or an intentional policy choice.
- Drafting checks:
lean checkagainst the latest XML; any new fault fails the test suite andgit blamereveals the responsible Act. - Model maintenance: Adding or updating a provision is a one‑off effort; the build fails automatically if any proved property is violated.
- Comparison pipeline: Mapping inputs to external calculators is the hardest part, but once established, discrepancies are flagged automatically.
8. Limitations and Open Questions
- Coverage: The model handles the 2025 individual income tax for a household but omits the kiddie tax, 28 % capital gains, §1250 gain, foreign income, passive activity rules, and many AMT preferences.
- Human review: Drafting‑fault certificates and model proofs were generated by AI agents and have not been audited by lawyers or CPAs.
- Agreement ≠ correctness: All four calculators could share a systematic misinterpretation; the Lean theorems and IRS‑example tests are the ultimate arbiter.
9. Community Reactions (Selected HN Comments)
"If the tax law is inconsistent, does that mean we don't have to pay any tax? Lean supports the principle of explosion." – coctuh
"The loopholes are often intentional; judges interpret the spirit, not the letter, of the law." – jedberg
"The mixed 2025/2026 language creates a huge SALT deduction disparity for married couples filing jointly." – rancar2
"Formalizing law is attractive but will hit a wall with common‑law jurisdictions where precedent is fluid." – nixonaddiction
"This is wonderful; the magnitude of work was previously impossible." – carterschonwald
10. Where to Find the Code and Data
All Lean definitions, proofs, certificates, and search scripts are in the lean-proofs directory of the global‑law repository:
https://github.com/lexifina/global-law/tree/main/lean-proofs
The repository includes the version‑controlled US Code XML, the test suite for drafting faults, and the full 2025 tax model.