5.1.5 · D2Reinforcement Learning Foundations

Visual walkthrough — Bellman equations

2,182 words10 min readBack to topic

This is the visual companion to Bellman equations. We build the state-value Bellman expectation equation — the parent's central boxed result — from absolute scratch.


Step 1 — What is an agent, a state, and a reward?

WHAT: Look at the board. You sit on a square, pick an arrow, slide to a new square, and a number pops out.

WHY: Everything else is built from this loop: state → action → reward → new state. If we cannot picture this single tick of time, no equation later will mean anything.

PICTURE: In the figure, the chalk-blue dot is you in state . The pale-yellow arrow is one action . The pink number is the reward the move pays. The dot lands in a new state we will call (read "s-prime", just "the next state").

Figure — Bellman equations

Step 2 — The return: adding up all future reward

WHAT: One reward is not enough. We care about the whole future stream of rewards. Stack them:

Here is the reward from the first move, from the second, and so on forever. The capital letter is the return — the grand total.

WHY: A move that pays now but traps you in a pit later is a bad move. Only the total tells the truth, so we must sum the whole tail.

PICTURE: The figure is a chalk timeline. Each tick drops one reward brick into a growing stack on the right. The stack never stops — that is the problem we fix next.

Figure — Bellman equations

Step 3 — The discount factor: why far-off reward counts less

Term by term:

  • — this step's reward, full strength (multiplied by ).
  • — next step's reward, shrunk once.
  • — two steps away, shrunk twice.

WHY this tool and not a plain sum? Two reasons, both visible in the picture. (1) A shrinking geometric stack has a finite total even if it runs forever — so values become comparable. (2) It bakes in "reward now beats reward later," which matches real impatience. See Discount Factor.

PICTURE: Same timeline as Step 2, but each brick is now scaled by a shrinking pale-yellow bar . The bricks visibly melt toward zero, so the total stack has a ceiling (the dashed line).

Figure — Bellman equations
Recall

Why does make the infinite sum finite? ::: Because , a finite number whenever . What does mean in words? ::: Only the immediate reward matters; the agent is fully short-sighted.


Step 4 — Expectation: the world rolls dice

WHAT: The same action can land you in different squares (a windy world, a random policy). So the return is not one fixed number — it's a bag of possible totals, each with a probability. We take the average of that bag.

WHY the average? We must commit to a single "how good is this state?" number before the dice are rolled. The fair single number is the probability-weighted mean — that is exactly .

PICTURE: From state the figure fans out three chalk paths with probabilities and totals . The pink dashed line marks the weighted average .

Figure — Bellman equations

Now we can finally name our quantity:

The letter here is just a name for a strategy; see Markov Decision Process for the full setup.


Step 5 — The one clever cut: peel off the first reward

WHAT: Split the discounted stack into the first brick plus everything after it:

Now factor one out of the whole future group:

WHY this exact cut? Stare at the parenthesis. It is a return again — the very same shape as , only starting one step later, from the next state. That self-similarity is the whole trick: the future-from-here contains a smaller copy of the same problem.

PICTURE: The figure snaps the reward stack into two chalk boxes: a yellow box holding lone , and a blue box holding the rest — and the blue box is drawn as a miniature copy of the entire original stack, sitting on the next state .

Figure — Bellman equations

Step 6 — Fold the tail into

WHAT: Take the expectation of both sides of the Step 5 cut. Because the parenthesis is the return starting from the next state , its expectation is :

Term by term:

  • — average reward for the first move out of .
  • — shrink the future by one step.
  • — average value of wherever we land.

WHY: We replaced an infinite sum with a finite expression that mentions once on the left and once on the right. The infinity is gone; a self-referencing rule remains.

PICTURE: The figure shows the equation as a chalk machine: enters, the yellow box emits one reward, the blue box (labelled ) feeds its own value back in scaled by — an arrow literally curving back on itself.

Figure — Bellman equations

Step 7 — Open the expectation: sum over actions and outcomes

WHAT: An expectation is just "each outcome times its probability, added up." Two dice are rolled: the policy picks the action (), then the world picks where you land and what you're paid (). Sum over both:

Reading it left to right, exactly where each symbol sits:

  • average over your choices: for every action , weight it by how often policy picks it.
  • average over the world's dice: for every possible landing spot and payout , weight by its probability.
  • — the immediate payout of that branch.
  • — the discounted value of that landing spot.

WHY split into two sums? Because two independent random choices happen: yours () and the environment's (). Each needs its own weighted average, nested.

PICTURE: A two-layer chalk tree. Layer 1: from , one yellow branch per action, labelled with . Layer 2: each action fans into blue branches labelled , each leaf carrying .

Figure — Bellman equations

This is the parent's central boxed result. It also seeds Dynamic Programming (solve it iteratively) and Temporal Difference Learning (solve it from samples).


Step 8 — Edge and degenerate cases

WHAT & WHY: A derivation you can trust must survive its extreme inputs. Four corners:

  1. Terminal state. A terminal state has no future — it never moves. So . The blue future box in the figure is empty; only the reward-on-entry survives.
  2. (fully short-sighted). The term vanishes: — pure one-step reward. The self-loop arrow is cut.
  3. Deterministic world. Each inner sum collapses to a single branch (probability ): . The blue fan becomes one twig.
  4. Greedy (deterministic) policy. The outer collapses to the one chosen action: the yellow fan becomes a single stalk — the doorway to the optimality equations and to Q-Learning.

PICTURE: Four small chalk panels, each showing which part of the Step-7 tree gets pruned in that corner (pruned branches drawn as faded dashed chalk).

Figure — Bellman equations
Recall

In case 1 (terminal), what is the value and why? ::: Zero — a terminal state has no future rewards to discount. Which sum disappears when the policy is deterministic (greedy)? ::: The outer sum over actions, — only one action has probability 1.


Step 9 — Numbers on the parent's grid-world

We reuse the parent's Example 1: uniform policy (each of 4 actions has ), per step, , and by symmetry the two neighbours share value ; two actions bump walls and stay in .

Collect terms:

If we take (a converged neighbour value), then .

Bellman-optimality flavour (Example 2): with , , , learning rate , starting from :

Figure — Bellman equations

The one-picture summary

Figure — Bellman equations

The whole page in a single chalk diagram: state pays an immediate reward (yellow), then discounts the value of the next state by (blue) — and that next value obeys the same rule, so the arrow loops back into itself. Infinite future, one-step law.

Recall Feynman retelling — say it like you'd explain to a friend

Imagine you're standing on a square and you want a single grade for "how good is standing here?" The honest grade is all the reward you'll ever collect from here on, but future reward matters a bit less each step, so you shrink it with . That total looks infinite and scary. Then you notice a trick: peel off just the first reward, and everything left over is the exact same kind of grade, only for the square you land on next. So "value here" = "reward now" + " times value of the next square." Because the world and your own choices are both random, you average over every action you might pick and every place you might land. That's the Bellman equation — a rule that quietly points back at itself, which is why a computer can solve it by keeping estimates and improving them until they stop changing.


Connections