# Upper semi-continuity of rank

Given a finitely generated module $M$, define the rank of $M$ at $P \in Spec(A)$ to be the dimension of $M \otimes_A A_P/m_P$ as $A_P/m_P$ vector space. Why the set of $P \in Spec(A)$ where the rank of $M$ is at least $r$ is closed set?

I know that this may be proved using one of the corollaries of Nakayma lemma (elements of $M$ span $M$ over $A$ if and only if their residue classes span $M/mM$ over $A/m$), but can't see it. Can anyone show me the proof?

Let us show that the complement is open. If at a prime rank is less than $r$, then you can lift these generators to $M$ and we have a map $A^s\to M$, where $s<r$ is the rank at $P$. By Nakayama, when we localize at $P$, this map is surjective and thus it is by inverting a single element, since $M$ is finitely generated. Thus rank of $M$ is at most $s$ in a Zariski neighbourhood of $P$.
• Let $N$ be the quotient of $M$ by image of $A^s$ and let $S=A-P$. Then, we are given $S^{-1}N=0$ and $N$ is finitely generated, say by $n_1,\ldots, n_k$. Then, you can find $s_i\in S$ such that $s_in_i=0$. Take $s=\prod s_i$. Commented Dec 13, 2016 at 14:35