Computing the kernel of a homomorphism from a free $\mathbb{Z}$-module Given a finitely generated free $\mathbb{Z}$-module $N$ and a homomorphism $\varphi:N\to M$, is there an easy way to compute the kernel of $\varphi$? Since the kernel is also a free $\mathbb{Z}$-module, is there an easy way to compute a basis for the kernel?
I don't mind if I have to perform some steps using a computer algebra system, but I want to understand how such a computation would be done.
 A: The most familiar case is when $M$ is free itself. So we've got a homomorphism $\varphi:\mathbb{Z}^n\to\mathbb{Z}^m$, which we can represent by an $m\times n$ matrix $A$ just as in linear algebra over a field. Were we working over a field the next step in computing the kernel would be row-reduction. In fact that's still the next step, but we can't get the reduced matrix into quite as nice a form: in particular we can't get $1$s down the diagonal of the columns that map onto the image. This is fine, though-the rest of the algorithm works in the same way and we still get a free kernel. The non-units generating components of the image just correspond to the fact that $\mathbb{Z}^m/\varphi(\mathbb{Z}^n)$ might have torsion elements, which doesn't happen over a field.
If $M$ is not free, as long as it's finitely generated it's $\mathbb{Z}^m\oplus \bigoplus_{p,k}\mathbb{Z}_{p^k}$ by the structure theorem for such abelian groups. $\varphi$ induces morphisms to each of the $\mathbb{Z}^m,\mathbb{Z}_{p^k}$, so to compute the kernel we can intersect the kernels of those component maps. Let's observe it's actually possible to intersect a finite number of subgroups of a free abelian group algorithmically: this is another standard linear algebra problem, which over a field is expressed as finding a basis vector for a given subspace as a linear combination of basis vectors of another. So all that remains is to compute the kernel of $\varphi:\mathbb{Z}^n\to\mathbb{Z}_{p^k}$. But that's the easiest part: given a basis $e_1...e_n$ for $\mathbb{Z}^n$ the kernel's a rank-$n$ subgroup generated by $m_ie_i,$ where $p^k$ divides $m_i(\varphi(e_i))$ and $p$ does not divide $m_i(\varphi(e_i))/p^k$. 
