%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                         BIBLIOGRAPHY FILE                                 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The `filecontents` command will crete a file in the inputs directory called
%% refs.bib containing the references in the document, in case this file does
%% not exist already.
%% If you want to add a BibTeX entry, please don't add it directly to the
%% refs.bib file.  Instead, add it in this file between the
%% \begin{filecontents*}{refs.bib} and \end{filecontents*} lines
%% then delete the existing refs.bib file so it will be automatically generated
%% again with your new entry the next time you run pdfaltex.
\begin{filecontents*}{inputs/refs.bib}
@book {MR2455216,
    AUTHOR = {Gr{\"a}tzer, George},
     TITLE = {Universal algebra},
   EDITION = {second},
      NOTE = {With appendices by Gr{\"a}tzer, Bjarni J{\'o}nsson, Walter
              Taylor, Robert W. Quackenbush, G{\"u}nter H. Wenzel, and
              Gr{\"a}tzer and W. A. Lampe},
 PUBLISHER = {Springer, New York},
      YEAR = {2008},
     PAGES = {xx+586},
      ISBN = {978-0-387-77486-2},
   MRCLASS = {08-02},
  MRNUMBER = {2455216},
       DOI = {10.1007/978-0-387-77487-9},
       URL = {http://dx.doi.org/10.1007/978-0-387-77487-9},
}
@article {MR0237401,
    AUTHOR = {Gr{\"a}tzer, G. and Wenzel, G. H.},
     TITLE = {On the concept of congruence relation in partial algebras},
   JOURNAL = {Math. Scand.},
  FJOURNAL = {Mathematica Scandinavica},
    VOLUME = {20},
      YEAR = {1967},
     PAGES = {275--280},
      ISSN = {0025-5521},
   MRCLASS = {08.30},
  MRNUMBER = {0237401},
MRREVIEWER = {B. H. Neumann},
}
@article {MR0309833,
    AUTHOR = {Berman, Joel},
     TITLE = {On the congruence lattices of unary algebras},
   JOURNAL = {Proc. Amer. Math. Soc.},
  FJOURNAL = {Proceedings of the American Mathematical Society},
    VOLUME = {36},
      YEAR = {1972},
     PAGES = {34--38},
      ISSN = {0002-9939},
   MRCLASS = {08A15},
  MRNUMBER = {0309833},
MRREVIEWER = {I. Petrescu},
}

@article {MR0308011,
    AUTHOR = {Berman, Joel},
     TITLE = {Strong congruence lattices of finite partial algebras},
   JOURNAL = {Algebra Universalis},
  FJOURNAL = {Algebra Universalis},
    VOLUME = {1},
      YEAR = {1971/72},
     PAGES = {133--135},
      ISSN = {0002-5240},
   MRCLASS = {08A25},
  MRNUMBER = {0308011},
MRREVIEWER = {M. Kolibiar},
}

@book {MR2619731,
    AUTHOR = {Berman, Joel},
     TITLE = {{C}ongruence {L}attices of {F}inite {U}niversal {A}lgebras},
      NOTE = {Thesis (Ph.D.)--University of Washington},
 PUBLISHER = {ProQuest LLC, Ann Arbor, MI},
      YEAR = {1970},
     PAGES = {64},
   MRCLASS = {Thesis},
  MRNUMBER = {2619731},
       URL = {https://dl.dropboxusercontent.com/u/17739547/diss/berman-phd-thesis.pdf}
}
@COMMENT {http://gateway.proquest.com/openurl?url_ver=Z39.88-2004&rft_val_fmt=info:ofi/fmt:kev:mtx:dissertation&res_dat=xri:pqdiss&rft_dat=xri:pqdiss:7100941},
@misc{Lampe:20161017,
  author        = "Bill Lampe",
  howpublished  = "personal communication",
  note          = "October 17",
  year          = "2016"
}
@article {MR552159,
    AUTHOR = {Pudl{\'a}k, Pavel and T{\.u}ma, Ji{\v{r}}{\'{\i}}},
     TITLE = {Every finite lattice can be embedded in a finite partition
              lattice},
   JOURNAL = {Algebra Universalis},
  FJOURNAL = {Algebra Universalis},
    VOLUME = {10},
      YEAR = {1980},
    NUMBER = {1},
     PAGES = {74--95},
      ISSN = {0002-5240},
   MRCLASS = {06B15 (05C99)},
  MRNUMBER = {552159},
MRREVIEWER = {James W. Lea, Jr.},
       DOI = {10.1007/BF02482893},
       URL = {http://dx.doi.org/10.1007/BF02482893},
}
@article {MR3076179,
    AUTHOR = {Kearnes, Keith A. and Kiss, Emil W.},
     TITLE = {The shape of congruence lattices},
   JOURNAL = {Mem. Amer. Math. Soc.},
  FJOURNAL = {Memoirs of the American Mathematical Society},
    VOLUME = {222},
      YEAR = {2013},
    NUMBER = {1046},
     PAGES = {viii+169},
      ISSN = {0065-9266},
      ISBN = {978-0-8218-8323-5},
   MRCLASS = {08B05 (08B10)},
  MRNUMBER = {3076179},
MRREVIEWER = {James B. Nation},
       DOI = {10.1090/S0065-9266-2012-00667-8},
       URL = {http://dx.doi.org/10.1090/S0065-9266-2012-00667-8},
}
@unpublished{Nation-notes,
author = {J. B. Nation},
title = {Notes on Lattice Theory},
note = {Unpublished notes},
year = {2007, 2016},
URL = {http://www.math.hawaii.edu/~jb/}
}
\end{filecontents*}
\documentclass[12pt]{amsart}
% The following \documentclass options may be useful:
% preprint      Remove this option only once the paper is in final form.
% 10pt          To set in 10-point type instead of 9-point.
% 11pt          To set in 11-point type instead of 9-point.
% numbers       To obtain numeric citation style instead of author/year.

%% \usepackage{setspace}\onehalfspacing

\usepackage{amsmath}
\usepackage{amscd,amssymb,amsthm} %, amsmath are included by default
\usepackage{latexsym,stmaryrd,mathrsfs,enumerate,scalefnt,ifthen}
\usepackage{mathtools}
\usepackage[mathcal]{euscript}
\usepackage[colorlinks=true,urlcolor=black,linkcolor=black,citecolor=black]{hyperref}
\usepackage{url}
\usepackage{scalefnt}
\usepackage{tikz}
\usepackage{color}
\usepackage[margin=1in]{geometry}
\usepackage{scrextend}

%%////////////////////////////////////////////////////////////////////////////////
%% Theorem styles
\numberwithin{equation}{section}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{prop}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{Fact}[theorem]{Fact}
\newtheorem*{fact}{Fact}
\newtheorem{example}[theorem]{Example}
\newtheorem{examples}[theorem]{Examples}
\newtheorem{exercise}{Exercise}
\newtheorem*{lem}{Lemma}
\newtheorem*{cor}{Corollary}
\newtheorem*{remark}{Remark}
\newtheorem*{remarks}{Remarks}
\newtheorem*{obs}{Observation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Acronyms
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% \usepackage[acronym, shortcuts]{glossaries}
%\usepackage[smaller]{acro}
\usepackage[smaller]{acronym}
\usepackage{xspace}

%% \acs{CSP} -- short version of the acronym\\
%% \acl{CSP} -- expanded acronym without mentioning the acronym.\\
%% \acp{CSP} -- plurals.\\
%% \acfp{CSP} -- long forms into plurals.\\
%% \acsp{CSP} -- short form into a plural.\\
%% \aclp{CSP} -- long form into a plural.\\
%% \acfi{CSP} -- Full Name acronym in italics and abbreviated form in upshape.\\
%% \acsu{CSP} -- short form of the acronym and marks it as used.\\
%% \aclu{CSP} -- Prints the long form of the acronym and marks it as used.\\

\acrodef{lics}[LICS]{Logic in Computer Science}
\acrodef{sat}[SAT]{satisfiability}
\acrodef{nae}[NAE]{not-all-equal}
\acrodef{ctb}[CTB]{cube term blocker}
\acrodef{tct}[TCT]{tame congruence theory}
\acrodef{wnu}[WNU]{weak near-unanimity}
\acrodef{CSP}[CSP]{constraint satisfaction problem}
\acrodef{MAS}[MAS]{minimal absorbing subuniverse}
\acrodef{MA}[MA]{minimal absorbing}
\acrodef{cib}[CIB]{commutative idempotent binar}
\acrodef{sd}[SD]{semidistributive}
\acrodef{NP}[NP]{nondeterministic polynomial time}
\acrodef{P}[P]{polynomial time}
\acrodef{PeqNP}[P $ = $ NP]{P is NP}
\acrodef{PneqNP}[P $ \neq $ NP]{P is not NP}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{inputs/proof-dashed}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Put new macros in the macros.sty file
\usepackage{inputs/macros}

\usepackage[backend=bibtex]{biblatex}
\bibliography{inputs/refs.bib}

\begin{document}

\title[Congruences of Partial Algebras]{Congruences of Partial and Total Algebras}
\date{24 October 2016}
\author[W.~DeMeo]{William DeMeo}
\address{University of Hawaii}
\email{williamdemeo@gmail.com}

\maketitle

%% \begin{abstract}\end{abstract}

\section{Introduction}
\label{sec:introduction}
Section~\ref{sec:simple-proof-well} gives a straight-forward proof that every finite
lattice is the congruence lattice of a finite partial algebra.
Bill Lampe~\cite{Lampe:20161017} pointed out
that this result has been known for a long time, and in
Section~\ref{sec:more-gener-appr}
we give some background about closure operators and
begin to develop the framework in which the original result was presented.
We also recall a theorem from Berman's thesis that relates congruence lattices of
partial algebras with those of total algebras.

This is a mash-up of notations, definitions, and theorems
for the Universal Algebra and Lattice Theory Seminar
in Hawaii, Fall Semester 2016.
The notes are unfinished and far from perfect.
Nonetheless, they might stimulate discussion
in the seminar and elicit some criticism
that we can use to improve them.
So far most, if not all, of what appears below is known.
See, for example, \cite{MR2619731, MR0308011, MR0237401, MR2455216}.

\section{A well known result}
\label{sec:simple-proof-well}
In this section we give a straight-forward proof of the fact that every finite
lattice is the congruence lattice of a finite partial algebra.

\begin{lemma}
Let $X$ be a finite set, and let $\Eq(X)$ denote the lattice of equivalence
relations on $X$. If $L\leq \Eq(X)$ is a 0-1-sublattice,
and $\rho \in \Eq(X)$ and $\rho \notin L$, then for some $k < \omega$ there exists a partial
operation $f\colon X^k \rightharpoonup X$ that is compatible with $L$ and
incompatible with $\rho$.
\end{lemma}
\begin{proof}
  First we focus on the relations in $L$ that are above $\rho$.
  Let $\rho^\uparrow \cap L = \{\gamma \in L \mid \gamma \geq \rho\}$.
  Since $\rho\notin L$, we have $\gamma > \rho$ for all $\gamma \in \rho^\uparrow \cap L$.
  Now, $\rho^\uparrow \cap L$ has a least element
  $\rho^* = \Meet (\rho^\uparrow \cap L)$.  Clearly
  $\rho^*\geq \rho$ and since $\rho^* \in L$ we have
  $\rho^*\neq \rho$, so
  $\rho^* > \rho$.  Therefore, there exists $(u,v) \in \rho^* - \rho$.

  Next consider the elements of $L$ that are not above $\rho$. For each such
  $\alpha_i \in L - \rho^\uparrow$ there exists $(x_i, y_i) \in \rho -\alpha_i$.
  Let $(x_1, y_1), \dots, (x_k, y_k)$ be the list of all unique such pairs
  (i.e., each pair appears in the list exactly once).
  Define the partial function $f\colon X^k \rightharpoonup X$ at only two points of $X^k$; specifically, let
  \[ f(x_1, \dots, x_k) = u \quad \text{ and } \quad f(y_1, \dots, y_k) = v. \]
  Then, since $(\forall i)(x_i, y_i) \in \rho$ and $(u,v) \notin \rho$,
  $f$ is incompatible with $\rho$.  On the other hand,
  $(u,v) \in  \rho^* = \Meet (\rho^\uparrow \cap L)$, so
  $(u,v) \in \gamma$  for every $\gamma \in \rho^\uparrow \cap L$, so
  $f$ is compatible with every $\gamma \in \rho^\uparrow \cap L$.

  Finally, for each $\alpha_i\in L$ not above $\rho$ there is at least one pair
  $(x_i, y_i)\notin \alpha_i$.  Therefore, it is impossible for $f$ to be
  incompatible with any such $\alpha_i$.
\end{proof}

\begin{theorem}
Let $X$ be a finite set and let $L\leq \Eq(X)$ be a 0-1-sublattice.
Then there exists a finite partial algebra
$\mathbb X = \< X, F\>$ with $\Con(\mathbb X) =  L$.
\end{theorem}

\begin{proof}
  By the lemma, for each $\rho \in \Eq(X) - L$, there exists $k< \omega$ and
  $f_\rho \colon  X^k \rightharpoonup X$ such that $f_\rho$ is compatible with every relation in
  $L$ and incompatible with $\rho$.  Let $\mathcal{R}$ be the set $\Eq(X) - L$ of
  all equivalence relations on $X$ that do not belong to $L$.  Define,
  $F = \{f_\rho \mid \rho \in \mathcal{R}\}$.  Evidently, $\Con \<X, F\> = L$.
\end{proof}

\section{Closure Systems and Moore Families}
\label{sec:more-gener-appr}

\subsection{Closure systems and operators}
%% \footnote{See J. B. Nation's notes~\cite{Nation-notes} for more details.}
A \defn{closure system} on a set $X$ is a collection $\sC$
of subsets of $X$ that is closed under arbitrary intersection (including the empty
intersection, so $\bigcap \emptyset = X \in \sC$).
Thus a closure system is a complete meet semilattice with respect to subset
inclusion ordering.
Since every complete meet semilattice is automatically a complete lattice
(see \cite[Theorem 2.5]{Nation-notes}),
the closed sets of a closure system form a complete lattice.
%% The sets in $\sC$ are called \defn{closed sets}.

Examples of closure systems that are especially relevant for our work are the following:
\begin{itemize}
\item order ideals of an ordered set
\item subalgebras of an algebra
\item equivalence relations on a set
\item congruence relations of an algebra
\end{itemize}

\newcommand{\cl}{\ensuremath{\operatorname{\sansC}}}

Let $\bP = \<P, \leq \>$ be a poset.
An function $\cl \colon P \to P$ is called a \defn{closure operator} on $\bP$
if it satisfies the following axioms for all $x, y\in P$.
\begin{enumerate}
\item $x \leq \cl x$ (extensivity)
\item $x \leq y$ implies $\cl x \leq \cl y$ (monotonicity)
\item $\cl \cl x = \cl x$ (idempotence)
\end{enumerate}
Thus, a closure operator is an extensive idempotent poset endomorphism,
and the definition above is equivalent to the single axiom
$(\forall\, x, y \in P) (x \leq \cl y \, \longleftrightarrow  \, \cl x \leq  \cl y)$.

\begin{example}
Let $X$ be a set and let $Y \subseteq X$.
Define $\cl_Y\colon \sP(X) \to \sP(X)$ by $\cl_Y (W) = W \cup Y$.
Then $\cl_Y$ is a closure operator on $\<\sP(X), \subseteq\>$.
\end{example}

A \defn{fixed point} of a
function $\cl \colon  P \to P$ is an $x\in P$ satisfying $\cl x = x$.
A fixed point of a closure operator is called \defn{closed}.
%% A \defn{closure operator} on a set $X$ is a map $\sansc  \colon \sP(X) \to \sP(X)$
%% satisfying, for all $A, B \in \sP(X)$,
%% \begin{enumerate}[(a)]
%% \item $A \subseteq \sansC A$ (extensivity)
%% \item $A \subseteq B$ implies $\sansC A \subseteq \sansC B$ (monotonicity)
%% \item $\sansC  \sansC A = \sansC A$ (idempotence)
%% \end{enumerate}
%% A fixpoint of a closure operator is called a \defn{closed set}.
If the poset $\bP = \<P, \leq\>$ happens to be a complete lattice,
then by extensivity the largest element $\top = \Join P$ is
a fixed point of every closure operator on $\bP$.
Also, the collection of fixed points of a closure operator is closed under arbitrary meets.
(Proof: If $\sA$ is a set of fixed points of $\cl$ and
$a \in \sA$, then $\Meet \sA \leq a$, so by monotonicity
$\cl \bigl( \Meet \sA \bigr) \leq \cl a = a$.
Since $a$ was arbitrary,
$\cl \bigl( \Meet \sA \bigr) \leq  \Meet \sA$.
By extensivity,
$\Meet \sA \leq \cl \bigl( \Meet \sA\bigr)$. % \subseteq \bigcap \sA$,
Therefore, $\cl \bigl( \Meet \sA \bigr) =  \Meet \sA$.)
%% ; that is,  $\Meet \sA$ is a fixpoint of $\cl$.)
The set of closure operators on $\bP$
themselves form a complete lattice under the pointwise
order: $\cl_1 \leq  \cl_2$ iff $\cl_1 x \leq  \cl_2 x$ for all $x \in P$.

Some of these observations can be restated as follows:
if $\bP = \<P, \leq\>$ is a complete lattice,
then the set $\sC \subseteq P$ of fixed points of a closure operator
is a \defn{Moore family} on $\bP$---that is,
%% A subset $\sM \subseteq P$ is called a \defn{Moore family} if
$\Join P \in \sC$ and every nonempty subset of $\sC$ is closed under arbitrary meets.
%% If $\bL = \<L, \join, \meet\>$ is a complete lattice with top $\top = \Join L$, then
%% That is, if $\emptyset \neq S \subseteq \sM$, then $\Meet S \in S$.
%% If $\bL = \<L, \join, \meet\>$ is a complete lattice, then a

Conversely, if we are given a Moore family $\sC$ on $\bP$, and if we define
$\cl \colon P \to P$ by
\[
\cl a = \Meet \{b \in \sC \mid a\leq b\},
\]
then $\cl$ satisfies conditions (1)--(3)
above, making it a closure operator.
To summarize, $\sC \subseteq P$ is the set of fixed points (i.e., closed elements)
of a closure operator on
$\bP$ if and only if $\sC$ is a Moore family on $\bP$.

Every Moore family on $\bP$ is itself the universe of a complete lattice with the order inherited
from $\bP$, though the join may differ from the join of $\bP$.

\subsubsection{More Moore families}
The name ``closure system'' is typically reserved for the special case
in which $\bP$ happens to be the powerset Boolean
algebra of a set $X$---that is, $\bP = \<\sP(X), \subseteq\>$; in that case, a Moore family on $\bP$
is called a closure system on $X$.

\begin{example}
  Let $X$ be a set,
  let $\sansR(X) = \bigcup_{n<\omega}\sP(X^n)$ be the set of all finitary
  relations on $X$, and let
  %% let $\Eq(X)$ denote the lattice of equivalence relations on $X$, and let
  $\sansO(X) = \bigcup_{n< \omega} X^{X^n}$ be the set of all finitary operations on $X$.
  Define $F \colon  \sP(\sansR(X)) \to \sP(\sansO(X))$
  and $G \colon \sP(\sansO(X)) \to \sP(\sansR(X))$ as follows:
  if $A \subseteq\sansR(X)$ and $B \subseteq \sansO(X)$, then
  %% \sF_n(S) = \{f \in \sansO(X)X^{X^n} \mid f \text{ is compatible with every $s\in S$}\}
  %% \[  \sF(S) = \bigcup \sF_n(S)  \]
  \[
  F(A) = \{f \in \sansO(X) \mid f \text{ is compatible with every relation in $A$}\},
  \]
  \[
  G(B) = \{\rho \in \sansR(X) \mid \rho \text{ is compatible with every operation in $B$}\}.
  \]
  Then $G \circ F$ is a closure operator on the lattice % $\<\sansR(X), \subseteq\>$
  of all relations on $X$.
\end{example}

\begin{example}
  Let $X$ be a set,
  let $\Eq(X)$ denote the lattice of equivalence relations on $X$, and let
  $X^X$ be the set of all unary operations on $X$.
  Define $F_1 \colon  \sP(\Eq(X)) \to \sP(X^X)$
  and $G_1 \colon \sP(X^X) \to \sP(\Eq(X))$ as follows:
  if $A \subseteq\Eq(X)$ and $B \subseteq X^X$, then
  %% \sF_n(S) = \{f \in \sansO(X)X^{X^n} \mid f \text{ is compatible with every $s\in S$}\}
  %% \[  \sF(S) = \bigcup \sF_n(S)  \]
  \[
  F_1(A) = \{f \in X^X\mid f \text{ is compatible with every relation in $A$}\},
  \]
  \[
  G_1(B) = \{\rho \in \Eq(X) \mid \rho \text{ is compatible with every operation in $B$}\}.
  \]
  Then $G_1 \circ F_1$ is a closure operator on the lattice $\Eq(X)$
  of all equivalence relations on $X$.
\end{example}
\newcommand{\Luv}{\ensuremath{L_{u,v}}}
\newcommand{\bLuv}{\ensuremath{\mathbf{L}_{u,v}}}
\newcommand{\juv}{\ensuremath{\vee_{u,v}}}
\newcommand{\suv}{\ensuremath{\sigma_{u,v}}}
\begin{example}[Pudl{\'a}k-T{\.u}ma~\cite{MR552159}]
  Let $\bL = \<L, \join, \meet\>$ be a lattice, $u, v \in L$, and $u\leq v$.
  Define a subset $\Luv$ of $L$ by
  $\Luv =\{x\in L \mid v\leq x \text{ or } u \nleq x\}$.
  The partial order relation of the lattice $\bL$ induces a lattice order on
  $\Luv$. Denote the resulting lattice by $\bLuv$.
  Then the meet of $\bLuv$ is that of $\bL$, whereas the join of $\bLuv$ is
  \[
  x \juv y =
  \begin{cases}
    x \join y, & \text{ if $u \nleq x \join y$,}\\
    x \join y \join v, & \text{ if $u \leq x \join y$.}
  \end{cases}
  \]
  Define a mapping $\suv \colon L \to \Luv$ as follows:
  \[
  \suv (x)  =
  \begin{cases}
    x, & \text{ if $u \nleq x$,}\\
    x \join v, & \text{ if $u \leq x$.}
  \end{cases}
  \]
  Then $\suv$ is a surjective join-homomorphism. In fact, every
  join-homomorphism $\phi \colon L \to K$ satisfying $\phi(u) = \phi(v)$ splits as
  $\phi =  \psi \circ \suv$ for some $\psi \colon \Luv \to K$.
  (See the commutative diagram in Figure~\ref{fig:splitting}.)
  As a mapping from $\bL$ to itself, $\suv$ does not preserve joins. However,
  $\suv \colon L \to L$ is a closure operator and
  $\Luv$ is the set of fixed points of $\suv$ (the closed sets).

  \begin{center}
    \begin{figure}[h]
      \begin{tikzpicture}[node distance=2cm, scale=3]
        \node (10) at (1,0)  {$\Luv$};
        \node (21) at (2,1)  {$K$};
        \node (01) at (0,1)  {$L$};
        \node (middle) at (1,0.6)  {$\circlearrowleft$};
        \draw[->,thick] (01) -- (21)  node[pos=.5,above] {$\phi$};
        \draw[->,thick] (01) -- (10)  node[pos=.5,left] {$\suv$};
        \draw[->,dashed,thick] (10) -- (21)  node[pos=.5,right] {$\exists \,\psi$};
      \end{tikzpicture}
      \caption{Every join-homomorphism collapsing $u$ and $v$ is divisible by $\suv$.}
      \label{fig:splitting}
    \end{figure}
  \end{center}

\end{example}

\section{Algebraic Closure Systems}
A subset $D$ of an ordered set $P$ is called \defn{up-directed}
if for every $x, y \in D$ there exists $z \in D$ such that
$x \leq z$ and $y \leq z$.
A closure operator $\cl\colon \sP(X) \to \sP(X)$ is called \defn{algebraic} provided,
for all $A\subseteq X$,
\[
\cl A = \bigcup \{\cl F \mid F \subseteq A \text{ and } F \text{ finite } \}.
\]
The collection $\sC$ of closed sets of an algebraic closure operator is called an
\defn{algebraic closure system}.
\begin{theorem}[cf.~\cite{Nation-notes} Thm 3.1]
  Let $\sC$ be the closure system of fixed points of the closure operator $\cl\colon \sP(X) \to \sP(X)$.
  The following are equivalent:
\begin{enumerate}
\item $\cl$ is an algebraic closure operator
\item $\sC$ is an algebraic closure system
\item If $D\subseteq \sC$ is up-directed and $C\subseteq D$ is a chain, then $\bigcup C$ is closed.
\item If $D\subseteq \sC$ is up-directed, then $\bigcup D$ is closed.
\item If $C\subseteq \sC$ is a chain, then $\bigcup C$ is closed.
\end{enumerate}
\end{theorem}

\subsection{Algebraic closure systems are subalgebra lattices}
For an algebra $\bA$, the subalgebra generation operator $\Sg^{\bA}$ is an algebraic
closure operator (on the poset $\<\sP(A), \subseteq\>$) whose fixed points are the
subalgebras of $\bA$.
Thus the lattice $\<\Sub(\bA), \join, \meet\>$ of subalgebras of $\bA$ is an algebraic closure
system.
Conversely, given an algebraic closure system $\sS$, we can construct an algebra
$\bA =\<A, F\>$ so that $\sS = \Sub(\bA)$.
Here is how: let $\cl_{\sS}$ denote the corresponding closure operator.
For each $a_0, a_1, \dots, a_{n-1}, b \in A$ such that
$b \in \cl_{\sS} \bigl(\{a_0, a_1, \dots, a_{n-1}\}\bigr)$, define the $n$-ary operation
$f_{\ba, b}$ so that $f_{\ba, b}(a_0, a_1, \dots, a_{n-1}) = b$ and
for all other tuples $f_{\ba, b}(c_0, c_1, \dots, c_{n-1}) = c_0$.
%% Do this for each $\ba = (a_0, a_1, \dots, a_{n-1})$.
Then define
\[
F = \{f_{\ba, b} \mid  n< \omega, \, \ba \in A^n,  \, b \in \cl_{\sS} \ba\}.
\]
Every subalgebra is the union of its finitely generated subsubalgebras...
{\it (to be continued)}

\subsection{Congruence lattices}
Start with an algebraic closure system $\sS$ of equivalence relations on a set
$A$ and let $\cl_{\sS}$ be the associated closure operator.
Let $(a_0, b_0)$, $(a_1, b_1)$, $\dots$, $(a_{n-1},b_{n-1})$, and $(c_0,
c_1)$ belong to $A\times A$,
and suppose
$(c_0,c_1) \in \cl_{\sS}\bigl(\{(a_0, b_0), (a_1, b_1), \dots,
(a_{n-1},b_{n-1})\}\bigr)$.
Define $f_{\ba, \bb, \bc}\colon (A\times A)^n \to A\times A$
so that
$f_{\ba, \bb, \bc}\bigl((a_0, b_0), (a_1, b_1), \dots, (a_{n-1},b_{n-1})\bigr) =(c_0,c_1)$.
Do this for each triple $\ba$, $\bb$, $\bc$...
{\it (to be continued)}

\section{Strong Congruence Relations}
We use bold letters like $\bx$ to denote tuples like $(x_0, \dots, x_{n-1})$,
where the value $n$ will be clear from context.
Let $\theta$ be an equivalence relation on a set $A$ and suppose
$f\colon A^n \rightharpoonup A$ is a partial function.
We call $\theta$ and $f$
\begin{itemize}
\item \defn{weakly compatible} provided that, for all $(a_i, b_i) \in \theta$,
if $f(\ba)$ and $f(\bb)$ are both defined, then $f(\ba) \mathrel{\theta} f(\bb)$.
\item \defn{strongly compatible} provided that, for all $(a_i, b_i) \in \theta$,
if $f(\ba)$ is defined, then $f(\bb)$ is defined and $f(\ba) \mathrel{\theta} f(\bb)$.
\end{itemize}

Let $\A = \<A, F\>$ be a partial algebra and $\theta$ an equivalence relation on $A$.
We call $\theta$ a \defn{strong} (resp., \defn{weak}) \defn{congruence} of $\A$
if $\theta$ is strongly (resp., weakly) compatible with every $f\in F$.
Denote by $\SCon(\A)$ (resp., $\WCon(\A)$) the set of strong (resp., weak)
congruences of $\A$.
%% If $\A = \<A, F\>$ is a (partial) algebra then a \defn{(strong) congruence relation} of $\A$ is
%% an equivalence relation on $A$ that is (strongly) compatible with every $f\in F$.

Here are some elementary observations about strong and weak congruences.
(See Berman's thesis~\cite{MR2619731} and paper~\cite{MR0308011} for more details and proofs.)
If $\A = \<A, F\>$ is a partial algebra then the set $\SCon(\A)$ of strong congruence relations of
$\A$ forms a sublattice of $\Eq(A)$.
The set $\WCon(\A)$ of weak congruences also forms a lattice, but it is not a sublattice of $\Eq(A)$
since there may be pairs of relations whose join in $\Eq(A)$ is strictly below
their join in $\WCon(\A)$. We will see examples below.

A \emph{total algebra}---an algebra for which all operations are defined everywhere---is
a special case of a partial algebra. In case a partial algebra is not total,
we may refer to it as a \emph{proper partial algebra}.
This simply means that there is at least one operation that is not defined everywhere.
It should be obvious that for total algebras strong and weak congruences reduce to the usual
definition of congruence relation on an algebra.
In particular, if $\A$ is total, then the largest strong congruence of $\A$ is $1_A := A\times A$.
%% Let $\theta$ be a strong congruence of the partial algebra

The converse of the last sentence in the previous paragraph is also true.
That is, if the largest strong congruence of $\A$ is $1_A$, then $\A$ is total.
To see this, suppose $f \in F$ is an $n$-ary partial operation and
denote by $\dom(f)$ the subset of $A^n$ on which $f$ is defined.
Let $\theta$ be a strong congruence of $\A$.
Then the following implication holds:
\[ (a_0, a_1, \dots, a_{n-1})\in \dom(f) \;  \Longrightarrow \;
   [a_0]_\theta \times [a_1]_\theta \times \cdots \times [a_{n-1}]_\theta \subseteq \dom(f).
   \]
That is, if $f$ is defined at an $n$-tuple,
%% $\ba = (a_0, a_1, \dots, a_{n-1})$,
then $f$ must also be defined on the whole Cartesian product of $\theta$-blocks containing the
coordinates of that tuple.
In particular, if $1_A$ is a strong congruence of $\A$, then every operation of
$\A$ must be total, while if $\A = \<A, F\>$ is a \emph{proper partial algebra},
then the largest strong congruence of $\A$
must be strictly below $1_A$.

To summarize, $\A$ is a total algebra iff $\Join \SCon(\A) = 1_A$.

\begin{theorem}[Berman's Thesis~\cite{MR2619731} Thm~1.18]
  \label{thm:berman-1-18}
  Let $\A$ be a finite partial algebra and $\SCon(\A)$ the lattice of strong
  congruence relations of $\A$.  Then there exists a finite algebra $\bA$
  such that $\Con(\bA) = \SCon(\A)$.
\end{theorem}
\begin{remarks}\
  \begin{enumerate}
  \item  Either one or both of the algebras in Theorem~\ref{thm:berman-1-18} can be
    taken to be unary.
  \item It follows easily from Theorem~\ref{thm:berman-1-18} that the class
    of lattices isomorphic to strong congruence lattices of finite
    partial algebras is equal to the class of lattices isomorphic to
    congruence lattices of finite partial algebras.
    (This is~\cite[Thm~1.19]{MR2619731}.)
  \end{enumerate}
\end{remarks}

\section*{Acknowledgments}
The author would like to thank Peter Jipsen
and Bill Lampe for many helpful discussions.

%% \appendix
%% \section{Appendix Title}
%% This is the text of the appendix, if you need one.

%\bibliographystyle{amsplain} %% or amsalpha
%% \bibliographystyle{plain-url}
\printbibliography

\end{document}


\section{Discussion}

% \subsection{Overlapping Rules} Already discussed in previous sections

This section discusses some insights that we gained from our work and contrasts
the scoping mechanisms we have employed with those in DK's algorithm.
We also discuss a way to improve the precision of their scope tracking.
Furthermore we discuss and sketch an extension of our algorithm with
an elaboration to a target calculus, and discuss an extension of our algorithm
with scoped type variables~\citep{scoped-type-variables}.

\begin{comment}
\subsection{Implementation}
Anything to say about the implementation? Do we have one?
\end{comment}

\subsection{Contrasting Our Scoping Mechanisms with DK's}\label{sec:discussion:scoping}

A nice feature of our worklists is that, simply by interleaving variable declarations and
judgment chains, they make the scope of variables
precise.  DK's algorithm deals with garbage collecting variables in a
different way: through type variable or existential variable
markers (as discussed in Section~\ref{ssec:DK_Algorithm}).  Despite
the sophistication employed in DK's algorithm to keep scoping precise,
there is still a chance that unused existential variables leak their
scope to an output context and accumulate indefinitely.
For example, the derivation of the judgment $(\lam x)~() \Lto 1$ is as follows
$$
\inferrule*
{
    \inferrule*
    {
        \inferrule*
        {
            \inferrule*
            {\ldots x \To \al \ldots \\ \ldots \al \le \bt \ldots}
            {\Gm, \al, \bt, x:\al \vdash x \Lto \bt \dashv \Gm_1, x:\al}
        }
        {\Gm \vdash \lam x \To \al \to \bt \dashv \Gm_1}
        \\
        \inferrule*
        {\ldots () \Lto \al \ldots}
        {\Gm_1 \vdash \appInf{\al \to \al}{()}{\al} \dashv \Gm_2}
    }
    {\Gm \vdash (\lam x)~() \To \al \dashv \Gm_2}
    \\
    \inferrule*
    {~}
    {\Gm_2 \vdash 1 \le 1 \dashv \Gm_2}
}
{\Gm \vdash (\lam x)~() \Lto 1 \dashv \Gm, \al = 1, \bt = \al}
$$
where $\Gm_1 := (\Gm, \al, \bt = \al$) solves $\bt$,
and $\Gm_2 := (\Gm, \al = 1, \bt = \al$) solves both $\al$ and $\bt$.

If the reader is not familiar with DK's algorithm,
he/she might be confused about the inconsistent types across judgment.
As an example, $(\lam x)~()$ synthesizes $\al$,
but the second premise of the subsumption rule uses $1$ for the result.
This is because a context application $[\Gm,\al=1,\bt=\al]\al = 1$ happens between the premises.

The existential variables $\al$ and $\bt$ are clearly not used after the subsumption rule,
but according to the algorithm, they are kept in the context
until some parent judgment recycles a block of variables,
or to the very end of a type inference task.
In that sense, DK's algorithm does not control the scoping of variables precisely.
%However, it is a minor issue that does not affect the soundness and completeness properties.

Two rules we may blame for not garbage collecting correctly are the inference rule for lambda
functions and an application inference rule:
$$
\inferrule*[right=$\mathtt{DK\_{\to}I{\To}}$]
{\Gamma, \al, \bt, x:\al \vdash e \Lto \bt \dashv \Delta, x:\al, \Theta}
{\Gamma \vdash \lam e \To \al \to \bt \dashv \Delta}
\\
\inferrule*[right=$\mathtt{DK\_\forall App}$]
{\Gamma, \al \vdash [\al/a] \appInf{A}{e}{C} \dashv \Delta}
{\Gamma \vdash \appInf{\all A}{e}{C} \dashv \Delta}
$$
In contrast, Rule 25 of our algorithm collects the existential variables
right after the second judgment chain,
and Rule 27 collects one existential variable similarly:
\[\Gm \Vdash \lam e \To_a \jg \rrule{25}
\Gm,\al,\bt \Vdash [\al\to\bt/a]\jg, x:\al \Vdash e\Lto \bt\]
\[\Gm \Vdash \appInfAlg{\all A}{e} \rrule{27} \Gm,\al \Vdash \appInfAlg{[\al/a]A}{e}\]
It seems impossible to achieve a similar outcome in DK's system by only modifying these two rules.
Taking $\mathtt{DK\_{\to}I{\To}}$ as an example,
the declaration or solution for $\al$ and $\bt$ may be referred to by subsequent judgments.
Therefore leaving $\al$ and $\bt$ in the output context is the only choice,
when the subsequent judgments cannot be consulted.

To fix the problem, one possible modification is on the algorithmic subsumption rule,
as garbage collection for a checking judgment is always safe:
$$
\inferrule*[right=$\mathtt{DK\_Sub}$]
{\Gamma, \blacktriangleright_{\al} \vdash e \To A \dashv \Theta \\
\Theta \vdash [\Theta]A \le [\Theta]B \dashv \Delta, \blacktriangleright_{\al}, \Delta'}
{\Gamma \vdash e \Lto B \dashv \Delta}
$$
Here we employ the markers in a way they were originally not intended for.
We create a dummy fresh existential $\al$ and add a marker to the input context of the inference judgment.
After the subtyping judgment is processed we look for the marker and drop everything afterwards.
We pick this rule because it is the only one where a checking judgment calls an inference judgment.
That is the point where our algorithm recycles variables---right after a judgment chain is satisfied.
After applying this patch, to the best of our knowledge,
DK's algorithm behaves equivalently to our algorithm in terms of variable scoping.
However, this exploits markers in a way they were not intended to be used and seems ad-hoc.

% \subsection{Scoped type variables} Not discussed for this paper

%-------------------------------------------------------------------------------
\subsection{Elaboration}

Type-inference algorithms are often extended with an
associated elaboration. For example, for languages with implicit
polymorphism, it is common to have an elaboration to a variant of
System F~\citep{reynolds1983types}, which recovers type information and explicit type
applications. Therefore a natural question is whether our algorithm
can also accommodate such elaboration.
While our algorithmic reduction does not elaborate to System F,
we believe that it is not difficult to extend the algorithm with a (type-directed) elaboration.
We explain the rough idea as follows.

Since the judgment form of our algorithmic worklist contains a collection of judgments,
elaboration expressions are also generated as a list of equal length to
the number of judgments (\emph{not judgment chains}) in the worklist.
As usual, subtyping judgments translate to coercions (denoted by $f$ and
represented by System F functions),
all three other types of judgments translate to terms in System F (denoted by $t$).

Let $\Phi$ be the elaboration list, containing translated type coercions and terms:
$$\Phi ::= \nil \mid \Phi, f \mid \Phi, t$$

Then the form of our algorithmic judgment becomes:
$$\Gamma \hookrightarrow \Phi$$

We take Rule 18 as an example, rewriting small-step reduction in a relational style,
$$
\inferrule*[right=$\mathtt{Translation\_18}$]
{\Gamma \Vdash e \To_a a \le B \hookrightarrow \Phi, f, t}
{\Gamma \Vdash e \Lto B \hookrightarrow \Phi, f~t}
$$
As is shown in the conclusion of the rule,
a checking judgment at the top of the worklist corresponds to a top element for elaboration.
The premise shows that one judgment chain may relate to more than one elaboration elements,
instead, one single judgment relates to one elaborated term.
The outer judgment, being processed before inner ones,
elaborates to the top element in the elaboration list.

Moreover, existential variables need special treatment, since they may be solved at any point,
or be recycled if not solved within their scopes.
If an existential variable is solved, we not only propagate the solution to the other judgments,
but also replace occurrences in the elaboration list.
If an existential variable is recycled, meaning that it is not constrained,
we can pick any well-formed monotype as its solution.
The unit type $1$, as the simplest type in the system, is a good choice.

\subsection{Lexically-Scoped Type Variables}
We have further extended the type system with the support for
lexically-scoped type variables~\citep{scoped-type-variables}.
Our Abella formalization for this extension proves
all the metatheory we discuss in Section~\ref{sec:metatheory}.

From a
practical point of view, this extension allows the implementation of a function
to refer to type variables from its type signature. For example,
$$(\lam{\lam[y] (x:a)}) : \all[a~b] a \to b \to a$$
has an annotation $(x:a)$ that refers to the type variable $a$ in the type signature.
This is not a surprising feature, since the declarative system already accepts similar programs
$$
\inferrule*[right=$\mathtt{DeclAnno}$]
{
    \Psi \vdash \all A \quad
    \inferrule*[right=$\mathtt{Decl\forall I}$]
    {\Psi,a \vdash e \Lto A}
    {\Psi\vdash e\Lto \all A}
}
    {\Psi\vdash (e: \all A)\To \all A}
$$

The main issue is the well-formedness condition.
Normally $\Psi \vdash (e : A)$ follows from $\Psi \vdash e$ and $\Psi \vdash A$.
However, when $A = \all A'$, the type variable $a$ is not in scope at $e$,
therefore $\Psi \vdash e$ is not derivable.
To address the problem, we add a new syntactic form that explicitly binds a
type variable simultaneously in a function and its annotation.
$$
\begin{array}{l@{\qquad}lcl}
\text{Expressions}\qquad&e &::=&\quad \ldots \mid \Lambda a.~e:A
\end{array}
$$

This new type-lambda syntax $\Lambda a.~e:A$ actually annotates its body $e$ with $\all A$,
while making $a$ visible inside the body of the function.
The well-formedness judgments are extended accordingly:
$$
\inferrule*[right=$\mathtt{wf_d}\Lambda$]
    {\Psi,a \vdash e \quad \Psi,a \vdash A}
    {\Psi \vdash \Lambda a.~e:A}
\qquad
\inferrule*[right=$\mathtt{wf\_}\Lambda$]
    {\Gm,a \vdash e \quad \Gm,a \vdash A}
    {\Gm \vdash \Lambda a.~e:A}
$$

Corresponding rules are introduced for both the declarative system and the algorithmic system:
$$
\inferrule*[right=$\mathtt{Decl}\Lambda$]
    {\Psi,a \vdash A \quad \Psi,a \vdash e\Lto A}
    {\Psi\vdash \Lambda a.~e:A \To \all A}
$$
$$\Gm \Vdash \Lambda a.~e:A \To_b \jg \algrule \Gm \Vdash [(\all A)/b]\jg, a \Vdash e \Lto A$$

In practice, programmers would not write the syntax $\Lambda a.~e : A$ directly.
The ScopedTypeVariables extension of Haskell is effective only
when the type signature is explicitly universally quantified
(which the compiler translates into an expression similar to $\Lambda a.~e : A$);
otherwise the program means the normal syntax $e : \all A$
and may not later refer to the type variable $a$.

We have proven all three desired properties for the extended system,
namely soundness, completeness and decidability.


\chapter{The $N$-representability problem}\label{ch2}

For a given wave function, the \gls{2dm} can be calculated using its definition. However, when given a random symmetric matrix,
is it possible to find a corresponding (ensemble of) wave function which has the given matrix as the \gls{2dm}? This is the essence of the $N$-representability problem.

\section{General \mbox{$N$-representability} theorem}\label{ch2-general-n-rep}
A graphical depiction of this theorem can be found in \Vref{ch2-fig1}. The boundary of the convex set
of $N$-representable $p$th-order reduced density matrices is formed by an infinite number of tangent hyperplanes, where
each hyperplane represents a $p$-particle Hamiltonian and its ground state energy.
\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{n-representability}
    \caption{Graphical depiction of the necessary and sufficient conditions for $N$-representability. Every Hamiltonian $H^{(p)}$ can be represented by a hyperplane that bounds the convex set of $N$-representable ${^p\Gamma}$.}
    \label{ch2-fig1}
\end{figure}

\section{Approximately $N$-representability conditions}\label{2-approx-n-representability}
In \Vref{ch2-general-n-rep} we showed the necessary and sufficient conditions for $N$-representability. These required the knowledge of the
ground state energy of every possible Hamiltonian and are thus not usable as a sufficient condition. We can, however, use it as a necessary
condition: if we restrict XX to Hamiltonians of which we know the ground state energy or a lower bound on it, we can approximate the convex set of $N$-representable \gls{2dm}'s.
\begin{figure}
    \centering
    \includegraphics[width=0.9\textwidth]{approx-n-representability}
    \caption{Graphical depiction of the necessary conditions for $N$-representability. $H_1^{(p)}$ belongs to the class of Hamiltonians of which we know a bound on ground state energy while $H_2^{(p)}$ does not. The true convex set of $N$-representable ${^p\Gamma}$ is smaller than the approximate convex set delimited by the Hamiltonians of the class of $H_1^{(p)}$.}
    \label{ch2-fig3}
\end{figure}
In \Vref{ch2-fig3} we give a graphical interpretation of this idea. The approximate set of $N$-representable \gls{2dm} will be larger than the true set: there will be \gls{2dm}'s which fulfil all the necessary conditions but are still not derivable from an ensemble of wave functions.
As a consequence the variational optimization of the \gls{2dm} will give a lower bound on the energy. This is one of the highly attractive features of \gls{v2dm}.

\section{Symmetry considerations}\label{ch2-sym}

\subsection{Spatial point group symmetry}\label{ch2-pointsym}

For example, the $\ce{C2H4}$ molecule shown in \Vref{2-fig4} has $D_{2h}$ symmetry.
\begin{figure}[h]
    \centering
    \chemfig{H-[1]C(-[3]H)=C(-[1]H)(-[:-45]H)}
    \caption{The ethylene molecule has $D_{2h}$ symmetry.}
    \label{2-fig4}
\end{figure}
The main two-fold rotation axis is the connecting axis between the two carbon atoms (the z-axis). The two two-fold rotation axes are the x- and y-axis. The three reflection planes are xy, xz and yz.

As an example, we show the character table and the multiplication table of $C_{2}$ group in \Vref{2-tab1}.
\begin{table}
    \begin{subtable}{.5\linewidth}
        \centering
        \begin{tabular}{c|cc}
            & $E$ & $C_2$ \\
            \hline
            A & 1 & 1 \\
            B & 1 & -1
        \end{tabular}
        \caption{Character table of $C_2$}
        \label{2-tab1a}
    \end{subtable}
    ~
    \begin{subtable}{.5\linewidth}
    \centering
    \begin{tabular}{c|cc}
        & A & B \\
        \hline
        A & A & B \\
        B & B & A
    \end{tabular}
    \caption{Multiplication table of $C_2$}
    \label{2-tab1b}
    \end{subtable}
    \caption{$C_2$ overview: it has 2 classes of operations. The identity operation and rotations over $180\degree$. The two irreducible representations are $A$ and $B$.}
    \label{2-tab1}
\end{table}
The character table contains the trace of the matrices of the irreducible representations. It it split up into conjugacy classes as the trace is invariant under a similarity transformation. These tables are extremely useful for decomposing a representation in its irreducible parts. The first irreducible representation $A$ is called the trivial representation because all the representation matrices (scalars in this case) are one. Every group has this irreducible representation.

\section{The doubly-occupied Hilbert space}\label{ch2-doci}
In previous sections, we only made general assumptions about the (ensemble of) wave functions from which the \gls{2dm} is derivable. All wave functions should be normalized and antisymmetric. For symmetry, we made assumptions on the quantum numbers of the wave function: it should be a singlet wave function, or the wave function should transform according to a certain irreducible representation.
But we could make other or additional assumptions. If we take a look at the \acrfull{fullci} expansion of the wave function, we see that a Slater determinant is the basic building block
\begin{equation}
    \ket{\Psi} = \sum_\mathbf{k} \sum_\mathbf{s} c_{\mathbf{k};\mathbf{s}} ~ \padd{k_1 s_1}\padd{k_2s_2}\ldots\padd{k_Ns_N}\ket{},
        \label{2-eq106}
\end{equation}

% vim: spell spelllang=en syntax=tex  tw=140


\section{Machine Learning Fundamentals} \label{sec:bt/MLF}

Artificial intelligence is a field of research that has been practiced for a very long time, contrary to popular belief. The first work that is now recognized as AI was written by \textcite{mcculloch1943}. Even still, the concept of artifacts operating under their own control can be traced back to Alexandria ca. 250 BC, where a water regulator was built that could maintain a constant flow rate. Other examples of self-regulating feedback control systems include the steam engine governor and the thermostat, all invented before the 19th-century \cite{russell2009}. This thesis will concentrate on machine learning, a particular form of artificial intelligence that employs prior knowledge of historical data to tackle tasks that are too difficult to solve with fixed programs written and designed by human beings \cite{goodfellow2016}.

% \subsection{Statistical Inference}
\subsection{Learning Algorithms}

A machine learning algorithm is characterized by the fact that it can learn properties from data. \textcite{mitchell1997} famously defines this aspect of learning as "A computer program is said to learn from experience $E$ with respect to some class of tasks $T$ and performance measure $P$, if its performance at tasks in $T$, as measured by $P$, improves with experience $E$." Since machine learning algorithms can be employed in a wide range of problems and trained by an equally wide range of methods, $T$, $P$, and $E$ in this definition can be constructed as just about anything. However, a very common class of tasks $T$ central to this thesis is that of \textit{classification}. The experience $E$ required to train towards this task is usually provided through either \textit{supervised-} or \textit{unsupervised learning}.

\subsubsection{Classification}

% In the classification task, the computer program is asked to determine which of $k$ discrete categories some input belongs.
Classification is the task of determining which of $k$ discrete categories some input belongs. Given data (experience $E$) produced by a function $f:\mathbb{R}^{2}\to\{1,\dots,k\}$, a learning algorithm tasked with classification will generate a hypothesis $h:\mathbb{R}^{2}\to\{1,\dots,k\}$ that approximates $f$. Given an input vector $\bm{x}$, $h(\bm{x})$ outputs a probability distribution over possible categories. One popular application is that of object detection, where an image is given as the input $\bm{x}$, and the output is the category to which an object in the image belongs. If $k=2$, the learning problem is called binary classification, and the hypothesis $h$ merely outputs the probability of whether an input represents a single target category or not. Multi-class classification is more common in the general case, however.

% \subsubsection{The No Free Lunch Theorem}

Since we often cannot assume any prior knowledge of the inherent properties of $f$, choosing a hypothesis $h$ with which to approximate it is no trivial task. We say that $h$ is selected from a \textit{hypothesis space} $\mathcal{H}$, which needs to be defined by the learning algorithm designer. Looking at figure \ref{fig:bt_hypotheses}, one can see the importance of choosing a hypothesis space that is complex enough to approximate $f$ accurately yet simple enough that the function does not overfit. For this example, a 12-degree polynomial is required to produce an approximation that perfectly agrees with all the data. However, since we cannot assume that $f$ is not stochastic, this polynomial might generalize poorly to unseen data. In such a case, a simpler hypothesis in a linear or a sinusoidal function might be the optimal choice.

\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{figures/bt_hypotheses.png}
    \caption{Finding hypotheses to fit data. The four plots each show best-fit functions from four different hypothesis spaces trained on the same dataset.}
    \source{\cite{russell2009}}
    \label{fig:bt_hypotheses}
\end{figure}

\subsubsection{Supervised Learning}

A machine learning algorithm can be called a supervised learning algorithm if it is trained by experiencing a dataset of examples $\bm{x}$, where each example is associated with a target $y$. The training process thus becomes to approximate a function that can reproduce $y$ given $\bm{x}$.

One classic learning algorithm is linear regression, which is supervised learning in its simplest form \cite{goodfellow2016}. The goal of linear regression is to predict a target value $\hat{y}\in\mathbb{R}$ from an $n$-dimensional input vector $\bm{x}\in\mathbb{R}^n$. Since we know then that the output should be a linear function of the input, the problem becomes to approximate the hypothesis given by equation \ref{eq:bt_linReg}. Here $\bm{w}\in\mathbb{R}^n$ is a vector of model parameters, which control the behavior of the system.

\begin{equation}
    \label{eq:bt_linReg}
    h(\bm{x})=\hat{y}=\bm{w}^T\bm{x}
\end{equation}

Now, to determine the optimal value of $\bm{w}$, we need a performance measure $P$. For this particular problem, a typical choice is the \textit{mean squared error} (MSE), given in equation \ref{eq:bt_MSE}. MSE is calculated from a matrix of $m$ input vectors $\bm{X}=\{\bm{x}_1,\dots,\bm{x}_m\}$, their corresponding $m$ target values $\bm{y}=\{y_1,\dots,y_m\}$, and model parameters $\bm{w}$.

\begin{equation}
    \label{eq:bt_MSE}
    MSE=\frac{1}{m}\sum_{i}(\hat{\bm{y}}-\bm{y})^2
    =\frac{1}{m}||\hat{\bm{y}}-\bm{y}||^2_2
\end{equation}

By setting $\hat{\bm{y}}=\bm{y}$, one can see that $MSE=0$, and furthermore that it increases linearly with the euclidean distance between $\hat{\bm{y}}$ and $\bm{y}$. As such, the optimal model parameters can be obtained by minimizing $MSE$ with respect to $\bm{w}$. This can be done by solving for where its gradient is $\bm{0}$, as is in equations \ref{eq:bt_MSE_gradientB} to \ref{eq:bt_MSE_gradientE}.

\begin{equation}
    \label{eq:bt_MSE_gradientB}
    \nabla_{\bm{w}}MSE=\bm{0}
\end{equation}
\begin{equation}
    \Rightarrow \nabla_{\bm{w}}\frac{1}{m}||\hat{\bm{y}}-\bm{y}||^2_2=\bm{0}
\end{equation}
\begin{equation}
    \Rightarrow \nabla_{\bm{w}}\frac{1}{m}||\bm{X}\bm{w}-\bm{y}||^2_2=\bm{0}
\end{equation}
\begin{equation*}
    \vdots
\end{equation*}
\begin{equation}
    \label{eq:bt_MSE_gradientE}
    \Rightarrow \bm{w}=(\bm{X}^T\bm{X})^{-1}\bm{X}^T\bm{y}
\end{equation}

Evaluation of equation \ref{eq:bt_MSE_gradientE} results in a value of $\bm{w}$ which optimally fits the training dataset. As such, it constitutes a simple learning algorithm \cite{goodfellow2016}.

% For object detection, each image in the dataset is accompanied by a value representing the object it displays.

% \subsection{Decision Tree Classifier}

% Decision tree induction is one of the simplest and yet most successful forms of machine learning (\cite{russell2009}). It is also a supervised learning algorithm, as it requires a dataset of labeled examples to be trained. The Decision Tree Classifier takes a vector of attribute values as input and returns a "decision." It reaches this decision by performing a sequence of tests on one or more attributes. An example is presented in figure \ref{fig:bt_decision_tree}. Here, one can imagine that the species of an animal is to be determined based upon a set of attributes \{"Has feathers?", "Can fly?", "Has finns?"\}. The likely animal species can be determined by following a path from the root node to a leaf node. Although this example is simple, the general principle holds for more complex classification problems as well.

% \begin{figure}[h]
%     \centering
%     \includegraphics[width=0.5\textwidth]{Images/bt_decision_tree.png}
%     \caption{Decision Tree Example. Each internal node represents a test on one attribute, and its branches are labeled with possible attribute values. Leaf nodes represent a decision.}
%     \label{fig:bt_decision_tree}
% \end{figure}

% The training process of decision trees is done with specialized algorithms, the specific details of which are outside the scope of this thesis. However, they are usually based on a greedy divide-and-conquer strategy, where the training dataset is split on whatever attribute is most important. Which attribute this is, and at what attribute value the split is done, is determined by a notion of \textit{information gain}.

% \subsection{Ensemble Learning}

% Ensemble learning is a relatively straightforward method that has a remarkable effect of reducing generalization error (\cite{goodfellow2016}). When a machine learning model has been trained, one is left with a single hypothesis $h$ that, to a certain degree, is able to approximate some function $f$. However, if the model is trained once more, the resulting approximation would likely produce slightly differing predictions. The notion of ensemble learning is to train multiple independent models and combine their predictions. Specifically, by determining the output by majority voting or an average, the method is termed \textit{model averaging}.
% Some ensemble methods construct their ensemble of models by random, others by some rationale. \textit{Bootstrap aggregating} (bagging), for example, trains each model on a subset of the original training dataset by sampling at random with replacement. This strategy ensures an inherent distinction between models, which offers a broader hypothesis space and reduced generalization error.


\chapter{CHAPTER TITLE}
\label{chp:chapter_1}

This chapter describes the ... In Section~\ref{sec:SECTIONTITLE}, examples are given om how to use tables and figures in this MSc thesis.

\section{SECTION TITLE}
\label{sec:SECTIONTITLE}

Define models with math, such that
%
\begin{equation}
x = a^2 + b^2,
\label{eq:EQUATION}
\end{equation}
%
where $a$ and $b$ are your parameters, define your system.

Remarks on style:

\begin{enumerate}
	\item use `Section` name to refer to sections when citing (so Section~\ref{sec:SECTIONTITLE} not Sec.~\ref{sec:SECTIONTITLE} or Subsection~\ref{sec:SECTIONTITLE}); Same comment applies to Tables, Algorithms and Figures
	\item Tables and figures must be at the top of the page---use [t] marker (not [h], for `here`);
	\item Every caption should end with a period;
	\item Encapsulate equations in `()` brackets and do not add word `equation before` (therefore `in~(\ref{eq:EQUATION})`, not `in Equation~\ref{eq:EQUATION}` or in Eq.~\ref{eq:EQUATION});
	\item Equations are sentences, so punctuation applies at the end of it (comma, semicolon or full-stop).
\end{enumerate}

Here is a simple table

\begin{table}[t]
\centering
\begin{tabular}{| l | c | r |}
\hline
left aligned & centred & right aligned \\
\hline \hline
12 & 34 & 56 \\
\hline
\end{tabular}
\caption{Complete sentence describing the tabular data. Caption should summarize the conclusions of the result.}
\label{tab:table_1}
\end{table}

Here is a simple figure.

\begin{figure}[t]
\includegraphics[width=\textwidth]{template-pics/tud-ens-logo-tikz/tud-ens-logo}
\caption{Complete sentence describing the figure thoroughly. Caption should summarize the conclusions of the result.}
\label{fig:example-figure}
\end{figure}

Citations are here~\cite{polastre2004analysis,powercast_website,hester2016persistent,schaper_msc_thesis_2017,dementyev_uist_2016}. See `bib/MyMScTUDENSThesisBibFile.bib` file for a list of requirements when typesetting a bibliography.


%!TEX root = ../thesis.tex
%*******************************************************************************
%*********************************** Third Chapter *****************************
%*******************************************************************************

\chapter{Numerical Methods}  %Title of the Third Chapter

\ifpdf
    \graphicspath{{Chapter3/Figs/PDF/}{Chapter3/Figs/}}
\else
    \graphicspath{{Chapter3/Figs/}}
\fi

In this chapter, we are going to discuss the details of the numerical method used in \texttt{Gmunu} \cite{cheong2020gmunu,cheong2020gmunu_amr}.
In the fully-constrained scheme, the evolution of relativistic hydrodynamics in dynamical spacetime
consists of a set of coupled hyperbolic-elliptic system.
Firstly, we discuss the numerical method adopted for the hyperbolic system in \texttt{Gmunu},
including the high-resolution shock-capturing (HRSC) method and the finite volume method.
Then, we discuss the multigrid solver in \texttt{Gmunu},
which is used to solve the elliptic system.

%********************************** %First Section  **************************************
\section{High-resolution shock-capturing (HRSC) methods}
The high-resolution shock-capturing (HRSC) methods is a class of methods commonly used to
reproduce accurately the discontinuous features in the solution
with no spurious oscillation \cite{harten1997high}.
Note that the HRSC methods can be distinguished in \textit{finite-difference (conservative)} method
which evolves the \textit{pointwise values} of the solution,
and \textit{finit-volume (conservative)} method which evolves the \textit{cell average} of the solution.
Although the accuracy of finite-difference method can be extended to higher order easily,
it is extremely diffcult to extend the method to general non-uniform grids \cite{merriman2003understanding}.
On the other hand,
the finite-volume methods are natural to conservative scheme as well as non-structured grid,
but the multidimensional reconstruction algorithm is complicated and computational expensive especially for higher-order method.\\
In this section,
we will first discuss the finite-volume conservative methods,
and then focus on the \textit{Godunov methods} which guarantee the upwind property of conservative non-linear equations \cite{van1999introduction}.

\subsection{Finite-volume conservative methods}
Given the conservative equation in orthogonal coordinate system $(x^1, x^2, x^3)$ in form
\begin{align}\label{eq:finite_vol_cons}
    \partial_t \mathbf{q} + \frac{1}{\sqrt{\hat{\gamma}}}\hat{\nabla}_i \left( \sqrt{\hat{\gamma}} \mathbf{f}^i \right)
    &= \mathbf{s} + \mathbf{s}_{geom},
\end{align}
where $\mathbf{q}$ are the conserved variables,
$\mathbf{f}^i$ are the flux terms, $\mathbf{s}$ are the source terms
and $\mathbf{s}_{geom}$ are the geometrical source term which is related to the 3-Christoffel symbol
$\hat{\Gamma}^i{}_{jk}$ of the reference metric $\hat{\gamma}_{ij}$.
We can then discretize equation (\ref{eq:finite_vol_cons}) on a computational domain divided into $N_1 \times N_2 \times N_3$ cells.
Each cells can be represented by a tuple of integers $(i,j,k)$ where $1 \leq i \leq N_1$, $1 \leq j \leq N_2$ and $1 \leq k \leq N_3$.
The cell bounds are given by
\begin{align}
    (x^1_{i-1/2}, &x^1_{i+1/2}), & (x^2_{j-1/2}, &x^2_{j+1/2}), & (x^3_{k-1/2}, &x^3_{k+1/2}).
\end{align}
Thus, the mesh cell spacings are
\begin{align}
    \Delta x^1_i &= x^1_{i+1/2} - x^1_{i-1/2}, & \Delta x^2_j &= x^2_{j+1/2}- x^2_{j-1/2}, & \Delta x^3_k &= x^3_{k+1/2} - x^3_{k-1/2},
\end{align}
and the cell centres are
\begin{align}
    x^1_i &= \frac{1}{2} \left(x^1_{i+1/2} + x^1_{i-1/2}\right), & x^2_j &= \frac{1}{2} \left( x^2_{j+1/2}- x^2_{j-1/2} \right),
    & x^3_k &= \frac{1}{2} \left( x^3_{k+1/2} - x^3_{k-1/2} \right).
\end{align}
By integrating equation \ref{eq:finite_vol_cons} over cell volume and applying divergence theorem on the flux terms,
it becomes
\begin{align}
    \begin{split}
    \frac{d}{dt} \left\langle \mathbf{q} \right\rangle_{i,j,k} = - \frac{1}{\Delta V_{i,j,k}} \bigg\{ &\left[
    \left. \left( \left\langle \mathbf{f} \right\rangle^1 \Delta A^1 \right) \right|_{i+1/2,j,k} -
    \left. \left( \left\langle \mathbf{f} \right\rangle^1 \Delta A^1 \right) \right|_{i-1/2,j,k} \right] \\
    + &\left[
    \left. \left( \left\langle \mathbf{f} \right\rangle^2 \Delta A^2 \right) \right|_{i,j+1/2,k} -
    \left. \left( \left\langle \mathbf{f} \right\rangle^2 \Delta A^2 \right) \right|_{i,j-1/2,k} \right] \\
    + &\left[
    \left. \left( \left\langle \mathbf{f} \right\rangle^3 \Delta A^3 \right) \right|_{i,j,k+1/2} -
    \left. \left( \left\langle \mathbf{f} \right\rangle^3 \Delta A^3 \right) \right|_{i,j,k-1/2} \right] \bigg\} \\
    + &\left\langle \mathbf{s} \right\rangle_{i,j,k}
    + \left\langle \mathbf{s}_{geom} \right\rangle_{i,j,k}
    \end{split}
\end{align}
where the cell volume and the volume-average are defined as
\begin{align}
    \Delta V_{i,j,k} &\coloneqq \int_{cell} \sqrt{\hat{\gamma}} dx^1 dx^2 dx^3, &
    \left\langle \bullet \right\rangle &\coloneqq \frac{1}{\Delta V_{i,j,k}} \int_{cell} \bullet \sqrt{\hat{\gamma}} dx^1 dx^2 dx^3
\end{align},
while the cell surface and the surface-average are defined as
\begin{align}
    \Delta A^i &\coloneqq \int_{surface} \sqrt{\hat{\gamma}} dx^{j,j\neq i}, &
    \left\langle \bullet \right\rangle &\coloneqq \frac{1}{\Delta A^i} \int_{surface} \bullet \sqrt{\hat{\gamma}} dx^{j,j\neq i}.
\end{align}
Since the reference metric $\hat{\gamma}_{ij}$ is time-independent,
the cell volume, cell surface and the volume-averaged 3-Christoffel symbols
$\left\langle \hat{\Gamma}^i{}_{jk} \right\rangle$ in the geometrical source term
are determined once the coordinate is chosen.
We have included these quantities in Appendix.

\subsection{Godunov methods}
\label{section3.1.2}
For simplicity, we consider one-dimensional hyperbolic conservation laws
\begin{align}\label{eq:conservation_law}
    \partial_t \mathbf{q}\left(x,t\right) + \partial_x \mathbf{f} \left[\mathbf{q}\left(x,t\right)\right] &= 0,
\end{align}
We apply the discretization on spatial domain into computing cell $I_j$ with size $\Delta x$
\begin{align}
    I_j &= \left[ x_{j-1/2},x_{j+1/2} \right], & \Delta x &= x_{j+1/2}-x_{j-1/2},
\end{align}
and time slices $\left[t^n, t^{n+1}\right]$.
Thus, equation (\ref{eq:conservation_law}) can be recasted into a \textit{conservative} scheme as
\begin{align}
    \left\langle\mathbf{q}\right\rangle^{n+1}_j &= \left\langle\mathbf{q}\right\rangle^n_j
    + \frac{\Delta t}{\Delta x} \left( \left\langle\mathbf{f}\right\rangle_{j-1/2} - \left\langle\mathbf{f}\right\rangle_{j+1/2} \right),
\end{align}
where
\begin{align}
    \left\langle\mathbf{q}\right\rangle^{n}_j &\coloneqq \frac{1}{\Delta x} \int^{x_{j+1/2}}_{x_{j-1/2}} \mathbf{q} \left(x, t^n\right) dx
\end{align}
is the \textit{cell-average} and
\begin{align}
    \left\langle\mathbf{f}\right\rangle_{j\pm 1/2} &\coloneqq \frac{1}{\Delta t} \int^{t^{n+1}}_{t^n} \mathbf{f} \left[\mathbf{q}\left(x_{j\pm 1/2},t\right)\right] dt
\end{align}
is the \textit{numerical fluxes}.\\
In Godunov's original approach \cite{konstantinovich1959difference},
he considered a piecewise-constant distribution of data
\begin{align}
    \mathbf{q}(x, t^n) &=
    \begin{cases}
        \left\langle\mathbf{q}\right\rangle^{n}_j  &\text{if } x \leq x_{j+1/2}, \\
        \left\langle\mathbf{q}\right\rangle^{n}_{j+1}  &\text{if } x >x_{j+1/2},
    \end{cases}
\end{align}
and built a local Riemann problem
$\mathcal{RP}\left(\left\langle \mathbf{q}\right\rangle_{L}, \left\langle \mathbf{q} \right\rangle_{R} \right)$
with left state $\left\langle \mathbf{q}\right\rangle_{L} = \left\langle\mathbf{q}\right\rangle^{n}_j$ and
right state $\left\langle \mathbf{q} \right\rangle_{R} = \left\langle\mathbf{q}\right\rangle^{n}_{j+1}$.
Therefore, the numerical fluxes
\begin{align}
    \left\langle\mathbf{f}\right\rangle_{j+ 1/2} &=
    \frac{1}{\Delta t} \int^{t^{n+1}}_{t^n} \mathbf{f} \left[\mathbf{q}\left(x_{j+ 1/2},t\right)\right] dt
    = \mathcal{F}\left( \left\langle\mathbf{q}\right\rangle^{n}_j, \left\langle\mathbf{q}\right\rangle^{n}_{j+1} \right)
\end{align}
only depends on the two constant states $\left\langle\mathbf{q}\right\rangle^{n}_j$ and $\left\langle\mathbf{q}\right\rangle^{n}_{j+1}$.\\
Note that the Godunov method is a \textit{monotone method}.
Consider an explicit method of the type
\begin{align}
    \left\langle \mathbf{q}\right\rangle^{n+1}_j &=
    \mathcal{H} \left(\left\langle \mathbf{q}\right\rangle^n_j, \left\langle \mathbf{q}\right\rangle^n_{j\pm 1},
    \left\langle \mathbf{q}\right\rangle^n_{j\pm 2}, \dots,
    \left\langle \mathbf{q}\right\rangle^{n-m}_j,\left\langle \mathbf{q}\right\rangle^{n-m}_{j\pm 1},
    \left\langle \mathbf{q}\right\rangle^{n-m}_{j\pm 2}, \dots \right).
\end{align}
The method is \textit{monotone} if
\begin{align}
    \frac{\partial \mathcal{H}}{\partial \left\langle \mathbf{q}\right\rangle^n_j } &\geq 0
    \quad \forall \left\langle \mathbf{q}\right\rangle^n_j.
\end{align}
From this definition, we can further prove that given the data $\{ \left\langle \mathbf{q}\right\rangle^n_j \}$,
the solution $\{ \left\langle \mathbf{q}\right\rangle^{n+1}_j \}$ obtained by a monotone method is
\begin{align}
    \max_{j} \{ \left\langle \mathbf{q}\right\rangle^{n+1}_j \} &\leq \max_{j} \{\left\langle \mathbf{q}\right\rangle^n_j \}, &
    \min_{j} \{ \left\langle \mathbf{q}\right\rangle^{n+1}_j \} &\geq \min_{j} \{\left\langle \mathbf{q}\right\rangle^n_j \},
\end{align}
that is, no spurious new extrema introduced in the solution as time evolves.

\subsection{Reconstruction scheme}
The Godunov method introduced in the previous section is only first-order accurate in space and time
because of the piecewise-constant distribution of data.
In practice, the spatial accuracy can be higher than first-order
if the left state $\left\langle \mathbf{q} \right\rangle_{L}$
and right state $\left\langle \mathbf{q} \right\rangle_{R}$ of the Riemann problem
at the cell interface $x_{j+1/2}$
are \textit{reconstructed} using a higher-order polynomial representation of $\mathbf{q}$
rather than $\left\langle \mathbf{q} \right\rangle^n_j$ and $\left\langle \mathbf{q} \right\rangle^n_{j+1}$.\\
One of the reconstruction techniques are the \textit{slope-limiter} methods
which improve the piecewise-constant representation by providing a piecewise-linear reconstruction
of $\mathbf{q}^n(x)$ at each cell
\begin{align}
    \mathbf{q}^n_j (x) &= \left\langle \mathbf{q} \right\rangle^n_j + \mathbf{\sigma}^n_j \left(x-x_j \right) &
    \text{for } & x_{j-1/2} \leq x \leq x_{j+1/2},
\end{align}
where $\mathbf{\sigma}^n_j$ is the slope of the linear reconstruction.
Here, we list out several common slope-limiters
\paragraph{Minmod slope-limiter}
The \textit{minmod slope-limiter} \cite{ziegler2011semi,kolgan1972application,van1979towards}
is given by
\begin{align}
    \mathbf{\sigma}^n_j &\coloneqq \text{minmod}\left(
    \frac{\left\langle \mathbf{q} \right\rangle^n_j-\left\langle \mathbf{q} \right\rangle^n_{j-1}}{\Delta x},
    \frac{\left\langle \mathbf{q} \right\rangle^n_{j+1}-\left\langle \mathbf{q} \right\rangle^n_{j}}{\Delta x} \right),
\end{align}
where
\begin{align}
    \text{minmod}\left(\alpha, \beta \right) &\coloneqq
    \begin{cases}
        \alpha & \text{if } |\alpha|<|\beta| \text{ and } \alpha\beta>0, \\
        \beta & \text{if } |\alpha|>|\beta| \text{ and } \alpha\beta>0, \\
        0 & \text{if } \alpha\beta \leq 0,
    \end{cases}\\
    &\coloneqq \frac{1}{2}\left[ \text{sgn}{\alpha} + \text{sgn}{\beta} \right] \min \left(|\alpha|,|\beta| \right).
\end{align}

\paragraph{Monotonized central-difference (MC) limiter}
The MC limiter \cite{van1974towards} is given by
\begin{align}
    \mathbf{\sigma}^n_j &\coloneqq \text{minmod}\left(
    \frac{\left\langle \mathbf{q} \right\rangle^n_{j+1}-\left\langle \mathbf{q} \right\rangle^n_{j-1}}{2 \Delta x},
    \frac{\left\langle \mathbf{q} \right\rangle^n_j-\left\langle \mathbf{q} \right\rangle^n_{j-1}}{\Delta x},
    \frac{\left\langle \mathbf{q} \right\rangle^n_{j+1}-\left\langle \mathbf{q} \right\rangle^n_{j}}{\Delta x} \right),
\end{align}
where
\begin{align}
    \text{minmod}\left(\alpha, \beta, \gamma \right) &\coloneqq
    \begin{cases}
        \min\left(\alpha, \beta, \gamma\right) & \text{if } \alpha,\beta,\gamma > 0, \\
        \max\left(\alpha, \beta, \gamma\right) & \text{if } \alpha,\beta,\gamma < 0, \\
        0 & \text{otherwise}.
    \end{cases}
\end{align}\\
Note that the methods mentioned above are \textit{total variation diminishing (TVD)}.
The total variation of a solution at time $t^n$ is defined as
\begin{align}
    \text{TV}\left( \left\langle \mathbf{q} \right\rangle^n \right) &\coloneqq
    \sum_i \left| \left\langle \mathbf{q} \right\rangle^n_{j+1} - \left\langle \mathbf{q} \right\rangle^n_j \right|,
\end{align}
which measures the oscillations appeared in the solution.
A numerical method is called \textit{total variation diminishing (TVD)} if it satisfies
\begin{align}\label{eq:TVD}
    \text{TV}\left( \left\langle \mathbf{q} \right\rangle^{n+1} \right) \leq
    \text{TV}\left( \left\langle \mathbf{q} \right\rangle^n \right), \quad \forall \left\langle \mathbf{q} \right\rangle^n,
\end{align}
which shows that the oscillations of the solution in TVD method are reduced.\\
Here, we list out all the possible reconstruction schemes in \texttt{Gmunu} in Table \ref{tab:limiters}.
\begin{table}[h]
	\centering
	\caption{\label{tab:limiters}Reconstruction schemes available in \texttt{Gmunu}.}
	\begin{tabular}{ l | l | l | l | l }
		\multicolumn{1}{c|}{ Order of accuracy } & \multicolumn{1}{c|}{ 2nd } & \multicolumn{1}{c|}{ 3rd } & \multicolumn{1}{c|}{ 5th } & \multicolumn{1}{c}{ 7th }\\ \hline
		  & Minmod \cite{ziegler2011semi,kolgan1972application,van1979towards}
          & PPM \cite{colella1984piecewise} & MP5 \cite{suresh1997accurate} & WENO7\\
		  & MC \cite{van1974towards} & Koren & WENO5 & MP-WENO7 \\
		  & Superbee \cite{roe1986characteristic} & Cada3 & WENO5-Z & EXENO7 \\
		  & Vanleer \cite{van1977towards} & WENO3 & WENO5-Z+ &  \\
		  & Albada & WENO3-YC-3 & WENO-NM-5 &  \\
		  & MC-beta &  & WENO-NM-Z &  \\
		  & Cada &  & WENO-NM-Z+ &  \\
		  & Venk &  &  &  \\
	\end{tabular}
\end{table}

\subsection{Approximate Riemann solver}
As discussed in section \ref{section3.1.2},
the Godunov method requires the solution of local \textit{Riemann problem }
$RP\left(\left\langle \mathbf{q} \right\rangle_{L}, \left\langle \mathbf{q} \right\rangle_{R} \right)$
at the cell interface $x_{j+1/2}$ involving the left state $\left\langle \mathbf{q} \right\rangle_{L}$
and right state $\left\langle \mathbf{q} \right\rangle_{R}$.
Although the exact solution of the Riemann problem is available in relativistic hydrodynamics,
it is computational costy in multidimensional case.
Therefore, an \textit{approximate Riemann solver} is used in \texttt{Gmunu}
which is computationally less expensive and yet very accurate in general.
Approximation Riemann solver can be divided into two types
\begin{enumerate}[label=(\roman*)]
    \item \textit{Complete Riemann solver} which contains all the charateristic fields of the exact solution, and
    \item \textit{Incomplete Riemann solver} which only contains a subset of them.
\end{enumerate}
In this section, we discuss some commonly used incomplete Riemann solver in \texttt{Gmunu}.
For a comprehensive introduction, we refer readers to \cite{toro2013riemann}.

\paragraph{The HLL solver}
This Riemann solver was proposed by Harten, Lax and van Leer \cite{harten1983upstream}, hence the name \textit{HLL Riemann solver}.
The solution is approximated by
\begin{align}
    \mathbf{q}(x,t) &=
    \begin{cases}
        \mathbf{q}_L & \text{if } x/t < \lambda_L, \\
        \mathbf{q}_{HLL} & \text{if } \lambda_L \leq x/t \leq \lambda_R, \\
        \mathbf{q}_R & \text{if } x/t > \lambda_R,
    \end{cases}
\end{align}
where $\lambda_L \leq 0$ and $\lambda_R \geq 0$ are the minimum and maximum of the characteristic speeds respectively
\begin{align}
    \lambda_L &\coloneqq \min\left(0, \lambda_- \left(\mathbf{q}_L\right), \lambda_- \left(\mathbf{q}_R\right) \right), \\
    \lambda_L &\coloneqq \max\left(0, \lambda_+ \left(\mathbf{q}_L\right), \lambda_+ \left(\mathbf{q}_R\right) \right),
\end{align}
and $\lambda_{\pm}$ are given by the eigenvalues of the hydrodynamics equations.
The single constant state $\mathbf{q}_{HLL}$ is given by
\begin{align}
    \mathbf{q}_{HLL} &= \frac{\lambda_R \mathbf{q}_R - \lambda_L \mathbf{q}_L + \mathbf{f}_L - \mathbf{f}_R}{\lambda_R-\lambda_L}.
\end{align}
Thus, the numerical fluxes can be calculated as
\begin{align}
    \mathbf{f} &=
    \begin{cases}
        \mathbf{f}_L & \text{if } x/t < \lambda_L, \\
        \mathbf{f}_{HLL} & \text{if } \lambda_L \leq x/t \leq \lambda_R, \\
        \mathbf{f}_R & \text{if } x/t > \lambda_R,
    \end{cases}
\end{align}
where the HLL fluxes are
\begin{align}\label{eq:HLL_flux}
    \mathbf{f}_{HLL} &=
    \frac{\lambda_R \mathbf{f}_L - \lambda_L \mathbf{f}_R + \lambda_L \lambda_R \left(\mathbf{q}_R - \mathbf{q}_L\right)}{\lambda_R-\lambda_L}
\end{align}

\paragraph{The Rusanov solver}
The \textit{Rusanov approximate Riemann solver} \cite{rusanov1962calculation},
also known as the \textit{total variation diminishing Lax-Friedrichs (TVDLF) flux} \cite{shu1989efficient},
is a special case of the HLL Riemann solver where the condition $\lambda_R = -\lambda_L = \lambda$ is imposed.
As a result, the Rusanov flux can be reduced from equation (\ref{eq:HLL_flux}) as
\begin{align}
    \mathbf{f}_{Rusanov} &= \frac{1}{2}\left(\mathbf{f}_L + \mathbf{f}_R \right) - \frac{1}{2}\lambda \left(\mathbf{q}_R - \mathbf{q}_L \right),
\end{align}
where one can take the single speed $\lambda$ to be $\lambda = \max\left(|\lambda_L|,|\lambda_R| \right)$.

%********************************** %Second Section  *************************************
\section{Time discretization}
\subsection{Explicit Runge-Kutta method}
To perform the time integration,
one can expand time derivative using Taylor expansion
\begin{align}
    \partial_t \mathbf{q} &= \frac{1}{2 \Delta t} \left(\mathcal{q}^{n+1} - \mathcal{q}^{n-1} \right).
\end{align}
However, it is not a practical time integration scheme because
\begin{enumerate}[label=(\roman*)]
    \item Large amount of data for the previous time steps is need to be stored in higher-order scheme.
    \item Stability is not guaranteed.
\end{enumerate}
In constract, in the Runge-Kutta (RK) methods,
we do not need to store large amount of data,
and it enables stable time integration for higher-order-accurate scheme.
Consider a system of equations in form
\begin{align}
    \frac{d \mathbf{q}}{dt} &= \mathbf{F} \left(\mathbf{q},t \right),
\end{align}
where $\mathbf{F}$ denotes the right-hand side of the equation.
The general $m$-stage explicit Runge-Kutta method of the Shu-Osher form \cite{shu1988efficient} is
\begin{align}
    \mathbf{q}^{(0)} &= \mathbf{q}^n \\
    \mathbf{q}^{(i)} &= \sum^{i-1}_{k=0} \left[ \alpha_{ik} \mathbf{q}^{(k)}
    + \Delta t \beta_{ik} \mathbf{F}\left( \mathbf{q}^{(k)}, t^n + \gamma_k \Delta t \right) \irght],
    \quad i=1,2,\dots,m \\
    \mathbf{q}^{n+1} &= \mathbf{q}^{(m)},
\end{align}
where the coefficient $\alpha_{ik}, \beta_{ik}$ and $\gamma_k$ are chosen such that the order conditions are satisfied.

\subsubsection{Strong stability-preserving (explicit) Runge-Kutta methods}
The strong stability-preserving Runge-Kutta (SSPRK) methods \cite{shu1988total,shu1988efficient}
is special class of RK methods which maintains total variation diminishing property (\ref{eq:TVD})
in higher-order time integration scheme.
Due to its non-oscillatory property,
the SSPRK methods are desirable in problems with discontinuities and strong shocks \cite{hesthaven2007nodal}.\\
As mentioned in section \ref{section1.5.3},
the hyperbolic system in the FCF scheme becomes unconditionally unstable
if first-order or second-order explicit RK method is used.
As a result, we use fourth-order SSPRK scheme to evolve the FCF hyperbolic sector
and the hydrodynamics equation in \texttt{Gmunu}.

\subsection{Courant-Friedrichs-Lewy conditions}
One necessary condition for stability is the \textit{Courant-Friedrichs-Lewy} (CFL) conditions \cite{courant1928partiellen}.
From a physical point of view,
the CFL condition ensures that the propagation speed of any physical perturbation
is always smaller than the numerical speed $\lamda_N$
\begin{align}
    |\lambda| \leq \lambda_N \coloneqq \frac{\Delta x}{\Delta t}.
\end{align}
Therefore, the time steps for the time integration can be obtained by
\begin{align}
    \Delta t = c_{CFL} \min_k \left(\frac{\Delta x}{|\lambda_k|} \right),
\end{align}
where $c_{CFL}\leq 1$ is a dimensionless constant
and $\lambda_k$ is the charateristic speed of the evolution system.

%********************************** %Third Section  *************************************
\section{Atmosphere treatment}
One of the challenge in astrophysical simulation is handle the interface between fluid and vacuum
where the density $\rho$, pressurece $p$ and velocities $v^i$ vanish.
In this section, we outline the positivity preserving limiter \cite{hu2013positivity} used in $\texttt{Gmunu}$
for atmosphere handling.

\subsection{Positivity preserving limiter}
We consider a discretized first-order Euler timestep
\begin{align}
    &\frac{u^{n+1}_i - u^n_i}{\Delta t} = \frac{1}{\delta V_i}
    \left( f_{i-1/2} \Delta A_{i-1/2} - f_{i+1/2} \Delta A_{i+1/2} \right),\\
    &\Rightarrow u^{n+1}_i = \frac{1}{2}\left( u^{+}_i - u^-_i \right),
\end{align}
where
\begin{align}
    u^-_i &\coloneqq \left( u^n_i - 2\frac{\Delta t}{\Delta V_i} f_{i+1/2} \Delta A_{i+1/2} \right), \\
    u^+_i &\coloneqq \left( u^n_i + 2\frac{\Delta t}{\Delta V_i} f_{i-1/2} \Delta A_{i-1/2} \right),
\end{align}
To ensure the positivity of $u^+_i$ and $u^-_i$, we modify the flux as \cite{hu2013positivity}
\begin{align}
    f_{i+1/2} &= \theta f_{i+1/2}^{HO} + (1-\theta) f_{i+1/2}^{LO},
\end{align}
where $f_{i+1/2}^{HO}$ is the original high-order flux scheme
and $f_{i+1/2}^{LO}$ is the first order Lax-Friedrichs flux.
The parameter $\theta \in \left[0,1\right]$ is the maximum value such that
$u^+_i$ and $u^-_i$ are positive.
Since the Lax-Friedrichs scheme is positivity preserving,
we can always choose $\theta$ to preserve the positvity.
Note that once the positivity in one first-order Euler timestep is preserved,
the positivity is guaranteed for any strong-stability preserving Runge-Kutta (SSPRK) time integrator.\\
In \texttt{Gmunu}, we implemented the positivity preserving limiter in conserved density $D$
and energy density $\tau$ to preserve the positivity of density $\rho$ and pressure $p$.
For the multidimensional case, we apply the limiter with component-by-component approach.

%********************************** %Fourth Section  *************************************
\section{Multigrid Method for elliptic equations} %Section - 3.1
\label{section3.1}

\subsection{Overview} %Section - 3.1.1
\label{section3.1.1}
The elliptic equations can be solved using \textit{iterative methods} such as
Jocabi method, Gauss-Seidel (GS) method and successive overrelaxation (SOR) \cite{young2014iterative}.
These methods are very effective in eliminating high-frequency or
oscillatory components of the error,
but less effective in reducing low-frequency or smooth components of the error
since the changes of error are only made with spatially locally correction \cite{briggs2000multigrid}.
This problem will become even more severe for higher resolution
because the convergence rate behaves like $1-\mathcal{O}(h^2)$.
Since the smooth modes in a fine grid become oscillatory in a coarser grid,
one can move to a coarser grid to smooth out the low-frequency mode error and return back to the fine grids.
This is the key idea of the multigrid method.\\
In the multigrid method, the key ingredients are
\begin{enumerate}[label=(\roman*)]
    \item \textbf{Multigrid cycle scheme} tells the structure of the multigrid solver (see Figure \ref{fig:MG_cycles} for example).
    \item \textbf{Restriction} maps the values from the fine grid to the coarse grid.
    \item \textbf{Prolongation} maps the values from the coarse grid to the fine grid.
    \item \textbf{Smoother} to smooth out the error at different levels.
    \item \textbf{Direct solver} to solve the equation at the coarsest level.
\end{enumerate}
\begin{figure}[h!]
	\centering
	\begin{subfigure}{0.3\columnwidth}
		\centering
        \includegraphics[width=\columnwidth]{MG_Vcycle.jpeg}
		\caption{V-cycle}
	\end{subfigure}
	%\hfill
	\begin{subfigure}{0.6\columnwidth}
		\centering
        \includegraphics[width=\columnwidth]{MG_Wcycle.jpeg}
        \caption{W-cycle}
	\end{subfigure}

	\begin{subfigure}{0.45\columnwidth}
		\centering
        \includegraphics[width=\columnwidth]{MG_Fcycle.jpeg}
        \caption{F-cycle}
	\end{subfigure}
	\begin{subfigure}{0.45\columnwidth}
		\centering
        \includegraphics[width=\columnwidth]{MG_FMG.jpeg}
        \caption{Full multigrid (FMG) cycle}
	\end{subfigure}

	\begin{subfigure}{0.2\columnwidth}
		\centering
        \includegraphics[width=\columnwidth]{MG_note.jpeg}
	\end{subfigure}

	\caption[Four different types of four-level cycles in multigrid methods.]{
		``S'' denotes smoothing. ``Sol'' denotes direct solver.
		Descending line $\setminus$ denotes restriction and ascending line / denotes prolongation.
	}
	\label{fig:MG_cycles}
\end{figure}

For more comprehensive discussion of multigrid method,
we refer the readers to \cite{briggs2000multigrid,trottenberg2000multigrid,young2014iterative,brandt2011multigrid}.

\subsection{Cell-centred discretization and operator} %Section - 3.1.2
\label{section3.1.2}
Given a non-linear elliptic equation
\begin{align}
    \mathcal{L}\left(u\right) = f,
\end{align}
with elliptic operator $\mathcal{L}$, solution $u$ and source term $f$,
it can be discretized as
\begin{align}
    \mathcal{L}_h \left(u_h \right) = f_h,
\end{align}
where $\mathcal{L}_h$ is the discretized operator with resolution $h$,
$u_h$ and $f_h$ are solution and source term defined at the cell-centres.

\subsubsection{Laplacian operator}
The Laplacian operator is one of the elliptic operators that commonly used in \texttt{Gmunu},
including the constraint \cref{eq:XCFC_psi,eq:XCFC_alp} in XCFC scheme
and the algebraic constraint \cref{eq:FCF_g_trace} in the FCF scheme.
It is discretized with a standard 5/7-point (in 2D/3D) second-order accurate discretization.
The details of the discretization in different geometry is shown in Appendix.

\subsubsection{Mixed derivatives}
In the elliptic sector of the FCF scheme (\cref{eq:FCF_X,eq:FCF_psi,eq:FCF_alp,eq:FCF_beta})
and the vector elliptic equations in the XCFC scheme (\cref{eq:XCFC_X,eq:XCFC_beta}),
the elliptic operators contain mixed derivative terms $\frac{\partial^2 u}{\partial x \partial y}$.
We use second-order accuracy discretization as follows
\begin{align}
    \left(\frac{\partial^2 u}{\partial x \partial y} \right)_{i,j,k} &=
    \frac{u_{i+1,j+1,k} - u_{i-1,j+1,k} - u_{i+1,j-1,k} + u_{i-1,j-1,k}}{4 \Delta x \Delta y}
\end{align}

\subsubsection{Convection-diffusion equation}
In the momentum constraint (\cref{eq:FCF_X,eq:FCF_X_2}) of the FCF scheme,
the elliptic operator contains a convective term $\Delta^i{}_{kl}\left( L X \right)^{kl}$
which has a similar form as the following
\begin{align}\label{eq:convection_diff}
    \frac{\partial^2 u}{\partial x^2} + a \frac{\partial u}{\partial x} = 0.
\end{align}
While the Laplacian operator in equation (\ref{eq:convection_diff}) is discretized using standard 5/7-point approximation,
the convection term needs to be discretized using upwind method \cite{trottenberg2000multigrid}.
In \texttt{Gmunu}, we adopts second-order accuracy lopsided spatial finite differencing as
\begin{align}
    \left(\frac{\partial u}{\partial x} \right)_i &= \frac{1}{2 \Delta x}
    \begin{cases}
        3 u_i - 4 u_{i-1} + u_{i-2} &\quad a \leq 0,\\
        -3 u_i + 4 u_{i+1} - u_{i+2} &\quad a \geq 0.
    \end{cases}
\end{align}

\subsection{Smoothers and solvers} %Section - 3.1.3
\label{section3.1.3}
Another essential element in multigrid method is the smoothers and direct solvers.
In \texttt{Gmunu}, we implemented the point-wise \textit{Newton Gauss-Seidel} smoothers \cite{press1996numerical}
\begin{align}
    u^{new}_{i,j,k} = u^{old}_{i,j,k} - \Bigg(\mathcal{L}\left(u^{old}_{i,j,k}\right) - f_{i,j,k} \Bigg)
    \left/ \left( \left. \frac{\partial \mathcal{L}}{\partial u_{i,j,k}}\right|_{u=u^{old}_{i,j,k}}\right)\right. ,
\end{align}
where the components of the new approximation are used as soon as they are computed.
Note that if $mathcal{L}$ is linear in $u$,
the Newton Gauss-Seidel method reduces to the standard Gauss-Seidel method.\\
There are two order of sweeping through the components $u_{i,j,k}$ implemented in \texttt{Gmunu}.
\begin{enumerate}
    \item \textit{Standard Gauss-Seidel} which follows the linear order of the indexes $i,j,k,$ stored in computer's memory.
    \item \textit{Red-black Gauss-Seidel} which sweeps through all the even indexes first (i.e. $i+j+k$ is even) then the odd indexes.
\end{enumerate}

Although the convergence rate of the smoothers is lowered in 2D/3D spherical and 3D cylindrical coordinate due to the anisotropy \cite{trottenberg2000multigrid},
currently we still implemented the smoothers for all coordinate.
For simplicity,
we adopt the Newton Gauss-Seidel method for the direct solver.

\subsection{Transfer operators: restriction and prolongation} %Section - 3.1.4
\label{section3.1.4}
The transfer operators connect data at different level.
The \textit{restriction} operators map the values from the fine grid to the coarse grid,
while the \textit{prolongation} operators map the values from the coarse grid to the fine grid.
For prolongation,
we use linear interpolation based on the nearest neighbors \cite{teunissen2019geometric,zhang2016boxlib,teunissen2018afivo},
which can be described by the following:
\begin{align}
    u_{x+h/2,y+h/2} &= \frac{1}{4} \left(2 u_{x,y} + u_{x+h, y} + u_{x,y+h} \right) + \mathcal{O}\left(h^2 \right),\\
    u_{x-h/2,y+h/2} &= \frac{1}{4} \left(2 u_{x,y} + u_{x-h, y} + u_{x,y+h} \right) + \mathcal{O}\left(h^2 \right),
\end{align}
or in stencil notation
\begin{align*}
	\frac{1}{4} \left]\begin{array}{ccccc}
		\cdot  & 1 &   & 1 & \cdot	\\
		1 & 2 &   & 2 & 1	\\
		  &   & * &   &  	\\
		1 & 2 &   & 2 & 1	\\
		\cdot & 1 &   & 1 & \cdot
	\end{array}\right[^h_{2h},
\end{align*}
where the ``$*$'' denotes the location of the coarse grid
and the notation shows the weighting of the value which are the neighbours of the coarse grid node ``$*$''.
For restriction, the value of four (2D) or eight (3D) fine grid values is averaged to obtain a coarse grid value.

\subsection{The Full Approximation Scheme} %Section - 3.1.5
\label{section3.1.5}
To solve the non-linear elliptic equations,
we adopt the Full Approximation Scheme (FAS) \cite{brandt1977multi,brabazon2014nonlinear,press1996numerical}.
Here, we briefly outline the FAS algorithm.
we define the residual $r$
\begin{align}
    r \coloneqq f - \mathcal{L} \left(v \right),
\end{align}
where $f$ is the right-hand side of the equation,
$\mathcal{L}$ is the elliptic operator
and $v$ is an approximation solution.
For the discretized equation with resolution $h$, we have
\begin{align}
    r_h = f_h - \mathcal{L}_h \left( v_h \right).
\end{align}
The current approximation $v_h$ is then restricted to coarse grid
$v_{2h} = \mathcal{R} \left( v_h \right)$ where $\mathcal{R}$ is the restriction operator.
A copy of $v^{old}_{2h} = v_{2h}$ is stored for later usage.
The coarse-grid right-hand side is then update as
\begin{align}
    f_{2h} = \mathcal{R} \left(r_h \right) + \mathcal{L}_{2h} \left(v_{2h} \right).
\end{align}
Smoothing steps are then applied to the coarse grid.
In the prolongation steps,
the solution is updated with a correction from the coarse grid as
\begin{align}
    v_{h} = v_{h} + \mathcal{P} \left(v_{2h} - v^{old}_{2h} \right),
\end{align}
where $mathcal{P}$ is the prolongation operator.
In practise, this procedure will be repeated until the solution converges
(i.e. the $L_\infty$ norm of the residual is below chosen threshold value).\\
Since the current version of \texttt{Gmunu} is built upon the framework of \texttt{AMRVAC 2.0} \cite{xia2018mpi,keppens2021mpi},
it is natural use the open-source geometric multigrid library \texttt{octree-mg} \cite{teunissen2019geometric}
which is MPI-parallelized, support quadtree/octree AMR grids,
and provide periodic, Dirichlet, and Neumann boundary conditions.
Nonetheless, the library only supports 2D/3D Cartesian coordinate and 2D cylindrical coordinate.
We extended it to support multidimensional spherical and cylindrical coordinates as well as the Robin boundary condition.
In addition, only a single layer of ghost cell without diagonal cell is used in \texttt{octree-mg}.
In order to calculate the mixed derivatives and solve the convection-diffusion problems,
we extend the library to support multiple layers of ghost cells with diagonal cells,
which also allow us to explore higher-order scheme in the future.


\chapter{Conclusion}

We have shown that the Follow-the-Leader model converges to the unique weak entropy solution of the Lighthill-Whitham-Richards model for traffic flow, with space dependence. First, we proved that the scheme was uniformly bounded in total variation and that the maximal distance between two vehicles converge to zero. These were the key ingredients to prove compactness of the sequence of approximations, using Kolmagorov-Riesz and the Arzela-Ascoli theorem. Using the properties of the scheme, we showed that any limit of a convergent subsequence is a weak solution, and in fact a kružkov entropy solution. The uniqueness of the entropy solution ensures that the entire sequence converges.


\subsection{Entropy Solutions}
\begin{enumerate}
    \item For any process, we define the change in entropy as the sum of $\frac{\delta Q}{T}$ for many infinitesimal steps. In an adiabatic process, heat never flows, so $\delta Q = 0$ for all of these steps. Thus, in an adiabatic process the entropy of a system remains constant.
    \item There are four triplets of numbers that could sum to $7$, $(5,1,1)$, $(4,2,1)$, $(3,3,1)$, and $(3,2,2)$. Each of these has $3!$ orders they could be rolled in. Hence there are $24$ microstates, for a total entropy of $k_{b}\ln{24}$.
    \item In this case, all possible orders of those four triples are considered the same microstate. So we instead have four possible microstates, for a total entropy of $k_{b}\ln{4}$.
    \item After one cycle, the gas medium of a heat engine is in its initial state. Since entropy is a function of state, the gas must then have the same total entropy as it did at the start of a cycle. So after one cycle, the gas's entropy will not change.
    \item The number of possible ways that the particles could be distributed after removing the partition is much higher than before the partition was removed (i.e. the disorder of the system increases quite a bit). So, the entropy of the system has increased. Therefore, to spontaneously return to their initial state the gases would have to violate the second law of thermodynamics. (One thing to note here is that it's technically possible that the system will eventually momentarily reach its original configuration, just extremely unlikely).
    \item Using the Sackur-Tetrode equation we have that
    \begin{equation*}
        \Delta S = nc_{v}\ln{\frac{T_1}{T_0}} + nR\ln{\frac{V_1}{V_0}}.
    \end{equation*}
    $T_0 = 300\textrm{K}$, $T_1 = 400\textrm{K}$, and $n = 1\textrm{mol}$ are given. Furthermore, since it expands to double its original size, we know that $V_1 = 2V_0$. Finally, we know that the gas has 3 degrees of freedom, since its monoatomic, and therefore $c_v = \frac{3}{2}R$. So plugging those in we get
    \begin{gather*}
        \Delta S = (1\textrm{mol})(\frac{3}{2})(8.314\frac{\textrm{J}}{\textrm{mol}\cdot \textrm{K}})\ln{\frac{400\textrm{K}}{300\textrm{K}}} + (1\textrm{mol})(8.314\frac{\textrm{J}}{\textrm{mol}\cdot \textrm{K}})\ln{\frac{2V_0}{V_0}} \\
        \Delta S \approx 9.35\frac{\textrm{J}}{\textrm{K}}
    \end{gather*}
    \item
    \begin{enumerate}
        \item From the ideal gas law, if both compartments have the same amount and volume of gas, but the right side has a higher temperature, then we know that the right side will have a higher pressure than the left. Therefore, the gas on the right side will expand and the gas on the left side of the box will be compressed (as the gas molecules on the right are pushing with more force on the central piston), in an adiabatic process (as no heat can flow). The process will terminate once the pressure on both sides of the box is equal.
        \item Since this process resulted in no energy gain or loss (as the box is isolated from its environment), the internal energy change of the system is zero. Since this process raises the temperature on the left to be closer to that on the right, you would think that this process raises the entropy of the system. However, since both sides of the box underwent an adiabatic process, neither had a change in entropy. Entropy is an extensive quantity, so the entropy of the box must have remained constant as well.
        \item At the end, the pressure of the two sides would be equal, as the net force on the central piston would be zero. The volume of the left side would be less than the right. Finally, since both sides of the box have the same number of moles of gas, we can use ideal gas law to say that after the process is over:
    \[
        \frac{P_lV_l}{T_l} = \frac{P_rV_r}{T_r}
    \]
    which since the final pressures are equal simplifies to
    \[
        \frac{V_l}{T_l} = \frac{V_r}{T_r}
    \]
    We know that the final volume of the left side is less than the final volume on the right side. Therefore, the final temperature on the right must be greater than that on the left. The system is not in thermal equilibrium, which does make sense as the two containers were not in thermal contact with one another.
    \end{enumerate}
\end{enumerate}


\section{Introduction}
For the calculability course, we had to realize a project. This project is a RAM language interpreter. The RAM language is a pseudo code discussed in class with 4 instructions. This project is divided in 3 parts: the parser, the interpreter and the graphics.

\section{About RAM program}
\label{sec:RAM_intro}
A \textit{RAM} program is a program made by :
\begin{itemize}
    \item a potentially infinity memory with three main registers
    \begin{itemize}
        \item the \textit{memory counter ($R_C$)} which allows to know at each moment what is the current instruction to be executed. If $R_C$ is $0$ or a integer bigger then the number of instructions of the code, the program execution will stop
        \item \textit{$R_0$} the first register of the memory representing the input of the program
        \item \textit{$R_1$} the second register which can be seen as the case of the memory containing the output of our program
    \end{itemize}
    \item 4 instructions :
    \begin{itemize}
        \item $R_k = R_k + 1$ which increases the value stock in the register $k$ by one
        \item $R_k = R_k \dotminus{} 1$, same as previous instruction, but the value is decreased by one (NB : if the value in $R_k$ is equal to 0, we have that $0 \dotminus{} 1 = 0$ since RAM machines work in $\mathbb{N}$ number set
        \item $IF \; R_k \neq 0 \; THEN \; GOTOB \; n$ means that if the register $k$ does not equal $0$ then $R_C = R_C \dotminus{} n$ (here, as before the subtraction is done as follow $A \dotminus{} B = max(0, A - B)$
        \item $IF \; R_k \neq 0 \; THEN \; GOTOF \; n$ which makes the following operation : $R_C = R_C + n$
    \end{itemize}
\end{itemize}

With a RAM program, as demonstrated in course, it is possible to code all the programs we usually code with any other programming language such as \textit{Python, C, Java, etc.}

Another important aspect of RAM program we should consider is that, thanks to its infinite registers and the fact that efficiency time of programs is not taken, this program model can be reused and adapted to every new programming language.

Finally working only in $\mathbb{N}$ does not restrict RAM programs, since in fact $\mathbb{Z}$, $\mathbb{Q}$ and  $\mathbb{R}$ can be seen as an extensions of $\mathbb{N}$.

\newpage
We can also introduce some predefined and useful macros, such as, \textit{rp} and \textit{lp} (resp. for \textit{right\_part} and \textit{left\_part}), allowing to treat the value of a register as a \textit{Cantor's couple} (see \ref{sec:cant_pair_func}), this let you pass a variable number of parameters.\\
For example, if you have a program that calculate the sum of $x$ and $y$ then you will put $n$ that is $cantor(x,y)$ in $R_0$.
\\Other two macros are \textit{push} and \textit{pop} which respectively push and pop the value from a register $k$ to a very big register that normally should not be used by the program (we have chosen the $2^{64}$ register).

\section{Design choices}

\subsection{Choice of tools}

\begin{itemize}
\item Technologies : \textbf{Python3.9.9}\\
To realize this project we used the following libraries:
    \begin{itemize}
        \item ply==3.11 (For the parser)
        \item tkhtmlview==0.1.0 (For the help)
    \end{itemize}
\end{itemize}

\subsection{Installation}

You can use the file \textbf{install.sh}

\begin{verbatim}
$ chmod u+x install.sh
$ ./install.sh
\end{verbatim}
Or

\begin{verbatim}
$ python3 -m pip install -r requirements.txt
\end{verbatim}