[guided]The uniqueness of the invariant factors is deeper than the uniqueness of the rank. We need to show that the ideals $(d_1), \ldots, (d_k)$ are determined by $M$ alone, not by the particular presentation $M \cong R^n / K$.
The key tool is the **determinantal ideal** (also called the **Fitting ideal**). For each integer $t \geq 1$, define $\Delta_t(A)$ to be the ideal of $R$ generated by all $t \times t$ minors of $A$. We claim these ideals are invariants of the presentation $R^n \xrightarrow{A} R^n$ and ultimately of $M$ itself.
**Step 1: Determinantal ideals are unchanged by elementary operations.** The Smith normal form gives $D = PAQ$ where $P \in GL_n(R)$ and $Q \in GL_m(R)$. We need $\Delta_t(A) = \Delta_t(D)$. By the Cauchy-Binet formula, a $t \times t$ minor of $PAQ$ is an $R$-linear combination of $t \times t$ minors of $A$ (with coefficients coming from minors of $P$ and $Q$), and vice versa (since $A = P^{-1} D Q^{-1}$). Since $P$ and $Q$ are invertible over $R$, the ideals generated by the $t \times t$ minors of $A$ and $D$ coincide: $\Delta_t(A) = \Delta_t(D)$.
**Step 2: Read off the determinantal ideals of $D$.** The diagonal matrix $D$ has diagonal entries $d_1, \ldots, d_s, 0, \ldots, 0$. A $t \times t$ submatrix of $D$ has nonzero determinant only if it is a diagonal submatrix, in which case its determinant is a product $d_{i_1} \cdots d_{i_t}$ for some $1 \leq i_1 < \cdots < i_t \leq s$. The divisibility chain $d_1 \mid \cdots \mid d_s$ ensures that $d_1 \cdots d_t$ divides every other such product: for any $1 \leq i_1 < \cdots < i_t \leq s$, we have $i_j \geq j$ for each $j$, so the divisibility chain gives $d_j \mid d_{i_j}$, and therefore $d_1 \cdots d_t \mid d_{i_1} \cdots d_{i_t}$. Conversely, $d_1 \cdots d_t$ is itself a $t \times t$ minor of $D$ (the upper-left $t \times t$ block). Therefore $\Delta_t(D) = (d_1 \cdots d_t)$ for $t \leq s$ and $\Delta_t(D) = (0)$ for $t > s$.
**Step 3: Recover individual invariant factors.** Setting $\Delta_0(A) := R$, the $t$-th invariant factor satisfies
\begin{align*}
(d_t) = \Delta_t(A) / \Delta_{t-1}(A),
\end{align*}
meaning $d_t$ is the generator of the principal ideal $\Delta_t(A) \cdot \Delta_{t-1}(A)^{-1}$ (which makes sense in a PID: $\Delta_{t-1}(A) \mid \Delta_t(A)$ since every $(t-1) \times (t-1)$ minor divides a cofactor expansion of a $t \times t$ minor).
**Step 4: Independence of presentation.** We must show that $\Delta_t(A)$ depends only on $M$, not on the choice of generators or relations. Suppose $M \cong R^{n'} / K'$ is a different presentation with relation matrix $A' \in R^{n' \times m'}$. The two presentations are related by a sequence of three types of operations on the relation matrix: (1) elementary row operations (corresponding to automorphisms of $R^n$, i.e., change of generators of the ambient free module), (2) elementary column operations (corresponding to automorphisms of $R^m$, i.e., change of basis of the relation submodule $K$), and (3) stabilisation — adding a zero row and zero column bordered by a $1$ (corresponding to adding a redundant generator $m_{n+1} = 0$ and the relation $m_{n+1} = 0$, which enlarges the presentation without changing $M$). Operations (1) and (2) preserve $\Delta_t$ by the Cauchy-Binet argument from Step 1: left- or right-multiplication by an invertible matrix replaces each $t \times t$ minor by an $R$-linear combination of $t \times t$ minors, and the invertibility ensures the ideals coincide. Operation (3) also preserves $\Delta_t$: if $B$ is obtained from $A$ by bordering with a row and column whose intersection entry is $1$ (and all other new entries are $0$), then the $t \times t$ minors of $B$ include all $t \times t$ minors of $A$ plus additional minors involving the new row and column, but expanding along the new row shows each such minor equals a $(t-1) \times (t-1)$ minor of $A$, which already lies in $\Delta_{t-1}(A) \subseteq \Delta_t(A)$. Therefore $\Delta_t(B) = \Delta_t(A)$. Since any two presentations of $M$ are connected by a finite sequence of these operations and their inverses, $\Delta_t$ is an invariant of $M$. The invariant factors, recovered as $(d_t) = \Delta_t / \Delta_{t-1}$, are therefore uniquely determined up to units.[/guided]