Part 06›
✎

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):

  1. 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).
  2. 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).
  3. 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).
  4. 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#

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

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#

  1. Trusting a compiled proof as trust in the theorem. Fix: review the formal statement; check equivalence with the intended one where a solver can.
  2. Searching an unrestricted action space. Fix: define the allowed step types and prune with a symbolic tool.
  3. Reading an olympiad score as research-level ability. Fix: evaluate with long-context benchmarks such as miniCTX.
  4. Tuning everything to one competition. Fix: hold out problem types, as Hubert says he wants to.
  5. Expecting coverage. Fix: check that the library supports the area before promising automation.
  6. 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

Key takeaways#

What this means for someone building agents#

  1. Where a true checker exists, make it the reward and the evaluation, and design the curriculum of problems; see evaluation is the product.
  2. 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.
  3. 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#

  1. 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
  2. Put the four AlphaProof steps in order.
  3. Why is proof search harder than searching moves in Go, in Yang's argument?
  4. In Draft-Sketch-Prove, what fills the gaps of the formal sketch?
  5. 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#

Next#

→ 05. What Frontier Domains Teach About Agents, which compares all four domains on environments, verifiers, search, tools and evaluation.