What's the property of $g$ necessary and sufficient to commute with $\sup$? I asked myself the following question:
Does it hold that $\left ( \sup_x |f(x)|\right)^2 = \sup_x |f(x)|^2$.
The answer in this case is: yes. Then I went on to wonder what the defining property of square is that makes it commute with $\sup$. My first thought was continuity but I'm not so sure. For example, if one drops the absolute value then it does not hold anymore. So, my question is: For what functions $g: \mathbb R \to \mathbb R$ does it hold that 
$$ g(\sup_x f(x)) = \sup_x g(f(x))$$?

The property does not depend on $f$ much, the only input we get from $f$ is the set of all of its values, i.e., the range. Let's denote this set by $E$ and forget about $f$. What properties of $g$ ensure $g(\sup E) = \sup g(E)$, you ask? 
Trying two-point sets $E=\{a,b\}$, we discover that $g$ needs to be increasing (not necessarily strictly). 
Trying a set of the form $E=(a,b)$, we discover the need for $g(b)=\lim_{x\to b^-}g(x)$. That is, $g$ must be continuous from the left. 
Conversely, if $g$ is increasing and continuous from the left, then $g(\sup E) = \sup g(E)$ holds for every $E\subset \mathbb R$. This isn't hard to prove: if $\sup E\in E$,  then you don't even use left-continuity, but if  $\sup E\notin E$, it comes into play.
