\subsection{Sheaves}

\begin{definition}[Sheaf]
    Let $X$ be any topological space.

    A \vocab{presheaf} $\mathcal{G}$ of sets (or rings, (abelian) groups) on $X$ associates a set (or rings, or (abelian) group) $\mathcal{G}(U)$ to every open subset  $U$ of $X$, and a map  (or ring or group homomorphism)  $\mathcal{G}(U) \xrightarrow{r_{U,V}} \mathcal{G}(V)$ to every inclusion $V \subseteq U$ of open subsets of $X$ such that $r_{U,W} = r_{V,W} r_{U,V}$ for inclusions $U \subseteq V \subseteq W$ of open subsets.

    Elements of $\mathcal{G}(U)$ are often called \vocab{sections}  of $\mathcal{G}$ on $U$ or \vocab{global sections} when $U = X$.

    Let $U \subseteq X$ be open and $U = \bigcup_{i \in  I} U_i$ an open covering.
    A family $(f_i)_{i \in I} \in \prod_{i \in I} \mathcal{G}(U_i)$ is called \vocab[Sections!compatible]{compatible}  if $r_{U_i, U_i \cap U_j}(f_i) = r_{U_j, U_i \cap U_j}(f_j)$ for all $i,j \in I$.

    Consider the map 
    \begin{align}
        \phi_{U, (U_i)_{i \in I}}: \mathcal{G}(U) &\longrightarrow \{(f_i)_{i \in I} \in \prod_{i \in I} \mathcal{G}(U_i) | r_{U_i, U_i \cap U_j}(f_i) = r_{U_j, U_i \cap U_j}(f_j) \text{ for } i,j \in I  \}  \\
    f &\longmapsto (r_{U, U_i}( f))_{i \in I}
    \end{align}

    A presheaf is called \vocab[Presheaf!separated]{separated}  if $\phi_{U, (U_i)_{i \in I}}$ is injective for all such $U$ and $(U_i)_{i \in I}$.\footnote{This also called ``locality''.}
    It satisfies \vocab{gluing} if $\phi_{U, (U_i)_{i \in I}}$ is surjective. 

    A presheaf is called a \vocab{sheaf}  if it is separated and satisfies gluing. 

    The bijectivity of the $\phi_{U, (U_i)_{i \in I}}$ is called the \vocab{sheaf axiom}. 
\end{definition}
\begin{trivial}+
    A presheaf is a contravariant functor $\mathcal{G} : \mathcal{O}(X) \to C$ where $\mathcal{O}(X)$ denotes the category of open subsets of $X$ with inclusions as morphisms and $C$ is the category of sets, rings or (abelian) groups.
\end{trivial}
\begin{definition}
    A subsheaf $\mathcal{G}'$ is defined by subsets (resp. subrings or subgroups) $\mathcal{G}'(U) \subseteq \mathcal{G}(U)$ for all open $U \subseteq X$ such that the sheaf axioms still hold.
\end{definition}
\begin{remark}
    If $\mathcal{G}$ is a sheaf on $X$ and $\Omega \subseteq X$ open, then $\mathcal{G}\defon{\Omega}(U) \coloneqq \mathcal{G}(U)$ for open $U \subseteq \Omega$ and $r_{U,V}^{(\mathcal{G}\defon{\Omega})}(f) \coloneqq r_{U,V}^{(\mathcal{G})}(f)$ is a sheaf of the same kind as $\mathcal{G}$ on $\Omega$.
\end{remark}
\begin{remark}
    The notion of restriction of a sheaf to a closed subset, or of preimages under general continuous maps, can be defined but this is a bit harder.
\end{remark}
\begin{notation}
    It is often convenient to write $f \defon{V}$ instead of $r_{U,V}(f)$.
\end{notation}
\begin{remark}
    Applying the \vocab{sheaf axiom} to the empty covering of $U = \emptyset$, one finds that $\mathcal{G}(\emptyset) = \{0\} $.
\end{remark}




\subsubsection{Examples of sheaves}
\begin{example}
    Let $G$ be a set and let $\mathfrak{G}(U)$ be the set of arbitrary maps $U \xrightarrow{f} G$. We put $r_{U,V}(f) = f\defon{V}$.
    It is easy to see that this defines a sheaf.
    If $\cdot $ is a group operation on $G$, then $(f\cdot g)(x) \coloneqq f(x)\cdot g(x)$ defines the structure of a sheaf of group on $\mathfrak{G}$.
    Similarly, a ring structure on $G$ can be used to define the structure of a sheaf of rings on  $\mathfrak{G}$.
\end{example}
\begin{example}
    If in the previous example $G$ carries a topology and $\mathcal{G}(U) \subseteq \mathfrak{G}(U)$ is the subset (subring, subgroup) of continuous functions $U \xrightarrow{f} G$, then $\mathcal{G}$ is a subsheaf of  $\mathfrak{G}$, called the sheaf of continuous $G$-valued functions on (open subsets of) $X$.
\end{example}

\begin{example}
    If $X = \R^n$, $\mathbb{K} \in  \{\R, \C\}$ and $\mathcal{O}(U)$ is the sheaf of $\mathbb{K}$-valued $C^{\infty}$-functions on $U$, then $\mathcal{O}$ is a subsheaf of the sheaf (of rings) of $\mathbb{K}$-valued continuous functions on $X$.
\end{example}
\begin{example}
    If $X = \C^n$  and  $\mathcal{O}(U)$ the set of holomorphic functions on $X$, then $\mathcal{O}$ is a subsheaf of the sheaf of $\C$-valued $C^{\infty}$-functions on $X$.
\end{example}
\subsubsection{The structure sheaf on a closed subset of $\mathfrak{k}^n$}

Let $X \subseteq \mathfrak{k}^n$ be open. Let $R = \mathfrak{k}[X_1,\ldots,X_n]$.
\begin{definition}\label{structuresheafkn}
    For open subsets $U \subseteq X$, let $\mathcal{O}_X(U)$ be the set of functions $U \xrightarrow{\phi} \mathfrak{k}$ such that every $x \in U$ has a neighbourhood $V$ such that there are $f,g \in  R$  such that for $y \in V$ we have $g(y) \neq 0$ and $\phi(y) = \frac{f(y)}{g(y)}$.
