hcju/stacksqa huggingface dataset:
Let $k \subset K$ be a field extension such that $X_K$ is quasi-affine. The morphism $X_K \to X$ is surjective. Hence $X$ is quasi-compact as the image of a quasi-compact scheme (Properties, Definition \ref{properties-definition-quasi-affine}). Since $X_K$ is quasi-separated (as an open subscheme of an affine scheme) we see that $X$ is quasi-separated: If $U, V \subset X$ are affine open, then $(U \cap V)_K = U_K \cap V_K$ is quasi-compact and $(U \cap V)_K \to U \cap V$ is surjective. Thus Schemes, Lemma \ref{schemes-lemma-characterize-quasi-separated} applies. \medskip\noindent Write $K = \colim A_i$ as the colimit of the subalgebras of $K$ which are of finite type over $k$. Denote $X_i = X \times_{\Spec(k)} \Spec(A_i)$. Since $X_K = \lim X_i$ we find an $i$ such that $X_i$ is quasi-affine (Limits, Lemma \ref{limits-lemma-limit-quasi-affine}; here we use that $X$ is quasi-compact and quasi-separated as just shown). By the Hilbert Nullstellensatz (Algebra, Theorem \ref{algebra-theorem-nullstellensatz}) the residue field $k' = A_i/\mathfrak m$ is a finite extension of $k$. Hence $X_{k'} \subset X_i$ is a closed subscheme hence is quasi-affine (Properties, Lemma \ref{properties-lemma-quasi-affine-locally-closed}). Since $X_{k'} \to X$ is finite locally free we conclude by Divisors, Lemma \ref{divisors-lemma-push-down-quasi-affine}.
By definition a morphism of schemes $g : Y \to T$ is quasi-projective if it is locally of finite type, quasi-compact, and there exists a $g$-ample invertible sheaf on $Y$. Let $k \subset K$ be a field extension such that $X_K$ is quasi-projective over $K$. Let $\Spec(A) \subset X$ be an affine open. Then $U_K$ is an affine open subscheme of $X_K$, hence $A_K$ is a $K$-algebra of finite type. Then $A$ is a $k$-algebra of finite type by Algebra, Lemma \ref{algebra-lemma-finite-type-descends}. Hence $X \to \Spec(k)$ is locally of finite type. Since $X_K \to \Spec(K)$ is quasi-compact, we see that $X_K$ is quasi-compact, hence $X$ is quasi-compact, hence $X \to \Spec(k)$ is of finite type. By Morphisms, Lemma \ref{morphisms-lemma-finite-type-over-affine-ample-very-ample} we see that $X_K$ has an ample invertible sheaf. Then $X$ has an ample invertible sheaf by Lemma \ref{lemma-ample-after-field-extension}. Hence $X \to \Spec(k)$ is quasi-projective by Morphisms, Lemma \ref{morphisms-lemma-finite-type-over-affine-ample-very-ample}.
Let $k \subset K$ be a field extension such that $X_K$ is proper over $K$. Recall that this implies $X_K$ is separated and quasi-compact (Morphisms, Definition \ref{morphisms-definition-proper}). The morphism $X_K \to X$ is surjective. Hence $X$ is quasi-compact as the image of a quasi-compact scheme (Properties, Definition \ref{properties-definition-ample}). Since $X_K$ is separated we see that $X$ is quasi-separated: If $U, V \subset X$ are affine open, then $(U \cap V)_K = U_K \cap V_K$ is quasi-compact and $(U \cap V)_K \to U \cap V$ is surjective. Thus Schemes, Lemma \ref{schemes-lemma-characterize-quasi-separated} applies. \medskip\noindent Write $K = \colim A_i$ as the colimit of the subalgebras of $K$ which are of finite type over $k$. Denote $X_i = X \times_{\Spec(k)} \Spec(A_i)$. By Limits, Lemma \ref{limits-lemma-eventually-proper} there exists an $i$ such that $X_i \to \Spec(A_i)$ is proper. Here we use that $X$ is quasi-compact and quasi-separated as just shown. Choose a maximal ideal $\mathfrak m \subset A_i$. By the Hilbert Nullstellensatz (Algebra, Theorem \ref{algebra-theorem-nullstellensatz}) the residue field $k' = A_i/\mathfrak m$ is a finite extension of $k$.  The base change $X_{k'} \to \Spec(k')$ is proper (Morphisms, Lemma \ref{morphisms-lemma-base-change-proper}). Since $k \subset k'$ is finite both $X_{k'} \to X$ and the composition $X_{k'} \to \Spec(k)$ are proper as well (Morphisms, Lemmas \ref{morphisms-lemma-finite-proper}, \ref{morphisms-lemma-base-change-proper}, and \ref{morphisms-lemma-composition-proper}). The first implies that $X$ is separated over $k$ as $X_{k'}$ is separated (Morphisms, Lemma \ref{morphisms-lemma-image-universally-closed-separated}). The second implies that $X \to \Spec(k)$ is proper by Morphisms, Lemma \ref{morphisms-lemma-image-proper-is-proper}.
A scheme over $k$ is projective over $k$ if and only if it is quasi-projective and proper over $k$. See Morphisms, Lemma \ref{morphisms-lemma-projective-is-quasi-projective-proper}. Thus the lemma follows from Lemmas \ref{lemma-quasi-projective-after-field-extension} and \ref{lemma-proper-after-field-extension}.
Set $\kappa = \kappa(x)$. Observe that we have a pushout in the category of schemes $$ \Spec(\kappa[\epsilon]) \amalg_{\Spec(\kappa)} \Spec(\kappa[\epsilon]) = \Spec(\kappa[\epsilon_1, \epsilon_2]) $$ where $\kappa[\epsilon_1, \epsilon_2]$ is the $\kappa$-algebra with basis $1, \epsilon_1, \epsilon_2$ and $\epsilon_1^2 = \epsilon_1\epsilon_2 = \epsilon_2^2 = 0$. This follows immediately from the corresponding result for rings and the description of morphisms from spectra of local rings to schemes in Schemes, Lemma \ref{schemes-lemma-morphism-from-spec-local-ring}. Given two arrows $\theta_1, \theta_2 : \Spec(\kappa[\epsilon]) \to X$ we can consider the morphism $$ \theta_1 + \theta_2 : \Spec(\kappa[\epsilon]) \to \Spec(\kappa[\epsilon_1, \epsilon_2]) \xrightarrow{\theta_1, \theta_2} X $$ where the first arrow is given by $\epsilon_i \mapsto \epsilon$. On the other hand, given $\lambda \in \kappa$ there is a self map of $\Spec(\kappa[\epsilon])$ corresponding to the $\kappa$-algebra endomorphism of $\kappa[\epsilon]$ which sends $\epsilon$ to $\lambda \epsilon$. Precomposing $\theta : \Spec(\kappa[\epsilon]) \to X$ by this selfmap gives $\lambda \theta$. The reader can verify the axioms of a vector space by verifying the existence of suitable commutative diagrams of schemes. We omit the details. (An alternative proof would be to express everything in terms of local rings and then verify the vector space axioms on the level of ring maps.)
Set $\kappa = \kappa(x)$. Given $\theta \in T_{X/S, x}$ we obtain a map $$ \theta^*\Omega_{X/S} \to \Omega_{\Spec(\kappa[\epsilon])/\Spec(\kappa(s))} \to \Omega_{\Spec(\kappa[\epsilon])/\Spec(\kappa)} $$ Taking sections we obtain an $\mathcal{O}_{X, x}$-linear map $\xi_\theta : \Omega_{X/S, x} \to \kappa \text{d}\epsilon$, i.e., an element of the right hand side of the formula of the lemma. To show that $\theta \mapsto \xi_\theta$ is an isomorphism we can replace $S$ by $s$ and $X$ by the scheme theoretic fibre $X_s$. Indeed, both sides of the formula only depend on the scheme theoretic fibre; this is clear for $T_{X/S, x}$ and for the RHS see Morphisms, Lemma \ref{morphisms-lemma-base-change-differentials}. We may also replace $X$ by the spectrum of $\mathcal{O}_{X, x}$ as this does not change $T_{X/S, x}$ (Schemes, Lemma \ref{schemes-lemma-morphism-from-spec-local-ring}) nor $\Omega_{X/S, x}$ (Modules, Lemma \ref{modules-lemma-stalk-module-differentials}). \medskip\noindent Let $(A, \mathfrak m, \kappa)$ be a local ring over a field $k$. To finish the proof we have to show that any $A$-linear map $\xi : \Omega_{A/k} \to \kappa$ comes from a unique $k$-algebra map $\varphi : A \to \kappa[\epsilon]$ agreeing with the canonical map $c : A \to \kappa$ modulo $\epsilon$. Write $\varphi(a) = c(a) + D(a) \epsilon$ the reader sees that $a \mapsto D(a)$ is a $k$-derivation. Using the universal property of $\Omega_{A/k}$ we see that each $D$ corresponds to a unique $\xi$ and vice versa. This finishes the proof.
The second isomorphism follows from the first by Lemma \ref{lemma-tangent-space-cotangent-space}. For the first, we can replace $S$ by $s$ and $X$ by $X_s$, see Morphisms, Lemma \ref{morphisms-lemma-base-change-differentials}. We may also replace $X$ by the spectrum of $\mathcal{O}_{X, x}$, see Modules, Lemma \ref{modules-lemma-stalk-module-differentials}. Thus we have to show the following algebra fact: let $(A, \mathfrak m, \kappa)$ be a local ring over a field $k$ such that $\kappa/k$ is separable algebraic. Then the canonical map $$ \mathfrak m/\mathfrak m^2 \longrightarrow \Omega_{A/k} \otimes \kappa $$ is an isomorphism. Observe that $\mathfrak m/\mathfrak m^2 = H_1(\NL_{\kappa/A})$. By Algebra, Lemma \ref{algebra-lemma-exact-sequence-NL} it suffices to show that $\Omega_{\kappa/k} = 0$ and $H_1(\NL_{\kappa/k}) = 0$. Since $\kappa$ is the union of its finite separable extensions in $k$ it suffices to prove this when $\kappa$ is a finite separable extension of $k$ (Algebra, Lemma \ref{algebra-lemma-colimits-NL}). In this case the ring map $k \to \kappa$ is \'etale and hence $\NL_{\kappa/k} = 0$ (more or less by definition, see Algebra, Section \ref{algebra-section-etale}).
The morphism $f$ is locally of finite type by Morphisms, Lemma \ref{morphisms-lemma-permanence-finite-type}. The map $\text{d}f$ is injective, if and only if $\Omega_{Y/S, y} \otimes \kappa(y) \to \Omega_{X/S, x} \otimes \kappa(x)$ is surjective (Lemma \ref{lemma-map-tangent-spaces}). The exact sequence $f^*\Omega_{Y/S} \to \Omega_{X/S} \to \Omega_{X/Y} \to 0$ (Morphisms, Lemma \ref{morphisms-lemma-triangle-differentials}) then shows that this happens if and only if $\Omega_{X/Y, x} \otimes \kappa(x) = 0$. Hence the result follows from Morphisms, Lemma \ref{morphisms-lemma-unramified-at-point}.
Condition (4) implies $X$ is locally Noetherian (Morphisms, Lemma \ref{morphisms-lemma-finite-type-noetherian}). The set of points at which morphism is quasi-finite is open (Morphisms, Lemma \ref{morphisms-lemma-quasi-finite-points-open}). A dense open of a locally Noetherian scheme contains all generic point of irreducible components, hence (4) implies (3). Condition (3) implies condition (1) by Morphisms, Lemma \ref{morphisms-lemma-residue-field-quasi-finite}. Condition (1) implies condition (2). Thus it suffices to prove the lemma in case (2) holds. \medskip\noindent Assume (2) holds. Recall that $\Spec(\mathcal{O}_{Y, y})$ is the set of points of $Y$ specializing to $y$, see Schemes, Lemma \ref{schemes-lemma-specialize-points}. Combined with Morphisms, Lemma \ref{morphisms-lemma-base-change-quasi-finite} this shows we may replace $Y$ by $\Spec(\mathcal{O}_{Y, y})$. Thus we may assume $Y = \Spec(B)$ where $B$ is a Noetherian local ring of dimension $\leq 1$ and $y$ is the closed point. \medskip\noindent Let $X = \bigcup X_i$ be the irreducible components of $X$ viewed as reduced closed subschemes. If we can show each fibre $X_{i, y}$ is a discrete space, then $X_y = \bigcup X_{i, y}$ is discrete as well and we conclude that $X \to Y$ is quasi-finite at all points of $X_y$ by Morphisms, Lemma \ref{morphisms-lemma-quasi-finite-at-point-characterize}. Thus we may assume $X$ is an integral scheme. \medskip\noindent If $X \to Y$ maps the generic point $\eta$ of $X$ to $y$, then $X$ is the spectrum of a finite extension of $\kappa(y)$ and the result is true. Assume that $X$ maps $\eta$ to a point corresponding to a minimal prime $\mathfrak q$ of $B$ different from $\mathfrak m_B$. We obtain a factorization $X \to \Spec(B/\mathfrak q) \to \Spec(B)$. Let $x \in X$ be a point lying over $y$. By the dimension formula (Morphisms, Lemma \ref{morphisms-lemma-dimension-formula}) we have $$ \dim(\mathcal{O}_{X, x}) \leq \dim(B/\mathfrak q) + \text{trdeg}_{\kappa(\mathfrak q)}(R(X)) - \text{trdeg}_{\kappa(y)} \kappa(x) $$ We know that $\dim(B/\mathfrak q) = 1$, that the generic point of $X$ is not equal to $x$ and specializes to $x$ and that $R(X)$ is algebraic over $\kappa(\mathfrak q)$. Thus we get $$ 1 \leq 1 - \text{trdeg}_{\kappa(y)} \kappa(x) $$ Hence every point $x$ of $X_y$ is closed in $X_y$ by Morphisms, Lemma \ref{morphisms-lemma-algebraic-residue-field-extension-closed-point-fibre} and hence $X \to Y$ is quasi-finite at every point $x$ of $X_y$ by Morphisms, Lemma \ref{morphisms-lemma-quasi-finite-at-point-characterize} (which also implies that $X_y$ is a discrete topological space).
By Lemma \ref{lemma-quasi-finite-in-codim-1} the morphism $f$ is quasi-finite at every point of the fibre $X_y$. Hence $X_y$ is a discrete topological space (Morphisms, Lemma \ref{morphisms-lemma-quasi-finite-at-point-characterize}). As $f$ is proper the fibre $X_y$ is quasi-compact, i.e., finite. Thus we can apply Cohomology of Schemes, Lemma \ref{coherent-lemma-proper-finite-fibre-finite-in-neighbourhood} to conclude.
Write $S = \Spec(A)$ and $X = \Spec(B)$ and let $A \to B$ be the ring map corresponding to $f$. Let $\mathfrak p \subset A$ be the prime ideal corresponding to $s$. We can choose a surjection $A[x_1, \ldots, x_r] \to B$. By Algebra, Lemma \ref{algebra-lemma-Noether-normalization} there exist elements $y_1, \ldots, y_d \in A$ in the $\mathbf{Z}$-subalgebra of $A$ generated by $x_1, \ldots, x_r$ such that the $A$-algebra homomorphism $A[t_1, \ldots, t_d] \to B$ sending $t_i$ to $y_i$ induces a finite $\kappa(\mathfrak p)$-algebra homomorphism $\kappa(\mathfrak p)[t_1, \ldots, t_d] \to B \otimes_A \kappa(\mathfrak p)$. This proves the lemma.
By Morphisms, Lemma \ref{morphisms-lemma-finite-type-differentials} the first dimension is finite. The first equality follows as the restriction of $\Omega_{X/S}$ to the fibre is the module of differentials from Morphisms, Lemma \ref{morphisms-lemma-base-change-differentials}. The last equality follows from Lemma \ref{lemma-tangent-space-cotangent-space}. Thus we see that the statement makes sense. \medskip\noindent To prove the lemma write $S = \Spec(A)$ and $X = \Spec(B)$ and let $A \to B$ be the ring map corresponding to $f$. Let $\mathfrak q \subset B$ be the prime ideal corresponding to $x$. Choose a surjection of $A$-algebras $A[x_1, \ldots, x_t] \to B$. Since $\Omega_{B/A}$ is generated by $\text{d}x_1, \ldots, \text{d}x_t$ we see that their images in $\Omega_{X/S, x} \otimes_{\mathcal{O}_{X, x}} \kappa(x)$ generate this as a $\kappa(x)$-vector space. After renumbering we may assume that $\text{d}x_1, \ldots, \text{d}x_r$ map to a basis of $\Omega_{X/S, x} \otimes_{\mathcal{O}_{X, x}} \kappa(x)$. We claim that $P = A[x_1, \ldots, x_r] \to B$ is unramified at $\mathfrak q$. To see this it suffices to show that $\Omega_{B/P, \mathfrak q} = 0$ (Algebra, Lemma \ref{algebra-lemma-unramified}). Note that $\Omega_{B/P}$ is the quotient of $\Omega_{B/A}$ by the submodule generated by $\text{d}x_1, \ldots, \text{d}x_r$. Hence $\Omega_{B/P, \mathfrak q} \otimes_{B_\mathfrak q} \kappa(\mathfrak q) = 0$ by our choice of $x_1, \ldots, x_r$. By Nakayama's lemma, more precisely Algebra, Lemma \ref{algebra-lemma-NAK} part (2) which applies as $\Omega_{B/P}$ is finite (see reference above), we conclude that $\Omega_{B/P, \mathfrak q} = 0$.
Pick any affine open $U \subset X$ with $x \in U$ and $f(U) \subset V$. Apply Lemma \ref{lemma-unramfied-over-affine} to $U \to V$ to get $U \to \mathbf{A}^r_V \to V$ as in the statement of that lemma. By Lemma \ref{lemma-geometric-structure-unramified} we get a factorization $$ U \xrightarrow{j} D \xrightarrow{j'} \mathbf{A}^{r + 1}_V \xrightarrow{p} \mathbf{A}^r_V \to V $$ where $j$ and $j'$ are immersions, $p$ is the projection, and $p \circ j'$ is standard \'etale. Thus we see in particular that (1) and (2) hold.
Recall that $\Spec(\mathcal{O}_{Y, y})$ is the set of points of $Y$ specializing to $y$, see Schemes, Lemma \ref{schemes-lemma-specialize-points}. Thus we may replace $Y$ by $\Spec(\mathcal{O}_{Y, y})$ and assume $Y = \Spec(B)$ where $B$ is a Noetherian local ring of dimension $\leq 1$ and $y$ is the closed point. We may also replace $X$ by an affine neighbourhood of $x$. \medskip\noindent Let $X = \bigcup X_i$ be the irreducible components of $X$ viewed as reduced closed subschemes. If we can show each fibre $X_{i, y}$ has dimension $d$, then $X_y = \bigcup X_{i, y}$ has dimension $d$ as well. Thus we may assume $X$ is an integral scheme. \medskip\noindent If $X \to Y$ maps the generic point $\eta$ of $X$ to $y$, then $X$ is a scheme over $\kappa(y)$ and the result is true by assumption. Assume that $X$ maps $\eta$ to a point $\xi \in Y$ corresponding to a minimal prime $\mathfrak q$ of $B$ different from $\mathfrak m_B$. We obtain a factorization $X \to \Spec(B/\mathfrak q) \to \Spec(B)$. By the dimension formula (Morphisms, Lemma \ref{morphisms-lemma-dimension-formula}) we have $$ \dim(\mathcal{O}_{X, x}) + \text{trdeg}_{\kappa(y)} \kappa(x) \leq \dim(B/\mathfrak q) + \text{trdeg}_{\kappa(\mathfrak q)}(R(X)) $$ We have $\dim(B/\mathfrak q) = 1$. We have $\text{trdeg}_{\kappa(\mathfrak q)}(R(X)) = d$ by our assumption that $\dim_\eta(X_\xi) = d$, see Morphisms, Lemma \ref{morphisms-lemma-dimension-fibre-at-a-point}. Since $\mathcal{O}_{X, x} \to \mathcal{O}_{X_s, x}$ has a kernel (as $\eta \mapsto \xi \not = y$) and since $\mathcal{O}_{X, x}$ is a Noetherian domain we see that $\dim(\mathcal{O}_{X, x}) > \dim(\mathcal{O}_{X_y, x})$. We conclude that $$ \dim_x(X_s) = \dim(\mathcal{O}_{X_s, x}) + \text{trdeg}_{\kappa(y)} \kappa(x) \leq d $$ (Morphisms, Lemma \ref{morphisms-lemma-dimension-fibre-at-a-point}). On the other hand, we have $\dim_x(X_s) \geq \dim_\eta(X_{f(\eta)}) = d$ by Morphisms, Lemma \ref{morphisms-lemma-openness-bounded-dimension-fibres}.
Exactly as in the proof of Lemma \ref{lemma-dimension-fibre-in-codim-1} we reduce to the case $X = \Spec(A)$ with $A$ a domain and $Y = \Spec(B)$ where $B$ is a Noetherian local ring whose maximal ideal corresponds to $y$. After replacing $B$ by $B/\Ker(B \to A)$ we may assume that $B$ is a domain and that $B \subset A$. Then we use the dimension formula (Morphisms, Lemma \ref{morphisms-lemma-dimension-formula}) to get $$ \dim(\mathcal{O}_{X, x}) + \text{trdeg}_{\kappa(y)} \kappa(x) \leq \dim(B) + \text{trdeg}_B(A) $$ We have $\text{trdeg}_B(A) = d$ by our assumption that $\dim_\eta(X_\xi) = d$, see Morphisms, Lemma \ref{morphisms-lemma-dimension-fibre-at-a-point}. Since $\mathcal{O}_{X, x} \to \mathcal{O}_{X_s, x}$ has a kernel (as $f(\eta) \not = y$) and since $\mathcal{O}_{X, x}$ is a Noetherian domain we see that $\dim(\mathcal{O}_{X, x}) > \dim(\mathcal{O}_{X_y, x})$. We conclude that $$ \dim_x(X_s) = \dim(\mathcal{O}_{X_s, x}) + \text{trdeg}_{\kappa(y)} \kappa(x) < \dim(B) + d $$ (equality by Morphisms, Lemma \ref{morphisms-lemma-dimension-fibre-at-a-point}) which proves what we want.
Let $X$ be a locally algebraic $k$-scheme of dimension $0$. Let $U = \Spec(A) \subset X$ be an affine open subscheme. Since $\dim(X) = 0$ we see that $\dim(A) = 0$. By Noether normalization, see Algebra, Lemma \ref{algebra-lemma-Noether-normalization} we see that there exists a finite injection $k \to A$, i.e., $\dim_k(A) < \infty$. Hence $A$ is Artinian, see Algebra, Lemma \ref{algebra-lemma-finite-dimensional-algebra}. This implies that $A = A_1 \times \ldots \times A_r$ is a product of finitely many Artinian local rings, see Algebra, Lemma \ref{algebra-lemma-artinian-finite-length}. Of course $\dim_k(A_i) < \infty$ for each $i$ as the sum of these dimensions equals $\dim_k(A)$. \medskip\noindent The arguments above show that $X$ has an open covering whose members are finite discrete topological spaces. Hence $X$ is a discrete topological space. It follows that $X$ is isomorphic to the disjoint union of its connected components each of which is a singleton. Since a singleton scheme is affine we conclude (by the results of the paragraph above) that each of these singletons is the spectrum of a local Artinian $k$-algebra $A$ with $\dim_k(A) < \infty$. \medskip\noindent Finally, if $X$ is an algebraic $k$-scheme of dimension $0$, then $X$ is quasi-compact hence is a finite disjoint union $X = \Spec(A_1) \amalg \ldots \amalg \Spec(A_r)$ hence affine (see Schemes, Lemma \ref{schemes-lemma-disjoint-union-affines}) and we have seen the finiteness of $X \to \Spec(k)$ in the first paragraph of the proof.
The morphism $f$ is locally of finite type by Morphisms, Lemma \ref{morphisms-lemma-permanence-finite-type}. Hence the base change $X_y \to \Spec(\kappa(y))$ is locally of finite type. This proves (1). In the rest of the proof we will freely use the results of Lemma \ref{lemma-dimension-locally-algebraic} for $X$, $Y$, and the fibres of $f$. \medskip\noindent Proof of (2). Let $\eta \in X$ be the generic point and set $\xi = f(\eta)$. Then $Z = \overline{\{\xi\}}$. Hence $$ d = \dim(X) - \dim(Z) = \text{trdeg}_k \kappa(\eta) - \text{trdeg}_k \kappa(\xi) = \text{trdeg}_{\kappa(\xi)} \kappa(\eta) = \dim_\eta(X_\xi) $$ Thus parts (2)(a) and (2)(b) follow from Morphisms, Lemma \ref{morphisms-lemma-openness-bounded-dimension-fibres}. Parts (2)(c) and (2)(d) follow from Lemmas \ref{lemma-dimension-fibre-in-higher-codimension} and \ref{lemma-dimension-fibre-in-codim-1}. \medskip\noindent Proof of (3). Let $x \in X$. Let $X' \subset X$ be a irreducible component of $X$ passing through $x$ of dimension $\dim_x(X)$. Then (2) implies that $\dim_x(X_y) \geq \dim(X') - \dim(Z')$ where $Z' \subset Y$ is the closure of the image of $X'$. This proves (3).
Proof of (1). Consider the factorization $$ X \times Y \longrightarrow Y \longrightarrow \Spec(k) $$ of the structure morphism. The first morphism $p : X \times Y \to Y$ is flat as a base change of the flat morphism $X \to \Spec(k)$ by Morphisms, Lemma \ref{morphisms-lemma-base-change-flat}. Moreover, we have $\dim_z(p^{-1}(y)) = \dim_x(X)$ by Morphisms, Lemma \ref{morphisms-lemma-dimension-fibre-after-base-change}. Hence $\dim_z(X \times Y) = \dim_x(X) + \dim_y(Y)$ by Morphisms, Lemma \ref{morphisms-lemma-dimension-fibre-at-a-point-additive}. Part (2) is a direct consequence of (1).
The existence of the isomorphism is an immediate consequence of the Cohen structure theorem\footnote{Note that if $\kappa$ has characteristic $p$, then the theorem just says we get a surjection $\Lambda[[x_1, \ldots, x_n]] \to \mathcal{O}_{X, x}^\wedge$ where $\Lambda$ is a Cohen ring for $\kappa$. But of course in this case the map factors through $\Lambda/p\Lambda[[x_1, \ldots, x_n]]$ and $\Lambda/p\Lambda = \kappa$.} (Algebra, Theorem \ref{algebra-theorem-cohen-structure-theorem}). \medskip\noindent Let $p$ be an odd prime number, let $k = \mathbf{F}_p(t)$, and $A = k[x, y]/(y^2 + x^p - t)$. Then the completion $A^\wedge$ of $A$ in the maximal ideal $\mathfrak m = (y)$ is isomorphic to $k(t^{1/p})[[z]]$ as a ring but not as a $k$-algebra. The reason is that $A^\wedge$ does not contain an element whose $p$th power is $t$ (as the reader can see by computing modulo $y^2$). This also shows that any isomorphism (\ref{equation-complete-local-ring}) cannot be a $k$-algebra isomorphism. \medskip\noindent If $\kappa/k$ is separable, then there is a $k$-algebra homomorphism $\kappa \to \mathcal{O}_{X, x}^\wedge$ inducing the identity on residue fields by More on Algebra, Lemma \ref{more-algebra-lemma-lift-residue-field}. Let $f_1, \ldots, f_n \in \mathfrak m_x$ be generators. Consider the map $$ \kappa[[x_1, \ldots, x_n]] \longrightarrow \mathcal{O}_{X, x}^\wedge,\quad x_i \longmapsto f_i $$ Since both sides are $(x_1, \ldots, x_n)$-adically complete (the right hand side by Algebra, Lemmas \ref{algebra-lemma-hathat-finitely-generated}) this map is surjective by Algebra, Lemma \ref{algebra-lemma-completion-generalities} as it is surjective modulo $(x_1, \ldots, x_n)$ by construction.