Dynamic programming: planning with a known model

How the Bellman equations are solved exactly when the model is known: the MDP and its values, policy evaluation, policy iteration and value iteration, why they converge and what they cost. A child of Topic: rl. Sources linked inline; data as of October 2026. Reading: 39 min, plus 11 in closed details. Best resources +7h 15m.

The idea in one screen

When the model is known, the Bellman equation becomes an assignment: a state's value is the reward now plus the discounted value of where you land, averaged with the model's probabilities. Back up every state from its successors, sweep after sweep, and the error shrinks by a factor γ per sweep onto the exact values; the optimal policy is then read off greedily.

One backup, then the same backup everywhere: reward spreads out one step per sweep

  1. One state, two actions. Class 3 in Silver's student MDP at γ = 1: Study pays +10 and ends the episode; Pub pays +1 and then chance moves you.
  2. Read the values of where you can land. From the Pub, chance sends you to Class 1, 2 or 3 with probabilities 0.2, 0.4 and 0.4; their optimal values are 6, 8 and 10 (the bars). The glass plate is the model, P(s′ | Pub); the values stream through it into the Pub.
  3. Average them with the model's probabilities. Pub is worth 1 + 0.2 × 6 + 0.4 × 8 + 0.4 × 10 = 9.4: the reward now plus the probability-weighted value of the successor, stacked piece by piece.
  4. Keep the best action. The backup keeps the larger, Study's 10, and writes it into Class 3. That is one assignment of the Bellman optimality equation.
  5. The same backup on every cell at once: one sweep. Silver's 4 × 4 shortest-path grid (−1 per move, goal in the corner, values from zeros); bar height is −V, the moves still to pay. After one sweep every cell says −1.
  6. After 3 sweeps. Cells within three moves of the goal hold minus their distance; every cell farther out says −3. The cells exactly three moves away (orange) have just become exact, fed by the neighbour one move closer.
  7. After 6 sweeps: exact. At every stage the values hold −min(sweeps, steps to the goal), so after six sweeps, the distance of the far corner, they are the true distances.

You need: expectations and a linear solve, nothing more. The parent Topic: rl places DP among the families (every RL method estimates the same expected return; DP computes it exactly from the model). Learning the same values from samples, without the model, is Model-free prediction and control.

MDP
states, actions, transition probabilities P(s′ | s, a), expected rewards R(s, a) and a discount γ (section 1).
Return Gt, discount γ
the discounted sum of future rewards; a reward k + 1 steps ahead counts γk (section 2).
Vπ, Qπ
expected return from a state, or from a state and an action, when following policy π (section 3).
Bellman equation
value now = reward now + γ × expected value next; expectation form for a fixed policy, optimality form with a max (section 3).
Backup, sweep
one Bellman assignment to one state; one backup of every state. Synchronous reads the previous sweep's values, in place the latest (section 4).
Policy iteration, value iteration
evaluate a policy, then make it greedy, repeat; or back up with the max directly, no policy stored (sections 6 and 7).
GPI
generalised policy iteration: any interleaving of evaluation and improvement (section 6).
Contraction
a sweep brings any two value functions at least γ times closer; why DP converges (section 9).
Bellman equationTurned into an update, it isSolvesStops when
Expectation, for VπPolicy evaluation (section 4); also solvable directly as a linear systemPredictionThe largest change in a sweep is below θ
Expectation, then a greedy stepPolicy iteration (section 6): evaluate, improve, repeatControlThe policy stops changing: exact and finite
Optimality, for V*Value iteration (section 7): one sweep of evaluation per improvementControlThe largest change is below θ: approximate
Either, in any orderAsynchronous DP (section 12): in place, prioritised sweeping, real-time DPEitherEvery state keeps being backed up

Why it matters beyond small tables: DP is the ideal every model-free method approximates (they replace its exact expectation over successors with one sampled successor), and its backup is the template for every learning target in RL (section 13). DP is model-based planning, not learning: nothing is learned from interaction (Sutton and Barto, chapter 4; Silver, Lecture 3). The Sweep lab runs every method here side by side on four worlds.

1The object DP solves: a Markov decision process

The loop. At each step t the agent receives an observation Ot and a reward Rt, then chooses an action At; the environment answers with Ot+1 and Rt+1 (Silver, Lecture 1). So the reward that follows action At is Rt+1, which is why every return below starts at Rt+1; texts that write rt for the reward of the action at t shift only the subscript.

ℙ[St+1 | St] = ℙ[St+1 | S1, ..., St]
Markov
a state is Markov if the next state depends only on the current one: "the future is independent of the past given the present". The state is then a sufficient statistic of the future and the history can be thrown away.

The Markov property is what makes DP's one-step recursion valid: the backup reads only the successor's value, never the path that led there. A single Atari frame is not Markov (it shows where the ball is, not where it is going); stacking the last four frames, as DQN does, recovers the velocity (Mnih et al. 2015, Methods). When the agent observes the environment's state directly the problem is fully observable, formally an MDP; all of DP on this page lives there. When it sees the state only indirectly (a robot not told its absolute location, a poker agent that sees only the public cards) it is a partially observable MDP (POMDP), and the agent must build its own state. The language-model case: the state is the prompt plus the tokens so far and appending a token is deterministic, so generation is a fully observable MDP with a trivial, known transition (section 13 says why DP still cannot solve it).

History, agent state, the POMDP choices and notation (depth, 2 min)
Ht = O1, R1, A1, O2, R2, A2, ..., At−1, Ot, Rt
Ht
the history: everything observed up to t. It ends with the latest observation and reward and does not yet contain At, because the agent chooses At from it (putting At into it is a common slip). It grows without bound, which is why agents summarise it.

A state is any function of the history, St = f(Ht). The environment state Set is the environment's private representation, whatever it uses to pick the next observation and reward; it is usually invisible to the agent and may hold irrelevant detail. The agent state Sat = f(Ht) is the agent's own summary, the state RL algorithms work with. The environment state is Markov, and so, trivially, is Ht; the design problem is a compact agent state that is still Markov. Fully observable means Ot = Sat = Set. In a POMDP (also a trading agent that sees only current prices) the three standard agent states are:

  • the complete history, Sat = Ht (a decoder conditioning on its full token prefix makes this choice);
  • a belief: the vector of probabilities (ℙ[Set = s1], ..., ℙ[Set = sn]) over the n possible environment states;
  • a learned recurrent summary, an RNN state Sat = σ(Ws Sat−1 + Wo Ot), with σ an elementwise nonlinearity (logistic sigmoid or tanh), Ws a learned matrix on the previous agent state and Wo one on the new observation.

