Module contents
Lesson 5 of 25Core 95 min

Rank and the four fundamental subspaces

The complete map of a matrix: what it reaches (column space), what it destroys (null space), and how the four subspaces pair up with their dimensions. Prove row rank equals column rank and the rank–nullity theorem, and introduce CR factorization as a sum of rank-one matrices, leading to SVD and rank bottlenecks in deep learning.

After this lesson you can

  • Calculate bases of C(A), N(A), C(Aᵀ) and N(Aᵀ) and verify dimensions r, n - r, r and m - r.
  • Prove rank–nullity and equality of row and column rank.
  • Describe the solution set of Ax = b as a particular solution plus the null space and explain its affine geometry.
  • Factor A = CR and express a rank-r matrix as a sum of r outer products.
  • Bound ranks of products and sums and apply them to bottleneck layers and low-rank updates.

Before you start

Motivation: what a matrix reaches and what it destroys

In the linear transformations lesson, matrix A∈Rm×n\mat{A} \in \R^{m \times n} stopped being a table and became a function x↦Ax\vb{x} \mapsto \mat{A}\vb{x} from Rn\R^n to Rm\R^m. For any function two things matter: which values it can produce and which distinct inputs it confuses. For arbitrary functions the answers can be shapeless sets. For a linear map they are subspaces, computed using elimination from the previous lesson, and their dimensions obey an exact conservation law. This lesson builds the complete map.

The map appears as soon as you build something real:

  • A bottleneck layer. A linear autoencoder computes x↦W2W1x\vb{x} \mapsto \mat{W}_2\mat{W}_1\vb{x} with W1∈Rk×d\mat{W}_1 \in \R^{k \times d} and k<dk < d. However it is trained, reconstructions lie in a subspace of dimension at most kk, and a subspace of input directions of dimension at least d−kd - k is invisible to the network. Which subspace it learns connects to PCA in the linear autoencoder.
  • An attention head. In the original Transformer (Vaswani et al., 2017), with dmodel=512d_{\text{model}} = 512 and h=8h = 8 heads, each query uses a matrix WQ∈R64×512\mat{W}_Q \in \R^{64 \times 512}. By the end of the lesson you can prove in one line that a subspace of input directions of dimension at least 448448 is completely ignored by that query.
  • Regression with redundant variables. If a categorical variable is encoded with one indicator column per category plus an intercept, the ones column is the sum of indicators. There is then a vector z≠0\vb{z} \ne \vb{0} with Xz=0\mat{X}\vb{z} = \vb{0}, and weights w\vb{w} and w+tz\vb{w} + t\vb{z} give exactly the same predictions for every tt: coefficients are not identified. This is perfect collinearity, the dummy-variable trap.
  • A redundant robot arm. A seven-joint arm controlling gripper position and orientation (six numbers) has Jacobian matrix J∈R6×7\mat{J} \in \R^{6 \times 7}. Joint velocities q˙\dot{\vb{q}} with Jq˙=0\mat{J}\dot{\vb{q}} = \vb{0} move the elbow without moving the gripper, and always exist. This redundancy is used to avoid obstacles.
  • Cheap fine-tuning. LoRA restricts each weight-matrix update to a product ΔW=BA\Delta\mat{W} = \mat{B}\mat{A} with small inner dimension rr. All possible updates have rank at most rr; understanding that means understanding what a LoRA adapter can and cannot learn.

All five ask the same question: given a matrix, which output subspace can it reach (its column space), which input subspace does it destroy (its null space), and how are dimensions divided between them? The complete answer comprises four subspaces with dimensions rr, n−rn - r, rr and m−rm - r, where rr, the rank, summarizes almost everything needed about a matrix.

First look: flatten the cube

Before the definitions, see what happens when a column stops adding a new direction. Matrix 3×33 \times 3 sends the unit cube to the solid generated by its columns a1,a2,a3\vb{a}_1, \vb{a}_2, \vb{a}_3: point (x1,x2,x3)(x_1, x_2, x_3) of the cube goes to x1a1+x2a2+x3a3x_1\vb{a}_1 + x_2\vb{a}_2 + x_3\vb{a}_3.

InteractiveFlatten the cube
  • unit cube
  • its image
  • segments parallel to v\vb{v}
Transformation
Columns of A\mat{A}
60 %
0 %
A=[1.35−0.350.320.601.300.570.100.150.60]\mat{A} = \begin{bmatrix} 1.35 & -0.35 & 0.32 \\ 0.60 & 1.30 & 0.57 \\ 0.10 & 0.15 & 0.60 \end{bmatrix}
Rank rr3
Volume ∣det⁡A∣\abs{\det\mat{A}}1.039
dim⁡null⁡(A)=3−r\dim\nullsp(\mat{A}) = 3 - r0
∥Av∥\norm{\mat{A}\vb{v}} (red direction)0.471
Rank 3: volume 1.04, no direction is lost. The red one, v\vb{v}, is stretched the least: ∥Av∥=0.47\norm{\mat{A}\vb{v}} = 0.47.
The unit cube (dashed) and its image under A\mat{A} (magenta). “Before” and “After” show continuous deformation from I\mat{I} to A\mat{A}. The first slider moves a3\vb{a}_3 toward 0.5 a1+0.6 a20.5\,\vb{a}_1 + 0.6\,\vb{a}_2; the second moves a2\vb{a}_2 toward −0.5 a1-0.5\,\vb{a}_1. In red are the least-stretched direction v\vb{v} and three cube segments parallel to it. Observe what happens to those segments when selecting “Flatten to a plane” and toggling “Before” and “After.”

What you should have seen:

  • While all three columns are independent, the solid has volume. Moving a3\vb{a}_3 toward the plane of a1\vb{a}_1 and a2\vb{a}_2, volume, which is ∣det⁡A∣\abs{\det\mat{A}} as the determinant shows, falls to 00. The solid does not disappear: it flattens onto the plane spanned by the columns.
  • One direction is completely flattened. When a3=0.5 a1+0.6 a2\vb{a}_3 = 0.5\,\vb{a}_1 + 0.6\,\vb{a}_2, vector v=(0.5,0.6,−1)\vb{v} = (0.5, 0.6, -1) satisfies Av=0.5 a1+0.6 a2−a3=0\mat{A}\vb{v} = 0.5\,\vb{a}_1 + 0.6\,\vb{a}_2 - \vb{a}_3 = \vb{0}. A linear relation among columns is exactly a vector the matrix sends to zero.
  • Each segment parallel to that direction maps to one point. If Av=0\mat{A}\vb{v} = \vb{0}, then A(p+tv)=Ap\mat{A}(\vb{p} + t\vb{v}) = \mat{A}\vb{p} for every tt: from the output you cannot tell which point on the segment it came from. That information is lost.
  • What is lost and what survives add to 3. With one column relation the image is a plane (dimension 2) and a line is lost (dimension 1). With two relations the image is a line and an entire plane is lost. This accounting is the rank–nullity theorem, the lesson’s central result.

Column space and null space

What the matrix reaches

The descriptions coincide by the column reading of the matrix–vector product: Ax=x1a1+⋯+xnan\mat{A}\vb{x} = x_1\vb{a}_1 + \dots + x_n\vb{a}_n, so possible outputs of A\mat{A} are exactly linear combinations of its columns. Thus col⁡(A)\col(\mat{A}) is the image (range) of linear map x↦Ax\vb{x} \mapsto \mat{A}\vb{x}, and a subspace of Rm\R^m because it is a span. The consequence for linear systems is immediate and worth stating explicitly: Ax=b\mat{A}\vb{x} = \vb{b} has a solution if and only if b∈col⁡(A)\vb{b} \in \col(\mat{A}).

Use one example throughout the lesson:

A=[120124143615]∈R3×4.\mat{A} = \begin{bmatrix} 1 & 2 & 0 & 1 \\ 2 & 4 & 1 & 4 \\ 3 & 6 & 1 & 5 \end{bmatrix} \in \R^{3 \times 4}.

Its columns have two visible relations: a2=2a1\vb{a}_2 = 2\vb{a}_1 and a4=a1+2a3\vb{a}_4 = \vb{a}_1 + 2\vb{a}_3. All four span the same space as a1=(1,2,3)\vb{a}_1 = (1, 2, 3) and a3=(0,1,1)\vb{a}_3 = (0, 1, 1), which are not parallel, so col⁡(A)\col(\mat{A}) is a plane in R3\R^3. Which? Both columns have third coordinate equal to the sum of the other two, hence

col⁡(A)={b∈R3:b3=b1+b2}.\col(\mat{A}) = \{\vb{b} \in \R^3 : b_3 = b_1 + b_2\}.

System Ax=(1,3,4)\mat{A}\vb{x} = (1, 3, 4) has a solution because 4=1+34 = 1 + 3; system Ax=(1,0,0)\mat{A}\vb{x} = (1, 0, 0) does not, and there is no need to try solving it to know.

What the matrix destroys

