Let $R$ be a PID. I want to show that if $P$ is a finitely generated left $R$-module and $P$ is isomorphic to $R^n$ and $R^m$ (as $R$-modules) for $n,m$ in the natural numbers, then $n=m$. I was wondering if the following proof is enough: Assume $m<n$. Let $f: R^m \to R^n$ be isomorphic. Then the image of the basis for $R^m$ generates $R^n$. But then $m$ elements generate $R^n$, showing that $m=n$.
I'm not that good at working with modules, so my question is, if this proof is valid?
I'm afraid not. The invariant basis number or IBN property is not satisfied by all rings.
It is true for the so-called stably free rings, for which, given two $n\times n$ matrices, $AB=I_n\Rightarrow BA=I_n$.
Among stably free rings are commutative rings, noetherian rings, artinian rings and semi-local rings.
An example of a ring that does not satisfy IBN is $R=\mathbf{CFM}_\mathbf{N}(A)$, the set of infinite matrices, indexed by $\mathbf N\times\mathbf N$ with coefficients in a ring $A$ and only a finite number of non-zero coefficients in each column.
One shows the map: $$\begin{aligned} R&\longrightarrow R\times R\\ X&\longmapsto (O,E) \end{aligned}\quad \text{where}\quad \begin{array}{|l}O=\text{odd columns of }X,\\E=\text{even columns of }X\end{array}$$ is such an isomorphism.