$f:\mathbb{R}\rightarrow\mathbb{R}$ be continuous function such that $f\circ f=f.$ Lt $f:\mathbb{R}\rightarrow\mathbb{R}$ be continuous function such that $f\circ f=f.$ I like to prove that if $f$ is non constant function then $f(x)=x$ i.e. $f$ is identity function. I think to prove it it is sufficient to prove that $f $ is one one function as in that case if $f(x)\neq x $ for some $x$ then $f(f(x))\neq f(x)$ which gives a contradiction. So how to prove that it is one one? Please help. Thanks a lot.
 A: This sort of problem is discussed in linear algebra, where a linear map $f$ between vector spaces is called a projection if $f\circ f = f$. Examples in linear algebra of such functions are like $\pi_1:\mathbb{R}^2\to\mathbb{R}^2$ defined by $\pi_1(x,y) = (x,0)$. So, we see that functions that behave as you want move points into an image and once they are there, they stay there no matter how many times you apply $f$. This is formulated in the following way:
Claim: If $x$ is in the range of $f$, then $f(x) = x$.
Proof: If $x$ is in the range of $f$, then there is a point $x'$ such that $f(x') = x$. Then we see that $$f(x) = f(f(x')) = (f\circ f)(x') = f(x') = x,$$
which is what we wanted to show. $\blacksquare$ 
So, we see that if $f$ has range $R \subset \mathbb{R}$, then $f$ restricted to $R$ is the identity function. However, outside $R$ $f$ can do anything as long as it maps into $R$. Note that all such functions $f$ have to have this property and that if a function has this property then $f\circ f = f$. So, we get the following, which is formulated above in another response.
Theorem: Let $f:X\to X$. Then $f$ restricted to its range is the identity function if and only if $f \circ f = f$.
A: In general, if there exists a subset $X\subset\mathbb{R}$ such that


*

*$f(x) = x$ for all $x\in X$,

*$f(\mathbb{R})\subseteq X$, i.e. the range of $f$ is contained in $X$,


then $f\circ f = f$. If, furthermore, $X\ne\mathbb{R}$, then it is impossible for $f$ to be the identity function.
An example of a continuous nonconstant function satisfying the above two properties is $f(x) = |x|$ (with $X = [0,\infty)$), but for nice enough subsets $X$ you can play around and generate more functions like this by following the above two rules.
A: You have that $f:\mathbb{R}\to\mathbb{R}:x\mapsto |x|$ it is continuous, and $f\circ f=f$, it is not constant, and $f\neq \mbox{id}_\mathbb{R}$.
