Introduction
Translating natural language mathematics into formal, machine-verifiable code—a process known as autoformalization—suffers from unreliable evaluation metrics and severe model hallucinations. Theorem provers like Lean 4 can rigorously verify mathematical proofs, but they require math to be written in highly specific formal languages. While Large Language Models (LLMs) show promise in translating standard math into formal code, the field faces two massive hurdles:
- The Evaluation Gap: Automatically checking if an LLM's generated formal code means the same thing as the ground-truth answer is notoriously difficult. String matching and translation metrics (like BLEU) fail because math can be written in many syntactically different but logically equivalent ways. Simply checking if the code compiles ("typechecking") is too weak, as it might compile but state the wrong theorem. Furthermore, LLMs acting as graders are easily tricked by subtle logical differences.
- Agnosia of Context: When LLMs generate formal code, they often hallucinate definitions, functions, or types that do not exist in the formal library. They are essentially trying to write code without access to the API documentation, leading to failures when the code is actually tested in the verifier.
This paper introduces BEq, a neuro-symbolic metric that accurately judges if two formal statements are mathematically equivalent, and RAutoformalizer, a retrieval-augmented approach that grounds models in existing formal libraries. Together, these tools significantly improve both the generation and evaluation of formal math, especially in complex, out-of-distribution scenarios.
Methods
BEq: Bidirectional Extended Definitional Equivalence
To solve the evaluation problem, the authors propose BEq. Instead of relying on surface-level text comparison, BEq acts as a neuro-symbolic metric. It asks an LLM to write a short, restricted proof in Lean showing that Statement A implies Statement B, and vice versa. If the Lean kernel verifies both proofs, the statements are deemed equivalent.
By restricting the "tactics" (proof steps) the LLM is allowed to use, BEq perfectly mimics human intuition about whether two statements are "obviously" the same, treating equivalence as a bounded proof search problem.
RAutoformalizer: Retrieval-Augmented Autoformalization
To solve the hallucination problem, the authors introduce RAutoformalizer. Just as human programmers rely on existing libraries to write software, LLMs need to see the specific formal definitions available in a given environment. Before generating formal code, the system uses a dense retriever to search the formal library for relevant dependencies (theorems, definitions) based on the informal natural language prompt.
To train this system, the authors developed Topological Informalization. They mapped the dependency graph of Lean's massive Mathlib 4 library and used an LLM to translate formal objects back into natural language from the bottom up. This ensures that complex theorems are informalized using the context of their foundational dependencies, yielding much higher quality synthetic training data.
Datasets
The approaches were evaluated across several datasets:
- Mathlib 4: Used to synthesize a massive training dataset of 243,797 formal objects via topological informalization.
- ProofNet: An existing benchmark for undergraduate-level math autoformalization.
- Con-NF (Novel): A new, out-of-distribution (OOD) benchmark created by the authors. Based on a recent Lean 4 library proving the consistency of Quine's New Foundations, it contains 961 informal-formal statement pairs. It tests whether models can handle frontier, research-level math outside of standard Mathlib training data.
- Human Equivalence Benchmark: 200 formal statement pairs manually graded by experts to evaluate the accuracy of the BEq metric itself.
Key Results
- BEq is Highly Reliable: On the human-annotated benchmark, BEq achieved 100% precision (zero false positives) and 90.50% accuracy, vastly outperforming BLEU scores and LLM-as-a-judge baselines (which hovered around 48-82% accuracy).
- RAutoformalizer Boosts Performance: On the standard ProofNet benchmark, RAutoformalizer improved the success rate (BEq@8) from 12.83% to 18.18%.
- Massive Gains on Out-of-Distribution Math: On the highly complex Con-NF benchmark, baseline models completely collapsed. RAutoformalizer improved performance from a dismal 4.58% to 16.86%.
- Huge Oracle Headroom: When the RAutoformalizer was given the perfect ground-truth dependencies (Oracle retrieval), performance on Con-NF skyrocketed to 55.36%, proving that dependency retrieval is the right path forward and that better retrievers will unlock massive gains.
Limitations and Future Work
While highly precise, BEq requires a ground-truth formal statement to compare against, meaning it cannot evaluate novel theorems without a known answer. Furthermore, because it relies on an LLM to find the equivalence proof, it sometimes fails to find complex transformations, resulting in false negatives.
Additionally, the current dense retriever (based on BGE-M3) is relatively basic. The massive gap between the actual results and the "Oracle" results shows that the retriever is the current bottleneck. Future work should focus on advanced retrieval techniques like multi-vector embeddings, re-ranking, and query augmentation to close this gap.
Summary updated