Improving semantic equivalence in research-level math formalization

Ayush Khaitan, Liam Fowl, Tomàs Ortega, Alex Kontorovich, Sanjeev AroraarXiv 2026

TL;DR

Formalizing research-level mathematics isn't a simple "Google Translate" job; it requires a mathematician to bridge the gap between intuitive prose and the rigid requirements of code. This paper introduces a dataset of over 4,000 audited "discrepancies" where Lean code intentionally departs from its source text, proving that training AI on these specific human-made adjustments nearly doubles its success rate in writing complex mathematical proofs.

What Problem Does This Paper Address?

When a mathematician sits down to turn a research paper into Lean (a formal proof language), they quickly realize that a word-for-word translation is impossible. To make the math "compile," they must generalize definitions, add "obvious" hypotheses the author skipped, or split one long argument into several smaller lemmas.

Current AI models often fall into the "verbatim trap." They spend millions of tokens trying to translate natural language literally, only to hit a wall when the code doesn't fit the existing library (Mathlib) or fails to account for hidden assumptions. Furthermore, most AI benchmarks focus on "toy" problems—short, isolated competition exercises. In the real world, math happens in massive repositories with tens of thousands of lines of interconnected code. The authors tackle the challenge of autoformalization within these large-scale, research-level projects.

Methods

The researchers took a "learning from the gaps" approach. Instead of just showing a model correct code, they focused on the differences between the paper and the code.

  1. Auditing Discrepancies: They identified 4,076 instances where Lean formalizations deliberately deviated from their natural language sources.
  2. Fine-Tuning: They used a LoRA (Low-Rank Adaptation) adapter to fine-tune a base model, Qwen3.8-27B. This "writer adapter" was trained on pairs consisting of a file's prefix (the context), the informal math passage, and the actual Lean declaration a human wrote to bridge the gap.
  3. Evaluation: They tested the model on its ability to write definitions, theorem statements, and proofs within 27 held-out projects. Crucially, they measured success using "Gold Agreement"—whether the AI's output matched the specific mathematical choices made by the project's human authors, rather than just being a "correct-ish" translation.

Datasets

The study introduces a new benchmark derived from 832 Lean repositories. After rigorous auditing for code quality and formalization accuracy, they narrowed this down to:

  • Training Set: 3,431 tasks from 141 repositories.
  • Test Set: 645 tasks from 27 held-out repositories.

The researchers categorized the discrepancies into 17 distinct types, such as hypothesis_change, representation_change, and proof_detail_expansion.

Table 2: The 17 difference types and how many of the 1,160 records carry each label (a record can carry more than one).

Key Insights and Ideas

  • The "Verbatim Trap" is Real: Models that are great at translating sentences in isolation often fail in large projects because they don't understand the "project-specific" dialect or the necessary generalizations required by the underlying math library.
  • Gold vs. Natural Language (NL) Agreement: A model might write a theorem that perfectly reflects a sentence in a paper (NL Agreement), but if it misses a hypothesis that the rest of the project relies on, it’s useless. "Gold Agreement" is the stricter, more meaningful metric for real-world utility.
  • Hints Aren't Enough: Interestingly, simply telling the model how the code should differ (e.g., "add a hypothesis") didn't help much. The model needed to see the actual examples of the code-text pairs to internalize the "style" of research-level formalization.
  • Small Models, Big Gains: A 27B parameter model with a small amount of targeted, in-project training can become competitive with much larger models like the 120B parameter gpt-oss-120b.

Key Results

The "writer adapter" showed significant improvements across the board, particularly in the most difficult tasks:

  • Proof Completion: The success rate for writing complete, compiling proofs nearly doubled, jumping from 11.2% to 20.4%.
  • Gold Agreement: For theorem statements, the share of AI outputs in "gold agreement" with human-written code rose from 30.4% to 39.2%.
  • Efficiency: While some models (like Goedel-Prover) were better at writing code that simply compiled, the fine-tuned Qwen model was far superior at writing code that was mathematically correct for the specific project context.
Table 1: Results over the full task count (n = 145/250/250 for def/thm/proof; gpt-oss-120b has 119/241/250 because 26 definition and 9 statement generations returned no code; Appendix D gives its rates over the full counts). NL agreement: compiles and is judged to state the paper’s passage correctly. Gold agreement: compiles and is judged the same statement as the project’s own declaration. For proofs the statement is given, so Compiles is the score. Best per column in bold, second best underlined (ties share the mark).

Limitations and Future Work

  • Search and Feedback: The models were tested using "greedy decoding" (one shot, no second guesses). In a real workflow, an agentic system that uses compiler feedback to self-correct would likely perform much better.
  • Dataset Scope: While 4,000 examples is a great start, research-level math is vast. The authors note that the gain grows with more data, suggesting that further scaling of this "discrepancy" dataset could yield even better results.
  • The "Dark Matter" of Math: The study doesn't yet account for how much of the gain comes from the specific choice of discrepancy examples versus just having more in-project Lean data in general. This remains a fertile ground for future investigation.

Summary updated

Abstract

Formalizing mathematics in Lean is never a word-for-word translation of a paper: a Lean formalization changes definitions, strengthens hypotheses, splits arguments, and adds lemmas the paper never mentions. It stands to reason that a model that is good at autoformalization must be a good predictor of how a natural language source must differ from its faithful Lean formalization. With that in mind, we collect 4{,}076 audited examples of such changes from 832 Lean projects that formalize research-level mathematics, and use them to ask a practical question: how well can a model \emph{write} Lean inside a real research-level project that may contain tens of thousands of lines of code, and does training on discrepancies between natural language sources and their faithful Lean formalizations help? Our training set consists of 3{,}431 tasks from 141 repositories, and the test set consists of 645 tasks from the remaining 27 repositories. Training on in-project Lean nearly doubles complete proofs ($11\% \to 20\%$) and raises the share of statements in gold agreement with the project's own formalization by nearly a third ($30\%$ to $39\%$). The gain comes from the pairs themselves: an adapter trained only to predict how the Lean will differ, or a model told the difference in advance, barely helps. Training on where formalizations depart from their sources is thus an effective way of improving semantic equivalence in research-level formalization.
BibTeX
@misc{khaitan2026improving,
  author = {Ayush Khaitan and Liam Fowl and Tomàs Ortega and Alex Kontorovich and Sanjeev Arora},
  title = {{Improving semantic equivalence in research-level math formalization}},
  year = {2026},
  eprint = {2611.28819},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.28819},
}
Figure