Skip to content

Metric Spaces

In this lesson you’ll see distance reduced to four axioms, meet examples ranging from the familiar to the strange, define open sets from open balls, and discover that different metrics can produce identical topologies.

A metric on a set XX is a function d:X×XRd: X\times X\to\mathbb{R} satisfying, for all x,y,zx,y,z:

  1. Non-negativity. d(x,y)0d(x,y)\ge0
  2. Identity of indiscernibles. d(x,y)=0d(x,y)=0 if and only if x=yx=y
  3. Symmetry. d(x,y)=d(y,x)d(x,y)=d(y,x)
  4. Triangle inequality. d(x,z)d(x,y)+d(y,z)d(x,z)\le d(x,y)+d(y,z)

The pair (X,d)(X,d) is a metric space. That is the entire definition, and it is worth appreciating how little it demands: no coordinates, no algebra, no dimension.

The fourth axiom does almost all the work. The triangle inequality is what makes limits behave and what every convergence proof in analysis eventually appeals to. Without it, “close to xx” and “close to yy” would carry no information about each other.

Note the “only if” in axiom 2. Dropping it gives a pseudometric, where distinct points can be at distance 0. Dropping symmetry gives a quasimetric, which is how one-way street distances are modelled.

Euclidean, on Rn\mathbb{R}^n. d2(x,y)=(xiyi)2d_2(x,y) = \sqrt{\sum(x_i-y_i)^2}. The default.

Taxicab, on Rn\mathbb{R}^n. d1(x,y)=xiyid_1(x,y) = \sum|x_i-y_i|. The distance a car drives on a rectangular street grid, hence the name.

Maximum, on Rn\mathbb{R}^n. d(x,y)=maxixiyid_\infty(x,y) = \max_i|x_i-y_i|. Also called the Chebyshev distance; it is the number of moves a chess king needs.

Discrete. d(x,y)=1d(x,y)=1 for xyx\ne y and 0 otherwise. Valid on any set at all, and it makes every subset open.

Supremum metric on functions. d(f,g)=supxf(x)g(x)d(f,g) = \sup_x|f(x)-g(x)| on the continuous functions on [a,b][a,b]. Convergence in this metric is exactly uniform convergence, which is the link back to real analysis.

Hamming distance. On strings of fixed length, the number of positions where they differ. This is the metric coding theory is built on.

The pp-adic metric. On Q\mathbb{Q}, two numbers are close when their difference is divisible by a high power of pp. It satisfies a stronger inequality, d(x,z)max(d(x,y),d(y,z))d(x,z)\le\max(d(x,y),d(y,z)), and it is the foundation of a large part of modern number theory.

The open ball is B(x,r)={yX:d(x,y)<r}B(x,r) = \{y \in X : d(x,y)<r\}.

A set UXU\subseteq X is open if every point of UU has some ball around it contained in UU.

That second definition is the bridge to the rest of the section. It converts a numerical notion, distance, into a purely set-theoretic one, openness - and openness is all the next lesson will keep.

Open balls need not look round. The shape depends entirely on the metric.

In the figure, the same “unit ball” is a disc, a diamond, and a square for the three standard metrics on R2\mathbb{R}^2. Each boundary is computed by scaling directions until the norm equals 1, so the shapes come out of the formulas rather than being drawn by hand.

Here is the observation that motivates the whole abstraction.

Two metrics on the same set are topologically equivalent if they produce exactly the same open sets.

For Rn\mathbb{R}^n, the metrics d1d_1, d2d_2, and dd_\infty are all equivalent. The reason is that each ball fits inside a scaled copy of the others:

dd2d1ndd_\infty \le d_2 \le d_1 \le n\,d_\infty

The figure measures the relevant constants on R2\mathbb{R}^2: over the Euclidean unit circle, d1d_1 ranges between 1 and 2\sqrt2, and dd_\infty between 12\frac{1}{\sqrt2} and 1. Since each is bounded above and below by a multiple of the other, any ball of one metric contains a ball of the other, so the open sets coincide.

Consequence: every topological statement about R2\mathbb{R}^2 - continuity, convergence, connectedness, compactness - gives the same answer for all three. Proving a theorem once topologically covers all of them.

The discrete metric on R\mathbb{R} is not equivalent to the usual one, since it makes every singleton open. That is a genuinely different topology.

What metrics still give you that topology does not

Section titled “What metrics still give you that topology does not”

Not everything survives the abstraction, and it is worth knowing what is lost:

  • Cauchy sequences and completeness need actual distances.
  • Uniform continuity and Lipschitz conditions are metric notions, not topological ones.
  • Boundedness is metric; the topological substitute is compactness.
  • Diameter and any quantitative estimate.

So metric spaces are not superseded. Analysis needs them, and lesson 11 returns to them for the extra results they support.

Example 1: Verify the discrete metric is a metric.

Solution. Non-negativity and symmetry are clear from the definition. Axiom 2 holds because d(x,y)=0d(x,y)=0 precisely when x=yx=y.

