Lean and Formal Verification as Reward Signal for Math RL
Lean and Formal Verification as Reward Signal for Math RL
Mathematical reasoning is one of the clearest frontiers in post-training. Models can manipulate symbols fluently. They fail at proof. The gap is not linguistic; it is logical. Lean and formal verification as reward signal for math RL offers a precise, non-gameable answer to that gap: replace human judgment with a proof checker that returns a binary, mechanically verifiable verdict. This post explains how that pipeline works, where it breaks down, and what it demands from task authors and verifier designers.
Answer Capsule
Lean and formal verification as reward signal for math RL means using a proof assistant (most commonly Lean 4) as the reward oracle during reinforcement learning. The model generates a formal proof; Lean compiles it; the reward is 1 if the proof type-checks and 0 if it does not. This produces a dense, unambiguous, contamination-resistant training signal for mathematical reasoning, without requiring human annotators to judge correctness.
What Is the Reward Signal in Formal Verification RL?
The reward signal is the compiler output of a proof assistant. Lean 4, Isabelle, Coq, and Metamath all implement dependent type systems or formal logic frameworks in which a proof is a term that must satisfy a type. Compilation either succeeds or fails. There is no partial output to misinterpret and no LLM-as-judge scoring a rubric.
In a standard training loop, the model receives a theorem statement in Lean syntax, generates a tactic proof, and submits it to the Lean elaborator. The elaborator checks every inference step against the kernel. If the proof is complete and type-correct, the reward function returns 1. If any step is invalid, the reward is 0. The signal is binary, deterministic, and grounded in formal semantics rather than in human preference.
This is the defining property that separates formal verification from rubric-based or LLM-as-judge reward. A rubric can be gamed; a proof kernel cannot. A model that learns to satisfy a Lean verifier has, by construction, produced a valid proof.
For a deeper look at how verifier design choices affect reward quality across domains, see the discussion of verifiable rewards and tasks that resist automatic grading.
How the Training Pipeline Is Structured
A formal verification RL pipeline for math has four components: a theorem corpus, a sampling policy, a Lean server, and a reward aggregator. Each component introduces distinct failure modes.
Theorem corpus. A set of formal theorem statements in Lean 4 syntax, ranging from undergraduate algebra to research-level number theory. The corpus determines the difficulty distribution the model trains on. Sourcing matters: theorems scraped from Mathlib (the Lean 4 mathematics library) carry contamination risk for models trained on GitHub-derived data.
Sampling policy. At each training step, the model generates k candidate proofs per theorem. Pass@k estimates the probability that at least one of k samples is correct. During training, the reward is typically computed over a sampled subset rather than exhaustively, to manage compute cost.
Lean server. A persistent process running the Lean elaborator, accepting proof strings over a socket or subprocess interface. Latency is the dominant engineering constraint. Proof checking for non-trivial theorems can take seconds; batching and parallelism are required at scale.
Reward aggregator. Maps the binary elaborator output to a scalar reward, optionally with step-level shaping. A pure 0/1 signal is sparse; many training runs add intermediate rewards for partial proof states (tactics that reduce the goal without completing it). The design of intermediate rewards is where reward hacking risk concentrates.
The reward signal density question, specifically how to balance sparse terminal rewards against denser intermediate signals, is examined in detail in the post on reward signal density across sparse, dense, and staged settings.
Difficulty Calibration: Which Theorems Should Be in the Training Set?
Difficulty calibration is empirical, not intuitive. A theorem that looks elementary can be formally complex because Lean requires every definitional step to be explicit. A theorem that looks hard can be trivially dispatched by a simp or decide tactic call.
The operational calibration method is pass@k measurement against a fixed model family at a fixed date. A theorem where pass@1 exceeds 0.9 for a frontier model provides no training signal; the model already solves it. A theorem where pass@1 is below 0.01 for all models in the training compute budget provides no gradient signal either; the model never succeeds, so the reward is always 0 and no learning occurs.
The productive range is typically pass@k between 0.05 and 0.6 for the model being trained, measured at k=16 or k=32. This range keeps the reward non-zero often enough to provide a learning signal while still requiring genuine capability improvement. For a rigorous treatment of when sub-10% pass rates are useful signal versus noise, see sub-10% pass rate benchmarks.
Difficulty drifts. A theorem calibrated as hard against one model generation may become easy for the next. Corpora require re-calibration as base models improve. This is not a theoretical concern; it is an operational reality that any team running a formal math RL program will encounter within months.
Worked Example: A Lean 4 Reward Loop
Illustrative example. Numbers and proof content are constructed to demonstrate the pipeline; they are not results from a specific published training run.
Consider training on a theorem stating that for any natural numbers a and b, a + b = b + a (commutativity of addition over the naturals). In Lean 4 syntax:
theorem add_comm_nat (a b : Nat) : a + b = b + a := by induction a with | zero => simp | succ n ih => simp [Nat.succ_add, ih]
The model generates this tactic proof. The Lean elaborator checks that simp closes the base case and that Nat.succ_add combined with the induction hypothesis closes the inductive step. If both goals are discharged, the elaborator returns success. Reward = 1.
Now consider a harder theorem: that the sum of the first n natural numbers equals n(n+1)/2. A model that writes by decide will fail because the statement is universally quantified over an infinite domain. The model must produce a genuine inductive proof. Pass@16 for a mid-tier frontier model on this class of theorem might be approximately 0.3 (illustrative). That is a productive training point: the model sometimes succeeds, receives reward, and can improve.
The reward aggregator records the binary outcome per sample, computes a group-relative policy gradient (as in the GRPO formulation described in the DeepSeek-R1 technical report), and updates the policy. No human annotator is involved in the reward computation.
Common Failure Modes
Six failure modes recur in formal verification RL pipelines. Each has a detection method and a fix.
Tactic overfitting to Mathlib lemma names. Models learn to invoke specific named lemmas that close goals without understanding the underlying argument. Detection: evaluate on theorems that require no named imports, only primitive tactics. Fix: include a proportion of theorems solvable only with
induction,cases, andrfl.Proof by
native_decideordecideon bounded instances. The model learns that decision procedures close many goals without constructing a proof. Detection: audit the tactic distribution; flag proofs wheredecideappears as the sole or primary tactic. Fix: filter theorems wheredecideis a valid closing tactic, or penalize its use explicitly.Lean server timeout masking failures. Long-running elaboration times out; the pipeline treats timeout as failure (reward = 0). If timeouts are common on hard theorems, the model learns to avoid hard theorems rather than solve them. Detection: log timeout rates per difficulty bucket. Fix: set per-theorem time budgets calibrated to observed elaboration time on correct proofs, not a single global timeout.
Corpus contamination from Mathlib. Theorems drawn from Mathlib are present in the pretraining data of most frontier models. A model may recall the proof rather than derive it. Detection: measure pass@1 on Mathlib theorems versus pass@1 on original theorems authored independently; a large gap indicates recall. Fix: use original theorem statements with novel variable names, domains, or formulations not present in public repositories.
Reward hacking via sorry. Lean accepts
sorryas a proof placeholder that type-checks without verifying the goal. A naive reward function that checks only for elaboration success without checking forsorry-free proofs will be immediately exploited. Detection: trivial; grep forsorryin generated proofs. Fix: add a pre-check that rejects any proof containingsorrybefore submitting to the elaborator.Difficulty distribution collapse. As training progresses, easy theorems saturate (pass@1 approaches 1) and the effective training signal concentrates on a shrinking hard tail. Detection: track pass@1 distribution across the corpus at regular intervals. Fix: implement curriculum scheduling that removes saturated theorems and introduces harder ones dynamically.
The sorry failure mode is a specific instance of the broader reward hacking problem in verifiable settings. The post on partial credit verifiers and reward shaping without gaming addresses the design principles that prevent this class of exploit.
Where This Approach Breaks Down
Formal verification RL is powerful within a narrow scope. It breaks down in four situations.
First, it requires theorems to be formally stated in a proof assistant language. Most mathematical knowledge is not yet formalized. Research-level results in areas such as combinatorics, probability theory, or applied analysis have sparse Mathlib coverage. The approach is limited to domains where formalization exists or can be authored.
Second, the binary reward signal provides no guidance on proof strategy. A model that fails receives no information about which tactic was wrong or how far it progressed. Process reward models trained on step-level labels can supplement this, but they require expert annotation of intermediate proof states, which is expensive and requires annotators who can read Lean. The comparison between automated step verification and expert step labels is examined in the post on automated versus expert step verification.
Third, Lean elaboration latency limits throughput. At scale, the Lean server becomes the bottleneck. Parallelism helps, but the compute cost per training step is substantially higher than for domains with fast programmatic verifiers (such as unit-tested code).
Fourth, performance on Lean proof tasks does not transfer automatically to informal mathematical reasoning. A model trained to generate Lean tactics may not improve on natural-language proof writing or on applied problem-solving that requires mathematical judgment without formal structure.
Frequently Asked Questions
What proof assistants other than Lean 4 are used for math RL?
Isabelle and Coq have been used in published work, including the miniF2F benchmark which spans Lean, Isabelle, and Metamath. Lean 4 has become the most common choice in recent post-training work because Mathlib 4 provides the largest formal mathematics library and the elaborator has an accessible API. Results are not portable across proof assistants; a model trained on Lean tactics does not generalize to Isabelle proof scripts.
How is pass@k computed in a formal math RL setting?
Pass@k estimates the probability that at least one of k independently sampled proofs for a given theorem is accepted by the verifier. The unbiased estimator from the Codex paper (Chen et al., 2021) computes this from n total samples where n is greater than or equal to k, avoiding the variance of directly sampling exactly k proofs. In practice, k=4, k=16, and k=32 are common evaluation points for math RL, with k=1 reserved for reporting deployment-realistic performance.
Can synthetic theorem generation replace human-authored theorems?
Synthetic generation (using a model to propose new theorems, then filtering for those with known proofs) can scale corpus size but introduces distributional bias toward theorem types the generating model finds natural. Contamination risk is also higher because generated theorems may closely paraphrase existing Mathlib content. Human-authored theorems with novel structure provide a contamination-resistant upper bound on difficulty, particularly for evaluating capability on genuinely unseen problem classes.
What does the training signal look like when the model is near the capability ceiling?
As pass@k approaches 1 across the training corpus, the gradient signal collapses. The model receives reward on almost every sample, so the policy update is near zero. This is the saturation signal that the corpus needs to be refreshed with harder theorems. Monitoring the variance of rewards across a training batch is a practical early-warning indicator: low variance means the corpus is too easy.
Is formal verification RL applicable outside pure mathematics?
The same principle applies wherever a formal verifier exists: hardware description language simulation, type-checked program synthesis, and constraint-satisfaction problems with algebraic verifiers. The key requirement is a deterministic oracle that accepts or rejects a candidate answer without human judgment. For engineering domains with simulation-backed oracles, the analogous approach is described in the post on simulator-backed verification and physics reward oracles. The mathematical proof assistant is one instance of a broader class of formal verifiers.
What This Means in Practice
Lean and formal verification as reward signal for math RL is the most rigorous approach available for training mathematical reasoning. The reward is unambiguous, the verifier cannot be gamed without being caught, and the signal scales with corpus difficulty. The operational constraints are real: formalization coverage is incomplete, elaboration latency is high, and difficulty calibration requires continuous re-measurement as models improve. Teams that treat theorem corpus design as a first-class engineering problem, not an afterthought, will extract the most from this approach. The verifier is only as useful as the tasks it is asked to verify.
Chiron Data Labs builds expert-authored, empirically calibrated tasks for domains where frontier models still fail. If you are designing formal verification RL environments or need contamination-resistant math tasks, get in touch with Chiron Data Labs.
Have questions or want personalised guidance? Contact us and we'll be happy to help.
Mathematical reasoning is one of the clearest frontiers in post-training. Models can manipulate symbols fluently. They fail at proof. The gap is not linguistic; it is logical. Lean and formal verification as reward signal for math RL offers a precise, non-gameable answer to that gap: replace human judgment with a proof checker that returns a binary, mechanically verifiable verdict. This post explains how that pipeline works, where it breaks down, and what it demands from task authors and verifier designers.
Answer Capsule
Lean and formal verification as reward signal for math RL means using a proof assistant (most commonly Lean 4) as the reward oracle during reinforcement learning. The model generates a formal proof; Lean compiles it; the reward is 1 if the proof type-checks and 0 if it does not. This produces a dense, unambiguous, contamination-resistant training signal for mathematical reasoning, without requiring human annotators to judge correctness.
What Is the Reward Signal in Formal Verification RL?
The reward signal is the compiler output of a proof assistant. Lean 4, Isabelle, Coq, and Metamath all implement dependent type systems or formal logic frameworks in which a proof is a term that must satisfy a type. Compilation either succeeds or fails. There is no partial output to misinterpret and no LLM-as-judge scoring a rubric.
In a standard training loop, the model receives a theorem statement in Lean syntax, generates a tactic proof, and submits it to the Lean elaborator. The elaborator checks every inference step against the kernel. If the proof is complete and type-correct, the reward function returns 1. If any step is invalid, the reward is 0. The signal is binary, deterministic, and grounded in formal semantics rather than in human preference.
This is the defining property that separates formal verification from rubric-based or LLM-as-judge reward. A rubric can be gamed; a proof kernel cannot. A model that learns to satisfy a Lean verifier has, by construction, produced a valid proof.
For a deeper look at how verifier design choices affect reward quality across domains, see the discussion of verifiable rewards and tasks that resist automatic grading.
How the Training Pipeline Is Structured
A formal verification RL pipeline for math has four components: a theorem corpus, a sampling policy, a Lean server, and a reward aggregator. Each component introduces distinct failure modes.
Theorem corpus. A set of formal theorem statements in Lean 4 syntax, ranging from undergraduate algebra to research-level number theory. The corpus determines the difficulty distribution the model trains on. Sourcing matters: theorems scraped from Mathlib (the Lean 4 mathematics library) carry contamination risk for models trained on GitHub-derived data.
Sampling policy. At each training step, the model generates k candidate proofs per theorem. Pass@k estimates the probability that at least one of k samples is correct. During training, the reward is typically computed over a sampled subset rather than exhaustively, to manage compute cost.
Lean server. A persistent process running the Lean elaborator, accepting proof strings over a socket or subprocess interface. Latency is the dominant engineering constraint. Proof checking for non-trivial theorems can take seconds; batching and parallelism are required at scale.
Reward aggregator. Maps the binary elaborator output to a scalar reward, optionally with step-level shaping. A pure 0/1 signal is sparse; many training runs add intermediate rewards for partial proof states (tactics that reduce the goal without completing it). The design of intermediate rewards is where reward hacking risk concentrates.
The reward signal density question, specifically how to balance sparse terminal rewards against denser intermediate signals, is examined in detail in the post on reward signal density across sparse, dense, and staged settings.
Difficulty Calibration: Which Theorems Should Be in the Training Set?
Difficulty calibration is empirical, not intuitive. A theorem that looks elementary can be formally complex because Lean requires every definitional step to be explicit. A theorem that looks hard can be trivially dispatched by a simp or decide tactic call.
The operational calibration method is pass@k measurement against a fixed model family at a fixed date. A theorem where pass@1 exceeds 0.9 for a frontier model provides no training signal; the model already solves it. A theorem where pass@1 is below 0.01 for all models in the training compute budget provides no gradient signal either; the model never succeeds, so the reward is always 0 and no learning occurs.
The productive range is typically pass@k between 0.05 and 0.6 for the model being trained, measured at k=16 or k=32. This range keeps the reward non-zero often enough to provide a learning signal while still requiring genuine capability improvement. For a rigorous treatment of when sub-10% pass rates are useful signal versus noise, see sub-10% pass rate benchmarks.
Difficulty drifts. A theorem calibrated as hard against one model generation may become easy for the next. Corpora require re-calibration as base models improve. This is not a theoretical concern; it is an operational reality that any team running a formal math RL program will encounter within months.
Worked Example: A Lean 4 Reward Loop
Illustrative example. Numbers and proof content are constructed to demonstrate the pipeline; they are not results from a specific published training run.
Consider training on a theorem stating that for any natural numbers a and b, a + b = b + a (commutativity of addition over the naturals). In Lean 4 syntax:
theorem add_comm_nat (a b : Nat) : a + b = b + a := by induction a with | zero => simp | succ n ih => simp [Nat.succ_add, ih]
The model generates this tactic proof. The Lean elaborator checks that simp closes the base case and that Nat.succ_add combined with the induction hypothesis closes the inductive step. If both goals are discharged, the elaborator returns success. Reward = 1.
Now consider a harder theorem: that the sum of the first n natural numbers equals n(n+1)/2. A model that writes by decide will fail because the statement is universally quantified over an infinite domain. The model must produce a genuine inductive proof. Pass@16 for a mid-tier frontier model on this class of theorem might be approximately 0.3 (illustrative). That is a productive training point: the model sometimes succeeds, receives reward, and can improve.
The reward aggregator records the binary outcome per sample, computes a group-relative policy gradient (as in the GRPO formulation described in the DeepSeek-R1 technical report), and updates the policy. No human annotator is involved in the reward computation.
Common Failure Modes
Six failure modes recur in formal verification RL pipelines. Each has a detection method and a fix.
Tactic overfitting to Mathlib lemma names. Models learn to invoke specific named lemmas that close goals without understanding the underlying argument. Detection: evaluate on theorems that require no named imports, only primitive tactics. Fix: include a proportion of theorems solvable only with
induction,cases, andrfl.Proof by
native_decideordecideon bounded instances. The model learns that decision procedures close many goals without constructing a proof. Detection: audit the tactic distribution; flag proofs wheredecideappears as the sole or primary tactic. Fix: filter theorems wheredecideis a valid closing tactic, or penalize its use explicitly.Lean server timeout masking failures. Long-running elaboration times out; the pipeline treats timeout as failure (reward = 0). If timeouts are common on hard theorems, the model learns to avoid hard theorems rather than solve them. Detection: log timeout rates per difficulty bucket. Fix: set per-theorem time budgets calibrated to observed elaboration time on correct proofs, not a single global timeout.
Corpus contamination from Mathlib. Theorems drawn from Mathlib are present in the pretraining data of most frontier models. A model may recall the proof rather than derive it. Detection: measure pass@1 on Mathlib theorems versus pass@1 on original theorems authored independently; a large gap indicates recall. Fix: use original theorem statements with novel variable names, domains, or formulations not present in public repositories.
Reward hacking via sorry. Lean accepts
sorryas a proof placeholder that type-checks without verifying the goal. A naive reward function that checks only for elaboration success without checking forsorry-free proofs will be immediately exploited. Detection: trivial; grep forsorryin generated proofs. Fix: add a pre-check that rejects any proof containingsorrybefore submitting to the elaborator.Difficulty distribution collapse. As training progresses, easy theorems saturate (pass@1 approaches 1) and the effective training signal concentrates on a shrinking hard tail. Detection: track pass@1 distribution across the corpus at regular intervals. Fix: implement curriculum scheduling that removes saturated theorems and introduces harder ones dynamically.
The sorry failure mode is a specific instance of the broader reward hacking problem in verifiable settings. The post on partial credit verifiers and reward shaping without gaming addresses the design principles that prevent this class of exploit.
Where This Approach Breaks Down
Formal verification RL is powerful within a narrow scope. It breaks down in four situations.
First, it requires theorems to be formally stated in a proof assistant language. Most mathematical knowledge is not yet formalized. Research-level results in areas such as combinatorics, probability theory, or applied analysis have sparse Mathlib coverage. The approach is limited to domains where formalization exists or can be authored.
Second, the binary reward signal provides no guidance on proof strategy. A model that fails receives no information about which tactic was wrong or how far it progressed. Process reward models trained on step-level labels can supplement this, but they require expert annotation of intermediate proof states, which is expensive and requires annotators who can read Lean. The comparison between automated step verification and expert step labels is examined in the post on automated versus expert step verification.
Third, Lean elaboration latency limits throughput. At scale, the Lean server becomes the bottleneck. Parallelism helps, but the compute cost per training step is substantially higher than for domains with fast programmatic verifiers (such as unit-tested code).
Fourth, performance on Lean proof tasks does not transfer automatically to informal mathematical reasoning. A model trained to generate Lean tactics may not improve on natural-language proof writing or on applied problem-solving that requires mathematical judgment without formal structure.
Frequently Asked Questions
What proof assistants other than Lean 4 are used for math RL?
Isabelle and Coq have been used in published work, including the miniF2F benchmark which spans Lean, Isabelle, and Metamath. Lean 4 has become the most common choice in recent post-training work because Mathlib 4 provides the largest formal mathematics library and the elaborator has an accessible API. Results are not portable across proof assistants; a model trained on Lean tactics does not generalize to Isabelle proof scripts.
How is pass@k computed in a formal math RL setting?
Pass@k estimates the probability that at least one of k independently sampled proofs for a given theorem is accepted by the verifier. The unbiased estimator from the Codex paper (Chen et al., 2021) computes this from n total samples where n is greater than or equal to k, avoiding the variance of directly sampling exactly k proofs. In practice, k=4, k=16, and k=32 are common evaluation points for math RL, with k=1 reserved for reporting deployment-realistic performance.
Can synthetic theorem generation replace human-authored theorems?
Synthetic generation (using a model to propose new theorems, then filtering for those with known proofs) can scale corpus size but introduces distributional bias toward theorem types the generating model finds natural. Contamination risk is also higher because generated theorems may closely paraphrase existing Mathlib content. Human-authored theorems with novel structure provide a contamination-resistant upper bound on difficulty, particularly for evaluating capability on genuinely unseen problem classes.
What does the training signal look like when the model is near the capability ceiling?
As pass@k approaches 1 across the training corpus, the gradient signal collapses. The model receives reward on almost every sample, so the policy update is near zero. This is the saturation signal that the corpus needs to be refreshed with harder theorems. Monitoring the variance of rewards across a training batch is a practical early-warning indicator: low variance means the corpus is too easy.
Is formal verification RL applicable outside pure mathematics?
The same principle applies wherever a formal verifier exists: hardware description language simulation, type-checked program synthesis, and constraint-satisfaction problems with algebraic verifiers. The key requirement is a deterministic oracle that accepts or rejects a candidate answer without human judgment. For engineering domains with simulation-backed oracles, the analogous approach is described in the post on simulator-backed verification and physics reward oracles. The mathematical proof assistant is one instance of a broader class of formal verifiers.
What This Means in Practice
Lean and formal verification as reward signal for math RL is the most rigorous approach available for training mathematical reasoning. The reward is unambiguous, the verifier cannot be gamed without being caught, and the signal scales with corpus difficulty. The operational constraints are real: formalization coverage is incomplete, elaboration latency is high, and difficulty calibration requires continuous re-measurement as models improve. Teams that treat theorem corpus design as a first-class engineering problem, not an afterthought, will extract the most from this approach. The verifier is only as useful as the tasks it is asked to verify.
Chiron Data Labs builds expert-authored, empirically calibrated tasks for domains where frontier models still fail. If you are designing formal verification RL environments or need contamination-resistant math tasks, get in touch with Chiron Data Labs.
Have questions or want personalised guidance? Contact us and we'll be happy to help.