Notation. Sutton and Barto write the dynamics as one joint p(s′, r | s, a) rather than P and an expected R; they note the MDP literature usually uses the pair, and for DP the two are equivalent because only the expected reward enters the backups (Sutton and Barto, chapter 3 notes).

DP extends to POMDPs by planning over beliefs, which turns a finite problem into one over a continuous belief space (Sutton and Barto, chapter 1 history cites Lovejoy's 1991 survey).

Three objects, each adding one ingredient, on David Silver's student example (Silver, Lecture 2; the diagram in section 3 draws all three):

  1. Markov process (Markov chain) ⟨𝒮, P⟩: a finite state set and a transition matrix Pss′ = ℙ[St+1 = s′ | St = s], each row summing to 1. States Class 1, Class 2, Class 3, Pass, Pub, Facebook and Sleep (terminal). Class 1 goes to Class 2 or Facebook with probability 0.5 each; Class 2 to Class 3 with 0.8 or Sleep with 0.2; Class 3 to Pass with 0.6 or Pub with 0.4; Pass to Sleep with 1.0; Pub to Class 1, 2 or 3 with 0.2, 0.4 and 0.4; Facebook stays with 0.9 and returns to Class 1 with 0.1.
  2. Markov reward process (MRP) ⟨𝒮, P, R, γ⟩: add Rs = 𝔼[Rt+1 | St = s], the expected reward for leaving s, and a discount γ ∈ [0, 1]. Each class gives −2, Facebook −1, Pub +1, Pass +10, Sleep 0. An MRP has a return and a value, but nobody decides anything.
  3. Markov decision process (MDP) ⟨𝒮, 𝒜, P, R, γ⟩: add a finite action set; transitions and rewards now depend on the action, Pass′ = ℙ[St+1 = s′ | St = s, At = a] (written P(s′ | s, a) below) and Ras = 𝔼[Rt+1 | St = s, At = a] (written R(s, a)). In the student MDP: from Class 1, Study (−2, to Class 2) or Facebook (−1); from Facebook, Facebook again (−1) or Quit (0, back to Class 1); from Class 2, Study (−2, to Class 3) or Sleep (0, the end); from Class 3, Study (+10, pass, the end) or Pub (+1, then chance sends you to Class 1, 2 or 3 with 0.2, 0.4 and 0.4).

A policy is a distribution over actions given states, π(a | s); a deterministic policy picks one action, π(s). Fixing a policy turns an MDP back into an MRP, Pπss′ = Σa π(a | s) Pass′ and Rπs = Σa π(a | s) Ras: averaging over the policy's choices removes the agency, which is why evaluating a fixed policy is an MRP problem, and linear (section 4).

2The return, and why to discount

A concrete return first. Start in Class 1 with γ = ½ and sample the episode Class 1, Class 2, Class 3, Pass, Sleep: the rewards for leaving each state are −2, −2, −2 and +10, so the return is −2 + ½(−2) + ¼(−2) + ⅛(10) = −2 − 1 − 0.5 + 1.25 = −2.25. Another episode from the same start, Class 1, Facebook, Facebook, Class 1, Class 2, Sleep, gives −2 − ½ − ¼ − 2/8 − 2/16 = −3.125. The return is a random variable; the value is its average. Averaging samples is what model-free methods do; DP computes the same average exactly from the model.

Gt = Rt+1 + γRt+2 + γ²Rt+3 + ... = Σk=0∞ γk Rt+k+1    and recursively    Gt = Rt+1 + γGt+1
Gt
the return: the total discounted reward from step t on; in an episodic task the sum stops at the terminal step
γ ∈ [0, 1]
near 0 is myopic, near 1 far-sighted. The weights sum to 1/(1 − γ), so γ = 0.9 behaves like a horizon of about 10 steps and γ = 0.99 like 100 derived

The agent maximises cumulative reward, so it can pay to sacrifice reward now (refuelling a helicopter costs time now but may prevent a crash hours later; Silver, Lecture 1). Silver's four reasons to discount: cycles (it keeps returns finite when the chain can loop on Facebook indefinitely); uncertainty (the future, and the model of it, is less certain); convenience (with γ < 1 the Bellman operators are contractions, the reason DP converges, section 9); preference (people and animals prefer reward sooner, and immediate money can earn interest). Undiscounted returns (γ = 1) are fine when every sequence is guaranteed to terminate; LLM RL typically uses γ = 1, because every response ends and the reward arrives at the end.

The value is the average return: sampled means creep toward the exact value DP computes

The line is the running mean of the sampled returns, the dashed line the exact value from the Bellman equation (next section). Episodes of the student MRP from Class 1 are drawn with the chain's own probabilities from a seeded stream (seed 42), so each reset replays the same draws. The mean creeps toward the exact value slowly, because one episode can loop on Facebook for dozens of steps: that slowness is what the model buys you out of.

3Value functions and the Bellman equations

The value is the expected return, which removes the randomness of single episodes. In an MRP, V(s) = 𝔼[Gt | St = s]. In an MDP the return depends on how you act, so values are defined for a policy π, and the two kinds are one step apart:

Vπ(s) = 𝔼π[Gt | St = s] = Σa π(a | s) Qπ(s, a),    Qπ(s, a) = 𝔼π[Gt | St = s, At = a] = R(s, a) + γ Σs′ P(s′ | s, a) Vπ(s′)
Vπ(s)
the state value: expected return from s following π; it averages the action values under the policy
Qπ(s, a)
the action value: take a in s, then follow π. Its right-hand side is the one-step lookahead, the step that needs the model, P and R
𝔼π
an expectation over the randomness of both the policy and the environment

That asymmetry is why Q is what you want for model-free control: acting greedily on Q is argmaxa Q(s, a), a lookup, while acting greedily on V needs the lookahead and so the dynamics (a model-free agent that stores only V cannot pick actions from it). DP has the model, so it works with V and computes Q when it needs it. Optimal values: V*(s) = maxπ Vπ(s) and Q*(s, a) = maxπ Qπ(s, a). An MDP is solved once Q* is known: picking argmaxa Q*(s, a) everywhere is optimal. For any finite MDP an optimal policy π* is at least as good as every other policy in every state, all optimal policies share V* and Q*, and there is always a deterministic one (Silver, Lecture 2).

The Bellman equation cuts a long-horizon problem into one-step pieces, and follows from the return's own recursion: V(s) = 𝔼[Rt+1 + γGt+1 | St = s] = 𝔼[Rt+1 + γV(St+1) | St = s], where the last step replaces the random tail by its expectation, which the Markov property allows. The value of a state is the immediate reward plus the discounted value of the successor. For a known MRP it reads V(s) = Rs + γ Σs′ Pss′ V(s′). Four value functions give four equations:

Expectation (fixed π):   Vπ(s) = Σa π(a | s) [ R(s, a) + γ Σs′ P(s′ | s, a) Vπ(s′) ]
Qπ(s, a) = R(s, a) + γ Σs′ P(s′ | s, a) Σa′ π(a′ | s′) Qπ(s′, a′)
Optimality:   V*(s) = maxa [ R(s, a) + γ Σs′ P(s′ | s, a) V*(s′) ]
Q*(s, a) = R(s, a) + γ Σs′ P(s′ | s, a) maxa′ Q*(s′, a′)
s, a, s′, a′
the current state, an action, a possible next state, the action taken there
bracket
the one-step lookahead value of action a

The expectation equations are linear: one equation per state, as many unknowns as states, so Vπ = Rπ + γPπVπ has the direct solution Vπ = (I − γPπ)−1 Rπ, with column vectors over states and Pπ the MRP's matrix from section 1. Inversion costs O(n³) for n states, so it is only for small problems. The max makes the optimality equations nonlinear: matrix inversion does not solve them, there is no closed form in general, and they are solved iteratively, by value and policy iteration when the model is known (this page) and from samples by Q-learning and SARSA when it is not (Model-free prediction and control). Everything downstream, from value iteration to DQN's TD target to the value model in PPO-based RLHF, is a way of approximately solving one of these equations; the DP algorithms are "little more than these equations turned into assignment statements" (Sutton and Barto §4.8).

Stateγ = 0γ = 0.9γ = 1
Class 1−2.0−5.0−12.5
Class 2−2.00.91.5
Class 3−2.04.14.3
Pass10.010.010.0
Pub1.01.90.8
Facebook−1.0−7.6−22.5

The student MRP solved as V = (I − γP)−1R, Sleep terminal at 0, to one decimal (checked in src/recompute.py).

Reading the numbers. At γ = 0 every value is the immediate reward. At γ = 1 Facebook is the worst state: it loops back with probability 0.9, so the agent stays 10 steps on average at −1 each, then lands in Class 1, worth −12.5, for −22.5 in total. Check Class 3 at γ = 1: V(Class 3) = −2 + 1 × (0.6 × 10 + 0.4 × 0.8) = −2 + 6 + 0.32 = 4.32, the solved 4.3. And reward is not value: Class 2 has reward −2 and value +1.5. In the MDP at γ = 1:

  • Optimal: V* = 6, 8, 10 and 6. The action values say why: Class 1, Study −2 + 8 = 6 against Facebook −1 + 6 = 5; Class 2, Study −2 + 10 = 8 against Sleep 0; Class 3, Study 10 against Pub 9.4 (the hero); Facebook, Quit 0 + 6 = 6 against Facebook −1 + 6 = 5. Reading the policy off Q* needs no knowledge of where the Pub leads; reading it off V* needs the 0.2, 0.4 and 0.4.
  • One step of improvement. The uniform policy's own action values are Qπ(Class 1, Study) = 0.69 against Facebook −3.31; Class 2, Study 5.38 against Sleep 0; Class 3, Study 10 against Pub 4.77; Facebook, Quit −1.31 against Facebook −3.31. Greedy on them is already optimal (Study, Study, Study, Quit Facebook): prediction serving control, the engine of policy iteration (section 6).
The uniform random policy's values, checked (depth)

Each action with probability 0.5, γ = 1: Vπ = −1.3 (Class 1), 2.7 (Class 2), 7.4 (Class 3), −2.3 (Facebook). At Class 3, half the time the Pub and half the time Study: 0.5 × (1 + 0.2 × (−1.3) + 0.4 × 2.7 + 0.4 × 7.4) + 0.5 × 10 = 7.4. The widget's middle mode shows every state's equation.

Correction: Silver's slide prints Q*(Class 3, Pub) = 8.4
The arithmetic gives 1 + 0.2 × 6 + 0.4 × 8 + 0.4 × 10 = 9.4 (the widget computes it). Either way Study, at 10, wins, so the optimal policy is unchanged.

Prediction and control are the two problems these equations pose. Prediction: given a fixed π, compute Vπ or Qπ. Control: find π*, equivalently V* or Q*. You usually solve prediction to solve control: evaluate, improve greedily, repeat. With a model, prediction is policy evaluation (section 4) and control is policy iteration (section 6) or value iteration (section 7).

Every state satisfies its own one-step equation: click a state to check it with the numbers

Values solve the Bellman expectation equation exactly (a 6- or 4-state linear system) or, for the optimal policy, iterate the optimality equation to convergence. At γ = 0, 0.9 and 1 the Markov reward process reproduces the table in Silver's Lecture 2 independently; the slide rounds Class 1 and Facebook at γ = 1 to −13 and −23 (exactly −12.54 and −22.54).

4Backups, sweeps and policy evaluation

Four words recur (Sutton and Barto §4.1). A backup (Sutton and Barto: an expected update) is one application of the right-hand side of a Bellman equation to one state, as an assignment; "expected" because it averages over every possible successor with its probability rather than one sampled successor, which is what a full-width backup means and why it needs the model. A sweep backs up every state once. A synchronous sweep computes every new value from the previous sweep's values, keeping two arrays (Jacobi-style, after Jacobi's method for linear systems). An in-place sweep overwrites as it goes, so later states already see this sweep's new values (Gauss–Seidel-style): one array, usually faster, and then the order in which states are swept matters (section 8); Sutton and Barto "usually have the in-place version in mind" (chapter 4 notes).

