Level sets and quotients on affine varieties Let $X \subset \mathbb A^n$ be an affine variety, say the zero set of polynomials $P_1,\dots, P_m$. Now, for an arbitrary polynomial $Q$, we can introduce an equivalence relation on $X$: two points $x_1,x_2\in X$ are equivalent (write $x_1\sim x_2$) if $$Q(x_1) = Q(x_2)$$

Question: In what conditions is the quotient $X/\sim$ still a variety?

For example, let's say $X=\mathbb A^2$ and $Q=x_1$ then $X/\sim$ is isomorphic to $ \mathbb A^1$. But is there a more general theory about this story?
 A: I can positively answer your question when the base field $k$ is algebraically closed. If this assumption is unacceptable for you, let me know - but I fear the answer may be significantly more complex and potentially negative. That's just a feeling, though.
Since $Q$ defines a regular function on your variety, it can be seen as a morphism $q:X\to\Bbb A^1$. You are now looking for a way to give the set of fibers of this morphism the structure of an affine variety. Now, you already have a pretty good candidate for that variety: The image $Y\subseteq\Bbb A^1$ of $q$. 
It is known that the image $Y$ of $q$ is a constructible set, i.e. it contains an open and dense subset $U$ of its closure. We are lucky that the Zariski topology of $\Bbb A^1$ is relatively easy when $k$ is algebraically closed: Every finite set is closed, and that's all of them (except for $\Bbb A^1$ itself, of course). Now from this we can conclude that the image of $q$ is open or closed: If the dimension of $U$ is zero, it must be a discrete set, hence $Y=U$, and it is closed. Otherwise, the dimension of $U$ is equal to one and it can only exclude a finite number of points from $\Bbb A^1$. In that case, $Y$ as well can only exclude a finite number of points from $\Bbb A^1$ and must be open. Of course, it could happen that $Y=\Bbb A^1$ in this case which would mean that $Y$ is open and closed.
Now, all the open subsets of $\Bbb A^1$ are also affine because when $Y=\Bbb A^1 \setminus \{ a_1, \ldots, a_n \}$ then we may take $f(t):=\prod_{i=1}^n (t-a_i)$ and observe that $Y=D(f)$, hence $Y=\{ (x,y) ~\mid~ f(x)\cdot y -1 = 0 \}\subseteq\Bbb A^2$ is a realization of $Y$ as a closed subvariety of $\Bbb A^2$.
In summary, the image $Y:=q(X)$ can always be given the structure of an affine variety and this affine variety models your quotient $X/\sim$.
