© 2026 NeckPinch · www.neckpinch.com · All rights reserved.
Course 2Book 2B: Spaces, Functions and ChangeChapter 1
Metric Spaces
Distance between points, strings, functions and places on Earth, and the topology it defines.
Read with Tao, Analysis II, chapter "Metric spaces": the definitions and examples, "Some point-set topology of metric spaces" and "Relative topology". The sections on Cauchy sequences and compact metric spaces go with chapters 2B.2 and 2B.3.
In this chapter · 7 sections
Book 2A was about one space, the real line, and one way of measuring distance in it, . Almost everything proved there used only a few properties of that distance: it is never negative, it is zero only between a point and itself, it is symmetric, and it obeys the triangle inequality. This chapter takes those four properties as a definition. Anything that satisfies them is a metric, and a set with a metric is a metric space.
The gain is enormous. Points on the Earth, strings of letters, binary codewords, continuous functions and (much later) whole geometric shapes all carry natural metrics. Once they do, convergence, continuity, open and closed sets, completeness and compactness all make sense for them, with the same definitions and often the same proofs as on . The route to Perelman runs through several such spaces: spaces of functions in Courses 3, 4 and 6, a Riemannian manifold viewed as a metric space in 9A.3 Geodesics and the Exponential Map, and finally a space whose points are themselves metric spaces, in which limits of Ricci flows are taken (9B.4 Convergence of Manifolds).
By the end of this chapter you will be able to:
- check the four axioms of a metric, and recognise the standard metrics on , on spheres, on strings and on function spaces;
- define open and closed balls, open and closed sets, interior, closure and boundary, and prove the basic facts that connect them to convergent sequences;
- work with subsets of a metric space, and tell "open in " from "open in ";
- decide whether two metrics on the same set are equivalent, and show that two natural metrics on continuous functions are not;
- compute great-circle, taxicab, Hamming and edit distances, and say what the triangle inequality buys in each case.
Distance, in general
John F. Kennedy airport in New York is at about 40.64° N, 73.78° W, and Hong Kong International at about 22.31° N, 113.92° E. On a flat Mercator map the obvious route runs west across North America and the Pacific. But the shortest path along the surface of the Earth is an arc of a great circle, the intersection of the sphere with a plane through its centre. Treating the Earth as a sphere of radius km, that arc is about km long, and it passes within about 6° of the North Pole (Figure 1.3).
Airlines know this. When Cathay Pacific announced its nonstop Hong Kong–New York service in 2001, the announcement said it would fly over the North Polar region, saving more than two hours each way compared with the North Pacific routing. (Real routes also bend to follow winds and airspace, so an actual flight track is close to the great circle, not on it.)
The distance an aircraft cares about is not the distance in any map. It is measured on the sphere, and it differs from the straight-line distance through the Earth and from the distance a ruler measures on a chart. Each of these is a legitimate way of measuring distance between the same pairs of points, and each obeys the same four rules.
A metric space is a set with a function , the metric or distance, such that for all :
- ;
- (positivity) if ;
- (symmetry) ;
- (triangle inequality) .
The triangle inequality carries nearly all of the weight. It says that a detour through can't be shorter than going directly. In every argument of 2A.6 Sequences and 2A.9 Continuous Functions that split into , the triangle inequality for does the same job here, and those arguments carry over word for word.
A useful consequence, the reverse triangle inequality, says that distances to a fixed point change no faster than the point moves:
(Apply the triangle inequality twice, once with as the detour and once with .)
A sequence in a metric space converges to if as a sequence of real numbers; that is, for every there is an with for all .
Limits are unique: if and , then , so and by positivity. This is the first place positivity is used. Without it, "the limit" would not make sense.
A zoo of metric spaces
Three metrics on
For points and of there are three standard distances:
The first is the Euclidean metric, the ruler distance. The second is the taxicab metric, the distance travelled along a grid of streets. The third is the sup (or maximum) metric, the largest disagreement in any one coordinate.
For and , the triangle inequality follows coordinate by coordinate from the one on . For the Euclidean metric it needs one idea.
For , .
Proof. Write and . If there is nothing to prove. Otherwise, for every real ,
A quadratic in that is never negative has discriminant at most : .
With and , expanding gives .
The three metrics give the same answer on the real line, and different answers in the plane. The clearest way to see the difference is to draw each one's unit ball, the set of points at distance less than from the origin.
On a grid of streets, a pedestrian or a taxi can't cut across blocks, so the distance that matters is the taxicab distance, measured along the grid's two directions. Most of Manhattan is laid out on the grid of the Commissioners' Plan of 1811, whose avenues run about 29° east of true north, roughly along the island. So the taxicab metric that describes Manhattan is in coordinates rotated by 29° from north and east, not in map coordinates. Between two corners, the walking distance is between and times the straight-line distance: equal when both corners are on the same street, and largest when the straight line runs at 45° to the grid (Exercise 1.15). Every shortest walk is a staircase, and there are usually very many of them (Figure 1.2).
The sphere
Put the Earth's centre at the origin and represent a place by its unit vector . The great-circle distance on a sphere of radius is times the angle between the vectors:
Positivity and symmetry are immediate. The triangle inequality, which says that angles between directions obey , is Exercise 1.16.
The arccos formula loses precision when and are close, because is very steep near . Navigation software uses an equivalent form, the haversine formula, which with latitudes and longitudes reads
For New York and Hong Kong this gives the km above.
The Mercator map is a function from (most of) the sphere to the plane, and it does not preserve distance. No map can: there is no way to flatten any piece of a sphere onto the plane while keeping every distance (Gauss's Theorema Egregium, 8A.9 The Curvature of Surfaces). That is the first sign of curvature, the subject of Book 9A.
Discrete spaces, codes and strings
On any set, the discrete metric for (and for ) satisfies the axioms. It is useful mainly as a test case: it shows what can go wrong when a space has no notion of "nearby".
More interesting discrete spaces come from information.
For two strings of the same length over an alphabet, the Hamming distance is the number of positions in which they differ.
The triangle inequality holds because a position in which and differ must be one in which differs from or differs from . For binary strings of length , the space is the eight corners of a cube, and counts edges along a shortest path between corners (Figure 1.4).
Let be a set of codewords of length whose pairwise Hamming distances are all at least . Then the closed balls of radius around the codewords are disjoint. So if a codeword is sent and at most symbols are corrupted, the received string is closer to the sent codeword than to any other, and decoding to the nearest codeword recovers it.
Proof. If a string had and for codewords , the triangle inequality would give , a contradiction.
A QR code stores its data as bytes protected by Reed–Solomon codes, as specified in the international standard ISO/IEC 18004. The symbols are bytes rather than bits, but the principle is Proposition 1.5: the codewords are chosen far apart in Hamming distance, so a damaged code is still closer to the right message than to any other. The standard offers four error-correction levels, L, M, Q and H, which can recover roughly , , and of the codewords respectively. Higher levels place the codewords farther apart, at the cost of more redundant bytes. That is why a QR code still scans with a logo printed over its middle.
For strings of different lengths, Hamming distance is useless: "kitten" and "sitting" don't even line up. The edit distance (or Levenshtein distance) between two strings is the least number of single-character insertions, deletions and substitutions that turn one into the other. From "kitten" to "sitting" it is : substitute k→s, substitute e→i, insert g. It is a metric. The triangle inequality holds because an edit sequence from to followed by one from to is an edit sequence from to .
A spell checker must find the dictionary words within edit distance of a misspelling, without comparing it to every word in the dictionary. A BK-tree (Burkhard and Keller, 1973) stores the dictionary in a tree where each child of a word is filed under its distance from . To search for words within distance of a query , compute at the root. The reverse triangle inequality says that a word with must have , so only the children filed under distances from to need to be explored. The rest of the tree is skipped without being looked at. The same pruning, valid in any metric space, is used in nearest-neighbour search for images, sounds and DNA sequences. It fails for "distances" that violate the triangle inequality, which is one practical reason the axiom matters.
Spaces of functions
The most important metric spaces in this guidebook are spaces whose points are functions.
Let be any set, and let be the set of bounded functions . The sup metric is
It is a metric: the supremum is finite because and are bounded, and the triangle inequality holds pointwise and then for the supremum. Two functions are within in this metric exactly when the graph of one lies in a band of height around the graph of the other, everywhere. Convergence in is uniform convergence, the subject of 2B.5 Uniform Convergence and Arzelà–Ascoli. On a compact interval, every continuous function is bounded (2A.9 Continuous Functions), so , the continuous functions on , is a metric space with .
On there is another natural metric, the area between the graphs:
The triangle inequality comes from and monotonicity of the integral (2A.11 The Riemann Integral). Positivity is the interesting axiom: if , then is positive at some point, hence (by continuity) at least some on a small interval around it, so the integral is positive. For merely integrable functions this fails. A function that is at one point and elsewhere has integral . Course 3 deals with this by agreeing to identify functions that differ on a negligible set (3A.3 The Lebesgue Integral).
Open and closed sets
From here on, is a metric space. The definitions are those of 2A.9 Continuous Functions for the real line, with replaced by .
The open ball of radius about is . The closed ball is .
Balls depend on the metric. In they are diamonds, discs or squares (Figure 1.1). In with , the ball of radius around is the set of continuous functions whose graphs stay inside the band of half-width around the graph of , with some room to spare (the supremum of is attained on , so it must be strictly less than ). In the discrete metric, the ball of radius around is just .
Let and .
- is an interior point of if some ball lies inside ; an exterior point if some ball around misses entirely; and a boundary point if it is neither, that is, if every ball around meets both and its complement.
- is an adherent point of if every ball around meets . The set of adherent points is the closure .
- is open if it contains none of its boundary points (equivalently, every point of is interior). is closed if it contains all of its boundary points (equivalently, ).
Open balls are open. If , let . Then by the triangle inequality: . So every point of an open ball is an interior point. In the same way, closed balls are closed (Exercise 1.17).
Sets need not be either open or closed: in is neither. And a set can be both: and always are, and in the discrete metric every set is both, since every ball of radius is a single point.
The most-used fact connects closedness to sequences. It is what lets us prove a set is closed by taking limits.
Let . A point is in if and only if some sequence in converges to . Hence is closed if and only if every sequence in that converges in has its limit in .
Proof. If , then for each the ball meets ; choose in it. Then . Conversely, if and , then every ball contains for large , so it meets , and . The second sentence follows because is closed exactly when .
is open if and only if its complement is closed. Any union of open sets is open, and any intersection of finitely many open sets is open. Correspondingly, any intersection of closed sets is closed, and any finite union of closed sets is closed.
Proof. and have the same boundary points, by the symmetric definition. So contains none of them exactly when contains all of them. If each is open and , then lies in some , which contains a ball around ; so the union does too. If are open and lies in all of them, with , then the ball of radius lies in all of them. (The minimum of finitely many positive numbers is positive. For infinitely many it may be : is not open.) The statements about closed sets follow by taking complements.
These properties of open sets are all that is needed to define continuity and convergence, and they are what survives when the metric is thrown away. A collection of subsets of that contains and and is closed under arbitrary unions and finite intersections is called a topology. Topological spaces are the subject of 7A.1 Topological Spaces and Quotients. Until then, every space we meet has a metric, and the metric is the easiest way to work.
Subspaces and relative topology
Any subset is a metric space with the same distance, restricted to pairs of points of . This is how the sphere inherits the straight-line (chordal) distance from , and how inherits its metric from .
Being open is then a statement relative to the space you are in. In , the set is open: the ball of radius around in is . But is not open in , because no interval around fits inside it.
Let . A set is open in if and only if for some set that is open in . The same holds with "closed" in place of "open".
Proof. A ball in is the intersection of with the ball in of the same centre and radius. If is open in , then for each choose with , and let . This is open in , and . Conversely, if with open in , then each has a ball , so . For closed sets, take complements within .
Relative topology will matter as soon as we work on a manifold, which lives inside some larger space but is studied as a space in its own right (8A.1 Smooth Structures).
Equivalent and inequivalent metrics
The three metrics on give different numbers but, it turns out, the same convergent sequences and the same open sets. The reason is that each is bounded by a constant multiple of each other:
(The first two inequalities compare a largest term, a root-sum-of-squares and a sum of non-negative terms; the last bounds each of terms by the largest.)
Two metrics and on the same set are equivalent if they have the same convergent sequences with the same limits. They are uniformly equivalent (or bi-Lipschitz equivalent) if there are constants with for all .
Uniformly equivalent metrics are equivalent: if and only if . By Proposition 1.9, equivalent metrics have the same closed sets, hence the same open sets. So on , one can use whichever of the three is convenient for the problem at hand: to handle coordinates one at a time, for geometry, for counting.
In infinite-dimensional spaces, this freedom disappears.
Let be the "tent" that rises linearly from at to height at , falls back to at , and is on (for ). Then
So in the metric but not in the sup metric. The metrics are not equivalent. The general inequality (on an interval of length ) holds, but no inequality in the other direction can, because a tall narrow tent has small area.
Which metric is right depends on the question. For a sensor that must never exceed a threshold, the worst case matters, and the sup metric is the right one. For the total energy delivered by a signal, the area metric (or its square-integral cousin) is the right one. 2B.5 Uniform Convergence and Arzelà–Ascoli develops the sup metric, and Courses 3 and 4 develop the integral metrics. A whole family of them, one for each exponent , will be needed (3A.7 Lᵖ Spaces and Jensen’s Inequality), and the inequalities that relate them, the Sobolev inequalities of 4A.10 Sobolev Embeddings and Critical Exponents, are among the main tools of geometric analysis.
Once a Riemannian manifold is turned into a metric space (9A.3 Geodesics and the Exponential Map), we can ask how far apart two whole spaces are. For two subsets of a metric space, the Hausdorff distance is the least such that each set lies within distance of the other (Exercise 1.21). Gromov's extension, the Gromov–Hausdorff distance, compares two metric spaces that don't sit inside a common space, by asking how well they can be placed inside one. It makes "the space of all compact metric spaces" into a metric space (9B.4 Convergence of Manifolds). That is the setting in which one says that a sequence of rescaled Ricci flows converges to a limit, and the limits obtained this way, the blow-ups at a singularity, are how Perelman classified singularities (11B.4 Singularities, 12B.2 The Structure of κ-Solutions).
History
The idea of an abstract distance came from analysis, not geometry. Maurice Fréchet's 1906 thesis studied sets of functions and curves on which only a notion of distance was given, and showed that much of the theory of limits carried over to them. Felix Hausdorff named and systematised these "metric spaces" in his Grundzüge der Mengenlehre (1914), the founding text of general topology. The examples that drove both were spaces of functions, exactly the spaces that differential equations need. Hamming distance came from engineering: Richard Hamming introduced it in his 1950 paper on error-detecting and error-correcting codes, written at Bell Labs for computers that had to keep running despite occasional single-bit errors.
A metric space is a set with a distance obeying four axioms, the decisive one being the triangle inequality. Convergence, open and closed sets, closure and boundary are defined exactly as on , and a set is closed precisely when it contains the limits of its convergent sequences. Subsets inherit a metric, and openness is relative to the ambient space. On the standard metrics are uniformly equivalent, but on spaces of functions natural metrics can disagree about which sequences converge. 2B.2 Completeness and Contraction asks which metric spaces are complete, and proves the theorem that makes completeness pay: the contraction mapping principle.
Exercises
Decide which of these are metrics on , and for each that isn't, name an axiom that fails: (a) ; (b) ; (c) ; (d) .
Hint
For (b) and (d), use that and are increasing with for .
Solution
(a) Not a metric: , so the triangle inequality fails. (b) A metric: , squaring the last inequality to check it. (c) Not a metric: although , so positivity fails. (d) A metric, by the hint. It is bounded by but has the same convergent sequences as : so every metric is equivalent to a bounded one.
Show that for , , with equality on the right exactly when the segment from to makes an angle of 45° with the axes. What are the best constants in ?
Solution
With and : gives the left inequality, and , which is , gives the right one, with equality when . In , , the right one by Cauchy–Schwarz applied to and .
For unit vectors , let and , both in . Write and with unit vectors perpendicular to . Show that , and deduce that . This proves the triangle inequality for great-circle distance.
Solution
, using (Cauchy–Schwarz) and . If , then since is decreasing on , . If , then anyway.
(a) Show that a closed ball is a closed set, using Proposition 1.9 and the reverse triangle inequality. (b) In the discrete metric on a set with at least two points, show that the closure of the open ball is not the closed ball of radius . (So "closure of the open ball" and "closed ball" can differ.)
Solution
(a) If and , then , so . (b) , which is closed, so its closure is . The closed ball of radius is the whole space.
Let with the metric from . Show that is both open and closed in . (In 2B.4 Connectedness this is exactly what it means for to be disconnected.)
A binary code of length has minimum distance . Show that the number of codewords is at most (the Hamming bound), by counting the points in the disjoint balls of Proposition 1.5. For and the bound is ; the Hamming code attains it, so its balls tile the whole cube.
Solution
A closed ball of radius in contains strings (choose which positions to flip). The balls around distinct codewords are disjoint and all lie in a set of strings. For , : .
(a) Show that for , so that uniform convergence implies convergence in . (b) Use Example 1.13 to show that the open ball is open for but not for . (So the two metrics have different open sets, not only different convergent sequences.)
Solution
(a) . (b) The zero function is in the set. Every -ball around , of radius , contains for , since ; but , so is not in the set. Hence is not a -interior point.
For non-empty closed bounded subsets of , let and define . (a) Compute between the unit circle and the closed unit disc in , and between and . (b) Show that satisfies the triangle inequality. (c) Show that a sequence of finite sets can converge in to an interval. This is how a sequence of discrete approximations, or of shrinking and rescaled shapes, can converge to a continuum. The Gromov–Hausdorff version of this metric is the one used for limits of Riemannian manifolds in 9B.4 Convergence of Manifolds.
Solution
(a) Every point of the disc is within of the circle, and the centre is exactly away, so . For the grid, every point of is within of a grid point, and the midpoint of a gap is exactly that far, so . (b) If and , then by the triangle inequality in ; similarly in the other direction. (c) By (a), the grids converge to .
© 2026 NeckPinch (www.neckpinch.com). All content in the guidebook (text, mathematics, figures and exercises) is protected by copyright. All rights reserved. No part may be copied, republished or redistributed without written permission.