Geometric intuition for the Stein factorization theorem?
What is the intuition behind the Stein Factorization Theorem? I understand that it was originally a theorem in several complex variables, so I was wondering if there's some geometric explanation that isn't as opaque as the statement in EGA.
In particular, why would one expect this theorem to be true? Are there any suggestive examples or heuristics? For example, when I think about the upper semi-continuity of dimension, I always have in the back of my head the picture of a blow up.
I've reorganized this answer to highlight the intuition in the complex analytic case, and how the difficulties are in different places compared to the algebraic case.
The thing that makes Stein factorization "unintuitive," I think, is the following corollary (III.11.3 in Hartshorne) to the Theorem on Formal Functions:
Zariski's Connectedness Theorem. If $f\colon X \to Y$ is a proper map of complex spaces, and $\mathcal{O}_Y \to f_*\mathcal{O}_X$ is an isomorphism, then the fibres $f^{-1}(y)$ are connected for all $y \in Y$.
The reason we even need formal functions in the algebraic proof of this theorem is that the Zariski topology is too coarse, and so we can't use actual open sets to construct a section of $\mathcal{O}_X$ that doesn't push forward to a section on $\mathcal{O}_Y$. On the other hand, the topology for complex analytic spaces (basically, ringed spaces that are locally isomorphic to zero sets of sets of holomorphic functions in a domain in $\mathbf{C}^n$) is fine enough that we can prove this quite easily:
Proof. First, $f$ is surjective, and so $f^{-1}(y)$ is non-empty for all $y \in Y$. Now suppose $f^{-1}(y)$ is disconnected; then, there exists an open neighborhood $U$ of $f^{-1}(y)$ which is disconnected. By shrinking the neighborhood if necessary, we can assume $U = U_1 \cup U_2$ has the form $f^{-1}(V)$ for $V$ a neighborhood of $y$ in $Y$ (by the closedness of $f$; see, e.g., [Grauert–Remmert Lem. 2.3.1]), and that $U_1 \cap U_2 = \emptyset$. The section of $\mathcal{O}_X$ which is $1$ on $U_1$ and $0$ on $U_2$ gives a section $\varphi$ of $\mathcal{O}_Y$ on $V$ by the isomorphism $\mathcal{O}_Y \overset{\sim}{\to} f_*\mathcal{O}_X$; this is a contradiction since $\varphi(y) = 0$ and $\varphi(y) = 1$. $\blacksquare$
Provided this fact, the subtleties in the complex analytic case are actually things that in algebraic geometry, we often take for granted. The two central results are:
Grauert's Direct Image theorem [Grauert–Remmert, Thm. 10.4.6]. If $f\colon X \to Y$ is proper, and $\mathscr{F}$ is a coherent $\mathcal{O}_X$-module, then $f_*\mathscr{F}$ is a coherent $\mathcal{O}_Y$-module.
Note this holds for higher direct images as well, but the point is that the proof is surprisingly difficult. On the other hand, for Hartshorne (in the projective case) this follows (in Cor. II.5.20) by the fact that (in the notherian case) the push-forward of a quasi-coherent sheaf is quasi-coherent, and the module of global sections on a projective scheme is finitely-generated over the base ring.
The other central result is:
Remmert's Proper Mapping Theorem [Grauert–Remmert, Thm. 10.6.1]. If $f\colon X \to Y$is proper, then the image set $f(X)$ is an analytic subset of $Y$.
This is a direct corollary of the Direct Image theorem (since $f(X) = \operatorname{Supp} f_*(\mathcal{O}_X)$ is analytic), but can be proved independently using the extension theorem of Remmert–Stein. In any case, the proofs seem to be much more subtle than in Hartshorne, Exc. II.4.4, where you prove the same result in the algebraic context.
With the facts above you can prove the Stein factorization theorem in exactly the same way as in, say, Hartshorne, Cor. III.11.5. What is nice, though, is that the intuition that the Stein factorization first contracts connected components of fibers to points, and then gives a finite cover of your target, is actually true.
So suppose you have a proper morphism $f\colon X \to Y$ of complex spaces. We define a level set of $f$ to be any connected component of a fibre $f^{-1}(y)$ of $y \in Y$. Denote the set of level sets of $f$ by $Y'$, and let $p \colon Y' \to Y$ be the natural map taking a level set in $f^{-1}(y)$ to $y$.
Now assign to each $x \in X$ the connected component of $f^{-1}(f(x))$ which contains $x$, and call this map $f'\colon X \to Y'$. We then have the factorization $$X \overset{f'}{\longrightarrow} Y' \overset{p}{\longrightarrow} Y$$ The map $f'$ is surjective, and so we can endow $Y'$ with the quotient topology. Then, $f'$ is proper, and $p$ is a finite continuous map (it has finite fibers and is proper). Now give $Y'$ the structure of a ringed space by letting $f_*'(\mathcal{O}_X)$ be its structure sheaf. In this setting, we have the following
Theorem [Bănică–Stănăşilă, Thm. III.2.12]. The ringed space $(Y',f_*'(\mathcal{O}_X)$ is a complex space, and is isomorphic to $Z := \operatorname{\mathbf{Spec}} f_*\mathcal{O}_X$.
In the reduced case, unraveling the definition of $\operatorname{\mathbf{Spec}} f_*\mathcal{O}_X$ gives an even more explicit description of the factorization as follows, following [Bell–Narasimhan, Thm. 2.10].
First, since $f_*(\mathcal{O}_X)$ is coherent as an $\mathcal{O}_Y$-module by Grauert's Direct Image theorem, for any $y \in Y$ there is a neighborhood $U$ such that $f_*(\mathcal{O}_X)$ is generated by holomorphic functions $h_1,\ldots,h_k$ over $\mathcal{O}_Y$. Then, the map $g_U\colon f^{-1}(U) \to U \times \mathbf{C}^k$ where $x \mapsto (f(x),h_1(x),\ldots,h_k(x))$ is proper and its image is an analytic subset $Z_U$ by Remmert's Proper Mapping theorem. The $h_j$ are constant on connected components of fibres of $f$ by the maximum modulus principle, and so the restriction of the projection $U \times \mathbf{C}^k \to U$ to $Z_U$ is finite. You can then glue these $Z_U$ together to get the space $Z$.