\end{definition}

\begin{remark}\label{structuresheafcontinuous}
    $\mathcal{O}_X$ is a subsheaf (of rings) of the sheaf of $\mathfrak{k}$-valued functions on $X$.
    The elements of $\mathcal{O}_X(U)$ are continuous:
    Let $M \subseteq \mathfrak{k}$ be closed. We must show the closedness of $N \coloneqq \phi^{-1}(M)$ in $U$. For $M = \mathfrak{k}$ this is trivial. Otherwise $M$ is finite and we may assume $M = \{t\} $ for some $t \in \mathfrak{k}$. For $x \in U$, there are open $V_x \subseteq U$ and $f_x, g_x \in R$ such that $\phi = \frac{f_x}{g_x}$ on $V_x$.
    Then $N \cap V_x = V(f_x - t\cdot g_x) \cap V_x)$ is closed in $V_x$. As the $V_x$ cover $U$ and $U$ is quasi-compact, $N$ is closed in $U$.
\end{remark}

\begin{proposition}\label{structuresheafri}
    Let $X = V(I)$ where $I = \sqrt{I}  \subseteq R$ is an ideal. Let $A = R / I$. Then
    \begin{align}
        \phi: A &\longrightarrow \mathcal{O}_X(X) \\
        f \mod I &\longmapsto f\defon{X}
    \end{align}
is an isomorphism.
\end{proposition}

\begin{proof}
    It is easy to see that the map $A \to \mathcal{O}_X(X)$ is well-defined and a ring homomorphism.
    Its injectivity follows from the Nullstellensatz and $I = \sqrt{I}$ (\ref{hns3}).


    Let $\phi \in  \mathcal{O}_X(X)$. for $x \in X$, there are an open subset $U_x \subseteq X$ and $f_x, g_x \in R$ such that $\phi = \frac{f_x}{g_x}$ on $U_x$.
    \begin{claim}
        Without loss of generality loss of generality we can assume $U_x = X \setminus V(g_x)$.
    \end{claim}
    \begin{subproof}
        The closed subsets $(X \setminus U_x) \subseteq \mathfrak{k}^n$ has the form $X\setminus U_x = V(J_x)$ for some ideal $J_x \subseteq R$.
        As $x \not\in  X \setminus V_x$ there is $h_x \in J_x$ with $h_x(x) \neq 0$.
        Replacing $U_x$ by $X \setminus V(h_x)$, $f_x$ by $f_xh_x$ and $g_x$ by $g_xh_x$, we may assume $U_x = X \setminus V(g_x)$.
    \end{subproof}
    \begin{claim}
        Without loss of generality loss of generality we can assume $V(g_x)  \subseteq V(f_x)$.
    \end{claim}
    \begin{subproof}
        Replace $f_x$ by $f_xg_x$ and $g_x$ by $g_x^2$.
    \end{subproof}
    As $X$ is quasi-compact, there are finitely many points $(x_i)_{i=1}^m$ such that the $U_{x_i}$ cover $X$.
    Let $U_i \coloneqq U_{x_i}, f_i \coloneqq f_{x_i}, g_i \coloneqq g_{x_i}$.

    As the $U_i = X \setminus V(g_i)$ cover $X$, $V(I) \cap \bigcap_{i=1}^m V(g_i) = X \cap \bigcap_{i=1}^m V(g_i) = \emptyset$.
    By the Nullstellensatz (\ref{hns1}) the ideal of $R$ generated by $I$ and the $a_i$ equals $R$. 
    There are thus $n \ge m \in \N$ and elements $(g_i)_{i = m+1}^n$ of $I$ and $(a_i)_{i=1}^n \in R^n$ such that $1 = \sum_{i=1}^{n} a_ig_i$.
    Let for $i > m$ $f_i \coloneqq 0$, $F = \sum_{i=1}^{n} a_if_i = \sum_{i=1}^{m} a_if_i \in R$.
    
    \begin{claim}
        For all $x \in X $ ~ $f_i(x) = \phi(x) g_i(x)$.
    \end{claim}
    \begin{subproof}
        If $x \in V_i$ this follows by our choice of $f_i$ and $g_i$.
        If $x \in X \setminus V_i$ or $i > m$ both sides are zero.
    \end{subproof}
    It follows that
    \[
        \phi(x) = \phi(x) \cdot  1 = \phi(x) \cdot \sum_{i=1}^{n} a_i(x) g_i(x) = \sum_{i=1}^{n} a_i(x) f_i(x) = F(x)
    \] 
    Hence $\phi = F\defon{X}$.
\end{proof}
\subsubsection{The structure sheaf on closed subsets of $\mathbb{P}^n$}
Let $X \subseteq \mathbb{P}^n$ be closed and $R_\bullet = \mathfrak{k}[X_0,\ldots,X_n]$ with its usual grading.

\begin{definition}\label{structuresheafpn}
    For open $U \subseteq X$, let $\mathcal{O}_X(U)$ be the set of functions $U \xrightarrow{\phi} \mathfrak{k}$ such that for every $x \in U$, there are an open subset $W \subseteq U$, a natural number $d$ and $f,g \in R_d$ such that $W \cap \Vp(g) = \emptyset$ and $\phi(y) = \frac{f(y_0,\ldots,y_n)}{g(y_0,\ldots,y_n)}$ for $y = [y_0,\ldots,y_n] \in  W$.
\end{definition}

\begin{remark}
    This is a subsheaf of rings of the sheaf of $\mathfrak{k}$-valued functions on $X$.
Under the identification $\mathbb{A}^n =\mathfrak{k}^n$ with $\mathbb{P}^n \setminus \Vp(X_0)$, one has $\mathcal{O}_X \defon{X \setminus \Vp(X_0)} = \mathcal{O}_{X \cap \mathbb{A}^n}$ as subsheaves of the sheaf of $\mathfrak{k}$-valued functions, where the second sheaf is a sheaf on a closed subset of $\mathfrak{k}^n$:

