TITLE: Locus of points in which two morphisms of schemes coincide
QUESTION [6 upvotes]: This question is somewhat related to a previous question of mine, but appeared in a different context.
Suppose given two morphisms of $S$-schemes $f,g:X \to Y$. Intuitively, I am interested on the locus of points of $X$ in which these two morphisms coincide. A schematic approach to that, would be to consider $Z$ as the pullback of the diagonal $\Delta: Y \to Y\times_S Y$ by the morphism $(f,g): X \to Y\times_S Y$.
Then, for example, if $Y\to S$ is separated ("Hausdorff"), then $Z \to X$ is a closed immersion, which makes sense.
Also, the composition of $Z \to X$ with $f$ and $g$ are the same (by the commutativity of the cartesian diagram defining $Z$). Hence, I would expect that the scheme $Z$ is what I'm searching.
But one could also take a naive, set-theoretic, approach (which we know is usually inappropriate when dealing with schemes) and define the set $A=\{x\in X \mid f(x)=g(x)\}$.
My question is: what is the relation between $Z$ and $A$?
The most strange thing is that $A$ can be empty, but $Z$ seems to be always well defined. In this case (when $A$ is empty), how this information is "captured" in the scheme $Z$?

REPLY [8 votes]: This is not really a problem with morphisms $f,g$ but the points of the diagonal $\Delta:=\Delta_{Y/S}$ of $Y\to S$. Denote by 
$$\Delta_{st}=\{ z\in Y\times_S Y \mid p(z)=q(z) \}$$ 
where $p, q$ denote the projections to $Y$. Then the scheme-theoretical locus where $f=g$ is $h^{-1}(\Delta)$ (with $h=(f,g) : X\to Y\times_S Y$) while $A=h^{-1}(\Delta_{st})$. 
So the issue is the comparison of the scheme-theoretical diagonal $\Delta$ with the set-theoretical diagonal $\Delta_{st}$. We have obviously $\Delta\subseteq \Delta_{st}$ as sets. But the inverse inclusion doesn't hold in general. A simple example is when $S, Y$ are affine defined respectively by $\mathbb R$ and $\mathbb C$. Then $Y\times_S Y$ physically has $4$ points, all in $\Delta_{st}$, but $\Delta$ has only one point (image of $S$ by the diagonal map).