Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|cite|improve this question
the formalu $max(x,y)=x1_{x\ge y}+y1_{x<y}$, where $1_p=1$ when $p$ is correct, may help deriving it. – user59671 May 6 '13 at 1:40
@sizz : you start at the middle (average) and you go up or down as needed. – Stefan Smith May 6 '13 at 1:40
@StefanSmith there's no "down". Think of it as starting at the middle, and adding the difference between the middle and the max. – Alex L May 6 '13 at 1:42
Sorry guys, I have absolutely no idea what you guys are talking about "up" and "down". Feels like an elevator conversation I am reading – Hawk May 6 '13 at 1:47
@Alex L : I'm thinking of the positive direction as up and the negative direction as down, obviously. – Stefan Smith May 6 '13 at 20:44
up vote 10 down vote accepted

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:

  1. $x-y$ and $y-x$ are the same up to a change of sign.
  2. the difference between the max and the middle is positive.


$$\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}.$$

share|cite|improve this answer
Crazy question, but why do we start with "half way"? Why not consider (x + y)/3 or 2(x + y)/3 – Hawk May 26 '13 at 3:08
@sidht i want to know too. – Tucker Rapu Mar 7 '14 at 15:49
@TuckerRapu If you start halfway, then the amount you need to add is the same whichever of $x$ or $y$ is the max. If you don't start halfway, then the amount you need to add depends on $\max(x,y)$. – Alex L Mar 9 '14 at 10:29
@AlexL +Upvote yesterday. thank you. please add this to your answer? – Tucker Rapu Mar 9 '14 at 14:52

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$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.