# Show $\max{\{a,b\}}=\frac1{2}(a+b+|a-b|)$

I am tasked with showing that

If $a,b\in \mathbb{R}$, show that $\max{\{a,b\}}=\frac1{2}(a+b+|a-b|)$

I think I can say "without loss of generality, let $a<b$." Then $b-a>0$ But also, $$\max{\{a,b\}}=b=\frac1{2}a+\frac1{2}b-\frac1{2}a+\frac1{2}b$$ $$=\frac1{2}(a+b-a+b)$$ $$=\frac1{2}(a+b+(-a+b))$$ $$=\frac1{2}(a+b+|b-a|)$$ $$=\frac1{2}(a+b+|a-b|)$$

Is this valid? Does the proof (if valid) work the same way for the $\min$ function?

• If you don't believe yourself, just think of it this way: there are two cases, $a<b$ and $a>b$. In both cases, does the left-hand side of the equation equal the right-hand side? – angryavian Feb 22 '14 at 1:35
• The validity of using "without loss of generality" depends on what you consider to be "obvious". If you think $|a - b| = |b - a|$ to be obvious, then yes. – dani_s Feb 22 '14 at 1:37

There are $3$ separate cases you must cover.

1. $a \lt b$

2. $a = b$ and

3. $a \gt b$

You've covered (1). But this is just one possibility. You must also show that the equality holds for $a = b$. Again, would not be too difficult. And you can argue that case (3) can be shown pretty much the same way as the first one.

The fallacy in the logic is this: "Not all real numbers are such that $a \lt b$ and you are required to prove the identity for every real number"

• I know that showing $a<b$ and $b<a$ are basically the same. Can't I just show one and infer the proof is the same for the other case? – Faffi-doo Feb 22 '14 at 1:45
• @Faffi-doo: Yeah absolutely. You've shown one case. Just mention "the case for $a \gt b$ can be shown in a similar way". No one requires you to write pretty much the same arguments repeatedly. If you want to be fancy use the phrase "mutatis mutandis".. – Ishfaaq Feb 22 '14 at 1:50

Here is another approach:

$\max(x,y)+\min(x,y) = x+y$, and $\max(x,y)-\min(x,y) = |x-y|$.

Adding/subtracting gives $\max(x,y) = {1 \over 2}(x+y+|x-y|)$, $\min(x,y) = {1 \over 2}(x+y-|x-y|)$

• Great answer. I can never remember the formula for max and min, but the equalities you wrote are more evident to me. – André 3000 Feb 22 '14 at 2:38

The "without loss of generality $a<b$" assumes we know that $|a-b|=|b-a|$. I would usually skip that, but not if the topic of discussion is the $|\cdot|$ absolute value function itself.

You also need to cover the case $a=b$.

• i was under the impression that "without loss of generality" means we don't need to do both $a<b$ and $b<a$. And for $a=b$, that proof is trivial, right (just substitute $a$ for $b$ and cancel revealing $a$), but it just needs to be shown for completeness? – Faffi-doo Feb 22 '14 at 1:39
• To invoke WLOG, the situation must be exactly the same if you swap variables (or replace something with its negative, or whatever cases you're "combining"). E.g. if you're trying to show $a-b$ is a factor of $a^2-b^2$, you can't just say WLOG $a<b$. But in your problem, since $|a-b|=|b-a|$, swapping the variables does end up with the exact same equation. – aschepler Feb 22 '14 at 2:35
• @Faffi-doo You can only use "WLOG" if the expression in question is symmetric in $a$ and $b$, meaning swapping them doesn't change it. This is only true in your case because $|a-b| = |b-a|$, as aschepler says. – André 3000 Feb 22 '14 at 2:36

$$max(a,b) = \frac 1 2 (a + b + |a - b|)$$ $$\text{if}(a \ge b, a, b) = \frac 1 2 (a + b + \text{if}(a - b \ge 0, a - b, -(a - b))$$

$$\text{if}(a \ge b, a, b) = \frac 1 2 (a + b + \text{if}(a \ge b, a - b, b - a))$$

$$\text{if}(a \ge b, a, b) = \text{if}(a \ge b, \frac 1 2 (a + b + a - b), \frac 1 2 (a + b + b - a))$$

$$\text{if}(a \ge b, a, b) = \text{if}(a \ge b, a, b)$$