Vectors, Spans & Linear Independence

Volume I, Chapter 1 — Part I. A rigorous foundation for vector spaces, linear combinations, span, linear independence, inner products, and similarity. We prove the exchange lemma, develop the geometric language of machine learning representations, and derive the cosine-similarity framework underlying attention mechanisms.

Beginner

Table of Contents

  1. Learning Objectives
  2. Prerequisites
  3. Notation
  4. Core Intuition
  5. Vector Spaces: Definition and Axioms
  6. Subspaces and the Zero Vector
  7. Linear Combinations
  8. Span of a Set of Vectors
  9. Linear Independence and Dependence
  10. The Exchange Lemma and Basis Uniqueness
  11. Basis and Dimension
  12. Inner Products, Norms, and Similarity
  13. Cosine Similarity and the Geometry of Attention
  14. The Matrix Formulation of Independence
  15. Worked Examples
  16. Connection to Machine Learning
  17. Common Pitfalls and Misconceptions
  18. Research Perspective
  19. Summary of Takeaways
  20. Exercises

Learning Objectives

After reading this chapter, you should be able to:

  1. State and verify the vector space axioms for concrete examples arising in machine learning (Rn\mathbb{R}^n, matrix spaces, function spaces).
  2. Prove that the span of any set of vectors is a subspace, and characterize linear dependence as redundancy among directions.
  3. Apply the linear independence criterion iαivi=0    αi=0\sum_i \alpha_i \mathbf{v}_i = \mathbf{0} \implies \alpha_i = 0 to determine whether a set of feature vectors or embeddings is redundant.
  4. Define a basis, prove that coordinates with respect to a basis are unique, and explain why dimension is well-defined.
  5. Derive the Cauchy–Schwarz inequality and use it to define cosine similarity and the angle between representations.
  6. Explain how dot-product attention computes similarity-weighted linear combinations of value vectors.

Prerequisites

This is the opening chapter of Volume I. No prior chapters are required. Familiarity with basic set notation, real numbers, and elementary algebra is assumed.


Notation

  • F\mathbb{F} — Field (typically R\mathbb{R} or C\mathbb{C})
  • V,WV, W — Vector spaces; 0\mathbf{0} the zero vector
  • vi,α\mathbf{v}_i, \boldsymbol{\alpha} — Vectors and coefficient vector
  • span(S)\text{span}(S) — Set of all linear combinations of SS
  • dim(V)\dim(V) — Dimension of VV
  • u,v\langle \mathbf{u}, \mathbf{v} \rangle — Inner product;  —v —\ — \mathbf{v}\ — induced norm
  • V,VTV\mathbf{V}, \mathbf{V}^T\mathbf{V} — Matrix of column vectors and Gram matrix

Core Intuition

Machine learning operates almost entirely inside vector spaces. A dataset of nn examples with dd features is an n×dn \times d matrix whose rows and columns are vectors. A neural network's parameters form a long vector in Rp\mathbb{R}^p. An embedding maps discrete tokens into a continuous vector space where geometric proximity encodes semantic similarity.

Before we can discuss matrices, optimization, or attention, we need a precise language for three questions:

  • Which outputs can we reach? This is the span — all vectors obtainable as linear combinations of given directions.
  • Are any directions redundant? This is linear independence — no vector in the set can be built from the others.
  • What is the minimal complete description? This is a basis — an independent spanning set whose size defines dimension.

These concepts are not merely algebraic formalism. They determine whether a linear regression problem has a unique solution, whether an embedding space has redundant dimensions, and whether an attention head can represent distinct contextual relationships. The rest of this chapter develops these ideas with full proofs.

Series context. This is Part I of Chapter 1 (Linear Algebra) in Volume I: Foundations. Subsequent parts in this chapter cover Matrix Operations & Linear Transformations, Eigenvalues & Eigenvectors, and the Singular Value Decomposition.


Vector Spaces: Definition and Axioms

Definition 1 (Field). A field F\mathbb{F} is a set equipped with addition and multiplication satisfying the usual axioms. In this curriculum we work primarily with F=R\mathbb{F} = \mathbb{R} (real numbers) and occasionally F=C\mathbb{F} = \mathbb{C} (complex numbers).

Definition 2 (Vector Space). A vector space over F\mathbb{F} is a set VV together with two operations:

  • Vector addition: +:V×VV+: V \times V \to V, written u+v\mathbf{u} + \mathbf{v}
  • Scalar multiplication: :F×VV\cdot: \mathbb{F} \times V \to V, written αv\alpha \mathbf{v}

such that for all u,v,wV\mathbf{u}, \mathbf{v}, \mathbf{w} \in V and α,βF\alpha, \beta \in \mathbb{F}, the following axioms hold.

Additive structure:

