TITLE: What means this notion for scheme morphism?
QUESTION [6 upvotes]: I apologize for the naivity of this question but I am a beginner of algebraic geometry. Moreover, I realized that the initial question (quoted at the end) was not formulated very clearly. Hopefully, I can do better now involving the things learned from  Zhen Lin's comments.
One sometimes sees morphism of affine or projective schemes over a base field defined by some kind of coordinate notation, e.g.
\begin{equation}
f:\mathbb{A^2}\to \mathbb{A^3}, (a,b)\mapsto (a^2+b,b^2-2,4)\hspace{20pt} (*)
\end{equation}
but formally a morphism of schemes is a priori a pair consisting of a map $f:\mathbb{A^2}\to \mathbb{A^3}$ of topological spaces and a morphism $f^\sharp:\mathcal{O_{\mathbb{A^3}}}\to f_*\mathcal{O_{\mathbb{A^2}}}$ of structure sheaves.
As Zhen Lin explains in the comments, the map of topological spaces $f$ is determined by what is does on the maximal ideals of $\mathbb{A}^2$. If the base field is algebraically closed, these maximal ideals are of the form $(x_1-a,x_2-b)$ by the Hilbert nullstellensatz. Hence, in this case it suffices to specify an image for the pairs $(a,b)$ to get the topological morphism.
I have (still) two problems with this notion. 
Firstly, why exactly does such an assignment $(a,b)\mapsto (f_1(a,b),f_2(a,b),f_3(a,b))$ lead to a morphism of schemes and not only of topological spaces? I guess, the thing is that the $f_i$ are given by polynomials and not by arbitrary functions $k^2\to k$. Let me please look at a concrete example to see how this works.
Consider $f:Spec~k[x]\to Spec~k[y]$ and the assignment $a\mapsto a^2-1$. To construct a map of the structure sheaves, I have to build a $k$-algebra map $\tilde f:k[y]\to k[x]$ such that the pre-image of the ideal $(x-a)$ is the ideal $(y-(a^2-1))$. Is it correct to set $y\mapsto a^2-a-1$ and is it obvious that one finds such a $k$-algebra morphism for the ''higher dimensional'' analogues like $\bar f:k[y_1,y_2,y_3]\to k[x_1,x_2]$?
Secondly, when the base field is not algebraically closed, why does it suffice to specify an image only for the pairs $(a,b)$, too? Maybe, this is because for the special case of the ring $k[x_1,x_2]$, the maximal ideals are still precisely $(x_1-a,x_2-b)$, is this true?

This was the initial question to which  Zhen Lin's comments refer to.

What is the very formal legitimation of defining a morphism $f:X\to Y$
  of affine or projective schemes by a kind of coordinate notion (explained below)
  instead of applying the spectrum functor to a ring morphism (in the
  other direction) or instead of working with the prime ideals?

