% -*- TeX-master: "master.tex" -*-

\setcounter{section}{7}
\setcounter{subsection}{1}
\subsection{Monoidal Categories, Functoriality of ADTs, Profunctors}

\subsubsection{Monoidal Categories}

We start out by seeing how we can generalize monoid in a category. We know
pretty well how monoid based on set theory, we got a unit $\mathbf{1} \in \Set$,
a binary function $f : \Set \times \Set \to \Set$, few rules and so on.

In monoid categories, we need to think about what it means to multiply two
object. This gives rise to product category. The monoidal unit in this category
is the unit object, the singleton set in $\Set$, or the terminal object to be
more general.

Here's a how we the terminal object is a good candidate for the unit. This is to
say, in a product category, $(a, ()) \iso a$.

\begin{center}
  \begin{tikzcd}[sep=large]
    & b
    \ar[bend right=15]{ldd}[left]{p}
    \dar[dashed]{p}
    \ar[bend left=15,dashed]{rdd}{\mathrm{unit}_b} & \\
    & a \ar{ld}{\id_a} \ar[dashed]{rd}[swap]{\mathrm{unit}_a} & \\
    a & & ()
  \end{tikzcd}
\end{center}

As we can see, the projections $\pi_1 = \id$ and $\pi_2 = \mathrm{unit}$. Given
any $\cd{b \rar{p} \& a}$, we have $\mathrm{unit}_b$ which maps $b$ to $()$, we
always have a unique factorization $\cd{b \ar[dashed]{r}{p} \& a}$. This means
the projections just worked and we indeed have $(a, ()) \iso a$.

So in a monoidal category (at least product category), monoid unit is the
terminal object. This also apply to other categories. Say the coproduct
category. In this case the terminal object is the empty set (initial object of
the coproduct category). And they both are specialized bifunctor category. All
these things as product, coproduct, any bifunctors are called \emph{tensor product}
(denoted $C \otimes C \to C$).

What we really need is to have a bifuntor, and a unit for the bifunctor. Then we
can get a monoidal category, assuming monoidal properties hold.

\subsubsection{Functoriality of ADTs}

Dr. Milewski has mentioned that ADTs has functoriality by their nature many
times in his lecture.

From the previous section, we see how these monoidal categories are related to
their corresponding bifunctors. We see, product types are functorial, sum
types are functorial, what about other types, \code{Bool}, \code{Int}?

So we still have some types that do not depend on type variables, how can we
make them instance of \code{Functor}? We can say they dependent on type indeed,
but in a \emph{trivial} way. So here's the place for the constant functor trick.

\begin{lstlisting}
data Const c a = Const c

instance Functor (Const c) where
  fmap :: (a -> b) -> Const c a -> Const c b
  fmap f (Const c) = Const c
\end{lstlisting}

In category theory, constant functor $\Delta_c$ maps every object in a category
to the object $c$ and every morphisms to $\id_c$. Taking it to the Haskell world
where every thing is in $\Hask$, the constant functor is used to map everything
into the given value. Think of functors working as containers, then the constant
functor is like an empty container. It eats up all information and collapse into
something that does not contain any inforamtion.

Another trivial functor is the identity functor:

\begin{lstlisting}
data Identity a = Identity a

instance Functor (Identity a) where
  fmap :: (a -> b) -> Identity a -> Identity a
  fmap f (Identity a) = Identity (f a)
\end{lstlisting}

This functor maps everything back to itself. So this functor is like a container
with one thing in it. So this is how we convert any ADTs into our standard
notion.

\begin{lstlisting}
data Maybe a = Nothing | Just a
-- sum types can be decomposed into Either
data Maybe a = Either Nothing (Just a)
-- any constant type can be represented using Const functor
-- and Just is just an Identity functor
data Maybe a = Either (Const () a) (Identity a)
\end{lstlisting}

Now we have a \code{Const ()} functor and an \code{Identity} functor; and
\code{Either} is just a bifunctor. Thus overall \code{Maybe} is a bifunctor.
Since we have the same parameter \code{a} for \code{Const ()} and
\code{Identity}, we can add a diagonal functor before the bifunctor of the
\code{Either}/\code{Maybe}, reducing it into a regular endofunctor.

This process of functorizing any ADT type can be automated, and it's built-in to
Haskell as an extension: \code{DeriveFunctor}. Could there be more than one
\code{fmap} defined for an ADT functor? No, Because of parametricity of
polymorphism in Haskell, the canonical one is the only possible one!

\hfill
\begin{remark}
  A \emph{diagonal functor} maps $C \to C \times C$ by replicating everything
  including objects and morphisms $a \mapsto (a, a)$.
\end{remark}

\subsubsection{Profunctors}

Other than product (\code{()})and sum types (\code{Either}). Another type
constructor that takes two types is the function type ($\to$). We can write
\code{(}$\to$\code{)}~\code{a b} to represent \code{a -> b}. The question is, is
$\to$ a bifunctor?

We already knew that \code{(-> c)} is a functor, called the \emph{Reader
  functor}.

\begin{lstlisting}
instance Functor (-> c) where
  fmap :: (a -> b) -> (c -> a) -> (c -> b)
  fmap f g = f  .  g
\end{lstlisting}

What about we fix on the returning type and see if that's a functor. The
\code{fmap} would have type \code{fmap :: (a -> b) -> (a -> c) -> (b -> c)}.
If we name $f: a\to b$ and $g: a \to c$, we have this diagram: \cd{a \rar{f}
  \dar{g} \& b \ar[red]{ld}{} \\ c \& }. We need to find the red arrow and
obviously it cannot be constructed using $f$ and $g$, so it is not a functor.

Or is it? Why not saying it a functor mapping from the opposite category? This
kind of functors is called a \emph{contravariant functor}. Using the container
analogy, a contravariant functor is like a container that store negative things:
instead of containing something we need to give it something.

\hfill
\begin{remark}
  The \emph{opposite category} $C^{op}$ of category $C$ is a category where for
  every objects in $C$ there is an object in $C^{op}$ and for every morphisms $f
  : a\to b$ in $C$ there is a morphism $f^{op} : b \to a$ in $C^{op}$.
\end{remark}

\begin{lstlisting}
class Contravariant f where
  contramap :: (b -> a) -> f a -> f b

data Op c a = Op (a -> c)

instance Contravariant (Co c) where
  contramap :: (b -> a) -> (Op c a) -> (Op c b)
--contramap ::  (b -> a) -> (a -> c) -> (b -> c)
  contramap f (Op g) = Op (f  .   g)
\end{lstlisting}

