Volume I, Chapter 1 — Part II. Matrices as linear transformations, composition, the four fundamental subspaces, rank-nullity theorem, determinants, and affine maps. Full derivations connecting matrix algebra to neural network layers and attention.
T:V→W — Linear transformation between vector spaces
In — n×n identity matrix
A−1,AT — Inverse and transpose
Core Intuition
A matrix is not merely a table of numbers — it is a concrete representation of a linear transformation. When a neural network layer computes h=Wx, the matrix W specifies how each input coordinate contributes to each output coordinate. Composing layers corresponds to multiplying matrices. Understanding which outputs are reachable (column space), which inputs are collapsed to zero (null space), and how much information is preserved (rank) is essential for analyzing model capacity, bottlenecks, and low-rank adaptation.
This chapter develops matrix algebra from the transformation viewpoint, proves the rank-nullity theorem in full, introduces determinants as volume-scaling factors, and connects the theory to attention mechanisms and affine neural network layers.
Observe: The blue/green arrows show where the standard basis vectors e₁=(1,0) and e₂=(0,1) land after transformation. The shaded area is the transformed unit square — its area equals |det(A)|. When det < 0, orientation flips.
Linear Transformations
Definition 1 (Linear Transformation). A function T:V→W between vector spaces over F is a linear transformation (linear map) if for all u,v∈V and α,β∈F:
T(αu+βv)=αT(u)+βT(v).(1)
Equivalently, T satisfies additivityT(u+v)=T(u)+T(v) and homogeneityT(αv)=αT(v).
Proposition 1.Every linear transformation maps the zero vector to the zero vector: T(0)=0.
Proof.T(0)=T(0⋅v)=0⋅T(v)=0. ■
Corollary 1.An affine map f(x)=Wx+b with b=0 is not linear.
Proof.f(0)=b=0, contradicting Proposition 1. ■
Neural network layers apply affine maps followed by nonlinear activations: h=σ(Wx+b). The linear part is W; the bias b shifts the origin.
Definition 2 (Kernel and Image). For T:V→W:
ker(T)={v∈V:T(v)=0},im(T)={T(v):v∈V}.(2)
Both are subspaces of V and W respectively.
Matrix Representation of Linear Maps
Theorem 1 (Matrix Representation).Every linear transformation T:Rn→Rm can be represented as multiplication by a unique matrix A∈Rm×n:
T(x)=Ax∀x∈Rn.(3)
Proof. Let {e1,…,en} be the standard basis of Rn. Any x=∑j=1nxjej. By linearity:
T(x)=j=1∑nxjT(ej).(4)
Define A=[T(e1)∣T(e2)∣⋯∣T(en)]∈Rm×n, so the j-th column is the image of the j-th basis vector. Then (4) becomes T(x)=Ax.
For uniqueness, suppose Ax=Bx for all x. Taking x=ej gives the j-th columns of A and B equal for all j, so A=B. ■
Important equation. Equation (3) identifies the matrix column j with T(ej). In a neural network, column j of W tells us how input feature j contributes to every output dimension.
Proposition 2.Under the identification T↔A, ker(T)=null(A) and im(T)=col(A).
Matrix Multiplication as Composition
Let T1:Rn→Rm with matrix A∈Rm×n and T2:Rm→Rp with matrix B∈Rp×m.
Definition 3 (Composition). The composition T2∘T1:Rn→Rp satisfies
(T2∘T1)(x)=T2(T1(x))=B(Ax)=(BA)x.(5)
Thus composition corresponds to matrix multiplication, defined by (BA)ij=∑k=1mBikAkj.
Theorem 2 (Four Interpretations of C=AB).Let A∈Rm×n, B∈Rn×p, C=AB∈Rm×p.
Entrywise (dot product):Cij=ai∗⋅b∗j (row i of A dotted with column j of B).
Column view:c∗j=Ab∗j=∑k=1nBkja∗k.
Row view:ci∗=ai∗B=∑k=1nAikbk∗.
Outer-product (rank-1 sum):C=∑k=1na∗kbk∗T.
Proof of (4).(a∗kbk∗T)ij=AikBkj, and summing over k gives Cij. ■
The outer-product view is foundational for low-rank matrix factorization and LoRA fine-tuning: a rank-r update is a sum of r rank-1 terms.
Proposition 3 (Non-commutativity).Matrix multiplication is associative: (AB)C=A(BC), but not commutative in general.
Deep networks compute WL⋯W2W1x — rightmost factor applied first.
The Four Fundamental Subspaces
For A∈Rm×n, define:
col(A)null(A)row(A)null(AT)={Ax:x∈Rn}⊆Rm={x∈Rn:Ax=0}⊆Rn=col(AT)⊆Rn={y∈Rm:ATy=0}⊆Rm(column space / range)(null space / kernel)(row space)(left null space)(6)
Theorem 3 (Orthogonality Relations).
row(A)col(A)⊥null(A)⊥null(AT)(both in Rn)(both in Rm)(7)
Proof of first relation. Let x∈null(A) and r∈row(A). Then rTx=0 because each row of A is orthogonal to x (since Ax=0). Any vector in row(A) is a linear combination of rows, hence also orthogonal to x. ■
Visual description. In Rn, the row space and null space are complementary orthogonal subspaces: every vector decomposes uniquely into a component in row(A) and a component in null(A). The column space describes reachable outputs; the null space describes input directions "invisible" to the transformation.
Proof. Let r=rank(A) and k=nullity(A). Choose a basis {u1,…,uk} for null(A) and extend to a basis {u1,…,uk,w1,…,wr} for Rn (possible since row(A)⊕null(A)=Rn and dim(row(A))=r).
Claim:{Aw1,…,Awr} is a basis for col(A).
Spanning: Any Ax with x=∑iαiui+∑jβjwj equals ∑jβjAwj since Aui=0.
Independence: If ∑jβjAwj=0, then A(∑jβjwj)=0, so ∑jβjwj∈null(A). But ∑jβjwj is also in span(wj), which intersects null(A) only at 0 (by construction of the extended basis). Hence all βj=0. ■
Important equation. Equation (8) quantifies the trade-off between information preserved (rank) and information destroyed (nullity). A layer with rank(W)<din has a nontrivial null space — distinct inputs can produce identical outputs.
Corollary 2.For A∈Rn×n, A is invertible if and only if rank(A)=n if and only if null(A)={0}.
Determinants and Invertibility
Definition 5 (Determinant — axiomatic). The determinant is the unique function det:Rn×n→R satisfying:
Multilinearity in rows (or columns).
Alternating: swapping two rows changes sign.
Normalization:det(I)=1.
Theorem 5 (Multiplicativity).For A,B∈Rn×n:
det(AB)=det(A)det(B).(9)
Theorem 6.A∈Rn×n is invertible if and only if det(A)=0.
Geometric interpretation.∣det(A)∣ is the factor by which A scales n-dimensional volume. det(A)=0 means the transformation collapses space to lower dimension.
Proposition 4 (Characteristic connection).det(A)=∏i=1nλi where λi are eigenvalues (with multiplicity).
This is the foundation of linear regression, treated in Volume II, Chapter 4.
Connection to independence.ATA is invertible iff columns of A are linearly independent (Proposition 5, Part I). Dependent columns make the normal equations singular.
Transpose, Symmetry, and Orthogonality
Definition 6 (Transpose).(AT)ij=Aji.
Proposition 5.
(AT)T=A,(A+B)T=AT+BT,(αA)T=αAT,(AB)T=BTAT.(15)
Proof of reversal.((AB)T)ij=(AB)ji=∑kAjkBki=∑k(BT)ik(AT)kj=(BTAT)ij. ■
Definition 7.A is symmetric if A=AT. It is orthogonal if ATA=I.
Orthogonal matrices preserve Euclidean norms: ∥Qx∥=∥x∥. They appear in SVD, QR decomposition, and orthogonal initialization.
Definition 8 (Gram matrix).G=ATA encodes inner products between columns of A: Gij=⟨ai,aj⟩.
Affine Transformations and Homogeneous Coordinates
An affine transformation is f(x)=Ax+b.
Homogeneous coordinates. Augment x with a 1:
x~=[x1]∈Rn+1,A~=[A0Tb1]∈R(m+1)×(n+1).(16)
Then A~x~=[Ax+b1], and composition of affine maps becomes matrix multiplication in the augmented space.
This trick allows us to treat biases as part of a larger linear system — useful in backpropagation (Chapter 8) and in projective geometry for computer vision.
Special Matrix Structures in Deep Learning
Diagonal matrices
D=diag(d1,…,dn) scales coordinate i by di. Layer normalization applies a learned diagonal scaling after centering.
Block-diagonal matrices
Multi-head attention uses block structure:
WOW1⋱Wh(17)
Each block operates on a head-specific subspace.
Low-rank matrices
A=UVT with U∈Rm×r, V∈Rn×r, r≪min(m,n). Storage O(r(m+n)) vs O(mn). LoRA fine-tuning learns ΔW=BA with small rank r.
Toeplitz and convolution
A 1D convolution corresponds to multiplication by a Toeplitz matrix — each row is a shifted copy of the filter. CNN theory (Chapter 9) builds on this equivalence.
Attention as Composed Linear Maps
Self-attention on input X∈RT×d ( T tokens, dimension d) proceeds as:
Step 1 — Linear projections:
Q=XWQ,K=XWK,V=XWV,(18)
where WQ,WK,WV∈Rd×dk.
Step 2 — Similarity matrix:
S=dkQKT∈RT×T.(19)
Entry Sij=⟨qi,kj⟩/dk is a scaled inner product (cosine similarity when vectors are normalized).
Steps 1, 2, and 4 are purely linear (matrix multiplications). Softmax introduces nonlinearity. The overall map is not linear, but each linear sub-step inherits the subspace structure developed in this chapter: col(V) determines reachable outputs; rank constraints on WQ,WK limit expressivity.
Visual description. Think of QKT as a T×T table of pairwise affinities between tokens. Softmax converts each row into a probability vector. Multiplying by V blends value vectors according to these probabilities — a data-dependent linear combination.
Common Pitfalls and Misconceptions
Pitfall 1: Treating matrix multiplication as element-wise multiplication. The Hadamard product A⊙B is different from AB. Composition vs local gating are distinct operations.
Pitfall 2: Assuming AB=BA. Order of transformations matters. Reversing layer order generally changes the network function.
Pitfall 3: Confusing rank with number of nonzero entries. A sparse matrix can be full rank; a dense matrix can be rank-deficient.
Pitfall 4: Ignoring the null space in dimensionality reduction. Projecting onto col(A) loses all information in null(A). PCA (Chapter 1, Part V) chooses directions to preserve variance, not arbitrary projections.
Pitfall 5: Inverting nearly singular matrices. When det(A)≈0, A−1 is numerically unstable. The condition number κ(A)=∥A∥∥A−1∥ measures this sensitivity.
Research Perspective
The matrix formulation of linear algebra crystallized in the nineteenth century (Cayley, Sylvester). The four-subspace framework was popularized by Gilbert Strang and provides the language for modern numerical linear algebra.
In machine learning, matrix factorization underpins recommender systems (Koren et al., 2009), where low-rank structure in rating matrices is exploited via SVD-like methods. The rank-nullity theorem explains bottleneck layers in autoencoders: an encoder with rank r can pass at most r independent features to the decoder. Low-rank adaptation (LoRA, Hu et al., 2021) exploits the empirical observation that fine-tuning updates often have low intrinsic rank.
Attention's formulation as matrix multiplication (Vaswani et al., 2017) enabled GPU-optimized implementations and subsequent algorithmic improvements (FlashAttention, linear attention). The linear-algebraic decomposition in equations (18)–(21) remains the reference point for all variants.
Summary of Takeaways
Linear map — T(αu+βv)=αT(u)+βT(v) — Layers without bias
Rank-nullity — rank+nullity=n — Capacity vs compression
Normal equations — ATAx^=ATb — Linear regression
Attention — softmax(QKT/dk)V — Transformer core
Next article:Eigenvalues & Eigenvectors → — intrinsic directions of linear transformations and spectral analysis of symmetric matrices.
Exercises
Exercise 1. Prove that rank(A)=rank(AT) using the rank-nullity theorem applied to A and AT and the dimension identity n=dim(row)+dim(null).
Exercise 2. Let A∈Rm×n with linearly independent columns. Derive x^=(ATA)−1ATb from the normal equations (12) and interpret P=A(ATA)−1AT as an orthogonal projection onto col(A).
Exercise 3. For A∈R2×2, prove det(A)=0 iff columns of A are linearly independent.
Exercise 4. Show that orthogonal matrices satisfy ∥Qx∥=∥x∥ and that eigenvalues of Q have modulus 1.
Exercise 5 (Attention). For T=3, dk=2, suppose S (before softmax) has rows with equal entries. Prove that A=softmax(S) has Aij=1/3 for all i,j, and hence the attention output for each token is the arithmetic mean of all value vectors.
Exercise 6 (Composition). A network has layers W1∈Rd2×d1, W2∈Rd3×d2. Express rank(W2W1) in terms of ranks of W1,W2. Give an example where rank(W2W1)<min(rank(W1),rank(W2)).
Exercise 7 (Affine maps). Prove that the composition of two affine maps f(x)=Ax+a and g(x)=Bx+b is affine, and compute its homogeneous matrix (16).