Tutorials › Real Analysis › Examples of Metrics

Metric Spaces · Tutorial 653 of 1000

Examples of Metrics

Compare familiar and less obvious metrics, and learn two general constructions that let you build metrics from existing ones.

Advanced 9 min read

What You'll Learn

  • Compare Euclidean, taxicab, and maximum-coordinate distances on the plane
  • Verify weighted coordinate formulas using the metric axioms
  • Compute a distance between continuous functions using the supremum norm
  • Construct a metric by mapping points injectively into a known metric space
  • Build metrics on product spaces from sums or maxima of coordinate distances
  • Recognize why a non-injective map may fail to define a metric

Many Distances on the Same Set

The definition of a metric gives a test for a proposed distance, but it does not prescribe a single formula. The same set can carry several different metrics, each measuring separation in a different way. For instance, on the plane one can measure the straight-line distance, add the coordinate changes, or use only the larger coordinate change. These formulas lead to different numerical distances while each satisfies the metric axioms.

When checking an example, keep the four requirements in view: distances are nonnegative and vanish only for identical points, are symmetric, and satisfy the triangle inequality. The theorem “A Norm Induces a Distance,” established earlier in the course, provides a useful shortcut for distances of the form \(d(x,y)=\|x-y\|\). Other constructions do not require a vector-space structure at all.

Three Metrics on the Plane

Worked Example: Euclidean Distance in the Plane

For \(x=(x_1,x_2)\) and \(y=(y_1,y_2)\) in \(\mathbb{R}^2\), the Euclidean distance is $$ d_2(x,y)=\sqrt{(x_1-y_1)^2+(x_2-y_2)^2}. $$ This is the distance induced by the Euclidean norm, so “A Norm Induces a Distance” shows that it is a metric. Its formula gives the familiar straight-line distance.

For example, take \(x=(1,-2)\) and \(y=(4,2)\). The coordinate differences are \(1-4=-3\) and \(-2-2=-4\), so $$ d_2(x,y)=\sqrt{(-3)^2+(-4)^2} =\sqrt{9+16} =5. $$ The signs of the coordinate differences do not affect the distance because they are squared.

Worked Example: Taxicab and Maximum-Coordinate Distances

Two other distances on \(\mathbb{R}^2\) are $$ d_1(x,y)=|x_1-y_1|+|x_2-y_2| $$ and $$ d_{\max}(x,y)=\max\{|x_1-y_1|,|x_2-y_2|\}. $$ The first adds the coordinate changes. The second records only the larger of them.

Here is a direct check for \(d_1\). It is nonnegative, symmetric, and equals zero exactly when both coordinate differences are zero, which is equivalent to \(x=y\). For \(x,y,z\in\mathbb{R}^2\), the absolute-value triangle inequality in each coordinate gives $$ |x_1-z_1|\leq |x_1-y_1|+|y_1-z_1|, \qquad |x_2-z_2|\leq |x_2-y_2|+|y_2-z_2|. $$ Adding these inequalities gives \(d_1(x,z)\leq d_1(x,y)+d_1(y,z)\).

For \(d_{\max}\), nonnegativity and symmetry follow from those of absolute value. If \(d_{\max}(x,y)=0\), both coordinate differences are zero, so \(x=y\); the reverse implication also holds. To prove the triangle inequality, write \(a_i=|x_i-y_i|\) and \(b_i=|y_i-z_i|\) for \(i=1,2\). Then $$ |x_i-z_i|\leq a_i+b_i \leq \max\{a_1,a_2\}+\max\{b_1,b_2\} $$ for each coordinate \(i\). Taking the maximum over \(i=1,2\) proves $$ d_{\max}(x,z)\leq d_{\max}(x,y)+d_{\max}(y,z). $$ Thus both formulas are metrics.

For \(x=(1,-2)\) and \(y=(4,2)\), the coordinate changes have magnitudes \(3\) and \(4\). Therefore \(d_1(x,y)=7\) and \(d_{\max}(x,y)=4\), whereas the Euclidean distance is \(5\). The three metrics agree on which pairs have distance zero, but they need not assign the same positive distance.

These examples also illustrate a useful distinction: a metric is not required to match a particular geometric picture. The metric axioms determine which distance calculations are legitimate; the chosen formula determines what kinds of changes count most.

Weighted Coordinates and Function Values