So a profunctor is just a bifunctor that is contravariant in the first argument
and covariant in the second. What's the problem?
\footnote{\url{https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/profunctors\#profunctors}}

\begin{lstlisting}
class Profunctor p where
-- define dimap
  dimap :: (a' -> a) -> (b -> b') -> p a b -> p a' b'
  dimap f g h = lmap f (rmap g h)

-- or both lmap and rmap
  lmap :: (a' -> a) -> p a b -> p a' b
  lmap = (`dimap` id)
  rmap :: (b -> b') -> p a b -> p a b'
  rmap = (id `dimap`)
\end{lstlisting}

To function type, let's see how it is implemented. $f : a' \to a$, $g : b \to
b'$, and $h : a \to b$. So the diagram is just \cd{a' \rar{f} \ar[red,bend
  right=90]{rrr}{} \& a \rar{h} \& b \rar{g} \& b'}. Bravo, finally we have this
approachable red arrow.

The functions \code{lmap} and \code{rmap} correspond to \code{contramap} and
\code{fmap}, which is a implication of the fact that a profunctor is a bifunctor
over a contravariant functor and a covariant functor.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Basis Set}\ref{BASIS:2}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction to STO and GTO}
%
% introduction to STO and GTO, their expression; difference
%
%
%
Basis sets is some classical content in the quantum chemistry.
Furthermore, if we want to understand or write some codes related to
the quantum chemistry, the details of the basis sets is
indispensable. For this part, the discussion is mainly taken from some
classical textbooks\cite{levine, szabo,Jensen}.

Historically\footnote{this part of content is taken from some html
  materials\cite{JKL}.}, the quantum calculations for molecules were
performed as LCAO MO, i.e. Linear Combination of Atomic Orbitals -
Molecular Orbitals. This means that molecular orbitals are formed as a
linear combination of atomic orbitals:
\begin{equation}\label{}
  \varphi_{i} = \sum_{\mu}c_{\mu i}\phi_{\mu}
\end{equation}
where $\varphi_{i}$ is the i-th molecular orbital, $c_{\mu i}$ are the
coefficients of linear combination, $\phi_{\mu}$ is the $\mu$ -th
atomic orbital, and n is the number of atomic orbitals.

Strictly speaking, Atomic Orbitals (AO) are solutions of the
Hartree-Fock equations for the atom, i.e. a wave functions for a
single electron in the atom. Anything else is not really an atomic
orbital. Some things are similar though, and there is a lot of
confusion in the terminology used. Later on, the term atomic orbital
was replaced by "basis function" or "contraction," when appropriate.
Early, the Slater Type Orbitals (STO's) were used as basis functions
due to their similarity to atomic orbitals of the hydrogen atom.  They
are described by the function depending on spherical coordinates:
\begin{equation}\label{}
  \phi_{i}(\zeta,n,l,m,r,\theta,\varphi) = Nr^{n-1}e^{-\zeta
    r}Y_{lm}(\theta,\varphi)
\end{equation}
where N is a normalization constant, $\zeta$ is called "exponent".
The r, $\theta$ , and $\varphi$ are spherical coordinates, and
$Y_{lm}(\theta,\varphi)$ is the angular momentum part(see the eigen
function of the angular momentum operator).The n, l, and m are quantum
numbers: principal, angular momentum, and magnetic;
respectively. Since for the hydrogen atom the radical part of the
orbitals can be expressed as: $p(r)e^{-\zeta r}$, where the $p(r)$ is
some polynomial functions for r; thus the atomic orbitals can be
expressed as some linear combination of the STOs.

Cartesian slater type of orbitals can be defined as:
\begin{equation}\label{}
  \phi_{i}(k,l,m) = Nx^{k}y^{l}z^{m}e^{-\zeta r}
\end{equation}
Ordinary slater orbitals can be expanded as a linear combinations of
these kind of orbitals.

Unfortunately, functions of this kind are not suitable for fast
calculations of necessary two-electron integrals. That is why, the
Gaussian Type Orbitals (GTOs) were introduced. You can approximate the
shape of the STO function by summing up a number of GTOs with
different exponents and coefficients. Even if you use 4 or 5 GTO's to
represent STO, you will still calculate your integrals much faster
than if original STOs are used. The GTO (called also cartesian
gaussian) is expressed as:
\begin{equation}\label{}
  g(\alpha, n, l, m, x,y,z) = Nx^{n}y^{l}z^{m}e^{-\alpha r^{2}}
\end{equation}
where N is a normalization constant, $\alpha$ is called "exponent",
similar to the $\zeta$ in STO; the x, y, and z are cartesian
coordinates. The l, m, and n are not quantum numbers but simply
integral exponents at cartesian coordinates. Here, $r^{2} = x^{2} +
y^{2}+ z^{2}$.

Calling gaussian GTOs is probably a misnomer, since they are not
really orbitals. They are simpler functions. In recent literature,
they are frequently called gaussian primitives (actually that's the
terminology used in the Gaussian 03 program!). The main difference is
that $r^{n-1}$ , the pre-exponential factor, is dropped from the STOs,
the r in the exponential function is squared, and angular momentum
part is a simple function of cartesian coordinates. The absence of
$r^{n-1}$ factor restricts single gaussian primitive to approximating
only 1s, 2p, 3d, 4f ... orbitals (see the above discussion on the
combination of STOs). It was done for practical reasons, namely, for
fast integral calculations. However, combinations of these functions
are able to approximate correct nodal properties of atomic orbitals by
taking them with different signs. Following gaussian functions are
possible:
\begin{align}\label{}
  1s = Ne^{-\alpha r^{2}} &  \nonumber \\
  2p_{x} =Nxe^{-\alpha r^{2}} & \quad 2p_{y} =Nye^{-\alpha r^{2}}
  \quad
  2p_{z} =Nze^{-\alpha r^{2}} \nonumber \\
  3d_{xx} = Nx^{2}e^{-\alpha r^{2}} & \quad 3d_{xy} = Nxye^{-\alpha
    r^{2}} \quad  3d_{xz} = Nxze^{-\alpha r^{2}} \nonumber \\
  3d_{yy} = Ny^{2}e^{-\alpha r^{2}} &\quad 3d_{yz} = Nyze^{-\alpha
    r^{2}} \quad 3d_{zz} = Nz^{2}e^{-\alpha r^{2}}  \nonumber \\
  \text{etc.}
\end{align}

The sum of exponents at cartesian coordinates $L = l+m+n$, is used
analogously to the angular momentum quantum number for atoms, to mark
functions as s-type (L=0), p-type (L=1), d-type (L=2), f-type (L=3),
etc.

There is a problem with d-type and higher functions. There are only 5
linearly independent and orthogonal d orbitals, while there are 6
possible cartesian gaussian primitives. If we use all six, we are also
introducing a 3s type function since:
\begin{equation}\label{}
  3d_{xx}+3d_{yy}+3d_{zz} = Nx^{2}e^{-\alpha r^{2}} + Ny^{2}e^{-\alpha
    r^{2}} + Nz^{2}e^{-\alpha r^{2}} = Nr^{2}e^{-\alpha r^{2}} = 3s
\end{equation}

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this section of content has been commented out by us. The
% mathematical derivation provides us the details of the GTO, however,
% before really knowing the basis sets, I mean; how to use it in the
% whole programming; it's not benefit to deduct the details of the GTO
% or STO. We still has to be keep on to the general understanding
% level.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{comment}
  \section{Some Mathematical Derivation To GTO}
  In this part, we are going to demonstrate some mathematical
  properties of the GTO. Here, an arbitrary GTO $g(\alpha, n, l, m,
  x,y,z)$ is abbreviated as $\chi(\alpha,l,m,n)$:
  \begin{equation}\label{}
    \chi(\alpha,l,m,n) = Nx^{l}y^{m}z^{n}e^{-\alpha r^{2}}
  \end{equation}

  First let's see the normalization of the GTO.
  \begin{align}\label{}
    I &= N^{2}\langle\chi(\alpha,l,m,n)|\chi(\alpha,l,m,n)\rangle
    \nonumber \\
    &=N^{2}\int x^{2l}e^{-2\alpha x^{2}}dx\int y^{2m}e^{-2\alpha
      y^{2}}dy\int z^{2n}e^{-2\alpha z^{2}}dz
  \end{align}

  We can gain the integrals with the help of some much more general
  function of $\Gamma(m)$:
  \begin{equation}\label{}
    \Gamma(m) = \int^{\infty}_{0}x^{m-1}e^{-x}dx  \qquad (m>0)
  \end{equation}
  For the $\Gamma(m)$, we have some recursive equation: $\Gamma(m) =
  (m-1)\Gamma(m-1)$ for $m > 1$. Thus we can get $\Gamma(m) = (m-1)!$
  for the integer. If m is half integer, it can prove that
  $\Gamma(1/2) = \sqrt{\pi}$, therefore $\Gamma(m+1/2) =
  \frac{(2m-1)!!}{2^{m}}\sqrt{\pi}$.

  It can be proved that:
  \begin{equation}\label{BASISeq:1}
    \int^{\infty}_{0}x^{l}e^{-ax^{2}}dx =
    \frac{1}{2}a^{-\frac{l+1}{2}}\Gamma(\frac{l+1}{2})
  \end{equation}
  Thus if the integrals from $-\infty$ to $\infty$, we have:
  \begin{equation}\label{}
    \int^{\infty}_{-\infty}x^{l}e^{-ax^{2}}dx =
    a^{-\frac{l+1}{2}}\Gamma(\frac{l+1}{2}) \qquad \text{l is an even
      number}
  \end{equation}

  Therefore, for the integral of the quadrature of the GTO, we have:
  \begin{equation}\label{}
    1=N^{2}(2\alpha)^{-(l+m+n+\frac{3}{2})}\Gamma(l+\frac{1}{2})\Gamma(m+\frac{1}{2})\Gamma(n+\frac{1}{2})
  \end{equation}
  We get the normalized factor of $N$.

  Furthermore, we can derive the orthogonal relationship between
  different GTO on the same atom (thus they share the same $exp(-
  r^{2})$, and the exponent of $\alpha$ may be different from each
  other) based on the deduction we made above.

  From the (\ref{BASISeq:1}), we can see that if two different GTO
  multiplied, the exponent of $x$, $y$ or $z$ should be the even
  number so as to avoid the orthogonality. Thus, the s-shell and the
  p-shell are always orthogonal, and the p-shell is orthogonal to the
  d-shell. However, for the s-shell and d-shell, some are orthogonal
  (such as the s and $d_{xy}$), but some are not (such as the s and
  $d_{x^{2}}$). Anyway, by applying the rules mentioned above we can
  determine that wether any two GTO are orthogonal or not.

  Next we are going to prove some important theorem related to the
  GTO, which makes the calculation of the three center and four center
  electron repulsion integrals much more easier compared with the STO.

  \begin{figure}[htbp]
    \begin{center}
      \includegraphics[scale=0.6]{gto.eps}\label{BASIS:1}
      \caption{the center theorem related to GTO}
    \end{center}
  \end{figure}

  If there's two center GTO orbital, one is residing on A, and the
  other is residing on B; we can prove that the multiplication of the
  two GTOs can be transformed into a one center of GTO, who is located
  in center of P (see the \ref{BASIS:1}).

  Thus we have:
  \begin{equation}\label{}
    exp(-ar_{A}^{2})exp(-br_{B}^{2}) = Kexp(-ar_{p}^{2})
  \end{equation}

\end{comment}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Contracted Gaussian type orbitals}
%
% to use the gaussian function, people always to contract them
% together to form the basis sets.  what's the relation between GTO
% and basis sets?  how to contract them to form the basis sets?
% introduce the two different way of contracting: segmental and
% general way
%
Gaussian primitives are usually obtained from quantum calculations on
atoms (i.e. Hartree-Fock or Hartree-Fock plus some correlated
calculations, e.g. CI). Typically, the exponents are varied until the
lowest total energy of the atom is achieved. In some cases, the
exponents are optimized independently. In others, the exponents are
related to each other by some equation, and parameters in this
equation are optimized (e.g. even-tempered or "geometrical" and
well-tempered basis sets). The primitives so derived describe isolated
atoms and cannot accurately describe deformations of atomic orbitals
brought by the presence of other atoms in the molecule.  Basis sets
for molecular calculations are therefore frequently augmented with
other functions, which has smaller exponent and able to describe the
motion of electrons far away from the nucleus.

For molecular calculations, these gaussian primitives have to be
contracted, i.e., certain linear combinations of them will be used as
basis functions. The term contraction means "a linear combination of
gaussian primitives to be used as basis function".  Such a basis
function will have its coefficients and exponents fixed. The
contractions are sometimes called Contracted Gaussian Type Orbitals
(CGTO). For instance, there's a four s-type gaussian primitives used
to represent 1s orbital of hydrogen as:
\begin{multline}\label{}
  \varphi_{1s} = 0.50907N_{1}e^{-0.123317r^{2}} +
  0.47449N_{2}e^{-0.453757r^{2}} \\
  + 0.13424N_{3}e^{-2.01330r^{2}} + 0.01906N_{4}e^{-13.3615r^{2}}
\end{multline}
$N_{i}$ is a normalization constant for a given primitive. In the case
of gaussian primitives of type s it is equal to
$(2\alpha/\pi)^{\frac{3}{4}}$.

These primitives may be grouped in 2 contractions. The first
contraction contains only 1 primitive:
\begin{equation}\label{}
  \phi_{1} = Ne^{-0.123317r^{2}}
\end{equation}

3 primitives are present in the second contraction:
\begin{multline}\label{}
  \phi_{2} = N[0.47449N_{2}e^{-0.453757r^{2}} +
  0.13424N_{3}e^{-2.01330r^{2}} \\
  + 0.01906N_{4}e^{-13.3615r^{2}}]
\end{multline}

N is a normalization constant for the whole contraction.

In this case, 4 primitives were contracted to 2 basis functions. It is
frequently denoted as $(4s) \rightarrow [2s]$ contraction (some use
(4s)/[2s] notation). The coefficients in function $\phi_{2}$ are then
fixed in subsequent molecular calculations.

Obviously, the best results could be obtained if all coefficients in
gaussian expansion were allowed to vary during molecular
calculations. Moreover, the computational effort (i.e. "CPU time") for
calculating integrals in the Hartree-Fock procedure depends upon the
4th power in the number of gaussian primitives. However, all
subsequent steps depend upon the number of basis functions (i.e.
contractions). Also, the storage required for integrals (when Direct
SCF is not used) is proportional to the number of basis functions (not
primitives!). Frequently the disk storage and not the CPU time is a
limiting factor. The CPU time requirements are more acute when
post-Hartree- Fock (e.g. correlated methods) are used, since the
dependance upon the number of basis functions here is more steep than
the 4th power.

There are two basic forms of contractions, namely "segmented" and
"general". The segmented contractions are disjointed, i.e., given
primitive appears only in one contraction. The example given above
$(4s) \rightarrow [2s]$ is a segmented contraction. Occasionally, one
or two primitives may appear in more than one contraction, but this is
an exception to the rule. The general contractions, on the contrary,
allow each of the primitives to appear in each basis function
(contraction). The segmented contractions are far more popular and
will be described first. The reason for their popularity is not that
they are better, but simply, that the most popular ab initio packages
do not implement efficient integral calculations with general
contractions. The computer code to perform integral calculations with
general contractions is much more complex than that for the segmented
case.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Segmented basis sets}
%
% how to form the segmented basis sets? there's some rules: 1 the
% inner part is assigned with less flexibility (less basis sets), but
% more GTO used to get a better shape (such as 6-31g, use 6 GTOs to
% simulate the inner shell, but only three the the outer ones) 2 the
% outer ones are assigned with better flexibility (more basis sets) so
% that to make the basis sets more adaptable to the change of
% molecular environments.  3 also the polarized function and diffuse
% functions are used. they are always left uncontracted, since that
% they are not derived from the atom calculation.  these functions are
% used to help the basis set to change more flexible.
%
The segmented basis sets are usually structured in such a way that the
most diffuse primitives (primitives with the smallest exponent) are
left uncontracted (i.e. one primitive per basis function). More
compact primitives (i.e. those with larger exponents) are taken with
their coefficients from atomic Hartree-Fock calculations and one or
more contractions are formed. Then the contractions are renormalized.

Cartesian gaussian primitives are grouped in shells corresponding to
the same value of angular momentum quantum number. Of course, these
shells should not be confused with electron shells (i.e. electrons
with the same principal quantum number: $K \rightarrow n=1$, $L
\rightarrow n=2$, etc.). So as to avoid the ambiguity, we use s-shell,
p-shell, d-shell, f-shell, g-shell, etc. to signal the shell of
gaussian primitives. The shell is a collection of cartesian gaussian
primitives that have the same L (see definition of cartesian gaussian
above). Strictly speaking, the s-shell is a collection of s type
gaussian primitives; p-shell is a collection of p-type gaussian
primitives; d-shell is a collection of d-type gaussian primitives; and
so on. Of course, combining primitives belonging to different shells
within the same contraction does not make sense because primitives
from different shells are orthogonal.

But even here there is a room for more confusion. Many basis sets use
the same exponents for functions corresponding to the same principal
quantum number, i.e., electronic shell. 3-21g is an example, as well
as other basis sets from Pople's group. Atoms of the first and second
row (i.e. Li - Ne, Na - Cl) have the same exponents for s- and p-type
gaussian primitives formally associated with a given electron shell of
the isolated atom. For the basis sets in which s- and p-type functions
share the same exponents, the term SP-shell is used (here in the
output job file by Gaussian03, this is clearly
demonstrated). Sometimes term L-shell is used by analogy to the 2nd
electron shell. This approximation works very well in
practice. Moreover, it is possible to write efficient code for
calculating integrals for such cases. It is important to stress here
that the distinction between inner orbitals and valence orbitals is
kind of carry-over from the past era of Slater orbitals.  Contractions
consisting of primitives with large exponents are associated with
inner atomic orbitals while more diffuse functions are allied with
valence orbitals. Basis functions are not usually atomic orbitals, and
in many cases, they do not even resemble orbitals of isolated
atoms. In fact, examining coefficients of molecular orbitals
frequently reveals that these "core" basis functions contribute
substantially to the Highest Occupied Molecular Orbital (HOMO). It
comes as a consequence of the fact that basis functions on a given
center are usually not orthogonal to each other and "core" basis
functions on different centers overlap to a great extent - situation
not likely to occur with true atomic orbitals.

The early gaussian contractions were obtained by a least square fit to
Slater atomic orbitals. The number of contractions (not primitives!)
used for representing a single Slater atomic orbital (i.e. zeta) was a
measure of the goodness of the set. From this era we have terms like
single zeta (SZ), double zeta (DZ), triple zeta (TZ), quadruple zeta
(QZ), etc. In the minimal basis set (i.e. SZ) only one basis function
(contraction) per Slater atomic orbital is used. DZ sets have two
basis functions per orbital, etc. Since valence orbitals of atoms are
more affected by forming a bond than the inner (core) orbitals, more
basis functions are assigned frequently to describe valence
orbitals. This prompted development of split-valence (SV) basis sets,
i.e., basis sets in which more contractions are used to describe
valence orbitals than core orbitals. That more basis functions are
assigned to valence orbitals does not mean the valence orbitals
incorporate more primitives.  Frequently, the core orbitals are long
contractions consisting of many gaussian primitives to represent well
the "cusp" of s type function at the position of the nucleus. The
"zeta" terminology is often augmented with a number of polarization
functions which will be described later. So, DZP means double-zeta
plus polarization, TZP stands for triple-zeta plus polarization,
etc. Sometimes the number of polarization functions is given,
e.g. TZDP, TZ2P, TZ+2P stands for triple-zeta plus double
polarization. Letter V denotes split valence basis sets, e.g., DZV
represents basis set with only one contraction for inner orbitals, and
two contractions for valence orbitals. The creativity here is enormous
and spontaneous.

The minimal basis set is the smallest possible set, i.e., it contains
only one function per occupied atomic orbital in the ground
state. Actually, it always includes all orbitals from partially
occupied sub shells and valence p-type functions for elements from the
first 2 groups of the periodic table. So for Li and Be atoms it has 2
s-type contractions and 1 p-type contraction. Minimal basis set for S
atom has 3 s-type contractions and 2 p-type contractions.  The most
popular minimal basis sets are the STO-nG, where n denotes number of
primitives in the contraction. These sets were obtained by least
square fit of the combination of n gaussian functions to a Slater type
orbital of the same type with zeta = 1.0, For this set additional
constraint is used, that exponents of corresponding gaussian
primitives are the same for basis functions describing orbitals with
the same principal quantum number (e.g. the same primitives are used
for 2s and 2p function).For the minimal basis set, the STO-3G (i.e. 3
primitives per each function) is the most widely used set.

For other sets a more complicated notation needs to be used to specify
the number of primitives and contractions explicitly. The parentheses
() embrace the number of primitives that are given in the order of
angular momentum quantum number. Square brackets [] are used to
specify the number of resulting contractions. For example: (12s,9p,1d)
means 12 primitives on s-shell, 9 primitives on p-shell, and 1
primitive on d-shell. This is sometimes abbreviated even further by
skipping the shell symbols (12,9,1). The [5,4,1] means that s-shell
has 5 contractions, p-shell has 4 contractions and d-shell has 1
contraction. To denote how contractions were performed, the following
notation is frequently used: $(12,9,1) \rightarrow [5,4,1]$ or
$(12,9,1)/[5,4,1]$ or $(12s,9p,1d) \rightarrow [5s,4p,1d]$. This means
that 12 s-type primitives were contracted to form 5 s-type
contractions, 9 p-primitives were contracted to 4 basis functions and
1 d-primitive was used as a basis function by itself. Note of caution
here. The statement "9 p-primitives were contracted to 4 basis
functions" actually means that 12 basis functions were created. Each
p-type basis functions has 3 variants: $p_{x}, p_{y}, p_{z}$ which
differ in their cartesian part (i.e., angular part). The same is true
for d-, f-, and higher angular momentum functions.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Basis sets in computation}
%
% 1 importance in the understanding of the quantum chemistry codes 2
% introduce the primitive shells, and to see the difference between
% the gaussians and the primitive shells.  3 basis sets are linear
% combination of the primitive shells 4 shells concept 5 what should
% be contained in the quantum chemistry program
%
%
To some extent, basis sets is the foundation of the codes in the
quantum chemistry, it's impossible to understand any quantum chemistry
codes without the understanding of the basis sets. Hence, in this
section we hope to give some basic concept of how to express the basis
sets in the quantum chemistry codes. Here the examples are all from
the Gaussian program, but other programs share the similar ideas so
that it's easy to derive the others forms.