(A1) Closure:u+vV(A2) Commutativity:u+v=v+u(A3) Associativity:(u+v)+w=u+(v+w)(A4) Zero vector:0V such that v+0=v    v(A5) Additive inverse:vV,  (v)V with v+(v)=0(1)\begin{aligned} \text{(A1) Closure:} \quad & \mathbf{u} + \mathbf{v} \in V \\ \text{(A2) Commutativity:} \quad & \mathbf{u} + \mathbf{v} = \mathbf{v} + \mathbf{u} \\ \text{(A3) Associativity:} \quad & (\mathbf{u} + \mathbf{v}) + \mathbf{w} = \mathbf{u} + (\mathbf{v} + \mathbf{w}) \\ \text{(A4) Zero vector:} \quad & \exists\, \mathbf{0} \in V \text{ such that } \mathbf{v} + \mathbf{0} = \mathbf{v} \;\; \forall \mathbf{v} \\ \text{(A5) Additive inverse:} \quad & \forall \mathbf{v} \in V,\; \exists\, (-\mathbf{v}) \in V \text{ with } \mathbf{v} + (-\mathbf{v}) = \mathbf{0} \end{aligned} \tag{1}

Scalar multiplication structure:

(M1) Closure:αvV(M2) Distributivity (vectors):α(u+v)=αu+αv(M3) Distributivity (scalars):(α+β)v=αv+βv(M4) Associativity:α(βv)=(αβ)v(M5) Unit:1v=v(2)\begin{aligned} \text{(M1) Closure:} \quad & \alpha \mathbf{v} \in V \\ \text{(M2) Distributivity (vectors):} \quad & \alpha(\mathbf{u}+\mathbf{v}) = \alpha\mathbf{u} + \alpha\mathbf{v} \\ \text{(M3) Distributivity (scalars):} \quad & (\alpha+\beta)\mathbf{v} = \alpha\mathbf{v} + \beta\mathbf{v} \\ \text{(M4) Associativity:} \quad & \alpha(\beta\mathbf{v}) = (\alpha\beta)\mathbf{v} \\ \text{(M5) Unit:} \quad & 1 \cdot \mathbf{v} = \mathbf{v} \end{aligned} \tag{2}

Definition 3 (Vector). An element vV\mathbf{v} \in V is called a vector. When V=RnV = \mathbb{R}^n, we write v=(v1,,vn)T\mathbf{v} = (v_1, \ldots, v_n)^T and call viv_i the components of v\mathbf{v}.

Example 1 (Rn\mathbb{R}^n). The set Rn={(x1,,xn):xiR}\mathbb{R}^n = \{(x_1, \ldots, x_n) : x_i \in \mathbb{R}\} with component-wise addition and scalar multiplication is a vector space. Every feature vector in supervised learning lives in Rd\mathbb{R}^d for some feature dimension dd.

Vector Addition & Scalar Multiplication

-6-6-4-4-2-2224466v₁ (3, 1)v₂ (1, 3)v₁+v₂ = (4, 4)1.5·v₁
v₁v₂v₁ + v₂α·v₁
α (scalar)
1.5
Drag the colored dots to move vectors. The parallelogram rule shows v₁ + v₂ as the diagonal. Negative α reverses direction.

Example 2 (Matrix space). The set Rm×n\mathbb{R}^{m \times n} of m×nm \times n real matrices, with matrix addition and scalar multiplication, is a vector space. A neural network's weight matrices collectively span a subspace of a much larger matrix space.

Example 3 (Function space). The set C([0,1],R)C([0,1], \mathbb{R}) of continuous real-valued functions on [0,1][0,1], with pointwise addition and scalar multiplication, is an infinite-dimensional vector space. Reproducing kernel Hilbert spaces used in kernel methods are subspaces of such function spaces.

Proposition 1. In any vector space VV, the zero vector 0\mathbf{0} is unique, and for each vV\mathbf{v} \in V, the additive inverse v-\mathbf{v} is unique.

Proof. Suppose 0\mathbf{0} and 0\mathbf{0}' are both additive identities. Then 0=0+0=0\mathbf{0} = \mathbf{0} + \mathbf{0}' = \mathbf{0}'. For inverses, if v+w1=0\mathbf{v} + \mathbf{w}_1 = \mathbf{0} and v+w2=0\mathbf{v} + \mathbf{w}_2 = \mathbf{0}, then w1=w1+0=w1+(v+w2)=(w1+v)+w2=0+w2=w2\mathbf{w}_1 = \mathbf{w}_1 + \mathbf{0} = \mathbf{w}_1 + (\mathbf{v} + \mathbf{w}_2) = (\mathbf{w}_1 + \mathbf{v}) + \mathbf{w}_2 = \mathbf{0} + \mathbf{w}_2 = \mathbf{w}_2. \blacksquare


Subspaces and the Zero Vector

Definition 4 (Subspace). A subset WVW \subseteq V is a subspace of VV if WW is itself a vector space under the same operations — equivalently, if:

  1. 0W\mathbf{0} \in W
  2. u,vW    u+vW\mathbf{u}, \mathbf{v} \in W \implies \mathbf{u} + \mathbf{v} \in W (closed under addition)
  3. uW,αF    αuW\mathbf{u} \in W, \alpha \in \mathbb{F} \implies \alpha \mathbf{u} \in W (closed under scalar multiplication)

Proposition 2. A nonempty subset WVW \subseteq V is a subspace if and only if it is closed under linear combinations: u,vW,α,βF    αu+βvW\mathbf{u}, \mathbf{v} \in W, \alpha, \beta \in \mathbb{F} \implies \alpha\mathbf{u} + \beta\mathbf{v} \in W.

This characterization is the workhorse for proving that various constructions (span, null space, column space) yield subspaces.


Linear Combinations

