# Contractible Spaces and Homotopic Maps

I'm trying to prove the following statement, but I am stuck.

Let $X$ and $Y$ be topological spaces. If one of them is a contractible space, then every continuous function from $X$ to $Y$ is homotopic to a constant map.

Start of my solution: Assume, without loss of generality, that $X$ is a contractible space. Then the identity map $\mathrm{id}_{X}:X\to X$ is nullhomotopic such that $\mathrm{id}_{X}\simeq c$, where $c$ is some constant map. In other words, there exists a continuous function $F:X\times[0,1]\to X$ such that $F(x,0)=\mathrm{id}_{X}$ and $F(x,1)=c$. Let $f:X\to Y$ be a continuous function. Then....

That's where I'm stuck. I'm not sure how to show that any arbitrary continuous function is necessarily homotopic to a constant map. Thanks in advance for any help!

• "Without loss of generality" is invalid here, because the roles of $X$ and $Y$ are not symmetric: the problems is about continous functions from $X$ to $Y$. The proof when $X$ is contractible is different from the proof when $Y$ is contractible. – Lee Mosher Oct 18 '17 at 19:58

Let $g:X \to Y$ be the function $g(x)=f(c)$. Then $g$ and $f$ are homotopic using the function $G: X \times [0,1] \to Y$ which is $G(x,r)= f(F(x,r))$. Then $G(x,0)=f$ and $G(x,1)=g(x)= f(c)$.
To provide a bit of a wider context on ulo's answer, consider the following general situation. Suppose $g,g':A\to B$ and $f,f':B\to C$ are maps with $g\simeq g'$ and $f\simeq f'$ via homotopies $H:A\times [0,1]\to B$ and $I:B\times[0,1]\to C$. Then $f\circ g$ is homotopic to $f'\circ g'$, by just "composing" the two homotopies. To be precise, you use the homotopy $J:A\times [0,1]\to C$ defined by $J(a,t)=I(H(a,t),t))$.
In your case, you can take $A=B=X$, $C=Y$, $g=\mathrm{id}_X$, $g'=c$, and $f=f'$ to be your arbitrary map $X\to Y$. You get that $f\circ g=f\circ\mathrm{id}_X=f$ is homotopic to $f'\circ g'=f\circ c$, and $f\circ c$ is a constant map because $c$ is a constant map.