Manuscript Offprint
arXiv:2610.02792Law And Order: Tax Law Autoformalization
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
ABSTRACT
Legal systems are increasingly implemented through software, yet scalable methods for translating legal texts into accurate symbolic representations remain underdeveloped. We study this problem through tax law, where forms and filing instructions define large computational structures involving arithmetic, branching, recursion, and tabular reasoning. We propose LAW&ORDER, a neuro-symbolic framework for automatically formalizing tax forms and instructions into executable symbolic programs. Our approach establishes two forms of correspondence between law and logic: structural correspondence, which aligns legal and symbolic components such as cells and schedules, and denotational correspondence, which requires symbolic components to implement the computations specified by their legal counterparts. We combine large language model synthesis with cell-level verification and iterative localized error repair using human-written OpenTaxSolver tax returns. We then evaluate the resulting formalizations on independently authored, held-out TaxCalcBench returns, that are never exposed during generation or repair. Although the most advanced LLM achieves only 66% accuracy, LAW&ORDER achieves 100% cell-level and form-level accuracy on 51 held-out returns, demonstrating the effectiveness of combining LLM-based synthesis with symbolic verification for scalable and verifiable large-scale legal autoformalization compared with using an LLM alone.
1 INTRODUCTION
Modern societies increasingly rely on software to operationalize law (de la Garza, 2020; Lessig, 2009). Tax systems, regulatory frameworks, and other rule-based systems translate legal requirements written in natural language into executable procedures. Yet automating this translation remains an open problem. Existing auto-formalization methods are concentrated primarily in mathematics (Jiang et al., 2022; Zhou et al., 2024; Yang et al., 2026), while formalization in expert legal domains remains largely manual, expensive, and difficult to scale (Lawsky, 2026b; Holzenberger et al., 2020). For example, the IRS Direct File system required $16 million and more than two years to build (Treasury Inspector General for Tax Administration, 2026). Beyond applications to relatively small legal fragments (Judson et al., 2024; Lawsky, 2022), scalable automated legal formalization has yet to be realized.
Tax law provides a challenging setting for studying this problem. Existing implementations illustrate its scale: OpenTaxSolver (Roberts, 2026) contains more than 16,000 lines of C code, while implementations of individual forms such as Form 1040 can exceed 1,000 lines. Moreover, legal rules exist at different levels of abstraction. Statutes and other high-level legal sources are progressively refined through regulations, guidance, forms, and instructions before ultimately being implemented in software. We focus on IRS tax forms and their accompanying instructions. These documents occupy a useful intermediate position between legal text and software. Unlike statutes and regulations, they are written for ordinary taxpayers and express many legal requirements in comparatively concrete and operational terms.
Tax forms also provide a natural structure for formalization and verification. A form consists of cells containing numeric, Boolean, or finite-sort values. Some cells are taxpayer inputs, while others are computed from preceding cells according to natural-language instructions. Formalization therefore
Please direct correspondence to sophiahsm6@gmail.com.
Part of this project was done when Yoshiki Takashima was a Postdoctoral Scholar at Yale Law School.

