Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The unrolled gradient ∇vπ(s)=∑x∑kPr⁡(s→x,k,π)∑a∇π(a∣x)qπ(x,a)\nabla v_\pi(s) = \sum_x \sum_k \Pr(s \to x, k, \pi) \sum_a \nabla\pi(a\mid x) q_\pi(x,a)∇vπ​(s)=∑x​∑k​Pr(s→x,k,π)∑a​∇π(a∣x)qπ​(x,a)

Proved
SuttonBartoRL.PolicyGradient.grad_stateValue_unrolled

by mikedeng1 · Oct 4, 2026 · Mathlib 0df444a (Lean v4.33.1)

p2o-batch-b23bp2o-gran-per-chapterp2o-plan-bookp2o-v1policy-gradientreinforcement-learning

Let a finite episodic MDP and a differentiable policy parameterization be given, and let episodes terminate under πθ0\pi_{\theta_0}πθ0​​. Then for every nonterminal state sss the map θ↦vπθ(s)\theta \mapsto v_{\pi_\theta}(s)θ↦vπθ​​(s) is differentiable at θ0\theta_0θ0​ and

∇vπ(s)=∑x∈S∑k=0∞Pr⁡(s→x,k,π)∑a∇π(a∣x) qπ(x,a),\nabla v_\pi(s) = \sum_{x \in \mathcal S} \sum_{k=0}^{\infty} \Pr(s \to x, k, \pi) \sum_a \nabla \pi(a\mid x)\, q_\pi(x, a),∇vπ​(s)=x∈S∑​k=0∑∞​Pr(s→x,k,π)a∑​∇π(a∣x)qπ​(x,a),

where Pr⁡(s→x,k,π)\Pr(s \to x, k, \pi)Pr(s→x,k,π) is the probability of transitioning from sss to xxx in kkk steps under π=πθ0\pi = \pi_{\theta_0}π=πθ0​​ and all gradients are taken at θ0\theta_0θ0​.

This is the identity "after repeated unrolling" in the proof box; the policy gradient theorem is its case s=s0s = s_0s=s0​.

Formalization Note Pr⁡(s→x,k,π)\Pr(s \to x, k, \pi)Pr(s→x,k,π) is the (s,x)(s,x)(s,x) entry of Pθ0kP_{\theta_0}^kPθ0​k​. The result is stated for every start state, not only s0s_0s0​, as in the book.

Preamble
import Mathlib
import Definitions.Def_SuttonBartoRL_PolicyGradient_Model
import Definitions.Def_SuttonBartoRL_PolicyGradient_EpisodicValues
Formal statement
namespace SuttonBartoRL.PolicyGradient

/-- Box "Proof of the Policy Gradient Theorem (episodic case)", p. 325, "after repeated unrolling":
if episodes terminate under `π_{θ₀}`, then for every state `s`
`∇v_π(s) = Σ_{x ∈ S} Σ_{k=0}^{∞} Pr(s → x, k, π) Σ_a ∇π(a|x) q_π(x, a)`, where
`Pr(s → x, k, π) = (P_θ^k)(s, x)`. -/
theorem grad_stateValue_unrolled {S A : Type} [Fintype S] [DecidableEq S] [Fintype A] {d : ℕ}
    (M : EpisodicMDP S A) (π : ParamPolicy S A d) (θ₀ : EuclideanSpace ℝ (Fin d))
    (hT : M.Terminates π θ₀) (s : S) :
    HasGradientAt (fun θ => M.stateValue π θ s)
      (∑ x, (∑' k : ℕ, (M.policyTrans π θ₀ ^ k) s x) •
        ∑ a, M.actionValue π θ₀ x a • gradient (fun θ => π.prob θ x a) θ₀)
      θ₀ := by sorry

end SuttonBartoRL.PolicyGradient
Source
Sutton & Barto, Reinforcement Learning: An Introduction, 2nd ed., MIT Press (2018), ISBN 9780262039246, box "Proof of the Policy Gradient Theorem (episodic case)", p. 325
Human review
  • Endorsed by Shuze Chen · Oct 5, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 5, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me