Definition 5 (Linear Combination). Given vectors v1,,vkV\mathbf{v}_1, \ldots, \mathbf{v}_k \in V and scalars α1,,αkF\alpha_1, \ldots, \alpha_k \in \mathbb{F}, the vector

w=i=1kαivi=α1v1+α2v2++αkvk(3)\mathbf{w} = \sum_{i=1}^{k} \alpha_i \mathbf{v}_i = \alpha_1 \mathbf{v}_1 + \alpha_2 \mathbf{v}_2 + \cdots + \alpha_k \mathbf{v}_k \tag{3}

is called a linear combination of v1,,vk\mathbf{v}_1, \ldots, \mathbf{v}_k.

Important equation. Equation (3) is the fundamental building block of linear models. A prediction y^=wTx=j=1dwjxj\hat{y} = \mathbf{w}^T \mathbf{x} = \sum_{j=1}^d w_j x_j is a scalar obtained from a linear combination of features followed by an inner product. Each layer of a neural network computes linear combinations of activations before applying a nonlinearity.

Proposition 3. The set of all linear combinations of {v1,,vk}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\} is the smallest subspace of VV containing v1,,vk\mathbf{v}_1, \ldots, \mathbf{v}_k.

We will denote this set by span(v1,,vk)\text{span}(\mathbf{v}_1, \ldots, \mathbf{v}_k) and prove in the next section that it is indeed a subspace.


Span of a Set of Vectors

Definition 6 (Span). The span of S={v1,,vk}VS = \{\mathbf{v}_1, \ldots, \mathbf{v}_k\} \subseteq V is

span(S)={i=1kαivi  |  α1,,αkF}.(4)\text{span}(S) = \left\{ \sum_{i=1}^{k} \alpha_i \mathbf{v}_i \;\middle|\; \alpha_1, \ldots, \alpha_k \in \mathbb{F} \right\}. \tag{4}

If S=S = \emptyset, we define span()={0}\text{span}(\emptyset) = \{\mathbf{0}\}.

Theorem 1. For any set SVS \subseteq V, span(S)\text{span}(S) is a subspace of VV.

Proof. We verify the three subspace conditions.

(i) Contains zero: For S={v1,,vk}S = \{\mathbf{v}_1, \ldots, \mathbf{v}_k\}, set all αi=0\alpha_i = 0. Then i0vi=0span(S)\sum_i 0 \cdot \mathbf{v}_i = \mathbf{0} \in \text{span}(S).

(ii) Closed under addition: Let u=iαivi\mathbf{u} = \sum_i \alpha_i \mathbf{v}_i and w=iβivi\mathbf{w} = \sum_i \beta_i \mathbf{v}_i belong to span(S)\text{span}(S). Then

u+w=i=1k(αi+βi)vispan(S).(5)\mathbf{u} + \mathbf{w} = \sum_{i=1}^{k} (\alpha_i + \beta_i)\, \mathbf{v}_i \in \text{span}(S). \tag{5}

(iii) Closed under scalar multiplication: Let u=iαivispan(S)\mathbf{u} = \sum_i \alpha_i \mathbf{v}_i \in \text{span}(S) and cFc \in \mathbb{F}. Then

cu=i=1k(cαi)vispan(S).(6)c\mathbf{u} = \sum_{i=1}^{k} (c\alpha_i)\, \mathbf{v}_i \in \text{span}(S). \quad \blacksquare \tag{6}

Geometric interpretation in R3\mathbb{R}^3. For nonzero v1\mathbf{v}_1:

  • span(v1)\text{span}(\mathbf{v}_1) is a line through the origin.
  • span(v1,v2)\text{span}(\mathbf{v}_1, \mathbf{v}_2) is a plane through the origin, provided v2span(v1)\mathbf{v}_2 \notin \text{span}(\mathbf{v}_1).
  • span(v1,v2,v3)=R3\text{span}(\mathbf{v}_1, \mathbf{v}_2, \mathbf{v}_3) = \mathbb{R}^3 if the three vectors are not coplanar.

Visual description. Imagine three flashlight beams emanating from the origin. Each beam is span(vi)\text{span}(\mathbf{v}_i). The span of two non-parallel beams fills a flat sheet (a plane). The span of three non-coplanar beams fills all of space. Machine learning representations similarly "fill" a subspace of Rd\mathbb{R}^d; the dimension of that subspace measures how many independent degrees of freedom the representation possesses.

Interactive: Span of Two Vectors

v₁v₂αv₁+βv₂
span = ℝ² (whole plane)

v₁ = (2, 1)

v₂ = (-1, 2)

det = v₁×v₂ = 5.00

Try: Make v₁ and v₂ parallel (same or opposite direction) and see the span collapse from a plane to a line. The dots show reachable points via integer/half-integer combinations.

Linear Independence and Dependence

Definition 7 (Linear Independence). Vectors v1,,vkV\mathbf{v}_1, \ldots, \mathbf{v}_k \in V are linearly independent if the only solution to

α1v1+α2v2++αkvk=0(7)\alpha_1 \mathbf{v}_1 + \alpha_2 \mathbf{v}_2 + \cdots + \alpha_k \mathbf{v}_k = \mathbf{0} \tag{7}

