All notes / Mathematics of machine learning

Reinforcement Learning I

Optimal policies, Bellman operators, and dynamic programming

Will Gao · September 2026

Contents
  1. 1 Mathematical Prerequisites
  2. 2 Finite Discounted Markov Decision Processes
  3. 3 Policy Evaluation as a Fixed Point
  4. 4 Existence of an Optimal Policy
  5. 5 Policies with Memory
  6. 6 Value Iteration
  7. 7 Policy Iteration

This note is an alternative treatment of Sections 18.1.2–18.2.4 of Principles of Robot Autonomy (2026), reorganized to suit the way I learn. A reader can use it in place of those sections and then return to the book.

The book's treatment is excellent, but it largely takes the existence of an optimal policy for granted, and under its definitions that existence was not obvious to me. The main goal here is to prove it (Theorem 4.3) and to show how the proof leads directly to the two classical algorithms, value iteration and policy iteration.

I have done my best to ensure correctness, but errors may remain.

1Mathematical Prerequisites

Definition 1.1 (Metric space).

A metric space is a set S together with a function d:S×S→R, called a metric, such that for all x,y,z∈S:

  1. d(x,y)≥0;

  2. d(x,y)=0⟺x=y;

  3. d(x,y)=d(y,x);

  4. d(x,z)≤d(x,y)+d(y,z).

Example 1.2.

Let S be a nonempty set. The set of bounded real-valued functions on S,

ℓ∞(S):={f:S→R∣f is bounded},

is a metric space under d(f,g)=supx∈S|f(x)−g(x)|, which is finite because f and g are bounded. We write ‖f‖∞:=supx∈S|f(x)|, so that d(f,g)=‖f−g‖∞. When S is finite, every function on S is bounded, and ℓ∞(S) is simply R|S| with the max norm.

Definition 1.3 (Complete metric space).

A metric space (S,d) is complete if every Cauchy sequence in S converges to an element of S.

It is straightforward to verify from the definitions that ℓ∞(S) is complete.

Definition 1.4 (Contraction).

Let (S,d) be a metric space. A map T:S→S is a contraction if there exists c∈[0,1) such that d(Tx,Ty)≤cd(x,y) for all x,y∈S. We then call T a c-contraction.

Theorem 1.5 (Banach fixed-point theorem).

Let (S,d) be a nonempty complete metric space and let T:S→S be a c-contraction. Then:

  1. there exists a unique x∗∈S such that Tx∗=x∗;

  2. for any x0∈S, the iterates xk+1=Txk converge to x∗, and d(xk,x∗)≤ckd(x0,x∗).

We use this theorem without proof. (The error bound in part 2 follows by applying the contraction property k times to d(xk,x∗)=d(Txk−1,Tx∗).)

Order notation. For f,g∈ℓ∞(S) we write f≤g if f(x)≤g(x) for every x∈S. Convergence in ℓ∞(S) implies pointwise convergence, so pointwise inequalities survive limits: if fk→f and fk≤g for all k, then f≤g.

We will also need one elementary inequality.

Lemma 1.6.

Let U be a finite set and let au,bu∈R for u∈U. Then

|maxu∈Uau−maxu∈Ubu|≤maxu∈U|au−bu|.
Proof.

Let u∗ attain maxuau. Then maxuau−maxubu≤au∗−bu∗≤maxu|au−bu|. Exchanging the roles of a and b gives the same bound for maxubu−maxuau.

□

2Finite Discounted Markov Decision Processes

A finite discounted Markov decision process (MDP) is a tuple

M=(X,U,p,R,γ),

where X is a finite set of states, U is a finite set of actions,

p(x′∣x,u)=Pr(xt+1=x′∣xt=x,ut=u)

is the transition probability, R:X×U→R is the reward function, and γ∈[0,1) is the discount factor. For every x∈X and u∈U,

p(x′∣x,u)≥0,∑x′∈Xp(x′∣x,u)=1.

Throughout, n:=|X| and m:=|U|.