In the quantum chemistry program, it's a trivial way to store all the
basis sets information by the form of gaussian functions, in the
context below; we can see that it's some way too verbose. On the
contrary, it's convenient to contract the information inside the
gaussian functions to form some "compact" expressions, they are more
suitable to store in the computer and the information is easy to
extract from them. That's what we called the shells and the primitive
shells.

The primitive shells are defined as the set of gaussian functions
which share the same exponents and the same maximum quantum angular
number. For example, the $2s$, $2px$, $2py$ and $2pz$ are considered
to be the same primitive shell, but $1s$, $3d$ gaussian functions are
not in this primitive shell because they have different angular part.

Since that the $S$ type gaussian and $P$ type gaussian are always to
be made to share the same primitive shell, should we follow the same
way to deal with the $D$ orbital and even $F$ orbitals? But there's an
problem; that if people want to calculate the molecules containing the
$d$ orbitals; all the $S$, $P$ and $D$ gaussian functions in the same
shell will be introduced together (if the $d$ orbital is introduced as
some polarized functions, we do not want to do the work in this way);
thus some way need to devised to avoid this situation.

Therefore, for the higher angular momentum part of gaussian functions
(namely the $d$ type and the $f$ type), we use the constraint shells
instead; that is in these shells, only the $d$ or $f$ functions are
inside to form the primitive shells. The only difference related to
these shells is only that to use the pure form or the cartesian
form. For the $d$ type of orbitals, the pure type owns only five
orbitals, whereas the cartesian type has six orbitals; these has been
discussed in the above content.

In the real program, so far people always use the the $SP$ shell to
represent the $s$ type and $p$ type gaussians (thus they share the
same exponents), this is popular in the Pople basis sets; but in other
kind of basis sets such as the Dunning basis sets, the $s$ and $p$ are
separated to be into different primitive shells.

At last let's give some example. Take the oxygen atom of the $6-31g$
as an example, the $6$ gaussians are the six primitive shells (they
have different exponents), they are composed into the basis function
which characterizes the inner orbital of $1s$. On the other hand, the
other $3$ gaussians and additional one gaussians form the other two
group of primitive shells, each one represents the $2s$, $2px$, $2py$
and $2pz$, separately. Thus the ten primitive shells represents $9$
basis sets and contain $14$ gaussian functions.

Now we can see that if we use the pure gaussian functions instead,
it's some too wordy way since that different $px$ $py$ and $pz$ are
take into account. Therefore, in the quantum chemistry the primitive
shells are used as the elementary brick to construct the storing whole
basis sets.

Next, the basis sets are considered to be the linear combination of
the same type of the primitive shells. Thus the basis sets consist of
the same type of angular part. In quantum chemistry, the basis sets is
the most elementary components, the function space are formed from the
variation of the basis sets.

Finally, shells are the most abstract concept. The shell is considered
to contains the same type of primitive shells, they share the same
angular momentum number. For example, $S$ shell, $P$ shell or $D$
shell. It can see that the concept of shell is larger than the basis
sets. For example, the basis of $6-31g$ use two different basis sets
to represent the same type of shell (if for oxygen atom, it's the $SP$
shell; if for the $Br$ atom, it's the $3d$, $4s$ and $4p$ shell).

At last, we try to list the data information used in the common
quantum chemistry package. All the basis sets information, is actually
contracted into the shell array (also the primitive shell array). Here
below is the necessary part of these arrays:
\begin{itemize}
\item for each shell, what kind of atom it belongs to.
\item for each shell, the starting point of its gaussian functions
  list. For example, O atom with $6-31g$ basis set has three shells
  $(1s, 2sp, 3s^{'}p^{'})$. $1s$ has six primitives, thus $array(1) =
  1$, $array(2) = 7$. In this way we can determine the number of
  gaussians it contains.
\item the number of gaussians for each shell.
\item for each shell, what is its angular part? $S$, $SP$ or $D$?
\item For the $D$ or $F$, we use the pure ones or cartesian ones?
\item total shell number
\item the maximum angular type
\item the exponent array, and the corresponding coefficients for the
  primitive shells
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Pople's Basis Sets}
A different convention was adopted by Pople and coworkers. The basis
set structure is given for the whole molecule, rather than particular
a atom. This notation emphasizes also a split valence (SV) nature of
these sets. Symbols like n-ijG or n-ijkG can be encoded as: n - number
of primitives for the inner shells; ij or ijk - number of primitives
for contractions in the valence shell. The ij notations describes sets
of valence double zeta quality and ijk sets of valence triple zeta
quality. Generally, in basis sets derived by Pople's group, the s and
p contractions belonging to the same "electron shell"
(i.e. corresponding formally to the same principal quantum number n)
are folded into a sp-shell. In this case, number of s-type and p-type
primitives is the same, and they have identical exponents. However,
the coefficients for s- and p-type contractions are different.

Now, we are giving some examples. The 4-31G basis set for hydrogen
(hydrogen has only valence electrons!) is a contraction $(31)$ or
$(4s)\rightarrow[2s]$; for first row atoms $(8s,4p) \rightarrow
[3s,2p]$; and for 2nd row atoms the contraction scheme is $(12s,8p)
\rightarrow [4s,3p]$. The 6-311G set represents the following
contractions for water is $(11s,5p/5s) \rightarrow [4s,3p/3s]$.

The Pople's basis sets can also be augmented with d type polarization
functions on heavy atoms only (n-ijG* or n-ijkG*) or on all atoms,
with p-functions on hydrogens (n-ijG** or n-ijkG**). In methane, the
4-31G* encodes following split $(8s,4p,1d/4s) \rightarrow
[3s,2p,1d/2s]$, while 6-311G** for HCN molecule would involve
following contractions: $(11s,5p,1d/5s,1p) \rightarrow
[4s,3p,1d/3s,1p]$.

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../../main"
%%% End:


\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}