It is a subspace: it contains 0\vb{0}, and if Ax=Ay=0\mat{A}\vb{x} = \mat{A}\vb{y} = \vb{0}, then A(αx+βy)=αAx+βAy=0\mat{A}(\alpha\vb{x} + \beta\vb{y}) = \alpha\mat{A}\vb{x} + \beta\mat{A}\vb{y} = \vb{0}. Read by columns, Ax=0\mat{A}\vb{x} = \vb{0} says x1a1+⋯+xnan=0x_1\vb{a}_1 + \dots + x_n\vb{a}_n = \vb{0}: each null-space vector is a linear relation among columns, and the null space is the set of all such relations. In the example, relations 2a1−a2=02\vb{a}_1 - \vb{a}_2 = \vb{0} and a1+2a3−a4=0\vb{a}_1 + 2\vb{a}_3 - \vb{a}_4 = \vb{0} give two null-space vectors,

s1=(−2,1,0,0),s2=(−1,0,−2,1),\vb{s}_1 = (-2, 1, 0, 0), \qquad \vb{s}_2 = (-1, 0, -2, 1),

with sign chosen so that the fourth coordinate of s2\vb{s}_2 equals 11. You will soon see they form a basis of null⁡(A)\nullsp(\mat{A}).

The null space measures exactly how much the matrix confuses inputs: Ax=Ay\mat{A}\vb{x} = \mat{A}\vb{y} if and only if A(x−y)=0\mat{A}(\vb{x} - \vb{y}) = \vb{0}, meaning x\vb{x} and y\vb{y} differ by a null-space vector. This yields an often-used equivalence: map x↦Ax\vb{x} \mapsto \mat{A}\vb{x} is injective if and only if null⁡(A)={0}\nullsp(\mat{A}) = \{\vb{0}\}, exactly when columns of A\mat{A} are linearly independent. The second equivalence is the definition of linear independence: the only relation among columns is trivial.

The general solution: particular plus null space

The null space says more than whether the solution of Ax=b\mat{A}\vb{x} = \vb{b} is unique. It says exactly how many there are and what shape they have.

Proof

If z∈null⁡(A)\vb{z} \in \nullsp(\mat{A}), then A(xp+z)=b+0=b\mat{A}(\vb{x}_p + \vb{z}) = \vb{b} + \vb{0} = \vb{b}, so every xp+z\vb{x}_p + \vb{z} is a solution. Conversely, if Ax=b\mat{A}\vb{x} = \vb{b}, then A(x−xp)=b−b=0\mat{A}(\vb{x} - \vb{x}_p) = \vb{b} - \vb{b} = \vb{0}, so z=x−xp\vb{z} = \vb{x} - \vb{x}_p lies in the null space and x=xp+z\vb{x} = \vb{x}_p + \vb{z}.

∎

Three consequences. First, the number of solutions is 00, 11 or infinite, with nothing in between, because a subspace other than {0}\{\vb{0}\} contains a whole line. Second, a solution, if it exists, is unique exactly when null⁡(A)={0}\nullsp(\mat{A}) = \{\vb{0}\}. Third, and easiest to forget: with b≠0\vb{b} \ne \vb{0} the solution set is not a subspace, because it does not contain 0\vb{0}. It is an affine subspace, a set of form p+U\vb{p} + U with UU a subspace: a copy of UU translated by p\vb{p}, which is a subspace if and only if p∈U\vb{p} \in U. These are the sets the lesson 3 affine maps send into one another.

In the example, elimination from the previous lesson takes augmented matrix [A∣b][\mat{A} \mid \vb{b}] with b=(b1,b2,b3)\vb{b} = (b_1, b_2, b_3) to

[1201b10012b2−2b10000b3−b1−b2].\left[\begin{array}{cccc|c} 1 & 2 & 0 & 1 & b_1 \\ 0 & 0 & 1 & 2 & b_2 - 2b_1 \\ 0 & 0 & 0 & 0 & b_3 - b_1 - b_2 \end{array}\right].

The last row says 0=b3−b1−b20 = b_3 - b_1 - b_2: condition b∈col⁡(A)\vb{b} \in \col(\mat{A}) already known, now derived by elimination. For b=(1,3,4)\vb{b} = (1, 3, 4), pivot variables are x1x_1 and x3x_3, and free variables x2=sx_2 = s and x4=tx_4 = t. Solving,

x=[1010]⏟xp+s[−2100]⏟s1+t[−10−21]⏟s2,s,t∈R.\vb{x} = \underbrace{\begin{bmatrix} 1 \\ 0 \\ 1 \\ 0 \end{bmatrix}}_{\vb{x}_p} + s\underbrace{\begin{bmatrix} -2 \\ 1 \\ 0 \\ 0 \end{bmatrix}}_{\vb{s}_1} + t\underbrace{\begin{bmatrix} -1 \\ 0 \\ -2 \\ 1 \end{bmatrix}}_{\vb{s}_2}, \qquad s, t \in \R.

Solutions form a plane in R4\R^4 that does not pass through the origin, parallel to the null space. With A\mat{A} of 3×43 \times 4 we cannot draw it, but with a matrix 3×33 \times 3 we can.

InteractiveThe solution set translates without rotating
Input: solutions of Ax=b\mat{A}\vb{x} = \vb{b}
  • null⁡(A)\nullsp(\mat{A})
  • xp+null⁡(A)\vb{x}_p + \nullsp(\mat{A})
  • xp\vb{x}_p (in the row space)
A\mat{A}
Output: the right-hand side b\vb{b}
  • col⁡(A)\col(\mat{A})
  • null⁡(A⊤)\nullsp(\mat{A}\T)
  • b\vb{b}
Matrix
Move b\vb{b}
0.70
dim⁡\dim of the solution set1
y⊤b\vb{y}\T\vb{b}, with y∈null⁡(A⊤)\vb{y} \in \nullsp(\mat{A}\T)0.00
x=[1.070.470.13]⏟xp+t [−0.410.820.41]⏟∈ null⁡(A),Ax=[1.202.60−0.20]\vb{x} = \underbrace{\begin{bmatrix} 1.07 \\ 0.47 \\ 0.13 \end{bmatrix}}_{\vb{x}_p} + t\,\underbrace{\begin{bmatrix} -0.41 \\ 0.82 \\ 0.41 \end{bmatrix}}_{\in\, \nullsp(\mat{A})}, \qquad \mat{A}\vb{x} = \begin{bmatrix} 1.20 \\ 2.60 \\ -0.20 \end{bmatrix}
b∈col⁡(A)\vb{b} \in \col(\mat{A}): the solutions form a line parallel to null⁡(A)\nullsp(\mat{A}), which does not pass through the origin unless b=0\vb{b} = \vb{0}.
On the right, right-hand side b\vb{b} (drag its tip) and the column space of a rank-2 3×33 \times 3 matrix. On the left, the null space (dashed red line through the origin) and solution set xp+null⁡(A)\vb{x}_p + \nullsp(\mat{A}) (solid red line). Move b\vb{b} within the plane: the solution line translates but does not rotate. Traverse solutions with tt and check Ax\mat{A}\vb{x} does not change. Then select “Move b\vb{b} out of col⁡(A)\col(\mat{A})” and try the rank-1 matrix, whose solutions use two parameters, tt and ss.

Three things worth observing:

  • The line’s direction does not depend on b\vb{b}. It is always null⁡(A)\nullsp(\mat{A}); b\vb{b} only determines the copy’s location. For the rank-1 matrix, the null space is a plane and solutions form planes parallel to it.
  • Among all solutions one is privileged. Blue arrow xp\vb{x}_p is the shortest solution and forms a right angle with the null space. This is no coincidence: it lies in the row space, the third of the four subspaces, proved in a few sections.
  • If b\vb{b} leaves col⁡(A)\col(\mat{A}), the line disappears. The separation of b\vb{b} from the plane points in a specific direction perpendicular to col⁡(A)\col(\mat{A}), and readout y⊤b\vb{y}\T\vb{b}, with y\vb{y} perpendicular to the plane, ceases to be 00. That y\vb{y} lives in the fourth subspace. What to do without a solution (find the closest Ax\mat{A}\vb{x}) is the least-squares problem.

Rank

By definition the example’s rank is 2. To calculate it generally without guessing relations, use Gaussian elimination, thanks to a property used without stating it in the previous lesson.

Proof

Ax=0\mat{A}\vb{x} = \vb{0} implies EAx=0\mat{E}\mat{A}\vb{x} = \vb{0}, and multiplying by E−1\mat{E}\inv reverses the implication. A column relation is a null-space vector, and column jj of EA\mat{E}\mat{A} is Eaj\mat{E}\vb{a}_j.

∎

Elimination is exactly this: reduced row echelon form is R0=rref⁡(A)=EA\mat{R}_0 = \operatorname{rref}(\mat{A}) = \mat{E}\mat{A}, with E\mat{E} an invertible product of elementary matrices. Column relations are easy to read in R0\mat{R}_0, and the lemma transfers them to A\mat{A}.

Proof