Worked Example: Unequal Weights on the Plane

Define, for \(x=(x_1,x_2)\) and \(y=(y_1,y_2)\), $$ d_w(x,y)=2|x_1-y_1|+5|x_2-y_2|. $$ The positive weights make changes in the second coordinate count more heavily than equal changes in the first. The formula is nonnegative and symmetric. It is zero exactly when both coordinate differences vanish, hence exactly when \(x=y\).

For the triangle inequality, apply the absolute-value triangle inequality in each coordinate: $$ |x_i-z_i|\leq |x_i-y_i|+|y_i-z_i|,\qquad i=1,2. $$ Multiplication by the positive weights preserves the inequalities. Adding the result for the first coordinate, weighted by \(2\), and the second, weighted by \(5\), yields $$ d_w(x,z)\leq d_w(x,y)+d_w(y,z). $$ Thus \(d_w\) is a metric. For \(x=(1,-2)\) and \(y=(4,2)\), it gives $$ d_w(x,y)=2|1-4|+5|-2-2|=2\cdot3+5\cdot4=26. $$

Worked Example: Distance Between Continuous Functions

On \(C[0,1]\), the set of continuous real-valued functions on \([0,1]\), define $$ d_\infty(f,g)=\sup_{t\in[0,1]}|f(t)-g(t)|. $$ Because \([0,1]\) is compact, a continuous function is bounded there, so this supremum is finite. The formula is the distance induced by the supremum norm on \(C[0,1]\); the earlier result “The Supremum Norm Makes \(C(K)\) a Normed Space” and “A Norm Induces a Distance” show that it is a metric.

For a concrete calculation, let \(f(t)=t\) and \(g(t)=t^2\). On \([0,1]\), \(t-t^2=t(1-t)\geq0\), and $$ |f(t)-g(t)|=t(1-t)=\frac14-\left(t-\frac12\right)^2\leq\frac14. $$ Equality holds at \(t=\frac12\), so $$ d_\infty(f,g)=\frac14. $$ This metric measures the largest pointwise difference between the functions, rather than an average difference or a difference at one selected input.

Two General Constructions

The examples above suggest ways to create metrics systematically. One construction combines metrics already available on two spaces. Another transfers a metric along a map, provided that map keeps distinct points distinct.

Theorem (Sum and Maximum Metrics on a Product): Let \((X,d_X)\) and \((Y,d_Y)\) be metric spaces. For \((x_1,y_1),(x_2,y_2)\in X\times Y\), define $$ D_1((x_1,y_1),(x_2,y_2)) =d_X(x_1,x_2)+d_Y(y_1,y_2) $$ and $$ D_{\max}((x_1,y_1),(x_2,y_2)) =\max\{d_X(x_1,x_2),d_Y(y_1,y_2)\}. $$ Both \(D_1\) and \(D_{\max}\) are metrics on \(X\times Y\).

Proof. For either formula, the resulting value is nonnegative and symmetric because each coordinate distance has those properties. For \(D_1\), the sum is zero exactly when both coordinate distances are zero. For \(D_{\max}\), the maximum is zero exactly when both coordinate distances are zero. In either case, the zero-distance condition holds exactly when \(x_1=x_2\) and \(y_1=y_2\), that is, when the two points in \(X\times Y\) are identical.

It remains to prove the triangle inequalities. Let \(p=(x_1,y_1)\), \(q=(x_2,y_2)\), and \(r=(x_3,y_3)\). The coordinate triangle inequalities give $$ d_X(x_1,x_3)\leq d_X(x_1,x_2)+d_X(x_2,x_3) $$ and $$ d_Y(y_1,y_3)\leq d_Y(y_1,y_2)+d_Y(y_2,y_3). $$ Adding proves \(D_1(p,r)\leq D_1(p,q)+D_1(q,r)\).

For the maximum formula, each coordinate distance from \(p\) to \(r\) is at most its corresponding distance from \(p\) to \(q\) plus its distance from \(q\) to \(r\). Each of those two terms is bounded by the corresponding maximum. Consequently, $$ d_X(x_1,x_3)\leq D_{\max}(p,q)+D_{\max}(q,r) $$ and $$ d_Y(y_1,y_3)\leq D_{\max}(p,q)+D_{\max}(q,r). $$ Taking the maximum of the left sides proves the triangle inequality for \(D_{\max}\). Both formulas therefore satisfy all the metric axioms. \(\square\)

