Prerequisite · Linear Algebra

Vector Spaces and Subspaces

17 min read
By the end of this reading you will be able to:
  • Verify whether a set with operations satisfies the eight vector space axioms
  • Test whether a subset is a subspace using the three-condition test: zero vector, closure under addition and scaling
  • Determine whether a vector belongs to a span by reducing the corresponding augmented system
  • Describe the null space and column space of a matrix geometrically and explain their role in ML model expressivity

Why Axiomatize?

In the previous readings, vectors were nn-tuples of reals. But "addition" and "scalar multiplication" appear in many other settings — polynomials, functions, matrices. The concept of a vector space abstracts the shared structure, letting us prove theorems once that apply everywhere.

Definition of a Vector Space

A vector space over R\mathbb{R} is a set VV equipped with two operations — addition v⃗+w⃗\vec{v} + \vec{w} and scalar multiplication cv⃗c\vec{v} — satisfying ten axioms:

Addition axioms:

  1. Closure: v⃗+w⃗∈V\vec{v} + \vec{w} \in V
  2. Commutativity: v⃗+w⃗=w⃗+v⃗\vec{v} + \vec{w} = \vec{w} + \vec{v}
  3. Associativity: (v⃗+w⃗)+u⃗=v⃗+(w⃗+u⃗)(\vec{v} + \vec{w}) + \vec{u} = \vec{v} + (\vec{w} + \vec{u})
  4. Zero element: there exists 0⃗∈V\vec{0} \in V such that v⃗+0⃗=v⃗\vec{v} + \vec{0} = \vec{v}
  5. Additive inverse: for each v⃗\vec{v} there exists −v⃗-\vec{v} such that v⃗+(−v⃗)=0⃗\vec{v} + (-\vec{v}) = \vec{0}

Scalar multiplication axioms:

  1. Closure: cv⃗∈Vc\vec{v} \in V
  2. Distributivity over vector addition: c(v⃗+w⃗)=cv⃗+cw⃗c(\vec{v} + \vec{w}) = c\vec{v} + c\vec{w}
  3. Distributivity over scalar addition: (c+d)v⃗=cv⃗+dv⃗(c + d)\vec{v} = c\vec{v} + d\vec{v}
  4. Associativity: (cd)v⃗=c(dv⃗)(cd)\vec{v} = c(d\vec{v})
  5. Identity: 1v⃗=v⃗1\vec{v} = \vec{v}

The axioms capture exactly what it means for a set to behave "like" Rn\mathbb{R}^n.

Canonical Examples

Rn\mathbb{R}^n: column vectors with component-wise operations. The archetypal vector space.

Mm×n\mathcal{M}_{m \times n}: m×nm \times n matrices with component-wise addition and scalar scaling. The zero vector is the zero matrix.

Pn\mathcal{P}_n: polynomials of degree ≤n\leq n, with coefficient-wise addition. E.g., (1+2x)+(3−x)=4+x(1 + 2x) + (3 - x) = 4 + x. The zero vector is the zero polynomial.

Function spaces: the set of all functions f:R→Rf: \mathbb{R} \to \mathbb{R} with (f+g)(x)=f(x)+g(x)(f+g)(x) = f(x)+g(x) and (cf)(x)=c⋅f(x)(cf)(x) = c\cdot f(x). This is an infinite-dimensional vector space. Fourier analysis lives here.

Trivial space: {0⃗}\{\vec{0}\} with the only possible operations. Dimension zero.

Subspaces

A subspace of VV is a subset W⊆VW \subseteq V that is itself a vector space under the same operations. Rather than checking all ten axioms, a subset WW is a subspace if and only if:

  1. 0⃗∈W\vec{0} \in W
  2. Closed under addition: u⃗,v⃗∈W⇒u⃗+v⃗∈W\vec{u}, \vec{v} \in W \Rightarrow \vec{u} + \vec{v} \in W
  3. Closed under scalar multiplication: v⃗∈W,c∈R⇒cv⃗∈W\vec{v} \in W, c \in \mathbb{R} \Rightarrow c\vec{v} \in W

Conditions 2 and 3 can be combined: WW is a subspace iff for all u⃗,v⃗∈W\vec{u}, \vec{v} \in W and scalars a,ba, b: au⃗+bv⃗∈Wa\vec{u} + b\vec{v} \in W.

Examples of subspaces of R3\mathbb{R}^3:

  • {0⃗}\{\vec{0}\} (trivial)
  • Any line through the origin: {tv⃗:t∈R}\{t\vec{v} : t \in \mathbb{R}\}
  • Any plane through the origin: {su⃗+tv⃗:s,t∈R}\{s\vec{u} + t\vec{v} : s, t \in \mathbb{R}\}
  • All of R3\mathbb{R}^3

