# If $(f ∘ f)$ is differentiable, is $f$ also differentiable?

Question:

If $(f \circ f)$ is differentiable on $\mathbb R$, then $f$ is differentiable on $\mathbb R$.

Is this statement true or false and why?

I have had a look at this question and really can't get my head around it.

I have thought that it is False, because if we let $f(x) = 2$, $(f\circ f)$ can't be defined as $(f(f(2))$ doesn't exist. So the statement would be false as we can't define $(f\circ f)$ so it can't be differentiable on $\mathbb R$.

Is this way of looking at it right or not?

• That's certainly not the right way of looking at it. Indeed, $f(x) =$ any integer $= 2$ doesn't really even make sense. – John Hughes Dec 17 '17 at 12:20
• yes it does. If we let f(x) = 2, then what is (fof)(x)?? – The Statistician Dec 17 '17 at 12:21
• If $f(x)=2$, then $f\circ f(x)=f(f(x))=f(2)$. Where is the problem? – Mundron Schmidt Dec 17 '17 at 12:24
• If $f(x) = 2$ for all real numbers $x$, then $(f \circ f)(x) = f(f(x)) = f(2) = 2$ for all $x$. – littleO Dec 17 '17 at 12:27
• Well...it was the " $=$ any integer $= 2$ " that didn't make sense; when you edit out the nonsense, it becomes fine. Carry on! – John Hughes Dec 17 '17 at 12:45

There is a very simple counterexample. Consider $$f(x)=\begin{cases}2 & x\geq 0\\1 & x<0\end{cases}$$ which is not differentiable (not even continuous) at $0$ but $f\circ f\equiv 2$ is constant, so differentiable on $\mathbb R$.

• If we want to see that this is still false even if $f$ is assumed to be continuous, we can use the same strategy of "choose $f$ so that it behaves well on its image" to come up with examples like $f(x)=\begin{cases}-x & x\leq 0 \\ x^2 & x\geq 0\end{cases}$. – Milo Brandt Dec 17 '17 at 17:05

We can do even better than Mundron Schmidt's counterexample. For example, the Dirichlet function: $$f(x) = \begin{cases}1 & \text{if } x \in \mathbb Q \\ 0 & \text{if } x \notin \mathbb Q\end{cases}$$ is discontinuous (and thus non-differentiable) everywhere on $\mathbb R$, but $f \circ f$ is constant.

A slight modification will also provide a counterexample such that $(f \circ f)' \ne 0$. For example, the function: $$g(x) = \begin{cases}\phantom{+}x & \text{if } x \in \mathbb Q \\ -x & \text{if } x \notin \mathbb Q\end{cases}$$ is discontinuous almost everywhere on $\mathbb R$ (except at the origin), while $g \circ g$ is the identity function (and thus $(g \circ g)' = 1$). Or, for a counterexample that's truly discontinuous everywhere, we could instead pick, say: $$h(x) = \begin{cases}-x & \text{if } x \in \mathbb Q \\ 1/x & \text{if } x \notin \mathbb Q\end{cases}$$ which also satisfies $(h \circ h)(x) = x$.

Your assumption that the statement is false is correct, but your argument is wrong. With $f(x)=2$ you certainly can form $f\circ f$: $$(f\circ f)(x) = f(f(x)) = f(2) = 2$$ Indeed, whenever the range if $f$ is a subset of its domain, $f\circ f$ can be formed.

Also, besides your wrong argument, $f(x)=2$ isn't a valid counterexample, as it is a differentiable function, with $f'(x)=0$. Any valid counterexample to the claim involves a non-differentiable function.

A list of valid counterexamples has already been given by Mundron Schmidt and Ilmari Karonen.

Let $$f(x)=\begin{cases}1&\text{if } x=2 \\ 0 & \text{otherwise}\end{cases}$$ then $$f(f(x))=0$$ is differentiable, although $f$ is not at $x=2$.

For $f$ being the Dirichlet's function: $$f(x)=\begin{cases}1&\text{if } x\in\mathbb Q \\ 0 & \text{otherwise}\end{cases}$$ you have $$f(f(x))=1$$ differentiable, although $f$ is not differentiable, and even not continuous anywhere.