# If $|f(x)|$ is a differentiable function, then $f(x)$ is also?

If $|f(x)|$ is a differentiable function, then $f(x)$ is also a differentiable function.

Why is this wrong? Can you find a counterexample please? It seems like a true sentence.

-

Just to give a very extreme example: let $f:\mathbb R \to \mathbb R$ be given by $f(x)=1$ if $x$ is rational and $f(x)=-1$ if $x$ is irrational. Then $|f|$ is constantly $1$, thus differentiable (as many times as you want). But $f$ is not continuous at any point and thus can't be differentiable.

-

$$f(x)=\begin{cases} 1,&\text{if }x\ge 0\\ -1,&\text{if }x<0\;? \end{cases}$$

-

If $f$ is not continuous, then $\left|f\right|$ may be continuous and even differentiable as pointed out by Brian. Suppose $f$ is continuous at $a$ and $\left|f(x)\right|$ is differentiable at $a$. Then, $$\lim_{x\to a}\frac{\left|f(x)\right|-\left|f(a)\right|}{x-a}=L\in \mathbb{R}$$ If $f(a)>0$ by continuity, $f(x)>0$ near $a$ and so $$\lim_{x\to a}\frac{f(x)-f(a)}{x-a}=L\in \mathbb{R}$$ and $f$ is differentiable at $a$. Similarly if $f(a)<0$.

If $f(a)=0$ then $$\lim_{x\to a}\frac{\left|f(x)\right|}{x-a}=L\in \mathbb{R}$$ As Robert said in the comments, $$L=\lim_{x\to a^+}\frac{\left|f(x)\right|}{x-a}\ge 0$$ while $$L=\lim_{x\to a^-}\frac{\left|f(x)\right|}{x-a}\le 0$$ and so $L=0$. Therefore, $$\lim_{x\to a^+}\left|\frac{f(x)}{x-a}\right|=0\implies \lim_{x\to a^+}\frac{f(x)}{x-a}=0$$ while $$\lim_{x\to a^-}\left|\frac{f(x)}{x-a}\right|=0\implies \lim_{x\to a^-}\frac{f(x)}{x-a}=0$$ and so $f$ is differentiable at $0$.

Moral: If $f$ is discontinuous then $\left|f\right|$ may be differentiable. If $f$ is continuous and $\left|f\right|$ is differentiable then $f$ is differentiable as well

-
What counter-example? Since $\dfrac{|f(x)|}{x-a} \ge 0$ for $x > a$ and $\le 0$ for $x < a$, if $\displaystyle \lim_{x \to a} \frac{|f(x)|}{x-a}$ exists, it must be $0$. And then this is also $\displaystyle \lim_{x \to a} \frac{f(x)}{x-a}$. – Robert Israel Dec 28 '12 at 9:52
@RobertIsrael Right – Nameless Dec 28 '12 at 9:54