\setup{font=lm}
\title{Design Report: Design of Analog Integrated Circuits}
\date{2013-09-01}
\author{John Doe}

\begin{document}
  \maketitle
  \newpage
\section{Hand calculations}
\subsection{Settling error}
For the analysis of the settling error, the circuit digram as shown in the figure \ref{fig:amp_phase} has been used.

\begin{figure}[h!]
  \includegraphics[width=\linewidth]{amplification_phase.png}
  \caption{During amplification phase}
  \label{fig:amp_phase}
\end{figure}

During the sampling phase, capacitor C0 is charged to $V_{in}$. At the beginning of the amplification phase, because he voltage across a capacitor cannot change simultaneously, there will be a negative step on node X. This can be represented as an ideal capacitor with a voltage source in series whose output in a negative going step as shown. The transfer fucntion $\frac{V_{out}}{V_s}(s)$ needs to be determined.
The current through the capacitor $C_o$ can be written as $i_{c0}=-\frac{V_x-V_s}{sC_0}$ \\
Also,
	\begin{equation}
		(V_x-V_{out})sC_f = g_mV_x + V_{out}(\frac{1}{R_0} +sC_L)
	\end{equation}
	\begin{equation*}
		V_{out}=V_x-\frac{i_{c0}}{sC_f}=V_x+\frac{(V_x-V_s)C_0}{C_f}
	\end{equation*}
The last equation can be re-written as
	\begin{equation}
		V_x=\frac{V_{out}+V_s\frac{C_0}{C_f}}{1+\frac{C_0}{C_f}}
	\end{equation}
Combining equations (1) and (2), the transfer function is derived as:
	\begin{equation}
		\frac{V_{out}}{V_s}(s) = \frac{\frac{-g_mC_0R_0}{g_mR_0C_f + C_0 +c_f}}{1+\frac{s(C_LC_0+C_LC_f+C_0C_f)R_0}{g_mR_0C_f + C_0 + C_f}}
	\end{equation}
The time constant of the settiling behavior, is thus given by
	\begin{equation}
		\tau=\frac{(C_LC_0+C_LC_f+C_0C_f)R_0}{g_mR_0C_f + C_0 + C_f}
	\end{equation}
Assuming that the duty cycle of the clock is 50\%, then there will be just half the period left for settling. Because it is a single pole system, the exprsssion for settling time can be derived simply as:
Settling error =$ e^ {-\frac{1}{2f_{clk}\tau}}$
	\begin{equation}
	Error = e^ {-\frac{g_mR_0C_f + C_0 + C_f}{[(C_LC_0+C_LC_f+C_0C_f)R_0]2f_{clk}}}
	\end{equation}
An interesting observation ( not so if you think about it) is that the pole in the expression is approximated by: $ \frac{\beta gm}{C_L + C_0//C_f} $
The look in impedance (with the feedback network) is $\frac{1}{\beta g_m}$ and the total capacitance is indeed $C_L$ in parallel with the series combination of $C_0$ and $C_f$.
However this expression is only valid for a single stage OTA. The settling of the internal node comes into picture. Because the pole at the output of the first stage is typically the lowest frequency, it may be a safe approximation to say that the internal node's GBW will limit the setling behavior. A detailed analysis of it can be found in \cite{4663680}. . \\ \\
However, for the simplicity of the design we approximated the settling time constant for settling as the inverse of GBW.
\section{Common Mode feedback}

In a fully differntial amplifer, where a current source is used as the load, there are two current sources in series. [encirled in figure \ref{fig:simple_ota1}].
\begin{figure}[h]
  \includegraphics{simple_ota_cmfb.png}
  \caption{During amplification phase}
  \label{fig:simple_ota1}
\end{figure}
 Because of the high impedance of the current sources, the output common mode is not well defined. To define the output common mode, a CMFB circuit is used. A CMFB circuit senses the output common mode variation and changes the bias voltage of one of the current sources so that the output common mode is set to a fixed value. A CMFB circuit works in unity gain; \\
\begin{figure}[h!]
  \includegraphics[width=\linewidth]{cmfb.png}
  \caption{During amplification phase}
  \label{fig:cmfb}
\end{figure}
An ideal CMFB circuit is shown in figure \ref{fig:cmfb}. The two resistors forms a voltage divider to cancel out the differential mode signals. The resistor along with the capacitance at the output of the CMFB circuit will define the GBW of the CMFB circuit. A CMFB circuit needs to be faster than the differential circuit. If it is slower, then it may be possible that the bias voltages are not stable. \\
The A0 in the circuit is (part) of open loop gain of the CMFB circuit. The other part of the gain comes from the transfer function from the output of the CMFB circuit to the node where the CMFB circuit is connected. In this case, larger the value of A0 is, smaller is the requirement on the accuracy of Vest. Vest is the estimated bias voltage of the current source that the CMFB will be driving. Vest does not need to be very accurate if A0 is large enough. \\
One of the problems seen during simulation if the simulator finds the solution as a large gate voltage which causes a large drain to gate current [basically a gate breakdown] but no drain to source current. In a real situation the voltage will be limited by the supply rails. The cmfb.cir netlist has been modified to reflect clamping of the output voltage to supply rails.
\bibliographystyle{unsrt}
\bibliography{reference}

\end{document}


\section{Introduction}\label{sec:introduction}
One of the most promising approaches for fault-tolerant quantum computation is based on surface quantum error-correcting codes \cite{dennis2002topological, kitaev2003fault}. With surface codes, error correction only requires the measurement of local operators on a two-dimensional lattice of qubits. The set of measurement outcomes, called the syndrome, is passed to the decoding algorithm to infer the error that has occurred and to supply a correction operator. The resilience against errors can be improved by increasing the system size if the physical error rate is below a threshold value $p_{\text{th}}$. For this increased resiliency to hold, it is essential that the decoder has low time complexity; if the clock-rate of the quantum computer becomes limited by the decoder, the advantages of increasing the system size could be compromised.

Many decoding algorithms have been developed that either aim to improve the threshold and lower logical error rates \cite{wang2003confinement, raussendorf2007faulttolerant, fowler2012towards, fowler2013minimum, heim2016optimal, duclos2010fast, duclos2013fault, bravyi2014efficient, darmawan2018linear}, or to perform under more realistic noise models \cite{tuckett2020fault, hutter2015improved, bravyi2013quantum,  nickerson2019analysing, wootton2012high, huang2020fault}, including a new class of neural network decoders \cite{baireuther2019neural, chamberland2018deep, liu2019neural, nautrup2019optimizing, torlai2017neural, varsamopoulos2017decoding, varsamopoulos2020decoding}. %, and other types \cite{bombin2012universal, herold2015cellular, horsman2012surface, kubica2019cellular, kuo2021exploiting, watson2015fast}.
The most popular decoder for surface codes is the Minimum-Weight Perfect Matching (MWPM) decoder. It performs near-optimal for a bit-flip noise model \cite{dennis2002topological} on a standard toric code with a threshold of $p_{\text{th}} = 10.3\%$, and for a phenomenological noise model \cite{wang2003confinement}, which includes faulty measurements, with $p_{\text{th}} = 2.9\%$. The main idea is to approximate the error with the minimum-weight error configuration compatible with the syndrome. The minimum-weight configuration is found by constructing a fully connected graph between the nodes of the syndrome, which leads to a cubic worst-case time complexity \cite{kolmogorov2009blossom}. Recent empirical results show that, in some regimes, MWPM can be performed with worst case linear complexity \cite{fowler2012towards} but further work is necessary to achieve the throughput required for real-time error correction.

In this work, we build on top of a recently proposed decoder called the Union-Find (UF) decoder. It combines a low worst-case time complexity with a high threshold \cite{delfosse2017almost}, making it a practical solution for real devices \cite{huang2020fault,delfosse2020hierarchical,das2020scalable}. The UF decoder's thresholds on the toric code with independent bit-flip noise and phenomenological noise are $9.9\%$ and $2.7\%$, and its worst-case time complexity is $\mathcal{O}(n\alpha(n))$, where $\alpha$ is the inverse of Ackermann's function \cite{tarjan1975efficiency}. For any physically feasible amount of qubits, this value is $\alpha(n) \leq 3$, leading to an ``almost-linear'' time complexity.

Our goal is to bridge the gap between MWPM and UF while maintaining a quasi-linear complexity. For this, we first investigate several small modifications of the UF decoder and notice that the best performance is achieved by the modifications that output matchings with minimal weight. Leveraging this idea, we propose a modified UF decoder that heuristically attempts to minimize the weight of the matchings. The modified decoder, which we dub the \emph{Union-Find Partitioned-Growth decoder} (UFPG), performs similar to the MWPM decoder while maintaining a quasi-linear time complexity. In \Cref{sec:surfacecode,sec:unionfind}, we introduce the surface code and the UF decoder. In \Cref{sec:ufbb}, we describe the modified algorithm and its motivation. We discuss the algorithm's complexity in \Cref{sec:complexity} and compare its performance with other decoders in \Cref{sec:performance}.

\section{The Surface Code}\label{sec:surfacecode}

The \emph{toric code}, a topological code introduced by Kitaev \cite{kitaev2003fault}, is defined as an arrangement of qubits on the edges of a square lattice with periodic boundary conditions. We denote by $V,E,F$ the set of vertices, set of edges and set of faces of the lattice. The code is defined as the ground state of the Hamiltonian
\begin{equation}
    H = -\sum_{v \in V} X_v -\sum_{f \in F} Z_f,
\end{equation}
where the operator $X_v$ is the product of Pauli $X$ operators on the qubits located on the edges incident to the vertex $v$, \emph{i.e.}, $X_v = \prod_{e \in v} X_e$, and the operator $Z_f = \prod_{e \in f} Z_e$ is the product of Pauli $Z$ operators on the qubits located on edges of face $f$. The code space is spanned by the simultaneous ``+1'' eigenstate of all operators $X_v$ and $Z_f$. Together with any possible product of them, these operators are the \emph{stabilizers} of the code and form the stabilizer group $S$. The torus' non-trivial cycles encode the logical operators. Below a certain threshold, physical errors mostly introduce local effects that do not add up to a non-trivial cycle.

For simplicity, we consider noise caused by independent and identically distributed (i.i.d.) bit-flip errors, where each qubit is subjected to a Pauli $X$ error with probability $p_X$. Due to {lattice duality}, the error detection and correction of phase-flip errors are identical. We consider a phenomenological model where the ideal measurements outputs are flipped also with probability $p_X$.
%Additionally, any qubit may be \emph{erased} from the system with probability $p_e$. The set of erased qubits is denoted with $\varepsilon$. This \emph{erasure} is detectable, such that we can replace or reinitiate all erased qubits, which corresponds to a random Pauli error after measurement.

Error correction is preceded by measuring a set of stabilizers of the code, \emph{i.e.}, the operators $X_v$ and $Z_f$. For a set of bit-flip errors $E_X = \{I,X\}^{\otimes n}$, the stabilizers $Z_f$ that anticommute with the error return a non-trivial outcome. The set of non-trivial eigenvalues of the stabilizers is called the syndrome $\sigma$ of the code. Given the measured $\sigma$, it is the task of the decoder to find the correction operator $\mathcal{C}(\sigma)$. When the correction operator is applied, the code is returned to the code space. %Since the error is corrected up to a stabilizer, the mapping of the syndrome to the correction is not one-to-one. The task of the decoder is to choose the correction most similar to the error.

\section{Union-Find decoder}\label{sec:unionfind}
The Union-Find decoder \cite{delfosse2017almost} maps each element of the syndrome $\sigma$ to a vertex $v$ in a non-connected graph defined on the code lattice. From this starting point, it grows clusters around these vertices by repeatedly adding a layer of edges and vertices to existing clusters, until all clusters have an even number of non-trivial syndrome vertices. %This process is described as the growth of a cluster or the growth of the vertices that lie on a cluster's boundary.
Then, it selects a spanning tree $F$ for each cluster. %, such that each cluster becomes a connected acyclic graph.
The leaves of each spanning tree are conditionally peeled in a tail-recursive breadth-first search until all non-trivial syndrome vertices are paired and linked by an unique path within $F$, which \textcolor{cyan}{in sum} is the correcting operator $\mathcal{C}$ \cite{delfosse2017almost}. The strategy for constructing the clusters turns out to have a strong effect on performance. For instance, the threshold for bit-flip noise of a decoder that grows the clusters following a random order is $9.2\%$ \cite{delfosse2017almost}, while if the clusters are grown in order of cluster size, which we call \textbf{Weighted Growth}, the threshold increases to $9.9\%$ (see \Cref{thres_comp})\cite{delfosse2017almost}. %for bit-flip noise in this \textbf{Weighted Growth} variant of the decoder.

The complexity of the Union-Find decoder is driven by the merging of the clusters. For this, the algorithm uses the Union-Find or disjoint-set data structure \cite{tarjan1975efficiency}. This data structure contains a set of elements, in this case vertices on the lattice. The set of elements is represented by a two-level tree. At the root of the tree sits one element chosen arbitrarily; the rest of the elements are linked to the root element. The structure admits two functions: find and union. Given $v$ an element from the structure, the function $\Find(v)$ returns the root element of the tree. This is is used to %travel in the cluster-tree --- a disjoint set of the cluster's vertices --- from vertex $v$ to the representative element, to
identify the cluster to which $v$ belongs. The second function is $\Union(u, v)$, this function merges the sets associated with elements $u$ and $v$. This requires pointing all the elements of one of the sets to the root of the other. In order to minimize the number of operations the root of the set with the larger number of elements is chosen as root for the merged set, this is called \textbf{Weighted Union}. In this context, $\Union$ is used when the growth of a cluster requires adding a vertex that belongs to another. % cluster, two vertices $u, v$ are connected on a newly added edge $(u,v)$, $\Find(u), \Find(v)$ output the roots $r_u, r_v$. If $r_u \neq r_v$, the two cluster-trees are not connected. The two cluster are then merged by $\Union(r_u, r_v)$ by pointing one tree's root to another root.


\subsection{Choosing the number of delays}

\begin{figure}
\img[0.75]{searcharray}
\captionn
{Performance of the GEVec-based SWR detector, for different delay line lengths}
{At the chosen 1000 Hz sampling rate, each delay corresponds to 1 ms. The red baseline is the state-of-the-art SWR detector. Detection latency is specified as a fraction of the duration of the corresponding SWR event, and is evaluated at the threshold where each detector reaches its maximum $F_1$-score. In the latency panel, bold lines and shaded areas indicate the median and the interquartile range of the latency distributions, respectively.}
\label{fig:num-delays}
\end{figure}

Adding more delays (\cref{fig:num-delays}) improves detection accuracy even further -- up to a peak \emph{max $F_1$} of 93\% at about eleven delays. (This corresponds to eleven milliseconds, or approximately half a ripple phase). Detection latency also increases with increasing number of delays, but only slightly, always staying well below the state-of-the-art latency. Like the \emph{max $F_1$} score, latency stagnates after about eleven delays. Further, we note that the latency distributions of the GEVec-based detectors have a lower spread than those of the state-of-the-art detector.

There is thus a slight tradeoff to be made when choosing the number of delays for a GEVec-based detector: using more delays yields detectors that are more accurate, but also slightly slower. Given that the decrease in speed is minor (about five percentage-points), it is reasonable to choose the amount of delays that maximizes detection accuracy. In this analysis, this optimal point is reached at an eleven milliseconds-long delay line.


% This is part of the TFTB Reference Manual.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file refguide.tex for copying conditions.

\renewcommand{\footnoterule}{}
\markright{tfrbert}
\section*{\hspace*{-1.6cm} tfrbert}

\vspace*{-.4cm}
\hspace*{-1.6cm}\rule[0in]{16.5cm}{.02cm}
\vspace*{.2cm}

{\bf \large \sf Purpose}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Unitary Bertrand time-frequency distribution.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Synopsis}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
[tfr,t,f] = tfrbert(x)
[tfr,t,f] = tfrbert(x,t)
[tfr,t,f] = tfrbert(x,t,fmin,fmax)
[tfr,t,f] = tfrbert(x,t,fmin,fmax,N)
[tfr,t,f] = tfrbert(x,t,fmin,fmax,N,trace)
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Description}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
        {\ty tfrbert} generates the auto- or cross- unitary Bertrand
        distribution, defined as
