Proving uniqueness in the structure theorem for finitely generated modules over a principal ideal domain In an introductory algebra course, one proves the Structure theorem for finitely generated modules over a principal ideal domain.
http://en.wikipedia.org/wiki/Structure_theorem_for_finitely_generated_modules_over_a_principal_ideal_domain
In every book that I have looked in, the uniqueness part of the proof is a mess.
Can anyone give me a reference for a nicer proof of the uniqueness part? I am especially interested in a proof of uniqueness when the underlying ring is the ring of polynomials in one variable over a field.
 A: Let $M$ be the finitely generated module, and $M_{tor}$ its torsion submodule.
As part of the proof of the structure theorem, one shows that $M/M_{tor}$ is free
of finite rank, and that $M$ is isomorphic to $M_{tor} \oplus M/M_{tor}$,
so it suffices to show uniqueness for free modules and torsion modules separately.
For a free module, its free rank can be computed as the maximal number of linearly independent
elements (just using the usual linear algebra definition, but applied to the free module).
So the free rank of $M/M_{tor}$ is uniquely determined.  (In fact, one can apply this
directly to $M$ --- the free part of $M$ in the decomposition given by the structure theorem
is just the maximal number of linearly independent elements of $M$ --- and so you
don't need to explicitly consider $M/M_{tor}$ if you don't want to.)
We are now reduced to the case when $M = M_{tor}$, i.e. $M$ is torsion.  The structure theorem then gives us that $M$ is a direct sum of modules of the
form $A/\wp_j^{i_j} A$ for various non-zero prime ideals $\wp_j$ of $A$, and various indices $i_j$.
Imagine now that we have another such decomposition, into a direct sum of $A/\wp ' {} _j^{i'_j}.$
If we fix a non-zero prime ideal $\wp$ of $M$, and some $n \geq 0,$
then let $M[\wp^n]$ denote the submodule of $M$ consisting of elements annihilated by
$\wp^n$.  A direct computation with each of the decompositions in turn shows that
$M[\wp^n]/M[\wp^{n-1}]$ is an $A/\wp$-vector space of dimension equal to the number
of $j$ for which $\wp_j = \wp$ and $i_j \geq n,$ and also equal to the number of 
$j$ for which $\wp'_j = \wp$ and $i'_j \geq n.$  Since $\wp$ and $n$ were arbitrary,
this shows that the two decompositions coincide.
One can also make the following variant of this argument, in which we break it into two steps.
Namely, first fix a non-zero prime ideal of $A$, and consider $M[\wp^n]$.  If $n$ is larger than
any of the $i_j$ or $i'_j$, then this is the direct sum of just those $A/\wp_j^{i_j}$
for which $\wp_j = \wp$, and also is the direct sum of just those
$A/\wp' {} _j^{i'_j}$ for which $\wp'_j = \wp$.
Thus, replacing $M$ by $M[\wp^n]$ as $\wp$ runs over all the $\wp_j$ and $\wp'_j$, we may assume that all the $\wp_j$ and $\wp'_j$ coincide with some fixed prime ideal $\wp$.
We can then repeat the above argument, but just varying $n$, and keeping $\wp$ equal
to our given choice of prime ideal.
There is also the following variant, using quotients, rather than subobjects, namely,
fix a non-zero prime ideal of $A$, and consider $M/\wp^n M$.  Again, if $n$ is larger than
any of the $i_j$ or $i_j'$, then this is the direct sum of just those $A/\wp_j^{i_j}$
for which $\wp_j = \wp$, and also is the direct sum of just those
$A/\wp' {} _j^{i'_j}$ for which $\wp'_j = \wp$.
At this point, we could consider submodules of prescribed torsion, as above,
but, since we have started by using quotients, we can finish by using quotients as well,
by considering the quotients of the form $\wp^n M/\wp^{n+1}M$ just as in
Pierre-Yves Gaillard's comment above.  As he explains, this also gives the desired uniqueness.
A: As a complement to Matt E's nice answer, let $A$ be your PID, and $p\in A$ a prime. It suffices to prove the uniqueness in the case where your finitely generated module $M$ is the product of a finite family of modules of the form $$M_i:=A/p^{i+1}A.$$ For each $j$ the quotient $p^jM/p^{j+1}M$ is an $A/pA$ vector space of finite dimension $n_j$. The multiplicity of $A/p^{i+1}A$ is then $n_i-n_{i+1}$. 
Here is a way to see this. 
Form the polynomial $M(X):=\sum\ n_j\ X^j$. We have 
$$M_i(X)=\frac{X^{i+1}-1}{X-1}=1+X+X^2+\cdots+X^i,$$ 
and we must solve $\sum\ m_i\ M_i(X)=\sum\ n_j\ X^j$ for the $m_i$, where the $n_j$ are considered as known quantities (almost all equal to zero). Multiplying throughout by $X-1$ we get $$\sum\ m_{i-1}\ X^i-\sum\ m_i=\sum\ (n_{i-1}-n_i)\ X^i,$$ 
whence the formula.
A: I will give a proof of uniqueness that handles the torsion and torsion-free components simultaneously and that characterizes the invariant factors directly, rather than doing it indirectly through the elementary divisors $p^i$. Specifically, I prove the following result.

