Complete formalization of the US Internal Revenue Code (Title 26) using Lean 4 and Harmonic Aristotle
Create a complete, machine-verified formalization of US tax law enabling:
- Automated tax calculation verification
- Detection of legal inconsistencies and ambiguities
- Formal proofs of tax law properties
- Educational resource for understanding tax law
765 IRC sections formalized — Strong coverage of income and estate taxes.
| Subtitle | Sections | Coverage | Notes |
|---|---|---|---|
| A: Income Taxes | 653 | ~93% | Core individual & business rules |
| B: Estate & Gift | 98 | ~89% | Complete except GST rules |
| C: Employment | 14 | ~7% | FUTA partial, FICA missing |
| D-K: Other | 0 | 0% | Excise, procedure, specialized |
For typical taxpayers: ~90% of commonly-encountered tax rules are formalized.
See COVERAGE.md for detailed breakdown.
| Metric | Value |
|---|---|
| Main Section Files | 752 |
| Aristotle Output Files | 703 |
| Total Lean Files | 1,455 |
| Lines of Lean Code | 537,400 |
| Theorems & Lemmas | 607 |
Remaining sorry |
17 |
- Broad IRC Coverage: 765 sections of Title 26 formalized
- Income Tax Complete: 93% coverage of Subtitle A (core tax rules)
- Formal Proofs: 607 theorems and lemmas proven
- Automated Pipeline: Processed via Aristotle API with batch automation
- Quality Tooling: Loophole detection and contradiction analysis tools
| Area | Sections | Impact |
|---|---|---|
| Partnerships | §701-777 | LLCs, investment funds |
| Trusts & Estates | §641-692 | Trust taxation, inheritance |
| Natural Resources | §611-638 | Oil/gas depletion |
| FICA | §3101-3128 | Payroll taxes |
src/
TaxCode/ # 752 formalized IRC sections
Section1.lean # Tax rates
Section1_aristotle_output.lean
Section61.lean # Gross income
Section61_aristotle_output.lean
...
Common/
Basic.lean # Core type definitions
Currency.lean # Currency handling
Utils/ # Helper functions
tools/ # 20 analysis tools
safe_loophole_finder.py # Single-threaded contradiction detector
loophole_classifier.py # Pattern classification
grok_loophole_investigator.py
contradiction_detector.py
dependency_analyzer.py
scripts/ # 22 automation scripts
process_remaining_stubs.py
process_oversized_stubs.py
process_final_19.py
monitor_queue.py
tests/ # 5 test files
docs/ # Documentation
data/ # Scraped IRC data, queue state
-- Currency amounts (IRC calculations)
def Currency := Int
-- Tax years (modern income tax era)
structure TaxYear where
year : Nat
h_valid : year >= 1913
deriving DecidableEq
-- Filing status (IRC Section 1)
inductive FilingStatus
| Single
| MarriedFilingJointly
| MarriedFilingSeparately
| HeadOfHousehold
| QualifyingWidower
| Estate
| Trust
deriving Repr, DecidableEq, InhabitedSingle-threaded contradiction detector that analyzes all sections:
# Run full analysis (safe, single-threaded)
python3 tools/safe_loophole_finder.py
# With progress resumption
python3 tools/safe_loophole_finder.py --resume
# Skip pairwise checks (faster)
python3 tools/safe_loophole_finder.py --skip-contradictionsDetection Patterns:
- Type definition inconsistencies (Currency, FilingStatus, TaxYear)
- Numeric threshold conflicts
- Deprecated function references
- Incomplete implementations (sorry, TODO, admit)
- Overlapping boolean conditions
- isTaxExempt vs isTaxable conflicts
python3 tools/dependency_analyzer.py# Install Lean 4
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh
# Install Python dependencies
pip3 install aristotlelib psutil
# Set Aristotle API key (for new formalizations)
export ARISTOTLE_API_KEY=your_key_here# Build entire project
lake build
# Check specific section
lake build TaxCode.Section61# Run loophole analysis
python3 tools/safe_loophole_finder.py --skip-contradictions
# Check for incomplete proofs
grep -r "sorry" src/TaxCode/*.lean| Category | Count |
|---|---|
| IRC Sections Formalized | 752 |
| Lines of Lean Code | 537,400 |
| Proven Theorems/Lemmas | 607 |
| Test Files | 5 |
| Processing Scripts | 22 |
| Analysis Tools | 20 |
Each IRC section was processed through:
- Scraping: Cornell Law IRC text extracted
- Stub Generation: Lean skeleton with type signatures
- Aristotle Submission: INFORMAL mode proof search
- Integration: Output files merged into project
- Build Verification:
lake buildvalidation - Quality Analysis: Loophole finder checks
Large files were handled with truncation strategies:
- Editorial Notes removed (non-legal content)
- Amendments sections truncated
- 600-line limit for very large sections
- Retry logic for API failures
| Section | Description | Status |
|---|---|---|
| 1 | Tax Rates & Brackets | Complete |
| 61 | Gross Income Defined | Complete |
| 62 | Adjusted Gross Income | Complete |
| 63 | Taxable Income | Complete |
| 151 | Personal Exemptions | Complete |
| 152 | Dependent Defined | Complete |
| Section | Description | Status |
|---|---|---|
| 162 | Business Expenses | Complete |
| 163 | Interest Deductions | Complete |
| 164 | Taxes | Complete |
| 165 | Losses | Complete |
| 167 | Depreciation | Complete |
| 170 | Charitable Contributions | Complete |
| Section | Description | Status |
|---|---|---|
| 1001 | Gain/Loss Calculation | Complete |
| 1012 | Cost Basis | Complete |
| 1221 | Capital Asset Defined | Complete |
| 1231 | Business Property | Complete |
| Section | Description | Status |
|---|---|---|
| 11 | Corporate Tax Rate | Complete |
| 301 | Corporate Distributions | Complete |
| 401 | Qualified Plans | Complete |
| 482 | Transfer Pricing | Complete |
| Section | Issue |
|---|---|
| 103 | Complex municipal bond rules |
| 168 | Accelerated depreciation |
| 453 | Installment sales |
| 704 | Partnership allocations |
| 831 | Insurance company rules |
| 951-956 | Controlled foreign corps |
| 1297 | PFIC definitions |
- Legal Text: Cornell Law - 26 USC
- Tax Brackets: IRS Tax Tables
- Formalization Tool: Harmonic Aristotle
- Check open issues for enhancement opportunities
- Run
lake buildto verify changes compile - Run
safe_loophole_finder.pyto check for new issues - Include test cases with
#evalexamples - Cite IRC section sources in comments
- Built with Lean 4
- Powered by Harmonic Aristotle
- Tax data from IRS
- Legal text from Cornell Law School LII
Status: 93% Income Tax Coverage | 17 sorry remaining
Last Updated: 2025-12-18
Sections Formalized: 765 (Subtitle A: 653, B: 98, C: 14)