04. Agents for Formal Mathematics#
Level: Professional · Reading time: 21 min · Exercise: 60 min
In one sentence: After this chapter you can explain why a proof assistant gives an agent a perfect verifier, describe the AlphaProof recipe and where it stopped, and decide when a checker you fully trust is worth its cost.
Why this matters#
Sean Welleck shows a language model solving a math problem. The final answer is right. Intermediate steps contain subtle mistakes (2:00). For a homework hint that is fine. For a proof that other proofs will build on, a person has to check every line, which cancels the gain.
The core idea#
Formal mathematics is mathematics written as source code. The language is a proof assistant, also called an interactive theorem prover; Lean, Coq and Isabelle are examples. A theorem becomes a specification and a proof becomes code. If the code compiles, the proof is correct (2:00). Informal mathematics is everything else: prose, LaTeX, papers.
A tactic is one small proof step, such as applying a known lemma, a smaller theorem already proved. Mathlib is the open-source Lean library of formalized mathematics. Autoformalization translates a statement or a proof from prose into formal code.
For a programmer the analogy is a type checker, except that a proof assistant checks the whole argument. It still says only that the proof matches the formal statement: a proof of a mistranslated statement compiles without complaint.
| Informal | Formal | |
|---|---|---|
| Form | Prose, LaTeX, papers | Source code in Lean |
| Who checks | A person | The proof assistant |
| Guarantee | None | Correct if it compiles |
| Coverage | All of mathematics | What the library supports |
| Cost to write | Low | Every step spelled out |
How it works, step by step#
Why agents benefit#
Thomas Hubert names four properties behind systems that beat experts: scaled-up trial and error, grounded feedback, search, and a curriculum, a graded sequence of problems (32:00). Lean supplies the first two: it is "the environment to explore mathematics completely in silico", that is, on a computer, and it reports what is proved and what remains. Kaiyu Yang adds the other half: current training leans on abundant data and checkable answers, and advanced mathematics has neither, so formal tools must supply the feedback (14:00).
Hubert spells out what a trusted checker changes. Proof checking can be left to the computer, so large proofs can be trusted, and the correctness worries he hears about, mostly from the more abstract fields, go away (12:00). Terence Tao argues for a second effect, massive collaboration: papers mostly have one author or two and five is roughly the ceiling, since every author has to check the rest. With Lean checking, a project can take a lemma from a stranger, as Mathlib does with hundreds of contributors (16:00).
The AlphaProof recipe#
Hubert describes two models, a formaliser and a prover, and four steps (60:00):
- Autoformalize. The formaliser model turns natural-language problems into Lean statements. His team ran about a million problems through it and kept roughly a hundred translations each (64:00).
- Imitate. The prover model, pre-trained on code, trains on Mathlib, about 200,000 theorems, to propose the next tactic for the current proof state, the list of what is known and what remains to be shown. Alone it solves close to 0 percent of IMO-type problems (64:00, 66:00).
- Reinforce. The prover trains by reinforcement learning (RL), trial and error against a reward, inside an AlphaZero-style search: each action is one line of proof and Lean verifies it, so the model climbs from easy problems to IMO difficulty (62:00, 66:00).
- Train at test time. On a problem it cannot yet solve, the system generates easier variants, solves one that is within reach, learns from that proof, and repeats until it reaches the target (68:00, 70:00).
Hubert adds a note on that reward: it need not be dense or point toward a solution. One if the goal is reached, zero otherwise, is enough if there is a goal (22:04). His "zero" philosophy says that an agent which masters a domain from scratch has shown it can discover knowledge by itself, so the method should carry to other domains. The same AlphaZero recipe learned Go from random self-play and, through AlphaTensor, discovered new ways to multiply matrices in an action space of size about 10 to the 30th. With language models he is more pragmatic: start from an existing knowledge base and make sure the algorithm keeps discovering from there (26:00).
Demonstrated, and expected#
- Demonstrated. At the International Mathematical Olympiad (IMO) 2024, AlphaProof fully solved problems 1, 2 and 6, and AlphaGeometry, a separate geometry system, solved problem 4. Problem 3 yielded progress but no partial point, and the system reached silver-medal score, one point below gold, with more time and compute than the human contestants; only 5 of 609 students solved problem 6 in full (56:00). Human experts failed to formalize problem 5 in Lean (52:00).
- Conditions. The run was framed as an Apollo program, an existence proof that the system can solve such problems at all with the compute at hand, when this was thought to be five or ten years away (44:14). Lean experts formalized the problems by hand before the system saw them, since what the team wanted to measure was reasoning, not translation. For problems that ask for all answers, they declined what was known as the easy mode, in which the prover is handed the answer and asked only to prove it: Gemini generates candidate answers, and AlphaProof attempts to prove and to refute each (48:00).
- Why this contest. Each country sends six high-school students, who meet six problems in two sessions, each four and a half hours long, two of each level: easy, medium and hard. The organizers pick problems unlike anything set before, and nobody had leaked the 2024 problems, so in Hubert's view the contest measures reasoning and not recall (42:00). An earlier round asks for an integer between 1 and 1,000, which is simple to grade automatically, but a right number says nothing about the reasoning.
- Expected. Hubert's stated bet is that "perfect verification will, in the long run, be the most important property for mathematics" (38:00). He also wants a method not tuned to the IMO (68:00).
- Not yet. Mathlib covers about 80 percent of undergraduate curricula in his estimate (10:00), has gaps such as geometry, and research mathematics needs new objects and theories (70:00). On his slide, 0.1 to 1 percent of mathematicians use Lean (17:00).
What the practitioners say#
Four lectures, four ways to use the same checker:
| System | Lecturer | Model proposes | Checker | Idea |
|---|---|---|---|---|
| AlphaProof | Hubert | Tactics, after RL | Lean | RL at scale, then RL on one problem |
| ReProver | Yang | Tactics, after retrieving useful lemmas | Lean | Retrieval narrows the search |
| LIPS | Yang | Inequality steps | Symbolic reasoning | Restrict the action space |
| Lean-STaR | Welleck | A thought, then a tactic | Lean | Think in prose before each step |
| Draft-Sketch-Prove | Welleck | An informal proof, then a formal sketch | Automated provers | Separate high-level and low-level work |
| Copra | Chaudhuri | Tactics, with optional informal hints | Lean | No training, all in context |
- Yang on search. Go has a 19 by 19 board, so the legal moves are finite; proving allows countless tactics, which makes it a harder search (26:00). LIPS sorts the steps of an inequality proof into two types: scaling, applying an existing lemma, a finite set that a symbolic algorithm can enumerate; and rewriting the formula, an infinite space left to the language model (28:00, 30:00). On 20 olympiad inequalities o3-mini proved 3, DeepSeek-R1 4, a gold medalist at least 15 and LIPS 16, including one the US team's IMO coach had said could not be solved with AM-GM, a standard inequality (32:00).
- Yang on autoformalization. Statements have no reliable automatic evaluation, and human proofs leave holes, some marked as left to the reader (36:00). His answer is to restrict the domain: "problems intractable in general can be made tractable in a specific domain" (44:00). On LeanEuclid, his benchmark of 48 problems from Book I of Euclid's Elements, the team checks a translated statement by proving that it and the reference statement imply each other, with an SMT solver, a program that decides whether a formula follows from given facts (36:00). Prompted with up to five demonstrations and no training, GPT-4 still translated only just over 20 percent correctly (50:00).
- Yang on diagrammatic gaps. Euclid's first construction takes for granted that its two circles meet. His axioms cannot establish this, and nobody bothers, because the diagram makes it plain, but Lean has no diagram (46:00). A philosopher who now works at CMU had isolated axioms that Euclid never wrote down, and a fact counts as obvious in the diagram exactly when it follows from them. For the proof, Lean points out where the model's version has holes, and the SMT solver tests whether each hole is obvious in that sense (48:00). More demonstrations helped, the model given the diagram did a little better, and extending the approach beyond one domain remains open (50:00).
- Welleck on the gap. Each formal step must be spelled out, which is the gap between how people reason and what Lean accepts (12:00). Lean-STaR trains a model to write a thought before each tactic: because no Lean proof comes with such thoughts, a model first writes them in hindsight for Mathlib steps, then learns from full proofs that Lean accepts or rejects (18:00, 20:00). Tree search struggled to score thoughts, so proofs are sampled in parallel and the successful ones kept for retraining, which reached the state of the art at the time on miniF2F, a benchmark of competition problems stated in Lean (22:00, 24:00). Draft-Sketch-Prove splits the work another way: draft an informal proof, translate it into a formal sketch with gaps, and let automated provers, good at small gaps and lost on whole olympiad problems, close them (30:00, 32:00). For research mathematics, theorems depend on long, cross-file context. On miniF2F extra context makes no difference; on his miniCTX benchmark, built from real Lean projects, it opens a dramatic gap (66:00).
- Welleck on hammers. A hammer integrates an automated theorem prover with the interactive kind. Lean checks proofs but cannot find them; an automated prover searches in some logic and struggles with complex goals (38:00). Handing it every fact in Mathlib, hundreds of thousands, overwhelms it, so premise selection first picks the few that are likely to help. In work not yet published, Welleck's team trains that selector as a retriever, a language model with a contrastive loss over proof states and their positive and negative premises; small choices, such as whether terms are simplified, change how it behaves (42:00). Selector, translation into higher-order logic, automated prover and a step that rebuilds the proof in Lean all sit inside a tree search over tactics, which one command calls (44:00).
- Welleck on the measurements. In a demo the hammer fills, gap by gap, a human sketch from the textbook Mathematics in Lean (46:00). On theorems kept out as a test set, with the hammer run on the first proof step, the system proved little without premise selection, more with an earlier retriever retrained on the same snapshot of the library, and decently with a symbolic selector that a member of the Lean community rebuilt (50:00). The team's own retriever does better still, and taking the union of its premises with the symbolic selector's added a boost (52:00). The result approaches what the system reaches with the premises that the human proof uses, and the retriever itself has just 100 million parameters.
- Welleck on research mathematics. Terence Tao's account of formalizing one of his papers gives the shape of the work: write a blueprint that splits the proof into its definitions and lemmas, arranged in a dependency graph and written in LaTeX, then prove each node in Lean (54:00). The simplest trusted help from AI is one lemma of that blueprint: Lean checks what the model returns. A first obstacle is the accessibility gap: capable methods are often closed, or too costly to run. His tool LLMLean queries any model for the next step, drops the incorrect outputs and shows, in green, the candidates that complete a proof, in blue those that merely run without error. It works with a local model or an API and has completed some lemmas in Tao's project; the bottleneck, he says, is now the model (58:00).
- Chaudhuri on in-context agents. Proof trees are wide and deep, harder than any game solved so far (24:00). Copra, published at COLM 2024, trains nothing: inside a depth-first search a frontier model proposes a tactic for each proof state, as in Figure 1 (26:00, 30:00, 32:00). The absolute numbers are modest, about 29 to 30 percent on miniF2F with 60 queries per attempt, and he calls the Lean feedback essential, because o3-mini hallucinated lemmas (38:00, 46:00). In one demo the agent splits a theorem into three helper lemmas, proves each, and then the whole; given the theorem as one block, it fails (42:00, 44:00). His other theme is abstraction: LaSR evolves equations that fit data and names the concepts behind them in a library, its addition to DeepMind's FunSearch; it beat plain genetic programming, which recombines formulas without concepts, even with models run locally (74:00, 76:00).
- Chaudhuri on systems. Formal verification reaches beyond mathematics: a real system becomes a set of definitions, its properties theorems. He calls such systems almost impossible to hack, citing a US Department of Defense program in which a drone running the formally verified kernel seL4 survived six weeks of attack by a red team (48:00). The method has been too expensive for all but the most safety-critical uses; he expects AI for mathematics to change that balance. His example is a minimal compiler for sums and products, targeting a stack machine. Copra did not manage the correctness theorem in one attempt. A reasoning model proposed an auxiliary lemma instead, that a single compilation step is correct; Copra proved the lemma, then the theorem once that proof was in its prompt (56:00).
- Chaudhuri on reading a discovery. A hint on the kind of equation brought LaSR a modest early benefit (78:00). He confronts the objection that the model merely remembers a famous law such as Coulomb's: all the system sees is numbers, and on equations invented for the test the gains were still substantial (80:00). One result he calls preliminary: asked for a scaling law for language-model loss, LaSR produced a law with one more variable, the number of examples given in the context, which hurts weak models and helps those past a capability threshold (82:00). A person who merged that insight into the earlier hand-fitted law predicted better than either (84:00). His open problems: nothing verifies hypotheses or concepts, concepts exist only as natural language, the search has yet to be shown to hold up in larger search spaces, and only proposing hypotheses is automated (86:00).
Figure 1. The loop behind most rows of the table: the model proposes a tactic, the proof assistant rules.
flowchart TD
S["Proof state: what is known, what remains"] --> M["Model proposes a tactic"]
M --> L["Proof assistant runs the tactic"]
L -->|"invalid"| E["Error message goes back into the prompt"]
E --> M
L -->|"valid, goals remain"| S
L -->|"valid, nothing remains"| D["Proof accepted"]
A wrong step costs one error message, returned to the model at once, so nobody grades each step.
Pitfalls#
- Trusting a compiled proof as trust in the theorem. Fix: review the formal statement; check equivalence with the intended one where a solver can.
- Searching an unrestricted action space. Fix: define the allowed step types and prune with a symbolic tool.
- Reading an olympiad score as research-level ability. Fix: evaluate with long-context benchmarks such as miniCTX.
- Tuning everything to one competition. Fix: hold out problem types, as Hubert says he wants to.
- Expecting coverage. Fix: check that the library supports the area before promising automation.
- Assuming your own domain has a perfect checker. Most software requirements are not formal; the next best thing is a test suite, which checks examples, not all cases.
Try it#
Feel the checker accept and reject.
-- Minimal Lean 4, no library needed. Illustrative; check it in a Lean 4 web editor.
theorem add_flip (a b : Nat) : a + b = b + a := Nat.add_comm a b
theorem wrong (a b : Nat) : a + b = b - a := by rfl -- rejected: not true
- Deliverable: ask a model to translate five one-line statements into Lean. Record for each one: rejected by Lean, accepted but meaning something else, or accepted and right. To judge meaning, have a model restate each accepted statement in plain words and compare it with what you meant.
- Acceptance criteria: you are done when the table has five verdicts with a one-line reason each, and you found at least one statement that compiles yet says the wrong thing, or can explain why none did.
- Stretch: take one accepted proof, change a hypothesis, and see which tactics still succeed.
Key takeaways#
- A proof assistant is a verifier that cannot pass a wrong proof of a formal statement.
- AlphaProof combined autoformalization, imitation of Mathlib, RL and RL at test time; at IMO 2024 it solved three of six problems.
- At the olympiad, experts formalized the problems by hand; the run tested reasoning, not translation.
- The statement itself is the weak point: autoformalization can be wrong and still compile.
- Search is hard because the action space is unbounded; retrieval, restricted step types and sketches all narrow it.
- Competition results do not transfer automatically to research mathematics.
What this means for someone building agents#
- Where a true checker exists, make it the reward and the evaluation, and design the curriculum of problems; see evaluation is the product.
- Separate what language does well, such as plans and sketches, from what symbolic tools do well, such as exact gaps; see tool design and function calling.
- Verify the specification, not only the solution, and when a case is too hard, solve an easier neighbor and carry the lesson back; see testing generative and LLM components.
Self-check#
- A proof compiles in Lean. What exactly is now guaranteed? A. The theorem is true as the author intended it B. The proof is correct for the formal statement C. The statement was translated faithfully D. The proof is the shortest possible one
- Put the four AlphaProof steps in order.
- Why is proof search harder than searching moves in Go, in Yang's argument?
- In Draft-Sketch-Prove, what fills the gaps of the formal sketch?
- What does test-time RL do with a problem that is too hard, in Hubert's account?
Show answers
1. B. Only the proof of the formal statement. The statement itself still needs review. 2. Autoformalization, supervised training on Mathlib, reinforcement learning, then RL at test time on the target problem. 3. Go has finitely many legal moves on its board; proving allows countless tactics and lemmas, so the action space is unbounded. 4. Automated theorem provers, called by tools such as a hammer. 5. It generates easier variants, solves one that is within reach, learns from that proof, and repeats until the original is solved.Sources#
- Lecture: Thomas Hubert, "AlphaProof: when reinforcement learning meets formal mathematics", UC Berkeley Advanced LLM Agents MOOC, Spring 2025 (March 31, 2025): video · guide, used at Lean and Mathlib, four properties, test-time RL
- Lecture: Kaiyu Yang, "Language models for autoformalization and theorem proving", UC Berkeley Advanced LLM Agents MOOC, Spring 2025 (April 7, 2025): video · guide, used at why formal, search, autoformalization
- Lecture: Sean Welleck, "Bridging Informal and Formal Mathematical Reasoning with AI", UC Berkeley Advanced LLM Agents MOOC, Spring 2025 (April 14, 2025): video · guide, used at informal and formal, the gap, miniCTX
- Lecture: Swarat Chaudhuri, "Abstraction and Discovery with Large Language Model Agents", UC Berkeley Advanced LLM Agents MOOC, Spring 2025 (April 21, 2025): video · guide, used at proof search
- Reading: Yang et al., "Formal Mathematical Reasoning: A New Frontier in AI" (2024): arXiv
- Reading: DeepMind, "AI solves IMO problems at silver-medal level" (July 2024): post
Next#
→ 05. What Frontier Domains Teach About Agents, which compares all four domains on environments, verifiers, search, tools and evaluation.