7. Vector spaces and subspaces (abstract definition, not just ℝⁿ)

📖 Reading · 10 min
💡 Every code box below is live — edit it and hit Run.

§16.0 listed a handful of algebraic laws that vector addition and scalar multiplication in \mathbb{R}^n happen to satisfy — commutativity, associativity, distributivity. This lesson takes those laws and makes them the definition. The payoff: anything satisfying them — polynomials, matrices, functions — automatically gets every tool this course builds, with no further proof required each time.

The definition

A vector space over \mathbb{R} is a set V with an addition (\vec u+\vec v\in V) and a scalar multiplication (c\vec v\in V for c\in\mathbb{R}) satisfying, for all \vec u,\vec v,\vec w\in V and scalars c,d:

  1. \vec u+\vec v=\vec v+\vec u (commutativity)
  2. (\vec u+\vec v)+\vec w=\vec u+(\vec v+\vec w) (associativity)
  3. There is a zero vector \vec0 with \vec v+\vec0=\vec v
  4. Every \vec v has an additive inverse -\vec v with \vec v+(-\vec v)=\vec0
  5. 1\vec v=\vec v
  6. c(d\vec v)=(cd)\vec v
  7. c(\vec u+\vec v)=c\vec u+c\vec v
  8. (c+d)\vec v=c\vec v+d\vec v

That's the whole definition. Notice it never says what the elements of V are — only how they combine. \mathbb{R}^n satisfies all eight trivially (§16.0 already checked the two that need checking; the rest inherit directly from real-number arithmetic). What makes the definition powerful is everything else that also satisfies it:

  • P_n, polynomials of degree \le n: (x^2+1)+(3x-2)=x^2+3x-1, and 5(x^2+1)=5x^2+5 — both still degree \le2 polynomials. The zero vector is the zero polynomial.
  • M_{m\times n}, all m\times n matrices, under §16.2's matrix addition and scalar multiplication.
  • C[a,b], continuous functions on an interval, under pointwise addition (f+g)(x)=f(x)+g(x) and scaling (cf)(x)=cf(x).
  • The solution set of a homogeneous linear system A\vec x=\vec0 — checked directly below, and central to §17.4.

Once any of these eight axioms are confirmed for a set, every later lesson in this course applies to it without modification: span, basis, dimension, linear transformations, even eigenvalues (for spaces of matrices or functions) all only ever use these eight properties.

Subspaces

A subspace W of a vector space V is a subset that is itself a vector space, using the same operations. Checking all eight axioms from scratch is never necessary — since W\subseteq V already inherits commutativity, associativity, and the distributive laws from V, only three things need verifying:

Subspace test. W\subseteq V is a subspace if and only if:

  1. \vec0\in W (nonempty, and specifically contains the zero vector)
  2. \vec u,\vec v\in W\implies\vec u+\vec v\in W (closed under addition)
  3. \vec v\in W,\,c\in\mathbb{R}\implies c\vec v\in W (closed under scalar multiplication)

(2) and (3) combine into closed under linear combinations — the single property that matters most, and the reason span (§17.1) always produces a subspace.

Geometric picture in \mathbb{R}^3: the subspaces are exactly the origin \{\vec0\}, lines through the origin, planes through the origin, and all of \mathbb{R}^3 — always something passing through the origin, since axiom (1) demands it. A line not through the origin fails the test immediately: it doesn't contain \vec0.

Worked non-example, and why it matters

Is W=\{(x,y)\in\mathbb{R}^2:y=x^2\} a subspace of \mathbb{R}^2? No — it fails immediately: (1,1)\in W (since 1=1^2), but 2(1,1)=(2,2)\notin W (since 2\neq2^2=4). Not closed under scalar multiplication, so it's not a subspace, even though it contains \vec0=(0,0).

This is the general lesson: linearity is a strong requirement. A subset defined by any equation involving a square, a product of two variables, an inequality, or a missing origin is essentially never a subspace. What does survive is exactly the solution set of a homogeneous (=\vec0 right-hand side) linear system — checked next, and the reason §17.4 calls it the null space rather than just "a solution set."

Doing it in Python: verifying closure

import numpy as np

# W = solutions of x + 2y - z = 0, a plane through the origin in R^3
def in_W(v):
    x, y, z = v
    return np.isclose(x + 2*y - z, 0)

u = np.array([1., 0., 1.])   # 1 + 0 - 1 = 0
v = np.array([0., 1., 2.])   # 0 + 2 - 2 = 0
print("u in W:", bool(in_W(u)))
print("v in W:", bool(in_W(v)))
print("u + v in W:", bool(in_W(u + v)))
print("3u in W:", bool(in_W(3 * u)))

