Local rank and direct sum decomposition Let $A$ be a non zero commutative ring with unit. Let $n_1, n_2,\cdots , n_r$ be the distinct local ranks of the finitely generated projective $A$ module $M$. Could somebody help me to show that $A$ can be written as a direct sum of ideals $I_i$, $1\leq i\leq r$, and accordingly $M$ as the direct sum of submodules $M_i=I_iM$, $1\leq i\leq r$, such that the $I_i$ module $M_i$ is projective of rank $n_i$ for $1\leq i\leq n$.        
Local Rank: The rank $n_p$ of the free $A_p$ module $M_p$ is called the local rank of $M$ at $p$, $p\in \operatorname{Spec}R$.   
Note: The set of local ranks of a finitely generated projective module is finite.               
 A: Let $A$ be a non-zero ring and let $M$ be a finitely generated projective $A$-module.
For every $n \geq 1$, consider the set
$$
U_n = \{ \mathfrak{p} \in \mathrm{Spec} A \mid M_\mathfrak{p} \simeq A_\mathfrak{p}^n \},
$$
i.e. the set of prime ideals where $M$ has local rank equal to $n$. We want to prove that each $U_n$ is open in $\mathrm{Spec} A$ and only a finite number of them are non-empty.


*

*$M$ is finitely presented. Since $M$ is finitely generated, there exists a short exact sequence
$$
0 \longrightarrow K \longrightarrow F \longrightarrow M \longrightarrow 0,
$$
where $F$ is a free finitely generated module. Since $M$ is projective, the exact sequence above splits and then $F \simeq K \oplus M$, then $K$ is finitely generated.

*$U_n$ is an open subset of $\mathrm{Spec} A$. Let $\mathfrak{p} \in U_n$, then $M_\mathfrak{p}$ is a free $A_\mathfrak{p}$-module of rank $n$; consider $\omega_1, \dots, \omega_n$ an $A_\mathfrak{p}$-basis of $M_\mathfrak{p}$. We may suppose that $\omega_i = x_i / s$, where $x_i \in M$, $s \in A \setminus \mathfrak{p}$. We may consider the map $f \colon A^n \to M$ given by $f(a_1, \dots, a_n) = a_1 x_1 + \cdots + a_n x_n$. It is clear that the localization $f_\mathfrak{p} \colon A_\mathfrak{p}^n \to M_\mathfrak{p}$ is an isomorphism. Since $M$ is finitely presented, $\ker f$ is finitely generated. Since $(\ker f)_\mathfrak{p} = (\mathrm{coker} f)_\mathfrak{p} = 0$ and $\ker f$ and $\mathrm{coker} f$ are finitely generated, there exists $t \in A \setminus \mathfrak{p}$ such that $(\ker f) \otimes_A A[t^{-1}] = (\mathrm{coker} f) \otimes_A A[t^{-1}] = 0$. This proves that $f \otimes_A A[t^{-1}]$ is an isomorphism. Then for every $\mathfrak{q} \in \mathrm{Spec}(A[t^{-1}]) = \mathrm{Spec}(A) \setminus \mathrm{V}(t)$ we have $M_\mathfrak{q} \simeq A_\mathfrak{q}^n$, i.e. $\mathfrak{q} \in U_n$. This proves that $U_n$ contains the open neighborhood $\mathrm{Spec}(A) \setminus \mathrm{V}(t)$ of $\mathfrak{p}$.

*Only a finite number of $U_n$'s are non-empty. Since $M$ is finitely generated, there exists a surjection $A^r \to M$, then every local rank is not greater than $r$.
Now we have a decomposition of $\mathrm{Spec}(A)$ into a disjoint union of open subsets $U_{n_1} \coprod \cdots \coprod U_{n_r}$. It is clear that $U_{n_i}$ is also closed, then this proves that $A \simeq A_1 \times \cdots \times A_r$, where $A_i$ is a ring and $U_{n_i} \simeq \mathrm{Spec}(A_i)$. It is clear that $M \otimes_A A_i$ has constant rank equal to $n_i$.
A: It is well known that $M$ is finitely generated projective iff $M$ is locally free of finite rank (see texts on commutative algebra), and that any partition of $\mathrm{Spec}(R)$ into open subsets (automatically finite) corresponds to a product decomposition of $R$.
