Doubt related to proof of a theorem on dimension of fibers. 
*

*$f:X \rightarrow Y$ be a morphism of varieties such that for each $p\in Y,\, \dim f^{-1}(p) = n$. Then $\dim X=\dim Y+n$. In the proof of this theorem if I replace $X$ by an affine open set why the dimension of the fiber is same. Please explain.

*$f:X \rightarrow Y$ be a morphism of affine varieties such that for each $p\in W,\, \dim f^{-1}(p) =n$ for some dense subset $W$ of $Y$. Then $\dim X= \dim Y+n$. I have tried to write down a proof of this which is as follows:

Proof by induction on $\dim Y$. Nothing to prove when $\dim Y=0$. Let $X \subseteq A^{r}, Y \subseteq A^{m}$ be closed subvarieties. $f=(f_{1},...,f_{m})$,  where   $f_{i} \in K[x_{1},...,x_{r}]$.
Let  $F \in K[x_{1},...,x_{m}] \setminus I(Y)$.   $\quad Y^{'}=Y \cap Z(F)$.
$X^{'}=f^{-1}(Y^{'})=X \cap Z(F(f_{1},...,f_{m}))$. $\quad F(f_{1},...,f_{m}) \in K[x_{1},...,x_{r}] \setminus I(X)$.
$\widetilde{X}$ be an irreducible component of $X^{'}$. $\quad \dim \widetilde{X}=\dim X-1$.
There exists an irreducible component $\widetilde{Y}$ of $Y^{'}$ such that $\quad f(\widetilde{X}) \subseteq \widetilde{Y}$. $\quad \dim \widetilde{Y}=\dim Y-1$.
Consider $f:\widetilde{X} \rightarrow \widetilde{Y}$.
How can I conclude the fiber is same? Please resolve this.
 A: Let's assume irreducibility here.

*

*Since affine opens are dense, by restricting to an affine open, you either miss out an fiber completely, or an fiber simply becomes another dense subset of itself (hence doesn't change dimension). For a picture in mind, consider the trivial projection $\mathbb{P}^1\times\mathbb{P}^1\to\mathbb{P}^1$, where each fiber is a copy of $\mathbb{P}^1$. If you restrict to an affine open $\mathbb{A}^1\times\mathbb{A}^1$, the fiber becomes $\mathbb{A}^1$ or empty (over infinity).


*Intuitively, if you consider the algebra map $f^*:B=\Gamma(Y)\to A=\Gamma(X)$, then any generic maximal ideal $\mathfrak{m}$ is mapped to some prime ideal $P$ which can be extended to a chain $P\subset P_1\subset\cdots \subset P_n$. Notice that $f^*$ should be injective (not quite, but lets assume that here), then the maximal ideal has a chain $P'_0\subset\cdots\subset P'_{\text{dim}(Y)}=\mathfrak{m}$, and the image of those primes is still prime; so you have a long chain of length $\dim(Y)+n$ in $\Gamma(X)$. I'm not sure if completing this to a full proof is easier...
