Prove that $M = f(\mathbb{R}^{n})$ is a $C^{\infty}$ submanifold of $\mathbb{R}^{n}$ when $f \circ f = f$. 
Let $f: \mathbb{R}^{n} \to \mathbb{R}^{n}$ be a $C^{\infty}$ function such that $f\circ f = f$. Prove that $M = f(\mathbb{R}^{n})$ is a $C^{\infty}$ submanifold of $\mathbb{R}^{n}$.

Definition. A subset $M$ of $\mathbb{R}^{n}$ is a $C^{k}$ submanifold of dimension $m$ if for each $p \in M$ there is an open $U \ni p$ of $\mathbb{R}^{n}$ such that $V = U \cap M$ is the range of a $C^{k}$ parameterization of dimension $m$, that is, there is $\varphi: V_{0} \to V = U \cap M$, $C^{k}$, with $V_{0} \subset \mathbb{R}^{m}$
Definition A $C^{k}$ parameterization of dimension $m$ is a function $\varphi:V_{0} \to V$ with $V_{0} \subset \mathbb{R}^{m}$ such that $\varphi$ is a imersion and $\varphi$ is a homeomorphism.
Now, $f \circ f = f$ implies $Df_{f(p)}\circ Df_{p} = Df_{p}$. Since $\mathrm{rank}(A \circ B) \leq \min(\mathrm{rank}A,\mathrm{rank}B)$, $\mathrm{rank}Df_{p} \leq \mathrm{rank}Df_{f(p)}$.
My first attempt was to find a atlas for $M$. But cannot find the parameterizations.
My professor hint me to prove that the $\mathrm{rank}f$ is constant on $f(\mathbb{R}^{n})$. I did not try, but I suppose that I should fix a point $p$ and to use "clopen argument". The problem is: I donk know how to use it. Can someone help me?
 A: We can use the Constant Rank Theorem to tackle this problem. Note that each point in $f(\mathbb{R^n})$ is a fixed point of $f$. Suppose we have shown that the rank of $f$ is constant on its image (hint: $(df)_p$ is idempotent for $p \in f(\mathbb{R^n})$) and denote it by $r$.
Fix $p \in f(\mathbb{R^n})$ and let $U'$ be a small neighborhood. Denote by $U$ the connected component of $f^{-1}(U')$ containing $p$ ($p$ is a fixed point) so that $f(U) = U' \cap f(\mathbb{R^n})$.
Up to shrinking these neighborhoods if necessary, said Constant Rank Theorem provides us with diffeomorphisms $\phi \colon \mathbb{R^n} \rightarrow U$ and $\psi \colon V \rightarrow \mathbb{R^n}$, where $V$ is a neighborhood of $p$ with $f(U) \subset V$, such that $f = \psi \circ (df)_p \circ \phi^{-1}$ on $U$.
But $(df)_p$ is a linear map, so $(df)_p \circ \phi^{-1}(U)$ is a $r$-dimensional linear subspace of $\mathbb{R^n}$. Denote this subspace by $W$.
Then $U' \cap f(\mathbb{R^n}) = f(U) = \psi(W)$. Being the restriction of a diffeomorphism, $\psi|_W$ is your desired parametrization.
In particular, the dimension of $f(\mathbb{R^n})$ is the rank of $f$.
