TITLE: $f$ continuous on $(a,b)$ and $|f|$ differentiable on $(a,b)$; is $f$ differentiable in $(a,b)$?
QUESTION [10 upvotes]: Let $f:(a,b) \to \mathbb R$ be a continuous function such that $|f|$ is differentiable in $(a,b)$ ; then is $f$ differentiable in $(a,b)$ ?

REPLY [2 votes]: Let's write $g(x)=\left|f(x)\right|$ to save typing.
First, let us get rid of the easy case: If $f(x_0)\ne 0$, then due to continuity, there's an open interval $I$ around $x_0$ such that $f(x)\ne 0$ for any $x\in\mathbb I$. Since $f(x)$ is real, this implies either $f(x)=g(x)$ or $f(x)=-g(x)$ for all $x\in I$; in both cases $f$ is obviously differentiable in $x_0$.
So let's now consider the case $f(x_0)=0\iff g(x_0)=0$.
We know by definition that $g(x)\ge 0$, and $g(x)$ is differentiable by assumption. We will now show that for any $x_0$ with $g(x_0)=0$ we also have $g'(x_0)=0$:
On one hand,
$$g'(x_0) = \lim_{x\to x_0+0}\frac{g(x)-g(x_0)}{x-x_0} = \lim_{x\to x_0+0}\frac{g(x)}{x-x_0}$$
Now since $g(x)\ge 0$, for $x>x_0$, clearly $\frac{g(x)}{x-x_0}\ge 0$ and thus $g'(x_0)\ge 0$.
On the other hand,
$$g'(x_0) = \lim_{x\to x_0-0}\frac{g(x)-g(x_0)}{x-x_0} = \lim_{x\to x_0-0}\frac{g(x)}{x-x_0}$$
The analogous argumentation as above gives $g'(x_0)\le 0$. Therefore $g'(x_0)=0$.
Now
$$\lim_{x\to x_0} \frac{f(x)-f(x_0)}{x-x_0} = \lim_{x\to x_0}\frac{f(x)}{x-x_0}$$
Consider any sequence $(x_n)$ converging to $x_0$. Then obviously
$$\frac{-g(x_n)}{x_n-x_0} \le \frac{f(x_n)}{x_n-x_0} \le \frac{g(x_n)}{x_n-x_0}$$
But the left and right side both converge to $0$, and thus does also the sequence in the center. Since this holds for any $(x_n)$, it follows that also
$$\lim_{x\to x_0}\frac{f(x)}{x-x_0}=0$$
in other words, $f'(x_0)$ exists and is $0$.