hcju/stacksqa huggingface dataset:
It suffices to show that $I$ and $J$ are finite locally free $A$-modules of rank $1$, see Lemma \ref{lemma-finite-projective}. To do this, write $f = \sum_{i = 1, \ldots, n} x_i y_i$ with $x_i \in I$ and $y_i \in J$. We can also write $x_i y_i = a_i f$ for some $a_i \in A$. Since $f$ is a nonzerodivisor we see that $\sum a_i = 1$. Thus it suffices to show that each $I_{a_i}$ and $J_{a_i}$ is free of rank $1$ over $A_{a_i}$. After replacing $A$ by $A_{a_i}$ we conclude that $f = xy$ for some $x \in I$ and $y \in J$. Note that both $x$ and $y$ are nonzerodivisors. We claim that $I = (x)$ and $J = (y)$ which finishes the proof. Namely, if $x' \in I$, then $x'y = af = axy$ for some $a \in A$. Hence $x' = ax$ and we win.
Assume (1). The argument is nontrivial because we did not assume that $R$ was Noetherian in our definition of a Dedekind domain. Let $\mathfrak p \subset R$ be a prime ideal. Observe that $\mathfrak p \not = \mathfrak p^2$ by uniqueness of the factorizations in the definition. Pick $x \in \mathfrak p$ with $x \not \in \mathfrak p^2$. Let $y \in \mathfrak p$ be a second element (for example $y = 0$). Write $(x, y) = \mathfrak p_1 \ldots \mathfrak p_r$. Since $(x, y) \subset \mathfrak p$ at least one of the primes $\mathfrak p_i$ is contained in $\mathfrak p$. But as $x \not \in \mathfrak p^2$ there is at most one. Thus exactly one of $\mathfrak p_1, \ldots, \mathfrak p_r$ is contained in $\mathfrak p$, say $\mathfrak p_1 \subset \mathfrak p$. We conclude that $(x, y)R_\mathfrak p = \mathfrak p_1R_\mathfrak p$ is prime for every choice of $y$. We claim that $(x)R_\mathfrak p = \mathfrak pR_\mathfrak p$. Namely, pick $y \in \mathfrak p$. By the above applied with $y^2$ we see that $(x, y^2)R_\mathfrak p$ is prime. Hence $y \in (x, y^2)R_\mathfrak p$, i.e., $y = ax + by^2$ in $R_\mathfrak p$. Thus $(1 - by)y = ax \in (x)R_\mathfrak p$, i.e., $y \in (x)R_\mathfrak p$ as desired. \medskip\noindent Writing $(x) = \mathfrak p_1 \ldots \mathfrak p_r$ anew with $\mathfrak p_1 \subset \mathfrak p$ we conclude that $\mathfrak p_1 R_\mathfrak p = \mathfrak p R_\mathfrak p$, i.e., $\mathfrak p_1 = \mathfrak p$. Moreover, $\mathfrak p_1 = \mathfrak p$ is a finitely generated ideal of $R$ by Lemma \ref{lemma-product-ideals-principal}. We conclude that $R$ is Noetherian by Lemma \ref{lemma-cohen}. Moreover, it follows that $R_\mathfrak m$ is a discrete valuation ring for every prime ideal $\mathfrak p$, see Lemma \ref{lemma-characterize-dvr}. \medskip\noindent The equivalence of (2) and (3) follows from Lemmas \ref{lemma-normality-is-local} and \ref{lemma-characterize-dvr}. Assume (2) and (3) are satisfied. Let $I \subset R$ be an ideal. We will construct a factorization of $I$. If $I$ is prime, then there is nothing to prove. If not, pick $I \subset \mathfrak p$ with $\mathfrak p \subset R$ maximal. Let $J = \{x \in R \mid x \mathfrak p \subset I\}$. We claim $J \mathfrak p = I$. It suffices to check this after localization at the maximal ideals $\mathfrak m$ of $R$ (the formation of $J$ commutes with localization and we use Lemma \ref{lemma-characterize-zero-local}). Then either $\mathfrak p R_\mathfrak m = R_\mathfrak m$ and the result is clear, or $\mathfrak p R_\mathfrak m = \mathfrak m R_\mathfrak m$. In the last case $\mathfrak p R_\mathfrak m = (\pi)$ and the case where $\mathfrak p$ is principal is immediate. By Noetherian induction the ideal $J$ has a factorization and we obtain the desired factorization of $I$. We omit the proof of uniqueness of the factorization.
By Krull-Akizuki (Lemma \ref{lemma-krull-akizuki}) the ring $B$ is Noetherian. By Lemma \ref{lemma-integral-sub-dim-equal} $\dim(B) = 1$. Thus $B$ is a Dedekind domain by Lemma \ref{lemma-characterize-Dedekind}. Surjectivity of the map on spectra follows from Lemma \ref{lemma-integral-overring-surjective}. The last two statements follow from Lemma \ref{lemma-finite-extension-residue-fields-dimension-1}.
Proof of (1). Assume (1)(a). Say $y_1, \ldots, y_m$ generate $M'$. Then each $y_i = x_i/f_i$ for some $x_i \in M$ and nonzero $f_i \in R$. Hence we see that $f_1 \ldots f_m M' \subset M$. Since $R$ is Noetherian local of dimension $1$ we see that $\mathfrak m^n \subset (f_1 \ldots f_m)$ for some $n$ (for example combine Lemmas \ref{lemma-one-equation} and Proposition \ref{proposition-dimension-zero-ring} or combine Lemmas \ref{lemma-finite-length} and \ref{lemma-length-infinite}). In other words $\mathfrak m^nM' \subset M$ for some $n$ Hence $\text{length}(M'/M) < \infty$ by Lemma \ref{lemma-length-finite}, in other words (1)(b) holds. Assume (1)(b). Then $M'/M$ is a finite $R$-module (see Lemma \ref{lemma-finite-length-finite}). Hence $M'$ is a finite $R$-module as an extension of finite $R$-modules. Hence (1)(c). The implication (1)(c) $\Rightarrow$ (1)(a) follows from the remark following Definition \ref{definition-lattice}. \medskip\noindent Proof of (2). Suppose $M$ is a lattice in $V$ and $M' \subset M$ is an $R$-submodule. We have seen in (1) that if $M'$ is a lattice, then $\text{length}_R(M/M') < \infty$. Conversely, assume that $\text{length}_R(M/M') < \infty$. Then $M'$ is finitely generated as $R$ is Noetherian and for some $n$ we have $\mathfrak m^n M \subset M'$ (Lemma \ref{lemma-length-infinite}). Hence it follows that $M'$ contains a basis for $V$, and $M'$ is a lattice. \medskip\noindent Proof of (3). Assume $M$, $M'$ are lattices in $V$. Since $R$ is Noetherian the submodule $M \cap M'$ of $M$ is finite. As $M$ is a lattice we can find $x_1, \ldots, x_n \in M$ which form a $K$-basis for $V$. Because $M'$ is a lattice we can write $x_i = y_i/f_i$ with $y_i \in M'$ and $f_i \in R$. Hence $f_ix_i \in M \cap M'$. Hence $M \cap M'$ is a lattice also. The fact that $M + M'$ is a lattice follows from part (1). \medskip\noindent Part (4) follows from additivity of lengths (Lemma \ref{lemma-length-additive}) and the exact sequence $$ 0 \to M'/M \to M''/M \to M''/M' \to 0 $$ Part (5) follows from repeatedly applying part (4).
The ring $B$ is semi-local by Lemma \ref{lemma-finite-in-codim-1}. Write $y = b/b'$ for some $b, b' \in B$. By the additivity of $\text{ord}$ and multiplicativity of $\text{Nm}$ it suffices to prove the lemma for $y = b$ or $y = b'$. In other words we may assume $y \in B$. In this case the right hand side of the formula is $$ \sum [\kappa(\mathfrak m_i) : \kappa(\mathfrak m_A)] \text{length}_{B_{\mathfrak m_i}}((B/yB)_{\mathfrak m_i}) $$ By Lemma \ref{lemma-pushdown-module} this is equal to $\text{length}_A(B/yB)$. By Lemma \ref{lemma-order-vanishing-determinant} we have $$ \text{length}_A(B/yB) = d(B, yB) = \text{ord}_A(\det\nolimits_K(L \xrightarrow{y} L)). $$ Since $x = \text{Nm}_{L/K}(y) = \det\nolimits_K(L \xrightarrow{y} L)$ by definition the lemma is proved.
Suppose $\mathfrak q$ is an isolated point of $\Spec(S)$, i.e., $\{\mathfrak q\}$ is open in $\Spec(S)$. Because $\Spec(S)$ is a Jacobson space (see Lemmas \ref{lemma-finite-type-field-Jacobson} and \ref{lemma-jacobson}) we see that $\mathfrak q$ is a closed point. Hence $\{\mathfrak q\}$ is open and closed in $\Spec(S)$. By Lemmas \ref{lemma-disjoint-decomposition} and \ref{lemma-disjoint-implies-product} we may write $S = S_1 \times S_2$ with $\mathfrak q$ corresponding to the only point $\Spec(S_1)$. Hence $S_1 = S_{\mathfrak q}$ is a zero dimensional ring of finite type over $k$. Hence it is finite over $k$ for example by Lemma \ref{lemma-Noether-normalization}. We have proved (1) implies (2). \medskip\noindent Suppose $S_{\mathfrak q}$ is finite over $k$. Then $S_{\mathfrak q}$ is Artinian local, see Lemma \ref{lemma-finite-dimensional-algebra}. So $\Spec(S_{\mathfrak q}) = \{\mathfrak qS_{\mathfrak q}\}$ by Lemma \ref{lemma-artinian-finite-length}. Consider the exact sequence $0 \to K \to S \to S_{\mathfrak q} \to Q \to 0$. It is clear that $K_{\mathfrak q} = Q_{\mathfrak q} = 0$. Also, $K$ is a finite $S$-module as $S$ is Noetherian and $Q$ is a finite $S$-module since $S_{\mathfrak q}$ is finite over $k$. Hence there exists $g \in S$, $g \not \in \mathfrak q$ such that $K_g = Q_g = 0$. Thus $S_{\mathfrak q} = S_g$ and $D(g) = \{ \mathfrak q \}$. We have proved that (2) implies (3). \medskip\noindent Suppose $D(g) =  \{ \mathfrak q \}$. Since $D(g)$ is open by construction of the topology on $\Spec(S)$ we see that $\mathfrak q$ is an isolated point of $\Spec(S)$. We have proved that (3) implies (1). In other words (1), (2) and (3) are equivalent. \medskip\noindent Assume $\dim_{\mathfrak q} \Spec(S) = 0$. This means that there is some open neighbourhood of $\mathfrak q$ in $\Spec(S)$ which has dimension zero. Then there is an open neighbourhood of the form $D(g)$ which has dimension zero. Since $S_g$ is Noetherian we conclude that $S_g$ is Artinian and $D(g) = \Spec(S_g)$ is a finite discrete set, see Proposition \ref{proposition-dimension-zero-ring}. Thus $\mathfrak q$ is an isolated point of $D(g)$ and, by the equivalence of (1) and (2) above applied to $\mathfrak qS_g \subset S_g$, we see that $S_{\mathfrak q} = (S_g)_{\mathfrak qS_g}$ is finite over $k$. Hence (4) implies (2). It is clear that (1) implies (4). Thus (1) -- (4) are all equivalent. \medskip\noindent Lemma \ref{lemma-dimension-closed-point-finite-type-field} gives the implication (5) $\Rightarrow$ (4). The implication (4) $\Rightarrow$ (6) follows from Lemma \ref{lemma-dimension-at-a-point-finite-type-field}. The implication (6) $\Rightarrow$ (5) follows from Lemma \ref{lemma-finite-residue-extension-closed}. At this point we know (1) -- (6) are equivalent. \medskip\noindent The two statements at the end of the lemma we saw during the course of the proof of the equivalence of (1), (2) and (3) above.
Note that $S_{\mathfrak q}/\mathfrak pS_{\mathfrak q} = (S \otimes_R \kappa(\mathfrak p))_{\overline{\mathfrak q}}$. Moreover $S \otimes_R \kappa(\mathfrak p)$ is of finite type over $\kappa(\mathfrak p)$. The conditions correspond exactly to the conditions of Lemma \ref{lemma-isolated-point} for the $\kappa(\mathfrak p)$-algebra $S \otimes_R \kappa(\mathfrak p)$ and the prime $\overline{\mathfrak q}$, hence they are equivalent.
Write $S \otimes_R \kappa(\mathfrak p) = S_1 \times S_2$ with $S_1$ finite over $\kappa(\mathfrak p)$ and such that $\mathfrak q$ corresponds to a point of $S_1$ as in Lemma \ref{lemma-isolated-point}. This product decomposition induces a corresponding product decomposition for any $S \otimes_R \kappa(\mathfrak p)$-algebra. In particular, we obtain $S' \otimes_{R'} \kappa(\mathfrak p') = S'_1 \times S'_2$. Because $S \otimes_R R' \to S'$ is surjective the canonical map $(S \otimes_R \kappa(\mathfrak p)) \otimes_{\kappa(\mathfrak p)} \kappa(\mathfrak p') \to S' \otimes_{R'} \kappa(\mathfrak p')$ is surjective and hence $S_i \otimes_{\kappa(\mathfrak p)} \kappa(\mathfrak p') \to S'_i$ is surjective. It follows that $S'_1$ is finite over $\kappa(\mathfrak p')$. The map $S' \otimes_{R'} \kappa(\mathfrak p') \to \kappa(\mathfrak q')$ factors through $S_1'$ (i.e.\ it annihilates the factor $S_2'$) because the map $S \otimes_R \kappa(\mathfrak p) \to \kappa(\mathfrak q)$ factors through $S_1$ (i.e.\ it annihilates the factor $S_2$). Thus $\mathfrak q'$ corresponds to a point of $\Spec(S_1')$ in the disjoint union decomposition of the fibre: $\Spec(S' \otimes_{R'} \kappa(\mathfrak p')) = \Spec(S_1') \amalg \Spec(S_2')$, see Lemma \ref{lemma-spec-product}. Since $S_1'$ is finite over a field, it is Artinian ring, and hence $\Spec(S_1')$ is a finite discrete set. (See Proposition \ref{proposition-dimension-zero-ring}.) We conclude $\mathfrak q'$ is isolated in its fibre as desired.
Suppose $A \to B$ and $B \to C$ are quasi-finite ring maps. By Lemma \ref{lemma-compose-finite-type} we see that $A \to C$ is of finite type. Let $\mathfrak r \subset C$  be a prime of $C$ lying over $\mathfrak q \subset B$ and $\mathfrak p \subset A$. Since $A \to B$ and $B \to C$ are quasi-finite at $\mathfrak q$ and $\mathfrak r$ respectively, then there exist $b \in B$ and $c \in C$ such that $\mathfrak q$ is the only prime of $D(b)$ which maps to $\mathfrak p$ and similarly $\mathfrak r$ is  the only prime of $D(c)$ which maps to $\mathfrak q$. If $c' \in C$ is the image of $b \in B$, then $\mathfrak r$ is the only prime of $D(cc')$ which maps to $\mathfrak p$. Therefore $A \to C$ is quasi-finite at $\mathfrak r$.
Let $\mathfrak p' \subset R'$ be a prime lying over $\mathfrak p \subset R$. Then the fibre ring $S' \otimes_{R'} \kappa(\mathfrak p')$ is the base change of the fibre ring $S \otimes_R \kappa(\mathfrak p)$ by the field extension $\kappa(\mathfrak p) \to \kappa(\mathfrak p')$. Hence the first assertion follows from the invariance of dimension under field extension (Lemma \ref{lemma-dimension-at-a-point-preserved-field-extension}) and Lemma \ref{lemma-isolated-point}. The stability of quasi-finite maps under base change follows from this and the stability of finite type property under base change. The second assertion follows since the assumption implies that given a prime $\mathfrak q \subset S$ we can find a prime $\mathfrak q' \subset S'$ lying over it.
Observe that $B \to C$ is of finite type (Lemma \ref{lemma-compose-finite-type}) so that the statement makes sense. Let us use characterization (3) of Lemma \ref{lemma-isolated-point-fibre}. If $A \to C$ is quasi-finite at $\mathfrak r$, then there exists some $c \in C$ such that $$ \{\mathfrak r' \subset C \text{ lying over }\mathfrak p\} \cap D(c) = \{\mathfrak{r}\}. $$ Since the primes $\mathfrak r' \subset C$ lying over $\mathfrak q$ form a subset of the primes $\mathfrak r' \subset C$ lying over $\mathfrak p$ we conclude $B \to C$ is quasi-finite at $\mathfrak r$.
Let $x_1, \ldots, x_n$ be generators of $S$ over $R$. Since $\mathfrak p$ is a minimal prime we have that $\mathfrak pR_{\mathfrak p}$ is a locally nilpotent ideal, see Lemma \ref{lemma-minimal-prime-reduced-ring}. Hence $\mathfrak pS_{\mathfrak p}$ is a locally nilpotent ideal, see Lemma \ref{lemma-locally-nilpotent}. By assumption the finite type $\kappa(\mathfrak p)$-algebra $S_{\mathfrak p}/\mathfrak pS_{\mathfrak p}$ has finitely many primes. Hence (for example by Lemmas \ref{lemma-finite-type-algebra-finite-nr-primes} and \ref{lemma-Noether-normalization}) $\kappa(\mathfrak p) \to S_{\mathfrak p}/\mathfrak pS_{\mathfrak p}$ is a finite ring map. Thus we may find monic polynomials $P_i \in R_{\mathfrak p}[X]$ such that $P_i(x_i)$ maps to zero in $S_{\mathfrak p}/\mathfrak pS_{\mathfrak p}$. By what we said above there exist $e_i \geq 1$ such that $P(x_i)^{e_i} = 0$ in $S_{\mathfrak p}$. Let $g_1 \in R$, $g_1 \not \in \mathfrak p$ be an element such that $P_i$ has coefficients in $R[1/g_1]$ for all $i$. Next, let $g_2 \in R$, $g_2 \not \in \mathfrak p$ be an element such that $P(x_i)^{e_i} = 0$ in $S_{g_1g_2}$. Setting $g = g_1g_2$ we win.
Write $t \varphi(p) = \varphi(r)$ for some $r \in R[x]$. Using euclidean division, write $r = qp + r'$ with $q, r' \in R[x]$ and $\deg(r') < \deg(p)$. We may replace $t$ by $t - \varphi(q)$ which is still integral over $R[x]$, so that we obtain $t \varphi(p) = \varphi(r')$. In the ring $S_t$ we may write this as $\varphi(p) - (1/t) \varphi(r') = 0$. This implies that $\varphi(x)$ gives an element of the localization $S_t$ which is integral over $\varphi(R)[1/t] \subset S_t$. On the other hand, $t$ is integral over the subring $\varphi(R)[\varphi(x)] \subset S$. Combined we conclude that $t$ is integral over the subring $\varphi(R)[1/t] \subset S_t$, see Lemma \ref{lemma-integral-transitive}. In other words there exists an equation of the form $$ t^d + \sum\nolimits_{i < d} \left(\sum\nolimits_{j = 0, \ldots, n_i} \varphi(r_{i, j})/t^j\right) t^i = 0 $$ in $S_t$ with $r_{i, j} \in R$. This means that $t^{d + N} + \sum_{i < d} \sum_{j = 0, \ldots, n_i} \varphi(r_{i, j}) t^{i + N - j} = 0$ in $S$ for some $N$ large enough. In other words $t$ is integral over $R$.
Let $R'$ and $S'$ be the localization of $R$ and $S$ at the element $a_k$. Let $\varphi' : R'[x] \to S'$ be the localization of $\varphi$. Let $t' \in S'$ be the image of $t$. Set $p' = p/a_k \in R'[x]$. Then $t' \varphi'(p') \in \Im(\varphi')$ since $t \varphi(p) \in \Im(\varphi)$. As $p'$ is monic, by Lemma \ref{lemma-make-integral-trick} there exists a $q' \in R'[x]$ such that $t' - \varphi'(q')$ is integral over $R'$. We may choose an $n \geq 0$ and an element $q \in R[x]$ such that $a_k^n q'$ is the image of $q$. Then $\varphi(a_k)^n t - \varphi(q)$ is an element of $S$ whose image in $S'$ is integral over $R'$. By Lemma \ref{lemma-integral-closure-localize} there exists an $m \geq 0$ such that $\varphi(a_k)^m(\varphi(a_k)^n t - \varphi(q))$ is integral over $R$. Thus $\varphi(a_k)^{m + n}t - \varphi(a_k^m q)$ is integral over $R$ as desired.
Assume that $S$ is generated by $t_1, \ldots, t_n$ as an $R[x]$-module. In this case $J = \{ g \in S \mid gt_i \in \Im(\varphi)\text{ for all }i\}$. Note that each element $u t_i$ is integral over $R[x]$, see Lemma \ref{lemma-finite-is-integral}. We have $\varphi(a_0 + a_1x + \ldots + a_k x^k) u t_i \in \Im(\varphi)$. By Lemma \ref{lemma-combine-lemmas}, for each $i$ there exists an integer $n_i$ and an element $q_i \in R[x]$ such that $\varphi(a_k^{n_i}) u t_i - \varphi(q_i)$ is integral over $R$. By assumption this element is in $\varphi(R)$ and hence $\varphi(a_k^{n_i}) u t_i \in \Im(\varphi)$. It follows that $m = \max\{n_1, \ldots, n_n\}$ works.
Under the assumptions of the lemma we have $u^n \varphi(a_0 + a_1x + \ldots + a_k x^k)^n \in J$ for some $n \geq 1$. By Lemma \ref{lemma-leading-coefficient-in-J} we deduce $u^n \varphi(a_k^{nm}) \in J$ for some $m \geq 1$. Thus $u \varphi(a_k) \in \sqrt{J}$, and so $u \varphi(a_0 + a_1x + \ldots + a_k x^k) - u \varphi(a_k x^k) = u \varphi(a_0 + a_1x + \ldots + a_{k-1} x^{k-1}) \in \sqrt{J}$. We win by induction on $k$.
Suppose $u(a_0 + a_1x + \ldots + a_k x^k) \in \mathfrak q$. By Lemma \ref{lemma-minimal-prime-reduced-ring} the local ring $S_{\mathfrak q}$ is a field, and hence $u(a_0 + a_1x + \ldots + a_k x^k) $ is zero in $S_{\mathfrak q}$. Thus $uu'(a_0 + a_1x + \ldots + a_k x^k) = 0$ for some $u' \in S$, $u' \not\in \mathfrak q$. Since $x$ is strongly transcendental over $R$ we get $uu'a_i = 0$ for all $i$. This in turn implies that $ua_i \in \mathfrak q$.
As a first case, assume that $R$ is normal, see Definition \ref{definition-ring-normal}. By Lemma \ref{lemma-polynomial-ring-normal} we see that $R[x]$ is normal. Take a prime $\mathfrak q \subset S$, and set $\mathfrak p = R \cap \mathfrak q$. Assume that the extension $\kappa(\mathfrak p) \subset \kappa(\mathfrak q)$ is finite. This would be the case if $R \to S$ is quasi-finite at $\mathfrak q$. Let $\mathfrak r = R[x] \cap \mathfrak q$. Then since $\kappa(\mathfrak p) \subset \kappa(\mathfrak r) \subset \kappa(\mathfrak q)$ we see that the extension $\kappa(\mathfrak p) \subset \kappa(\mathfrak r)$ is finite too. Thus the inclusion $\mathfrak r \supset \mathfrak p R[x]$ is strict. By going down for $R[x] \subset S$, see Proposition \ref{proposition-going-down-normal-integral}, we find a prime $\mathfrak q' \subset \mathfrak q$, lying over the prime $\mathfrak pR[x]$. Hence the fibre $\Spec(S \otimes_R \kappa(\mathfrak p))$ contains a point not equal to $\mathfrak q$, namely $\mathfrak q'$, whose closure contains $\mathfrak q$ and hence $\mathfrak q$ is not isolated in its fibre. \medskip\noindent If $R$ is not normal, let $R \subset R' \subset K$ be the integral closure $R'$ of $R$ in its field of fractions $K$. Let $S \subset S' \subset L$ be the subring $S'$ of the field of fractions $L$ of $S$ generated by $R'$ and $S$. Note that by construction the map $S \otimes_R R' \to S'$ is surjective. This implies that $R'[x] \subset S'$ is finite. Also, the map $S \subset S'$ induces a surjection on $\Spec$, see Lemma \ref{lemma-integral-overring-surjective}. We conclude by Lemma \ref{lemma-four-rings} and the normal case we just discussed.
Let $\mathfrak q \subset S$ be any prime. Choose a minimal prime $\mathfrak q' \subset \mathfrak q$. According to Lemmas \ref{lemma-reduced-strongly-transcendental-minimal-prime} and \ref{lemma-domains-transcendental-not-quasi-finite} the extension $R/(R \cap \mathfrak q') \subset S/\mathfrak q'$ is not quasi-finite at the prime corresponding to $\mathfrak q$. By Lemma \ref{lemma-four-rings} the extension $R \to S$ is not quasi-finite at $\mathfrak q$.
Let $\mathfrak p$ be the image of $\mathfrak q$ in $\Spec(R)$. There exists an $f \in I$, $f = a_nx^n + \ldots + a_0$ such that $a_i \not \in \mathfrak p$ for some $i$. Namely, otherwise the fibre ring $S \otimes_R \kappa(\mathfrak p)$ would be $\kappa(\mathfrak p)[x]$ and the map would not be quasi-finite at any prime lying over $\mathfrak p$. We conclude there exists a relation $b_m x^m + \ldots + b_0 = 0$ with $b_j \in S'$, $j = 0, \ldots, m$ and $b_j \not \in \mathfrak q \cap S'$ for some $j$. We prove the lemma by induction on $m$. The base case is $m = 0$ is vacuous (because the statements $b_0 = 0$ and $b_0 \not \in \mathfrak q$ are contradictory). \medskip\noindent The case $b_m \not \in \mathfrak q$. In this case $x$ is integral over $S'_{b_m}$, in fact $b_mx \in S'$ by Lemma \ref{lemma-make-integral-trivial}. Hence the injective map $S'_{b_m} \to S_{b_m}$ is also surjective, i.e., an isomorphism as desired. \medskip\noindent The case $b_m \in \mathfrak q$. In this case we have $b_mx \in S'$ by Lemma \ref{lemma-make-integral-trivial}. Set $b'_{m - 1} = b_mx + b_{m - 1}$. Then $$ b'_{m - 1}x^{m - 1} + b_{m - 2}x^{m - 2} + \ldots + b_0 = 0 $$ Since $b'_{m - 1}$ is congruent to $b_{m - 1}$ modulo $S' \cap \mathfrak q$ we see that it is still the case that one of $b'_{m - 1}, b_{m - 2}, \ldots, b_0$ is not in $S' \cap \mathfrak q$. Thus we win by induction on $m$.
Let $\mathfrak q \subset S$ be a point at which the ring map is quasi-finite. By Theorem \ref{theorem-main-theorem} there exists an integral ring extension $R \to S'$, $S' \subset S$ and an element $g \in S'$, $g\not \in \mathfrak q$ such that $S'_g \cong S_g$. Since $S$ and hence $S_g$ are of finite type over $R$ we may find finitely many elements $y_1, \ldots, y_N$ of $S'$ such that $S''_g \cong S_g$ where $S'' \subset S'$ is the sub $R$-algebra generated by $g, y_1, \ldots, y_N$. Since $S''$ is finite over $R$ (see Lemma \ref{lemma-characterize-integral}) we see that $S''$ is quasi-finite over $R$ (see Lemma \ref{lemma-quasi-finite}). It is easy to see that this implies that $S''_g$ is quasi-finite over $R$, for example because the property of being quasi-finite at a prime depends only on the local ring at the prime. Thus we see that $S_g$ is quasi-finite over $R$. By the same token this implies that $R \to S$ is quasi-finite at every prime of $S$ which lies in $D(g)$.
Because $S/R$ is quasi-finite we may apply Theorem \ref{theorem-main-theorem} to each point $\mathfrak q$ of $\Spec(S)$. Since $\Spec(S)$ is quasi-compact, see Lemma \ref{lemma-quasi-compact}, we may choose a finite number of $g_i \in S'$, $i = 1, \ldots, n$ such that $S'_{g_i} = S_{g_i}$, and such that $g_1, \ldots, g_n$ generate the unit ideal in $S$ (in other words the standard opens of $\Spec(S)$ associated to $g_1, \ldots, g_n$ cover all of $\Spec(S)$). \medskip\noindent Suppose that $D(g) \subset \Spec(S')$ is contained in the image. Then $D(g) \subset \bigcup D(g_i)$. In other words, $g_1, \ldots, g_n$ generate the unit ideal of $S'_g$. Note that $S'_{gg_i} \cong S_{gg_i}$ by our choice of $g_i$. Hence $S'_g \cong S_g$ by Lemma \ref{lemma-cover}. \medskip\noindent We construct a finite algebra $S'' \subset S'$ as in (3). To do this note that each $S'_{g_i} \cong S_{g_i}$ is a finite type $R$-algebra. For each $i$ pick some elements $y_{ij} \in S'$ such that each $S'_{g_i}$ is generated as $R$-algebra by $1/g_i$ and the elements $y_{ij}$. Then set $S''$ equal to the sub $R$-algebra of $S'$ generated by all $g_i$ and all the $y_{ij}$. Details omitted.