Final F is evaluated once on a separate test set for the reported accuracy.
Figure 1: The LAW&ORDER generation–verification–repair loop. Starting from an initial set of cell functions F and a repair-set of test cases T, the system repeatedly executes F on T and compares each cell's model output o against its gold annotation G. Any cell function f whose output disagrees with G is regenerated by an LLM using that cell's natural-language instruction, and the cycle repeats until every cell matches across all repair-set test cases. The resulting corrected F is then evaluated once on a held-out test set — never seen during synthesis or repair — to produce the final reported accuracy.
requires translating these instructions into executable arithmetic, branching, tabular operations, and dependencies among cells. Although individual computations are often simple, errors can propagate through the dependency structure of a large form, making final-output verification insufficient for identifying where a formalization diverges from the intended rules.
They are relatively self-contained: annual revisions are consolidated within form and instruction documents rather than dispersed across amendments and cross-references. Although forms and instructions carry less legal authority than statutes or regulations, they serve as the primary interface through which taxpayers operationalize tax law and determine their tax obligations.
Our central approach is to preserve this structure in the symbolic representation. We represent computed cells as individual symbolic functions and organize them according to the sections and schedules of the source form. This correspondence allows natural-language instructions, symbolic functions, and execution outputs to be compared at the same granularity. When an output disagrees with an expected return, the system can localize the discrepancy to individual cells and revise the corresponding functions. Building on this structure, we present a neuro-symbolic system for tax-law auto-formalization. The system combines (1) a synthesis module that translates tax forms and instructions into executable symbolic representations, (2) a verification module that compares generated programs against expected cell-level outputs, and (3) an iterative repair procedure that localizes discrepancies and revises the corresponding symbolic functions. The system therefore performs test-driven legal formalization, repeatedly generating, executing, verifying, and repairing the formalization. Figure 1 illustrates this process.
Crucially, we use different test cases for development and final evaluation. During synthesis and repair, the system receives human-written test returns from OpenTaxSolver (Roberts, 2026). These returns provide execution feedback and are explicitly available for correcting the generated formalization. Once this process is complete, the formalization is frozen and evaluated on a separate set of independently authored returns from TaxCalcBench (Bock et al., 2025). These evaluation returns were written by Certified Public Accountants (CPAs) and are never exposed during generation or correction. The final evaluation therefore measures whether formalizations developed using one set of human-written cases generalize to independently written, previously unseen returns.
Our contributions are threefold. First, we formulate large-scale legal formalization around structurally corresponding representations that align natural-language rules with executable units. Second, we introduce a neuro-symbolic synthesis, verification, and repair framework that exploits this structure for fine-grained error localization. Third, we demonstrate that resulting formalizations generalize from human-written development cases to independently authored, CPA-written held-out returns across 26 tax forms. Although the most advanced LLM can only achieve 66% accuracy, LAW&ORDER achieves 100%, showing the effectiveness of our neuro-symbolic system.
Lean program: > 10,000 lines
/-- 2025 SALT cap (post-OBBBA): base cap 20,000 MFS), reduced by 30% of MAGI (^AGI) over 250,000 MFS), but not below the 5,000 MFS) floor. -/
def cell_072_a5e_limited_state_local_taxes (i : Inputs) : Float := let baseCap := if i.isMarriedSeparate then 20000.0 else 40000.0 let threshold := if i.isMarriedSeparate then 250000.0 else 500000.0 let floorCap := if i.isMarriedSeparate then 5000.0 else 10000.0 let reduced := baseCap - 0.30 * notLessThanZero (i.agi - threshold) let cap := if reduced < floorCap then floorCap else reduced smallerOf (cell_071_a5d_state_local_taxes i) cap
def cell_075_a10_total_interest (i : Inputs) : Float := cell_074_a8e_home_mortgage_interest i + inputNum "A9" i
def cell_076_a14_total_gifts_to_charity (i : Inputs) : Float := inputNum "A11" i + inputNum "A12" i + inputNum "A13" i
def cell_077_a17_total_itemized_deductions (i : Inputs) : Float := cell_070_a4_medical_deduction i + cell_073_a7_total_taxes i + cell_075_a10_total_interest i + cell_076_a14_total_gifts_to_charity i + inputNum "A15" i + inputNum "A16" i
end F1040sa
More than 10,000 lines of reusable executable formalization
Figure 2: Excerpt from an automatically generated tax program. Shown is a small contiguous excerpt of the executable symbolic program generated from tax forms and filing instructions. The complete formalization comprises more than 10,000 lines of Lean code, with dependencies spanning individual cells, worksheets, schedules, and forms. The output of legal auto-formalization is therefore not merely an isolated formula or short program, but a large, interconnected executable artifact. This scale illustrates a central challenge of legal auto-formalization: correctness must be maintained not only for individual rules, but across the computational structure as a whole. It also motivates our focus on compositional synthesis and verification: even when individual rules are relatively compact, their composition produces a program whose correctness cannot be reliably established through generation alone.
2.1 AUTOFORMALIZATION METHODS AND VERIFICATION
Autoformalization has been studied primarily in mathematics, with benchmarks spanning Olympiad problems, undergraduate theorems, Euclidean geometry, and large-scale Lean 4 corpora (Azerbaiyev et al., 2023; Murphy et al., 2024; Gao et al., 2025; Li et al., 2024; Weng et al., 2025). Large language models have shown substantial capability in translating natural-language mathematics into formal specifications (Wu et al., 2022; Zheng et al., 2022; Azerbaijan et al., 2023; Murphy et al., 2024), while subsequent work has improved performance on larger formalization tasks through decomposition, dependency information, and iterative correction (Liu et al., 2025; Wang et al., 2025; Min et al., 2026). Evaluation, however, remains challenging: syntactic validity and successful compilation do not guarantee that a generated formalization preserves the meaning of its source. Prior work therefore supplements compilation with semantic evaluation or formal equivalence checks (Murphy et al., 2024; Liu et al., 2025). This distinction is important for legal formalization, where a well-formed executable program may encode a different rule from the underlying legal text.
2.2 COMPUTATIONAL LAW AND TAX-LAW FORMALIZATION
Computational-law research has long developed executable representations of legal rules. Catala supports the systematic translation of statutory law into executable programs while preserving default-and-exception structure (Merigoux et al., 2021), and related work frames tax-software construction as legal formalization (Lawsky, 2022; 2026a); these approaches, however, largely rely on human-authored formalizations. Legal benchmarks such as SARA and DeonticBench evaluate statutory reasoning and executable Prolog generation (Holzenberger et al., 2020; Dou et al., 2026). Formal methods have also been used for validation: CUTECat generates tests through concolic
Algorithm 1: Generation, Verification and Correction of Tax-Form Symbolic Logic
Input: Test cases with cell-by-cell output ; cell functions ; instructions ; dependency structure over
Output: Corrected cell functions
repeat
// Execute computation graph on all test cases for do for to do inputs required by ; ; // Repair functions that disagree with NL reasoning for to do for to do if then ; end end end end
until ; return
execution (Goutagny et al., 2025), while Gogani Khiabani et al. (2026) use LLM agents and metamorphic testing to synthesize and test tax-preparation software. Our approach instead automatically synthesizes formalizations and compares their executions against expected intermediate cell values, providing localized feedback for repairing discrepancies while preserving correct computation.
3 METHOD
Our approach transforms tax forms and their accompanying instructions into an executable symbolic representation assisted tax return examples. The pipeline consists of three stages: (1) form structure extraction, (2) function signature generation, (3) instruction-grounded program synthesis and 4) repair set-assisted program verification and correction.
The objective of our system is to synthesize a symbolic program that exactly reproduces the computations specified by a tax form and its accompanying instructions.
3.1 FORM STRUCTURE EXTRACTION
Given a tax form, we first use a regex-based algorithm for extracting all computationally relevant cells and their associated definitions from the PDF file. Each cell and its definition corresponds to a function in the resulting symbolic representation.
To evaluate the reliability of this stage, we manually audited the extracted representations across a diverse collection of federal and state tax forms, including U.S. Form 1040 and its schedules, as well as tax forms from Arizona, California, Massachusetts, Michigan, New Jersey, New York, North Carolina, Ohio, Oregon, Pennsylvania, and Virginia. Across all audited forms, the extracted cell structures matched the source documents without observed errors.
3.2 FUNCTION SIGNATURE GENERATION
For each extracted cell, we generate an empty function specification that represents the computation required to determine the value of that cell. At this stage, only the function interface is generated; the implementation logic is intentionally omitted. Let (P) denote the synthesized program and let denote a collection of benchmark tax returns from our repair set. Each repair set example contains a complete set of input values and expected outputs. We evaluate the synthesized functions by executing (F) on the repair set example inputs and comparing the resulting cell values against the repair set example outputs . We then employ an iterative synthesis–verification loop for symbolic logic generation.
Formally, each cell is associated with a function where denotes the set of input variables referenced by the tax form. The resulting collection of function signatures defines the computational skeleton of the tax form while remaining agnostic to the underlying implementation language. The representation can be instantiated in any formal language capable of expressing executable symbolic logic, including Epilogue, C++, Lean, Python, or domain-specific languages.
As with the extraction stage, we manually verified the correctness of generated function signatures across all audited tax forms and observed no errors.
3.3 INSTRUCTION-GROUNDED PROGRAM SYNTHESIS
Tax forms are accompanied by official instructions that specify how each cell should be computed . We leverage these instructions as the authoritative semantic source for program generation as they are specifically drafted for ordinary tax-payers, logically well-structured, and require substantially less legal interpretation than statues and Code of Federal Regulations.
During this step, an LLM receives (1) the tax form, (2) the corresponding instruction text, and (3) the function signatures. The model synthesizes executable symbolic logic for each function signature that implements the computation described in the instructions. Conceptually, this stage performs a translation from natural-language legal rules into formal executable specifications. The synthesized logic may use any formal language that preserves the tax instructions' semantics and supports deterministic execution.
3.4 REPAIR SET-ASSISTED VERIFICATION AND CORRECTION
Recent work has increasingly emphasized that syntactic validity alone is insufficient for evaluating autoformalization. Liu et al. (2025) introduce an equivalence-based metric for measuring faithful formalization. We introduce two complementary forms of correspondence for law and software. Structural correspondence asks whether components of the legal artifact—such as cells, schedules, and dependencies—have corresponding components in the symbolic representation. Denotational correspondence asks whether those components produce the prescribed behavior. Tax forms provide an unusually useful setting for the latter because benchmark returns expose intermediate cell values. Discrepancies can therefore be localized to individual symbolic functions and used to drive targeted repair. Agreement on a finite benchmark establishes cell-level behavioral agreement on the repair set examples rather than universal semantic equivalence over all possible taxpayer inputs.
To validate the synthesized program, we compare its outputs—specifically, the cell values computed by each generated function—against an independently generated repair set of tax returns. Each example in the repair set consists of a set of input variables together with the expected values for all cells in the form. Validation proceeds sequentially, comparing cell values step by step. When a discrepancy is identified, the function corresponding to the affected cell is regenerated by prompting the LLM with the relevant tax form and instruction context to correct the implementation. The validation process is then repeated. This iterative refinement cycle continues until the outputs produced through symbolic execution match the repair set examples for every cell in the form.
Because tax forms define a deterministic computation graph, agreement at every intermediate cell implies agreement for the repair-set examples on the final tax outputs. Consequently, the final synthesized program is accepted only when it reproduces the complete computation trace without any inconsistencies.
4 EXPERIMENTS
4.1 EXPERIMENTAL SETUP
Models. For symbolic logic translation and correction, we evaluate seven language models spanning a range of capabilities and scales: proprietary frontier models GPT-6 (OpenAI, 2026), Claude Opus 5.5 (Anthropic, 2026b), Claude Fable 5.1 (Anthropic, 2026a), Gemini Flash 3.8 (Google DeepMind, 2026), and Gemini 3.1 Pro Preview (Google, 2026) and open-weight models Kimi K3 (Moonshot AI, 2026) and Qwen 3.6 8B (Qwen Team, 2026).
Repair set. We use test cases generated from OpenTaxSolver as the repair set during the program-repair stage, where failing test cases are used to diagnose and modify the program. OpenTaxSolver (OTS) is a free, open-source tax preparation package (Roberts, 2026). OTS 2024 contains 24 form
https://www.irs.gov/pub/irs-pdf/i1040gi.pdf
Table 1: Comparison of model performance on Tax Year (TY) 2025 tax-return computation, with and without symbolic formalization. For each model, we report baselines without formalization followed by direct translation, self-debugging with execution feedback, and LAW&ORDER with localized execution feedback. WS stands for Web Search. Best results within each model are shown in bold.
| Model | Method | Correct returns (strict) | Correct returns (lenient) | Correct (by cell) | Correct (by cell, lenient) |
|---|---|---|---|---|---|
| GPT-6 | w/o formalization | 38.0% | 54.0% | 83.2% | 88.0% |
| w/o formalization + WS | 66.0% | 78.0% | 88.6% | 92.0% | |
| Direct translation | 95.0% | 95.0% | 99.3% | 99.3% | |
| Self-debugging | 100.0% | 100.0% | 100.0% | 100.0% | |
| LAW&ORDER | 100.0% | 100.0% | 100.0% | 100.0% | |
| GPT-5.5 (Medium) | Direct translation | 17.5% | 17.5% | 73.3% | 73.5% |
| Self-debugging | 37.5% | 37.5% | 75.0% | 75.4% | |
| LAW&ORDER | 95.0% | 95.0% | 99.3% | 99.3% | |
| Claude Opus 5.5 | w/o formalization | 40.0% | 50.0% | 83.6% | 87.3% |
| w/o formalization + WS | 64.0% | 76.0% | 89.0% | 92.9% | |
| Direct translation | 52.5% | 52.5% | 89.3% | 89.3% | |
| Self-debugging | 95.0% | 95.0% | 99.0% | 99.0% | |
| LAW&ORDER | 85.0% | 85.0% | 97.6% | 97.6% | |
| Claude Fable 5.1 | w/o formalization | 40.0% | 50.0% | 83.5% | 86.3% |
| w/o formalization + WS | 48.0% | 64.0% | 84.4% | 89.4% | |
| Direct translation | 55.0% | 55.0% | 93.9% | 94.1% | |
| Self-debugging | 92.5% | 92.5% | 98.5% | 98.5% | |
| LAW&ORDER | 72.5% | 72.5% | 95.2% | 95.4% | |
| Gemini 3.8 Flash | Direct translation | 27.5% | 27.5% | 78.4% | 78.4% |
| Self-debugging | 75.0% | 77.5% | 96.9% | 97.1% | |
| LAW&ORDER | 75.0% | 77.5% | 96.6% | 96.8% | |
| Kimi K3 | w/o formalization | 6.0% | 12.0% | 64.5% | 68.4% |
| Direct translation | 62.5% | 62.5% | 90.8% | 90.8% | |
| Self-debugging | 95.0% | 95.0% | 98.6% | 98.6% | |
| LAW&ORDER | 85.0% | 85.0% | 96.3% | 96.3% | |
| Qwen 3.6 8B | Direct translation | 0.0% | 0.0% | 54.7% | 55.0% |
| Self-debugging | 0.0% | 0.0% | 54.8% | 55.2% | |
| LAW&ORDER | 0.0% | 0.0% | 55.7% | 55.9% |
programs and the tax solver accounts for 14,114 of those lines, and the 2024 Form 1040 solver is 2,441 lines. OTS 2025 contains 27 form programs and the tax solver has 16,060 lines, the shared routines file is 1,369 lines, and the 2025 Form 1040 solver is 2,625 lines. The three programs added in 2025 are Schedule 1-A (282 lines), Form 2441 (654 lines), and Form 6781 (542 lines).
Test set. For evaluating our system, we use the 51 tax-return cases from TaxCalcBench. Each case provides taxpayer inputs, the corresponding expected return output, and a testing harness that verifies whether a model produces the correct result. TaxCalcBench includes both federal and state tax returns and covers a range of complex tax and financial scenarios.
Baselines We compare five approaches to tax-return computation. Without formalization directly computes tax returns from taxpayer inputs and tax instructions without constructing an executable symbolic representation. Without formalization + Web Search (WS) follows the same approach but additionally allows the model to retrieve relevant information from the Web. Direct translation (Han et al., 2024a; Olausson et al., 2023) translates tax forms and instructions into an executable symbolic program in a single pass. Self-debugging (Chen et al., 2024) iteratively revises the generated program using execution feedback. Finally, LAW&ORDER performs targeted program repair using localized execution feedback.
4.2 ACCURACY MEASUREMENT
We define cell-level accuracy as
A cell is considered correct if its value matches the output value for the corresponding test case. A synthesized form is considered correct if all cells match the benchmark outputs across all evaluation
Table 2: Comparison of model performance on Tax Year (TY) 2024 tax-return computation using symbolic formalization. For each model, we compare direct translation, self-debugging with execution feedback, and LAW&ORDER with localized execution feedback. Best results within each model are shown in bold.
| Model | Method | Correct returns (strict) | Correct returns (lenient) | Correct (by cell) | Correct (by cell, lenient) |
|---|---|---|---|---|---|
| GPT-6 | Direct translation | 100.0% | 100.0% | 100.0% | 100.0% |
| Self-debugging | 86.3% | 86.3% | 97.5% | 97.5% | |
| LAW&ORDER | 100.0% | 100.0% | 100.0% | 100.0% | |
| GPT-5.5 (Medium) | Direct translation | 29.4% | 31.4% | 91.1% | 91.4% |
| Self-debugging | 72.5% | 72.5% | 94.4% | 94.4% | |
| LAW&ORDER | 35.3% | 35.3% | 91.4% | 91.4% | |
| Claude Opus 5.5 | Direct translation | 92.2% | 92.2% | 98.3% | 98.3% |
| Self-debugging | 76.5% | 76.5% | 96.5% | 96.5% | |
| LAW&ORDER | 92.2% | 92.2% | 98.3% | 98.3% |
cases. Form-level accuracy is therefore defined as
4.3 MAIN RESULTS
Table 1 shows that LAW&ORDER 's primary strength is its ability to substantially improve weaker initial formalizations through localized execution feedback, with the clearest gains appearing for GPT-5.5 (Medium). For this model, LAW&ORDER increases strict return-level accuracy from only under direct translation and under self-debugging to , while increasing cell-level accuracy from and to , respectively. This large gap over self-debugging suggests that localized feedback can be particularly effective when global debugging fails to identify or isolate errors. LAW&ORDER also reaches return- and cell-level accuracy with GPT-6 and substantially improves over direct translation for several other models. However, LAW&ORDER does not consistently outperform conventional self-debugging: Claude Opus 5.5, Claude Fable 5.1, and Kimi K3 perform better with self-debugging, while the two approaches are comparable for Gemini 3.8 Flash. We hypothesize that this difference may arise because Claude models have been optimized for global self-debugging and agentic coding workflows, making them particularly effective at repairing programs from execution feedback without explicit localization. Finally, LAW&ORDER cannot fully compensate for insufficient underlying model capability, as Qwen 3.6 8B remains at return-level accuracy despite modest improvements at the cell level. Overall, these results suggest that LAW&ORDER is especially valuable when global self-debugging is ineffective—as illustrated by the large improvement for GPT-5.5—although its advantage is model-dependent.
Importantly, the results of self-debugging and LAW&ORDER should not be interpreted as the accuracy of a single LLM generation pass. Rather, they reflect the accuracy of the complete synthesis–verification-repair system, which combines program generation, symbolic execution, discrepancy localization, and iterative correction until consistency is achieved. We also show the results of model performance with formalization on Tax Year 2024 in Table 2. GPT-5.5 performs relatively poorly with LAW&ORDER on Tax Year 2024 primarily because it fails to correctly formalize Form 1040 Line 35a, which computes the tax refund. This cell is relatively complex, involving four operations, including a division. Because Line 35a lies on the main computation path, this error affects all returns that result in a refund, substantially reducing return-level accuracy. Returns without a refund are unaffected by this error.
Overall, these results demonstrate the value of explicit symbolic structure in domains such as taxation and law, where correctness depends on adherence to formal rules rather than linguistic plausibility alone. Combining natural-language understanding with executable symbolic representations enables intermediate computations to be inspected, verified, and repaired. By grounding computation in explicit symbolic structures, LAW&ORDER facilitates fine-grained verification and localized correction of generated formalizations.

Figure 3: Distribution of calculation chain lengths for correct and incorrect GPT-5.5 predictions.

