Group theory- rank of a group. What am I doing wrong? I was given a question: Let $n\in \mathbb{N}$ and let $A$ and $B$ groups, both isomorphic to $\mathbb{Z}^n$. Let $f:A \to B$ be a surjective homomorphism. Prove $f$ is an isomorphism. 
Here's my proof. There's going to be a part when I was noted by the tutor(which will be marked red). I would appreciate it if you referred it.
$proof$: Both $A$ and $B$ are isomorphic to $\mathbb{Z}^n$. Therefore, both are finitely generated abelian group of rank n. Let $x\in Kerf$ and let $e_1,...,e_n$ be a basis of $A$. Therefore $x=a_1x_1+...+a_nx_n$ where $a_i \in \mathbb{Z}$. Suppose $x\neq0$. We get that: $f(x)=f(a_1x_1+...+a_nx_n)=a_1f(x_1)+...+a_nf(x_n)$. Since $x\neq0$, there's at least some $j$ such that $a_j\neq0$, which means $f(x_1),...,f(x_n)$ are linearly dependent. Therefore, therefore, the rank of $<f(x_1),...,f(x_n)>$ is $\le n-1$. $\color{red}{\text{It is not as direct as it was in Linear Algebra. You have to actually prove it.}}$ That is a contradiction to the fact that $f$ is surjective; $f$ depends on $f(x_1),...,f(x_n)$ (every element in $A$ can be represented as a linear combination of $e_1,...,e_n$ and therefore its image will ever depend of $f(x_1),...,f(x_n)$ ), but if $f(x_1),...,f(x_n)$ are linearly dependent, then they cannot generate a group of rank $n-1$. Hence, $x=0$ and $f$ is injective. Therefore, $f$ is an isomorphism. 
I understand the set theory line of thinking, but that is merely inadmissible in that case according to my teacher...
 A: Your teacher is just observing that your proof is incomplete for the reasons Greg Martin mentions in his comment: you use a lemma from linear algebra that is not necessarily true for $\mathbb Z^n$.
Here is a proof that takes advantage of the fact that $\mathbb Z$ lives inside $\mathbb Q$, which allows you to reduce the proof to the basic fact from linear algebra that if a set of $n$ elements generates a vector space, they must automatically be linearly independent.
Proof. Consider the group homomorphism $f: A\to B$ that was given. Since $A\cong\Bbb Z^n\cong B$, we may as well write $f:\Bbb Z^n\to\Bbb Z^n$ and recall that $f$ is surjective. 
Let $e_1 = (1,0,\dots,0)$, $e_2=(0,1,0,\dots,0)$ denote the standard generators for $\Bbb Z^n$ and denote $x_i := f(e_i)$. Since $$f(\lambda_1,\lambda_2,\dots,\lambda_n)=f(\sum_i\lambda_i e_i)=\sum_i \lambda_i x_i,$$ the image of $f$ are precisely the $\Bbb Z$-linear combinations of the $x_i$. 
Therefore, since $f$ is surjective, the elements $x_1,x_2,\dots,x_n$ generate all of $\Bbb Z$ i.e. every $y\in\Bbb Z^n$ can be written as $y=\sum_i\lambda_i x_i$ with $\lambda_i\in\Bbb Z$. 
Then in particular the set $\{x_1,\dots,x_n\}$ generates the elements $e_1 = (1,0,\dots,0)$, $e_2=(0,1,0,\dots,0)$ etc. Therefore, if we consider them as elements of the vector space $\mathbb Q^n$, they generate all of $\mathbb Q^n$ (by taking $\Bbb Q$-linear combinations). Because there are exactly $n$ of them, this automatically means they are linearly independent over $\Bbb Q$. But then, they are a fortiori linearly independent over $\Bbb Z$.
But this implies that $f$ is injective: we verify that $\mathrm{ker}(f)=0$. Assume that $f(\sum_i \lambda_i e_i)=0$, with $\lambda_i\in\Bbb Z$, then $\sum_i \lambda_i x_i=0$ and because the $x_i$ are linearly independent this implies that all $\lambda_i=0$, thus $\sum_i\lambda_ie_i=0$. $\Box$
