Skip to content
DARC
■ Change #181 · wiki.edited

Formalise the policy gradient theorem for finite discounted MDPs in Lean 4: Normalize Markdown to canonical form

by DARC wiki2026-10-22 20:31:22 UTCOpen the page →
explainer.student
**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'\mid s,a)$, rewards $r(s,a)$ and a discount $0\le\gamma<1$. A stationary policy gives probabilities $\pi(a\mid s)$. Its value $V^\pi(s)$, the expected discounted reward when starting from $s$ (an expected value is a probability-weighted average), satisfies the Bellman equation
− $$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].$$
+ $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^\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^\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(\theta)$ is differentiable and its gradient is $\sum_s d^{\pi}(s)\sum_a\pi(a\mid s)\,Q^{\pi}(s,a)\,\nabla\log\pi(a\mid s)$, where $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.
+ **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.
hash 70690988f7a2ce03dd37f7002e5bb46b7d37e2b47c61922e81ae6177c2cb45e2
previous 7937a1c5f8ff1baf497a619c010b82b6dbb05b07f816b8dbd72d9e127b04b945