Absolute difference

From HandWiki
Short description: Absolute value of (x - y), a metric
Showing the absolute difference of real numbers [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math] as the distance between them on the real line.

The absolute difference of two real numbers [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math] is given by [math]\displaystyle{ |x-y| }[/math], the absolute value of their difference. It describes the distance on the real line between the points corresponding to [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math]. It is a special case of the Lp distance for all [math]\displaystyle{ 1\le p\le\infty }[/math] and is the standard metric used for both the set of rational numbers [math]\displaystyle{ \Q }[/math] and their completion, the set of real numbers [math]\displaystyle{ \R }[/math].

As with any metric, the metric properties hold:

  • [math]\displaystyle{ |x-y|\ge 0 }[/math], since absolute value is always non-negative.
  • [math]\displaystyle{ |x-y|= 0 }[/math]   if and only if   [math]\displaystyle{ x=y }[/math].
  • [math]\displaystyle{ |x-y|=|y-x| }[/math]     (symmetry or commutativity).
  • [math]\displaystyle{ |x-z|\le|x-y|+|y-z| }[/math]     (triangle inequality); in the case of the absolute difference, equality holds if and only if [math]\displaystyle{ x\le y\le z }[/math] or [math]\displaystyle{ 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]\displaystyle{ x-y=0 }[/math] if and only if [math]\displaystyle{ x=y }[/math], and [math]\displaystyle{ x-z=(x-y)+(y-z) }[/math].

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

[math]\displaystyle{ |x-y|\lt |z-w| }[/math] if and only if [math]\displaystyle{ (x-y)^2\lt (z-w)^2 }[/math].

This follows since [math]\displaystyle{ |x-y|^2=(x-y)^2 }[/math] and squaring is monotonic on the nonnegative reals.

See also

  • Absolute deviation