Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Do two arrows agree?
Two friends push a box. If they push in the same direction, their efforts add up perfectly. If they push at right angles, neither helps the other. If they push in opposite directions, they fight each other. The dot product is a single number that captures this: big and positive when the arrows agree, zero when they’re at right angles, and negative when they disagree.
Shadows
Shine a torch straight down on an arrow. Its shadow on the floor shows how much of the arrow points along the floor. The dot product is closely related to the length of that shadow.
Many ways to measure distance
How far is the shop that’s 3 blocks east and 4 blocks north?
- A bird flies straight there: 5 blocks (the straight line).
- A taxi must follow the streets: 3 + 4 = 7 blocks.
- A chess king, which moves diagonally for free, needs 4 moves (the bigger of 3 and 4).
All three are sensible ways to measure distance. Mathematicians call them norms.
- 1. Two people push a cart in exactly opposite directions. Their 'agreement' number is…
- 2. A taxi goes 5 blocks east and 2 north. How many blocks does it drive?
- 3. Two arrows at a perfect right angle. Their agreement number is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.The dot product
Multiply matching components and add:
Example. , and .
| Sign of | Angle between them | Meaning |
|---|---|---|
| positive | less than 90° | roughly the same direction |
| zero | exactly 90° | perpendicular (orthogonal) |
| negative | more than 90° | roughly opposite |
Length and distance from the dot product
The distance between and is .
Try the playground. Make the dot product zero and watch the angle become exactly 90°:
- 1. (1, 2, 3)·(4, −5, 6) = ?
- 2. (3, 1)·(−1, 3) = 0. The vectors are…
- 3. Distance between (0, 0) and (6, 8)?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.The geometric formula
The right-hand side is the cosine similarity, which ranges from −1 (opposite) through 0 (unrelated) to 1 (same direction). It ignores length and only compares direction. That’s why it’s the standard way to compare text embeddings in search and RAG systems (F10).
Projection
The projection of onto the direction of is the “shadow” from Level 0:
What’s left over, , is perpendicular to . Splitting a vector into “along” and “across” parts is the idea behind least squares (A2.4), Gram–Schmidt, and decomposing a robot’s force into normal and tangential parts.
Properties
The dot product is symmetric (), linear in each argument (), and positive definite ( unless ). Any operation with these three properties is called an inner product (A2.4).
The p-norms
These are the bird (), taxi (, “Manhattan”) and king (, “Chebyshev”) distances. The unit ball changes shape with : a diamond at , a circle at , and close to a square as :
Lasso adds to the loss, while Ridge adds . The ball has sharp corners on the axes, so the best point within it often lands on a corner, where some weights are exactly zero. The round ball has no corners, so weights shrink but rarely reach zero (D2).
- 1. Cosine similarity of (2, 0) and (5, 0)?
- 2. ‖(3, −4)‖₁ and ‖(3, −4)‖∞ are…
- 3. Projection of (2, 3) onto (1, 0)?
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.Why the geometric formula is true
, where is the angle between and .
Proof. Expand using linearity: . The triangle with sides , and also satisfies the law of cosines: . Compare the two. ∎
Two consequences:
- Pythagoras in dimensions: if , then .
- Cauchy–Schwarz: since , . The algebraic proof, which works in any dimension without needing angles, is in A1-6. In we define the angle through this formula, and Cauchy–Schwarz guarantees it makes sense.
What makes a norm
A norm satisfies: with equality only for , , and the triangle inequality. Every with is a norm (Minkowski, A1-6).
The parallelogram law. holds for , but not for or . In fact, a norm comes from an inner product if and only if it satisfies this law (Jordan–von Neumann theorem, 1935).
All norms on ℝⁿ are equivalent
For all : and .
Proof. If , then , which gives the first pair. For the second: . And by Cauchy–Schwarz with the all-ones vector, . ∎
So in finite dimensions, “converges” means the same thing whichever norm you use. Only the constants change, and those constants grow with , which matters in high-dimensional ML.
Dual norms. . and are dual to each other, and is its own dual. Duality appears in adversarial robustness (an attack budget leads to an weight penalty, M1) and in optimization (A6).
Exercise 3.1: Check the parallelogram law for u = (1,0) and v = (0,1) in L1
, but . The law fails, so doesn’t come from any inner product.
- 1. If u ⊥ v with ‖u‖ = 6 and ‖v‖ = 8, then ‖u + v‖ = ?
- 2. For x ∈ ℝ¹⁰⁰, the largest possible ‖x‖₁ / ‖x‖₂ is…
- 3. Which norm satisfies the parallelogram law?
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.The curse of dimensionality for distances
As the dimension grows, distances from a query to random points concentrate: the nearest and farthest points become almost equally far away. Beyer et al. (1999) showed that under broad conditions, , which makes “nearest neighbour” less meaningful. Practical consequences:
- Similarity search over embeddings relies on learned representations that are far from random, not raw high-dimensional data.
- Search engines and RAG systems use approximate nearest-neighbour indexes such as HNSW graphs (Malkov and Yashunin, 2020) and quantization, trading a little accuracy for huge speed-ups (F10).
Dot products at the heart of Transformers
Attention scores are dot products . If the entries are independent with variance 1, the dot product of two -dimensional vectors has variance . Dividing by brings it back to variance 1, which keeps the softmax from saturating (Vaswani et al., 2017). Some models go further and normalize queries and keys (QK-norm), so the score is a scaled cosine similarity. This has been reported to stabilize large-scale training (F5).
Dot products in robotics and physics
- Work and power: and . A motor that pushes perpendicular to the motion does no work. Practice Code 5 shows that a constant force does the same work on every path between two points.
- Joint power: for a robot arm, mechanical power is (torques times joint speeds), which is used in energy-aware control.
- Contact and collision: the normal component of a contact force is . Friction acts on the tangential remainder (R4).
- Visibility and lighting: a surface faces a camera when , which is used in rendering and 3D perception (G4).
References
- P. Jordan and J. von Neumann (1935). “On inner products in linear, metric spaces.” Annals of Mathematics, 36(3).
- R. Tibshirani (1996). “Regression shrinkage and selection via the lasso.” Journal of the Royal Statistical Society B, 58(1).
- K. Beyer, J. Goldstein, R. Ramakrishnan, U. Shaft (1999). “When is ‘nearest neighbor’ meaningful?” ICDT.
- A. Vaswani et al. (2017). “Attention is all you need.” NeurIPS.
- Y. Malkov and D. Yashunin (2020). “Efficient and robust approximate nearest neighbor search using hierarchical navigable small world graphs.” IEEE TPAMI, 42(4).
- G. Strang (2016). Introduction to Linear Algebra, 5th ed. Chapter 1.2.