When $f(z) = 1/z$ and $g(z) = 1-z$, why is $f \circ g \circ f \circ g \circ f \circ g (z) = g \circ f \circ g \circ f \circ g \circ f (z) = z$? A recent contest question I was attempting involved a long string of repeated and random applications of the two complex functions $f(z) = 1/z \,$ and $\, g(z) = 1-z \,$ to an unknown complex number other than $0$ or $1$. Since $f$ and $g$ are obvious involutions, such a string could be reduced to a string of alternating applications of $f$ and $g$.
When I started to analyze such a string, I quickly came across the following:
$$f \circ g \circ f \circ g \circ f \circ g \, (z) = g \circ f \circ g \circ f \circ g \circ f \, (z) = z$$
This may be a well-known property of these two functions, but I'd never come across it before and I was quite surprised by it, in particular that it took three iterations of each to become an identity - somehow I think I would have been less surprised if it had taken two or four iterations.
The algebra is quite straightforward; it's easy to see that applying the first of the two above compositions gives
$$z \to \frac{1}{z} \to \frac{z-1}{z} \to \frac{z}{z-1} \to \frac{1}{1-z} \to 1-z \to z$$
and that the second gives the same chain in reverse. However, this gave me no insight into why three is the magic number.
I tried looking at this geometrically, but my complex geometry is admittedly pretty weak. As best as I could see, $f(z)$ reflects a point in the real axis and then inverts the image in the circle $r=1$; and $g(z)$ reflects a point in the line $x=\frac{1}{2}$ and then reflects the image in the real axis. Since for either function the order of the two transformations can be interchanged, when applying one function followed by the other the two reflections in the real axis would cancel each other out and result in an inversion in the circle $r=1$ followed by a reflection in the line $x=\frac{1}{2}$, or vice-versa. However, this did not help as I could not see why doing this three times would return a point to its original position. Even restricting to just real values didn't lead to any enlightenment as the transformations would still be essentially the same.
So, is there some not-too-complicated way to see why it is that three alternating iterations of each of these two functions is an identity?

In the same vein as Ravi Fernando, being linear fractional transformations, these functions have an associated matrix representation. The function $f(z)=\frac{az+b}{cz+d}$ is associated to the matrix $M_f:=\begin{pmatrix}a&b\\c&d\end{pmatrix}$, and you can then manually confirm that $M_{f\circ g}=M_f M_g$. Your two functions have the associated matrices
$$M_f=\begin{pmatrix}0&1\\1&0\end{pmatrix},~~M_g=\begin{pmatrix}-1&1\\0&1\end{pmatrix}.$$
Now you can simply calculate for yourself that $M_{f\circ g\circ f}$ and $M_{g\circ f\circ g}$ are inverses of each other, so $M_{f\circ g\circ f\circ g\circ f\circ g}=M_{g\circ f\circ g\circ f\circ g\circ f}=\operatorname{id}$. And the identity matrix is associated to the identity function.