is the trivial solution α1=α2==αk=0\alpha_1 = \alpha_2 = \cdots = \alpha_k = 0.

Definition 8 (Linear Dependence). The set is linearly dependent if there exist scalars α1,,αk\alpha_1, \ldots, \alpha_k, not all zero, satisfying equation (7).

Important equation. Equation (7) is the master test for independence. In machine learning, if columns of a feature matrix satisfy a nontrivial version of (7), the features carry redundant information and the model may be unidentifiable.

Theorem 2. The set {v1,,vk}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\} is linearly dependent if and only if at least one vector is a linear combination of the others.

Proof. (\Rightarrow) Suppose iαivi=0\sum_i \alpha_i \mathbf{v}_i = \mathbf{0} with not all αi=0\alpha_i = 0. Let jj be an index with αj0\alpha_j \neq 0. Then

vj=ijαiαjvi.(8)\mathbf{v}_j = -\sum_{i \neq j} \frac{\alpha_i}{\alpha_j}\, \mathbf{v}_i. \tag{8}

(\Leftarrow) Suppose vj=ijβivi\mathbf{v}_j = \sum_{i \neq j} \beta_i \mathbf{v}_i. Rearranging,

ijβivivj=0,(9)\sum_{i \neq j} \beta_i \mathbf{v}_i - \mathbf{v}_j = \mathbf{0}, \tag{9}

which is a nontrivial linear combination equal to zero (the coefficient of vj\mathbf{v}_j is 10-1 \neq 0). \blacksquare

Theorem 3 (Steinitz Exchange Lemma — Preview). If {v1,,vk}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\} is linearly independent and each vispan(w1,,wm)\mathbf{v}_i \in \text{span}(\mathbf{w}_1, \ldots, \mathbf{w}_m), then kmk \leq m.

This fundamental result implies that any linearly independent set in a space spanned by mm vectors has at most mm elements. We will use it to prove that all bases have the same size.

Interactive: Linear Independence Test

v₁v₂v₃
⚠ Linearly DEPENDENT

v₁ = (2, 1)

v₂ = (1, 3)

v₃ = (3, 4)

Dependence relation:
v₃ = 1.00·v₁ + 1.00·v₂
v₃ can be built from v₁ and v₂ — it adds no new direction.
Explore: Drag v₃ onto the line formed by v₁ and v₂ to see dependence. Make all three point in different directions to make them "appear" independent (but in ℝ² they always become dependent when you have 3 vectors).

Corollary 1. In Rn\mathbb{R}^n, any set of more than nn vectors is linearly dependent.

Proof. Any kk vectors in Rn\mathbb{R}^n belong to span(e1,,en)\text{span}(\mathbf{e}_1, \ldots, \mathbf{e}_n) where {ei}\{\mathbf{e}_i\} is the standard basis. If k>nk > n, the exchange lemma applied to an independent subset (if one existed with k>nk > n elements) yields a contradiction. \blacksquare


The Exchange Lemma and Basis Uniqueness

We now prove a version of the exchange lemma, which underpins the concept of dimension.

Lemma 1 (Exchange Lemma). Let {v1,,vk}\{\mathbf{v}_1, \ldots, \mathbf{v}_k\} be linearly independent and suppose vkspan(w1,,wm)\mathbf{v}_k \in \text{span}(\mathbf{w}_1, \ldots, \mathbf{w}_m). Then there exists an index j{1,,m}j \in \{1, \ldots, m\} such that {v1,,vk1,wj}\{\mathbf{v}_1, \ldots, \mathbf{v}_{k-1}, \mathbf{w}_j\} is linearly independent.

Proof. Write vk=j=1mβjwj\mathbf{v}_k = \sum_{j=1}^m \beta_j \mathbf{w}_j with not all βj=0\beta_j = 0 (since vk0\mathbf{v}_k \neq \mathbf{0} by independence of the vi\mathbf{v}_i). Choose jj with βj0\beta_j \neq 0. Suppose α1v1++αk1vk1+γwj=0\alpha_1 \mathbf{v}_1 + \cdots + \alpha_{k-1}\mathbf{v}_{k-1} + \gamma \mathbf{w}_j = \mathbf{0}. Substituting for wj\mathbf{w}_j from the expression for vk\mathbf{v}_k yields a linear combination of v1,,vk\mathbf{v}_1, \ldots, \mathbf{v}_k equal to zero. Independence of the vi\mathbf{v}_i forces αi=0\alpha_i = 0 and then γ=0\gamma = 0. \blacksquare

Theorem 4. All bases of a finite-dimensional vector space have the same cardinality.

Proof sketch. Let B1={b1,,bn}\mathcal{B}_1 = \{\mathbf{b}_1, \ldots, \mathbf{b}_n\} and B2={c1,,cm}\mathcal{B}_2 = \{\mathbf{c}_1, \ldots, \mathbf{c}_m\} be two bases. Since B1\mathcal{B}_1 is independent and spans the space, and each bi\mathbf{b}_i is in span(B2)\text{span}(\mathcal{B}_2), the exchange lemma gives nmn \leq m. Reversing roles gives mnm \leq n. Hence n=mn = m. \blacksquare


Basis and Dimension

Definition 9 (Basis). A basis for a vector space VV is a set BV\mathcal{B} \subseteq V that is:

  1. Linearly independent, and
  2. Spanning: span(B)=V\text{span}(\mathcal{B}) = V.

