Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The importance-sampling ratio corrects the returns: Eb[ρt:T−1Gt∣St=s]=vπ(s)\mathbb E_b[\rho_{t:T-1}G_t \mid S_t = s] = v_\pi(s)Eb​[ρt:T−1​Gt​∣St​=s]=vπ​(s) (5.4)

Proved
SuttonBartoRL.ImportanceSampling.ordinary_importance_sampling_unbiased

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

importance-samplingmonte-carlop2o-batch-b23bp2o-gran-per-chapterp2o-plan-bookp2o-v1reinforcement-learning

Let bbb cover π\piπ, let 0≤γ≤10 \le \gamma \le 10≤γ≤1, and assume that under bbb every episode started at sss terminates within HHH steps with probability one. Then the return of an episode generated by bbb, weighted by its importance-sampling ratio, has expectation equal to the value of sss under the target policy:

Eb[ρ0:T−1G0∣S0=s]=vπ(s).\mathbb E_b\bigl[\rho_{0:T-1} G_0 \mid S_0 = s\bigr] = v_\pi(s) .Eb​[ρ0:T−1​G0​∣S0​=s]=vπ​(s).

This is why the first-visit ordinary importance-sampling estimator (5.5) is unbiased.

Formalization Note Time is shifted to t=0t = 0t=0. vπ(s)v_\pi(s)vπ​(s) is the expected return of an episode generated by π\piπ from sss (not a Bellman fixed point). The book leaves termination implicit; the bounded-horizon hypothesis is a restriction relative to the book, which Example 5.5 (unbounded episodes) shows is not necessary in general.

Preamble
import Mathlib
import Definitions.Def_SuttonBartoRL_ImportanceSampling_Episodes
Formal statement
namespace SuttonBartoRL.ImportanceSampling

/-- Sutton & Barto (2018), §5.5, p. 104, Eq. (5.4): `E_b[ρ_{t:T-1} G_t | S_t = s] = v_π(s)`.
Episodes start at `S_0 = s` and follow the behaviour policy `b`, which covers the target policy
`π`; under `b` every episode from `s` terminates within `H` steps with probability one; the
discount rate is `γ ∈ [0, 1]`. -/
theorem ordinary_importance_sampling_unbiased {S A : Type} [Fintype S] [DecidableEq S] [Fintype A]
    (M : MDP S A) (term : Finset S) (π b : SuttonBartoRL.FiniteMDP.Policy S A) (hcov : Coverage π b)
    (γ : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ ≤ 1) (s : S) (H : ℕ)
    (hH : ∑ n ∈ Finset.range (H + 1), ∑ e : Episode M n, episodeProb M term b s e = 1) :
    expectation M term b s (fun n e => e.isRatio π b n * e.ret γ) = value M term π γ s := by sorry

end SuttonBartoRL.ImportanceSampling
Source
Sutton & Barto, Reinforcement Learning: An Introduction, 2nd ed., MIT Press (2018), ISBN 9780262039246, Eq. (5.4), p. 104
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 paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me