Policy evaluation estimates Vπ of a given, fixed policy by turning the expectation equation into that assignment:

Vk+1(s) = Σa π(a | s) [ R(s, a) + γ Σs′ P(s′ | s, a) Vk(s′) ]
Vk
the estimate after k sweeps. Start from any guess, usually zeros, with terminal states at 0; sweep until the largest change, maxs |Vk+1(s) − Vk(s)|, falls below a small threshold θ

Why it converges. Vπ is a fixed point of the update and the backup is a γ-contraction (section 9), so the iteration reaches the unique Vπ from any start. Sutton and Barto's condition is wider: Vπ exists, is unique and is the limit "as long as either γ < 1 or eventual termination is guaranteed from all states under the policy π" (§4.1). Or solve it directly: (I − γPπ)−1Rπ is one linear solve of order n³. Iterative evaluation is "a classical successive approximation algorithm for solving a system of linear equations" (Sutton and Barto, chapter 4 notes); it wins when n is large, when transitions are sparse (a sweep then costs about n times the number of successors), and when a good starting guess exists, as inside policy iteration.

Figure 4.1 in depth: the random policy's values sink sweep by sweep, while the greedy arrows settle long before

  1. k = 0: zeros. Every greedy arrow ties, because every neighbour looks equally worthless.
  2. k = 1: one sweep. Each cell pays −1 whatever it does and reads zeros, so −1.0 everywhere; only the four cells beside a corner get an arrow, into it. Bar height is −V.
  3. k = 2. Cells beside a corner reach −1.75 (a quarter of their moves end at once), the rest −2.0. Close up, the cell right of the top-left corner: each move has probability ¼, so it pays −1 and averages what its four moves land on, 0 in the corner and −1 to the right, below and (bumping the top edge) itself: −1 + ¼ (0 − 1 − 1 − 1) = −1.75.
  4. k = 3: the greedy policy is already optimal. Values between −2.4 and −3.0, far from converged, yet the arrows (orange) are every shortest move to a corner: one greedy improvement now gives π*.
  5. k = 10. Values between −6.1 and −9.0, still sinking; the arrows have not changed since k = 3.
  6. k = ∞: Vπ itself. The exact solution, −14, −18, −20 and −22: minus the expected number of random steps to a corner. Greedy on it gives the same policy.

