$f(f(x))=f(x)$ question I am wondering what is the class of functions $f: \mathbb{R}\rightarrow\mathbb{R}$ such that $f(f(x))=f(x)$?
I think it should be:


*

*Constant Value functions

*the identity function

*absolute value function $|x|$


But I don't know if this is right or how to show it rigorously.
Any suggestions?
 A: Here is a large family of such functions.  Choose any function $g(x)$, defined on $(-\infty,0)$, that satisfies $g(x)\ge 0$ for all negative $x$.  Then we define $$f(x)=\begin{cases} g(x) & x<0 \\ x & x\ge 0\end{cases}$$
The absolute value is an example from this family, corresponding to $g(x)=-x$.  But any function with that condition will do, such as $g(x)=x^2$ or $g(x)=\sqrt{-x}$ or $g(x)=e^x$ or $g(x)=1+\sin x$.
A: Such functions can be described in the following way:
If $A$ is an arbitrary subset of $\mathbb{R}$ and $g:\mathbb{R} \setminus A \mapsto A$ an arbitrary funtion. Define
$$
f(x) = \left\{ 
  \begin{array}{l l}
    x & \quad  \forall x\in A\\
    g(x) & \quad \forall x \not \in A
  \end{array} \right.
$$
$f$ has this idempotency property. 
Contrary for an $f$ with the idempotency property  such an $A$ and $g$ can be found: $A:=f(\mathbb{R})$ and $g:=f \rvert _{\mathbb{R}\setminus A}$
A: Put $f\left( \mathbb{R} \right) = U \ne \emptyset $, then $\forall y \in U$, we have $f\left( y \right) = y$ by $f\left( {f\left( x \right)} \right) = f\left( x \right)$. We can call $U$ a collection of fixed points of $f$.
If a funtion $g$ maps $\mathbb{R}-U$ to $U$, then it satisfies $g\left( {g\left( x \right)} \right) = g\left( x \right)$.
For example, $f\left( x \right) = \left| x \right|$, we get $U = \left[ {0, + \infty } \right)$, luckily, $f$ maps $\left( { - \infty ,0} \right)$ to $U$.
And, if $U$ has exactly one (fixed) point, say $c$, i.e. $f(c)=c$, then $f$ must maps $\left( { - \infty ,\infty } \right) - \left\{ c \right\}$ to $\{c\}$. That is, $f$ is a constant value function.
A: Assuming $f^{-1}$ exists,
$$f(f(x))=f(x)\\
\implies f^{-1}(f(f(x)))=f^{-1}(f(x))\\
\implies \boxed{f(x)=x}$$
This is the identity function, or, the inclusion map acting on $\mathbb{R}^1$.
