very basic question about definition of constant group scheme Let $M$ be a finite set, and give it the discrete topology. Let $R$ be a commutative ring with unity. We have a ring $\mathbb{Z}^M = \prod_{m \in M}\mathbb{Z}$. Why is the set of ring homomorphisms $$\text{Hom}(\mathbb{Z}^M, R)$$ in bijection with the set
$$\text{Hom}_{\text{continuous}}(\text{Spec } R, M)$$
of continous maps $\text{Spec }R \to M$? Since $M$ has the discrete topology, this is the same as locally constant maps.
Also, I believe ${\text{Hom}(\mathbb{Z}^M, R) = R^M}$. (Edit: no, this claim is not true).
The motivation for my question comes from the constant group scheme $\mathbb{M}$ (over $\mathbb{Z}$) associated to an abstract group $M$. Then as a scheme $\mathbb{M}=\coprod_{m \in M}\text{Spec }\mathbb{Z} = \text{Spec }\mathbb{Z}^M$. Its functor of points (on say Zariski site of affine schemes), evaluated on $\text{Spec }R$, on the one hand is the set of maps $\text{Spec }R  \to \mathbb{M}$ and on the other hand is (claimed/defined) in many places to be given by sending $\text{Spec } R$ to the set/group of locally constant functions $\text{Spec }R \to M$. I see this claimed everywhere (e.g. https://stacks.math.columbia.edu/tag/03YW ) but never proved so it may be very obvious but I have never understood it. If you can provide a reference for where this is proved that is also fine.
 A: More generally, let $R_i, i \in I$ be a finite collection of commutative rings and let $S$ be a commutative ring. Check that $\text{Hom}(\prod R_i, S)$ can naturally be identified with the data of

*

*a decomposition $S = \prod S_i$ of $S$ into a product over the same index set, and

*a tuple $f_i : R_i \to S_i$ of ring homomorphisms.

(There are several ways to think about this. A hint is to examine the images of the primitive idempotents $e_i = (0, \dots 1, \dots 0)$, where the $1$ occurs in the $i^{th}$ place.)
When each $r_i = \mathbb{Z}$ the ring homomorphisms $f_i$ are unique so the data is the data of a decomposition of $S$ into a product over $I$. Geometrically this is the same thing as a decomposition of $\text{Spec } S$ into $I$ disjoint components, which is in turn the same thing as a continuous (equivalently, locally constant) function $\text{Spec } S \to I$.
The case $|I| = 2$ is particularly easy to think about because we only need to track one nontrivial idempotent. $\mathbb{Z} \times \mathbb{Z} \cong \mathbb{Z}[e]/(e^2 - e)$ is the free commutative ring on an idempotent, so
$$\text{Hom}(\mathbb{Z} \times \mathbb{Z}, S) \cong \{ e \in S : e^2 = e \}$$
is precisely the set of idempotents in $S$, which you can check is in natural bijection with the set of ways to decompose $\text{Spec } S$ into two disjoint components.
Geometrically, the general claim is that a morphism $\text{Spec } S \to \bigsqcup \text{Spec } R_i$ disconnects $\text{Spec } S$ into $I$ components, the pullbacks of the morphism along the inclusions of each $\text{Spec } R_i$; more formally, the slice category over $\bigsqcup \text{Spec } R_i$ is naturally isomorphic to the product of the slice categories over each $\text{Spec } R_i$, which is one of the axioms defining an extensive category. This means intuitively that coproducts behave "disjointly," the way coproducts of sets or spaces do (but not the way coproducts of, say, groups do).
It's very false that $\text{Hom}(\mathbb{Z}^I, S) = S^I$ (although it's true that $\mathbb{Z}^I \otimes S \cong S^I$). The LHS is a set and the RHS is a ring, and the LHS is covariant in $I$ while the RHS is contravariant.
Another way to think about this result is to first check that $\text{Mod}(\prod R_i) \cong \prod \text{Mod}(R_i)$; that is, the category of modules over a finite product breaks up into a finite product of module categories, and the equivalence is given very explicitly via the primitive idempotents above. This is even an equivalence of symmetric monoidal categories, and so induces an equivalence from the category of commutative $\prod R_i$-algebras to the product of categories of commutative $R_i$-algebras, and the equivalence is the identification above.

Edit: Here's a cute corollary. Consider morphisms $\text{Hom}(R^I, R^J)$ where $I, J$ are finite sets and $R$ is a ring with no nontrivial endomorphisms (e.g. $\mathbb{Z}$, any localization of $\mathbb{Z}$, any prime field, but also weirder examples like $\mathbb{R}$). We get that such maps correspond exactly to morphisms $J \to I$ of finite sets, hence:

Claim: Let $R$ be a ring with no nontrivial endomorphisms. Then $\text{FinSet} \ni I \mapsto \text{Spec } R^I \in \text{Aff}$ is a fully faithful embedding.

