# Exercise on locally ringed spaces

I try to solve exercise 2.19 on page 65 in "Algebraic Geometry I" by U.Görtz/T.Wedhorn. The exercise reads:

Let $(X,O_X)$ be a locally ringed space, and $f\in O_X(X)$. Define $X_f:=\{ x\in X; f(x) \neq 0\}$. Show that $X_f$ is an open subset of $X$. What is $X_f$ if $X$ is an affine scheme?

With regard to the first question I don't know what to do. Isn't it necessary to have more information on the topology to prove this?

If we take $X$ as an affine scheme we can assume $X=\text{Spec}(A)$ for a commutative ring $A$. Then $X_f = D(f) = V(f)^c$ is clearly open. Is that right?

-

What does the expression $f (x)$ itself mean? I will take it to mean the residue of the germ $f_x$ modulo the maximal ideal of the local ring $\mathscr{O}_{X,x}$.
So suppose $x$ is a point such that $f(x) \ne 0$. That means $f_x$ is not in the maximal ideal of $\mathscr{O}_{X,x}$, and so $f_x$ is invertible. Then, there must exist an open neighbourhood $U$ of $x$ and an element $g$ in $\mathscr{O}_X (U)$, such that $f_x g_x = 1$ in $\mathscr{O}_{X,x}$. Consider the element $f |_U g$. Since $f_x g_x = 1$, there must exist an open neighbourbood $V$ of $x$ such that $V \subseteq U$ and $f |_V g |_V = 1$ (by the construction of directed colimits), i.e. $f |_V$ is invertible in $\mathscr{O}_X (V)$. It is now clear that for all $y$ in $V$, the germ $f_y$ is invertible in $\mathscr{O}_{X,y}$, and so $f (y) \ne 0$ for all $y$ in $V$. Thus $$D(f) = \{ x \in X : f (x) \ne 0 \}$$ is open in $X$.