Lean-STaR: Learning to Interleave Thinking and Proving

Haohan Lin, Zhiqing Sun, Sean Welleck, Yiming Yang

TL;DR

Lean-STaR is a new framework that boosts automated theorem proving by training language models to generate natural language "thoughts" before writing formal code. By combining retrospective reasoning (using GPT-4 to explain existing proofs) with self-improvement loops (Expert Iteration), the authors achieved a new state-of-the-art on the miniF2F mathematics benchmark.

What Problem Does This Paper Address?

Formal theorem proving—writing code in languages like Lean that a computer can mathematically verify—is notoriously difficult for AI. Most current approaches treat it as a "next-token prediction" task: given a mathematical state, predict the next "tactic" (a command that advances the proof).

The problem is that formal code is incredibly dense and lacks the "why" behind a move. When humans prove theorems, we don't just output code; we have an informal mental plan or a "chain-of-thought." Because this informal reasoning is missing from formal proof datasets (like Mathlib), models struggle to bridge the gap between a complex mathematical goal and the specific code needed to solve it.

Methods

The authors introduce Lean-STaR, which stands for Lean + Self-Taught any-Reasoner.

Comparison of direct tactic prediction versus Lean-STaR's thought-augmented approach.

The framework operates in three main stages to bridge the gap between formal state and tactic prediction:

  1. Retrospective Rationale Generation: Since we don't have "thoughts" for existing proofs, the authors used GPT-4 to look at human-written Lean proofs and "backfill" the reasoning. For every step in a successful proof, GPT-4 generated a natural language explanation of why that specific tactic was chosen.
  2. Supervised Fine-Tuning (Lean-CoT): They fine-tuned a base model (InternLM2-7B) on these (State, Thought, Tactic) triplets. This created a model capable of interleaving informal "thinking" with formal "proving."
  3. Expert Iteration (The STaR Loop): To further improve, the model was tasked with solving new problems. If the model found a correct proof (verified by the Lean solver), that proof—including the generated thoughts—was added back into the training set for another round of fine-tuning. This allows the model to learn from its own successful "thinking" paths.

Crucially, at inference time, the model generates a thought before the tactic, allowing the informal reasoning to condition and improve the formal prediction.

Datasets

  • Mathlib / LeanDojo: The primary source of human-written formal proofs used for the initial "retrospective" thought generation (approx. 50,000 examples).
  • miniF2F: A standard benchmark consisting of high school competition math problems (AIME, AMC, IMO).
  • ProofNet: Used for additional evaluation of undergraduate-level mathematics.

Key Insights and Ideas

  • The "Oracle" Strategy: The authors found that even the best models (like GPT-4) struggle to prove hard theorems from scratch. However, they are excellent at explaining a proof that has already been written. This "retrospective" approach provided high-quality training data that wouldn't otherwise exist.
  • Robustness to "Thought" Errors: Interestingly, the paper notes that even if the model makes a minor calculation error in its natural language "thought," the proof can still succeed. This is because the "thought" serves as a high-level guide, while the formal Lean solver acts as a rigorous "symbolic" check that prevents the final code from being wrong.
  • Diversity Aids Exploration: Generating thoughts increases the diversity of the model's outputs. In the context of a proof search, this diversity helps the model explore more potential paths, making it more likely to stumble upon the correct solution.

Key Results

Lean-STaR showed significant performance gains across the board:

  • Base Model Improvement: On the miniF2F-test benchmark, the InternLM2-7B base model improved from 28.7% to 36.1% (Pass@64) after applying the Lean-STaR framework.
  • New SOTA: Using a stronger "plus" version of the base model, Lean-STaR achieved 46.3% (Pass@64), outperforming previous specialized systems like COPRA (30.7%) and the standard InternLM2-plus (43.4%).
  • Expert Iteration Works: Each round of self-improvement (Expert Iteration) consistently added 1-2% to the success rate, proving that the model can indeed learn to "think better" by practicing.

Limitations and Future Work

  • Computational Cost: Generating natural language thoughts significantly increases the number of tokens the model must produce, which slows down inference and increases the cost of proof search.
  • Search Algorithms: The authors found that traditional "Best-First Search" (common in theorem proving) doesn't play well with long natural language thoughts. They had to rely on parallel sampling instead. Developing search algorithms that can efficiently navigate both informal and formal spaces is a key next step.
  • Scaling: While 50k examples is a good start, the dataset is still relatively small compared to general-purpose LLM training sets. Scaling the "thought-augmented" data further could yield even better results.

Summary updated

BibTeX
@inproceedings{lin2025lean,
  author = {Haohan Lin and Zhiqing Sun and Sean Welleck and Yiming Yang},
  title = {{Lean-STaR: Learning to Interleave Thinking and Proving}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=SOWZ59UyNc},
}
Figure