Definition of Vector Spaces
Everything we did with vectors in used only two operations: adding vectors and multiplying them by numbers. Polynomials, functions, matrices, sound signals and bit strings can be added and scaled too. A vector space is any collection with those two operations obeying the usual rules, and every theorem proved from the rules then holds for all of them at once.
The axioms
Fix a field of scalars , usually , sometimes or GF(2) (Fields). A vector space over is a set with an addition and a scalar multiplication (for and ) such that, for all and :
| # | Axiom | Name |
|---|---|---|
| 1 | addition is commutative | |
| 2 | addition is associative | |
| 3 | there is a vector with | zero vector |
| 4 | each has a with | additive inverse |
| 5 | distributive over vectors | |
| 6 | distributive over scalars | |
| 7 | compatible multiplication | |
| 8 | unit scalar |
"In " is part of the deal: the sum of two elements and every scalar multiple must land back in (closure). The elements of are called vectors, whatever they actually are.
A few facts follow from the axioms alone, and so hold in every vector space: the zero vector is unique, , , and . For example, by axiom 6, and adding to both sides leaves .
A zoo of examples
| Space | Vectors | Addition and scaling | Zero vector |
|---|---|---|---|
| lists | entry by entry | ||
| polynomials of degree | add/scale coefficients | the zero polynomial | |
| matrices | entry by entry (Matrix Addition) | the zero matrix | |
| all functions | , | ||
| continuous functions on | as for functions | ||
| solutions of | functions | as for functions | |
| bit strings of length | XOR, scalars 0 and 1 | 00…0 | |
| sequences | infinite lists | term by term |
The point is not to memorise the list but to notice that "vector" is a role, not a type. A function is a vector in . An audio clip of 44 100 samples is a vector in . A word embedding is a vector in .
In code, a polynomial of degree can be stored as its coefficient list, and then its vector-space operations are exactly those of :
from fractions import Fraction as Fr
def add(p, q): return [a + b for a, b in zip(p, q)]
def scale(c, p): return [c * a for a in p]
def show(p):
terms = [f"{a}{['', 'x', 'x^2'][i]}" for i, a in enumerate(p) if a != 0]
return " + ".join(terms).replace("+ -", "- ") or "0"
p = [1, -2, 3] # 1 - 2x + 3x^2
q = [Fr(1, 2), 0, -1] # 1/2 - x^2
print("p + q =", show(add(p, q)))
print("3p - 2q =", show(add(scale(3, p), scale(-2, q))))
print("p + (-p) =", show(add(p, scale(-1, p))))p + q = 3/2 - 2x + 2x^2
3p - 2q = 2 - 6x + 11x^2
p + (-p) = 0
Non-examples
Checking a candidate usually comes down to closure and the zero vector:
| Set | Why it fails |
|---|---|
| the line in | does not contain ; is off the line |
| polynomials of degree exactly 2 | has degree 1 |
| vectors in with | is in, but is not |
| invertible matrices | is not invertible |
| (integer vectors) over | is not in |
An exotic example
The axioms only care about the operations, not what they look like. Let (the positive reals) with
The zero vector is the number 1 (since ), and the "negative" of is . Axiom 6 becomes , and axiom 5 becomes : the laws of exponents. The logarithm turns this space into ordinary (), which is why log-probabilities are added in machine learning code instead of multiplying probabilities.
import math
add = lambda u, v: u * v
smul = lambda c, v: v ** c
u, v, a, b = 2.0, 5.0, 3.0, -0.5
checks = {
"commutative": math.isclose(add(u, v), add(v, u)),
"zero is 1": math.isclose(add(u, 1.0), u),
"inverse 1/v": math.isclose(add(v, 1 / v), 1.0),
"a(u+v)=au+av": math.isclose(smul(a, add(u, v)), add(smul(a, u), smul(a, v))),
"(a+b)v=av+bv": math.isclose(smul(a + b, v), add(smul(a, v), smul(b, v))),
"a(bv)=(ab)v": math.isclose(smul(a, smul(b, v)), smul(a * b, v)),
}
for name, ok in checks.items():
print(f"{name:14} {ok}")commutative True
zero is 1 True
inverse 1/v True
a(u+v)=au+av True
(a+b)v=av+bv True
a(bv)=(ab)v True
In software
- Generic code: interpolation, averaging and gradient steps need only + and scaling, so the same
lerp(a, b, t) = a + t·(b − a)works for positions, colours, quaternions (approximately) and neural-network weights. - Signals and functions: audio mixing is vector addition and volume is scaling; Fourier analysis treats functions as vectors (Orthogonal Projections and Fourier Series).
- ML: model weights live in with in the billions; "model merging" and LoRA updates are vector additions in that space (Low-Rank Approximation).
- Coding theory: bit strings form a vector space over GF(2), the basis of error-correcting codes (Application: Error Correcting Codes).
Exercises
Exercise 1: Trace-zero matrices
Is the set of matrices with trace 0 a vector space (with the usual operations)?
Answer
Yes.
Solution
The axioms 1–8 are inherited from , so only closure and the zero vector need checking. , , and the zero matrix has trace 0. (It is a subspace of , see Subspaces.)
Exercise 2: Polynomials with
Is a vector space?
Answer
No.
Solution
It does not contain the zero polynomial (which has ), and it is not closed under addition: if then .
Exercise 3: A broken addition
On define and the usual scalar multiplication. Which axiom fails?
Answer
Axiom 3: there is no zero vector. Axioms 5 and 6 fail too, for vectors with .
Solution
A zero vector would need for every vector, but the result always has second entry 0. So for every . Axiom 6 fails as well: , but . Axioms 1, 2 and 8 still hold, which shows that each axiom has to be checked separately.
Exercise 4: Solutions of an ODE
Show that the solutions of form a vector space, and check with SymPy that , and are all solutions.
Answer
The left side is linear in , so sums and multiples of solutions are solutions, and is one. All three functions give 0.
Solution
If , then and . So implies and .
from sympy import symbols, exp, diff, simplify
x = symbols("x")
L = lambda y: simplify(diff(y, x, 2) - 3 * diff(y, x) + 2 * y)
for y in [exp(x), exp(2 * x), 4 * exp(x) - 7 * exp(2 * x), exp(3 * x)]:
print(f"L({y}) = {L(y)}")L(exp(x)) = 0
L(exp(2*x)) = 0
L(-7*exp(2*x) + 4*exp(x)) = 0
L(exp(3*x)) = 2*exp(3*x)
The last line is a function that is not a solution, for comparison.
Test yourself
Which set is a vector space with the usual operations?
- Polynomials of degree exactly 3
- The line in
- All symmetric matrices
- Vectors in with all entries
In the space with and , what is the zero vector?
- 0
- 1
- There is none
Which fact holds in every vector space?
- Vectors are lists of numbers
- for every vector
- Every vector has a length
- Vectors can be multiplied by each other