# on what morphism of schemes look like locally

I am working on the following exercise (Exercise 6.3.C. on Ravi Vakil's online notes), which has two parts:

Given a morphism of schemes $\pi: X \rightarrow Y$, show that if Spec $A$ is an affine open subset of $X$ and Spec $B$, an affine open subset of Y, such that $\pi($ Spec $A) \subseteq$ Spec $B$, then the induced morphism on the ringed space is a morphism of affine schemes.

Show that it suffices to check on a set (Spec $A_i$, Spec $B_i$) where the Spec $A_i$ form an open cover of $X$.

I would appreciate any help with the first part. I am also having trouble understanding exactly what it is being asked for the second part. Thank you for your time.

The first part of the question seems straightforward. If $\pi : X \to Y$ is a morphism of schemes, then by definition it is a morphism of the underlying locally ringed spaces. If $\text{Spec }A \subset X$ and $\text{Spec B} \subset Y$ are affine opens with $\pi(\text{Spec }A) \subset \text{Spec }B$, then the restriction of $\pi$ to $\text{Spec }A$ gives a map of locally ringed spaces, and hence a map of schemes, to $\text{Spec }B$. To see why this is the case, note that restriction of $\pi$ is necessarily a map of ringed spaces, and the condition that a map induce morphisms of local rings on stalks is a "local" condition. Finally, to check that the resulting map of schemes $\text{Spec }A \to \text{Spec }B$ is a map of affine schemes, one needs to show that it is induced from a ring map $B \to A$. But this is precisely what the "Key Proposition" on the previous page says!
The second part of the question is somewhat unclear, but I believe Vakil is trying to say the following. Suppose one has a morphism $\pi : X \to Y$ of ringed spaces such that there exists a cover of $X$ by affine open subschemes $\text{Spec } A_i$ and a cover of $Y$ by affine open subschemes $\text{Spec } B_i$ with the property that $\pi(\text{Spec } A_i) \subset \text{Spec } B_i$ for each $i$. Then $\pi$ is a map of schemes if and only if the restriction of $\pi$ to each $\text{Spec }A_i$ gives a morphism of affine schemes from $\text{Spec }A_i$ to $\text{Spec } B_i$.
This doesn't make a ton of sense to me. The phrasing kind of suggests that one has to prove that a morphism of locally ringed spaces between affine schemes is a morphism of affine schemes," but affine schemes are locally ringed spaces, and a morphism between them is just a morphism of locally ringed spaces, so there is nothing like this to show. The intended content seems to be (a particular case of) the following very general statement: if $f:X\to Y$ is a map of locally ringed spaces and you have opens $i:U\subseteq X$ and $j:V\subseteq Y$ such that $f(U)\subseteq V$, then there is a unique morphism $g:U\to V$ such that $j\circ g=f\circ i$, where $U$ and $V$ are regarded as locally ringed spaces with the sheaves of rings obtained by restriction from $X$ and $Y$, respectively (I unfortunately don't know how to make commutative diagrams on MSE but this would be much better with a commutative diagram instead of the equality of compositions).
If $X$ and $Y$ happen to be schemes and $U$ and $V$ happen to be affine opens, then certainly the induced map $g:U\to V$ is a morphism of affine schemes, because, as recalled above, by definition this is just a morphism of locally ringed spaces.
I think something useful (at least psychologically reassuring to someone like me) which could be added to the exercise is that there are canonical isomorphisms $c_U:U\simeq\mathrm{Spec}(\mathscr{O}_X(U))$ and likewise $c_V:V\simeq\mathrm{Spec}(\mathscr{O}_Y(V))$ (this follows e.g. from my answer here: on the adjointness of the global section functor and the Spec functor), and under these identifications, the map $g:U\to V$ becomes identified with the map $\mathrm{Spec}(\mathscr{O}_X(U))\to\mathrm{Spec}(\mathscr{O}_Y(V))$ induced in the usual way by the ring map $\mathscr{O}_Y(V)\xrightarrow{f^\sharp_V}\mathscr{O}_X(f^{-1}(V))\xrightarrow{\mathrm{res}}\mathscr{O}_X(U)$, in the sense that, if we call this ring map $\varphi$, we have $\mathrm{Spec}(\varphi)\circ c_U=c_V\circ g$. So you can truly (canonically!) identify $g:U\to V$ with the map of spectra of coordinate rings induced by the obvious ring map. In this way you are on rigorous ground when looking at the "local structure" of a morphism within the context of spectra of rings and their functoriality.
I was bothered when I first encountered scheme theory by the following questions: do we have to keep track of the "identifications" of "affine opens" with the spectra of their coordinate rings? Are their potentially many such identifications? But the (pleasant) reality is that affineness can be characterized intrinsically. For any locally ringed space whatsoever, the canonical morphism (again coming from the post I linked to above) $X\to\mathrm{Spec}(\mathscr{O}_X(X))$, which can be characterized as being the unique morphism of locally ringed spaces inducing the identity on global sections, is an isomorphism if and only if $X$ is "an affine scheme" in the sense of admitting some isomorphism to the spectrum of a ring. Of course the pros probably don't think about this much, but some of them, maybe, discovered this fact early in their careers, and perhaps it was beneficial to their general psychological and intellectual well-being. It was for me.