Let p1<⋯<prp_1 < \dots < p_r be pivot columns of R0\mat{R}_0. Column pip_i of R0\mat{R}_0 is standard vector ei∈Rm\vb{e}_i \in \R^m, so pivot columns of R0\mat{R}_0 are independent. Any other column jj of R0\mat{R}_0 has zeros in rows r+1,…,mr + 1, \dots, m, which are zero rows, so it is ∑i=1r(R0)ij ei\sum_{i=1}^{r} (\mat{R}_0)_{ij}\,\vb{e}_i: a combination of pivot columns. By the lemma, the same columns of A\mat{A} are independent and each nonpivot column of A\mat{A} is the same combination of pivot columns of A\mat{A}. They therefore span col⁡(A)\col(\mat{A}) and form a basis.

∎

The A=CR\mat{A} = \mat{C}\mat{R} factorization

The theorem fits into one matrix equality. Call C∈Rm×r\mat{C} \in \R^{m \times r} the matrix of pivot columns of A\mat{A}, and R∈Rr×n\mat{R} \in \R^{r \times n} the rr nonzero rows of rref⁡(A)\operatorname{rref}(\mat{A}). Then

A=CR.\mat{A} = \mat{C}\mat{R}.

Column jj of CR\mat{C}\mat{R} is ∑irij api\sum_{i} r_{ij}\,\vb{a}_{p_i}, and the proof says this is precisely the combination yielding aj\vb{a}_j. In the example, with p1=1p_1 = 1 and p2=3p_2 = 3,

[120124143615]⏟A=[102131]⏟C[12010012]⏟R.\underbrace{\begin{bmatrix} 1 & 2 & 0 & 1 \\ 2 & 4 & 1 & 4 \\ 3 & 6 & 1 & 5 \end{bmatrix}}_{\mat{A}} = \underbrace{\begin{bmatrix} 1 & 0 \\ 2 & 1 \\ 3 & 1 \end{bmatrix}}_{\mat{C}}\underbrace{\begin{bmatrix} 1 & 2 & 0 & 1 \\ 0 & 0 & 1 & 2 \end{bmatrix}}_{\mat{R}}.

R\mat{R} is the recipe: column jj says how much of each pivot column enters aj\vb{a}_j. Column 2 of R\mat{R} is (2,0)(2, 0) because a2=2a1\vb{a}_2 = 2\vb{a}_1; column 4 is (1,2)(1, 2) because a4=a1+2a3\vb{a}_4 = \vb{a}_1 + 2\vb{a}_3; and on pivot columns R\mat{R} contains identity. Also, C\mat{C} and R\mat{R} occupy r(m+n)r(m + n) numbers versus mnmn for A\mat{A}: with m=n=1000m = n = 1000 and r=10r = 10, fifty times fewer.

Row rank equals column rank

Rows of A\mat{A} are vectors in Rn\R^n and span another subspace: the row space, the column space of the transpose, col⁡(A⊤)⊆Rn\col(\mat{A}\T) \subseteq \R^n, also written row⁡(A)\row(\mat{A}). In the example the third row is the sum of the first two, so row space also has dimension 2. That the number of independent rows always equals the number of independent columns is not obvious: for matrix 3×10003 \times 1000 it says that among a thousand columns in R3\R^3, exactly as many are independent as there are independent rows among three vectors in R1000\R^{1000}.

Proof

Let r=dim⁡col⁡(A)r = \dim\col(\mat{A}) and let C∈Rm×r\mat{C} \in \R^{m \times r} be a matrix whose columns form a basis of col⁡(A)\col(\mat{A}). Each column aj\vb{a}_j lies in col⁡(A)\col(\mat{A}), so it is a combination of columns of C\mat{C}: aj=Crj\vb{a}_j = \mat{C}\vb{r}_j for some rj∈Rr\vb{r}_j \in \R^r. Combining the nn equalities gives A=CR\mat{A} = \mat{C}\mat{R} with R=[r1⋯rn]∈Rr×n\mat{R} = [\vb{r}_1 \cdots \vb{r}_n] \in \R^{r \times n}.

Now read the same product by rows: row ii of A\mat{A} is ∑k=1rcik\sum_{k=1}^{r} c_{ik} times row kk of R\mat{R}. Every row of A\mat{A} is a combination of the rr rows of R\mat{R}, so col⁡(A⊤)\col(\mat{A}\T) lies in a space generated by rr vectors and dim⁡col⁡(A⊤)≤r=dim⁡col⁡(A)\dim\col(\mat{A}\T) \le r = \dim\col(\mat{A}).

The argument holds for every matrix, in particular A⊤\mat{A}\T: dim⁡col⁡(A)=dim⁡col⁡((A⊤)⊤)≤dim⁡col⁡(A⊤)\dim\col(\mat{A}) = \dim\col((\mat{A}\T)\T) \le \dim\col(\mat{A}\T). The two inequalities give equality.

∎

The proof does not use elimination: only that every subspace has a basis, with factorization A=CR\mat{A} = \mat{C}\mat{R} doing the rest. Elimination gives a second proof and a row-space basis: row operations are invertible, so A\mat{A} and R0\mat{R}_0 have the same row space, and the rr nonzero rows of R0\mat{R}_0 are independent because each has 11 in a pivot column where the others have 00. Thus rows of R\mat{R} form a basis of col⁡(A⊤)\col(\mat{A}\T), just as columns of C\mat{C} do for col⁡(A)\col(\mat{A}).

The theorem yields everyday bounds and names. Since col⁡(A)⊆Rm\col(\mat{A}) \subseteq \R^m and col⁡(A⊤)⊆Rn\col(\mat{A}\T) \subseteq \R^n, rank⁡A≤min⁡(m,n)\rank\mat{A} \le \min(m, n). If r=nr = n, the matrix has full column rank: independent columns, null⁡(A)={0}\nullsp(\mat{A}) = \{\vb{0}\}. If r=mr = m, it has full row rank: col⁡(A)=Rm\col(\mat{A}) = \R^m and every system is solvable. Shape and rank determine, without further calculation, how many solutions Ax=b\mat{A}\vb{x} = \vb{b} has:

CaseShapedim⁡null⁡(A)\dim\nullsp(\mat{A})col⁡(A)\col(\mat{A})Solutions of Ax=b\mat{A}\vb{x} = \vb{b}
r=m=nr = m = nsquare00Rm\R^mexactly 1
r=n<mr = n < mtall00proper0 or 1
r=m<nr = m < nwiden−rn - rRm\R^minfinitely many
r<min⁡(m,n)r < \min(m, n)anyn−rn - rproper0 or infinitely many

“Proper” means a subspace other than Rm\R^m; “tall” means more equations than unknowns; “wide,” the reverse. The tall row is regression’s regime, with many more data than parameters, leading to least squares. The wide row describes overparameterized models with infinitely many exact solutions to choose among, studied with the pseudoinverse.

Which row is typical? If entries are randomly chosen from a continuous distribution, rank is min⁡(m,n)\min(m, n) with probability 1. For a square matrix, deficient rank is equivalent to det⁡A=0\det\mat{A} = 0, and determinant is a polynomial in n2n^2 entries that is not identically zero; the zero set of such a polynomial has Lebesgue measure zero. For m×nm \times n with m≤nm \le n, rank below mm requires every minor m×mm \times m to vanish, in particular that of the first mm columns, and the same argument applies. Two practical consequences follow. Meaningful low ranks come from structure rather than chance: redundant variables, bottlenecks, latent factors. Noisy data have full rank even if the signal does not, a problem revisited at the end.

The rank–nullity theorem

The two halves of what a matrix does are tied together by an equality.

The rank–nullity theorem reads as a conservation law: each of the nn input dimensions either survives, contributing to the image, or is destroyed, contributing to the null space. dim⁡null⁡(A)\dim\nullsp(\mat{A}) is called nullity. Notice that mm does not appear: the domain dimension is what counts.

Proof

Since null⁡(A)=null⁡(R0)\nullsp(\mat{A}) = \nullsp(\mat{R}_0) by the lemma, study R0x=0\mat{R}_0\vb{x} = \vb{0}. It has rr pivot variables and n−rn - r free variables. For each free variable xfx_f, obtain special solution sf\vb{s}_f by setting xf=1x_f = 1, the other free variables to 00, and solving each pivot variable: the equation in row ii gives xpi=−(R0)ifx_{p_i} = -(\mat{R}_0)_{if}. Show that the n−rn - r special solutions form a null-space basis.

They are independent. At coordinate ff, sf\vb{s}_f equals 11 and the other special solutions equal 00. If ∑fcfsf=0\sum_f c_f\vb{s}_f = \vb{0}, looking at coordinate ff gives cf=0c_f = 0.

They span the null space. Let x∈null⁡(A)\vb{x} \in \nullsp(\mat{A}) and y=x−∑fxfsf\vb{y} = \vb{x} - \sum_f x_f\vb{s}_f. This is another null-space vector whose free variables all equal 00. Equations of R0y=0\mat{R}_0\vb{y} = \vb{0} give each pivot variable as a combination of free variables, so they are also 00: y=0\vb{y} = \vb{0} and x=∑fxfsf\vb{x} = \sum_f x_f\vb{s}_f.

Therefore dim⁡null⁡(A)=n−r\dim\nullsp(\mat{A}) = n - r.

∎

