Skip to content

LA1

Vector spaces

A vector space is a set where you can add elements and scale them by numbers, and where those two operations obey the rules you already use without thinking. Nothing else: no lengths, no angles, no coordinates, no arrows. Every model in machine learning lives in one, because data, weights, gradients and even functions can be added and scaled.

Needs: F1 Sets, families and intersections. Used by: LA2 Span, and everything after.

You scale vectors by numbers, so first we fix what “numbers” are allowed to be.

Definition LA1.1Field#

A field is a set F\mathbb{F} with two operations F×F→F\mathbb{F} \times \mathbb{F} \to \mathbb{F}, addition and multiplication, such that:

  • addition and multiplication are associative and commutative;
  • there exist elements 0≠10 \neq 1 in F\mathbb{F} such that a+0=aa + 0 = a and 1⋅a=a1 \cdot a = a for all aa;
  • every aa has an additive inverse −a-a with a+(−a)=0a + (-a) = 0, and every a≠0a \neq 0 has a multiplicative inverse a−1a^{-1} with aa−1=1a a^{-1} = 1;
  • multiplication distributes over addition: a(b+c)=ab+aca(b + c) = ab + ac for all a,b,ca, b, c.

Compare: Axler, LADR 4e, “Digression on fields” (ch. 1A)

SetField?Why
Q\mathbb{Q}, R\mathbb{R}, C\mathbb{C}yesall the rules hold
F2={0,1}\mathbb{F}_2 = \{0, 1\}, arithmetic mod 2yes1+1=01 + 1 = 0; check the rest by hand
Z\mathbb{Z}no22 has no inverse: 12∉Z\tfrac{1}{2} \notin \mathbb{Z}
float64 numbersnoaddition is not associative (below)

Convention LA1.2F means ℝ or ℂ#

On this site F\mathbb{F} stands for R\mathbb{R} or C\mathbb{C} unless a page says otherwise. Elements of F\mathbb{F} are called scalars.

Full explanationWhy a field, and why your computer doesn't have one

The field rules are exactly what you need to solve for things. Linear algebra constantly finds unknown coefficients, and finding them means dividing. Integers fail here: you cannot solve 2a=12a = 1 in Z\mathbb{Z}.

Floating-point numbers also fail, in a way that matters in practice. In float64,

(0.1+0.2)+0.3=0.6000000000000001,0.1+(0.2+0.3)=0.6.(0.1 + 0.2) + 0.3 = 0.6000000000000001, \qquad 0.1 + (0.2 + 0.3) = 0.6.

Associativity is broken by rounding. In float32, (108+1)−108=0(10^8 + 1) - 10^8 = 0 while (108−108)+1=1(10^8 - 10^8) + 1 = 1: added to the large number first, the 11 is absorbed by rounding. This is why summing the same numbers in a different order (on another GPU, or with another batch split) can give slightly different results, and why numerical code is written to keep rounding under control. The mathematics on this site is exact, over R\mathbb{R} or C\mathbb{C}; computers approximate it.

Who uses which field. R\mathbb{R} is the default in machine learning. C\mathbb{C} appears wherever there are rotations and frequencies: Fourier transforms, signal processing, quantum computing, and rotary position embeddings in transformers, which rotate pairs of coordinates by an angle that grows with position (the same thing as multiplying complex numbers by eiθe^{i\theta}). F2\mathbb{F}_2 is the field of bits: error-correcting codes, cryptography and hashing do linear algebra over it.

Definition LA1.3Vector space#

A vector space over F\mathbb{F} is a set VV together with

  • an addition V×V→VV \times V \to V, written (u,v)↦u+v(u, v) \mapsto u + v, and
  • a scalar multiplication F×V→V\mathbb{F} \times V \to V, written (a,v)↦av(a, v) \mapsto av,

such that for all u,v,w∈Vu, v, w \in V and all a,b∈Fa, b \in \mathbb{F}:

AxiomName
VS1u+v=v+uu + v = v + ucommutativity
VS2(u+v)+w=u+(v+w)(u + v) + w = u + (v + w)associativity
VS3there is 0∈V0 \in V with v+0=vv + 0 = v for all vvadditive identity
VS4for each vv there is w∈Vw \in V with v+w=0v + w = 0additive inverse
VS5(ab)v=a(bv)(ab)v = a(bv)compatibility of scaling
VS61v=v1v = vscaling by one
VS7a(u+v)=au+ava(u + v) = au + avdistributivity over vectors
VS8(a+b)v=av+bv(a + b)v = av + bvdistributivity over scalars

