Worked examples — Policies and value functions
This page is the drill ground for the parent topic. We do not re-derive the theory here — we stress-test it. Every kind of situation a value-function problem can throw at you gets its own fully-worked example, and we label each with the exact cell of the scenario matrix it covers.
If any symbol below feels unfamiliar, that means you skipped ahead — go read the parent note and 5.1.02-Markov-Decision-Processes first, because we assume you already met:
- a state (the situation the agent is in),
- an action (a choice the agent makes),
- a reward (a number the environment hands back),
- the discount (how much we shrink future rewards, a number between and ),
- the policy (probability of choosing action in state ),
- and the two value functions and .
The scenario matrix
Think of every value-function problem as living in a grid. The rows are the structural traps — the shapes an MDP can take. If you can solve one example in every row, nothing on an exam can surprise you.
| # | Cell (what makes it tricky) | Where it bites | Covered by |
|---|---|---|---|
| A | Absorbing / terminal state (you get stuck and keep collecting) | Geometric series, | Ex 1 |
| B | Self-loop with a mix (partly stay, partly leave) | Coupled linear equations | Ex 2 |
| C | Multiple actions → compute , pick greedy | vs , | Ex 3 |
| D | Stochastic policy (agent flips a coin) | Weighted average over actions | Ex 4 |
| E | Degenerate: (total impatience) | Value collapses to immediate reward | Ex 5 |
| F | Limiting: (perfect patience) | Divergence vs finite horizon | Ex 6 |
| G | Negative rewards / a "trap" state | Signs, avoiding bad states | Ex 7 |
| H | Optimal policy with a | Bellman optimality, not expectation | Ex 8 |
| I | Real-world word problem | Translating English → MDP | Ex 9 |
| J | Exam twist: which action does pick? | Reading off | Ex 10 |
We reuse a tiny running world so the numbers stay checkable by hand, and change one knob per example so you see exactly what each knob does.
Warm-up geometry: what a value even is
Before the examples, one picture. The value of a state is a sum of shrinking rewards stretching into the future. The discount is what makes each later reward count for less.

