nLab metric space




A metric space is a set which comes equipped with a function which measures distance between points, called a metric. The metric may be used to generate a topology on the set, the metric topology, and a topological space whose topology comes from some metric is said to be metrizable.


Traditionally, a metric space is defined to be a set XX equipped with a distance function

d:X×X[0,) d\colon X \times X \to [0, \infty)

(valued in non-negative real numbers) satisfying the following axioms:

  • Triangle inequality: d(x,y)+d(y,z)d(x,z)d(x, y) + d(y, z) \geq d(x, z);

  • Point inequality: 0d(x,x)0 \geq d(x, x) (so 0=d(x,x)0 = d(x,x));

  • Separation: x=yx = y if d(x,y)=0d(x, y) = 0 (so x=yx = y iff d(x,y)=0d(x,y) = 0);

  • Symmetry: d(x,y)=d(y,x)d(x, y) = d(y, x).

Given a metric space (X,d)(X, d) and a point xXx \in X, the open ball centered at xx of radius rr is

B r(x){yX:d(x,y)<r} B_r(x) \coloneqq \{y \in X : d(x, y) \lt r\}

and it may be shown that the open balls form a basis for a topology on XX, the metric topology. In fact, metric spaces are examples of uniform spaces, and much of the general theory of metric spaces, including for example the notion of completion of a metric space, can be extrapolated to uniform spaces and even Cauchy spaces.

As a Richman premetric space

In constructive mathematics, a metric space is a Richman premetric space (X,)(X, \sim) such that for all non-negative rational numbers q 0q \in \mathbb{Q}_{\geq 0}, and r 0r \in \mathbb{Q}_{\geq 0}, if q<rq \lt r, than for every xXx \in X and yXy \in X, either x ryx \sim_r y or ¬(x qy)\neg(x \sim_q y). Classically, every Richman premetric space is a metric space, but constructively, Richman premetric spaces are only “metric spaces” that are valued in the lower Dedekind real numbers.

Metrizable spaces

A metrizable topological space is a topological space XX which admits a metric such that the metric topology agrees with the topology on XX. In general, many different metrics (even ones giving different uniform structures) may give rise to the same topology; nevertheless, metrizability is manifestly a topological notion.

Metrizable spaces enjoy a number of separation properties: they are Hausdorff, regular, and even normal. They are also paracompact.

Metrizable spaces are closed under topological coproducts and of course subspaces (and therefore equalizers); they are closed under countable products but not general products (for instance, a product of uncountably many copies of the real line \mathbb{R} is not a normal space).

Fundamental early work in point-set topology established a number of metrization theorems, i.e., theorems which give sufficient conditions for a space to be metrizable. One of the more useful theorems is due to Urysohn:


A compact Hausdorff space that is second-countable is metrizable.


A compact Hausdorff space that is merely separable need not be metrizable.

One counter-example is the Stone-Cech compactification β()\beta(\mathbb{N}), in which the discrete space \mathbb{N} of natural numbers is dense, whle no non-principal ultrafilter UU is the limit of a sequence X={x n}X = \{x_n\} \subseteq \mathbb{N} of principal ultrafilters.

Namely: Supposing it were, choose complementary subsets A,BA, B \subseteq \mathbb{N} such that AXA \cap X and BXB \cap X are infinite. By the decomposition β()=β(A+B)=β(A)+β(B)\beta(\mathbb{N}) = \beta(A + B) = \beta(A) + \beta(B), we have UU belonging to exactly one of β(A),β(B)\beta(A), \beta(B), say β(B)\beta(B). But since the subsequence AXA \cap X converges to UU, the basic open neighborhood β(B)={Vβ():BV}\beta(B) = \{V \in \beta(\mathbb{N}): B \in V\} of UU intersects AXA \cap X non-trivially, i.e., BB is contained in some principal ultrafilter prin(a)prin(a) with aAXa \in A \cap X. Then aa lies in disjoint sets BB and AXA \cap X, contradiction.


