hcju/stacksqa huggingface dataset:
Let $A$ be a Noetherian ring with $pA = 0$. Let $I \subset A$ be the ideal of nilpotent elements. Then $I^n = 0$ for some $n$ (Algebra, Lemma \ref{algebra-lemma-Noetherian-power}). Pick $e$ such that $p^e \geq n$. Then $$ A/I \longrightarrow A,\quad f \bmod I \longmapsto f^{p^e} $$ is well defined. This produces a norm of degree $p^e$ for $\Spec(A/I) \to \Spec(A)$. Now if $X$ is obtained by glueing some affine schemes $\Spec(A_i)$ then for some $e \gg 0$ these maps glue to a norm map for $X_{red} \to X$. Details omitted.
Case (1) follows from a combination of Lemmas \ref{lemma-finite-locally-free-has-norm} and \ref{lemma-norm-quasi-affine}. In case (2) we first replace $X$ by an irreducible component of $X$ which dominates $Y$ (viewed as a reduced closed subscheme of $X$). Then we can apply Lemma \ref{lemma-norm-in-normal-case}.
Using Lemma \ref{lemma-characterize-effective-Cartier-divisor} we translate this as follows into algebra. Let $A \to B$ be a ring map and $h \in B$. Assume $h$ is a nonzerodivisor and that $B/hB$ is flat over $A$. Then $$ 0 \to B \xrightarrow{h} B \to B/hB \to 0 $$ is a short exact sequence of $A$-modules with $B/hB$ flat over $A$. By Algebra, Lemma \ref{algebra-lemma-flat-tor-zero} this sequence remains exact on tensoring over $A$ with any module, in particular with any $A$-algebra $A'$.
This translates into the following algebra fact: Let $A \to B$ be a ring map and $h_1, h_2 \in B$. Assume the $h_i$ are nonzerodivisors and that $B/h_iB$ is flat over $A$. Then $h_1h_2$ is a nonzerodivisor and $B/h_1h_2B$ is flat over $A$. The reason is that we have a short exact sequence $$ 0 \to B/h_1B \to B/h_1h_2B \to B/h_2B \to 0 $$ where the first arrow is given by multiplication by $h_2$. Since the outer two are flat modules over $A$, so is the middle one, see Algebra, Lemma \ref{algebra-lemma-flat-ses}.
This translates into the following algebra fact: Let $A \to B$ be a ring map and $h_1, h_2 \in B$. Assume the $h_i$ are nonzerodivisors, that $B/h_iB$ is flat over $A$, and that $(h_2) \subset (h_1)$. Then we can write $h_2 = h h_1$ where $h \in B$ is a nonzerodivisor. We get a short exact sequence $$ 0 \to B/hB \to B/h_2B \to B/h_1B \to 0 $$ where the first arrow is given by multiplication by $h_1$. Since the right two are flat modules over $A$, so is the middle one, see Algebra, Lemma \ref{algebra-lemma-flat-ses}.
Set $A = \mathcal{O}_{S, f(x)}$ and $B = \mathcal{O}_{X, x}$. Let $h \in B$ be an element which generates the ideal of $D$. Then $h$ is a nonzerodivisor in $B$ such that $B/hB$ is a flat local $A$-algebra. Let $I \subset A$ be a finitely generated ideal. Consider the commutative diagram $$ \xymatrix{ 0 \ar[r] & B \ar[r]_h & B \ar[r] & B/hB \ar[r] & 0 \\ 0 \ar[r] & B \otimes_A I \ar[r]^h \ar[u] & B \otimes_A I \ar[r] \ar[u] & B/hB \otimes_A I \ar[r] \ar[u] & 0 } $$ The lower sequence is short exact as $B/hB$ is flat over $A$, see Algebra, Lemma \ref{algebra-lemma-flat-tor-zero}. The right vertical arrow is injective as $B/hB$ is flat over $A$, see Algebra, Lemma \ref{algebra-lemma-flat}. Hence multiplication by $h$ is surjective on the kernel $K$ of the middle vertical arrow. By Nakayama's lemma, see Algebra, Lemma \ref{algebra-lemma-NAK} we conclude that $K= 0$. Hence $B$ is flat over $A$, see Algebra, Lemma \ref{algebra-lemma-flat}.
Pick $x \in D$. It suffices to find an open neighbourhood $U \subset X$ of $x$ such that $f|_U$ is flat. Hence the lemma reduces to the case that $X = \Spec(B)$ and $S = \Spec(A)$ are affine and that $D$ is given by a nonzerodivisor $h \in B$. By assumption $B$ is a finitely presented $A$-algebra and $B/hB$ is a flat $A$-algebra. We are going to use absolute Noetherian approximation. \medskip\noindent Write $B = A[x_1, \ldots, x_n]/(g_1, \ldots, g_m)$. Assume $h$ is the image of $h' \in A[x_1, \ldots, x_n]$. Choose a finite type $\mathbf{Z}$-subalgebra $A_0 \subset A$ such that all the coefficients of the polynomials $h', g_1, \ldots, g_m$ are in $A_0$. Then we can set $B_0 = A_0[x_1, \ldots, x_n]/(g_1, \ldots, g_m)$ and $h_0$ the image of $h'$ in $B_0$. Then $B = B_0 \otimes_{A_0} A$ and $B/hB = B_0/h_0B_0 \otimes_{A_0} A$. By Algebra, Lemma \ref{algebra-lemma-flat-finite-presentation-limit-flat} we may, after enlarging $A_0$, assume that $B_0/h_0B_0$ is flat over $A_0$. Let $K_0 = \Ker(h_0 : B_0 \to B_0)$. As $B_0$ is of finite type over $\mathbf{Z}$ we see that $K_0$ is a finitely generated ideal. Let $A_1 \subset A$ be a finite type $\mathbf{Z}$-subalgebra containing $A_0$ and denote $B_1$, $h_1$, $K_1$ the corresponding objects over $A_1$. By More on Algebra, Lemma \ref{more-algebra-lemma-base-change-H1-regular} the map $K_0 \otimes_{A_0} A_1 \to K_1$ is surjective. On the other hand, the kernel of $h : B \to B$ is zero by assumption. Hence every element of $K_0$ maps to zero in $K_1$ for sufficiently large subrings $A_1 \subset A$. Since $K_0$ is finitely generated, we conclude that $K_1 = 0$ for a suitable choice of $A_1$. \medskip\noindent Set $f_1 : X_1 \to S_1$ equal to $\Spec$ of the ring map $A_1 \to B_1$. Set $D_1 = \Spec(B_1/h_1B_1)$. Since $B = B_1 \otimes_{A_1} A$, i.e., $X = X_1 \times_{S_1} S$, it now suffices to prove the lemma for $X_1 \to S_1$ and the relative effective Cartier divisor $D_1$, see Morphisms, Lemma \ref{morphisms-lemma-base-change-module-flat}. Hence we have reduced to the case where $A$ is a Noetherian ring. In this case we know that the ring map $A \to B$ is flat at every prime $\mathfrak q$ of $V(h)$ by Lemma \ref{lemma-flat-at-x}. Combined with the fact that the flat locus is open in this case, see Algebra, Theorem \ref{algebra-theorem-openness-flatness} we win.
This translates into the following algebra fact: Let $A \to B$ be a ring map and $h \in B$. Assume $h$ is a nonzerodivisor, that $B/hB$ is flat over $A$, and that the localization $B_h$ is flat over $A$. Then $B$ is flat over $A$. The reason is that we have a short exact sequence $$ 0 \to B \to B_h \to \colim_n (1/h^n)B/B \to 0 $$ and that the second and third terms are flat over $A$, which implies that $B$ is flat over $A$ (see Algebra, Lemma \ref{algebra-lemma-flat-ses}). Note that a filtered colimit of flat modules is flat (see Algebra, Lemma \ref{algebra-lemma-colimit-flat}) and that by induction on $n$ each $(1/h^n)B/B \cong B/h^nB$ is flat over $A$ since it fits into the short exact sequence $$ 0 \to B/h^{n - 1}B \xrightarrow{h} B/h^nB \to B/hB \to 0 $$ Some details omitted.
Let $\partial Z' = \overline{Z'} \setminus Z'$ and $\partial Z = \overline{Z} \setminus Z$. These are closed subsets of $X'$ and of $X$. Replacing $X'$ by $X' \setminus \partial Z'$ and $X$ by $X \setminus \big(g^{-1}(\partial Z') \cup \partial Z\big)$ we see that we may assume that $i$ and $i'$ are closed immersions. \medskip\noindent The fact that $g \circ i$ factors through $i'$ implies that $g^*\mathcal{I}'$ maps into $\mathcal{I}$ under the canonical map $g^*\mathcal{I}' \to \mathcal{O}_X$, see Schemes, Lemmas \ref{schemes-lemma-characterize-closed-subspace} and \ref{schemes-lemma-restrict-map-to-closed}. Hence we get an induced map of quasi-coherent sheaves $g^*((\mathcal{I}')^n/(\mathcal{I}')^{n + 1}) \to \mathcal{I}^n/\mathcal{I}^{n + 1}$. Pulling back by $i$ gives $i^*g^*((\mathcal{I}')^n/(\mathcal{I}')^{n + 1}) \to i^*(\mathcal{I}^n/\mathcal{I}^{n + 1})$. Note that $i^*(\mathcal{I}^n/\mathcal{I}^{n + 1}) = \mathcal{C}_{Z/X, n}$. On the other hand, $i^*g^*((\mathcal{I}')^n/(\mathcal{I}')^{n + 1}) = f^*(i')^*((\mathcal{I}')^n/(\mathcal{I}')^{n + 1}) = f^*\mathcal{C}_{Z'/X', n}$. This gives the desired map. \medskip\noindent Checking that the map is locally described as the given map $(I')^n/(I')^{n + 1} \to I^n/I^{n + 1}$ is a matter of unwinding the definitions and is omitted. Another observation is that given any $x \in i(Z)$ there do exist affine open neighbourhoods $U$, $U'$ with $f(U) \subset U'$ and $Z \cap U$ as well as $U' \cap Z'$ closed such that $x \in U$. Proof omitted. Hence the requirement of the lemma indeed characterizes the map (and could have been used to define it).
Since we may check exactness at stalks, a sequence $f_1, \ldots, f_r$ is a regular sequence if and only if the maps $$ f_i : \mathcal{O}_{X, x}/(f_1, \ldots, f_{i - 1}) \longrightarrow \mathcal{O}_{X, x}/(f_1, \ldots, f_{i - 1}) $$ are injective for all $x \in X$. In other words, the image of the sequence $f_1, \ldots, f_r$ in the ring $\mathcal{O}_{X, x}$ is a regular sequence for all $x \in X$. The other types of regularity can be checked stalkwise as well (details omitted). Hence the implications follow from More on Algebra, Lemmas \ref{more-algebra-lemma-regular-koszul-regular}, \ref{more-algebra-lemma-koszul-regular-H1-regular}, and \ref{more-algebra-lemma-H1-regular-quasi-regular}.
It is clear that if $U \subset X$ is an open such that $\mathcal{J}|_U$ is generated by a quasi-regular sequence $f_1, \ldots, f_r \in \mathcal{O}_X(U)$ then $\mathcal{J}|_U$ is of finite type, $\mathcal{J}|_U/\mathcal{J}^2|_U$ is free with basis $f_1, \ldots, f_r$, and the maps in (3) are isomorphisms because they are coordinate free formulation of the degree $n$ part of (\ref{equation-map-quasi-regular}). Hence it is clear that being quasi-regular implies conditions (1), (2), and (3). \medskip\noindent Conversely, suppose that (1), (2), and (3) hold. Pick a point $x \in \text{Supp}(\mathcal{O}_X/\mathcal{J})$. Then there exists a neighbourhood $U \subset X$ of $x$ such that $\mathcal{J}|_U/\mathcal{J}^2|_U$ is free of rank $r$ over $\mathcal{O}_U/\mathcal{J}|_U$. After possibly shrinking $U$ we may assume there exist $f_1, \ldots, f_r \in \mathcal{J}(U)$ which map to a basis of $\mathcal{J}|_U/\mathcal{J}^2|_U$ as an $\mathcal{O}_U/\mathcal{J}|_U$-module. In particular we see that the images of $f_1, \ldots, f_r$ in $\mathcal{J}_x/\mathcal{J}^2_x$ generate. Hence by Nakayama's lemma (Algebra, Lemma \ref{algebra-lemma-NAK}) we see that $f_1, \ldots, f_r$ generate the stalk $\mathcal{J}_x$. Hence, since $\mathcal{J}$ is of finite type, by Modules, Lemma \ref{modules-lemma-finite-type-surjective-on-stalk} after shrinking $U$ we may assume that $f_1, \ldots, f_r$ generate $\mathcal{J}$. Finally, from (3) and the isomorphism $\mathcal{J}|_U/\mathcal{J}^2|_U = \bigoplus \mathcal{O}_U/\mathcal{J}|_U f_i$ it is clear that $f_1, \ldots, f_r \in \mathcal{O}_X(U)$ is a quasi-regular sequence.
First assume that $\mathcal{J}$ is quasi-regular. We may choose an open neighbourhood $U \subset X$ of $x$ and a quasi-regular sequence $g_1, \ldots, g_s \in \mathcal{O}_X(U)$ which generates $\mathcal{J}|_U$. Note that this implies that $\mathcal{J}/\mathcal{J}^2$ is free of rank $s$ over $\mathcal{O}_U/\mathcal{J}|_U$ (see Lemma \ref{lemma-quasi-regular-ideal} and its proof) and hence $r = s$. We may shrink $U$ and assume $f_1, \ldots, f_r \in \mathcal{J}(U)$. Thus we may write $$ f_i = \sum a_{ij} g_j $$ for some $a_{ij} \in \mathcal{O}_X(U)$. By assumption the matrix $A = (a_{ij})$ maps to an invertible matrix over $\kappa(x)$. Hence, after shrinking $U$ once more, we may assume that $(a_{ij})$ is invertible. Thus we see that $f_1, \ldots, f_r$ give a basis for $(\mathcal{J}/\mathcal{J}^2)|_U$ which proves that $f_1, \ldots, f_r$ is a quasi-regular sequence over $U$. \medskip\noindent Note that in order to prove (2) and (3) we may, because the assumptions of (2) and (3) are stronger than the assumption in (1), already assume that $f_1, \ldots, f_r \in \mathcal{J}(U)$ and $f_i = \sum a_{ij}g_j$ with $(a_{ij})$ invertible as above, where now $g_1, \ldots, g_r$ is a $H_1$-regular or Koszul-regular sequence. Since the Koszul complex on $f_1, \ldots, f_r$ is isomorphic to the Koszul complex on $g_1, \ldots, g_r$ via the matrix $(a_{ij})$ (see More on Algebra, Lemma \ref{more-algebra-lemma-change-basis}) we conclude that $f_1, \ldots, f_r$ is $H_1$-regular or Koszul-regular as desired.
By assumption we can find an open neighbourhood $U$ of $x$ over which $\mathcal{J}$ is generated by a regular (resp.\ Koszul-regular, $H_1$-regular, quasi-regular) sequence $f_1, \ldots, f_r \in \mathcal{O}_X(U)$. After shrinking $U$ we may assume that $U$ is affine, say $U = \Spec(A)$. Since $\mathcal{J}$ is quasi-coherent by Lemma \ref{lemma-regular-ideal-sheaf-quasi-coherent} we see that $\mathcal{J}|_U = \widetilde{I}$ for some ideal $I \subset A$. Now we can use the fact that $$ \widetilde{\ } : \text{Mod}_A \longrightarrow \QCoh(\mathcal{O}_U) $$ is an equivalence of categories which preserves exactness. For example the fact that the functions $f_i$ generate $\mathcal{J}$ means that the $f_i$, seen as elements of $A$ generate $I$. The fact that (\ref{equation-map-regular}) is injective (resp.\ (\ref{equation-koszul}) is exact, (\ref{equation-koszul}) is exact in degree $1$, (\ref{equation-map-quasi-regular}) is an isomorphism) implies the corresponding property of the map $A/(f_1, \ldots, f_{i - 1}) \to A/(f_1, \ldots, f_{i - 1})$ (resp.\ the complex $K_\bullet(A, f_1, \ldots, f_r)$, the map $A/I[T_1, \ldots, T_r] \to \bigoplus I^n/I^{n + 1}$). Thus $f_1, \ldots, f_r \in A$ is a regular (resp.\ Koszul-regular, $H_1$-regular, quasi-regular) sequence of the ring $A$.
It follows from Lemma \ref{lemma-regular-ideal-sheaf-scheme} that (5) $\Leftrightarrow$ (9), (6) $\Leftrightarrow$ (10), (7) $\Leftrightarrow$ (11), and (8) $\Leftrightarrow$ (12). It is clear that (5) $\Rightarrow$ (1), (6) $\Rightarrow$ (2), (7) $\Rightarrow$ (3), and (8) $\Rightarrow$ (4). We have (1) $\Rightarrow$ (5) by Algebra, Lemma \ref{algebra-lemma-regular-sequence-in-neighbourhood}. We have (9) $\Rightarrow$ (10) $\Rightarrow$ (11) $\Rightarrow$ (12) by Lemma \ref{lemma-regular-quasi-regular-scheme}. Finally, (4) $\Rightarrow$ (1) by Algebra, Lemma \ref{algebra-lemma-quasi-regular-regular}. Now all 12 statements are equivalent.
An open immersion is locally of finite presentation. Hence we may replace $X$ by an open subscheme $U \subset X$ such that $i$ identifies $Z$ with a closed subscheme of $U$, i.e., we may assume that $i$ is a closed immersion. Let $\mathcal{I} \subset \mathcal{O}_X$ be the corresponding quasi-coherent sheaf of ideals. Recall, see Morphisms, Lemma \ref{morphisms-lemma-closed-immersion-finite-presentation} that $\mathcal{I}$ is of finite type if and only if $i$ is locally of finite presentation. Hence the equivalence follows from Lemma \ref{lemma-quasi-regular-ideal} and unwinding the definitions.
Since $\mathcal{C}_{Z/Y}$ is finite locally free (see Lemma \ref{lemma-quasi-regular-immersion} and Lemma \ref{lemma-regular-quasi-regular-scheme}) it suffices to prove that the sequence is exact. By what was proven in Morphisms, Lemma \ref{morphisms-lemma-transitivity-conormal} it suffices to show that the first map is injective. Working affine locally this reduces to the following question: Suppose that we have a ring $A$ and ideals $I \subset J \subset A$. Assume that $J/I \subset A/I$ is generated by an $H_1$-regular sequence. Does this imply that $I/I^2 \otimes_A A/J \to J/J^2$ is injective? Note that $I/I^2 \otimes_A A/J = I/IJ$. Hence we are trying to prove that $I \cap J^2 = IJ$. This is the result of More on Algebra, Lemma \ref{more-algebra-lemma-conormal-sequence-H1-regular}.
The algebraic version of (1) is Algebra, Lemma \ref{algebra-lemma-join-regular-sequences}. The algebraic version of (2) is More on Algebra, Lemma \ref{more-algebra-lemma-join-koszul-regular-sequences}. The algebraic version of (3) is More on Algebra, Lemma \ref{more-algebra-lemma-join-H1-regular-sequences}. The algebraic version of (4) is More on Algebra, Lemma \ref{more-algebra-lemma-join-quasi-regular-H1-regular}.
After shrinking $Y$ and $X$ we may assume that $i$ and $j$ are closed immersions. Denote $\mathcal{I} \subset \mathcal{O}_X$ the ideal sheaf of $Y$ and $\mathcal{J} \subset \mathcal{O}_X$ the ideal sheaf of $Z$. The conormal sequence is $0 \to \mathcal{I}/\mathcal{I}\mathcal{J} \to \mathcal{J}/\mathcal{J}^2 \to \mathcal{J}/(\mathcal{I} + \mathcal{J}^2) \to 0$. Let $z \in Z$ and set $y = i(z)$, $x = j(y) = j(i(z))$. Choose $f_1, \ldots, f_n \in \mathcal{I}_x$ which map to a basis of $\mathcal{I}_x/\mathfrak m_z\mathcal{I}_x$. Extend this to $f_1, \ldots, f_n, g_1, \ldots, g_m \in \mathcal{J}_x$ which map to a basis of $\mathcal{J}_x/\mathfrak m_z\mathcal{J}_x$. This is possible as we have assumed that the sequence of conormal sheaves is split in a neighbourhood of $z$, hence $\mathcal{I}_x/\mathfrak m_x\mathcal{I}_x \to \mathcal{J}_x/\mathfrak m_x\mathcal{J}_x$ is injective. \medskip\noindent Proof of (1). By Lemma \ref{lemma-generate-regular-ideal} we can find an affine open neighbourhood $U$ of $x$ such that $f_1, \ldots, f_n, g_1, \ldots, g_m$ forms a quasi-regular sequence generating $\mathcal{J}$. Hence by Algebra, Lemma \ref{algebra-lemma-truncate-quasi-regular} we see that $g_1, \ldots, g_m$ induces a quasi-regular sequence on $Y \cap U$ cutting out $Z$. \medskip\noindent Proof of (2). Exactly the same as the proof of (1) except using More on Algebra, Lemma \ref{more-algebra-lemma-truncate-H1-regular}. \medskip\noindent Proof of (3). By Lemma \ref{lemma-generate-regular-ideal} (applied twice) we can find an affine open neighbourhood $U$ of $x$ such that $f_1, \ldots, f_n$ forms a Koszul-regular sequence generating $\mathcal{I}$ and $f_1, \ldots, f_n, g_1, \ldots, g_m$ forms a Koszul-regular sequence generating $\mathcal{J}$. Hence by More on Algebra, Lemma \ref{more-algebra-lemma-truncate-koszul-regular} we see that $g_1, \ldots, g_m$ induces a Koszul-regular sequence on $Y \cap U$ cutting out $Z$.
Since $X$ (and hence $Y$) is locally Noetherian all 4 types of regular immersions agree, and moreover we may check whether a morphism is a regular immersion on the level of local rings, see Lemma \ref{lemma-Noetherian-scheme-regular-ideal}. The implication (1) $\Rightarrow$ (2) is Lemma \ref{lemma-composition-regular-immersion}. The implication (2) $\Rightarrow$ (3) is Lemma \ref{lemma-transitivity-conormal-quasi-regular}. Thus it suffices to prove that (3) implies (1). \medskip\noindent Assume (3). Set $A = \mathcal{O}_{X, x}$. Denote $I \subset A$ the kernel of the surjective map $\mathcal{O}_{X, x} \to \mathcal{O}_{Y, y}$ and denote $J \subset A$ the kernel of the surjective map $\mathcal{O}_{X, x} \to \mathcal{O}_{Z, z}$. Note that any minimal sequence of elements generating $J$ in $A$ is a quasi-regular hence regular sequence, see Lemma \ref{lemma-generate-regular-ideal}. By assumption the conormal sequence $$ 0 \to I/IJ \to J/J^2 \to J/(I + J^2) \to 0 $$ is split exact as a sequence of $A/J$-modules. Hence we can pick a minimal system of generators $f_1, \ldots, f_n, g_1, \ldots, g_m$ of $J$ with $f_1, \ldots, f_n \in I$ a minimal system of generators of $I$. As pointed out above $f_1, \ldots, f_n, g_1, \ldots, g_m$ is a regular sequence in $A$. It follows directly from the definition of a regular sequence that $f_1, \ldots, f_n$ is a regular sequence in $A$ and $\overline{g}_1, \ldots, \overline{g}_m$ is a regular sequence in $A/I$. Thus $j$ is a regular immersion at $y$ and $i$ is a regular immersion at $z$.
We may assume that $X$ is affine and the ideal of $Z$ generated by a Koszul-regular sequence by replacing $X$ by the members of a suitable affine open covering (affine opens as in Lemma \ref{lemma-regular-ideal-sheaf-scheme}). The affine case is More on Algebra, Lemma \ref{more-algebra-lemma-Koszul-regular-flat-locally-regular}.
Let $z \in Z$. By Lemma \ref{lemma-Noetherian-scheme-regular-ideal} it suffices to show that the kernel of $\mathcal{O}_{X, z} \to \mathcal{O}_{Z, z}$ is generated by a regular sequence. This follows from Algebra, Lemmas \ref{algebra-lemma-regular-quotient-regular} and \ref{algebra-lemma-regular-ring-CM}.
Let $f_1, \ldots, f_r \in \mathcal{O}_{X, x}$ be a quasi-regular sequence cutting out the ideal of $Z$ at $x$. By Algebra, Lemma \ref{algebra-lemma-quasi-regular-regular} we know that $f_1, \ldots, f_r$ is a regular sequence. Hence $f_r$ is a nonzerodivisor on $\mathcal{O}_{X, x}/(f_1, \ldots, f_{r - 1})$ such that the quotient is a flat $\mathcal{O}_{S, f(x)}$-module. By Lemma \ref{lemma-flat-at-x} we conclude that $\mathcal{O}_{X, x}/(f_1, \ldots, f_{r - 1})$ is a flat $\mathcal{O}_{S, f(x)}$-module. Continuing by induction we find that $\mathcal{O}_{X, x}$ is a flat $\mathcal{O}_{S, s}$-module.
Pick $x \in Z$ with image $s \in S$. To prove this it suffices to find an affine neighbourhood of $x$ contained in $U$ such that the result holds on that affine open. Hence we may assume that $X$ is affine and there exist a quasi-regular sequence $f_1, \ldots, f_r \in \Gamma(X, \mathcal{O}_X)$ such that $Z = V(f_1, \ldots, f_r)$. By More on Algebra, Lemma \ref{more-algebra-lemma-relative-regular-immersion-algebra} the sequence $f_1|_{X_s}, \ldots, f_r|_{X_s}$ is a quasi-regular sequence in $\Gamma(X_s, \mathcal{O}_{X_s})$. Since $X_s$ is Noetherian, this implies, possibly after shrinking $X$ a bit, that $f_1|_{X_s}, \ldots, f_r|_{X_s}$ is a regular sequence, see Algebra, Lemmas \ref{algebra-lemma-quasi-regular-regular} and \ref{algebra-lemma-regular-sequence-in-neighbourhood}. By Lemma \ref{lemma-fibre-Cartier} it follows that $Z_1 = V(f_1) \subset X$ is a relative effective Cartier divisor, again after possibly shrinking $X$ a bit. Applying the same lemma again, but now to $Z_2 = V(f_1, f_2) \subset Z_1$ we see that $Z_2 \subset Z_1$ is a relative effective Cartier divisor. And so on until on reaches $Z = Z_n = V(f_1, \ldots, f_n)$. Since being a relative effective Cartier divisor is preserved under arbitrary base change, see Lemma \ref{lemma-relative-Cartier}, we also see that the final statement of the lemma holds.
By Schemes, Lemma \ref{schemes-lemma-semi-diagonal} the morphism $\sigma$ is an immersion. After replacing $X$ by an open neighbourhood of $\sigma(S)$ we may assume that $\sigma$ is a closed immersion. Let $T = \sigma(S)$ be the corresponding closed subscheme of $X$. Since $T \to S$ is an isomorphism it is flat and of finite presentation. Also a smooth morphism is flat and locally of finite presentation, see Morphisms, Lemmas \ref{morphisms-lemma-smooth-flat} and \ref{morphisms-lemma-smooth-locally-finite-presentation}. Thus, according to Lemma \ref{lemma-fibre-quasi-regular}, it suffices to show that $T_s \subset X_s$ is a quasi-regular closed subscheme. This follows immediately from Morphisms, Lemma \ref{morphisms-lemma-section-smooth-morphism} but we can also see it directly as follows. Let $k$ be a field and let $A$ be a smooth $k$-algebra. Let $\mathfrak m \subset A$ be a maximal ideal whose residue field is $k$. Then $\mathfrak m$ is generated by a quasi-regular sequence, possibly after replacing $A$ by $A_g$ for some $g \in A$, $g \not \in \mathfrak m$. In Algebra, Lemma \ref{algebra-lemma-characterize-smooth-over-field} we proved that $A_{\mathfrak m}$ is a regular local ring, hence $\mathfrak mA_{\mathfrak m}$ is generated by a regular sequence. This does indeed imply that $\mathfrak m$ is generated by a regular sequence (after replacing $A$ by $A_g$ for some $g \in A$, $g \not \in \mathfrak m$), see Algebra, Lemma \ref{algebra-lemma-regular-sequence-in-neighbourhood}.
We can write $i$ as the composition $$ Y \to Y \times_S X \to X $$ By Lemma \ref{lemma-section-smooth-regular-immersion} the first arrow is a regular immersion. The second arrow is a flat base change of $Y \to S$, hence is a regular (resp.\ Koszul-regular, $H_1$-regular, quasi-regular) immersion, see Lemma \ref{lemma-flat-base-change-regular-immersion}. We conclude by an application of Lemma \ref{lemma-composition-regular-immersion}.