The Formal Definition of a Metric
The previous tutorial explained why distance is useful even when points cannot be subtracted. A metric makes that idea precise: it is a real-valued function on pairs of points that satisfies four requirements. These requirements are enough to support the basic language of nearness without requiring the points to be numbers, vectors, or functions.
- \(d(x,y)=0\) if and only if \(x=y\).
- \(d(x,y)=d(y,x)\).
- \(d(x,z)\leq d(x,y)+d(y,z)\).
The codomain \([0,\infty)\) means that every distance is a finite, nonnegative real number. The first axiom is sometimes stated in two parts: \(d(x,y)\geq0\), and \(d(x,y)=0\) exactly when \(x=y\). Stating only that \(d(x,y)\geq0\) is not enough. If two distinct points were allowed to have distance zero, the function would not be a metric under this definition.
The second axiom says that the order of the two points does not affect their distance. The third is the triangle inequality: going from \(x\) to \(z\) directly is no farther than going from \(x\) to \(y\), then from \(y\) to \(z\). The points in the definition are arbitrary; the intermediate point \(y\) is not required to be distinct from either endpoint.
A useful way to check a proposed metric is to verify each requirement separately. In particular, the triangle inequality must hold for every triple, including triples in which some points coincide. It is not enough to check that the formula resembles a familiar distance or that it works for a few selected triples.
Worked Examples: Checking the Axioms
Worked Example: A Square-Root Distance on the Real Line
For \(x,y\in\mathbb{R}\), define $$ d(x,y)=\sqrt{|x-y|}. $$ We check the metric axioms. Absolute values are nonnegative, so \(d(x,y)\geq0\). Also, $$ d(x,y)=0 \quad\Longleftrightarrow\quad |x-y|=0 \quad\Longleftrightarrow\quad x=y. $$ Since \(|x-y|=|y-x|\), the formula is symmetric.
For the triangle inequality, the usual absolute-value triangle inequality gives $$ |x-z|\leq |x-y|+|y-z|. $$ The square-root function is increasing on \([0,\infty)\), so $$ \sqrt{|x-z|} \leq \sqrt{|x-y|+|y-z|}. $$ For \(a,b\geq0\), we have $$ (\sqrt a+\sqrt b)^2=a+b+2\sqrt{ab}\geq a+b. $$ Both sides being nonnegative, taking square roots yields \(\sqrt{a+b}\leq\sqrt a+\sqrt b\). Apply this with \(a=|x-y|\) and \(b=|y-z|\). It follows that $$ d(x,z)\leq d(x,y)+d(y,z). $$ Thus the formula defines a metric. For example, \(d(1,5)=\sqrt4=2\), while \(d(1,2)+d(2,5)=1+\sqrt3\), which is greater than \(2\).
Worked Example: A Metric on the Positive Real Numbers
On \(X=(0,\infty)\), set $$ d(x,y)=|\ln x-\ln y|. $$ The logarithms are defined for every point of \(X\). The formula is nonnegative and symmetric. Moreover, $$ d(x,y)=0 \quad\Longleftrightarrow\quad \ln x=\ln y \quad\Longleftrightarrow\quad x=y, $$ because the logarithm is injective on \((0,\infty)\).
For \(x,y,z>0\), the absolute-value triangle inequality gives $$ d(x,z)=|\ln x-\ln z| =|(\ln x-\ln y)+(\ln y-\ln z)| \leq|\ln x-\ln y|+|\ln y-\ln z| =d(x,y)+d(y,z). $$ So \(d\) is a metric. For instance, $$ d(2,8)=|\ln2-\ln8|=|\ln2-3\ln2|=2\ln2, $$ and $$ d(2,4)+d(4,8)=|\ln2-\ln4|+|\ln4-\ln8| =\ln2+\ln2=2\ln2. $$ In this example, equal multiplicative changes correspond to equal distances: multiplying \(2\) by \(2\) and then \(4\) by \(2\) gives the same distance each time.
Worked Example: A Metric on Three Points
Let \(X=\{A,B,C\}\). Define \(d(x,x)=0\), and assign $$ d(A,B)=d(B,A)=2,\qquad d(B,C)=d(C,B)=3,\qquad d(A,C)=d(C,A)=4. $$ The distances are nonnegative, and only pairs of identical points have distance zero. The assignments are symmetric by construction.
It remains to check the triangle inequality. For the three distinct points, the only potentially restrictive comparisons are $$ d(A,C)=4\leq d(A,B)+d(B,C)=2+3=5, $$ $$ d(B,C)=3\leq d(B,A)+d(A,C)=2+4=6, $$ and $$ d(A,B)=2\leq d(A,C)+d(C,B)=4+3=7. $$ Reversing the order of a triple does not change these inequalities, because the distances are symmetric. If a triple has repeated points, its triangle inequality follows directly: for example, \(d(A,A)=0\leq d(A,B)+d(B,A)\), and \(d(A,B)\leq d(A,A)+d(A,B)\) is equality. Thus every triple satisfies the triangle inequality, and the assignment is a metric.
How a Proposed Distance Can Fail
A formula may satisfy some metric axioms but fail another. For example, on \(\mathbb{R}\) consider the squared difference \(q(x,y)=|x-y|^2\). It is nonnegative, symmetric, and zero exactly when \(x=y\). But for \(x=0\), \(y=1\), and \(z=2\), $$ q(0,2)=|0-2|^2=4, \qquad q(0,1)+q(1,2)=|0-1|^2+|1-2|^2=1+1=2. $$ The triangle inequality would require \(4\leq2\), which is false. Therefore \(q\) is not a metric. This illustrates why checking all the axioms matters: having three of the required properties does not compensate for failure of the fourth.
Theorem (A Norm Induces a Distance), established in “Why Metric Spaces?”, gives an important source of metrics: a normed vector space \(V\) has the metric \(d(x,y)=\|x-y\|\). That result is a special case of the definition, not an additional requirement on a metric space. A general metric space need not have addition, scalar multiplication, or a norm.
Consequences of the Triangle Inequality
Although the triangle inequality gives an upper bound on one distance, it also controls how much two distances to the same point can differ. This estimate follows from applying the triangle inequality in both directions.
Proof. Applying the triangle inequality to the points \(x,y,z\) gives $$ d(x,z)\leq d(x,y)+d(y,z), $$ so \(d(x,z)-d(y,z)\leq d(x,y)\). Interchange \(x\) and \(y\) in the same argument. Then $$ d(y,z)\leq d(x,y)+d(x,z), $$ which gives \(d(y,z)-d(x,z)\leq d(x,y)\). The two inequalities together say $$ -d(x,y)\leq d(x,z)-d(y,z)\leq d(x,y). $$ This is equivalent to \(|d(x,z)-d(y,z)|\leq d(x,y)\), as required. \(\square\)
The reverse triangle inequality says that moving the first point from \(x\) to \(y\) changes its distance to a fixed point \(z\) by no more than the distance \(d(x,y)\) moved. It is often useful when comparing distances without calculating them exactly. Notice that it was derived from the metric axioms; it is not a fifth axiom.
Metrics also make it possible to define convergence without vector operations. A sequence \((x_n)\) in a metric space converges to \(x\in X\) if, for every \(\varepsilon>0\), there is an integer \(N\) such that \(d(x_n,x)<\varepsilon\) whenever \(n\geq N\). Equivalently, the distances \(d(x_n,x)\) tend to zero. The metric axioms ensure that such a limit cannot be two different points.
Proof. Suppose a sequence \((x_n)\) converges both to \(x\) and to \(y\). Let \(\varepsilon>0\). By convergence to \(x\), there is an integer \(N_1\) such that \(d(x_n,x)<\varepsilon/2\) for \(n\geq N_1\). By convergence to \(y\), there is an integer \(N_2\) such that \(d(x_n,y)<\varepsilon/2\) for \(n\geq N_2\). Choose \(n\geq\max\{N_1,N_2\}\). The triangle inequality gives $$ d(x,y)\leq d(x,x_n)+d(x_n,y)<\frac{\varepsilon}{2}+\frac{\varepsilon}{2}=\varepsilon. $$ This holds for every \(\varepsilon>0\). Since \(d(x,y)\geq0\), it follows that \(d(x,y)=0\): if it were positive, taking \(\varepsilon=d(x,y)/2\) would contradict \(d(x,y)<\varepsilon\). The zero-distance axiom now implies \(x=y\). Thus the limit is unique. \(\square\)
Balls and the Role of the Axioms
For \(x\in X\) and \(r>0\), the metric defines the open ball of radius \(r\) centered at \(x\) by $$ B_r(x)=\{y\in X:d(x,y)<r\}. $$ This set consists of the points whose distance from \(x\) is less than \(r\). Symmetry ensures that the distance from \(x\) to \(y\) does not depend on the order of the pair, while the triangle inequality controls how balls relate to one another. For example, if \(d(x,y)<s\), then every \(z\in B_r(x)\) satisfies $$ d(z,y)\leq d(z,x)+d(x,y)<r+s, $$ so \(B_r(x)\subseteq B_{r+s}(y)\).
The definition is deliberately limited to the properties needed to reason about distance. The metric does not have to come from a norm, and its points need not be numbers. Conversely, the same underlying set can be equipped with different metrics, so statements about convergence or balls refer to the chosen metric. In each setting, the axioms are the test that the proposed notion of distance must pass.
Check Your Understanding
Use the definition and the proved consequences to test your understanding of metrics.
- Which part of the definition rules out distinct points having distance zero?
- Why must the squared difference \(q(x,y)=|x-y|^2\) fail to be a metric on \(\mathbb{R}\)? Give a triple that demonstrates the failure.
- In the reverse triangle inequality, where are the two applications of the triangle inequality used?
- Why does \(d(x,y)<\varepsilon\) for every \(\varepsilon>0\) imply \(d(x,y)=0\)?
- For a metric \(d\), explain why \(d(x,y)<s\) implies \(B_r(x)\subseteq B_{r+s}(y)\).