Problem II.6.2 in Hartshorne In this problem we consider a closed irreducible subset of $X\subset \mathbb{P}^n_k$ which is regular in codimension 1, where $k$ is an algebraically closed field.
I'm stuck on parts b and c and much would appreciate any long or short hint or full solution!
In part a) we define a group homomorphism out of the subgroup of $\operatorname{div}\mathbb{P}^n_k$ generated by the prime divisors $Z\subset \mathbb{P}^n_k$ that don't contain $X$ into $\operatorname{div}X$. This map is defined by
$$Z\mapsto Z.X$$
where $Z.X:=\sum n_iY_i$, $Y_i$ are the irreducible components of $X\cap Z$ (which are automatically of codim 1 in $X$). The numbers $n_i$ are defined as follows: let $r=r(i)$ be such that $D_+(x_{r})\cap Y_i\neq \emptyset$. Then $Y_i\cap D_+(X_{r})=Y_i\cap \operatorname{Spec}(k[x_0/x_{r},...,x_n/x_r])$ is cut out by some $f_i\in \operatorname{Spec}(k[x_0/x_{r},...,x_n/x_r])$. If $\eta_i$ is the generic point of $Y_i$ we know $\mathcal{O}_{X,\eta_i}$ is a DVR with valuation say $v_i$ and we define $n_i:=v_i(\bar{f})$.
In part b) we have to show that if D is principal in $\operatorname{div}\mathbb{P}^n_k$ and if $D.X$ is defined then D.X is principal in $\operatorname{div}X$. Any hints on how to do this?
In part c) we have to show that the integers $n_i$ equal the intersection multiplicities $i(X,Z;Y_i)$. Here too I would appreciate any help!
After some hints I've made a little bit of progress on part b:
Since $D$ is principal there exists
$$f=g/h\in K(\mathbb{P}^n)=k[x_0,...,x_n]_{((0))}$$
such that $D=(f)=\sum_{Z_i\subset \mathbb{P}^n}v_{Z_i}(f)\cdot Z_i$. Here, the sum is over all irreducible subsets of codim 1 for which $v_Z(f)\neq 0$ and $v_Z$ denotes the valuation defining the local ring associated to the generic point of $Z$.
Since $X$ is a closed irreducible subscheme of $\mathbb{P}^n$ we have $X=\text{Proj}(k[x_0,...,x_n]/I_X)$ for some prime homogeneous ideal $I_X$. I claim that $g,h\notin I_X$. If $h\in I_X$, then let us consider any point $p\in X$. We have $h\in I_X\subset p$. Let $q\subset k[x_0,...,x_n]$ be a minimal prime such that $h\in q\subset p$. By Krull's Hauptidealsatz $q$ has height one and there for $\overline{\{q\}}\subset \mathbb{P}^n$ has codimension 1. Therefore $\mathcal{O}_{\mathbb{P}^n,q}$ is a DVR and $h\in q$ means $g/h\notin \mathcal{O}_{\mathbb{P}^n,q} $ so $v_q(f)<0$. This means $ \overline{\{q\}}=Z$ for one of the $Z$ occurring in $D$. Since $p\in \overline{\{q\}}$ and $p$ was an arbitrary point of $X$ we have $X\subset D$ which is a contradiction. A similar argument shows that $g\notin I_X$. Therefore $\bar{g}/\bar{h}$ is an element (non-zero) of the field
$$(k[x_0,...,x_n]/I_X)_{((0))}=K(X).$$
We may note also that $\bar{g}/\bar{h}$ is the image of $f$ under the composite
$$\mathcal{O}_{\mathbb{P}^n}(D_+(h))\to\mathcal{O}_X(D_+(h)\cap X)\to K(X).$$
Next I want to show that $D.X=(\bar{f})$ where $\bar{f}:=\bar{g}/\bar{h}$ and this is where I am currently stuck. What I have tried so far is to write $D.X$ and $(\bar{f})$ as:
$$D.X=\Big(\sum_{Z_i\subset \mathbb{P}^n}v_{Z_i}(f)\cdot Z_i\Big).X=\sum_{ij}v_{Z_i}v_{ij}(f_j)Y_{ij}$$
(where the $Y_{ij}'$s are the components of $X\cap Z_i$) and
$$(\bar{f})=\sum_{Y\subset X}v_Y(\bar{f})\cdot Y$$
and show that the same prime divisors appear in these two expressions but I'm not really getting anywhere.
 A: Claim: Let $X\subset \Bbb P^n$ be a closed subvariety, regular in codimension one. If $D=(f)$ is a principal divisor on $\Bbb P^n$, none of who's components contain $X$, then $D.X=(f|_X)$.
Proof: Write $D=\sum v_{Y_i}(f)Y_i$, and for each $Y_i$ let $f_i$ be a local equation for $Y_i$ on some neighborhood which intersects $X$. Then by definition of $D.X$, we have that $$D.X=\sum_{Y_i} v_{Y_i}(f)\left(\sum_{Y_{ij}\subset Y_i\cap X} v_{Y_{ij}}(f_i|_X)Y_{ij}\right).$$
On the other hand, for each $Y_i$ we can find an open set of $\Bbb P^n$ which intersects $Y_i$ and $X$ on which $f=u\cdot f_i^{v_{Y_i}(f)}$ for $f_i$ as before and $u$ a unit: this is true in the local ring $\mathcal{O}_{\Bbb P^1,Y_i}$, so it is true in an open neighborhood. Then restricting to $X$, we get that $f|_X$ has valuation $v_{Y_i}(f)\cdot v_{Y_{ij}}(f_i|_X)$ along $Y_{ij}$. Therefore $(f|_X)=\sum_{Y_{ij}\subset X} v_{Y_i}(f)\cdot v_{Y_{ij}}(f_i|_X) Y_{ij}$ and we're done.

To attack part (c), the key idea is to sheafify the filtration coming from the definition of intersection multiplicity in chapter I. I'll write a full proof, but I'll leave most of it under spoilers so you can access it at your own pace.
The first step is to prove that the functor sending a graded module $M$ over a graded ring $S$ to the sheaf $\widetilde{M}$ on $\operatorname{Proj} S$ is exact:

 Proof: It's enough to show that $M\mapsto M_{(\mathfrak{p})}$ is exact for $\mathfrak{p}$ a graded prime ideal of $S$ not containing the irrelevant ideal, because the stalk of $\widetilde{M}$ at a point $\mathfrak{p}\in\operatorname{Proj} S$ is given by $M_{(\mathfrak{p})}$ per proposition II.5.11(a) and exactness of a sequence of sheaves can be checked on stalks.


 First we show that for a homogeneous element $f\in S$, the graded localization functor $M\mapsto M_{(f)}$ is exact.
 Given an exact sequence of graded $S$-modules $0\to M'\to M\to M''\to 0$, we have that localization at a homogeneous element $f$ gives an exact sequence of graded modules $0\to M'_f \to M_f \to M''_f\to 0$ because localization is exact and commutes with direct sums: the $d^{th}$ graded piece of $M_f$ is exactly the elements $\frac{m}{f^n}$ where $\deg m - n\deg f=d$. As our maps are maps of graded modules and therefore preserve degree, we can restrict to the elements of any fixed degree to get an exact sequence $0\to (M'_f)_d \to (M_f)_d \to (M''_f)_d \to 0$, so we have the claim.


 Next, I claim that if $\mathfrak{p}\subset S$ is a graded prime ideal and $f$ is a homogeneous element not in $\mathfrak{p}$, then $M_{(\mathfrak{p})} = (M_{(f)})_{\mathfrak{p}'}$ where $\mathfrak{p}'$ is $(\mathfrak{p}_{(f)})_0$. This is not hard to see: given an element $\frac{x}{g}\in M_{(\mathfrak{p})}$, we can write it as $(xg^{\deg(f) -1}/f^{\deg(x)})/(g^{\deg(f)}/f^{\deg(g)})$ because $\deg(x)=\deg(g)$ and $g^{\deg(f)}/f^{\deg(g)}$ isn't in $\mathfrak{p}'$. Conversely, if we have an element $(x/f^n)/(g/f^m)\in (M_{(f)})_{\mathfrak{p}'}$, we can write it as $(xf^m)/(gf^n)$ and the composition both ways is the identity.


 This shows that $M\mapsto M_{(\mathfrak{p})}$ is the composition of the two exact functors $M\mapsto M_{(f)}$ and $M_{(f)}\mapsto (M_{(f)})_{\mathfrak{p}'}$. $\blacksquare$

With that proven, we can actually follow our main idea.

 Let $S=k[t_0,\cdots,t_n]$ be the homogeneous coordinate ring of $\Bbb P^n_k$ in the sense of chapter I, $I_X\subset S$ the homogeneous ideal of $X\subset\Bbb P^n_k$, and $\hat{f}$ be the homogeneous equation of $V$. Then by proposition I.7.4, we get a finite filtration of $S/(I_X+\hat{f})$ by graded submodules $M_i$ with subquotients isomorphic to $(S/\mathfrak{p}_i)(n_i)$ for integers $n_i$ and homogeneous prime ideals $\mathfrak{p}_i\subset S$. Chapter I's intersection multiplicity along $Y$ is the number of times $\mathfrak{p}_i=I_Y$ among the subquotients of this filtration. Applying the associated sheaf functor (which is exact), we get a finite filtration of $\mathcal{O}_{X\cap V}$ by sheaves $\widetilde{M}_i$ with subquotients isomorphic to $(j_{i})_*\mathcal{O}_{Z_i}(n_i)$ for $Z_i$ integral subschemes of $\Bbb P^n_k$ contained in $X\cap V$ with closed immersion $j_i:Z_i\to \Bbb P^n_k$. Now we take the stalk at $\eta$, the generic point of $Y$: since $\eta\in Z_i$ iff $Z_i=Y$, we get that the subquotients of the filtration $(\widetilde{M}_i)_\eta$ are all either $0$ or $\mathcal{O}_{Y,\eta}(n_i)\cong \mathcal{O}_{Y,\eta}$ (this last bit isomorphism relies on the fact that $\mathcal{O}(1)$ is invertible), and so the intersection multiplicity from chapter I is the length of $\mathcal{O}_{X,\eta}/(f)$. But $\mathcal{O}_{X,\eta}$ is a DVR, so $(f)=\mathfrak{m}_\eta^{\nu_Y(f)}$, and $\mathcal{O}_{X,\eta}/(f)$ has length $\nu_Y(f)$: it's filtered by $$0\subset \mathcal{O}_{X,\eta}/\mathfrak{m}_\eta \subset \mathcal{O}_{X,\eta}/\mathfrak{m}_\eta^2\subset \cdots \subset \mathcal{O}_{X,\eta}/\mathfrak{m}_\eta^{\nu_Y(f)} = \mathcal{O}_{X,\eta}/(f).$$ Thus the two quantities are equal, and writing $n_i=\deg(D)$ we see that by theorem I.7.7 we have that $\deg(D.X)=(\deg D)\cdot(\deg X)$.

A: $D$ being a principle divisor means $D = \operatorname{div}(f)$ for some rational function $f \in K(\mathbb P^n)$. The assumption that $X \not \subset D$ means that $f$ does not vanish identically on $X$, so $f$ defines a rational function $\bar f  \in K(X)$. Then I guess that $\operatorname{div}(\bar f) = D.X$.
