Skip to content
DAH

Formalise the policy gradient theorem for finite discounted MDPs in Lean 4

OpenTo verify: Lean proofPosed by Sutton, McAllester, Singh and Mansour (1999); Lean 4 and Mathlib
AI-reviewed
On this page17 sections
Difficulty
18/100Engineering
How far from a resolution. P vs NP = 100
Application value
6/100Theoretical
Realistic practical impact if resolved. P vs NP = 100
Leverage
15/100Isolated
How much other knowledge hinges on it. P vs NP = 100

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.

  1. 1Define a small decision world
  2. 2Show rule value is well defined
  3. 3Compare two rules exactly
  4. 4Prove the gradient formula
  5. 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 P(s′∣s,a)P(s'\mid s,a), rewards r(s,a)r(s,a) and a discount 0≤γ<10\le\gamma<1. A stationary policy gives probabilities π(a∣s)\pi(a\mid s). Its value Vπ(s)V^\pi(s), the expected discounted reward when starting from ss (an expected value is a probability-weighted average), satisfies the Bellman equation Vπ=TπVπ,(TπV)(s)=∑aπ(a∣s)[r(s,a)+γ∑s′P(s′∣s,a) V(s′)].V^\pi=T^\pi V^\pi,\qquad (T^\pi V)(s)=\sum_a\pi(a\mid s)\Big[r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)\,V(s')\Big]. 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.

  1. TπT^\pi is a contraction: applying it to two value vectors brings them closer by a factor γ\gamma 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 VπV^\pi exists and is unique.
  2. 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.
  3. The policy gradient theorem for softmax policies: J(θ)J(\theta) is differentiable and its gradient is ∑sdπ(s)∑aπ(a∣s) Qπ(s,a) ∇log⁡π(a∣s)\sum_s d^{\pi}(s)\sum_a\pi(a\mid s)\,Q^{\pi}(s,a)\,\nabla\log\pi(a\mid s), where dπd^\pi 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 (S,A,P,r,γ)(S,A,P,r,\gamma) with 0≤γ<10\le\gamma<1, (1) the Bellman operator of a stationary policy is a γ\gamma-contraction in the sup norm and has a unique fixed point VπV^\pi; (2) the performance difference lemma; (3) the policy gradient theorem for softmax policies: the map θ↦J(πθ)\theta\mapsto J(\pi_\theta) is differentiable and its gradient equals ∑sdμπθ(s)∑aπθ(a∣s) Qπθ(s,a) ∇θlog⁡πθ(a∣s)\sum_s d^{\pi_\theta}_\mu(s)\sum_a \pi_\theta(a\mid s)\,Q^{\pi_\theta}(s,a)\,\nabla_\theta\log\pi_\theta(a\mid s), where dμπd^{\pi}_\mu is the discounted state-visitation measure.

Words on this page (11)
Words on this page
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)
New to this? Read first

Path to understanding

foundations → problem

The research entries this problem rests on, in the order to read them. Each links to its explainer.

  1. Start with
  2. Step 2
  3. 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 proof

A 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 ∑sdμπθ(s)∑aπθ(a∣s)Qπθ(s,a)∇θlog⁡πθ(a∣s)\sum_s d^{\pi_\theta}_\mu(s)\sum_a \pi_\theta(a\mid s)Q^{\pi_\theta}(s,a)\nabla_\theta\log\pi_\theta(a\mid s), and the contraction and performance-difference lemmas are proved as separate theorems.

Claims

No claimed results on this problem.

Where the work is

Theory
5%
New mathematical or conceptual ideas
Engineering
85%
Building instruments, chips, systems, software, formal proofs
Compute
0%
Raw computation, search, simulation
Empirical
10%
Observation, experiment, data collection

Formalisation effort; the mathematics is classical.

Connected problems

No connected problems.

Progress

  1. Nov 5, 2025
    Q-learning and TD convergence in Lean

    Zhang formalises almost-sure convergence of Q-learning and linear TD (preprint).

    source