Visual walkthrough — State-value and action-value functions
This page rebuilds the single most important identity in state-value and action-value functions — the Bellman expectation equation — one picture at a time. We assume you know nothing: not what a "value" is, not what means, not what a "policy" does. Every symbol is earned before it is used.
By the end you will see, in one picture, why:
Don't worry that this looks like alphabet soup. We build it letter by letter.
Step 1 — What is a reward, and why sum the future?
WHAT. An agent lives in states (situations) and takes actions. After each action the world hands it a number called a reward — think of it as points. We write the reward that arrives at time step as . The little subscript is just a clock reading: "this reward showed up on tick ."
WHY. A single reward tells you almost nothing. Grabbing now might trap you somewhere that pays forever after. So the quantity we actually care about is the whole future stream of rewards added up, starting right after the current moment :
- ::: the return — total future points collected from time onward
- each ::: one payout, one tick apart on the clock
PICTURE. Look at the timeline below. The agent sits at (the magenta dot). Every arrow forward drops a coin into the bucket labelled .
Step 2 — Why discount? Introducing
WHAT. The naive sum has a problem: if rewards keep coming forever, the sum can blow up to infinity, and infinity can't be compared to infinity. We fix this by shrinking each future reward a little more the further away it is, using a knob (Greek letter "gamma"), a number between and :
- ::: the discount factor, how much we care about the next step's future ( ignore future, future matters as much as now)
- ::: a reward steps away is worth only of its face value
- ::: "add up over all future steps "
WHY and not, say, subtracting a constant? Multiplying by each step makes the coins geometrically smaller, so even an infinite stream adds to a finite number (a geometric series). Subtraction wouldn't guarantee that. It also captures a real idea: points sooner are worth more than points later.
PICTURE. The same coins as Step 1, but now each is drawn smaller — scaled by — a shrinking staircase.
Step 3 — Why average? Introducing the policy and
WHAT. Two things are uncertain: (a) which action the agent picks, and (b) where the world sends it afterward. The rule for picking actions is the policy . We write = "the probability of choosing action when in state ."
Because outcomes are random, is a random number — different every time you play. So we take its expected value (its long-run average over many playthroughs), written .
WHY average and not the best case? The agent doesn't get to pick the luckiest future; it gets the typical one under its own habits . The honest "how good is here?" number is the mean return, not the max.
PICTURE. From one state, three possible futures fan out with probabilities . Each future has its own bucket . The expectation is the probability-weighted blend of all buckets.
Step 4 — The one trick that makes it recursive: peel off the first reward
WHAT. Look again at the return. The very first coin is special — it's the only one not multiplied by any . Factor out of everything after it:
- ::: the immediate reward — the payout for this one step
- ::: the entire rest of the future, discounted once and viewed from the next state
WHY this peel? It turns an infinite sum into a two-piece object: now + (discounted) later. And "later" has exactly the same shape as the thing we started with — that self-similarity is what lets us write an equation for in terms of itself.
PICTURE. The coin staircase splits with a scissors cut after the first coin: a lone coin , then the whole remaining staircase compressed into one box labelled .
Step 5 — Where do you land next? The environment
WHAT. After you pick action in state , the world decides two things at once: the reward it pays, and the next state it drops you into. It does this randomly, with probability
- ::: the next state (read "s prime")
- ::: the reward that comes with that landing
- ::: probability the world sends you to paying , given you did in
WHY do we need this? In Step 4 we said "the rest of the future is viewed from the next state." But which next state? The environment answers that — and it may be random. To take the average return we must average over all the places we might land, weighted by .
PICTURE. From the pair (a small square) the world branches to several outcomes, each edge labelled with its probability .
Step 6 — Assemble : immediate reward + discounted value of where you land
WHAT. Start from (Step 4's peel, applied to ). Split the average into "now" and "later," then average both over the landings from Step 5. The key fact — the Markov property — is that once you know you landed in , the future no longer cares how you got there, so is exactly . This gives:
Term by term, reading the picture:
- ::: "average over every place you might land"
- ::: the weight (probability) of that landing
- ::: the immediate coin for that landing
- ::: the discounted value of all future coins, viewed from
WHY split like this? Because the immediate reward is knowable now, but everything after landing is summarised by the number we already defined. We never re-simulate the whole future — we reuse . That reuse is called bootstrapping.
PICTURE. Each branch from Step 5 now carries a label ; multiply by , add the branches.
Step 7 — Assemble : average over the policy's action choices
WHAT. In state the policy picks an action randomly with weights . Each possible action has its own quality . The state's value is the probability-weighted blend:
- ::: "average over every action you might take"
- ::: the weight of action under your policy
- ::: how good that action is (Step 6)
WHY this exact average? is "how good is the state," and a state is only ever experienced through the actions you choose there. The honest answer is the mean over those choices, weighted by how often you make them.
PICTURE. A hub with action-spokes; each spoke has thickness and a value tag . The blended result flows back into .
Step 8 — Substitute and get the Bellman expectation equation
WHAT. Now nest Step 6 inside Step 7. Replace each in the -average with its immediate-plus-discounted form:
Reading the two layers:
- outer sum ::: average over my action choices
- inner sum ::: average over the world's landings
- ::: this step's coin plus the discounted value of next step's whole future
WHY is this profound? appears on the left and appears on the right. The value of a state is pinned down by the values of its neighbours. Solving this self-consistent web is what policy evaluation does exactly, Monte-Carlo estimates by sampling whole returns, and temporal-difference learning approximates by nudging toward .
PICTURE. The full two-layer tree: state → action layer (policy weights) → outcome layer (environment weights) → successor states , each feeding its own back up.
Step 9 — Edge & degenerate cases (never let the reader hit an unshown scenario)
WHAT. Three boundary situations that break naive intuition:
- Terminal (goal) state. There is no future, so . The sum has no successors; the recursion stops here. This is the anchor that makes back-substitution work in the gridworld below.
- . The future term vanishes entirely: — pure immediate reward, a myopic agent.
- Deterministic transition. If action always leads to one with one , then and the inner sum collapses to a single term: . No averaging needed.
WHY show these? Every real computation lives in one of these regimes. Miss the terminal case and your recursion never bottoms out (infinite loop). Miss and you can't explain a myopic agent.
PICTURE. Three mini-panels: a terminal state with a flat tag; a tree with the future branch greyed out; a deterministic single-arrow transition.
The one-picture summary
The whole derivation in one diagram: from state , the policy chooses an action (magenta weights ), the environment chooses a landing (orange weights ), each landing pays and hands you the discounted value of the next state's future — and averaging both layers gives back .
Recall Feynman retelling — say it like you'd explain to a friend
Imagine standing on a tile in a game. You want one number that says "how good is standing here, playing the way I usually play?" That number is . To get it, you ask two questions and take averages. First: "what might I do?" — you don't always pick the same move, so you average over your habits, weighting each move by how often you make it. Second, for each move: "where might the world throw me, and what does it pay?" — again random, so you average over landings, weighting by their probabilities. On each landing you collect the immediate coin , and you also get "how good is the new tile," shrunk by because it's one step in the future. Add coin plus shrunken next-tile-value, blend over the world's dice, blend over your own dice — and you're back to the value of the tile you started on. That circular sentence is the Bellman equation. And it terminates because a goal tile has no future, so its value is just zero — the wall the whole recursion leans against.