hcju/stacksqa huggingface dataset:
Pick $x_1, \ldots, x_n \in S$ which generate $S$ over $R$. Let $K$ be the fraction field of $R$ and $S_K = S \otimes_R K$. By Lemma \ref{lemma-Noether-normalization} we can find $y_1, \ldots, y_d \in S$ such that $K[y_1, \ldots, y_d] \to S_K$ is a finite injective map. Note that $y_i \in S$ because we may pick the $y_j$ in the $\mathbf{Z}$-algebra generated by $x_1, \ldots, x_n$. As a finite ring map is integral (see Lemma \ref{lemma-finite-is-integral}) we can find monic $P_i \in K[y_1, \ldots, y_d][T]$ such that $P_i(x_i) = 0$ in $S_K$. Let $f \in R$ be a nonzero element such that $fP_i \in R[y_1, \ldots, y_d][T]$ for all $i$. Then $fP_i(x_i)$ maps to zero in $S_K$. Hence after replacing $f$ by another nonzero element of $R$ we may also assume $fP_i(x_i)$ is zero in $S$. Set $x_i' = fx_i$ and let $S' \subset S$ be the $R$-subalgebra generated by $y_1, \ldots, y_d$ and $x'_1, \ldots, x'_n$. Note that $x'_i$ is integral over $R[y_1, \ldots, y_d]$ as we have $Q_i(x_i') = 0$ where $Q_i = f^{\deg_T(P_i)}P_i(T/f)$ which is a monic polynomial in $T$ with coefficients in $R[y_1, \ldots, y_d]$ by our choice of $f$. Hence $R[y_1, \ldots, y_d] \subset S'$ is finite by Lemma \ref{lemma-characterize-finite-in-terms-of-integral}. Since $S' \subset S$ we have $S'_f \subset S_f$ (localization is exact). On the other hand, the elements $x_i = x'_i/f$ in $S'_f$ generate $S_f$ over $R_f$ and hence $S'_f \to S_f$ is surjective. Whence $S'_f \cong S_f$ and we win.
We may write $S = k[x_1, \ldots, x_n]/\mathfrak p$. By Lemma \ref{lemma-dimension-height-polynomial-ring} all local rings of $S$ at maximal ideals have the same dimension. Apply Lemma \ref{lemma-Noether-normalization}. We get a finite injective ring map $$ k[y_1, \ldots, y_d] \to S $$ with $d = \dim(S)$. Clearly, $k(y_1, \ldots, y_d) \subset K$ is a finite extension and we win.
By Lemma \ref{lemma-dimension-prime-polynomial-ring} we know that $r = \text{trdeg}_k\ \kappa(\mathfrak p)$ is equal to the dimension of $V(\mathfrak p)$. Pick any maximal chain of primes $\mathfrak p \subset \mathfrak p_1 \subset \ldots \subset \mathfrak p_r$ starting with $\mathfrak p$ in $S$. This has length $r$ by Lemma \ref{lemma-dimension-spell-it-out}. Let $\mathfrak q_j$, $j \in J$ be the minimal primes of $S$ which are contained in $\mathfrak p$. These correspond $1-1$ to minimal primes in $S_{\mathfrak p}$ via the rule $\mathfrak q_j \mapsto \mathfrak q_jS_{\mathfrak p}$. By Lemma \ref{lemma-dimension-at-a-point-finite-type-over-field} we know that $\dim_x(X)$ is equal to the maximum of the dimensions of the rings $S/\mathfrak q_j$. For each $j$ pick a maximal chain of primes $\mathfrak q_j \subset \mathfrak p'_1 \subset \ldots \subset \mathfrak p'_{s(j)} = \mathfrak p$. Then $\dim(S_{\mathfrak p}) = \max_{j \in J} s(j)$. Now, each chain $$ \mathfrak q_i \subset \mathfrak p'_1 \subset \ldots \subset \mathfrak p'_{s(j)} = \mathfrak p \subset \mathfrak p_1 \subset \ldots \subset \mathfrak p_r $$ is a maximal chain in $S/\mathfrak q_j$, and by what was said before we have $\dim_x(X) = \max_{j \in J} r + s(j)$. The lemma follows.
By Lemma \ref{lemma-Noether-normalization} there exists a finite injective map $k[y_1, \ldots, y_d] \to S$ with $d = \dim(S)$. Since $K$ is flat over $k$ we also get a finite injective map $K[y_1, \ldots, y_d] \to K \otimes_k S$. The result follows from Lemma \ref{lemma-integral-sub-dim-equal}.
Choose a presentation $S = k[x_1, \ldots, x_n]/I$. This gives a presentation $K \otimes_k S = K[x_1, \ldots, x_n]/(K \otimes_k I)$. Let $\mathfrak q_K' \subset K[x_1, \ldots, x_n]$, resp.\ $\mathfrak q' \subset k[x_1, \ldots, x_n]$ be the corresponding primes. Consider the following commutative diagram of Noetherian local rings $$ \xymatrix{ K[x_1, \ldots, x_n]_{\mathfrak q_K'} \ar[r] & (K \otimes_k S)_{\mathfrak q_K} \\ k[x_1, \ldots, x_n]_{\mathfrak q'} \ar[r] \ar[u] & S_{\mathfrak q} \ar[u] } $$ Both vertical arrows are flat because they are localizations of the flat ring maps $S \to S_K$ and $k[x_1, \ldots, x_n] \to K[x_1, \ldots, x_n]$. Moreover, the vertical arrows have the same fibre rings. Hence, we see from Lemma \ref{lemma-dimension-base-fibre-equals-total} that $\text{height}(\mathfrak q') - \text{height}(\mathfrak q) = \text{height}(\mathfrak q_K') - \text{height}(\mathfrak q_K)$. Denote $x' \in X' = \Spec(k[x_1, \ldots, x_n])$ and $x'_K \in X'_K = \Spec(K[x_1, \ldots, x_n])$ the points corresponding to $\mathfrak q'$ and $\mathfrak q_K'$. By Lemma \ref{lemma-codimension} and what we showed above we have \begin{eqnarray*} n - \dim_x X & = & \dim_{x'} X' - \dim_x X \\ & = & \text{height}(\mathfrak q') - \text{height}(\mathfrak q) \\ & = & \text{height}(\mathfrak q_K') - \text{height}(\mathfrak q_K) \\ & = & \dim_{x'_K} X'_K - \dim_{x_K} X_K \\ & = & n - \dim_{x_K} X_K \end{eqnarray*} and the lemma follows.
Observe that $S_\mathfrak q \to (S_K)_{\mathfrak q_K}$ is a flat local homomorphism of local Noetherian rings with special fibre $(S_K \otimes_S \kappa(\mathfrak q))_{\mathfrak q_K}$. Hence the first equality by Lemma \ref{lemma-dimension-base-fibre-equals-total}. The second equality follows from the fact that we have $\dim_x X = \dim_{x_K} X_K$ with notation as in Lemma \ref{lemma-dimension-at-a-point-preserved-field-extension} and we have $\dim_x X = \dim S_\mathfrak q + \text{trdeg}_k \kappa(\mathfrak q)$ by Lemma \ref{lemma-dimension-at-a-point-finite-type-field} and similarly for $\dim_{x_K} X_K$. If we choose $\mathfrak q_K$ minimal over $\mathfrak q S_K$, then the dimension of the fibre ring will be zero.
The first statement is obvious. The second follows from Lemma \ref{lemma-graded-ring-minimal-prime}. The equality $\dim(S) = \dim_x\Spec(S)$ follows from the fact that every irreducible component passes through $x$ according to (2). Hence we may compute this dimension as the dimension of the local ring $R = S_{\mathfrak m}$ with $\mathfrak m = S_{+}$ by Lemma \ref{lemma-dimension-closed-point-finite-type-field}. Since $\mathfrak m^d/\mathfrak m^{d + 1} \cong \mathfrak m^dR/\mathfrak m^{d + 1}R$ we see that the Hilbert function of the local ring $R$ is equal to the Hilbert function of $S$, which is (4). We conclude the last equality of (3) by Proposition \ref{proposition-dimension}.
Let $K$ be the fraction field of $R$. Set $S_K = K \otimes_R S$. This is an algebra of finite type over $K$. We will argue by induction on $d = \dim(S_K)$ (which is finite for example by Noether normalization, see Section \ref{section-Noether-normalization}). Fix $d \geq 0$. Assume we know that the lemma holds in all cases where $\dim(S_K) < d$. \medskip\noindent Suppose given $R \to S$ and $M$ as in the lemma with $\dim(S_K) = d$. By Lemma \ref{lemma-filter-Noetherian-module} there exists a filtration $0 \subset M_1 \subset M_2 \subset \ldots \subset M_n = M$ so that $M_i/M_{i - 1}$ is isomorphic to $S/\mathfrak q$ for some prime $\mathfrak q$ of $S$. Note that $\dim((S/\mathfrak q)_K) \leq \dim(S_K)$. Also, note that an extension of free modules is free (see basic notion \ref{item-extension-free}). Thus we may assume $M = S$ and that $S$ is a domain of finite type over $R$. \medskip\noindent If $R \to S$ has a nontrivial kernel, then take a nonzero $f \in R$ in this kernel. In this case $S_f = 0$ and the lemma holds. (This is really the case $d = -1$ and the start of the induction.) Hence we may assume that $R \to S$ is a finite type extension of Noetherian domains. \medskip\noindent Apply Lemma \ref{lemma-Noether-normalization-over-a-domain} and replace $R$ by $R_f$ (with $f$ as in the lemma) to get a factorization $$ R \subset R[y_1, \ldots, y_d] \subset S $$ where the second extension is finite. Choose $z_1, \ldots, z_r \in S$ which form a basis for the fraction field of $S$ over the fraction field of $R[y_1, \ldots, y_d]$. This gives a short exact sequence $$ 0 \to R[y_1, \ldots, y_d]^{\oplus r} \xrightarrow{(z_1, \ldots, z_r)} S \to N \to 0 $$ By construction $N$ is a finite $R[y_1, \ldots, y_d]$-module whose support does not contain the generic point $(0)$ of $\Spec(R[y_1, \ldots, y_d])$. By Lemma \ref{lemma-support-closed} there exists a nonzero $g \in R[y_1, \ldots, y_d]$ such that $g$ annihilates $N$, so we may view $N$ as a finite module over $S' = R[y_1, \ldots, y_d]/(g)$. Since $\dim(S'_K) < d$ by induction there exists a nonzero $f \in R$ such that $N_f$ is a free $R_f$-module. Since $(R[y_1, \ldots, y_d])_f \cong R_f[y_1, \ldots, y_d]$ is free also we conclude by the already mentioned fact that an extension of free modules is free.
Write $S = R[x_1, \ldots, x_n]/(g_1, \ldots, g_m)$. For $g \in R[x_1, \ldots, x_n]$ denote $\overline{g}$ its image in $S$. We may write $M = S^{\oplus t}/\sum Sn_i$ for some $n_i \in S^{\oplus t}$. Write $n_i = (\overline{g}_{i1}, \ldots, \overline{g}_{it})$ for some $g_{ij} \in R[x_1, \ldots, x_n]$. Let $R_0 \subset R$ be the subring generated by all the coefficients of all the elements $g_i, g_{ij} \in R[x_1, \ldots, x_n]$. Define $S_0 = R_0[x_1, \ldots, x_n]/(g_1, \ldots, g_m)$. Define $M_0 = S_0^{\oplus t}/\sum S_0n_i$. Then $R_0$ is a domain of finite type over $\mathbf{Z}$ and hence Noetherian (see Lemma \ref{lemma-Noetherian-permanence}). Moreover via the injection $R_0 \to R$ we have $S \cong R \otimes_{R_0} S_0$ and $M \cong R \otimes_{R_0} M_0$. Applying Lemma \ref{lemma-generic-flatness-Noetherian} we obtain a nonzero $f \in R_0$ such that $(M_0)_f$ is a free $(R_0)_f$-module. Hence $M_f = R_f \otimes_{(R_0)_f} (M_0)_f$ is a free $R_f$-module.
We first prove the lemma for $S = R[x_1, \ldots, x_n]$, and then we deduce the result in general. \medskip\noindent Assume $S = R[x_1, \ldots, x_n]$. Choose elements $m_1, \ldots, m_t$ which generate $M$. This gives a short exact sequence $$ 0 \to N \to S^{\oplus t} \xrightarrow{(m_1, \ldots, m_t)} M \to 0. $$ Denote $K$ the fraction field of $R$. Denote $S_K = K \otimes_R S = K[x_1, \ldots, x_n]$, and similarly $N_K = K \otimes_R N$, $M_K = K \otimes_R M$. As $R \to K$ is flat the sequence remains exact after tensoring with $K$. As $S_K = K[x_1, \ldots, x_n]$ is a Noetherian ring (see Lemma \ref{lemma-Noetherian-permanence}) we can find finitely many elements $n'_1, \ldots, n'_s \in N_K$ which generate it. Choose $n_1, \ldots, n_r \in N$ such that $n'_i = \sum a_{ij}n_j$ for some $a_{ij} \in K$. Set $$ M' = S^{\oplus t}/\sum\nolimits_{i = 1, \ldots, r} Sn_i $$ By construction $M'$ is a finitely presented $S$-module, and there is a surjection $M' \to M$ which induces an isomorphism $M'_K \cong M_K$. We may apply Lemma \ref{lemma-generic-flatness-finitely-presented} to $R \to S$ and $M'$ and we find an $f \in R$ such that $M'_f$ is a free $R_f$-module. Thus $M'_f \to M_f$ is a surjection of modules over the domain $R_f$ where the source is a free module and which becomes an isomorphism upon tensoring with $K$. Thus it is injective as $M'_f \subset M'_K$ as it is free over the domain $R_f$. Hence $M'_f \to M_f$ is an isomorphism and the result is proved. \medskip\noindent For the general case, choose a surjection $R[x_1, \ldots, x_n] \to S$. Think of both $S$ and $M$ as finite modules over $R[x_1, \ldots, x_n]$. By the special case proved above there exists a nonzero $f \in R$ such that both $S_f$ and $M_f$ are free as $R_f$-modules and finitely presented as $R_f[x_1, \ldots, x_n]$-modules. Clearly this implies that $S_f$ is a finitely presented $R_f$-algebra and that $M_f$ is a finitely presented $S_f$-module.
Let $u \in U(R \to S, M_1) \cap U(R \to S, M_3)$. Choose $f_1, f_3 \in R$ such that $u \in D(f_1)$, $u \in D(f_3)$ and such that (\ref{equation-flat-and-finitely-presented}) holds for $f_1$ and $M_1$ and for $f_3$ and $M_3$. Then set $f = f_1f_3$. Then $u \in D(f)$ and (\ref{equation-flat-and-finitely-presented}) holds for $f$ and both $M_1$ and $M_3$. An extension of free modules is free, and an extension of finitely presented modules is finitely presented (Lemma \ref{lemma-extension}). Hence we see that (\ref{equation-flat-and-finitely-presented}) holds for $f$ and $M_2$. Thus $u \in U(R \to S, M_2)$ and we win.
In view of Lemma \ref{lemma-generic-flatness-locus-localize} this is a purely topological statement. Namely, by that lemma we see that $U(R \to S, M) \cap D(f_i)$ is dense in $D(f_i)$ for each $i \in I$. By Topology, Lemma \ref{topology-lemma-nowhere-dense-local} we see that $U(R \to S, M) \cap U$ is dense in $U$. Since $U$ is dense in $\Spec(R)$ we conclude that $U(R \to S, M)$ is dense in $\Spec(R)$.
Choose any valuation ring $A \subset K$ dominating $R$ (which exist by Lemma \ref{lemma-dominate}). Denote $v$ the corresponding valuation. Let $x_1, \ldots, x_r$ be a minimal set of generators of the maximal ideal $\mathfrak m$ of $R$. We may and do assume that $v(x_r) = \min\{v(x_1), \ldots, v(x_r)\}$. Consider the ring $$ S = R[x_1/x_r, x_2/x_r, \ldots, x_{r - 1}/x_r] \subset K. $$ Note that $\mathfrak mS = x_rS$ is a principal ideal. Note that $S \subset A$ and that $v(x_r) > 0$, hence we see that $x_rS \not = S$. Choose a minimal prime $\mathfrak q$ over $x_rS$. Then $\text{height}(\mathfrak q) = 1$ by Lemma \ref{lemma-minimal-over-1} and $\mathfrak q$ lies over $\mathfrak m$. Hence we see that $R' = S_{\mathfrak q}$ is a solution.
Observe that $(R, \mathfrak m)$ is not Artinian if and only if $V(\mathfrak m) \subset \Spec(R)$ is nowhere dense. See Proposition \ref{proposition-dimension-zero-ring}. We assume this from now on. \medskip\noindent Let $J \subset R$ be the largest ideal killed by a power of $\mathfrak m$. If $J \not = 0$ then $R \to R/J$ shows that $(R, \mathfrak m)$ is as in (4). \medskip\noindent Otherwise $J = 0$. In particular $\mathfrak m$ is not an associated prime of $R$ and we see that there is a nonzerodivisor $x \in \mathfrak m$ by Lemma \ref{lemma-ideal-nonzerodivisor}. If $\mathfrak m$ is not an associated prime of $R/xR$ then $\text{depth}(R) \geq 2$ by the same lemma. Thus we are left with the case when there is an $y \in R$, $y \not \in xR$ such that $y \mathfrak m \subset xR$. \medskip\noindent If $y \mathfrak m \subset x \mathfrak m$ then we can consider the map $\varphi : \mathfrak m \to \mathfrak m$, $f \mapsto yf/x$ (well defined as $x$ is a nonzerodivisor). By the determinantal trick of Lemma \ref{lemma-charpoly-module} there exists a monic polynomial $P$ with coefficients in $R$ such that $P(\varphi) = 0$. We conclude that $P(y/x) = 0$ in $R_x$. Let $R' \subset R_x$ be the ring generated by $R$ and $y/x$. Then $R \subset R'$ and $R'/R$ is a finite $R$-module annihilated by a power of $\mathfrak m$. Thus $R$ is as in (4). \medskip\noindent Otherwise there is a $t \in \mathfrak m$ such that $y t = u x$ for some unit $u$ of $R$. After replacing $t$ by $u^{-1}t$ we get $yt = x$. In particular $y$ is a nonzerodivisor. For any $t' \in \mathfrak m$ we have $y t' = x s$ for some $s \in R$. Thus $y (t' - s t ) = x s - x s = 0$. Since $y$ is not a zero-divisor this implies that $t' = ts$ and so $\mathfrak m = (t)$. Thus $(R, \mathfrak m)$ is regular of dimension 1.
The equivalence of (1) and (2) is Lemma \ref{lemma-valuation-ring-Noetherian-discrete}. Moreover, in the proof of Lemma \ref{lemma-valuation-ring-Noetherian-discrete} we saw that if $A$ is a discrete valuation ring, then $A$ is a PID, hence (3). Note that a regular local ring is a domain (see Lemma \ref{lemma-regular-domain}). Using this the equivalence of (3) and (4) follows from dimension theory, see Section \ref{section-dimension}. \medskip\noindent Assume (3) and let $\pi$ be a generator of the maximal ideal $\mathfrak m$. For all $n \geq 0$ we have $\dim_{A/\mathfrak m} \mathfrak m^n/\mathfrak m^{n + 1} = 1$ because it is generated by $\pi^n$ (and it cannot be zero). In particular $\mathfrak m^n = (\pi^n)$ and the graded ring $\bigoplus \mathfrak m^n/\mathfrak m^{n + 1}$ is isomorphic to the polynomial ring $A/\mathfrak m[T]$. For $x \in A \setminus \{0\}$ define $v(x) = \max\{n \mid x \in \mathfrak m^n\}$. In other words $x = u \pi^{v(x)}$ with $u \in A^*$. By the remarks above we have $v(xy) = v(x) + v(y)$ for all $x, y \in A \setminus \{0\}$. We extend this to the field of fractions $K$ of $A$ by setting $v(a/b) = v(a) - v(b)$ (well defined by multiplicativity shown above). Then it is clear that $A$ is the set of elements of $K$ which have valuation $\geq 0$. Hence we see that $A$ is a valuation ring by Lemma \ref{lemma-valuation-valuation-ring}. \medskip\noindent A valuation ring is a normal domain by Lemma \ref{lemma-valuation-ring-normal}. Hence we see that the equivalent conditions (1) -- (3) imply (5). Assume (5). Suppose that $\mathfrak m$ cannot be generated by $1$ element to get a contradiction. Then Lemma \ref{lemma-nonregular-dimension-one} implies there is a finite ring map $A \to A'$ which is an isomorphism after inverting any nonzero element of $\mathfrak m$ but not an isomorphism. In particular we may identify $A'$ with a subset of the fraction field of $A$. Since $A \to A'$ is finite it is integral (see Lemma \ref{lemma-finite-is-integral}). Since $A$ is normal we get $A = A'$ a contradiction.
Pick $x \in \mathfrak m$ nonzero. Apply Lemma \ref{lemma-finite-length} to the submodule $S \subset L \cong K^{\oplus n}$ where $n = [L : K]$. Thus the ring $S/xS$ has finite length over $R$. It follows that $S/\mathfrak m S$ has finite length over $\kappa(\mathfrak m)$. In other words, $\dim_{\kappa(\mathfrak m)} S/\mathfrak m S$ is finite (Lemma \ref{lemma-dimension-is-length}). Thus $S/\mathfrak mS$ is Artinian (Lemma \ref{lemma-finite-dimensional-algebra}). The structural results on Artinian rings implies parts (1) and (2), see for example Lemma \ref{lemma-artinian-finite-length}. Part (3) is implied by the finiteness established above.
Since $R$ has dimension $1$ we see that $x$ is contained in finitely many primes $\mathfrak m_i$, $i = 1, \ldots, n$, each maximal. Since $R$ is Noetherian we see that $R/xR$ is Artinian and $R/xR = \prod_{i = 1, \ldots, n} (R/xR)_{\mathfrak m_i}$ by Proposition \ref{proposition-dimension-zero-ring} and Lemma \ref{lemma-artinian-finite-length}. Hence $M/xM$ similarly decomposes as the product $M/xM = \prod (M/xM)_{\mathfrak m_i}$ of its localizations at the $\mathfrak m_i$. By Lemma \ref{lemma-finite-length} applied to $M_{\mathfrak m_i}$ over $R_{\mathfrak m_i}$ we see each $M_{\mathfrak m_i}/xM_{\mathfrak m_i} = (M/xM)_{\mathfrak m_i}$ has finite length over $R_{\mathfrak m_i}$. Thus $M/xM$ has finite length over $R$ as the above implies $M/xM$ has a finite filtration by $R$-submodules whose successive quotients are isomorphic to the residue fields $\kappa(\mathfrak m_i)$.
To begin we may assume that $L$ is the fraction field of $A$ by replacing $L$ by the fraction field of $A$ if necessary. Let $I \subset A$ be a nonzero ideal. Clearly $I$ generates $L$ as a $K$-vector space. Hence we see that $I \cap R \not = (0)$. Pick any nonzero $x \in I \cap R$. Then we get $I/xA \subset A/xA$. By Lemma \ref{lemma-finite-length-global} the $R$-module $A/xA$ has finite length as an $R$-module. Hence $I/xA$ has finite length as an $R$-module. Hence $I$ is finitely generated as an ideal in $A$.
If $L$ is not finite over $K$ choose a transcendence basis $x_1, \ldots, x_r$ of $L$ over $K$ and replace $R$ by $R[x_1, \ldots, x_r]$ localized at the maximal ideal generated by $\mathfrak m_R$ and $x_1, \ldots, x_r$. Thus we may assume $K \subset L$ finite. \medskip\noindent By Lemma \ref{lemma-dominate-by-dimension-1} we may assume $\dim(R) = 1$. \medskip\noindent Let $A \subset L$ be the integral closure of $R$ in $L$. By Lemma \ref{lemma-krull-akizuki} this is Noetherian. By Lemma \ref{lemma-integral-overring-surjective} there is a prime ideal $\mathfrak q \subset A$ lying over the maximal ideal of $R$. By Lemma \ref{lemma-characterize-dvr} the ring $A_{\mathfrak q}$ is a discrete valuation ring dominating $R$ as desired.
Assume $R$ is a UFD and let $\mathfrak p$ be a height 1 prime ideal. Take $x \in \mathfrak p$ nonzero and let $x = a_1 \ldots a_n$ be a factorization into irreducibles. Since $\mathfrak p$ is prime we see that $a_i \in \mathfrak p$ for some $i$. By Lemma \ref{lemma-characterize-UFD} the ideal $(a_i)$ is prime. Since $\mathfrak p$ has height $1$ we conclude that $(a_i) = \mathfrak p$. \medskip\noindent Assume every height $1$ prime is principal. Since $R$ is Noetherian every nonzero nonunit element $x$ has a factorization into irreducibles, see Lemma \ref{lemma-factorization-exists}. It suffices to prove that an irreducible element $x$ is prime, see Lemma \ref{lemma-characterize-UFD}. Let $(x) \subset \mathfrak p$ be a prime minimal over $(x)$. Then $\mathfrak p$ has height $1$ by Lemma \ref{lemma-minimal-over-1}. By assumption $\mathfrak p = (y)$. Hence $x = yz$ and $z$ is a unit as $x$ is irreducible. Thus $(x) = (y)$ and we see that $x$ is prime.
Say $x = \alpha \beta$ for $\alpha, \beta \in S^{-1}A$. Then $\alpha = a/s$ and $\beta = b/s'$ for $a, b \in A$, $s, s' \in S$. Thus we get $ss'x = ab$. By assumption we can write $ss' = p_1 \ldots p_r$ for some prime elements $p_i$. For each $i$ the element $p_i$ divides either $a$ or $b$. Dividing we find a factorization $x = a' b'$ and $a = s'' a'$, $b = s''' b'$ for some $s'', s''' \in S$. As $x$ is irreducible, either $a'$ or $b'$ is a unit. Tracing back we find that either $\alpha$ or $\beta$ is a unit. This proves (1). \medskip\noindent Suppose $x$ is prime. Then $A/(x)$ is a domain. Hence $S^{-1}A/xS^{-1}A = S^{-1}(A/(x))$ is a domain or zero. Thus $x$ maps to a prime element or a unit. \medskip\noindent Suppose that the image of $x$ in $S^{-1}A$ is a unit. Then $y x = s$ for some $s \in S$ and $y \in A$. By assumption $s = p_1 \ldots p_r$ with $p_i$ a prime element. For each $i$ either $p_i$ divides $y$ or $p_i$ divides $x$. In the second case $p_i$ and $x$ are associates (as $x$ is irreducible) and we are done. But if the first case happens for all $i = 1, \ldots, r$, then $x$ is a unit which is a contradiction. \medskip\noindent Suppose that the image of $x$ in $S^{-1}A$ is a prime element. Assume $a, b \in A$ and $ab \in (x)$. Then $sa = xy$ or $sb = xy$ for some $s \in S$ and $y \in A$. Say the first case happens. By assumption $s = p_1 \ldots p_r$ with $p_i$ a prime element. For each $i$ either $p_i$ divides $y$ or $p_i$ divides $x$. In the second case $p_i$ and $x$ are associates (as $x$ is irreducible) and we are done. If the first case happens for all $i = 1, \ldots, r$, then $a \in (x)$ as desired. This completes the proof of (2). \medskip\noindent The final statement of the lemma follows from (1) and (2) and Lemma \ref{lemma-characterize-UFD}.
Consider an ascending chain $(f_1) \subset (f_2) \subset (f_3) \subset \ldots$ of principal ideals in $R[x]$. Since $f_{n + 1}$ divides $f_n$ we see that the degrees decrease in the sequence. Thus $f_n$ has fixed degree $d \geq 0$ for all $n \gg 0$. Let $a_n$ be the leading coefficient of $f_n$. The condition $f_n \in (f_{n + 1})$ implies that $a_{n + 1}$ divides $a_n$ for all $n$. By our assumption on $R$ we see that $a_{n + 1}$ and $a_n$ are associates for all $n$ large enough (Lemma \ref{lemma-easy-divisibility}). Thus for large $n$ we see that $f_n = u f_{n + 1}$ where $u \in R$ (for reasons of degree) is a unit (as $a_n$ and $a_{n + 1}$ are associates).
Let $R$ be a UFD. Then $R$ satisfies the ascending chain condition for principal ideals (Lemma \ref{lemma-UFD-ascending-chain-condition-principal-ideals}), hence $R[x]$ satisfies the ascending chain condition for principal ideals (Lemma \ref{lemma-factoring-in-polynomial}), and hence every element of $R[x]$ has a factorization into irreducibles (Lemma \ref{lemma-factorization-exists}). Let $S \subset R$ be the multiplicative subset generated by prime elements. Since every nonunit of $R$ is a product of prime elements we see that $K = S^{-1}R$ is the fraction field of $R$. Observe that every prime element of $R$ maps to a prime element of $R[x]$ and that $S^{-1}(R[x]) = S^{-1}R[x] = K[x]$ is a UFD (and even a PID). Thus we may apply Lemma \ref{lemma-invert-prime-elements} to conclude.