In the example, free variables are x2x_2 and x4x_4, with special solutions s1\vb{s}_1 and s2\vb{s}_2 from before: 2+2=42 + 2 = 4 columns. The proof uses coordinates; the theorem applies to linear maps between abstract spaces, and the coordinate-free proof is even cleaner. Try it.

ProofRank–nullity without coordinates
Prove: Let T:V→WT: V \to W be linear with finite dim⁡V=n\dim V = n. Then dim⁡ker⁡T+dim⁡im⁡T=n\dim \ker T + \dim \operatorname{im} T = n, where ker⁡T={v:T(v)=0}\ker T = \{\vb{v} : T(\vb{v}) = \vb{0}\} and im⁡T={T(v):v∈V}\operatorname{im} T = \{T(\vb{v}) : \vb{v} \in V\}.
0
Let (u1,…,uk)(\vb{u}_1, \dots, \vb{u}_k) be a basis of ker⁡T\ker T, finite-dimensional as a subspace of VV.

Step 1 of 4. How do you construct a basis of VV using the kernel basis?

Consequences are immediate and useful:

  • More unknowns than equations forces a nontrivial null space. If n>mn > m, then rank⁡A≤m<n\rank\mat{A} \le m < n and dim⁡null⁡(A)≥n−m>0\dim\nullsp(\mat{A}) \ge n - m > 0: the homogeneous system has nonzero solutions. This is the motivating attention head: WQ∈R64×512\mat{W}_Q \in \R^{64 \times 512} has rank at most 6464, so dim⁡null⁡(WQ)≥512−64=448\dim\nullsp(\mat{W}_Q) \ge 512 - 64 = 448, and input components in that subspace do not affect the query. It is also the seven-joint arm: dim⁡null⁡(J)≥7−6=1\dim\nullsp(\mat{J}) \ge 7 - 6 = 1.
  • For a square matrix, injective equals surjective. With m=nm = n, null⁡(A)={0}\nullsp(\mat{A}) = \{\vb{0}\} if and only if rank⁡A=n\rank\mat{A} = n, that is, if and only if col⁡(A)=Rn\col(\mat{A}) = \R^n. Both are equivalent to A\mat{A} being invertible: the rank entry in lesson 3’s equivalence list now follows from dimension counting.
  • The solution set has dimension n−rn - r. If Ax=b\mat{A}\vb{x} = \vb{b} is consistent, its solutions form an affine subspace of dimension n−rank⁡An - \rank\mat{A}: the number of free variables, now with geometric meaning.

The four fundamental subspaces

Three subspaces have appeared: column space, null space and row space. The fourth is the transpose’s null space, completing a symmetry.

The fourth is named because, after transposing, A⊤y=0\mat{A}\T\vb{y} = \vb{0} is equivalent to y⊤A=0⊤\vb{y}\T\mat{A} = \vb{0}\T: y\vb{y} multiplies A\mat{A} on the left. If a~i⊤\tilde{\vb{a}}_i\T is row ii of A\mat{A}, the row reading gives y⊤A=∑iyia~i⊤\vb{y}\T\mat{A} = \sum_i y_i\tilde{\vb{a}}_i\T, so the left null space is the set of linear relations among rows, just as the null space contains relations among columns. Two lie in Rn\R^n, the input space, and two in Rm\R^m, the output space.

Proof

The first is the definition of rank; the second, rank–nullity; the third, row rank equals column rank. For the fourth, apply rank–nullity to A⊤∈Rn×m\mat{A}\T \in \R^{n \times m}, with mm columns and rank rr: dim⁡null⁡(A⊤)=m−r\dim\nullsp(\mat{A}\T) = m - r.

∎

One elimination gives bases for all four. If EA=R0\mat{E}\mat{A} = \mat{R}_0 with E\mat{E} invertible:

SubspaceDimensionBasis
col⁡(A)\col(\mat{A})rrpivot columns of A\mat{A}
col⁡(A⊤)\col(\mat{A}\T)rrnonzero rows of R0\mat{R}_0
null⁡(A)\nullsp(\mat{A})n−rn - rspecial solutions
null⁡(A⊤)\nullsp(\mat{A}\T)m−rm - rlast m−rm - r rows of E\mat{E}

The last follows because rows of E\mat{E} are independent as E\mat{E} is invertible; the last m−rm - r satisfy y⊤A=0⊤\vb{y}\T\mat{A} = \vb{0}\T because they produce zero rows of R0\mat{R}_0; and their count equals the dimension of null⁡(A⊤)\nullsp(\mat{A}\T). In the example, eliminating on [A∣I][\mat{A} \mid \mat{I}] gives

E=[100−210−1−11],EA=[120100120000],\mat{E} = \begin{bmatrix} 1 & 0 & 0 \\ -2 & 1 & 0 \\ -1 & -1 & 1 \end{bmatrix}, \qquad \mat{E}\mat{A} = \begin{bmatrix} 1 & 2 & 0 & 1 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 0 & 0 \end{bmatrix},

so null⁡(A⊤)=span⁡{(−1,−1,1)}\nullsp(\mat{A}\T) = \spn\{(-1, -1, 1)\}: the relation “row 3 minus row 1 minus row 2 is zero.” This is the same condition b3−b1−b2=0b_3 - b_1 - b_2 = 0 deciding whether Ax=b\mat{A}\vb{x} = \vb{b} has a solution, and not by chance. The counts agree: r=2r = 2, n−r=2n - r = 2, r=2r = 2 and m−r=1m - r = 1.

Orthogonality: the null space is perpendicular to the row space

So far everything requires only addition and scaling. The dot product brings geometry.

Proof

Read by rows, Ax=0\mat{A}\vb{x} = \vb{0} says a~i⊤x=0\tilde{\vb{a}}_i\T\vb{x} = 0 for every row ii: x\vb{x} is perpendicular to each row. Any row-space vector is A⊤z=∑izia~i\mat{A}\T\vb{z} = \sum_i z_i\tilde{\vb{a}}_i, and in one line, (A⊤z)⊤x=z⊤(Ax)=z⊤0=0(\mat{A}\T\vb{z})\T\vb{x} = \vb{z}\T(\mat{A}\vb{x}) = \vb{z}\T\vb{0} = 0. The same argument with A⊤\mat{A}\T instead of A\mat{A} gives the second claim: (Az)⊤y=z⊤(A⊤y)=0(\mat{A}\vb{z})\T\vb{y} = \vb{z}\T(\mat{A}\T\vb{y}) = 0.

∎

Check the example: (1,2,0,1)⊤s1=−2+2=0(1, 2, 0, 1)\T\vb{s}_1 = -2 + 2 = 0, (1,2,0,1)⊤s2=−1+1=0(1, 2, 0, 1)\T\vb{s}_2 = -1 + 1 = 0, and (0,0,1,2)(0, 0, 1, 2) also annihilates both; in R3\R^3, (−1,−1,1)(-1, -1, 1) is perpendicular to (1,2,3)(1, 2, 3) and (0,1,1)(0, 1, 1). The proof gives more than its statement: x⊥a~i\vb{x} \perp \tilde{\vb{a}}_i for every ii defines Ax=0\mat{A}\vb{x} = \vb{0}, so null⁡(A)\nullsp(\mat{A}) contains all vectors perpendicular to row space, not just some. If V⊥V^\perp denotes vectors perpendicular to all VV, its orthogonal complement, formalized in lesson 7, we have just shown null⁡(A)=col⁡(A⊤)⊥\nullsp(\mat{A}) = \col(\mat{A}\T)^\perp. The other half, that row space is everything perpendicular to the null space, requires dimension counting. It is the next exercise.

ProofThe null space is the orthogonal complement of row space
Prove: For A∈Rm×n\mat{A} \in \R^{m \times n} of rank rr: (a) null⁡(A)=col⁡(A⊤)⊥\nullsp(\mat{A}) = \col(\mat{A}\T)^\perp; (b) every x∈Rn\vb{x} \in \R^n is uniquely written x=xr+xn\vb{x} = \vb{x}_r + \vb{x}_n with xr∈col⁡(A⊤)\vb{x}_r \in \col(\mat{A}\T) and xn∈null⁡(A)\vb{x}_n \in \nullsp(\mat{A}); (c) col⁡(A⊤)=null⁡(A)⊥\col(\mat{A}\T) = \nullsp(\mat{A})^\perp.
0
The rows of A\mat{A}, as column vectors, are a~1,…,a~m\tilde{\vb{a}}_1, \dots, \tilde{\vb{a}}_m, and V⊥={x:x⊤v=0 for every v∈V}V^\perp = \{\vb{x} : \vb{x}\T\vb{v} = 0 \text{ for every } \vb{v} \in V\}.

Step 1 of 4. (a) If x⊥col⁡(A⊤)\vb{x} \perp \col(\mat{A}\T), is x\vb{x} in the null space?

Symbol ⊕\oplus denotes a direct sum: every vector is uniquely a sum of one from each subspace. The version in Rm\R^m finally answers the opening question, when a system has a solution, with a criterion requiring no solution.

Proof