Figure 4: Histogram of cell count by reasoning depth, pooled across all 26 benchmark forms ( ). Depth 0 (raw inputs) accounts for 1,021 cells; a long tail of multi-step tax logic extends to depth 30.
4.4 PROVING SEMANTIC EQUIVALENCE AND DIVERGENCE
We uniformly sampled 50 cells and compare the implementations generated by Claude Opus 5.5 with their corresponding gold implementations. We use Claude Code to construct formal proofs of equivalence or, when the implementations differ semantically, to identify inputs that demonstrate their divergence. For 43 of the 50 sampled cells, equivalence is successfully proven. For the remaining seven cells, Claude Code identifies counterexamples under which the generated and gold implementations produce different outputs. Manual inspection shows that six of these divergences result from errors in the Opus 5.5 implementations, while one reveals an error in the gold implementation: it assigns a 200,000 specified in the tax instructions. Examples of equivalence proofs and counterexamples are provided in Appendix A.1.
5 ANALYSIS
5.1 COMPLEXITY ANALYSIS OF THE TEST SET
Figure 4 shows the distribution of reasoning depth across the 1,847 cells in the 26 benchmark forms. While 1,021 cells correspond to raw inputs at depth 0, the remaining cells span a broad range of reasoning depths, reflecting computations that depend on increasingly long chains of intermediate values. A substantial number of cells require multiple levels of reasoning, with depths of 5, 10, and beyond representing nontrivial dependency chains. The distribution extends to a maximum depth of 30, illustrating that tax-form computation can involve deeply nested dependencies and long sequences of interconnected calculations.
5.2 ACCURACY VS LENGTH OF CALCULATION CHAINS
From Figure 3, we show that errors are concentrated among examples with longer calculation chains, indicating that model accuracy decreases as reasoning depth increases. This pattern is consistent with the hypothesis that intermediate mistakes accumulate over multi-step computations, leading to a higher probability of failure on long reasoning trajectories. Similar phenomena have been reported in prior deductive reasoning and math reasoning benchmarks (Han et al., 2024b; Miner et al., 2025) where model performance degrades as the length and complexity of the reasoning chain increase.
As shown in Figure 5 and Figure 6, in both repair and test sets, LAW&ORDER shows a more stable iterative improvement than self-debugging. On the repair set, trace-level accuracy generally increases steadily under LAW&ORDER, and these gains are accompanied by rapid improvements in line-level accuracy on the independently authored test set, with GPT-6 reaching 100% and GPT-5.5 reaching 99.8%. In contrast, although self-debugging performs well with the stronger models, it is highly unstable with GPT-5.5, exhibiting substantial regressions and fluctuations on both sets. These results indicate that LAW&ORDER provides a more consistent optimization trajectory and that improvements on the repair set generally transfer to the held-out test set.

(a) LAW&ORDER

(b) Self-Debugging
Figure 5: Trace-level accuracy across optimization iterations for LAW&ORDER and self-debugging across different models. For self-debugging, the final observed values for GPT-6 and Claude Opus 5.5 are extended through the remaining iterations.

(a) LAW&ORDER

(b) Self-Debugging
Figure 6: Cell-level accuracy across optimization iterations for LAW&ORDER and self-debugging across different models. For self-debugging, the final observed values for GPT-6 and Claude Opus 5.5 are extended through the remaining iterations.
5.3 LINE COVERAGE OF THE TEST CASES
Tax forms exhibit relatively limited branching structure, allowing most cells to be exercised with only one or two examples. For Tax Year (TY) 2024, the repair set, containing at most two inputs per form, achieves 94.6% cell coverage and 44.0% branch coverage. By comparison, the 51-input test set increases coverage to 98.6% of cells and 73.1% of branches. A similar pattern holds for TY 2025: the repair set achieves 93.3% cell coverage and 44.0% branch coverage, whereas the 51-input test set achieves 93% cell coverage and 73% branch coverage. Thus, even a small number of examples exercises the vast majority of tax-form cells, although substantially more examples are required to cover alternative execution paths. Despite the sparsity of the repair sets, the relatively rigid structure and unambiguous wording of tax forms allow limited execution feedback to provide broad coverage of the underlying computations.
6 CONCLUSION
We proposed LAW&ORDER, an iterative optimization framework for large-scale tax law auto-formalization with localized program repair. Extensive experiments and analyses demonstrate that LAW&ORDER achieves strong performance beyond the human-written repair cases used for optimization, including on independently authored, CPA-written held-out tax returns across 30 tax forms. On these held-out returns, a frontier LLM correctly computes only 66% of returns, whereas LAW&ORDER achieves 100% accuracy. Our analysis further shows that iterative repair consistently improves performance on the repair set, with corresponding improvements on held-out test cases, demonstrating the effectiveness of localized optimization for producing reliable formalizations. We hope that LAW&ORDER provides a foundation for extending tax law auto-formalization to other jurisdictions, languages, and tax systems.
7 ACKNOWLEDGEMENT
We would like to thank Alex Aiken, Bella Li (Clark Raymond & Company (CPA) PLLC), Cleo Cornovardi, and Ahmad Jabbar for their fruitful discussions and constructive criticism.
8 STATEMENTS
AI USE STATEMENT
In this work, we used generative AI tools to polish writing; generate and format tables based on our experimental results; create a flowchart of our algorithm; summarize and analyze existing literature; improve the readability of the manuscript; identify relevant literature; and format references. We also used generative AI tools to create and modify scientific figures or images, generate software code, and assist in drafting portions of the manuscript.
We did not use generative AI tools to generate synthetic datasets; propose or refine hypotheses; design or provide feedback on research methodology or experiments; assist with translation; clean or reformat datasets; conduct qualitative or thematic data analysis; interpret experimental results; develop theoretical models or conceptual frameworks; formulate mathematical claims; provide critical ingredients for proving mathematical claims; or assist in writing mathematical proofs. These uses are therefore not applicable to this work.
All AI-assisted content was reviewed by the authors. In particular, LLM-generated code was validated against real-world inputs. The authors take full responsibility for the final content of this work, including all text, claims, code, figures, and other artifacts produced with the assistance of generative AI.
REPRODUCIBILITY STATEMENT
We will make the data and code used in this paper publicly available upon publication. We will also release all experimental output files and provide detailed experimental procedures in the appendix.
REFERENCES
Anthropic. Claude Fable 5.1. https://www.anthropic.com/claudefable-and-mythos-5-1, 2026a. Accessed: 2026-09-24.
Anthropic. Introducing Claude Opus 5.5. https://www.anthropic.com/claude-opus-5-5, September 2026b. Accessed: 2026-09-24.
Zhangir Azerbaijan, Bartosz Piotrowski, Hailey Schoelkopf, Edward W Ayers, Dragomir Radev, and Jeremy Avigad. Proofnet: Autoformalizing and formally proving undergraduate-level mathematics. arXiv preprint arXiv:2302.12433, 2023.
Michael R. Bock, Kara Molisee, Zachary Ozer, and Sumit Shah. Taxcalcbench: Evaluating frontier models on the tax calculation task, 2025. URL https://arxiv.org/abs/2507.16126.
Xinyun Chen, Maxwell Lin, Nathanael Schärli, and Denny Zhou. Teaching large language models to self-debug. In The Twelfth International Conference on Learning Representations, 2024. URL https://openreview.net/forum?id=KuPixIqPiq.
Alejandro de la Garza. States' automated systems are trapping citizens in bureaucratic nightmares with their lives on the line, May 2020. URL https://time.com/5840609/algorithm-unemployment/. [Online; accessed 2026-05-31].
Guangyao Dou, Luis Brena, Akhil Deo, William Jurayj, Jingyu Zhang, Nils Holzenberger, and Benjamin Van Durme. Deonticbench: A benchmark for reasoning over rules, 2026. URL https://arxiv.org/abs/2604.04443.
Guoxiong Gao, Yutong Wang, Jiedong Jiang, Qi Gao, Zihan Qin, Tianyi Xu, and Bin Dong. Herald: A natural language annotated lean 4 dataset. In International Conference on Learning Representations, volume 2025, pp. 55720–55762, 2025.
Sina Gogani Khiabani, Ashutosh Trivedi, Diptikalyan Saha, and Saeid Tizpaz-Niari. An llm agentic approach for legal-critical software: A case study for tax prep software. In Proceedings of the 2026 IEEE/ACM 48th International Conference on Software Engineering, ICSE '26, pp. 272–283, New York, NY, USA, 2026. Association for Computing Machinery. ISBN 9798400720253. doi:10.1145/3744916.3764575. URL https://doi.org/10.1145/3744916.3764575.
Google. Gemini 3.1 Pro Preview. https://ai.google.dev/gemini-api/docs/models/gemini-3.1-pro-preview, 2026. Accessed: 2026-09-24.
Google DeepMind. Gemini 3.5: Frontier Intelligence with Action. https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-3-5/, May 2026. Accessed: 2026-09-24.
Pierre Goutagny, Aymeric Fromherz, and Raphaël Monat. Cutecat: Concolic execution for computational law, 2025. URL https://arxiv.org/abs/2410.18212.
Simeng Han, Hailey Schoelkopf, Yilun Zhao, Zhenting Qi, Martin Riddell, Wenfei Zhou, James Coady, David Peng, Yujie Qiao, Luke Benson, Lucy Sun, Alexander Wardle-Solano, Hannah Szabó, Ekaterina Zubova, Matthew Burtell, Jonathan Fan, Yixin Liu, Brian Wong, Malcolm Sailor, Ansong Ni, Linyong Nan, Jungo Kasai, Tao Yu, Rui Zhang, Alexander Fabbri, Wojciech Maciej Kryscinski, Semih Yavuz, Ye Liu, Xi Victoria Lin, Shafiq Joty, Yingbo Zhou, Caiming Xiong, Rex Ying, Arman Cohan, and Dragomir Radev. FOLIO: Natural language reasoning with first-order logic. In Yaser Al-Onaizan, Mohit Bansal, and Yun-Nung Chen (eds.), Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing, pp. 22017–22031, Miami, Florida, USA, November 2024a. Association for Computational Linguistics. doi: 10.18653/v1/2024.emnlp-main.1229. URL https://aclanthology.org/2024.emnlp-main.1229/.
Simeng Han, Aaron Yu, Rui Shen, Zhenting Qi, Martin Riddell, Wenfei Zhou, Yujie Qiao, Yilun Zhao, Semih Yavuz, Ye Liu, Shafiq Joty, Yingbo Zhou, Caiming Xiong, Dragomir Radev, Rex Ying, and Arman Cohan. P-FOLIO: Evaluating and improving logical reasoning with abundant human-written reasoning chains. In Yaser Al-Onaizan, Mohit Bansal, and Yun-Nung Chen (eds.), Findings of the Association for Computational Linguistics: EMNLP 2024, pp. 16553–16565, Miami, Florida, USA, November 2024b. Association for Computational Linguistics. doi: 10.18653/v1/2024.findings-emnlp.966. URL https://aclanthology.org/2024.findings-emnlp.966/.
Nils Holzenberger, Andrew Blair-Stanek, and Benjamin Van Durme. A dataset for statutory reasoning in tax law entailment and question answering. In Nikolaos Aletras, Ion Androutsopoulos, Leslie Barrett, Adam Meyers, and Daniel Preotiuc-Pietro (eds.), Proceedings of the Natural Legal Language Processing Workshop 2020 co-located with the 26th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining (KDD 2020), Virtual Workshop, August 24, 2020, CEUR Workshop Proceedings, pp. 31–38. CEUR-WS.org, 2020. URL https://ceur-ws.org/Vol-2645/paper5.pdf.
Albert Jiang, Charles Edgar Staats, Christian Szegedy, Markus Rabe, Mateja Jamnik, Wenda Li, and Yuhuai Tony Wu. Autoformalization with large language models. 2022.
Samuel Judson, Matthew Elacqua, Filip Cano, Timos Antonopoulos, Bettina Könighofer, Scott J. Shapiro, and Ruzica Piskac. 'put the car on the stand': Smt-based oracles for investigating decisions. In Proceedings of the 2024 Symposium on Computer Science and Law, CSLAW '24, pp. 73–85, New York, NY, USA, 2024. Association for Computing Machinery. ISBN 9798400703331. doi: 10.1145/3614407.3643699. URL https://doi.org/10.1145/3614407.3643699.
Sarah B. Lawsky. Coding the code: Catala and computationally accessible tax law. SMU Law Review, 75(3):535–557, 2022. doi: 10.25172/smulr.75.3.4. URL https://scholar.smu.edu/smulr/vol75/iss3/4/.
Sarah B. Lawsky. Direct file as formalization. Pittsburgh Tax Review, 23(2):283–, 2026a. doi:10.5195/taxreview.2026.293.
Sarah B. Lawsky. Direct file as formalization. Pittsburgh Tax Review, 23, 2026b. doi: 10.2139/ssrn.6721958. URL https://ssrn.com/abstract=6721958. University of Illinois College of Law Legal Studies Research Paper No. 26-8.
Lawrence Lessig. Code: And other laws of cyberspace. ReadHowYouWant.com, 2009.
Zhaoyu Li, Jialiang Sun, Logan Murphy, Qidong Su, Zenan Li, Xian Zhang, Kaiyu Yang, and Xujie Si. A survey on deep learning for theorem proving. arXiv preprint arXiv:2404.09939, 2024.
Qi Liu, Xinhao Zheng, Xudong Lu, Qinxiang Cao, and Junchi Yan. Rethinking and improving autoformalization: Towards a faithful metric and a dependency retrieval-based approach. In The Thirteenth International Conference on Learning Representations, 2025.
Denis Merigoux, Nicolas Chataing, and Jonathan Protzenko. Catala: A programming language for the law. Proceedings of the ACM on Programming Languages, 5(OOPSLA), 2021. doi:10.1145/3473582. URL https://arxiv.org/abs/2103.03198.
Marcus J. Min, Yeqi Gao, Wilson Sy, Zhaoyu Li, Xujie Si, and Osbert Bastani. Divide and abstract: Autoformalization via decomposition and abstraction learning. In The Fourteenth International Conference on Learning Representations, 2026. URL https://openreview.net/forum?id=NjgaeXNit3.
Stephen Miner, Yoshiki Takashima, Simeng Han, Sam Kouteili, Ferhat Erata, Ruzica Piskac, and Scott J Shapiro. Scheherazade: Evaluating chain-of-thought math reasoning in LLMs with chain-of-problems. In NeurIPS 2025 Workshop on Efficient Reasoning, 2025. URL https://openreview.net/forum?id=hEavDDH0Du.
Moonshot AI. Kimi K3. https://www.moonshot.ai/, 2026. Accessed: 2026-09-24.
Logan Murphy, Kaiyu Yang, Jialiang Sun, Zhaoyu Li, Anima Anandkumar, and Xujie Si. Autoformalizing euclidean geometry. arXiv preprint arXiv:2405.17216, 2024.
Theo X. Olausson, Alex Gu, Ben Lipkin, Cedegao E. Zhang, Armando Solar-Lezama, Joshua B. Tenenbaum, and Roger P. Levy. LINC: A neurosymbolic approach for logical reasoning by combining language models with first-order logic provers. In The 2023 Conference on Empirical Methods in Natural Language Processing, 2023. URL https://openreview.net/forum?id=h00GHjWDEp.
OpenAI. GPT-6 Astra: A New Generation of Intelligence. https://openai.com/index/gpt-6-astra/, 2026. Accessed: 2026-09-24.
Qwen Team. Qwen3.6. https://huggingface.co/Qwen/Qwen3-8B, 2026. Accessed: 2026-09-24.
Aston Roberts. Open tax solver, 2026. URL https://opentaxsolver.sourceforge.net/. Open-source income tax preparation software.
Treasury Inspector General for Tax Administration. Direct file activity for the 2025 filing season. Audit Report 2026-408-006, Treasury Inspector General for Tax Administration, March 2026. URL https://www.tigta.gov/.
Hanyu Wang, Ruohan Xie, Yutong Wang, Guoxiong Gao, Xintao Yu, and Bin Dong. Aria: An agent for retrieval and iterative auto-formalization via dependency graph. arXiv preprint arXiv:2510.04520, 2025.
Ke Weng, Lun Du, Sirui Li, Wangyue Lu, Haozhe Sun, Hengyu Liu, and Tiancheng Zhang. Autoformalization in the era of large language models: A survey. arXiv preprint arXiv:2505.23486, 2025.
Yuhuai Wu, Albert Q. Jiang, Wenda Li, Markus N. Rabe, Charles Staats, Mateja Jamnik, and Christian Szegedy. Autoformalization with large language models, 2022. URL https://arxiv.org/abs/2205.12615.
Kaiyu Yang, Gabriel Poesia, Jingxuan He, Wenda Li, Kristin Lauter, Swarat Chaudhuri, and Dawn Song. Formal reasoning meets llms: Toward ai for mathematics and verification. Communications of the ACM, 69(3):66–73, 2026. doi: 10.1145/3750038.
Kunhao Zheng, Jesse Michael Han, and Stanislas Polu. minif2f: a cross-system benchmark for formal olympiad-level mathematics. In International Conference on Learning Representations, 2022. URL https://openreview.net/forum?id=9ZPegFuFTFv.

