Proving functions are injective and surjective I am having trouble with the following problem:
For nonempty sets $A$ and $B$ and functions $f:A \rightarrow B$ and $g:B \rightarrow A$ suppose that $g\circ f=i_A$, the identity function of $A$. Prove that $f$ is injective and $g$ is surjective.
Work: Since $g\circ f=i_A$, then $g\circ f:A\rightarrow A$. 
After this point, I don't know how to proceed. 
 A: Claim. $f: A \to B$ is injective.
Assume for $a, b \in A$ that $f(b) = f(a)$. Then, $g(f(b)) = g(f(a))$, which implies that $(g \circ f)(b) = (g \circ f)(a)$, or $b = a$ by the definition of the identity function. Hence, $f$ is injective.
I'll have you try the other one.
A: Well as a start, look to the definitions of injective and surjective.
Then from there you may have a see how to prove it, when you see what it is exactly that you are supposed to show.
So, for injective,
f : A $\rightarrow$ B is injective if, for x, y $\in$ A,
$$f(x) = f(y)$$ if and only if $$x = y$$
That is to say, each element in the codomain is the image of exactly one element in the domain.
Then, f : A $\rightarrow$ B is surjective if, for each z $\in$ B, 
$$z = f(x)$$
for some x $\in$ A.
That is to say, each element of the codomain is the image of some element in the domain.
Then apply the extra information that you have a see where you can get...
A: If $f$ weren't injective then $f(x_1)= f(x_2)$ for some $x_1\neq x_2$ in $A$.
So that $x_1=g\circ f\;(x_1)=g\circ f\;(x_2)=x_2$, since $g\circ f$ is the identity function on $A$.
Similarly, if $g$ weren't surjective then for some $a\in A$ there is no $b\in B$ such that $g(b)=a$. But $g\circ f\;(a)=a$.
