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 cvc\vec{v} — satisfying ten axioms:

Addition axioms:

  1. Closure: v+wV\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 0V\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: cvVc\vec{v} \in V
  2. Distributivity over vector addition: c(v+w)=cv+cwc(\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=v1\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)+(3x)=4+x(1 + 2x) + (3 - x) = 4 + x. The zero vector is the zero polynomial.

Function spaces: the set of all functions f:RRf: \mathbb{R} \to \mathbb{R} with (f+g)(x)=f(x)+g(x)(f+g)(x) = f(x)+g(x) and (cf)(x)=cf(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 WVW \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. 0W\vec{0} \in W
  2. Closed under addition: u,vWu+vW\vec{u}, \vec{v} \in W \Rightarrow \vec{u} + \vec{v} \in W
  3. Closed under scalar multiplication: vW,cRcvW\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,vW\vec{u}, \vec{v} \in W and scalars a,ba, b: au+bvWa\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:tR}\{t\vec{v} : t \in \mathbb{R}\}
  • Any plane through the origin: {su+tv:s,tR}\{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={v1,,vk}S = \{\vec{v}_1, \ldots, \vec{v}_k\} is the set of all linear combinations:

[S]=span(S)={c1v1+c2v2++ckvk:ciR}[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{u1,,uk}\text{span}\{\vec{u}_1, \ldots, \vec{u}_k\}, ask: do scalars a1,,aka_1, \ldots, a_k exist such that

a1u1++akuk=v?a_1 \vec{u}_1 + \cdots + a_k \vec{u}_k = \vec{v}\,?

Assemble A=[u1uk]A = [\vec{u}_1 \mid \cdots \mid \vec{u}_k] (columns are the spanning vectors) and apply Gauss's method to [Av][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{u1=(1,1),u2=(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)=3u1+1u2(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{u1,u2}=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 AMm×nA \in \mathcal{M}_{m \times n}:

  • Null space N(A)={xRn: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:xRn}\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