Composition of Idempotent Mappings

Theorem
Let $S$ be a set.

Let $f, g: S \to S$ be idempotent mappings.

Suppose that $f \circ g$ and $g \circ f$ have the same images.

That is, suppose that $f(g(S))= g(f(S))$.

Then $f \circ g$ and $g \circ f$ are idempotent.

Proof
Let $x \in S$.

By the premise:


 * $f(g(x)) \in g(f(S))$.

Since $f(S) \subseteq S$:


 * $f(g(x)) \in g(S)$

Thus for some $y \in S$: $f(g(x)) = g(y)$.

Since $g$ is idempotent, $g(g(y)) = g(y)$.

By the choice of $y$:


 * $g(f(g(x))) = g(g(y)) = g(y) = f(g(x))$.

Thus $f(g(f(g(x)))) = f(f(g(x))) = f(g(x))$.

Therefore $f \circ g$ is idempotent.