Figure 7: Legal rules are built in nested refinement. A constitution has the highest authority but least detail, containing many ambiguities, vagueness, and gaps. Concrete details emerge as law is refined into more operational rules like legislation, regulation, and guidance. We formalize tax forms because they are closest to software, permitting mechanical translation.
Jin Zhou, Charles Staats, Wenda Li, Christian Szegedy, Kilian Weinberger, and Yuhuai Wu. Don't trust: Verify – grounding llm quantitative reasoning with autoformalization. In B. Kim, Y. Yue, S. Chaudhuri, K. Fragkiadaki, M. Khan, and Y. Sun (eds.), International Conference on Learning Representations, volume 2024, pp. 2544–2563, 2024. URL https://proceedings.iclr.cc/paper_files/paper/2024/file/0a79ecda13603817de4cdfc68b417e89-Paper-Conference.pdf.
A APPENDIX
A.1 DETAILS ON TAX FILING AND TAX FORMS
Federal income tax filing. The federal income tax filing process can be characterized as a sequence of interdependent computations that transform reported income into a final tax settlement. Taxpayers first aggregate income from sources such as wages, interest, dividends, retirement distributions, and Social Security benefits, after which eligible adjustments are applied to derive Adjusted Gross Income (AGI). AGI constitutes a central intermediate quantity, as numerous subsequent eligibility criteria, phase-outs, and tax computations depend on it.
Taxable income is subsequently derived from AGI by applying the relevant deductions, including the standard or itemized deduction and, where applicable, the Qualified Business Income (QBI) deduction. The resulting taxable income forms the basis for computing tax liability under the applicable IRS tax tables and worksheets, with separate computational rules governing income that receives preferential tax treatment, such as qualified dividends and capital gains. Finally, applicable tax credits and prior payments, including withholding and estimated tax payments, are applied against the resulting liability. This reconciliation determines the taxpayer's final position as either a refund or a balance due.
Progressively refined legal rules. As illustrated in Figure 7, statutes and other high-level legal sources are progressively refined through regulations, guidance, forms, and instructions before ultimately being implemented in software.
Semantic equivalence and divergence proof examples
Most proofs of equivalence were short, using reflection tactics like Fig. 8(a).
A.2 OTHER ANALYSES
Distribution of the number of cells. Table 3 summarizes the distribution of synthesized cells across the 26 tax forms in our generated Lean code. In total, the dataset contains 28 files and 1,019 synthesized cells, with substantial variation in the number of cells across forms. The largest forms are CA 540, Form CA 5805, NY IT-201, and OR-40, containing 153, 143, 118, and 102 synthesized cells, respectively. In contrast, several smaller forms contain fewer than 20 synthesized cells. This
-- gold def cell_155 (s : FormInput) : Float := (List.range 24).foldl (fun acc i acc + schedC_add i s) 0.0 -- Claude Opus 5.5 def opus_cell_155 (s : FormInput) : Float := (List.range 24).foldl (fun acc k acc + schedC_add k s) 0.0
theorem eq_155 : opus_cell_155 = cell_155 := rfl
(a) Equivalence
-- gold def cell_32 (p : ParsedInput) : Nat := (if over65ForVA (entryDate "YourDOB:" p) then 1 else 0) + (if cell_01_filing_status p == .marriedJoint && over65ForVA (entryDate "SpouseDOB:" p) then 1 else 0) + (if cell_24_you_blind_input p then 1 else 0) + (if cell_01_filing_status p = .marriedJoint && cell_25_spouse_blind_input p then 1 else 0) -- Claude Opus 5.5 def opus_cell_32 (p : ParsedInput) : Nat := let you := entryDate "YourDOB" p let sp := entryDate "SpouseDOB" p (if you.year > 0 && over65ForVA you then 1 else 0) + (if cell_24_you_blind_input p then 1 else 0) + (if sp.year > 0 && over65ForVA sp then 1 else 0) + (if cell_25_spouse_blind_input p then 1 else 0)
def input : ParsedInput := parseInputText "Status Married/joint\nYourDOB: 6/3/1970\nSpouseDOB: 11/2/1956"
theorem neg_32 : opus_cell_32 input cell_32 input := by native_decide
(b) Divergence
Figure 8: Lean 4 proofs relating Claude Opus 5.5's grind cells to gold. (a) CA 540 Schedule CA C11–C23 total: the bodies differ only in bound-variable names, so rfl closes the goal. (b) VA 760 age/blind exemptions: Opus looks up "SpouseDOB", but the input label is "SpouseDOB: ", so a spouse born in 1956 is never counted as 65 or older. Gold counts 1 exemption; Opus counts 0, and native_decide proves the outputs differ.
Table 3: Number of source files and synthesized cells for each tax form. Across 26 forms, the dataset contains 28 source files and 1,019 synthesized cells.
| Form | Files | Cells | Form | Files | Cells |
|---|---|---|---|---|---|
| CA_540 | 1 | 153 | VA_760 | 1 | 21 |
| Form_CA_5805 | 1 | 143 | MI_1040 | 1 | 19 |
| NY_IT201 | 1 | 118 | NC_D400 | 1 | 19 |
| OR_40 | 1 | 102 | Form_2441 | 1 | 18 |
| US_1040_2025ty | 2 | 76 | Form_8959 | 1 | 18 |
| MA_1 | 1 | 46 | Form_8960 | 1 | 17 |
| US_1040_Sched_1-A | 1 | 37 | Form_8606 | 1 | 16 |
| AZ_140 | 2 | 31 | Form_8995 | 2 | 13 |
| OH_IT1040 | 1 | 30 | Form_2210 | 1 | 12 |
| Form_8829 | 4 | 27 | HSA_Form_8889 | 1 | 12 |
| NJ_1040 | 1 | 26 | PA_40 | 1 | 12 |
| Form_8812 | 1 | 21 | US_1040_Sched_SE | 1 | 12 |
| Form_6781 | 1 | 9 | US_1040_Sched_C | 1 | 11 |
variation reflects the heterogeneity of tax forms in the dataset, which range from relatively small schedules and auxiliary forms to larger forms requiring substantially more cell-level formalization.
Distribution of the number of operations for one cell. Figure 9 shows the distribution of operator counts across 1,847 cells from 26 tax forms, revealing substantial variation in the computational complexity of tax-form logic. The distribution exhibits a pronounced long tail: while operator counts are generally concentrated at lower values, a nontrivial subset of cells requires substantially larger

