Proof that retract of contractible space is contractible I'm reading Hatcher and I'm doing exercise 9 on page 19. Can you tell me if my answer is correct?
Exercise: Show that a retract of a contractible space is contractible.
Proof:
Let $X$ be a contractible space, i.e. $\exists f :X \rightarrow \{ * \}$,$g: \{ * \} \rightarrow X$ continuous such that $fg \simeq id_{\{ *\}}$ and $gf \simeq id_X$ and let $r:X \rightarrow X$ be a retraction of $X$ i.e. $r$ continuous and $r(X) = A$ and $r\mid_A = id_A$.
(Edited using Anton's answer)
Define $f^\prime := f\mid_A$ and $g^\prime := r \circ g$.
Now we need to show $f^\prime \circ g^\prime \simeq id_{ \{ * \} }$  and $g^\prime \circ f^\prime \simeq id_A$.
$f^\prime \circ g^\prime \simeq id_{ \{ * \} }$ follows from $f^\prime \circ g^\prime = id_{ \{ * \} }$ (because there is only one function $\{ * \} \rightarrow \{ * \}$).
From $gf \simeq id_X$ we have a homotopy $H: I \times X \rightarrow X$ such that $H(0,x) = g \circ f (x)$ and $H(1,x) = id_X$. From this we build a homotopy $H^\prime : I \times A \rightarrow A$ by defining $H^\prime := r \circ H \mid_{I \times A}$. Then $H^\prime (0,x) = g^\prime \circ f\mid_A (x)$ and $H^\prime (1,x) = id_A$.
I'm particularly dissatisfied with the amount of detail in my reasoning but I can't seem to produce what I'm looking for. Many thanks for your help!
 A: Your real questions have allready been answered. Here I give an alternative proof, demanding some familiarity with categories. It illustrates how convenient 'abstract nonsense' can be. I go out from retraction $r:X\rightarrow A$ and inclusion $i:A\rightarrow X$ with $ri=1$.
The contractible objects in category $\mathbf{Top}$ are exactly the
terminal objects in category $\mathbf{hTop}$. If $X$ is a terminal object in $\mathbf{hTop}$, then for every object $Y$ the 
homset $\mathbf{hTop}\left(Y,X\right)$ contains exactly one arrow.
Let us denote this arrow by $\left[c\right]$. Then homset $\mathbf{hTop}\left(Y,A\right)$
contains arrow $\left[r\right]\left[c\right]$. Now let $\left[f\right]\in\mathbf{hTop}\left(Y,A\right)$.
Then $\left[i\right]\left[f\right]\in\mathbf{hTop}\left(Y,X\right)$
so $\left[i\right]\left[f\right]=\left[c\right]$. Then we find $\left[f\right]=\left[r\right]\left[i\right]\left[f\right]=\left[r\right]\left[c\right]$
demonstrating that $\left[r\right]\left[c\right]$ is the only element
of $\mathbf{hTop}\left(Y,A\right)$. Proved is now that $A$ is terminal
in $\mathbf{hTop}$, hence contractible in $\mathbf{Top}$.

It can be done even shorter:
$\left[\right]:\mathbf{Top}\rightarrow\mathbf{hTop}$ is a functor
and functors respect retractions (=arrows that have a right-inverse). So if $r:X\rightarrow A$ is a retraction
in $\mathbf{Top}$ then $\left[r\right]:X\rightarrow A$ is a retraction
in $\mathbf{hTop}$.
If $\left[r\right]:X\rightarrow A$ is a retraction and
$X$ is terminal then $\left[r\right]$ is an isomorphism, hence $A$
is terminal. (This is true in every category, but to maintain the line of the proof I keep on using the notation $\left[r\right]$.)
Proof of that: some $\left[s\right]:A\rightarrow X$ exists with $\left[r\right]\left[s\right]=1$;
then $\left[s\right]\left[r\right]:X\rightarrow X$ and the identity
is the only endomorphism here, so $\left[s\right]\left[r\right]=1$.
A: You're glossing over the most important things. You are given the information that $X$ is contractible. This means that there exists a specific homotopy $H:I\times X\to X$ which contracts the identity map. Your goal is to construct a specific homotopy $H':I\times A\to A$ which contracts the identity map. Your proof never explicitly makes use of $H$ and never explicitly (maybe not even implicitly) defines $H'$. This makes it feel like a bunch of symbol-pushing. (This isn't meant to be insulting; I'm just explaining why the proof feels unsatisfying.)
Two preliminary points:


*

*$\newcommand{\pt}{{\{\ast\}}}f'=f\circ r$ isn't a map between the right things; it should be a map $A\to\pt$, but it's a map $X\to \pt$. This isn't too important since there's only one map from anything to a point, but the algebraic manipulation will be clearer if you set $f':=f|_A$.

*You don't need to check $f'\circ g'\cong id_\pt$ since there's only one map $\pt\to\pt$.
So you only need to find a homotopy from $id_A$ to $g'\circ f'$. That is, you need to make a movie (homotopy) which continuously crushes $A$ to a point. But you already have a movie $H:I\times X\to X$ which crushes $X$ to a point (i.e. $H(0,-)=id_X$ and $H(1,-)=g\circ f$), and you have a way to retract anything in $X$ to something in $A$, so you can just retract your movie, setting $H' = r\circ H|_{I\times A}$. Then $H'(0,-) = r\circ H(0,-)|_A = r\circ id_A = id_A$ and $H'(1,-)=r\circ H(1,-)|_A = r\circ (g\circ f)|_A = r\circ g\circ f|_A = g'\circ f'$.
