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.
Table of Contents
- Learning Objectives
- Prerequisites
- Notation
- Core Intuition
- Vector Spaces: Definition and Axioms
- Subspaces and the Zero Vector
- Linear Combinations
- Span of a Set of Vectors
- Linear Independence and Dependence
- The Exchange Lemma and Basis Uniqueness
- Basis and Dimension
- Inner Products, Norms, and Similarity
- Cosine Similarity and the Geometry of Attention
- The Matrix Formulation of Independence
- Worked Examples
- Connection to Machine Learning
- Common Pitfalls and Misconceptions
- Research Perspective
- Summary of Takeaways
- Exercises
Learning Objectives
After reading this chapter, you should be able to:
- State and verify the vector space axioms for concrete examples arising in machine learning (, matrix spaces, function spaces).
- Prove that the span of any set of vectors is a subspace, and characterize linear dependence as redundancy among directions.
- Apply the linear independence criterion to determine whether a set of feature vectors or embeddings is redundant.
- Define a basis, prove that coordinates with respect to a basis are unique, and explain why dimension is well-defined.
- Derive the Cauchy–Schwarz inequality and use it to define cosine similarity and the angle between representations.
- 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
- — Field (typically or )
- — Vector spaces; the zero vector
- — Vectors and coefficient vector
- — Set of all linear combinations of
- — Dimension of
- — Inner product; induced norm
- — Matrix of column vectors and Gram matrix
Core Intuition
Machine learning operates almost entirely inside vector spaces. A dataset of examples with features is an matrix whose rows and columns are vectors. A neural network's parameters form a long vector in . 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 is a set equipped with addition and multiplication satisfying the usual axioms. In this curriculum we work primarily with (real numbers) and occasionally (complex numbers).
Definition 2 (Vector Space). A vector space over is a set together with two operations:
- Vector addition: , written
- Scalar multiplication: , written
such that for all and , the following axioms hold.
Additive structure:
Scalar multiplication structure:
Definition 3 (Vector). An element is called a vector. When , we write and call the components of .
Example 1 (). The set with component-wise addition and scalar multiplication is a vector space. Every feature vector in supervised learning lives in for some feature dimension .
Vector Addition & Scalar Multiplication
Example 2 (Matrix space). The set of 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 of continuous real-valued functions on , 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 , the zero vector is unique, and for each , the additive inverse is unique.
Proof. Suppose and are both additive identities. Then . For inverses, if and , then .
Subspaces and the Zero Vector
Definition 4 (Subspace). A subset is a subspace of if is itself a vector space under the same operations — equivalently, if:
- (closed under addition)
- (closed under scalar multiplication)
Proposition 2. A nonempty subset is a subspace if and only if it is closed under linear combinations: .
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 and scalars , the vector
is called a linear combination of .
Important equation. Equation (3) is the fundamental building block of linear models. A prediction 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 is the smallest subspace of containing .
We will denote this set by and prove in the next section that it is indeed a subspace.
Span of a Set of Vectors
Definition 6 (Span). The span of is
If , we define .
Theorem 1. For any set , is a subspace of .
Proof. We verify the three subspace conditions.
(i) Contains zero: For , set all . Then .
(ii) Closed under addition: Let and belong to . Then
(iii) Closed under scalar multiplication: Let and . Then
Geometric interpretation in . For nonzero :
- is a line through the origin.
- is a plane through the origin, provided .
- if the three vectors are not coplanar.
Visual description. Imagine three flashlight beams emanating from the origin. Each beam is . 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 ; the dimension of that subspace measures how many independent degrees of freedom the representation possesses.
Interactive: Span of Two Vectors
v₁ = (2, 1)
v₂ = (-1, 2)
det = v₁×v₂ = 5.00
Linear Independence and Dependence
Definition 7 (Linear Independence). Vectors are linearly independent if the only solution to
is the trivial solution .
Definition 8 (Linear Dependence). The set is linearly dependent if there exist scalars , 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 is linearly dependent if and only if at least one vector is a linear combination of the others.
Proof. () Suppose with not all . Let be an index with . Then
() Suppose . Rearranging,
which is a nontrivial linear combination equal to zero (the coefficient of is ).
Theorem 3 (Steinitz Exchange Lemma — Preview). If is linearly independent and each , then .
This fundamental result implies that any linearly independent set in a space spanned by vectors has at most elements. We will use it to prove that all bases have the same size.
Interactive: Linear Independence Test
v₁ = (2, 1)
v₂ = (1, 3)
v₃ = (3, 4)
v₃ = 1.00·v₁ + 1.00·v₂
v₃ can be built from v₁ and v₂ — it adds no new direction.
Corollary 1. In , any set of more than vectors is linearly dependent.
Proof. Any vectors in belong to where is the standard basis. If , the exchange lemma applied to an independent subset (if one existed with elements) yields a contradiction.
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 be linearly independent and suppose . Then there exists an index such that is linearly independent.
Proof. Write with not all (since by independence of the ). Choose with . Suppose . Substituting for from the expression for yields a linear combination of equal to zero. Independence of the forces and then .
Theorem 4. All bases of a finite-dimensional vector space have the same cardinality.
Proof sketch. Let and be two bases. Since is independent and spans the space, and each is in , the exchange lemma gives . Reversing roles gives . Hence .
Basis and Dimension
Definition 9 (Basis). A basis for a vector space is a set that is:
- Linearly independent, and
- Spanning: .
Definition 10 (Dimension). If has a finite basis, the dimension of , written , is the number of vectors in any basis. If no finite basis exists, is infinite-dimensional.
Theorem 5 (Unique Representation). If is a basis for , then every has a unique representation
Proof. Existence follows from spanning. For uniqueness, suppose . Then , and independence gives for all .
The scalars are the coordinates of with respect to .
Standard basis. The standard basis of is where has a 1 in position and zeros elsewhere. Every has coordinates 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 , we equip the vector space with an inner product.
Definition 11 (Inner Product). An inner product on is a function satisfying, for all and :
- Symmetry:
- Linearity in the first argument:
- Positive definiteness: , with equality iff
The Euclidean inner product (dot product) is .
Definition 12 (Norm). The norm induced by an inner product is
Theorem 6 (Cauchy–Schwarz Inequality). For all ,
Equality holds if and only if and are linearly dependent.
Proof. If , the inequality is trivial. Otherwise, for any , positive definiteness gives
This quadratic in has nonpositive discriminant:
which is precisely (12). Equality occurs when for some , i.e., when and are dependent.
Definition 13 (Angle and Cosine Similarity). For nonzero , the cosine similarity is
where is the angle between and . By (12), .
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
Angle θ
53.1°
Dot product
6.00
‖u‖
3.16
‖v‖
3.16
Proposition 4 (Parallelogram Law). For all ,
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 for a single attention head, the scaled dot-product attention score is
For unit-norm queries and keys (), where is the angle between and .
Attention weights. For a sequence of tokens with queries , keys , and values , the attention output for token is
Interpretation. Equation (18) is a linear combination (Definition 5) of value vectors, where the coefficients are positive and sum to 1 (a convex combination). The weights depend on the similarity between query and key via equation (17). Thus attention selects which value directions to combine based on geometric alignment in representation space.
Visual description. Imagine token casting a query vector into a shared space. Each other token 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 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 , form the matrix
Then where . The vectors are linearly independent iff
i.e., .
Proposition 5. For with , the following are equivalent:
- Columns of are linearly independent.
- .
- is invertible.
Proof. (1 2) is the definition of rank as column rank. (2 3): is and . A square matrix is invertible iff its rank equals its size.
The Gram matrix appears in normal equations, kernel methods, and the analysis of feature redundancy. When it is singular, the columns of are dependent.
Worked Examples
Example 4: Testing Independence in
Determine whether the following vectors are linearly independent:
Solution. We solve with :
Row reduction yields rank 2, so there is a free variable. One nontrivial solution is , giving . The vectors are linearly dependent and span a 2-dimensional plane in .
Observation. , so the three vectors lie on a single line of arithmetic progressions — a classic rank-deficient configuration.
Example 5: Cosine Similarity
Let and . Then
The angle is . Normalizing both vectors before computing dot products would yield the same similarity score — the reason many embedding pipelines use -normalized vectors for retrieval.
Connection to Machine Learning
Feature Redundancy and Identifiability
If the columns of a feature matrix are linearly dependent, then is singular and the normal equations for linear regression lack a unique solution. Multiple parameter vectors produce identical predictions . Regularization (Ridge regression adds to ) 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 into . The embedding matrix has rank at most , so all word vectors lie in a -dimensional subspace of (when viewed as rows) or (as columns). Training learns a basis for semantic directions within this subspace.
Attention Head Subspaces
Multi-head attention with heads and model dimension partitions representations into subspaces of dimension . Each head computes attention within its subspace; concatenating heads spans at most 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 . 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, , , and are dependent because , yet no vector is a scalar multiple of another.
Pitfall 3: Assuming . The dimension of the span equals the size of a maximal independent subset, not the size of itself. Duplicate or redundant vectors do not increase dimension.
Pitfall 4: Ignoring the origin in geometric intuition. Spans and subspaces always contain . An "offset" subspace such as is an affine set, not a subspace, unless . 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 with 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 combination — — Predictions, layer outputs, attention
- Span — All linear combinations of a set — Representable functions / outputs
- Independence — Only trivial solution to — 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 similarity — — 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 with matrix addition and scalar multiplication satisfies all vector space axioms (1)–(2).
Exercise 2 (Subspace test). Let embedded in via concatenation. Prove that is a subspace and find a basis. What is ?
Exercise 3 (Independence). Show that is a basis for by verifying independence and that .
Exercise 4 (Cauchy–Schwarz application). For nonzero , prove the triangle inequality using the Cauchy–Schwarz inequality.
Exercise 5 (Attention algebra). Let with . Suppose and . Compute the attention output (18) when and softmax is applied over . Show that the output reduces to 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 to a linear map breaks the subspace structure, and describe how augmenting 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.