Proposition. Let $A$ be a commutative ring and $I_1 \subseteq I_2 \subseteq \dots \subseteq I_n$ an increasing sequence of proper ideals of $A$ (some or all of which may be zero). Let $E$ be an $A$-module for which an isomorphism
  \begin{equation} \tag{*}
E \cong A/I_1 \times \dots \times A/I_n
\end{equation}
  holds.
$(1)$ The minimal number of generators of $E$ is $n$.
$(2)$ For $k = 1, \dots, n$, the ideal $I_k$ is equal to the set of all $x \in A$ such that the $A$-module $xE$ can be generated by fewer than $k$ elements.

Proof of $(1)$. Since $E$ is in an obvious way the homomorphic image of $A^n$, it is clear that $E$ has a generating set consisting of $n$ elements. Conversely, assume that $E$ can be generated by $r$ elements for some $r < n$. Let $M$ be a maximal ideal containing $I_n$. We have an obvious $A$-linear surjection $E \to (A/M)^n$. Consequently, $(A/M)^n$ can be generated by $r$ elements as an $A$-module and hence also as an $A/M$-vector space, which is absurd.
Proof of $(2)$. Let $x \in A$, and let $k \leq n$. For any ideal $I$ of $A$, denote by $I_x$ the ideal of $A$ that is the inverse image of $I$ under the map $A \to A, \ y \mapsto xy$. We have
\begin{equation}
xE \cong A/{(I_1)}_x \times \dots \times A/{(I_n)}_x.
\end{equation}
This decomposition is of the type $\text{(*)}$ except for the fact that some of the factors $A/{(I_j)}_x$ at the end may be zero. By $(1)$, the module $xE$ can be generated by fewer than $k$ elements if and only if the $k$th factor $A/{(I_k)}_x$ is zero, or equivalently when $x \in I_k$.
Note. The existence of $M$ asserted in the proof of $(1)$ follows from Krull's Theorem. However, its existence is trivial when $A$ is a p.i.d., which is the case of interest here. If $A$ is a p.i.d. other than a field, we can let $M = pA$, where $p$ is an irreducible element dividing a generator of $I_n$. If $A$ is a field, let $M = {0}$. 
The use of Krull's Theorem can also be avoided entirely by replacing $M$ with $I_n$ and using the fact that there can be no $B$-linear surjection $f \colon B^r \to B^n$, where $B = A/I_n$. For if there were, it would split, say $fg = \operatorname{id}_{B^n}$. This is absurd, because the characteristic polynomial of $fg$ is divisible by $X^{n-r}$, as shown here.
