TITLE: Continuity of $\max$ function
QUESTION [8 upvotes]: Given continuous functions $f,g: \mathbb{R} \to \mathbb{R}$, in order to prove that $ \max(f(x),g(x))$ is continuous, a standard trick is to rewrite it as a linear combination of continuous functions:
$$
\max(f(x),g(x)) = \frac{1}{2} (f(x) + g(x) + |f(x) - g(x)|   )
$$
Is there any sort of motivation for why one might come up with this particular combination of continuous functions? I can see that it works, but without knowing this fact beforehand , what might lead you to consider writing $ \max(f(x),g(x)  ) $ in the above manner?

REPLY [13 votes]: The following is an "abstract nonsense" answer to your question.
Given two real numbers $a$ and $b$ there is a quadratic equation having these two numbers as solutions, namely
$$(x-a)(x-b)=x^2-p x + q =0\ ,$$
where $p=a+b$ and $q=ab$. The two coefficients $p$ and $q$ encode the multiset $\{a,b\}$ in a reversible way, insofar as we can write
$$\{a,b\}=\left\{{p-\sqrt{p^2-4q}\over2},{p+\sqrt{p^2-4q}\over2}\right\}\ .$$
Now on the right side the two numbers appear  in increasing order. Therefore
$$\max\{a,b\}={1\over2}\left(p+\sqrt{p^2-4q}\right)={1\over2}\bigl(a+b+|a-b|\bigr)\ .$$