English · Español
Phase 03 — Linear Algebra from First Principles¶
Requires: 02 — Numerical Representation Teaches:
tensors·matmul·einsum·svd·rank·normsJump to any chapter from the phase reference index.
Chapter map¶
Pre-written per A12; re-anchored to A13 (English verb grammar). Theory + lab statements are stable drafts; solutions land just-in-time at phase open.
🇪🇸 Los tensores no son "arrays con más dimensiones". Son mapas lineales coordinados, y la matmul es la composición de esos mapas. Esta fase te entrena a predecir shapes sin ejecutar código, derivar SVD, y conectar la eficiencia de matmul con la jerarquía de memoria de Fase 1. Los ejemplos viven en el universo del modelo: vectores one-hot que indexan formas verbales y matrices que actúan como tablas de búsqueda sobre el vocabulario §A13.
Goal¶
Internalize linear algebra deeply enough that Borja can:
- Read any einsum expression and predict the resulting shape (and number of FLOPs) without running it — including the batched-embedding-lookup expression that anchors Phase 13.
- Derive
||Ax|| ≤ ||A||·||x||from SVD on a blank page. - Measure a 50× speedup between naive matmul and
np.matmulon his i5-8250U and explain it as a roofline fact (Phase 1) compounded by vectorisation absence (Phase 6 preview). - Reconstruct a verb-form conjugation-count matrix with
ksingular values and quantify the reconstruction error as a function ofk. - See, mechanically, how
M @ one_hot(i)is a lookupM[:, i]— the operation every embedding layer does.
Read order¶
theory/00-motivation.md— why a linear-algebra phase before any autograd.theory/01-tensors-and-shapes.md— scalar / vector / matrix / tensor; shape arithmetic; einsum as a unifying grammar; one-hot encodings of verb forms.theory/02-matmul-and-shapes.md— matmul as composition, dot/outer/Hadamard distinctions, batched matmul, embedding lookup as matmul. The most important page in Phase 3.theory/03-svd-and-rank.md— SVD as rotate-scale-rotate, rank, low-rank approximation, Eckart-Young; applied to a conjugation-count matrix.theory/04-norms-and-conditioning.md— vector / matrix norms, operator norm, condition number.lab/00-shapes-by-hand.md— predict shapes from einsum strings (no code at first), including embedding-lookup and batched-matmul patterns.lab/01-matmul-perf.md— race four matmul implementations on your machine.lab/02-svd-compression.md— compress a synthetic conjugation-count matrix with rank-k SVD.lab/03-norms-by-experiment.md— verify||Ax|| ≤ ||A||·||x||empirically and find the equality case.
solutions/ is empty at pre-write — populated at phase open.
Definition of Done¶
See PHASE_03_PLAN.md §6. Briefly:
- Four experiment directories with manifests + artefacts committed.
- Matmul performance chart shows ≥ 50× gap between naive Python and
np.matmulat N=1024. - SVD reconstruction grid + error curve on the conjugation-count matrix committed.
- Borja can predict einsum shapes on a blank page and derive
||Ax|| ≤ ||A||·||x||from SVD.
What this phase intentionally does NOT cover¶
- Autograd / gradients. Phase 4 (calculus) and Phase 7 (scalar autograd).
- A
src/minigrad/linalg.pymodule. Phase 3 stays inexperiments/; the linalg primitives are promoted in Phase ⅞ when an autograd consumer is built. - Probability / random matrices / random projections. Phase 5 + Phase 10 (RMSNorm/init).
- Eigendecomposition of non-symmetric matrices. Mentioned for vocabulary; the work is SVD.
- Numerical algorithms for SVD itself. We use
np.linalg.svd; deriving Jacobi / QR-based SVD is out of curriculum scope. - Sparse / structured matrices. Phase 27 (efficient attention) touches block-diagonal; nothing here.
- GPU matmul (BLAS / cuBLAS / Triton GEMM). Phase 23+.
Phase 3's scope is understanding tensor shapes, matmul mechanics, and SVD intuition deeply enough to make every later phase's linear-algebra step boring. Nothing more.
Further reading¶
Optional — enrichment, not required to pass the phase.
- 📕 Linear Algebra and Learning from Data — Strang · 2019. linear algebra written for ML, not for math majors.
- ✍️ Essence of Linear Algebra — 3Blue1Brown · 2016. build the geometric intuition before the index gymnastics.