# Maths in motion — ten references

95 original units, inventory dated 9 November 2026. Read originals for figures and proofs. Component exercises, without wholesale copying or certification.

## Immersive Linear Algebra

https://immersivemath.com/ila/

### Read the notation

A scalar is a number, a vector an ordered list, and a matrix an array representing a map in chosen bases. Distinguishing column vectors, transposes and indices prevents incompatible products. Check dimensions first: (m×n)(n×1) produces m components.

- [1.1 Brief Note on Notation](https://immersivemath.com/ila/ch01_introduction/ch01.html#sec_intro_notation)

u = (x, 1), v = (2, −1) ; u·v = 2x − 1

Example : x component of u = 2 → dot product = 3.

Solve : x component of u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 5.

### Trigonometry of motion

On the unit circle, cos θ and sin θ are coordinates. A length r gives (r cos θ, r sin θ). Degrees are convenient for arm controls; calculus and numerical functions use radians. Try a full turn and a quarter turn, checking the sign of y.

- [1.2 Some Trigonometry](https://immersivemath.com/ila/ch01_introduction/ch01.html#sec_intro_trigo)

x = 2 cos(θ) ; y = 2 sin(θ)

Example : Angle θ (degrees) = 30 → x coordinate = 1.7320508075688774.

Solve : Angle θ (degrees) = 60. Interpret, change an assumption, write a limitation.

Numerical answer : 1.0000000000000002.

### Points, displacements and arithmetic

A point denotes a position; a vector denotes a displacement. Add components and scale every component by a scalar. Addition is associative and commutative: two displacements reach the same endpoint in either order, although intermediate paths differ. Reconstruct the laboratory route with two arrows.

- [2.1 Points and Vectors](https://immersivemath.com/ila/ch02_vectors/ch02.html#auto_label_33)
- [2.2 Vector Addition](https://immersivemath.com/ila/ch02_vectors/ch02.html#sec_vec_addition)
- [2.3 Scalar Vector Multiplication](https://immersivemath.com/ila/ch02_vectors/ch02.html#sec_vec_scalar_mult)
- [2.4 Properties of Vector Arithmetic](https://immersivemath.com/ila/ch02_vectors/ch02.html#sec_vec_arithmetic)
- [2.7 Summary](https://immersivemath.com/ila/ch02_vectors/ch02.html#auto_label_36)

u = (x, 1), v = (−1, 2) ; u + v

Example : First displacement x component = 2 → first sum component = 1.

Solve : First displacement x component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Bases and coordinates

Columns of B are new basis vectors expressed in the old basis. Coordinates c represent v=Bc; recovering c requires solving Bc=v. An orthogonal rotation gives B⁻¹=Bᵀ; a general basis needs an actual inverse. An oblique basis shows why coordinates are not always orthogonal projections.

- [2.5 Vector Bases and Coordinates](https://immersivemath.com/ila/ch02_vectors/ch02.html#sec_vec_bases)
- [5.10 Change of Basis](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_change_of_basis)
- [6.8 Change of Base](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_change_of_base)

A=[[2,1],[1,1]], b=(c,1) ; A⁻¹=[[1,−1],[−1,2]] ; A⁻¹b

Example : Right-hand side c = 2 → first solution component = 1.

Solve : Right-hand side c = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Spaces of arbitrary dimension

A vector space is closed under addition and scalar multiplication, with a zero vector and the usual laws. A subspace must contain zero: y=2x qualifies, y=2x+1 does not. A robot state or embedding can have hundreds of coordinates while obeying the same rules.

- [2.6 Vector Spaces with More Than 3 Dimensions](https://immersivemath.com/ila/ch02_vectors/ch02.html#auto_label_34)
- [2.6.1 The General Definition](https://immersivemath.com/ila/ch02_vectors/ch02.html#auto_label_35)
- [8.1 Linear Subspaces](https://immersivemath.com/ila/ch08_rank/ch08.html#sec_linear_subspace)

u = (x, 1), v = (−1, 2) ; u + v

Example : First displacement x component = 2 → first sum component = 1.

Solve : First displacement x component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Dot product and work

In an orthonormal basis, u·v=Σuᵢvᵢ=‖u‖‖v‖cos θ. It measures alignment and the work of a constant force over a displacement. It is bilinear and symmetric. Reverse one direction and check the sign; the component formula depends on the basis.

- [3.1 Introduction](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_introduction)
- [3.2 Definition and Applications](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#auto_label_106)
- [3.2.3 Rules and Properties](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_rules_and_properties)
- [3.5 Some Examples](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_examples)

u = (x, 1), v = (2, −1) ; u·v = 2x − 1

Example : x component of u = 2 → dot product = 3.

Solve : x component of u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 5.

### Normalize and orthonormalize

The Euclidean norm is √(u·u). Dividing a nonzero vector by its norm gives a unit direction. Gram–Schmidt removes projections onto earlier directions, then normalizes. Orthonormal columns satisfy QᵀQ=I. An orthogonal matrix preserves lengths and angles even when its determinant is −1.

- [3.2.1 Unit Vectors and Normalization](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_normalization)
- [3.3 Orthonormal Basis](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_orthogonal_basis)
- [3.3.1 Vector Length in Orthonormal Basis](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_vector_length)
- [6.9 Orthogonal Matrices](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_orthogonal_matrices)

u = (x, 4) ; ‖u‖ = √(x² + 16)

Example : x component of u = 3 → norm = 5.

Solve : x component of u = 4. Interpret, change an assumption, write a limitation.

Numerical answer : 5.656854249492381.

### Project and bound an error

Projection onto nonzero v is ((u·v)/(v·v))v. The residual is orthogonal to v. Cauchy–Schwarz bounds |u·v| by ‖u‖‖v‖; the triangle inequality bounds ‖u+v‖ by ‖u‖+‖v‖. These bound an error without its exact direction. Check the residual to verify a projection.

- [3.2.2 Projection](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#auto_label_107)
- [3.4 Inequalities](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_inequalities)

u=(x,2), v=(1,1) ; projᵥu = (u·v)/(v·v) v

Example : x component of u = 2 → first projected component = 2.

Solve : x component of u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.5.

### Lines, planes and rays

A line is p+td and a plane is n·(x−p₀)=0. Substitution gives ray intersection t=n·(p₀−p)/(n·d). A zero denominator requires distinguishing a parallel ray from one lying in the plane. An intersection behind the origin (t<0) is not a hit for the directed ray.

- [3.6 Lines and Planes](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_lines_and_planes)
- [3.6.1 Lines](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_lines)
- [3.6.2 Planes](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_planes)
- [3.7 Follow up on Ray Tracing](https://immersivemath.com/ila/ch03_dotproduct/ch03.html#sec_dp_followup_ray_tracing)

u = (x, 1), v = (2, −1) ; u·v = 2x − 1

Example : x component of u = 2 → dot product = 3.

Solve : x component of u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 5.

### Orientation and cross product

In oriented 3D, u×v is perpendicular to both vectors; its norm is parallelogram area. The right-hand rule fixes the sign and v×u=−u×v. It is distributive but not associative. It computes surface normals and torque r×F, and vanishes for parallel directions.

- [4.1 Introduction](https://immersivemath.com/ila/ch04_vectorproduct/ch04.html#sec_vp_intro)
- [4.2 Orientation](https://immersivemath.com/ila/ch04_vectorproduct/ch04.html#sec_vp_orientation)
- [4.3 Definition of Vector Product](https://immersivemath.com/ila/ch04_vectorproduct/ch04.html#sec_vp_definition)
- [4.4 Rules and Properties](https://immersivemath.com/ila/ch04_vectorproduct/ch04.html#sec_vp_rules_and_properties)
- [4.7 Examples](https://immersivemath.com/ila/ch04_vectorproduct/ch04.html#sec_vp_examples)
- [4.8 Followup on the Introduction Example](https://immersivemath.com/ila/ch04_vectorproduct/ch04.html#sec_vp_followup)

u=(x,1,0), v=(1,2,0) ; u×v = (0,0,2x−1)

Example : x component of u = 2 → product z component = 3.

Solve : x component of u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 5.

### Triple products

The scalar triple product u·(v×w) is signed volume and a determinant. Zero volume signals dependent vectors. The vector triple product is u×(v×w)=v(u·w)−w(u·v), not an associative rule. Check dimensions: the first result is a scalar, the second a vector.

- [4.5 Scalar Triple Product](https://immersivemath.com/ila/ch04_vectorproduct/ch04.html#sec_vp_scalar_triple_product)
- [4.6 Vector Triple Product](https://immersivemath.com/ila/ch04_vectorproduct/ch04.html#sec_vp_vector_triple_product)

u=(x,0,0), v=(0,2,0), w=(0,0,3) ; u·(v×w)=6x

Example : x component of u = 2 → signed volume = 12.

Solve : x component of u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 18.

### Elimination and pivots

Elementary operations swap rows, scale an equation by a nonzero number, or add a multiple of another equation. They preserve solutions of the augmented system. Elimination builds pivots, followed by back substitution; a numerically tiny pivot is a reason to swap rows.

- [5.1 Introduction](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_introduction)
- [5.2 Examples](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_examples)
- [5.3 Gaussian Elimination](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_gaussian_elimination)
- [5.7 Theoretical Underpinning](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_theoretical_underpinning)
- [5.7.1 The Gaussian Elimination Rules](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_gauss_elim_rules)
- [5.7.2 The General Case](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_the_general_case)

a + b = c ; a − b = 1 ; a = (c+1)/2

Example : Right-hand side c = 3 → unknown a = 2.

Solve : Right-hand side c = 5. Interpret, change an assumption, write a limitation.

Numerical answer : 3.

### Singular and parametrized systems

A row 0=1 makes a system inconsistent; a variable without a pivot creates a free parameter. Ax=0 always admits zero, and its null space describes motions invisible to A. A general inhomogeneous solution is one particular solution plus a null-space vector: implicit and parametrized forms describe the same set.

- [5.4 Special Cases](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_special_cases)
- [5.5 The Homogeneous Case](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_homogeneous)
- [5.6 Implicit and Explicit form](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_implicit_and_explicit)

A=[[1,1],[1,x]] ; det=x−1 ; rang + nullité = 2

Example : Coefficient x (rank 1 when x = 1) = 1 → rank = 1.

Solve : Coefficient x (rank 1 when x = 1) = 2. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Independence and span

A family is independent when only all-zero coefficients give a zero linear combination. Its span contains all linear combinations. For a square matrix, independent columns, full span and invertibility are equivalent; for a rectangular matrix, distinguish column rank from the number of unknowns.

- [5.8 Linear Dependence and Independence](https://immersivemath.com/ila/ch05_gausselim/ch05.html#auto_label_300)
- [5.9 Spanning](https://immersivemath.com/ila/ch05_gausselim/ch05.html#sec_ge_spanning)
- [6.7 Inverses, Independence, and Span](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_inverse_independence_span)

A=[[1,1],[1,x]] ; det=x−1 ; rang + nullité = 2

Example : Coefficient x (rank 1 when x = 1) = 1 → rank = 1.

Solve : Coefficient x (rank 1 when x = 1) = 2. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Matrix arithmetic

Addition and scalar multiplication act componentwise. Each entry of AB is a row–column dot product, and inner dimensions must agree. Multiplication is associative and distributive but generally AB≠BA. Test this with homogeneous rotation and translation.

- [6.1 Introduction](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_intro)
- [6.2 Definition](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_def)
- [6.3 Matrix Operations](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_operations)
- [6.3.1 Matrix Multiplication by a Scalar](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_mult_by_scalar)
- [6.3.2 Matrix Addition](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_addition)
- [6.3.3 Matrix-Matrix Multiplication](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_matrix_mult)
- [6.5 Properties of Matrix Arithmetic](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_matrix_rules)

R₉₀(x,1) + (2,3) = (1,x+3)

Example : Point x component = 2 → final y coordinate = 5.

Solve : Point x component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 6.

### Geometric matrices

Matrix columns are images of basis vectors. Rotation, reflection, scaling and shear are linear; translation does not fix zero and is affine. Homogeneous coordinates add one component to compose rotations and translations. In 3D, rotations about different axes generally do not commute.

- [6.4 Some Useful Two- and Three-Dimensional Matrices](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_useful_matrices)
- [6.4.1 Two Dimensions](https://immersivemath.com/ila/ch06_matrices/ch06.html#auto_label_435)
- [6.4.2 Three Dimensions](https://immersivemath.com/ila/ch06_matrices/ch06.html#auto_label_436)
- [6.10 Followup on the Introduction Example](https://immersivemath.com/ila/ch06_matrices/ch06.html#sec_mtx_followup)

R₉₀(x,1) + (2,3) = (1,x+3)

Example : Point x component = 2 → final y coordinate = 5.

Solve : Point x component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 6.

### Invert without confusing operations

A⁻¹ undoes a square invertible A on both sides. Solving Ax=b by elimination is preferable to explicitly forming the entire inverse. Product inversion reverses order: (AB)⁻¹=B⁻¹A⁻¹. A near-zero determinant warns of trouble, but conditioning better measures perturbation sensitivity.

- [6.6 Matrix Inverse](https://immersivemath.com/ila/ch06_matrices/ch06.html#auto_label_437)
- [9.4 Inverse Mapping](https://immersivemath.com/ila/ch09_linear_mappings/ch09.html#auto_label_762)

A=[[2,1],[1,1]], b=(c,1) ; A⁻¹=[[1,−1],[−1,2]] ; A⁻¹b

Example : Right-hand side c = 2 → first solution component = 1.

Solve : Right-hand side c = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Determinants, permutations and volume

A determinant measures signed volume scaling. In 2D it is ad−bc; in dimension n the formula sums signed products over permutations. Swapping columns reverses the sign. Zero determinant is equivalent to dependent columns of a square matrix.

- [7.1 Introduction](https://immersivemath.com/ila/ch07_determinants/ch07.html#sec_dt_intro)
- [7.2 Definition](https://immersivemath.com/ila/ch07_determinants/ch07.html#sec_dt_definition)
- [7.3 Permutations and Determinants](https://immersivemath.com/ila/ch07_determinants/ch07.html#sec_dt_permutations)
- [7.8 Determinants, Independence, and Invertibility](https://immersivemath.com/ila/ch07_determinants/ch07.html#sec_main_theorem)

A=[[x,1],[1,2]] ; det(A)=2x−1

Example : Coefficient a₁₁ = 2 → determinant = 3.

Solve : Coefficient a₁₁ = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 5.

### Cofactors, adjugate and Cramer

det(AB)=det(A)det(B), det(Aᵀ)=det(A), and det(A⁻¹)=1/det(A). Column expansion uses minors and alternating signs. The adjugate transposes cofactors and A⁻¹=adj(A)/det(A). Cramer replaces a column with b; these explain algebra but are not a general numerical strategy.

- [7.4 Transposition, Multiplication, and Inverse](https://immersivemath.com/ila/ch07_determinants/ch07.html#sec_transposition)
- [7.5 Expansion Along a Column](https://immersivemath.com/ila/ch07_determinants/ch07.html#sec_dt_expansion)
- [7.6 Adjoint Matrix](https://immersivemath.com/ila/ch07_determinants/ch07.html#sec_adjoint)
- [7.7 Cramer's Rule](https://immersivemath.com/ila/ch07_determinants/ch07.html#sec_cramers_rule)

A=[[x,1],[1,2]] ; det(A)=2x−1

Example : Coefficient a₁₁ = 2 → determinant = 3.

Solve : Coefficient a₁₁ = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 5.

### Null space, image and rank theorem

The null space contains x with Ax=0; the image is spanned by columns. Row rank equals column rank. For n columns, rank(A)+dim ker(A)=n. A rank-deficient sensor matrix leaves state directions unobserved; identify which directions disappear.

- [8.2 Null Space and Nullity](https://immersivemath.com/ila/ch08_rank/ch08.html#sec_rank_null_space)
- [8.3 Column Space, Row Space, and Rank](https://immersivemath.com/ila/ch08_rank/ch08.html#auto_label_684)
- [8.4 Rank and Determinants](https://immersivemath.com/ila/ch08_rank/ch08.html#auto_label_685)
- [8.5 Followup on the Introduction Example](https://immersivemath.com/ila/ch08_rank/ch08.html#auto_label_686)

A=[[1,1],[1,x]] ; det=x−1 ; rang + nullité = 2

Example : Coefficient x (rank 1 when x = 1) = 1 → rank = 1.

Solve : Coefficient x (rank 1 when x = 1) = 2. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Maps and compositions

A linear map preserves sums and scalar multiples. Its columns are images of a chosen basis; changing bases changes its matrix, not the map. Applying A then B gives BAx. The lab illustrates composition with affine transforms, which require homogeneous coordinates because of translation.

- [9.1 Introduction](https://immersivemath.com/ila/ch09_linear_mappings/ch09.html#sec_lm_introduction)
- [9.2 Transformation Matrices](https://immersivemath.com/ila/ch09_linear_mappings/ch09.html#auto_label_760)
- [9.3 Composite Linear Mappings](https://immersivemath.com/ila/ch09_linear_mappings/ch09.html#auto_label_761)

R₉₀(x,1) + (2,3) = (1,x+3)

Example : Point x component = 2 → final y coordinate = 5.

Solve : Point x component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 6.

### Eigenvalues and characteristic polynomial

Av=λv with nonzero v defines an eigen direction. Roots of det(A−λI) give eigenvalues; solving (A−λI)v=0 gives eigenvectors. Their sum is the trace and product the determinant, counting multiplicities. Eigenvalues can be complex for real matrices; a general plane rotation has no real eigen direction.

- [10.1 Introduction](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_introduction)
- [10.2 Eigenvalues and Eigenvectors](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_definition)
- [10.3 Calculating Eigenvalues and Eigenvectors](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_calculation)
- [10.7 Miscellaneous Results on Eigenvalues and Eigenvectors](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_miscellaneous)

A=[[2,0],[0,3]], v=(x,0) ; Av=2v

Example : Component on the first direction = 2 → first component of Av = 4.

Solve : Component on the first direction = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 6.

### Diagonalization and dynamics

With an eigenvector basis, A=SΛS⁻¹ and Aᵏ=SΛᵏS⁻¹. A real symmetric matrix has an orthonormal basis: A=QΛQᵀ, with maximum stretch max|λ|. General matrices require singular values for maximum stretch. Eigenmodes explain stability, Markov chains and optimization; not every matrix is diagonalizable.

- [10.4 Diagonalization](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_diagonalization)
- [10.5 Diagonalization of symmetric matrices](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_diagonalization_symmetry)
- [10.6 Max Elongation of a Vector During Linear Mapping](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_example_elongation2)
- [10.8 Eigenvalues and Eigenvectors are Useful](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_applications)
- [10.9 Outlook](https://immersivemath.com/ila/ch10_eigen/ch10.html#sec_eig_outlook)

A=[[2,0],[0,3]], v=(x,0) ; Av=2v

Example : Component on the first direction = 2 → first component of Av = 4.

Solve : Component on the first direction = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 6.

## Seeing Theory

https://seeing-theory.brown.edu/

### Events and frequencies

A probability lies in [0,1] and totals one across possible outcomes. An empirical frequency varies between samples; finitely many trials do not make it exactly equal to probability. Compare multiple measurement series before treating a fluctuation as a sensor change.

- [Chance Events](https://seeing-theory.brown.edu/basic-probability/index.html#section1)

frequency = successes / 10

Example : Successes in 10 trials = 3 → frequency = 0.3.

Solve : Successes in 10 trials = 4. Interpret, change an assumption, write a limitation.

Numerical answer : 0.4.

### Expected measurement

Expectation is a probability-weighted average: E[X]=ΣxP(X=x), or an integral against a density. It may be a value X never takes. Linearity E[aX+b]=aE[X]+b does not require independence; products need additional care.

- [Expectation](https://seeing-theory.brown.edu/basic-probability/index.html#section2)

X∈{0,2}, P(X=2)=p ; E[X]=2p ; Var(X)=4p(1−p)

Example : Probability p = 0.25 → expectation = 0.5.

Solve : Probability p = 0.5. Interpret, change an assumption, write a limitation.

Numerical answer : 1.

### Spread and variance

Var(X)=E[(X−E[X])²]=E[X²]−E[X]²; its unit is squared. Standard deviation restores the measurement unit. Independent variances add; correlated measurements require covariance terms. A very stable sensor can still be biased.

- [Variance](https://seeing-theory.brown.edu/basic-probability/index.html#section3)

X∈{0,2}, P(X=2)=p ; Var(X)=4p(1−p)

Example : Probability p = 0.25 → variance = 0.75.

Solve : Probability p = 0.5. Interpret, change an assumption, write a limitation.

Numerical answer : 1.

### Sets and events

Union, intersection and complement encode “or”, “and” and “not”. P(A∪B)=P(A)+P(B)−P(A∩B) avoids double counting. Disjoint events have empty intersection; independent events satisfy P(A∩B)=P(A)P(B), a different property.

- [Set Theory](https://seeing-theory.brown.edu/compound-probability/index.html#section1)

P(A)=0.4, P(B)=0.5 ; P(A∪B)=0.9−P(A∩B)

Example : P(A∩B) = 0.2 → union probability = 0.7.

Solve : P(A∩B) = 0.1. Interpret, change an assumption, write a limitation.

Numerical answer : 0.8.

### Count before dividing

Permutations count orders; combinations select without order. Choosing k distinct objects from n without replacement gives C(n,k)=n!/(k!(n−k)!). “Favourable / possible cases” requires equally likely outcomes; check that assumption first.

- [Counting](https://seeing-theory.brown.edu/compound-probability/index.html#section2)

C(n,2)=n(n−1)/2

Example : Objects n (integer) = 5 → combination count = 10.

Solve : Objects n (integer) = 6. Interpret, change an assumption, write a limitation.

Numerical answer : 15.

### Conditioning and independence

Conditioning on B restricts the universe to B: P(A|B)=P(A∩B)/P(B), for P(B)>0. Independence means P(A|B)=P(A), not incompatibility. A sensor whose noise depends on temperature calls for conditioning the model on temperature.

- [Conditional Probability](https://seeing-theory.brown.edu/compound-probability/index.html#section3)

P(B)=0.5 ; P(A|B)=P(A∩B)/0.5

Example : P(A∩B) = 0.2 → conditional probability = 0.4.

Solve : P(A∩B) = 0.3. Interpret, change an assumption, write a limitation.

Numerical answer : 0.6.

### Random variables

A random variable assigns a number to each outcome. Different outcomes may share a value, and their probabilities add. Mapping “left target” and “right target” to robot distance produces a distribution of distances different from the distribution of states.

- [Random Variables](https://seeing-theory.brown.edu/probability-distributions/index.html#section1)

X∈{0,2}, P(X=2)=p ; E[X]=2p ; Var(X)=4p(1−p)

Example : Probability p = 0.25 → expectation = 0.5.

Solve : Probability p = 0.5. Interpret, change an assumption, write a limitation.

Numerical answer : 1.

### Discrete and continuous distributions

A discrete distribution assigns mass to values; a continuous distribution has a density integrated over a region. Density can exceed one, probability cannot. The cumulative distribution F(b)=P(X≤b) applies to both. An individual point has probability zero under a continuous distribution.

- [Discrete and Continuous](https://seeing-theory.brown.edu/probability-distributions/index.html#section2)

X∼U[0,4] ; P(0≤X≤b)=b/4 ; P(X=b)=0

Example : Bound b in [0,4] = 1 → interval probability = 0.25.

Solve : Bound b in [0,4] = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 0.75.

### Central limit theorem

For independent identically distributed measurements with finite variance, the standardized mean approaches a normal distribution. Its standard error is σ/√n. Individual measurements do not become normal and bias remains. Heavy tails or dependence can invalidate this simple approximation.

- [Central Limit Theorem](https://seeing-theory.brown.edu/probability-distributions/index.html#section3)

σ=2 ; standard error of the mean = 2/√n

Example : Size n (integer) = 4 → standard error = 1.

Solve : Size n (integer) = 16. Interpret, change an assumption, write a limitation.

Numerical answer : 0.5.

### Point estimation and bias

An estimator is a rule applied to a sample; an estimate is its observed value. The mean estimates position under zero-mean noise. An unbiased iid variance estimate divides squared deviations by n−1. Mean squared error combines variance and squared bias.

- [Point Estimation](https://seeing-theory.brown.edu/frequentist-inference/index.html#section1)

measurements=(1,2,x) ; mean=(3+x)/3

Example : Third measurement = 3 → mean = 2.

Solve : Third measurement = 6. Interpret, change an assumption, write a limitation.

Numerical answer : 3.

### Confidence interval

A 95% procedure covers a fixed parameter in 95% of repetitions under its assumptions. It does not assign 95% frequentist probability to that parameter after observation. This exercise assumes known variance and a normal mean; estimated variance calls for a Student interval under normality.

- [Confidence Interval](https://seeing-theory.brown.edu/frequentist-inference/index.html#section2)

known σ=2 ; mean=5 ; 95% half-width ≈1.96×2/√n

Example : Size n (integer) = 4 → half-width = 1.96.

Solve : Size n (integer) = 16. Interpret, change an assumption, write a limitation.

Numerical answer : 0.98.

### Bootstrap and sample limitations

Bootstrap resamples n observations with replacement and recomputes a statistic. Repetition approximates its sampling distribution. One resample, as here, illustrates mechanics without estimating an interval. Bootstrap cannot reveal unobserved situations and dependent series need an adapted method.

- [The Bootstrap](https://seeing-theory.brown.edu/frequentist-inference/index.html#section3)

data=(1,2,x) ; sampled indices=(0,2,2) ; mean*=(1+2x)/3

Example : Third data point = 4 → resampled mean = 3.

Solve : Third data point = 7. Interpret, change an assumption, write a limitation.

Numerical answer : 5.

### Bayes and base rates

Bayes reverses a condition: P(H|D)=P(D|H)P(H)/P(D). The denominator sums routes producing the data. High sensitivity is insufficient when objects are rare: false positives may dominate. Compare two priors with the same sensor.

- [Bayes' Theorem](https://seeing-theory.brown.edu/bayesian-inference/index.html#section1)

P(+|object)=0.9, P(+|empty)=0.2 ; P(object|+)=0.9p/(0.9p+0.2(1−p))

Example : Prior probability p = 0.1 → posterior probability = 0.33333333333333337.

Solve : Prior probability p = 0.2. Interpret, change an assumption, write a limitation.

Numerical answer : 0.5294117647058822.

### Likelihood and parameters

Likelihood L(θ)=P(data|θ) is a function of the parameter with data fixed. It is not a probability distribution over θ. Independent Bernoulli trials with s successes out of n give likelihood proportional to pˢ(1−p)ⁿ⁻ˢ. Compare candidates without swapping parameters and observations.

- [Likelihood Function](https://seeing-theory.brown.edu/bayesian-inference/index.html#section2)

3 successes out of 4 ; L(p)=C(4,3)p³(1−p)

Example : Candidate probability p = 0.5 → likelihood = 0.25.

Solve : Candidate probability p = 0.8. Interpret, change an assumption, write a limitation.

Numerical answer : 0.4096.

### Prior to posterior

With a Beta(a,b) prior and independent Bernoulli data, the posterior is Beta(a+s,b+n−s). The prior contributes pseudo-counts whose relative influence declines as n grows. Posterior mean and maximum likelihood usually differ. The exercise uses Beta(2,2) and four trials.

- [Prior to Posterior](https://seeing-theory.brown.edu/bayesian-inference/index.html#section3)

prior Beta(2,2) ; posterior Beta(2+s,6−s) ; mean=(2+s)/8

Example : Successes s out of 4 (integer) = 2 → posterior mean = 0.5.

Solve : Successes s out of 4 (integer) = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 0.625.

### Ordinary least squares

OLS minimizes Σ(yᵢ−a−bxᵢ)². Slope is Σ(xᵢ−x̄)(yᵢ−ȳ)/Σ(xᵢ−x̄)² for nonconstant x, and intercept is ȳ−bx̄. Residuals are orthogonal to design-matrix columns. Outliers or errors in x call for reconsidering the model.

- [Ordinary Least Squares](https://seeing-theory.brown.edu/regression-analysis/index.html#section1)

x=(0,1,2), y=(0,2,c) ; OLS slope=c/2 ; intercept=(2+c)/3−c/2

Example : Last observation y₃ = 4 → slope = 2.

Solve : Last observation y₃ = 6. Interpret, change an assumption, write a limitation.

Numerical answer : 3.

### Correlation and causality

Pearson correlation normalizes covariance by both standard deviations. It measures linear association, not causation; nonlinear dependence can have zero correlation. Zero variance makes it undefined. Positive scaling preserves correlation; negative scaling reverses its sign.

- [Correlation](https://seeing-theory.brown.edu/regression-analysis/index.html#section2)

x=(1,2,3), y=cx ; corr(x,y)=sign(c)

Example : Nonzero scale c = 2 → correlation = 1.

Solve : Nonzero scale c = -2. Interpret, change an assumption, write a limitation.

Numerical answer : -1.

### Analysis of variance

ANOVA compares between-group and within-group variation. F divides mean squares, already adjusted by degrees of freedom. A large value does not identify which pair differs. The test requires independence and an appropriate residual model. This exercise computes F without claiming a p-value.

- [Analysis of Variance](https://seeing-theory.brown.edu/regression-analysis/index.html#section3)

within-group MS=2 ; F = between-group MS / within-group MS

Example : Between-group mean square = 6 → F ratio = 3.

Solve : Between-group mean square = 8. Interpret, change an assumption, write a limitation.

Numerical answer : 4.

## Markov Chains · Explained Visually

https://setosa.io/ev/markov-chains/

### States and the Markov property

A state should summarize information needed for the next step: P(Sₖ₊₁|Sₖ,…)=P(Sₖ₊₁|Sₖ). Two states allow four transitions, including self-loops. If time spent in a zone affects the future, augment the state or change the model. One sampled transition is not the full transition distribution.

- [States and transitions](https://setosa.io/ev/markov-chains/)

P=[[0.8,0.2],[0.3,0.7]] ; p′(A)=0.8p+0.3(1−p)

Example : Initial P(A) = 0.6 → next probability of A = 0.6.

Solve : Initial P(A) = 0.8. Interpret, change an assumption, write a limitation.

Numerical answer : 0.7.

### Stochastic matrix and propagation

With the row convention, Pᵢⱼ≥0 and ΣⱼPᵢⱼ=1; a row distribution evolves as p′=pP. N states require N² entries before constraints. In the three-zone lab, compare sample frequencies with exact probabilities: a finite simulated population also produces discrepancies.

- [Transition matrix and editable playground](https://setosa.io/ev/markov-chains/)

P=[[0.8,0.2],[0.3,0.7]] ; p′(A)=0.8p+0.3(1−p)

Example : Initial P(A) = 0.6 → next probability of A = 0.6.

Solve : Initial P(A) = 0.8. Interpret, change an assumption, write a limitation.

Numerical answer : 0.7.

### Persistence, weather and equilibrium

Two chains can have the same average rainy fraction but very different run lengths. Strong self-loops produce persistence. A stationary distribution satisfies πP=π; convergence to a unique equilibrium requires conditions, including irreducibility and aperiodicity for a finite chain. An alternating chain is a convergence counterexample.

- [Weather persistence and simulation](https://setosa.io/ev/markov-chains/)

π(A)=0.6 ; after 2 steps: p₂(A)=0.6+0.25(p₀−0.6)

Example : Initial P(A) = 0.2 → probability of A after two steps = 0.5.

Solve : Initial P(A) = 0.9. Interpret, change an assumption, write a limitation.

Numerical answer : 0.675.

## How a Kalman Filter Works, in Pictures

https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/

### Define state and uncertainty

The filter estimates a distribution over a hidden state such as position and velocity. Covariance stores variances on the diagonal and covariances off it; covariance is not normalized correlation. It must be symmetric positive semidefinite. A position observation can correct velocity through their covariance.

- [What is it?](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)
- [What can we do with a Kalman filter?](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)
- [How a Kalman filter sees your problem](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)

P=[[1,c],[c,1]] ; λmin=1−|c| ≥0 ; det=1−c²

Example : Covariance c = 0.5 → smallest eigenvalue = 0.5.

Solve : Covariance c = -0.5. Interpret, change an assumption, write a limitation.

Numerical answer : 0.5.

### Matrix prediction and control

For a linear model, x̂⁻=Fx̂+Bu. F transports state and B maps known control into state units. Covariance transports as FPFᵀ; a deterministic translation adds no uncertainty. Check position and velocity separately: discretized continuous kinematics differs from semi-implicit integration.

- [Describing the problem with matrices](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)
- [External influence](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)

Δt=1, position=1, velocity=2 ; predicted position=1+2+u/2

Example : Known acceleration u = 2 → predicted position = 4.

Solve : Known acceleration u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 4.5.

### Process and measurement noise

The model uses P⁻=FPFᵀ+Q and z=Hx+v with Cov(v)=R. Q and R represent different errors. A scalar position observation has H=[1,0], which is not invertible; preserve dimensions in the equations. Reducing R without improving the sensor creates overconfidence.

- [External uncertainty](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)
- [Refining the estimate with measurements](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)

P=[[1,c],[c,1]] ; λmin=1−|c| ≥0 ; det=1−c²

Example : Covariance c = 0.5 → smallest eigenvalue = 0.5.

Solve : Covariance c = -0.5. Interpret, change an assumption, write a limitation.

Numerical answer : 0.5.

### Fuse two Gaussians

Multiplying a Gaussian prior by a Gaussian likelihood and normalizing gives a Gaussian posterior in the linear case. Scalar precisions (inverse variances) add. Gain P⁻/(P⁻+R) controls correction. Dependencies must be modeled coherently: counting the same information twice overstates precision.

- [Combining Gaussians](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)

x⁻=2, P⁻=4, R=1, H=1 ; K=0.8 ; x=2+0.8(z−2)

Example : Measurement z = 7 → corrected position = 6.

Solve : Measurement z = 4. Interpret, change an assumption, write a limitation.

Numerical answer : 3.6.

### Innovation, gain and complete loop

Innovation is y=z−Hx̂⁻ with covariance S=HP⁻Hᵀ+R. Gain is K=P⁻HᵀS⁻¹, then x̂=x̂⁻+Ky. Joseph form P=(I−KH)P⁻(I−KH)ᵀ+KRKᵀ better preserves numerical symmetry. Alternate prediction and correction; during dropout, predict without inventing measurements.

- [Putting it all together](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)

x⁻=2, P⁻=4, R=1, H=1 ; K=0.8 ; x=2+0.8(z−2)

Example : Measurement z = 7 → corrected position = 6.

Solve : Measurement z = 4. Interpret, change an assumption, write a limitation.

Numerical answer : 3.6.

### Nonlinearity and consistency

The linear Gaussian filter is exact under its assumptions; a wrong model can give a precise but wrong estimate. EKF uses local Jacobians to propagate covariance while predicting the mean with the nonlinear function. This local approximation gives no global guarantee. Test bias in the integrated mission.

- [Wrapping up](https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/)

Δt=1, position=1, velocity=2 ; predicted position=1+2+u/2

Example : Known acceleration u = 2 → predicted position = 4.

Solve : Known acceleration u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 4.5.

## Introduction to A* · Red Blob Games

https://www.redblobgames.com/pathfinding/a-star/introduction.html

### Map, vertices and edges

A graph abstracts the map: vertices are states and edges permitted moves. Obstacles remove passages and weights express costs. A point path does not ensure clearance for a robot with radius. Account for its footprint; the integrated mission also checks disk collisions.

- [Representing the map](https://www.redblobgames.com/pathfinding/a-star/introduction.html#graphs)

cell=(2,1), goal=(5,3) ; Manhattan h=5 ; f=g+h

Example : Accumulated cost g = 3 → priority f = 8.

Solve : Accumulated cost g = 5. Interpret, change an assumption, write a limitation.

Numerical answer : 10.

### Breadth-first search and stopping

BFS uses a FIFO queue and visits in increasing edge count. It finds a shortest path when edge costs are equal. Store each vertex parent to reconstruct the path, then stop on reaching the goal according to the algorithm. Explored-cell count differs from final path length.

- [Breadth First Search](https://www.redblobgames.com/pathfinding/a-star/introduction.html#breadth-first-search)
- [Early exit](https://www.redblobgames.com/pathfinding/a-star/introduction.html#early-exit)

cell=(2,1), goal=(5,3) ; Manhattan h=5 ; f=g+h

Example : Accumulated cost g = 3 → priority f = 8.

Solve : Accumulated cost g = 5. Interpret, change an assumption, write a limitation.

Numerical answer : 10.

### Costs and relaxation

Dijkstra prioritizes accumulated cost g. Relaxing u→v compares g(v) with g(u)+cost(u,v). With nonnegative costs, removing the goal from the queue settles its optimal cost. A geometrically shorter route can cost more when it crosses slow terrain.

- [Movement costs](https://www.redblobgames.com/pathfinding/a-star/introduction.html#dijkstra)

g(u)=3, g(v)=8 ; g′(v)=min(8,3+edge cost)

Example : Edge cost = 2 → new cost g(v) = 5.

Solve : Edge cost = 4. Interpret, change an assumption, write a limitation.

Numerical answer : 7.

### Heuristic and greedy search

A heuristic h estimates remaining cost. Greedy search uses h alone: it may reach the goal quickly while missing a cheaper detour. Manhattan distance suits a grid without diagonals and with a known minimum step cost. Changing permitted moves requires revisiting the heuristic.

- [Heuristic search](https://www.redblobgames.com/pathfinding/a-star/introduction.html#greedy-best-first)

cell=(2,1), goal=(5,3) ; Manhattan h=5 ; f=g+h

Example : Accumulated cost g = 3 → priority f = 8.

Solve : Accumulated cost g = 5. Interpret, change an assumption, write a limitation.

Numerical answer : 10.

### A* and optimality

A* prioritizes f=g+h. An admissible heuristic never overestimates remaining cost; consistency h(u)≤c(u,v)+h(v) lets vertices be settled without reopening. Otherwise, reopenings must be handled correctly. h=0 recovers Dijkstra. Compare final cost and expansions, then follow the original implementation links.

- [The A* algorithm](https://www.redblobgames.com/pathfinding/a-star/introduction.html#astar)
- [More: implementation and reference links](https://www.redblobgames.com/pathfinding/a-star/introduction.html#more)

cell=(2,1), goal=(5,3) ; Manhattan h=5 ; f=g+h

Example : Accumulated cost g = 3 → priority f = 8.

Solve : Accumulated cost g = 5. Interpret, change an assumption, write a limitation.

Numerical answer : 10.

## An Interactive Introduction to Fourier Transforms

https://www.jezzamon.com/fourier/index.html

### Sinusoid sums and sound

A signal can be represented by sinusoid amplitudes and phases. For N samples, DFT Xₖ=Σₙxₙexp(−2πikn/N). Bin zero carries the constant component. The inverse includes 1/N in this convention. Amplitudes alone lose the phase needed for reconstruction.

- [So what is this thing? — waves and sound](https://www.jezzamon.com/fourier/index.html#sowhatisthisthing)

signal=(1,2,3,x) ; X₀=Σsignal ; mean=X₀/4

Example : Fourth sample = 4 → coefficient X₀ = 10.

Solve : Fourth sample = 8. Interpret, change an assumption, write a limitation.

Numerical answer : 14.

### Harmonics and compression

An ideal square wave needs infinitely many harmonics; truncation oscillates near discontinuities (Gibbs). Removing coefficients can compress data but erase useful signal. Real audio codecs do more than threshold a DFT. Compare error against clean signal, not just visual smoothness.

- [Square wave, drawing and lossy compression](https://www.jezzamon.com/fourier/index.html#sowhatisthisthing)

fₛ=64 Hz ; aliased frequency = min(f,64−f)

Example : Frequency in Hz = 5 → aliased frequency = 5.

Solve : Frequency in Hz = 40. Interpret, change an assumption, write a limitation.

Numerical answer : 24.

### Complex numbers and epicycles

Encode a plane drawing as z(t)=x(t)+iy(t). Each term cₖexp(2πikt/T) rotates in the complex plane and their sum traces the curve. Negative frequencies rotate oppositely. Time parametrization matters: traversing the same contour at a different speed changes coefficients.

- [Epicycles](https://www.jezzamon.com/fourier/index.html#epicycles)

x = 2 cos(θ) ; y = 2 sin(θ)

Example : Angle θ (degrees) = 30 → x coordinate = 1.7320508075688774.

Solve : Angle θ (degrees) = 60. Interpret, change an assumption, write a limitation.

Numerical answer : 1.0000000000000002.

### 2D bases and JPEG

A 2D image basis combines horizontal and vertical patterns. JPEG uses an 8×8 block DCT followed by quantization and coding; quantization causes most loss. Our constant 2×2 orthonormal DCT isolates the DC coefficient. This is not a JPEG encoder and omits colour conversions.

- [JPEGs](https://www.jezzamon.com/fourier/index.html#jpegs)

constant 2×2 block c ; orthonormal DCT: DC coefficient = 2c ; AC=0

Example : Pixel value c = 2 → DC coefficient = 4.

Solve : Pixel value c = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 6.

### Continuous, discrete, FFT and windows

The continuous transform is an integral; a discrete-time sequence has a frequency-continuous DTFT; a DFT gives N values for N samples. FFT computes that same DFT faster. A whole song can be analyzed with successive windows (STFT): long and short windows trade time against frequency resolution. Frequencies beyond Nyquist alias.

- [Conclusion](https://www.jezzamon.com/fourier/index.html#conclusion)
- [Questions for the curious](https://www.jezzamon.com/fourier/index.html#questionsforthecurious)

fₛ=64 Hz ; aliased frequency = min(f,64−f)

Example : Frequency in Hz = 5 → aliased frequency = 5.

Solve : Frequency in Hz = 40. Interpret, change an assumption, write a limitation.

Numerical answer : 24.

## Why Momentum Really Works · Distill

https://distill.pub/2017/momentum/

### Differentiate to reduce loss

The gradient collects partial derivatives. The update w′=w−α∇f(w) decreases loss locally for a sufficiently small step. For f(w)=w², ∇f=2w and the error factor is 1−2α. Check the derivative with a centered finite difference; loss alone does not specify a direction.

- [First Steps: Gradient Descent](https://distill.pub/2017/momentum/)

f(w)=w² ; ∇f=2w ; α=0.1 ; w′=w−0.1×2w

Example : Position w = 2 → new weight w′ = 1.6.

Solve : Position w = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.4000000000000004.

### Decompose error and choose a step

For a quadratic with symmetric positive Hessian, eigen directions separate: e′ᵢ=(1−αλᵢ)eᵢ. Convergence requires 0<α<2/L for largest eigenvalue L. With μ>0, optimal constant GD step is 2/(L+μ). Large condition number κ=L/μ explains a slow direction alongside oscillations in another.

- [Decomposing the Error](https://distill.pub/2017/momentum/)
- [Choosing A Step-size](https://distill.pub/2017/momentum/)

μ=1 ; κ=L ; optimal GD step=2/(L+1)

Example : Largest curvature L = 4 → optimal GD step = 0.4.

Solve : Largest curvature L = 9. Interpret, change an assumption, write a limitation.

Numerical answer : 0.2.

### Polynomial regression and chain rule

A polynomial model is linear in its coefficients: ŷ=Σwⱼxʲ. For f=‖Xw−y‖²/2, gradient is Xᵀ(Xw−y) and Hessian XᵀX. Differently scaled columns can slow descent. Centering inputs or changing bases may improve conditioning without a more complex optimizer.

- [Example: Polynomial Regression](https://distill.pub/2017/momentum/)

x=(0,1,2), y=(0,2,c) ; OLS slope=c/2 ; intercept=(2+c)/3−c/2

Example : Last observation y₃ = 4 → slope = 2.

Solve : Last observation y₃ = 6. Interpret, change an assumption, write a limitation.

Numerical answer : 3.

### Momentum dynamics

Keep velocity v′=βv+∇f(w), then w′=w−αv′. Persistent gradients accumulate and sign changes can cancel. In one quadratic direction, eₖ₊₁=(1+β−αλ)eₖ−βeₖ₋₁. Initial velocity matters; overshooting alone does not imply divergence.

- [The Dynamics of Momentum](https://distill.pub/2017/momentum/)

previous v=1 ; β=0.9 ; v′=0.9+g ; w=2 ; α=0.1 ; w′=2−0.1v′

Example : Gradient g = 2 → new weight w′ = 1.71.

Solve : Gradient g = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 1.6099999999999999.

### Critical damping

Roots of r²−(1+β−αλ)r+β determine oscillation and damping. A double root occurs at (1+β−αλ)²=4β; β=(1−√(αλ))² describes a critical branch per direction. One α,β pair generally cannot critically damp all curvatures. This is a quadratic calculation, not an arbitrary-network guarantee.

- [The Critical Damping Coefficient](https://distill.pub/2017/momentum/)

βcrit=(1−√(αλ))² (one quadratic direction)

Example : Product αλ = 0.25 → critical β = 0.25.

Solve : Product αλ = 0.64. Interpret, change an assumption, write a limitation.

Numerical answer : 0.03999999999999998.

### Optimal parameters and their assumptions

For a strongly convex quadratic with curvature in [μ,L], heavy ball has α=4/(√L+√μ)² and β=((√L−√μ)/(√L+√μ))². These improve the asymptotic factor in that setting. Unknown curvature, nonconvex loss or noise removes that guarantee. Compare predictions with curves, then increase the step too far.

- [Optimal parameters](https://distill.pub/2017/momentum/)

α=4/(√L+1)² ; β=((√L−1)/(√L+1))²

Example : Curvature L (μ=1) = 4 → optimal α = 0.4444444444444444.

Solve : Curvature L (μ=1) = 9. Interpret, change an assumption, write a limitation.

Numerical answer : 0.25.

### Colourization and graph Laplacian

On a pixel graph, penalizing Σwᵢⱼ(cᵢ−cⱼ)² favours similar neighbouring colours. Fixed colours act as boundary conditions; remaining values solve a quadratic related to the Laplacian. Our three-vertex chain makes its central optimum hand-checkable. It illustrates the energy without reproducing the colourization interface.

- [Example: The Colorization Problem](https://distill.pub/2017/momentum/)

fixed endpoints 0 and 4 ; E(c)=((c−0)²+(c−4)²)/2 ; ∂E/∂c=2c−4

Example : Central vertex value = 2 → energy derivative = 0.

Solve : Central vertex value = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Polynomials, Krylov space and oracle

After k linear steps on a quadratic, error is a polynomial in the Hessian applied to initial error. Gradient information explores a Krylov subspace. Oracle lower bounds construct a difficult problem for a class of methods; they do not claim every problem is equally difficult. Conditioning limits simultaneous reduction across directions.

- [The Limits of Descent](https://distill.pub/2017/momentum/)
- [Adventures in Algorithmic Space](https://distill.pub/2017/momentum/)
- [The Resisting Oracle](https://distill.pub/2017/momentum/)

μ=1 ; κ=L ; optimal GD step=2/(L+1)

Example : Largest curvature L = 4 → optimal GD step = 0.4.

Solve : Largest curvature L = 9. Interpret, change an assumption, write a limitation.

Numerical answer : 0.2.

### Noisy gradients and moving averages

A minibatch gives a noisy gradient. Velocity also accumulates noise: smoothing does not remove variance and large β can amplify slow fluctuations. Including (1−β) changes convention and effective step. Evaluate losses across seeds while retaining divergent runs.

- [Momentum with Stochastic Gradients](https://distill.pub/2017/momentum/)

previous v=1 ; β=0.9 ; v′=0.9+g ; w=2 ; α=0.1 ; w′=2−0.1v′

Example : Gradient g = 2 → new weight w′ = 1.71.

Solve : Gradient g = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 1.6099999999999999.

### Connection to differential equations

Small-step descent resembles gradient flow ẇ=−∇f(w); momentum resembles damped inertia ẅ+γẇ+∇f(w)=0 after scaling. Discretization adds its own stability limits. A stable continuous trajectory can be poorly simulated with a large step: distinguish the equation from its numerical scheme.

- [Onwards and Downwards](https://distill.pub/2017/momentum/)

f(w)=w² ; ∇f=2w ; α=0.1 ; w′=w−0.1×2w

Example : Position w = 2 → new weight w′ = 1.6.

Solve : Position w = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.4000000000000004.

## REINFORCEjs · Andrej Karpathy

https://cs.stanford.edu/people/karpathy/reinforcejs/

### State, action and return

An MDP specifies states, actions, transitions and rewards. Discounted return is Gₜ=Σₖγᵏrₜ₊ₖ₊₁; a policy selects action distributions from state. Partial observations need not form a Markov state. Separate training from evaluation; increasing reward does not prove delivery succeeds.

- [About: algorithms and environment API](https://cs.stanford.edu/people/karpathy/reinforcejs/)

r=1 ; γ=0.9 ; target = 1 + 0.9V (nonterminal)

Example : Next value V = 2 → Bellman target = 2.8.

Solve : Next value V = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 3.7.

### Policy evaluation and improvement

With known dynamics, Vπ(s)=Σₐπ(a|s)Σₛ′P(s′|s,a)[r+γVπ(s′)]. Evaluation approximates Vπ; improvement chooses actions with best predicted return. Value iteration directly uses a maximum over actions. Terminal states have no future continuation value. Compare with A* when movement becomes stochastic.

- [Dynamic Programming](https://cs.stanford.edu/people/karpathy/reinforcejs/)
- [GridWorld: policy evaluation, improvement and value iteration](https://cs.stanford.edu/people/karpathy/reinforcejs/gridworld_dp.html)

states 0→1→2→3 terminal ; stay or advance ; reward 1 on arrival ; V←maxₐ(r+γV next)

Example : Discount γ = 0.9 → initial-state value V(0) = 0.81.

Solve : Discount γ = 0.5. Interpret, change an assumption, write a limitation.

Numerical answer : 0.25.

### SARSA, Q-learning and exploration

TD corrects a value using a partly estimated target. SARSA uses the actual next action: r+γQ(s′,a′). Q-learning uses r+γmaxₐQ(s′,a), even if exploration chooses differently. Both update Q←Q+α(target−Q). An ε-greedy policy explores; also evaluate without exploration.

- [Tabular Temporal Difference Learning](https://cs.stanford.edu/people/karpathy/reinforcejs/)
- [GridWorld: TD methods and controls](https://cs.stanford.edu/people/karpathy/reinforcejs/gridworld_td.html)

Q=1 ; α=0.2 ; Q′=1+0.2(y−1)

Example : Target y = 2 → new Q value = 1.2.

Solve : Target y = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 1.4.

### Eligibility traces and planning

Eligibility e(s,a) records recent visits, typically decaying by γλ. A TD error can update several past pairs: Q←Q+αδe. Planning reuses a learned model for additional updates; priority can favour large errors. Off-policy traces require a suitable rule, such as cutting them in Watkins Q(λ).

- [Eligibility traces and prioritized planning](https://cs.stanford.edu/people/karpathy/reinforcejs/gridworld_td.html)

Q=1 ; α=0.2 ; Q′=1+0.2(y−1)

Example : Target y = 2 → new Q value = 1.2.

Solve : Target y = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 1.4.

### Approximate Q with a network

DQN replaces the table with Qθ(s,a), one output per discrete action. A transition provides a Bellman target detached from gradients; backpropagation adjusts the prediction. Replay mixes transitions, reducing temporal correlation. A separate target network is a common stabilization, not assumed in every historical version. This exercise isolates a squared-loss gradient.

- [Deep Q Learning: replay and TD error clamping](https://cs.stanford.edu/people/karpathy/reinforcejs/)

detached target y=3 ; L=(q−3)²/2 ; ∂L/∂q=q−3

Example : Network prediction q = 1 → loss gradient = -2.

Solve : Network prediction q = 2. Interpret, change an assumption, write a limitation.

Numerical answer : -1.

### PuckWorld: continuous state, discrete actions

Continuous position and velocity yield too many states for a small table. A network can interpolate inputs while choosing a few discrete pushes. Normalize coordinates and distinguish learned performance from simple target chasing. The original demo shows full training; the local calculation handles one transition rather than training PuckWorld.

- [PuckWorld demo](https://cs.stanford.edu/people/karpathy/reinforcejs/puckworld.html)

detached target y=3 ; L=(q−3)²/2 ; ∂L/∂q=q−3

Example : Network prediction q = 1 → loss gradient = -2.

Solve : Network prediction q = 2. Interpret, change an assumption, write a limitation.

Numerical answer : -1.

### WaterWorld: perception and reward

Perception rays encode nearby objects and distances in an observation vector. Reward can favour food and avoid hazards, but performance depends on visible information and reward design. Hidden state outside the rays may make the task partially observable. Compare with exact position in our grid.

- [WaterWorld demo](https://cs.stanford.edu/people/karpathy/reinforcejs/waterworld.html)

r=1 ; γ=0.9 ; target = 1 + 0.9V (nonterminal)

Example : Next value V = 2 → Bellman target = 2.8.

Solve : Next value V = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 3.7.

### REINFORCE, baseline and recurrence

Stochastic policy gradients use ∇log πθ(a|s)(G−b). An action-independent baseline reduces variance without changing expectation; an actor chooses and a critic estimates value. An LSTM can retain observation history. Deterministic gradients chain ∂Q/∂a with ∂μθ/∂θ. The author flags these implementations as unstable: study the ideas without treating them as reliable training.

- [Policy Gradients: REINFORCE, LSTM, actor–critic and deterministic policies](https://cs.stanford.edu/people/karpathy/reinforcejs/)

p=sigmoid(θ) ; chosen action=1 ; advantage=2 ; ∂J/∂θ=2(1−p)

Example : Binary action logit θ = 0 → policy gradient = 1.

Solve : Binary action logit θ = 1. Interpret, change an assumption, write a limitation.

Numerical answer : 0.5378828427399902.

## Transformer Explainer

https://poloclub.github.io/transformer-explainer/

### Predict a token

An autoregressive model predicts the next token from preceding tokens, then repeats. Inputs pass through attention and position-wise networks before projection into vocabulary logits. The original demonstrates GPT-2; our fixed tiny examples expose dimensions without reproducing its knowledge or training a large model.

- [What is a Transformer?](https://poloclub.github.io/transformer-explainer/)
- [Transformer Architecture](https://poloclub.github.io/transformer-explainer/)
- [Transformer Block](https://poloclub.github.io/transformer-explainer/)

3 tokens × 4 components ; position → LN → 2 causal heads Q=K=V → residual → LN → GELU MLP → residual → LN → logits → softmax

Example : Third token first component = 2 → first candidate token probability = 0.7056287006753951.

Solve : Third token first component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 0.7355632397104205.

### Tokenization and embeddings

A tokenizer maps text to subword identifiers; a token need not be a word or character. An embedding table returns row Eᵢ for identifier i, not the identifier multiplied by a vector. Similar spelling need not imply nearby learned vectors. Vocabulary and tokenizer must match model weights.

- [Embedding](https://poloclub.github.io/transformer-explainer/)
- [Step 1: Tokenization](https://poloclub.github.io/transformer-explainer/)
- [Step 2. Token Embedding](https://poloclub.github.io/transformer-explainer/)

token=(x,1), position=(0.1,0.2) ; input=token+position

Example : Token first component = 2 → first input component = 2.1.

Solve : Token first component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 3.1.

### Position and final representation

Without position information, attention alone does not know input order. Position representations here add componentwise to token vectors. GPT-2 uses learned positions; the original Transformer used another method, sinusoids. Position indices are not new tokens appended to the sentence.

- [Step 3. Positional Encoding](https://poloclub.github.io/transformer-explainer/)
- [Step 4. Final Embedding](https://poloclub.github.io/transformer-explainer/)

token=(x,1), position=(0.1,0.2) ; input=token+position

Example : Token first component = 2 → first input component = 2.1.

Solve : Token first component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 3.1.

### Q, K, V projections and heads

For T×d input X, Q=XWQ, K=XWK and V=XWV. Each head uses dₕ components; QKᵀ is T×T and compares positions. Distinct heads learn distinct projections, not guaranteed linguistic categories. Check dimensions before values; division by √dₕ moderates score scale.

- [Multi-Head Self-Attention](https://poloclub.github.io/transformer-explainer/)
- [Step 1: Query, Key, and Value Matrices](https://poloclub.github.io/transformer-explainer/)
- [Step 2: Multi-Head Splitting](https://poloclub.github.io/transformer-explainer/)

u = (x, 1), v = (2, −1) ; u·v = 2x − 1

Example : x component of u = 2 → dot product = 3.

Solve : x component of u = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 5.

### Causal mask and value mixing

Future positions receive −∞ before softmax, making their weights zero. Each softmax row sums to one; multiplication by V mixes visible values. Head outputs are concatenated and projected by WO. A large weight describes the computation without proving a causal explanation of model behaviour.

- [Step 3: Masked Self-Attention](https://poloclub.github.io/transformer-explainer/)
- [Step 4: Output and Concatenation](https://poloclub.github.io/transformer-explainer/)

V₁=2, V₂=6 ; output = 2p+6(1−p)

Example : First token weight = 0.25 → weighted output = 5.

Solve : First token weight = 0.75. Interpret, change an assumption, write a limitation.

Numerical answer : 3.

### MLP and nonlinearity

The MLP uses the same weights at each position: GELU(XW₁+b₁)W₂+b₂. It mixes components within a token; attention mixes positions. Without nonlinearity, two affine layers collapse into one. Our exercise uses the stated tanh approximation to GELU rather than the exact Gaussian-integral function.

- [MLP: Multi-Layer Perceptron](https://poloclub.github.io/transformer-explainer/)

GELU approx(x)=0.5x(1+tanh(√(2/π)(x+0.044715x³))) ; output=2GELU(x)

Example : Input activation = 1 → 2GELU output = 1.6823839812165535.

Solve : Input activation = 2. Interpret, change an assumption, write a limitation.

Numerical answer : 3.90919538817555.

### Per-token normalization

LayerNorm subtracts the mean across one token components and divides by √(variance+ε), then applies learned γ and β. It does not normalize the whole batch. In GPT-2 pre-normalized blocks it precedes each sublayer. This exercise fixes γ=1 and β=0 and displays normalized components and mean.

- [Auxiliary Architectural Features](https://poloclub.github.io/transformer-explainer/)
- [Layer Normalization](https://poloclub.github.io/transformer-explainer/)

h=(1,2,x) ; μ=(3+x)/3 ; variance=Σ(h−μ)²/3 ; ε=10⁻⁵

Example : Third activation = 3 → activation mean = 2.

Solve : Third activation = 5. Interpret, change an assumption, write a limitation.

Numerical answer : 2.6666666666666665.

### Residual paths

A residual connection computes X+F(X) with matching dimensions. Its gradient includes an identity path as well as the path through F, aiding deep optimization without guaranteeing trouble-free training. One addition follows attention and another follows the MLP. Check that each branch preserves token dimension d.

- [Residual Connections](https://poloclub.github.io/transformer-explainer/)

branch F(x)=0.5x ; output=x+F(x)

Example : Input x = 2 → residual output = 3.

Solve : Input x = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 4.5.

### Dropout: training and inference

Dropout randomly removes activations during training. In inverted dropout, surviving values are divided by 1−p to preserve expectation; inference disables it. Variation in generated text at inference generally comes from token sampling rather than active dropout.

- [Dropout](https://poloclub.github.io/transformer-explainer/)

input=2 ; retained training activation=2/(1−p) ; inference=2

Example : Drop probability p = 0.2 → retained activation = 2.5.

Solve : Drop probability p = 0.5. Interpret, change an assumption, write a limitation.

Numerical answer : 4.

### Logits, temperature and selection

Final projection gives logits and softmax(logits/τ) gives probabilities. Top-k retains k candidates; top-p retains a set reaching cumulative mass p, then renormalizes. Low temperature concentrates probability without ensuring truth. Output-logit temperature differs from altering internal attention scores. Compare original controls and tutorial with our lab.

- [Output Probabilities](https://poloclub.github.io/transformer-explainer/)
- [Interactive Features](https://poloclub.github.io/transformer-explainer/)
- [Video Tutorial](https://poloclub.github.io/transformer-explainer/)

logits=(2,1,0,−1) ; divide by τ ; top-k=3 then top-p=0.8 (renormalized mass) ; final first-token probability

Example : Temperature τ = 1 → final first-token probability = 0.7310585786300049.

Solve : Temperature τ = 2. Interpret, change an assumption, write a limitation.

Numerical answer : 0.6224593312018546.

## Diffusion Explainer

https://poloclub.github.io/diffusion-explainer/

### Diffusion in latent space

A diffusion model learns to reverse progressive corruption. Stable Diffusion denoises mostly in latent space before decoding into an image. Our two-mode lab has an analytically known denoiser; it illustrates steps but runs neither a trained U-Net nor Stable Diffusion. This chapter isolates mathematical components.

- [What is Stable Diffusion?](https://poloclub.github.io/diffusion-explainer/)
- [How does Stable Diffusion work?](https://poloclub.github.io/diffusion-explainer/)

x₀=2 ; ᾱ=0.64 ; xₜ=0.8×2+0.6ε

Example : Noise ε = 1 → noisy signal xₜ = 2.2.

Solve : Noise ε = 2. Interpret, change an assumption, write a limitation.

Numerical answer : 2.8.

### From text to conditioning

A CLIP tokenizer produces identifiers and an encoder turns the sequence into text representations. The historical demonstration has a limited context length, not a universal diffusion-model limit. Conditioning guides the noise network rather than specifying pixel locations. Compare descriptions differing in one word.

- [Text Representation Generation](https://poloclub.github.io/diffusion-explainer/)
- [Tokenizing](https://poloclub.github.io/diffusion-explainer/)
- [Text encoding](https://poloclub.github.io/diffusion-explainer/)

token=(x,1), position=(0.1,0.2) ; input=token+position

Example : Token first component = 2 → first input component = 2.1.

Solve : Token first component = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 3.1.

### Noise network, time and attention

The network predicts noise from noisy latent, timestep and text. A U-Net combines convolutions, resolution changes and cross-level connections; attention can integrate text. Weights are learned from data, not rebuilt per image. A convolution sees a neighbourhood; this exercise isolates filtering rather than simulating a complete U-Net.

- [Image Representation Refining](https://poloclub.github.io/diffusion-explainer/)
- [Noise Prediction](https://poloclub.github.io/diffusion-explainer/)

neighbourhood=(1,c,3), kernel=(0.25,0.5,0.25) ; response=1+0.5c

Example : Central pixel c = 2 → convolution response = 2.

Solve : Central pixel c = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 2.5.

### Guidance and trade-offs

Guidance combines predictions: ε̂=ε̂empty+s(ε̂text−ε̂empty). At s=0 it uses the empty-text branch; at s=1 the conditioned branch. Larger s can improve text adherence while reducing diversity or introducing artifacts. It acts on predicted noise, not directly on words or final pixels.

- [Classifier-free guidance control](https://poloclub.github.io/diffusion-explainer/)

unconditional ε=1 ; text ε=2 ; guided ε=1+s(2−1)

Example : Scale s = 2 → guided noise = 3.

Solve : Scale s = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 4.

### Noise, clean signal and scheduler

Corruption is xₜ=√ᾱₜx₀+√(1−ᾱₜ)ε. Predicted ε̂ gives x̂₀=(xₜ−√(1−ᾱₜ)ε̂)/√ᾱₜ. A scheduler determines the next timestep transition; repeatedly subtracting identical noise is insufficient. DDPM and DDIM can use different transitions. More steps do not automatically fix an inadequate model.

- [Noise Removal](https://poloclub.github.io/diffusion-explainer/)

xₜ=2.2 ; ᾱ=0.64 ; x̂₀=(2.2−0.6ε̂)/0.8

Example : Predicted noise ε̂ = 1 → estimated clean signal = 2.

Solve : Predicted noise ε̂ = 2. Interpret, change an assumption, write a limitation.

Numerical answer : 1.2500000000000002.

### Decode the latent

A learned decoder transforms compact latent into image. The original narrative calls this “upscaling”; mathematically it decodes rather than merely resizing pixels. Our miniature affine function makes latent and output spaces distinct; it represents neither a trained VAE nor its real scaling factors.

- [Image Upscaling](https://poloclub.github.io/diffusion-explainer/)

toy decoder D(z)=(z,2z,z−1) ; first component= z

Example : Latent coordinate z = 1 → first decoded component = 1.

Solve : Latent coordinate z = 2. Interpret, change an assumption, write a limitation.

Numerical answer : 2.

### Compare prompts, seeds and steps

A seed fixes initial noise within a given implementation. Compare texts with that seed and other settings fixed, changing one word. Determinism also depends on model and computation. The original uses prepared examples; local notes do not automatically import its images. Robotic actions additionally require demonstrations, constraints and feedback control.

- [Prompt keyword comparison](https://poloclub.github.io/diffusion-explainer/)
- [Seed, guidance and prompt controls](https://poloclub.github.io/diffusion-explainer/)

unconditional ε=1 ; text ε=2 ; guided ε=1+s(2−1)

Example : Scale s = 2 → guided noise = 3.

Solve : Scale s = 3. Interpret, change an assumption, write a limitation.

Numerical answer : 4.

