Solution (source code)

= Solution

A <Euclidean domain> is a <principal ideal domain>. The <structure theorem for finitely generated modules over a principal ideal domain> therefore gives, for every <finitely generated module> $M$ over $R$,
$$
M\cong R^r\oplus R/(d_1)\oplus\cdots\oplus R/(d_s),
$$
where the $d_i$ are nonzero nonunits and $d_1\mid d_2\mid\cdots\mid d_s$. The factors $d_i$ are unique up to multiplication by <units>; $r$ is uniquely determined.

The <rank of a module> is this integer $r$. Equivalently, with $K$ the <field of fractions> of $R$,
$$
\boxed{\operatorname{rank}_R M=\dim_K(K\otimes_R M)=r.}
$$
The <tensor product of modules> kills each displayed torsion summand after extending scalars to $K$, while sending $R^r$ to $K^r$, explaining the equality.

If $M$ is a <torsion-free module>, no summand $R/(d_i)$ can occur: its nonzero element $1+(d_i)$ is killed by the nonzero scalar $d_i$. Hence $s=0$ and
$$
\boxed{M\cong R^r,\quad\text{so $M$ is a free module}.}
$$
This also covers $M=0$, with $r=0$.