hcju/stacksqa huggingface dataset:
In the statement $f(Z) \subset X$ is the scheme theoretic image of $f$ and it is also the reduced induced algebraic space structure on the closed subset $f(|Z|) \subset X$, see Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-scheme-theoretic-image-reduced}. Then $Z$ and $f(Z)$ are reduced, proper (hence decent) algebraic spaces over $k$, whence integral (Definition \ref{definition-integral-algebraic-space}). The left hand side is computed using the coefficient of $n_1 \ldots n_d$ in the function $$ \chi(Y, \mathcal{O}_Z \otimes f^*\mathcal{L}_1^{\otimes n_1} \otimes \ldots \otimes f^*\mathcal{L}_d^{\otimes n_d}) = \sum (-1)^i \chi(X, R^if_*\mathcal{O}_Z \otimes \mathcal{L}_1^{\otimes n_1} \otimes \ldots \otimes \mathcal{L}_d^{\otimes n_d}) $$ The equality follows from Lemma \ref{lemma-euler-characteristic-morphism} and the projection formula (Cohomology, Lemma \ref{cohomology-lemma-projection-formula}). If $f(Z)$ has dimension $< d$, then the right hand side is a polynomial of total degree $< d$ by Lemma \ref{lemma-numerical-polynomial-from-euler} and the result is true. Assume $\dim(f(Z)) = d$. Then by dimension theory (Lemma \ref{lemma-alteration-dimension}) we find that the equivalent conditions (1) -- (5) of Lemma \ref{lemma-finite-degree} hold. Thus $\deg(Z \to f(Z))$ is well defined. By the already used Lemma \ref{lemma-finite-degree} we find $f : Z \to f(Z)$ is finite over a nonempty open $V$ of $f(Z)$; after possibly shrinking $V$ we may assume $V$ is a scheme. Let $\xi \in V$ be the generic point. Thus $\deg(f : Z \to f(Z))$ the length of the stalk of $f_*\mathcal{O}_Z$ at $\xi$ over $\mathcal{O}_{X, \xi}$ and the stalk of $R^if_*\mathcal{O}_X$ at $\xi$ is zero for $i > 0$ (for example by Cohomology of Spaces, Lemma \ref{spaces-cohomology-lemma-finite-higher-direct-image-zero}). Thus the terms $\chi(X, R^if_*\mathcal{O}_Z \otimes \mathcal{L}_1^{\otimes n_1} \otimes \ldots \otimes \mathcal{L}_d^{\otimes n_d})$ with $i > 0$ have total degree $< d$ and $$ \chi(X, f_*\mathcal{O}_Z \otimes \mathcal{L}_1^{\otimes n_1} \otimes \ldots \otimes \mathcal{L}_d^{\otimes n_d}) = \deg(f : Z \to f(Z)) \chi(f(Z), \mathcal{L}_1^{\otimes n_1} \otimes \ldots \otimes \mathcal{L}_d^{\otimes n_d}|_{f(Z)}) $$ modulo a polynomial of total degree $< d$ by Lemma \ref{lemma-numerical-polynomial-leading-term}. The desired result follows.
We may replace $X$ by $Z$ and $\mathcal{L}_i$ by $\mathcal{L}_i|_Z$. Thus we may assume $X = Z$ and $\mathcal{L}_1 = \mathcal{O}_X(D)$. Then $\mathcal{L}_1^{-1}$ is the ideal sheaf of $D$ and we can consider the short exact sequence $$ 0 \to \mathcal{L}_1^{\otimes -1} \to \mathcal{O}_X \to \mathcal{O}_D \to 0 $$ Set $P(n_1, \ldots, n_d) = \chi(X, \mathcal{L}_1^{\otimes n_1} \otimes \ldots \otimes \mathcal{L}_d^{\otimes n_d})$ and $Q(n_1, \ldots, n_d) = \chi(D, \mathcal{L}_1^{\otimes n_1} \otimes \ldots \otimes \mathcal{L}_d^{\otimes n_d}|_D)$. We conclude from additivity (Lemma \ref{lemma-euler-characteristic-additive}) that $$ P(n_1, \ldots, n_d) - P(n_1 - 1, n_2, \ldots, n_d) = Q(n_1, \ldots, n_d) $$ Because the total degree of $P$ is at most $d$, we see that the coefficient of $n_1 \ldots n_d$ in $P$ is equal to the coefficient of $n_2 \ldots n_d$ in $Q$.
Choose a scheme $U$ with a point $u$ and an \'etale morphism $f : U \to X$ mapping $u$ to $x$. Lift $\overline{x}$ to a geometric point of $U$ over $u$. Recall that $\mathcal{O}_{X, \overline{x}} = \mathcal{O}_{U, u}^{sh}$ where the strict henselization is with respect to our chosen lift of $\overline{x}$, see Properties of Spaces, Lemma \ref{spaces-properties-lemma-describe-etale-local-ring}. Finally, we have $$ \mathcal{F}_{\overline{x}} = (f^*\mathcal{F})_u \otimes_{\mathcal{O}_{U, u}} \mathcal{O}_{X, \overline{x}} = (f^*\mathcal{F})_u \otimes_{\mathcal{O}_{U, u}} \mathcal{O}_{U, u}^{sh} $$ by Properties of Spaces, Lemma \ref{spaces-properties-lemma-stalk-quasi-coherent}. Hence the equivalence of (1), (2), and (3) follows from More on Flatness, Lemma \ref{flat-lemma-weakly-associated-henselization}. If $X$ is locally Noetherian, then any $U$ as above is locally Noetherian, hence we see that (1), resp.\ (2) are equivalent to (4), resp.\ (5) by Divisors, Lemma \ref{divisors-lemma-ass-weakly-ass}. On the other hand, in the locally Noetherian case the local ring $\mathcal{O}_{X, \overline{x}}$ is Noetherian too (Properties of Spaces, Lemma \ref{spaces-properties-lemma-Noetherian-local-ring-Noetherian}). Hence the equivalence of (3) and (6) by the same lemma (or by Algebra, Lemma \ref{algebra-lemma-ass-weakly-ass}).
For every geometric point $\overline{x} \in X$ the sequence of stalks $0 \to \mathcal{F}_{1, \overline{x}} \to \mathcal{F}_{2, \overline{x}} \to \mathcal{F}_{3, \overline{x}} \to 0$ is a short exact sequence of $\mathcal{O}_{X, \overline{x}}$-modules. Hence the lemma follows from Algebra, Lemma \ref{algebra-lemma-weakly-ass}.
Since $x \in \text{Supp}(\mathcal{F})$ the stalk $\mathcal{F}_{\overline{x}}$ is not zero. Hence $\text{WeakAss}(\mathcal{F}_{\overline{x}})$ is nonempty by Algebra, Lemma \ref{algebra-lemma-weakly-ass-zero}. On the other hand, the spectrum of $\mathcal{O}_{X, \overline{x}}$ is a singleton. Hence $x$ is a weakly associated point of $\mathcal{F}$ by definition. The final statement follows as $\mathcal{O}_{X, \overline{x}} \to \mathcal{O}_{Z, \overline{z}}$ is a surjection, the spectrum of $\mathcal{O}_{Z, \overline{z}}$ is a singleton, and $\mathcal{F}_{\overline{x}}$ is a nonzero module over $\mathcal{O}_{Z, \overline{z}}$.
(A quasi-separated algebraic space is decent, see Decent Spaces, Section \ref{decent-spaces-section-reasonable-decent}. A locally separated algebraic space is decent, see Decent Spaces, Lemma \ref{decent-spaces-lemma-locally-separated-decent}.) Choose a scheme $U$, a point $u \in U$, and an \'etale morphism $f : U \to X$ mapping $u$ to $x$. By Decent Spaces, Lemma \ref{decent-spaces-lemma-decent-no-specializations-map-to-same-point} if $u' \leadsto u$ is a nontrivial specialization, then $f(u') \not = x$. Hence we see that $u \in \text{Supp}(f^*\mathcal{F})$ is not a specialization of another point of $\text{Supp}(f^*\mathcal{F})$. Hence $u \in \text{WeakAss}(f^*\mathcal{F})$ by Divisors, Lemma \ref{lemma-minimal-support-in-weakly-ass}.
Let $s \in \Gamma(X, \mathcal{F})$ be a section which restricts to zero on $U$. Let $\mathcal{F}' \subset \mathcal{F}$ be the image of the map $\mathcal{O}_X \to \mathcal{F}$ defined by $s$. Then $\mathcal{F}'|_U = 0$. This implies that $\text{WeakAss}(\mathcal{F}') \cap \Im(|U| \to |X|) = \emptyset$ (by the definition of weakly associated points). On the other hand, $\text{WeakAss}(\mathcal{F}') \subset \text{WeakAss}(\mathcal{F})$ by Lemma \ref{lemma-ses-weakly-ass}. We conclude $\text{WeakAss}(\mathcal{F}') = \emptyset$. Hence $\mathcal{F}' = 0$ by Lemma \ref{lemma-weakly-ass-zero}.
By Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-pushforward} the $\mathcal{O}_Y$-module $f_*\mathcal{F}$ is quasi-coherent hence the lemma makes sense. Choose an affine scheme $V$, a point $v \in V$, and an \'etale morphism $V \to Y$ mapping $v$ to $y$. We may replace $f : X \to Y$, $\mathcal{F}$, $y$ by $X \times_Y V \to V$, $\mathcal{F}|_{X \times_Y V}$, $v$. Thus we may assume $Y$ is an affine scheme. In this case $X$ is quasi-compact, hence we can choose an affine scheme $U$ and a surjective \'etale morphism $U \to X$. Denote $g : U \to Y$ the composition. Then $f_*\mathcal{F} \subset g_*(\mathcal{F}|_U)$. By Lemma \ref{lemma-ses-weakly-ass} we reduce to the case of schemes which is Divisors, Lemma \ref{divisors-lemma-weakass-pushforward}.
Choose a scheme $V$ and a surjective \'etale morphism $V \to Y$. Set $U = X \times_Y V$. Then $U \to V$ is an affine morphism of schemes. By our definition of weakly associated points the problem is reduced to the morphism of schemes $U \to V$. This case is treated in Divisors, Lemma \ref{divisors-lemma-weakly-ass-reverse-functorial}.
Choose a scheme $V$ and a surjective \'etale morphism $V \to Y$. Set $U = X \times_Y V$. Then $U \to V$ is an affine morphism of schemes and $U$ is locally Noetherian. By our definition of weakly associated points the problem is reduced to the morphism of schemes $U \to V$. This case is treated in Divisors, Lemma \ref{divisors-lemma-ass-functorial-equal}.
Choose a scheme $V$ and a surjective \'etale morphism $V \to Y$. Set $U = X \times_Y V$. Then $U \to V$ is a finite morphism of schemes. By our definition of weakly associated points the problem is reduced to the morphism of schemes $U \to V$. This case is treated in Divisors, Lemma \ref{divisors-lemma-weakly-associated-finite}.
Choose a scheme $V$, a point $v \in V$, and an \'etale morphism $V \to Y$ mapping $v$ to $y$. Choose a scheme $U$, a point $u \in U$, and an \'etale morphism $U \to V \times_Y X$ mapping $v$ to a point lying over $v$ and $x$. This is possible because there is a $t \in |V \times_Y X|$ mapping to $(v, y)$ by Properties of Spaces, Lemma \ref{spaces-properties-lemma-points-cartesian}. By definition we see that the dimension of $\mathcal{O}_{U_v, u}$ is zero. Hence $u$ is a generic point of the fiber $U_v$. By our definition of weakly associated points the problem is reduced to the morphism of schemes $U \to V$. This case is treated in Divisors, Lemma \ref{divisors-lemma-weakly-ass-pullback}.
Observe that $X_v = v \times_Y X = \Spec(\kappa(v)) \times_Y X$. Hence the implications (2) $\Rightarrow$ (1) $\Rightarrow$ (3) are clear. Assume that $\Spec(k) \to Y$ is a morphism from the spectrum of a field such that $X_k$ is locally Noetherian. Let $V \to Y$ be an \'etale morphism from a scheme $V$ and let $v \in V$ a point mapping to $y$. Then the scheme $v \times_Y \Spec(k)$ is nonempty. Choose a point $w \in v \times_Y \Spec(k)$. Consider the morphisms $$ X_v \longleftarrow X_w \longrightarrow X_k $$ Since $V \to Y$ is \'etale and since $w$ may be viewed as a point of $V \times_Y \Spec(k)$, we see that $\kappa(w) \supset k$ is a finite separable extension of fields (Morphisms, Lemma \ref{morphisms-lemma-etale-over-field}). Thus $X_w \to X_k$ is a finite \'etale morphism as a base change of $w \to \Spec(k)$. Hence $X_w$ is locally Noetherian (Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-locally-finite-type-locally-noetherian}). The morphism $X_w \to X_v$ is a surjective, affine, flat morphism as a base change of the surjective, affine, flat morphism $w \to v$. Then the fact that $X_w$ is locally Noetherian implies that $X_v$ is locally Noetherian. This can be seen by picking a surjective \'etale morphism $U \to X$ and then using that $U_w \to U_v$ is surjective, affine, and flat. Working affine locally on the scheme $U_v$ we conclude that $U_w$ is locally Noetherian by Algebra, Lemma \ref{algebra-lemma-descent-Noetherian}. \medskip\noindent Finally, it suffices to prove that (3) implies (4) in case we have a monomorphism $\Spec(k_0) \to Y$ in the class of $y$. Then $\Spec(k) \to Y$ factors as $\Spec(k) \to \Spec(k_0) \to Y$. The argument given above then shows that $X_k$ being locally Noetherian impies that $X_{k_0}$ is locally Noetherian.
Observe that given $V, v, x'$ as in the lemma we can find $U \to X \times_Y V$ and $u \in U$ mapping to $x'$ and then the morphism $U_v \to X_v$ is \'etale. Thus it is clear that (1) and (3) are equivalent as well as (2) and (4). Each of these implies (5). We will show that (5) implies (2). Suppose given $V, v, x'$ as well as $\Spec(k) \to X$ and $t \in |X_k|$ such that the point $t$ is a weakly associated point of $\mathcal{F}|_{X_k}$. We can choose a point $w \in v \times_Y \Spec(k)$. Then we obtain the morphisms $$ X_v \longleftarrow X_w \longrightarrow X_k $$ Since $V \to Y$ is \'etale and since $w$ may be viewed as a point of $V \times_Y \Spec(k)$, we see that $\kappa(w) \supset k$ is a finite separable extension of fields (Morphisms, Lemma \ref{morphisms-lemma-etale-over-field}). Thus $X_w \to X_k$ is a finite \'etale morphism as a base change of $w \to \Spec(k)$. Thus any point $x''$ of $X_w$ lying over $t$ is a weakly associated point of $\mathcal{F}|_{X_w}$ by Lemma \ref{lemma-etale-weak-assassin-up-down}. We may pick $x''$ mapping to $x'$ (Properties of Spaces, Lemma \ref{spaces-properties-lemma-points-cartesian}). Then Lemma \ref{lemma-weakly-ass-change-fields} implies that $x'$ is a weakly associated point of $\mathcal{F}|_{X_v}$. \medskip\noindent To finish the proof it suffices to show that the equivalent conditions (1) -- (5) imply (6) if we are given $\Spec(k_0) \to Y$ as in (6). In this case the morphism $\Spec(k) \to Y$ of (5) factors uniquely as $\Spec(k) \to \Spec(k_0) \to Y$. Then $x_0$ is the image of $t$ under the morphism $X_k \to X_{k_0}$. Hence the same lemma as above shows that (6) is true.
Via \'etale localization, this is an immediate consequence of the result for schemes, see Divisors, Lemma \ref{divisors-lemma-bourbaki}. The result for schemes is more general only because we haven't defined associated points for non-Noetherian algebraic spaces (hence we need to assume $X$ and the fibres of $X \to Y$ are locally Noetherian to even be able to formulate this result).
This follows from the case of schemes by \'etale localization. We write out the details completely. Choose a scheme $V$ and a surjective \'etale morphism $V \to Y$. Choose a scheme $U$ and a surjective \'etale morphism $U \to V \times_Y X$. Choose a scheme $V'$ and a surjective \'etale morphism $V' \to V \times_Y Y'$. Then $U' = V' \times_V U$ is a scheme and the morphism $U' \to X'$ is surjective and \'etale. \medskip\noindent Proof of (1). Choose $u' \in U'$ mapping to $x'$. Denote $v' \in V'$ the image of $u'$. Then $x' \in \text{Ass}_{X'/Y'}(\mathcal{F}')$ is equivalent to $u' \in \text{Ass}(\mathcal{F}|_{U'_{v'}})$ by definition (writing $\text{Ass}$ instead of $\text{WeakAss}$ makes sense as $U'_{v'}$ is locally Noetherian). Applying Divisors, Lemma \ref{divisors-lemma-base-change-relative-assassin} we see that the image $u \in U$ of $u'$ is in $\text{Ass}(\mathcal{F}|_{U_v})$ where $v \in V$ is the image of $u$. This in turn means $g'(x') \in \text{Ass}_{X/Y}(\mathcal{F})$. \medskip\noindent Proof of (2). Choose $u \in U$ mapping to $x$. Denote $v \in V$ the image of $u$. Then $x \in \text{Ass}_{X/Y}(\mathcal{F})$ is equivalent to $u \in \text{Ass}(\mathcal{F}|_{U_v})$ by definition. Choose a point $v' \in V'$ mapping to $y' \in |Y'|$ and to $v \in V$ (possible by Properties of Spaces, Lemma \ref{spaces-properties-lemma-points-cartesian}). Let $t \in \Spec(\kappa(v') \otimes_{\kappa(v)} \kappa(u))$ be a generic point of an irreducible component. Let $u' \in U'$ be the image of $t$. Applying Divisors, Lemma \ref{divisors-lemma-base-change-relative-assassin} we see that $u' \in \text{Ass}(\mathcal{F}'|_{U'_{v'}})$. This in turn means $x' \in \text{Ass}_{X'/Y'}(\mathcal{F}')$ where $x' \in |X'|$ is the image of $u'$.
The transcendence degree of a point over its image is defined in Morphisms of Spaces, Definition \ref{spaces-morphisms-definition-dimension-fibre}. Let $x' \in |X'|$ with image $x \in |X|$. Choose a scheme $V$ and a surjective \'etale morphism $V \to Y$. Choose a scheme $U$ and a surjective \'etale morphism $U \to V \times_Y X$. Choose a scheme $V'$ and a surjective \'etale morphism $V' \to V \times_Y Y'$. Then $U' = V' \times_V U$ is a scheme and the morphism $U' \to X'$ is surjective and \'etale. Choose $u \in U$ mapping to $x$. Denote $v \in V$ the image of $u$. Then $x \in \text{Ass}_{X/Y}(\mathcal{F})$ is equivalent to $u \in \text{Ass}(\mathcal{F}|_{U_v})$ by definition. Choose a point $u' \in U'$ mapping to $x' \in |X'|$ and to $u \in U$ (possible by Properties of Spaces, Lemma \ref{spaces-properties-lemma-points-cartesian}). Let $v' \in V'$ be the image of $u'$. Then $x' \in \text{Ass}_{X'/Y'}(\mathcal{F}')$ is equivalent to $u' \in \text{Ass}(\mathcal{F}'|_{U'_{v'}})$ by definition. Now the lemma follows from the discussion in Divisors, Remark \ref{divisors-remark-base-change-relative-assassin} applied to $u' \in \Spec(\kappa(v') \otimes_{\kappa(v)} \kappa(u))$.
Note that since $Y$ is a scheme, it makes sense to take the fibres $X_y = \Spec(\kappa(y)) \times_Y X$. (Also, by our definitions, the set $\text{Ass}_{X_y}(\mathcal{F}_y)$ is exactly the fibre of $\text{Ass}_{X/Y}(\mathcal{F}) \to Y$ over $y$, but we won't need this.) The question is local on $Y$, indeed, we have to show that $E$ is constructible if $Y$ is affine. In this case $X$ is quasi-compact. Choose an affine scheme $W$ and a surjective \'etale morphism $\varphi : W \to X$. Then $\text{Ass}_{X_y}(\mathcal{F}_y)$ is the image of $\text{Ass}_{W_y}(\varphi^*\mathcal{F}_y)$ for all $y \in Y$. Hence the lemma follows from the case of schemes for the open $\varphi^{-1}(U) \subset W$ and the morphism $W \to Y$. The case of schemes is More on Morphisms, Lemma \ref{more-morphisms-lemma-relative-assassin-constructible}.
Recall that formation of $Z$ commutes with \'etale localization, see Morphisms of Spaces, Definition \ref{spaces-morphisms-definition-scheme-theoretic-support} (which uses Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-scheme-theoretic-support} to define $Z$). Hence (1) and (2) follow from the case of schemes, see Divisors, Lemma \ref{divisors-lemma-on-subscheme-cut-out-by-Fit-0}. To get $\mathcal{G}_0$ as in part (3) we can use that we have $\mathcal{G}$ on $Z$ as in Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-scheme-theoretic-support} and set $\mathcal{G}_0 = (Z \to Z_0)_*\mathcal{G}$.
Reduces to Divisors, Lemma \ref{divisors-lemma-fitting-ideal-generate-locally} by \'etale localization (as well as the description of the local ring in Properties of Spaces, Section \ref{spaces-properties-section-stalks-structure-sheaf} and the fact that the strict henselization of a local ring is faithfully flat to see that the equality over the strict henselization is equivalent to the equality over the local ring).
The equivalence of (1) -- (3) follows from Definition \ref{definition-effective-Cartier-divisor} and the references preceding it. Assume (1) and let $x \in |D|$. Choose a scheme $W$ and a surjective \'etale morphism $W \to X$. Choose $w \in D \times_X W$ mapping to $x$. By (3) $D \times_X W$ is an effective Cartier divisor on $W$. Hence we can find affine \'etale neighbourhood $U$ by choosing an affine open neighbourhood of $w$ in $W$ as in Divisors, Lemma \ref{divisors-lemma-characterize-effective-Cartier-divisor}. \medskip\noindent Assume (4). Then we see that $\mathcal{I}_D|_U$ is invertible by Divisors, Lemma \ref{divisors-lemma-characterize-effective-Cartier-divisor}. Since we can find an \'etale covering of $X$ by the collection of all such $U$ and $X \setminus D$, we conclude that $\mathcal{I}_D$ is an invertible $\mathcal{O}_X$-module.
The question is \'etale local on $X$, see Morphisms of Spaces, Lemmas \ref{spaces-morphisms-lemma-affine-local} and Lemma \ref{lemma-characterize-effective-Cartier-divisor}. Thus this follows from the case of schemes which is Divisors, Lemma \ref{divisors-lemma-complement-locally-principal-closed-subscheme}.
Affineness is Lemma \ref{lemma-complement-locally-principal-closed-subscheme}. The density question is \'etale local on $X$ by Morphisms of Spaces, Definition \ref{spaces-morphisms-definition-scheme-theoretically-dense}. Thus this follows from the case of schemes which is Divisors, Lemma \ref{divisors-lemma-complement-effective-Cartier-divisor}.
We claim that the reduced induced algebraic space structure $D$ on $X \setminus U$ (Properties of Spaces, Definition \ref{spaces-properties-definition-reduced-induced-space}) is the desired effective Cartier divisor. The construction of $D$ commutes with \'etale localization, see proof of Properties of Spaces, Lemma \ref{spaces-properties-lemma-reduced-closed-subspace}. Let $X' \to X$ be a surjective \'etale morphism with $X'$ affine. Since $X$ is separated, we see that $U' = X' \times_X U$ is affine. Since $|X'| \to |X|$ is open, we see that $U'$ is dense in $X'$. Since $D' = X' \times_X D$ is the reduced induced scheme structure on $X' \setminus U'$, we conclude that $D'$ is an effective Cartier divisor by Divisors, Lemma \ref{divisors-lemma-complement-open-affine-effective-cartier-divisor} and its proof. This is what we had to show.
Let $\mathcal{L}$ be an invertible $\mathcal{O}_X$-module. Choose a dense affine open $U \subset X$ such that $\mathcal{L}|_U$ is trivial. This is possible because $X$ has a dense open subspace which is a scheme, see Properties of Spaces, Proposition \ref{spaces-properties-proposition-locally-quasi-separated-open-dense-scheme}. Denote $s : \mathcal{O}_U \to \mathcal{L}|_U$ the trivialization. The complement of $U$ is an effective Cartier divisor $D$. We claim that for some $n > 0$ the map $s$ extends uniquely to a map $$ s : \mathcal{O}_X(-nD) \longrightarrow \mathcal{L} $$ The claim implies the lemma because it shows that $\mathcal{L} \otimes_{\mathcal{O}_X} \mathcal{O}_X(nD)$ has a regular global section hence is isomorphic to $\mathcal{O}_X(D')$ for some effective Cartier divisor $D'$ by Lemma \ref{lemma-characterize-OD}. To prove the claim we may work \'etale locally. Thus we may assume $X$ is an affine Noetherian scheme. Since $\mathcal{O}_X(-nD) = \mathcal{I}^n$ where $\mathcal{I} = \mathcal{O}_X(-D)$ is the ideal sheaf of $D$ in $X$, this case follows from Cohomology of Schemes, Lemma \ref{coherent-lemma-homs-over-open}.
Let $D' \subset X$ be the scheme theoretic image of $D \to X_K \to X$. Since this morphism is quasi-compact, formation of $D'$ commutes with flat base change, see Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-flat-base-change-scheme-theoretic-image}. In particular we find that $D'_K = D$. Hence, we may assume $X$ is affine. Say $X = \Spec(A)$. Then $X_K = \Spec(A \otimes_R K)$ and $D$ corresponds to an ideal $I \subset A \otimes_R K$. We have to show that $J = I \cap A$ cuts out an effective Cartier divisor in $X$. First, observe that $A/J$ is flat over $R$ (as a torsion free $R$-module, see More on Algebra, Lemma \ref{more-algebra-lemma-valuation-ring-torsion-free-flat}), hence $J$ is finitely generated by More on Algebra, Lemma \ref{more-algebra-lemma-flat-finite-type-valuation-ring-finite-presentation} and Algebra, Lemma \ref{algebra-lemma-extension}. Thus it suffices to show that $J_\mathfrak q \subset A_\mathfrak q$ is generated by a single element for each prime $\mathfrak q \subset A$. Let $\mathfrak p = R \cap \mathfrak q$. Then $R_\mathfrak p$ is a valuation ring (Algebra, Lemma \ref{algebra-lemma-make-valuation-rings}). Observe further that $A_\mathfrak q/\mathfrak p A_\mathfrak q$ is a regular ring by Algebra, Lemma \ref{algebra-lemma-characterize-smooth-over-field}. Thus we may apply More on Algebra, Lemma \ref{more-algebra-lemma-picard-group-generic-fibre-regular} to see that $I(A_\mathfrak q \otimes_R K)$ is generated by a single element $f \in A_\mathfrak p \otimes_R K$. After clearing denominators we may assume $f \in A_\mathfrak q$. Let $\mathfrak c \subset R_\mathfrak p$ be the content ideal of $f$ (see More on Algebra, Definition \ref{more-algebra-definition-content-ideal} and More on Flatness, Lemma \ref{flat-lemma-flat-finite-type-local-valuation-ring-has-content}). Since $R_\mathfrak p$ is a valuation ring and since $\mathfrak c$ is finitely generated (More on Algebra, Lemma \ref{more-algebra-lemma-content-finitely-generated}) we see $\mathfrak c = (\pi)$ for some $\pi \in R_\mathfrak p$ (Algebra, Lemma \ref{algebra-lemma-characterize-valuation-ring}). After relacing $f$ by $\pi^{-1}f$ we see that $f \in A_\mathfrak q$ and $f \not \in \mathfrak pA_\mathfrak q$. Claim: $I_\mathfrak q = (f)$ which finishes the proof. To see the claim, observe that $f \in I_\mathfrak q$. Hence we have a surjection $A_\mathfrak q/(f) \to A_\mathfrak q/I_\mathfrak q$ which is an isomorphism after tensoring over $R$ with $K$. Thus we are done if $A_\mathfrak q/(f)$ is $R_\mathfrak p$-flat. This follows from Algebra, Lemma \ref{algebra-lemma-grothendieck-general} and our choice of $f$.