\begin{eqnarray*}
B_x(t,\nu) =\nu \int_{-\infty}^{+\infty}
  \frac{u/2}{\sinh\left(\frac{u}{2}\right)}\ X\left(\frac{\nu\ u\
  e^{-u/2}}{2 \sinh\left(\frac{u}{2}\right)}\right)\ X^*\left(\frac{\nu\ u\
  e^{+u/2}}{2 \sinh\left(\frac{u}{2}\right)}\right)\ e^{-j2\pi\nu ut}\ du
\end{eqnarray*}
where $X(\nu)$ is the Fourier transform of $x(t)$.\\

\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}
Name & Description & Default value\\
\hline
        {\ty x} & signal (in time) to be analyzed. If {\ty x=[x1 x2]}, {\ty tfrbert}
           computes the cross-unitary Bertrand distribution {\ty (Nx=length(x))}\\
        {\ty t} & time instant(s) on which the {\ty tfr} is evaluated & {\ty (1:Nx)}\\
        {\ty fmin, fmax} & respectively lower and upper frequency bounds of
           the analyzed signal. These parameters fix the equivalent
           frequency bandwidth (expressed in Hz). When unspecified, you
           have to enter them at the command line from the plot of the
           spectrum. {\ty fmin} and {\ty fmax} must be $>0$ and $\leq 0.5$\\
        {\ty N} & number of analyzed voices & auto\footnote{This value,
	determined from {\ty fmin} and {\ty fmax}, is the
	next-power-of-two of the minimum value checking the non-overlapping
	condition in the fast Mellin transform.}\\
        {\ty trace} & if nonzero, the progression of the algorithm is shown
                                                & {\ty 0}\\

\hline\end{tabular*}\end{minipage} \newpage
\hspace*{1.5cm}\begin{minipage}[t]{13.5cm}
\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}
Name & Description & Default value\\\hline

     \hline {\ty tfr} & time-frequency matrix containing the coefficients of the
           distribution (x-coordinate corresponds to uniformly sampled
           time, and y-coordinate corresponds to a geometrically sampled
           frequency). First row of {\ty tfr} corresponds to the lowest
           frequency\\
        {\ty f} & vector of normalized frequencies (geometrically sampled
           from {\ty fmin} to {\ty fmax})\\

\hline
\end{tabular*}
\vspace*{.2cm}

When called without output arguments, {\ty tfrbert} runs {\ty tfrqview}
\end{minipage}
\vspace*{1cm}

{\bf \large \sf Example}
\begin{verbatim}
         sig=altes(64,0.1,0.45);
         tfrbert(sig);
\end{verbatim}
\vspace*{.5cm}

{\bf \large \sf See Also}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
all the {\ty tfr*} functions.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf References}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
[1] J. Bertrand, P. Bertrand ``Time-Frequency Representations of Broad-Band
Signals'' IEEE ICASSP-88, pp. 2196-2199, New-York, 1988.\\

[2] J. Bertrand, P. Bertrand ``A Class of Affine Wigner Functions with
		  Extended Covariance Properties'', J. Math. Phys.,
		  Vol. 33, No. 7, July 1992.
\end{minipage}


\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{color}
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\lstset{language=Matlab,%
    basicstyle=\footnotesize,
    breaklines=true,%
    morekeywords={matlab2tikz},
    keywordstyle=\color{blue},%
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    identifierstyle=\color{black},%
    stringstyle=\color{mylilas},
    commentstyle=\color{mygreen},%
    showstringspaces=false,%without this there will be a symbol in the places where there is a space
    numbers=left,%
    numberstyle={\tiny \color{black}},% size of the numbers
    numbersep=9pt, % this defines how far the numbers are from the text
    emph=[1]{for,end,break},emphstyle=[1]\color{red}, %some words to emphasise
    %emph=[2]{word1,word2}, emphstyle=[2]{style},
}
\title[Real-Time Spectrum Analyser~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\insertframenumber/\inserttotalframenumber]{Implementation of a Real-Time Spectrum Analyzer Synthesized on FPGA}
\author[David Lavoie-Boutin]{David Lavoie-Boutin, 260583602}
\date{\today}

\usetheme{Copenhagen}
\usecolortheme{beaver}

\begin{document}

\frame{\titlepage}

\begin{frame}
\frametitle{Table of Contents}
\tableofcontents
\end{frame}

\section{Motivation}

\begin{frame}\frametitle{FFT is useful }

  \begin{exampleblock}{}
    {\large ``The most important numerical algorithm of our lifetime''}
    \vskip5mm
    \hspace*\fill{\small--- Gilbert Strang}
  \end{exampleblock}
\end{frame}

