Clarification about injectivity of a function Let $f:{X\to Y}$ be a function. 
Show:
$f$ is injective $\Leftrightarrow \exists \space h:{Y\to X} \ni h\circ f=id_X$. 
If we have $f(x)=f(y)$ then $x=y$. My problem is how can we have the function $h$? f is injective but not surjective this means that there might be values of $Y$ that don't correspond to anything in $X$. By the definition of a function h must map all values from $Y$ to $X$. How can I find $h\circ f=id_X$
I am thinking about restriction function here, $ h:{Y/{A}\to X}$ but the problem asks for $Y$.
 A: Suppose there exists $h\colon Y\to X$ such that $h\circ f=\mathit{id}_X$; if $f(a)=f(b)$, for $a,b\in X$, then
$$
h(f(a))=h(f(b))
$$
so $a=b$, by assumption. Hence $f$ is injective.
Suppose on the contrary that $f$ is injective and that $X$ is not empty. Let $x_0\in X$ and define $h\colon Y\to X$
$$
h(y)=\begin{cases}
x & \text{if $f(x)=y$ for some $x\in X$}\\[4px]
x_0 & \text{if $y\ne f(x)$ for all $x\in X$}
\end{cases}
$$
Note that this is a good definition of a function $h\colon Y\to X$, because the element $x$ in the first case is uniquely determined, being $f$ injective.
Can you show that $h\circ f=\mathit{id}_X$?
Side notes


*

*The assumption that $X$ is not empty is essential

*The axiom of choice is not relevant for the argument

*If we identify $f$ with the set $\{(x,f(x)):x\in X\}$, then
$$h=\{(f(x),x):x\in X\}\cup\{(y,x_0):y\in Y\setminus\operatorname{im}f\}$$
A: You can define how $h$ works with those values $\alpha \in Y $ for which does not exists a $x \in X$ such that $f(x)=\alpha$ in this way: $h(\alpha)=x$ if $f(x)=\alpha$ and $h(\beta)=z \in X$ if $\not\exists x \in X \space ,f(x)=\beta.$
This function do what we want.