The standard example (drawn on the right) is Sutton and Barto's 4 × 4 gridworld (Example 4.1): two shaded corners end the episode, every move costs −1, a move off the grid leaves you in place, γ = 1, and the policy picks each move with probability ¼, so Vπ is minus the expected number of steps to a corner. The Sweep lab opens on it, and the greedy policy on its values is optimal from k = 3 on, as Figure 4.1's caption says (book p. 77), long before the values converge.

Figure 4.1, checked (depth)

The lab's computed values reproduce Figure 4.1 independently, 92 of the 96 printed values at two significant digits. The other four are the exact −1.75 at k = 2, printed −1.7 while the same figure prints −2.875 as −2.9: a rounding slip in the figure, not a different computation. Figure 4.1's numbers also require synchronous sweeps; an in-place sweep gives different intermediate values.

5Policy improvement and its theorem

Once you know Vπ, act greedily on it: compute every action's lookahead value and pick the best, π′(s) = argmaxa [ R(s, a) + γ Σs′ P(s′ | s, a) Vπ(s′) ] = argmaxa Qπ(s, a), a new deterministic policy. The student MDP did exactly this in section 3 and got the optimal policy in one step.

The policy improvement theorem (Sutton and Barto §4.2): if deterministic π and π′ satisfy Qπ(s, π′(s)) ≥ Vπ(s) in every state, then Vπ′(s) ≥ Vπ(s) in every state, strictly wherever the premise is strict. In words: taking the better action once and then following π is at least as good as following π, and doing so at every later step only adds improvement. The greedy policy satisfies the premise automatically (the best action's value is at least the policy-weighted average, which is Vπ(s)). And if greedy improvement changes nothing, then Vπ(s) = maxa Qπ(s, a) everywhere, which is the Bellman optimality equation: π is already optimal. So improvement "must give us a strictly better policy except when the original policy is already optimal".

The proof in one line, and ties (depth, 1 min)

Keep expanding the Q side and reapplying the premise:

Vπ(s) ≤ Qπ(s, π′(s)) = 𝔼π′[Rt+1 + γVπ(St+1) | St = s] ≤ 𝔼π′[Rt+1 + γRt+2 + γ²Vπ(St+2) | St = s] ≤ ... ≤ 𝔼π′[Rt+1 + γRt+2 + γ²Rt+3 + ... | St = s] = Vπ′(s)

Stochastic policies and ties. The theorem carries over to stochastic policies. When several actions tie for the max, the new policy may split its probability among them in any way, as long as every non-maximising action gets zero; Figure 4.1's right column draws an arrow for every tied action for this reason.

6Policy iteration: control with an explicit policy

Alternate the two steps until the policy stops changing: evaluate the current policy (sweeps until the values settle, or the linear solve), then improve it greedily. The chain π0 → Vπ0 → π1 → Vπ1 → ... → π* → V* has each policy strictly better than the last unless already optimal (Sutton and Barto §4.3). Start each evaluation from the previous policy's values: this "typically results in a great increase in the speed of convergence of policy evaluation (presumably because the value function changes little from one policy to the next)".

Why it terminates. A finite MDP has mn deterministic policies for m actions and n states; each improvement is at least as good everywhere and strictly better somewhere unless optimal, so no policy repeats and the loop ends at a policy that satisfies the optimality equation. In practice it needs very few outer iterations, because the policy changes in whole jumps and often becomes optimal long before its values converge: on Figure 4.1's gridworld it "would find the optimal policy after just one iteration"; on Jack's car rental (Example 4.2: two locations with up to 20 cars each, Poisson rentals and returns, γ = 0.9) π0, ..., π4 reach the optimum in four improvements (Figure 4.2). On the Sweep lab's worlds it stops after 2 improvements on both 4 × 4 grids, 3 on the Dyna maze and 5 on Russell and Norvig's 4 × 3 world.

The tie bug
As written, the stopping test "the policy did not change" may never fire if ties in the argmax are broken arbitrarily: the policy can flip forever between equally good actions while the values stay put. Sutton and Barto leave this as Exercise 4.4 ("a subtle bug ... okay for pedagogy, but not for actual use"; Exercise 4.4). Fix: keep the current action unless another is strictly better, or stop when the values stop changing. The Sweep lab keeps the current action among ties.

Evaluation does not have to converge. Stopping evaluation after k sweeps and improving anyway still reaches the optimal policy: modified policy iteration (Puterman and Shin 1978), which contains policy iteration (k → ∞) and value iteration (k = 1) as special cases. In Silver's 4 × 4 gridworld (Figure 4.1's) k = 3 evaluation sweeps were already enough for the greedy policy to be optimal (Silver, Lecture 3). One catch, found while building the old version of this page: with truncated evaluation, "the policy did not change" no longer proves optimality, because the values the policy was greedy on were not yet its own. Stop only when the policy is unchanged and the values have stopped changing.

Generalised policy iteration (GPI) is the general pattern: any interleaving of some evaluation with some improvement, at any granularity, down to a single state. "As long as both processes continue to update all states, the ultimate result is typically the same, convergence to the optimal value function and an optimal policy" (Sutton and Barto §4.6). The two compete (making the policy greedy makes the values wrong for it; making the values right makes the policy no longer greedy) and cooperate: both stabilise only when the policy is greedy on its own value function, which is the optimality equation. "Almost all reinforcement learning methods are well described as GPI", PPO included (section 13).

7Value iteration: the optimality equation as the update

Turn the Bellman optimality equation itself into the assignment, with no policy stored anywhere, and watch it on Silver's shortest-path grid: a 4 × 4 grid, one goal in the corner, −1 per move, γ = 1, values from zeros.

