Rank–nullity theorem
For a linear map T: V → W between finite-dimensional vector spaces, dim V = dim ker T + dim im T. The theorem is an exact dimension identity, proved by extending a basis of the kernel to a basis of the whole space.
1. Concept overview
Let and be vector spaces over a field , with finite-dimensional, and let be linear. The kernel and image are
Both are subspaces. Write and . The rank–nullity theorem states
This is an identity, not an inequality or an approximation. It says that a linear map loses exactly as many dimensions as it collapses into its kernel and transports the rest isomorphically into its image.
2. Why this concept exists
Rank and nullity are separately easy to define but hard to interpret in isolation. A matrix can have large rank and large nullity at the same time — for example a matrix of rank has nullity . The theorem supplies the missing bookkeeping: the domain dimension is partitioned between the directions the map kills and the directions it preserves.
It is also the reason Gaussian elimination gives a complete description of a linear system. The number of free variables is the nullity, the number of pivots is the rank, and their sum is the number of columns. Without the theorem, “count pivots” and “count free variables” would be two unrelated procedures rather than two halves of one statement.
3. Historical background
Rank–nullity is a standard theorem of finite-dimensional linear algebra. It appears in the modern form in standard texts such as Axler's Linear Algebra Done Right, Strang's Introduction to Linear Algebra, and Hoffman and Kunze's Linear Algebra. It does not have a single dramatic origin story, and it should not be attributed to a paper about optimization or PDE stability. The result is a consequence of the first isomorphism theorem for vector spaces, , together with the dimension formula for quotients.
4. Fundamental problem
Given a linear map , how much information about survives under , and how much is destroyed? Equivalently: if collapses some subspace to zero, what is the dimension of that subspace, and what is the dimension of the remaining image?
The naive answer “rank is the number of nonzero rows after elimination” computes one quantity but does not explain why the remaining dimensions must add up. The structural question is: can we choose a basis of in which has the block form
with ? Rank–nullity is the dimension count behind that normal form.
5. First-principles explanation
A linear map is determined by what it does to a basis. Suppose is a basis of . Extend it to a basis
of , where . The kernel directions are exactly the ones that vanish. The claim is that the images are a basis of . If true, the image has dimension , and the identity follows immediately.
So the entire proof reduces to two checks: those images span the image, and they are linearly independent. Both use only linearity and the fact that the already span the kernel.
6. Prerequisite concepts
You need: (a) the definition of a vector space, subspace, span, linear independence and basis; (b) the fact that any linearly independent set in a finite-dimensional space can be extended to a basis; (c) the definition of a linear map, kernel and image; (d) the dimension of a subspace. Quotient spaces are optional: they give the shortest conceptual proof, but the basis-extension proof below avoids them.
7. Complete mathematical formulation
Theorem. Let be finite-dimensional and linear. Then
Equivalent matrix form. For ,
where and .
Consequences.
- is injective iff iff .
- If and is injective, then is surjective (and hence invertible).
- For an matrix, , so when .
8. Notation dictionary
| Symbol | Meaning | Type | |---|---|---| | | vector spaces over a field | spaces | | | linear map | function | | | kernel | subspace of | | | image | subspace of | | | dimension over | integer | | | | integer | | | | integer | | | basis of the kernel | set of vectors | | | extension vectors completing a basis of | set of vectors | | | matrix representing after choosing bases | matrix | | | (number of columns) | integer | | | | integer |
9. Step-by-step derivation
Step 1 — choose a kernel basis. Let and choose a basis of . If , the kernel is and the argument below starts from the empty set.
Step 2 — extend to a basis of . The basis extension theorem gives vectors such that is a basis of , where .
Step 3 — the images span. Any has a unique expansion
Applying and using linearity plus ,
So spans .
Step 4 — the images are independent. Suppose
Then , so . Because the span the kernel, there are scalars with
Rearrange: . The set is a basis of , hence linearly independent, so every (and every ). Therefore the are linearly independent.
Step 5 — count dimensions. Steps 3 and 4 show that is a basis of . Hence
which is the theorem.
10. Proofs and proof intuition
The derivation above is a complete proof; this section records the two facts it uses and the quotient-space alternative.
Fact 1 (basis extension). If is a linearly independent subset of a finite-dimensional vector space , then can be extended to a basis of . Proof sketch. Repeatedly add a vector outside the current span until the span is all of ; finite dimension guarantees termination.
Fact 2 (first isomorphism theorem). The map , , is a well-defined linear isomorphism. Well-defined: if , then , so . Injective: implies . Surjective: every element of is .
Quotient dimension formula. For a subspace , . Therefore
Both proofs are exact and hold over any field.
11. Geometric interpretation
Think of as a projection followed by an isomorphism. The kernel is the subspace that is flattened to the origin. The image is the subspace that survives. Rank–nullity says the dimension of the domain is the dimension of the flattened part plus the dimension of the surviving part.
In , the map flattens the -axis to the origin and keeps the -plane. The kernel is the -axis (dimension 1), the image is the -plane (dimension 2), and . A rank-1 map such as flattens a whole plane (dimension 2) and keeps one line (dimension 1), and again . The theorem is dimension conservation under a linear map.
13. Numerical worked example
Example 1 (a rank-deficient matrix). Let
The second row is twice the first, so . The domain has dimension , so the nullity must be . Solving gives the single equation , whose solution set is
The two vectors are independent, so the nullity is indeed 2. Check: .
Example 2 (a linear map on ). has kernel and image , so nullity , rank , and .
Example 3 (full rank). on has kernel (if and , then ) and image , so .
14. Real-world analogy
A hotel with rooms sends guests through a check-in process. Some guests are turned away at the door (the kernel); the rest are assigned rooms (the image). Rank–nullity says the number of rooms in the hotel equals the number turned away plus the number successfully housed, provided the assignment is linear and every successfully housed guest occupies a distinct room. The analogy breaks if the process is nonlinear, which is exactly why the theorem requires linearity.
15. Algorithm pseudocode
algorithm RankNullity(A, tol):
# A is m x n
compute a rank-revealing decomposition (SVD or QR with pivoting)
r <- number of singular values greater than tol
nullity <- n - r
return (r, nullity)
algorithm NullspaceBasis(A, tol):
U, S, V^T <- SVD(A)
r <- count(S > tol)
return the last n - r columns of V # rows r..n-1 of V^T, transposed
Gaussian elimination gives the same information: is the number of pivots, is the number of free variables. The SVD version is numerically more reliable when the matrix is nearly rank-deficient.
16. Implementation from scratch
import numpy as np
def rank_nullity(A, tol=1e-9):
"""Return (rank, nullity) of an m x n matrix using its singular values."""
A = np.asarray(A, dtype=float)
if A.ndim != 2:
raise ValueError("A must be two-dimensional")
s = np.linalg.svd(A, compute_uv=False)
rank = int(np.sum(s > tol))
return rank, A.shape[1] - rank
def nullspace_basis(A, tol=1e-9):
"""Return an n x (n-rank) matrix whose columns span ker(A)."""
A = np.asarray(A, dtype=float)
_, s, vt = np.linalg.svd(A, full_matrices=True)
rank = int(np.sum(s > tol))
return vt[rank:].T
A = np.array([[1.0, 2.0, 3.0],
[2.0, 4.0, 6.0]])
rank, nullity = rank_nullity(A)
assert (rank, nullity) == (1, 2)
N = nullspace_basis(A)
assert N.shape == (3, 2)
assert np.allclose(A @ N, 0.0, atol=1e-10)
print("rank", rank, "nullity", nullity)
print("kernel basis columns:\n", N)
The assertion is the real test: it checks that the computed basis vectors actually lie in the kernel, not merely that the dimensions add up.
17. Professional library implementation
import numpy as np
from scipy.linalg import null_space
A = np.array([[1.0, 2.0, 3.0],
[2.0, 4.0, 6.0]])
rank = np.linalg.matrix_rank(A) # 1
N = null_space(A) # shape (3, 2)
print(rank, N.shape, np.linalg.norm(A @ N))
numpy.linalg.matrix_rank uses an SVD with a tolerance derived from the largest singular value; scipy.linalg.null_space does the same and returns an orthonormal basis. Both are preferable to counting nonzero rows after floating-point elimination, which can misclassify tiny pivots.
18. Code walkthrough
Scratch version. np.linalg.svd(A, compute_uv=False) returns the singular values in descending order. The number greater than tol is the numerical rank. The nullity is the number of columns minus that rank, which is exactly the theorem. nullspace_basis keeps the right singular vectors corresponding to the zero singular values; those vectors span the kernel.
Library version. matrix_rank and null_space hide the same SVD but choose a tolerance automatically. The library is convenient, but you should still verify and check that has the predicted number of columns. A dimension check alone can pass while the basis is wrong.
20. Time complexity
Computing an SVD of an matrix costs floating-point operations; for square matrices this is . Gaussian elimination to row-echelon form costs when . The rank–nullity identity itself is once the rank is known; the cost is entirely in computing the rank reliably.
21. Space complexity
A dense SVD requires storage for the matrix plus for the singular vectors if they are formed. Computing only singular values can use less. For very large sparse matrices, iterative methods (Lanczos, randomized SVD) approximate the leading singular values and avoid forming the full decomposition.
22. Experimental demonstration
Generate random matrices with , compute the numerical rank, and verify that for every trial. Then construct a matrix with a known rank by multiplying an matrix by an matrix; check that the computed rank is when the factors are well conditioned. Finally, add noise of increasing scale and observe the numerical rank increase — this shows that rank is not a stable function of floating-point data.
24. Limitations
- The theorem requires to be finite-dimensional. For infinite-dimensional spaces, cardinal arithmetic replaces subtraction and the simple identity can fail.
- It is an identity about dimensions, not about specific bases; it does not tell you which vectors are in the kernel.
- Numerical rank depends on a tolerance. A matrix that is mathematically rank 1 but has floating-point noise of size will be reported as higher rank if the tolerance is too small.
- The theorem says nothing about the condition number. A full-rank matrix can still be nearly singular and numerically unstable to invert.
25. Failure scenarios
- Using the wrong dimension. Rank–nullity uses the number of columns (the domain dimension), not the number of rows. For a matrix, rank + nullity = 3, not 2.
- Counting zero rows. A zero row after elimination indicates a dependency among rows, but the nullity is the number of free variables (non-pivot columns), not the number of zero rows in general.
- Ignoring tolerance. Treating every singular value below machine epsilon as nonzero overstates the rank and understates the nullity.
- Assuming rank = min(m,n). That is the maximum possible rank, not the actual rank.
- Confusing kernel with image. They live in different spaces (, ) and generally have different dimensions.
26. Common misconceptions
- “Rank–nullity says rank equals nullity.” No: it says their sum equals .
- “Nullity is the number of zero eigenvalues.” For a square matrix, the nullity is the geometric multiplicity of the eigenvalue 0, which can be smaller than the algebraic multiplicity. It is not simply the count of zero eigenvalues.
- “A square matrix with determinant zero has nullity 1.” It has nullity at least 1; a zero matrix has nullity 3.
- “The theorem applies to any function.” It requires a linear map between vector spaces. For nonlinear maps, the dimensions of level sets and images need not add up.
- “Rank is always obvious from the shape.” Shape gives only the upper bound .
27. Alternative approaches
- Gaussian elimination / RREF: gives rank and a nullspace basis directly, and is the standard hand-computation method. Less numerically stable than SVD for rank decisions.
- QR with column pivoting: exposes rank and an orthonormal basis of the column space; cheaper than SVD for some problems.
- SVD: most reliable for numerical rank and nullspace, at higher cost.
- Randomized SVD: approximates the leading singular values for very large matrices.
- The quotient-space proof: shortest conceptual proof, but requires quotient spaces.
29. Research applications
- Low-rank approximation: if has rank , it can be stored and multiplied using parameters instead of . This is the basis of LoRA and many compression methods.
- Control theory: controllability and observability are rank conditions on matrices built from and or .
- Coding theory: the dimension of a linear code is the rank of its generator matrix; the nullity of the parity-check matrix gives the number of independent parity constraints.
- Numerical linear algebra: rank-revealing factorizations decide when a matrix is effectively singular.
- Representation theory: dimension counting for kernels and images underlies exact sequences.
30. Important research papers
This is textbook material rather than a research result, so no research paper is cited here. The theorem is proved in:
- S. Axler, Linear Algebra Done Right, Springer. Chapter 3.
- G. Strang, Introduction to Linear Algebra, Wellesley-Cambridge Press. Chapter 3.
- K. Hoffman and R. Kunze, Linear Algebra, Prentice Hall. Chapter 3.
No citation is invented to make the page look more research-oriented.
31. Further reading
- Axler, Linear Algebra Done Right — the basis-extension proof and the quotient-space proof.
- Strang, Introduction to Linear Algebra — the matrix version with elimination and free variables.
- Hoffman and Kunze, Linear Algebra — the coordinate-free treatment.
- Any standard abstract algebra text for the first isomorphism theorem, of which rank–nullity is the vector-space case.
32. Practical exercises
- For , compute the rank, a basis of the column space, and a basis of the nullspace by hand. Verify rank + nullity = 3.
- For , show that the third row is the sum of the first two, find the nullity, and exhibit a nonzero kernel vector.
- Prove that a linear map with is injective if and only if it is surjective.
- Give an example of a matrix with rank 2 and nullity 1, and another with rank 1 and nullity 2.
- Explain why a matrix must have nullity at least 2.
- Implement
rank_nullityand test it on the matrices above. Then add noise of size and explain why the numerical rank may change.
Answer sketches.
- has : the second row is twice the first. A column-space basis is . The kernel is , with basis . Then .
- has third row first second, so and nullity . A kernel vector is : each row gives or .
- If is injective then , so nullity and rank , hence is surjective. Conversely, if is surjective then rank , so nullity and is injective.
- has rank 2, nullity 1. has rank 1, nullity 2.
- A matrix has rank at most 4, so nullity .
- Adding noise typically makes small singular values nonzero. With an absolute tolerance of the numerical rank rises and the numerical nullity falls; the correct tolerance scales with and the expected noise level.
33. Debugging challenges
- Your code reports rank 2 for a matrix whose second row is exactly twice the first. Check whether you are counting singular values with a tolerance that is too small relative to the matrix scale.
- Your nullspace matrix has the right shape but is not zero. Check whether you transposed the right singular vectors correctly; the nullspace is spanned by the last rows of , i.e. the last columns of .
- Rank + nullity does not equal the number of columns. You are probably using the number of rows, or computing nullity as
m - rank. - A square matrix has determinant zero but
matrix_rankreturns full rank. The matrix may be ill-conditioned rather than exactly singular; inspect the singular values before trusting the determinant.
34. Advanced exercises
- Prove the quotient-space version of rank–nullity without using the basis-extension theorem.
- Show that for , . Use the theorem to relate the nullity of and the left nullspace of .
- Derive the rank–nullity theorem for the adjoint map and explain why the dimensions match.
- For a block matrix , express the rank in terms of the ranks of and and the coupling . When is the rank exactly ?
- Show that the set of rank- matrices is a variety defined by the vanishing of all minors, and connect this to the dimension count.
35. Interview questions
- State the rank–nullity theorem precisely, including the finite-dimensional hypothesis.
- Prove it by extending a basis of the kernel.
- Why does the theorem use the number of columns rather than the number of rows for a matrix?
- What is the relationship between nullity and the number of free variables in Gaussian elimination?
- Give a linear map with rank 2 and nullity 3. What are the domain and image dimensions?
- Why is numerical rank tolerance-dependent, and how does the SVD help?
- What happens to the theorem for infinite-dimensional spaces?
36. Research questions
- How should rank be defined for matrices over rings rather than fields, and which dimension identities survive?
- What is the stable rank, and why is it a better numerical proxy than exact rank for random matrices?
- How do rank-revealing factorizations trade accuracy against cost for sparse matrices?
- Can the dimension identity be generalized to linear operators on infinite-dimensional Hilbert spaces using Fredholm index theory? (The index is , not a simple sum.)
37. Mastery assessment
To demonstrate mastery: (1) state the theorem with its hypotheses; (2) reproduce the basis-extension proof without notes; (3) compute rank and nullity for two concrete matrices and exhibit a kernel basis; (4) explain why rank + nullity uses the number of columns; (5) identify one numerical pitfall. A repository and GPU experiment are not required for this foundational theorem; the evidence is a correct proof and correct hand computations.
39. Completion criteria
All of: theorem stated correctly; proof reproduced; at least three concrete examples computed by hand; code run and checked against the examples; one failure mode (tolerance or wrong dimension) explained. No assessment score is claimed until the linked assessment is actually taken.