Definition 10 (Dimension). If VV has a finite basis, the dimension of VV, written dim(V)\dim(V), is the number of vectors in any basis. If no finite basis exists, VV is infinite-dimensional.

Theorem 5 (Unique Representation). If B={b1,,bn}\mathcal{B} = \{\mathbf{b}_1, \ldots, \mathbf{b}_n\} is a basis for VV, then every vV\mathbf{v} \in V has a unique representation

v=i=1ncibi.(10)\mathbf{v} = \sum_{i=1}^{n} c_i \mathbf{b}_i. \tag{10}

Proof. Existence follows from spanning. For uniqueness, suppose v=icibi=idibi\mathbf{v} = \sum_i c_i \mathbf{b}_i = \sum_i d_i \mathbf{b}_i. Then i(cidi)bi=0\sum_i (c_i - d_i)\mathbf{b}_i = \mathbf{0}, and independence gives ci=dic_i = d_i for all ii. \blacksquare

The scalars (c1,,cn)(c_1, \ldots, c_n) are the coordinates of v\mathbf{v} with respect to B\mathcal{B}.

Standard basis. The standard basis of Rn\mathbb{R}^n is {e1,,en}\{\mathbf{e}_1, \ldots, \mathbf{e}_n\} where ei\mathbf{e}_i has a 1 in position ii and zeros elsewhere. Every xRn\mathbf{x} \in \mathbb{R}^n has coordinates (x1,,xn)(x_1, \ldots, x_n) in this basis.

Learned bases in machine learning. Methods such as PCA, the SVD, and autoencoders learn alternative bases (or overcomplete frames) adapted to data structure. See Eigenvalues & Eigenvectors for the spectral construction of principal components.


Inner Products, Norms, and Similarity

For geometric reasoning in Rn\mathbb{R}^n, we equip the vector space with an inner product.

Definition 11 (Inner Product). An inner product on Rn\mathbb{R}^n is a function ,:Rn×RnR\langle \cdot, \cdot \rangle : \mathbb{R}^n \times \mathbb{R}^n \to \mathbb{R} satisfying, for all u,v,wRn\mathbf{u}, \mathbf{v}, \mathbf{w} \in \mathbb{R}^n and αR\alpha \in \mathbb{R}:

  1. Symmetry: u,v=v,u\langle \mathbf{u}, \mathbf{v} \rangle = \langle \mathbf{v}, \mathbf{u} \rangle
  2. Linearity in the first argument: αu+v,w=αu,w+v,w\langle \alpha \mathbf{u} + \mathbf{v}, \mathbf{w} \rangle = \alpha \langle \mathbf{u}, \mathbf{w} \rangle + \langle \mathbf{v}, \mathbf{w} \rangle
  3. Positive definiteness: v,v0\langle \mathbf{v}, \mathbf{v} \rangle \geq 0, with equality iff v=0\mathbf{v} = \mathbf{0}

The Euclidean inner product (dot product) is u,v=uTv=i=1nuivi\langle \mathbf{u}, \mathbf{v} \rangle = \mathbf{u}^T \mathbf{v} = \sum_{i=1}^n u_i v_i.

Definition 12 (Norm). The norm induced by an inner product is

v=v,v.(11)\|\mathbf{v}\| = \sqrt{\langle \mathbf{v}, \mathbf{v} \rangle}. \tag{11}

Theorem 6 (Cauchy–Schwarz Inequality). For all u,vRn\mathbf{u}, \mathbf{v} \in \mathbb{R}^n,

u,vuv.(12)|\langle \mathbf{u}, \mathbf{v} \rangle| \leq \|\mathbf{u}\| \, \|\mathbf{v}\|. \tag{12}

Equality holds if and only if u\mathbf{u} and v\mathbf{v} are linearly dependent.

Proof. If v=0\mathbf{v} = \mathbf{0}, the inequality is trivial. Otherwise, for any tRt \in \mathbb{R}, positive definiteness gives

0u+tv,u+tv=u2+2tu,v+t2v2.(13)0 \leq \langle \mathbf{u} + t\mathbf{v}, \mathbf{u} + t\mathbf{v} \rangle = \|\mathbf{u}\|^2 + 2t\langle \mathbf{u}, \mathbf{v} \rangle + t^2 \|\mathbf{v}\|^2. \tag{13}

This quadratic in tt has nonpositive discriminant:

4u,v24u2v20,(14)4\langle \mathbf{u}, \mathbf{v} \rangle^2 - 4\|\mathbf{u}\|^2 \|\mathbf{v}\|^2 \leq 0, \tag{14}

which is precisely (12). Equality occurs when u+tv=0\mathbf{u} + t\mathbf{v} = \mathbf{0} for some tt, i.e., when u\mathbf{u} and v\mathbf{v} are dependent. \blacksquare

Definition 13 (Angle and Cosine Similarity). For nonzero u,vRn\mathbf{u}, \mathbf{v} \in \mathbb{R}^n, the cosine similarity is

sim(u,v)=u,vuv=cosθ,(15)\text{sim}(\mathbf{u}, \mathbf{v}) = \frac{\langle \mathbf{u}, \mathbf{v} \rangle}{\|\mathbf{u}\| \, \|\mathbf{v}\|} = \cos \theta, \tag{15}