Both cannot occur: if Ax=b\mat{A}\vb{x} = \vb{b} and A⊤y=0\mat{A}\T\vb{y} = \vb{0}, then y⊤b=y⊤Ax=(A⊤y)⊤x=0\vb{y}\T\vb{b} = \vb{y}\T\mat{A}\vb{x} = (\mat{A}\T\vb{y})\T\vb{x} = 0. One must occur because col⁡(A)=null⁡(A⊤)⊥\col(\mat{A}) = \nullsp(\mat{A}\T)^\perp (the previous exercise applied to A⊤\mat{A}\T): if b\vb{b} is not in col⁡(A)\col(\mat{A}), it is not perpendicular to some y∈null⁡(A⊤)\vb{y} \in \nullsp(\mat{A}\T).

∎

Vector y\vb{y} is an inconsistency certificate: it specifies which combination of equations yields 0=y⊤b≠00 = \vb{y}\T\vb{b} \ne 0. In the example, y=(−1,−1,1)\vb{y} = (-1, -1, 1) subtracts the first two equations from the third, leaving 0=b3−b1−b20 = b_3 - b_1 - b_2. Checking a certificate costs a dot product, although finding one costs elimination. The same idea for inequalities is Farkas’ lemma, the basis of optimization duality in theorems of alternatives.

With the decomposition, the matrix’s action is fully understood.

Proof

Ax=Axr+Axn=Axr\mat{A}\vb{x} = \mat{A}\vb{x}_r + \mat{A}\vb{x}_n = \mat{A}\vb{x}_r. Every b∈col⁡(A)\vb{b} \in \col(\mat{A}) is Ax\mat{A}\vb{x} for some x\vb{x}, and by the above b=Axr\vb{b} = \mat{A}\vb{x}_r: the restriction is surjective. If Axr=Axr′\mat{A}\vb{x}_r = \mat{A}\vb{x}_r' with both in row space, their difference lies in row space and null space, hence is 0\vb{0}: it is injective.

∎

This is Strang’s (1993) big picture: Rn\R^n splits into two perpendicular pieces, the matrix collapses one to the origin and maps the other without loss onto its column space; in Rm\R^m, the left null space is what cannot be reached. With arbitrary dimensions it can be drawn as a flow.

InteractiveThe big picture as a flow of dimensions
0
row space col⁡(A⊤)\col(\mat{A}\T)
dim 2
null space null⁡(A)\nullsp(\mat{A})
dim 2
column space col⁡(A)\col(\mat{A})
dim 2
left null space null⁡(A⊤)\nullsp(\mat{A}\T)
dim 1 · not reached
⊥\perp
⊥\perp
R4\R^{4}
R3\R^{3}
→ A \xrightarrow{\ \mat{A}\ }
3
4
2
Apply
dim⁡col⁡(A⊤)=r\dim\col(\mat{A}\T) = r2
dim⁡null⁡(A)=n−r\dim\nullsp(\mat{A}) = n - r2
dim⁡col⁡(A)=r\dim\col(\mat{A}) = r2
dim⁡null⁡(A⊤)=m−r\dim\nullsp(\mat{A}\T) = m - r1
Rank deficient. Solutions of Ax=b\mat{A}\vb{x} = \vb{b}: none (if b∉col⁡(A)\vb{b} \notin \col(\mat{A})) or infinitely many, forming an affine subspace of dimension 2.
Each square is one dimension. Left: Rn\R^n split into row space and null space; right: Rm\R^m into column space and left null space. A\mat{A} maps the rr row-space dimensions to the rr column-space dimensions one by one, and collapses null-space dimensions to zero. Change mm, nn and rr: blue and green blocks always have the same size. Select A⊤\mat{A}\T: the flow reverses and the null spaces exchange roles.

The geometric version, with editable matrix 3×33 \times 3, also shows right angles.

InteractiveThe big picture of the four subspaces
Input: R3=col⁡(A⊤)⊕null⁡(A)\R^3 = \col(\mat{A}\T) \oplus \nullsp(\mat{A})
  • row space col⁡(A⊤)\col(\mat{A}\T)
  • null space null⁡(A)\nullsp(\mat{A})
  • x\vb{x}
A\mat{A}
Output: R3=col⁡(A)⊕null⁡(A⊤)\R^3 = \col(\mat{A}) \oplus \nullsp(\mat{A}\T)
  • column space col⁡(A)\col(\mat{A})
  • left null space null⁡(A⊤)\nullsp(\mat{A}\T)
  • Ax\mat{A}\vb{x}
Matrix A\mat{A}
When dragging x\vb{x}
Rank rr2
dim⁡col⁡(A⊤)=r\dim\col(\mat{A}\T) = r2
dim⁡null⁡(A)=3−r\dim\nullsp(\mat{A}) = 3 - r1
dim⁡col⁡(A)=r\dim\col(\mat{A}) = r2
dim⁡null⁡(A⊤)=3−r\dim\nullsp(\mat{A}\T) = 3 - r1
Ax=[−0.20−2.402.00]⏟Axr+[0.000.000.00]⏟Axn=[−0.20−2.402.00]\mat{A}\vb{x} = \underbrace{\begin{bmatrix} -0.20 \\ -2.40 \\ 2.00 \end{bmatrix}}_{\mat{A}\vb{x}_r} + \underbrace{\begin{bmatrix} 0.00 \\ 0.00 \\ 0.00 \end{bmatrix}}_{\mat{A}\vb{x}_n} = \begin{bmatrix} -0.20 \\ -2.40 \\ 2.00 \end{bmatrix}
xr⊤xn\vb{x}_r\T\vb{x}_n (perpendicular)0.00
Left: input space, with perpendicular row space (blue) and null space (red). Right: output space, with perpendicular column space (green) and left null space (yellow). Drag x\vb{x} and see its decomposition x=xr+xn\vb{x} = \vb{x}_r + \vb{x}_n. With “Fix xr\vb{x}_r” you can move only the null-space part: check Ax\mat{A}\vb{x} stays fixed. Try the rank-1 and invertible examples and edit A\mat{A}.

The bijection between row and column spaces has an immediate consequence: if b∈col⁡(A)\vb{b} \in \col(\mat{A}), there is exactly one solution of Ax=b\mat{A}\vb{x} = \vb{b} in row space, and it is the shortest of all. Others are xr+z\vb{x}_r + \vb{z} with z∈null⁡(A)\vb{z} \in \nullsp(\mat{A}), and by orthogonality,

∥xr+z∥2=∥xr∥2+2 xr⊤z+∥z∥2=∥xr∥2+∥z∥2≥∥xr∥2.\norm{\vb{x}_r + \vb{z}}^2 = \norm{\vb{x}_r}^2 + 2\,\vb{x}_r\T\vb{z} + \norm{\vb{z}}^2 = \norm{\vb{x}_r}^2 + \norm{\vb{z}}^2 \ge \norm{\vb{x}_r}^2.

This was the blue arrow in the solutions interactive. That minimum-norm solution is returned by the pseudoinverse and found by gradient descent on an overparameterized linear problem starting at 0\vb{0}, because each step is a combination of rows and never leaves row space.

Rank-one matrices

The simplest nonzero matrices have rank one, and every matrix is built from them.

Equivalence is checked in two lines. If A=uv⊤\mat{A} = \vb{u}\vb{v}\T, its column jj is vjuv_j\vb{u}: all are multiples of u\vb{u} and at least one is nonzero, so rank is one. If rank is one, col⁡(A)=span⁡{u}\col(\mat{A}) = \spn\{\vb{u}\} for some u≠0\vb{u} \ne \vb{0}, each column is aj=vju\vb{a}_j = v_j\vb{u} for some number vjv_j, and that is A=uv⊤\mat{A} = \vb{u}\vb{v}\T. The four subspaces of uv⊤\vb{u}\vb{v}\T follow from (uv⊤)x=u (v⊤x)(\vb{u}\vb{v}\T)\vb{x} = \vb{u}\,(\vb{v}\T\vb{x}): column space is the line of u\vb{u}, row space that of v\vb{v}, null space hyperplane {x:v⊤x=0}\{\vb{x} : \vb{v}\T\vb{x} = 0\} of dimension n−1n - 1, and left null space the hyperplane perpendicular to u\vb{u} of dimension m−1m - 1. A rank-one matrix stores m+nm + n numbers instead of mnmn.

Factorization A=CR\mat{A} = \mat{C}\mat{R}, read as a sum of outer products (column of C\mat{C} times row of R\mat{R}), says every rank-rr matrix is a sum of rr rank-one matrices:

A=CR=∑k=1rck r~k⊤.\mat{A} = \mat{C}\mat{R} = \sum_{k=1}^{r} \vb{c}_k\,\tilde{\vb{r}}_k\T.

In the example,

A=[123][1201]+[011][0012]=[120124023603]+[000000120012].\begin{aligned} \mat{A} &= \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}\begin{bmatrix} 1 & 2 & 0 & 1 \end{bmatrix} + \begin{bmatrix} 0 \\ 1 \\ 1 \end{bmatrix}\begin{bmatrix} 0 & 0 & 1 & 2 \end{bmatrix} \\ &= \begin{bmatrix} 1 & 2 & 0 & 1 \\ 2 & 4 & 0 & 2 \\ 3 & 6 & 0 & 3 \end{bmatrix} + \begin{bmatrix} 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 1 & 2 \end{bmatrix}. \end{aligned}

