Let’s first see why the Betti number \(n\) is uniquely determined. If we have
\begin{align*}
M \amp \cong R^n \oplus \Tor M\text{,}
\end{align*}
then
\begin{align*}
\Tor M \amp \cong \Tor(R^n)\oplus \Tor (\Tor M)\cong \{0\}\oplus \Tor M
\end{align*}
and thus
\begin{align*}
M/\Tor(M) \amp \cong (R^n\oplus \Tor(M))/(\{0\}\oplus \Tor M)\cong R^n\text{.}
\end{align*}
Thus \(n\) is the rank of the free module \(M/\Tor M\text{.}\) Since the rank of a free module is well defined, we see that \(n\) is uniquely determined by the module \(M\text{.}\) More explicitly, we have
\begin{align*}
M \cong R^m\oplus \Tor M\amp \iff m=\rank M/\Tor M\text{.}
\end{align*}
It remains to show that each of the two distinct decompositions of
\(\Tor M\) described in
Theorem 2.19.2 and
Theorem 2.19.7 satisfy the specified uniqueness claims. First observe that the we can obtain the elementary divisor form from the invariant factor form using the Chinese remainder theorem: given
\(a=\prod_{i=1}^rp_i^{n_i}\text{,}\) with
\(p_i\) pairwise nonassociate irreducibles, the ideals
\((p_i^{n_i})\) are pairwise coprime, and thus
\begin{align}
R/(a) \amp \cong \bigoplus_{i=1}^rR/(p_i^{n_i})\text{.}\tag{2.20.1}
\end{align}
Expanding out all the invariant factor quotients \(R/(a_i)\) in this way and then grouping all associate irreducible factors together, we obtain the elementary divisor form from the invariant factor form. Conversely, with a little bit of care you can group the elementary factor quotients together in such a way to get the invariant factor form. It is worth at least looking at one example of this reverse direction to see what the subtleties are. Consider the case \(R=\Z\) and the group
\begin{align*}
A \amp \cong \Z/2\Z\oplus \Z/2^2\Z\oplus \Z/2^2\Z \oplus \Z/3\Z\oplus \Z/3\Z\text{.}
\end{align*}
We have
\begin{align*}
A \amp \cong \Z/2\Z\oplus (\Z/2^2\Z\oplus \Z/3\Z)\oplus (\Z/2^2\Z\oplus \Z/3\Z) \\
\amp \cong \Z/2\Z \oplus \Z/12\Z \oplus \Z/12\Z\text{.}
\end{align*}
It thus suffices to show that the uniqueness claim for the elementary divisor form holds. Since this decomposition is a decomposition of \(\Tor M\text{,}\) we will assume \(M=\Tor M\) is torsion. Suppose we have a decomposition
\begin{align*}
M \amp \cong \bigoplus_{i=1}^r \bigoplus_{j=1}^{m_j}R/(p_i^{n_{ij}})
\end{align*}
where the \(p_i\) are pairwise nonassociate irreducible elements. In general, if \(p\) and \(q\) are nonassociate irreducible elements, then \(p\) and \(q^n\) are coprime for any positive integer \(n\text{,}\) from which it follows that multiplication by \(p\) is an automorphism of \(R/(q^n)\text{.}\) It follows that the \(p\)-primary component of \(R/(q^n)\) is \(\{0\}\) for any irreducible \(q\) not associate to \(p\) and positive integer \(n\text{.}\) Since \(p\)-primary components behave well with direct sums, we conclude that given the composition of \(M\) above, we have
\begin{align*}
M(p_i^\infty) \amp \cong \bigoplus_{i=1}^{m_i}R/(p_i^{n_{ij}})
\end{align*}
for all \(i\text{.}\) In other words, not surprisingly, we extract \(M(p_i^\infty)\) from the decomposition above by taking just the direct summands that involve \(p_i\text{.}\) Since \(M(p_i^\infty)\) is (up to isomorphism) uniquely determined by \(M\text{,}\) we have thus reduced the uniqueness problem to showing that each of these \(p_i\)-primary component decompositions is unique in the stipulated sense. From now on, we assume that \(p\) is an irreducible element, and that we have a module \(M\) with decomposition
\begin{align*}
M \amp \cong \bigoplus_{i=1}^m R/(p^{n_i})\text{.}
\end{align*}
The uniqueness of the \(n_i\) appearing in such a decomposition is now given by the following result, which actually tells us how to compute the sequence \(n_1\leq n_2\leq\dots \leq n_m\text{.}\)