where θ[0,π]\theta \in [0, \pi] is the angle between u\mathbf{u} and v\mathbf{v}. By (12), sim(u,v)[1,1]\text{sim}(\mathbf{u}, \mathbf{v}) \in [-1, 1].

Important equation. Equation (15) measures similarity by direction alone, ignoring magnitude. Two embedding vectors pointing in nearly the same direction are semantically similar even if one has larger norm (e.g., due to frequency effects in language models).

Interactive: Cosine Similarity & Angle

uv
Cosine Similarity0.600
-1 (opposite)0 (orthogonal)+1 (identical)

Angle θ

53.1°

Dot product

6.00

‖u‖

3.16

‖v‖

3.16

Key insight: Cosine similarity measures direction alignment, ignoring magnitude. The dashed line shows the projection of u onto v. In attention mechanisms, this measures how well a query aligns with each key.

Proposition 4 (Parallelogram Law). For all u,vRn\mathbf{u}, \mathbf{v} \in \mathbb{R}^n,

u+v2+uv2=2(u2+v2).(16)\|\mathbf{u} + \mathbf{v}\|^2 + \|\mathbf{u} - \mathbf{v}\|^2 = 2(\|\mathbf{u}\|^2 + \|\mathbf{v}\|^2). \tag{16}

This identity reflects the geometry of vector addition and is useful in analyzing distances in embedding spaces.


Cosine Similarity and the Geometry of Attention

Self-attention, developed in the Transformer architecture (Vaswani et al., 2017), computes similarity-weighted linear combinations of value vectors. The query–key dot product is cosine similarity when vectors are normalized.

Setup. Given query, key, and value vectors q,k,vRd\mathbf{q}, \mathbf{k}, \mathbf{v} \in \mathbb{R}^d for a single attention head, the scaled dot-product attention score is

s=q,kd.(17)s = \frac{\langle \mathbf{q}, \mathbf{k} \rangle}{\sqrt{d}}. \tag{17}

For unit-norm queries and keys (q=k=1\|\mathbf{q}\| = \|\mathbf{k}\| = 1), s=cosθ/ds = \cos\theta / \sqrt{d} where θ\theta is the angle between q\mathbf{q} and k\mathbf{k}.

Attention weights. For a sequence of TT tokens with queries qi\mathbf{q}_i, keys kj\mathbf{k}_j, and values vj\mathbf{v}_j, the attention output for token ii is

Attention(qi)=j=1Tαijvj,αij=exp(sij)k=1Texp(sik),sij=qi,kjd.(18)\text{Attention}(\mathbf{q}_i) = \sum_{j=1}^{T} \alpha_{ij}\, \mathbf{v}_j, \qquad \alpha_{ij} = \frac{\exp(s_{ij})}{\sum_{k=1}^{T} \exp(s_{ik})}, \quad s_{ij} = \frac{\langle \mathbf{q}_i, \mathbf{k}_j \rangle}{\sqrt{d}}. \tag{18}

Interpretation. Equation (18) is a linear combination (Definition 5) of value vectors, where the coefficients αij\alpha_{ij} are positive and sum to 1 (a convex combination). The weights depend on the similarity between query qi\mathbf{q}_i and key kj\mathbf{k}_j via equation (17). Thus attention selects which value directions to combine based on geometric alignment in representation space.

Visual description. Imagine token ii casting a query vector into a shared space. Each other token jj presents a key vector. The dot product measures how well the query "aligns" with each key — like projecting a search direction onto catalog entries. Softmax converts these alignment scores into a probability distribution over tokens. The output is then a weighted blend of value vectors, pulling information from tokens whose keys match the query.

The scaling factor d\sqrt{d} prevents dot products from growing with dimension, which would drive softmax into extreme (nearly one-hot) distributions. We develop the full Transformer theory in Volume III, Part IV.


The Matrix Formulation of Independence

Given v1,,vkRn\mathbf{v}_1, \ldots, \mathbf{v}_k \in \mathbb{R}^n, form the matrix

V=[v1v2vk]Rn×k.(19)\mathbf{V} = [\mathbf{v}_1 \mid \mathbf{v}_2 \mid \cdots \mid \mathbf{v}_k] \in \mathbb{R}^{n \times k}. \tag{19}

Then iαivi=Vα\sum_i \alpha_i \mathbf{v}_i = \mathbf{V}\boldsymbol{\alpha} where α=(α1,,αk)T\boldsymbol{\alpha} = (\alpha_1, \ldots, \alpha_k)^T. The vectors are linearly independent iff

Vα=0    α=0,(20)\mathbf{V}\boldsymbol{\alpha} = \mathbf{0} \implies \boldsymbol{\alpha} = \mathbf{0}, \tag{20}

i.e., null(V)={0}\text{null}(\mathbf{V}) = \{\mathbf{0}\}.

Proposition 5. For VRn×k\mathbf{V} \in \mathbb{R}^{n \times k} with knk \leq n, the following are equivalent:

  1. Columns of V\mathbf{V} are linearly independent.
  2. rank(V)=k\text{rank}(\mathbf{V}) = k.
  3. VTVRk×k\mathbf{V}^T \mathbf{V} \in \mathbb{R}^{k \times k} is invertible.

