Solution to puzzle 160: Absolute maximum
The absolute value of a real number is defined as its numerical value without regard for sign. So, for example, abs(2) = abs(−2) = 2.
The maximum of two real numbers is defined as the numerically bigger of the two. For example, max(2, −3) = max(2, 2) = 2.
- abs in terms of max
- max in terms of abs
- By inspection, abs(x) = max(x, −x).
- To express max(x, y) in terms of abs function(s), consider x and y positioned on the real number line.
The midpoint of the line is ½(x + y).
To obtain max(x, y), we then need to add half the length of the line segment connecting x and y; that is, we must add ½(abs(x − y)).
Hence max(x, y) = ½(x + y + abs(x − y)).
Source: Puzzle: an absolute reader maximum conundrum
Back to top