Why does the diagonal morphism of a map between affine schemes correspond to the following morphism of rings? Suppose I have a morphism of affine schemes $(f, f^\sharp) : \operatorname{Spec} A \to \operatorname{Spec} B$, then my question is - why does the diagonal morphism $(\Delta_f, \Delta_f^\sharp) : \operatorname{Spec} A \to \operatorname{Spec} A \times_{\operatorname{Spec} B} \operatorname{Spec} A = \operatorname{Spec} (A \otimes_B A)$ correspond the following morphism of rings $\phi : A \otimes_B A \to A$ given by $\phi(a \otimes a') = a\cdot a'$?

This was my attempt to try and asnwer that.
I know that we have the result that $$\operatorname{Hom}_{\textsf{Sch}}\left(\operatorname{Spec} A, \operatorname{Spec} (A \otimes_B A)\right) \cong \operatorname{Hom}_{\textsf{Ring}}(A \otimes_B A, A)$$
with the bijection given by $(g, g^\sharp) \mapsto g^\sharp_{\operatorname{Spec} A}$ so one possible way to show that the diagonal morphism does correspond to the claimed morphism of rings would be to show that ${\Delta_f}_{_{\operatorname{Spec} A}}^\sharp = \phi$ but I was unable to actually verify this.
Another thing I was thinking of was the following. If I let $(p_1, p_1^\sharp) : \operatorname{Spec} (A \otimes_B A) \to \operatorname{Spec} A$ denote the projection map that comes with the fibered product, then we know that $p_1 \circ \Delta_f = 1_{\operatorname{Spec} A}$ the identity map on $\operatorname{Spec} A$. Now I guess, (but I cannot show), that the morphism $(p_1, p_1^\sharp)$ corresponds to the morphism of rings $\iota : A \to A \otimes_B A$ given by $\iota(a) = a \otimes_B 1_A$, because then we see that $\phi \circ \iota = 1_A$ the identity map on $A$.
If it were the case that the morphism $(p_1, p_1^\sharp)$ corresponds to $\iota$, then since taking global sections is a contravariant functor (and really what that bijection above is) I would see that ${\Delta_f}_{_{\operatorname{Spec} A}}^\sharp\circ \iota = 1_A$ as well, but this isn't enough to prove that ${\Delta_f}_{_{\operatorname{Spec} A}}^\sharp = \phi$.
So I have in addition two further follow up questions in addition to the original one:

*

*How does one prove that the morphism $(p_1, p_1^\sharp)$ corresponds to $\iota$?

*Is there a more efficient way to prove that a morphism of schemes corresponds to a morphism of rings?


If it is relevant, you can assume that the construction of the fibered product I am working with is the same one given in Theorem 3.3 in Hartshorne's book.
 A: Note that $\Delta : \operatorname{Spec}(A) \to \operatorname{Spec}(A \otimes_B A)$ corresponds to a map $\Delta^*: A \otimes_B A \to A$ as you say. The map $\Delta$ is defined via the universal property of the fibre product with $(\mathrm{id}_{\operatorname{Spec}(A)}, \mathrm{id}_{\operatorname{Spec}(A)})$, so $\Delta^*$ is given (recall that the correspondence is natural, it is an equivalence of categories) by $(\mathrm{id}_A, \mathrm{id}_A)$ via the universal property of pushouts. In particular, it is the unique $B$-algebra homomorphism such that
$$ a \otimes 1 \mapsto a \quad\text{and} \quad 1 \otimes a \mapsto a$$ for every $a \in A$. In other words, $\Delta^*: a \otimes a' \mapsto aa'$.
The important part here is that the correspondence $$\operatorname{Hom}_{\mathbf{AffSch}}(\operatorname{Spec}(A), \operatorname{Spec}(B)) \cong \operatorname{Hom}_{\mathbf{Ring}}(B,A)$$ is not only a bijection but rather a natural bijection, it comes from an equivalence of categories $\mathbf{AffSch} \simeq \mathbf{Ring}^{\mathrm{op}}$. It really preserves diagrams! That should answer your first additional question. Unfortunately, this is often not stressed enough. In most textbooks I only see a proof that there is a bijection whereas the naturality is extremely important. It was definitely one part that wasn't entirely clear to me until I realized that the functoriality is an essential part of this assertion and is used over and over again.
I do not know of a more efficient way to prove it than to define the mutually inverse maps and checking that they define an equivalence of categories by hand. I haven't thought about it but you can probably also check that there is a fully faithful, essentially surjective functor $\mathbf{Ring}^{\mathrm{op}} \to \mathbf{AffSch}$, but the first approach should still be the preferred approach to understand both maps in the correspondence.
A: Question: "How does one prove that the morphism (p1,p♯1) corresponds to ι?"
Answer:  By the universal property of the fiber product, it follows the diagonal map $\Delta: X\rightarrow X\times_S X$ at the level of schemes, is the unique map commuting with the projection maps $p,q:X\times_S X \rightarrow X$. The multiplication map has the same property: The map $m:A\otimes_k A\rightarrow A$ defined by $m(a\otimes b):=ab$ is the unique map commuting with the maps $p,q:A \rightarrow A\otimes_k A$ defined by $p(a):=a\otimes 1, q(a):=1\otimes a$. Hence it follows the maps $\Delta$ and $m$ determine each other when $X:=Spec(A)$.
