Prove that $\mathbb Z^n$ is not isomorphic to $\mathbb Z^m$ for $m\neq n$ [duplicate]

$\mathbb{Z}^n \cong \mathbb{Z}^m$ implies $(\mathbb{Z}/2)^n \cong \mathbb{Z}^n / 2 \mathbb{Z}^n \cong \mathbb{Z}^m / 2 \mathbb{Z}^m \cong (\mathbb{Z}/2)^m$. By comparing the number of elements, we get $2^n=2^m$, i.e. $n=m$. (No linear algebra is necessary here!)


First proof

Suppose $\mathbb{Z}^n\cong\mathbb{Z}^m$, with $m\ne n$. Then you can find a set of $m$ free generators in $\mathbb{Z}^n$, say $\{f_1,f_2,\dots,f_m\}$. Then, for some integers $a_{ij}$, $b_{ij}$, you have \begin{align} f_j&=\sum_{i=1}^n a_{ij} e_i &&j=1,\dots, m\\ e_i&=\sum_{j=1}^m b_{ij} f_j &&i=1,\dots, n \end{align} where $\{e_1,\dots,e_n\}$ is the standard basis.

It's easy to show from this that the matrix $[a_{ij}]$ is invertible (over the integers, so, a fortiori, over the reals). But no matrix with a different number of rows and columns can have both a left and a right inverse.

Second proof

If $\mathbb{Z}^n\cong\mathbb{Z}^m$, then $$ \mathbb{Z}^n\otimes_{\mathbb{Z}}\mathbb{Q}\cong \mathbb{Z}^m\otimes_{\mathbb{Z}}\mathbb{Q} $$ so $$ \mathbb{Q}^n\cong\mathbb{Q}^m $$ which implies $n=m$ by well known facts of linear algebra.

Proof of the more general result for any commutative ring

Let $A$ be a nontrivial commutative ring (with identity) and suppose $A^n\cong A^m$ as $A$-modules. Let $I$ be a maximal ideal of $A$; then $$ A^n\otimes_A(A/I)\cong A^m\otimes_A(A/I) $$ that immediately gives $$ (A/I)^n\cong(A/I)^m $$ as $(A/I)$-modules. Since $A/I$ is a field, we get $n=m$.

If, instead of a maximal ideal we take a prime ideal $P$ and tensor with the field of quotients of $A/P$, we get our second proof for the special case of a domain (with $(0)$ as the prime ideal).