Vk+1(s) = maxa [ R(s, a) + γ Σs′ P(s′ | s, a) Vk(s′) ]    here:   Vk+1(s) = max over the four moves of (−1 + Vk(neighbour))
maxa
over every action available in s; Vk is the estimate after k synchronous sweeps; stop when the largest change falls below θ, then read the policy off once, greedily, with the same bracket

Values sweep out from the goal one cell per sweep: within k moves they are exact, beyond they all say −k

Predict before it plays: after 2 sweeps, what does the far corner (6 moves from the goal) hold, and which way does its greedy arrow point?

  1. Start: every value 0. The goal is terminal and stays 0. Every move ties, because every neighbour looks equally worthless: the values carry no information yet.
  2. Sweep 1: every cell becomes −1. Each non-goal cell pays −1 for any move and every neighbour is still 0. Only the cells next to the goal are right, and only they get an arrow: their move into the goal is the only one that does not land on a −1.
  3. Sweep 2: the answer to the prediction. Cells two moves away hold −2 and point the shortest way; every cell farther out also says −2, a number that is no policy's value: the far corner says −2 while it is six moves away, and all four of its moves tie, so its values carry no direction yet.
  4. Sweep 3. The reward information has travelled three steps back from the goal: cells within three moves are exact, the rest say −3.
  5. Sweep 4. The front moves one cell further: cells within four moves are exact, and the cells that changed (orange) are exactly those still farther out.
  6. Sweep 5. Only the three cells farthest from the goal still change.
  7. Sweep 6: the far corner reaches −6. The values are now the true distances, 0 to −6, and the arrows are every shortest move. Six sweeps, because the far corner is six moves away.
  8. Sweep 7: nothing changes, converged. A full sweep moved no value; the seventh only confirms.

Synchronous value iteration computed live by the page's engine (checked against src/recompute.py). Bar height is −V; orange bars changed in the sweep just shown, and the ringed cell is the backup worked out above, fed by streams from the four cells it reads; during each step a glass plane crosses the grid, and each column takes its new value as the plane reaches it (all computed from the previous sweep's values); arrows are greedy on the current values, every tied action drawn. The frames reproduce Silver's slide independently: his V1 is the all-zero start, V2 = −1 everywhere but the goal, V3 = −2 in most cells, and V7 holds the true distances, 0 to −6 (his Vk+1 is the frame after k sweeps here).

