Solution (source code)

= Solution

An $R$-module is free if it has a <basis>: a subset $B$ such that every element has a unique expression as a finite $R$-linear combination of elements of $B$.

Choose a maximal <ideal> $\mathfrak m$ of the nonzero <ring> $R$. If $R^n\cong R^m$, quotienting by $\mathfrak m$ gives
$$
(R/\mathfrak m)^n\cong(R/\mathfrak m)^m.
$$
These are <vector spaces> over the field $R/\mathfrak m$, so equality of dimension gives $n=m$. This proves <invariant basis number for a commutative ring>.

A direct summand of a free module need not be free. Take $R=\mathbb Z/6\mathbb Z$. Its <ideals> $P=(2)$ and $Q=(3)$ satisfy
$$
P\cap Q=0,
\qquad P+Q=R,
$$
so $P\oplus Q\cong R$. But $P$ has three elements, whereas a finite-rank free $R$-module has $6^r$ elements; hence $P$ is not free.