Find all differentiable functions $f$ such that $f\circ f=f$

I want to find all differentiable functions $f:\mathbb R \to \mathbb R$ such that $f\circ f=f$,

My attempt since $f$ is differentiable, $f'(f(x))f'(x)=f'(x)$ Now if $f'(x)\neq0$($f'=0$ means constant and they satisfy) then $f'(f(x))=1$, so we are looking for functions which satisfy $f'(f(x))=1$, How to proceed in this case? ($f(x)=x$ is also an obvious solution)

• Just in case someone finds this interesting: other (even discontinuous) solutions can also be characterized. Choose a subset $A\subseteq R$ and let $f(x)=x$ for $x\in A$ and for $x\notin A$ let $f(x)\in A$ be completely arbitrary. This is then a solution and every solution is of this form. – Dejan Govc Apr 18 '13 at 11:39

The only solutions are constants and $f(x)=x$.
Suppose $f$ isn't a constant. Let $X = f(\mathbb{R})$. $f$ is continuous, therefore $X$ is connected. Also, it is easy to see that $f(y)=y$ for all $y \in X$.
Let $x_0 = \inf X$. Suppose that $x_0 \neq - \infty$. From the above it is clear that $f(x_0 + \varepsilon) = x_0 + \varepsilon$ for all sufficiently small positive $\varepsilon$. From continuity we also have $f(x_0)=x_0$, so $x_0$ is in fact the minimum of $f$.
Now, on the one hand we see that $f'(x_0)=1$, and on the other hand $f'(x_0)=0$ by Fermat's theorem. This contradiction shows that $\inf X = -\infty$. In a similar fashion $\sup X = +\infty$, and therefore $X = \mathbb{R}$, which implies that $f(x)=x$ everywhere.
• Why $f(y) = y$ for $y \in X$? – marmistrz Feb 28 '16 at 16:47
• @marmistrz Because if $y \in X$, then $y = f(x)$ for some $x \in \mathbb{R}$, and therefore $f(y) = f(f(x)) = (f \circ f)(x) = f(x) = y$. – Dan Shved Feb 29 '16 at 8:49