Is it true that the cardinality of every maximal linearly independent subset of a finitely generated free module $A^{n}$ is equal to $n$ (not just at most $n$, but in fact $n$)? Here $A$ is a nonzero commutative ring. I know that it's true if $A$ is Noetherian or integral domain. I thought it was not true in general but I came up with something that looks like a proof and I can't figure out where it went wrong.

I think I have a counterexample. Let $A$ be the ring of functions $f$ from $\mathbb{C}^2 \setminus (0,0) \to \mathbb{C}$ such there is a polynomial $\widetilde{f} \in \mathbb{C}[x,y]$ such that $\widetilde{f}(x,y)=f(x,y)$ for all but finitely many $(x,y)$ in $\mathbb{C}^2$. Map $A$ into $A^2$ by $f \mapsto (fx, fy)$. We check that this is injective: If $fx=0$ then $f$ is zero off of the $x$axis. Similarly, if $fy=0$, then $f$ is zero off of the $y$axis. So $(fx, fy) = (0,0)$ implies that $f$ is zero everywhere on $\mathbb{C}^2 \setminus (0,0)$. We now claim that there do not exist $(u,v)$ in $A^2$ such that $(f,g) \mapsto (fx+gu, \ fy+gv)$ is injective. Suppose such a $(u,v)$ exists. Let $\widetilde{u}$ and $\widetilde{v}$ be the polynomials in $\mathbb{C}[x,y]$ which coincide with $u$ and $v$ at all but finitely many points. Let $\Delta=\widetilde{u} y  \widetilde{v} x$. Since $\Delta$ is a polynomial which vanishes at $(0,0)$, it is not a nonzero constant. Thus, $\Delta$ vanishes on an entire infinite subset of $\mathbb{C}^2$. Let $(p,q)$ be a point in $\mathbb{C}^2 \setminus (0,0)$ such that $\Delta(p,q)=0$, $\widetilde{u}(p,q)= u(p,q)$ and $\widetilde{v}(p,q)=v(p,q)$. So $q u(p,q)  p v(p,q) =0$. Since $(p,q) \neq (0,0)$, there is some $k \in \mathbb{C}$ such that $(u(p,q), v(p,q)) = (kp, kq)$. Take $f$ to be $k$ at $(p,q)$ and $0$ elsewhere; let $g$ be $1$ at $(p,q)$ and $0$ elsewhere. So $(fx+gu, fy+gv)=0$, and the map $(f,g) \mapsto (fx+gu, \ fy+gv)$ is not injective. 


We have to prove that $m \leq n$ if there is a monomorphism $A^m \to A^n$. Since this is given by a $n \times m$ matrix with entries in $A$ and every finitely generated ring is noetherian, it is enough to consider the case that $A$ is noetherian. Now you already know the proof for this case, but I just add it. Pick a minimal prime ideal $\mathfrak{p} \subseteq A$. This exists since $A \neq 0$. Now localize at $\mathfrak{p}$. Then we may replace $A$ by $A_{\mathfrak{p}}$, and thereby assume that $A$ is a $0$dimensional noetherian ring, thus artinian. For such a ring it is known that the length of finitely generated modules is finite, and additive on short exact sequences. In particular $m * l(A) \leq n * l(A)$. Since $l(A) \neq 0$ is finite, we get $m \leq n$. By the way, the assertion can be generalized to the infinite case:
Proof: Let $B$ be infinite. Representing elements of $L$ as linear combinations of elements in $B$ yields a map $f : L \to E(B)$, where $E(B)$ denotes the set of finite subsets of $B$. Now let $F$ be such a finite subset with $n$ elements. The finite case yields that there are at most $n$ linearly independent elements in $\langle F \rangle$, thus also in $f^{1}(F)$. Now we use cardinal arithmetics: $L = \sum_{n > 0} \sum_{F \in E(B), F=n} f^{1}(F) \leq \sum_{n > 0} B^n = \sum_{n > 0} B = B.$ EDIT: See the comments; this does not answer kwan's question yet. 


Assuming that $A$ has a maximal ideal $\mathfrak{m}$ (for example, by using Zorn's Lemma), one can proceed as follows: if $M$ is a free $A$module with basis $(v_i)_{i\in I}$, then $M \cong A^I$, whence $M / \mathfrak{m} M \cong A^I / \mathfrak{m} A^I \cong (A / \mathfrak{m} A)^I$. This is a vector space over $k := A / \mathfrak{m} A$ of dimension $I$. Since over fields, all vector space bases of the same vector space have the same length, and since the $k$vector space structure of $M / \mathfrak{m} M$ is independent of the choice of the basis, this shows that all $A$bases of $M$ have the same cardinality. I don't remember where I first saw this though... maybe someone else has a reference? I saw this first in the case that $A = \mathbb{Z}$ and $\mathfrak{m} = (2)$ for free abelian groups $M$, to show that the rank is welldefined. 


I have spotted the mistake in my proof. So here is the "wrong" proof: Let $v_{1},\ldots,v_{m}$ be linearly independent elements in $A^{n}$, where $m\lt n$. Write them as $n$tuples of elements in $A$, thereby forming an $n$by$m$ matrix. Linear independence of $v_{i}\ $s means that the rank of this matrix is $m$. So there is an $m$by$m$ minor with nonzero determinant. By exchanging rows if necessary, bring these $m$ rows to the top part of the matrix. Now add a colomn to the right side of the matrix whose entries are $0$ except at the $n+1$ th position, where the entry is $1$. Then the new $n$by$(m+1)$ matrix has rank $(m+1)$ and hence the $(m+1)$ columns, the first $m$ of which are the $v_{i}\ $s, are linearly independent. The mistake was the notion of rank of a matrix. When the entries are not from integral domain, the proper definition should be the largest integer $m$ such that there is no nonzero element in the ring annihilating the determinant of every $m$by$m$ minor. In the above example, I can't conclude that the rank of the $n$by$(m+1)$ matrix is $(m+1)$. With this, I can now exhale a sigh of relief and continue believing that this is not true in general. (By the way I also know that it is true for free modules of infinite rank) 

