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 \left({g \left({S}\right)}\right) = g \left({f \left({S}\right)}\right)$.

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

Proof
Let $x \in S$.

By the premise:


 * $f \left({g \left({x}\right)}\right) \in g \left({f \left({S}\right)}\right)$

Since $f \left({S}\right) \subseteq S$:


 * $f \left({g \left({x}\right)}\right) \in g \left({S}\right)$

Thus for some $y \in S$:
 * $f \left({g \left({x}\right)}\right) = g \left({y}\right)$

Since $g$ is idempotent:
 * $g \left({g \left({y}\right)}\right) = g \left({y}\right)$

By the choice of $y$:


 * $g \left({f \left({g \left({x}\right)}\right)}\right) = g \left({g \left({y}\right)}\right) = g \left({y}\right) = f \left({g \left({x}\right)}\right)$

Thus:
 * $f \left({g \left({f \left({g \left({x}\right)}\right)}\right)}\right) = f \left({f \left({g \left({x}\right)}\right)}\right) = f \left({g \left({x}\right)}\right)$

That is, $f \circ g$ is idempotent.