A metric, sometimes referred to as a distance function, is a function that defines a real nonnegative distance between every two elements of a set. It is commonly denoted by the variable \(d\). In colon-to notation, a metric \(d\) that defines distances between elements of the set \(S\) is written:

$$d: S \times S \to [0, \infty)$$

In this case we say \(d\) is a metric on \(S\).

That is, a metric \(d\) on a set \(S\) takes as input any two elements \(a\) and \(b\) from \(S\) and outputs a number that is taken to define their distance in \(S\) under \(d\). Apart from being nonnegative real numbers, the distances a metric outputs must follow three other rules in order for the function to meet the definition of a metric. A function that matches the above colon-to notation is called a metric if and only if it satisfies these requirements. The following must hold for any choice of \(a\), \(b\), and \(c\) in \(S\):

  1. \(d(a, b) = 0 \iff a = b\)

  2. \(d(a, b) = d(b, a)\)

  3. \(d(a, b) + d(b, c) \geq d(a, c)\)

(1) effectively states both that the distance from an element to itself is 0, and that the distance between non-identical elements must be greater than 0. (2) asserts that a metric must be commutative; informally the distance from \(a\) to \(b\) must be the same as the distance from \(b\) to \(a\). Finally, (3) is known as the triangle inequality and asserts that the distance from \(a\) to \(c\) is at most as large as the sum of the distances from \(a\) to \(b\) and from \(b\) to \(c\). It is named as such because in euclidean space, the points \(a\), \(b\), and \(c\) form a triangle, and the inequality requires that the length of one side of the triangle is not longer than the sum of the lengths of the other two sides; violating this would mean that the shortest path between two points is no longer the straight line between them.

It is possible (and relatively common!) to deal with multiple different metrics on the same set. This means we are using the same set elements as labels, but treating the distances between elements differently; in this case the different metric spaces we are defining may have very different properties. If multiple metrics are being considered, we must be careful when speaking of distances between elements of the set to specify which metric we are using. For example, if \(d\) and \(e\) are both metrics on \(S\), we cannot just say “the distance between \(a\) and \(b\) in \(S\)” because it is ambiguous whether we are referring to \(d(a, b)\) or to \(e(a, b)\). We could instead say something like “the distance between \(a\) and \(b\) under \(e\)” to remove the ambiguity.

The most commonly-used metric on Cartesian space is the Euclidean metric, defined in two dimensions as \(d(a, b) = \sqrt{(a_1-b_1)^2 + (a_2-b_2)^2}\), and more generally in \(n\) dimensions as \(d(a, b) = \sqrt{\sum_{i=1}^n (a_i-b_i)^2}\).

A less-common metric on Cartesian space is the Manhattan metric, defined generally as \(d(a, b) = \sum_{i=1}^n |a_i-b_i|\); the distance is analogous to the distance taken between two points on a rectangular grid when motion is constrained to be purely vertical or horizontal, but not diagonal.

A metric induces a topology add intuitive/​nonalgebraic explanation lens proof that Euclidean and Manhattan distances are metrics


  • Mathematics

    Mathematics is the study of numbers and other ideal objects that can be described by axioms.