Part I · Foundations of Sequential Decision-Making
2.The Mathematical Toolkit
“The relationship between disciplines has sufficient promise to be likened to that between physics and mathematics.”
Chapter 1 left three debts: the loop is not yet mathematics, reward is not yet a random variable, and 'eventually finds the best policy' is not yet a theorem. This chapter pays all three. We build the probability that makes expectations meaningful, the contraction machinery that every convergence proof in this book eventually invokes, the discretization that turns a robot's continuous physics into discrete decisions, and the Robbins–Monro theorem — the single result that explains why learning from noisy samples works at all. Pendle arrives to carry it, because he is simple enough that every calculation can be checked by hand.
Foundation
Probability spaces, conditional expectation and the tower property, contraction mappings with Banach proved in full, ODE discretization with error orders, and Robbins–Monro convergence.
Conceptual
A contraction you can iterate at any γ, and Pendle's dynamics integrated three ways so you can watch explicit Euler manufacture energy from nothing.
Practical
Pendle's dynamics and integrators in Rust with nalgebra, plus a Robbins–Monro estimator you can drive with noisy samples.
After this chapter you can
- State what a random variable and a conditional expectation actually are, and use the tower property fluently
- Prove the Banach fixed-point theorem and explain why it guarantees a unique optimal value function
- Discretize a continuous robot dynamics with Euler and RK4, and predict which one will explode and when
- State the Robbins–Monro conditions and recognize them in every learning rate you will meet later
- Read the incremental update rule New ← Old + α(Target − Old) as an instance of stochastic approximation
2.1 Probability, quickly but honestly
Chapter 1 said the world "advances" after an action. Making that precise requires almost no machinery, but it does require the right machinery.
A probability space is a triple : a set of outcomes , a collection of events we can assign probabilities to, and a measure assigning each event a number in with . A random variable is a function from to — not a number, a function. When we write we mean the event .
This matters for us because Rusty's next position is exactly such a function: it depends on the wheel slip that happened to occur, which is the outcome . Two identical commands from two identical positions produce two different results, and the difference is not error — it is the environment.
The expectation of is its probability-weighted average, in the discrete case. Expectation is linear, which is the property we will lean on constantly:
— and note this holds whether or not and are independent. A surprising amount of reinforcement learning is linearity of expectation applied patiently.
Definition 2.1— Conditional expectation
For random variables and , the conditional expectation is a random variable — a function of — whose value at is the average of over the outcomes where :
The single most useful fact about conditional expectation is that averaging it recovers the unconditional average.
Theorem 2.2— Tower property (law of total expectation)
▸Proof
Write the outer expectation as a sum over values of , then expand the inner one:
By the definition of conditional probability, . Substituting and exchanging the order of summation:
Every Bellman equation in this book is the tower property applied to a return, conditioned on the first action. That is genuinely all it is. When Chapter 4 derives
the derivation will consist of splitting the return into "first reward" plus "the rest", conditioning on where you land, and invoking Theorem 2.2.
2.2 Markov chains and the memory assumption
A sequence of random variables has the Markov property if the future is conditionally independent of the past given the present:
The state is then a sufficient statistic for prediction: knowing it, the history adds nothing.
2.3 Contraction mappings and the theorem behind everything
Here is the mathematical heart of the chapter — the result that will justify value iteration, Q-learning, and half of Part I.
Definition 2.3— Contraction mapping
Let be a metric space. An operator is a -contraction for if for all ,
Applying moves any two points strictly closer together. Intuitively, repeated application must crush everything toward a single point. The theorem says exactly that, and adds a computable error bound.
Theorem 2.4— Banach fixed-point theorem
Let be a complete metric space and a -contraction. Then:
- has exactly one fixed point with ;
- for any starting point , the sequence converges to ;
- the convergence is geometric, with the a-priori bound
▸Proof
The sequence is Cauchy. From the contraction property, consecutive iterates satisfy , and by induction
For any , the triangle inequality and the geometric series give
Since , the right-hand side goes to zero as , so the sequence is Cauchy. Completeness gives a limit .
The limit is a fixed point. A contraction is continuous (take in the definition), so
Uniqueness. Suppose and . Then , so . Since , this forces , hence .
The bound. Let in the Cauchy estimate above.
Three payoffs, all collected later: existence (an optimal value function exists), uniqueness (there is only one, so "the" optimal value function is well defined), and an algorithm with a stopping rule (iterate, and the bound tells you when to stop).
A contraction, iterated
ch02-contraction-mapT(x) = γx + 2 — every application shrinks distances by a factor γ, so the iterates must converge to a single point.
- iterate xₖ
- fixed point x*
Fixed point x*
10.0
c / (1 − γ)
Actual error
0.005
|x24 − x*|
A-priori bound
0.005
γᵏ‖x₁−x₀‖/(1−γ)
The bound never dips below the error — as the theorem guarantees.
2.4 From continuous physics to discrete decisions
Robots obey differential equations. Reinforcement learning acts at discrete time steps. Something must bridge them, and the bridge is not free.
Meet Pendle, a torque-actuated pendulum, measured with at the upright position:
Writing the state as turns this into a first-order system . To simulate it we need to advance by a finite step . The simplest choice is explicit Euler:
which is exact if is constant over the interval and wrong otherwise, with local error and global error . Fourth-order Runge–Kutta samples the derivative four times per step:
with global error — four extra derivative evaluations buying three extra orders of accuracy.
The difference is not academic. With the true pendulum conserves total mechanical energy exactly. Explicit Euler does not merely approximate that conservation — it systematically violates it, injecting energy at every step until the pendulum spins up out of nothing.
Pendle: continuous dynamics, discrete steps
ch02-integrator-playgroundm ℓ² θ̈ = m g ℓ sin θ − b θ̇ + τ, integrated three ways. θ = 0 is upright.
Energy
-9.70J
should stay flat at τ=0
Δt
20.0ms
50 Hz control rate
- explicit Euler
- semi-implicit Euler
- RK4
use nalgebra::Vector2;
pub struct PendleParams {
pub mass: f64,
pub length: f64,
pub gravity: f64,
pub damping: f64,
}
/// ẋ = f(x, τ) for the torque-actuated pendulum, θ = 0 at upright.
pub fn dynamics(x: &Vector2<f64>, tau: f64, p: &PendleParams) -> Vector2<f64> {
let (theta, omega) = (x[0], x[1]);
let inertia = p.mass * p.length * p.length;
let alpha = (p.mass * p.gravity * p.length * theta.sin()
- p.damping * omega
+ tau) / inertia;
Vector2::new(omega, alpha)
}
pub fn euler_step(x: &Vector2<f64>, tau: f64, dt: f64, p: &PendleParams) -> Vector2<f64> {
x + dt * dynamics(x, tau, p)
}
pub fn rk4_step(x: &Vector2<f64>, tau: f64, dt: f64, p: &PendleParams) -> Vector2<f64> {
let k1 = dynamics(x, tau, p);
let k2 = dynamics(&(x + 0.5 * dt * k1), tau, p);
let k3 = dynamics(&(x + 0.5 * dt * k2), tau, p);
let k4 = dynamics(&(x + dt * k3), tau, p);
x + (dt / 6.0) * (k1 + 2.0 * k2 + 2.0 * k3 + k4)
}2.5 Learning from noisy samples: Robbins–Monro
Now the result that makes learning possible at all.
Suppose you want to find the root of a function , but you can never evaluate — only a noisy sample . This is precisely our situation: we want the expected return, and we only ever observe one noisy trajectory at a time.
Robbins and Monro's answer, from 1951, is to take small steps in the direction each noisy sample suggests, with a step size that shrinks:
Theorem 2.5— Robbins–Monro conditions
Under regularity conditions on and bounded noise variance, the iterates converge almost surely to the root provided the step sizes satisfy
The two conditions have clean interpretations, and it is worth being able to recite them:
- — the steps must be able to travel infinitely far. If they sum to something finite, the iterate can never reach a root that lies beyond that distance, no matter how many samples arrive.
- — the steps must shrink fast enough to average out the noise. Otherwise the iterate rattles around the root forever without settling.
The canonical choice satisfies both: the harmonic series diverges, and the sum of converges to . A constant satisfies the first but not the second — which is why constant learning rates track a moving target instead of converging, exactly the trade you want when the environment is non-stationary.
2.6 Linear algebra and gradients, in the amount we need
Two more tools, stated without ceremony because they will be used constantly.
Matrices as operators. Given a policy on a finite state space, the transition probabilities form a matrix , and expected rewards a vector . Chapter 4 will show the value function satisfies , whose solution is
The inverse exists because has spectral radius at most , so the Neumann series converges — the same geometric argument as the Banach bound, wearing matrix clothes.
Gradients. For , the gradient points in the direction of steepest increase, and gradient ascent takes . Chapter 10 spends its entire length computing one specific gradient — that of expected return with respect to policy parameters — which is hard precisely because the distribution you are averaging over depends on the parameters you are differentiating.
2.7 Chapter bridge
The debts of Chapter 1 are paid. "The world advances" is a conditional distribution. "Reward" is a random variable with an expectation. "Eventually finds the best policy" will be Banach's theorem applied to an operator we have not yet built.
Chapter 3 puts the toolkit to work on the smallest problem that still contains the essential difficulty: a single decision, repeated, with no state at all. Stripping away state exposes the exploration–exploitation dilemma in its pure form, and lets us derive real regret bounds with the concentration inequalities we now have the vocabulary for. Reacher joins the cast there, choosing among grasp primitives where every attempt costs hardware wear.
- 01Foundation●●●Tower property by hand
Let X be the total reward from a two-step episode and Y the first action. Compute E[X] two ways — directly, and via E[E[X|Y]] — for a small example you construct. They must agree; make sure you see why.
- 02Foundation●●●Is the operator a contraction?
Show that T(x) = γx + c is a γ-contraction on ℝ with the usual metric, and find its fixed point in closed form. Then show that T(x) = x + c is not a contraction for any c ≠ 0, and explain what goes wrong with Banach’s conclusion.
- 03Foundation●●●Robbins–Monro schedules
Which of these satisfy both Robbins–Monro conditions? (a) α_k = 1/k, (b) α_k = 1/k², (c) α_k = 1/√k, (d) α_k = 0.1. For each failure, say which condition breaks and what behaviour that produces in practice.
- 04Conceptual●●●The γ → 1 slowdown
In the contraction widget, record the number of iterations needed to reach an error below 0.01 for γ = 0.5, 0.9, 0.95, 0.99. Plot iterations against 1/(1−γ). What relationship do you find, and why does the a-priori bound predict it?
- 05Conceptual●●●Find the stability boundary
In the Pendle playground with τ = 0, find the largest Δt at which explicit Euler keeps energy within 10% over ten seconds. Repeat for RK4. Express the ratio — that is the compute budget RK4 buys you per step.
- 06Practical●●●Implement Robbins–Monro
Write a seeded estimator that finds the mean of a noisy signal using α_k = 1/k, and a second using constant α = 0.1. Feed both a signal whose mean jumps halfway through the run. Plot both trajectories and explain which you would deploy on a robot whose payload changes.
- 07Practical●●●Verify the error orders
Empirically confirm that Euler’s global error is O(Δt) and RK4’s is O(Δt⁴): simulate Pendle for a fixed horizon at halving step sizes, measure error against a very-fine-step reference, and fit the slope on a log–log plot. The slopes should come out near 1 and 4.
References
Baseline references
- Sutton, R. S. & Barto, A. G. (2018). Reinforcement Learning: An Introduction. MIT Press, 2nd edition§2.4 incremental implementation — the Robbins–Monro special case that opens Chapter 3; §3.1 for the Markov property.
- Kober, J., Bagnell, J. A. & Peters, J. (2013). Reinforcement Learning in Robotics: A Survey. International Journal of Robotics Research 32(11)§1.3 for the continuous state–action setting that motivates the discretization material here.
Further reading & modern sources
- Robbins, H. & Monro, S. (1951). A Stochastic Approximation Method. Annals of Mathematical Statistics 22(3)The original paper. Short, readable, and the ancestor of every learning rate in this book.
- Banach, S. (1922). Sur les opérations dans les ensembles abstraits et leur application aux équations intégrales. Fundamenta Mathematicae 3The fixed-point theorem, in the original.
- Bertsekas, D. P. & Tsitsiklis, J. N. (1996). Neuro-Dynamic Programming. Athena ScientificThe rigorous treatment of stochastic approximation applied to dynamic programming. Where to go when this book says "the proof lives elsewhere".
- Hairer, E., Nørsett, S. P. & Wanner, G. (1993). Solving Ordinary Differential Equations I: Nonstiff Problems. SpringerThe reference for integrator error orders and stability regions — including why symplectic integrators behave so much better on mechanical systems.