Fewer than rr terms are impossible because a sum of kk rank-one matrices has rank at most kk (as shown next). Rank thus has a third characterization: the minimum number of outer products summing to the matrix. The decomposition is not unique: if M∈Rr×r\mat{M} \in \R^{r \times r} is invertible, A=(CM)(M−1R)\mat{A} = (\mat{C}\mat{M})(\mat{M}\inv\mat{R}) is another. SVD chooses the best, with terms ordered by importance.

InteractiveMosaic of rank-one layers
  • positive
  • negative
  • entries of u\vb{u} and v\vb{v} of the active layer
Sum of layers A^=∑kukvk⊤\hat{\mat{A}} = \sum_{k} \vb{u}_k\vb{v}_k\T (editing layer 1)
v1⊤\vb{v}_{1}\T
u1\vb{u}_{1}
Target A\mat{A}
Residual A−A^\mat{A} - \hat{\mat{A}}
Layers (click one to edit it):
=A^\hat{\mat{A}}
Active layer
Error ∥A−A^∥F/∥A∥F\norm{\mat{A} - \hat{\mat{A}}}_F / \norm{\mat{A}}_F65.5 %
rank⁡A\rank \mat{A}2
Layers kk (so rank⁡A^≤k\rank \hat{\mat{A}} \le k)1
Stored numbers k(m+n)k(m + n)16 of 64
rank⁡A=2\rank \mat{A} = 2: 1 layer cannot reconstruct exactly, because an outer product has rank ≤1\le 1.
Each layer is an outer product uv⊤\vb{u}\vb{v}\T: bars on the left (u\vb{u}) scale rows and bars on top (v⊤\vb{v}\T) scale columns. The cross starts with its horizontal bar painted; add a layer and design the vertical bar by looking at the residual. Then try the checkerboard, ratings and triangle. “Fit this layer” calculates the best possible layer for what remains.

What the mosaic shows:

  • The cross has rank 2: its rows have only two types (all ones, or ones in the two center columns). Two layers suffice; the second is not the whole vertical bar but the vertical bar without the intersection already painted by the first.
  • The ±1\pm 1 checkerboard has rank 1, though it looks most complicated: (−1)i+j=(−1)i(−1)j(-1)^{i+j} = (-1)^i(-1)^j, the outer product of two alternating vectors. With ones and zeros, however, the checkerboard is 1211⊤+12ss⊤\tfrac{1}{2}\vb{1}\vb{1}\T + \tfrac{1}{2}\vb{s}\vb{s}\T, with alternating s\vb{s}: rank 2. Adding a constant to every entry adds rank-one matrix c 11⊤c\,\vb{1}\vb{1}\T, changing rank by at most one. This is why centering data matters.
  • Ratings nearly fit in two layers. Rounding makes their rank 7, but two well-chosen layers leave error around 4%. This is the latent-factor assumption: few hidden tastes explain most preferences. Distinguishing exact from effective rank is the subject of low-rank approximation.
  • The triangle has no shortcuts: rank 8, so no sum of fewer than 8 layers reproduces it.

“Fit” solves the best-layer problem by alternating least squares: with v\vb{v} fixed, the best u\vb{u} is Rv/∥v∥2\mat{R}\vb{v}/\norm{\vb{v}}^2, and vice versa. Applied layer by layer to the residual (“Fit all”), it constructs the truncated SVD exactly; the Eckart–Young theorem will show no sum of kk layers does better.

Rank of products and sums: bottlenecks

In lesson 1 the column reading showed that columns of AB\mat{A}\mat{B} lie in col⁡(A)\col(\mat{A}). This lesson’s tools give the complete picture, with upper and lower bounds.

Proof

(1) Each column of AB\mat{A}\mat{B} is Abj\mat{A}\vb{b}_j, so col⁡(AB)⊆col⁡(A)\col(\mat{A}\mat{B}) \subseteq \col(\mat{A}) and rank⁡(AB)≤rank⁡A\rank(\mat{A}\mat{B}) \le \rank\mat{A}. For the other bound transpose: rank⁡(AB)=rank⁡(B⊤A⊤)≤rank⁡B⊤=rank⁡B\rank(\mat{A}\mat{B}) = \rank(\mat{B}\T\mat{A}\T) \le \rank\mat{B}\T = \rank\mat{B}, using row rank equals column rank twice. And rank⁡A≤k\rank\mat{A} \le k because A\mat{A} has kk columns.

(2) This is the interactive derivation below.

(3) null⁡(A⊤A)=null⁡(A)\nullsp(\mat{A}\T\mat{A}) = \nullsp(\mat{A}). If Ax=0\mat{A}\vb{x} = \vb{0}, certainly A⊤Ax=0\mat{A}\T\mat{A}\vb{x} = \vb{0}. If A⊤Ax=0\mat{A}\T\mat{A}\vb{x} = \vb{0}, multiply by x⊤\vb{x}\T: x⊤A⊤Ax=∥Ax∥2=0\vb{x}\T\mat{A}\T\mat{A}\vb{x} = \norm{\mat{A}\vb{x}}^2 = 0, hence Ax=0\mat{A}\vb{x} = \vb{0}. The matrices have kk columns and the same null space; rank–nullity gives the same rank.

(4) col⁡(A+B)⊆col⁡(A)+col⁡(B)\col(\mat{A} + \mat{B}) \subseteq \col(\mat{A}) + \col(\mat{B}) because (A+B)x=Ax+Bx(\mat{A} + \mat{B})\vb{x} = \mat{A}\vb{x} + \mat{B}\vb{x}. Combining a basis of col⁡(A)\col(\mat{A}) with one of col⁡(B)\col(\mat{B}) gives rank⁡A+rank⁡B\rank\mat{A} + \rank\mat{B} vectors spanning that sum, so its dimension is no larger.

∎

The lower bound is most interesting because it says how much rank must survive. Try predicting each step:

rank⁡(AB)=dim⁡A(col⁡(B))\rank(\mat{A}\mat{B}) = \dim \mat{A}\big(\col(\mat{B})\big)
Columns of AB\mat{A}\mat{B} span what A\mat{A} does to col⁡(B)\col(\mat{B}): the product's image is the image of col⁡(B)\col(\mat{B}) under A\mat{A}.
1/4

The second step also says when the upper bound is not attained: rank is lost exactly when col⁡(B)\col(\mat{B}) intersects the null space of A\mat{A}, meaning B\mat{B} produces vectors that A\mat{A} destroys. With A=[1000]\mat{A} = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix} and B=[0001]\mat{B} = \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix} both rank 1, AB=0\mat{A}\mat{B} = \mat{0}: everything produced by B\mat{B} lies in the null space of A\mat{A}. If A\mat{A} has full column rank, null⁡(A)={0}\nullsp(\mat{A}) = \{\vb{0}\} and exactly rank⁡(AB)=rank⁡B\rank(\mat{A}\mat{B}) = \rank\mat{B}; if B\mat{B} has full row rank, rank⁡(AB)=rank⁡A\rank(\mat{A}\mat{B}) = \rank\mat{A}.

Four places where these bounds matter:

  • Bottlenecks. A network without nonlinearities, x↦WL⋯W1x\vb{x} \mapsto \mat{W}_L\cdots\mat{W}_1\vb{x}, computes a single matrix whose rank cannot exceed the smallest intermediate dimension. A linear autoencoder with kk hidden units is at most a rank-kk matrix. Nonlinearities break the bound and prevent the linear collapse of depth.
  • LoRA. With ΔW=BA\Delta\mat{W} = \mat{B}\mat{A}, B∈Rdout×r\mat{B} \in \R^{d_{\text{out}} \times r} and A∈Rr×din\mat{A} \in \R^{r \times d_{\text{in}}}, point (1) gives rank⁡ΔW≤r\rank\Delta\mat{W} \le r, and r(dout+din)r(d_{\text{out}} + d_{\text{in}}) parameters are trained instead of doutdind_{\text{out}}d_{\text{in}}. With dout=din=4096d_{\text{out}} = d_{\text{in}} = 4096 and r=8r = 8, these are 65 53665\,536 versus 16 777 21616\,777\,216: 256 times fewer. Point (4) bounds how much weight rank can change, rank⁡(W0+ΔW)≤rank⁡W0+r\rank(\mat{W}_0 + \Delta\mat{W}) \le \rank\mat{W}_0 + r.
  • The softmax bottleneck. A language model calculates logits for NN contexts over a vocabulary of VV tokens as HW⊤\mat{H}\mat{W}\T, with H∈RN×d\mat{H} \in \R^{N \times d} and W∈RV×d\mat{W} \in \R^{V \times d}, of rank at most dd. Log probabilities subtract each row’s normalizer, changing rank by at most one. Yang et al. (2018) showed that if the true log-probability matrix has rank greater than d+1d + 1, no parameter values reproduce it. This is the softmax bottleneck.
  • Normal equations. By (3), X⊤X\mat{X}\T\mat{X} is invertible if and only if X\mat{X} has full column rank. This is the condition for least-squares normal equations to have a unique solution; the motivating perfect collinearity violates it.

