How does one DERIVE the formula for the maximum of two numbers [duplicate]
Andrew Mclaughlin
I want to derive (not prove that this is true) the formula
$\max (x,y) = \dfrac{x + y + |y-x|}{2}$
I was reading a proof (which they have the result ahead of time already) that we do cases and then we consider $x + y + |y - x|$. I am not sure how they first came up with $x + y + |y - x|$ in the first place
$\endgroup$ 62 Answers
$\begingroup$The value halfway between x and y is $$\frac{x+y}{2}.$$ If we want to add something to it to get to $\max \left( x,y \right)$, we would need to add the difference between $\max \left( x,y \right)$ and $\frac{x+y}{2}$. What is that value? well if $\max \left( x,y \right) = y$ then it is $$y- \frac{x+y }{2} = \frac{y-x }{2},$$ and if $\max \left( x,y \right) = x$ then it is $$x- \frac{x+y }{2} = \frac{x-y}{2}.$$
We know 2 things:
- $x-y$ and $y-x$ are the same up to a change of sign.
- the difference between the max and the middle is positive.
So,
$$\left| \frac{x-y}{2} \right|=\left| \frac{y-x}{2} \right|,$$
and whether $\max \left( x,y \right)$ is $x$ or $y$, you can add this amount to the value halfway between $x$ and $y$ to get $\max \left( x,y \right)$.
This gives you the formula:
$$\max \left( x,y \right) = \frac{x+y + \left| x-y \right|}{2}.$$
$\endgroup$ 4 $\begingroup$I expatiate on how this begets the formula for $\min(x,y) = -\max (-x,-y)$.
()
The smaller of the two numbers f and g is bigger when you reverse the sign. To recover the original number, one must again reverse the sign.
Videlicet, posit $y < x$. Ergo $\color{seagreen}{min(y, x) = y}$.
Modus operandi. Want $min(y, x) = y$ as a functin of $max(x,y)$.
$y < x \iff -y > -x$ ergo $-y$ is bigger. Ergo $max(-x, -y) = -y$.
To return to $\color{seagreen}{min(y, x) = y}$, reverse sign: $\color{magenta}{-}max(-x, -y) = \color{magenta}{-}-y$