Proof. (1     \iff 2) is the definition of rank as column rank. (2     \iff 3): VTV\mathbf{V}^T \mathbf{V} is k×kk \times k and rank(VTV)=rank(V)\text{rank}(\mathbf{V}^T \mathbf{V}) = \text{rank}(\mathbf{V}). A square matrix is invertible iff its rank equals its size. \blacksquare

The Gram matrix VTV\mathbf{V}^T \mathbf{V} appears in normal equations, kernel methods, and the analysis of feature redundancy. When it is singular, the columns of V\mathbf{V} are dependent.


Worked Examples

Example 4: Testing Independence in R3\mathbb{R}^3

Determine whether the following vectors are linearly independent:

v1=[123],v2=[456],v3=[789].(21)\mathbf{v}_1 = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}, \quad \mathbf{v}_2 = \begin{bmatrix} 4 \\ 5 \\ 6 \end{bmatrix}, \quad \mathbf{v}_3 = \begin{bmatrix} 7 \\ 8 \\ 9 \end{bmatrix}. \tag{21}

Solution. We solve Vα=0\mathbf{V}\boldsymbol{\alpha} = \mathbf{0} with V=[v1v2v3]\mathbf{V} = [\mathbf{v}_1 | \mathbf{v}_2 | \mathbf{v}_3]:

[147258369][α1α2α3]=[000].(22)\begin{bmatrix} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \end{bmatrix} \begin{bmatrix} \alpha_1 \\ \alpha_2 \\ \alpha_3 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix}. \tag{22}

Row reduction yields rank 2, so there is a free variable. One nontrivial solution is α=(1,2,1)T\boldsymbol{\alpha} = (1, -2, 1)^T, giving v12v2+v3=0\mathbf{v}_1 - 2\mathbf{v}_2 + \mathbf{v}_3 = \mathbf{0}. The vectors are linearly dependent and span a 2-dimensional plane in R3\mathbb{R}^3.

Observation. v3v2=v2v1\mathbf{v}_3 - \mathbf{v}_2 = \mathbf{v}_2 - \mathbf{v}_1, so the three vectors lie on a single line of arithmetic progressions — a classic rank-deficient configuration.

Example 5: Cosine Similarity

Let u=(1,0,0)T\mathbf{u} = (1, 0, 0)^T and v=(1,1,0)T\mathbf{v} = (1, 1, 0)^T. Then

u,v=1,u=1,v=2,sim(u,v)=120.707.(23)\langle \mathbf{u}, \mathbf{v} \rangle = 1, \quad \|\mathbf{u}\| = 1, \quad \|\mathbf{v}\| = \sqrt{2}, \quad \text{sim}(\mathbf{u}, \mathbf{v}) = \frac{1}{\sqrt{2}} \approx 0.707. \tag{23}

The angle is θ=45°\theta = 45°. Normalizing both vectors before computing dot products would yield the same similarity score — the reason many embedding pipelines use 2\ell_2-normalized vectors for retrieval.


Connection to Machine Learning

Feature Redundancy and Identifiability

If the columns of a feature matrix XRn×d\mathbf{X} \in \mathbb{R}^{n \times d} are linearly dependent, then XTX\mathbf{X}^T \mathbf{X} is singular and the normal equations for linear regression lack a unique solution. Multiple parameter vectors w\mathbf{w} produce identical predictions Xw\mathbf{X}\mathbf{w}. Regularization (Ridge regression adds λI\lambda \mathbf{I} to XTX\mathbf{X}^T \mathbf{X}) restores invertibility by perturbing the Gram matrix — a theme developed in Positive Definite Matrices.

Embedding Dimension and Rank

Word embeddings map a vocabulary of size V|V| into Rd\mathbb{R}^d. The embedding matrix ERV×d\mathbf{E} \in \mathbb{R}^{|V| \times d} has rank at most dd, so all word vectors lie in a dd-dimensional subspace of RV\mathbb{R}^{|V|} (when viewed as rows) or Rd\mathbb{R}^d (as columns). Training learns a basis for semantic directions within this subspace.

Attention Head Subspaces

Multi-head attention with hh heads and model dimension dd partitions representations into hh subspaces of dimension dk=d/hd_k = d/h. Each head computes attention within its subspace; concatenating heads spans at most dd dimensions. The linear-algebraic structure of these subspaces governs representational capacity — see Self-Attention in Volume III.


Common Pitfalls and Misconceptions

Pitfall 1: Confusing linear independence with orthogonality. Independent vectors need not be perpendicular. Orthogonality is a stronger geometric condition requiring u,v=0\langle \mathbf{u}, \mathbf{v} \rangle = 0. Independent vectors can have arbitrary angles.

Pitfall 2: Treating "linearly dependent" as "one vector is a scalar multiple of another." Dependence allows any linear combination, not just scaling. For example, (1,0,0)(1,0,0), (0,1,0)(0,1,0), and (1,1,0)(1,1,0) are dependent because (1,1,0)=(1,0,0)+(0,1,0)(1,1,0) = (1,0,0) + (0,1,0), yet no vector is a scalar multiple of another.

Pitfall 3: Assuming dim(span(S))=S\dim(\text{span}(S)) = |S|. The dimension of the span equals the size of a maximal independent subset, not the size of SS itself. Duplicate or redundant vectors do not increase dimension.