Elements of VV are called vectors.

Compare: Axler, LADR 4e, Definition 1.20; Hoffman & Kunze, §2.1

Full explanationHow to read the definition

The operations are part of the data. A vector space is not just a set; it is a set with a particular addition and scaling. The same set with different operations can be a vector space or not (see LA1.8 and LA1.9).

Closure is built in. Writing addition as a function V×V→VV \times V \to V already says that the sum of two vectors is again in VV. Some books list “closure” as two extra axioms. Here it lives in the arrows.

What is not there. Nothing in the definition mentions length, angle, distance, coordinates, multiplying two vectors together, or infinite sums. Those are extra structure added later (norms, inner products, bases). Keeping them out is what lets the same theorems apply to arrows in the plane, to polynomials and to probability-weighted functions.

“Vector” is a role, not a shape. A vector is anything that lives in a vector space. A function, a matrix or an image is a vector as soon as you put it in a space where it can be added and scaled.

Examples: one space that contains the others

Section titled “Examples: one space that contains the others”

Example LA1.4Fⁿ#

Fn\mathbb{F}^n, the nn-tuples of scalars, with componentwise operations: (x1,…,xn)+(y1,…,yn)=(x1+y1,…,xn+yn)(x_1, \dots, x_n) + (y_1, \dots, y_n) = (x_1 + y_1, \dots, x_n + y_n) and a(x1,…,xn)=(ax1,…,axn)a(x_1, \dots, x_n) = (ax_1, \dots, ax_n). The zero vector is (0,…,0)(0, \dots, 0).

Rather than checking eight axioms again for matrices, sequences, images and functions, prove them once for the space that contains all of these as special cases.

Theorem LA1.5Functions into a field form a vector space#

For any set XX, the set FX\mathbb{F}^X of all functions X→FX \to \mathbb{F} is a vector space with pointwise operations:

(f+g)(x):=f(x)+g(x),(af)(x):=a f(x).(f + g)(x) := f(x) + g(x), \qquad (af)(x) := a\, f(x).

Its zero vector is the constant function 00, and the additive inverse of ff is x↦−f(x)x \mapsto -f(x).

Proofof LA1.5

Each axiom, evaluated at a point x∈Xx \in X, becomes a rule of the field F\mathbb{F}. For VS2: ((f+g)+h)(x)=(f(x)+g(x))+h(x)=f(x)+(g(x)+h(x))=(f+(g+h))(x)((f + g) + h)(x) = (f(x) + g(x)) + h(x) = f(x) + (g(x) + h(x)) = (f + (g + h))(x), using associativity in F\mathbb{F}. Two functions that agree at every point are equal, so (f+g)+h=f+(g+h)(f + g) + h = f + (g + h). VS1 and VS5–VS8 go the same way, each using the matching field rule. VS3: (f+0)(x)=f(x)+0=f(x)(f + 0)(x) = f(x) + 0 = f(x). VS4: (f+(−f))(x)=f(x)−f(x)=0(f + (-f))(x) = f(x) - f(x) = 0.

Now choose the index set XX (recall F1, “A vector is a function”):

Choose XXFX\mathbb{F}^X isWho uses it
{1,…,n}\{1, \dots, n\}Fn\mathbb{F}^nevery feature vector, embedding and gradient
{1,…,m}×{1,…,n}\{1, \dots, m\} \times \{1, \dots, n\}m×nm \times n matricesweight matrices, covariance matrices, attention scores
a pixel grid ×{R, G, B}\times \{\text{R, G, B}\}colour imagescomputer vision
N\mathbb{N}infinite sequencessignals, time series, generating functions
R\mathbb{R} or [0,1][0, 1]real functionsfunction approximation, kernels, Gaussian processes

Example LA1.6Polynomials#