This result can be applied repeatedly to form metrics on products with more than two coordinates. The sum treats the total of all coordinate distances as the distance; the maximum is controlled by the largest coordinate distance. Neither choice requires the coordinate spaces to be subsets of a vector space.

Theorem (Metric Induced by an Injective Map): Let \((Y,\rho)\) be a metric space, let \(X\) be a nonempty set, and let \(F:X\to Y\) be injective. Then $$ d(x,x')=\rho(F(x),F(x')) $$ defines a metric on \(X\).

Proof. Since \(\rho\) takes nonnegative values, \(d(x,x')\geq0\). Also, symmetry of \(\rho\) gives $$ d(x,x')=\rho(F(x),F(x'))=\rho(F(x'),F(x))=d(x',x). $$ If \(x=x'\), then \(F(x)=F(x')\), so \(d(x,x')=0\). Conversely, if \(d(x,x')=0\), the zero-distance property of \(\rho\) implies \(F(x)=F(x')\). Injectivity of \(F\) then gives \(x=x'\). Finally, for any \(x,x',x''\in X\), the triangle inequality for \(\rho\) gives $$ d(x,x'')=\rho(F(x),F(x'')) \leq \rho(F(x),F(x'))+\rho(F(x'),F(x'')) =d(x,x')+d(x',x''). $$ Thus \(d\) satisfies all the metric axioms. \(\square\)

Worked Example: Pulling Back Distance Through the Exponential Function

The exponential function \(F(x)=e^x\) is injective from \(\mathbb{R}\) into \(\mathbb{R}\). Use the usual metric \(\rho(u,v)=|u-v|\) on \(\mathbb{R}\). The induced metric is $$ d(x,y)=|e^x-e^y|. $$ The theorem shows at once that this is a metric on \(\mathbb{R}\). For example, $$ d(0,\ln 3)=|e^0-e^{\ln 3}|=|1-3|=2. $$ The triangle inequality here follows from the usual absolute-value metric after applying the exponential function; it does not depend on a direct comparison of \(x,y,\) and \(z\) in the original coordinates.

What the Constructions Do—and Do Not—Guarantee

The injectivity hypothesis in the pullback construction is essential. If \(F\) maps two different points to the same point, the proposed distance between those points is zero, violating the metric’s zero-distance condition. For example, \(F(x)=x^2\) is not injective on \(\mathbb{R}\). The formula $$ d(x,y)=|x^2-y^2| $$ gives \(d(-1,1)=|1-1|=0\), even though \(-1\ne1\). It therefore is not a metric on \(\mathbb{R}\). On a domain where \(F\) is injective, the same construction does give a metric.

A second point is that different metrics on the same set can encode different notions of distance. In \(\mathbb{R}^2\), the Euclidean, taxicab, maximum-coordinate, and weighted formulas all distinguish points, yet their values need not agree. When using a metric space, calculations involving convergence or balls must refer to the particular metric chosen. For example, the ball \(B_r(x)\) is defined using \(d(x,y)<r\), so changing \(d\) changes which points satisfy that inequality.

The product and injective-map theorems are useful because they turn verified metrics into new ones without requiring a fresh axiom check from the beginning. In practice, first identify the source metric or coordinate metrics, then check any crucial condition such as injectivity, and finally use the construction theorem. This is more reliable than judging a formula by its appearance alone.

Takeaway: Euclidean, taxicab, maximum-coordinate, weighted, and supremum distances illustrate the variety of metric formulas. Sums and maxima combine coordinate metrics, while an injective map transfers a metric to its domain.

Check Your Understanding

Use the metric axioms and the constructions proved above to answer the following questions.

  1. For the points \(x=(1,-2)\) and \(y=(4,2)\), calculate their Euclidean, taxicab, and maximum-coordinate distances.
  2. Why does the formula \(2|x_1-y_1|+5|x_2-y_2|\) have zero distance only when the two points agree?
  3. In the proof for \(D_{\max}\) on a product, why can each coordinate distance be bounded by \(D_{\max}(p,q)+D_{\max}(q,r)\)?
  4. Which step in the induced-metric proof uses injectivity of \(F\)?
  5. Why does \(d(x,y)=|x^2-y^2|\) fail to be a metric on \(\mathbb{R}\)?