RL Bible · Appendix B
Math Refresher
Probability, expectation, gradients, optimization, and information theory as used in this book.
This appendix collects the mathematics the book uses, at the depth it uses it. It is a refresher, not a course: each section states the facts, the notation, and where in the book they carry load. If any section reads as new rather than half-remembered, the linked references are the efficient repair.
1. Probability
Random variables and distributions. A random variable takes values by chance; its distribution assigns probabilities. We write ("distributed as"), or for probability (mass or density), and use capital letters for random variables, lowercase for realized values — the convention that lets parse correctly everywhere in this book.
Joint, marginal, conditional. is the joint; the marginal integrates the other variable out, ; the conditional is . The chain rule is used every time the book factorizes a trajectory probability (Chapters 3, 11): .
Independence and conditional independence. iff . Conditional independence — "given Z, Y adds nothing about X" — is the Markov property (Chapter 3): the future is conditionally independent of the past given the present. Nearly every derivation that "drops the history" (Bellman equations, Chapter 5's importance-sampling cancellation) is an application.
Bayes' rule. — posterior ∝ likelihood × prior. Load-bearing in: Thompson sampling (Chapter 2), POMDP belief updates (Chapter 3), and the variational posterior/prior structure of world models (Chapter 23).
2. Expectation, Variance, and the Tools of Estimation
Expectation is the probability-weighted average, , and is linear unconditionally: whether or not X, Y are independent — the fact that makes returns decompose ( ⟹ Bellman equations) and baselines subtract cleanly (Chapter 11).
The tower rule (law of total expectation). . The book's most-used invisible tool: it converts "average over trajectories" into "average over states of the average over what follows" — the step inside the Bellman derivation (Chapter 3), the regret decomposition (Chapter 2, Exercise 2.2), and the unbiasedness proofs of Chapters 5 and 11.
Variance measures spread: . For independent variables variances add — which is why an -step return's variance grows with (each reward contributes; Chapter 7) and why averaging i.i.d. samples shrinks standard error like (Monte Carlo, Chapter 5).
Estimators. An estimator of θ from samples is unbiased if and consistent if with more data. The book's recurring trade: unbiased/high-variance (Monte Carlo returns, ordinary importance sampling, REINFORCE) versus biased/low-variance (TD targets, weighted importance sampling, critics). Bias–variance decomposition: mean squared error = bias² + variance — the accounting behind every "n-step / λ" dial (Chapter 7) and GAE (Chapter 11).
Concentration. Hoeffding's inequality: for i.i.d. bounded samples, — deviations decay exponentially. It is the engine of every confidence bound in the book: UCB (Chapter 2), UCBVI's confidence sets (Chapter 21). The union bound, , is how per-arm/per-state bounds become uniform ones (and why log factors appear everywhere).
Jensen's inequality. For convex : . With : — maximization bias, the single inequality responsible for Double Q-learning, Double DQN, and TD3's twin critics (Chapters 6, 10, 13).
Importance sampling. To estimate using samples from : , valid wherever (coverage). Unbiased; variance governed by the ratio's spread — the mathematics of all off-policy corrections (Chapters 5, 7, 12) and their failure modes (offline RL, Chapter 17).
3. The Gaussian, and Sampling Tricks
The Gaussian has density ; its log-density appears verbatim in every Gaussian-policy log-prob computation (Chapters 11, 13). Products stay Gaussian; sums of independent Gaussians are Gaussian; conditionals and marginals of joint Gaussians are Gaussian — the closure properties PILCO's moment matching exploits (Chapter 14).
Change of variables. If with invertible g, densities transform with the Jacobian: . This is the tanh-correction in SAC's squashed Gaussian (Chapter 13) — forget it and entropies come out wrong.
Reparameterization. Sampling blocks gradients; writing , restores them: . One of the book's two fundamental gradient estimators (Chapter 13; world models, Chapter 23) — the other being the score function identity , derived from (Chapter 11).
4. Linear Algebra and Calculus, as Used
Vectors and norms. ; (the sup-norm of Chapter 4's contraction proofs); (total-variation-flavored bounds, Chapter 21). Inner product ; vectors are columns.
Matrices as operators. A stochastic matrix (rows sum to 1) maps value vectors to expected-next values; its spectral radius is 1, so contracts and converges (the Neumann series = "sum over all discounted paths" — Chapter 3). Positive definiteness () is what makes expected TD updates stable (Chapter 9) and the Fisher matrix a metric (Chapter 12).
Gradients. points uphill; the chain rule composes through networks (backprop) and through sampled computation graphs (reparameterization). Two named gradients recur: the policy gradient and the pathwise/deterministic gradient — Chapters 11 and 13; know both derivations cold.
Taylor expansion. — the tool behind trust regions: TRPO expands the objective to first order and the KL constraint to second (whose Hessian is the Fisher matrix — Chapter 12, Exercise 12.4).
Fixed points and contractions. is a γ-contraction under norm if ; Banach's theorem gives a unique fixed point and geometric convergence of iteration. Proved and used in Chapter 4; echoed for soft Bellman operators (Chapter 13) and distributional operators (Chapter 10).
5. Optimization
Gradient descent/ascent with step size α; stochastic versions replace the gradient with an unbiased sample. Convergence for decaying steps under the Robbins–Monro conditions , (Chapters 2, 6, 21); constant steps track nonstationary targets instead (everywhere in deep RL). Momentum/Adam: adaptive per-parameter step sizes; the book's code uses Adam throughout without ceremony.
Constrained optimization and Lagrange multipliers. To maximize subject to : form , optimize over the primal, adjust λ by dual ascent (raise λ while the constraint is violated). Used for: TRPO's trust region (Chapter 12), SAC's automatic temperature (Chapter 13), and the max-ent derivations (Chapters 13, 16, 20 — where the Boltzmann distribution appears as the closed-form solution of entropy-regularized objectives; deriving that once, via calculus of variations on the simplex, pays off four separate times).
Convexity (one definition, three uses): convex iff chords lie above the graph. Uses: Jensen (Section 2), the log-sum-exp softmax bound (CQL, Chapter 17), and convex conjugates (GAIL's occupancy duality, Chapter 16 — used at the "trust the statement" level).
6. Information Theory
Entropy : expected surprise; maximized by uniform. The exploration bonus of Chapter 11, the objective term of max-ent RL (Chapter 13), and the tie-breaking principle of max-ent IRL (Chapter 16).
KL divergence : expected log evidence for p over q; nonnegative (Gibbs' inequality), zero iff , asymmetric — punishes q lacking mass where p has it (mode-covering), punishes q putting mass where p lacks it (mode-seeking); which direction appears in a loss is never an accident (RSSM's two-directional balance, Chapter 23; the RLHF leash, Chapter 20). Its local quadratic expansion defines the Fisher information matrix — the metric of natural gradients (Chapter 12).
Mutual information : shared information; the formal objective behind information-gain exploration (Chapter 15) and latent-action discovery (Genie, Chapter 23).
Cross-entropy = entropy + KL: minimizing it in q fits q to p — every classification loss, C51's projection loss (Chapter 10), and behavior cloning's objective (Chapter 16) in one identity.
7. Where to Repair Gaps
- Probability & estimation: Wasserman, All of Statistics — chapters 1–5 cover everything above at the right level. link.springer.com/book/10.1007/978-0-387-21736-9
- Linear algebra: Strang's lectures, or Axler for the operator view that makes Chapter 4 natural.
- Optimization: Boyd & Vandenberghe, Convex Optimization, chapters 1–5 — free at stanford.edu/~boyd/cvxbook. Lagrange duality is the one section this book truly leans on.
- Information theory: Cover & Thomas, Elements of Information Theory, chapters 1–2; or MacKay's free Information Theory, Inference, and Learning Algorithms — inference.org.uk/mackay/itila.
- Stochastic approximation (optional depth): Borkar, Stochastic Approximation: A Dynamical Systems Viewpoint — the machinery behind Chapters 6 and 21's convergence claims.