what function fulfills these conditions? So I know that if $f(x) = x^{-1}$, than $f(f(x)) = x$ but $f(x)$ is not necessarily $x$. So now, is there $g(x)$ such that $g(g(x)) \neq g(x) \neq x$ but $g(g(g(x))) = x$? If so what is it, else why not?
 A: Think about rotation about the origin by $120$ degrees. In the complex plane, consider $f$ defined by $f(z) = z e^{\frac{2\pi}{3}i}$. Then, clearly, $f^2(z)$, $f(z)$, and $z$ are all distinct, unless $z \neq 0$. However, $f^3(z) = z e^{2\pi i} = z$.
A: If you allow $g\colon \mathbb{C}\to\mathbb{C}$, then $g(z)=ze^{\frac{2pi i}{3}}$, a counter-clockwise rotation by $2\pi/3$ in the complex plane, satisfies your conditions. In that case $g(g(g(z)))=z$, but $g(g(z))\neq g(z)\neq z$ for $z\neq 0$.
This construction works for other values as well:


*

*$f_2(z)=ze^{\frac{2\pi i}{2}}=-z$ is a rotation by $\pi$ with $f(f(z))=z$.

*$f_4(z)=ze^{\frac{2\pi i}{4}}=iz$ is a rotation by $\pi/2$ with $f(f(f(f(z))))=z$.

*$f_5(z)=ze^{\frac{2\pi i}{5}}$ is a rotation by $2\pi/5$ with $f(f(f(f(f(z)))))=z$.

*etc.


It's worth mentioning that the listed functions aren't the only possibilities. For example, $f_4(z)=-iz$ would have worked just as well, and you already gave a different example of $f_2$ in your question.
A: In general if you are considering linear functions from $\mathbb{R}^d$ to $\mathbb{R}^d$ which are diagonalizable, then if your linear transformation matrix is represented as $MDM^{-1}$ where $D$ is the diagonal matrix of eigenvalues, then your matrix will satisfy your constraints as long as $D$ has all third roots of unity some of which are not $0, \pm 1$.
