Skip to content
intermediate

Deriving the Policy Improvement Theorem for Tabular MDPs

You run a round of policy iteration. The greedy policy looks better on paper, so you deploy it. The measured return drops. Nothing in your code threw an…

Published 2026-10-02Updated 2026-10-049 min read
A human brain model placed on a blue plate, viewed from above against a pastel background.
A human brain model placed on a blue plate, viewed from above against a pastel background. Photo by Amel Uzunovic on Pexels.

You run a round of policy iteration. The greedy policy looks better on paper, so you deploy it. The measured return drops. Nothing in your code threw an error, and nothing in the textbook was wrong. What broke was the mental model you were carrying: the belief that greedy improvement is always an improvement. It is not. It is an improvement if a specific set of conditions holds. This article derives the policy improvement theorem for tabular MDPs, names those conditions, and shows exactly where the guarantee leaks when you replace exact values with estimates.

What the Theorem Actually Claims

Before the derivation, state the result precisely. Let π\pi and π′\pi' be deterministic policies over a finite MDP. If, for every state ss,

Qπ(s,π′(s))≥Vπ(s),Q^{\pi}(s, \pi'(s)) \geq V^{\pi}(s),

then

Vπ′(s)≥Vπ(s)for all s.V^{\pi'}(s) \geq V^{\pi}(s) \quad \text{for all } s.

Read the hypothesis carefully. It is a per-state, pointwise comparison: at each state, the action π′\pi' picks must be worth at least as much as the current policy's value there. This is stronger than "better on average." A policy that improves the average return while quietly regressing in a few states does not satisfy the hypothesis, and the theorem says nothing about it.

Greedy improvement is the special case where π′(s)=arg⁡max⁡aQπ(s,a)\pi'(s) = \arg\max_a Q^{\pi}(s, a). Since the max is at least the policy-weighted average, the hypothesis holds automatically — provided you have the true QπQ^{\pi}.

Two things the theorem does not say:

  • It does not promise strict improvement. Ties are allowed, and the conclusion is ≥\geq, not >>.
  • It does not say the greedy policy is optimal after one step. Optimality requires the full policy iteration loop plus Bellman optimality.

If you already have the Bellman expectation relationship from the prerequisite material, you have everything you need. The only tool this proof uses is the one-step decomposition: value equals expected immediate reward plus discounted expected next-state value.

Knowledge check

Check your understanding

Answer this question before you continue.

Which condition on a candidate deterministic policy π′ is sufficient for the theorem’s stated guarantee?
Single Choice

Focus: Identify the pointwise action-value condition required for the policy improvement theorem.

Notation and the Assumptions That Carry the Proof

Here is the notation used throughout, with each symbol tied to what it represents in the system.

SymbolMeaning
SSfinite set of states
AAfinite set of actions
π(a∣s)\pi(a \mid s)probability of action aa in state ss under policy π\pi
P(s′∣s,a)P(s' \mid s, a)transition probability
R(s,a,s′)R(s, a, s')reward for the transition
γ\gammadiscount factor
Vπ(s)V^{\pi}(s)expected discounted return starting from ss under π\pi
Qπ(s,a)Q^{\pi}(s, a)expected discounted return starting from ss, taking aa, then following π\pi

I use the deterministic-policy convention in the greedy step: π′(s)\pi'(s) denotes the single action π′\pi' selects at ss. This keeps the algebra readable. The result extends to stochastic policies, but the deterministic case is where the intuition lives.

Four assumptions carry the proof:

  1. Finite tabular MDP with exact evaluation. The proof compares against true action values QπQ^{\pi}, not estimates. This is the assumption that breaks most often in practice.
  2. Discounting regime. γ<1\gamma < 1 for continuing tasks. For γ=1\gamma = 1, the theorem holds only when trajectories terminate in bounded time — episodic structure with a finite horizon.
  3. Rich enough policy class. The policy class must be able to represent the greedy choice at every state. Deterministic policies over the full action set satisfy this.
  4. Stationary environment and the Markov property. QπQ^{\pi} must be a well-defined function of state and action alone.

Keep these four in view. They are the same four things that fail when a real algorithm misbehaves.

Knowledge check

Check your understanding

Answer this question before you continue.

Which statement matches the article’s discounting assumption for the proof?
Misconception Check

Focus: State the discounting and termination conditions used to make the improvement proof’s residual vanish.

Deriving the Inequality Step by Step

A four-stage chain starts with Qπ(s, π′(s)) ≥ Vπ(s), expands the action value into expected reward plus discounted next-state value, applies the same inequality at the successor state, and unrolls to the conclusion Vπ′(s) ≥ Vπ(s) as the discounted residual vanishes.
The guarantee comes from reapplying the per-state inequality at each successor; discounting or termination removes the residual value.

The proof is a chain of substitutions, and every line has a reason. Follow the reasons, not the symbols.

Step 1 — Value as a policy-weighted average.

Vπ(s)=∑aπ(a∣s) Qπ(s,a).V^{\pi}(s) = \sum_a \pi(a \mid s) \, Q^{\pi}(s, a).

This is just the definition: the value of a state under π\pi is the average of the action values, weighted by how often π\pi picks each action.

Step 2 — Apply the hypothesis directly.

The theorem's hypothesis gives us Qπ(s,π′(s))≥Vπ(s)Q^{\pi}(s, \pi'(s)) \geq V^{\pi}(s) at every state. That is the inequality we need — no maximization required. Substituting the definition from Step 1:

Vπ(s)=∑aπ(a∣s)Qπ(s,a)≤Qπ(s,π′(s)).V^{\pi}(s) = \sum_a \pi(a \mid s) Q^{\pi}(s, a) \leq Q^{\pi}(s, \pi'(s)).

The left side is the current policy's value; the right side is the value of the action π′\pi' selects. The hypothesis is what licenses the step. If π′\pi' happens to be greedy, the inequality is tight at the max; if π′\pi' merely matches or beats the average, the inequality still holds.

Step 3 — Expand the action value.

Qπ(s,π′(s))=Eπ′ ⁣[ rt+1+γVπ(st+1) | st=s ].Q^{\pi}(s, \pi'(s)) = \mathbb{E}_{\pi'}\!\left[\, r_{t+1} + \gamma V^{\pi}(s_{t+1}) \,\middle|\, s_t = s \,\right].

The immediate reward is taken under π′\pi''s action, but the continuation is still valued under π\pi. This mismatch is the whole point — it is what we are about to repair.

Step 4 — Apply the same inequality at the next state.

At st+1s_{t+1}, the hypothesis gives Vπ(st+1)≤Qπ(st+1,π′(st+1))V^{\pi}(s_{t+1}) \leq Q^{\pi}(s_{t+1}, \pi'(s_{t+1})). Substituting:

Vπ(s)≤Eπ′ ⁣[ rt+1+γQπ(st+1,π′(st+1)) | st=s ].V^{\pi}(s) \leq \mathbb{E}_{\pi'}\!\left[\, r_{t+1} + \gamma Q^{\pi}(s_{t+1}, \pi'(s_{t+1})) \,\middle|\, s_t = s \,\right].

Expand the inner QπQ^{\pi} the same way and repeat:

Vπ(s)≤Eπ′ ⁣[ rt+1+γrt+2+γ2Vπ(st+2) | st=s ].V^{\pi}(s) \leq \mathbb{E}_{\pi'}\!\left[\, r_{t+1} + \gamma r_{t+2} + \gamma^2 V^{\pi}(s_{t+2}) \,\middle|\, s_t = s \,\right].

This is the unrolling step. The guarantee is earned here. Each state's improvement is paid forward to its successors, and the inequality survives every substitution because it held at every state.

Step 5 — Take the limit.

After kk unrollings:

Vπ(s)≤Eπ′ ⁣[ ∑j=0k−1γjrt+j+1+γkVπ(st+k) | st=s ].V^{\pi}(s) \leq \mathbb{E}_{\pi'}\!\left[\, \sum_{j=0}^{k-1} \gamma^j r_{t+j+1} + \gamma^k V^{\pi}(s_{t+k}) \,\middle|\, s_t = s \,\right].

As k→∞k \to \infty, the residual term γkVπ(st+k)\gamma^k V^{\pi}(s_{t+k}) vanishes when γ<1\gamma < 1, because VπV^{\pi} is bounded and γk→0\gamma^k \to 0. For episodic tasks with γ=1\gamma = 1, the residual vanishes once trajectories terminate. What remains is exactly Vπ′(s)V^{\pi'}(s). The conclusion follows.

The proof is a bootstrap argument. Improvement at one state is not free — it is collateralized by improvement at its successors. If any successor refuses to improve, the chain of inequalities snaps.

Knowledge check

Check your understanding

Answer this question before you continue.

Why can the proof replace V^π(sₜ₊₁) with Q^π(sₜ₊₁, π′(sₜ₊₁)) when unrolling the inequality?
Comparison Reasoning

Focus: Explain how a per-state improvement condition supports repeated substitution in the policy improvement proof.

Worked Example: One Improvement Step on a Tiny MDP

Two states, two actions, γ=0.9\gamma = 0.9. From state s1s_1, action aa transitions to s2s_2 with reward 11; action bb stays in s1s_1 with reward 00. From s2s_2, both actions stay in s2s_2 with reward 00. Start with π\pi: always take bb in s1s_1, always take aa in s2s_2.

Evaluate π\pi. From s1s_1, the agent loops forever taking bb with reward 00, so Vπ(s1)=0V^{\pi}(s_1) = 0. From s2s_2, same story: Vπ(s2)=0V^{\pi}(s_2) = 0.

Compute action values at s1s_1:

  • Qπ(s1,a)=1+0.9⋅Vπ(s2)=1Q^{\pi}(s_1, a) = 1 + 0.9 \cdot V^{\pi}(s_2) = 1
  • Qπ(s1,b)=0+0.9⋅Vπ(s1)=0Q^{\pi}(s_1, b) = 0 + 0.9 \cdot V^{\pi}(s_1) = 0

The greedy policy π′\pi' takes aa at s1s_1. Check the hypothesis: Qπ(s1,π′(s1))=1≥Vπ(s1)=0Q^{\pi}(s_1, \pi'(s_1)) = 1 \geq V^{\pi}(s_1) = 0. Holds. At s2s_2, both actions tie at 00, so the inequality is tight — a live demonstration that "at least as good" is not a formality.

Now evaluate π′\pi'. From s1s_1: reward 11, then s2s_2 forever with reward 00, so Vπ′(s1)=1V^{\pi'}(s_1) = 1. From s2s_2: Vπ′(s2)=0V^{\pi'}(s_2) = 0. The conclusion holds: 1≥01 \geq 0 and 0≥00 \geq 0.

Run this by hand. Change one reward. Watch which inequality breaks first.

Knowledge check

Check your understanding

Answer this question before you continue.

In the worked two-state MDP, what is V^π′(s₁) after π′ chooses action a at s₁?
Scenario Interpretation

Focus: Use the article’s two-state example to determine the value after its greedy policy improvement step.

Where the Guarantee Comes From — and Where It Leaks

In the exact case, policy iteration with full evaluation converges to an optimal policy. The theorem plus Bellman optimality is what makes the loop terminate: each improvement step is monotone, and a finite MDP has finitely many deterministic policies, so the sequence must stabilize at a policy that is greedy with respect to its own value function — an optimal one.

The approximate case is where the guarantee leaks. When QπQ^{\pi} is estimated from samples or a function approximator, the greedy step is taken against noisy values. The hypothesis Qπ(s,π′(s))≥Vπ(s)Q^{\pi}(s, \pi'(s)) \geq V^{\pi}(s) may be false at some states, and the proof's chain of inequalities has nothing to stand on. Approximate policy evaluation gives you a heuristic improvement step, not a monotonic guarantee. Measured return can regress.

Common mistake: Assuming the theorem licenses "always take the argmax of my current Q estimate" in deep RL or with limited data. The theorem licenses that step only when the estimate is the true QπQ^{\pi}.

This is why conservative improvement methods exist — trust regions, small step sizes, statistical lower bounds on the new policy's performance. They are not refinements of the theorem. They are replacements for a guarantee that is no longer available.

One boundary worth stating explicitly: the theorem also fails for episodic tasks with γ=1\gamma = 1 if some trajectories never terminate. A policy can look greedy against optimal action values and still be terrible, because the residual term never vanishes. The discount factor is not a tuning knob here. It is a load-bearing assumption.

What to Check Before You Trust an Improvement Step

Turn the derivation into a checklist:

  • Is your QQ estimate exact or sampled? If sampled, treat the improvement as a hypothesis to test, not a guarantee.
  • Is your discounting regime inside the theorem's scope? γ<1\gamma < 1, or episodic with bounded trajectories.
  • Are you comparing per-state values, or only aggregate return? Aggregate improvement can hide per-state regressions.
  • Does your policy class actually contain the greedy choice, or are you approximating it?

My rule: use the theorem to reason about the shape of the algorithm. Use measured evaluation to decide whether a specific update helped. The theorem tells you what must be true for greedy improvement to be safe. That list of conditions is the same list of things that break in practice.

Here is your next experiment. Take the two-state example above. Replace the exact QπQ^{\pi} values with noisy estimates — add a small random perturbation to each. Run the greedy step. Compute the true Vπ′V^{\pi'} and compare it to VπV^{\pi}. Repeat a hundred times and count how often the guarantee fails. You will not need a proof to remember the lesson after that.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

An agent greedily changes policy using noisy estimates of Q^π, and its measured return later drops. Which interpretation best follows from the article?
Question 1 of 2Misconception Check

Focus: Distinguish the theorem’s exact-value guarantee from greedy improvement using estimated action values.

A task uses γ = 1 and permits trajectories that continue forever. Which conclusion is supported by the article?
Question 2 of 2Scenario Interpretation

Focus: Recognize why the theorem’s proof does not guarantee improvement for undiscounted trajectories that may never terminate.

References

  1. - 4F13: Machine Learning - MLG Cambridgemlg.eng.cam.ac.uk
  2. Notes on finite MDPs, Bellman equations and policy ...www2.htw-dresden.de
  3. High Confidence Policy Improvementproceedings.mlr.press
Practical resource

Build a stronger RL mental model

Use structured resources to connect equations, algorithms, and observable agent behavior.

Browse resources
Related sites

Continue across related AI foundations

Use LearnPyFast for Python foundations and LearnLLMFast for practical language-model and agent application concepts.

Python tutorialstutorial

LearnPyFast

Beginner-friendly Python tutorials, examples, and learning paths for practical programming foundations.

PythonProgrammingBeginners
Visit LearnPyFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related reinforcement learning tutorials

Continue with nearby RL concepts, algorithms, and experiments that build on the same decision process.