A stationary stochastic policy π assigns to each state x a probability distribution π(⋅∣x) over actions:

π(u∣x)≥0,∑u∈Uπ(u∣x)=1.

When the system is in state xt, the action ut is drawn from π(⋅∣xt). “Stationary” means the distribution depends only on the current state, not on the time t or on the earlier history. We write Π for the set of all such policies. A deterministic policy is a map π:X→U; we identify it with the stochastic policy that puts probability 1 on π(x) at each state x. There are mn deterministic policies.

A finite trajectory of length T has the form

τ=(x0,u0,x1,u1,…,uT−1,xT).

Conditional on the initial state x0=x, its probability under π is

pπ(τ∣x0=x)=∏t=0T−1π(ut∣xt)p(xt+1∣xt,ut).

For an infinite trajectory (x0,u0,x1,u1,…), the discounted return is

∑t=0∞γtR(xt,ut).

Since X and U are finite, R is bounded: there is Rmax<∞ with |R(x,u)|≤Rmax for all x∈X, u∈U. Therefore

|∑t=0∞γtR(xt,ut)|≤∑t=0∞γtRmax=Rmax1−γ,

so the discounted return is well defined and bounded.

For a policy π∈Π, the state-value function Vπ:X→R is

Vπ(x)=Eπ[∑t=0∞γtR(xt,ut)|x0=x],

the expected discounted return when the process starts in x and follows π thereafter. By the bound above, |Vπ(x)|≤Rmax/(1−γ).

Conditioning on the first action u0 and the next state x1, and using the Markov property, we obtain the Bellman equation

Vπ(x)=∑u∈Uπ(u∣x)[R(x,u)+γ∑x′∈Xp(x′∣x,u)Vπ(x′)].
(1)

3Policy Evaluation as a Fixed Point

We work in the complete metric space ℓ∞(X). Since X is finite, this is just the space of all functions X→R, and in particular Vπ∈ℓ∞(X).

For a policy π∈Π, define the Bellman operator Tπ:ℓ∞(X)→ℓ∞(X) by

(Tπf)(x)=∑u∈Uπ(u∣x)[R(x,u)+γ∑x′∈Xp(x′∣x,u)f(x′)].
Lemma 3.1.

For every π∈Π:

  1. TπVπ=Vπ;

  2. Tπ is a γ-contraction;

  3. Tπ is monotone: if f≤g, then Tπf≤Tπg.

Proof.

Part 1 is the Bellman equation (1). For parts 2 and 3, note that for every x,

(Tπf)(x)−(Tπg)(x)=γ∑u∈Uπ(u∣x)∑x′∈Xp(x′∣x,u)(f(x′)−g(x′)),

because the reward terms cancel. The weights π(u∣x)p(x′∣x,u) are nonnegative and sum to 1. Hence

|(Tπf)(x)−(Tπg)(x)|≤γ∑uπ(u∣x)∑x′p(x′∣x,u)|f(x′)−g(x′)|≤γ‖f−g‖∞,

and taking the supremum over x gives ‖Tπf−Tπg‖∞≤γ‖f−g‖∞. If f≤g, the same identity (with f and g swapped) is a nonnegative combination of the nonnegative numbers g(x′)−f(x′), so Tπf≤Tπg.

□
Corollary 3.2.

Vπ is the unique fixed point of Tπ, and for any f∈ℓ∞(X), (Tπ)kf→Vπ as k→∞.

Proof.

Combine Lemma 3.1 with Theorem 1.5.

□

So we can compute Vπ to any accuracy by applying Tπ repeatedly, starting from any function (for example f=0). This is called iterative policy evaluation.

4Existence of an Optimal Policy

Evaluating a given policy is not the end goal: we want the best one. Ideally we want a single policy that is at least as good as every other policy from every starting state.

Definition 4.1 (Optimal policy).

A policy π∗∈Π is optimal if Vπ∗≥Vπ for every π∈Π, that is, Vπ∗(x)≥Vπ(x) for every π∈Π and every x∈X.

