Counter example of upper semicontinuity of fiber dimension in classical algebraic geometry

We know that if $f : X\to Y$ is a morphism between two irreducible affine varieties over an algebraically closed field $k$, then the function that assigns to each point of $X$ the dimension of the fiber it belongs to is upper semicontinuous on $X$.

Does anyone know of a simple counterexample when $X$ is not irreducible anymore (but remains an algebraic set over $k$, i.e a finitely generated $k$-algebra) ?

Edit : to avoid ambiguity about the definition of upper semicontinuity, it means here that for all $n\geq 0$, the set of $x\in X$ such that $\dim(f^{-1}(f(x) ) ) \geq n$ is closed in $X$.

It seems to me it is not so obvious to find a counterexample, since in fact the set of $x\in X$ such that the dimension of the irreducible component of $f^{-1}(f(x) )$ in $X$ that contains $x$ is $\geq n$ is always closed even when $X$ is not irreducible.

-

Let $X = (\mathbb{A}^2 \setminus \{x = 0\}) \coprod \mathbb{A}^1$, let $Y = \mathbb{A}^1$, and let $f$ be projection onto the first coordinate on the first component and the identity on the second. Then every point of $X$ lives in a one-dimensional fiber except the origin of the second component.

-
@EvanJenkins Thank you for your answer, but there are things I do not understand. First of all, how can you make X into an algebraic set (i.e. the Spec of a finitely generated algebra) ? It seems to me you cannot because of the plane minus a point. Second, the fiber to which belongs the origin of the second component is $0\amalg (\mathbb{A}^1-0)$ which is one dimensional right ? – brunoh Jun 13 '13 at 8:33
@brunoh: It's not a plane minus a point, it's a plane minus a line, which answers both your questions. – Dan Petersen Jun 13 '13 at 14:16
@brunoh: Evan isn't removing just a point from $\mathbb A^2$ but the whole line $\{x=0\}$. I think this clarifies both of the points you raised. – Andreas Blass Jun 13 '13 at 14:19
No, the set of points of $X$ which live in a positive dimensional fiber is $\mathbb A^2 \setminus \{x=0\} \sqcup \mathbb A^1 \setminus \{0\}$, which is not closed in $\mathbb A^2 \setminus \{x=0\} \sqcup \mathbb A^1$. – Dan Petersen Jun 13 '13 at 14:52
@EvenJenkins Is there a counterexample in which X is irreducible? – Yang Zhou Oct 4 '13 at 5:11

Let $X = \mathbb A^2 \cup pt$, let $Y = \mathbb P^1$. Let $f(\mathbb A^2) = \mathbb A^1$ by projection, and let $f(pt)=\infty$. Then the generic fiber dimension is $1$, but at one point the fiber dimension is $0$.

-
Thank you for your your answer. But first of all, I wanted a counterexample using only affine varieties, not projective ones. Second, I fail to see why it is a counterexample, since the dimension function is still upper semicontinuous on $X$, right ? – brunoh Jun 12 '13 at 22:43
It is not upper semicontinuous because the fiber dimension at infinity is $0$, but on any neighborhood of $0$ all other fibers are $1$-dimensional. The dimension function is actually lower semicontinuous here. – Matt Jun 13 '13 at 0:11
Yes, good point. To solve this, connect the point to $\mathbb A^2$ using a line. – Will Sawin Jun 13 '13 at 0:13
Let $Y$ be irreducible of positive dimension, and $p$ a point in $Y$. Let $X = ((Y\setminus p) \times {\mathbb A}^1) \coprod \{q\}$, and $X\to Y$ be projection on the first component, and $q\mapsto p$ on the second. – Allen Knutson Jun 13 '13 at 0:22
@Allen_Knutson It seems to me the dimension function is still upper semicontinuous. I also found this counterexample but realized my mistake. I think to find a counterexample one has to find fibers in $X$ with irreducible components of different dimensions each one of them staying in different irreducible components of $X$. I failed to do that yet ... – brunoh Jun 13 '13 at 1:07

For what its worth, I can give you a non-Noetherian example, even with both schemes affine, irreducible (and of finite Krull dimension).

Set $R = k[x,y,x/y, x/y^2, x/y^3, ...]$ and $S = k[y]$. We have the obvious map $S \hookrightarrow R$ which induces $$X = \text{Spec }R \to Y = \text{Spec }S.$$ Now, away from the origin of $S$, $y$ is invertible and $R[y^{-1}] = k[x,y,y^{-1}]$ has all fibers with dimension $1$. On the other hand, once we set $y = 0$ in $R$, we notice that $x = (x/y) y$ is a multiple, as is $(x/y) = (x/y^2) y$, and so is $(x/y^n)$ for all $n$. This is already a maximal ideal, so the fiber over $y = 0$ is $0$-dimensional.

-
@Karl First of all, thank you very much for taking the time to notice it was probably not an obvious question. I like very much your example also and upvoted it. Nevertheless I cannot consider it as an the counter example I was looking for, because of the non-noetherianness of $X$. Since the result on the upper semicontinuity of fiber dimension is based on the the Generic Freeness Lemma, a key hypothesis is finite generation of the algebra involved, right ? That is why I need a counterexample using algebraic sets (SpecMax of finitely generated algebra over $k$). – brunoh Jun 13 '13 at 15:27
I agree, it doesn't answer your question but I still thought it was amusing. – Karl Schwede Jun 13 '13 at 15:46
The origin in closed in $X$, is it not? – Karl Schwede Jun 13 '13 at 15:49
@Karl Yep, it is. Thanks again. – brunoh Jun 13 '13 at 15:56