Unit 5 of 11 · about 4 hours · derive

Bellman expectation and optimality equations

Planning iterates these equations. If the derivation is shaky, policy evaluation and value iteration look like arbitrary updates.

You'll be able to

  • Derive Bellman expectation equations for and from .
  • Derive Bellman optimality equations for and and state where maximum replaces expectation.
  • Explain why is wrong and what the correct marginalization gives.

Covers

Bellman expectation equations for policiesBellman optimality equations
1

Read

In this order, only the parts listed

0 of 4 done

  1. Bellman expectation and optimalityReinforcement Learning: An Introduction (2nd ed.) - Chapters 3 and 4

    Chapter 3, Sections 3.5 Policies and Value Functions and 3.6 Optimal Policies and Optimal Value Functions, equations (3.12) to (3.19), printed pp. 58 to 66. The authors post the full text free at incompleteideas.net.

  2. Bellman derivation with the wrong-equality warningHands-on Modern RL - MDPs, Values and Bellman Equations

    Derivation with the warning that direct equality is wrong and the three-tool marginalization, plus Matrix Form with (page read 2026-10-14)

  3. Optimality with the two-step numbersHands-on Modern RL - MDPs, Values and Bellman Equations

    Bellman Optimality Equation with the two-step example giving 8 for right and 4 for left, so (page read 2026-10-14)

  4. Bellman equation and backup operatorStanford CS234 Winter 2026 - Foundations and Planning

    Bellman Equation and Bellman Backup Operators with and definitions (slide 33)

2

Focus on

  • Expectation equations average over and . Optimality equations maximize over .
  • The recursion comes from plus Markov conditioning, not from intuition.
  • The and forms imply each other through .
Common mistakes · 3
  • Writing . The left side averages over next states. The right side is still random. The correct form sums .
  • Putting maximum inside the transition expectation. Maximum is over actions. Expectation over next states remains.
  • Assuming the optimal policy is unique. is unique. Several can tie, as the gambler family later shows.
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive both expectation equations from the return recursion on a two-action toy, then compute the Hands-on two-step case with optimal futures 8 and 4 to get and values 8 and 4.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What are the Bellman expectation equations for and ?Answer

    . .

  2. 2.What changes for and ?Answer

    Policy averaging becomes maximization: .

  3. 3.Why is the direct equality for the leftover return wrong?Answer

    The left side is already averaged given . The right side still depends on the random . Put it inside the same conditional expectation and marginalize over .

  4. 4.In the Hands-on two-step example with optimal futures 8 and 4, what are and ?Answer

    Right gives 8 and left gives 4, so by taking the maximum.

5

Practice

  • Sutton and Barto Exercises 3.14 and 3.17: Bellman checks

    Exercise 3.14 on Figure 3.2, printed p. 60, and Exercise 3.17 on action-value Bellman, printed p. 61. The authors post the full text free at incompleteideas.net.

    Verify numerically that (3.14) holds for each state in the figure before moving to evaluation.

You're done when

You derive both expectation forms and both optimality forms without notes and can point to where maximum replaces averaging.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 4 more in the section
  • Stanford CS234 Winter 2026 - Foundations and PlanningStanford University · primary

    Study Lecture 1 (lecture1pre.pdf and lecture1post.pdf) and Lecture 2 on tabular MDP planning (lecture2pre.pdf and lecture2post.pdf under https://web.stanford.edu/class/cs234/slides/). Work Assignment 1 independently: the written MDP, horizon and Bellman-operator questions and the vi_and_pi.py planning code on RiverSwim (NumPy only). Do not copy or publish course solutions.

  • Reinforcement Learning: An Introduction (2nd ed.) - Chapters 3 and 4Richard Sutton and Andrew Barto · required

    The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Chapter 3 (Sections 3.1 to 3.7, finite MDPs, returns, Bellman equations and optimality) and Chapter 4 (Sections 4.1 to 4.7, policy evaluation, improvement, policy and value iteration, asynchronous DP and GPI). Reproduce Example 4.1 and Figure 4.1 exactly, then Example 4.3 (the gambler), and write exact tests for stochastic transitions, terminals, ties and stopping error.

  • Hands-on Modern RL - MDPs, Values and Bellman EquationsWalking Labs · support

    Use the value and Bellman page and the value experiment page (code/chapter03_mdp/bellman_equation_verify.py and gridworld_q_learning.py run on CPU in seconds) as a code companion. Check every equation against Sutton and Barto before adopting it. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

Also in this section

  • Gymnasium - Time Limits and Episode SemanticsFarama Foundation · required

    Read the termination, truncation and "importance in learning code" sections, then the vector autoreset note at https://farama.org/Vector-Autoreset-Mode (next-step autoreset is the default in Gymnasium 1.x). Build a wrapper test that distinguishes termination from truncation and proves which cases bootstrap before using any third-party environment.

  • Deep-ML - Planning ProblemsDeep-ML · support

    Use named problems as closed-book checks after your own implementation passes: 157 (Bellman equation for value iteration), 164 (the gambler's problem by value iteration) and 467 (policy iteration). Read each problem's tests before trusting its statement.

  • Reinforcement Learning Control Laboratory - Planning CoreRoadmap-Final · required

    Complete Milestone A planning requirements: an explicit finite MDP, exact policy evaluation, value iteration, policy iteration, simulator agreement and seeded reward, transition, terminal and tie defects.

  • Reinforcement Learning: An Introduction (2nd ed.) - Chapter 2 banditsRichard Sutton and Andrew Barto · reference

    Read Section 2.9, Associative Search (Contextual Bandits), printed p. 41, with Exercise 2.10 as the context versus no-context check. Use only this section from Chapter 2.