P(F)\mathcal{P}(\mathbb{F}) is the set of polynomial functions p(x)=a0+a1x+⋯+adxdp(x) = a_0 + a_1 x + \dots + a_d x^d with coefficients in F\mathbb{F}, and Pd(F)\mathcal{P}_d(\mathbb{F}) those of degree at most dd (including the zero polynomial). With the usual addition and scaling of functions both are vector spaces: in fact they sit inside FF\mathbb{F}^{\mathbb{F}} as subspaces (LA1.13).

Full explanationWhere polynomials fit, and a trap over small fields

Polynomials are the first function space most people meet, and the right picture is a subspace of the big space FF\mathbb{F}^{\mathbb{F}} of all functions: the ones you can build from 1,x,x2,…1, x, x^2, \dots with finitely many additions and scalings. LA2 makes “build from” precise; it is called the span.

They matter because they are the functions a computer can evaluate exactly with ++ and ×\times. Taylor expansions approximate smooth functions by polynomials; polynomial regression fits Pd(R)\mathcal{P}_d(\mathbb{R}) to data; the polynomial kernel k(x,y)=(x⊤y+1)dk(x, y) = (x^\top y + 1)^d in kernel methods and SVMs corresponds to a feature space of polynomials. Over finite fields, polynomials are the backbone of Reed–Solomon codes, which protect data on QR codes and storage disks.

A trap. A polynomial (a list of coefficients) and a polynomial function (what it does to inputs) are the same thing over R\mathbb{R} and C\mathbb{C}, because a non-zero polynomial has only finitely many roots. Over F2\mathbb{F}_2 they differ: xx and x2x^2 are different polynomials, but as functions on {0,1}\{0, 1\} they are identical, since 02=00^2 = 0 and 12=11^2 = 1. This is why Axler restricts to R\mathbb{R} and C\mathbb{C} when he defines polynomials as functions.

Example LA1.7The zero space#

{0}\{0\}, a single vector with 0+0=00 + 0 = 0 and a0=0a0 = 0, is a vector space. It is the smallest one, and it turns up as the span of nothing (LA2).

A definition is understood when you can break it. Each non-example below breaks the definition at a specific point, often closure (the arrows in LA1.3). Example 2 isolates a single axiom, which shows that axiom is doing real work.

Non-example LA1.8Broken examples, one axiom at a time#

  1. The positive reals (0,∞)(0, \infty) with ordinary ++ and scaling. Scaling by −1-1 leaves the set: (−1)⋅2=−2(-1) \cdot 2 = -2. Scalar multiplication is not a function F×V→V\mathbb{F} \times V \to V. There is no zero vector either: with ordinary addition, v+e=vv + e = v forces ee to be the real number 00, which is not in (0,∞)(0, \infty), so VS3 fails.
  2. R2\mathbb{R}^2 with ordinary addition but a⊙(x,y):=(ax,0)a \odot (x, y) := (ax, 0). VS5, VS7 and VS8 still hold (check them), but VS6 fails: 1⊙(1,1)=(1,0)≠(1,1)1 \odot (1, 1) = (1, 0) \neq (1, 1). So VS6 is not a consequence of the others.
  3. Zn\mathbb{Z}^n (n≥1n \ge 1) as a space over R\mathbb{R}. 12⋅(1,0,…,0)∉Zn\tfrac{1}{2} \cdot (1, 0, \dots, 0) \notin \mathbb{Z}^n: scaling leaves the set.
  4. Probability vectors {p∈Rn:pi≥0, ∑ipi=1}\{p \in \mathbb{R}^n : p_i \ge 0, \ \sum_i p_i = 1\} with ordinary operations. Adding two of them gives total 22, not 11; and with ordinary addition the zero vector would have to be (0,…,0)(0, \dots, 0), which is not in the set.
  5. Unit vectors {v∈Rn:∥v∥=1}\{v \in \mathbb{R}^n : \|v\| = 1\}, with ∥v∥\|v\| the Euclidean length and n≥1n \ge 1. The sum of two unit vectors is rarely a unit vector, and the zero vector (forced to be (0,…,0)(0, \dots, 0), as in 4) is missing.

Example LA1.9The same set, different operations: now it is a vector space#

Take the positive reals again, as a space over R\mathbb{R}, but define “addition” as x⊕y:=xyx \oplus y := xy and “scaling” as a⊙x:=xaa \odot x := x^a. Every axiom holds. The zero vector is 11 (since x⊕1=xx \oplus 1 = x), the inverse of xx is 1/x1/x, and VS8 reads xa+b=xaxbx^{a+b} = x^a x^b.