If we allow dd to take values in [0,][0,\infty] (the nonnegative lower reals) instead of just in [0,)[0,\infty), then we get extended metric spaces. If we drop separation, then we get pseudometric spaces. If we drop the symmetry condition, then we get quasimetric spaces. Thus the most general notion is that of an extended quasipseudometric space, which are also called Lawvere metric spaces for the reasons below.

On the other hand, if we strengthen the triangle inequality to

max(d(x,y),d(y,z))d(x,z), max(d(x,y), d(y,z)) \geq d(x,z) ,

then we get ultrametric spaces, a more restricted concept. (This include for example pp-adic completions of number fields.) Extended quasipseudoultrametric spaces can also be called Lawvere ultrametric spaces.

Metrics valued in another Archimedean integral domain

In some cases, we might want our codomain of our metric to take values in values other than the real numbers \mathbb{R}. This is already important in the definition of the real numbers as modulated Cauchy real numbers, where the metric used is valued in the non-negative rational numbers 0\mathbb{Q}_{\geq 0}.

This becomes even more essential in constructive mathematics: while in classical mathematics, the modulated Cauchy real numbers are equivalent to the Dedekind real numbers, in constructive mathematics, those definitions are inequivalent to the Dedekind real numbers, and so there are multiple sets of real numbers in which a metric could be valued in. Something similar happens in predicative constructive mathematics with the axiom of fullness: the Dedekind real numbers could be defined as multivalued Cauchy real numbers, which is unique up to field isomorphism.

In predicative constructive mathematics without the axiom of fullness, the issue becomes even worse: there is no longer one set of Dedekind real numbers. In some foundations, there is a whole hierarchy of Dedekind real numbers, one set for every universe in the foundations. In other foundations, there isn’t even a single set of Dedekind real numbers. As a result, one cannot resort to merely using the Dedekind real numbers for defining the metric as in impredicative mathematics, one has to define metrics and metric spaces more generally.

Thus, given an Archimedean integral domain RR, an RR-metric on a set XX is a function d:X×XR 0d:X \times X \to R_{\geq 0}, where R 0R_{\geq 0} is the set of non-negative elements in RR, such that

  • Triangle inequality: d(x,y)+d(y,z)d(x,z)d(x, y) + d(y, z) \geq d(x, z);

  • Point inequality: 0d(x,x)0 \geq d(x, x) (so 0=d(x,x)0 = d(x,x));

  • Separation: x=yx = y if d(x,y)=0d(x, y) = 0 (so x=yx = y iff d(x,y)=0d(x,y) = 0);

  • Symmetry: d(x,y)=d(y,x)d(x, y) = d(y, x).

This is equivalently an (R 0,,+,0)(R_{\geq 0}, \geq, +, 0)-enriched set.

Given any Archimedean integral domain RR and an Archimedean integral subdomain SRS \subseteq R, then SS is an (R 0,,+,0)(R_{\geq 0}, \geq, +, 0)-enriched set.

In homotopy type theory

In homotopy type theory, metric and pseudometric spaces could be defined as any type, not just 0-truncated types. Let \mathbb{R} be some suitable notion of real number, and

0 a:a0\mathbb{R}_{\geq 0} \coloneqq \sum_{a:\mathbb{R}} a \geq 0

be the non-negative real numbers.


A pseudometric space is a type XX with a function d:X×X 0d:X \times X \to \mathbb{R}_{\geq 0}, which comes with witnesses for symmetry, the triangle identity, and the identity-to-zero-distance condition:

sym(x,y):d(x,y)=d(y,x)\mathrm{sym}(x, y):d(x, y) = d(y, x)
triangle(x,y,z):d(x,z)d(x,y)+d(y,z)\mathrm{triangle}(x, y, z):d(x, z) \leq d(x, y) + d(y, z)
idtozerodis(x,y):(x=y)(d(x,y)=0)\mathrm{idtozerodis}(x, y):(x = y) \to (d(x, y) = 0)

The last axiom is equivalent to the point inequality axiom

ptineq(x):d(x,x)=0\mathrm{ptineq}(x):d(x, x) = 0

by the induction principle of identity types. Every pseudometric can be shown to have an equivalence relation

