# 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?

The functions $$f(z) = 1/z$$ and $$g(z) = 1 - z$$ are both linear fractional transformations; that is, they have the form $$\frac{az + b}{cz + d}$$ for suitable complex numbers $$a, b, c, d$$ such that $$ad - bc \neq 0$$. Linear fractional transformations are invertible functions acting on the Riemann sphere $$\mathbb{CP}^1 = \mathbb C \cup \{\infty\}$$, and this action is sharply $$3$$-transitive: given any three distinct points $$a, b, c \in \mathbb{CP}^1$$, there exists a unique linear fractional transformation sending (for example) $$0$$ to $$a$$, $$1$$ to $$b$$, and $$\infty$$ to $$c$$.
What this uniqueness means for you is that in order to check whether any composition of $$f$$'s and $$g$$'s is the identity, it suffices to evaluate it on the three points $$z = 0, 1,$$ and $$\infty$$. Notice that both $$f$$ and $$g$$ happen to permute these three points: \begin{align*} f(0) = \infty, f(1) = 1, f(\infty) = 0, \\ g(0) = 1, g(1) = 0, g(\infty) = \infty. \end{align*} Both of these permutations are transpositions, and their composition (in either order) is a $$3$$-cycle. It follows that both $$fgfgfg$$ and $$gfgfgf$$ act as the identity on the set $$\{0, 1, \infty\}$$, and therefore also on all of $$\mathbb{CP}^1$$.
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.