Full explanationWhat the positive-reals example teaches

The set did not change; the operations did, and that decided everything. The logarithm translates this strange space into ordinary R\mathbb{R}: log⁡(xy)=log⁡x+log⁡y\log(xy) = \log x + \log y and log⁡(xa)=alog⁡x\log(x^a) = a \log x. Products become sums and powers become scalings. Later you will call such a translation an isomorphism.

You use this translation constantly in machine learning: likelihoods are products of probabilities, and taking logs turns them into sums of log-probabilities, which are easier to differentiate and do not underflow. Non-examples 4 and 5 matter for the same reason. Softmax outputs live on the probability simplex, and normalised embeddings live on the unit sphere. Neither is a vector space. On the simplex, sums, differences and scalings leave the set, although averages stay inside (the simplex is convex); on the unit sphere even averages leave it. That is why models apply softmax or re-normalise after doing linear algebra in the full space Rn\mathbb{R}^n.

Some facts look too obvious to prove. Proving them is how you find out which axioms they depend on, and it is the first practice at reasoning from definitions alone.

Theorem LA1.10First consequences#

In every vector space VV, for all v∈Vv \in V and a∈Fa \in \mathbb{F}:

  1. the zero vector is unique;
  2. each vv has exactly one additive inverse, written −v-v;
  3. 0v=00v = 0 (scalar zero times vv is the zero vector);
  4. a0=0a0 = 0;
  5. (−1)v=−v(-1)v = -v.
Proofof LA1.10
  1. Let 00 and 0′0' both satisfy VS3. Then 0′=0′+0=0+0′=00' = 0' + 0 = 0 + 0' = 0, using VS3 for 00, VS1, then VS3 for 0′0'.
  2. Let ww and w′w' both be inverses of vv. Then w=w+0=w+(v+w′)=(w+v)+w′=0+w′=w′w = w + 0 = w + (v + w') = (w + v) + w' = 0 + w' = w', using VS3, VS2 and VS1.
  3. 0v=(0+0)v=0v+0v0v = (0 + 0)v = 0v + 0v by VS8. Add −(0v)-(0v) to both sides and simplify with VS2, VS4 and VS3: 0=0v0 = 0v.
  4. a0=a(0+0)=a0+a0a0 = a(0 + 0) = a0 + a0 by VS7; add −(a0)-(a0) to both sides as in 3.
  5. v+(−1)v=1v+(−1)v=(1+(−1))v=0v=0v + (-1)v = 1v + (-1)v = (1 + (-1))v = 0v = 0, using VS6, VS8 and part 3. So (−1)v(-1)v is an inverse of vv, and by part 2 it is the inverse, −v-v.
Check In the strange space of LA1.9 (positive reals over ℝ, x ⊕ y = xy, a ⊙ x = x^a), what does part 3 of LA1.10, 0v = 0, say in ordinary notation?

The scalar 00 times xx is x0=1x^0 = 1, and the zero vector of this space is 11. So "0v=00v = 0" becomes x0=1x^0 = 1: a familiar fact, here forced by the axioms.

Definition LA1.11Subspace#

A subset U⊆VU \subseteq V is a subspace of VV if UU is itself a vector space with the addition and scalar multiplication of VV.

Theorem LA1.12Subspace test#

U⊆VU \subseteq V is a subspace if and only if

  1. 0∈U0 \in U;
  2. u,w∈Uu, w \in U implies u+w∈Uu + w \in U;
  3. a∈Fa \in \mathbb{F} and u∈Uu \in U implies au∈Uau \in U.

Compare: Axler, LADR 4e, §1C; Hoffman & Kunze, §2.2, Theorem 1

Proofof LA1.12

(⇒\Rightarrow) If UU is a subspace, its operations are those of VV and land in UU, which gives 2 and 3. UU has its own zero 0U0_U with 0U+0U=0U0_U + 0_U = 0_U. Adding the inverse of 0U0_U in VV to both sides gives 0U=00_U = 0, so 0∈U0 \in U.