Implementation from scratch: four subspaces with your own RREF

Everything above translates to about forty lines. Start with the previous lesson’s reduced row echelon form in compact form, with partial pivoting and tolerance relative to matrix scale to decide what counts as zero.

[ ]RREF with partial pivotingBrowser
import numpy as np

def rref(A, tol=1e-10):
    """RREF de A y columnas pivote (índices desde 0).

    Pivoteo parcial; una entrada es cero si |a| <= tol * max|A|.
    """
    R = np.array(A, dtype=float)
    m, n = R.shape
    eps = tol * np.abs(R).max() if R.size else 0.0
    pivots, row = [], 0
    for j in range(n):
        if row == m:
            break
        i = row + np.argmax(np.abs(R[row:, j]))  # pivoteo parcial
        if abs(R[i, j]) <= eps:
            R[row:, j] = 0.0          # columna libre: borra el ruido
            continue
        R[[row, i]] = R[[i, row]]     # intercambio de filas
        R[row] /= R[row, j]           # pivote igual a 1
        otras = np.arange(m) != row
        R[otras] -= np.outer(R[otras, j], R[row])  # ceros en la columna
        pivots.append(j)
        row += 1
    return R, pivots

A = np.array([[1, 2, 0, 1],
              [2, 4, 1, 4],
              [3, 6, 1, 5]], dtype=float)
R0, piv = rref(A)
print(R0)
print("columnas pivote:", piv, "-> rango", len(piv))

Code indices start at 0: pivot columns [0, 2] are the first and third. With RREF all four bases follow from the preceding table. For left null space use special solutions of A⊤\mat{A}\T, giving the same subspace as rows of E\mat{E} with less bookkeeping.

[ ]Bases of the four subspacesBrowser
def null_basis(A, tol=1e-10):
    """Base de null(A): una solución especial por variable libre."""
    R, piv = rref(A, tol)
    n = R.shape[1]
    libres = [j for j in range(n) if j not in piv]
    N = np.zeros((n, len(libres)))
    for k, f in enumerate(libres):
        N[f, k] = 1.0          # esta libre vale 1; las demás, 0
        for i, p in enumerate(piv):
            N[p, k] = -R[i, f]  # cada variable pivote la compensa
    return N + 0.0             # + 0.0 evita imprimir -0.0

def four_subspaces(A, tol=1e-10):
    """Bases (por columnas) de col(A), null(A), col(A^T), null(A^T)."""
    A = np.asarray(A, dtype=float)
    R, piv = rref(A, tol)
    r = len(piv)
    col = A[:, piv]          # columnas pivote de A (¡no de R!)
    row = R[:r].T            # filas no nulas de la RREF
    null = null_basis(A, tol)
    left_null = null_basis(A.T, tol)
    return col, null, row, left_null

col, null, row, left_null = four_subspaces(A)
for nombre, B in [("col(A)", col), ("null(A)", null),
                  ("col(A^T)", row), ("null(A^T)", left_null)]:
    print(f"{nombre}: dimensión {B.shape[1]}")
    print(B, "\n")

The result is exactly the hand-computed bases: s1\vb{s}_1 and s2\vb{s}_2 as columns of null, and (−1,−1,1)(-1, -1, 1) in left_null. Validate such an implementation against theory, not one example: random matrices of known rank must satisfy all four dimensions and relations Ax=0\mat{A}\vb{x} = \vb{0}, A⊤y=0\mat{A}\T\vb{y} = \vb{0}, row space ⊥\perp null space, and column space ⊥\perp left null space. To create rank rr, multiply m×rm \times r by r×nr \times n with Gaussian entries: the product has exactly rank rr with probability 1.

[ ]Check on 300 random matricesBrowser
def comprueba(A, tol=1e-10):
    """Rango y peor violación de las relaciones (relativa a max|A|)."""
    m, n = A.shape
    col, null, row, left_null = four_subspaces(A, tol)
    r = col.shape[1]
    assert row.shape[1] == r, "dim col(A^T) != r"
    assert null.shape[1] == n - r, "dim null(A) != n - r"
    assert left_null.shape[1] == m - r, "dim null(A^T) != m - r"
    peor = lambda M: np.abs(M).max(initial=0)
    err = max(peor(A @ null),          # A x = 0
              peor(A.T @ left_null),   # A^T y = 0
              peor(row.T @ null),      # fila ⟂ núcleo
              peor(col.T @ left_null)) # columna ⟂ núcleo izquierdo
    return r, err / max(np.abs(A).max(), 1.0)

rng = np.random.default_rng(0)
peor_err = 0.0
for _ in range(300):
    m, n = rng.integers(1, 9, size=2)
    r = rng.integers(0, min(m, n) + 1)
    # producto (m x r)(r x n): rango r con probabilidad 1
    M = rng.normal(size=(m, r)) @ rng.normal(size=(r, n))
    r_hat, err = comprueba(M)
    assert r_hat == r, (m, n, r, r_hat)
    peor_err = max(peor_err, err)
print("300 matrices: dimensiones r, n - r, r, m - r correctas")
print(f"peor error relativo: {peor_err:.1e}")

Worst relative error is on the order of 10−1410^{-14}: relations hold up to rounding. It works with r=0r = 0 too, as it should: the zero matrix breaks many implementations.

The professional version

SciPy computes these subspaces using SVD rather than elimination: scipy.linalg.null_space(A) returns an orthonormal null-space basis and scipy.linalg.orth(A) a column-space basis. These differ from ours and cannot be compared entrywise. Compare subspaces instead: span⁡(B1)=span⁡(B2)\spn(\mat{B}_1) = \spn(\mat{B}_2) if and only if both matrices and their concatenation [B1 B2][\mat{B}_1\ \mat{B}_2] have the same rank.

[ ]Same subspaces, different basesBrowser
import scipy.linalg as sla

def mismo_subespacio(B1, B2, tol=1e-9):
    """¿Generan B1 y B2 (por columnas) el mismo subespacio?"""
    r1 = np.linalg.matrix_rank(B1, tol=tol)
    r2 = np.linalg.matrix_rank(B2, tol=tol)
    r12 = np.linalg.matrix_rank(np.hstack([B1, B2]), tol=tol)
    return r1 == r2 == r12

print("null(A):  ", mismo_subespacio(null, sla.null_space(A)))
print("col(A):   ", mismo_subespacio(col, sla.orth(A)))
print("col(A^T): ", mismo_subespacio(row, sla.orth(A.T)))
print("null(A^T):", mismo_subespacio(left_null, sla.null_space(A.T)))

N = sla.null_space(A)
print("\nbase ortonormal de null(A) según SciPy:\n", N.round(4))
print("N^T N =\n", (N.T @ N).round(12))

# solución general de A x = b
b = np.array([1.0, 3.0, 4.0])
x_p = np.linalg.lstsq(A, b, rcond=None)[0]   # la de mínima norma
x = x_p + null @ rng.normal(size=null.shape[1])  # otra cualquiera
print("\nx_p =", x_p.round(4))
print("max|A x_p - b| =", np.abs(A @ x_p - b).max())
print("max|A x - b|   =", np.abs(A @ x - b).max())
print("null^T x_p =", (null.T @ x_p).round(12) + 0.0,
      "-> x_p está en el espacio fila")

The particular solution returned by lstsq, (0.1154,0.2308,0.1538,0.4231)(0.1154, 0.2308, 0.1538, 0.4231), is not the (1,0,1,0)(1, 0, 1, 0) from elimination: it is the minimum-norm solution, the only one in row space, hence perpendicular to columns of null. Any other is obtained by adding a null-space vector.

First encounter with numerical rank

In exact arithmetic rank is a well-defined integer. In floating point it is not: a rounding-sized perturbation can turn a rank-2 matrix full rank. Repeat the lesson 2 experiment, now with RREF.

[ ]Rank depends on toleranceBrowser
rng = np.random.default_rng(1)
E = 1e-12 * rng.normal(size=A.shape)     # ruido de medida diminuto
for tol in [1e-10, 1e-15]:
    r_elim = len(rref(A + E, tol)[1])
    print(f"tol = {tol:g}: rango por eliminación = {r_elim}")
s = np.linalg.svd(A + E, compute_uv=False)
print("valores singulares de A + E:", s)
print("matrix_rank(A + E):          ", np.linalg.matrix_rank(A + E))
print("matrix_rank(A + E, tol=1e-9):",
      np.linalg.matrix_rank(A + E, tol=1e-9))

The third singular value, on the order of 10−1310^{-13}, is the trace of noise. With a tolerance matching that noise rank is 2; with a finer one, 3. np.linalg.matrix_rank also says 3 because its default threshold, σ1max⁡(m,n) ε\sigma_1 \max(m, n)\,\eps with ε≈2.2⋅10−16\eps \approx 2.2 \cdot 10^{-16}, assumes the matrix exact except for SVD rounding. For measured data, error determines tolerance, not the machine. This is numerical rank; the low-rank approximation lesson teaches how to choose it.

Lab: rank bottlenecks

The second lab checks product bounds and looks inside a LoRA-like update.

[ ]Bottlenecks and low-rank updatesBrowser
import matplotlib.pyplot as plt

