Mathematics
This book starts with quantities, relationships, change, constraints, and uncertainty, then develops the mathematics used in computing. Intuitive examples lead into calculus, linear algebra, discrete mathematics, probability, numerical methods, optimization, information theory, and signals. Worked derivations and code show how an idea becomes a calculation. Predict a result, work a small case by hand, and test the numerical behavior before trusting a formula in a larger system.
100 sections
Start readingGlossaryContents
Section titled “Contents”Mathematical intuition
Section titled “Mathematical intuition”Calculus and linear algebra
Section titled “Calculus and linear algebra”- 6.1 Exponents, logarithms, and units of information
- 6.2 Trigonometry, rotations, complex numbers, and Euler’s formula
- 6.3 Sequences, geometric series, and frequency ladders
- 6.4 Polynomials, Horner’s rule, and stable quadratic roots
- 6.5 Problem set: functions, logarithms, trigonometry, series, polynomials, and inequalities
- 9.1 Vectors, matrices, row-major layout, and matmul
- 9.2 Gaussian elimination and LU with partial pivoting
- 9.3 Orthogonality, Householder QR, and orthogonal initialization
- 9.4 Eigenvalues, power iteration, and the spectral radius
- 9.5 SVD, Eckart-Young low rank, and least squares
- 9.6 Inner products, projections, cosine similarity, and top-k
- 9.7 Linear algebra problem set, part a: elimination, LU, bases, rank, determinants, eigenvalues, QR
- 9.8 Linear algebra problem set, part b: inner products, SVD and low rank, matmul accounting and the roofline
Discrete mathematics and uncertainty
Section titled “Discrete mathematics and uncertainty”- 11.1 Counting: parameters, FLOPs, KV bytes, and memory plans
- 11.2 Injective, surjective, bijective: the GPT-2 byte map
- 11.3 Discrete math 1 problem set: sets, counting, proofs, induction, relations, bijections
- 11.3.1 Tools and a worked proof
- 11.3.2 Sets, logic, and counting
- 11.3.3 Proofs, induction, and invariants
- 11.3.4 Relations, functions, and validation
- 12.1 Graphs, DAGs, and an iterative topological sort
- 12.2 Trees and tries, longest-prefix match
- 12.3 Modular arithmetic, hashing, and PCG32 in Python
- 12.4 Discrete math 2 problem set, part a: DAGs, modular arithmetic, hashing
- 12.5 Discrete math 2 problem set, part b: trees, birthday bounds, MinHash and LSH, Bloom filters, recurrences
- 13.1 Random variables, expectation, variance, and normal draws by Box-Muller
- 13.2 Categorical sampling: inverse CDF, Gumbel-max, alias method
- 13.3 MLE, Laplace, absolute discounting
- 13.4 Variance propagation and initialization
- 13.5 LLN, CLT, confidence intervals, bootstrap
- 13.6 Hypothesis tests: paired and two-sample permutation, McNemar, Holm
- 13.7 Rejection sampling and residual distributions
- 13.8 Logistic regression (IRLS), ROC-AUC, calibration (ECE)
- 13.9 Probability problem set, part a: axioms, Bayes, random variables, Box-Muller
- 13.10 Probability problem set, part b: joint distributions, covariance, MLE
- 13.11 Probability problem set, part c: limit theorems and confidence intervals
- 13.12 Probability problem set, part d: hypothesis tests, regression, queueing, balls into bins
Numerics, optimization, and information
Section titled “Numerics, optimization, and information”- 14.1 Dual numbers and forward-mode autodiff
- 14.2 Scalar reverse mode: the Value graph
- 14.3 Matrix differentials, the trace trick, and closed-form VJPs
- 14.4 Hessian-vector products and the recompute-versus-memory schedule
- 14.5 Matrix calculus problem set: differentials, trace trick, VJPs, SDPA Jacobian
- 15.1 IEEE 754 anatomy, ulps, and round to nearest even
- 15.2 Stable numerics: logsumexp, softmax, and compensated sums
- 15.3 Error analysis, condition numbers, and tolerance budgets
- 15.4 FP8 and microscaling formats
- 15.5 Fixed-point iteration and fast inverse square root in C
- 15.6 Polynomial approximation and range reduction: expf in C
- 15.7 Low-precision conversions in C
- 15.8 Problem set A: representation, rounding, and cancellation
- 15.9 Problem set B: condition numbers, error bounds, Newton, polynomial approximation, and low precision
- 16.1 Convexity, smoothness, gradient descent, and Armijo line search
- 16.2 The Optimizer protocol: SGD, momentum, Nesterov, weight decay
- 16.3 Adam and AdamW: bias correction and decoupled weight decay
- 16.4 Learning-rate schedules (cosine, WSD, Noam) and gradient clipping
- 16.5 Optimization problem set, part a: convexity, GD rates, momentum, Adam
- 16.6 Optimization problem set, part b: constrained optimization, duality, and DPO
- 17.1 Entropy, cross-entropy, KL, JS, and the k3 estimator
- 17.2 Perplexity, bits per byte, NLL accumulator
- 17.3 Mutual information, PMI, and PPMI
- 17.4 Information theory problem set, part a: entropy, chain rules, KL and cross-entropy
- 17.5 Information theory problem set, part b: coding and Huffman, mutual information, maximum entropy, rate-distortion
What you will be able to do
Section titled “What you will be able to do”- Model quantities, growth, constraints, and uncertainty in a concrete problem.
- Use calculus and linear algebra to explain change, geometry, and optimization.
- Reason with proofs, discrete structures, probability, and statistical evidence.
- Explain the numerical errors and stability limits of a computed result.
- Connect a derivation to its implementation and validate it with independent checks.
Ways through this book
Section titled “Ways through this book”Read the parts in order for the full progression, or choose a route below and follow its prerequisites. Pause at the review questions before revealing worked answers.
- Starting from intuition: Quantities and relationships, then Change and growth, then Project: plan a community event.
- Preparing for computing: Precalculus, then Linear Algebra, then Discrete Math 1, then Probability and Statistics.
- Preparing for AI and numerical work: Matrix Calculus and Autodiff, then Numerical Methods and Floating Point, then Optimization, then Information Theory.
Before you start
Section titled “Before you start”The opening part assumes arithmetic and curiosity. Later chapters state their prerequisites; use the prerequisite map to find gaps. Programming and Algorithms develops the coding background. AI Engineering and Data Engineering show where the mathematical models are used.
How to read these books explains the shared first-principles, prediction, reasoning, testing, and validation method.