Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The three factors of ∇PBE as expectations under the behavior policy (p. 278)

Proved
SuttonBartoRL.OffPolicy.pbe_gradient_factors

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

linear-algebraoff-policyp2o-batch-b23bp2o-gran-per-chapterp2o-plan-bookp2o-v1reinforcement-learning

Let π\piπ be the target and bbb the behavior policy, with coverage (π(a∣s)>0⇒b(a∣s)>0\pi(a\mid s)>0\Rightarrow b(a\mid s)>0π(a∣s)>0⇒b(a∣s)>0) and ratio ρt=π(At∣St)/b(At∣St)\rho_t = \pi(A_t\mid S_t)/b(A_t\mid S_t)ρt​=π(At​∣St​)/b(At​∣St​). Let St∼μS_t\sim\muSt​∼μ (the state distribution under bbb), At∼b(⋅∣St)A_t\sim b(\cdot\mid S_t)At​∼b(⋅∣St​), (St+1,Rt+1)∼p(⋅,⋅∣St,At)(S_{t+1},R_{t+1})\sim p(\cdot,\cdot\mid S_t,A_t)(St+1​,Rt+1​)∼p(⋅,⋅∣St​,At​), xt=x(St)\mathbf x_t = \mathbf x(S_t)xt​=x(St​), xt+1=x(St+1)\mathbf x_{t+1} = \mathbf x(S_{t+1})xt+1​=x(St+1​) and δt=Rt+1+γw⊤xt+1−w⊤xt\delta_t = R_{t+1} + \gamma\mathbf w^\top\mathbf x_{t+1} - \mathbf w^\top\mathbf x_tδt​=Rt+1​+γw⊤xt+1​−w⊤xt​. With D=diag⁡(μ)\mathbf D = \operatorname{diag}(\mu)D=diag(μ) and PπP_\piPπ​ the target policy's transition matrix, for every w\mathbf ww:

X⊤Dδˉw=∑sμ(s) x(s) δˉw(s)=E[ρtδtxt];\mathbf X^\top\mathbf D\bar\delta_{\mathbf w} = \sum_s\mu(s)\,\mathbf x(s)\,\bar\delta_{\mathbf w}(s) = \mathbb E[\rho_t\delta_t\mathbf x_t];X⊤Dδˉw​=s∑​μ(s)x(s)δˉw​(s)=E[ρt​δt​xt​];
E[ρt(γxt+1−xt)xt⊤]=(γPπX−X)⊤DX;\mathbb E\bigl[\rho_t(\gamma\mathbf x_{t+1} - \mathbf x_t)\mathbf x_t^\top\bigr] = (\gamma P_\pi\mathbf X - \mathbf X)^\top\mathbf D\mathbf X;E[ρt​(γxt+1​−xt​)xt⊤​]=(γPπ​X−X)⊤DX;
X⊤DX=∑sμ(s) x(s)x(s)⊤=E[xtxt⊤].\mathbf X^\top\mathbf D\mathbf X = \sum_s\mu(s)\,\mathbf x(s)\mathbf x(s)^\top = \mathbb E[\mathbf x_t\mathbf x_t^\top].X⊤DX=s∑​μ(s)x(s)x(s)⊤=E[xt​xt⊤​].

These identities turn the matrix form of the PBE gradient into the expectation form (11.27), whose factors can be sampled from off-policy experience.

Formalization Note Each expectation is written out as the finite sum over s∼μs\sim\mus∼μ, a∼ba\sim ba∼b and (s′,r)∼p(s',r)\sim p(s′,r)∼p. Item 2 gives the value of the first factor of (11.27); the book obtains it as the transpose of the gradient of E[ρtδtxt]\mathbb E[\rho_t\delta_t\mathbf x_t]E[ρt​δt​xt​], and the goal theorem states that gradient in matrix form. μ\muμ need not be stationary for these identities.

Preamble
import Mathlib
import Definitions.Def_SuttonBartoRL_OffPolicy_LinearGeometry

open Matrix
Formal statement
namespace SuttonBartoRL.OffPolicy

/-- Sutton & Barto (2018), p. 278: the three factors of the PBE gradient as expectations under the
behavior policy. Let `π` be the target and `b` the behavior policy with coverage
(`π(a|s) > 0 → b(a|s) > 0`), `ρ = π(a|s)/b(a|s)`, and `S_t ∼ µ`, `A_t ∼ b`,
`(S_{t+1}, R_{t+1}) ∼ p`, with `x_t = x(S_t)`, `x_{t+1} = x(S_{t+1})` and
`δ_t = R_{t+1} + γwᵀx_{t+1} − wᵀx_t`. Then
1. `XᵀDδ̄_w = Σ_s µ(s) x(s) δ̄_w(s) = E[ρ_t δ_t x_t]`;
2. `E[ρ_t (γx_{t+1} − x_t) x_tᵀ] = (γP_πX − X)ᵀ D X`;
3. `XᵀDX = Σ_s µ(s) x(s) x(s)ᵀ = E[x_t x_tᵀ]`. -/
theorem pbe_gradient_factors {S A : Type} [Fintype S] [DecidableEq S] [Fintype A] {d : ℕ}
    (M : MDP S A) (π b : SuttonBartoRL.FiniteMDP.Policy S A) (hcov : ∀ s a, 0 < π.prob s a → 0 < b.prob s a)
    (γ : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ ≤ 1)
    (μ : S → ℝ) (hμ0 : ∀ s, 0 ≤ μ s) (hμ1 : ∑ s, μ s = 1)
    (X : Matrix S (Fin d) ℝ) (w : Fin d → ℝ) :
    (Xᵀ *ᵥ (Dmat μ *ᵥ bellmanError M π γ X w) = ∑ s, (μ s * bellmanError M π γ X w s) • X s ∧
      ∑ s, (μ s * bellmanError M π γ X w s) • X s
        = behaviorExp M b μ
            (fun s a s' r => (isRatio π b s a * (r + γ * (w ⬝ᵥ X s') - w ⬝ᵥ X s)) • X s)) ∧
    behaviorExp M b μ (fun s a s' _ => isRatio π b s a • vecMulVec (γ • X s' - X s) (X s))
      = (γ • (policyTrans M π * X) - X)ᵀ * Dmat μ * X ∧
    (Xᵀ * Dmat μ * X = ∑ s, μ s • vecMulVec (X s) (X s) ∧
      ∑ s, μ s • vecMulVec (X s) (X s) = behaviorExp M b μ (fun s _ _ _ => vecMulVec (X s) (X s))) := by sorry

end SuttonBartoRL.OffPolicy
Source
Sutton & Barto, Reinforcement Learning: An Introduction, 2nd ed., MIT Press (2018), ISBN 9780262039246, §11.7, the three factor identities, p. 278
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