\begin{frame}
  \frametitle{Steps}
  \begin{itemize}
    \item Matlab Implementation
    \item Code Generation
    \item Display Module
    \item Full Integration
  \end{itemize}
\end{frame}

\section{Matlab}

\begin{frame}
  \frametitle{Cooley–Tukey Algorithm}
  \lstinputlisting[language=Matlab, firstline=3, lastline=14, caption=Recursive FFT implementation]{../myFFT.m}
\end{frame}

\begin{frame}
  \lstinputlisting[language=Matlab, caption=Iterative FFT implementation, lastline=5]{../fft_it.m}
\end{frame}

\begin{frame}
  \frametitle{Simulink schematic}
  \begin{figure}[!htb]
    \centering
    \includegraphics[width=0.8\textwidth]{sim2.PNG}
    \caption{Simulink schematic of a HDL optimized FFT}
    \label{fig:simulink}
  \end{figure}
\end{frame}

\section{Display on the FPGA}
\begin{frame}\frametitle{Display module using switches}
  \begin{figure}[!htb]
    \centering
    \includegraphics[width=0.8\textwidth]{switch_circuit.PNG}
  \end{figure}
\end{frame}

\begin{frame}\frametitle{Package Definitions}
\lstinputlisting[language=VHDL, firstline=5, lastline=10]{../VideoLab/graph_display.vhd}
\end{frame}

\begin{frame}\frametitle{Modular Bar Chart}
\lstinputlisting[language=VHDL, firstline=47, lastline=49]{../VideoLab/graph_display.vhd}
\end{frame}

\begin{frame}\frametitle{Array Input}
\lstinputlisting[language=VHDL]{array_ex.vhd}
\end{frame}

\begin{frame}\frametitle{Switch to Test}
\lstinputlisting[language=VHDL, firstline=7, lastline=12]{../VideoLab/switch_to_array.vhd}
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.8\textwidth]{switch_sim.PNG}
  \caption{Modelsim simulation of the switch to array module}
  \label{fig:switch_sim}
\end{figure}
\end{frame}

\section{FFT on FPGA}

\begin{frame}\frametitle{Audio processing pipeline}
\begin{figure}[!htb]
  \centering
  \includegraphics[width=\textwidth]{full_filter.PNG}
  \caption{FFT integration in the audio processing unit}
  \label{fig:block_filter}
\end{figure}
\end{frame}

\begin{frame}\frametitle{FFT Controller}
\lstinputlisting[language=VHDL, firstline=18, lastline=34]{../VideoLab/fft_controller_block.vhd}
\end{frame}

\begin{frame}\frametitle{Magnitude of complex number}
\lstinputlisting[language=VHDL, firstline=5, lastline=8, caption=Square-Root function]{../VideoLab/sqrt.vhd}
\lstinputlisting[language=VHDL, firstline=18, lastline=20, caption=Magnitude module]{../VideoLab/magnitude.vhd}
Non-Restoring Square Root Algorithm
\end{frame}

\begin{frame}\frametitle{Data buffer}
\lstinputlisting[language=VHDL, firstline=7, caption=Buffer module for the FFT output, lastline=16]{../VideoLab/buffer_fft_output.vhd}
\end{frame}

\begin{frame}\frametitle{Data buffer}

\begin{figure}[!htb]
  \centering
  \includegraphics[width=\textwidth]{buffer_sim.PNG}
  \caption{Simulation results for the buffer module}
  \label{fig:buff_sim}
\end{figure}
\end{frame}

\begin{frame}\frametitle{Audio processing pipeline}
\begin{figure}[!htb]
  \centering
  \includegraphics[width=\textwidth]{full_filter.PNG}
\end{figure}
\end{frame}

\begin{frame}\frametitle{Full Design}
\begin{figure}[!htb]
  \centering
  \includegraphics[width=\textwidth]{top_level.PNG}
\end{figure}
\end{frame}

\end{document}


\chapter{Cyclic Cubic Fields}
\label{chap:chap-five}
In this chapter, we start with a cubic polynomial with Galois group $A_3=C_3$. A famous work with only half page given by Seidelmann in 1917 \citep{seidelmann1917gesamtheit} showed the condition of the polynomial which satisfies the Galois group $C_3$. We have recovered the process to get this condition with a lemma which can be found in Cohen's book. Then we proceed to rearrange the explicit results for cyclic cubic field based on Cohen's book. At last, we will propose some examples on prime decomposition and computing class number.

In additional, we have offered some special examples in the last section \ref{sec:ssccf} for cyclic cubic field without the standard form which we will show as follows. What's more, we also give a formula (See theorem \ref{thm:ccuformula}) for a type of cyclic cubic field which is given risen by the ideas of F.C. Orvay's \citep{orvay1991cyclic}.

Firstly, we propose some preliminaries of cyclyc cubic field $K$. Let $K$ be a number field of degree 3 over $\mathbb{Q}$, i.e. a cubic field. If $K$ is Galois over $Q$, with $\operatorname{Gal}(K)=A_3$, then $K$ is so called a cyclic cubic field. let denote the Galois group of $K$ be $\langle\sigma\rangle$, where $\sigma^{-1}=\sigma^2$. Note that, for cyclic cubic field $K$ can only be totally real, based on the Lemma \ref{lem:signaturegal}.

\section{Cubic Polynomial and Cyclic Cubic Field}
The cyclic cubic fields can be viewed as generating by cubic polynomials. let's consider a polynomial of degree 3 which has the form
$$f(x)=ax^3+bx^2+cx+d$$
where $a\neq0$. There are two possible Galois groups for splitting field of cubic polynomial, namely $S_3$ and $A_3=C_3$.

Now we will reduce the general cubic equation into a cubic trinomial by eliminating the quadratic term. We begin with the general cubic with rational coefficients $$ax^3+bx^2+cx+d$$
and make the substitution $x=X-\frac{b}{3a}$ to get
$$aX^3+\left(c-\frac{b^2}{3a}\right)X-\frac{bc}{3a}+d+\frac{2b^3}{27a^2}$$
Since each of these coefficients are rational, we have now have a cubic trinomial in $\mathbb{Q}$. Also, since we are working over the rational numbers, we can easily divide by the leading coefficient of the $x^3$ term and obtain a monic cubic equation.

The main distinction of cubics with a Galois group of $C_3$ is that the polynomial discriminant is equal to a square in $\mathbb{Q}$ which is a direct corollary of Theorem \ref{thm:discriminantsq}. Seidelmann uses this fact to give a form for the coefficients of a monic cubic trinomial with a Galois group of $C_3$. For $p,q\in\mathbb{Q}$, the equation
$$f(x)=x^3-3(p^2+3q^2)x+2p(p^2+3q^2)$$
where $f(x)$ is not reducible, represents all equations of degree 3 with a Galois group of $C_3$.

In Seidelmann's paper (German version), there are only few rows to show the result but without proof, so now we give a brief proof of it. We assume that $K$ is a cyclic cubic field. Let $\theta$ be an algebraic integer such that $K=\mathbb{Q}(\theta)$, and let $f(x)=x^3+ax+b$ be the minimal polynomial of $\theta$ as we mentioned before.

One important consequence is necessary for calculation. Since any cyclic cubic field has at least one real embedding and since $K$ is Galois, all the roots of $f$ must be real(See Lemma \ref{lem:signaturegal}). Of course, we can get this from the square discriminant of $f$.

Consider the primitive cube roots of unity $\zeta=e^{2\pi i/3}$, then it's easy to see that $K(\zeta)$ is a sextic field over $\mathbb{Q}$. What's more, it's also Galois with Galois group $\langle\sigma,\tau\rangle$, where $\sigma$ has been defined above which fixes $\zeta$, $\tau$ is the complex conjugation. We first prove the following lemma, one could find a similar lemma in Cohen's book  \citep{cohen1993course}.

\begin{lemma}
Set $\gamma=\theta+\zeta^2\sigma(\theta)+\zeta\sigma^2(\theta)\in K(\zeta)$, and $\beta=\gamma^2/\tau(\gamma)$. Then $\beta\in\mathbb{Q}(\zeta)$ and we have $$f(x)=x^3-\frac{e}{3}x-\frac{eu}{27},$$ where $e=\beta\tau(\beta)$ and $u=\beta+\tau(\beta)$.
\begin{proof}
We have $\tau(\gamma)=\theta+\zeta\sigma(\theta)+\zeta^2\sigma^2(\theta)$, also we can verify that $$\sigma(\gamma)=\sigma(\theta)+\zeta^2\sigma^2(\theta)+\zeta\theta=\zeta\gamma$$ and $$\sigma(\tau(\gamma))=\sigma(\theta)+\zeta\sigma^2(\theta)+\zeta^2\theta=\zeta^2\tau(\gamma).$$ Hence, we have $$\sigma(\beta)=\sigma(\gamma^2/\tau(\gamma))=\gamma^2/\tau(\gamma)=\beta,$$ i.e. $\beta$ is invariant under the action of $\sigma$, so by the Galois theory $\beta\in\mathbb{Q}(\zeta)$.

Note that $e$ and $u$ are norm and trace of $\beta$ in $\mathbb{Q}(\zeta)$ respectively, hence is rational numbers.

Now we have the following matrix equation:
\begin{equation*}
\left(\begin{array}{c}0\\ \gamma\\ \tau(\gamma)\end{array}\right)=\left(\begin{array}{ccc}1&1&1\\ 1&\zeta^2&\zeta\\ 1&\zeta&\zeta^2\end{array}\right)\left(\begin{array}{c}\theta\\ \sigma(\theta)\\ \sigma^2(\theta)\end{array}\right)
\end{equation*}
Then, we have
\begin{equation*}
\left(\begin{array}{c}\theta\\ \sigma(\theta)\\ \sigma^2(\theta)\end{array}\right)=\frac{1}{3}\left(\begin{array}{ccc}1&1&1\\ 1&\zeta&\zeta^2\\ 1&\zeta^2&\zeta\end{array}\right)\left(\begin{array}{c}0\\ \gamma\\ \tau(\gamma)\end{array}\right)
\end{equation*}
From the formula, we have $$a=\theta\sigma(\theta)+\theta\sigma^2(\theta)+\sigma(\theta)\sigma^2(\theta)=-\frac{\gamma\tau(\gamma)}{3}$$ and $$b=-\theta\sigma(\theta)\sigma^2(\theta)=-\frac{\gamma^3+(\tau(\gamma))^3}{27}.$$
Note that $\tau(\beta)=\tau(\gamma^2/\tau(\gamma))=\tau(\gamma^2)/\gamma=(\tau(\gamma))^2/\gamma$. We can easily verify that the norm and trace of $\beta$ coincide $e$ and $u$.
\end{proof}
\end{lemma}

