Vector spaces
向量空间
Why do some numerical sets allow arbitrary linear combinations while others do not? Understand closure through balance constraints and probabilities.
vector-spacesDoes adding valid data produce valid data?
Two three-dimensional vectors fit the same array type but may belong to sets permitting different operations. If coordinates represent net balances required to sum to zero, adding two balanced accounts preserves the constraint. If they represent three class probabilities, each distribution sums to 1, but adding two distributions gives total mass 2.
This is a question of closure, not array shape. A vector space permits addition and arbitrary scalar scaling without leaving the space. Probability distributions can be represented by real vectors, but the set of valid distributions is not a vector space under ordinary addition.
Specifying the permitted operations helps determine whether dimension reduction, superposition, or optimization violates a model’s constraints. Bounded image pixels likewise do not make the set of valid images closed under every real scaling.
A set, a scalar field, and operations
We use real vector spaces: nonempty sets equipped with vector addition and multiplication by real scalars. Addition is commutative and associative, with a zero vector and an additive inverse for every vector. Scalar multiplication obeys compatibility and distributive rules:
Operations must return elements of . Saying that contains arrays does not fully define the space; the scalar field and operations also matter. Matrices, polynomials with a fixed upper degree bound, and suitable sets of functions can form vector spaces under their respective addition and scaling operations. MML, Section 2.4
For a subset of an existing vector space using the inherited operations, the subspace test is simpler: is nonempty and closed under arbitrary linear combinations. For the following set, the closure argument fits in one line:
The zero vector belongs to , so it is a subspace. It is not the entire three-dimensional ambient space: one constraint restricts the coordinates to a plane through the origin. Formal dimension calculations come in the article on bases and rank.
The span of vectors is the set of all their linear combinations:
Adding two combinations or multiplying one by a scalar produces another combination of the same generators, so a span is always a subspace. It can be smaller than the ambient space, and its generating vectors can be redundant. Deep Learning, Section 2.4
Use code for counterexamples and algebra for proofs
This complete example contrasts zero-sum and probability constraints. Integers and exact fractions keep floating-point tolerances separate from the definitions.
from fractions import Fraction as F
def combine(a, x, b, y):
if len(x) != len(y):
raise ValueError("dimension mismatch")
return tuple(a * u + b * v for u, v in zip(x, y))
def zero_sum(x):
return sum(x) == 0
def probability_vector(x):
return all(v >= 0 for v in x) and sum(x) == 1
u, v = (1, -1, 0), (0, 2, -2)
assert zero_sum(u) and zero_sum(v)
assert combine(2, u, -3, v) == (2, -8, 6)
assert zero_sum(combine(2, u, -3, v))
p, q = (1, 0, 0), (0, 1, 0)
assert probability_vector(p) and probability_vector(q)
assert not probability_vector(combine(1, p, 1, q))
assert probability_vector(combine(F(1, 2), p, F(1, 2), q))
A combination or constraint check requires coordinate operations, with output allocation for a combination. Exact-fraction bit costs additionally depend on numerator and denominator lengths. A test can find a counterexample to closure; passing finitely many inputs cannot prove a claim about every vector and coefficient.
Subspaces, affine sets, and convex sets
Changing the constraint to gives a plane missing the zero vector, so it is not a linear subspace. It is a translated subspace, an affine set. Adding nonnegativity gives the probability simplex, which is closed under combinations with nonnegative coefficients summing to 1 and is convex.
These three kinds of sets should not be conflated. Averaging probability vectors preserves a valid distribution, while subtracting one distribution or multiplying it by 3 generally does not. Projections and constraints in optimization address this distinction.
Exact constraints also differ from noisy observations. Three measured values summing almost to zero do not establish an exact zero-sum law. An approximate subspace model should report deviations, noise scales, and fitting error.
What can one counterexample establish?
- Do all nonnegative two-dimensional vectors form a real vector space? Answer: no. Multiplying by -1 leaves the set.
- Do real polynomials of degree at most 2 form a space under ordinary operations? Answer: yes, including the zero polynomial. Polynomials of exactly degree 2 are not closed because leading terms can cancel.
- Is the intersection of two subspaces a subspace? Answer: yes. Both contain zero, and a linear combination remains in both.
- Is their union necessarily a subspace? Answer: no. The union of the horizontal and vertical axes does not contain .
Allowed combinations become modeling assumptions
Principal component analysis seeks a low-dimensional subspace, and linear regression restricts predictions to a design matrix’s column space. Constrained optimization handles the probability simplex, nonnegative sets, and other regions that do not permit arbitrary linear combinations. Establish the set in which a model operates before discussing distance, direction, and optimality. Convenient array operations do not determine a problem’s mathematical structure.
Make a prediction, then check
Do nonnegative probability vectors summing to one form a vector space under usual addition and scaling?
Learning objectives
- Check a subspace using the zero vector and closure under addition and scaling.
- Distinguish vector spaces, spans, and probability sets with nonnegativity constraints.
Prerequisites & connections
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Deep Learning — Chapter 2: Linear Algebra
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Checked real-space axioms and nonempty linear-combination closure; recalculated zero-sum combinations and probability counterexamples.
- Checked inclusion of the zero polynomial, subspace intersection, and the union-of-axes counterexample; distinguished affine sets and the probability simplex.
- Compared arguments, numbers, examples, limitations, and exercise answers across languages; structural validation separately compares display formulas, code, sources, and sections. No independent human peer review.
Source locations checked:
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · §2.4, PDF pp. 43–45 (2024-01-15 draft)
- Deep Learning — Chapter 2: Linear Algebra · §2.4: span and linear dependence
Related topics