rng = np.random.default_rng(0)
rank = np.linalg.matrix_rank
m, n = 60, 40
print("dimensión interior k -> rank(AB)   (cota min(k, m, n))")
for k in [1, 3, 10, 25, 40, 55]:
    A_ = rng.normal(size=(m, k))
    B_ = rng.normal(size=(k, n))
    print(f"k = {k:2d} -> {rank(A_ @ B_):2d}        ({min(k, m, n)})")

# una actualización de tipo LoRA: dW = B A, dimensión interior r
d_out, d_in, r = 256, 192, 8
W0 = rng.normal(size=(d_out, d_in)) / np.sqrt(d_in)  # congelados
B_lo = 0.1 * rng.normal(size=(d_out, r))
A_lo = 0.1 * rng.normal(size=(r, d_in))
dW = B_lo @ A_lo
print("\nrank(dW) =", rank(dW))
print("parámetros entrenables:", B_lo.size + A_lo.size,
      "frente a", W0.size)

# cota superior no alcanzada: B produce vectores que A destruye
n6 = 6
A6 = rng.normal(size=(n6, 4)) @ rng.normal(size=(4, n6))  # rango 4
N6 = sla.null_space(A6)                                   # 2 columnas
B6 = np.column_stack([N6, rng.normal(size=n6)])           # rango 3
rA, rB, rAB = rank(A6), rank(B6), rank(A6 @ B6)
print(f"\nrank A = {rA}, rank B = {rB}, rank AB = {rAB}")
print(f"cota superior {min(rA, rB)}, cota de Sylvester {rA + rB - n6}")

s = np.linalg.svd(dW, compute_uv=False)
plt.semilogy(np.arange(1, len(s) + 1), s, "o", ms=3)
plt.axvline(r + 0.5, ls="--", color="gray")
plt.xlabel("índice i")
plt.ylabel(r"$\sigma_i(\Delta W)$")
plt.title(f"ΔW = BA con r = {r}: solo {r} valores singulares no nulos")
plt.show()

Three readings. Generic products always attain bound min⁡(k,m,n)\min(k, m, n): structure, not chance, is needed to lose rank. The LoRA update has exactly rank 8 with 3584 parameters instead of 49,152, visible in the graph: eight singular values on the order of 1, followed by a fifteen-order-of-magnitude jump to the rounding floor. When two columns of B\mat{B} fall in the null space of A\mat{A}, product rank collapses to 1, exactly Sylvester’s bound 4+3−64 + 3 - 6: the lower bound is attained too.

Common mistakes

Exercises

QuizWhere does each subspace live?
Let A∈R5×3\mat{A} \in \R^{5 \times 3}. Which of these are subspaces of R3\R^3?

More than one answer may be correct.

NumericLeft null-space dimension
Let A∈R7×10\mat{A} \in \R^{7 \times 10} have rank 4. What is the dimension of null⁡(A⊤)\nullsp(\mat{A}\T)?
NumericWhen is there a solution?
For the example matrix A=[120124143615]\mat{A} = \begin{bmatrix} 1 & 2 & 0 & 1 \\ 2 & 4 & 1 & 4 \\ 3 & 6 & 1 & 5 \end{bmatrix}, what value of β\beta makes Ax=(2,5,β)\mat{A}\vb{x} = (2, 5, \beta) consistent?
QuizRead a column-space basis
The reduced row echelon form of A=[121243364]\mat{A} = \begin{bmatrix} 1 & 2 & 1 \\ 2 & 4 & 3 \\ 3 & 6 & 4 \end{bmatrix} is [120001000]\begin{bmatrix} 1 & 2 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0 \end{bmatrix}. Which list is a basis of col⁡(A)\col(\mat{A})?
QuizSubspace or not?
Let b≠0\vb{b} \ne \vb{0} and suppose S={x:Ax=b}S = \{\vb{x} : \mat{A}\vb{x} = \vb{b}\} is nonempty. Which statement is correct?
QuizRank of a product
Let A∈R5×3\mat{A} \in \R^{5 \times 3} have rank⁡A=3\rank\mat{A} = 3 and B∈R3×6\mat{B} \in \R^{3 \times 6} have rank⁡B=2\rank\mat{B} = 2. What values can rank⁡(AB)\rank(\mat{A}\mat{B}) take?
QuizRank of a sum
Let A,B∈R3×3\mat{A}, \mat{B} \in \R^{3 \times 3} have rank 1. What values can rank⁡(A+B)\rank(\mat{A} + \mat{B}) take?
QuizNormal equations with redundant columns
A design matrix X∈R1000×20\mat{X} \in \R^{1000 \times 20} has two columns that are exact combinations of the rest, so rank⁡X=18\rank\mat{X} = 18. What can you say about X⊤X∈R20×20\mat{X}\T\mat{X} \in \R^{20 \times 20}?
QuizWhat is my data's rank?
A measurement matrix X∈R1000×50\mat{X} \in \R^{1000 \times 50} comes from 50 sensors, 5 of which are exact linear combinations of others, plus measurement noise of size 10−610^{-6} relative to data scale. np.linalg.matrix_rank(X) returns 50. What do you conclude?
NumericHow much does LoRA save?
Weight matrix W∈R4096×4096\mat{W} \in \R^{4096 \times 4096} is fine-tuned with rank-r=16r = 16 LoRA, ΔW=BA\Delta\mat{W} = \mat{B}\mat{A} with B∈R4096×16\mat{B} \in \R^{4096 \times 16} and A∈R16×4096\mat{A} \in \R^{16 \times 4096}. By what factor does the update reduce trainable parameters compared with full fine-tuning of W\mat{W}?
NumericA null space of matrices
Let A∈R4×6\mat{A} \in \R^{4 \times 6} have rank 2. What is the dimension of subspace {X∈R6×3:AX=0}\{\mat{X} \in \R^{6 \times 3} : \mat{A}\mat{X} = \mat{0}\}?
CodeCR factorization
Implement cr_factorization(A, tol=1e-10), returning (C, R) with C the pivot columns of A and R the nonzero rows of its reduced row echelon form, so A = C @ R. Decide what is zero using relative tolerance tol * max|A|. For a zero matrix of shape (m, n), C must have shape (m, 0) and R shape (0, n). Write it from scratch without SymPy's rref.
import numpy as np

def cr_factorization(A, tol=1e-10):
  """(C, R): C = columnas pivote de A; R = filas no nulas de la RREF."""
  A = np.asarray(A, dtype=float)
  # 1. Reduce una copia de A a su RREF anotando las columnas pivote.
  # 2. C = esas columnas de la A original.
  # 3. R = las primeras r filas de la RREF.
  raise NotImplementedError
Shift+Enter to run

Summary

Key idea
A matrix A∈Rm×n\mat{A} \in \R^{m \times n} of rank rr splits input into perpendicular row space (rr dimensions) and null space (n−rn - r); it collapses the null space to 0\vb{0} and maps row space without loss onto column space (rr dimensions), whose perpendicular complement in output, the left null space (m−rm - r), is never reached.
  • Column space and null space. col⁡(A)\col(\mat{A}) is what the matrix reaches: Ax=b\mat{A}\vb{x} = \vb{b} is solvable if and only if b∈col⁡(A)\vb{b} \in \col(\mat{A}). null⁡(A)\nullsp(\mat{A}) is what it destroys, the set of column relations, and solutions form affine subspace xp+null⁡(A)\vb{x}_p + \nullsp(\mat{A}).
  • Rank. rank⁡A=dim⁡col⁡(A)\rank\mat{A} = \dim\col(\mat{A}) is the pivot count, equals row rank, and is the minimum number of outer products summing to A\mat{A}. Factorization A=CR\mat{A} = \mat{C}\mat{R} (pivot columns times nonzero RREF rows) contains it all.
  • Rank–nullity. rank⁡A+dim⁡null⁡(A)=n\rank\mat{A} + \dim\nullsp(\mat{A}) = n: each input dimension survives or is destroyed. More unknowns than equations forces a nontrivial null space.
  • Orthogonality. null⁡(A)=col⁡(A⊤)⊥\nullsp(\mat{A}) = \col(\mat{A}\T)^\perp and null⁡(A⊤)=col⁡(A)⊥\nullsp(\mat{A}\T) = \col(\mat{A})^\perp, with dimensions n−rn - r and m−rm - r. Only the row-space part of x\vb{x} reaches output, and the row-space solution has minimum norm.
  • Products and sums. rank⁡A+rank⁡B−k≤rank⁡(AB)≤min⁡(rank⁡A,rank⁡B)\rank\mat{A} + \rank\mat{B} - k \le \rank(\mat{A}\mat{B}) \le \min(\rank\mat{A}, \rank\mat{B}), rank⁡(A+B)≤rank⁡A+rank⁡B\rank(\mat{A} + \mat{B}) \le \rank\mat{A} + \rank\mat{B} and rank⁡(A⊤A)=rank⁡A\rank(\mat{A}\T\mat{A}) = \rank\mat{A}. These are the calculations behind bottlenecks, LoRA and normal equations.
  • In floating point, rank depends on a tolerance set by data noise, not the machine.