Asking for domination at every state simultaneously is a strong requirement: a priori, one policy might be best from x1 while a different policy is best from x2. Fortunately this cannot happen.

Define the Bellman optimality operator T:ℓ∞(X)→ℓ∞(X) by

(Tf)(x)=maxu∈U[R(x,u)+γ∑x′∈Xp(x′∣x,u)f(x′)].
Lemma 4.2.
  1. T is a γ-contraction.

  2. For every π∈Π and every f∈ℓ∞(X), Tπf≤Tf.

Proof.

1. Fix x. By Lemma 1.6,

|(Tf)(x)−(Tg)(x)|≤maxu|γ∑x′∈Xp(x′∣x,u)(f(x′)−g(x′))|≤γmaxu∑x′∈Xp(x′∣x,u)|f(x′)−g(x′)|≤γmaxu∑x′∈Xp(x′∣x,u)‖f−g‖∞=γ‖f−g‖∞.

Taking the supremum over x gives ‖Tf−Tg‖∞≤γ‖f−g‖∞.

2. (Tπf)(x) is an average, with weights π(u∣x), of the bracketed quantities, and an average never exceeds the maximum, which is (Tf)(x).

□
Theorem 4.3 (Existence of an optimal policy).

Every finite discounted MDP has an optimal policy, and it can be chosen to be deterministic. Moreover, if V∗ denotes the unique fixed point of T, then Vπ∗=V∗ for every optimal π∗.

Proof.

Step 1: the fixed point. By Lemma 4.2 and Theorem 1.5, T has a unique fixed point h∈ℓ∞(X).

Step 2: a policy that achieves h. Since U is finite, for each x the maximum in (Th)(x) is attained. Define a deterministic policy by choosing, for each x,

π∗(x)∈argmaxu∈U[R(x,u)+γ∑x′∈Xp(x′∣x,u)h(x′)].

Because π∗(⋅∣x) puts all its mass on a maximizing action,

(Tπ∗h)(x)=R(x,π∗(x))+γ∑x′∈Xp(x′∣x,π∗(x))h(x′)=(Th)(x)=h(x).

So h is a fixed point of Tπ∗. By Corollary 3.2, the only fixed point of Tπ∗ is Vπ∗; hence h=Vπ∗.

Step 3: no policy does better. Let π∈Π. By Lemma 4.2, Tπh≤Th=h. We claim that

(Tπ)k+1h≤(Tπ)khfor all k≥0.

The case k=0 is the inequality just shown. If it holds for k, applying the monotone operator Tπ (Lemma 3.1) to both sides gives it for k+1. Hence

h≥Tπh≥(Tπ)2h≥⋯,

so (Tπ)kh≤h for all k. By Corollary 3.2, (Tπ)kh→Vπ, and passing to the limit gives Vπ≤h=Vπ∗.

Thus π∗ is optimal. Finally, if π~ is any optimal policy, then Vπ~≥Vπ∗ and Vπ∗≥Vπ~, so Vπ~=Vπ∗=h=V∗.

□

V∗ is called the optimal value function, and the equation V∗=TV∗ is the Bellman optimality equation. The optimal value function is unique, but optimal policies need not be: any policy that is greedy with respect to V∗, in the sense of Step 2, is optimal.

5Policies with Memory

Theorem 4.3 shows that π∗ is optimal among stationary policies. A natural worry is that a policy which looks at the clock, or remembers where it has been, could do better. This section shows it cannot.

Definition 5.1 (General policy).

A history at time t is ht=(x0,u0,x1,u1,…,xt). A general policy σ assigns to each history ht a probability distribution σ(⋅∣ht) over actions, and the action at time t is drawn as ut∼σ(⋅∣ht).

For example, “take action a for the first ten steps, then b” and “take a if x3 has been visited before, otherwise b” are general policies but not stationary ones. Stationary policies are the special case in which σ(⋅∣ht) depends only on the last state xt.