REPLY [3 votes]: Allow me to focus on (irreducible) affine varieties over an algebraically closed field $k$, for simplicity. Let $X$ and $Y$ be two such: that is to say, $X$ and $Y$ are integral affine schemes of finite type over $k$ (or $\operatorname{Spec} k$, if we're being pedantic), with affine coordinate rings $A(X)$ and $A(Y)$ respectively. I write $X(k)$ and $Y(k)$ for the subspace of $k$-valued points of $X$ and $Y$; since $k$ is algebraically closed, every closed point of $X$ and $Y$ are $k$-valued points. Note that $X(k)$ and $Y(k)$ are irreducible affine varieties in the classical sense.
I claim the following are true:

If $\phi : X(k) \to Y(k)$ is a morphism of varieties in the classical sense, then the map
$$f \mapsto f \circ \phi$$
is a $k$-algebra homomorpism $\phi^* : A(Y) \to A(X)$, when elements of $A(Y)$ are regarded as genuine functions $Y(k) \to k$. On the other hand, if $\phi^* : A(Y) \to A(X)$ is a $k$-algebra homomorphism, there is a map $\phi : X(k) \to Y(k)$ so that $\phi^*$ is of the above form. (Simply choose generators of $A(Y)$ and $A(X)$ and use them to embed $Y$ and $X$ in some affine space $k^n$.) In other words, there is a natural bijection
$$\textrm{Hom}(X, Y) \cong \textrm{Hom}(A(Y), A(X))$$
where the LHS is the set of morphisms $X \to Y$ and the RHS is the set of $k$-algebra homomorphisms $A(Y) \to A(X)$.
This is explained in detail in Hartshorne's Algebraic Geometry [Ch. I, §3]. This is the only part where the hypothesis that $k$ is algebraically closed is truly indispensable.
If $A$ and $B$ are any two (commutative) rings, then there is a natural bijection
$$\textrm{Hom}(A, B) \cong \textrm{Hom}(\operatorname{Spec} B, \operatorname{Spec} A)$$
where the LHS is the set of ring homomorphisms $A \to B$ and the RHS is the set of scheme morphisms $\operatorname{Spec} B \to \operatorname{Spec} A$.
This is proven in Hartshorne [Ch. II, §2]. For our purposes, this implies that any $k$-algebra homomorphism $\phi^* : A(Y) \to A(X)$ gives rise to a unique morphism of $k$-schemes $\phi : X \to Y$ such that $\phi^\sharp_Y : \mathscr{O}_Y(Y) \to \phi_* \mathscr{O}_X(Y)$ is exactly the map $\phi^*$, once we have identified $\mathscr{O}_Y(Y) = A(Y)$ and $\phi_* \mathscr{O}_X(Y) = A(X)$. Here we may drop the hypothesis that $k$ is algebraically closed.
If $\phi : X \to Y$ is a morphism of $k$-schemes, then $\phi |_{X(k)}$ has image contained in $Y(k)$. Moreover, if $\psi : X \to Y$ is another, then $\phi = \psi$ if and only if $\phi |_{X(k)} = \psi |_{Y(k)}$.
The first claim is a straightforward consequence of the fact that a $k$-valued point of $X$ is exactly the same thing as a morphism of $k$-schemes $\operatorname{Spec} k \to X$. The second claim just comes from putting together the natural bijections of (1) and (2) and recognising that this is simply the correspondence between $\phi$ and $\phi |_{X(k)}$.

Here is a modified form of (3). Let $A$ and $B$ be $k$-algebras of finite type, where $k$ is no longer assumed to be algebraically closed. It is a fact of commutative algebra that a $k$-algebra of finite type is a Jacobson ring. Let $X = \operatorname{Spec} A$ and $Y = \operatorname{Spec} B$, and let $X_m = \operatorname{MaxSpec} A$ and $Y_m = \operatorname{MaxSpec} B$. I claim that if $\phi, \psi : X \to Y$ are two morphisms of $k$-schemes, then $\phi = \psi$ (as maps of topological spaces) if and only if $\phi |_{X_m} = \psi |_{Y_m}$ (as maps of topological spaces).
Indeed, by the definition of Jacobson ring, if $\mathfrak{p} \in X$, then
$$\mathfrak{p} = \bigcap_{\mathfrak{m} \in X_m, \mathfrak{p} \subseteq \mathfrak{m}} \mathfrak{m}$$
and by the natural bijection in (2) above,
$$\phi(\mathfrak{p}) = {\phi^*}^{-1} \mathfrak{p}$$
where $\phi^* : A \to B$ is the $k$-algebra homomorphism corresponding to $\phi : X \to Y$. But it is a fact of set theory that
$${\phi^*}^{-1} \bigcap_{\mathfrak{m}} \mathfrak{m} = \bigcap_{\mathfrak{m}} {\phi^*}^{-1} \mathfrak{m}$$
and our hypothesis is that $\phi (\mathfrak{m}) = \psi (\mathfrak{m})$, so indeed $\phi = \psi$, at least as maps of topological spaces.
Unfortunately, it need not be true that $\phi = \psi$ as morphisms of $k$-schemes. For a simple example, consider $A = k[t]/(t^2)$ and $B = k[x, y]/(x^2, x y, y^2)$. It is clear that $\operatorname{Spec} A$ and $\operatorname{Spec} B$ are both single points, but there are plenty of $k$-morphisms $\operatorname{Spec} A \to \operatorname{Spec} B$: in fact, at least a whole $k^2$ worth, given by
$$t \mapsto a x + b y$$
where $(a, b) \in k^2$. One may object that $A$ and $B$ are not integral domains, but it turns out that this hypothesis is not sufficient when $k$ is not algebraically closed. For example, let $K$ be any finite field extension of $k$ with a non-trivial $k$-automorphism $\sigma : K \to K$; as usual $\operatorname{Spec} K$ is just a point but $\sigma$ gives rise to a non-trivial $k$-morphism $\operatorname{Spec} K \to \operatorname{Spec} K$.
Fortunately, there is still a way to rescue the situation: in addition to assuming that $A$ and $B$ are integral domains, we also assume $\phi^\sharp$ and $\psi^\sharp$ agree on the stalks of $\mathscr{O}_Y$ over the closed points. This lets us embed $A$ and $B$ into their respective fields of fractions $K(A)$ and $K(B)$, and it follows that $\phi^\sharp$ and $\psi^\sharp$ must agree on the stalks of $\mathscr{O}_Y$ over the generic points in addition to the closed points: after all, if $\mathfrak{p} \subseteq \mathfrak{m}$ then $B_\mathfrak{p} \subseteq B_\mathfrak{m}$ (considered as subrings of $K(B)$). This is enough to conclude that $\phi^\sharp = \psi^\sharp$ as maps of sheaves, and so $\phi = \psi$ as morphisms of schemes.