I came across the following problem in my self-study of real analysis:

For any real numbers $a$ and $b$, show that $$\max \{a,b \} = \frac{1}{2}(a+b+|a-b|)$$ and $$\min\{a,b \} = \frac{1}{2}(a+b-|a-b|)$$

So $a \geq b$ iff $a-b \ge0$ and $b \ge a$ iff $b-a \ge 0$. At first glance, it seems like an average of distances. For the first case, go to the point $a+b$, add $|a-b|$ and divide by $2$. Similarly with the second case.

Would you just break it up in cases and verify the formulas? Or do you actually need to come up with the formulas?


How can you come up with the formulas if they're already given? :)

Yes, you're right, it is a good idea to look at this formula as strongly related to an average. I find it more intuitive to look at it as $$\max{\{a,b\}} = \frac{a+b}{2} + \frac{|a-b|}{2},$$ so go to the midpoint of $a$ and $b$ and add half the distance $|a-b|$ between them to get to the larger among them. Similarly for the second formula.

Yes, the proof is probably easiest if you break it into the two cases you suggest and use the definition of the absolute value.

  • $\begingroup$ So we wan modify this for any $n$. In particular, for $n=3$, $\max \{a,b \} = \frac{a+b}{3} + |a-b|$ and $\min \{a,b \} = \frac{a+b}{3} - |a-b|$? $\endgroup$ – Damien Jun 22 '11 at 17:38
  • $\begingroup$ Bueler: Can we instead start at $\frac{a+b}{3}$ and get to $\max \{a,b \}$? In other words, do we have to choose the midpoint? $\endgroup$ – Damien Jun 22 '11 at 17:47
  • $\begingroup$ @Damien: (this was addressing the previous version of your comment) No, the formula you're suggesting is wrong: Take $a = 0$ and $b=6$, for instance. Your formula gives $8$. In my answer I just rewrote your formula $$\frac{1}{2}(a+b+|a-b|) = \frac{1}{2}(a+b) + \frac{1}{2}|a-b|.$$ $\endgroup$ – t.b. Jun 22 '11 at 17:47
  • $\begingroup$ In other words, suppose someone told me to come up with a formula for $\max \{a,b \}$. Can I start at $\frac{a+b}{3}$ and get to the maximum also? Or is $\frac{a+b}{2}$ the only option. $\endgroup$ – Damien Jun 22 '11 at 17:50
  • $\begingroup$ @Damien: But what meaning does $\frac{a+b}{3}$ have? The formula you doesn't work so simply, consider what happens when you replace $a$ by $-a$ and $b$ by $-b$? The case "$n=2$" is simpler becuase the midpoint of $-a,-b$ is $-$ the midpoint of $a,b$. $\endgroup$ – t.b. Jun 22 '11 at 17:51

The formulas can be thought of in geometric terms. First you know that the distance between the points $a, b$ is just the absolute value of their difference, that is $d = |a - b|$. Now, the midpoint between $a, b$ is just $\frac{a+b}{2}$. Then each formula just tells you the following:

  1. To get the maximum $\max{(a, b)}$ you step on the midpoint $\frac{a+b}{2}$ and then "walk" half the distance between them on the positive direction on real line, that is, you add $\frac{|a-b|}{2}$ so you get $$\max{(a, b)} = \frac{a+b + |a-b|}{2}$$
  2. To get the minimum $\min{(a, b)}$ you would do the same thing, but you would "walk" now in the negative direction, so you would subtract $\frac{|a-b|}{2}$ to get now $$\min{(a, b)} = \frac{a+b - |a-b|}{2}$$

I know this is a little bit late, but here another way to get into that formula.

If we want to know $\min(a,b)$ we can know which is smaller by taking the sign of $b-a$. The sign is defined as $sign(x)=\frac{x}{|x|}$ and $msign(x)=\frac{sign(x)+1}{2}$ to get the values $0$ or $1$; if $msign(a-b)$ is $1$ it means that $a$ is bigger, if it is $0$, $a$ is smaller. To get the minimum value, we need to sum all values that $sign(x-y)$ is $1$ (which means that $x$ is bigger than $y$) for $y=a$ and $x=b$. So we have

$$\min(a,b)=msign(b-a)a+msign(a-b)b$$ and $$\max(a,b)=msign(a-b)a+msign(b-a)b$$

and simplifying

$$\min(a,b)=\frac{1}{2}\left(a+b-|a-b|\right)$$ $$\max(a,b)=\frac{1}{2}\left(a+b+|a-b|\right)$$

All this come from this equations:

$$\min(a,b)= \begin{cases} a & msign(a-b)==0\\ b & msign(a-b)==1 \end{cases} $$

$$\max(a,b)= \begin{cases} a & msign(a-b)==1\\ b & msign(a-b)==0 \end{cases} $$


It is easy once you realize that always

$$a+b=max+min$$ because you are adding the smallest and the largest if you add both and $$|a-b|=max-min$$ because you calculate the distance by taking the largest and subtracting the smallest.

To compute the formula given, you just add or subtract the two equations.


protected by user223391 Mar 16 '18 at 16:43

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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