Operations
Figure 9: Distribution of operator counts per cell_function across 1,847 cells from 28 tax forms. Some cells like the Taxpayer Identification Number are purely informational and thus ignored for the benchmark. Ignored cells are always zero operation.
computations. Some cells contain tens or hundreds of operators, with 17 cells exceeding 200 operators. This wide range demonstrates that tax-form formalization must accommodate computations spanning several orders of magnitude in size, including large, structurally complex calculations that pose substantially greater challenges for synthesis and verification.
Individual forms contributing to cells with different reasoning depths. We show the list of individual forms contributing to cells with different reasoning depths in Table 4 and Table 5 below.
A.3 EXPERIMENTAL DETAILS
Hyper-parameters. We set a maximum of 20 iterations for both the self-debugging and LAW&ORDER runs.
Prompts. We show the prompts used in different stages of our algorithm below.
Table 6: Translation prompt (TRANSLATION_PROMPT). The placeholders method_text, hint_text, cell_breakdown, section_parser_snippet, and row_pattern_snippet are expanded as shown in Table 7–Table 12.
You complete a Lean 4 tax-form skeleton (Template.lean).
The skeleton already defines helpers, structures, render, and main. Each def cell_* function whose body is sorry must be filled in using the
form instructions provided below. These include the instruction booklet (when
bundled), inline {...} guidance from the form template, and --
comments on
cells in Template.lean.
Do not change function names, type signatures, or the overall file
structure except
to replace sorry bodies with real implementations.
Leave any def cell_* that already reads an input (for example a single
inputNum
or entryNumber call) unchanged.
Return only one complete Lean 4 file inside a single lean code
block.
Do not write prose before or after the code block.
Continued on next page
Table 6 (continued)
The file will be checked with lake env lean --run under Lean 4.29.1.
Do not use C code, gold outputs, JSON, or APIs that are not imported or defined.
The first non-comment command in the file must be exactly import ExampleParse'. Do not put set_option', open', namespace', or any declaration before that import.
Do not import Mathlib', Std', or any module other than ExampleParse'. The submitted file must not contain sorry'.
Portable ExampleParse contract:
- Every benchmark provides `parseInputFile (path : System.FilePath) : IO ParsedInput'.
- Every benchmark provides
parsedInput.entries : List Entry', and eachEntry' haslabel : String' andvalues : List String'. - The common helper subset across benchmarks is:
entryValues',entryText',entryNumber',cleanLine',words',trimString', `toFloat?'. - On the shared parser used here, helper return types are:
entryValues : String -> ParsedInput -> List String',entryText : String -> ParsedInput -> String',entryNumber : String -> ParsedInput -> Float',entryInt : String -> ParsedInput -> Nat', `entryBool : String -> ParsedInput -> Bool'. - Some benchmarks also define extra helpers such as
entryBool',entryInt',statusFromInput',entityFromInput',entryNumberAt', orparsedInput.raw', but many do not. - Use prefix calls such as
entryText "YourName:" p',toFloat? tok', `trimString s'. - The
entry*helpers take the wholeparsedInput', notp.entries'. If you bindlet entries := p.entries', do not passentries' intoentryText' orentryNumber'. - Do not pattern-match on
entryText',entryNumber',entryInt', orentryBool' as if they returnedOption'. If you need an optional parse, usetoFloat?' on raw strings from `entryValues'. - The only numeric parser you should assume exists is
toFloat? (s : String) : Option Float'. There is noString.toFloat?',Float.toLong', orFloat.toInt'. - If helper availability is uncertain, write a small local helper over
p.entries' orentryText' instead of assuming a benchmark-specific API exists. - For checkbox logic, prefer a fresh local helper such as
localTruthy : String -> Bool' over assumingentryBool' exists. - Do not redefine names that may already be imported from
ExampleParse', such astruthy',cleanLine',words',trimString',toFloat?',entryText',entryValues',entryNumber',entryBool',entryInt',statusFromInput', orentityFromInput'. If you need a local variant, give it a fresh name likelocalTruthy'. Avoid new top-level names that collide with common field names such asentries',values', or `label'. - If
statusFromInput' orentityFromInput' are already available from `ExampleParse', use them directly instead of redefining them.
Continued on next page
Table 6 (continued)
- Do not write
ExampleParse.parseInputFile,tok.toFloat?',s.trim', parser combinators, guessed helpers likegetFloat!'', or guessed utilities likeList.enum'. - Do not use
List.enum',List.enumFrom',mapIdx',List.mapIdx',List.join',mut',String.trim', baregetD', orFloat.toInt'. If you need row indices, write a recursive helper that threadsidx : Nat'. If you need a default fromOption', use pattern matching oropt.getD default'. Write the full application, for example(toFloat? s).getD 0.0'. Do not use proof-based indexing such asxs[i]',List.nthLe', orxs.get <i, h>'. AftersplitOn', pattern match on the resulting list instead of usingget!'. Example:match s.splitOn "-" with | a :: b :: c :: _ => ... | _ => ...'. UseString.intercalateandtrimString s', not dot notation likexs.intercalateor `s.trimString'.
Program contract:
- Import `ExampleParse'.
- Fill every
def cell_*whose body is currentlysorryaccording to the form instructions below (not by guessing from examples or gold outputs). - Input cells should read from
parsedInput(orFormStatewhen the skeleton does); computed cells should be formulas over earliercell_*functions. - Keep the existing
renderandmaindefinitions unless a minimal edit is required for your filledcell_*functions to typecheck. - Reuse only real form labels. Do not emit notes, comments, section headers, `Part', or synthetic labels.
- Default strategy for most forms: use
entryText',entryNumber', local helpers over `p.entries', and direct scalar formulas. Most benchmarks are scalar forms and do not need custom row parsing. - Some visible labels start repeating tables or worksheets rather than scalar cells. Do not emit
L1 = ...just because a section starts with `L1'; treat it as rows, not one scalar cell. - Only use
p.rawor raw-line section parsing on benchmarks that actually exposeparsedInput.raw'. Many forms do not exposeraw', so on those forms you must stay withinp.entriesand the common helpers. - A template likely needs raw row parsing only when a label is followed by continuation lines up to
'; and simpleentryValues` would lose row boundaries. Otherwise avoid raw parsing. - For repeating rows, use labels like
L10row1_a',L10row1_b', ... with the form's row order and column-letter suffixes. Do not invent descriptive suffixes likegross',date', or `loss'. - If a row line contains brace text like ` { Broker A }, that brace text is usually the text cell.
- When a repeated row has a description or date text column, that column must use `textLine', not numeric parsing.
- Illustrative example only:
Continued on next page
Table 6 (continued)
wrong: L1 = 1710.99, L10row1_gross = 1000.0
right: L1row1_a: Broker A', L1row1_b = -300.99', L1row2_c = 10.99', L10row1_d = 1000.0`
- Emit all present rows in order, capped by the visible row count of the form.
- Use simple recursive helpers and list pattern matching such as
a :: b :: rest. AvoidList.get!,get?, imperative loops, and parser DSLs. entryValuesis fine for simple cells but loses row boundaries for multiline tables. Parse repeating sections fromp.rawonly on benchmarks that actually defineraw.- Parse repeating rows first, then compute downstream scalar cells from those parsed rows.
- If and only if the benchmark exposes
p.raw, a good repeated-section pattern is: {section_parser_snippet} - If and only if the benchmark exposes
p.raw, a good row-building and row-rendering pattern is: {row_pattern_snippet} - Emit deterministic trace lines only:
- numeric cells as
Label = value - text and checkbox cells as
Label: value - checkbox values as
Xor empty text, nevertrueorfalse
- numeric cells as
- Numeric input cells still render with
line, nottextLine. - Omit optional row cells that should be absent in the comparable trace instead of printing
= 0. - The checker compares emitted cells in order. An early wrong label causes an immediate failure, so do not emit approximate summaries before the exact row/cell labels.
- Prefer small helpers like:
def fmt (x : Float) : String := toString xdef line (label : String) (value : Float) : String := label ++ " = " ++ fmt valuedef textLine (label value : String) : String := label ++ " : " ++ valuedef notLessThanZero (x : Float) : Float := if x < 0.0 then 0.0 else x - Row renderers should return
List String, not one newline-joinedString. Use the recursiverenderIndexedFromstyle above instead ofmapIdx - If you normalize dates, split the original date string and use
String.toNat?, not float arithmetic. - End with
render : ParsedInput -> Stringand this exact main shape: ``lean def main (args : List String) : IO UInt32 := do match args with | inputPath :: _ => let parsed <- parseInputFile inputPath IO.print (render parsed) return 0 | [] => IO.eprintln "usage: form <example input>" return 1 ...
Continued on next page
Table 6 (continued)
- Avoid Lean warnings and unused helpers because warning text breaks trace comparison.
- The checker effectively treats warnings as failures. Never use deprecated APIs such as
String.trim. - It is acceptable to add
set_option linter.unusedVariables falsenear the top if needed. - Keep the code conservative and typecheck-first.
{method.text}{hint.text}{cell.breakdown}
Form instructions (booklet + inline form text; use these to fill each
sorry): {form_instructions}
Lean skeleton (Template.lean):
{tax_form_template}
Table 7: Method instructions (METHOD_INSTRUCTIONS), substituted for method_text in the translation prompt. Empty in the ablation.
Use a deliberate completion method:
- Read the form instructions provided below (instruction booklet, inline
{...}notes from the form template, and--comments in Template.lean), then the skeleton helpers and existing inputcell_*functions. - For every
def cell_*whose body issorry, implement the computation described in those instructions for that line or cell. Match each function to the form using its name, labels, and comments in Template.lean. - Fill sorries in dependency order so later cells can call earlier ones.
- Encode each computed cell as a small formula over other
cell_*functions and inputs. Do not invent formulas that contradict the instructions. - Keep rendering deterministic and ordered like the form.
- Prefer simple Float arithmetic and small helper functions over hard-coded examples.
Table 8: Repair-round hint text, substituted for hint_text in the translation prompt when feedback from a previous attempt is available.
Highest-priority repair target from the previous attempt: {hints} Use that feedback as the first thing to fix. Preserve earlier cells that already match. If the feedback names a first failing cell, keep every earlier emitted cell unchanged and make the next emitted output line match the expected cell exactly before changing later cells. If the feedback is a Lean diagnostic, fix that exact construct first and avoid unrelated rewrites. {available_cells_section}
Table 9: Available-cells section, substituted for available_cells_section in the hint text and the repair prompt.
Available cell functions (use only these identifiers; do not invent new cell_* names or guess namespaced spellings): {joined}
Table 10: Cell-breakdown header (CELL_BREAKDOWN_HEADER), prepended to the per-cell instruction text substituted for cell_breakdown.
Per-cell breakdown of the sorry functions you must implement. Each entry gives the def cell_* you must fill and the form text describing it. Implement exactly these functions; leave every other definition unchanged.
Table 11: Section-parser snippet (SECTION_PARSER_SNIPPET), substituted for section_parserSnippet in the translation prompt.
~~lean def wordsBeforeSemicolon (tokens : List String) : List String := tokens.takeWhile (fun tok => tok != ";"")
def startsSection (label : String) (line : String) : Bool := match words (cleanLine line) with | first :: _ => first = label | [] => false
partial def collectSectionLines (label : String) (lines : List String) (started : Bool) (acc : List String) : List String := match lines with | [] => acc.reverse | line :: rest => if started then let acc' := line :: acc if (words (cleanLine line)).any (fun tok => tok = ";"") then acc'.reverse else collectSectionLines label rest true acc' else if startsSection label line then let acc' := [line] if (words (cleanLine line)).any (fun tok => tok = ";"") then acc' else collectSectionLines label rest true acc' else collectSectionLines label rest false acc
def sectionLines (label : String) (p : ParsedInput) : List String := collectSectionLines label (p.raw.splitOn "\n") false []
def braceText (line : String) : Option String := match line.splitOn "{ " with | _ :: after :: _ => match after.splitOn "}" with | inside :: _ => some (trimString inside) | [] => none | _ => none
Continued on next page
Table 11 (continued)
...
Table 12: Row-pattern snippet (ROW_PATTERN_SNIPPET), substituted for row_pattern_snippet in the translation prompt.
`lean structure Row where desc : String x : Float y : Float
partial def buildRows : List String -> List String -> List Row | desc :: descs, x :: y :: rest => { desc := desc, x := (toFloat? x).getD 0.0, y := (toFloat? y).getD 0.0 } :: buildRows descs rest | -, - => []
def renderRow (idx : Nat) (row : Row) : List String := [textLine ("Llrow" ++ toString idx ++ "_a") row.desc, if row.x != 0.0 then line ("Llrow" ++ toString idx ++ "_b") row.x else "", if row.y != 0.0 then line ("Llrow" ++ toString idx ++ "_c") row.y else ""]
partial def renderIndexedFrom {α : Type} (limit : Nat) (idx : Nat) (renderRow : Nat -> α -> List String) : List α -> List String | [] => [] | row :: rows => if idx > limit then [] else renderRow idx row ++ renderIndexedFrom limit (idx + 1) renderRow rows ...
Table 13: Entailment prompt (ENTAILMENT_PROMPT): the model fills in the computed cells of a partially filled form.
Fill the missing computed cells in this tax form and return only a comparable trace.
Return plain text only. Do not use markdown, code fences, explanations, or notes. Do not emit section headers, comments, or synthetic summary labels.
Trace rules:
- Use
Label = valuefor numeric cells. - Use
Label: valuefor text and checkbox cells. - Preserve the form's order.
- Copy existing input cells into the trace too.
- Reuse only real form labels.
- For repeating tables, emit row/cell labels such as
Llrow1_a,Llrow1_b,Ll0row1_d,Ll4row2_e. - Use the form's row order and column-letter suffixes instead of descriptive suffixes.
Continued on next page
Table 13 (continued)
- If a row contains brace text like
{ Broker A }, use that text for the row's text cell. - Wrong:
L1 = 1710.99,L10row1_gross = 1000.0. Right:L1row1_a: Broker A,L1row1_b = -300.99,L10row1_d = 1000.0. - Checkbox values must be
Xor empty text, nevertrueorfalse. - Omit optional row cells that should be absent in the comparable trace instead of printing
= 0.
Partial tax form with missing computed cells: {partial_tax_form}
Table 14: Cell-extraction prompt (CELL_EXTRACTION_PROMPT).
You read filled-in examples of one tax form and list every cell on the form.
A "cell" is one numbered line or labeled entry on the form, for example L1, L4, BoxA,
or YourName. For each cell decide whether it is an input (a value
the filer enters
directly, copied from a document or another form) or computed (a value
derived by
arithmetic from other cells on this same form).
Return only a single JSON array. Do not write prose, headings, or any code fence other than the JSON. Each array element is an object with exactly these keys:
- "number": integer position of the cell on the form, starting at 1 and increasing in form order.
- "name": short snake-case summary of the cell, ascii letters/digits/underscores only, no spaces, for example "l4_adjustments" or "boxA_mixed_straddle".
- "label": the exact label as written in the form text, for example "L4", "BoxA", "YourName".
- "kind": either "input" or "computed".
- "value_kind": one of "number", "text", "checkbox".
Rules:
- Walk the form from top to bottom and emit the cells in that order.
- Identity fields such as names and SSNs are inputs with value_kind "text".
- Checkbox cells (shown as Y, N, or X) use value_kind "checkbox".
- A cell whose example value equals a sum, difference, min/max, or other arithmetic over earlier cells is "computed". A cell read straight from a W-2, 1099, schedule, or the filer is "input".
- A repeating worksheet listing (a label followed by several rows up to a `) is one input cell with value_kind "number".
Filled-in example form(s): {examples}
Table 15: Batched correspondence localization prompt (CORRESPONDENCE_BATCH_PROMPT). cells_block repeats the block in Table 16 once per cell.
You verify every cell of a Lean 4 tax-form translation against its instructions in one pass.
For each cell below (listed from low to high), decide whether the Lean implementation matches the natural-language instruction. Report every cell whose Lean code does not match its instruction.
If every cell matches, answer on the first line with exactly MATCH ALL.
If any cells mismatch, list each one in order using this format (repeat for every mismatch): MISMATCH <cell_name> <explanation of what is wrong and what the correct computation should be, so another model can repair the Lean code>
Cells to verify: {cells_block}
Table 16: Per-cell block substituted into cells_block of the correspondence and self-consistency prompts.
{name}
Instruction: {n1}
Lean: ~~lean {lean} ...
Table 17: Single-cell correspondence localization prompt (CORRESPONDENCE_JUDGE_PROMPT).
You verify one cell of a Lean 4 tax-form translation against its instruction.
Cell: {cell_name}
Natural-language instruction for this cell: {n1}
Lean implementation of this cell: ~~lean {lean} ...
Does the Lean implementation correctly implement the natural-language instruction?
Answer on the first line with exactly MATCH or MISMATCH.
Continued on next page
Table 17 (continued)
If MISMATCH, then on the following lines explain precisely what is wrong and what the correct computation should be, so another model can repair the Lean code.
Table 18: Self-consistency critique prompt (SELF_CONSISTENCY_CRITIQUE_PROMPT). cells_block is formatted as in Table 16.
You previously produced this Lean 4 tax-form translation. Critique your own output.
For each cell below (listed from low to high), decide whether the Lean implementation correctly matches the natural-language instruction. Do not use external oracles, gold answers, or test traces | judge only from the instructions and the Lean code you see.
If you agree that every cell is correct, answer on the first line with exactly MATCH ALL.
If you find problems, list each one in order using this format (repeat for every mismatch): MISMATCH <cell_name> <explanation of what is wrong and what the correct computation should be, so a repair step can fix the Lean code>
Cells to critique: {cells_block}
Table 19: Round-trip localization, step 1, batched (LEAN_TO_NL_BATCH_PROMPT). cells_block repeats the block in Table 21.
Describe, in one or two plain-English sentences each, exactly what every Lean 4 tax-form cell below computes. For each cell output one line in this exact format: <cell_name>: <description>
Describe only the computation each cell performs in terms of the other cells and inputs it reads; add no commentary, caveats, or markdown outside those lines.
Cells: {cells_block}
Table 20: Per-cell block substituted into cells_block of the batched Lean-to-English prompt.
# {name}
~lean
{lean}
Continued on next page
Table 20 (continued)
....
Table 21: Per-cell block substituted into cells_block of the batched Lean-to-English prompt.
{name}
...lean
{lean}
....
Table 22: Round-trip localization, step 2, batched (NL EQUIVALENCE BATCH PROMPT). cells_block repeats the block in Table 23.
You compare reference instructions against descriptions derived from Lean code
for every cell of a tax form in one pass.
For each cell below, decide whether the two descriptions describe the same computation.
Report every cell where they differ.
If every cell matches, answer on the first line with exactly MATCH ALL.
If any cells mismatch, list each one in order using this format (repeat for every mismatch):
MISMATCH <cell_name>
<explanation of what differs and what the Lean code should compute instead>Cells:
{cells_block}
Table 23: Per-cell block substituted into cells_block of the batched equivalence prompt.
{name}
Reference instruction:
{expected_nl}
Description derived from Lean:
{derived_nl}
Table 24: Round-trip localization, step 1, single cell (LEAN_TO_NL_PROMPT).
Describe, in one or two plain-English sentences, exactly what this Lean 4 tax-form cell computes. Describe only the computation it performs in terms of the other
cells and inputs it reads; add no commentary, caveats, or markdown.
Continued on next page
Table 24 (continued)
| …lean |
|---|
| {lean} |
| … |
Table 25: Round-trip localization, step 2, single cell (NL EQUIVALENCE PROMPT).
You compare two descriptions of one tax-form cell.
Reference instruction (from the form): {expected_n1}
Description derived from the Lean code: {derived_n1}
Do the two descriptions describe the same computation for this cell? Answer on the first line with exactly MATCH or MISMATCH. If MISMATCH, explain on the following lines what differs and what the Lean code should compute instead, so another model can repair it.
Table 26: Entailment-divergence explanation prompt (DIVERGENCE_EXPLANATION_PROMPT).
A Lean 4 tax form and an independently filled-in version of the same form disagree on one cell.
Cell / line: {label}
Natural-language instruction for this cell: {n1}
Cell values computed for earlier lines (for context, in order): {context}
Value from the Lean translation: {lean_value} Value from the filled-in form: {expected_value}
Explain in plain English why these two values differ and what the correct computation for this cell should be, so another model can repair the Lean code. Be concrete about the formula or inputs the Lean code should use.
Table 27: Shared repair prompt (REPAIR_PROMPT). The optional sections are shown in Table 28 and Table 9.
You repair a Lean 4 tax-form translation (a filled Main.lean-style file).
A localization step identified the first incorrect cell and produced a hint describing the
Continued on next page
Table 27 (continued)
issue. Fix ONLY that primary failing cell (and at most the tiny helper edits required for it
to typecheck). Keep every other cell_* function, helper, render, and main exactly as
they are. Do not reorder top-level declarations. Do not introduce
sorry. Do not change
function names or type signatures except where the hint requires it.
Rounding check: when gold expects a value with fractional cents (for example 5.10 or 57985.65) but the candidate prints a whole amount (5.00 or ...55 with .00 cents), or the mismatch is exactly 0.01, or 1 tax mismatch on a downstream line often comes from a $0.10 AGI drift caused by rounding L6b or another upstream cell.
Return only one complete Lean 4 file inside a single lean code
block, with no prose
before or after it. The file must still start with import ExampleParse
as its first
non-comment command and must typecheck under Lean 4 with lake env lean --run.
Primary failing cell (if any one is singled out): {failing_cell}
Localization hint (fix every issue described): {hint} {rounding_hint_section}{available_cells_section}{form_instructions_section} Current Lean file to repair: ``lean {lean_code} ...
Table 28: Optional sections of the repair prompt: rounding_hint_section (top; rounding_extra is one message from Table 29) and form_instructions_section (bottom). Each is included only when non-empty.
Detected rounding pattern: {rounding_extra}
Reference instructions for the failing cell only (use these to confirm the correct computation): {instructions}
Table 29: Rounding-mismatch messages (rounding_mismatch_hint). At most one, selected by the kind of mismatch, is inserted into the repair prompt.
[Fractional cents expected, whole amount produced]
Gold keeps fractional cents ({expected_value}) but the candidate returned a whole amount ({actual_value}). Inspect this cell and upstream cells for unconditional wholeRound. Gold Main.lean often keeps raw floats on regular example inputs and only rounds when isTaxCalcBenchInput s is true (pattern: if isTaxCalcBenchInput s then wholeRound x else x).
[Difference of exactly $0.10]
Values differ by exactly $0.10 ({expected_value} vs {actual_value}). This often means an upstream cell rounded a value like 5.1 down to 5.0 with wholeRound where gold keeps the float. Fix the upstream rounding guard before changing downstream tax formulas.
[Difference of exactly $1.00]
Values differ by exactly $1.00 ({expected_value} vs {actual_value}). If the localized cell is downstream (tax, credits), first check upstream income/deduction cells for mistaken wholeRound that shifted AGI or taxable income across a bracket boundary.
[Difference of exactly $0.01]
Values differ by exactly $0.01 ({expected_value} vs {actual_value}). Check for an extra or missing wholeRound, or a float-vs-cent rounding mismatch in this cell or its direct inputs.
Table 30: Forward-reference repair prompt (FORWARD_REF_REPAIR_PROMPT).
You fix a forward reference in a Lean 4 tax-form cell.
The cell "caller_name" calls "bad_callee" , but "bad_callee" is defined
later in the file (higher cell number). Replace each bad call with an earlier cell
from the allowed list, or inline logic using only allowed cells / inputs.
Return only JSON (no markdown) in this shape: {"replacements": {"bad_callee": "cell_XXX_allowed_name", "reason": "brief"}
Natural-language instruction for "caller_name":
{caller_nl}
Allowed earlier "cell_*" names (pick from this list only):
{allowed_cells}
Current Lean for "caller_name":
``lean
{caller_lean}
...
A.4 EXAMPLES
Formalization of IRS Schedule A generated by GPT 6 Astra
import ExampleParse
set_option linter.unusedVariables false
def form_inputs : List String := ["US_1040_Sched_1-A_example.txt"]
def notLessThanZero (x : Float) : Float := if x < 0.0 then 0.0 else x
def smallerOf (a b : Float) : Float := if a < b then a else b
def largerOf (a b : Float) : Float := if a > b then a else b
def fmt (x : Float) : String := toString x def fmtInt (n : Nat) : String := toString n
-- Inputs from example / imported from 1040 def cell_01_11_form_1040_line_11b (p : ParsedInput) : Float := entryNumber "L1" p
def cell_02_filing_status (p : ParsedInput) : FilingStatus := statusFromInput p
def cell_03_you_over_65 (p : ParsedInput) : Bool := entryBool "CkYouOver65" p
def cell_04_spouse_over_65 (p : ParsedInput) : Bool := entryBool "CkSpouseOver65" p
-- Part I inputs def cell_05_l2a_income_puerto_rico (p : ParsedInput) : Float := entryNumber "L2a" p def cell_06_l2b_form_2555_line_45 (p : ParsedInput) : Float := entryNumber "L2b" p def cell_07_l2c_form_2555_line_50 (p : ParsedInput) : Float := entryNumber "L2c" p def cell_08_l2d_form_4563_line_15 (p : ParsedInput) : Float := entryNumber "L2d" p
-- Part I computed def cell_09_l2e_total_modifications (p : ParsedInput) : Float := cell_05_l2a_income_puerto_rico p + cell_06_l2b_form_2555_line_45 p + cell_07_l2c_form_2555_line_50 p + cell_08_l2d_form_4563_line_15 p
def cell_10_l3_magi (p : ParsedInput) : Float := cell_01_11_form_1040_line_11b p + cell_09_l2e_total_modifications p
-- Part II inputs def cell_11_l4a_qualified_tips_w2 (p : ParsedInput) : Float := entryNumber "L4a" p def cell_12_l4b_qualified_tips_4137 (p : ParsedInput) : Float := entryNumber "L4b" p def cell_13_l5_tips_business (p : ParsedInput) : Float := entryNumber "L5" p
-- Part II computed def cell_14_l4c_larger_tips (p : ParsedInput) : Float := largerOf (cell_11_l4a_qualified_tips_w2 p) (cell_12_l4b_qualified_tips_4137 p)
def cell_15_l6_total_tips (p : ParsedInput) : Float := cell_14_l4c_larger_tips p + cell_13_l5_tips_business p
def cell_16_l7_capped_tips (p : ParsedInput) : Float := smallerOf (cell_15_l6_total_tips p) 25000.0
def cell_17_l8_magi_tips (p : ParsedInput) : Float := cell_10_l3_magi p
def cell_18_l9_tips_phaseout_threshold (p : ParsedInput) : Float := if cell_02_filing_status p = FilingStatus.marriedJoint then 300000.0 else 150000.0
def cell_19_l10_tips_excess (p : ParsedInput) : Float := notLessThanZero (cell_17_l8_magi_tips p - cell_18_l9_tips_phaseout_threshold p)
def cell_20_l11_tips_phaseout_units (p : ParsedInput) : Float := Float.ceil (cell_19_l10_tips_excess p / 1000.0) def cell_21_l12_tips_phaseout_reduction (p : ParsedInput) : Float := cell_20_l11_tips_phaseout_units p * 100.0
def cell_22_l13_tips_allowance (p : ParsedInput) : Float := notLessThanZero (cell_16_l7_capped_tips p - cell_21_l12_tips_phaseout_reduction p)
-- Part III inputs def cell_23_l14a_overtime_w2 (p : ParsedInput) : Float := entryNumber "L14a" p def cell_24_l14b_overtime_1099 (p : ParsedInput) : Float := entryNumber "L14b" p
-- Part III computed def cell_25_l14c_total_overtime (p : ParsedInput) : Float := cell_23_l14a_overtime_w2 p + cell_24_l14b_overtime_1099 p
def cell_26_l15_capped_overtime (p : ParsedInput) : Float := smallerOf (cell_25_l14c_total_overtime p) (if cell_02_filing_status p = FilingStatus.marriedJoint then 25000.0 else 12500.0)
def cell_27_l16_magi_overtime (p : ParsedInput) : Float := cell_10_l3_magi p
def cell_28_l17_overtime_phaseout_threshold (p : ParsedInput) : Float := if cell_02_filing_status p = FilingStatus.marriedJoint then 300000.0 else 150000.0
def cell_29_l18_overtime_excess (p : ParsedInput) : Float := notLessThanZero (cell_27_l16_magi_overtime p - cell_28_l17_overtime_phaseout_threshold p)
def cell_30_l19_overtime_phaseout_units (p : ParsedInput) : Float := Float.ceil (cell_29_l18_overtime_excess p / 1000.0)
def cell_31_l20_overtime_phaseout_reduction (p : ParsedInput) : Float := cell_30_l19_overtime_phaseout_units p * 100.0
def cell_32_l21_overtime_allowance (p : ParsedInput) : Float := notLessThanZero (cell_26_l15_capped_overtime p - cell_31_l20_overtime_phaseout_reduction p)
-- Part IV inputs def cell_33_l22aii_interest_sched (p : ParsedInput) : Float := entryNumber "L22aii" p def cell_34_l22aiii_interest_sched_1a (p : ParsedInput) : Float := entryNumber "L22aiii" p def cell_35_l22bii_interest_sched_2 (p : ParsedInput) : Float := entryNumber "L22bii" p def cell_36_l22biii_interest_sched_1a_2 (p : ParsedInput) : Float := entryNumber "L22biii" p
-- Part IV computed def cell_37_l23_total_interest (p : ParsedInput) : Float := cell_34_l22aiii_interest_sched_1a p + cell_36_l22biii_interest_sched_1a_2 p
def cell_38_l24_capped_interest (p : ParsedInput) : Float := smallerOf (cell_37_l23_total_interest p) 10000.0
def cell_39_l25_magi_interest (p : ParsedInput) : Float := cell_10_l3_magi p
def cell_40_l26_interest_phaseout_threshold (p : ParsedInput) : Float := if cell_02_filing_status p = FilingStatus.marriedJoint then 200000.0 else 100000.0
def cell_41_l27_interest_excess (p : ParsedInput) : Float := notLessThanZero (cell_39_l25_magi_interest p - cell_40_l26_interest_phaseout_threshold p)
def cell_42_l28_interest_phaseout_units (p : ParsedInput) : Float := Float.ceil (cell_41_l27_interest_excess p / 1000.0)
def cell_43_l29_interest_phaseout_reduction (p : ParsedInput) : Float := cell_42_l28_interest_phaseout_units p * 200.0
def cell_44_l30_interest_allowance (p : ParsedInput) : Float := notLessThanZero (cell_38_l24_capped_interest p - cell_43_l29_interest_phaseout_reduction p)
-- Part V computed def cell_45_l31_magi_age (p : ParsedInput) : Float := cell_10_l3_magi p
def cell_46_l32_age_phaseout_threshold (p : ParsedInput) : Float := if cell_02_filing_status p = FilingStatus.marriedJoint then 150000.0 else 75000.0
def cell_47_l33_age_excess (p : ParsedInput) : Float := notLessThanZero (cell_45_l31_magi_age p - cell_46_l32_age_phaseout_threshold p)
def cell_48_l34_age_reduction (p : ParsedInput) : Float := cell_47_l33_age_excess p * 0.06 def cell_49_135_age_deduction_base (p : ParsedInput) : Float := notLessThanZero (6000.0 - cell_48_134_age_reduction p)
def cell_50_136a_you_age_deduction (p : ParsedInput) : Float := if cell_03_you_over_65 p then cell_49_135_age_deduction_base p else 0.0
def cell_51_136b_spouse_age_deduction (p : ParsedInput) : Float := if cell_02_filing_status p = FilingStatus.marriedJoint && cell_04_spouse_over_65 p then cell_49_135_age_deduction_base p else 0.0
def cell_52_137_total_age_deduction (p : ParsedInput) : Float := cell_50_136a_you_age_deduction p + cell_51_136b_spouse_age_deduction p
-- Part VI computed def cell_53_138_total_additional_deduction (p : ParsedInput) : Float := cell_22_113_tips_allowance p + cell_32_121_overtime_allowance p + cell_44_130_interest_allowance p + cell_52_137_total_age_deduction p
def digitsOnly (s : String) : String := String.ofList (s.toList.filter (fun c => c.isDigit))
def takeChars (n : Nat) (s : String) : String := String.ofList (s.toList.take n)
def dropChars (n : Nat) (s : String) : String := String.ofList (s.toList.drop n)
def fmtSsn (s : String) : String := let d := digitsOnly s if d.length == 9 then takeChars 3 d ++ "" ++ takeChars 2 (dropChars 3 d) ++ "" ++ dropChars 5 d else d
def identityLines (p : ParsedInput) : List String := [ "YourNames:" ++ entryText "YourLastName:" p ++ "," ++ entryText "Your1stName:" p ++ "," ++ entryText "Spouse1stName:" p, "YourSocSec#:" ++ fmtSsn (entryText "YourSocSec#: " p) ]
def render (p : ParsedInput) : String := String.intercalate "\n" (identityLines p ++ [ "L1_=" ++ fmt (cell_01_11_form_1040_line_11b p), "L2a_=" ++ fmt (cell_05_12a_income_puerto_rico p), "L2b_=" ++ fmt (cell_06_12b_form_2555_line_45 p), "L2c_=" ++ fmt (cell_07_12c_form_2555_line_50 p), "L2d_=" ++ fmt (cell_08_12d_form_4563_line_15 p), "L2e_=" ++ fmt (cell_09_12e_total_modifications p), "L3_=" ++ fmt (cell_10_13_magi p), "L4a_=" ++ fmt (cell_11_14a_qualified_tips_w2 p), "L4b_=" ++ fmt (cell_12_14b_qualified_tips_4137 p), "L4c_=" ++ fmt (cell_14_14c_larger_tips p), "L5_=" ++ fmt (cell_13_15_tips_business p), "L6_=" ++ fmt (cell_15_16_total_tips p), "L7_=" ++ fmt (cell_16_17_capped_tips p), "L8_=" ++ fmt (cell_17_18_magi_tips p), "L9_=" ++ fmt (cell_18_19_tips_phaseout_threshold p), "L10_=" ++ fmt (cell_19_110_tips_excess p), "L11_=" ++ fmt (Float.floor (cell_20_111_tips_phaseout_units p)), "L12_=" ++ fmt (cell_21_112_tips_phaseout_reduction p), "L13_=" ++ fmt (cell_22_113_tips_allowance p), "L14a_=" ++ fmt (cell_23_114a_overtime_w2 p), "L14b_=" ++ fmt (cell_24_114b_overtime_1099 p), "L14c_=" ++ fmt (cell_25_114c_total_overtime p), "L15_=" ++ fmt (cell_26_115_capped_overtime p), "L16_=" ++ fmt (cell_27_116_magi_overtime p), "L17_=" ++ fmt (cell_28_117_overtime_phaseout_threshold p), "L18_=" ++ fmt (cell_29_118_overtime_excess p), "L19_=" ++ fmt (Float.floor (cell_30_119_overtime_phaseout_units p)), "L20_=" ++ fmt (cell_31_120_overtime_phaseout_reduction p), "L21_=" ++ fmt (cell_32_121_overtime_allowance p), "L22aii_=" ++ fmt (cell_33_122aii_interest_sched p), "L22aiii_=" ++ fmt (cell_34_122aiii_interest_sched_1a p), "L22bii_=" ++ fmt (cell_35_122bii_interest_sched_2 p), "L22biii_=" ++ fmt (cell_36_122biii_interest_sched_1a_2 p), "L23_=" ++ fmt (cell_37_123_total_interest p), "L24_=" ++ fmt (cell_38_124_capped_interest p), "L25_=" ++ fmt (cell_39_125_magi_interest p), "L26_=" ++ fmt (cell_40_126_interest_phaseout_threshold p), "L27_=" ++ fmt (cell_41_127_interest_excess p), "L28_=" ++ fmt (Float.floor (cell_42_128_interest_phaseout_units p)), "L20_=" ++ fmt (cell_43_129_interest_phaseout_reduction p),
"L30_=" ++ fmt (cell_44_l30_interest_allowance p), "L31_=" ++ fmt (cell_45_l31_magi_age p), "L32_=" ++ fmt (cell_46_l32_age_phaseout_threshold p), "L33_=" ++ fmt (cell_47_l33_age_excess p), "L34_=" ++ fmt (cell_48_l34_age_reduction p), "L35_=" ++ fmt (cell_49_l35_age_deduction_base p), if cell_03_you_over_65 p then "L36a_=" ++ fmt (cell_50_l36a_you_age_deduction p) else "", if cell_02_filing_status p = FilingStatus.marriedJoint && cell_04_spouse_over_65 p then "L36b_=" ++ fmt (cell_51_l36b_spouse_age_deduction p) else "", "L37_=" ++ fmt (cell_52_l37_total_age_deduction p), "L38_=" ++ fmt (cell_53_l38_total_additional_deduction p) ]) ++ "\n"
def main (args : List String) : IO UInt32 := do match args with | inputPath :: _ => let parsed <- parseInputFile inputPath IO.print (render parsed) return 0 | [] => IO.eprintln "usage: us_1040_sched_1a<example_input>" return 1
The code implements an executable symbolic representation of Schedule 1-A, organized as a sequence of fine-grained computations corresponding to individual form lines. It first parses taxpayer information and values imported from Form 1040, including adjusted gross income, filing status, and age indicators. The program then evaluates the schedule section by section: it computes modified adjusted gross income (MAGI); determines deductions for qualified tips and qualified overtime compensation subject to statutory caps and income-based phaseouts; calculates the deduction for eligible interest payments using a similar capped phaseout structure; and computes the additional deduction available to taxpayers age 65 or older. Each intermediate quantity is represented as a separate Lean function, preserving the structure and dependencies of the underlying tax form. The final computation aggregates the allowable deductions from these components into the total additional deduction reported on line 38. Auxiliary functions implement common operations such as nonnegative truncation, minimum and maximum selection, formatting, and taxpayer identification rendering, while the 'render' function evaluates the symbolic program and produces line-by-line form output from a parsed example return.
| Reasoning Depth | # Cells | Forms Contributing |
|---|---|---|
| 0 | 1021 | AZ_140 (58), CA_540 (92), Form_2210 (54), Form_2441 (35), Form_6781 (11), Form_8606 (20), Form_8812 (15), Form_8829 (34), Form_8959 (10), Form_8960 (25), Form_8995 (10), Form_CA_5805 (79), HSA_Form_8889 (15), MA_1 (55), MI_1040 (31), NC_D400 (21), NJ_1040 (32), NY_IT201 (74), OH_IT1040 (17), OR_40 (56), PA_40 (24), US_1040_2025ty (157), US_1040_Sched_1-A (17), US_1040_Sched_C (46), US_1040_Sched_SE (8), VA_760 (25) |
| 1 | 227 | AZ_140 (10), CA_540 (21), Form_2210 (1), Form_2441 (8), Form_6781 (3), Form_8606 (3), Form_8812 (7), Form_8829 (7), Form_8959 (5), Form_8960 (5), Form_8995 (4), Form_CA_5805 (13), HSA_Form_8889 (4), MA_1 (18), MI_1040 (7), NC_D400 (6), NJ_1040 (3), NY_IT201 (7), OH_IT1040 (4), OR_40 (15), PA_40 (2), US_1040_2025ty (52), US_1040_Sched_1-A (8), US_1040_Sched_C (4), US_1040_Sched_SE (3), VA_760 (7) |
| 2 | 119 | AZ_140 (3), CA_540 (10), Form_2210 (2), Form_2441 (8), Form_6781 (1), Form_8606 (3), Form_8812 (4), Form_8829 (1), Form_8959 (4), Form_8960 (3), Form_8995 (4), Form_CA_5805 (11), HSA_Form_8889 (3), MA_1 (5), MI_1040 (3), NC_D400 (3), NJ_1040 (2), NY_IT201 (2), OH_IT1040 (2), OR_40 (10), PA_40 (2), US_1040_2025ty (23), US_1040_Sched_1-A (4), US_1040_Sched_C (2), US_1040_Sched_SE (2), VA_760 (2) |
| 3 | 86 | AZ_140 (2), CA_540 (10), Form_2210 (1), Form_2441 (4), Form_6781 (1), Form_8606 (2), Form_8812 (1), Form_8829 (3), Form_8959 (4), Form_8960 (1), Form_8995 (1), Form_CA_5805 (9), HSA_Form_8889 (2), MA_1 (4), MI_1040 (1), NC_D400 (2), NJ_1040 (2), NY_IT201 (5), OH_IT1040 (1), OR_40 (5), PA_40 (1), US_1040_2025ty (15), US_1040_Sched_1-A (5), US_1040_Sched_C (1), US_1040_Sched_SE (1), VA_760 (2) |
| 4 | 55 | AZ_140 (1), CA_540 (3), Form_2441 (1), Form_6781 (1), Form_8606 (3), Form_8812 (1), Form_8829 (3), Form_8959 (2), Form_8960 (2), Form_8995 (1), Form_CA_5805 (6), HSA_Form_8889 (1), MA_1 (2), MI_1040 (1), NC_D400 (1), NJ_1040 (1), NY_IT201 (3), OH_IT1040 (1), OR_40 (2), PA_40 (1), US_1040_2025ty (11), US_1040_Sched_1-A (4), US_1040_Sched_C (1), US_1040_Sched_SE (1), VA_760 (1) |
| 5 | 48 | AZ_140 (1), CA_540 (2), Form_2441 (1), Form_6781 (2), Form_8606 (3), Form_8812 (1), Form_8829 (2), Form_8959 (1), Form_8960 (2), Form_8995 (1), Form_CA_5805 (6), HSA_Form_8889 (1), MA_1 (2), MI_1040 (1), NC_D400 (1), NJ_1040 (1), NY_IT201 (1), OH_IT1040 (2), OR_40 (1), PA_40 (1), US_1040_2025ty (7), US_1040_Sched_1-A (4), US_1040_Sched_C (1), US_1040_Sched_SE (2), VA_760 (1) |
| 6 | 44 | AZ_140 (1), CA_540 (2), Form_2441 (1), Form_8606 (2), Form_8812 (1), Form_8829 (2), Form_8959 (1), Form_8960 (1), Form_CA_5805 (5), MA_1 (3), MI_1040 (1), NC_D400 (1), NJ_1040 (4), NY_IT201 (1), OH_IT1040 (2), OR_40 (1), PA_40 (2), US_1040_2025ty (6), US_1040_Sched_1-A (4), US_1040_Sched_C (1), US_1040_Sched_SE (1), VA_760 (1) |
| 7 | 35 | AZ_140 (1), CA_540 (1), Form_2441 (2), Form_8812 (1), Form_8829 (2), Form_8960 (1), Form_CA_5805 (4), MA_1 (1), MI_1040 (1), NC_D400 (1), NJ_1040 (3), NY_IT201 (1), OH_IT1040 (2), OR_40 (1), PA_40 (2), US_1040_2025ty (3), US_1040_Sched_1-A (5), US_1040_Sched_C (1), US_1040_Sched_SE (1), VA_760 (1) |
Table 4: Distribution of cells by reasoning depth and contributing tax forms (depths 0–7).
| Reasoning Depth | # Cells | Forms Contributing |
|---|---|---|
| 8 | 26 | AZ_140 (1), CA_540 (1), Form_2441 (2), Form_8812 (1), Form_8829 (1), Form_CA_5805 (4), MA_1 (1), MI_1040 (2), NC_D400 (2), NJ_1040 (3), NY_IT201 (1), OH_IT1040 (2), OR_40 (1), US_1040_2025ty (2), US_1040_Sched_1-A (1), VA_760 (1) |
| 9 | 24 | AZ_140 (1), CA_540 (1), Form_2441 (1), Form_8812 (1), Form_8829 (2), Form_CA_5805 (4), MA_1 (1), MI_1040 (1), NC_D400 (1), NJ_1040 (2), NY_IT201 (1), OH_IT1040 (2), OR_40 (1), US_1040_2025ty (2), US_1040_Sched_1-A (1), VA_760 (2) |
| 10 | 19 | AZ_140 (2), CA_540 (1), Form_2441 (1), Form_8812 (1), Form_8829 (1), Form_CA_5805 (4), MA_1 (1), NJ_1040 (1), NY_IT201 (1), OH_IT1040 (1), OR_40 (1), US_1040_2025ty (2), VA_760 (2) |
| 11 | 17 | AZ_140 (1), CA_540 (1), Form_2441 (1), Form_8812 (1), Form_CA_5805 (4), MA_1 (1), NJ_1040 (2), NY_IT201 (1), OH_IT1040 (2), OR_40 (1), US_1040_2025ty (2) |
| 12 | 14 | AZ_140 (2), CA_540 (1), Form_2441 (1), Form_CA_5805 (4), MA_1 (1), NY_IT201 (1), OH_IT1040 (1), OR_40 (1), US_1040_2025ty (2) |
| 13 | 10 | CA_540 (1), Form_2441 (1), Form_CA_5805 (1), MA_1 (2), NY_IT201 (1), OR_40 (2), US_1040_2025ty (2) |
| 14 | 11 | CA_540 (1), Form_2441 (1), Form_CA_5805 (2), MA_1 (1), NY_IT201 (1), OR_40 (2), US_1040_2025ty (3) |
| 15 | 10 | CA_540 (1), Form_CA_5805 (3), MA_1 (1), NY_IT201 (1), OR_40 (1), US_1040_2025ty (3) |
| 16 | 11 | CA_540 (1), Form_CA_5805 (4), NY_IT201 (2), OR_40 (1), US_1040_2025ty (3) |
| 17 | 14 | CA_540 (1), Form_CA_5805 (6), NY_IT201 (3), US_1040_2025ty (4) |
| 18 | 10 | CA_540 (2), Form_CA_5805 (4), NY_IT201 (3), US_1040_2025ty (1) |
| 19 | 6 | CA_540 (1), Form_CA_5805 (3), NY_IT201 (1), US_1040_2025ty (1) |
| 20 | 7 | CA_540 (1), Form_CA_5805 (5), NY_IT201 (1) |
| 21 | 8 | Form_CA_5805 (7), NY_IT201 (1) |
| 22 | 4 | Form_CA_5805 (3), NY_IT201 (1) |
| 23 | 4 | Form_CA_5805 (3), NY_IT201 (1) |
| 24 | 6 | Form_CA_5805 (4), NY_IT201 (2) |
| 25 | 5 | Form_CA_5805 (4), NY_IT201 (1) |
| 26 | 1 | Form_CA_5805 (1) |
| 27 | 1 | Form_CA_5805 (1) |
| 28 | 2 | Form_CA_5805 (2) |
| 29 | 1 | Form_CA_5805 (1) |
| 30 | 1 | Form_CA_5805 (1) |
Table 5: Distribution of cells by reasoning depth and contributing tax forms (depths 8–30).