Metric (source code)
= Metric
{title2=$d$}
= Distance function
{synonym}
A <metric> on a <set> $X$ is a <function> $d:X\times X\to[0,\infty)$ satisfying, for every $x,y,z\in X$:
* $d(x,y)\geq0$: distances are nonnegative and finite.
* $d(x,y)=0$ if and only if $x=y$: distinct elements have positive distance.
* $d(x,y)=d(y,x)$: exchanging the endpoints leaves the distance unchanged.
* $d(x,z)\leq d(x,y)+d(y,z)$: the <triangle inequality>.
A <metric> equips its underlying <set> with a <metric space> structure; the distance <function> and the space carrying it are distinct concepts. The second requirement distinguishes a <metric> from a <pseudometric>, which may identify distinct elements at zero distance. The symmetry requirement also explains why directed travel times, such as uphill versus downhill times, need not define a <metric>.
A tempting alternative on the <real numbers> is $d(x,y)=(x-y)^2$. It is nonnegative, symmetric, and zero exactly on equal endpoints, but fails the <triangle inequality>: $d(0,2)=4>1+1=d(0,1)+d(1,2)$. Checking only the first three requirements would miss the failure.
Back to article page