Under a general policy, the probability of a trajectory is

pσ(τ∣x0=x)=∏t=0T−1σ(ut∣ht)p(xt+1∣xt,ut),

and its value is defined exactly as before,

Vσ(x)=Eσ[∑t=0∞γtR(xt,ut)|x0=x],|Vσ(x)|≤Rmax1−γ.

The environment is still Markov: whatever σ does, the next state is drawn from p(⋅∣xt,ut). What changes is that Vσ generally does not satisfy a Bellman equation of the form V=TπV, because how σ behaves after reaching x1 can depend on how it got there. So Step 3 of the proof of Theorem 4.3, which works through Tπ, does not apply. We need a different argument.

Proposition 5.2.

For every general policy σ, Vσ≤V∗.

Proof.

Fix σ and a start state x0. For k≥0 define

Wk=Eσ[∑t=0k−1γtR(xt,ut)+γkV∗(xk)].

(i) The start: W0=V∗(x0). With k=0 there are no rewards yet, only the term V∗(x0).

(ii) The limit: Wk→Vσ(x0).

|Wk−Vσ(x0)|≤∑t=k∞γtRmax+γk‖V∗‖∞=γk(Rmax1−γ+‖V∗‖∞)→k→∞0.

(iii) Each step goes down: Wk+1≤Wk.

Wk+1−Wk=γkEσ[R(xk,uk)+γV∗(xk+1)−V∗(xk)].

Condition on the history hk and the action uk. However σ chose uk, the next state is drawn from p(⋅∣xk,uk), so Eσ[V∗(xk+1)∣hk,uk]=∑x′p(x′∣xk,uk)V∗(x′). Hence

Wk+1−Wk=γkEσ[g(xk,uk)],g(x,u):=R(x,u)+γ∑x′p(x′∣x,u)V∗(x′)−V∗(x).

Since V∗(x)=(TV∗)(x) is the maximum over u of the first two terms of g(x,u), we have g(x,u)≤0 for every state x and every action u. Therefore Wk+1−Wk≤0.

Conclusion. By (iii), Wk≤Wk−1≤⋯≤W0 for every k. By (i) and (ii), letting k→∞ gives Vσ(x0)≤V∗(x0). Since x0 was arbitrary, Vσ≤V∗.

□

6Value Iteration

The proof is constructive. Starting from any V0 (for example V0=0), iterate

Vk+1=TVk.

By Theorem 1.5, Vk→V∗ and ‖Vk−V∗‖∞≤γk‖V0−V∗‖∞. This algorithm is called value iteration. After stopping, we output a policy that is greedy with respect to the final iterate, as in Step 2 of the proof. The next proposition says that a good approximation of V∗ yields a good policy.

Proposition 6.1.

Let V∈ℓ∞(X) satisfy ‖V−V∗‖∞≤ε, and let π be greedy with respect to V, i.e. TπV=TV. Then

‖V∗−Vπ‖∞≤2γε1−γ.
Proof.

Using V∗=TV∗, Vπ=TπVπ and TπV=TV,

V∗−Vπ=(TV∗−TV)+(TπV−TπV∗)+(TπV∗−TπVπ).

Each operator is a γ-contraction, so ‖V∗−Vπ‖∞≤γε+γε+γ‖V∗−Vπ‖∞. Rearranging gives the claim.

□

In fact, because there are only finitely many deterministic policies, once Vk is close enough to V∗ the greedy policy is exactly optimal; but how close is “close enough” depends on gaps in the problem that are not known in advance, so in practice one stops at a tolerance.

Complexity. One application of T costs O(mn2): for each of the n states and m actions, we sum over n next states. With V0=0 we have ‖V0−V∗‖∞=‖V∗‖∞≤Rmax/(1−γ), so ‖Vk−V∗‖∞≤ε as soon as γkRmax/(1−γ)≤ε, that is,

k ≥ log⁡(Rmax/((1−γ)ε))log⁡(1/γ).