Now since $\mathbb{Q}(\zeta)=\mathbb{Q}(\sqrt{-3})$, we can assume that $\beta=p+q\sqrt{-3}\in\mathbb{Q}(\zeta)$, where $p,q\in\mathbb{Q}$ then $e=\operatorname{N}(\beta)=(p+q\sqrt{-3})(p-q\sqrt{-3})=p^2+3q^2$, $u=\operatorname{Tr}(\beta)=2p$, hence we have
$$f(x)=x^3-\frac{p^2+3q^2}{3}x-\frac{2p(p^2+3q^2)}{27},$$
which is equivalent to $f(x)=x^3-3(p^2+3q^2)x-2p(p^2+3q^2)=x^3-3ex-eu$ up to scaling. (The sign of the constant term's coefficient can be change by replace $p$ into $-p$.)

\section{Discriminant and Integral Basis}
Now, for simplicity, up to suitable scaling, we use $f(x)=x^3-3ex-e u$, where wlog, we assume that $e,u$ are rational integer. Note that then $\beta$ can be written down an algebraic integer of $\mathbb{Q}(\zeta)$,i.e. we have $\beta=\frac{u+v\sqrt{-3}}{2}, u,v\in\mathbb{Z}$. What's more, $u$ cannot be divisible by 3 since $\beta$ is not divisible by the ramified prime. Hence, by suitable choosing $\beta$ or $-\beta$, we may assume that $u\equiv2(\operatorname{mod} 3).$
In this notation, $e=\frac{u^2+3v^2}{4}$, then $e\equiv 1(\operatorname{mod} 3)$. In fact, $e$ is the product of distinct primes which congruent to 1 modulo 3 (including $e=1$) \citep{cohen1993course}.
i.e. we have following lemma:
\begin{lemma}\label{basiccubic}
For any cyclic cubic field $K$, there exists a unique pair of integer $e,u$ such that $e$ is equal to a product of distinct primes congruent to 1 modulo 3, $u\equiv2(\operatorname{mod} 3)$, $v>0$ and such that $K=\mathbb{Q}(\theta)$, where $\theta$ is a root of the polynomial $$f(x)=x^3-3ex-eu.$$
Moreover, the conjugates of $\theta$ are given by following formulas:
\begin{eqnarray}\label{eqn:conjugatescub}
\sigma(\theta)&=&\frac{-2e}{v}-\frac{u+v}{2v}\theta+\frac{\theta^2}{v},\\
\sigma^2(\theta)&=&\frac{2e}{v}+\frac{u-v}{2v}\theta-\frac{\theta^2}{v}
\end{eqnarray}
\begin{proof}
For simplicity, we just give the proof of the conjugates. Firstly, since the discriminant of $x^3+ax+b$ is equal to $-(4a^3+27b^2)$ (Also can refer the Appendix \ref{prop:disctri}), hence the discriminant of $f$ is equal to $$-(4(-3e)^3+27e^2u^2)=-27e^2(u^2-4e)=81e^2v^2.$$
Then from the definition of Polynomial we have $d=(\theta-\sigma(\theta))(\sigma(\theta)-\sigma^2(\theta))(\sigma^2(\theta)-\theta)=\pm9ev$. If necessary, by exchanging the $\sigma(\theta), \sigma^2(\theta)$, we may assume that $$\sigma(\theta)-\sigma^2(\theta)=\frac{9ev}{(\theta-\sigma(\theta))(\theta-\sigma^2(\theta))}=\frac{9ev}{f'(\theta)}=9ev/(3\theta^2-3e).$$
Now we should simplify this equation. Since $f(\theta)=\theta^3-3e\theta-eu=0$, hence we can use the extended Euclidean algorithm with $A(x)=x^3-3ex-eu$ and $B(x)=x^2-e$, then we got the inverse of $B$ modulo $A$ is equal to $(2x^2-ux-4e)/(3v^2e)$ (note that $\operatorname{gcd}(A,B)=1$ for there is no multiple roots in $f(x)$.), hence $$\sigma(\theta)-\sigma^2(\theta)=\frac{2\theta^2-u\theta-4e}{v}$$
On the other hand, since the trace of $\theta$ is equal to 0, so we have $\sigma(\theta)+\sigma^2(\theta)=-\theta$, we can get the final result of $\sigma(\theta)$ and $\sigma^2(\theta)$ from above equations.
\end{proof}
\end{lemma}

The following theorem\citep{cohen1993course} shows the integral basis and discriminant of cyclic cubic field:
\begin{theorem}\label{thm:cbfintegralnor}
Let $K=\mathbb{Q}(\theta)$ be a cyclic cubic field where $\theta$ is a root of $x^3-3ex-eu=0$ and where, as above, $e=\frac{u^3+3v^2}{4}$ is equal to a product of distinct primes (namely $t$ distinct primes) congruent to 1 modulo 3, $u\equiv2(\operatorname{mod} 3)$, then
\begin{enumerate}
\item Assume that $3\nmid v$, i.e. 3 is ramified in $K$. Then $(1,\theta,\sigma(\theta))$\footnote{$\sigma$ is given by lemma \ref{basiccubic}.} is an integral basis of $K$ and the discriminant of $K$ is equal to $(9e)^2$. What's more, there exists up to isomorphism exactly $2^t$ cyclic cubic fields of discriminant $(9e)^2$ defined by the polynomial.
\item Assume that $3\mid v$, i.e. 3 is unramified in $K$. Then let $\theta'=(\theta+1)/3$, $(1,\theta',\sigma(\theta'))$ is an integral basis of $K$ and the discriminant of $K$ is equal to $e^2$. What's more, there exists up to isomorphism exactly $2^{t-1}$ cyclic cubic fields of discriminant $e^2$ defined by the polynomial.
\end{enumerate}
\end{theorem}

For the first case, not that $\theta^2=v\sigma(\theta)+((u+v)/2)\theta+2e$ from the result of $\sigma(\theta)$, so the $\mathbb{Z}$-module $O_K$ generated by $(1,\theta,\sigma(\theta))$ contains $\mathbb{Z}[\theta]$. So the index $[O_K:\mathbb{Z}[\theta]]=v$.
For the second case, ie, if the prime 3 is unramified in $K$, then we can write the minimal polynomial of $\theta'$, i.e. $\theta'$ is a root of the equation with coefficients in $\mathbb{Z}$ \begin{equation} f(x)=x^3-x^2+\frac{1-e}{3}x-\frac{1-3e+eu}{27},\end{equation} where  $e=\frac{u^2+27v'^2}{4},u\equiv2(\operatorname{mod} 3), u\equiv v' (\operatorname{mod} 2), v'>0$, and $e$ is the product of distinct primes congruent to 1 modulo 3. For the same reason, we have $[O_K:\mathbb{Z}[\theta']]=v/3=v'$.

With new notation on $e,u,v$, Cohen's book\citep{cohen1993course} given us another theorem as follows:
\begin{theorem}\label{thm:ccpoly}
All cyclic cubic fields $K$ are given exactly once (up to isomorphism) in the following way:
\begin{enumerate}
\item If the prime 3 is ramified in $K$, then $K=\mathbb{Q}(\theta)$ where $\theta$ is a root of the equation with coefficients in $\mathbb{Z}$ \begin{equation} f(x)=x^3-\frac{e}{3}x-\frac{e u}{27},\end{equation} where $e=\frac{u^2+27v^2}{4},u\equiv6(\operatorname{mod} 9),3\nmid v, u\equiv v (\operatorname{mod} 2), v>0$, and $e/9$ is the product of distinct primes congruent to 1 modulo 3 (could be 1).
\item If the prime 3 is unramified in $K$, then $K=\mathbb{Q}(\theta)$ where $\theta$ is a root of the equation with coefficients in $\mathbb{Z}$ \begin{equation} f(x)=x^3-x^2+\frac{1-e}{3}x-\frac{1-3e+eu}{27},\end{equation} where  $e=\frac{u^2+27v^2}{4},u\equiv2(\operatorname{mod} 3), u\equiv v (\operatorname{mod} 2), v>0$, and $e$ is the product of distinct primes congruent to 1 modulo 3.
\item In both cases, the discriminant of $f$ is equal to $e^2v^2$ and the discriminant of number field $K$ is equal to $e^2$.
\item Conversely, if $e$ is equal to 9 times the product of $t-1$ distinct primes congruent to 1 modulo 3, (resp. is equal to the product of $t$ distinct primes congruent to 1 modulo 3), then there exists up to isomorphism exactly $2^{t-1}$ cyclic cubic fields of discriminant $e^2$ defined by the polynomials $f(x)$ given in (1) (resp. (2)).
\end{enumerate}
\end{theorem}

For this case, the integral basis is showed as follows.
\begin{theorem}\label{thm:ccpolycon}
With the notation in Theorem \ref{thm:ccpoly}, the conjugates of $\theta$ are given by the formulas:
\begin{enumerate}
\item If 3 is ramified in $K$,(i.e. in case (1)) then $$\sigma^{\pm1}(\theta)=\mp\frac{2e}{9v}+\frac{-3v\mp u}{6v}\theta\pm\frac{\theta^2}{v};$$
\item If 3 is unramified in $K$,(i.e. in case (2)) then $$\sigma^{\pm1}(\theta)=\frac{9v\pm(u+2-4e)}{18v}+\frac{-3v\mp (u+4)}{6v}\theta\pm\frac{\theta^2}{v}$$
In all cases, $(1,\theta,\sigma(\theta))$ is an integral basis of $K$.
\end{enumerate}
\end{theorem}

\section{Prime Decomposition}\label{sec:ccf-decom}
Without loss of generality, we use the symbol in theorem \ref{thm:ccpoly} for simplicity. The situation of the decomposition of prime number in cyclic cubic field is quite easy, from the transitivity properties of Galois group, there are only three cases for decomposition, inert, totally ramified, splits completely.

From the fundamental theorem of ramification, i.e. theorem \ref{thm:ramification}, it follows that if $p|e$, i.e. $p$ is one of the prime number (including 3) lies in $e$'s factorization expression, then $p$ is totally ramified. If $p\nmid e$ , then $p$ is unramified, even from theorem \ref{thm:unramified}, we can not determine the inert or splits completely. However if $p\nmid v$, then we can use the theorem \ref{thm:kummer} to determine the prime decomposition. In fact, the result is similar to quadratic field but change the Kronecker symbol to a cubic residue symbol, i.e. consider the congruence $x^3\equiv e(\operatorname{mod} p)$ is solvable or not.(or equivalently $p^{(e-1)/3}\equiv 1(\operatorname{mod} p)$).

If $p\mid v$, then $f$ has at least a double root modulo $p$. If $f$ has a double root, but not a triple root, then $f$ also has a simple root which corresponds to a prime ideal of degree 1. In this case $pO_K$ is the product of three ideals of degree $1$, i.e. splits completely. Finally, if $f$ has a triple root modulo $p$, we must apply other techniques, see Cohen's book 6.2.5 \citep{cohen1993course}.

\section{Units and Class Number}
From Dirichlet Unit Theorem, since $K$ is a real field, hence $\mu(K)=\{\pm1\}$ and we have $U(K)=\{\pm1\}\times{\mathbb{Z}^2}$. A unit $\tau$ of $K$ is called the fundamental unit of $K$ if and only if $\{-1,\tau,\sigma(\tau)\}$ generate the group of units of $K$.
From the property of units, we have $\operatorname{N}(\tau)=\pm1$. The only fundamental units are $\pm\tau^{\pm1},\pm(\sigma(\tau))^{\pm1},\pm(\sigma^2(\tau))^{\pm1}$. The fundamental unit $\tau$ is uniquely determined except for taking conjugates and inverses.

This fundamental system of units can be calculated by means of generalized continued fraction algorithms by Voronoi \citep{voronoi1896generalization}, which have been interpreted geometrically by Delone and Faddeev \citep{delone1964theory}.

Harvey Cohn and Saul Gorn first give the units of 45 cyclic cubic fields of discriminants, where $e$ is the prime congruent to 1 modulo 3 between 7 to 499.

Then, a table of class numbers and units in cyclic cubic fields with $e<4000$\footnote{this $e$ is the same to the one in Theorem \ref{thm:ccpoly}} has been given by Marie-Nicole Gras \citep{gras1975methodes}, after that Veikko Ennola and Reino Turunen \citep{ennola1985cyclic} have constructed an extended table for $e<16000$.

\section{Conductor of Cyclic Cubic Field}
From the definition of conductor and some results in chapter \ref{chap:chap-two}, we can get the conductor of a cyclic cubic field $f_3$ is of the form \citep{maki1980determination}

$$f_3=\left\{\begin{array}{cc}q_0q_1\cdots q_n& if 3\nmid f_3\\ 9q_1\cdots q_n&if 3\mid f_3\end{array}\right.$$
where $q_i$ are pairwise distinct rational primes satisfying $q_i\equiv1(\operatorname{mod} 3)$ for $i=1,2,\dots,n$. And the discriminant of $K_3$ is $d_3=f_3^2$.

\section{Examples}
In this section, we would propose some examples on prime decomposition and computing class number.

\subsection{An Example for Prime Decomposition}
\begin{example}
Consider $K=\mathbb{Q}(\theta)$, where $\theta$ is a root of $f(x)=x^3-93x-124$, it's easy to compute the discriminant of it is $e^2=31^2=961$, and $v=2$. Hence, we have $p=31$ is ramified totally in $O_K$, while the other special prime is $p=2$, since $2\mid v$. Consider $f(x)\equiv x(1+x)^2 \mod 2$, hence $p=2$ is splits completely in $O_K$. Other prime numbers can be determined by the Kummer's theorem \ref{thm:kummer}. Note that for $p=2$, this decomposition in $\mathbb{F}_2$ has no meaning in Dedekind's criterion \ref{thm:Dedekindcri}.
\end{example}

\subsection{Some Examples for computing class group}
First of all, we consider the class group of the the number field $K=\mathbb{\theta}$, where $\theta$ is a root of $f(x)=x^3-3x+1$, since the discriminant of the polynomial is $81=9^2$, hence $K$ is a cyclic cubic field. From Theorem \ref{thm:cbfintegralnor}, we get the integral basis of the field is $(1,\theta,\sigma(\theta))=(1,\theta,\theta^2-2)=(1,\theta,\theta^2)$, i.e. it has a power integral basis, $O_K=\mathbb{Z}[\theta]$. The discriminant of the field is $d(K)=(9)^2=81$, then from the definition of Minkowski's bound, we have $C_K=\frac{2}{9}|81|^{1/2}=2$, hence $Cl(K)=\langle[\wp]|\wp|2\rangle$.
Now we consider the decomposition of 2, for $p=2$, $f(x)\equiv x^3+x+1 (\operatorname{mod} 2)$ is an irreducible polynomial, i.e. $2$ is inert in $K$. Hence $Cl(K)=\{1\}$, and $h(K)=1$.

Then we see another example, the number field $K=\mathbb{Q}(\theta)$ with $\theta$ is a root of $f(x)=x^3-x^2-4x-1$. This is a standard form of cyclic cubic field with the secdond case of Theorem \ref{thm:ccpoly}, we yield that $e=13,u=5,v=1$ for this case. Hence, the discriminant of the field is $13^2=169$, with $v=[O_K:\mathbb{Z}[\theta]]=1$, hence for any case, we can use theorem \ref{thm:kummer}, since $K$ is monogenic with integral basis $(1,\theta,\theta^2)$. From the definition of Minkowski's bound, we have $C_K=\frac{2}{9}|169|^{1/2}=2.889<3$, hence just consider $p=2$. Since $f(x)\equiv x^3+x^2+1 (\operatorname{mod} 2)$ is irreducible, i.e. we have $2$ is inert in $K$. Hence $Cl(K)=\{1\}$, and $h(K)=1$.

\section{Some Special Cyclic Cubic Fields}\label{sec:ssccf}
In this section, we'd like to share some cyclic cubic fields which have been researched by some mathematicians.
\subsection{Cubic Trinomials}
First, we would like to introduce F.C. Orvay's work \citep{orvay1991cyclic}. Some important results for the structure of cyclic cubic fields with cubic trinomials are listed as followings. For the sake of brevity, we just write down these lemma without proofs. These results can be found in F.C. Orvay's article.

\begin{lemma}
Let $K=\mathbb{Q}(\theta)$, $\operatorname{Irr}(\theta,\mathbb{Q})=x^3-px+p$ \footnote{Note that this is not the standard form of cyclic cubic field, however, it is isomorphisic to $f(x)=x^3-3px-(4p-27)p$.}, $p=3^{\delta}p_1\cdots p_r, p_i\equiv1(\operatorname{mod} 3)$ (distinct), $\delta\in\{0,2\}$, $4p-27\in\mathbb{Z}^2$, then the following hold:
\begin{enumerate}
\item $d(K)=p^2$, $K$ is monogenic\footnote{with power integral basis} with integral basis $\{1,\sigma,\sigma^2\}$.
\item $\{\sigma,\sigma'\}$ is a system of fundamental units of $K$, where $\sigma=(m+\theta_1)/3$, $\sigma'$ denote the conjugate of $\sigma$, $\theta_1=(4p-9\theta-6\theta^2)/\sqrt{4p-27}$ and $m=(\sqrt{4p-27}-3)/2$.
\end{enumerate}
\end{lemma}

This lemma is suitable for $p=9,13,19,37,63,79,97,117,139,163,\cdots$.

\begin{lemma}
Let $K=\mathbb{Q}(\theta)$, $\operatorname{Irr}(\theta,\mathbb{Q})=x^3-px+pq, p=p_1\cdots p_r, p_i\equiv1(\operatorname{mod} 3)$ (distinct),$q>2$, $4p-27q^2=1$, then the following hold:
\begin{enumerate}
\item $d(K)=p^2$, $K$ is monogenic with integral basis $\{1,\theta,\theta^2\}$.
\item $\{\mu,\mu'\}$ is a system of fundamental units of $K$, where $\mu=2+3\sigma+3\tau$, $\sigma=(-1+\theta_1)/3$,$\tau=(\sigma^2+((q+1)/2)\sigma)/q$, $\theta_1=4p-9q\theta-6\theta^2$ and $\mu'=-1-6\sigma+3\tau$.
\item $\operatorname{Irr}(\mu,\mathbb{Q})=x^3-3((1+9q)/2)x^2+((27q-3)/2)x+1$.
\item $\{1,\sigma,\tau\}$ is another integral basis.
\end{enumerate}
\end{lemma}

This lemma is suitable for $p=61,331,547,817,1141,\cdots$.

For the first lemma, on choosing $p$ more precisely , we have found a results as follows:
\begin{theorem}\label{thm:ccuformula}
For any integer $k$, set $p=k^2+k+7$. The polynomial  $X^3-p X+p$ is irreducible over $Q$ and has Galois group $A_3$.
\begin{proof}
For any odd number $p$, $x^3-px+p\equiv x^3+x+1 (\operatorname{mod} 2)$, hence $x^3-px+p$ is irreducible over $\mathbb{Q}$. Its discriminant is $(-4)(-p)^3-27p^2=p^2(4p-27)$. To have a Galois group $A_3$, we need $4p-27\in\mathbb{Z}^2$. Writing $c^2=4p-27$, then we have $p=\frac{1}{4}(c^2+27)$. To make it integral we need $c$ odd, and write $c=2k+1$, then $$p=\frac{1}{4}(4k^2+4k+28)=k^2+k+7.$$ For any $k,k^2+k+7$ is odd so if we defined this expression to be $p$, then $x^3-px+p$ has Galois group $A_3$ over $\mathbb{Q}$.
\end{proof}
\end{theorem}

\subsection{Simplest Cubic Fields}
There is another special class of cyclic cubic fields called the simplest cubic fields first studied by Daniel Shanks \citep{shanks1974simplest}, Shanks computed the discriminant of the polynomial, fundamental units of the field, the regulator and some class number. A recent job for this type of cyclic cubic fields can be find in Lang's article \citep{lang2009properties}.

The simplest cubic field is defined by the following polynomial,
\begin{equation}
f(x)=x^3-ax^2-(a+3)x-1,\label{eqn:simpcubic}
\end{equation} where $a\in\mathbb{Z}$. One can calculate the discriminant from the formula of the discriminant of polynomials (Refer to \ref{prop:disctri}), then $\operatorname{Disc}(f)=(a^2+3a+9)^2$.

D. Shanks only focuses on that $e:=a^2+3a+9$ is a prime, then from theorem \ref{thm:ccpoly}, there is only one cyclic cubic satisfies this polynomial equation up to isomorphism, and $e$ is also discriminant of the field.

What's more, one can verify that if $\theta$ is a root of equation \ref{eqn:simpcubic}, then $\theta'=1/(\theta+1)$ and $\theta''=1/(\theta'+1)$ are also a root of the equation \ref{eqn:simpcubic}.
And since $\theta(\theta^2-a\theta-a-3)=1$, i.e. $\theta$ is a unit, so is $\theta'$, then $1+\theta=-1/\theta'$ is also a unit. In fact, $(\theta,1+\theta)$ are independent fundamental
units, which can be verified by Godwin's criterion \citep{godwin1960determination}. More generally, we have following theorem which could be found in Lang's article \citep{lang2009properties}.
\begin{theorem}
If $e:=a^2+3a+9$ is square-free, then $(1,\theta,\theta^2)$ is an integral basis of $K$, and $(-1,\theta,\theta')$ generates the full group of units $O_K$.
\end{theorem}

A simple result about decomposing prime is that $2$ is inert in $K$, since $O_K=\mathbb{Z}[\theta]$ and $\bar{f}(x)\equiv x^3+x^2+1 (\operatorname{mod} 2)$ when $m$ is odd, while $\bar{f}(x)\equiv x^3+x+1 (\operatorname{mod} 2)$ when $m$ is even.

The explicit solution (a positive root) of equation \ref{eqn:simpcubic} is $$\theta=\frac{1}{2}(2\sqrt{e}\cos\phi+a),$$ where $$\phi=\frac{1}{3}\arctan\frac{\sqrt{27}}{2a+3}$$

As for the class number of them, D. Shanks \citep{shanks1974simplest} finally give a formula to compute them:
\begin{equation}
h=\frac{a^2+3a+9}{4\log^2 a}\left[1-\frac{3}{a\log a}+o(\frac{1}{a^2})\right]\prod_{p=2}^{\infty}f(p).
\end{equation}
where $f(p)$ is defined by
\begin{equation}
f(p)=\left\{\begin{array}{ll} 1& \text{for } p=e,\\ \left(\frac{q}{q-1}\right)^2 & \text{for } p^{(e-1)/3}\equiv 1(\operatorname{mod} p),\\
\frac{q^2}{q^2+q+1} & \text{otherwise}.
\end{array}\right.
\end{equation}

Shanks give a table of class number for $-1\leq a\leq 410$, where $e$ is a prime.