It is [well known](https://math.stackexchange.com/a/509018/656606) that an open subscheme of an affine scheme is not necessarily an affine one. But what are (if possible the most general) sufficient conditions for its affinity? And is it known how, in such cases, to directly describe its ring in terms of its corresponding radical ideal?


(I'm just starting to learn algebraic geometry, so any of your answers will most likely be useful to me)



Under what conditions is an open subscheme of an affine scheme affine and what ring corresponds to it?
Here is the best general result I'm aware of:


**Lemma.** *Let $A$ be a commutative ring with an ideal $I$, let $X = \operatorname{Spec} A$ with closed subset $Z = V(I)$ and open complement $U = D(I)$.*


1. *If $Z$ is a Cartier divisor, then $U$ is affine and dense in $X$.*
2. *If $A$ is Noetherian and $U$ is affine and dense in $X$, then $Z$ is a Weil divisor.*


The assumption in (1) means that $I$ is locally generated by one element (i.e. there exist elements $f\_1,\ldots,f\_n \in A$ generating the unit ideal such that each $I\_{f\_i} \subseteq A\_{f\_i}$ is a principal ideal). The conclusion in (2) means that every minimal prime containing $I$ has height $1$, i.e. $Z$ has pure codimension $1$ in $X$.


Every Cartier divisor is a Weil divisor (this is Krull's principal ideal theorem), and the converse is true if $X$ has mild singularities. For this problem, you can take $X$ to be locally factorial (or locally $\mathbf Q$-factorial if you don't mind replacing your ideal by a suitable power); in particular it is true when $A$ is regular. This gives:


**Corollary.** *Suppose $A$ is Noetherian and locally $\mathbf Q$-factorial, and that $U \subseteq X$ is dense. Then $U$ is affine if and only if every component of $Z$ has codimension $1$.* $\square$


There is also something to say about the case where $Z$ contains an entire irreducible component of $X$, but let me not attempt this here. At any rate, algebraic geometers often stick to irreducible schemes, where any nonempty open subset is dense.


*Proof of Lemma* (sketch). Statement (1) is relatively easy if you know some scheme-theory. The slogan is that the property of a morphism being affine can be checked locally (Hartshorne, Exercise II.5.17). Let me do it in a way that also computes the ring $B = \Gamma(U,\mathcal O\_U)$ in terms of $I$. By general stuff we get a morphism of schemes $\phi \colon U \to \operatorname{Spec} B$ (see e.g. Hartshorne, Exercise II.2.4), which we will show is an isomorphism.


Choose $f\_1,\ldots,f\_n \in A$ generating the unit ideal and elements¹⁾ $g\_1,\ldots,g\_n \in A$ such that $I\_{f\_i} = (g\_i)\_{f\_i} \subseteq A\_{f\_i}$. Then
$$U \cap D(f\_i) = D(g\_i) \cap D(f\_i) = D(f\_ig\_i) \cong \operatorname{Spec} A\_{f\_ig\_i},$$
and these cover $U$ since the $D(f\_i)$ cover $X$. The sheaf condition for $\mathcal O\_U$ gives an exact sequence
$$0 \to B \to \bigoplus\_{i=1}^n A\_{f\_ig\_i} \to \bigoplus\_{i<j} A\_{f\_ig\_if\_jg\_j},\label{1}\tag{1}$$
where the second map takes $(a\_i)\_i$ to $(a\_i-a\_j)\_{i<j}$. Localising \eqref{1} at $f\_i$ on the one hand computes $B\_{f\_i}$ by exactness of localisation, but on the other hand computes $\Gamma(U \cap D(f\_i),\mathcal O\_U) = A\_{f\_ig\_i}$ via the sheaf condition on $U \cap D(f\_i)$. If $Y = \operatorname{Spec} B$, we see that both $D(f\_i) \subseteq Y$²⁾ and its inverse image $U \cap D(f\_i) \subseteq U$ are affine, with isomorphic coordinate rings, so $\phi$ is an isomorphism above $D(f\_i) \subseteq Y$. Since these cover $Y$, we conclude that $\phi$ is an isomorphism, i.e. $U$ is affine. (See also Hartshorne, Exercises II.2.16, II.2.17, and II.5.17.)


Statement (2) is a little harder, and relies on the observation that for a Noetherian *local* ring $(R,\mathfrak m)$, the punctured spectrum $\operatorname{Spec} R \setminus\{\mathfrak m\}$ is affine if and only if $\dim R \leq 1$. See [Tag [0BCQ](https://stacks.math.columbia.edu/tag/0BCQ)] for a proof. Statement (2) then follows by taking $(R,\mathfrak m)$ to be the localisation of $A$ at a minimal prime $\mathfrak p$ containing $I$. If $U$ is affine, then so is $U \times\_X \operatorname{Spec} A\_{\mathfrak p} = \operatorname{Spec} A\_{\mathfrak p} \setminus \{\mathfrak p\}$ since a fibre product of affine schemes is affine. This forces $\operatorname{ht} \mathfrak p \leq 1$, i.e. every irreducible component of $Z$ has codimension $\leq 1$. The assumption that $U$ is dense means that every component of $Z$ has codimension exactly $1$. $\square$




---


¹⁾ A priori you only get $I\_{f\_i} = \big(\tfrac{g\_i}{f\_i^r}\big)\_{f\_i}$ for some $g\_i \in A$ and $r\in \mathbf N$, but then $g\_i$ also generates the ideal in $A\_{f\_i}$ since $f\_i$ is invertible.


²⁾ This is abuse of notation: we should really take the ring homomorphism $\psi \colon A \to B$ and talk of $D(\psi(f\_i)) \subseteq Y$. Then $B\_{f\_i}$ (localisation as $A$-modules) agrees with $B\_{\psi(f\_i)}$ (localisation as $B$-modules), etcetera. I hope this does not lead to confusion.


