hcju/stacksqa huggingface dataset:
To prove that $f$ is flat, it suffices to prove $Y_s \to X_s$ is flat for all $s \in S$ (More on Morphisms, Lemma \ref{more-morphisms-lemma-morphism-between-flat-Noetherian}). Flatness of $Y_s \to X_s$ follows from Algebra, Lemma \ref{algebra-lemma-CM-over-regular-flat}. By More on Morphisms, Lemma \ref{more-morphisms-lemma-lci-permanence} the morphism $f$ is a local complete intersection morphism. Thus the statement on the different follows from the corresponding statement on the K\"ahler different by Lemma \ref{lemma-different-syntomic-quasi-finite}. Finally, since we have the exact sequence $$ f^*\Omega_{X/S} \xrightarrow{\text{d}f} \Omega_{X/S} \to \Omega_{Y/X} \to 0 $$ by Morphisms, Lemma \ref{morphisms-lemma-triangle-differentials} and since $\Omega_{X/S}$ and $\Omega_{Y/S}$ are finite locally free of rank $n$ (Morphisms, Lemma \ref{morphisms-lemma-smooth-omega-finite-locally-free}), the statement for the K\"ahler different is clear from the definition of the zeroth fitting ideal. If $f$ is \'etale at the associated points of $Y$, then $\wedge^n\text{d}f$ does not vanish in the associated points of $Y$, which implies that the local equation of $R$ is a nonzerodivisor. Hence $R$ is an effective Cartier divisor. The canonical isomorphism sends $1$ to $\wedge^n\text{d}f$, see Divisors, Lemma \ref{divisors-lemma-characterize-OD}.
The horizontal implications in the diagram are trivial. Let $S \subset A$ be the set of nonzerodivisors so that $Q(A) = S^{-1}A$ and $Q(A) \otimes_A B = S^{-1}B$. Recall that $S = A \setminus \bigcup_{\mathfrak p \in \text{Ass}(A)} \mathfrak p$ by Algebra, Lemma \ref{algebra-lemma-ass-zero-divisors}. Let $\mathfrak q \subset B$ be a prime lying over $\mathfrak p \subset A$. \medskip\noindent Assume (2). If $\mathfrak q \in \text{Ass}(B)$ then $\mathfrak q$ consists of zerodivisors, hence (1) implies the same is true for $\mathfrak p$. Hence $\mathfrak p$ corresponds to a prime of $S^{-1}A$. Hence $A \to B_\mathfrak q$ is flat by our assumption (2). If $\mathfrak q$ lies over an associated prime $\mathfrak p$ of $A$, then certainly $\mathfrak p \in \Spec(S^{-1}A)$ and the same argument works. \medskip\noindent Assume (3). Let $f \in A$ be a nonzerodivisor. If $f$ were a zerodivisor on $B$, then $f$ is contained in an associated prime $\mathfrak q$ of $B$. Since $A \to B_\mathfrak q$ is flat by assumption, we conclude that $\mathfrak p$ is an associated prime of $A$ by Algebra, Lemma \ref{algebra-lemma-bourbaki}. This would imply that $f$ is a zerodivisor on $A$, a contradiction. \medskip\noindent Assume (4) and going up for $A \to B$. We already know (1) holds. If $\mathfrak q$ corresponds to a prime of $S^{-1}B$ then $\mathfrak p$ is contained in an associated prime $\mathfrak p'$ of $A$. By going up there exists a prime $\mathfrak q'$ containing $\mathfrak q$ and lying over $\mathfrak p$. Then $A \to B_{\mathfrak q'}$ is flat by (4). Hence $A \to B_{\mathfrak q}$ is flat as a localization. Thus $A \to S^{-1}B$ is flat and so is $S^{-1}A \to S^{-1}B$, see Algebra, Lemma \ref{algebra-lemma-flat-localization}.
As the Dedekind different for $A \to B$ is defined we can apply Lemma \ref{lemma-explain-condition} to see that $Y \to X$ satisfies condition (1) of Remark \ref{remark-different-generalization}. Recall that there is a canonical isomorphism $c : \mathcal{L}_{B/A} \to \omega_{B/A}$, see Lemma \ref{lemma-dedekind-complementary-module}. Let $K = Q(A)$ and $L = K \otimes_A B$ as above. By construction the map $c$ fits into a commutative diagram $$ \xymatrix{ \mathcal{L}_{B/A} \ar[r] \ar[d]_c & L \ar[d] \\ \omega_{B/A} \ar[r] & \Hom_K(L, K) } $$ where the right vertical arrow sends $x \in L$ to the map $y \mapsto \text{Trace}_{L/K}(xy)$ and the lower horizontal arrow is the base change map (\ref{equation-bc-dualizing}) for $\omega_{B/A}$. We can factor the lower horizontal map as $$ \omega_{B/A} = \Gamma(Y, \omega_{Y/X}) \to \Gamma(V, \omega_{V/X}) \to \Hom_K(L, K) $$ Since all associated points of $\omega_{V/X}$ map to associated primes of $A$ (Lemma \ref{lemma-dualizing-associated-primes}) we see that the second map is injective. The element $\tau_{V/X}$ maps to $\text{Trace}_{L/K}$ in $\Hom_K(L, K)$ by the very definition of trace elements (Definition \ref{definition-trace-element}). Thus $\tau$ as in condition (2) of Remark \ref{remark-different-generalization} exists if and only if $1 \in \mathcal{L}_{B/A}$ and then $\tau = c(1)$. In this case, by Lemma \ref{lemma-dedekind-different-ideal} we see that $\mathfrak{D}_{B/A} \subset B$. Finally, the agreement of $\mathfrak{D}_f$ with $\mathfrak{D}_{B/A}$ is immediate from the definitions and the fact $\tau = c(1)$ seen above.
By Zariski's main theorem we can choose a factorization $f = f' \circ j$ where $j : Y \to Y'$ is an open immersion and $f' : Y' \to X$ is a finite morphism, see More on Morphisms, Lemma \ref{more-morphisms-lemma-quasi-finite-separated-pass-through-finite}. By our construction in Duality for Schemes, Lemma \ref{duality-lemma-shriek-well-defined} we have $f^! = j^* \circ a'$ where $a' : D_\QCoh(\mathcal{O}_X) \to D_\QCoh(\mathcal{O}_{Y'})$ is the right adjoint to $Rf'_*$ of Duality for Schemes, Lemma \ref{duality-lemma-twisted-inverse-image}. By Duality for Schemes, Lemma \ref{duality-lemma-finite-twisted} we see that $\Phi(a'(\mathcal{O}_X)) = R\SheafHom(f'_*\mathcal{O}_{Y'}, \mathcal{O}_X)$ in $D_\QCoh^+(f'_*\mathcal{O}_{Y'})$. In particular $a'(\mathcal{O}_X)$ has vanishing cohomology sheaves in degrees $< 0$. The zeroth cohomology sheaf is determined by the isomorphism $$ f'_*H^0(a'(\mathcal{O}_X)) = \SheafHom_{\mathcal{O}_X}(f'_*\mathcal{O}_{Y'}, \mathcal{O}_X) $$ as $f'_*\mathcal{O}_{Y'}$-modules via the equivalence of Morphisms, Lemma \ref{morphisms-lemma-affine-equivalence-modules}. Writing $(f')^{-1}U = V' = \Spec(B')$, we obtain $$ H^0(V', a'(\mathcal{O}_X)) = \Hom_A(B', A). $$ As the zeroth cohomology sheaf of $a'(\mathcal{O}_X)$ is a quasi-coherent module we find that the restriction to $V$ is given by $\omega_{B/A} = \Hom_A(B', A) \otimes_{B'} B$ as desired. \medskip\noindent The statement about restriction maps signifies that the restriction mappings of the quasi-coherent $\mathcal{O}_{Y'}$-module $H^0(a'(\mathcal{O}_X))$ for opens in $Y'$ agrees with the maps defined in Lemma \ref{lemma-localize-dualizing} for the modules $\omega_{B/A}$ via the isomorphisms given above. This is clear. \medskip\noindent Let $f : Y \to X$ be a quasi-finite morphism of schemes of finite type over a Noetherian base $S$ endowed with a dualizing complex $\omega_S^\bullet$. Consider opens $V \subset Y$ and $U \subset X$ with $f(V) \subset U$ and $V$ and $U$ separated over $S$. Denote $f|_V : V \to U$ the restriction of $f$. By the discussion above and Duality for Schemes, Lemma \ref{duality-lemma-duality-bootstrap} there are canonical isomorphisms $$ H^0(f_{new}^!\mathcal{O}_X)|_V = H^0((f|_V)^!\mathcal{O}_U) = \omega_{V/U} = \omega_{Y/X}|_V $$ We omit the verification that these isomorphisms glue to a global isomorphism $H^0(f_{new}^!\mathcal{O}_X) \to \omega_{Y/X}$.
Parts (1) and (2) are equivalent by definition. Parts (3) and (4) are equivalent by the construction of $\omega_{Y/X}$ in Remark \ref{remark-relative-dualizing-for-quasi-finite}. Thus we have to show that (1)-(2) is equivalent to (3)-(4). \medskip\noindent First proof. Working affine locally we can assume $f$ is a separated morphism and apply Lemma \ref{lemma-compare-dualizing} to see that $\omega_{Y/X}$ is the zeroth cohomology sheaf of $f^!\mathcal{O}_X$. Under both assumptions $f$ is flat and quasi-finite, hence $f^!\mathcal{O}_X$ is isomorphic to $\omega_{Y/X}[0]$, see Duality for Schemes, Lemma \ref{duality-lemma-flat-quasi-finite-shriek}. Hence the equivalence follows from Duality for Schemes, Lemma \ref{duality-lemma-affine-flat-Noetherian-gorenstein}. \medskip\noindent Second proof. By Lemma \ref{lemma-characterize-invertible}, we see that it suffices to prove the equivalence of (2) and (3) when $X$ is the spectrum of a field $k$. Then $Y = \Spec(B)$ where $B$ is a finite $k$-algebra. In this case $\omega_{B/A} = \omega_{B/k} = \Hom_k(B, k)$ placed in degree $0$ is a dualizing complex for $B$, see Dualizing Complexes, Lemma \ref{dualizing-lemma-dualizing-finite}. Thus the equivalence follows from Dualizing Complexes, Lemma \ref{dualizing-lemma-gorenstein}.
Let $U = \lim U_i$ be a directed limit of affine schemes over $S$. We claim that the functor $$ \colim \mathcal{X}_{U_i} \longrightarrow \mathcal{X}_U \times_{\mathcal{Y}_U} \colim \mathcal{Y}_{U_i} $$ is fully faithful if and only if the functor $$ \colim \mathcal{X}_{U_i} \longrightarrow \mathcal{X}_U \times_{(\mathcal{X} \times_\mathcal{Y} \mathcal{X})_U} \colim (\mathcal{X} \times_\mathcal{Y} \mathcal{X})_{U_i} $$ is an equivalence. This will prove the lemma. Since $(\mathcal{X} \times_\mathcal{Y} \mathcal{X})_U = \mathcal{X}_U \times_{\mathcal{Y}_U} \mathcal{X}_U$ and $(\mathcal{X} \times_\mathcal{Y} \mathcal{X})_{U_i} = \mathcal{X}_{U_i} \times_{\mathcal{Y}_{U_i}} \mathcal{X}_{U_i}$ this is a purely category theoretic assertion which we discuss in the next paragraph. \medskip\noindent Let $\mathcal{I}$ be a filtered index category. Let $(\mathcal{C}_i)$ and $(\mathcal{D}_i)$ be systems of groupoids over $\mathcal{I}$. Let $p : (\mathcal{C}_i) \to (\mathcal{D}_i)$ be a map of systems of groupoids over $\mathcal{I}$. Suppose we have a functor $p : \mathcal{C} \to \mathcal{D}$ of groupoids and functors $f : \colim \mathcal{C}_i \to \mathcal{C}$ and $g : \colim \mathcal{D}_i \to \mathcal{D}$ fitting into a commutative diagram $$ \xymatrix{ \colim \mathcal{C}_i \ar[d]_p \ar[r]_f & \mathcal{C} \ar[d]^p \\ \colim \mathcal{D}_i \ar[r]^g & \mathcal{D} } $$ Then we claim that $$ A : \colim \mathcal{C}_i \longrightarrow \mathcal{C} \times_\mathcal{D} \colim \mathcal{D}_i $$ is fully faithful if and only if the functor $$ B : \colim \mathcal{C}_i \longrightarrow \mathcal{C} \times_{\Delta, \mathcal{C} \times_\mathcal{D} \mathcal{C}, f \times_g f} \colim (\mathcal{C}_i \times_{\mathcal{D}_i} \mathcal{C}_i) $$ is an equivalence. Set $\mathcal{C}' = \colim \mathcal{C}_i$ and $\mathcal{D}' = \colim \mathcal{D}_i$. Since $2$-fibre products commute with filtered colimits we see that $A$ and $B$ become the functors $$ A' : \mathcal{C}' \to \mathcal{C} \times_\mathcal{D} \mathcal{D}' \quad\text{and}\quad B' : \mathcal{C}' \longrightarrow \mathcal{C} \times_{\Delta, \mathcal{C} \times_\mathcal{D} \mathcal{C}, f \times_g f} (\mathcal{C}' \times_{\mathcal{D}'} \mathcal{C}') $$ Thus it suffices to prove that if $$ \xymatrix{ \mathcal{C}' \ar[d]_p \ar[r]_f & \mathcal{C} \ar[d]^p \\ \mathcal{D}' \ar[r]^g & \mathcal{D} } $$ is a commutative diagram of groupoids, then $A'$ is fully faithful if and only if $B'$ is an equivalence. This follows from Categories, Lemma \ref{categories-lemma-fully-faithful-diagonal-equivalence} (with trivial, i.e., punctual, base category) because $$ \mathcal{C} \times_{\Delta, \mathcal{C} \times_\mathcal{D} \mathcal{C}, f \times_g f} (\mathcal{C}' \times_{\mathcal{D}'} \mathcal{C}') = \mathcal{C}' \times_{A', \mathcal{C} \times_\mathcal{D} \mathcal{D}', A'} \mathcal{C}' $$ This finishes the proof.
Write $\mathcal{X} = Y \times_{Y_0} \mathcal{X}_0$ and $\mathcal{X}_i = Y_i \times_{Y_0} \mathcal{X}_0$. Choose an affine scheme $U_0$ and a surjective smooth morphism $U_0 \to \mathcal{X}_0$. Set $U = Y \times_{Y_0} U_0$ and $U_i = Y_i \times_{Y_0} U_0$. Then $U$ and $U_i$ are affine and $U \to \mathcal{X}$ and $U_i \to \mathcal{X}_i$ are smooth and surjective. Set $R_0 = U_0 \times_{\mathcal{X}_0} U_0$. Set $R = Y \times_{Y_0} R_0$ and $R_i = Y_i \times_{Y_0} R_0$. Then $R = U \times_\mathcal{X} U$ and $R_i = U_i \times_{\mathcal{X}_i} U_i$. \medskip\noindent With this notation note that $\mathcal{X} \to Y$ is separated implies that $R \to U \times_Y U$ is proper as the base change of $\mathcal{X} \to \mathcal{X} \times_Y \mathcal{X}$ by $U \times_Y U \to \mathcal{X} \times_Y \mathcal{X}$. Conversely, we see that $\mathcal{X}_i \to Y_i$ is separated if $R_i \to U_i \times_{Y_i} U_i$ is proper because $U_i \times_{Y_i} U_i \to \mathcal{X}_i \times_{Y_i} \mathcal{X}_i$ is surjective and smooth, see Properties of Stacks, Lemma \ref{stacks-properties-lemma-check-property-covering}. Observe that $R_0 \to U_0 \times_{Y_0} U_0$ is locally of finite type and that $R_0$ is quasi-compact and quasi-separated. By Limits of Spaces, Lemma \ref{spaces-limits-lemma-eventually-proper} we see that $R_i \to U_i \times_{Y_i} U_i$ is proper for large enough $i$ which finishes the proof.
By Morphisms of Stacks, Definition \ref{stacks-morphisms-definition-locally-finite-presentation} the morphism $\mathcal{X} \to X$ is quasi-compact, locally of finite presentation, and quasi-separated. Since $X$ is quasi-compact and $\mathcal{X} \to X$ is quasi-compact, we see that $\mathcal{X}$ is quasi-compact (Morphisms of Stacks, Definition \ref{stacks-morphisms-definition-quasi-compact}). Hence we can find an affine scheme $U$ and a surjective smooth morphism $U \to \mathcal{X}$ (Properties of Stacks, Lemma \ref{stacks-properties-lemma-quasi-compact-stack}). Set $R = U \times_\mathcal{X} U$. We obtain a smooth groupoid in algebraic spaces $(U, R, s, t, c)$ over $X$ such that $\mathcal{X} = [U/R]$, see Algebraic Stacks, Lemma \ref{algebraic-lemma-stack-presentation}. Since $\mathcal{X} \to X$ is quasi-separated and $X$ is quasi-separated we see that $\mathcal{X}$ is quasi-separated (Morphisms of Stacks, Lemma \ref{stacks-morphisms-lemma-composition-separated}). Thus $R \to U \times U$ is quasi-compact and quasi-separated (Morphisms of Stacks, Lemma \ref{stacks-morphisms-lemma-fibre-product-after-map}) and hence $R$ is a quasi-separated and quasi-compact algebraic space. On the other hand $U \to X$ is locally of finite presentation and hence also $R \to X$ is locally of finite presentation (because $s : R \to U$ is smooth hence locally of finite presentation). Thus $(U, R, s, t, c)$ is a groupoid object in the category of algebraic spaces which are of finite presentation over $X$. By Limits of Spaces, Lemma \ref{spaces-limits-lemma-descend-finite-presentation} there exists an $i$ and a groupoid in algebraic spaces $(U_i, R_i, s_i, t_i, c_i)$ over $X_i$ whose pullback to $X$ is isomorphic to $(U, R, s, t, c)$. After increasing $i$ we may assume that $s_i$ and $t_i$ are smooth, see Limits of Spaces, Lemma \ref{spaces-limits-lemma-descend-smooth}. The quotient stack $\mathcal{X}_i = [U_i/R_i]$ is an algebraic stack (Algebraic Stacks, Theorem \ref{algebraic-theorem-smooth-groupoid-gives-algebraic-stack}). \medskip\noindent There is a morphism $[U/R] \to [U_i/R_i]$, see Groupoids in Spaces, Lemma \ref{spaces-groupoids-lemma-quotient-stack-functorial}. We claim that combined with the morphisms $[U/R] \to X$ and $[U_i/R_i] \to X_i$ (Groupoids in Spaces, Lemma \ref{spaces-groupoids-lemma-quotient-stack-arrows}) we obtain an isomorphism (i.e., equivalence) $$ [U/R] \longrightarrow [U_i/R_i] \times_{X_i} X $$ The corresponding map $$ [U/_{\!p}R] \longrightarrow [U_i/_{\!p}R_i] \times_{X_i} X $$ on the level of ``presheaves of groupoids'' as in Groupoids in Spaces, Equation (\ref{spaces-groupoids-equation-quotient-stack}) is an isomorphism. Thus the claim follows from the fact that stackification commutes with fibre products, see Stacks, Lemma \ref{stacks-lemma-stackification-fibre-product-fibred-categories}.
First we use exactly the same procedure as in the proof of Lemma \ref{lemma-finite-type-closed-in-finite-presentation} (and we borrow its notation) to construct the embedding $\mathcal{X} \to \mathcal{X}'$ as a morphism $\mathcal{X} \to \mathcal{X}' = Y \times_{Y_i} \mathcal{X}_i$ with $\mathcal{X}_i = [U_i/R_i]$. Thus it is enough to show that $\mathcal{X}_i \to Y_i$ is separated for sufficiently large $i$. In other words, it is enough to show that $\mathcal{X}_i \to \mathcal{X}_i \times_{Y_i} \mathcal{X}_i$ is proper for $i$ sufficiently large. Since the morphism $U_i \times_{Y_i} U_i \to \mathcal{X}_i \times_{Y_i} \mathcal{X}_i$ is surjective and smooth and since $R_i = \mathcal{X}_i \times_{\mathcal{X}_i \times_{Y_i} \mathcal{X}_i} U_i \times_{Y_i} U_i$ it is enough to show that the morphism $(s_i, t_i) : R_i \to U_i \times_{Y_i} U_i$ is proper for $i$ sufficiently large, see Properties of Stacks, Lemma \ref{stacks-properties-lemma-check-property-covering}. We prove this in the next paragraph. \medskip\noindent Observe that $U \times_Y U \to Y$ is quasi-separated and of finite type. Hence we can use the construction of  Limits of Spaces, Remark \ref{spaces-limits-remark-finite-type-gives-well-defined-system} to find an $i_1 \in I$ and an inverse system $(V_i)_{i \geq i_1}$ with $U \times_Y U = \lim_{i \geq i_1} V_i$. By Limits of Spaces, Lemma \ref{spaces-limits-lemma-good-diagram-fibre-product} for $i$ sufficiently large the functoriality of the construction applied to the projections $U \times_Y U \to U$ gives closed immersions $$ V_i \to U_i \times_{Y_i} U_i $$ (There is a small mismatch here because in truth we should replace $Y_i$ by the scheme theoretic image of $Y \to Y_i$, but clearly this does not change the fibre product.) On the other hand, by Limits of Spaces, Lemma \ref{spaces-limits-lemma-morphism-good-diagram-proper} the functoriality applied to the proper morphism $(s, t) : R \to U \times_Y U$ (here we use that $\mathcal{X}$ is separated) leads to morphisms $R_i \to V_i$ which are proper for large enough $i$. Composing these morphisms we obtain a proper morphisms $R_i \to U_i \times_{Y_i} U_i$ for all $i$ large enough. The functoriality of the construction of Limits of Spaces, Remark \ref{spaces-limits-remark-finite-type-gives-well-defined-system} shows that this is the morphism is the same as $(s_i, t_i)$ for large enough $i$ and the proof is complete.
Assume (3). Let $T = \lim T_i$ be a directed limit of affine schemes. Consider the functor $$ \colim \mathcal{X}_{T_i} \longrightarrow \mathcal{X}_T \times_{\mathcal{Y}_T} \colim \mathcal{Y}_{T_i} $$ Let $(x, y_i, \beta)$ be an object on the right hand side, i.e., $x \in \Ob(\mathcal{X}_T)$, $y_i \in \Ob(\mathcal{Y}_{T_i})$, and $\beta : f(x) \to y_i|_T$ in $\mathcal{Y}_T$. Then we can consider $(x, y_i, \beta)$ as an object of the algebraic stack $\mathcal{X}_{y_i} = \mathcal{X} \times_{\mathcal{Y}, y_i} T_i$ over $T$. Since $\mathcal{X}_{y_i} \to T_i$ is locally of finite presentation (as a base change of $f$) we see that it is limit preserving by Lemma \ref{lemma-locally-finite-presentation-limit-preserving}. This means that $(x, y_i, \beta)$ comes from an object over $T_{i'}$ for some $i' \geq i$ and unwinding the definitions we find that $(x, y_i, \beta)$ is in the essential image of the displayed functor. In other words, the displayed functor is essentially surjective. Another formulation is that this means $f$ is limit preserving on objects. Now we apply this to the diagonal $\Delta$ of $f$. Namely, by Morphisms of Stacks, Lemma \ref{stacks-morphisms-lemma-diagonal-morphism-finite-type} the morphism $\Delta$ is locally of finite presentation. Thus the argument above shows that $\Delta$ is limit preserving on objects. By Lemma \ref{lemma-representable-by-spaces-limit-preserving} this implies that $\Delta$ is limit preserving. By Lemma \ref{lemma-limit-preserving-diagonal} we conclude that the displayed functor above is fully faithful. Thus it is an equivalence (as we already proved essential surjectivity) and we conclude that (1) holds. \medskip\noindent The implication (1) $\Rightarrow$ (2) is trivial. Assume (2). Choose a scheme $V$ and a surjective smooth morphism $V \to \mathcal{Y}$. By Criteria for Representability, Lemma \ref{criteria-lemma-base-change-limit-preserving} the base change $\mathcal{X} \times_\mathcal{Y} V \to V$ is limit preserving on objects. Choose a scheme $U$ and a surjective smooth morphism $U \to \mathcal{X} \times_\mathcal{Y} V$. Since a smooth morphism is locally of finite presentation, we see that $U \to \mathcal{X} \times_\mathcal{Y} V$ is limit preserving (first part of the proof). By Criteria for Representability, Lemma \ref{criteria-lemma-composition-limit-preserving} we find that the composition $U \to V$ is limit preserving on objects. We conclude that $U \to V$ is locally of finite presentation, see Criteria for Representability, Lemma \ref{criteria-lemma-representable-by-spaces-limit-preserving}. This is exactly the condition that $f$ is locally of finite presentation, see Morphisms of Stacks, Definition \ref{stacks-morphisms-definition-locally-finite-presentation}.
Choose an element $0 \in I$. Note that $I$ is nonempty as the limit is directed. For every $i \geq 0$ consider the quasi-coherent sheaf of $\mathcal{O}_{S_0}$-algebras $\mathcal{A}_i = f_{i0, *}\mathcal{O}_{S_i}$. Recall that $S_i = \underline{\Spec}_{S_0}(\mathcal{A}_i)$, see Morphisms, Lemma \ref{morphisms-lemma-characterize-affine}. Set $\mathcal{A} = \colim_{i \geq 0} \mathcal{A}_i$. This is a quasi-coherent sheaf of $\mathcal{O}_{S_0}$-algebras, see Schemes, Section \ref{schemes-section-quasi-coherent}. Set $S = \underline{\Spec}_{S_0}(\mathcal{A})$. By Morphisms, Lemma \ref{morphisms-lemma-affine-equivalence-algebras} we get for $i \geq 0$ morphisms $f_i : S \to S_i$ compatible with the transition morphisms. Note that the morphisms $f_i$ are affine by Morphisms, Lemma \ref{morphisms-lemma-affine-permanence} for example. By Lemma \ref{lemma-directed-inverse-system-affine-schemes-has-limit} above we see that for any affine open $U_0 \subset S_0$ the inverse image $U = f_0^{-1}(U_0) \subset S$ is the limit of the system of opens $U_i = f_{i0}^{-1}(U_0)$, $i \geq 0$ in the category of schemes. \medskip\noindent Let $T$ be a scheme. Let $g_i : T \to S_i$ be a compatible system of morphisms. To show that $S = \lim_i S_i$ we have to prove there is a unique morphism $g : T \to S$ with $g_i = f_i \circ g$ for all $i \in I$. For every $t \in T$ there exists an affine open $U_0 \subset S_0$ containing $g_0(t)$. Let $V \subset g_0^{-1}(U_0)$ be an affine open neighbourhood containing $t$. By the remarks above we obtain a unique morphism $g_V : V \to U = f_0^{-1}(U_0)$ such that $f_i \circ g_V = g_i|_{U_i}$ for all $i$. The open sets $V \subset T$ so constructed form a basis for the topology of $T$. The morphisms $g_V$ glue to a morphism $g : T \to S$ because of the uniqueness property. This gives the desired morphism $g : T \to S$. \medskip\noindent The final statement is clear from the construction of the limit above.
Pick $i \in I$. Take $U_i \subset S_i$ an affine open. Denote $U_{i'} = f_{i'i}^{-1}(U_i)$ and $U = f_i^{-1}(U_i)$. Here $f_{i'i} : S_{i'} \to S_i$ is the transtion morphism and $f_i : S \to S_i$ is the projection. By Lemma \ref{lemma-directed-inverse-system-has-limit} we have $U = \lim_{i' \geq i} U_i$. Suppose we can show that $U_{set} = \lim_{i' \geq i} U_{i', set}$. Then the lemma follows by a simple argument using an affine covering of $S_i$. Hence we may assume all $S_i$ and $S$ affine. This reduces us to the algebra question considered in the next paragraph. \medskip\noindent Suppose given a system of rings $(A_i, \varphi_{ii'})$ over $I$. Set $A = \colim_i A_i$ with canonical maps $\varphi_i : A_i \to A$. Then $$ \Spec(A) = \lim_i \Spec(A_i) $$ Namely, suppose that we are given primes $\mathfrak p_i \subset A_i$ such that $\mathfrak p_i = \varphi_{ii'}^{-1}(\mathfrak p_{i'})$ for all $i' \geq i$. Then we simply set $$ \mathfrak p = \{x \in A \mid \exists i, x_i \in \mathfrak p_i \text{ with }\varphi_i(x_i) = x\} $$ It is clear that this is an ideal and has the property that $\varphi_i^{-1}(\mathfrak p) = \mathfrak p_i$. Then it follows easily that it is a prime ideal as well.