Solution (source code)

= Solution
{c}

Identify the bottom $j(X)=q(X\times\{0\})$ with $X$; its natural map $j$ is a <topological embedding>. To verify this directly, an <open subset> $O\subseteq X$ gives the saturated <open subset> $O\times[0,1/2)$ of the space before taking the <quotient topology>; its image is open in $M(f)$ and meets the bottom in $j(O)$.

Suppose first that there is a <retraction> $R:M(f)\to j(X)$. Define the <continuous map>
$$
g=j^{-1}Ri:Y\longrightarrow X.
$$
Then
$$
L(x,t)=j^{-1}R(q(x,t))
$$
is a <homotopy> with $L(x,0)=x$ and $L(x,1)=g(f(x))$. Hence $gf\simeq\operatorname{id}_X$.

Conversely, suppose a <continuous map> $g:Y\to X$ has $gf\simeq\operatorname{id}_X$. Reverse the parameter if necessary to choose a <homotopy> $L$ with $L(x,0)=x$ and $L(x,1)=gf(x)$. Set
$$
R(q(x,t))=j(L(x,t)),\qquad R(i(y))=j(g(y)).
$$
At the glued end, $j(L(x,1))=j(gf(x))$, exactly the value prescribed at $i(f(x))$. The <universal property of the quotient topology> therefore gives a <continuous map> $R:M(f)\to j(X)$. At the bottom, $R(j(x))=j(x)$, proving that $R$ is a <retraction>. We have established the <mapping-cylinder bottom retraction criterion>:
$$
\boxed{j(X)\text{ is a retract of }M(f)\iff\exists g:Y\to X\text{ continuous with }gf\simeq\operatorname{id}_X.}
$$