Formalise the policy gradient theorem for finite discounted MDPs in Lean 4
On this page17 sections
Difficulty 18: textbook mathematics; the work is building finite-MDP infrastructure (occupancy measures, softmax derivatives) in Mathlib, more than PutnamBench reproduction (8) but far below a kernel-conformance proof (52). Application value 6. Leverage 15: a base for later formal RL theory.
The problem
Have a computer proof checker verify the basic formula behind policy-gradient learning.
- 1Define a small decision world
- 2Show rule value is well defined
- 3Compare two rules exactly
- 4Prove the gradient formula
- 5Machine checks every step
Why it matters. RL theory papers contain long calculations, and errors in published proofs do occur. A proof assistant such as Lean checks every step of a proof mechanically, and Mathlib is its large shared library of formalised mathematics. Formalising the basic theorems of RL would give a checked foundation on which later results, such as convergence of PPO-style methods, can be built and machine-verified, and a test set for AI theorem provers.
The objects. A finite discounted MDP has finitely many states and actions, transition probabilities , rewards and a discount . A stationary policy gives probabilities . Its value , the expected discounted reward when starting from (an expected value is a probability-weighted average), satisfies the Bellman equation In words: the value of a state is the expected immediate reward plus the discounted value of wherever you land next.
The three statements to formalise.
- is a contraction: applying it to two value vectors brings them closer by a factor in the largest-entry (sup) distance. By the Banach fixed-point theorem a contraction has exactly one fixed point, and repeated application converges to it, so exists and is unique.
- The performance difference lemma: the value gap between two policies equals a weighted sum of one policy's advantages, weighted by how often the other policy visits each state.
- The policy gradient theorem for softmax policies: is differentiable and its gradient is , where is the discounted state-visitation measure, how often (with discounting) each state is visited.
What exists. Mathlib has the Banach fixed-point theorem (ContractingWith.fixedPoint), so step 1 reduces to proving the contraction inequality. Zhang's rl-theory-in-lean, published in the Reinforcement Learning Journal, formalises almost-sure convergence of Q-learning and linear TD learning in Lean 4. No Lean 4 formalisation of the performance difference lemma or of the policy gradient theorem is known, and Mathlib has no library for MDPs, policy values or occupancy measures.
Why it is laborious rather than deep. The mathematics is textbook, but differentiating softmax inside nested finite sums, handling the infinite discounted sum and choosing definitions that later results can reuse all take real formalisation effort.
The target. A Lean 4 development that compiles against a stated Mathlib version with no sorry (a placeholder for a missing proof) and only the standard axioms (propext, Classical.choice, Quot.sound), proving all three statements. The statement skeleton given with the problem is a sketch that has not been type-checked.
Go deeper
The full technical text.
State and prove in Lean 4 with Mathlib, for a finite discounted MDP with , (1) the Bellman operator of a stationary policy is a -contraction in the sup norm and has a unique fixed point ; (2) the performance difference lemma; (3) the policy gradient theorem for softmax policies: the map is differentiable and its gradient equals , where is the discounted state-visitation measure.
Words on this page (11)
- reinforcement learning
- Learning by trial and error: an agent acts, gets rewards, and adjusts to collect more reward.
- Lean
- A programming language and proof assistant in which mathematical proofs are checked by computer.
- Mathlib
- The large community library of formalised mathematics for Lean.
- fixed point
- A value that a function maps to itself.
- contraction mapping
- A function that always brings any two points closer together by a fixed factor below 1.
- policy gradient theorem
- The formula giving the slope of expected reward with respect to a policy's parameters.
- MDP
- Markov decision process: the standard model of acting in a changing world with rewards.
- Bellman equation
- The recursive equation saying a state's value equals the expected immediate reward plus the discounted value of the next state.
- proof assistant
- Software that checks every step of a mathematical proof written in a formal language.
- expected value
- The probability-weighted average of all possible outcomes.
- differentiable
- Having a well-defined derivative (here, a gradient) at every point considered.
New to this? Read first (3)
- Towards Formalizing Reinforcement Learning Theory (arXiv preprint)Existing Lean work on RL convergence.
- Lean: Theorem Proving in Lean 4How Lean proofs work.
- Spinning Up: policy optimizationA derivation of the formula on paper.
Path to understanding
foundations → problemThe research entries this problem rests on, in the order to read them. Each links to its explainer.
- Start with
- Step 2
- Policy gradient methods and PPOAlgorithm · host
- Then
- Formalise the policy gradient theorem for finite discounted MDPs in Lean 4The problem
State of the art
Mathlib has the Banach fixed-point theorem for contracting maps (Mathlib/Topology/MetricSpace/Contracting.lean, ContractingWith.fixedPoint), so step (1) reduces to showing the Bellman operator contracts. Zhang's rl-theory-in-lean project (arXiv 2511.03618, RL Journal 2026) formalises almost-sure convergence of Q-learning and linear TD with the Robbins-Siegmund theorem in Lean 4 on Mathlib. Bellman optimality for finite MDPs has been formalised in other provers (Isabelle/AFP, Coq), and Zhang's paper describes earlier Lean work as dynamic programming rather than RL. No public Lean 4 formalisation of the performance difference lemma or of the policy gradient theorem was found in Mathlib, in rl-theory-in-lean or by a search on 2026-10-17; anyone starting should check the Lean Zulip first.
Realistic applications
A verified base for later formal proofs of convergence of policy optimisation (natural policy gradient, PPO-style updates), and a test bed for AI theorem provers on RL theory.
What counts as solved
A Lean 4 development, compiled against a stated Mathlib version with no sorry and no new axioms, proving all three statements, accepted into a public repository or Mathlib-style library.
How it gets verified
To verify: Lean proofA formal proof checked by Lean 4 / Mathlib.
Route: Lean 4 + Mathlib, checked by lake build against a stated Mathlib commit with zero sorry and #print axioms showing only propext, Classical.choice and Quot.sound. Mathlib has the fixed-point theorem (ContractingWith.fixedPoint in Mathlib/Topology/MetricSpace/Contracting.lean) but no MDP, policy-value or occupancy-measure library; rl-theory-in-lean provides stochastic-approximation tools but not this theorem. Sketch only, not type-checked (the formaliser fixes the final form):
structure FiniteMDP (S A : Type) [Fintype S] [Fintype A] where
P : S → A → S → ℝ -- transition probabilities, nonneg, rows sum to 1
r : S → A → ℝ
γ : ℝ
hγ : 0 ≤ γ ∧ γ < 1
-- softmax policy, value V^π as the fixed point of the Bellman operator, J θ = Σ_s μ s * V^{π_θ} s
theorem policy_gradient (M : FiniteMDP S A) (μ : S → ℝ) (θ : S → A → ℝ) :
HasFDerivAt (fun θ => J M μ θ) (pgGradient M μ θ) θ := by
sorry
where pgGradient is the occupancy-weighted sum , and the contraction and performance-difference lemmas are proved as separate theorems.
Claims
No claimed results on this problem.
Where the work is
Formalisation effort; the mathematics is classical.
Connected problems
No connected problems.
Progress
- Nov 5, 2025Q-learning and TD convergence in Leansource
Zhang formalises almost-sure convergence of Q-learning and linear TD (preprint).