Subspaces
A subspace is a vector space sitting inside a bigger one: a subset that is closed under addition and scaling. Instead of checking all eight axioms you only check three things. Subspaces of polynomial, matrix and function spaces are everywhere: symmetric matrices, polynomials with a given root, solutions of a linear equation.
The subspace test
A subset of a vector space is a subspace if it is a vector space with the same operations. Because the axioms (commutativity, distributivity, …) already hold in , it is enough to check:
| # | Condition |
|---|---|
| 1 | |
| 2 | (closed under addition) |
| 3 | , a scalar (closed under scaling) |
Conditions 2 and 3 can be merged into one: . This is the same test used for Subspaces of , now applied in any space. The quickest way to rule a set out is usually condition 1: if is missing, stop.
Examples and non-examples
| Set | In | Subspace? | Reason |
|---|---|---|---|
| yes | , | ||
| no | |||
| even functions | yes | sums and multiples of even functions are even | |
| symmetric matrices | yes | , | |
| upper triangular matrices | yes | zeros below the diagonal stay zeros | |
| matrices with | no | has | |
| solutions of | yes | the equation is linear and homogeneous | |
| solutions of | no | is not a solution | |
| differentiable functions | yes | sums and multiples of differentiable functions are differentiable | |
| (the two axes) | no |
The pattern: sets described by homogeneous linear conditions ("= 0", built from sums and scalar multiples) are subspaces. Anything with "= 1", a product of unknowns, an inequality or a determinant usually is not.
from sympy import Matrix
# matrices with det = 0 are not closed under addition
A, B = Matrix([[1, 0], [0, 0]]), Matrix([[0, 0], [0, 1]])
print("det A =", A.det(), " det B =", B.det(), " det(A+B) =", (A + B).det())
# symmetric matrices are closed under combinations
S, T = Matrix([[1, 2], [2, 5]]), Matrix([[0, -3], [-3, 4]])
C = 3 * S - 2 * T
print("3S - 2T =", C.tolist(), " symmetric:", C == C.T)det A = 0 det B = 0 det(A+B) = 1
3S - 2T = [[3, 12], [12, 7]] symmetric: True
Finding a basis of a subspace
A subspace defined by linear conditions is the null space of a matrix once you use coordinates. Example: . Write :
Two independent equations in four unknowns leave a 2-dimensional subspace:
from sympy import Matrix, symbols, factor
x = symbols("x")
conditions = Matrix([[1, 1, 1, 1], [0, 1, 2, 3]])
for v in conditions.nullspace():
p = sum(c * x**i for i, c in enumerate(v))
print(list(v), "->", p, "=", factor(p))[1, -2, 1, 0] -> x**2 - 2*x + 1 = (x - 1)**2
[2, -3, 0, 1] -> x**3 - 3*x + 2 = (x - 1)**2*(x + 2)
Both basis polynomials have the factor , as they must: means 1 is a double root. So , all cubics with a double root at 1.
Building new subspaces
If and are subspaces of :
| Construction | Subspace? |
|---|---|
| (vectors in both) | always |
| (vectors in either) | only if one contains the other |
| always; the smallest subspace containing both | |
| always; the smallest subspace containing the |
The union fails for the -axis and the -axis in (see the table above); their sum is all of .
In software
- Constraints in solvers: "the result must satisfy these linear equations" defines a subspace (or a shifted one); constrained least squares and physics joint solvers project onto it.
- Data validation: symmetric matrices (covariances, distance matrices) are a subspace, so averaging them or adding them keeps them symmetric, but a determinant or rank condition does not survive averaging.
- Linear codes: a code is a subspace of , which is what makes encoding a matrix product and decoding a null-space check (Application: Error Correcting Codes).
- ML: LoRA restricts a weight update to a low-dimensional set of matrices; fine-tuning in a subspace keeps updates cheap (Low-Rank Approximation).
Exercises
Exercise 1: Skew-symmetric matrices
Is a subspace? What does a general element look like, and what is its dimension?
Answer
Yes. A general element is ; the dimension is 3.
Solution
; ; . The diagonal must satisfy , so it is 0, and the entries below the diagonal are minus those above. The three entries above the diagonal are free.
Exercise 2: Equal endpoints
Is a subspace of ? What about ?
Answer
The first is a subspace; the second is not.
Solution
is the homogeneous linear condition : the zero function satisfies it, and . The second condition fails for the zero function, since .
Exercise 3: A union
Let be the -axis and the line in . Is a subspace? Describe .
Answer
is not a subspace; .
Solution
and , but their sum is on neither line. contains and , which are independent, so it is all of : .
Exercise 4: Polynomials vanishing at two points
Find a basis and the dimension of , using SymPy.
Answer
; a basis is and (that is, and ).
Solution
from sympy import Matrix, symbols, factor
x = symbols("x")
for v in Matrix([[1, 1, 1, 1], [1, -1, 1, -1]]).nullspace():
p = sum(c * x**i for i, c in enumerate(v))
print(list(v), "->", factor(p))[-1, 0, 1, 0] -> (x - 1)*(x + 1)
[0, -1, 0, 1] -> x*(x - 1)*(x + 1)
SymPy's basis is and , matching the answer.
Test yourself
Which set is a subspace of ?
- Matrices with determinant 0
- Invertible matrices
- Matrices whose entries add up to 0
- Matrices with entry equal to 1
What is the quickest way to show that a set is NOT a subspace?
- Find two elements whose sum is in the set
- Show the zero vector is not in it, or find a sum or multiple that leaves it
- Show it is infinite
- Show it has a basis
If and are subspaces, which of these is always a subspace?
- The complement of
- minus