not_a_subspace = np.array([1., 1., 1.])  # 1 + 2 - 1 = 2, not on the plane
shifted = not_a_subspace + u             # a plane NOT through the origin, offset by (1,1,1)
print("\n(1,1,1) in W:", bool(in_W(not_a_subspace)))
u in W: True
v in W: True
u + v in W: True
3u in W: True

(1,1,1) in W: False

Worked example

Is W=\{(x,y,z):x-2y+z=0\} a subspace of \mathbb{R}^3?

(1) \vec0\in W? 0-2(0)+0=0 ✓.

(2) Closed under addition? Let \vec u,\vec v\in W, so u_1-2u_2+u_3=0 and v_1-2v_2+v_3=0. For \vec u+\vec v:

(u_1+v_1)-2(u_2+v_2)+(u_3+v_3)=(u_1-2u_2+u_3)+(v_1-2v_2+v_3)=0+0=0

so \vec u+\vec v\in W ✓.

(3) Closed under scaling? (cu_1)-2(cu_2)+(cu_3)=c(u_1-2u_2+u_3)=c(0)=0 ✓.

\boxed{W\text{ is a subspace (a plane through the origin)}}

Sanity check with concrete vectors: \vec u=(2,1,0)\in W (since 2-2=0) and \vec v=(0,1,2)\in W (since -2+2=0). \vec u+\vec v=(2,2,2): 2-4+2=0 ✓, confirming the general argument with actual numbers, exactly like the Python check above.

Your turn

1. Is W=\{(x,y):x\ge0\} (the right half-plane) a subspace of \mathbb{R}^2? Which axiom fails, if any?

2. Is W=\{p\in P_2:p(0)=0\} (quadratics with no constant term) a subspace of P_2?

3. True or false: the union of two subspaces is always a subspace.

Solutions

1. Not a subspace. It contains \vec0=(0,0), and it's closed under addition (sum of two nonnegative first coordinates is nonnegative), but it fails closure under scalar multiplication: (1,0)\in W, but -1(1,0)=(-1,0)\notin W.

2. Yes, a subspace. \vec0 (the zero polynomial) satisfies 0=0 ✓. If p(0)=0 and q(0)=0, then (p+q)(0)=p(0)+q(0)=0 ✓, and (cp)(0)=c\cdot p(0)=c(0)=0 ✓ for any c. (This subspace is exactly \operatorname{span}\{x,x^2\}, previewed properly in §17.1.)

3. False. Counterexample: the x-axis and y-axis are both subspaces of \mathbb{R}^2, but their union is not — (1,0) and (0,1) are each in the union, but (1,0)+(0,1)=(1,1) is in neither axis, so the union isn't closed under addition. (The intersection of two subspaces, by contrast, is always a subspace — a fact worth checking directly from the three-part test.)

Check yourself in code

Check whether W_1=\{(x,y,z):2x-y+3z=0\} and W_2=\{(x,y,z):x^2+y+z=0\} satisfy the subspace test's closure-under-scaling condition, using the vector \vec v=(2,-2,-2) and scalar c=2.

Print exactly this:

v in W1: True
2v in W1: True
v in W2: True
2v in W2: False
def in_W1(v):
    x, y, z = v
    return 2*x - y + 3*z == 0

def in_W2(v):
    x, y, z = v
    return x**2 + y + z == 0

v = (2, -2, -2)
print("v in W1:", in_W1(v))
# print "2v in W1", "v in W2", and "2v in W2" the same way (2v = (4,-4,-4))
def in_W1(v):
    x, y, z = v
    return 2*x - y + 3*z == 0

def in_W2(v):
    x, y, z = v
    return x**2 + y + z == 0

v = (2, -2, -2)
v2 = (4, -4, -4)

print("v in W1:", in_W1(v))
print("2v in W1:", in_W1(v2))
print("v in W2:", in_W2(v))
print("2v in W2:", in_W2(v2))

A vector space is any set with an addition and scalar multiplication obeying eight familiar-looking laws — satisfied not just by \mathbb{R}^n but by polynomials, matrices, and functions, which is exactly why the rest of this course applies to all of them. A subspace needs only three checks: contains \vec0, closed under addition, closed under scaling — equivalently, closed under linear combinations.

Next: span and linear independence — making precise which linear combinations of a set of vectors are reachable, and when none of those vectors is redundant.