Definition (metric space)

Let $X$ be any set. A metric is a function $d: X\times X\to\R$ such that

  1. (positive semidefinite) $d(x,y)\geq 0$ for all $x,y\in X$, and $d(x,y)=0$ iff $x=y$;

  2. (symmetry) $d(x,y) = d(y,x)$ for all $x,y\in X$;

  3. (triangle inequality) $d(x,y) \leq d(x,z) + d(z,y)$ for all $x,y,z\in X$.

We say $(X,d)$ is a metric space.