TITLE: Homotopy equivalence iff both spaces are deformation retracts
QUESTION [12 upvotes]: I'm trying to prove that 
$f: X \rightarrow Y$ is a homotopy equivalence $\iff$ $X$, $Y$ are both homeomorphic to a deformation retract of a space $Z$
The $\Leftarrow$ was not a problem. If both are deformation retracts it follows that $Z \simeq X$ and $Z \simeq Y$ and by transitivity $X \simeq Y$.
The first half of $\Rightarrow$ was also not a problem, because using the mapping cylinder $Z_f$ as their common super-space, $X \times I$ can be deformation-retracted down to $Y$ by the homotopy $(x,s,t)\mapsto (x,st)$, i.e. along a vertical line.
Now I'm stuck with the deformation retraction of $Z_f$ onto $X$. For example, do I construct a homotopy from $Z_f$ to $X \times I$ and then to $X$ or directly from $Z_f$ to $X$? I'm also not sure where to use $f \circ g \simeq id_Y$ and $g \circ f \simeq id_X$ and $id_{Z_f} \simeq i \circ r_Y$, where $r_Y$ is the retraction from $Z_f$ onto $Y$. 
I'm tempted to do something like this but it doesn't seem to lead anywhere: $i \circ r_Y \simeq id_Y \simeq f \circ g$.
Can someone help me finish this proof? I'd much appreciate any help!

REPLY [4 votes]: Ok, here is a proof taken from Lee's Introduction to topological manifolds pp. 207:
claim: $X \times [0,1]$ is a deformation retract of $Z_f$
proof:
(DEF) mapping cylinder $Z_f$
If $f: X \rightarrow Y$ is a continuous map then its mapping cylinder $Z_f$ is the space $X \times [0,1] \cup Y / \sim$ where $\sim$ identifies two points $x \in X$ and $y \in Y$ if $f(x) = y$.
(i) Let $r_Y$ be the retraction of $Z_f$ onto $Y$ in $Z_f$, $r_Y:Z_f \rightarrow Z_f$: $$\begin{array}{ccc} [x,s] & \mapsto & [x, 0] \\
                            [y] &   \mapsto & [y]    \\  
\end{array}$$
(ii) Let $h_1$ be a homotopy from $id_X$ to $r_Y$, $h_1: Z_f \times [0,1] \rightarrow Z_f$: $$\begin{array}{ccc} [x,s], t & \mapsto & [x, s(1-t)] \\
                            [y], t &   \mapsto & [y]    \\  
\end{array}$$
(iii) Let $F:Y \times [0,1] \rightarrow Y$ be the homotopy from $ f\circ g $ to $id_Y$
(iv) Let $G:X \times [0,1] \rightarrow X$ be the homotopy from $ g \circ f$ to $id_X$
(v) if $B: Z_f \rightarrow Z_f$ is the map
$$\begin{array}{ccc} [x,s] & \mapsto & [g(f(x)),0] \\
                            [y]&   \mapsto & [g(y),0]    \\  
\end{array}$$
then $h_2:Z_f \times [0,1] \rightarrow Z_f$ is a homotopy from $r_Y$ to $B$: $$\begin{array}{ccc} [x,s], t & \mapsto & [F(f(x), 1-t] \\
                            [y], t &   \mapsto & [F(y, 1 - t)]    \\  
\end{array}$$
(vi) and if $r_X: Z_f \rightarrow Z_f$ is the retraction of $Z_f$ onto $X$:
$$\begin{array}{ccc} [x,s], t & \mapsto & [G(x, s), 1] \\
                            [y], t &   \mapsto & [g(y), 1]    \\  
\end{array}$$
then $h_3: Z_f \times [0,1] \rightarrow Z_f$ is a homotopy from $B$ to $r_X$: $$\begin{array}{ccc} [x,s], t & \mapsto & [G(x, st), t] \\
                            [y], t &   \mapsto & [G(g(y), t)]    \\  
\end{array}$$
With $[f(x)] = [x,0]$ (because $[y] = [x,0]$ if $f(x) = y$) one sees that
$$ r_X \simeq B \simeq r_Y \simeq id_{Z_f}$$ where $B = h_2(.,1) = h_3(.,0)$.
Even given the proof it doesn't seem obvious to me. Particularly frustrating is that I think I'd be able to reconstruct it but it doesn't feel "natural" or intuitive.