dimension of fiber of variety I have a problem proving the fiber dimension theorem:
For a morphism between irreducible $k$ varieties, there is a nonempty open subset $U \subset Y$ such that for every $q \in U$ the fiber over $q$ has pure dimension $\operatorname{dim} X - \operatorname{dim} Y$.
In Ravi Vakil FOAG this is posed as an exerise 11.4.B, and I tried to prove $\operatorname{dim} X - \operatorname{dim} Y \geq \operatorname{codim}_{\pi^{-1}(q)} p$ as follows: $\operatorname{codim}_X p \leq \operatorname{codim}_Y q + \operatorname{codim}_{\pi^{-1}(q)} p$ and
$\operatorname{dim}_X p + \operatorname{codim}_X p = \operatorname{dim} X, \operatorname{dim}_Y q + \operatorname{codim}_Y q = \operatorname{dim} Y$
so it suffices to show
$\operatorname{coht} p \leq \operatorname{coht} q$
where the points are regarded as prime ideals of $X = \operatorname{Spec} A, Y = \operatorname{Spec} B$.
But $B/q \rightarrow A/p$ is injective, and therefore $\operatorname{dim} B/q \leq \operatorname{dim} A/p $ by considering transcendence degree.
Here is my problem. I got the converse inequality. Where I went wrong? And how can I prove it?
 A: Thanks for asking this question. It is nice to know that I am not the only one who is stuck on this. Let me try to attempt answering this, but I hope that someone corrects it, if I make any wrong remark.
Following the remarks Vakil makes in 11.4.B in his notes, we are in the situation where we have $\pi : X = \text{Spec}(A) \rightarrow \text{Spec}(B) = Y$ induced by an inclusion $B \hookrightarrow A$ of integral domains that are finitely generated over a field $k$. Fix any $y \in Y$.
We use what Vakil proves later which is the existence of a nonempty distinguished open $U$ in $X$ such that $\pi^{-1}(U) \rightarrow U$ factors as $\pi^{-1}(U) \rightarrow \mathbb{A}^{m-n}_{k} \times_{k} U \rightarrow U$ where the first map is finite and surjective and the second one is the projection map. Since $U$ is distinguished open, we may write $U = \text{Spec}(B_{g})$. Then we can write down the given factorization as $\text{Spec}(A_{\phi(g)}) \rightarrow \mathbb{A}^{m-n}_{B_{g}} \rightarrow \text{Spec}(B_{g})$ where $\phi : B \rightarrow A$ denotes the corresponding ring map of $\pi : X \rightarrow Y$. Thus, the corresponding ring map $B_{g} \rightarrow A_{\phi(g)}$ must factor as $B_{g} \rightarrow B_{g}[t_{1}, \dots, t_{m-n}] \rightarrow A_{\phi(g)}$. Since $B_{g}$ has fraction field $B_{(0)}$, by considering transcendence degree, we have $\dim(B_{g}) = \dim(B)$. Similarly, we have $\dim(A_{\phi(g)}) = \dim(A)$. This lets us replace $B_{g}$ with $B$ and $A_{g}$ with $A$ in our proof. Hence, we are working with $B \rightarrow B[t_{1}, \dots, t_{m-n}] \rightarrow A$.
Fix $y \in U$. We want to show that $\pi^{-1}(y)$ is of pure dimension $m - n$ where $m = \dim(A)$ and $n = \dim(Y)$.  Note that by convention we give $\pi^{-1}(y)$ a scheme structure by taking the spectrum of $R = \kappa(y) \otimes_{B} A$, and this is a finitely generated algebra over the residue field $\kappa(y)$. Thus, for any minimal prime $\mathfrak{h} \subset R$, we have $\dim(R) = \dim(R/\mathfrak{h})$, which shows that $\dim(\pi^{-1}(y)) = \dim(R)$ is of pure dimension of some number. Thus, we only need to check $\dim(\pi^{-1}(y)) = m - n$.
Applying base change over $\kappa(y)$ to the factorization $\pi^{-1}(U) \rightarrow \mathbb{A}^{m-n}_{k} \times U \rightarrow U$, we get $\pi^{-1}(y) \rightarrow \mathbb{A}^{m-n}_{\kappa(y)} \rightarrow \text{Spec}(\kappa(y))$, and the first map is still finite and surjective by 9.4.B (d) and 9.4.D of Vakil's notes.
Step 1. We first show $\dim(\pi^{-1}(y)) \leq m - n$.
Let $Z = \overline{\{x\}} \cap \pi^{-1}(y) \subset \pi^{-1}(y) = \text{Spec}(\kappa(y) \otimes_{B} A)$ be any irreducible component. Then we may write $Z = \text{Spec}((\kappa(y) \otimes_{B} A)/\mathfrak{p}')$ where $\mathfrak{p}'$ represents $x$ in the fiber. Ring-wise, we have $\kappa(y) \hookrightarrow \kappa(y)[t_{1}, \dots, t_{m-n}]/\mathfrak{q}' \hookrightarrow (\kappa(y) \otimes_{B} A)/\mathfrak{p}'$, where $\mathfrak{q}'$ is the image of $x$ in $\mathbb{A}^{m-n}_{\kappa(y)}$ under $\pi^{-1}(y) \rightarrow \mathbb{A}^{m-n}_{\kappa(y)}$. Since the second inclusion is finite, it must preserve dimension, so
$\begin{align*}\dim(\pi^{-1}(y)) &= \dim(Z)\\ &= \dim((\kappa(y) \otimes_{B} A)/\mathfrak{p}')\\ &= \dim(\kappa(y)[t_{1}, \dots, t_{m-n}]/\mathfrak{q}')\\ &= m-n-\text{ht}(\mathfrak{q'}) \\&\leq m-n,\end{align*}$
as desired.
Step 2. It remains to show that $\dim(\pi^{-1}(y)) \geq m-n.$
We use the finite surjection $\pi^{-1}(y) \twoheadrightarrow \mathbb{A}^{m-n}_{\kappa(y)}.$ Consider $(0) \in \text{Spec}(\kappa(y)[t_{1}, \dots, t_{m-n}]) = \mathbb{A}^{m-n}_{\kappa(y)},$ the generic point. Since the map is surjective there must be some $x \in \pi^{-1}(y)$ mapping into $(0)$. Writing $\pi^{-1}(y) = \text{Spec}(R)$ and denoting $x = \mathfrak{p},$ the map corresponds to a finite ring map $\kappa(y)[t_{1}, \dots, t_{m-n}] \rightarrow R$ and this map pulls $\mathfrak{p}$ back to $(0)$. Hence we get a finite ring map $\kappa(y)[t_{1}, \dots, t_{m-n}] \rightarrow R/\mathfrak{p}$ that pulls $(0)$ to $(0)$, so we must have a finite extension $\kappa(y)[t_{1}, \dots, t_{m-n}] \hookrightarrow R/\mathfrak{p},$ and since finite extension does not change the dimension, we must have $m-n = \dim(R/\mathfrak{p}) \leq \dim(R) = \dim(\pi^{-1}(y)),$ as desired.
Remark. I am quite bothered by the fact that Step 2 does not use Vakil's hint in his book. I tried to work out that way, but I could not come up with any sounding proof. If anyone finds a mistake in Step 2 or has a different answer, I would love to see it!