Since log⁡(1/γ)≥1−γ, it suffices to take k≥11−γlog⁡Rmax(1−γ)ε. The total cost is therefore

O(mn21−γlog⁡Rmax(1−γ)ε).

7Policy Iteration

Policy iteration takes a different route: it moves through a sequence of deterministic policies, each strictly better than the last, until it reaches an optimal one.

For a policy π, define the action-value function

Qπ(x,u):=R(x,u)+γ∑x′∈Xp(x′∣x,u)Vπ(x′).

Qπ(x,u) is the expected discounted return from starting at x, taking action u once, and following π thereafter. In this notation,

Vπ(x)=∑uπ(u∣x)Qπ(x,u)≤maxuQπ(x,u)=(TVπ)(x).

The algorithm. Start from any policy π0. For k=0,1,2,…:

  1. Policy evaluation: compute Vπk (see below).

  2. Policy improvement: define a deterministic policy

    πk+1(x)∈argmaxu∈UQπk(x,u),

    keeping πk+1(x)=πk(x) whenever πk is deterministic and πk(x) already attains the maximum.

  3. Stop if πk+1=πk.

The tie-breaking rule in step 2 prevents the algorithm from cycling among equally good policies.

Proposition 7.1 (Policy improvement).

Let π∈Π and let π′ be greedy with respect to Vπ, i.e. π′(x)∈argmaxuQπ(x,u). Then

Vπ′ ≥ TVπ ≥ Vπ.

Consequently, if (TVπ)(x)>Vπ(x) at some state x, then Vπ′(x)>Vπ(x); and if TVπ=Vπ, then π is optimal.

Proof.

By construction, Tπ′Vπ=TVπ≥Vπ. Applying the monotone operator Tπ′ repeatedly, exactly as in Step 3 of the proof of Theorem 4.3 but with the inequalities reversed, gives

Vπ≤Tπ′Vπ≤(Tπ′)2Vπ≤⋯,

and this sequence converges to Vπ′ by Corollary 3.2. So Vπ′≥Tπ′Vπ=TVπ≥Vπ. If TVπ=Vπ, then Vπ is a fixed point of T, so Vπ=V∗ and π is optimal.

□
Corollary 7.2.

Policy iteration terminates after at most mn improvement steps, with an optimal deterministic policy.

Proof.

All πk with k≥1 are deterministic. If the algorithm stops, i.e. πk+1=πk, then TVπk=Tπk+1Vπk=TπkVπk=Vπk, so πk is optimal by Proposition 7.1. If it does not stop, the tie-breaking rule means that at some state x the action πk(x) does not attain maxuQπk(x,u), so (TVπk)(x)>Vπk(x), and Proposition 7.1 gives Vπk+1≥Vπk with strict inequality at x. Value functions therefore strictly increase, so no deterministic policy is visited twice. Since there are mn deterministic policies, the algorithm stops after at most mn steps.

□

Exact policy evaluation. Unlike value iteration, policy evaluation can be done exactly, for any stationary policy π (deterministic or not). Define the matrix Pπ∈Rn×n and the vector rπ∈Rn by

Pxx′π=∑uπ(u∣x)p(x′∣x,u),rπ(x)=∑uπ(u∣x)R(x,u).

The Bellman equation (1) reads Vπ=rπ+γPπVπ, that is,

(I−γPπ)Vπ=rπ.

The matrix I−γPπ is invertible: if (I−γPπ)v=0, then v=γPπv, and since Pπ is row-stochastic, ‖v‖∞≤γ‖v‖∞, which forces v=0.

Complexity. Solving this n×n linear system costs O(n3) by Gaussian elimination, or O(nω) with fast matrix multiplication (for example, ω=log2⁡7≈2.807 with Strassen's algorithm). The improvement step computes Qπk at cost O(mn2). One iteration of policy iteration therefore costs

O(n3+mn2).

In practice, policy iteration usually needs far fewer iterations than value iteration, but each iteration is more expensive.