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 on $A$. Prove: $f$ is surjective if and only if $g$ is injective.
Work: Proof: 1. We prove that if $g$ is injective then $f$ is surjective. 2. We will then prove that if $f$ is surjective then $g$ is injective. We now prove that if $g$ is injective then $f$ is surjective. Suppose $g$ is not injective, then there exists $b_1\neq b_2$ such that $g(b_1)=g(b_2)$. Suppose that $f$ is surjective, that is , there exists $a_1\neq a_2$ such that $f(a_i)=b_i$. We obtain a contradiction since $a_1=(g\circ f)(a_1)=(g\circ f)(a_2)=a_2$ and $a_1\neq a_2$. Suppose $f$ is not surjective and suppose that $g$ is injective. Then there exists $b\in B$ such that $f(a)\neq b$ for all $a\in A$. Since $g$ is injective, $g(x)=g(y)$ then $x=y$ for $x,y\in B$. However, $g(b)$ is not mapped in $A$. Therefore, $g$ cannot be injective since not all of its domain is mapped to a unique value in $A$.