Indeed, if $W$ is as in the definition then $\phi([1,y_1,\ldots,y_n]) = \frac{f(1,y_1,\ldots,y_n)}{g(1,y_1,\ldots,y_n)}$ for $[1,y_1,\ldots,y_n] \in  W$.
Conversely  if $\phi([1,y_1,\ldots,y_n]) = \frac{f(y_1,\ldots,y_n)}{g(y_1,\ldots,y_n)}$ on an open subset $W $ of $X \cap \mathbb{A}^n$ then 
$\phi([y_0,\ldots,y_n]) = \frac{F(y_0,\ldots,y_n)}{G(y_0,\ldots,y_n)}$ on $W$ where $F(X_0,\ldots,X_n) \coloneqq X_0^d f(\frac{X_1}{X_0}, \ldots, \frac{X_n}{X_0})$ and $G(X_0,\ldots,X_n) = X_0^d g(\frac{X_1}{X_0},\ldots, \frac{X_n}{X_0})$ with a sufficiently large $d \in \N$.
\end{remark}
\begin{remark}
    It follows from the previous remark and the similar result in the affine case that the elements of $\mathcal{O}_X(U)$ are continuous on $U \setminus V(X_0)$.
    Since the situation is symmetric in the homogeneous coordinates, they are continuous on all of $U$.
\end{remark}
The following is somewhat harder than in the affine case:
\begin{proposition}
    If $X$ is connected (e.g. irreducible), then the elements of $\mathcal{O}_X\left( X \right) $ are constant functions on $X$.
\end{proposition}



% Lecture 14

\subsection{The notion of a category}
\begin{definition}
    A \vocab{category}  $\mathcal{A}$ consists of:
    \begin{itemize}
        \item A class  $\Ob \mathcal{A}$ of \vocab[Objects]{objects of $\mathcal{A}$}.
        \item For two arbitrary objects $A, B \in \Ob \mathcal{A}$, a \textbf{set}  $\Hom_\mathcal{A}(A,B)$ of \vocab[Morphism]{morphisms for $A$ to $B$ in $\mathcal{A}$}.
        \item A map $\Hom_\mathcal{A}(B,C) \times  \Hom_\mathcal{A}(A,B) \xrightarrow{\circ} \Hom_\mathcal{A}(A,C)$, the composition of morphisms, for arbitrary triples $(A,B,C)$ of objects of $\mathcal{A}$.
    \end{itemize}
    The following conditions must be satisfied:
    \begin{enumerate}[A]
        \item For morphisms $A \xrightarrow{f} B\xrightarrow{g} C \xrightarrow{h} D$, we have $h \circ (g \circ f) = (h \circ g) \circ f$.
        \item For every  $A \in \Ob(\mathcal{A})$, there is an $\Id_A \in  \Hom_{\mathcal{A}}(A,A)$ such that $\Id_A \circ f = f$ (reps. $g \circ \Id_A = g$) for arbitrary morphisms $B \xrightarrow{f} A$ (reps. $A \xrightarrow{g} C).$
    \end{enumerate}

    A morphism $X \xrightarrow{f} Y$ is called an \vocab[Isomorphism]{isomorphism (in $\mathcal{A} $)} if there is a morphism $Y \xrightarrow{g} X$ (called the \vocab[Inverse morphism]{inverse $f^{-1}$ of $f$)} such that $g \circ f = \Id_X$ and $f \circ g = \Id_Y$.  
\end{definition}
\begin{remark}
    \begin{itemize}
        \item The distinction between classes and sets is important here.
        \item We will usually omit the composition sign $\circ$.
        \item It is easy to see that $\Id_A$ is uniquely determined by the above condition $B$, and that the inverse $f^{-1}$ of an isomorphism $f$ is uniquely determined.
    \end{itemize}