Non-examples: a line not through the origin is not a subspace (it doesn't contain 0⃗\vec{0}). The set of vectors with non-negative entries is not a subspace (not closed under negation).

Spanning Sets

The span of a set S={v⃗1,…,v⃗k}S = \{\vec{v}_1, \ldots, \vec{v}_k\} is the set of all linear combinations:

[S]=span(S)={c1v⃗1+c2v⃗2+⋯+ckv⃗k:ci∈R}[S] = \text{span}(S) = \{c_1 \vec{v}_1 + c_2 \vec{v}_2 + \cdots + c_k \vec{v}_k : c_i \in \mathbb{R}\}

The span is always a subspace. We say SS spans WW if [S]=W[S] = W.

When looking for a spanning set for a space arising from a linear system, write the solution set in parametric form — the vectors multiplied by the free parameters form a spanning set for the null space.

Checking Span Membership with Gauss's Method

To test whether v⃗\vec{v} lies in span{u⃗1,…,u⃗k}\text{span}\{\vec{u}_1, \ldots, \vec{u}_k\}, ask: do scalars a1,…,aka_1, \ldots, a_k exist such that

a1u⃗1+⋯+aku⃗k=v⃗ ?a_1 \vec{u}_1 + \cdots + a_k \vec{u}_k = \vec{v}\,?

Assemble A=[u⃗1∣⋯∣u⃗k]A = [\vec{u}_1 \mid \cdots \mid \vec{u}_k] (columns are the spanning vectors) and apply Gauss's method to [A∣v⃗][A \mid \vec{v}]. If the system is consistent, v⃗\vec{v} is in the span; if it is inconsistent, it is not.

Example. Is v⃗=(5,4)\vec{v} = (5,4) in span{u⃗1=(1,1), u⃗2=(2,1)}\text{span}\{\vec{u}_1=(1,1),\,\vec{u}_2=(2,1)\}?

a(11)+b(21)=(54)⟹[125114]a\begin{pmatrix}1\\1\end{pmatrix}+b\begin{pmatrix}2\\1\end{pmatrix}=\begin{pmatrix}5\\4\end{pmatrix}\quad\Longrightarrow\quad\left[\begin{array}{rr|r}1&2&5\\1&1&4\end{array}\right]

The reduction ρ2←ρ2−ρ1\rho_2 \leftarrow \rho_2 - \rho_1 gives b=1b=1, then back-substitution gives a=3a=3, so (5,4)=3u⃗1+1u⃗2(5,4) = 3\vec{u}_1 + 1\vec{u}_2. Replacing the right-hand side with a general (x,y)(x,y) shows a solution always exists, confirming span{u⃗1,u⃗2}=R2\text{span}\{\vec{u}_1,\vec{u}_2\} = \mathbb{R}^2.

Computing Span Membership with einsum

Once you have the coefficients, einsum is the idiomatic way to verify a linear combination in both PyTorch and TensorFlow. The subscript 'ij,j->i' means: multiply column jj of AA by scalar cjc_j and sum over jj to produce output index ii.

import numpy as np

# Spanning vectors as *columns* of A
A = np.array([[1., 2.],
              [1., 1.]])
v = np.array([5., 4.])

# Solve A @ c = v  (find coefficients)
c = np.linalg.solve(A, v)
print('coefficients:', c)          # [3. 1.]

# Verify: einsum 'ij,j->i' means sum_j A_ij * c_j
v_hat = np.einsum('ij,j->i', A, c)
print('reconstructed v:', v_hat)    # [5. 4.]

# Does the span cover all of R^2?
# Yes iff det(A) != 0
print('det(A):', np.linalg.det(A))  # -1.0  (nonzero -> span = R^2)

The einsum string 'ij,j->i' is identical in NumPy, PyTorch (torch.einsum), and TensorFlow (tf.einsum). For over-determined systems (more equations than spanning vectors) where an exact solution may not exist, use np.linalg.lstsq — a non-zero residual means v⃗\vec{v} is not in the span.

The Null Space and Column Space Revisited

For A∈Mm×nA \in \mathcal{M}_{m \times n}:

  • Null space N(A)={x⃗∈Rn:Ax⃗=0⃗}\mathcal{N}(A) = \{\vec{x} \in \mathbb{R}^n : A\vec{x} = \vec{0}\} is a subspace of Rn\mathbb{R}^n.
  • Column space C(A)={Ax⃗:x⃗∈Rn}\mathcal{C}(A) = \{A\vec{x} : \vec{x} \in \mathbb{R}^n\} is a subspace of Rm\mathbb{R}^m (the span of the columns of AA).

Both are subspaces — they are closed under the linear combinations that define those spaces. This is why the General = Particular + Homogeneous theorem works: N(A)\mathcal{N}(A) is a genuine subspace, so we can form the coset p⃗+N(A)\vec{p} + \mathcal{N}(A).

References
Hefferon 2020 — Linear Algebra, Ch. Two §I: Definition of Vector Space