The absolute difference of two real numbers <math>x</math> and <math>y</math> is given by <math>|x-y|</math>, the absolute value of their difference. It describes the distance on the real line between the points corresponding to <math>x</math> and <math>y</math>. It is a special case of the Lp distance for all <math>1\le p\le\infty</math> and is the standard metric used for both the set of rational numbers <math>\Q</math> and their completion, the set of real numbers <math>\R</math>.
As with any metric, the metric properties hold:
<math>|x-y|\ge 0</math>, since absolute value is always non-negative.
<math>|x-y|= 0</math> if and only if <math>x=y</math>.
<math>|x-z|\le|x-y|+|y-z|</math> (triangle inequality); in the case of the absolute difference, equality holds if and only if <math>x\le y\le z</math> or <math>x\ge y\ge z</math>.
By contrast, simple subtraction is not non-negative or commutative, but it does obey the second and fourth properties above, since <math>x-y=0</math> if and only if <math>x=y</math>, and <math>x-z=(x-y)+(y-z)</math>.
When it is desirable to avoid the absolute value function – for example because it is expensive to compute, or because its derivative is not continuous – it can sometimes be eliminated by the identity
Шаблон:Bi
This follows since <math>|x-y|^2=(x-y)^2</math> and squaring is monotonic on the nonnegative reals.