Prove that if $Z\subseteq Y$, then $(g\circ f)^{-1}(Z)=f^{-1}(g^{-1}(Z)).$ 
Let $W ,X$ and $Y$ be three sets and let $f :W \to X$ and $g: X \to Y$ be two functions. Consider the composition $g \circ f: W \to Y $ which, as usual, is defined by $(g\circ f)(w)=g(f(w))$ for $w \in W$.
$(a)$ Prove that f $Z\subseteq Y$, then $(g\circ f)^{-1}(Z)=f^{-1}(g^{-1}(Z)).$
$(b)$ Deduce that if $(W,c) ,(X,d)$ and $(Y,e)$ are metric spaces and the functions $f$ and $g$ are both continuous, then the function $g \circ f$ is continuous.

Definitions:

*

*Let $(X, d)$ and $(Y, e)$ be metric spaces, and let $x \in X$. A
function $f : X \to Y$ is continuous at $x$ if:
$\forall B \in \mathcal  B(f(x))  \exists  A \in \mathcal  B(x) : f(A) \subseteq B$
 A: Note that $f: X \rightarrow Y$ is continuous iff for for any open set $U \subseteq Y$, $f^{-1}(U)$ is open in $X$.
To prove $g \circ f$ is continuous, for any open set $U \subset Y$, we only need to prove $(g \circ f)^{-1}(U)$ is open in $W$.
To see this, as $(g \circ f)^{-1}(U)=f^{-1}(g^{-1}(U))$, and $g$ is continuous, we see
$g^{-1}(U)$ is open; as $f$ is continuous, then $f^{-1}(g^{-1}(U))$ is also open. 
A: The part (a) is not answered here - so let me include it, for the sake of completeness.$\newcommand{\inv}[1]{{#1}^{-1}}$
We want to show that $\inv{(g\circ f)}(Z)=\inv f(\inv g(Z))$. For any $w\in W$ we have:

*

*$w\in \inv{(g\circ f)}(Z)$ $\Leftrightarrow$ $(g\circ f)(w)\in Z$ $\Leftrightarrow$ $g(f(w))\in Z$

*$w\in \inv f(\inv g(Z))$ $\Leftrightarrow$ $f(w) \in \inv g(Z)$ $\Leftrightarrow$ $g(f(w))\in Z$
So we see that
$$w\in \inv{(g\circ f)}(Z) \Leftrightarrow w\in \inv f(\inv g(Z)),$$
which means that $\inv{(g\circ f)}(Z)=\inv f(\inv g(Z))$.

Proof of this can be found also in an answer to this question: Show that $(g \circ f)^{-1}(C) = g^{-1}(f^{-1}(C)).$ (Although the claim formulated in the title of that question is incorrect - notice the wrong order of $\inv g$ and $\inv f$.)
