Proof about composed functions (elementary number theory) Let f : X → Y and g : Y → X be functions and assume $g ◦ f = I_X$. Prove
of g is injective then $f ◦ g = I_Y$.
Approach if g is the left inverse of f then there exists $x\in X$ and $y \in Y$ such that $f(x)=y$ and $g(y)=x$.
I am confused about the left inverse of f. How is it possible that the left inverse of f is not its right inverse. If g is not one to one, this would imply that  f is not a function or such g doesn't exist. I think that for $g ◦ f = I_X$ to be true g has to be injective.
In my approach, I think that a good start is to say that f(g(y))=y, but how can this be true? or how can this be false?
 A: 
I think that for $g \circ f = I_X$ to be true, $g$ has to be injective.

Not necessarily. For a counterexample, take $X = Y = \mathbb N$ and define $f\colon \mathbb N \to \mathbb N$ and $g\colon \mathbb N \to \mathbb N$ by:
$$
f(x) = 2x \qquad\text{and}\qquad
g(y) = \begin{cases}
y/2 &\text{if $y$ is even} \\
42 &\text{otherwise}
\end{cases}
$$
Observe that for all $x \in \mathbb N$, we have that $g(f(x)) = g(2x) = x$ so that $g \circ f = I_\mathbb N$. But $g$ is not injective, since for example:
$$
g(3) = 42 = g(5)
$$


Show that if $g \circ f = I_X$ and $g$ is injective, then $f \circ g = I_Y$.

Given any $y \in Y$, we want to show that $f(g(y)) = y$. To this end, choose any $y \in Y$ and let $x = g(y)$. Then since $g \circ f = I_X$, we know that:
$$
g(f(x)) = x
$$
In other words, we know that $g(f(g(y))) = g(y)$. But since $g$ is injective, we conclude that $f(g(y)) = y$, as desired. $~~\blacksquare$
A: The key here is the fact that $g$ is injective (this is the crucial point, without that this will not go through).
Assume (i) $g\circ f = I_X$ and (ii) $g$ is injective. We want to establish $f\circ g = I_Y$, i.e. $f\circ g(y) = y$ for all $y\in Y$.
Take any $y\in Y$, and consider $z\stackrel{\rm def}{=} f\circ g(y)\in Y$. We want to show $z=y$, which reminds a lot of what injectivity can help proving -- so let us use the injective function we have by (ii), $g$:
$$
g(z) = g( f\circ g(y) ) = g\circ f\circ g(y) = (g\circ f)( g(y ) ) = g(y)
$$
the last equality by (i).
So $g(z)=g(y)$... but by (ii) we know $g$ is injective, which implies $z=y$.
A: For $g\circ f$ to be the identity, it is required that $f$ be injective and $g$ be surjective (but not necessarily that $g$ be injective or $f$ surjective). Prove this first. Then note that $f\circ g$ being the identity requires $g$ to be injective.