\end{remark}
\subsubsection{Examples of categories}
\begin{example}
    \begin{itemize}
        \item The category of sets.
        \item The category of groups.
        \item The category of rings.
        \item If $R$ is a ring, the category of $R$-modules and the category $\Alg_R$ of $R$-algebras
        \item The category of topological spaces
        \item The category $\Var_\mathfrak{k}$ of varieties over $\mathfrak{k}$ (see \ref{defvariety})
        \item If $\mathcal{A}$ is a category, then the \vocab{opposite category}  or \vocab{dual category}  is defined by $\Ob(\mathcal{A}\op) = \Ob(\mathcal{A})$ and $\Hom_{\mathcal{A}\op}(X,Y) = \Hom_\mathcal{A}(Y,X)$.
    \end{itemize}
    In most of these cases, isomorphisms in the category were just called `isomorphism'. The isomorphisms in the category of topological spaces are the homeomophisms.
\end{example}
\subsubsection{Subcategories}
\begin{definition}[Subcategories]
    A \vocab{subcategory}  of $\mathcal{A}$ is a category $\mathcal{B}$ such that $\Ob(\mathcal{B}) \subseteq \Ob(\mathcal{A})$, such that $\Hom_\mathcal{B}(X,Y) \subseteq \Hom_\mathcal{A}(X,Y)$ for objects $X$ and $Y$ of $\mathcal{B}$, such that for every object $X \in \Ob(\mathcal{B})$, the identity $\Id_X$ of $X$ is the same in $\mathcal{B}$ as in $\mathcal{A}$, and such that for composable morphisms in $\mathcal{B}$, their compositions in $\mathcal{A}$ and $\mathcal{B}$ coincide.
    We call $\mathcal{B}$ a \vocab{full subcategory}  of $\mathcal{A}$ if in addition $\Hom_\mathcal{B}(X,Y) = \Hom_\mathcal{A}(X,Y)$ for arbitrary $X,Y \in \Ob(\mathcal{B})$.
\end{definition}
\begin{example}
    \begin{itemize}
        \item The category of abelian groups is a full subcategory of the category of groups.
            It can be identified with the category of $\Z$-modules.
        \item The category of finitely generated $R$-modules as a full subcategory of the category of $R$-modules.
        \item The category of $R$-algebras of finite type as a full subcategory of $\Alg_R$.
        \item The category of affine varieties over $\mathfrak{k}$ as a full subcategory of the category of varieties over $\mathfrak{k}$.
    \end{itemize}
\end{example}

\subsubsection{Functors and equivalences of categories}
\begin{definition}
    A \vocab[Functor!covariant]{(covariant) functor} (resp.  \vocab[Functor!contravariant]{contravariant functor}) between categories $\mathcal{A} \xrightarrow{F} \mathcal{B}$ is a map $\Ob(\mathcal{A}) \xrightarrow{F} \Ob(\mathcal{B})$ with a family of maps $\Hom_\mathcal{A}(X,Y) \xrightarrow{F} \Hom_\mathcal{B}(F(X),F(Y))$ (resp. $\Hom_\mathcal{A}(X,Y) \xrightarrow{F} \Hom_\mathcal{B}(F(Y),F(X))$ in the case of contravariant functors), where $X$ and $Y$ are arbitrary objects of $\mathcal{A}$, such that the following conditions hold:
     \begin{itemize}
         \item $F(\Id_X) = \Id_{F(X)}$ 
         \item For morphisms $X \xrightarrow{f} Y \xrightarrow{g} Z$ in $\mathcal{A}$, we have $F(gf) = F(g)F(f)$ ( resp. $F(gf) = F(f)F(g)$)
    \end{itemize}
    A functor is called \vocab[Functor!essentially surjective]{essentially surjective}  if every object of $\mathcal{B}$ is isomorphic to an element of the image of $\Ob(\mathcal{A}) \xrightarrow{F}  \Ob(\mathcal{B})$.
    A functor is called \vocab[Functor!full]{full} (resp. \vocab[Functor!faithful]{faithful}) if it induces surjective (resp. injective) maps between sets of morphisms.
    It is called an \vocab{equivalence of categories} if it is full, faithful and essentially surjective.
\end{definition}
\begin{example}
    \begin{itemize}
        \item There are \vocab[Functor!forgetful]{forgetful functors} from rings to abelian groups or from abelian groups to sets which drop the multiplicative structure of a ring or the group structure of a group.
        \item If $\mathfrak{k}$ is any vector space there is  a contravariant functor from $\mathfrak{k}$-vector spaces to itself sending $V$ to its dual vector space $V\subseteq$ and $V \xrightarrow{f} W$ to the dual linear map $W^{\ast} \xrightarrow{f^{\ast}} V^{\ast}$.
            When restricted to the full subcategory of finite-dimensional vector spaces it becomes a contravariant self-equivalence of that category.
        \item The embedding of a subcategory is a faithful functor. In the case of a full subcategory it is also full.
    \end{itemize}
\end{example}



\subsection{The category of varieties}

\begin{definition}[Algebraic variety]\label{defvariety}
    An \vocab{algebraic variety}  or \vocab{prevariety}  over $\mathfrak{k}$ is a pair $(X, \mathcal{O}_X)$, where $X$ is a topological space and $\mathcal{O}_X$ a subsheaf of the sheaf of $\mathfrak{k}$-valued functions on  $X$ such that for every $x \in X$, there are a neighbourhood $U_x$ of $x$ in $X$, an open subset $V_x$ of a closed subset $Y_x$ of $\mathfrak{k}^{n_x}$\footnote{By the result of \ref{affopensubtopbase} it can be assumed that $V_x = Y_x$ without altering the definition.} and a homeomorphism $V_x \xrightarrow{\iota_x} U_x$ such that for every open subset $V \subseteq U_x$ and every function $V\xrightarrow{f} \mathfrak{k}$, we have $f \in \mathcal{O}_X(V) \iff \iota^{\ast}_x(f) \in \mathcal{O}_{Y_x}(\iota_x^{-1}(V))$,

        In this, the \vocab{pull-back} $\iota_x^{\ast}(f)$ of $f$ is defined by $(\iota_x^{\ast}(f))(\xi) \coloneqq f(\iota_x(\xi))$.


        A morphism $(X, \mathcal{O}_X) \to  (Y, \mathcal{O}_Y)$ of varieties is a continuous map $X \xrightarrow{\phi} Y$ such that for all open $U \subseteq Y$ and $f \in \mathcal{O}_Y(U)$, $\phi^{\ast}(f) \in \mathcal{O}_X(\phi^{-1}(U))$.
        An isomorphism is a morphism such that $\phi$ is bijective and $\phi^{-1}$ also is a morphism of varieties.
\end{definition}
\begin{example}
    \begin{itemize}
        \item If $(X, \mathcal{O}_X)$ is a variety and $U \subseteq X$ open, then $(U, \mathcal{O}_X\defon{U})$ is a variety (called an \vocab{open subvariety}  of $X$), and the embedding $U \to  X$ is a morphism of varieties.
        \item If $X$ is a closed subset of $\mathfrak{k}^n$ or $\mathbb{P}^n$, then $(X, \mathcal{O}_X)$ is a variety, where $\mathcal{O}_X$ is the structure sheaf on $X$ (\ref{structuresheafkn}, reps. \ref{structuresheafpn}).
            A variety is called \vocab[Variety!affine]{affine} (resp. \vocab[Variety!projective]{projective}) if it is isomorphic to a variety of this form, with $X $ closed in $\mathfrak{k}^n$ (resp. $\mathbb{P}^n$).
            A variety which is isomorphic to and open subvariety of $X$ is called \vocab[Variety!quasi-affine]{quasi-affine} (resp. \vocab[Variety!quasi-projective]{quasi-projective}). 
        \item If $X = V(X^2 - Y^3) \subseteq \mathfrak{k}^2$ then $\mathfrak{k} \xrightarrow{t \mapsto (t^3,t^2)} X$ is a morphism which  is a homeomorphism of topological spaces but not an isomorphism of varieties.
            % TODO

        \item The composition of two morphisms $X \to  Y \to Z$ of varieties is a morphism of varieties.
        \item $X\xrightarrow{\Id_X} X$ is a morphism of varieties.
    \end{itemize}
\end{example}

\subsubsection{The category of affine varieties}
\begin{lemma}\label{localinverse}
    Let $X$ be any $\mathfrak{k}$-variety and $U \subseteq X$ open.
    \begin{enumerate}[i)]
        \item All elements of $\mathcal{O}_X(U)$ are continuous.
        \item If $U \subseteq X$ is open, $U \xrightarrow{\lambda} \mathfrak{k}$ any function and every $x \in U$ has a neighbourhood $V_x \subseteq U$ such that $\lambda \defon{V_x}  \in  \mathcal{O}_X(V_x)$, then $\lambda \in \mathcal{O}_X(U)$.
        \item If $\vartheta \in \mathcal{O}_X(U)$ and $\vartheta(x) \neq 0$ for all $x \in U$, then $\vartheta \in \mathcal{O}_X(U)^{\times }$.
    \end{enumerate}
\end{lemma}
\begin{proof}
    \begin{enumerate}[i)]
        \item  The property is local on $U$, hence it is sufficient to show it in the quasi-affine case. This was done in \ref{structuresheafcontinuous}.
        \item For the second part, let $\lambda_x \coloneqq \lambda \defon{V_x} $. 
            We have $\lambda_x\defon{V_x \cap V_y} = \lambda \defon{V_x \cap V_y} =  \lambda_y \defon{V_x \cap V_y} $.
            The $V_x$ cover $U$. By the sheaf axiom for $\mathcal{O}_X$ there is $\ell \in \mathcal{O}_X(U)$ with $\ell\defon{V_x} =\lambda_x$. It follows that  $\ell=\lambda$.
        \item By the definition of variety, every $x \in U$ has a quasi-affine neighbourhood $V \subseteq U$. We can assume  $U$ to be quasi-affine and $X = V(I) \subseteq \mathfrak{k}^n$, as the general assertion follows by an application of ii).
            If $x \in U$ there are a neighbourhood $x \in W \subseteq U$ and $a,b \in R = \mathfrak{k}[X_1,\ldots,X_n]$ such that $\vartheta(y) = \frac{a(y)}{b(y)}$ for $y \in W$, with $b(y) \neq 0$.
            Then $a(x) \neq 0$ as $\vartheta(x) \neq 0$. Replacing $W$ by $W \setminus V(a)$, we may assume that $a$ has no zeroes on $W$.
            Then $\lambda(y) = \frac{b(y)}{a(y)}$ for $y \in W$ has a non-vanishing denominator and $\lambda \in \mathcal{O}_X(U)$.
            We have $\lambda \cdot \vartheta = 1$, thus $\vartheta \in  \mathcal{O}_X(U)^{\times}$.
    \end{enumerate}

    
\end{proof}
\begin{proposition}[About affine varieties]
    \label{propaffvar}
    \begin{itemize}
        \item Let $X,Y$ be varieties over $\mathfrak{k}$. Then the map
            \begin{align}
                \phi: \Hom_{\Var_\mathfrak{k}}(X,Y) &\longrightarrow \Hom_{\Alg_\mathfrak{k}}(\mathcal{O}_Y(Y), \mathcal{O}_X(X)) \\
                (X \xrightarrow{f} Y) &\longmapsto (\mathcal{O}_Y(Y) \xrightarrow{f^{\ast}}  \mathcal{O}_X(X))
            \end{align}
            is injective when $Y$ is quasi-affine and bijective when $Y$ is affine.
        \item The contravariant functor
            \begin{align}
                F: \Var_\mathfrak{k} &\longrightarrow \Alg_\mathfrak{k} \\
                X &\longmapsto \mathcal{O}_X(X)\\
                (X\xrightarrow{f} Y) &\longmapsto (\mathcal{O}_X(X) \xrightarrow{f^{\ast}} \mathcal{O}_Y(Y))
            \end{align}
            restricts to an equivalence of categories between the category of affine varieties over $\mathfrak{k}$ and the full subcategory $\mathcal{A}$ of $\Alg_\mathfrak{k}$,
            having the $\mathfrak{k}$-algebras $A$ of finite type with $\nil A = \{0\} $ as objects.
    \end{itemize}
\end{proposition}

\begin{remark}
    It is clear that $\nil(\mathcal{O}_X(X)) = \{0\}$ for arbitrary varieties. For general varieties it is however not true that $\mathcal{O}_X(X)$ is a $\mathfrak{k}$-algebra of finite type.
    There are counterexamples even for quasi-affine $X$. %TODO

    If, however, $X$ is affine, we may assume w.l.o.g. that $X = V(I)$ where $I = \sqrt{I} \subseteq R$ is an ideal with $R = \mathfrak{k}[X_1,\ldots,X_n]$.
    Then $\mathcal{O}_X(X) \cong R / I$ (see \ref{structuresheafri}) is a $\mathfrak{k}$-algebra of finite type.
\end{remark}

\begin{proof}




    It suffices to investigate $\phi$ when $Y$ is an open subset of $V(I) \subseteq \mathfrak{k}^n$, where $I = \sqrt{I}  \subseteq R$ is an ideal and $Y = V(I)$ when  $Y$ is affine.
    Let $(f_1,\ldots,f_n)$ be the components of $X \xrightarrow{f} Y \subseteq \mathfrak{k}^n$. Let $Y \xrightarrow{\xi_i}  \mathfrak{k}$ be the $i$-th coordinate.
    By definition $f_i = f^{\ast}(\xi_i) $. Thus $f$ is uniquely determined by $\mathcal{O}_Y(Y) \xrightarrow{f^{\ast}} \mathcal{O}_X(X)$.
    Conversely, let $Y = V(I)$ and $\mathcal{O}_Y(Y) \xrightarrow{\phi} \mathcal{O}_X(X)$ be a morphism of $\mathfrak{k}$-algebras. Define $f_i \coloneqq \phi(\xi_i)$ and consider $X \xrightarrow{f = (f_1,\ldots,f_n)} Y\subseteq \mathfrak{k}^n$.
    \begin{claim}
        $f$ has image contained in $Y$.
    \end{claim}
    \begin{subproof}
        For $x \in X, \lambda \in I$ we have $\lambda(f(x)) = (\phi(\lambda \mod I))(x) = 0$ as $\phi$ is a morphism of $\mathfrak{k}$-algebras.
        Thus $f(x) \in V(I) = Y$.
    \end{subproof}
    \begin{claim}
        $f$ is a morphism in $\Var_\mathfrak{k}$
    \end{claim}
    \begin{subproof}
        For open $\Omega \subseteq Y, U = f^{-1}(\Omega) = \{x \in X | \forall \lambda \in J ~ (\phi(\lambda))(x) \neq 0\}$ is open in $X$, where $Y \setminus \Omega = V(J)$.
        If $\lambda \in \mathcal{O}_Y(\Omega)$ and $x \in U$, then $f(x)$ has a neighbourhood $V$ such that there are $a,b \in R$ with $\lambda(v) = \frac{a(v)}{b(v)}$ and $b(v) \neq 0$ for all $v \in V$.
        Let $W \coloneqq f^{-1}(V)$. Then $\alpha \coloneqq \phi(a)\defon{W} \in \mathcal{O}_X(W)$,  $\beta \coloneqq \phi(b)\defon{W} \in \mathcal{O}_X(W)$.
        By the second part of \ref{localinverse} $\beta \in \mathcal{O}_X(W)^{\times}$ and $f^{\ast}(\lambda)\defon{W}  = \frac{\alpha}{\beta} \in \mathcal{O}_X(W)$.
        The first part of \ref{localinverse} shows that  $f^{\ast}(\lambda) \in  \mathcal{O}_X(U)$.
    \end{subproof}
    By definition of $f$, we have $f^{\ast} = \phi$. This finished the proof of the first point.



    \begin{claim}
        The functor in the second part maps affine varieties to objects of $\mathcal{A}$ and is essentially surjective.
    \end{claim}
    \begin{subproof}
        It follows from the remark that the functor maps affine varieties to objects of $\mathcal{A}$.

        If $A \in \Ob(\mathcal{A})$ then $ A /\mathfrak{k}$ is of finite type, thus $A \cong R / I$ for some $n$.
        Since $\nil(A) = \{0\}$ we have $I = \sqrt{I}$, as for $x \in \sqrt{I}$, $x \mod I \in  \nil(R / I) \cong \nil(A) = \{0\}$.
        Thus $A \cong\mathcal{O}_X(X)$ where $X = V(I)$.
    \end{subproof}
    Fullness and faithfulness of the functor follow from the first point.
\end{proof}

\begin{remark}
    Note that giving a contravariant functor $\mathcal{C} \to \mathcal{D}$ is equivalent to giving a functor $\mathcal{C} \to \mathcal{D}\op$. We have thus shown that the category of affine varieties is equivalent to $\mathcal{A}\op$, where $\mathcal{A} \subsetneq \Alg_\mathfrak{k}$ is the full subcategory of $\mathfrak{k}$-algebras $A$ of finite type with $\nil(A) = \{0\}$.
\end{remark}
\subsubsection{Affine open subsets are a topology base}

\begin{definition}
    A set $\mathcal{B}$ of open subsets of a topological space $X$ is called a \vocab{topology base} for $X$ if every open subset of $X$ can be written as a (possibly empty) union of elements of $\mathcal{B}$.
\end{definition} 
\begin{fact}
If $X$ is a set, then $\mathcal{B} \subseteq \mathcal{P}(X)$ is a base for some topology on $X$ iff $X = \bigcup_{U \in \mathcal{B}} U$ and for arbitrary $U, V \in \mathcal{B}, U \cap V$ is a union of elements of $\mathcal{B}$.
\end{fact}
\begin{definition}
    Let $X$ be a variety.
    An \vocab{affine open subset} of $X$ is a subset which is an affine variety. 
    
\end{definition}
\begin{proposition}\label{oxulocaf}
    Let $X$ be an affine variety over $\mathfrak{k}$, $\lambda \in \mathcal{O}_X(X)$ and $U = X \setminus V(\lambda)$.
    Then  $U$ is an affine variety and the morphism $\phi: \mathcal{O}_X(X)_\lambda \to \mathcal{O}_X(U)$ defined by the restriction $\mathcal{O}_X(X) \xrightarrow{\cdot |_U } \mathcal{O}_X(U)$ and the universal property of the localization is an isomorphism.
\end{proposition}
\begin{proof}
    Let $X$ be an affine variety over $\mathfrak{k}, \lambda \in  \mathcal{O}_X(X)$ and $U = X \setminus V(\lambda)$. The fact that $\lambda\defon{U}  \in \mathcal{O}_x(U)^{\times}$ follows from \ref{localinverse}.
    Thus the universal property of the localization $\mathcal{O}_X(X)_\lambda$ can be applied to $\mathcal{O}_X(X) \xrightarrow{\cdot |_U} \mathcal{O}_X(U)$.
    \[
        \begin{tikzcd}
            \mathcal{O}_X(X) \arrow{d}{\cdot |_U}\arrow{r}{x \mapsto \frac{x}{1}} & \mathcal{O}_X(X)_\lambda \arrow[dotted, bend left]{dl}{\existsone \phi} \\
            \mathcal{O}_X(U) &
        \end{tikzcd}
      \]
      \[
        \begin{tikzcd}
            &Y \arrow[bend right, swap]{ld}{\pi_0} \arrow[bend right, swap]{d}{\pi}&\mathcal{O}_Y(Y) \cong A_\lambda \arrow{d}{\mathfrak{s}}& \\
            X \arrow[hookrightarrow]{r}{}& U \arrow[swap]{u}{\sigma} & \mathcal{O}_X(U)
        \end{tikzcd}
      \]
    For the rest of the proof, we may assume $X = V(I) \subseteq \mathfrak{k}^n$ where $I = \sqrt{I} \subseteq R \coloneqq\mathfrak{k}[X_1,\ldots,X_n]$ is an ideal.
    Then $A \coloneqq \mathcal{O}_X(X) \cong R / I$ and there is $\ell \in R$ such that $\ell\defon{X} = \lambda$.
    Let $Y = V(J) \subseteq \mathfrak{k}^{n+1}$ where $J \subseteq \mathfrak{k}[Z,X_1,\ldots,X_n]$ is generated by the elements of $I$ and $1 - Z\ell(X_1,\ldots,X_n)$.

    Then $\mathcal{O}_Y(Y) \cong \mathfrak{k}[Z,X_1,\ldots,X_n] / J \cong A[Z] / (1 -\lambda Z) \cong A_\lambda$.
    By the proposition about affine varieties (\ref{propaffvar}), the morphism $\mathfrak{s}: \mathcal{O}_Y(Y) \cong A_\lambda \to \mathcal{O}_X(U)$ corresponds to a morphism $U \xrightarrow{\sigma} Y$.
    We have $\mathfrak{s}(Z \mod J) = \lambda^{-1}$ and $\mathfrak{s}(X_i \mod J) = X_i \mod I$.
    Thus $\sigma(x) = (\lambda(x)^{-1}, x)$ for $x \in U$.
    Moreover, the projection $Y \xrightarrow{\pi_0} X$ dropping the $Z$-coordinate has image contained in $U$, as for $(z,x) \in Y$ the equation
    \[
        1 = z\lambda(x)
    \] 
    implies $\lambda(x) \neq 0$. It thus defines a morphism $Y \xrightarrow{\pi} U$ and by the description of $\sigma$ it follows that $\sigma \pi = \Id_U$.
    Similarly it follows that $\sigma \pi =  \Id_Y$. Thus, $\sigma$ and $\pi$ are inverse to each other.   
\end{proof}
\begin{corollary}\label{affopensubtopbase}
    The affine open subsets of a variety $X$ are a topology base on $X$.
\end{corollary}
\begin{proof}
    Let $X = V(I) \subseteq \mathfrak{k}^n$ with $I = \sqrt{I}$. If $U \subseteq X$ is open then $X \setminus U = V(J)$ with $J \supseteq I$ and $U = \bigcup_{f \in J} (X \setminus V(f))$.
    Thus $U$ is a union of affine open subsets. The same then holds for arbitrary quasi-affine varieties.
    
    Let $X$ be any variety, $U \subseteq X$ open and $x \in U$.
    By the definition of variety, $x$ has a neighbourhood $V_x$ which is quasi-affine, and replacing $V_x$ by $U \cap V_x$ which is also quasi-affine we may assume  $V_x \subseteq U$.
    $V_x$ is a union of its affine open subsets. Because $U$ is the union of the $V_x$, $U$ as well is a union of affine open subsets.
\end{proof}


% Lecture 14A TODO?

% Lecture 15

% CRTPROG

\subsection{Stalks of sheaves}

\begin{definition}[Stalk]
    Let $\mathcal{G}$ be a presheaf of sets on the topological space $X$, and let  $x \in X$.
    The \vocab{stalk} (\vocab[Stalk]{Halm}) of $\mathcal{G}$ at $x$ is the set of equivalence classes of pairs $(U, \gamma)$, where $U$ is an open neighbourhood of $x$ and $\gamma \in \mathcal{G}(U)$
    and the equivalence relation $\sim $ is defined as follows:
    $( U , \gamma) \sim (V, \delta)$ iff  there exists an open neighbourhood $W \subseteq U \cap V$ of $x$ such that $\gamma \defon{W}  = \delta \defon{W}$. 


    If $\mathcal{G}$ is a presheaf of groups, one can define a groups structure on $\mathcal{G}_x$ by
    \[
        ((U, \gamma) / \sim ) \cdot \left( (V,\delta) / \sim  \right) = (U \cap V, \gamma \defon{U \cap V}  \cdot \delta\defon{U \cap V}) / \sim 
    \] 

    If $\mathcal{G}$ is a presheaf of rings, one can similarly define a ring structure on $\mathcal{G}_x$.
    

    If $U$ is an open neighbourhood of $x \in X$, then we have a map (resp. homomorphism)
    \begin{align}
        \cdot_x : \mathcal{G}(U) &\longrightarrow \mathcal{G}_x \\
        \gamma &\longmapsto \gamma_x \coloneqq (U, \gamma) / \sim 
    \end{align}

\end{definition}
\begin{fact}
    Let $\gamma,\delta \in  \mathcal{G}(U)$. If $\mathcal{G}$ is a sheaf\footnote{or, more generally, a separated presheaf} and if for all $x \in U$, we have $\gamma_x = \delta_x$, then $\gamma = \delta$.

    In the case of a sheaf, the image of the injective map $\mathcal{G}(U) \xrightarrow{\gamma \mapsto (\gamma_x)_{x \in U}} \prod_{x \in U} \mathcal{G}_x$
    is the set of all $(g_x)_{x \in U} \in  \prod_{x \in U} \mathcal{G}_x  $ satisfying the following \vocab{coherence condition}:
    For every $x \in U$, there are an open neighbourhood $W_x \subseteq U$ of $x$ and $g^{(x)} \in \mathcal{G}(W_x)$ with $g_y^{(x)} = g_y$ for all $y \in  W_x$.
\end{fact}
\begin{proof}
    Because of $\gamma_x = \delta_x$, there is $x \in W_x \subseteq U$ open such that $\gamma\defon{W_x}  = \delta\defon{W_x}$. As the $W_x$ cover $U$, $\gamma = \delta$ by the sheaf axiom.
\end{proof}
\begin{definition}
    Let $\mathcal{G}$ be a sheaf of functions.
    Then $\gamma_x$ is called the \vocab{germ}  of the function $\gamma$ at $x$.
    The \vocab[Germ!value at $x$]{value at $x$ } of $g = (U, \gamma) / \sim \in \mathcal{G}_x$ defined as $g(x) \coloneqq \gamma(x)$, which is independent of the choice of the representative $\gamma$. 
\end{definition}
\begin{remark}
       If $\mathcal{G}$ is a sheaf of $C^{\infty}$-functions (resp. holomorphic functions), then $\mathcal{G}_x$ is called the ring of germs of $C^\infty$-functions (resp. of holomorphic functions) at $x$.

\end{remark}
\subsubsection{The local ring of an affine variety}
\begin{definition}
    If $X$ is a variety, the stalk $\mathcal{O}_{X,x}$ of the structure sheaf at $x$ is called the \vocab{local ring}  of $X$ at $x$.
    This is indeed a local ring, with maximal ideal $\mathfrak{m}_x = \{f \in \mathcal{O}_{X,x} | f(x) = 0\}$.
\end{definition}
\begin{proof}
    By \ref{localring} it suffices to show that $\mathfrak{m}_x$ is a proper ideal, which is trivial, and that the elements of $\mathcal{O}_{X,x} \setminus \mathfrak{m}_x$ are units in $\mathcal{O}_{X,x}$.
    Let $g = (U, \gamma)/\sim \in \mathcal{O}_{X,x}$ and $g(x) \neq 0$.
    $\gamma$ is  Zariski continuous (first point of \ref{localinverse}). Thus $V(\gamma)$ is closed. By replacing $U$ by $U \setminus V(\gamma)$ we may assume that $\gamma$ vanishes nowhere on $U$.
    By the third point of \ref{localinverse} we have $\gamma \in \mathcal{O}_X(U)^{\times}$.
    $(\gamma^{-1})_x$ is an inverse to $g$.
\end{proof}

\begin{proposition}\label{proplocalring}
    Let $X = \Va(I) \subseteq \mathfrak{k}^n$ be equipped with its usual structure sheaf, where $I = \sqrt{I} \subseteq R = \mathfrak{k}[X_1,\ldots,X_n]$ . Let $x \in X$ and $A = \mathcal{O}_X(X) \cong R / I$.
    $\{P \in  R | P(x) = 0\} \text{\reflectbox{$\coloneqq$}} \fn_x \subseteq R$ is maximal, $I \subseteq \fn_x$ and  $\mathfrak{m}_x \coloneqq \fn_x / I$ is the maximal ideal of elements of $A$ vanishing at $x$.
    If $\lambda \in  A \setminus \mathfrak{m}_x$, we have $\lambda_x \in  \mathcal{O}_{X,x}^{\times}$, where $\lambda_x$ denotes the image under $A \cong \mathcal{O}_X(X) \to  \mathcal{O}_{X,x}$.
    By the universal property of the localization, there exists a unique ring homomorphism $A_{\mathfrak{m}_x} \xrightarrow{\iota} \mathcal{O}_{X,x}$ 
    such that 
    \[
        \begin{tikzcd}
            A \arrow{r}{} \arrow{d}{\lambda \mapsto \lambda_x} & A_{\mathfrak{m}_x} \arrow[dotted, bend left]{ld}{\existsone \iota} \\
            \mathcal{O}_{X,x}
        \end{tikzcd}
      \]
    commutes.
   
    The morphism $A_{\mathfrak{m}_x}\xrightarrow{\iota} \mathcal{O}_{X,x}$ is an isomorphism.

\end{proposition}
\begin{proof}
    To show surjectivity, let $\ell = (U, \lambda) / \sim  \in  \mathcal{O}_{X,x}$, where $U$ is an open neighbourhood of $x$ in $X$. 
    We have $X \setminus U = V(J)$ where $J \subseteq A$ is an ideal. As $x \in U$ there is $f \in J$ with $f(x) \neq 0$. Replacing $U $ by $X \setminus V(f)$ we may assume $U = X \setminus V(f)$.
    By \ref{oxulocaf}, $\mathcal{O}_X(U) \cong A_f$, and $\lambda = f^{-n}\vartheta$ for some $n \in \N$ and $\vartheta \in A$.
    Then $\ell = \iota(f^{-n} \vartheta)$ where the last fraction is taken in $A_{\mathfrak{m}_x}$.


    Let $\lambda = \frac{\vartheta}{g} \in  A_{\mathfrak{m}_x}$ with $\iota(\lambda) = 0$.
    It is easy to see that $\iota(\lambda) = (X \setminus V(g), \frac{\vartheta}{g}) / \sim $.
    Thus there is an open neighbourhood $U$ of $x$ in $X \setminus V(g)$ such that $\vartheta$ vanishes on $U$.
    Similar as before there is $h \in A$ with $h(x) \neq 0$ and $W = X \setminus V(h) \subseteq U$.
    By the isomorphism $\mathcal{O}_X(W) \cong A_h$, there is $n \in \N$ with $h^{n}\vartheta = 0$ in $A$. Since $h \not\in \mathfrak{m}_x$, $h$ is a unit and the image of $\vartheta$ in $A_{\mathfrak{m}_x}$ vanishes, implying $\lambda = 0$.
\end{proof}
\subsubsection{Intersection multiplicities and Bezout's theorem}
\begin{definition}
    Let $R = \mathfrak{k}[X_0,X_1,X_2]$  equipped with its usual grading and let $x \in \mathbb{P}^{2}$.
Let $G \in R_g, H \in R_h$ be homogeneous polynomials with $x \in V(G) \cap V(h)$.
Let $\ell\in R_1$ such that $\ell(x) \neq 0$. Then $x \in U = \mathbb{P}^2 \setminus V(\ell)$ and the rational functions $\gamma = \ell^{-g}G, \eta = \ell^{-h}H$ are elements of $\mathcal{O}_{\mathbb{P}^2}(U)$.
Let $I_x(G,H) \subseteq \mathcal{O}_{\mathbb{P}^2,x}$ denote the ideal generated by $\gamma_x$ and $\eta_x$.


\noindent The dimension $\dim_{\mathfrak{k}}(\mathcal{O}_{X,x} / I_x(G,H)) \text{\reflectbox{$\coloneqq$}} i_x(G,H)$ is called the \vocab{intersection multiplicity} of $G$ and $H$ at $x$. 
\end{definition}
\begin{remark}
    If $\tilde \ell \in R_1$ also satisfies $\tilde \ell(x) \neq 0$, then the image of $\tilde \ell / \ell$ under $\mathcal{O}_{\mathbb{P}^2}(U) \to \mathcal{O}_{\mathbb{P}^2,x}$ is a unit, showing that the image of $\tilde \gamma = \tilde \ell^{-g}  G$ in $\mathcal{O}_{\mathbb{P}^2,x}$ is multiplicatively equivalent to  $\gamma_x$, and similarly for $\eta_x$.
    Thus $I_x(G,H)$ does not depend on the choice of $\ell \in R_1$ with $\ell(x) \neq 0$.
\end{remark}
\begin{theorem}[Bezout's theorem]
    In the above situation, assume that $V(H)$ and $V(G)$ intersect properly in the sense that $V(G) \cap V(H) \subseteq \mathbb{P}^2$ has no irreducible component of dimension $\ge 1$.
    Then 
    \[
        \sum_{x \in V(G) \cap V(H)} i_x(G,H) = gh
    \] 
    Thus, $V(G) \cap V(H)$ has $gh$ elements counted by multiplicity.
\end{theorem}
\printvocabindex
\end{document}
