hcju/stacksqa huggingface dataset:
The problem is local on $X$ and $S$. Hence we may assume that $X = \Spec(B)$, $S = \Spec(A)$ and $f$ corresponds to a pseudo-coherent ring map $A \to B$. \medskip\noindent If (1) holds, then $B$ has finite tor dimension $d$ as $A$-module. Then $B_\mathfrak q$ has tor dimension $d$ as an $A_\mathfrak p$-module for all primes $\mathfrak q \subset B$ with $\mathfrak p = A \cap \mathfrak q$, see More on Algebra, Lemma \ref{more-algebra-lemma-tor-amplitude-localization}. Then $\mathcal{O}_X$ has tor dimension $d$ as a  sheaf of $f^{-1}\mathcal{O}_S$-modules by Cohomology, Lemma \ref{cohomology-lemma-tor-amplitude-stalk}. Thus (1) implies (2). \medskip\noindent By Cohomology, Lemma \ref{cohomology-lemma-tor-amplitude-stalk} (2) implies (3). \medskip\noindent Assume (3). We cannot use More on Algebra, Lemma \ref{more-algebra-lemma-tor-amplitude-localization} to conclude as we are not given that the tor dimension of $B_\mathfrak q$ over $A_\mathfrak p$ is bounded independent of $\mathfrak q$. Choose a presentation $A[x_1, \ldots, x_n] \to B$. Then $B$ is pseudo-coherent as a $A[x_1, \ldots, x_n]$-module. Let $\mathfrak q \subset A[x_1, \ldots, x_n]$ be a prime ideal lying over $\mathfrak p \subset A$. Then either $B_\mathfrak q$ is zero or by assumption it has finite tor dimension as an $A_\mathfrak p$-module. Since the fibres of $A \to A[x_1, \ldots, x_n]$ have finite global dimension, we can apply More on Algebra, Lemma \ref{more-algebra-lemma-perfect-over-polynomial-ring} to $A_\mathfrak p \to A[x_1, \ldots, x_n]_\mathfrak q$ to see that $B_\mathfrak q$ is a perfect $A[x_1, \ldots, x_n]_\mathfrak q$-module. Hence $B$ is a perfect $A[x_1, \ldots, x_n]$-module by More on Algebra, Lemma \ref{more-algebra-lemma-check-perfect-stalks}. Thus $A \to B$ is a perfect ring map by definition.
This is more or less immediate from the definition. Namely, let $U = \Spec(A)$ be an affine open of $X$. Then $i^{-1}(U) = \Spec(A/I)$ for some ideal $I \subset A$ and $A/I$ has a finite resolution by finite projective $A$-modules by More on Algebra, Lemma \ref{more-algebra-lemma-perfect-ring-map}. Hence $i_*\mathcal{O}_Z|_U$ can be represented by a finite length complex of finite locally free $\mathcal{O}_U$-modules. This is what we had to show, see Cohomology, Section \ref{cohomology-section-perfect}.
We claim that Derived Categories of Schemes, Lemma \ref{perfect-lemma-perfect-direct-image} applies. Conditions (1) and (2) are immediate. Condition (3) is local on $X$. Thus we may assume $X$ and $S$ affine and $E$ represented by a strictly perfect complex of $\mathcal{O}_X$-modules. Thus it suffices to show that $\mathcal{O}_X$ has finite tor dimension as a sheaf of $f^{-1}\mathcal{O}_S$-modules. This is equivalent to being perfect by Lemma \ref{lemma-check-perfect-stalks}.
Let $\{g_i : X_i \to X\}_{i \in I}$ be an fppf covering of schemes and let $f : X \to S$ be a morphism such that each $f \circ g_i$ is perfect. By Lemma \ref{lemma-pseudo-coherent-fppf-local-source} we conclude that $f$ is pseudo-coherent. Hence by Lemma \ref{lemma-check-perfect-stalks} it suffices to check that $\mathcal{O}_{X, x}$ is an $\mathcal{O}_{S, f(x)}$-module of finite tor dimension for all $x \in X$. Pick $i \in I$ and $x_i \in X_i$ mapping to $x$. Then we see that $\mathcal{O}_{X_i, x_i}$ has finite tor dimension over $\mathcal{O}_{S, f(x)}$ and that $\mathcal{O}_{X, x} \to \mathcal{O}_{X_i, x_i}$ is faithfully flat. The desired conclusion follows from More on Algebra, Lemma \ref{more-algebra-lemma-flat-descent-tor-amplitude}.
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 Divisors, Lemma \ref{divisors-lemma-Noetherian-scheme-regular-ideal}. Thus the result follows from Divided Power Algebra, Lemma \ref{dpa-lemma-regular-sequence}.
Assume $i$ is a Koszul-regular immersion in a neighbourhood of $x$. Consider the morphism $j = (i, i') : U \to P \times_S P' = P''$. Since $P'' = P \times_S P' \to P$ is smooth, it follows from Divisors, Lemma \ref{divisors-lemma-lift-regular-immersion-to-smooth} that $j$ is a Koszul-regular immersion, whereupon it follows from Divisors, Lemma \ref{divisors-lemma-push-regular-immersion-thru-smooth} that $i'$ is a Koszul-regular immersion.
Since a perfect morphism is pseudo-coherent (because a perfect ring map is pseudo-coherent) and a pseudo-coherent morphism is locally of finite presentation (because a pseudo-coherent ring map is of finite presentation) it suffices to prove the last statement. Being perfect is a local property, hence we may assume that $f$ factors as $\pi \circ i$ where $\pi$ is smooth and $i$ is a Koszul-regular immersion. A Koszul-regular immersion is perfect, see Lemma \ref{lemma-regular-immersion-perfect}. A smooth morphism is perfect as it is flat and locally of finite presentation, see Lemma \ref{lemma-flat-finite-presentation-perfect}. Finally a composition of perfect morphisms is perfect, see Lemma \ref{lemma-composition-perfect}.
Let $g : Y \to S$ and $f : X \to Y$ be local complete intersection morphisms. Let $x \in X$ and set $y = f(x)$. Choose an open neighbourhood $V \subset Y$ of $y$ and a factorization $g|_V = \pi \circ i$ for some Koszul-regular immersion $i : V \to P$ and smooth morphism $\pi : P \to S$. Next choose an open neighbourhood $U$ of $x \in X$ and a factorization $f|_U = \pi' \circ i'$ for some Koszul-regular immersion $i' : U \to P'$ and smooth morphism $\pi' : P' \to Y$. In fact, we may assume that $P' = \mathbf{A}^n_V$, see discussion preceding and following Definition \ref{definition-lci}. Picture: $$ \xymatrix{ X \ar[d] & U \ar[l] \ar[r]_-{i'} & P' = \mathbf{A}^n_V \ar[d] \\ Y \ar[d] &  & V \ar[ll] \ar[r]_i & P \ar[d] \\ S & & & S \ar[lll] } $$ Set $P'' = \mathbf{A}^n_P$. Then $U \to P' \to P''$ is a Koszul-regular immersion as a composition of Koszul-regular immersions, namely $i'$ and the flat base change of $i$ via $P'' \to P$, see Divisors, Lemma \ref{divisors-lemma-regular-immersion-noetherian} and Divisors, Lemma \ref{divisors-lemma-composition-regular-immersion}. Also $P'' \to P \to S$ is smooth as a composition of smooth morphisms, see Morphisms, Lemma \ref{morphisms-lemma-composition-smooth}. Hence we conclude that $X \to S$ is Koszul at $x$ as desired.
Working affine locally this is More on Algebra, Lemma \ref{more-algebra-lemma-syntomic-lci}. We also give a more geometric proof. \medskip\noindent Assume (2). By Morphisms, Lemma \ref{morphisms-lemma-syntomic-locally-standard-syntomic} for every point $x$ of $X$ there exist affine open neighbourhoods $U$ of $x$ and $V$ of $f(x)$ such that $f|_U : U \to V$ is standard syntomic. This means that $U = \Spec(R[x_1, \ldots, x_n]/(f_1, \ldots, f_c)) \to V = \Spec(R)$ where $R[x_1, \ldots, x_n]/(f_1, \ldots, f_c)$ is a relative global complete intersection over $R$. By Algebra, Lemma \ref{algebra-lemma-relative-global-complete-intersection-conormal} the sequence $f_1, \ldots, f_c$ is a regular sequence in each local ring $R[x_1, \ldots, x_n]_{\mathfrak q}$ for every prime $\mathfrak q \supset (f_1, \ldots, f_c)$. Consider the Koszul complex $K_\bullet = K_\bullet(R[x_1, \ldots, x_n], f_1, \ldots, f_c)$ with homology groups $H_i = H_i(K_\bullet)$. By More on Algebra, Lemma \ref{more-algebra-lemma-regular-koszul-regular} we see that $(H_i)_{\mathfrak q} = 0$, $i > 0$ for every $\mathfrak q$ as above. On the other hand, by More on Algebra, Lemma \ref{more-algebra-lemma-homotopy-koszul} we see that $H_i$ is annihilated by $(f_1, \ldots, f_c)$. Hence we see that $H_i = 0$, $i > 0$ and $f_1, \ldots, f_c$ is a Koszul-regular sequence. This proves that $U \to V$ factors as a Koszul-regular immersion $U \to \mathbf{A}^n_V$ followed by a smooth morphism as desired. \medskip\noindent Assume (1). Then $f$ is a flat and locally of finite presentation (Lemma \ref{lemma-lci-properties}). Hence, according to Morphisms, Lemma \ref{morphisms-lemma-syntomic-locally-standard-syntomic} it suffices to show that the local rings $\mathcal{O}_{X_s, x}$ are local complete intersection rings. Choose, locally on $X$, a factorization $f = \pi \circ i$ for some Koszul-regular immersion $i : X \to P$ and smooth morphism $\pi : P \to S$. Note that $X \to P$ is a relative quasi-regular immersion over $S$, see Divisors, Definition \ref{divisors-definition-relative-H1-regular-immersion}. Hence according to Divisors, Lemma \ref{divisors-lemma-relative-regular-immersion-flat-in-neighbourhood} we see that $X \to P$ is a regular immersion and the same remains true after any base change. Thus each fibre is a regular immersion, whence all the local rings of all the fibres of $X$ are local complete intersections.
We may assume there is a factorization $X \to \mathbf{A}^n_Y \to Y$ where the first arrow is an immersion. As $Y$ is regular also $\mathbf{A}^n_Y$ is regular by Algebra, Lemma \ref{algebra-lemma-regular-goes-up}. Hence $X \to \mathbf{A}^n_Y$ is a regular immersion by Divisors, Lemma \ref{divisors-lemma-immersion-regular-regular-immersion}.
In the course of this proof all schemes will be locally Noetherian and all rings will be Noetherian. We will use without further mention that regular sequences and Koszul regular sequences agree in this setting, see More on Algebra, Lemma \ref{more-algebra-lemma-noetherian-finite-all-equivalent}. Moreover, whether an ideal (resp.\ ideal sheaf) is regular may be checked on local rings (resp.\ stalks), see Algebra, Lemma \ref{algebra-lemma-regular-sequence-in-neighbourhood} (resp.\ Divisors, Lemma \ref{divisors-lemma-Noetherian-scheme-regular-ideal}) \medskip\noindent The question is local. Hence we may assume $S$, $X$, $Y$ are affine. In this situation we may choose a commutative diagram $$ \xymatrix{ \mathbf{A}^{n + m}_S \ar[d] & X \ar[l] \ar[d] \\ \mathbf{A}^n_S \ar[d] & Y \ar[l] \ar[ld] \\ S } $$ whose horizontal arrows are closed immersions. Let $x \in X$ be a point and consider the corresponding commutative diagram of local rings $$ \xymatrix{ J \ar[r] & \mathcal{O}_{\mathbf{A}^{n + m}_S, x} \ar[r] & \mathcal{O}_{X, x} \\ I \ar[r] \ar[u] & \mathcal{O}_{\mathbf{A}^n_S, f(x)} \ar[r] \ar[u] & \mathcal{O}_{Y, f(x)} \ar[u] } $$ where $J$ and $I$ are the kernels of the horizontal arrows. Since $X \to S$ is a local complete intersection morphism, the ideal $J$ is generated by a regular sequence. Since $X \to Y$ is perfect the ring $\mathcal{O}_{X, x}$ has finite tor dimension over $\mathcal{O}_{Y, f(x)}$. Hence we may apply Divided Power Algebra, Lemma \ref{dpa-lemma-perfect-map-ci} to conclude that $I$ and $J/I$ are generated by regular sequences. By our initial remarks, this finishes the proof.
Translated into algebra this is More on Algebra, Lemma \ref{more-algebra-lemma-lci-NL}. To do the translation use Lemmas \ref{lemma-affine-lci} and \ref{lemma-NL-affine} as well as Derived Categories of Schemes, Lemmas \ref{perfect-lemma-affine-compare-bounded}, \ref{perfect-lemma-tor-dimension-affine} and \ref{perfect-lemma-perfect-affine}.
Translated into algebra this is Divided Power Algebra, Lemma \ref{dpa-lemma-perfect-NL-lci}. To do the translation use Lemmas \ref{lemma-affine-lci} and \ref{lemma-NL-affine} as well as Derived Categories of Schemes, Lemmas \ref{perfect-lemma-affine-compare-bounded}, \ref{perfect-lemma-tor-dimension-affine} and \ref{perfect-lemma-perfect-affine}.
Translated into algebra this is Divided Power Algebra, Lemma \ref{dpa-lemma-flat-fp-NL-lci}. To do the translation use Lemmas \ref{lemma-affine-lci} and \ref{lemma-NL-affine} as well as Derived Categories of Schemes, Lemmas \ref{perfect-lemma-affine-compare-bounded}, \ref{perfect-lemma-tor-dimension-affine} and \ref{perfect-lemma-perfect-affine}.
Assume (1). Then $f$ is flat by Morphisms, Lemma \ref{morphisms-lemma-smooth-flat}. The projections $X \times_Y X \to X$ are smooth by Morphisms, Lemma \ref{morphisms-lemma-base-change-smooth}. Hence the diagonal is a section to a smooth morphism and hence a regular immersion, see Divisors, Lemma \ref{divisors-lemma-section-smooth-regular-immersion}. Hence (1) $\Rightarrow$ (2). The implication (2) $\Rightarrow$ (3) is Lemma \ref{lemma-regular-immersion-lci}. The implication (3) $\Rightarrow$ (4) is Lemma \ref{lemma-lci-properties}. The interesting implication (4) $\Rightarrow$ (1) follows immediately from Divided Power Algebra, Lemma \ref{dpa-lemma-perfect-diagonal}.
Let $f : X \to S$ be a morphism of schemes. Let $\{S_i \to S\}$ be an fpqc covering of $S$. Assume that each base change $f_i : X_i \to S_i$ of $f$ is a local complete intersection morphism. Note that this implies in particular that $f$ is locally of finite type, see Lemma \ref{lemma-lci-properties} and Descent, Lemma \ref{descent-lemma-descending-property-locally-finite-type}. Let $x \in X$. Choose an open neighbourhood $U$ of $x$ and an immersion $j : U \to \mathbf{A}^n_S$ over $S$ (see discussion preceding Definition \ref{definition-lci}). We have to show that $j$ is a Koszul-regular immersion. Since $f_i$ is a local complete intersection morphism, we see that the base change $j_i : U \times_S S_i \to \mathbf{A}^n_{S_i}$ is a Koszul-regular immersion, see Lemma \ref{lemma-lci}. Because $\{\mathbf{A}^n_{S_i} \to \mathbf{A}^n_S\}$ is a fpqc covering we see from Descent, Lemma \ref{descent-lemma-descending-property-regular-immersion} that $j$ is a Koszul-regular immersion as desired.
We will use the criterion of Descent, Lemma \ref{descent-lemma-properties-morphisms-local-source} to prove this. It follows from Lemmas \ref{lemma-flat-lci} and \ref{lemma-composition-lci} that being a local complete intersection morphism is preserved under precomposing with syntomic morphisms. It is clear from Definition \ref{definition-lci} that being a local complete intersection morphism is Zariski local on the source and target. Hence, according to the aforementioned Descent, Lemma \ref{descent-lemma-properties-morphisms-local-source} it suffices to prove the following: Suppose $X' \to X \to Y$ are morphisms of affine schemes with $X' \to X$ syntomic and $X' \to Y$ a local complete intersection morphism. Then $X \to Y$ is a local complete intersection morphism. To see this, note that in any case $X \to Y$ is of finite presentation by Descent, Lemma \ref{descent-lemma-flat-finitely-presented-permanence-algebra}. Choose a closed immersion $X \to \mathbf{A}^n_Y$. By Algebra, Lemma \ref{algebra-lemma-lift-syntomic} we can find an affine open covering $X' = \bigcup_{i = 1, \ldots, n} X'_i$ and syntomic morphisms $W_i \to \mathbf{A}^n_Y$ lifting the morphisms $X'_i \to X$, i.e., such that there are fibre product diagrams $$ \xymatrix{ X'_i \ar[d] \ar[r] & W_i \ar[d] \\ X \ar[r] & \mathbf{A}^n_Y } $$ After replacing $X'$ by $\coprod X'_i$ and setting $W = \coprod W_i$ we obtain a fibre product diagram of affine schemes $$ \xymatrix{ X' \ar[d] \ar[r] & W \ar[d]^h \\ X \ar[r] & \mathbf{A}^n_Y } $$ with $h : W \to \mathbf{A}^n_Y$ syntomic and $X' \to Y$ still a local complete intersection morphism. Since $W \to \mathbf{A}^n_Y$ is open (see Morphisms, Lemma \ref{morphisms-lemma-fppf-open}) and $X' \to X$ is surjective we see that $X$ is contained in the image of $W \to \mathbf{A}^n_Y$. Choose a closed immersion $W \to \mathbf{A}^{n + m}_Y$ over $\mathbf{A}^n_Y$. Now the diagram looks like $$ \xymatrix{ X' \ar[d] \ar[r] & W \ar[d]^h \ar[r] & \mathbf{A}^{n + m}_Y \ar[ld] \\ X \ar[r] & \mathbf{A}^n_Y } $$ Because $h$ is syntomic and hence a local complete intersection morphism (see above) the morphism $W \to \mathbf{A}^{n + m}_Y$ is a Koszul-regular immersion. Because $X' \to Y$ is a local complete intersection morphism the morphism $X' \to \mathbf{A}^{n + m}_Y$ is a Koszul-regular immersion. We conclude from Divisors, Lemma \ref{divisors-lemma-permanence-regular-immersion} that $X' \to W$ is a Koszul-regular immersion. Hence, since being a Koszul-regular immersion is fpqc local on the target (see Descent, Lemma \ref{descent-lemma-descending-property-regular-immersion}) we conclude that $X \to \mathbf{A}^n_Y$ is a Koszul-regular immersion which is what we had to show.
The set is open by definition (see Definition \ref{definition-lci}). Let $S' \to S$ be a morphism of schemes. Set $X' = S' \times_S X$, $Y' = S' \times_S Y$, and denote $f' : X' \to Y'$ the base change of $f$. Let $x' \in X'$ be a point such that $f'$ is Koszul at $x'$. Denote $s' \in S'$, $x \in X$, $y' \in Y'$ , $y \in Y$, $s \in S$ the image of $x'$. Note that $f$ is locally of finite presentation, see Morphisms, Lemma \ref{morphisms-lemma-finite-presentation-permanence}. Hence we may choose an affine neighbourhood $U \subset X$ of $x$ and an immersion $i : U \to \mathbf{A}^n_Y$. Denote $U' = S' \times_S U$ and $i' : U' \to \mathbf{A}^n_{Y'}$ the base change of $i$. The assumption that $f'$ is Koszul at $x'$ implies that $i'$ is a Koszul-regular immersion in a neighbourhood of $x'$, see Lemma \ref{lemma-lci}. The scheme $X'$ is flat and locally of finite presentation over $S'$ as a base change of $X$ (see Morphisms, Lemmas \ref{morphisms-lemma-base-change-flat} and \ref{morphisms-lemma-base-change-finite-presentation}). Hence $i'$ is a relative $H_1$-regular immersion over $S'$ in a neighbourhood of $x'$ (see Divisors, Definition \ref{divisors-definition-relative-H1-regular-immersion}). Thus the base change $i'_{s'} : U'_{s'} \to \mathbf{A}^n_{Y'_{s'}}$ is a $H_1$-regular immersion in an open neighbourhood of $x'$, see Divisors, Lemma \ref{divisors-lemma-relative-regular-immersion} and the discussion following Divisors, Definition \ref{divisors-definition-relative-H1-regular-immersion}. Since $s' = \Spec(\kappa(s')) \to \Spec(\kappa(s)) = s$ is a surjective flat universally open morphism (see Morphisms, Lemma \ref{morphisms-lemma-scheme-over-field-universally-open}) we conclude that the base change $i_s : U_s \to \mathbf{A}^n_{Y_s}$ is an $H_1$-regular immersion in a neighbourhood of $x$, see Descent, Lemma \ref{descent-lemma-descending-property-regular-immersion}. Finally, note that $\mathbf{A}^n_Y$ is flat and locally of finite presentation over $S$, hence Divisors, Lemma \ref{divisors-lemma-fibre-quasi-regular} implies that $i$ is a (Koszul-)regular immersion in a neighbourhood of $x$ as desired.
The first assertion follows immediately from Lemma \ref{lemma-unramified-formally-unramified} and the fact that a local complete intersection morphism is locally of finite type. To compute the conormal sheaf of $f$ we choose, locally on $X$, a factorization of $f$ as $f = p \circ i$ where $i : X \to V$ is a Koszul-regular immersion and $V \to Y$ is smooth. By Lemma \ref{lemma-two-unramified-morphisms-formally-smooth} we see that $\mathcal{C}_{X/Y}$ is a locally direct summand of $\mathcal{C}_{X/V}$ which is finite locally free as $i$ is a Koszul-regular (hence quasi-regular) immersion, see Divisors, Lemma \ref{divisors-lemma-quasi-regular-immersion}.
The question is local on $Z$ hence we may assume there exists a factorization $Z \to \mathbf{A}^n_Y \to Y$ of the morphism $Z \to Y$. Then we get a commutative diagram $$ \xymatrix{ Z \ar[r]_{i'} \ar@{=}[d] & \mathbf{A}^n_Y \ar[r] \ar[d] & \mathbf{A}^n_X \ar[d] \\ Z \ar[r]^i & Y \ar[r] & X } $$ As $Z \to Y$ is a local complete intersection morphism, we see that $Z \to \mathbf{A}^n_Y$ is a Koszul-regular immersion. Hence by Divisors, Lemma \ref{divisors-lemma-transitivity-conormal-quasi-regular} the sequence $$ 0 \to (i')^*\mathcal{C}_{\mathbf{A}^n_Y/\mathbf{A}^n_X} \to \mathcal{C}_{Z/\mathbf{A}^n_X} \to \mathcal{C}_{Z/\mathbf{A}^n_Y} \to 0 $$ is exact and locally split. Note that $i^*\mathcal{C}_{Y/X} = (i')^*\mathcal{C}_{\mathbf{A}^n_Y/\mathbf{A}^n_X}$ by Lemma \ref{lemma-universal-thickening-fibre-product-flat} and note that the diagram $$ \xymatrix{ (i')^*\mathcal{C}_{\mathbf{A}^n_Y/\mathbf{A}^n_X} \ar[r] & \mathcal{C}_{Z/\mathbf{A}^n_X} \\ i^*\mathcal{C}_{Y/X} \ar[u]^{\cong} \ar[r] & \mathcal{C}_{Z/X} \ar[u] } $$ is commutative. Hence the lower horizontal arrow is a locally split injection. This proves the lemma.
Observe that under both assumptions (1) and (2) the morphism $f$ is flat. Thus we may assume $f$ is flat. Let $x \in X$ with image $y = f(x)$ in $Y$. There are canonical maps of rings $$ \mathcal{O}_{X, x} \otimes_{\mathcal{O}_{Y, y}} \mathcal{O}_{X, x} \longrightarrow \mathcal{O}_{X \times_Y X, \Delta_{X/Y}(x)} \longrightarrow \mathcal{O}_{X, x} $$ where the first map is a localization (hence flat) and the second map is a surjection (hence an epimorphism of rings). Condition (1) means that for all $x$ the second arrow is flat. Condition (2) is that for all $x$ the composition is flat. These conditions are equivalent by Algebra, Lemma \ref{algebra-lemma-composition-flat} and More on Algebra, Lemma \ref{more-algebra-lemma-key}.
Let $x \in X$ with image $y = f(x)$ in $Y$. Since $X \to X \times_Y X$ is flat, we see that $\mathcal{O}_{X, x} \otimes_{\mathcal{O}_{Y, y}} \mathcal{O}_{X, x} \to \mathcal{O}_{X, x}$ is flat. Hence the result follows from More on Algebra, Lemma \ref{more-algebra-lemma-key} and the definitions.
Suppose given open subschemes $U \subset X$, $V \subset S$ with $f(U) \subset V$. Then $U \times_V U \subset X \times_Y X$ is open (Schemes, Lemma \ref{schemes-lemma-open-fibre-product}) and the diagonal $\Delta_{U/V}$ of $f|_U : U \to V$ is the restriction $\Delta_{X/Y}|_U : U \to U \times_V U$. Since flatness is a local property of morphisms of schemes (Morphisms, Lemma \ref{morphisms-lemma-flat-characterize}) the final statement of the lemma is follows as well as the equivalence of (1) and (3). If $X$ and $Y$ are affine, then $X \to Y$ is weakly \'etale if and only if $\mathcal{O}_Y(Y) \to \mathcal{O}_X(X)$ is weakly \'etale (use again Morphisms, Lemma \ref{morphisms-lemma-flat-characterize}). Thus (1) and (3) are also equivalent to (2) and (4).
Part (1) follows from the factorization $$ X \to X \times_Y X \to X \times_Z X $$ of the diagonal of $X$ over $Z$, the fact that $$ X \times_Y X = (X \times_Z X) \times_{(Y \times_Z Y)} Y, $$ the fact that a base change of a flat morphism is flat, and the fact that the composition of flat morphisms is flat (Morphisms, Lemmas \ref{morphisms-lemma-base-change-flat} and \ref{morphisms-lemma-composition-flat}). Part (2) follows from part (1) and the fact (just used) that the composition of flat morphisms is flat.
Assume $X \to X \times_Y X$ is flat. The morphism $X' \to X' \times_{Y'} X'$ is the base change of $X \to X \times_Y X$ by $Y' \to Y$. Hence it is flat by Morphisms, Lemmas \ref{morphisms-lemma-base-change-flat}. This proves (1). Part (2) follows from (1) and the fact (just used) that the base change of a flat morphism is flat.
Consider the commutative diagram $$ \xymatrix{ X \ar[r] \ar[d] & X \times_Z X \ar[d] \\ Y \ar[r] & Y \times_Z Y } $$ The top horizontal arrow is flat and the vertical arrows are flat. Hence $X$ is flat over $Y \times_Z Y$. By Morphisms, Lemma \ref{morphisms-lemma-flat-permanence} we see that $Y$ is flat over $Y \times_Z Y$.
Recall that $f$ is formally unramified if and only if $\Omega_{X/Y} = 0$ by Lemma \ref{lemma-formally-unramified-differentials}. Via Lemma \ref{lemma-weakly-etale-characterize} and Morphisms, Lemma \ref{morphisms-lemma-differentials-affine} this follows from the case of rings which is More on Algebra, Lemma \ref{more-algebra-lemma-formally-unramified}.
If (1) holds, then $\Delta_{X/Y}$ is an isomorphism (Schemes, Lemma \ref{schemes-lemma-monomorphism}), hence certainly $f$ is weakly \'etale. Case (2) is a special case of (1). The diagonal of an unramified morphism is an open immersion (Morphisms, Lemma \ref{morphisms-lemma-diagonal-unramified-morphism}), hence flat. Thus a flat unramified morphism is weakly \'etale. An \'etale morphism is flat and unramified (Morphisms, Lemma \ref{morphisms-lemma-etale-smooth-unramified}), hence (4) follows from (3).