# Metrics

Example 1. Let
$\mathcal{X}\subseteq\mathbb{R}$
be a nonempty set and define
$d:\mathcal{X}\times\mathcal{X}\rightarrow\mathbb{R}$
by
 ​$d(x,y)\triangleq\begin{cases}\begin{array}{cl}1 & \text{if x=y} \\0 & \text{otherwise.}\end{array}\end{cases}$​ ​
Prove
$d$
forms a metric.
Ex 1: Comment
Hint
Visual
Formal Write-Up
Follow-Up
This interesting metric might not be useful for finding our usual notion of "distance'' between to points on a map, but it is useful for illustrations and identifying general properties of metrics (since it is so simple to analyze).
It suffices to verify each of the three properties of a metric hold.
Illustration of discrete metric for 3 points in the 2D plane. An arrow from a point to a point with label denotes . The distance between any pair of points is 1 while the distance between a point and itself is zero. Symmetry is also apparent since the "distance'' between points does not depend on direction.
To verify
$d$
is a metric we verify three properties hold: symmetry, positivity, and the triangle inequality. By definition,
$d(x,y) = 1 > 0$
if
$x\neq y$
and
$d(x,x) = 0$
. Thus, positivity holds for
$d$
$x\ne y$
implies
$d(x,y) = 1 = d(y,x)$
, and so symmetry holds also. Let three points
$x,y,z\in\mathcal{X}$
be given. If
$x=z$
, then
 ​$d(x,z)=0\leq d(x,y)+d(y,z),$​ ​
where the inequality holds by positivity of
$d$
(i.e.
$d(x,y)\geq 0$
and
$d(y,z)\geq 0$
). Next, suppose
$x\neq z$
. This implies either
$x\ne y$
or
$y\neq z$
, making either
$d(x,y) = 1$
or
$d(y,z) = 1$
, and so
 ​$d(x,z) = 1 \leq d(x,y)+d(y,z)$​ ​
In either case,
$d(x,z) \leq d(x,y) + d(y,z).$
Since
$x,y,z\in\mathcal{X}$
were arbitrarily chosen, the triangle inequality holds. Thus, all three properties hold, i.e.
$d$
forms a metric.
 ​$\blacksquare$​ ​
Note we start by identifying the definition of what must be shown to complete a satisfactory proof. This is a good practice in general. It makes clear what must be done and where we are headed.
To prove something holds "for all elements...'' it is typically easiest to assume arbitrary elements are given. Then we prove whatever statement with this arbitrary elements and then state that, because these were chosen arbitrarily, the result holds for all such elements (see second to last sentence of proof).
Sometimes a particular relation can be hard to verify directly. However, we can, at times, break the relationship up into a handful of cases that are each easier to verify.
Example 2. Let
$\mathcal{X} \triangleq {1,2,3,4}$
and define
$d\colon\mathcal{X}\times\mathcal{X}\rightarrow\mathbb{R}$
by
 ​$d(x,y)\triangleq \begin{cases} \begin{array}{cl} 0 & \text{if x=y, }\\[5pt] \frac{1}{3} & \text{if x > y}, \\[5pt] \frac{2}{3} & \text{if x < y.} \\\end{array}\end{cases}$​ ​
Is
$(\mathcal{X},d)$
Hint
Visual
Formal Write-Up
Follow-Up
For
$(\mathcal{X},d)$
to be a metric space, each of the four axioms must hold.
Illustration of function for 3 points on the 1D number line. An arrow from a point to a point with label denotes . Notice is not a metric since it does not possess symmetry.
No,
$(\mathcal{X},d)$
is not a metric space since the symmetry axiom fails, e.g. note
 ​$d(1,2) = \dfrac{2}{3} > \dfrac{1}{3} = d(2,1).$​ ​
 ​$\blacksquare$​ ​
To prove
$(\mathcal{X},d)$
is a metric space, one must verify each of the four axioms hold. However, to prove something is not a metric space, it suffices to find a single counterexample that shows a violation of one of the axioms.