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…

Key topics
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 and be deterministic policies over a finite MDP. If, for every state ,
then
Read the hypothesis carefully. It is a per-state, pointwise comparison: at each state, the action 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 . Since the max is at least the policy-weighted average, the hypothesis holds automatically — provided you have the true .
Two things the theorem does not say:
- It does not promise strict improvement. Ties are allowed, and the conclusion is , 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.
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.
| Symbol | Meaning |
|---|---|
| finite set of states | |
| finite set of actions | |
| probability of action in state under policy | |
| transition probability | |
| reward for the transition | |
| discount factor | |
| expected discounted return starting from under | |
| expected discounted return starting from , taking , then following |
I use the deterministic-policy convention in the greedy step: denotes the single action selects at . 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:
- Finite tabular MDP with exact evaluation. The proof compares against true action values , not estimates. This is the assumption that breaks most often in practice.
- Discounting regime. for continuing tasks. For , the theorem holds only when trajectories terminate in bounded time — episodic structure with a finite horizon.
- 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.
- Stationary environment and the Markov property. 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.
Deriving the Inequality Step by Step
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.
This is just the definition: the value of a state under is the average of the action values, weighted by how often picks each action.
Step 2 — Apply the hypothesis directly.
The theorem's hypothesis gives us at every state. That is the inequality we need — no maximization required. Substituting the definition from Step 1:
The left side is the current policy's value; the right side is the value of the action selects. The hypothesis is what licenses the step. If happens to be greedy, the inequality is tight at the max; if merely matches or beats the average, the inequality still holds.
Step 3 — Expand the action value.
The immediate reward is taken under 's action, but the continuation is still valued under . 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 , the hypothesis gives . Substituting:
Expand the inner the same way and repeat:
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 unrollings:
As , the residual term vanishes when , because is bounded and . For episodic tasks with , the residual vanishes once trajectories terminate. What remains is exactly . 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.
Worked Example: One Improvement Step on a Tiny MDP
Two states, two actions, . From state , action transitions to with reward ; action stays in with reward . From , both actions stay in with reward . Start with : always take in , always take in .
Evaluate . From , the agent loops forever taking with reward , so . From , same story: .
Compute action values at :
The greedy policy takes at . Check the hypothesis: . Holds. At , both actions tie at , so the inequality is tight — a live demonstration that "at least as good" is not a formality.
Now evaluate . From : reward , then forever with reward , so . From : . The conclusion holds: and .
Run this by hand. Change one reward. Watch which inequality breaks first.
Knowledge check
Check your understanding
Answer this question before you continue.
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 is estimated from samples or a function approximator, the greedy step is taken against noisy values. The hypothesis 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 .
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 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 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? , 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 values with noisy estimates — add a small random perturbation to each. Run the greedy step. Compute the true and compare it to . 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.
References
Build a stronger RL mental model
Use structured resources to connect equations, algorithms, and observable agent behavior.


