Introduction to Metric Spaces
What if "distance" didn't mean a ruler? A taxi in Manhattan cannot cut diagonally through a city
block — for it, the distance between two corners is the number of blocks driven, not the
crow-flies length. A chess king measures distance in moves: three squares east and two
north is three moves away, because a diagonal step covers both directions at once. A spell-checker
measures the distance between recieve and receive in
edit operations. And in
uniform convergence
you have already measured the distance between two functions as the biggest gap between
their graphs.
Four rulers, four utterly different notions of "how far" — and yet every argument in
analysis you have
met so far leans on just a handful of properties of the humble
|x - y|. Distil those properties into axioms, and something remarkable
happens: limits, continuity, convergence, completeness — the whole machinery — runs
unchanged in every one of these worlds. Prove a theorem once, from the axioms, and it
holds for numbers, for points of the plane under any of these distances, for spaces of functions,
for words in a dictionary. That abstraction is the metric space, and it is the
gateway from calculus into modern analysis.
A metric on a set X is a function
d : X \times X \to [0, \infty) assigning a distance to each pair of
points, subject to three axioms. For all x, y, z \in X:
\textbf{(M1)} \;\; d(x, y) \ge 0, \quad \text{and} \quad d(x, y) = 0 \iff x = y \qquad (\text{positivity / identity}),
\textbf{(M2)} \;\; d(x, y) = d(y, x) \qquad (\text{symmetry}),
\textbf{(M3)} \;\; d(x, z) \le d(x, y) + d(y, z) \qquad (\text{the triangle inequality}).
The pair (X, d) is a metric space. Notice what the
axioms do not say: nothing about coordinates, angles, straight lines, or even numbers.
X is a bare set — its "points" may be words, sequences, functions,
matrices. If a rule for measuring gaps obeys (M1)–(M3), all of analysis is open for business on it.
Earning each axiom: what breaks without it
Axioms should never be a shopping list to memorise — each one is there because dropping it
destroys something you need.
-
Without identity (M1): try d(x, y) = |x^2 - y^2| on
\mathbb{R}. It is symmetric and even obeys the triangle inequality —
but d(1, -1) = 0 although 1 \ne -1. Two
different points at distance zero means limits stop being unique: a sequence could
"converge" to both 1 and -1 at once.
(Weaken this axiom deliberately and you get a pseudometric — useful, but you pay in
ambiguity.)
-
Without symmetry (M2): think of travel time in a city of one-way streets, or
walking uphill versus downhill. "Time from x to
y" can genuinely differ from the reverse — a legitimate object (a
quasimetric), but now "the ball around x" splits into a ball
of points you can reach and a ball of points that can reach you, and every definition doubles.
-
Without the triangle inequality (M3): try
d(x, y) = (x - y)^2 on \mathbb{R}.
Positive, zero exactly on the diagonal, symmetric — it looks innocent. But
d(0, 2) = 4 while
d(0, 1) + d(1, 2) = 1 + 1 = 2: the detour is shorter than
the direct trip. With that, "close to close is close" fails, and the workhorse estimate of all
analysis — bound d(x, z) by hopping through an intermediate point —
is gone. No triangle inequality, no limit theorems.
One pleasant economy: you never need to check d \ge 0 separately. From
the other axioms,
0 = d(x, x) \le d(x, y) + d(y, x) = 2\,d(x, y) — non-negativity is free.
A metric space is a pair (X, d) with
d : X \times X \to [0, \infty) satisfying, for all
x, y, z:
-
(M1) Positivity / identity: d(x, y) \ge 0, and
d(x, y) = 0 \iff x = y.
- (M2) Symmetry: d(x, y) = d(y, x).
-
(M3) Triangle inequality:
d(x, z) \le d(x, y) + d(y, z).
-
The Euclidean metric on \mathbb{R}^n, the absolute value on
\mathbb{R}, and the sup metric on
C[a, b] are all metrics. (X, d) is
complete when every Cauchy sequence converges within X.
When you meet a candidate "distance", (M1) and (M2) are usually a glance — (M3) is where
the real audit happens, and where most impostors fail. You saw
(x - y)^2 fail above; squaring any honest metric tends to break (M3)
the same way, because squaring rewards one long hop over two short ones.
Two more traps for the intuition:
-
A metric needn't come from a norm, a formula, or any geometry at all. The
discrete metric below, and the edit distance between words, are defined by counting and
case-splitting — no coordinates in sight. "Metric" is a contract about behaviour, not a
promise of a nice formula.
-
Intuitions trained on \mathbb{R} must retrain. In
the discrete metric, a sequence converges iff it is eventually constant: once
d(x_n, x) < 1 is demanded, the only available distance below
1 is 0, so
x_n = x from some point on. "Getting closer and closer" is not a
metaphor about creeping up gradually — it is exactly the statement
d(x_n, x) \to 0, and in some spaces the only way to get close is
to arrive.
A gallery of metrics
-
\mathbb{R} with the absolute value:
d(x, y) = |x - y|. The ordinary number line — the special case all
the others generalise.
-
\mathbb{R}^n with the Euclidean metric:
d_2(x, y) = \sqrt{\sum_{i=1}^{n} (x_i - y_i)^2}. Straight-line ("as
the crow flies") distance.
-
\mathbb{R}^2 with the taxicab metric:
d_1(x, y) = |x_1 - y_1| + |x_2 - y_2|. Blocks east plus blocks north
— no diagonals allowed.
-
\mathbb{R}^2 with the Chebyshev (max) metric:
d_\infty(x, y) = \max\big(|x_1 - y_1|,\, |x_2 - y_2|\big). Exactly
the number of moves a chess king needs, since one move fixes a step in both coordinates.
-
Functions with the sup metric: on the continuous functions on
[a, b],
d_\infty(f, g) = \sup_{x} |f(x) - g(x)|. Two functions are "close"
when their graphs are everywhere close — exactly the
uniform distance,
now recognised as a genuine metric on a space whose points are functions.
-
Any set X with the discrete metric:
d(x, y) = 0 if x = y and
d(x, y) = 1 otherwise. Weird but perfectly legal — see the worked
example below.
Worked example 1: the taxicab metric really is a metric
Claim: d_1(x, y) = |x_1 - y_1| + |x_2 - y_2| satisfies (M1)–(M3) on
\mathbb{R}^2.
(M1). A sum of two absolute values is \ge 0, and it
equals 0 only when both terms vanish — that is, when
x_1 = y_1 and x_2 = y_2, i.e.
x = y. (Note the "and": one matching coordinate is not enough, which is
exactly why the identity axiom quantifies over the whole point.)
(M2). |x_i - y_i| = |y_i - x_i| coordinate by
coordinate, so the sum is symmetric.
(M3). The one-dimensional triangle inequality
|a + b| \le |a| + |b| gives, in each coordinate,
|x_i - z_i| = |(x_i - y_i) + (y_i - z_i)| \le |x_i - y_i| + |y_i - z_i|.
Add the two coordinate inequalities and regroup:
d_1(x, z) = \sum_{i=1}^{2} |x_i - z_i| \;\le\; \sum_{i=1}^{2} |x_i - y_i| + \sum_{i=1}^{2} |y_i - z_i| = d_1(x, y) + d_1(y, z).
Done — the grid-walking distance is a genuine metric, and the same argument works in
\mathbb{R}^n for any n. Notice the strategy,
because it recurs throughout analysis: reduce a many-dimensional triangle inequality to the
one-dimensional one, coordinate by coordinate, then sum.
Worked example 2: the Euclidean metric obeys the triangle inequality
For d_2, positivity and symmetry are again immediate (a square root of
a sum of squares is \ge 0 and vanishes only when every coordinate
matches; swapping x and y changes nothing).
The real work is the triangle inequality — and this time no coordinate-by-coordinate shortcut
exists, because the square root tangles the coordinates together. Write the claim with
displacement vectors u = x - y and v = y - z,
so that x - z = u + v and the claim becomes
\|u + v\| \le \|u\| + \|v\|.
Step 1 — square the target. Both sides are non-negative, so it suffices to compare
their squares. Expand using the dot product:
\|u + v\|^2 = (u + v) \cdot (u + v) = \|u\|^2 + 2\,(u \cdot v) + \|v\|^2.
Step 2 — bound the cross term by Cauchy–Schwarz. The one fact we borrow is the
Cauchy–Schwarz inequality |u \cdot v| \le \|u\|\,\|v\|. In particular
u \cdot v \le \|u\|\,\|v\|, so
\|u + v\|^2 \le \|u\|^2 + 2\,\|u\|\,\|v\| + \|v\|^2.
Step 3 — recognise a perfect square. The right-hand side is
(\|u\| + \|v\|)^2:
\|u + v\|^2 \le \big(\|u\| + \|v\|\big)^2.
Step 4 — take square roots. Both sides are non-negative, and the square root is
increasing, so
\|u + v\| \le \|u\| + \|v\|.
Step 5 — translate back to distances. Substituting
u = x - y and v = y - z gives exactly (M3):
d_2(x, z) = \|x - z\| \le \|x - y\| + \|y - z\| = d_2(x, y) + d_2(y, z).
So Euclidean distance is a genuine metric. Geometrically this is the schoolroom fact that
any side of a triangle is at most the sum of the other two — a detour through
y is never shorter than the straight path.
Worked example 3: the discrete metric — weird but legal
On any set X whatsoever, define
d(x, y) = \begin{cases} 0 & x = y, \\ 1 & x \ne y. \end{cases}
(M1) and (M2) hold by construction. For (M3),
check d(x, z) \le d(x, y) + d(y, z) by cases: if
x = z the left side is 0 and there is
nothing to prove. If x \ne z, the left side is
1 — and y cannot equal both
x and z, so at least one term on the right
is 1. Every case checks out: a metric.
Its geometry is gloriously strange. Every point sits in splendid isolation: the ball
B(x, \tfrac{1}{2}) contains only x itself,
so every singleton — indeed every subset — is an open set. Every function out of
a discrete space is continuous. And, as the "Watch out!" box warned, a sequence converges only by
eventually sitting still. The discrete metric is the standard stress test: whenever you conjecture
"surely every metric space behaves like \mathbb{R}^n…", run it past the
discrete metric first.
The shape of "within radius r": the iconic picture
Here is the picture every analyst carries in their head. Fix a centre and a radius
r, and draw the open ball
B(0, r) = \{\, y : d(0, y) < r \,\} in three different metrics on the
same plane. In the Euclidean metric d_2 it is the familiar round
disc. In the taxicab metric d_1 it is a
diamond — the set |x| + |y| < r, whose corners poke
out along the axes because moving along one axis is "cheap". In the Chebyshev metric
d_\infty it is an axis-aligned square — the set
\max(|x|, |y|) < r, everything a king reaches in fewer than
r moves.
Slide the radius and watch all three grow together. Notice the nesting,
\text{diamond} \subset \text{disc} \subset \text{square}, which encodes
the inequalities d_\infty \le d_2 \le d_1 — the same pair of points is
"closest" in the king's metric and "farthest" in the taxi's. Because each ball fits inside a
scaled copy of the others (e.g. d_1 \le 2\,d_\infty in the plane),
the three metrics declare exactly the same sequences convergent and the same sets open:
they are equivalent metrics. Different geometry, identical analysis.
The vocabulary, generalised — analysis runs verbatim
With a metric in hand, the basic notions of analysis transplant word for word — every
|x - y| becomes d(x, y), and nothing else
changes.
-
Open ball: B(x, r) = \{\, y \in X : d(x, y) < r \,\} — all
points within radius r of x. In
C[a,b] with the sup metric, B(f, \varepsilon)
is a tube of width 2\varepsilon around the graph of
f.
-
Open set: a set U such that every point of
U has some ball B(x, r) \subseteq U around it —
the metric's version of "no boundary points included".
-
Convergence: x_n \to x means
d(x_n, x) \to 0; spelled out, for every
\varepsilon > 0 there is an N with
d(x_n, x) < \varepsilon for all n \ge N —
the tail of the sequence enters every \varepsilon-ball. In
(C[a,b], d_\infty) this is exactly uniform convergence.
-
Continuity: f : (X, d_X) \to (Y, d_Y) is continuous
at a when for every \varepsilon > 0 there
is a \delta > 0 such that
d_X(x, a) < \delta \Rightarrow d_Y\big(f(x), f(a)\big) < \varepsilon.
Compare this with the \varepsilon–\delta
definition on \mathbb{R}: it is the same sentence with the absolute
values renamed — and now it covers maps between any two metric spaces, even with
different metrics on each side.
Cauchy = convergent becomes completeness. Recall that on the
real line a sequence
converges iff it is Cauchy — its terms eventually crowd together. A general
(x_n) is Cauchy when
d(x_m, x_n) \to 0 as m, n \to \infty. Crowding
together does not by itself guarantee a limit inside the space — the rationals are Cauchy
toward \sqrt{2}, which is not rational. A metric space in which every
Cauchy sequence does converge to a point of the space is called complete:
(X, d) \text{ complete} \;\;\iff\;\; \big[\, (x_n) \text{ Cauchy} \Rightarrow x_n \to x \text{ for some } x \in X \,\big].
"\mathbb{R} is complete" is precisely the no-holes property of the reals,
now seen as one instance of a property any metric space may or may not have. The space
(C[a,b], d_\infty) is complete too — that is the uniform-limit theorem
wearing its metric-space clothes — and the discrete metric is trivially complete, since its Cauchy
sequences are eventually constant.
Completeness is not just tidy bookkeeping — it manufactures solutions out of thin air. A map
T : X \to X on a metric space is a contraction if it
shrinks all distances by a fixed factor q < 1:
d\big(T(x), T(y)\big) \le q\,d(x, y), \qquad 0 \le q < 1.
Banach's contraction mapping theorem: on a complete metric space, a
contraction has exactly one fixed point x^* = T(x^*), and
the iterates x_{n+1} = T(x_n) converge to it from any starting
point. The proof is pure metric-space reasoning: the iterates form a Cauchy sequence (successive gaps
shrink geometrically like q^n), completeness supplies the limit, and
continuity pins it as the fixed point.
This single theorem is an existence engine. Cast "solve the differential equation
y' = f(x, y)" as a fixed point of an integral operator on the complete
space C[a, b] with the sup metric; the contraction theorem then yields a
unique solution — that is the Picard–Lindelöf existence theorem for ODEs. The same
move proves the inverse function theorem and underlies countless numerical iterations.
Take X to be the set of all finite strings over an alphabet, and let
d(u, w) be the edit distance (Levenshtein distance):
the minimum number of single-letter insertions, deletions and substitutions turning
u into w. So
d(\text{cat}, \text{cart}) = 1 (insert an r) and
d(\text{kitten}, \text{sitting}) = 3. Identity: zero edits means the
words are already equal. Symmetry: every edit is reversible (an insertion undoes a deletion), so
the cheapest path back costs the same. Triangle inequality: editing
u \to v and then v \to w is one
particular way of turning u into w, so
the optimum can only be cheaper. A full-blown metric space whose points are words.
Your spell-checker lives in this space: recieve is at distance
2 (one transposition counted as two edits) from
receive and far from rhinoceros, so the ball of small radius around
the typo contains the likely corrections. Bioinformatics plays the same game with the four-letter
alphabet A, C, G, T — sequence-alignment tools ranking how "close" two DNA strands are run on a
weighted cousin of this metric. When Maurice Fréchet introduced abstract metric spaces in his 1906
doctoral thesis (at 28, essentially inventing the subject to talk about spaces of functions), no
one imagined the axioms would one day organise dictionaries and genomes — that is the payoff of
abstraction: prove it once, use it everywhere, including places not yet invented.