Hartogs Theorem says every function whose undefined locus is of codim 2 can be extend to the whole domain. I saw people saying this corresponds to the (S2) property of a ring. But I can't see why this is true. Can anybody explain this or give a heuristic argument?

Let $\mathscr F$ be a coherent sheaf on a noetherian scheme $X$ and assume that ${\rm supp}\mathscr F=X$. Let $Z\subset X$ be a subscheme of codimension at least $2$ and $U=X\setminus Z$. Let $\iota:U\hookrightarrow X$ denote the natural embedding and assume that $\mathcal F_x$ is $S_2$ for every $x\in Z$. Now the $S_2$ assumption implies that $$ \mathscr H^0_Z(X,\mathscr F)= \mathscr H^1_Z(X,\mathscr F)=0 $$ and the Hartog type extension is equivalent to $$ \iota_*\iota^*\mathscr F\simeq \mathscr F. $$ Finally one has the exact sequence $$ \mathscr H^0_Z(X,\mathscr F) \to \mathscr F\to \iota_*\iota^*\mathscr F \to \mathscr H^1_Z(X,\mathscr F).$$ [See also this MO answer] 


This is an answer to a question of Karl in the comments to my first answer to this question. [EDIT: The following is a minimally simplified version of Proposition 3.3 of HasettKovács04.] Theorem. Let $X$ be a noetherian scheme, $r\in\mathbb N$, $Z\subseteq X$ a subscheme such that ${\rm codim}_XZ\geq r$, and $\mathscr F$ a coherent $\mathscr O_X$module such that ${\rm supp}\\,\mathscr F=X$ and $\mathscr F_x$ is $S_r$ for every $x\in Z$. Then $$ \mathscr H^i_Z(X,\mathscr F)=0\quad\text{for $i=0,\ldots,r1$}. $$ Proof. Let $x\in Z$ and notice that we have the following equality of functors: $$ H^0_x = H^0_x\circ \mathscr H^0_Z $$ which induces a Grothendieck spectral sequence $$ E^{p,q}_2= H^p_x \circ \mathscr H^q_Z \Rightarrow H^{p+q}_x. $$ Now prove the statement using induction on $i$. Suppose $\exists\\,\sigma\in\mathscr H^0_Z(X,\mathcal F)$, $\sigma\neq 0$. Let $x\in Z$ be the general point of an irreducible component of ${\rm supp}\\,\sigma$. Then $H^0_x(X, \mathscr H^0_Z(X,\mathscr F))\neq 0$ and hence $H^0_x(X,\mathscr F)\neq 0$. But this contradicts the assumption that $\mathscr F_x$ is $S_r$. Now suppose that we already know that $$ \mathcal H^i_Z(X,\mathscr F)=0\quad\text{for $i=0,\ldots,k1$} $$ for some $k<r$ and assume that $\mathscr H^k_Z(X,\mathscr F)\neq 0$. By the same argument as above we find a point such that $E^{0,k}_2=H^0_x(X,\mathscr H^k_Z(X,\mathscr F))\neq 0$. Since it is an $E^{0,k}$ term there are no differentials (including later pages of the spectral sequence) mapping to this term and all subsequent differentials mapping from this term map to something of the form $E^{p,q}$ with $0\leq q\leq k1$. However those latter kind are zero by the inductive hypothesis. Therefore this implies that then $H^k_x(X,\mathscr F)\neq 0$ which is again a contradiction to the assumption that $\mathscr F_x$ is $S_r$. Q.E.D. See also this MO answer 


Here's a somewhat more elementary argument that (S2) implies the Hartogs condition. More precisely, I will show that if $X$ is an (S2) noetherian scheme, then any rational function defined outside a closed subset of codimension two can be extended to the whole domain. (This extension is unique by definition of a rational function.) Assume, by way of contradiction, that $X$ is an (S2) noetherian scheme and $f$ is a rational function on $X$ that is defined outside a closed set of codimension at least two, but cannot be extended to the whole domain. Let $\mathscr{I}$ be the ideal of denominators of $f$; in other words, over an open affine $\operatorname{Spec} A$, $$I = \{g \in A \mid g f \in A\}.$$ This is welldefined as a sheaf since the ideal of denominators is preserved under flat pullback (and in particular, localization); see this mathoverflow question. If $g \in A$ is a nonzerodivisor, then $g \in I$ if and only if $f = a / g$ for some $a \in A$, hence the name "ideal of denominators." One can check that the closed subscheme $Z \subset X$ corresponding to $\mathscr{I}$ is, settheoretically, the "indeterminacy locus of $f$": the smallest closed subset such that $f$ is defined over $X \smallsetminus Z$. By hypothesis, $f$ can be defined outside a closed subset of codimension two, so $\operatorname{codim} Z \geq 2$. Equivalently, whenever $W$ is an irreducible component of $Z$, then the local ring $\mathscr{O}_{X,W}$ has dimension at least two. Since $X$ is assumed to be (S2), every maximal regular sequence in $\mathscr{O}_{X,W}$ has length at least two. Since $W$ is an irreducible component of the subscheme corresponding to $\mathscr{I}$, it follows that the radical of $\mathscr{I}_W \subset \mathscr{O}_{X,W}$ is precisely the maximal ideal $\mathfrak{p}$. (Algebraically, $\mathfrak{p}$ is a minimal prime over $I$, and corresponds to the generic point of $W$.) Let $g,h \in \mathfrak{p}$ form a regular sequence (which exists since $X$ is (S2)). Replacing $g$ and $h$ by appropriate powers, we may assume that they are both contained in $\mathscr{I}_W$. By definition of regular sequence, $g$ is a nonzerodivisor. Since $h,g$ is a also a regular sequence, $h$ is a nonzerodivisor. Thus, $g$ and $h$, being nonzerodivisors that lie in the ideal of denominators, are in fact denominators of $f$: there exist $a, b \in \mathscr{O}_X,W$ such that $$\frac{a}{g} = \frac{b}{h} = f$$ $$ah = bg.$$ Since $g,h$ is a regular sequence, $h$ is a nonzerodivisor mod $g$. When we mod out by $g$, the equation above becomes $ah \equiv 0$, which would imply $a \equiv 0 \pmod{g}$. In other words, $a \in (g)$. But since $f = a/g$, this would imply that $f \in \mathscr{O}_{X,W}$, a contradiction since $f$ cannot be extended over $W$. 


Look at the exercises of Hartshorne, III.3. 


See MR1291023 (95k:14008), Hartshorne, "Generalized divisors on Gorenstein schemes" Proposition 1.11. 

