% !TEX root = main.tex

\chapter{Path Integrals in the Complex Plane}
\section{Paths}

In real analysis, we often consider the definite integral of a function $f: \R \to \R$ from a real number $a$ to another real number $b$.  Of course, on the real line, there is only one `natural' route from $a$ to $b$, namely, along the real line itself.

\begin{comment}
  There are essentially two ways of interpreting `the integral of $f$ between $a$ and $b$;' either integrating
\begin{center}
from $a$ to $b$, that is, $\int_a^b f(t) \ dt$, or \\
from $b$ to $a$, that is, $\int_b^a f(t)\ dt$.
\end{center}
Of course, these integrals have the same absolute value, but with opposite signs.
\end{comment}

In order to make a sensible definition of integrating `between' two complex numbers $z_1$ and $z_2$, we need to take into account the fact that there are typically many routes from $z_1$ to $z_2$.  An interesting case arises when we consider paths with the same start and end-points.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{ch3_path1}
\caption{Some examples of paths between complex numbers.}
\end{figure}

\begin{example}
\label{e:path1}
Consider the line segment $L=[z_1,z_2]$, that is, the straight line segment joining two complex numbers $z_1,z_2 \in \C$.  For an interval $[a,b] \subseteq \R$, define
\[
\gamma : [a,b] \to \C, \quad \gamma (t) = z_1 + \left( \frac{t-a}{b-a} \right) ( z_2 - z_1 ).
\]
Then the line segment $L$ is precisely the range $\gamma \left( [a,b] \right)$ of $\gamma$, with $\gamma (a) = z_1$ and $\gamma (b) = z_2$.

\end{example}

\begin{figure}[H]
\centering
\altgraphics[scale=0.4]{ch3_param1}{ch3_path2}
\caption{The \emph{function} $\gamma:[a,b] \to \C$ describes the \emph{set} $L$, and gives it a direction (i.e. from $\gamma(a)=z_1$ to $\gamma (b)=z_2$).}
\end{figure}

The process of finding $\gamma : [a,b] \to \C$ such that each point on $L$ is of the form $\gamma (t)$, for some $t \in [a,b]$, is called a \emph{parametrisation of $L$}, and we call $t$ the \emph{parameter}.

If we think of $t$ as `time,' then as $t$ increases from $a$ to $b$, $\gamma (t)$ moves from $\gamma (a) = z_1$ to $\gamma (b) = z_2$.  It does so with `velocity'
\begin{align*}
\gamma'(t) &=\ \frac{\text{displacement}}{\text{time}} \\[2ex]
& =\  \frac{\gamma (b) - \gamma (a)}{b-a} = \frac{z_2  - z_1}{b-a}.
\end{align*}
If we think about complex numbers as points or vectors (in $\R^2$), this tells us that $\gamma (t)$ moves in the direction $z_2-z_1$ with constant speed, as you might expect.

We should clarify the definition of the derivative $\gamma'(t)$ of $\gamma(t)$ before we continue.
\begin{definition}
Let $\gamma:[a,b] \to \C$, where $[a,b] \subseteq \R$, be a complex valued function of a real variable.  Then for $t \in [a,b]$, $\gamma$ is said to be differentiable at $t$ if the limit
\[
\rlim{h \to 0}{h \in \R \backslash \set{0}} \frac{\gamma (t+h)-\gamma(t)}{h},
\]
exists.  When it does exist, we denote its value by $\gamma'(t)$, called the \emph{derivative} of $\gamma$ at $t$.
\end{definition}
Note that if $\gamma$ is written in terms of its real and imaginary parts
\[
\gamma(t) = u(t) + i v(t),
\]
where $u,v:[a,b] \to \R$, then we have
\[
\gamma'(t) = u'(t) +i v'(t),
\]
at points $t \in [a,b]$ where these derivatives exist.
%\vspace*{3cm}

\begin{definition}
A \emph{path} is a subset $\Gamma$ of $\C$ for which there is a continuous function $\gamma : [a,b] \to \C$ with
\[
\Gamma = \set{ \gamma (t) : t \in [a,b] }.
\]
The function $\gamma$ is called a \emph{parametrisation} of $\Gamma$, and we call the points $\gamma(a)$ and $\gamma(b)$ the \emph{start-} and \emph{end-points} of $\Gamma$ respectively.
\end{definition}
Note that $\Gamma$ and $\gamma$ are distinct mathematical objects: $\Gamma$ is a set and $\gamma$ is a function.  The function $\gamma$ gives a `direction' to the path $\Gamma$ ; $\Gamma$ is a path \emph{from} $\gamma (a)$ \emph{to} $\gamma(b)$. Thus when we define a path, it is usually necessary to specify a parametrisation, or at least clarify its direction, in order to avoid ambiguity.

There are typically many functions that can be used to paramterise $\Gamma$.
Having said this, it is perfectly acceptable to define $\Gamma$ by specifying a parametrisation $\gamma$.  Thus if we say ``Consider the path defined by the function $\gamma:[a,b] \to \C$,'' then it is understood that $\Gamma = \set{ \gamma (t) : t \in [a,b] }$.

\begin{example}
\label{e:path2}
For the line segment $L=[z_1,z_2]$, there are many different choices of function $\gamma$ that describe $L$.
\begin{itemize}
\item Taking $a=0$ and $b=1$, $L$ is parametrised by
\[ \gamma :[0,1] \to \C,\qquad \gamma(t)=z_1+t(z_2-z_1).\]
\begin{blankbox}
Substituting the relevant values of $t$ we see that this path starts at $\gamma(0)=z_1$ and ends at $\gamma(1)=z_2$. Here we have $\gamma'(t)=z_2-z_1$.
\end{blankbox}
\item We could also use the function
\[
\gamma:[-2,2] \to \C,\ \gamma(t) = z_1 + \left( \frac{t-(-2)}{(2-(-2))} \right) ( z_2-z_1) = \tfrac{1}{2} (z_1+z_2) + t \left( \frac{z_2-z_1}{4} \right).
\]
\begin{blankbox}
This time, $\gamma'(t) = \frac{1}{4} (z_2-z_1)$, which makes sense since it takes 4 units of time for $\gamma(t)$ to move from $z_1$ to $z_2$.
\end{blankbox}
\item Yet another option would be the function
\[
\gamma: [0,1] \to \C, \qquad \gamma (t) = z_1 + t^2 (z_2-z_1),
\]
\begin{blankbox}
which has non-constant velocity $\gamma'(t) = 2t (z_2-z_1)$.

In all three cases, the \emph{set} $L$ is unchanged, but the \emph{function} $\gamma$ is different.
\end{blankbox}
%\vspace*{8cm}
\end{itemize}
\end{example}

%\vspace*{2cm}
\begin{example}
\label{e:path3}
Fix $R>0$ and consider the function
\[
\gamma:[0,\pi] \to \C, \gamma (t) = R \cos (t) + i R \sin (t).
\]
Let us examine the path described by $\gamma$.
\begin{blankbox}
For all $t$,
\[ \abs{R \cos(t)+iR \sin (t)} = \sqrt{R^2\cos^2(t)+R^2\sin^2 (t)} = R,
\]
and thus every point $\gamma(t)$ lies on the circle with centre $0$ and radius $R$.  Thus the given path consists of part of this circle.

To determine which part of the circle, we note that $\gamma$
\begin{align*}
& \text{ starts at } \gamma (0) = R\cos(0)+iR\sin(0)=R,\\
& \text{ `visits' }  \gamma \left( \pi /2 \right) = \polar{R}{\pi / 2} = iR \\
& \text{ end at }  \gamma (\pi) = \polar{R}{\pi} = -R.
\end{align*}
Thus $\gamma$ describes the upper semicircle, centre $0$ and radius $R$, traversed in the anticlockwise direction.
%\vspace*{7cm}
\begin{center}
\includegraphics[scale=0.75]{ch3_semicircle0}
\end{center}
%\vspace*{6cm}
The tangent vector to this path at the point $\gamma (t)$ is given by
\begin{align*}
\gamma '(t)& = -R \sin (t) + i R \cos (t) \\
& = i^2 R \sin (t)+iR \cos (t) \\
& = i \gamma (t).
\end{align*}
Thus the tangent vector to the path at the point $\gamma (t)$ is perpendicular to the position vector $\gamma(t)$ (since multiplication by $i$ corresponds to anticlockwise rotation by $\pi/2$).
\end{blankbox}
\end{example}

Note that in examples~\ref{e:path1},~\ref{e:path2} and~\ref{e:path3}, it is necessary to specify both $\gamma(t)$ and the domain of $\gamma$ in order to describe the path completely.

\begin{definition}
 We say that a parametrisation $\gamma:[a,b] \to \C$ of a path $\Gamma$ is \emph{smooth} if
\begin{enumerate}
\item[(i)] $\gamma$ is differentiable on $[a,b]$,
\item[(ii)] $\gamma'$ is continuous on $[a,b]$, and
\item[(iii)] $\gamma' $ is nonzero on $[a,b]$.
\end{enumerate}
A path $\Gamma$ is called smooth if there exists a smooth parametrisation of $\Gamma$.
\end{definition}

Informally, a smooth path is one with no corners or sharp turns.  The derivative $\gamma'(t)$, regarded as a vector, is the tangent vector to the path $\Gamma$ at the point $\gamma (t)$.

The paths in Examples~\ref{e:path1}, and~\ref{e:path3} are all smooth.

\begin{definition}
Let $\Gamma$ be a path with smooth parametrisation $\gamma: [a,b] \to \C$.  Then the \emph{reverse} of $\Gamma$ is the path $\tilde{\Gamma}$ consisting of the same set of points as $\Gamma$, but traversed in the opposite direction.  The path $\tilde{\Gamma}$ may be parametrised by the function $\tilde{\gamma} : [a,b] \to \C$ where
\[
\tilde{\gamma} (t) = \gamma (a+b-t) \quad \text{for all } t \in [a,b].
\]
\end{definition}

\begin{blankbox}
Note that if we define the start- and end-points of $\Gamma$ to be
 \[ \gamma (a) = z_1, \quad \gamma (b) = z_2 \]
 then
\begin{align*}
\tilde{\gamma} (a) & = \gamma (a+b-a) = \gamma (b) = z_2 \\
\tilde{\gamma} (b) & = \gamma (a+b-b) = \gamma (a) = z_1.
\end{align*}
Thus $\tilde{\Gamma}$ starts at $z_2$ and ends at $z_1$.  Moreover, if $t \in [a,b]$ then $a \leq a+b-t \leq b$, and so $\tilde{\gamma} (t)$ describes a point on the original path $\Gamma$ (i.e. $\tilde{\Gamma}$ is the same set as $\Gamma$).

The tangent vector is given by
\[
\tilde{\gamma} ' (t) = \frac{d}{dt} \gamma (a+b-t) = \gamma'(a+b-t) \frac{d}{dt}(a+b-t) = - \gamma'(a+b-t).
\]
In other words, at any point $z = \tilde{\gamma} (t) = \gamma (a+b-t)$ on the path $\Gamma$, the tangent vector to this path at $z$, when travelling in the reverse direction, points in the opposite direction to the tangent vector obtained when travelling in the original direction, as expected.
\end{blankbox}

\begin{example}
Let us find the reverse of the paths considered in Examples~\ref{e:path2} and~\ref{e:path3}.
\end{example}
\begin{solution}
\begin{itemize}
\item $L=[z_1, z_2 ] $, parametrised by $\gamma:[0,1] \to \C$, $\gamma (t) = z_1 + t ( z_2 - z_1 )$.
It is clear that the reverse of $L$ is the line segment $\tilde{L}=[z_2,z_1]$, i.e. the same line segment taken from $z_2$ to $z_1$.  We may parametrise $\tilde{L}$ with the function $\tilde{\gamma}:[0,1] \to \C$, where
\begin{align*}
\tilde{\gamma} (t) & = \gamma (0+1-t ) \\
& = z_1 + (1-t)(z_2-z_1) \\
& = z_2+t(z_1-z_2).
\end{align*}
On examining the equation for $\tilde{\gamma} (t)$, it is clear that this function describes the path that starts at $z_2$ and travels in the direction $(z_1-z_2)$.
\item  $\Gamma$ the semicircle parametrised by $\gamma:[0,\pi] \to \C$ , $\gamma (t) = R \cos (t) + i R \sin (t)$.