For the triangle inequality, take any x,y,zx,y,z. If x=zx=z then the left side is 0 and there is nothing to prove. If xzx\ne z then the left side is 1, and at least one of yxy\ne x or yzy\ne z must hold, so the right side is at least 1. ✓

In this space B(x,12)={x}B(x,\frac12) = \{x\}, so every singleton is open, hence every subset is open. ∎

Example 2: Show d(x,y)=xy2d(x,y)=|x-y|^2 is not a metric on R\mathbb{R}.

Solution. The triangle inequality fails. Take x=0x=0, y=1y=1, z=2z=2:

d(0,2)=4,d(0,1)+d(1,2)=1+1=2d(0,2) = 4, \qquad d(0,1)+d(1,2) = 1+1 = 2

and 4>24 > 2. ∎

Squaring breaks the triangle inequality, while square-rooting does not: xy\sqrt{|x-y|} is a metric.

Example 3: Describe the unit ball of d1d_1 in R2\mathbb{R}^2.

Solution. The condition x+y<1|x|+|y|<1 describes the open diamond with vertices at (±1,0)(\pm1,0) and (0,±1)(0,\pm1).

It is inscribed in the Euclidean unit disc, touching it only at those four vertices. ∎

Example 4: Show dd22dd_\infty \le d_2 \le \sqrt2\,d_\infty in R2\mathbb{R}^2.

Solution. Write a=Δxa = |\Delta x| and b=Δyb=|\Delta y|, and suppose without loss of generality aba\ge b, so d=ad_\infty = a.

Lower bound: d2=a2+b2a2=a=dd_2 = \sqrt{a^2+b^2}\ge\sqrt{a^2} = a = d_\infty

Upper bound: d2=a2+b2a2+a2=a2=2dd_2 = \sqrt{a^2+b^2}\le\sqrt{a^2+a^2} = a\sqrt2 = \sqrt2\,d_\infty

So each metric is bounded by a constant times the other, which is exactly what makes the balls nest and the topologies agree. ∎

Example 5: Is (0,1)(0,1) open in R\mathbb{R} with the usual metric?

Solution. Yes. Given x(0,1)x\in(0,1), set r=min(x,1x)>0r = \min(x, 1-x) > 0. Then B(x,r)=(xr,x+r)(0,1)B(x,r) = (x-r,x+r)\subseteq(0,1).

Answer: open. ∎

Note [0,1)[0,1) is not open, because no ball around 0 stays inside: every B(0,r)B(0,r) contains negative numbers.

Example 6: Show the closed ball need not be the closure of the open ball.

Solution. Use the discrete metric on a set with at least two points, and take r=1r=1.

B(x,1)={x},Bˉ(x,1)=XB(x,1) = \{x\}, \qquad \bar B(x,1) = X

The open ball is already closed, since every set is, so its closure is {x}\{x\}, not XX. ∎

In Rn\mathbb{R}^n they do agree, which is why this trap is easy to walk into. The general statement is only that the closure of the open ball is contained in the closed ball.

Example 7: Interpret the supremum metric.

What does d(f,g)=supx[0,1]f(x)g(x)<εd(f,g) = \sup_{x\in[0,1]}|f(x)-g(x)| < \varepsilon mean?

Solution. It says the graphs of ff and gg stay within vertical distance ε\varepsilon of each other at every point of [0,1][0,1] - the entire graph of gg lies in an ε\varepsilon-tube around ff.

Convergence in this metric is therefore uniform convergence, exactly the notion from real analysis, and a ball in this metric is the tube. ∎

The tube picture from uniform convergence was a metric ball all along, which is a good example of topology retroactively explaining an earlier definition.

Route planning. Taxicab distance models grid-based city travel, and real navigation uses graph metrics on road networks. The choice of metric changes which route is optimal but not which places are near each other in the topological sense.

Error-correcting codes. Hamming distance turns strings into a metric space, and a code corrects tt errors exactly when its codewords are more than 2t2t apart. Every disk drive and network protocol depends on this.

Machine learning. Nearest-neighbour classification, clustering, and embeddings all require choosing a metric, and the choice determines the results far more than the algorithm does. Cosine, Euclidean and Manhattan distances give different answers on the same data.

Text and DNA comparison. Edit distance is a metric on strings, and it drives spell checkers, plagiarism detection, and sequence alignment in bioinformatics.

Function approximation. The supremum metric measures worst-case error, which is the guarantee engineering needs, while the L2L^2 metric measures average error. Choosing between them is choosing what “close enough” means.

Number theory. The pp-adic metrics give a completely different notion of nearness on Q\mathbb{Q} and are central to modern arithmetic geometry, including the proof of Fermat’s Last Theorem.

Which axiom of a metric does most of the work in analysis?
Why is d(x, y) = |x − y|² not a metric on ℝ?
What shape is the unit ball of the taxicab metric in ℝ²?
What does it mean for two metrics to be topologically equivalent?
In the discrete metric, which subsets are open?
Is the closed ball always the closure of the open ball of the same radius?
What does convergence in the supremum metric d(f, g) = sup|f − g| mean?
Which of these is a metric notion rather than a topological one?