T. Y. Lam's definition for the rank of a projective module This is a concept from Lectures on Modules and Rings of T. Y. Lam. It's on page 34-35 of the book.
Throughout this post, $R$ will be used to denote a commutative ring.

Let $P$ be a f.g $R-$projective module. For any prime ideal $\mathfrak{p} \subset R$, the localization $P_{\mathfrak{p}} := P \otimes_R R_{\mathfrak{p}}$ is also a f.g projective $R_{\mathfrak{p}}-$module. $\color{green}{\textbf{I get this part. Yay!!!}}$ Since $R_{\mathfrak{p}}$ is a local ring, $P_{\mathfrak{p}}$ must actually be free (by FC 19.29). $\color{green}{\textbf{Sounds good!!!}}$, say $P_{\mathfrak{p}} \cong R_{\mathfrak{p}}^{n_{\mathfrak{p}}}$ (for some $n_\mathfrak{p} \in \mathbb{N}$), so we have a function $f: \text{Spec}(R) \to \mathbb{Z}$, sending each $\mathfrak{p}$ to $n_\mathfrak{p}$. If that function $f$ is constant, i.e $n_\mathfrak{p} = n, \forall \mathfrak{p} \in \text{Spec}{R}$, we shall say that $P$ has rank $n$. And denote it as: $\text{rk}(P) = n$. $\color{red}{\textbf{What I don't really get is the idea behind this definition.}}$.

And then, the author leaves a fact unproved:

Fact. Let $P$, $Q$ be two f.g projective $R-$modules of rank $n$, and $m$ respectively. Show that $\text{rk}(P^*) = n$, and $\text{rk}(P\otimes_RQ) = nm$, where $P^* = \text{Hom}_R(P; R)$.

I think it should be very easy, since the author doesn't prove it. So here's my try on the problem.
Since $P$, $Q$ are both f.g $R-$projective, there exists $R-$modules $P'$, and $Q'$, such that $R^i = P\oplus P'$, and $R^j = Q\oplus Q'$. So we'll have:


*

*$R^i = \text{Hom}(R^i,R) = \text{Hom}(P \oplus P',R) = \text{Hom}(P,R) \oplus \text{Hom}(P',R)$

*$R^j = \text{Hom}(R^j,R) = \text{Hom}(Q \oplus Q',R) = \text{Hom}(Q,R) \oplus \text{Hom}(Q',R)$


So basically, we'll have $P \oplus P' \cong \text{Hom}(P,R) \oplus \text{Hom}(P',R)$, and $Q \oplus Q' \cong \text{Hom}(Q,R) \oplus \text{Hom}(Q',R)$.
How can I proceed from here? Is this the correct way to start?

I just wanna ask 2 things:


*

*Firstly, can you guys please give me the idea (or some motivation) behind this definition for the rank of a projective modules?

*Secondly, can you guys check my work (are there any subtle errors, or something), and give me a little push on the problem? :(
Thank you so much for your help,
And have a good day,
 A: You know the rank of a free module, right? It is the cardinality of a basis (well-defined since $R$ is commutative and $R \neq 0$). This is already well-known from linear algebra ($R$ is a field), where it is called the dimension (but as you see, this is really the same concept). Now it turns out that finitely generated projective $R$-modules are "not far" from being free: They are locally free. This means that there is a Zariski covering of $\mathrm{Spec}(R)$ (the spectrum, consisting of prime ideals of $R$) such that the restrictions are free. More elementary: There are elements $f_1,\dotsc,f_n$ generating the unit ideal such that each localization at $f_i$ is a finitely generated free module over $R_{f_i}$. In particular, the localization at each prime ideal $\mathfrak{p}$ is a free module over $R_{\mathfrak{p}}$, so that we may consider its rank. It is a locally constant function on $\mathrm{Spec}(R)$. I don't know why Lam only considers the case that this is a constant  function (which is automatic when $R$ has non nontrivial idempotents for example), since this is not necessary at all.
The formulas $\mathrm{rank}(M^*) = \mathrm{rank}(M)$, $\mathrm{rank}(M \oplus N) = \mathrm{rank}(M) + \mathrm{rank}(N)$ and $\mathrm{rank}(M \otimes N) = \mathrm{rank}(M) \cdot \mathrm{rank}(N)$ are clear if $M,N$ are finitely generated free modules. By localization (this process preserves duals, direct sums and tensor products) it follows more generally when $M,N$ are finitely generated projective modules.
A typical example is the ideal $I = (2,1+\sqrt{-5})$ of $R=\mathbb{Z}[\sqrt{-5}]$. One can prove $I \oplus I \cong R^2$, so that $I$ is a finitely generated projective $R$-module of (constant) rank $1$. But $I$ is not a principal ideal, and hence not free.