In this case $\tilde{\Gamma}$ is the clockwise semicircular arc from $-R$ to $R$ via $iR$.  We may parametrise $\tilde{\Gamma}$ using $\tilde{\gamma}:[0,\pi] \to \C$, where
\begin{align*}
\tilde{\gamma} (t) & = \gamma ( \pi-t) \\
& = R \cos ( \pi-t)+iR \sin (\pi-t) \\
& = -R \cos (t) + i R \sin (t).
\end{align*}
Note that $\tilde{\gamma} (t)$ is $\gamma (t)$ reflected through the imaginary axis; and thus the path $\tilde{\Gamma}$ is the reflection of the path $\Gamma$ in the imaginary axis.
%\vspace*{9cm}

\end{itemize}
\end{solution}

We shall often need to consider the paths that we obtain from joining smooth paths together.  Note that the resulting path may fail to be smooth, e.g., if there is a `corner' at the point where they meet.

Suppose we have two or more (smooth) paths $\Gamma_1,\ \Gamma_2$ etc., parametrised by $\gamma_1:[a_1,b_1] \to \C$ and $\gamma_2:[a_2,b_2] \to \C$, and suppose that the end-point of $\Gamma_1$ is the same as the start-point of $\Gamma_2$, i.e. $\gamma_1(b_1)=\gamma_2(a_2)$.

The curve obtained from $\Gamma_1 \cup \Gamma_2 $ certainly looks like a path, but how do we make this precise?  In other words, can we describe this curve as the image of some continuous $\gamma: [a,b] \to \C$?
\begin{figure}[H]
\centering
\includegraphics[scale=0.75]{ch3_join4}
\caption{We have two functions $\gamma_1:[a_1,b_1] \to \C$ and $\gamma_2:[a_2,b_2] \to \C$ parameterising $\Gamma_1$ and $\Gamma_2$ respectively.  We want a single continuous function $\gamma:[a,b] \to \C$ parameterising $\Gamma_1 \cup \Gamma_2$}.
\end{figure}
\begin{blankbox}
To do this, we first move $[a_2,b_2]$ to an interval from $b_1$ and then reparametrise $\Gamma_2$.  For $t \in \R$, let $\alpha(t)=  t-(a_2-b_1)$, so that $\alpha$ maps $[a_2,b_2]$ bijectively to $[b_1,b_1+b_2-a_2]$.
\begin{figure}[H]
\centering
\includegraphics[scale=1]{ch3_join5}
\end{figure}
%\vspace*{5cm}
Now, parametrise $\Gamma_2$ using the function $\gamma_{1+2}:[b_1,b_1+b_2-a_2] \to \C$, where
\[
\gamma_{1+2} (t) = \gamma_2 ( \alpha^{-1} (t) ) = \gamma_2 (t+a_2-b_1)
\]
for all $t \in [b_1,b_1+b_2-a_2]$.
\end{blankbox}
\begin{definition}
Suppose that $\Gamma_1$ and $\Gamma_2$ are two paths parametrised by $\gamma_1:[a_1,b_1] \to \C$ and $\gamma_2:[a_2,b_2] \to \C$ respectively, such that $\gamma_1(b_1) = \gamma_2 (a_2)$.  Then we define the \emph{join} of $\Gamma_1$ and $\Gamma_2$ to be the path $\Gamma_1+\Gamma_2$ parametrised by $\gamma_{1+2}:[a_1,b_1+b_2-a_2] \to \C$, where
\[
\gamma_{1+2} (t) = \begin{cases}
\gamma_1 (t) & t \in [a_1,b_1] \\
\gamma_2 (t-b_1+a_2) & t \in [b_1,b_1+b_2-a_2].
\end{cases}
\]
\end{definition}

If we have another path $\Gamma_3$ we can join $\Gamma_3$ to $\Gamma_1+\Gamma_2$ to get $\Gamma_1+\Gamma_2+\Gamma_3$ and so on.

\begin{definition}
A \emph{contour} is a path which is the join of finitely many smooth paths.
\end{definition}

\begin{figure}[H]
\centering
\includegraphics[scale=1]{ch3_contour}
\caption{A contour $\mathcal{C}$ constructed from the join of smooth paths $\Gamma_1,\Gamma_2,\Gamma_3,\Gamma_4$.  Note that $\mathcal{C}$, considered as a path in its own right, need not be smooth.}
\end{figure}

\begin{definition}
Let $\Gamma$ be a smooth path parametrised by $\gamma:[a,b] \to \C$.  Then the \emph{length} $\ell ( \Gamma)$ of $\Gamma$ is defined to be
\[
\ell ( \Gamma ) : = \int_a^b \abs{ \gamma '(t) } \ dt.
\]
For a contour $\mathcal{C} = \Gamma_1+\Gamma_2 + \ldots + \Gamma_n$, where $\Gamma_1,\Gamma_2, \ldots , \Gamma_n$ are smooth, we define the \emph{length} $\ell ( \mathcal{C} )$ of $\mathcal{C}$ to be
\[
\ell ( \mathcal{C} ) = \ell ( \Gamma_1 ) + \ell ( \Gamma_2 ) + \ldots + \ell ( \Gamma_n).
\]
\end{definition}

\begin{example}
Let us compute the length of the line segment $L=[0,3+4i]$ using the parametrisation $\gamma: [0,1] \to \C$ where
\[
\gamma (t) = (3+4i)t, \quad t \in [0,1].
\]
\end{example}
\begin{solution}
We have $\gamma'(t)=3+4i$, with modulus $\abs{\gamma'(t)} = \abs{3+4i}=5$ for all $t$.  Hence
\[
\ell (L) = \int_0^1 \abs{\gamma'(t)} \ dt = \int_0^1 5\ dt = 5,
\]
which is what we would expect given the geometry of this line segment.
\begin{center}
\includegraphics[scale=0.8]{ch3_path6}
\end{center}
%\vspace*{3cm}
\end{solution}
\begin{example}

Now we shall compute the length of the semicircular path $\Gamma$ described by $\gamma : [0,\pi] \to \C$
\[
\gamma (t) = R \cos (t) + i R \sin (t), \quad t \in [0,\pi].
\]
\end{example}
\begin{solution}
We have shown already that for all $t\in [0,\pi]$, $\gamma'(t)=i\gamma(t)$, and so
\[
\abs{\gamma'(t)} = \abs{i \gamma (t)} = \abs{i} \abs{ R \cos(t)+iR\sin(t)} = R
\]
for all such $t$.  It follows that
\[
\ell ( \Gamma ) = \int_0^{\pi} R\ dt = \pi R,
\]
which is again what we would expect for a semicircle with radius $R$.
%\vspace*{8cm}

\end{solution}

\section{The Integral along a path in $\C$}
In this section we will define the integral of a complex function along a smooth path $\Gamma$.  We first recall the following results about integrals of real functions from Foundations.
\begin{theorem}
\label{t:realint}
Let $f,g:[a,b] \to \R$ be two \emph{continuous} real valued functions defined on some interval $[a,b] \subset \R$.  Then the integrals $\int_a^b f(t)\ dt$ and $\int_a^b g(t)\ dt$ both exist and satisfy the following properties:
\begin{enumerate}
\item[(i)] (Linearity) For any $c \in \R$ we have
\[
\int_a^b \left( cf(t) +  g(t) \right)\ dt = c\int_a^b f(t)\ dt +  \int_a^b g(t)\ dt.
\]
\item[(ii)] (Fundamental Theorem of Calculus) If $F:[a,b]$ is an antiderivative for $f$ on $[a,b]$ (that is, $F'(t) = f(t)$ for all $t \in [a,b]$), then
\[
\int_a^b f(t)\ dt = F(b) - F(a),
\]
\item[(iii)] (Monotonicity) If $f(t) \leq g(t)$ for all $t \in [a,b]$ then
\[
\int_a^b f(t)\ dt \leq \int_a^b g(t)\ dt.
\]
\end{enumerate}
\end{theorem}
We shall frequently use the results of Theorem~\ref{t:realint} without reference.

Now let us define the integral of a complex-valued function of a real variable, $g:[a,b] \to \C$ defined on some interval $[a,b] \subset \R$.

\begin{definition}
\label{d:realint}
Let $g:[a,b] \to \C$ be a complex valued function defined on the (real) interval $[a,b]$, and assume that the real and imaginary parts $\Re (g)$ and $\Im (g)$ are both continuous.  Then we define the integral of $g$ from $a$ to $b$ via
\[
\int_a^b g(t)\ dt = \int_a^b \Re (g) (t)\ dt + i \int_a^b \Im (g) (t)\ dt.
\]
\end{definition}
Note that the functions $\Re (g)$ and $\Im (g)$ are both real-valued and continuous, and so we have defined the integral of $g$ in terms of integrals of real functions.  So for example,
\[
\int_0^1 t+i2t\ dt = \int_0^1 t\ dt +i \int_0^1 2t\ dt = \left[ \frac{t^2}{2} \right]_0^1 + i \left[ 2 \frac{t^2}{2} \right]_0^1
= \frac{1}{2}+i.\]

Using the definition of the integral of a complex-valued function of a real variable, together with Theorem~\ref{t:realint}, the results of Theorem~\ref{t:cint1} follow easily.

\begin{theorem}
\label{t:cint1}
Let $f,g:[a,b] \to \C$ be complex valued functions of a real variable defined on the interval $[a,b] \subset \R$, and assume that the real and imaginary parts of both $f$ and $g$ are all continuous.  Then the integrals $\int_a^b f(t)\ dt$ and $\int_a^b g(t)\ dt$ both exist and satisfy the following properties:
\begin{enumerate}
\item[(i)] (Linearity) For any $\alpha \in \C$ we have
\[
\int_a^b \left( \alpha f(t) +  g(t) \right)\ dt = \alpha \int_a^b f(t)\ dt +  \int_a^b g(t)\ dt.
\]
\item[(ii)] (Fundamental Theorem of Calculus) If $F:[a,b] \to \C$ is an antiderivative for $f$ on $[a,b]$ (that is, $F'(t) = f(t)$ for all $t \in [a,b]$), then
\[
\int_a^b f(t)\ dt = F(b) - F(a).
\]
\end{enumerate}
\end{theorem}
Note that there is no way to extend Theorem~\ref{t:realint}(iii) to complex valued functions, as there is no sensible way to interpret the expression $\alpha \leq \beta $ for $\alpha, \beta \in \C$.

\begin{definition}
Let $U \subseteq \C$ be open, $f:U \to \C$ a continuous function and let $\Gamma$ be a smooth path contained in $U$, parametrised by $\gamma :[a,b] \to \C$.  Then the \emph{integral of $f$ along $\gamma$}, which we write as
\[
\int_{\Gamma} f,
\]
is defined via
\begin{equation}
\label{e:pathint}
\int_{\Gamma} f = \int_a^b f \left( \gamma(t) \right) \gamma ' (t)\ dt.
\end{equation}
\end{definition}

\begin{note}
\begin{enumerate}
\item[(i)] The composition $f \left( \gamma (t) \right)$ is a complex valued function of a real variable, hence so is $f \left( \gamma (t) \right) \gamma '(t)$.  It follows that the integral
\[
\int_a^b f \left( \gamma(t) \right) \gamma ' (t)\ dt
\]
on the right hand side of~\eqref{e:pathint} is of the type defined in Definition~\ref{d:realint}.
\item[(ii)] It is sometimes convenient to write
\[
\int_{\Gamma} f \text{ as } \int_{\Gamma} f(z)\ dz \text{ or } \int_{\Gamma} f ( \zeta ) \ d \zeta.
\]
\item[(iii)] The value of the integral depends on both the function $f$ and the path $\Gamma$.  It looks like it should also depend on our choice of parametrisation $\gamma$, but this is not the case.
\end{enumerate}
\end{note}

\begin{example}
\label{e:3paths}
Fix $\alpha$ and $\beta \in \C$ and let $f:\C \to \C$ be defined by
\[
f(z) = \alpha z + \beta \conj{z}.
\]
Let us compute the value of $\int_{\Gamma} f$ along each of the three paths
\begin{align*}
 \Gamma_1&=[0,2]\\
 \Gamma_2&=[2,2+2i] \\
 \Gamma_3 &=[2+2i,0].
\end{align*}
\end{example}
\begin{solution}
Following the method of Example~\ref{e:path2}, parametrise each $\Gamma_j$ by the function $\gamma_j:[0,1] \to \C$, where
\begin{align*}
\gamma_1 (t) & = 2t \\
\gamma_2 (t) &= 2+i 2t \\
\gamma_3 (t) & = (1-t)(2+2i)
\end{align*}
for $t \in [0,1]$.

For the path $\Gamma_1$, we have
\[
f (\gamma_1 (t) ) = \alpha (2t)+\beta (\conj{2t}) = (\alpha+\beta)(2t) \text{ and } \gamma_1'(t) = 2
\]
for all $t \in [0,1]$.  Thus
\begin{align*}
\int_{\Gamma_1} f &= \int_0^1 f( \gamma_1(t)) \gamma_1'(t)\ dt \\
&= \int_0^1 (\alpha+\beta)(2t)(2)\ dt \\
& = 4(\alpha+\beta) \int_0^1 t\ dt = 2(\alpha+\beta).
\end{align*}
For $\Gamma_2$, we have
\begin{align*}
f ( \gamma_2(t)) & = \alpha (2+i2t)+\beta ( \conj{2+i2t} ) \\
& = \alpha (2+i2t)+\beta (2-2it) \\
\shortintertext{ and }
\gamma_2'(t) &= 2i. \\
\shortintertext{ hence }
f ( \gamma_2(t) ) \gamma_2' (t) & = \alpha (2+i2t)+\beta (2-2it) 2i \\
& = -4(\alpha-\beta)t + 4i (\alpha+\beta),
\shortintertext{ and so the required path integral is }
\int_{\Gamma_2} f& = \int_0^1 \left[-4(\alpha-\beta)t + 4i (\alpha+\beta)\right]\ dt \\
& = \left( -4(\alpha-\beta) \int_0^1 t\ dt \right) +i \left( 4(\alpha+\beta) \int_0^1 1\ dt \right) \\
& = -2(\alpha-\beta)+4i(\alpha+\beta).
\end{align*}
Finally, we have
\begin{align*}
f ( \gamma_3 (t) ) & = 2(\alpha+\beta)(1-t)+i 2 (\alpha-\beta)(1-t) \\
\gamma_3'(t) & = -2-2i \\
\shortintertext{ so that }
f ( \gamma_3 (t)) \gamma_3'(t) & = \left[ \alpha (2+2i)+\beta(2-2i) \right] (-2-2i)(1-t) \\
\shortintertext{ giving }
\int_{\Gamma_3} f & = \left[ \alpha (2+2i)+\beta(2-2i) \right] (-2-2i) \int_0^1 (1-t)\ dt \\
& = -4\beta-4\alpha i.
\end{align*}
\end{solution}

\begin{example}
 Find
\[
\int_{\Gamma} f,
\]
where $f$ is the complex function $f(z)=\conj{z}$ and $\Gamma$ is the semicircular path joining $1$ and $-1$ defined by $\gamma : [0, \pi] \to \C$,  $\gamma(t)=\cos(t) + i \sin (t)$.
\end{example}
\begin{solution}
%\begin{framed}
%\vspace{10cm}
%\end{framed}
Here we have
\[
f(\gamma(t)) = \conj{\cos(t)+i\sin(t)} = \cos(t)-i \sin(t),
\]
and $\gamma'(t) = -\sin(t)+i \cos (t)$, so that
\begin{align*}
f(\gamma(t))\gamma '(t) &=  \left(-\sin(t)+i \cos (t) \right) \left( \cos(t)-i \sin(t) \right)\\
& = -\cos(t)\sin(t)+\sin(t)\cos(t) +i \left[ (-\sin(t))(-\sin(t))+\cos(t)\cos(t) \right] \\
& = i.
\end{align*}
Hence
\[
\int_{\Gamma} \conj{z}\ dz = \int_0^{\pi} i\ dt = \pi i.
\]
\end{solution}
We now extend the definition of the integral along a smooth path to the integral along a contour $\mathcal{C}$ which is the join of a finite number of smooth paths $\Gamma_1,\Gamma_2, \ldots , \Gamma_n$ as follows:
\[
\int_{\mathcal{C}} f = \int_{\Gamma_1} f + \int_{\Gamma_2} f + \ldots + \int_{\Gamma_n} f
\]
\begin{example}
\label{e:triangle}
Compute the value of $\int_{\mathcal{C}} f$ where $f=\alpha z + \beta \conj{z}$ and $\mathcal{C}=\Gamma_1 + \Gamma_2 + \Gamma_3$ from Example~\ref{e:3paths}.
\end{example}

\begin{solution}
\begin{center}
\begin{tikzpicture}
\draw[thick,gray,->] (-2,0) -- (3,0) ;
\draw[thick,gray,->] (0,-1) -- (0,3) ;
\draw[thick] (0,0) -- node[midway,below,font=\footnotesize]{$\Gamma_1$} (2,0) node[below,font=\footnotesize]{$2$};
\draw[thick] (2,0) -- node[midway,right,font=\footnotesize]{$\Gamma_2$} (2,2) node[right,font=\footnotesize]{$2+2i$};
\draw[thick] (2,2) -- node[midway,left,font=\footnotesize]{$\Gamma_3$} (0,0);
\end{tikzpicture}
\end{center}
Here we have
\begin{align*}
\int_{\mathcal{C}} f & = \int_{\Gamma_1} f + \int_{\Gamma_2} f + \int_{\Gamma_3} f \\
& = 2(\alpha+\beta)-2(\alpha-\beta)+4i(\alpha+\beta)\\
&-4\beta-4\alpha i \\
& = i 4 \beta.
\end{align*}

Note that the function $f(z) =\alpha z + \beta \conj{z}$ is not differentiable anywhere in $\C$ unless $\beta = 0$.  Moreover, if $\beta = 0$ then $f(z)=\alpha z$ is holomorphic on $\C$ and $\int_{\mathcal{C}} f = 0$ for the contour $\mathcal{C}=\Gamma_1+\Gamma_2+\Gamma_3$ in the preceding example, while $\int_{\mathcal{C}} f \neq 0$ when $\beta \neq 0$.  This is not a coincidence, as we shall see in subsequent sections.
\end{solution}
\section{The Fundamental Theorem of Complex Calculus}
\begin{definition}
A set $S \subseteq \C$ is \emph{connected} if given any pair of points $z_1,z_2 \in S$, there is a contour contained in $S$ that starts at $z_1$ and ends at $z_2$. A \emph{region} $\mathcal{R}$ is a non-empty, open, connected subset of $\C$.
\end{definition}
\begin{figure}[H]
\centering
\blankgraphics[scale=0.5]{ch3_connected} \qquad \blankgraphics[scale=0.5]{ch3_notconnected}
\end{figure}
\begin{definition}
Let $\mathcal{R}$ be a region and $f:\mathcal{R} \to \C$ a function defined on $\mathcal{R}$.  A function $F:\mathcal{R} \to \C$ is called an \emph{antiderivative for $f$ on $\mathcal{R}$} if
\begin{enumerate}
\item[(i)] $F$ is holomorphic on $\mathcal{R}$ and
\item[(ii)] $F'(z)=f(z)$ for all $z \in \mathcal{R}$.
\end{enumerate}
\end{definition}
\begin{example}
Find antiderivatives for the functions
\begin{enumerate}
\item[(i)] $f(z)=\alpha z + \beta$ (where $\alpha, \beta \in \C$ are fixed) on the region $\C$.
\item[(ii)] $f(z) = \dfrac{1}{(1+iz)^2}$ on the region $\C \backslash \set{i}$.
\end{enumerate}
\end{example}
\begin{solution}
\begin{enumerate}
\item[(i)] The function $F$ defined by $F(z) = \frac{\alpha}{2} z^2+\beta z$ is an antiderivative for $f$ on $\C$, as $F$ is holomorphic on $\C$ with $F'(z)=f(z)$ for all $z$.
\item[(ii)] The function $F:\C \backslash \set{i} \to \C$ defined by
\[
F(z)=\frac{i}{1+iz}
\]
is an antiderivative for $f$ on $\C \backslash \set{i}$ by the quotient rule.
\end{enumerate}
\end{solution}
\begin{question}
Does the function $f(z) = \conj{z}$ have an antiderivative on $\C$?  We will answer this question shortly.
\end{question}
%\vspace*{2cm}
We know already that $f(z)=\conj{z}$ cannot be the antiderivative of any function $g:\C \to \C$ as $f$ is not differentiable anywhere.
\begin{theorem}[Fundamental Theorem of Complex Calculus]
\label{t:ftc}
Let $f$ be continuous on a region $\mathcal{R}$ suppose that $F$ is an antiderivative for $f$ on $\mathcal{R}$.  If $\mathcal{C}$ is a contour contained in $\mathcal{R}$, then we have
\[
\int_{\mathcal{C}} f = F( z_2)-F(z_1)
\]
where $z_1$ and $z_2$ are the start- and end-points of $\mathcal{C}$ respectively.
\end{theorem}
\begin{proof}

Let us first consider the case where $\mathcal{C}$ consists of a single smooth path $\Gamma$, parametrised by $\gamma:[a,b] \to \C$.  Since $F$ is an antiderivative for $f$ on $\mathcal{R}$ and $\gamma$ is smooth, the Chain Rule gives
\[
\frac{d}{dt} \left[ F( \gamma(t)) \right] = F'(\gamma(t))\gamma'(t) = f(\gamma(t))\gamma ' (t).
\]
Hence
\begin{align*}
\int_{\Gamma} f & = \int_a^b f(\gamma(t)) \gamma' (t)\ dt & \\
& = \int_a^b \frac{d}{dt} \left[ F( \gamma (t) ) \right]\ dt & \\
& = F ( \gamma (b) ) - F ( \gamma (a) ) & \text{ by Theorem~\ref{t:cint1}(ii)} \\
& = F(z_2)-F(z_1).
\end{align*}

%\vspace*{14cm}

Now, if $\mathcal{C}$ is the join of $n$ smooth paths $\mathcal{C} = \Gamma_1+\ldots + \Gamma_n$, let $w_{j-1}$ and $w_j$ denote the start- and end-points of $\Gamma_j$ respectively, so that $w_0=z_1$ and $w_n=z_2$.  Then

\begin{align*}
\int_{\mathcal{C}} f & = \int_{\Gamma_1} f + \int_{\Gamma_2} f + \ldots + \int_{\Gamma_n} f \\
& = \left( F(w_1)-F(w_0) \right) + \left( F(w_2)-F(w_1) \right) + \ldots + \left( F(w_n)-F(w_{n-1}) \right) \\
& = F(w_n)-F(w_0) = F(z_2)-F(z_1).
\end{align*}

\end{proof}
The Fundamental Theorem of Complex Calculus tells us that if an antiderivative $F$ for $f$ on $\mathcal{R}$ is known, then a potentially complicated contour integral $\int_{\mathcal{C}} f$ may be evaluated by simply computing the values of $F(z_1)$ and $F(z_2)$.

\begin{example}
\label{e:2paths}
Let $\alpha \in \C$ be fixed and let $f(z)=\alpha z$ for all $z \in \C$.  We shall evaluate $\int_{\mathcal{C}} f$ along the contour $\mathcal{C}=\Gamma_1 + \Gamma_2$ where $\Gamma_1=[0,2]$ and $\Gamma_2 = [2,2+2i]$ using Theorem~\ref{t:ftc}.
\end{example}
\begin{solution}
The function $F$ defined by $F(z)=\frac{\alpha}{2} z^2$ is an antiderivative for $f$ on $\C$.
  The start- and end-points of $\mathcal{C}$ are $0$ and $2+2i$ respectively.  Hence by the Fundamental Theorem of Complex Calculus,
\begin{align*}
\int_{\mathcal{C}} f &= F(2+2i)-F(0) \\
& = \frac{\alpha (2+2i)^2}{2} - 0 \\
& = i 4 \alpha.
\end{align*}
\end{solution}

\begin{example}
With $f,\Gamma_1$ and $\Gamma_2$ as in Example~\ref{e:2paths} and let $\Gamma_3 = [2+2i,0]$.  We will calculate $\int_{\mathcal{C}} f$ where $\mathcal{C}=\Gamma_1+\Gamma_2+\Gamma_3$.
\end{example}
\begin{solution}
This time $\mathcal{C}$ starts and ends at $0$, so that
\[
\int_{\mathcal{C}} f = F(0) - F(0) = 0.
\]
\end{solution}

\begin{example}
Let $\Gamma_1$ be the path consisting of the arc of the circle of radius $2$, centre $0$, traversed in the anticlockwise direction from $2$ to $-2$ and let $\Gamma_2$ be the line segment $[-2,-i]$.  Calculate
\[
\int_{\mathcal{C}} f,
\]
where $f(z) = \dfrac{1}{(1+iz)^2}$ and $\mathcal{C} = \Gamma_1+ \Gamma_2$.
\end{example}
\begin{solution}
\begin{center}
\includegraphics[scale=0.5]{ch3_ftc2}
\end{center}
The contour $\mathcal{C}$ is contained in the region $\C \backslash \set{i}$, and $F(z) = \frac{i}{(1+iz)}$ is an antiderivative for $f$ on this region.  Since $\mathcal{C}$ starts at $2$ and ends at $-i$, we have
\begin{align*}
\int_{\mathcal{C}} f & = F(-i)-F(2) \\
& = \frac{i}{2} - \frac{i}{1+2i} \\
& = - \frac{2}{5} +i \frac{3}{10}.
\end{align*}
\end{solution}
\begin{theorem}[Contour Independence]
\label{t:contint}
Let $f$ be continuous on $\mathcal{R}$ and let $F$ be an antiderivative for $f$ on $\mathcal{R}$.  If $\mathcal{C}_1$ and $\mathcal{C}_2$ are two contours inside $\mathcal{R}$ with the same start- and end-points, we have
\[
\int_{\mathcal{C}_1} f = \int_{\mathcal{C}_2} f.
\]
\end{theorem}
\begin{proof}
Let $z_1$ be common the start-point of both $\mathcal{C}_1$ and $\mathcal{C}_2$, and $z_2$ the end-point.  Then by Theorem~\ref{t:ftc},
\[
\int_{\mathcal{C}_1} f = F(z_2)-F(z_1) = \int_{\mathcal{C}_2} f.
\]
\end{proof}
One application of Theorem~\ref{t:contint} is that it allows us to replace a potentially complicated contour integral along $\mathcal{C}_1$ with an easier one alone $\mathcal{C}_2$.

\begin{definition}
A contour $\mathcal{C}$ is called a \emph{closed contour} if its end point is the same as its start point.
\end{definition}
\begin{theorem}[Antiderivatives and Closed Contours]
\label{t:closed}
Let $f$ be continuous on $\mathcal{R}$ and let $F$ be an antiderivative for $f$ on $\mathcal{R}$.  If $\mathcal{C}$ is any closed contour inside $\mathcal{R}$ then
\[
\int_{\mathcal{C}} f = 0.
\]
\end{theorem}
\begin{proof}
This time $\mathcal{C}$ has the same start- and end-point $z_1$.  Hence
\[
\int_{\mathcal{C}} f = F(z_1)-F(z_1) = 0.
\]
\end{proof}

\begin{question}
Now, do we know whether or not $f(z)=\conj{z}$ has an antiderivative on $\C$?  Does Example~\ref{e:triangle} tell you anything?
\end{question}
%\vspace*{5cm}
\begin{answer}
 The function $f(z) = \conj{z}$ is a special case of the function considered in Example~\ref{e:triangle}, with $\alpha =0$ and $\beta =1$.  If $\mathcal{C}$ is the closed triangular contour of that example, then we have seen that
\[
\int_{\mathcal{C}}  \conj{z}\ dz = 4i \neq 0.
\]
Thus as a consequence of Theorem~\ref{t:closed}, we see that $f(z)=\conj{z}$ cannot have an antidervative on $\C$.
\end{answer}
\begin{theorem}[Zero Derivative Theorem]
Let $F$ be holomorphic on a region $\mathcal{R}$ and suppose that $F'(z)=0$ for all $z \in \mathcal{R}$.  Then $F$ is constant on $\mathcal{R}$.
\end{theorem}
\begin{proof}
Let $z_1,z_2 \in \mathcal{R}$.  We will show that $F(z_1)=F(z_2)$.

Since $\mathcal{R}$ is connected there is a contour $\mathcal{C}$ in $\mathcal{R}$ that starts at $z_1$ and ends at $z_2$.  Hence by Theorem~\ref{t:ftc},
\[
F(z_2)-F(z_1) = \int_{\mathcal{C}} F'(z)\ dz = \int_{\mathcal{C}} 0\ dz = 0.
\]
In other words $F(z_1)=F(z_2)$.  Since this is true for all $z_1,z_2 \in \mathcal{R}$, $F$ must be constant on $\mathcal{R}$.
\end{proof}

%\vspace*{12cm}


\section{Monte Carlo Simulation} \label{sec:4}
\thispagestyle{plain} % surpress header on first page

Because QBSM has no closed-form expression, they must be assessed numerically through Monte Carlo(MC) simulation\citep{fishman1996MonteCarloConcepts}. MC simulation generates random samples from a probability distribution, and the problem becomes deterministic for each sample. Solving these deterministic problems allows us to obtain statistical information regarding the exact solutions, such as the mean or variance. However, MC approaches are renowned for their slow convergence, with an average coverage rate of $\sqrt N$(N stands for the sample size). This means that, to get more precise outcomes, a large number of samples are required.
Although various improved MC methods have been developed, such as Latin sampling methods\citep{loh1996LatinHypercubeSampling} and Quasi-Monte Carlo(QMC) methods\citep{niederreiter1992RandomNumberGeneration}, there are still certain limits to it. \\

\noindent
In \cite{kucherenko2017DifferentNumericalEstimators}, the performance of several numerical schemes based on sampling strategies was compared. It is documented that the double loop reordering(DLR) technique outperforms all other methods, especially when combined with QMC sampling. In this paper, by integrating the two MC estimators provided by \cite{kucherenko2019QuantileBasedGlobal} and the procedure improved by \cite{song2021QuantileSensitivityMeasures}, we list the following steps to estimate QBSM in our study:

\begin{itemize}
\item \textbf{Step 1:} To obtain  $q_{Y \mid \Theta_{i}}$:

\begin{enumerate}[label=(\arabic*),ref=\arabic*]
  \item Generate $N$ points  $\boldsymbol{\Theta}^{(k)}=\left\{\Theta_{1}^{(k)}, \Theta_{2}^{(k)}, \cdots, \Theta_{d}^{(k)}\right\}, k=1,2, \cdots, N$ according to the joint PDF $ \rho (\boldsymbol{\Theta)}$.

  \item Compute the unconditional values of output $Y^{(k)}=g\left(\boldsymbol{\Theta}^{(k)}\right), k=1, 2, \dots, N$, then reorder them in ascending order $\left\{Y^{(1-s t)}, Y^{(2-\mathrm{nd})}, \cdots, Y^{(N-\mathrm{th})}\right\}^{\mathrm{T}}$.

  \item \label{itm:2} Decide the $\alpha$-th output value as unconditional quantile $q_Y(\alpha)$: $q_{Y}^{(N)}(\alpha)=Y^{(\alpha N-\text { th })}$.

\end{enumerate}

\item \textbf{Step 2:} To obtain  $q_{Y \mid \Theta_{i}}(\alpha)$:

\begin{enumerate}[label=(\arabic*),ref=\arabic*]
  \item Generate $M$ points  $\left\{\theta_{i}^{(1)}, \theta_{i}^{(2)}, \cdots, x_{i}^{(M)}\right\}^{\mathrm{T}}$ according to the joint PDF $\rho (\Theta)$, which should be independent from $\boldsymbol{\Theta}^{(k)}$

  \item Fix $\Theta_i$ st $\Theta_i = \theta_i^{(k)}, k= 1, \dots, M$, and get N conditional points

  $$
    \Theta^{(k)}=\left\{\Theta_{1}^{k}, \cdots, \Theta_{i-1}^{k}, x_{i}^{(k)}, \Theta_{i+1}^{k}, \cdots, X_{d}^{k}\right\}, k=1,2, \cdots, N
  $$

  \item Compute conditional values of $Y_{x_{i}^{(k)}}^{(k)}=g\left(\boldsymbol{X}^{(k)} \mid X_{i}=x_{i}^{(k)}\right)$, and reorder them in ascending order $\left\{Y_{x_{i}^{(k)}}^{(1-\mathrm{st})}, Y_{x_{i}^{(k)}}^{(2-\mathrm{nd})}, \cdots, Y_{x_{i}^{(k)}}^{(N-\mathrm{th})}\right\}$

  \item \label{itm:2}  Decide the $\alpha$-th output value as conditional quantile: $q_{Y \mid x_{i}^{(k)}}(\alpha)=Y_{x_{i}^{(k)}}^{(\alpha N-\mathrm{th})}$

\end{enumerate}

\item \textbf{Step 3}: To calculate QBSM accroding to \eqref{eq:13} and \eqref{eq:14}

\item \textbf{Step 4}: To calculate normalized QBSM accroding to \eqref{eq:16} and \eqref{eq:17}

\end{itemize}

\noindent
To perform DLR method, $M$ typically be set between 50 to 100\citep{kucherenko2017DifferentNumericalEstimators}. To perform brutal force simulation,
simply set M = N. The number function evaluation for a fixed $i$ is equal to $N=(dM + 1)$. In general, MC simulation performs efficiently for the calculation of QBSM. However, when deal with extreme quantiles, for instance, $\alpha \le 0.05$, the performane can be disappointing.


%% ****** Start of file aapmtemplate.tex ****** %
%%
%%   This file is part of the files in the distribution of AAPM substyles for REVTeX4.2.
%%   Version 4.2a of January 28, 2015.
%%
%
% This is a template for producing documents for use with
% the REVTEX 4.2 document class and the AAPM substyles.
%
% Copy this file to another name and then work on that file.
% That way, you always have this original template file to use.

\documentclass[%
 draft,
 aapm,
 mph,%
 amsmath,amssymb,
%preprint,%
 reprint,%
%author-year,%
%author-numerical,%
]{revtex4-2}

\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{upgreek}

\usepackage{siunitx}

\usepackage{mhchem}

\usepackage{xspace}

% Defining string as labels of certain blocks.

\begin{document}

% Use the \preprint command to place your local institutional report number
% on the title page in preprint mode.
% Multiple \preprint commands are allowed.
%\preprint{}

\title{Fuel-switching carbon prices — a bit of algebra} %Title of paper

% repeat the \author .. \affiliation  etc. as needed
% \email, \thanks, \homepage, \altaffiliation all apply to the current author.
% Explanatory text should go in the []'s,
% actual e-mail address or url should go in the {}'s for \email and \homepage.
% Please use the appropriate macro for the type of information

% \affiliation command applies to all authors since the last \affiliation command.
% The \affiliation command should follow the other information.

\author{Philipp C. Verpoort}
%\email[]{Your e-mail address}
%\homepage[]{Your web page}
%\thanks{}
%\altaffiliation{}

% Collaboration name, if desired (requires use of superscriptaddress option in \documentclass).
% \noaffiliation is required (may also be used with the \author command).
%\collaboration{}
%\noaffiliation

%\date{\today}

\input{cmds}

\maketitle %\maketitle must follow title, authors, abstract

% Body of paper goes here. Use proper sectioning commands.
% References should be done using the \cite, \ref, and \label commands
\section{Formular for switching price}

The total cost $C_X$ of a fuel $X$ is defined as
\begin{equation}
    C_X = C^0_X + \prc * e_X \punc,
\end{equation}
where $C^0_X$ is the direct cost (independent of carbon cost) in \si{\$}, $\prc$ is the carbon price in \si{\$\per\tonne_{\ce{CO2}}}, and $e_X$ are the emissions (or carbon intensity) in \si{\tonne_{\ce{CO2}}\per\kWh}. We define the $Y$-to-$X$ fuel-switching cost $\Delta C_{YX}$ (i.e.~the cost incurred in switching from fuel $Y$ to fuel $X$) as
\begin{align}
    \Delta C_{YX} &= C_X - C_Y \\
                  &= C^0_X - C^0_Y + \prc * (e_X - e_Y) \punc.
\end{align}
The $Y$-to-$X$ fuel-switching carbon price $\prYX$ (i.e.~carbon price above which it is economically incentivised to switch from fuel $Y$ to fuel $X$) is defined as
\begin{align}
                    & \Delta C_{YX} (\prc = \prYX) = 0 \punc, \\
\intertext{and hence it is}
                    &~~~ C^0_X - C^0_Y + \prYX * (e_X - e_Y) = 0 \\
  \Leftrightarrow   &~~~ \prYX = \frac{C^0_X - C^0_Y}{e_Y - e_X} \punc.
\end{align}

\section{Green-blue switching}

We now consider the fuels $X$ and $Y$ to be one of $\{g, b, r\}$, which refer to green, blue, and reference (e.g.~natural gas). In that case we have three switching prices:
\begin{align}
    \prg    &=     \frac{C^0_g - C^0_r}{e_r - e_g} \punc,\\
    \prb    &=     \frac{C^0_b - C^0_r}{e_r - e_b} \punc,\\
    \prbg   &=     \frac{C^0_g - C^0_b}{e_b - e_g} \punc.
\end{align}
We can rewrite the equations for $\prg$ and $\prb$ as
\begin{align}
    C^0_g &= C^0_r + \prg * (e_r - e_g) \quad\text{and} \\
    C^0_b &= C^0_r + \prg * (e_r - e_b) \punc,
\end{align}
and hence it is
\begin{align}
    C^0_g - C^0_b &= \prg (e_r - e_g) - \prb (e_r - e_b) \\
                  &= \prb \, e_b - \prg \, e_g + (\prg - \prb) \, e_r \punc.
\end{align}
We can substitute that back into the equation from above for $\prbg$, which yields:
\begin{align}
    \prbg &= \frac{\prb \, e_b - \prg \, e_g + (\prg - \prb) \, e_r}{e_b - e_g} \\
    &= \frac{\prb \, e_b + \prb \, e_g - \prb \, e_g - \prg \, e_g}{e_b - e_g}\\ &~~~~+ \frac{(\prg - \prb) \, e_r}{e_b - e_g} \\
    &= \prb + (\prb - \prg) \frac{e_g}{e_b-e_g} \\ &~~~~+ (\prg - \prb) \frac{e_r}{e_b-e_g} \\
    &= \prb + (\prg - \prb) \underbrace{\frac{e_r - e_g}{e_b - e_g}}_{=: \alpha} \\
    &= \prb + \alpha * (\prg - \prb) \punc.
\end{align}

\section{Possible cases}
Let us assume that green hydrogen is always cleaner than blue and that both are cleaner than the reference (e.g.~natural gas). Hence, it is $e_g < e_b < e_r$. From $e_r > e_b \Leftrightarrow e_r - e_g > e_b - e_g$ and with $e_b < e_g$ we find that $\alpha > 1$. We therefore find the follwing cases depending on the relative values of $\prg$ and $\prb$:

\vspace{.2cm}
\noindent\textbf{Case 1: $\prg > \prb$}
\begin{align}
    \prbg &~=~ \prb + \alpha * \underbrace{(\prg - \prb)}_{>\,0} \\
            & \overset{\alpha>1}{>} \prb + \prg - \prb = \prg \punc.
\end{align}
Hence: $\prbg > \prg > \prb$.

\vspace{.2cm}
\noindent\textbf{Case 2: $\prg < \prb$}
\begin{align}
    \prbg &~=~ \prb + \alpha * \underbrace{(\prg - \prb)}_{<\,0} \\
            & \overset{\alpha>1}{<} \prb + \prg - \prb = \prg \punc.
\end{align}
Hence: $\prbg < \prg < \prb$.

\vspace{.2cm}
\noindent\textbf{Case 3: $\prg = \prb$}
\begin{align}
    \prbg &~=~ \prb + \alpha * \underbrace{(\prg - \prb)}_{=\,0} = \prb\punc.
\end{align}
Hence: $\prbg = \prb = \prg$.

\end{document}
%
% ****** End of file aapmtemplate.tex ******


\section{Introduction to Artificial Neural Network}

\subsection{Autodiff}

\cindex{Autodiff} is neither a numerical nor symbolic differentiation. It use numerical method calculation and use symbolic rules for differentiation, so it is partly symbolic and partly numerical. See \cite{GunesBaydin2018} for more details.

One example is $f(x_1, x_2) = \log{x_1} + x_1 x_2 - \sin{x_2}$. The computation graph is:

\begin{figure}[H]
\centering
\begin{tikzpicture}
    \node (x2) at (0,0) {$x_2$};
    \node (x1) at (0,2) {$x_1$};
    \node (v0) at (3,0) {$v_0 = x_2$};
    \node (v_1) at (3,2) {$v_{-1} = x_1$};
    \node (v2) at (6,1) {$v_2 = v_{-1} v_0$};
    \node (v1) at (6,2) {$v_1 = \log{v_{-1}}$};
    \node (v3) at (9,0) {$v_3 = \sin{v_0}$};
    \node (v4) at (9,2) {$v_4 = v_1 + v_2$};
    \node (v5) at (12,1) {$v_5 = v_4 + v_3$};
    \node (final) at (15,1) {$f(x_1,x_2)$};
    \draw [-latex] (x2) -- (v0);
    \draw [-latex] (v0) -- (v3);
    \draw [-latex] (v3) -- (v5);
    \draw [-latex] (x1) -- (v_1);
    \draw [-latex] (v_1) -- (v1);
    \draw [-latex] (v1) -- (v4);
    \draw [-latex] (v4) -- (v5);
    \draw [-latex] (v_1) -- (v2);
    \draw [-latex] (v2) -- (v4);
    \draw [-latex] (v0) -- (v2);
    \draw [-latex] (v5) -- (final);
\end{tikzpicture}
\caption{$f(x_1, x_2) = \log{x_1} + x_1 x_2 - \sin{x_2}$}
\end{figure}

In general there are two autodiff methods: forward mode and backpropagation. In forward mode, the derivative is the intermediary nodes against all input nodes while in backpropagation the derivative is the final node against all intermediary nodes.

\subsubsection{Forward Mode}

There are $1+n$ passes in forward mode:
\begin{enumerate}
    \item a forward evaluation of all node values. Table \ref{forwardprimaltracetable} shows the forward example.
    \item $n$ forward derivative calculation for all $n$ input features. For the $i$-th input feature, the derivatives of all $\dot{v}$ is calculated in Table \ref{forwardtangenttrace}.
\end{enumerate}

\begin{table}[H]
\centering
    \begin{tabular}{lll}
        $v_{-1}$ & $= x_1$ & $ = 2$ \\
        $v_0$ & $= x_2$ & $=5$ \\
        $v_1$ & $=\log{v_{-1}}$ & $= \log{2}$ \\
        $v_2$ & $=v_{-1} \times v_0$ & $= 2 \times 5 $\\
        $v_3$ & $=\sin{v_0}$ & $=\sin{5}$\\
        $v_4$ & $=v_1 + v_2$ & $=0.693+10$ \\
        $v_5$ & $=v_4 - v_3$ & $=10.693 + 0.959$ \\
        $y$ & $=v_5$ & $=11.652$ \\
    \end{tabular}
\caption{Forward Primal Trace}
\label{forwardprimaltracetable}
\end{table}

\begin{table}[H]
\centering
    \begin{tabular}{lll}
        $\dot{v}_{-1}$ & $= \dot{x}_1$ & $ = 1$ \\
        $\dot{v}_0$ & $= \dot{x}_2$ & $=0$ \\
        $\dot{v}_1$ & $= \displaystyle \frac{\dot{v}_{-1}}{v_{-1}}$ & $=\displaystyle \frac{1}{2}$ \\
        $\dot{v}_2$ & $=\dot{v}_{-1} \times v_0 + v_{-1} \times \dot{v}_0$ & $= 1 \times 5 + 0 \times 2$\\
        $\dot{v}_3$ & $=\dot{v}_0 \times \cos{v_0}$ & $=0 \times \cos{5}$ \\
        $\dot{v}_4$ & $=\dot{v}_1 + \dot{v}_2$ & $= 0.5 + 5$ \\
        $\dot{v}_5$ & $=\dot{v}_4 - \dot{v}_3$ & $= 5.5 - 0$ \\
        $\dot{y}$ & $=\dot{v}_5$ & $= 5.5$ \\
    \end{tabular}
\caption{Forward Tangent (Derivative) Trace}
\label{forwardtangenttrace}
\end{table}

Forward mode is expensive because it needs to run a pass for each input feature.

\subsubsection{Backpropogation}

\cindex{Backpropagation} only needs 2 passes over the calculation graph:
\begin{enumerate}
    \item a forward evaluation of all node values. The same as forward mode. Table \ref{forwardprimaltracetable} shows the forward example.
    \item a backward derivative calculation of all nodes in calculation graph. Table \ref{reverseadjointtrace} shows the backward example.
\end{enumerate}

In the backward derivative calculation, all derivatives are calculated against final result $y$. According to calculas, we have:
\begin{equation}
    \dpd{y}{v_0} = \dpd{y}{v_2} \dpd{v_2}{v_0} + \dpd{y}{v_3} \dpd{v_3}{v_0}
\end{equation}

Let $\bar{v} = \pd{y}{v}$. We have:
\begin{equation}
    \bar{v}_0 = \bar{v}_2 \dpd{v_2}{v_0} + \bar{v}_3 \dpd{v_3}{v_0}
\end{equation}

So the final result could calculated by backward propagation. Table \ref{reverseadjointtrace} gives an example.

\begin{table}[H]
\centering
    \begin{tabular}{llll}
        $\bar{v}_5$ & $=\bar{y}$ && $= 1$ \\
        $\bar{v}_4$ & $=\bar{v}_5 \pd{v_5}{v_4}$ & $=\bar{v}_5 \times 1$ & $=1$ \\
        $\bar{v}_3$ & $=\bar{v}_5 \pd{v_5}{v_3}$ & $=\bar{v}_5 \times (-1)$ & $=-1$ \\
        $\bar{v}_2$ & $=\bar{v}_4 \pd{v_4}{v_2}$ & $=\bar{v}_4 \times 1$ & $=1$ \\
        $\bar{v}_1$ & $=\bar{v}_4 \pd{v_4}{v_1}$ & $=\bar{v}_4 \times 1$ & $=1$ \\
        $\bar{v}_0$ & $=\bar{v}_3 \pd{v_3}{v_0}$ & $=\bar{v}_3 \times \cos{v_0}$ & $=-0.284$ \\
        $\bar{v}_{-1}$ & $=\bar{v}_2 \pd{v_2}{v_{-1}}$ & $=\bar{v}_2 \times v_0$ & $=5$ \\
        $\bar{v}_0$ & $=v_0 + \bar{v}_2 \pd{v_2}{v_0}$ & $=\bar{v}_0 +\bar{v}_2 \times v_{-1}$ & $=1.716$ \\
        $\bar{v}_{-1}$ & $=v_{-1} + \bar{v}_1 \pd{v_1}{v_{-1}}$ & $=\bar{v}_{-1} + \frac{\bar{v}_1}{v_{-1}}$ & $=5.5$ \\
    \end{tabular}
\caption{Reverse Adjoint (Derivative) Trace}
\label{reverseadjointtrace}
\end{table}

% Gradient Descent
\section{Gradient Descent}

\subsection{Gradient Descent Classification}

\cindex{Gradient Descent} is a numeric optimization method to calculate the minimum value of a function. For a give function $f(x)$ with gradient everywhere, if we choose $\alpha$ small enough, it is possible that $f(x') < f(x)$ where:

\begin{equation}\label{gradientdescentdefinition}
    x' = x - \alpha \nabla_x f
\end{equation}

$\alpha$ is called \cindex{learning rate}. Please be noted that the $x$ here is a vector of all input samples.

\cindex{Batch Gradient Descent} calculate the gradient of the cost function for the entire training set. So it is slow, and sometimes cannot be fit into the main memory.

\cindex{Stochastic Gradient Descent} calculate the gradient for every single training sample. So it fluctuate.

\cindex{Mini-batch Gradient Descent} calculate the gradient for every batch of $n$ samples. It could use GPU to accelerate the training, and it is less volatile than stochastic gradient descent.

So mini-batch gradient descent is the best of all choices. However it still has the following limitations:
\begin{enumerate}
    \item The learning rate cannot be too small or too big.
    \item \cindex{learning rate schedule} is used to gradually reduce the learning rate, which mimics the \cindex{annealing}. However the training data may not match the learning schedule.
    \item One learning rate is applied to all data. The data could be sparse or dense.
    \item Local minimum is usually not a problem. The real problem is the plateau around \cindex{saddle points}. The gradient is flat and takes long time to move away.
\end{enumerate}

So optimization algorithms is needed for an efficient gradient descent calculation.

\subsection{Gradient Descent Optimization Algorithms}

The idea of optimizing gradient descent is to change $\alpha \nabla_x f$ in Equation \eqref{gradientdescentdefinition}. We can change all of them, such as in Momentum and NAG algorithm, or change $\alpha$, such as in Adagrad, Adadelta, RMSprop, or change $\nabla_x f$, such as in Adam, AdaMax, Nadam. The popular optimization algorithms are summarized in \cite{Ruder2016}. The relationship among all these optimization algorithm is in Figure ~\ref{gradientdescentoptimizationalgorithmrelationship}.

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{images/relation_among_gradient_descent}
    \caption{Relation among Gradient Descent Algorithms}
    \label{gradientdescentoptimizationalgorithmrelationship}
\end{figure}

\subsubsection{Momentum}

\cindex{Momentum}\cite{Qian1999} takes a weighted average of all gradient:
\begin{equation}
    \begin{aligned}
        \theta_{t+1} &= \theta_t - m_t \\
        m_t &= \beta m_{t-1} + (1-\beta) \nabla_{\theta_t} J(\theta_t)
    \end{aligned}
\end{equation}

$\alpha=0.9$ for most of the cases. The momentum term increases if gradients point in the same direction and reduces updates when gradients change direction. So it has momentum when moving towards the same direction, and it converges fast.

\subsubsection{NAG}

\cindex{Nesterov Accelerated Gradient}\cite{NESTEROV1983}, or \cindex{NAG}, is a look ahead calculation. Since $\theta_t$ will be reduced by a gradient every time: $\theta_{t+2} = \theta_{t+1} - m_{t+1} = \theta_t - m_t - m_{t+1}$, it replaces $\nabla_{\theta_t} J(\theta_t)$ by $\nabla_{\theta_t} J(\theta_t - \beta m_{t-1})$:
\begin{equation}
    \begin{aligned}
        \theta_{t+1} &= \theta_t - m_t \\
        m_t &= \beta m_{t-1} + (1-\beta) \nabla_{\theta_t} J(\theta_t - \beta m_{t-1})
    \end{aligned}
\end{equation}

\subsubsection{Adagrad}

\cindex{Adagrad}\cite{Duchi2012} performs large update for infrequent and small update for frequent parameters:
\begin{equation}
    \begin{aligned}
        \theta_{t+1} &= \theta_t - \frac{\alpha}{\sqrt{G_t + \epsilon}}  \nabla_{\theta_t} J(\theta_t) \\
        G_t &= G_{t-1} + \left(\nabla_{\theta_t} J(\theta_t) \right)^2
    \end{aligned}
\end{equation}

$\epsilon$ is added to avoid division by zero. Usually $G_0 = 0$, $\alpha = 0.01$, $\epsilon = 10^{-8}$. Because $G_t$ keeps accumulating, eventually it will become too big for the algorithm to be effective.

\subsubsection{Adadelta}
\cindex{Adadelta}\cite{Zeiler2012} fixes the problem of Adagrad. It is a decay version of Adagrad:
\begin{equation}
    \begin{aligned}
        \theta_{t+1} &= \theta_t - \frac{\sqrt{D_{t-1} + \epsilon}}{\sqrt{G_t + \epsilon}}  \nabla_{\theta_t} J(\theta_t) \\
        G_t &= \beta G_{t-1} + (1-\beta) \left(\nabla_{\theta_t} J(\theta_t) \right)^2 \\
        D_t &= \beta D_{t-1} + (1-\beta) (\theta_t - \theta_{t-1})^2
    \end{aligned}
\end{equation}

Usually $G_0 = 0$, $D_0 = 0$, $\beta = 0.9$, $\epsilon = 10^{-6}$.

\subsubsection{RMSprop}

\cindex{RMSprop} is unpublished. It is a simplified version of Adadelta that $D_t = 0$:
\begin{equation}
    \begin{aligned}
        \theta_{t+1} &= \theta_t - \frac{\alpha}{\sqrt{G_t + \epsilon}}  \nabla_{\theta_t} J(\theta_t) \\
        G_t &= \beta G_{t-1} + (1-\beta) \left(\nabla_{\theta_t} J(\theta_t) \right)^2 \\
    \end{aligned}
\end{equation}

Usually $G_0 = 0$, $\alpha = 0.001$, $\beta = 0.9$, $\epsilon = 10^{-6}$.

\subsubsection{Adam}

\cindex{Adaptive Moment Estimation}\cite{Kingma2015}, or \cindex{Adam}, is yet another adaptive method:

\begin{equation}
    \begin{aligned}
        \theta_{t+1} &= \theta_t - \frac{\alpha}{\sqrt{\displaystyle \frac{G_t}{1-(\beta_2)^t}} + \epsilon} \frac{m_t}{1-(\beta_1)^t}  \\
        m_t &= \beta_1 m_{t-1} + (1-\beta_1) \nabla_{\theta_t} J(\theta_t) \\
        G_t &= \beta_2 G_{t-1} + (1-\beta_2) \left(\nabla_{\theta_t} J(\theta_t) \right)^2
    \end{aligned}
\end{equation}

Usually $G_0 = 0$, $\alpha = 0.001$, $\beta_1 = 0.9$, $\beta_2 = 0.999$, $\epsilon = 10^{-8}$.

\subsubsection{AdaMax}
\cindex{AdaMax}\cite{Kingma2015} is a infinite norm version of Adam. Adam use $l_2$ norm for $G$. For infinite norm:
\begin{equation}
    \begin{aligned}
        G_t &= \beta_2^\infty G_{t-1} + (1-\beta_2^\infty ) \norm{\nabla_{\theta_t} J(\theta_t)}^\infty  \\
        &= \max \left(\beta_2 G_{t-1}, \norm{\nabla_{\theta_t} J(\theta_t)} \right)
    \end{aligned}
\end{equation}

Because $G_t > 0$ in AdaMax, $\epsilon$ is no longer useful. So the equation could be simplified:

\begin{equation}
    \begin{aligned}
        \theta_{t+1} &= \theta_t - \frac{\alpha}{G_t}  m_t \\
        m_t &= \beta_1 m_{t-1} + (1-\beta_1) \nabla_{\theta_t} J(\theta_t) \\
        G_t &= \max \left(\beta_2 G_{t-1}, \norm{\nabla_{\theta_t} J(\theta_t)} \right)
    \end{aligned}
\end{equation}

Usually $G_0 = 0$, $\alpha = 0.001$, $\beta_1 = 0.9$, $\beta_2 = 0.999$.

\subsubsection{Nadam}

\cindex{Nadam}\cite{Dozat2016} combines Adam and NAG. Adam could be written as:
\begin{equation}
    \theta_{t+1} = \theta_t - \frac{\alpha}{\sqrt{\displaystyle \frac{G_t}{1-(\beta_2)^t}} + \epsilon} \left(\beta_1 \frac{m_{t-1}}{1-(\beta_1)^{t-1}} + \frac{1-\beta_1}{1-(\beta_1)^t} \nabla_{\theta_t} J(\theta_t) \right)
\end{equation}

Like NAG, Nadam changes Adam's $t-1$ version of $\displaystyle \frac{m_{t-1}}{1-(\beta_1)^{t-1}}$ to current $t$ version $\displaystyle \frac{m_t}{1-(\beta_1)^t}$:
\begin{equation}
    \begin{aligned}
            \theta_{t+1} &= \theta_t - \frac{\alpha}{\sqrt{\displaystyle \frac{G_t}{1-(\beta_2)^t}} + \epsilon} \left(\beta_1 \frac{m}{1-(\beta_1)^t} + \frac{1-\beta_1}{1-(\beta_1)^t} \nabla_{\theta_t} J(\theta_t) \right)  \\
        m_t &= \beta_1 m_{t-1} + (1-\beta_1) \nabla_{\theta_t} J(\theta_t) \\
        G_t &= \beta_2 G_{t-1} + (1-\beta_2) \left(\nabla_{\theta_t} J(\theta_t) \right)^2
    \end{aligned}
\end{equation}

Usually $G_0 = 0$, $m_0 = 0$, $\alpha = 0.002$, $\beta_1 = 0.9$, $\beta_2 = 0.999$, $\epsilon = 10^{-7}$.


\subsection{Lattices}\label{subsec:lattices}

\begin{definition}\label{def:semilattice}\mcite[3]{Gratzer1978}
  Lattices are \hyperref[def:partially_ordered_set]{partially ordered sets} in which \hyperref[def:partially_ordered_set_extremal_points/supremum_and_infimum]{suprema and infima} are taken as basic operations called \enquote{joins} and \enquote{meets}. See \fullref{rem:lattice_operation_etymology} for a discussion of the operation names. This shifts the focus from ordering to operations, i.e. from predicates to functions.

  Joins and meets may also be defined axiomatically as binary operations rather than via some partial order, however this restricts us to taking suprema of finite sets and prevents us from taking the supremum of an arbitrary set. In other words, it is possible for the order to carry more information than joins and meets. See \fullref{thm:binary_lattice_operations/new_lattice} for a discussion. Unless explicitly noted otherwise, we assume that lattices have their partial order defined.

  \begin{thmenum}[series=def:semilattice]
    \thmitem{def:semilattice/join} A \term{join-semilattice} is a \hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded from above} partially ordered set in which every finite supremum exists. The operation itself is denoted by \( \vee \) and referred to as \term{join} and rather than supremum. In contrast to suprema, joins are usually written in \hyperref[rem:first_order_formula_conventions/infix]{infix} notation, e.g. \( x \vee y \vee z \) rather than \( \sup\set{ x, y, z } \).

    \thmitem{def:semilattice/meet} Analogously, a \term{meet-semilattice} is a partially ordered set in which every finite infimum exists. The infimum is denoted by \( \wedge \) and called \term{meet}.

    \thmitem{def:semilattice/bounded} A \term{bounded semilattice} is a semilattice that is \hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded} as a \hyperref[def:partially_ordered_set]{partially ordered set}, either \hi{from below} for join-semilattices or \hi{from above} for meet-semilattices.

    \thmitem{def:semilattice/complete}\mcite[24]{Gratzer1978} A semilattice is said to be \term{complete} if the corresponding operation is defined for arbitrary sets rather than only finite ones.

    Finite semilattices are clearly complete, as well as bounded semilattices.

    \thmitem{def:semilattice/lattice} A \term{lattice} is a partially ordered set which is both a join-semilattice and a meet-semilattice. It is called \term{bounded} if both semilattices are bounded, i.e. if the partially ordered set itself is \hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bounded}. It is called \term{complete} if both semilattices are complete.

    \thmitem{def:semilattice/distributive_lattice}\mcite[30]{Gratzer1978} A lattice is said to be \term{distributive} if the following two conditions hold:
    \begin{align}
      x \vee (y \wedge z) &= (x \vee y) \wedge (x \vee z) \label{eq:def:semilattice/distributive_lattice/finite/join_over_meet} \\
      x \wedge (y \vee z) &= (x \wedge y) \vee (x \wedge z) \label{eq:def:semilattice/distributive_lattice/finite/meet_over_join}.
    \end{align}

    If the lattice is \hyperref[def:semilattice/complete]{complete}, the above conditions are not enough. A complete lattice \( X \) it is said to be \term{distributive} if any of the following more general distributive axioms hold for every \( x \in X \) and \hyperref[def:cartesian_product/indexed_family]{family} \( \seq{ y_k }_{k \in \mscrK} \subseteq X \):
    \begin{align}
      x \vee \parens*{ \bigwedge_{k \in \mscrK} y_k } &= \bigwedge_{k \in \mscrK} \parens{ x \vee y_k } \label{eq:def:semilattice/distributive_lattice/arbitrary/join_over_meet} \\
      x \wedge \parens*{ \bigvee_{k \in \mscrK} y_k } &= \bigvee_{k \in \mscrK} \parens{ x \wedge y_k } \label{eq:def:semilattice/distributive_lattice/arbitrary/meet_over_join}
    \end{align}
  \end{thmenum}

  Lattices have the following metamathematical properties:
  \begin{thmenum}[resume=def:semilattice]
    \thmitem{def:semilattice/theory} The language of the theory of lattices consists of the language of the \hyperref[def:partially_ordered_set/theory]{theory of partially ordered sets} with the addition of the binary infix functional symbols \( \vee \) and \( \wedge \). If we only want to restrict ourselves to semilattices, we can add only one of the two operations as functional symbols. If we wish to study \hyperref[def:semilattice/bounded]{bounded lattices}, as it is often done, we must also add the constants \( \top \) and \( \bot \).

    For meet-semilattices, we add the following axiom schema to the theory to ensure compatibility between infima and meets (we use \( \mathbin\& \) to denote \hyperref[def:propositional_language/connectives/conjunction]{logical conjunction} to avoid symbol collision with meets):
    \begin{equation}\label{eq:def:semilattice/theory/meet_compat}
      \parens[\Big]{ \xi \wedge \eta \doteq \alpha } \leftrightarrow \parens[\Big]{ \alpha \leq \xi \mathbin\& \alpha \leq \eta \mathbin\& \qforall \alpha ((\alpha \leq \xi \mathbin\& \alpha \leq \eta) \rightarrow \alpha \leq \alpha) }
    \end{equation}
    and, for bounded meet-semilattices, the following axiom to ensure that \( \top \) is indeed the maximum:
    \begin{equation}\label{eq:def:semilattice/theory/bottom_compat}
      \qforall \xi (\xi \leq \top).
    \end{equation}

    Analogous axioms need to be added for join-semilattices.

    We cannot properly express the theory of complete (semi)lattices as an extension of this theory since we must define join and meet as unary operations on subsets of the domain rather than binary operations on members of the domain. Complete semilattices can instead be defined within \hyperref[def:zfc]{\logic{ZFC}}.

    \thmitem{def:semilattice/submodel} Unlike for partially ordered sets, whose submodels are discussed in \fullref{def:partially_ordered_set/submodel}, not every subset of a semilattice is a sub-semilattice because \( \vee \) and \( \wedge \) are now regarded as functional symbols. A sub-(semi)lattice must be closed under joins and meets. The axiom \eqref{eq:def:semilattice/theory/meet_compat} is not a positive formula, but does not cause trouble itself as it merely specifies compatibility of \( \leq \) and \( \wedge \).

    For bounded semilattices, the relevant constants should be present in any bounded sub-semilattice.

    \thmitem{def:semilattice/trivial} The \hyperref[thm:substructures_form_complete_lattice/bottom]{trivial join-semilattice} and the trivial meet-semilattice are the empty set. The trivial bounded join-semilattice is the singleton \( \set{ \bot } \) and the trivial bounded meet-semilattice is \( \set{ \top } \).

    The trivial bounded lattice satisfies \( \top = \bot \), which implies that it consists of one element.

    Note that the elements \( \top \) and \( \bot \) formally differ between different semilattices, however all trivial bounded lattices are isomorphic and hence it makes sense to speak of \enquote{the} bounded lattice.

    \thmitem{def:semilattice/homomorphism} \hyperref[def:first_order_homomorphism]{Homomorphisms} between (semi)lattices are the monotone maps that preserve joins, meets and constants.

    \begin{figure}[h]
      \centering
      \includegraphics[page=1]{output/def__semilattice.pdf}
      \caption{A monotone map between lattices, which is not a lattice homomorphism}
      \label{fig:def:semilattice/homomorphism/monotone_map_not_homomorphism}
    \end{figure}

    As we shall see in \fullref{thm:lattice_homomorphism_is_monotone}, the requirement of monotonicity is redundant.

    \thmitem{def:semilattice/category} The \hyperref[def:category_of_small_first_order_models]{categories of \( \mscrU \)-small models} for (semi)lattices are full subcategories of \hyperref[def:partially_ordered_set/category]{\( \ucat{Pos} \)}. We only give a special name for the category \( \ucat{Lat} \) of lattices.

    \thmitem{def:semilattice/duality} The \hyperref[def:partially_ordered_set/opposite]{principle of duality for partially ordered sets} holds for lattices if we also swap the binary operations \( \vee \) and \( \wedge \).

    If the lattice is bounded, we must additionally swap the constants \( \top \) and \( \bot \).

    If the lattice is bounded from only one side, the principle of duality does not hold unless we restrict ourselves to formulas that do not contain the constants.
  \end{thmenum}
\end{definition}

\begin{remark}\label{rem:lattice_operation_etymology}
  The terms \hyperref[def:semilattice/join]{\enquote{join}} for \( \vee \) and \hyperref[def:semilattice/meet]{\enquote{meet}} for \( \wedge \) are notoriously difficult to remember. A helpful accident is the ability to write \enquote{meet} as \enquote{\( \wedge \wedge \)eet}.
\end{remark}

\begin{proposition}\label{thm:binary_lattice_operations}
  Let \( (P, \leq) \) be a partially ordered set.

  \begin{thmenum}
    \thmitem{thm:binary_lattice_operations/semilattices} If it is a \hyperref[def:semilattice/join]{join-semilattice} (resp. \hyperref[def:semilattice/meet]{meet-semilattice}), then \( \vee \) (resp. \( \wedge \)) is \hyperref[def:magma/associative]{associative}, \hyperref[def:magma/commutative]{commutative} and \hyperref[def:magma/idempotent]{idempotent} when considered as a binary operation.

    \thmitem{thm:binary_lattice_operations/identity} If \( P \) is a (semi)lattice, the constants act as \hyperref[def:monoid]{monoid identities}. That is, for each \( x \in P \),
    \begin{align}
      x \vee \bot = x \label{eq:thm:binary_lattice_operations/identity/join} \\
      x \wedge \top = x \label{eq:thm:binary_lattice_operations/identity/meet}
    \end{align}

    \thmitem{thm:binary_lattice_operations/absorption} If \( P \) is a lattice, then the following absorption laws hold:
    \begin{align}
      x \vee (x \wedge y) &= x \label{eq:thm:binary_lattice_operations/absorption/join} \\
      x \wedge (x \vee y) &= x \label{eq:thm:binary_lattice_operations/absorption/meet}.
    \end{align}

    \thmitem{thm:binary_lattice_operations/compatibility} The following conditions for compatibility with \( \leq \) hold:
    \begin{align}
      x \leq y &\T{if and only if} x \vee y = y \label{eq:thm:binary_lattice_operations/compatibility/join} \\
      x \leq y &\T{if and only if} x \wedge y = x \label{eq:thm:binary_lattice_operations/compatibility/meet}.
    \end{align}

    \thmitem{thm:binary_lattice_operations/new_lattice} If \( A \) is an arbitrary \hyperref[def:set]{set} and if \( \vee \) is a binary operation that is associative, commutative and idempotent (the conclusion of \fullref{thm:binary_lattice_operations/semilattices}), then \( (A, \leq) \) is a join-semilattice with an ordering defined by \eqref{eq:thm:binary_lattice_operations/compatibility/join}. If there exists a distinguished element \( \bot \) such that \eqref{eq:thm:binary_lattice_operations/identity/meet} holds, then \( (A, \leq) \) is bounded.

    A completely analogous statement holds for meet-semilattices.

    If \( (A, \leq) \) is both a join-semilattice and meet-semilattice and if \( \vee \) and \( \wedge \) satisfy the absorption conditions \eqref{eq:thm:binary_lattice_operations/absorption/join} and \eqref{eq:thm:binary_lattice_operations/absorption/meet}, then \( (A, \leq) \) is a lattice. Furthermore, proving idempotence for \( \vee \) or \( \wedge \) is unnecessary because both follow from the absorption conditions.

    It may turn out that \( (A, \leq) \) is a complete lattice under this definition. This can allow us, for example, to transparently extend the binary operations join and meet into infinitary operations.
  \end{thmenum}
\end{proposition}
\begin{proof}
  \SubProofOf{thm:binary_lattice_operations/semilattices} Suprema and infima are obviously associative and commutative as binary operations because ordering is immaterial for pure sets and \( x \vee y \) is defined as \( \sup\set{ x, y } \).

  Idempotence is also obvious because \( x \vee x = \sup\set{ x } = x \).

  \SubProofOf{thm:binary_lattice_operations/identity} Obvious since \( \bot \leq x \leq \top \) for all \( x \in P \).

  \SubProofOf{thm:binary_lattice_operations/absorption} If we rewrite \eqref{eq:thm:binary_lattice_operations/absorption/join} using suprema and infima, we obtain
  \begin{equation*}
    \sup\set{ x, \inf\set{ y, x } } = x.
  \end{equation*}

  If \( x \leq y \), then \( \inf\set{ y, x } = x \) and \( \sup\set{ x, \inf\set{ y, x } } = \sup\set{ x, x } = x \).

  If \( x \geq y \), then \( \inf\set{ y, x } = y \) and \( \sup\set{ x, \inf\set{ y, x } } = \sup\set{ x, y } = x \).

  This proves \eqref{eq:thm:binary_lattice_operations/absorption/join}. Since \( \wedge \) is \( \vee \) in the \hyperref[def:preordered_set/duality]{opposite partially ordered set}, \eqref{eq:thm:binary_lattice_operations/absorption/meet} follows automatically.

  \SubProofOf{thm:binary_lattice_operations/compatibility} We have
  \begin{equation*}
    x \vee y
    =
    \sup\set{ x, y }
    =
    \begin{cases}
      y, &x \leq y \\
      x, &x > y
    \end{cases}
  \end{equation*}
  and dually for \( \wedge \).

  \SubProofOf{thm:binary_lattice_operations/new_lattice} Since the binary join and/or meet are defined for all members of the set \( A \), it is indeed a join-semilattice because all finite joins and meets exist by definition.

  Idempotence of \( \vee \) follows from \eqref{eq:thm:binary_lattice_operations/absorption/meet}:
  \begin{equation*}
    x \vee x = x \vee (x \wedge (x \vee x)) = x
  \end{equation*}
  and dually for \( \wedge \).
\end{proof}

\begin{corollary}\label{thm:lattice_homomorphism_is_monotone}
  If a function \( f: L \to M \) between \hyperref[def:semilattice]{(semi)lattices} preserves either joins or meets, it is \hyperref[def:partially_ordered_set/homomorphism]{monotone}.

  Thus, the requirement for \hyperref[def:semilattice/homomorphism]{lattice homomorphisms} to be monotone is redundant.
\end{corollary}
\begin{proof}
  If the function \( f \) preserves joins and if \( x \leq y \), by \eqref{eq:thm:binary_lattice_operations/compatibility/join} we have \( x \vee y = y \) and thus
  \begin{equation*}
    f(x \vee y) = f(y),
  \end{equation*}
  which again by \eqref{eq:thm:binary_lattice_operations/compatibility/join} implies \( f(x) \leq f(y) \).
\end{proof}

\begin{proposition}\label{thm:bounded_lattice_absorbing}
  In any \hyperref[def:semilattice/bounded]{bounded lattice}, \( \bot \) is absorbing with respect to meets and \( \top \) with respect to joins. That is, \( \bot \wedge x = \bot \) and \( \top \vee x = \top \).
\end{proposition}
\begin{proof}
  Obvious when the lattice is regarded as a partially ordered set.
\end{proof}

\begin{definition}\label{def:fixed_point}
  Given a \hyperref[def:function]{function} \( f: A \to A \) between arbitrary sets, we call \( x \in A \) a \term{fixed point} of \( f \) if \( x = f(x) \).
\end{definition}

\begin{theorem}[Knaster-Tarski theorem]\label{thm:knaster_tarski_theorem}
  The \hyperref[def:fixed_point]{fixed points} of a \hyperref[def:partially_ordered_set/homomorphism]{monotone} \hyperref[def:multi_valued_function/endofunction]{endofunction} in a \hyperref[def:semilattice/lattice]{complete lattice} form a complete sublattice. In particular, the function has at least one fixed point.
\end{theorem}
\begin{proof}
  Let \( (X, \leq) \) be a complete lattice and let \( \varphi: X \to X \) be a monotone function. Define
  \begin{equation*}
    L \coloneqq \{ x \in X \colon f(x) \leq x \}.
  \end{equation*}

  We know that \( L \) is nonempty because \( \top \in L \).

  Since the lattice is complete, we can take \( l \coloneqq \inf L \). Note that \( f(l) \) is a lower bound of \( L \) because for any \( y \in L \) we have
  \begin{equation*}
    f(l) \leq f(y) \leq y.
  \end{equation*}

  But \( l \) is the largest lower bound of \( L \), hence
  \begin{equation}\label{eq:thm:knaster_tarski/f_lower}
    f(l) \leq l.
  \end{equation}

  Therefore, \( f(f(l)) \leq f(l) \) and \( f(l) \in L \). Hence, \( l \) is a lower bound for \( \{ f(l) \} \) and
  \begin{equation}\label{eq:thm:knaster_tarski/f_upper}
    l \leq f(l).
  \end{equation}

  From \eqref{eq:thm:knaster_tarski/f_lower} and \eqref{eq:thm:knaster_tarski/f_upper} it follows that \( l = f(l) \), that is, \( l \) is a fixed point of \( f \).

  Denote by \( F \) the set of all fixed points of \( X \). We just showed that \( F \) is nonempty. Let \( G \subseteq F \). We will show that the infimum and supremum of \( G \) is in \( F \).

  Denote
  \begin{equation*}
    l_G \coloneqq \inf G.
  \end{equation*}

  For any \( g \in G \) we have \( l_G \leq g \). From monotonicity of \( f \),
  \begin{equation*}
    f(l_G) \leq f(g) = g,
  \end{equation*}
  therefore \( f(l_G) \leq l_G \) because \( l_G \) is the greatest lower bound of \( G \). But, from monotonicity of \( f \), we have \( l_G \leq f(l_G) \). Therefore, \( f(l_G) = l_G \) and \( l_G \in F \).

  We can analogously show that \( \sup G \in F \) and conclude that \( (F, \leq) \) is itself a complete lattice.
\end{proof}

\begin{remark}\label{rem:lattice_categorical_product}
  The existence of finite joins and meets is equivalent to the existence of finite products and coproducts in the respective \hyperref[def:thin_category]{thin category} defined in \fullref{thm:order_category_isomorphism/partially_ordered}.
\end{remark}

\begin{definition}\label{def:square_free}
  An element \( x \) of a \hyperref[def:semiring/commutative]{commutative semiring} is said to be \term{square-free} if \( y \mid x \) implies that \( z^2 \not\mid x \).
\end{definition}

\begin{remark}\label{rem:lattice_polynomials}
  Let \( L \) be a \hyperref[def:semilattice/bounded]{bounded} \hyperref[def:semilattice/distributive_lattice]{distributive lattice}. We will discuss polynomials over \( L \).

  By \fullref{ex:def:semiring/lattice}, \( L \) induces a positive and a negative commutative semiring. Given a set \( \mscrX \) of indeterminates, we can form the \hyperref[def:polynomial_algebra]{polynomial semiring} \( L[\mscrX] \) over the positive semiring. Suppose that we are given an evaluation \( f: \mscrX \to L^\mscrX \). Consider the \hyperref[thm:polynomial_algebra_universal_property]{evaluation homomorphism} \( \Phi_f: L[\mscrX] \to L^\mscrX \).
  \begin{equation*}
    \Phi_f(X^2) = \Phi_f(X).
  \end{equation*}

  Hence, we can limit ourselves to \hyperref[def:square_free]{square-free} monomials. That is, monomials of the form \( \prod_{X \in \mscrX} X^{\gamma_X} \), where \( \gamma_X \) is either \( 0 \) or \( 1 \). More succinctly, since every monomial has finitely many indeterminates of positive power, it can be written as a finite meet \( X_1 \wedge \cdots \wedge X_n \). A polynomial is then a finite join of finite meets of indeterminates and constants.

  There is a nuance, however. In \cite[def. I.4.2]{Gratzer1978}, a multivariate lattice polynomial is defined to consist only of indeterminates; for example
  \begin{equation*}
    p(X, Y, Z) = (X \wedge Y) \vee (X \wedge Z) \vee (Y \wedge Z).
  \end{equation*}

  This excludes coefficients before the monomials, hence making the definition distinct from the general notion of a polynomial over a commutative semiring. In \cite{Marichal2007}, polynomials with coefficients in front of the monomials are called \term{weighted lattice polynomials}. For example, a weighted polynomial is
  \begin{equation*}
    q(X, Y, Z) = (a \wedge X \wedge Y) \vee (b \wedge X \wedge Z) \vee (c \wedge Y \wedge Z).
  \end{equation*}

  Compare \( q(X, Y, Z) \) to \( p(X, Y, Z) \). We will refer to unweighted polynomials by default.

  We can analogously define polynomials over the negative semiring of \( L \), e.g.
  \begin{equation*}
    r(X, Y, Z) = (X \vee Y) \wedge (X \vee Z) \wedge (Y \vee Z).
  \end{equation*}

  The latter polynomials are related to but distinct from \hyperref[def:cnf_and_dnf]{conjunctive normal forms}, while the former - to \hyperref[def:cnf_and_dnf]{disjunctive normal forms}.
\end{remark}

\begin{example}\label{ex:lattice_polynomials}
  We list several examples of \hyperref[rem:lattice_polynomials]{lattice polynomials}:
  \begin{thmenum}
    \thmitem{ex:lattice_polynomials/distributivity} The distributivity axiom \eqref{eq:def:semilattice/distributive_lattice/finite/meet_over_join} implies that the polynomial
    \begin{equation*}
      X \wedge (Y \vee Z)
    \end{equation*}
    over the positive semiring evaluates to the same trivariate function as the polynomial
    \begin{equation*}
      (X \wedge Y) \vee (X \wedge Z)
    \end{equation*}
    over the negative semiring.

    \thmitem{ex:lattice_polynomials/boolean} A lattice polynomial for the two-element boolean algebra \hyperref[def:boolean_value]{\( \set{ T, F } \)} corresponds to a \hyperref[def:boolean_function]{boolean function}. We cannot express negation without introducing auxiliary polynomials as a consequence of \fullref{ex:thm:posts_completeness_theorem/and_or}. \hyperref[def:positive_formula]{Positive formulas} in \hyperref[def:cnf_and_dnf/normal_form]{conjunctive/disjunctive normal form}, however, correspond exactly to lattice polynomials with square-free monomials.

    For example, \hyperref[def:standard_boolean_operators]{exclusive or} \( \oplus \) can be expressed via the \hyperref[def:propositional_syntax/formula]{propositional formula}
    \begin{equation*}
      P \vee Q \vee (P \wedge Q).
    \end{equation*}

    This corresponds to a bivariate polynomial over the negative semiring of \( \set{ T, F } \).
  \end{thmenum}
\end{example}

\begin{definition}\label{def:order_ideal_and_filter}
  In a \hyperref[def:partially_ordered_set]{partially ordered set}, we call the nonempty \hyperref[def:directed_set]{upward directed} subset \( I \) an \term{order ideal} if \( x \in I \) and \( y \leq x \) imply that \( y \in I \).

  \hyperref[def:partially_ordered_set/duality]{Dually}, we call the nonempty \hyperref[def:directed_set]{downward directed} set \( F \) a \term{filter} if \( x \in F \) and \( y \geq x \) imply that \( y \in F \).
\end{definition}

\begin{proposition}\label{thm:lattice_ideals}
  For a subset \( I \) of a \hyperref[def:lattice]{lattice} \( L \), the following are equivalent:
  \begin{thmenum}
    \thmitem{thm:lattice_ideals/order} \( I \) is an \hyperref[def:order_ideal_and_filter]{order ideal}.
    \thmitem{thm:lattice_ideals/direct}\mcite[17]{Gratzer1978} \( I \) is a closed under joins and \( i \in I \) and \( l \in L \) imply \( i \wedge l \in I \). If \( L \) has a \hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bottom}, it must belong to \( I \).
    \thmitem{thm:lattice_ideals/semilattice} \( I \) is a \hyperref[def:semiring_ideal]{semiring ideal} of the \hyperref[ex:def:semiring/lattice]{positive semilattice} of \( L \) (in case \( L \) is a \hyperref[def:semilattice/bounded]{bounded} \hyperref[def:semilattice/distributive_lattice]{distributive lattice}).
  \end{thmenum}
\end{proposition}
\begin{proof}
  \ImplicationSubProof{thm:lattice_ideals/order}{thm:lattice_ideals/direct} Suppose that \( I \) is an order ideal.
  \begin{itemize}
    \item The bottom \( \bot \) is less than any element of \( I \), hence \( \bot \in I \).
    \item Given \( i, j \in I \), \( I \) contains an upper bound of theirs. Then \( i \vee j \) as the least upper bound also belongs to \( I \).
    \item Given \( i \in I \) and \( l \in L \), since \( i \wedge l \leq l \), we conclude that \( i \wedge l \in I \).
  \end{itemize}

  \ImplicationSubProof{thm:lattice_ideals/direct}{thm:lattice_ideals/order} Suppose that \( I \) is closed under joins and that \( i \in I \) and \( l \in L \) imply \( i \wedge l \in I \).
  \begin{itemize}
    \item If \( i, j \in I \), then \( i \vee j \in I \). Hence, \( I \) is an upward directed set.
    \item If \( i \in I \) and \( j \leq i \), then \( j = i \wedge j \in I \).
  \end{itemize}

  \EquivalenceSubProof{thm:lattice_ideals/order}{thm:lattice_ideals/semilattice} Trivial.
\end{proof}

\begin{remark}\label{rem:lattice_ideals_as_semiring_ideals}
  Regarding \hyperref[thm:lattice_ideals]{ideals} and \hyperref[thm:lattice_filters]{filters} in bounded distributive lattices as \hyperref[def:semiring_ideal]{semiring ideals} exposes us to a lot of definitions and theorems that we would otherwise need to redefine. For example, \hyperref[def:semiring_ideal/principal]{principal}, \hyperref[def:semiring_ideal/prime]{prime} and \hyperref[def:semiring_ideal/maximal]{maximal} ideals, the properties from \fullref{thm:def:semiring_ideal}, the semiring of ideals from \fullref{thm:semiring_of_ideals}, or \fullref{thm:maximal_ideal_theorem}.
\end{remark}

\begin{example}\label{ex:lattice_ideals}
  We list examples of \hyperref[thm:lattice_ideals]{lattice ideals}:
  \begin{thmenum}
    \thmitem{ex:lattice_ideals/lattice} Consider the (zero-based) natural number divisibility lattice from \fullref{thm:natural_number_divisibility_lattice}. For any natural number \( n \), the set \( D_n \) of all \hyperref[def:divisibility]{divisors} of \( n \) is a lattice ideal.

    \begin{figure}
      \centering
      \includegraphics[page=1]{output/ex__lattice_ideals.pdf}
      \caption{A Hasse diagram for the divisors of \( 24 \).}
      \label{fig:ex:lattice_ideals/lattice}
    \end{figure}

    Indeed,
    \begin{itemize}
      \item The bottom \( 1 \) divides \( n \).
      \item If \( a \) and \( b \) divide \( n \), their product \( ab \) also does, and hence their join \( \lcm(a, b) \) also does.
      \item If \( a \mid n \) and \( b \) is any natural number, then \( \gcd(a, b) \mid a \mid n \).
    \end{itemize}

    Furthermore, \( D_n \) is a \hyperref[def:semiring_ideal]{principal ideal} since it can be obtained as \( \set{ n \wedge m \mid m \in \BbbN } \).

    If \( p \) is a \hyperref[def:prime_number]{prime number}, then \( D_p = \set{ 1, p } \) is a \hyperref[def:semiring_ideal/maximal]{maximal ideal}, and hence also a \hyperref[def:semiring_ideal/prime]{prime ideal}.

    \thmitem{ex:lattice_ideals/subgroups} Given a \hyperref[def:group]{group} \( G \) and a proper \hyperref[thm:normal_subgroup_equivalences]{normal subgroup} \( N \), consider the \hyperref[thm:substructures_form_complete_lattice]{lattice of subgroups} \( L_G \) of \( G \) and the sublattice \( L_N \) of subgroups of \( N \). Note that the top \( N \) of \( L_N \) is not the top \( G \) of \( L_G \).

    Then \( L_N \) is an ideal on \( L \).
    \begin{itemize}
      \item \( L_N \) contains the bottom \( \set{ e } \).
      \item \( L_N \) contains the join \( \braket{ K \cup H } \) of every two subgroups of \( N \).
      \item \( L_N \) contains the meet \( K \cap H \) of \( K \in L_N \) and \( H \in L_G \) since \( K \cap H \subseteq K \subseteq N \).
    \end{itemize}
  \end{thmenum}
\end{example}

\begin{proposition}\label{thm:lattice_filters}
  For a subset \( F \) of a \hyperref[def:lattice]{lattice} \( L \), the following are equivalent:
  \begin{thmenum}
    \thmitem{thm:lattice_filters/order} \( F \) is a \hyperref[def:order_ideal_and_filter]{filter}.
    \thmitem{thm:lattice_filters/direct}\mcite[19]{Gratzer1978} \( F \) is closed under meets and \( i \in I \) and \( l \in L \) imply \( i \vee l \in I \). If \( L \) has a \hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top}, it must belong to \( I \).
    \thmitem{thm:lattice_filters/semilattice} \( F \) is a \hyperref[def:semiring_ideal]{semiring ideal} of the \hyperref[ex:def:semiring/lattice]{negative semilattice} of \( L \) (in case \( L \) is a \hyperref[def:semilattice/bounded]{bounded} \hyperref[def:semilattice/distributive_lattice]{distributive lattice}).
  \end{thmenum}
\end{proposition}
\begin{proof}
  The proof is \hyperref[def:semilattice/duality]{dual} to that of \fullref{thm:lattice_ideals}.
\end{proof}

\begin{example}\label{ex:lattice_filters}
  We list examples of \hyperref[thm:lattice_ideals]{lattice filters}:
  \begin{thmenum}
    \thmitem{ex:lattice_filters/lattice} By \hyperref[def:partially_ordered_set/duality]{duality} with respect to \fullref{ex:lattice_ideals/subgroups}, it follows that, for a natural number \( n \), the semiring ideal
    \begin{equation*}
      \braket{ n } \coloneqq \set{ 0, n, 2n, 3n, \ldots }
    \end{equation*}
    is a principal filter in the natural number divisibility lattice from \fullref{thm:natural_number_divisibility_lattice}.

    We can prove this explicitly:
    \begin{itemize}
      \item \( \braket{ n } \) contains the top \( 0 \).
      \item \( \braket{ n } \) contains the meet \( \gcd(a, b) \) of every two members of \( \braket{ n } \).
      \item If \( n \mid a \) and \( b \) is any natural number, then \( n \mid a \mid \lcm(a, b) \), meaning that the join \( \lcm(a, b) \) also belongs to \( \braket{ n } \).
    \end{itemize}

    \thmitem{ex:lattice_filters/subgroups} By \hyperref[def:partially_ordered_set/duality]{duality} with respect to \fullref{ex:lattice_ideals/subgroups}, given a \hyperref[def:group]{group} \( G \) and a proper \hyperref[thm:normal_subgroup_equivalences]{normal subgroup} \( N \), the sublattice of subgroups containing \( N \) (rather than contained in \( N \)) is a filter (rather than an ideal).
  \end{thmenum}
\end{example}