Absolute difference

Showing the absolute difference of real numbers x and y as the distance between them on the real line.

The absolute difference of two real numbers x, y is given by |x  y|, the absolute value of their difference. It describes the distance on the real line between the points corresponding to x and y. It is a special case of the Lp distance for all 1 ≤ p ≤ ∞ and is the standard metric used for both the set of rational numbers Q and their completion, the set of real numbers R.

As with any metric, the metric properties hold:

By contrast, simple subtraction is not non-negative or commutative, but it does obey the second and fourth properties above, since xy = 0 if and only if x = y, and xz = (xy) + (yz).

The absolute difference is used to define other quantities including the relative difference, the L1 norm used in taxicab geometry, and graceful labelings in graph theory.

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

|xy| < |zw| if and only if (xy)2 < (zw)2.

This follows since |xy|2 = (xy)2 and squaring is monotonic on the nonnegative reals.

References