Recall Why does
work — where does it come from? Let . Multiply by : . Subtract: , so , giving . It converges only because . ::: The trick is "subtract a shifted copy of the same series."
Ex 1 — Cell A: the absorbing state
Forecast: Guess a number before reading. Is it ? ? ? Write it down.
-
Write the Bellman expectation equation. Since the reward is deterministic () and the next state is always (i.e. ): Why this step? An absorbing state feeds into itself, so its value appears on both sides — this is what makes it solvable directly.
-
Solve the linear equation. Why this step? Collecting the terms turns "value defined by itself" into ordinary algebra.
Verify: Use the geometric formula directly: ✓ Both roads agree. (If you guessed , you forgot the forever; if , you over-shrunk.)
Ex 2 — Cell B: a self-loop that partly leaves
Forecast: pays less immediately (+1 vs +2) and sometimes traps you in the low-reward room. So expect below . How far below?
-
Write the Bellman equation, averaging over the two next states. Why this step? The environment is stochastic, so the future value is an expectation — weight each destination by its transition probability .
-
Substitute the known value . Why this step? We already solved , so it becomes a constant here — one unknown left.
-
Solve. Why this step? The unknown sits on both sides because of the self-loop; gathering its terms onto one side isolates it, and dividing by the leftover coefficient finally frees the single number we want.
Verify: ✓ (matches the forecast). Sanity check by plugging back: ✓
Ex 3 — Cell C: two actions, compute Q, act greedy
Forecast: pays more now and sends you to the good room. Bet on .
-
Apply the Bellman relation (deterministic transitions here). Why this step? answers "commit to this action first, then behave normally" — so it uses the immediate reward of that action, not the policy-averaged one.
-
Same for (it loops back into ): Why this step? Action 's immediate reward is , and afterward it returns to , so its future value is the state value we were given — we plug that in rather than re-deriving it.
-
Compare. , so . Why this step? Comparing -values at a fixed state is exactly how you improve a policy — pick the higher column.
Verify: ✓, so the greedy choice is , exactly as forecast. ✓
Ex 4 — Cell D: a genuinely stochastic policy
Forecast: Mostly picks the good action (), so should sit close to but pulled slightly down by the chance of .
-
Write the two equations — but depends on , which depends on both 's. This coupling is the whole point. Why this step? loops back to , so its Q needs the state's own value — a self-reference.
-
Use the linking identity : Why this step? A state's value is the policy-weighted average of its action-values — this is the bridge between and .
-
Substitute and solve the coupled system. Why this step? We have two equations in two unknowns ( and ). Substituting step 2 into step 1's second line eliminates , leaving a single equation where appears on both sides — then we gather its terms and divide, exactly like Ex 2.
-
Back out : Why this step? Now that is a known number, the linking identity from step 2 immediately hands us the state value — no more unknowns remain.
Verify: lies between and (the two 's), as a weighted average must ✓, and closer to because has the bigger weight ✓.
Ex 5 — Cell E: the degenerate discount
Forecast: With the future is worth nothing. So the value should collapse to just the one immediate reward — guess .
-
Apply the geometric formula at . Why this step? multiplies every future reward by ; only the immediate reward survives. Value literally equals the next reward — the agent is completely myopic.
-
Cross-check by expanding the sum. Why this step? Writing out the series confirms the formula didn't hide anything — every term past the first is annihilated.
Verify: ✓, matching the forecast. This is the degenerate endpoint: value cannot depend on any future.
Ex 6 — Cell F: the limiting discount
Forecast: Near-total patience adds up many rewards, so expect a big number. As hits exactly , expect trouble.
-
Evaluate at . Why this step? A tiny gap in the denominator makes the value huge — the agent now cares about roughly the next hundred rewards. Notice a small change in caused a large change in value: a warning when tuning discounts.
-
Take the limit . Why this step? At exactly nothing shrinks the future, so summing a constant positive reward forever diverges. The infinite-horizon value is undefined here — you would need a terminal state or an average-reward formulation instead.
Verify: ✓, and the value grows without bound as ✓ (see the green curve in the figure below shooting up near the red dashed line).

Ex 7 — Cell G: negative rewards and a trap
Forecast: Both values are negative. The trap should be worse than (which has one step of grace).
-
Value of the trap (geometric sum of a negative reward): Why this step? The formula doesn't care about the reward's sign — a constant forever piles up to .
-
Value of : Why this step? delays the pain by one discounted step, so it's less bad than the trap itself.
Verify: ✓ — is less negative, i.e. better, exactly as forecast. Units check: rewards are dimensionless "points," so values are points too. ✓
Ex 8 — Cell H: the optimal value with a max
Forecast: Optimal play never chooses the worse door, so should equal the better of the two action-values.
-
Write the Bellman optimality equation — note the , not a policy-weighted sum: Why this step? An optimal agent is greedy: it takes the single best action, so we maximize instead of average.
-
Evaluate each branch. For to ever win it would need , i.e. — impossible since the max is at most from branch . So wins. Why this step? We check the self-referential branch can't beat the clean one before committing.
-
Take the max: , and . Why this step? Once we know dominates at every feasible value, the simply selects 's number as , and the optimal policy is defined to pick whichever action attains that max — here .
Verify: Plug the greedy choice back: ✓ (consistent fixed point).
Ex 9 — Cell I: a real-world word problem
Forecast: Broken is a negative absorbing state → clearly negative. Working earns well but risks breaking → large positive.
-
Translate English to symbols. "Working" and "Broken" are states; the daily profit is the reward; "stays Working with prob 0.9" is a transition, i.e. and . This is just Ex 2's structure with real labels. Why this step? Word problems are trivial once you name the states, rewards, and transition probabilities.
-
Write and solve the Bellman equation for the absorbing Broken state. Broken pays and always returns to Broken, so: Gathering terms: , i.e. , so Why this step? Broken is absorbing, so its value depends only on itself — the same one-line algebra as Ex 1, now with a negative reward.
-
Write and solve the Bellman equation for Working (a self-loop that partly leaks into Broken): Substitute : Gather the terms: Why this step? Working feeds partly into itself and partly into Broken; averaging over both destinations (weighted by the transition probabilities ) and then isolating is exactly the coupled-equation move from Ex 2 — same math, business clothes.
Verify: ✓ and ✓. Plug back: ✓.
Ex 10 — Cell J: the exam twist ("which action?")
Forecast: is the biggest number; the optimal action is whichever hits that max — but here there's a tie.
-
Why this step? By definition — the value of a state under optimal play is the best action-value available.
-
. Both RIGHT and STAY achieve , so the optimal policy is any choice among the tied maximizers — RIGHT, STAY, or any mix of them. Why this step? The optimal policy need not be unique; ties mean multiple optimal policies exist, all equally good.
Verify: ✓ (the two maximizers agree), and LEFT () is strictly worse so it is never chosen ✓. This "read off the argmax" is precisely how 5.3.01-Q-Learning and 5.3.03-PolicyGradient-Methods recover a policy from learned values.
Recall One-line summary of each cell
A: absorbing → . B: self-loop → coupled linear eqn. C: two actions → compare . D: stochastic policy → weighted average. E: → value = immediate reward. F: → diverges. G: negative rewards → value stays negative. H: optimality → not average. I: word problem → name states first. J: read = . ::: If you can reproduce all ten, you have covered every scenario this topic offers.
Next stop: turn these hand-solved equations into an algorithm at 5.1.04-Bellman-Equations.