NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Autoformalization with Large Language Models

Yuhuai Wu, Albert Qiaochu Jiang, Wenda Li, Markus N. Rabe, Charles Staats, Mateja Jamnik, Christian Szegedy

TL;DR

This paper demonstrates that Large Language Models (LLMs) like Codex and PaLM can automatically translate natural language mathematics into formal, machine-verifiable code (Isabelle/HOL) with surprising accuracy. By using these "autoformalized" problems to train a neural theorem prover, researchers achieved a new state-of-the-art on the MiniF2F benchmark, proving that LLMs can help bridge the gap between human reasoning and formal verification.

What Problem Does This Paper Address?

In the world of mathematics and computer science, "formalization" is the process of translating a proof into a language that a computer can verify with absolute certainty. While this is the gold standard for correctness, it is incredibly tedious and expensive, often requiring years of work by specialized experts.

The "holy grail" of this field is autoformalization: a system that takes a math problem written in plain English (natural language) and automatically turns it into formal code. The primary challenge is that formal math data is incredibly scarce. For instance, the Archive of Formal Proofs is only about 180MB—less than 0.18% of the size of the datasets used to train models like Codex. Furthermore, there is almost no "aligned" data (pairs of English math problems and their exact formal equivalents) available for traditional supervised training.

Methods

The researchers explored whether LLMs could overcome this data scarcity through in-context learning (few-shot prompting). Instead of fine-tuning a model on massive amounts of formal math, they provided the models (Codex and PaLM) with just a few examples of English-to-Isabelle translations and asked them to formalize new problems.

To leverage this capability, the study employed Expert Iteration:

  1. Formalize: Use an LLM to translate thousands of natural language problems from the MATH dataset into Isabelle code.
  2. Prove: Use a neural theorem prover to find proofs for these newly formalized statements.
  3. Train: Fine-tune the theorem prover on the successful proofs it found.
  4. Repeat: This creates a self-improvement loop where the model learns from its own successful formalizations.

Key Insights and Ideas

  • The "Unreasonable" Effectiveness of Transfer: Despite the lack of aligned data, LLMs can transfer their understanding of logic and programming (from languages like Python) to formal math. They don't just copy syntax; they can infer types (e.g., realizing a function should map natural numbers to natural numbers) and handle complex logical structures like proof-by-contradiction.
Example of Codex successfully autoformalizing a natural language math problem into Isabelle/HOL, correctly setting up a proof by contradiction.
  • Scale Matters: The researchers found a clear "scaling law" for autoformalization. While smaller models (like PaLM 8B) struggled, the largest models showed a dramatic jump in their ability to produce correct formalizations.
  • Informalization is Easier: The models are significantly better at "informalization" (translating formal code back into plain English). They achieved a 76% success rate here, compared to ~25% for the reverse. This suggests that back-translation could be a powerful way to generate synthetic training data in the future.
  • The Power of Few-Shot Learning: The models were able to extrapolate from very different types of problems. For example, even if the prompt only contained algebra examples, the model could often formalize number theory or geometry problems correctly.

Key Results

  • Direct Translation: Codex successfully formalized 25.3% of a random sample of 150 competition problems perfectly on the first try.
  • Quantitative Performance: In terms of BLEU scores (a measure of translation quality), Codex outperformed the PaLM models, scoring 57.13 on algebra problems and 43.33 on number theory.
BLEU scores for autoformalization across different model scales and subjects.
  • New State-of-the-Art: By training on autoformalized data, the researchers improved the proof success rate on the MiniF2F benchmark from 29.6% to 35.2%, a significant leap over previous neural theorem provers.

Limitations and Future Work

While promising, the approach has limitations:

  • Alignment Issues: Models still struggle with "definition alignment"—mapping an informal phrase like "the greatest possible value" to the specific formal function Max or Greatest in Isabelle.
  • Context Windows: Current LLMs have a limited "memory" (context window). They cannot yet ingest an entire massive library of formal definitions to understand the context of a complex, advanced mathematical theory.
  • Static vs. Dynamic: The current approach uses a static model. The authors suggest that future work should involve retrieval-augmented models that can "look up" relevant formal definitions in real-time or use continuous training to keep up with evolving mathematical libraries.

Summary updated

BibTeX
@inproceedings{wu2022autoformalization,
  author = {Yuhuai Wu and Albert Qiaochu Jiang and Wenda Li and Markus N. Rabe and Charles Staats and Mateja Jamnik and Christian Szegedy},
  title = {{Autoformalization with Large Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=p7dmmlOH-h7},
}
Figure