Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Tables of numbers
A shop keeps a table of sales:
| Apples | Bananas | |
|---|---|---|
| Week 1 | 2 | 3 |
| Week 2 | 4 | 1 |
A table of numbers arranged in rows and columns is called a matrix. To get two weeks’ total of each fruit, you add matching boxes. To double every order, you double every box.
Multiplying a table by prices
Apples cost ₹10 and bananas ₹5. Week 1’s bill is 2 × 10 + 3 × 5 = 35, and week 2’s is 4 × 10 + 1 × 5 = 45. You took a row (the quantities), matched it with the prices, multiplied in pairs and added. That’s exactly how matrix multiplication works: row times column, again and again.
When a chatbot reads your sentence, most of its work is this one operation, rows times columns, repeated billions of times on huge tables of numbers.
- 1. A table has 3 rows and 4 columns. How many numbers does it hold?
- 2. Apples ₹10, bananas ₹5. You buy 3 apples and 4 bananas. Total?
- 3. To get two weeks' total sales, you…
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.Shape and entries
A matrix with rows and columns has shape . The entry in row , column is written or .
Adding and scaling
Both are done entry by entry, and addition needs the same shape:
Multiplying: row times column
is the dot product of row of with column of :
The shape rule: . The inner sizes must match, and the outer sizes give the result.
The identity matrix has 1s on the diagonal and 0s elsewhere. It does nothing: .
- 1. Shape of (2 × 3)(3 × 5)?
- 2. Can you add a 2 × 3 matrix to a 3 × 2 matrix?
- 3. (AB)₂₁ for A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.Four ways to see AB
The same product has four interpretations, and experts switch between them constantly:
| View | Statement | Useful for |
|---|---|---|
| Entries | computing by hand, attention scores | |
| Columns | column of = , a combination of ’s columns | seeing that |
| Rows | row of = (row of )·, a combination of ’s rows | processing a batch of data rows |
| Outer products | (column of A times row of B) | low-rank models, the SVD, LoRA |
Rules (and non-rules)
- ✅ Associative: . ✅ Distributive: .
- ❌ Not commutative: in general. Above, .
- ❌ No cancellation: is possible with and . For example, .
- ⚠️ So , not .
Matrix powers count paths
If is a graph’s adjacency matrix ( when there’s an edge from to ), then is the number of walks of length from to . If is a transition matrix of probabilities, then gives the distribution after steps. That’s the basis of Markov chains, PageRank and robot localization (T1).
In practice
| Where | Matrix multiplication |
|---|---|
| A batch through a dense layer | : one matmul processes the whole batch |
| Attention | and then |
| Data science | predicts every row at once. appears in regression |
| Robotics | chaining frames: |
- 1. Which view says AB = Σₖ (column k of A)(row k of B)?
- 2. (A + B)² equals A² + 2AB + B²…
- 3. In a triangle graph (every pair of 3 nodes connected), how many walks of length 2 go from node 1 back to node 1?
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.Associativity, by indices
whenever the shapes allow.
Proof. . The swap is allowed because finite sums can be reordered (A1-3). ∎ It’s also immediate from “matrices are maps, and multiplication is composition” (A2.1-5).
Block multiplication
Split the matrices into compatible blocks, and multiply the blocks as if they were numbers (keeping their order):
This is how GPUs tile big products into small blocks that fit in fast memory, and it’s the starting point of Strassen’s trick.
Walks: a proof by induction
For an adjacency matrix , is the number of walks of length from to .
Proof. For , it’s the definition. Assume it for . A walk of length from to is a walk of length to some node , followed by an edge . So the count is . ∎
The cost of multiplication
The schoolbook method for uses multiplications, so for square matrices. Associativity doesn’t change the answer, but it can change the cost hugely. With shapes , , , computing costs 7,500 multiplications, while costs 75,000.
Strassen (1969) showed that two (block) matrices can be multiplied with 7 products instead of 8. Applied recursively, this gives . The best known exponent has since been pushed to about 2.371 (Alman et al., 2024). Those algorithms are only faster for astronomically large matrices, though.
Exercise 3.1: Show that im(AB) ⊆ im(A), and hence rank(AB) ≤ rank(A)
Every column of is , which is in . So the whole column space of sits inside that of . Similarly, the rows of are combinations of the rows of , so .
- 1. How many multiplications does Strassen use for a 2 × 2 product?
- 2. Shapes 10×100, 100×5, 5×50. Which order is cheaper?
- 3. rank(AB) is at most…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.Matmul is the engine of deep learning
Multiplying costs about floating-point operations (FLOPs): one multiply and one add per term. Training and running large models is dominated by these products, so AI hardware is built around them: GPU tensor cores, TPU systolic arrays. Two ideas decide real speed:
- Arithmetic intensity: FLOPs per byte moved from memory. For square float32 matrices it’s about . Large matmuls are compute-bound (fast). Small ones and element-wise operations are memory-bound (slow per FLOP). That’s why kernels are fused and tiled (C5).
- Tiling: block multiplication lets each small tile stay in fast on-chip memory while it’s reused many times. FlashAttention is a famous example of reorganizing attention’s matmuls around this idea (E12).
Machines that discover multiplication algorithms
Finding the minimum number of multiplications for small matrix products is a hard combinatorial search. Fawzi et al. (2022) framed it as a game and used deep reinforcement learning (AlphaTensor). They rediscovered Strassen-like algorithms and found new ones for some sizes, including some tuned for specific hardware. It’s a striking example of AI being used to improve the mathematics AI runs on.
Markov chains in robotics and data science
A robot moving in a corridor whose wheel commands succeed only 80% of the time is described by a transition matrix . Its belief after steps is , the prediction step of a Bayes filter (T1). The same mathematics ranks web pages (PageRank, Page et al., 1999), models customer journeys in data science, and underlies MCMC sampling (A5). The long-run stationary distribution is an eigenvector problem (A2.3).
References
- A. Cayley (1858). “A memoir on the theory of matrices.” Philosophical Transactions of the Royal Society, 148.
- V. Strassen (1969). “Gaussian elimination is not optimal.” Numerische Mathematik, 13.
- L. Page, S. Brin, R. Motwani, T. Winograd (1999). “The PageRank citation ranking: Bringing order to the web.” Stanford InfoLab Technical Report.
- A. Fawzi et al. (2022). “Discovering faster matrix multiplication algorithms with reinforcement learning.” Nature, 610.
- T. Dao, D. Fu, S. Ermon, A. Rudra, C. Ré (2022). “FlashAttention: Fast and memory-efficient exact attention with IO-awareness.” NeurIPS.
- J. Alman, R. Duan, V. Vassilevska Williams, Y. Xu, Z. Xu, R. Zhou (2024). “More asymmetry yields faster matrix multiplication.” arXiv:2404.16349 (SODA 2025).
- G. Golub and C. Van Loan (2013). Matrix Computations, 4th ed. Johns Hopkins. Chapter 1.