Pitfall 4: Ignoring the origin in geometric intuition. Spans and subspaces always contain 0\mathbf{0}. An "offset" subspace such as {b+span(S)}\{\mathbf{b} + \text{span}(S)\} is an affine set, not a subspace, unless b=0\mathbf{b} = \mathbf{0}. Neural network biases introduce exactly such affine shifts.

Pitfall 5: Conflating cosine similarity with Euclidean distance. Two vectors can have high cosine similarity (same direction) but large Euclidean distance (different magnitudes). Retrieval systems must choose the metric appropriate to the task.


Research Perspective

The abstraction of vector spaces dates to Peano (1888) and the modern axiomatic treatment to Banach and Hilbert in functional analysis. The shift from coordinate-based calculations to coordinate-free linear algebra — emphasizing span, independence, and dimension — was essential for twentieth-century physics and statistics.

In machine learning, the vector space viewpoint became central with the development of kernel methods (Schölkopf & Smola, 2002), which embed data implicitly in high-dimensional (often infinite-dimensional) feature spaces. Word2Vec (Mikolov et al., 2013) demonstrated that semantic structure emerges as linear geometry in learned embedding spaces — analogies as vector arithmetic. Transformers (Vaswani et al., 2017) extended this to contextual representations, where attention computes dynamic linear combinations based on query–key similarity.

Modern research continues to probe the effective dimension of learned representations: although models operate in Rd\mathbb{R}^d with dd in the thousands, intrinsic dimension estimates often suggest that data manifolds occupy far lower-dimensional subspaces. Understanding span, rank, and independence remains essential for interpreting compression, pruning, and low-rank adaptation methods.


Summary of Takeaways

  • Vector space — Set with addition and scalar multiplication satisfying axioms (1)–(2) — Feature spaces, parameter spaces
  • Linear combinationiαivi\sum_i \alpha_i \mathbf{v}_i — Predictions, layer outputs, attention
  • Span — All linear combinations of a set — Representable functions / outputs
  • Independence — Only trivial solution to αivi=0\sum \alpha_i \mathbf{v}_i = \mathbf{0} — Non-redundant features
  • Basis — Independent + spanning — Minimal complete representation
  • Dimension — Size of any basis — Embedding dim, rank, capacity
  • Inner product — Symmetric bilinear form with positive definiteness — Dot products, kernels
  • Cosine similarityu,v/( —u — —v —)\langle \mathbf{u}, \mathbf{v} \rangle / (\ — \mathbf{u}\ — \ — \mathbf{v}\ — ) — Attention scores, retrieval

Next article: Matrix Operations & Linear Transformations → — where matrices are defined as linear maps between vector spaces, and composition becomes matrix multiplication.


Exercises

Exercise 1 (Verification). Prove that Rm×n\mathbb{R}^{m \times n} with matrix addition and scalar multiplication satisfies all vector space axioms (1)–(2).

Exercise 2 (Subspace test). Let W={(x,y)Rn×Rn:x=y}W = \{(\mathbf{x}, \mathbf{y}) \in \mathbb{R}^n \times \mathbb{R}^n : \mathbf{x} = \mathbf{y}\} embedded in R2n\mathbb{R}^{2n} via concatenation. Prove that WW is a subspace and find a basis. What is dim(W)\dim(W)?

Exercise 3 (Independence). Show that {(1,0,0),(1,1,0),(1,1,1)}\{(1,0,0), (1,1,0), (1,1,1)\} is a basis for R3\mathbb{R}^3 by verifying independence and that dim(span)=3\dim(\text{span}) = 3.

Exercise 4 (Cauchy–Schwarz application). For nonzero u,vRn\mathbf{u}, \mathbf{v} \in \mathbb{R}^n, prove the triangle inequality u+vu+v\|\mathbf{u} + \mathbf{v}\| \leq \|\mathbf{u}\| + \|\mathbf{v}\| using the Cauchy–Schwarz inequality.

Exercise 5 (Attention algebra). Let q,k1,k2,v1,v2Rd\mathbf{q}, \mathbf{k}_1, \mathbf{k}_2, \mathbf{v}_1, \mathbf{v}_2 \in \mathbb{R}^d with q=kj=1\|\mathbf{q}\| = \|\mathbf{k}_j\| = 1. Suppose q,k1=1\langle \mathbf{q}, \mathbf{k}_1 \rangle = 1 and q,k2=0\langle \mathbf{q}, \mathbf{k}_2 \rangle = 0. Compute the attention output (18) when T=2T = 2 and softmax is applied over j{1,2}j \in \{1, 2\}. Show that the output reduces to v1\mathbf{v}_1 in the limit of large scaling (before softmax saturation, analyze the weights explicitly for finite scaling).

Exercise 6 (Conceptual). Explain why adding a bias term b\mathbf{b} to a linear map xWx\mathbf{x} \mapsto \mathbf{W}\mathbf{x} breaks the subspace structure, and describe how augmenting x\mathbf{x} with a constant coordinate restores linearity. (Preview of affine transformations in the next article.)

Exercise 7 (Proof). Complete the proof of Theorem 4 (all bases have the same size) using the exchange lemma iteratively.