What the sweeps show. It looks like policy evaluation with one difference: each sweep takes a max over actions rather than an average under some π. Equivalently, each sweep is one evaluation sweep of the policy that is greedy on the current values, so value iteration is policy iteration with evaluation cut to a single sweep (Sutton and Barto §4.4). Silver's intuition: "start with final rewards and work backwards"; it "still works with loopy, stochastic MDPs". As step 3 shows, the intermediate value functions need not be the value of any policy; only the limit is, and it is the optimal policy's (Silver, Lecture 3). Formally value iteration converges only in the limit, but the greedy policy becomes optimal after finitely many sweeps (Bertsekas 1987, cited in Sutton and Barto's notes). Between the extremes, "faster convergence is often achieved by interposing multiple policy evaluation sweeps between each policy improvement sweep" (§4.4): modified policy iteration again.

A showcase: the gambler's problem, value iteration on 99 states (depth, 2 min, live chart)

Sutton and Barto's Example 4.3 (book p. 84): a gambler with capital s from 1 to 99 stakes any whole number from 1 to min(s, 100 − s) on a coin that comes up heads with probability ph; heads doubles the stake, reaching 100 pays +1, everything else 0, γ = 1, so the value is the probability of winning. In-place value iteration from zeros, as in the book's box, until no value moves by more than 10−12. With ph = 0.4 the optimal policy is famously curious: at capital 50 bet everything, at 51 bet a little. At ph = 0.4 it converges after 22 in-place sweeps (checked in src/recompute.py). The policy is optimal but not unique: a whole family of optimal policies comes from ties in the argmax (Exercise 4.8 asks why).

after sweeps 1, 2 and 3final value function
smallest optimal stakeother stakes tied for the best (within 10−9)

Reproduces Figure 4.3 in shape only: the book gives the curves as an image, which this page never reads numbers from. What the text states does hold: at ph = 0.4 the policy bets everything at 50 but not at 51, and many optimal policies exist. At ph = 0.55 the smallest stake is optimal everywhere: when the coin favours you, play many small rounds (at exactly 0.5 every stake ties) derived.

The same corridor, one backup per step: in place in the order the reward flows converges in one sweep

8Sweep order and policy iteration on one corridor

Three states in a row, A, B and C, with a terminal goal G to the right of C. Two deterministic actions, left and right. Moving right from C enters G, earns 10 and ends the episode; every other move earns 0; left from A bumps the wall and stays. γ = 0.9 and V(G) = 0. Synchronous value iteration backs up V(A) ← max(0.9 V(A), 0.9 V(B)), V(B) ← max(0.9 V(A), 0.9 V(C)) and V(C) ← max(0.9 V(B), 10 + 0.9 × 0).

SweepV(A)V(B)V(C)What happened
0000Initial guess
10010C: right gives 10 + 0.9 × 0 = 10, left gives 0.9 × 0 = 0
20910B: right gives 0.9 × 10 = 9
38.1910A: right gives 0.9 × 9 = 8.1
48.1910No change: converged

So V* = (8.1, 9, 10), right in every state; after k synchronous sweeps only rewards up to k steps away have been seen. Predict: if the sweep goes in place in the order C, B, A, how many sweeps does it take? And in the order A, B, C?

    Every number is computed live by the page's engine and checked against src/recompute.py; the defaults reproduce the table above, which comes from the old version of this page, independently. The line under the cells gives the values the backup reads: the previous sweep's (synchronous) or the current array (in place). The random-policy evaluation steps through its first three sweeps backup by backup, then jumps to sweep 40.

    The answer. In place in the order C, B, A converges in a single sweep (C becomes 10, then B sees the new C and becomes 9, then A becomes 8.1); in the order A, B, C it is no faster than synchronous here. That is why sweep order matters for in-place DP. Policy iteration on the same corridor, from the uniform random policy: its values converge to Vπ ≈ (4.29, 5.24, 7.36); greedy on them, right wins everywhere (in A, left 0.9 × 4.29 = 3.86 against right 0.9 × 5.24 = 4.72; in C, right 10 against 4.72), so one improvement gives the optimal policy, evaluating it gives (8.1, 9, 10), and policy iteration stops after two outer iterations. Evaluation did not need to converge: after only three sweeps, with values (1.0125, 2.25, 6.0125), the greedy comparison is already right everywhere. That is modified policy iteration paying off.

    The evaluation numbers sweep by sweep (depth, 1 min)

    Evaluation backups for the random policy: V(A) ← 0.45 V(A) + 0.45 V(B), V(B) ← 0.45 V(A) + 0.45 V(C) and V(C) ← 0.45 V(B) + 5, where 0.45 is 0.5 × 0.9 and 5 is 0.5 × 10. From zeros the sweeps give (0, 0, 5), then (0, 2.25, 5), then (1.0125, 2.25, 6.0125), then (1.4681, 3.1612, 6.0125), converging to the exact solution of the three linear equations. Improvement on the converged values: in B, left 3.86 and right 0.9 × 7.36 = 6.62; in C, left 0.9 × 5.24 = 4.72. After three sweeps: in A, right is 0.9 × 2.25 = 2.025 against left 0.9 × 1.0125 = 0.91; in B, 5.41 against 0.91; in C, 10 against 2.025.

    9Why it converges, and how fast

    Measure the distance between two value functions by the largest difference in any state, ‖u − v‖∞ = maxs |u(s) − v(s)|, and write T for one synchronous sweep (expectation backup for a fixed π, or optimality backup). Both are γ-contractions (Silver, Lecture 3):

    ‖Tu − Tv‖∞ ≤ γ ‖u − v‖∞   ⇒   ‖Vk − V*‖∞ ≤ γk ‖V0 − V*‖∞   ⇒   k ≥ ln(1/ε) / ln(1/γ) sweeps cut the error by 1/ε
    why
    for the expectation backup the rewards cancel and what is left is γ times an average of differences, at most γ times the largest; for the optimality backup, |maxa f(a) − maxa g(a)| ≤ maxa |f(a) − g(a)| finishes the argument
    then
    by the contraction mapping theorem (Banach's fixed-point theorem) repeated sweeps converge to a unique fixed point (Vπ or V*) from any start, at a linear rate; the second inequality uses TV* = V*

    How many sweeps. With γ = 0.9, cutting the error by a factor of 1,000 takes 66 sweeps (0.966 ≈ 0.00096); with γ = 0.99 it takes 688 derived. Since ln(1/γ) ≈ 1 − γ, the sweep count grows like the effective horizon 1/(1 − γ): rewards that far away still matter, and each sweep reaches one step further.

    A small change is not a small error. If one sweep changes no value by more than θ, the contraction gives ‖Vk+1 − V*‖∞ ≤ γθ/(1 − γ): with γ = 0.99 and θ = 0.001 the values can still be off by up to 0.099, about a hundred times the last change. A small error is a small loss, though: acting greedily on any V with ‖V − V*‖∞ ≤ ε loses at most 2γε/(1 − γ) of return in any state (Singh and Yee 1994, in the form given by RL Theory, lecture 3).

    Without discounting. At γ = 1 there is no contraction, yet Figure 4.1, Silver's shortest path and the 4 × 3 world all use γ = 1 and converge. What saves them is termination: if every policy evaluated eventually reaches a terminal state (a "proper" policy), the sweeps still converge, a stochastic-shortest-path result outside this page's scope (Bertsekas and Tsitsiklis 1996). Drop that and an undiscounted evaluation of a policy that loops forever on a −1 reward runs off to −∞. γ = 1 is not wrong in itself: it is standard when every episode terminates, as in LLM RL.

    The standard iteration count (depth)

    Szepesvári's lecture notes give the usual form: k ≥ ln(1/(ε(1 − γ)))/(1 − γ) iterations bring value iteration within ε of V* (RL Theory, lecture 3). It follows from the bound above: with rewards in [0, 1] and V0 = 0 the starting error is at most 1/(1 − γ), and ln(1/γ) ≥ 1 − γ derived.

    Two runs from different starts close in at least as fast as γk: the contraction, sweep by sweep
    error from zeros, ‖Vk − V*‖error from −1/(1 − γ) everywhere (−100 at γ = 1)gap between the two runsbound γk × the starting gap

    Predict, then drag γ to 0.99 and to 1: what happens to the grey bound, and do the runs still converge? Russell and Norvig's 4 × 3 world (section 13 and the Sweep lab), synchronous value iteration, log scale. The gap between the runs (purple) never rises above the bound (grey), checked sweep by sweep in src/recompute.py at γ = 0.5, 0.9 and 0.99. The errors fall faster than the bound because the bound is a worst case and the 4 × 3 world's paths end within a few steps. At γ = 1 the bound is flat and useless, yet both runs still converge: termination, not contraction.

    10Policy iteration against value iteration

    Policy iterationValue iteration
    What is storedPolicy-based: an explicit policy is stored and improvedValue-based: no explicit policy until the end
    Update ruleBellman expectation equation, plus greedy improvementBellman optimality equation directly
    Intermediate valuesAt every step, V corresponds to some actual policyIntermediate V may correspond to no policy; only the final V is (the optimal) one's
    Per-sweep costAn evaluation sweep under a deterministic policy reads one action per state, cheaper than a value-iteration sweep by a factor of the number of actions; only the improvement step reads all actions. But evaluation is a loop inside the outer loopEvery sweep maxes over all actions; a single loop
    Typical behaviourFew outer iterations; the policy often stabilises before the values fully convergeMore sweeps, each simple
    Stops whenThe policy does not change: an exact, finite stopping pointThe largest change in a sweep is below a threshold: approximate

    Both need the model and converge to the same V* and π*. "Both policy iteration and value iteration are widely used, and it is not clear which, if either, is better in general" (Sutton and Barto §4.7). Policy iteration wins when evaluation is cheap (few actions, or an affordable linear solve), value iteration when each state has many actions or the policy would change many times; modified policy iteration, with a handful of evaluation sweeps per improvement, sits between them and is often the practical choice. Counting model look-ups in the Sweep lab makes the trade concrete: to reach an error of 10−4 on the 4 × 4 grids, policy iteration needs about 60 to 80 times as many look-ups as value iteration, most of them spent evaluating the starting random policy at γ = 1, while modified policy iteration with three sweeps comes within a factor of 1.6 of value iteration; on the 4 × 3 world it beats value iteration (1,581 look-ups against 2,112).

    Worst-case complexity, known results (depth)
    • Policy iteration: at most Õ(nm/(1 − γ)) improvements for fixed γ, independent of the reward's precision: strongly polynomial (Ye 2011; bound as in RL Theory, lecture 4).
    • Value iteration: O(mn² ln(1/δ)/(1 − γ)) operations for a δ-optimal answer; its dependence on δ is not needed in principle, since Ω(n²m) operations are a lower bound for any method (RL Theory, lecture 3).

    11Cost, scale and the curse of dimensionality

    One sweep backs up every state, and each backup reads every action and every possible successor. With n states and m actions a sweep over state values costs O(mn²); a sweep over action values Q(s, a) costs O(m²n²), because there are mn entries and each backup reads mn successor pairs (Silver, Lecture 3). Those are dense worst cases: in a gridworld each action has at most three successors, so a sweep costs about 3mn look-ups, which is what the Sweep lab counts derived.

    DP is exponentially faster than searching policies. "In the worst case, the time that DP methods take to find an optimal policy is polynomial in the number of states and actions", although there are mn deterministic policies, each of which direct search would have to examine for the same guarantee (Sutton and Barto §4.7). In practice DP handles millions of states (Silver; Sutton and Barto) and "usually converge[s] much faster than [its] theoretical worst-case run times, particularly if [started] with good initial value functions or policies".

    The curse of dimensionality (Bellman's phrase) is the catch: states multiply with every state variable. Predict before moving the sliders: ten variables with ten values each make how many states? Then try twenty.

    Ten variables with ten values each already make ten billion states, and at that size even one backup can be too expensive. Backgammon has over 1020 states; Sutton and Barto note that at a million backups a second one sweep would take "over a thousand years" (§4.5), an understatement: 1020/106 seconds is about 3.2 million years derived. Large state sets are "inherent difficulties of the problem, not of DP as a solution method": DP copes with them better than direct search or linear programming.

    The linear-programming view (depth, 1 min)

    V* is the smallest function that satisfies every one-step inequality, so it solves a linear program: minimise Σs c(s) V(s) subject to V(s) ≥ R(s, a) + γ Σs′ P(s′ | s, a) V(s′) for every state and action, with any positive weights c; n variables and nm constraints (one inequality per action is how the max of the optimality equation becomes linear). Its dual has one variable per state-action pair, the discounted occupancy measure (how often the policy visits each pair), and the optimal policy read from it does not depend on the weights (Mahajan, Stochastic control notes, linear programming, written for costs, so the inequalities flip). An off-the-shelf solver returns exactly the V* that value iteration converges to on the 4 × 3 world (9 variables, 36 constraints), Figure 4.1's grid and the Dyna maze derived, checked in src/recompute.py. Linear programming can have better worst-case guarantees than DP, but "become[s] impractical at a much smaller number of states than do DP methods (by a factor of about 100)" (§4.7). The dual view returns in constrained MDPs and offline RL, where occupancy measures are the natural variable, and de Farias and Van Roy built approximate DP on it (de Farias and Van Roy 2003).

    States grow exponentially with the number of variables; one sweep soon takes years

    States n = (values)variables; look-ups per value-iteration sweep: mn² if every state can lead to every state, mnb with b = 3 successors per action as in the grids here; deterministic policies mn. The time assumes 109 look-ups a second, an illustrative rate.

    12Asynchronous DP: in place, prioritised, real time

    Asynchronous DP backs up states in any order rather than in systematic sweeps, "using whatever values of other states happen to be available"; some states may be updated several times before others once. It converges "given only that all states occur in the sequence {sk} an infinite number of times" for 0 ≤ γ < 1; the order can even be random (Sutton and Barto §4.5). It does not necessarily mean less computation: it means never getting "locked into any hopelessly long sweep before it can make progress", and freedom to choose which states to back up (Silver, Lecture 3; Bertsekas 1982, 1983). The Sweep lab races these on the same world with the same budget of model look-ups.

    • In-place DP: one array, each backup immediately visible to the next (the corridor of section 8 converges in one sweep with the right order). In the Sweep lab's Dyna maze, in-place value iteration in reverse reading order reaches an error of 10−4 with a third of the look-ups synchronous sweeps need (920 against 2,760; in reading order it needs 2,208): which order helps depends on where the reward sits.
    • Prioritised sweeping: back up the state with the largest Bellman error, |maxa(R + γΣPV) − V(s)|, kept in a priority queue; after each backup update the priorities of the affected states, which needs the reverse dynamics (predecessor states). The Sweep lab's model-known version pushes γ × P(s | p, a) × |change| onto each predecessor p: on the Dyna maze it needs 965 look-ups against 2,760 for synchronous sweeps.
    • Real-time DP (RTDP): back up only the states an agent actually visits while acting greedily on the current values, so computation goes where experience goes. On Sutton and Barto's racetrack it needed about half the updates of Gauss–Seidel value iteration for an equally good policy (numbers below). Trajectory sampling at scale is Model-based RL and planning's.
    The published numbers: prioritised sweeping and the racetrack (depth, 1 min)

    Prioritised sweeping was developed independently by Moore and Atkeson and by Peng and Williams in 1993 (Sutton and Barto §8.4 and notes); it solved a rod-manoeuvring task with 14,400 potential states that is "probably too large to be solved with unprioritized methods".

    On Sutton and Barto's racetrack (9,115 reachable states, only 599 relevant), Gauss–Seidel value iteration converged in 28 sweeps and 252,784 updates, about twice as fast as the Jacobi version; RTDP needed 127,600 updates over 4,000 episodes, about half, and left about 290 states never updated, with both policies averaging 14 to 15 steps (Sutton and Barto §8.7, Example 8.6; Barto, Bradtke and Singh 1995).

    13Beyond DP: drop the model, drop the table

    Past millions of states, either the model has to go or the table has to go. Sample backups replace the full sum over successors with one sampled transition ⟨S, A, R, S′⟩: they need no model, and the cost of a backup becomes "constant, independent of n", which "breaks the curse of dimensionality through sampling" (Silver, Lecture 3). Predict: on the same 9-cell world, how many sampled transitions does Q-learning need to get within a few hundredths of what value iteration reaches in about 20 sweeps?

    One world, two ways to get its values: sweep the model, or learn from samples

    1. Before any sweep. Non-terminal values start at 0; the exits hold +1 (green) and −1 (red), the grey block is the wall. Bar height is V.
    2. Sweep 1. Every cell pays −0.04 and reads zeros, except the cell beside the +1: −0.04 + 0.8 × 1 = 0.760, using the model's 0.8 for the intended move. Close up, the glass plate is that model: moving right lands on the +1 with 0.8, slips up into the wall and stays with 0.1, slips down with 0.1, and each outcome's value streams in with its probability.
    3. Sweep 2. Information spreads one step per sweep: the +1 is now felt two moves away (0.832 beside the exit, 0.560 and 0.464 one cell further).
    4. Sweep 3. Three moves away: the top-left corner now sees the +1 (0.392), while four cells, most of the bottom row and the left middle, still hold only step costs (−0.12).
    5. Sweep 5. Every cell now knows of an exit; the largest gap to the final values is down to 0.54.
    6. Sweep 10. The largest gap is 0.065, and every arrow but one is already optimal: the bottom row's third cell still points up, beside the −1, and turns left at sweep 12.
    7. Sweep 20: converged. Every cell matches AIMA's Figure 17.3 to three decimals. Note the bottom row: the cell second from the right goes left, the long way round, rather than up beside the −1 exit, where every move risks a 10% sideways slip into it.

    Russell and Norvig's 4 × 3 world (AIMA, Figure 17.1; the book's code): each move goes where intended with probability 0.8 and sideways with 0.1 each; bumping a wall stays put; every step costs 0.04; the two exits pay +1 and −1; γ = 1. Value iteration converges on exactly the utilities printed in AIMA's Figure 17.3 (0.812, 0.868, 0.918 on the top row; 0.762 and 0.660 in the middle; 0.705, 0.655, 0.611, 0.388 on the bottom), reproduced independently. The Q-learning agent never sees the 0.8 and 0.1: it starts each episode in a random cell, behaves ε-greedily (ε = 0.3), updates Q(s, a) toward −0.04 + maxa′ Q(s′, a′) with step 1/N(s, a)0.8, and shows maxa Q. Its run is one seeded draw; the step-size and start settings are illustrative.

    The answer. Value iteration reaches AIMA's values in about 20 sweeps, each touching all 9 states with 4 actions and 3 outcomes, and it never moves the agent. Q-learning gets within a few hundredths of the same numbers only after thousands of episodes and more than ten thousand transitions, and its rarely visited cells (bottom right, next to the −1) lag longest. The model buys exactness and speed; samples buy independence from the model. Step 7 of the value-iteration run shows what optimal means under risk.

    Where DP lives on. Replace the expectation by one sample and the backup is the TD target (Q-learning is sampled value iteration); replace the table by a network and it is approximate DP, DQN; keep evaluate-then-improve with both approximated and it is GPI, the shape of PPO. Token generation even has the known model DP needs, but every possible prefix is a state, so LLM RL samples instead.

    Each connection, with the page that owns it (links, 1 min)
    • The one-step backup is the template for every target: V(s) ← r + γV(s′) is a DP backup with the expectation replaced by one sample. It is the TD target, and Q-learning is the sampled form of value iteration (Model-free prediction and control). Approximate DP replaces the table with a function approximator and backs up only sampled states, as in fitted value iteration; DQN regresses a network onto the same target (Value-based deep RL), and GAE (generalised advantage estimation) is built from the TD errors r + γV(s′) − V(s) that the critic in PPO produces (RL for LLMs).
    • GPI is the shape of nearly every RL algorithm, including PPO for RLHF: the critic update is approximate policy evaluation and the policy-gradient step approximate improvement (Policy gradients and actor-critic). AlphaZero is GPI with Monte Carlo tree search as the improvement operator (Model-based RL and planning).
    • Token generation is an MDP with a trivial, known transition (append the token), so the model DP needs is available; what makes DP impossible is the size of the state space, every possible prefix, which is why LLM RL samples instead (RL for LLMs; the RL stage of post-training is on Alignment: SFT, RLHF, DPO family, RLVR).
    • Offline RL reuses the occupancy-measure view (section 11) and the danger of acting greedily on values the data never checked (Offline RL and imitation); bandits are the one-state MDP where planning is trivial and only exploration is left (Bandits and exploration). Topic: rl's Method atlas and Taxonomy tabs place value and policy iteration on every axis.

    Depth: history and mistakes

    Where the equations and the algorithms come from (history, 2 min)
    • Hamilton and Jacobi to Bellman. "Optimal control" came into use in the late 1950s. One approach, developed in the mid-1950s by Richard Bellman and others, extended a nineteenth-century theory of Hamilton and Jacobi: it uses a dynamical system's state and a value function, or "optimal return function", to define a functional equation, now called the Bellman equation; the class of methods that solve it came to be known as dynamic programming (Sutton and Barto §1.7). Bellman called the optimality equation the "basic functional equation"; its continuous-time, continuous-state counterpart is the Hamilton–Jacobi–Bellman equation (Sutton and Barto, chapter 3 notes).
    • The name. "The term dynamic programming is due to Bellman (1957a)", the book Dynamic Programming (Sutton and Barto, chapter 4 notes). Bellman later wrote that he picked it in 1950 at RAND so that the work would not sound like mathematical research to the Secretary of Defense, Charles Wilson, who disliked the word: "dynamic" because it was "impossible to use ... in a pejorative sense", and "programming" in the military sense of planning schedules and logistics, as in linear programming, not writing code (Dreyfus 2002, Operations Research 50(1), reprinting the autobiography). Russell and Norvig point out that the story "cannot be strictly true": Bellman's first paper using the term (1952) predates Wilson's appointment in 1953 (quoted in Wikipedia, Dynamic programming: History). The phrase curse of dimensionality is Bellman's too.
    • MDPs and value iteration. Bellman also introduced the discrete stochastic version of the optimal control problem, Markov decision processes (Bellman 1957, "A Markovian Decision Process", J. Math. Mech. 6). Value iteration, the successive-approximation solution of his equation, is his; it predates policy iteration, though textbooks now present it as truncated policy iteration (the Method atlas tab of Topic: rl places it first among 47 methods).
    • Policy iteration. "The policy improvement theorem and the policy iteration algorithm are due to Bellman (1957a) and Howard (1960)", Ronald Howard's Dynamic Programming and Markov Processes. Modified policy iteration, which contains both policy and value iteration as special cases, is due to Puterman and Shin (1978); asynchronous DP to Bertsekas (1982, 1983), who called it distributed DP; and the contraction-mapping treatment of DP to Denardo (1967) (Sutton and Barto, chapter 3 and 4 notes).
    • DP meets RL. The first connection was a footnote by Minsky (1961) on Samuel's checkers player, which may have led AI researchers to think DP applied only to analytically tractable problems; Werbos (1977) proposed "heuristic dynamic programming"; Watkins (1989) called a class of RL methods "incremental dynamic programming" and made the most influential link between RL and MDPs, with Q-learning (same source).
    Mistakes worth checking for (each points to the section that shows it)
    • Calling DP learning. It never interacts with an environment; it computes from a model it is given (the idea in one screen).
    • Treating the optimality equation as linear. Matrix inversion solves the expectation equation for a fixed policy, not the optimality equation (section 3).
    • Reading value iteration's intermediate values as a policy's value. Before convergence they may belong to no policy (section 7, frame 2).
    • Trusting a small last change. A last change of θ can hide an error of up to γθ/(1 − γ), a hundred times θ at γ = 0.99 (section 9).
    • Letting policy iteration flip between equally good actions, or stopping modified policy iteration on an unchanged policy alone (section 6).
    • Assuming full evaluation is required before improving. A few sweeps are usually enough; one sweep is value iteration (sections 6 and 8).
    • Blaming the curse of dimensionality on DP (section 11), or treating DP as obsolete: its evaluate-then-improve structure and its backup are inside every modern RL algorithm (section 13).