# Inverse image of composite function

There's a nice proof of the theorem about composite functions (see theorem 5 here) that states

$$(g\circ f)^{-1}=f^{-1}( g^{-1})$$

Notice that $f^{-1}$ means the inverse of $f$. Could anyone help me with proving similar equality for preimages?

The preimage of a function is defined as $f^{-1}[Y]=\{x \in X | f(x) \in Y\}$.

Let $f: X \to Y$ and $g: Y \to Z$. The theorem states that for every subset $S \subseteq Z$:

$$(g\circ f)^{-1}[S]=f^{-1}(g^{-1}[S])$$

So the thing is to show that two sets above are equal.

My attempt would be:

Let $M=(g\circ f)^{-1}[S] = \{x\in X | g(f(x))\in S\}$.

then $g^{-1}[S]$ is a set $G=\{y\in Y | g(y))\in S\}$, and $f^{-1}(g^{-1}[S])=\{x\in X | f(x) \in G\}$.

I'm not sure how to proceed with it next.

In general: $$x\in h^{-1}(S)\iff h(x)\in S$$ So the following statements are equivalent:
• $x\in(g\circ f)^{-1}(S)$
• $(g\circ f)(x)\in S$
• $g(f(x))\in S$
• $f(x)\in g^{-1}(S)$
• $x\in f^{-1}(g^{-1}(S))$
This shows that $$(g\circ f)^{-1}(S)=f^{-1}(g^{-1}(S))$$