(⇐\Leftarrow) By 2 and 3 the operations of VV restrict to functions U×U→UU \times U \to U and F×U→U\mathbb{F} \times U \to U. Axioms VS1, VS2 and VS5–VS8 hold for all vectors of VV, so in particular for those in UU. VS3 holds by 1. For VS4, take u∈Uu \in U: by 3, (−1)u∈U(-1)u \in U, and (−1)u=−u(-1)u = -u by LA1.10, so uu has its inverse inside UU.

Example LA1.13Subspaces, and look-alikes that aren't#

Subspaces. {0}\{0\} and VV itself. Lines and planes through the origin in R3\mathbb{R}^3. The solution set {x∈Rn:Ax=0}\{x \in \mathbb{R}^n : Ax = 0\} of a homogeneous linear system. Pd(F)⊆P(F)⊆FF\mathcal{P}_d(\mathbb{F}) \subseteq \mathcal{P}(\mathbb{F}) \subseteq \mathbb{F}^{\mathbb{F}}. Continuous functions inside RR\mathbb{R}^{\mathbb{R}}. Sequences with only finitely many non-zero terms inside FN\mathbb{F}^{\mathbb{N}}.

Not subspaces. A line that misses the origin, such as {(x,y):y=x+1}\{(x, y) : y = x + 1\} (no 00). The solutions of Ax=bAx = b with b≠0b \neq 0 (no 00). The union of the xx-axis and the yy-axis (not closed under addition). The unit disc (not closed under scaling). Polynomials of degree exactly 22 (x2+(−x2)=0x^2 + (-x^2) = 0 has no degree 22).

Theorem LA1.14Intersections of subspaces are subspaces#

The intersection of any non-empty family of subspaces of VV is a subspace of VV.

Compare: Hoffman & Kunze, §2.2, Theorem 2

Proofof LA1.14

Let U\mathcal{U} be a non-empty family of subspaces and W=⋂UW = \bigcap \mathcal{U}. Apply the subspace test. (1) Every U∈UU \in \mathcal{U} contains 00, so 0∈W0 \in W. (2) If u,w∈Wu, w \in W, then u,w∈Uu, w \in U for every U∈UU \in \mathcal{U}; each UU is closed under addition, so u+w∈Uu + w \in U for every UU, hence u+w∈Wu + w \in W. (3) Scaling is identical.

Unions do not behave this way: the two axes are subspaces, their union is not. To get the smallest subspace containing both, you intersect all the subspaces that contain them, exactly as in F1.15. That subspace is the span, the subject of LA2.

Check Is {(x, y, z) ∈ ℝ³ : x + y + z = 0} a subspace? And {(x, y, z) : x + y + z = 1}?

The first is: it contains 00, and sums and multiples of solutions are solutions. It is a plane through the origin. The second is not: 00 is missing (0+0+0≠10 + 0 + 0 \neq 1). It is the same plane shifted.

Check ℂ is a vector space over ℂ and also over ℝ. Is ℝ a subspace of ℂ?

It depends on the field. Over R\mathbb{R}, yes: real multiples of reals are real. Over C\mathbb{C}, no: i⋅1=i∉Ri \cdot 1 = i \notin \mathbb{R}. “Subspace” always means subspace over a given field.

Check In non-example LA1.8(2), verify that VS7 holds: a ⊙ (u + v) = a ⊙ u + a ⊙ v.

With u=(x1,y1)u = (x_1, y_1), v=(x2,y2)v = (x_2, y_2): a⊙(u+v)=(a(x1+x2),0)=(ax1,0)+(ax2,0)=a⊙u+a⊙va \odot (u + v) = (a(x_1 + x_2), 0) = (ax_1, 0) + (ax_2, 0) = a \odot u + a \odot v. Only VS6 breaks.

  • Sheldon Axler, Linear Algebra Done Right, 4th ed. (open access, 2024): fields (ch. 1A), Definition 1.20 (vector space), §1C (subspaces).
  • Kenneth Hoffman & Ray Kunze, Linear Algebra, 2nd ed. (1971): §2.1 (vector spaces), §2.2 Theorems 1–2 (subspace test, intersections of subspaces).
  • Deisenroth, Faisal & Ong, Mathematics for Machine Learning (2020): §2.4 (vector spaces), for a second, more applied angle.