how to prove this ( about surjective functions and inverse functions) I  was making excercises for an upcoming exam and when trying to make this one I really got stuck.
The question is:
Prove that a function $f$ from $X$ to $Y$ is surjective if and only if there exists a function $g$ from $Y$ to $X$ with $g$ after $f$ is the unit function (the function that maps every $x$ on $x$).
My thoughts directly went to the inverse function but than I started having doubts because if the domain is bigger than the co-domain the inverse function would have to have more than one value for every input and than g wouldn't be a function.
My second thought was the same but with a reduced domain so that f becomes bijective but I do't think thats allowed in this question.
Does someone know a way to solve/proof this question?
 A: You do not have to think about an inverse function in a strong sense. There is a more general terminology of left inverse and right inverse. In this case you have to proof the equivalence:
If $f\colon X\to Y$ is surjective, then there exists a function $g\colon Y\to X$ such that $f\circ g=\operatorname{id}_Y$. Which means that $g$ is right inverse to $f$. (Here you write it differently in the task. Maybe a typo or confusion with the notation)
Also you have to proof that when there is a function $g\colon Y\to X$ such that $g\circ f=\operatorname{id}_Y$, then $f$ is already surjective.
The first statement is more difficult, as you have to construct a suitable function $g$.
But "difficult" is a relative term. What makes it difficult is that there are some ways to go wrong, or to get confused. For example you have to make sure, that your function $g$ is well-defined.
The second implication is straightforward.
In any case your first step should be to recall the definitions.
Look up what surjective means, and when a function is said to be well-defined.
A: You don't need to show the existence of an inverse, because the inverse may not exist, if $f$ isn't 1-1. You are supposed to show the right inverse, that is a function $g\colon Y\to X$ such that $f\circ g = \mathrm{id}_Y$.
You are right that $f^{-1}(\{y\})$ can have more than one element. Take just one of them, that is define $g(y)\in f^{-1}(\{y\})$.
A: Suppose that $f$ is surjective. We want to define a function $g: Y \to X$ such that $f \circ g = \operatorname{Id}_Y$. Well, given $y \in Y$, we know that there exists at least one $x \in X$ such that $f(x) = y$. So define $g$ by choosing exactly one such $x$: that is, define $g$ by $g(y) = x$ for each $y \in Y$, where $x$ is an arbitrarily chosen element of $X$ such that $f(x) = y$ (and such an $x$ is guaranteed to exist because $f$ is surjective). In that case, the composition $g \circ f$ acts on each $y \in Y$ by $(f \circ g)(y) = f(g(y))= y$ by our construction of $g$, and hence the composition satisfies the desired property.
Conversely, suppose there exists $g: Y \to X$ such that $f \circ g = \operatorname{Id}_Y$. We want to prove $f$ is surjective, i.e to each $y \in Y$ we want to find $x \in X$ such that $f(x) = y$. Well, since $f \circ g = \operatorname{Id}_Y$, then for each $y \in Y$, $f(g(y)) = y$. So letting $x = g(y)$ we get $f(x) = y$, as desired. Therefore $f$ is surjective.
