Finite-Horizon Dynamic Programming and the Principle of Optimality
Anchor (Master): Bertsekas 2017 Dynamic Programming and Optimal Control 4e (Athena Scientific) Vol. 1 Ch. 1 (the full finite-horizon theory: perfect-state-information basic problem, the DP algorithm and its optimality proof, the deterministic shortest-path reduction, and state augmentation for delays and correlated disturbances); Puterman 1994 Markov Decision Processes (Wiley) Ch. 4 (finite-horizon MDPs and the optimality equations)
Intuition Beginner
Some decisions cannot be made one at a time in isolation, because each choice changes the situation you face next. A delivery driver picking the next street, a chess player choosing a move, a company deciding how much to produce this month — in every case a good choice now is good only if it sets up good choices later. Dynamic programming is the method for these staged problems. It asks not "what is the best single move?" but "what is the best whole plan, accounting for everything that follows?"
The core trick is to work backward. Imagine you are one step from the finish. There is no future left to worry about, so the best move is whatever costs the least right now. Now step back one stage. You do not need to re-plan the whole future, because you already know the best cost from every place the next stage could land you. You only weigh your current options against those already-computed future costs. Keep stepping backward, stage by stage, until you reach the start.
This is the principle of optimality, and it is almost a tautology once stated: any piece of a best plan must itself be a best plan for the situation it starts from. If some later stretch of your route could be improved, then your supposedly best plan was not best after all. Because of this, the enormous problem "find the best plan over all stages at once" breaks into a chain of small problems, one per stage, each solved by looking only one step ahead at a stored summary of the future.
The payoff is that a search which would otherwise explore an explosion of full plans collapses into a tidy backward sweep that visits each situation once.
Visual Beginner
Picture a small map laid out in columns, one column per stage, where you must travel from a start node on the left to a goal on the right, paying a labeled toll on each arrow you cross. Working backward, you write next to every node the cheapest total toll from that node to the goal.
The boxed number at a node is its cost-to-go: the best you can do from there onward. The rule that fills each box is to look one arrow ahead, add the arrow's cost to the box already written at the node it points to, and keep the smallest such sum. The bold arrow records which choice achieved it.
| stage you are filling | what you already know | how you fill a box |
|---|---|---|
| the goal column | nothing left to pay | box = |
| one stage before the goal | the goal boxes | box = cheapest arrow cost to the goal |
| any earlier stage | all later boxes | box = min over arrows of (arrow cost + next box) |
Reading the bold arrows forward from the start spells out the best plan, even though every box was computed backward.
Worked example Beginner
A small factory plans production for months to meet a fixed demand, choosing each month how many units to make. The "state" is the units already in stock at the start of a month. To keep arithmetic clean, suppose the stock can be or unit, each month you may produce or unit, producing costs per unit, and holding leftover stock to the next month costs per unit. Demand is unit each month, and you must never run short. At the end (after month ) leftover stock is worthless but not penalized.
Stage labels: decisions are made at the start of month (call it ) and month (); is the end.
End values (). Whatever stock remains costs nothing more: and .
Month (). You need unit to meet demand. If you start with stock , produce : cost , ending stock , so . If you start with stock , you must produce : cost , ending stock , so .
Month (), starting from stock . Demand is , so you must have a unit this month. Option A: produce , use it, end with stock , carry nothing. Cost now , plus , total . Option B: produce — not allowed, the cap is . So with a start of you cannot stock ahead here; the only feasible plan costs . Suppose instead the start were stock : produce this month (cost ), use the unit, end at stock , then , total .
What this tells us: from an empty start the best two-month cost is , achieved by producing exactly to meet each month's demand. Each monthly choice was decided by adding its immediate cost to a future cost already computed and stored — never by re-examining the whole plan. That backward bookkeeping is the entire method.
Check your understanding Beginner
Formal definition Intermediate+
A discrete-time controlled dynamical system over a horizon of stages is specified by, for each stage : a state space , a control space , a nonempty admissible-control set for each state , a disturbance space , a system map , and a disturbance distribution on that may depend on the current state and control but not on the past. The state evolves by
with initial state . The dependence of the disturbance law on only is the controlled-Markov structure of 37.05.01; expectations below are over the disturbances on a probability space 37.01.01.
A (deterministic Markov) policy is a tuple of functions with for all ; such a is admissible, and denotes the set of admissible policies. Under the controlled system is a Markov chain with .
Given stage-cost functions for and a terminal cost , the expected cost of from is
the expectation taken over with . The basic problem (perfect state information) is to minimize over ; the optimal cost is
and a attaining it is an optimal policy. The deterministic problem is the special case where each is a point mass, so drops out and along the deterministic trajectory.
The cost-to-go (value) functions , , are defined by the backward recursion
This recursion is the DP algorithm; the right-hand side is the stage- Bellman operator applied to . The symbols (state), (control), (disturbance), (cost-to-go), (policy cost), (optimal cost), and (admissible set) are recorded in _meta/NOTATION.md.
Counterexamples to common slips Intermediate+
"Optimizing each stage's immediate cost separately gives the optimal policy." Greedy stage-wise minimization of alone ignores how a control reshapes the future state. In the worked factory example, producing the cheapest amount each month locally would fail to stock ahead when stocking ahead lowers total cost; only the cost-to-go , not alone, carries that future information.
"The cost-to-go depends on how the chain reached state ." It does not. Because the disturbance law depends only on — the controlled-Markov property
37.05.01— the optimal remaining cost from at stage is a function of alone. A policy that tried to use past states could not beat the state-feedback optimum; this is what makes Markov policies suffice for the perfect-information problem." is the definition, not a theorem." The function is built by the backward recursion above, while is an infimum over all policies of an expectation. That these coincide is the content of the optimality theorem; equating them by fiat skips the interchange of the policy-infimum with the staged expectation.
"State augmentation changes the problem." When the disturbance is correlated or the dynamics involve a delay, one enlarges the state (e.g. ) so that the augmented system is again controlled-Markov. The augmented problem has the same optimal cost and policy as the original; augmentation is a reformulation that restores the Markov structure the DP algorithm requires, not a different optimization.
Key theorem with proof Intermediate+
The signature result is that the DP algorithm solves the basic problem: the backward recursion computes the optimal cost and a greedy policy read from it is optimal. It is the single statement that justifies replacing one optimization over all policies by separable one-stage optimizations.
Theorem (principle of optimality and optimality of the DP algorithm). Let be generated by the DP algorithm, and assume that for each and each the infimum defining is attained by some (e.g. when each is finite). Then for every ,
and the policy is optimal: .
Proof. For an admissible policy define its tail cost-to-go from stage ,
so and . Conditioning on the stage- disturbance and using that, given and , the future evolves as the chain started from under — the controlled-Markov property 37.05.01 — the tower property of conditional expectation 37.01.01 gives the one-step identity
Lower bound: for every admissible and all , by downward induction on . At , . Assume pointwise. Then for any , monotonicity of expectation in the integrand gives
the last inequality because is one admissible choice in the infimum. This closes the induction, so in particular for every , whence .
Attainment: for the greedy policy , for all , again by downward induction. At both equal . If , then by the one-step identity with ,
the second equality because attains the infimum defining . Hence . Combining, , so all three coincide and is optimal.
Bridge. This theorem is the foundational reason finite-horizon control is computationally tractable: the lower-bound induction is exactly the principle of optimality made quantitative — any tail of any policy costs at least the cost-to-go , so a best plan's tail must itself be best — and the attainment induction shows the backward recursion not only bounds but realizes the optimum. The central insight is that the policy-infimum and the staged expectation can be interchanged stage by stage, which is what collapses one optimization over policies into separate per-state minimizations. This builds toward the infinite-horizon theory 44.08.02, where the same Bellman operator is iterated to a fixed point rather than run for stages, and it appears again in the Markov decision process formulation 44.08.03, where becomes the finite-horizon value function and a greedy policy with respect to it. The deterministic case is dual to a shortest-path computation on a layered graph, and putting these together, the DP algorithm is the discrete-time, stochastic generalization of the Hamilton–Jacobi backward sweep — the bridge from the Pontryagin co-state of 44.07.01 to the value-function gradient.
Exercises Intermediate+
Advanced results Master
The finite-horizon theory extends in four directions: the exact equivalence between deterministic DP and shortest paths, the reverse reduction that lets shortest-path algorithms inherit the DP optimality proof, the state-augmentation construction that restores the Markov structure when it is broken by delays or correlation, and the measurable-selection refinement that secures attainment of the per-stage minima beyond the finite case.
Theorem 1 (deterministic DP equals shortest path). A deterministic finite-state finite-horizon problem with stages , state sets , transition costs for moves , and terminal cost is equivalent to a shortest-path problem on the layered directed graph with node set , an arc of weight for each admissible , and an artificial terminal node reached from each at cost . The DP cost-to-go equals the shortest-path distance from node to the terminal node, and the DP backward recursion is precisely backward dynamic-programming on this acyclic graph; conversely any shortest-path problem on an acyclic graph with a topological layering is a deterministic DP. The acyclicity of the layered graph is what makes the single backward sweep exact, in contrast with the iterative relaxation needed on graphs with cycles [Bertsekas Vol. 1 §1.3].
Theorem 2 (forward–backward symmetry and the reverse DP). For a deterministic problem the cost-to-go admits a forward dual: define the cost-to-arrive as the least cost to reach state at stage from , by the forward recursion , . Then for every and reachable , is constant along any optimal trajectory and equals , and at every stage. This forward/backward decomposition is the discrete shadow of the Hamilton–Jacobi value-function symmetry and underlies bidirectional shortest-path search and the label-correcting reinterpretation of the DP sweep [Bertsekas Vol. 1 §2.3].
Theorem 3 (state augmentation for delays and correlated disturbances). Suppose the dynamics involve a one-step control delay, , or the disturbances are correlated through an exogenous driving chain with . Define the augmented state in the first case, in the second. The augmented system is controlled-Markov 37.05.01, its disturbance law depending only on , and the DP algorithm applied to returns the optimal cost and policy of the original problem. The reformulation has the same optimal value; its cost is a larger state space, the generic price of restoring memorylessness [Bertsekas Vol. 1 §1.4].
Theorem 4 (existence and measurable selection of an optimal policy). When state and control spaces are uncountable, the per-stage infimum , with , need not be attained, and even when attained the minimizer need not depend measurably on . Under standard regularity — Borel spaces, a measurable set-valued map with compact values, lower semicontinuous in and measurable in , and the recursion preserving measurability and lower boundedness of — the Kuratowski–Ryll-Nardzewski measurable-selection theorem yields a measurable minimizer , so is measurable and an optimal deterministic Markov policy exists. For finite or countable the selection is automatic and the optimality theorem holds verbatim [Puterman Ch. 4].
Synthesis. The foundational reason finite-horizon control reduces to arithmetic is that one stochastic optimization over all policies factors, by the principle of optimality, into per-state minimizations linked only through the cost-to-go . The central insight is the interchange of the policy-infimum with the staged expectation: the lower-bound induction shows every policy tail costs at least , and the greedy attainment induction shows the backward recursion realizes that bound, so is a theorem, not a definition. This is dual to the forward cost-to-arrive recursion, the two meeting at exactly as the Hamilton–Jacobi value meets its characteristics, and it generalises the Pontryagin backward co-state sweep 44.07.01. State augmentation makes the framework universal — whatever breaks the Markov structure, delays or correlation, is absorbed into a larger state so the same recursion applies — and putting these together with the measurable-selection refinement gives an optimal Markov policy in full generality. The deterministic case is the bridge to combinatorial optimization, where the DP sweep is shortest path on an acyclic graph; the stochastic case builds toward the infinite-horizon fixed-point theory 44.08.02 and the Markov decision process 44.08.03, where the finite stage index gives way to iteration of one Bellman operator to its fixed point. The same algebraic move — collapsing an integral over all futures into a one-step optimization against a stored summary — appears again across value-function-based control and reinforcement learning.
Full proof set Master
Proposition 1 (one-step tail identity). For any admissible Markov policy and , , where is the tail cost-to-go from stage .
Proof. Split the cost in into the term and the remainder . Condition on via the tower property 37.01.01; this fixes . By the controlled-Markov property 37.05.01 the conditional law of the post- trajectory given equals that of the chain started at under , so . Taking the outer expectation over and adding the term gives the identity.
Proposition 2 (lower bound: ). For every admissible and every , for all .
Proof. Downward induction on . At , . Assume pointwise. By Proposition 1 and monotonicity of expectation, , since is one feasible choice in the infimum.
Proposition 3 (attainment: greedy policy realizes ). Assume each infimum defining is attained by . Then for the greedy policy , for all ; in particular .
Proof. Downward induction. At , . Assume . By Proposition 1 with , , which equals because attains the defining infimum. Hence , i.e. .
Proposition 4 (optimality of the DP algorithm). Under the attainment hypothesis, and is optimal.
Proof. Proposition 2 at gives for every admissible , so . Proposition 3 gives an admissible with , so . The two inequalities force , so is optimal.
Proposition 5 (cost-to-arrive/cost-to-go decomposition). In the deterministic case, with the cost-to-arrive and the cost-to-go, for every , and the minimizing are exactly the states lying on some optimal trajectory at stage .
Proof. For any state reachable at stage , is the least cost of a prefix and the least cost of a suffix terminal; concatenating a least prefix and a least suffix through gives a full trajectory of cost , so the minimum over is . Conversely an optimal full trajectory passes through some state at stage ; its prefix and suffix costs are and respectively, while their sum is , forcing prefix , suffix , and . Hence the minimum is attained and equals , with minimizers the on-optimal-path states.
Connections Master
The infinite-horizon discounted theory
44.08.02replaces the finite backward recursion with iteration of the single Bellman operator to its fixed point. The finite-horizon computed here are exactly the iterates of that operator, so the present unit is the truncated, non-stationary precursor whose limit (as the horizon grows and a discount stabilizes it) is the stationary value function; the contraction that makes the infinite-horizon fixed point unique is the asymptotic version of the finite-stage monotonicity used in the optimality proof here.The Markov decision process formulation
44.08.03is this unit's stochastic problem with the controlled-Markov disturbance37.05.01made the primitive: states, actions, transition kernels, and stage rewards, with the finite-horizon value functions and greedy policies becoming the MDP optimality equations and optimal decision rules. The optimality theorem proved here is the finite-horizon MDP optimality theorem; policy evaluation and the backward induction are the same recursion read in reward-maximization rather than cost-minimization form.The Pontryagin maximum principle
44.07.01is the continuous-time, calculus-of-variations counterpart: where DP computes a global value function over the whole state space by backward recursion, Pontryagin computes a co-state (adjoint) trajectory along a single candidate optimum by a backward differential equation. The co-state is the gradient of the value function, , so the discrete DP backward sweep and the Pontryagin backward adjoint are two readings of the same Hamilton–Jacobi backward flow, DP giving the field of values and Pontryagin its directional derivative along the optimal path.The controlled-Markov disturbance model rests on the Markov property and transition matrices
37.05.01: under a fixed policy the closed-loop system is an ordinary time-inhomogeneous Markov chain, the disturbance law composing with the feedback into a stochastic transition kernel. The tower property of conditional expectation on the underlying probability space37.01.01is what licenses the one-step tail identity that drives the entire optimality proof.
Historical & philosophical context Master
Dynamic programming was created by Richard Bellman at the RAND Corporation in the early 1950s, consolidated in the 1957 monograph Dynamic Programming [Bellman 1957]. Bellman's principle of optimality — that an optimal policy has the property that, whatever the initial state and first decision, the remaining decisions form an optimal policy for the resulting state — recast a multistage optimization as a functional equation in the value function, the recursion this unit calls the DP algorithm. Bellman's recollection that he chose the name "dynamic programming" partly to be politically palatable to a research-averse Secretary of Defense is a frequently retold piece of the method's origin; the mathematical substance is the functional-equation technique and the identification of the curse of dimensionality, the exponential growth of the state space that limits exact DP.
The stochastic, measure-theoretic formulation of the finite-horizon problem under perfect state information, with the controlled system , additive cost, and the optimality proof by backward induction, is the modern treatment systematized by Dimitri Bertsekas in Dynamic Programming and Optimal Control [Bertsekas Vol. 1 Ch. 1], whose Volume 1 Chapter 1 is the anchor for this unit. The measurable-selection difficulties in the uncountable case, and the conditions guaranteeing an optimal measurable Markov policy, were treated rigorously in the Markov-decision-process literature, with Martin Puterman's 1994 monograph [Puterman Ch. 4] giving the standard finite-horizon optimality-equation account. The deterministic reduction to shortest paths connects the method to the contemporaneous algorithmic work of Bellman, Ford, and Dijkstra on network optimization.
Bibliography Master
@book{bertsekas2017dp,
author = {Bertsekas, Dimitri P.},
title = {Dynamic Programming and Optimal Control, Volume 1},
edition = {4},
publisher = {Athena Scientific},
year = {2017}
}
@book{bellman1957dp,
author = {Bellman, Richard},
title = {Dynamic Programming},
publisher = {Princeton University Press},
year = {1957}
}
@book{puterman1994mdp,
author = {Puterman, Martin L.},
title = {Markov Decision Processes: Discrete Stochastic Dynamic Programming},
publisher = {John Wiley \& Sons},
year = {1994}
}
@article{bellman1954theory,
author = {Bellman, Richard},
title = {The theory of dynamic programming},
journal = {Bulletin of the American Mathematical Society},
volume = {60},
number = {6},
year = {1954},
pages = {503--515}
}
@book{bertsekas2012dpvol2,
author = {Bertsekas, Dimitri P.},
title = {Dynamic Programming and Optimal Control, Volume 2: Approximate Dynamic Programming},
edition = {4},
publisher = {Athena Scientific},
year = {2012}
}