xyd(x,y)=0x \sim y \coloneqq d(x, y) = 0

through the axioms of a pseudometric space.

In set theory, the separation axiom is usually defined as the converse of the identity-to-zero-distance axiom. However, in type theory, since not all identity types are propositions, merely postulating a function

sepax(x,y):(d(x,y)=0)(x=y)\mathrm{sepax}(x, y):(d(x, y) = 0) \to (x = y)

does not result in a metric space, since there might be many such functions into the identity type x=yx = y. Instead, one must strengthen the condition to a Rezk completeness condition for pseudometric spaces, similar to the type-theoretic antisymmetry condition in posets from preordered types:


A pseudometric space is a metric space if the axiom

idtozerodis(x,y):(x=y)(d(x,y)=0)\mathrm{idtozerodis}(x, y):(x = y) \to (d(x, y) = 0)

is an equivalence of types.

Since any type of non-negative real numbers is a set, the Rezk completeness condition automatically implies that every metric space is a set.

Category of metric spaces

When working with metric spaces one encounters a broad variety of different maps including non-continuous ones like almost isometries. For a convenient categorical set-up one often restricts to short maps, i.e. maps that do not increase any distance or, equivalently, have are of Lipschitz norm not greater than 1. The category of Lawvere metric spaces and short maps forms the category of metric spaces MetMet. The restriction to ordinary metric spaces is denoted by Met ordMet_{ord}.

Lawvere metric spaces

In Lawvere, 73, it was pointed out that Lawvere metric spaces are precisely categories enriched in the monoidal poset ([0,],)([0, \infty], \geq), where the tensor product is taken to be addition. The composition operation in this enriched category identifies with the triangle identity in the metric space (see at triangle inequality – Interpretation in enriched category theory).

Alternatively, taking the monoidal product to be supremum instead, enriched categories amount to Lawvere ultrametric spaces.

Thus generalized, many constructions and results on metric spaces turn out to be special cases of yet more general constructions and results of enriched category theory. This includes for example the notion of Cauchy completion, which in general enriched category theory is related to Karoubi envelopes and Morita equivalence.

Imposing the symmetry axiom then gives us enriched \dagger-categories. Note that when enriching over a cartesian monoidal poset, there is no difference between a \dagger-category and a groupoid, so ultrametric spaces can also be regarded as enriched groupoids, which is perhaps a more familiar concept.

(The requisite axioms for an enriched groupoid do not make sense when the enriching category is not cartesian, but one might argue that since in a poset “they would commute automatically anyway”, it makes sense to call any poset-enriched \dagger-category also an “enriched groupoid”. However, perhaps it makes more sense just to speak about enriched \dagger-categories.)

In the presence of the symmetry axiom, the “separation” axiom “x=yx=y if d(x,y)=0d(x,y)=0” is equivalent to skeletality of an enriched category. That is, a pseudo-metric space is a metric space precisely when it is skeletal. But in the non-symmetric case, this separation axiom is stronger than skeletality; the latter would say only “x=yx=y if d(x,y)=d(y,x)=0d(x,y)=d(y,x)=0”. That is, a quasi-pseudo-metric space can be skeletal without being a quasi-metric space, at least the way the latter term is usually used.

Note that like any kind of enriched category, Lawvere metric spaces are monads in a bicategory of “matrices”, whose objects are sets and whose morphisms from XX to YY are functions d:X×Y[0,]d:X\times Y \to [0,\infty]. This sort of perspective can be generalized to many other kinds of topological structures; an exposition can be found in the book Monoidal topology.

The category of metric spaces and categories of random maps as generalised metric spaces were studied in the thesis of Lawvere’s student Xiao-qing Meng.

Motivation for the axioms

The triangle axiom is the fundamental idea behind a metric space; it goes back (at least) to Euclid and captures the idea that we are discussing the shortest distance between two points. Given the triangle inequality, we have the polygon inequality

d(x 0,x 1)++d(x n1,x n)d(x 0,x n) d(x_0,x_1) + \cdots + d(x_{n-1},x_n) \geq d(x_0,x_n)

for all n>0n \gt 0; the point inequality extends this to n=0n = 0.

