Let $f \colon \mathbb R^n \to \mathbb R^n$ be a smooth function, and it satisfies that $f \circ f = f$.
How to prove that $S := f(\mathbb R^n)$ is a smooth surface?
Here the definition of a surface is that each point $x$ in $S$ has a neighbourhood $U$ in $S$ that is homeomorphic to $\mathbb R^k$, and a smooth surface is the case when the isomorphism from $\mathbb R^k$ to $U$ is also smooth (of class $C^{(m)}$, $m > 0$).
Examples like identity and linear projections indicates that the rank of the Jacobian $f'$ defines the dimension of the surface. In fact, the derivative (Jacobian) of $f$ must satisfies: $$ f' f' = f', $$ and therefore becomes a projection from $T_x\mathbb R^n$ to $T_{f(x)} S$.
Let $g(x) := f(x) - x$, we can see that $g(x) = 0 \leftrightarrow x \in S$. But how to prove that $g$ has a rank $n - k$ at every point in $S$? I don't see the constance of rank.
The question comes from Zorich Mathematics Analysis Chapter 12, §1, and my notations follows the book.