Besides extended metric spaces (where distances may be infinite), one might consider spaces where distances may be negative. But in fact this gives us nothing new, at least if we have symmetry. First,

d(x,x)+d(x,x)d(x,x) d(x,x) + d(x,x) \geq d(x,x)

forces d(x,x)0d(x,x) \geq 0, so d(x,x)=0d(x,x) = 0; then

2d(x,y)=d(x,y)+d(y,x)d(x,x) 2 d(x,y) = d(x,y) + d(y,x) \geq d(x,x)

forces d(x,y)0d(x,y) \geq 0. A generalisation to negative distances is possible for quasimetric spaces, however; the simplest example has 22 elements, with d(x,y)=d(y,x)d(x,y) = -d(y,x) (but necessarily d(x,x)=0d(x,x) = 0 still).

We can define a preorder \leq on the points of a Lawvere metric space:

xyd(x,y)=0. x \leq y \;\Leftrightarrow\; d(x,y) = 0 .

Then the symmetry axiom implies that this relation is symmetric and hence an equivalence relation. The quotient set under this equivalence relation satisfies separation; in this way, every pseudometric space is equivalent (as an enriched category) to a metric space. Even for quasimetric spaces, we can still define an equivalence relation:

xyd(x,y)=0d(y,x)=0. x \equiv y \;\Leftrightarrow\; d(x,y) = 0 \;\wedge\; d(y,x) = 0 .

In constructive mathematics, it works better to use \lneq:

xyd(x,y)>0; x \lneq y \;\Leftrightarrow\; d(x,y) \gt 0 ;

then the symmetry axiom implies that this is an apartness relation, which (for quasimetric spaces) we can also define directly:

x#yd(x,y)>0d(y,x)>0. x \# y \;\Leftrightarrow\; d(x,y) \gt 0 \;\vee\; d(y,x) \gt 0 .


  • Every set carries the discrete metric given by

    d(x,y){0 if x=y 1 otherwise d(x,y) \coloneqq \left\{\array{ 0 & \text{if } x = y \\ 1 & \text{otherwise} }\right.

    For certain purposes, it makes more sense to make most the non-zero distance \infty instead of 11; then one has an extended metric space.

  • Every normed vector space is a metric space by d(x,y)xyd(x,y) \coloneqq {\|x - y\|}; a pseudonormed vector space is a pseudometric space.

  • Every connected Riemannian manifold becomes a pseudometric space (or a metric space if, as is often assumed, the manifold is Hausdorff) by taking the distance between two points to be infimum of the Riemannian lengths of all continuously differentiable paths connecting them:

    d(x,y)inf xγylen(γ). d(x,y) \coloneqq inf_{x \stackrel{\gamma}{\to} y} len(\gamma) .

    If the manifold might not be connected, then it still becomes an extended metric space.


Generalized uniform structures

proarrowmonadRezk-complete versionpro-monadsymmetric versions
binary relationpreorderpartial orderquasiuniformitysymmetric relationequivalence relationequalityuniformity
binary function to [0,)[0,\infty)quasipseudometricquasimetricquasiprometricsymmetric binary functionpseudometricmetricprometric
topogenyquasiproximitysyntopogenysymmetric topogenyproximitysymmetric syntopogeny


  • Wikipedia, Metric space

  • Bill Lawvere (1973). Metric spaces, generalized logic and closed categories. Reprinted in TAC, 1986. Web.

  • Xiao-qing Meng, Categories of convex sets and of metric spaces with applications to stochastic programming and related areas, PhD thesis (djvu)

  • Dirk Hofmann, Gavin J. Seal, and Walter Tholen (editors), Monoidal topology: A Categorical Approach to Order, Metric, and Topology, Cambridge University Press, 2014

  • Fred Richman, Real numbers and other completions, Mathematical Logic Quarterly 54 1 (2008) 98-108 [doi:10.1002/malq.200710024]

  • Auke B. Booij, Analysis in univalent type theory (pdf)

Last revised on March 16, 2024 at 01:45:13. See the history of this page for a list of all contributions to it.