\documentclass[main.tex]{subfiles}
\begin{document}
%%%%%%%%%%%%%%%%%%%%
\section{Algebra}
For algebra, the problem seems to fall into three categories: group theory, rep theory, and ring/Galois theory.

\subsection{Group Theory}
The most important thing here is the Sylow theorems and how they are used. Sylow's theorem is about subgroups of prime orders. The idea is looking at the orbits of the conjugation action of $G$ on $G$.

\begin{definition}
Let $G$ be a finite group of order $p^n m$ where $m$ is coprime to $p$ to $p$. A Sylow $p$-subgroups of $G$ is a subgroup of order $p^n$. They are the maximal $p$-subgroups.
\end{definition}

Here the Sylow theorems:

\begin{theorem}[Sylow's 1st Theorem]
If $p$ is a prime number and $p | |G|$, then there exists a Sylow $p$-subgroup of $G$.
\end{theorem}

\begin{proof}
We find the group by looking at orbits of $G$ on subset of $G$ of size $p^n$, and then finding one $w$ with orbit size coprime to $p$. Then the stabilizer of this is $H$, which as it stabilizes it must act on the elements of the set (very confusing sentence). As it acts on the elements of $w$ freely, $H | |w| = p^n$. On the other hand, $|G|/|H| = orb(w)$ has size coprime to $p$, this means that $|H| = p^n$. (In fact $w = H$ as sets.
\end{proof}

\begin{theorem}[Sylow's 2nd Theorem]
For a given prime $p$, all Sylow $p$-subgroups are conjugate to each other.
\end{theorem}

\begin{corollary}
A Sylow $p$-subgroup of $G$ is unique iff it is normal in $G$. Thus it is unique iff it is abelian.
\end{corollary}

\begin{theorem}[Sylow's 3rd Theorem]
Let the number of Sylow $p$-subgroups to be $n_p$. Then the floowing results hold:
\begin{enumerate}
    \item $n_p = 1\ mod\ p$
    \item If $|G| = p^n m$ so that $m$ and $p$ are coprime, then $n_p | m$
    \item If $P$ is any Sylow $p$-subgroup of $G$, then $n_p = [G: N(P)]$, where $N(P)$ is the normalizer of $P$ in $G$
\end{enumerate}

\end{theorem}
\begin{remark}
part 2 and 3 of Sylow's 3rd theorem follows direct from  the facts that $G$ acts on the set of Sylow $p$-groups by conjugation, Sylow's 2nd theorem says that the action is transitive, and the stabilizer of this action at $P$ is exactly $N(P)$.
\end{remark}
\begin{corollary}
Let $G$ be a fintie group and $p$ a prime number. If $p^n$ divides the order of $G$, then $G$ has a subgroup of order $p^n$.
\end{corollary}

We also have the Cauchy's theorem:

\begin{theorem}[Cauchy's theorem]
If prime $q$ divides $|G|$, then there exists an element of order $q$.
\end{theorem}

Let $G$ acts on $G$ by conjugation, then the orbits are conjugacy classes.
Then the class equations says that $|G| = |Z(G)| + k_1 + k_2 ..$, where $|Z(G)|$ is the center of $G$ (those that commutes with all elements those belong to a single orbit), and $k_1$ are the size of distinct non-singlet orbits.

\subsubsection{Groups of order $p^2$}
Groups of order $p$ are isomorphic to $\mathbb{Z}/p\mathbb{Z}$, namely abelian. Similar thing is true for groups of order $p^2$, they are all abelian, so either $\mathbb{Z}/p\mathbb{Z} \sum \mathbb{Z}/p\mathbb{Z}$ or $\mathbb{Z}/p^2$

\subsubsection{Groups of order $p^3$}
There are ofc abelian once $3, (2,1), (1,1,1)$, and there are two non-isomorphic nonabelian.

\subsubsection{Groups of order $pq$}
This uses semidirect products:
\begin{definition}
Given $N, K$ groups and an action $K$ on $N$ ($K \rightarrow Aut(N)$), then the semidirect product of $N$ and $K$ $N \rtimes K$ as set is $N \times K$, with multiplication:
$$
(a_1, b_1) (a_2, b_2) \coloneqq (a_1 (b_1 \dot a_2), b_1 b_2)
$$
\end{definition}

We have inclusion $K \rightarrow N \rtimes K$ and projection $N \rtimes K \rightarrow K$. Conversely,
Splitting of groups gives action of $N$ on the kernel of the projection, and exhibits the total group to be the semidirect sum.

\begin{proposition}
Let $p \geq q$, if $q \nmid (p-1)$ then there are only one iso class of groups of order $pq$, namely the abelian group $\mathbb{Z}/pq\mathbb{Z}$. If $q | (p-1)$, then there are two groups of order $pq$:
\begin{enumerate}
    \item The abelian one: $\mathbb{Z}/pq\mathbb{Z}$
    \item The nonabelian one given by any non-trivial
    $$
    \phi: \mathbb{Z}/q\mathbb{Z} \rightarrow Aut(\mathbb{Z}/p\mathbb{Z}) \cong \mathbb{Z}/(p-1)\mathbb{Z}
    $$
\end{enumerate}
\end{proposition}

\begin{corollary}
For any odd prime $p$ there are two non-isomorphic groups of order $2p$:
\begin{enumerate}
    \item The cyclic group $\mathbb{Z}/2p\mathbb{Z}$
    \item The dihedral group $D_p = \mathbb{Z}/p\mathbb{Z} \rtimes \mathbb{Z}/2\mathbb{Z}$ with the sign action.
\end{enumerate}
\end{corollary}

\subsubsection{Dihedral Groups}

This leads us right into the dihedral group $D_n$.
\begin{definition}

For any $n \geq 1$, we have the Dihedral group
$$
D_n \coloneqq <r, s| r^n = 1, s^2 = 1, s r s = r^{-1} >
$$
This is the group of symmetry of the regular $n$ polygon, with $r$ being the a mininum rotation and $s$ being a reflection.

The group of rotation is normal, and all reflections are conjugate when $n$ is odd and there are two conjugacy classes when $n$ is even (easy to see there are two different kinds of reflections)
\end{definition}

\subsubsection{$GL_n(\mathbb{F}_p)$}
The size of finite group $GL_n(\mathbb{F}_p)$ is
$$
(p^n -1) (p^n - p) ...
$$
as this is number of choosing a nonzero vector, then choosing another vector away from the first one (the size of a $\mathbb{F}_p$ line is $p$)...

\subsection{Representation Theory}
This concerns $\mathbb{C}$-linear representation theory of finite groups, via the character theory.

\subsubsection{Basics}
Let $G$ be a finite group.
The category of (complex) finite dimensional representation $Rep(G)$ is quite simple, literally, it is a simple category:

\begin{theorem}[Maschke's Theorem]

Any short exact sequences of representations splits, and irreducibles are simples.

\end{theorem}

One can show this by the following proposition:
\begin{proposition}
For any $G$-rep $V$ there is a $G$-equivariant Hermitian structure on $V$.
\end{proposition}
This is done by choosing any hermitian structure and then add its $G$-orbits.

The maps between irreducible representations are also simple:

\begin{theorem} [Schur's Lemma]
let $V$ and $W$ be irreducible representations, and $f : V \rightarrow W$, then $f$ is either an isomorphism or 0. Moreover, endormorphism of a irreducible representation $V$ is scalar multiplication by $\mathbb{C}$.
\end{theorem}

\begin{proof}
As $V$ and $W$ are irreducible, then the kernel of $f$ is either $V$ or 0, similiarly, the cokernel is then $0$ or $W$.

As for the second part, given $f : V \rightarrow V$, then it must have one eigenvector $v$ with eigenvalue $\lambda$ (this is why we are in $\mathbb{C}$ and not in say $\mathbb{R}$, think rotation), then $f - \lambda Id$ has a nonzero kernel, thus it is $V$. So $f = \lambda Id$.
\end{proof}

The most important representation is the regular representation, that is, $G$ act on $\mathbb{C}[G]$ by left translation.

Here's the decomposition theorem, which we can easily prove using character theory:
\begin{theorem}
There are finitely many non-isomorphic irreducible representations, in fact there are the number of conjugacy classes of $G$ many. Moreover:
$$
\mathbb{C}[G] = \bigoplus_i V_i ^{dim V_i}
$$
where $V_i$ are the distinct irreducible representations.

\end{theorem}

Next we need the character theory:
\subsubsection{Character Theory}
This is the crux of the theory of finite dimensional reps. First we define characters:

\begin{definition}
Let $\rho$ be a $G$ rep on $V$. Then the character associated to $\rho$ is a complex-valued map on the set $\frac{G}{G}$ of conjugacy classes of $G$:
$$
\chi_V(g) \coloneqq tr(\rho(g))
$$
\end{definition}
Note that $\chi_V(1) = dim V$. It turns out they encode all the info about a rep $V$.

As $tr$ is conjugate-invariant, this is well-defined on conjugacy classes. A complex-valued map on $\frac{G}{G}$ is called a class function on $G$.

There is an inner product on class functions:
$$
(f_1, f_2) \coloneqq \frac{1}{|G|}\sum_{g \in G} f_1(g) \overline{f_2(g)}
$$

It turns out the characters of irreducible representations are orthogonal to this decomposition:

\begin{lemma}
Let $V$ and $V'$ be irreducible representations, if $V \cong V'$, then
$$
(\chi_V, \chi_{V'}) = \delta_{V, V'}
$$

\end{lemma}

We also have another orthogonal condition:
\begin{lemma}
Given $g, h$,
$$
\frac{1}{|G|} \sum_{V_i}\chi_{V_i}(g) \overline{\chi_{V_i}(h)} = \delta_{[g], [h]}
$$
\end{lemma}

Moreover, we have the delta functions $\delta_{[g]}$ on conjugacy classes, then we have
$$
(\delta_{[g]}, \delta_{[h]}) = \delta_{g,h}
$$
and $\chi_{V_i}(g) = (\chi, g)$ tells us that $\chi_{V_i}$ forms an orthonormal basis for the space of class functions!!!

This, for example, tells us that there are $|\frac{G}{G}|$ many irreducible representations.

This also means that we can easily compute the irreducibles in a rep $V$: $(\chi_V, \chi_{V_i})$ is the number of $V_i$ in $V$.

Given a finite group $G$, we can write down a table, with columns indexed by conjugacy classes of $G$ and rows indexed by irreducible representations. The valued at $(i,j)$ is $\chi_{V_i}(g_j)$. The orthogonal condition exists for both rows and columns (for rows need to multiply by the size of the conjugacy class). This can be used to find the characters of the irreducible reps.

\subsection{Galois Theory}

Galois theory is very similar to covering space theory, however in this case the (absolute) Galois group is profinite, so a bit harder to understand.

\subsubsection{Normality}

Let $F$ be a field. We will consider finite field (algebraic) extensions over $k$. Examples of them are  $F[x]/f(x)$ where $f$ is an irreducible polynomial over $k$.
\begin{remark}
We will assume that we have an algebriac closure $\overline{F}$ over $F$. Note that this choice is not canonical and it is like choosing a universal cover together with a base-point, equivalently, choosing a point of $BG$, where $BG$ is viewed as a non-based space. Making a choice will trivialize a lot of other things. This probably will not play a big factor in the quals but it is something really important to keep in mind.
\end{remark}

Given an algebraic field extension $K/F$ and $k \in K$, then there exists an unique monic minimal polynomial $f \in F[x]$ such that $f(k) = 0$ and all other polynomial that does has $f$ as a factor (hence minimality). This is because we have a map $F[x] \rightarrow K$ sending $x \mapsto k$. Since the extension if algebraic, this has a nonzero ideal as a kernel, as $F[x]$ is a $PID$, this is generated by some monic polynomial $f$.

Here's the notion of normality:
\begin{definition}
Let $K/F$ be a finite extension, then it is normal if for every $k \in K$, the minimal polynomial $f_k(x) \in F[x]$ of $k$ splits completely over $K$, that is, we can find all the roots of $f_k$ in $K$. Equivalently, it is normal if for every irreducible $f \in F[x]$ which has a root in $K$, then it splits completely over $K$.
\end{definition}

Here's a criterion for normality:
\begin{lemma}
Let $f \in F[x]$ be an irreducible polynomial, the field extension $K \coloneqq  F[x]/f(x)\ /F $ is normal iff it contains all the roots of $f$ ($f$ splits completely).
\end{lemma}

Here's some other equivalent notion for normality:
\begin{enumerate}
    \item All embeddings $K \xhookrightarrow{} \overline{F}$
    has the same image
    \item The automorphism group $Aut_F(K)$ acts transitively on the set of homomorphisms $K \xhookrightarrow{} \overline{F}$.
\end{enumerate}

Given an extension $K/F$, easy to see that there is a normal closure $N(K)/F$, where $N(K)$ is the mininal normal extension of including $K$ over $F$. It is generated by all the other roots of the minimal polynomial of elements of $K$.

Given $f \in F[x]$ not necessarily irreducible, we have the splitting field of $F$ which is the smallest normal extension that splits $f$ completely.

\begin{example}
Examples of normal extensions are cyclotomic extensions ($\mathbb{Q}[\zeta_i]$ where $\zeta_i$ is a primitive $i$-th root of unity. Equivalently, it is the splitting field of $x^n -1$ in $\mathbb{Q}$.)

Another one is $\mathbb{Q}[x]/(x^2 - 2)$, aka adjointing $\sqrt{2}$. In fact, any degree 2 extensions are normal.

An example of a non-normal extension is $\mathbb{Q}[\sqrt{2}^3]$, because this is contained in $\mathbb{R}$ (really an embedding of this into $\mathbb{C}$), but the other two are complex.
\end{example}

\subsubsection{Separability and Discriminants}

Given a polynomials $f$ and $g$, we can ask how to determine if they have a common factor base on their coefficients (common root in some extension). And the answer is that in that case $f, xf, ..., x^n f, g, ..., x^m g$ are linear dependent, thus the determinant of the matrix associated to this vanishes, it is product of $(\lamda_i - \mu_j)$ for $\lambda, \mu$ roots of $f$ and $g$.

To ask if $f$ has repeated roots, it is equivalent to ask if $f$ and $f'$ has common factors, the resultant of $f$ and $f'$ is called the discrimants, with the formula
$$
Disc_(f) = (-1)^{n(n-1)/2}\prod(r_i - r_j)
$$
it is invariant under galois group thus it is a polynomial in the coefficients. It is a degree $2(n-1)$ polynomial on coefficients of $f$. THIS IS SUPER IMPORTANT!!!!
We also have the notion of separable:

\begin{definition}
A polynomial $f \in F[x]$ is separable if it has no repeated roots (in $\overline{F}$).
An extension $K/F$ is separable if any minimal polynomial of an element of $K$ is separable.

An extension $K/F$ is purely-nonseperable if any minimal polynomial of an element of $K - F$ is non-separable.
\end{definition}

We have criterion for a polynomial to be separable:
\begin{lemma}
The following condition is equivalent:
\begin{enumerate}
    \item $f$ is separable
    \item $(f, f') = 1$, where $f'$ is the derivative of $f$.
    \item The discriminant of $f$ is 0, where discriminant is a homogeneous degree $2n-2$ polynomial in coefficients of $f$. It is something like $\prod_{i \neq j} (r_i - r_j)$, where $r_i, r_j$ are the roots of $f$.
\end{enumerate}
\end{lemma}

Here's an equivalent definition for seperable extension:

\begin{lemma}
An extension is separable iff there are exactly $[K:F]$ embedding from $K$ in $\overline{F}$ (or the normal closure of $F$.
\end{lemma}

Here's discriminant in low dimensions: in degree 2, the discriminant of $f = ax^2 + bx + c$ is $b^2 - 4ac$. In degree 3, the discriminant of $f = x^3 + px + q$ is $-4 p^3 - 27 q^2$ (note that this is not degree 4 polynomial as there are missing coefficients of $x^3$, which is set to 1.

For an irreducible polynomial $f$ to be nonseparable, we must have $f' = 0$. This can happen iff we are in char $p$ and $f$ is have entirely $x^{np}$ coefficients.

\begin{example}
All char $0$ irreducible polynomials are separable.

All char 0 field extensions and finite field extensions are separable. For a char $p$ field, any purely-nonseparable extensions are coming from $X^{p^n} - a$ for $a \in F$.
Typical example is to take $F = \mathbb{F}_p (t)$ and $K = \mathbb{F}_p (t^{\frac{1}{p}})$
\end{example}

\begin{definition}
A field $F$ is called perfect if $\overline{F}/F$ is separable.
\end{definition}

Examples are char 0 fields and finite fields.

\subsubsection{Galois theory}
We first start with the definition of a Galois extension:

\begin{definition}
A field extension $K/F$ is Galois iff it is normal and separable. In this case, the Galois group $Gal(K/F)$ is defined as $Aut_K(F)$.
\end{definition}

Here's where the Galois group comes in:
\begin{lemma}
$|Gal(K/F)| = [K: F]$.
\end{lemma}

\begin{proof}
By normality, the Galois group acts transitively on the set of embedding of $K$ into $\overline{F}$. One can show that the action if also free. Separability implies the size of the set of embedding of $K$ into $\overline{F}$ is $[K:F]$.
\end{proof}

Normality extension composes, and we also have the following lemma:
\begin{lemma}
If we have $E/K/F$, and $E/F$ is normal (separable, Galois), then so is $E/K$.
\end{lemma}

Given a Galois extension $E/F$, we have the associated group $G = Gal(E/F)$. We have the following construction:

For any intermediate field extension $E/K/F$, then we have the associated group $Gal(E/K) \subset G = Gal(E/F)$. Conversely, given a subgroup $H$, then we can construct the subfield $E^H$ of the fixed points of $E$ under the $H$ action.

Easily to see that $Gal(E/E^H) = H$. and $E^{Gal(E/K} = K$. Thus we have the following:

\begin{theorem}[Fundamental theorem of Galois Theory]
There exists an equivalence of category between the poset of intermediate extensions between $E/F$ and the poset of subgroup of $G = Gal(E/F)$.
\end{theorem}

\begin{remark}
This is completely analogous to the covering space with a base point situation.
\end{remark}

However, as with covering space, it is more interesting to think about extensions of $F$ not necessarily with an embedding, but in this case it gets a bit harder (there are profinite things for examples). Nevertheless we still have that $Aut (K/F) = N(Gal (E/K))/Gal (E/K)$. $N$ is the normalizer of $Gal(E/K)$ in $Gal(E/F)$. This means that if $K/F$ is Galois, then we have $Gal (K/F) = Gal(E/F) / Gal(E/K)$

\todo[inline]{Review the basics of field extensions and Galois theory, discriminants. How to know if a Galois extension is in $A_n$ etc. Examples of basic construction of Galois extensions that are like $\mathbb{Z}/2\mathbb{Z} \times \mathbb{Z}/2 \mathbb{Z}$ etc.}

\subsubsection{Galois theory of Cyclotomic Extensions}
The $n$-th cyclotomic field is the splitting field of $x^n-1$ over $\mathbb{Q}$. Note that $x^n -1$ is ofc not irreducible. It breaks into cyclotomic polynomials:
$\Phi_n = \prod_{i} (x - \zeta_i)$ where $\zeta_i$ are the primitive $n$-th roots (there are $\phi(n)$ of them, where $\phi$ is ofc the Euler function). They are actually integer valued polynomials. We have that
$$
x^n - 1 = \prod_{d | n} \Phi_d
$$

Thus we see that the $\mathbb{Q}[\zeta]$, where $\zeta$ is a primitive $n$-th root of unity,  is a degree $\phi(n)$ extension over $\mathbb{Q}$. Easy to see that this is the splitting field of $x^n -1$ as all other roots are powers of $\zeta$. The Galois group is $(\mathbb{Z}/n\mathbb{Z})^\times \cong \mathbb{Z}/\phi(n)\mathbb{Z}$, acting on $\zeta$ as $\zeta \mapsto \zeta^i$ for $i$ coprime to $n$. Ofc this determined where all other powers of $\zeta$ goes to.

\subsubsection{Primitive Element and Normal Basis Theorems}

Here's two nice theorems:
\begin{theorem}[Primitive element theorem]
For any separable field extension $K/F$, there exists an element of $k \in K$ such that $K = F(k)$.
\end{theorem}

\begin{remark}
The counterexample is the degree $p^2$ extension $\mathbb{F}_p(U^\frac{1}{p}, T^\frac{1}{p})$ over $\mathbb{F}_p(U,T)$, any rational polynomial on $U^\frac{1}{p}, T^\frac{1}{p}$ has $p$-th power in $\mathbb{F}_p(U,T)$.
\end{remark}

Here's the normal basis theorem:
\begin{theorem}[Normal basis theorem]
For any Galois extension $K/F$ with Galois group $G$, there exists an element $\sigma$ such that $G \sigma$ spans $K$ over $F$. Equivalently, we have $F[G] \cong K$ as left $F[G]$ modules.
\end{theorem}

\begin{remark}
Of course when the extension is not normal this is not true, as the size of the automorphism group is smaller the $[K:F]$.
\end{remark}

\subsubsection{Galois Theory of Finite Fields}

The theory of finite field extensions are easy: fix a characteristic $p \neq 0$. Then all finite extensions of char $p$ finite fields are Galois, for any $n > 0$, there is an unique finite field of size $p^n$ (degree $n$ extension of $\mathbb{F}_p$). All the Galois groups are cyclic and generated by the Frobenius. Basically it is as easy as it gets.

Fix a prime $p$. Given a finite field $K$ of size $p^n$, then it is a degree $n$ extension of $\mathbb{F}_p$. They are isomorphic to the splitting field of $x^{p^n} - x$:

\begin{lemma}
$K^\times$ is cyclic, thus $K^\times \cong \mathbb{Z}/(p^n - 1)\mathbb{Z} $
\end{lemma}

\begin{proof}
Consider the group of units $K^\times$, it is a group of size $p^n -1$. By Lagrange theorem, we have that for any $x \in K^\times$, $x^{p^n -1} = 1$. As there are only at most $p^m-1$ elements with order $p^m-1$, as $x^{p^m -1}$ has only maximally $p^m -1$ unique roots. The only abelian group is cyclic.
\end{proof}

\begin{lemma}
Any finite field $K$ of size $p^n$ a splitting field of $x^{p^n} -x$:
\end{lemma}

\begin{proof}
By above, we see that $x^{p^n} -x$ splits completely over $K$. Note that $x^{p^n} -x$ is separable and has $p^n$ distinct roots. Thus $K$ is the splitting field.
\end{proof}

This also implies that extensions of finite fields are normal and separable, thus Galois.

A field $K$ of order $p^n$ contains a field of order $p^m$ iff $m | n$.

Now we need to find the Galois group. Recall that for a ring $R$ over $\mathbb{F}_p$, there is a Frobenius morphism: $F : R \rightarrow R$, $x \mapsto x^p$.

\begin{theorem}
Let $K$ be a field of order $p^n$, then $Gal(K/\mathbb{F}_p) \cong \mathbb{Z}/n\mathbb{Z}$ is cyclic with generator the Frobenius morphism $F$.
\end{theorem}

\begin{proof}
Note that $F$ fixes. It is a isomorphism for $K$ as it is injective. As before, since $x^{p^n} = x$ is true for any element of $K$ we see that $F^n = Id$ on $K$. As $[K : \mathbb{F}_p] = n$, this implies the statement.
\end{proof}

\begin{corollary}
Let $F$ be a field of order $p^m$ and $K/F$ is a degree $n$ extension. Then $Gal(K/F) \cong \mathbb{Z}/n\mathbb{Z}$ with generator $F^m$.
\end{corollary}

\subsubsection{Examples of Galois Extensions with a given Galois Group}

\todo[inline]{We will see how important this section is. Like a $Z2 \times Z2$, $A_3, S_3,$, $D_n$, etc.}

\subsection{Ring Theory and Algebraic Number Theory}

We will first start with some (commutative) ring theory. There are a bunch of property a ring can satisfy: integral domain, integrally closed, UFD, PID... All rings are commutative.

\begin{definition}
A ring $R$ is an integral domain if it has no zero-divisor, that is, if $xy = 0$ then either $x = 0$ or $y = 0$.
\end{definition}

Geometrically they corresponds to irreducible schemes.

\begin{remark}
Given an integral domain $R$, we can localize at all nonzero element and get a field $K(R)$, called the field of fractions. $R$ injects into $K(R)$.
\end{remark}

\begin{definition}
Given an injective ring homomorphism $R \xhookrightarrow{} S$, an element $s \in S$ is integral over $R$ if the map $R[x] \rightarrow S$ is not injective, that is, there is a polynomial $f(x)$ with coefficients $R$ such that $f(s) = 0$. The subset of integral elements of $S$ forms a ring, called the integral closure of $R$ in $S$.
\end{definition}

Given the injection $R \xhookrightarrow{} K(R)$, we have $N(R)$ the integral closure of $R$.

\begin{definition}
A ring $R$ is integrally closed iff it is its integral closure.
\end{definition}

Given an integral domain $R$, we can ask if factorization is unique:

\begin{definition}
A domain $R$ is a uniquely factorizatable domain (UFD) if any two factorization of an element of $R$ is unique up to unit.
\end{definition}

\begin{lemma}
Any UFD is integrally closed, the proof is the same argument as $\mathbb{Z}$ is integrally closed in $\mathbb{Q}$.
\end{lemma}

\begin{example}
If $R$ is a UFD (like a field), then so is $R[x]$ (they are not PID tho, think $(2, x)$ in $\mathbb{Z}[x]$.)

To find an integrally closed ring that is not UFD, we go to one dimesion, where integrally closed Krull dimension 1 domains are called Dedekind domains. They are UFD iff PID. The ring $\mathbb{Z}[\sqrt{-5}]$ is not UFD as
$$
(1 + \sqrt{-5}) (1 - \sqrt{-5}) = 2 \times 3
$$
In fact, most ring of integers of number fields (are Dedekind domains) but are not UFD (or PID).
\end{example}

We can also ask if any ideals are principle (generated by one element):

\begin{definition}
A domain $R$ is a principal ideal domain (PID) iff all ideals are principal.
\end{definition}

\begin{remark}
All PID are UFD, but not the inverse. Example: $\mathbb{Z}[x]$ above is UFD but not PID ($(2, x)$).
\end{remark}

\begin{example}
The Gaussian integer $\mathbb{Z}[i]$ is a PID. Factorization is by the Euclidean algorithm with respect to the norm $|a + bi|^2 = a^2 + b^2$. For an Gaussian integer $a + bi$, then its factors are elements of prime norms. So find the primes of $|a + bi|$ and use see which of the factors of these primes divides $a + bi$.
\end{example}

\subsubsection{The Ramification Theory of Number Fields}

Let $R$ be a Dedekind domain, that is, a Krull dim 1 integrally closed domain. Given a finite extension of $K$ over $F = K(R)$ , then let $R_K$ be the integral closure of $R$ over $K$. It is also a Dedekind domain.

\begin{remark}
The setting that we are interested in is when $R = \mathbb{Z}$, then the integral closure is written as $\mathcal{O}_K$, called the ring of integer.
\end{remark}

\begin{lemma}
In a Dedekind domain, ideals uniquely factorizes into prime ideals.
\end{lemma}

\begin{remark}
There is this whole theory about fractional ideals (line bundles over the curve) and class group (the Picard group of the curve). A Dedekind domain is UFD (which in this case implies PID) iff its class group is zero.
\end{remark}

Geometrically, $Spec \mathcal{O}_K$ is the "smooth curve" with generic point corresponding to $K$.

 Geometrically, Dedekind domains are one dimensional curves. We can study $R_K$ by looking at the fibers over points of $R$, aka primes ideals. Algebraically, given a prime ideal $\mathfrak{q}$ of $R$, we study the quotient ring $R_K/\mathfrak{q}R_K$. This is a finite extension ring of $R/\mathfrak{q}$, of a constant rank $[K: \mathbb{Q}]$.

The fibers over each prime $p$ is a disjoint union of points, each one possibly non-reduced (ramifies) and have degree larger than $1$ over $p$.

Algebraically, this means that the prime $\mathfrak{q}R_K$ factorizes as a product of primes, each one $\mathfrak{p}_i$ may appear with multiplicities $ > 1$  and $R_K/\mathfrak{q}R_K$ might be a nontrivial field extension over $k$. The multiplicities is called the ramification index $e_i$, and the field extension degree $[R/\mathfrak{p}: R/\mathfrak{q}] $ is called the called the inertial degree (residue degree) $f_i$. Note that $\sum_i e_i f_i = [K : F = K(R)]$, where we summing over all primes over $p$. All of these works in general ground of an (injective) map of Dedekind domains and splitting of primes.

\begin{example}
Take $R = \mathbb{Z}$, $F = \mathbb{Q}$, $K = \mathbb{Q}[i]$ and $\mathcal{O}_K = \mathbb{Z}[i]$, then $(2) = (1+i)^2$ (this is because $1-i = -i (1 + i)$, $(5) = (2 + i) (2 -i)$, and $(7) = (7)$. So we see that $(2)$ ramifies, $(5)$ stays splits and $(7)$ is inert. As $[K = \mathbb{Q}[i], \mathbb{Q}]$ is a degree 2 extension, these are the only three behaviors.
\end{example}

When the extension $[K: F]$ is Galois, then the situation is even better. Namely we can study how the Galois group acts. Note that the Galois group restricts to an action on $R_K$ fixing $R$. Thus it acts on the prime ideals lying over $\mathfrak{q}$. This action is transitive, and thus the ramification and inertial index are all the same. If there are $g$ distinct primes, we see that $[K:F] = efg$. Fix a prime $\mathfrak{p}$ over $\mathfrak{q}$, then the decomposition group $D_\mathfrak{p}$ is the subgroup of $G = Gal(K/F)$ that fixes $\mathfrak{p}$. Therefore $|D_\mathfrak{p}| = ef$. There is an induced map $D_\mathfrak{p} \rightarrow Gal(K/\mathfrak{p}/F/\mathfrak{q})$, and this is surjective with kernel $I_\mathfrak{p}$, the inertial group. This group has size $e$. This is the general ramification theory of Galois extensions.

\subsubsection{Quadratic Extensions}
Let $d$ be a square-free integer, then we have the ring $\mathbb{Z}[\sqrt{d}]$. One natural question to ask is is $\mathbb{Z}[\sqrt{d}]$ integrally closed? Equivalently, is it the ring of integers in $\mathbb{Q}[\sqrt{d}]$. The answer is not always:

\begin{theorem}
If $d = 2,3 mod 4$ then $\mathbb{Z}[\sqrt{d}]$ is the ring of integer. if $d = 1 mod 4$, then $\mathbb{Z}[(1 + \sqrt{d})/2]$ is the ring of integer.
\end{theorem}

\begin{example}
So $\mathbb{Z}[i], \mathbb{Z}[\sqrt{2}]$
\end{example}

\subsection{Linear Algebra}

Given a finite dimensional vector space $V$ over a field $k$ and $T: V \rightarrow T$, then we want to understand how to decompose $T$. The idea is simple: use algebraic geometry: consider $T$ as $x$ in $k[x]$, then we can view $V$ as a coherent sheave over $\mathbb{A}^1 = spec k[x]$. Being finite dimensional, $V$ is supported at finite points. It is supported on the closed sub-scheme cut out by a polynomial $f$ on $k[x]$. This $f$ is the mininal polynomial on $x$ such that $f(T) = 0$. This is called the minimal polynomial of $T$:

\begin{definition}
The minimal polynomial $f$ of $T$ is the unique lowest degree polynomial in $T$ such that $f(T) = 0$.
\end{definition}

On the other hand, we also have the characteristic polynomial, which is a degree $n$ polynomial in T:
\begin{definition}
$char(x) coloneqq det (xId - T)$ is called the characteristic polynomial in T
\end{definition}

It's $x^{n-1}$ coefficient is $-tr(T)$ and the $x^0$ coefficient is $(-1)^{n-1} \ det \ T$.

The Cayley-Hamilton theorem says that
\begin{theorem}[Cayley-Hamilton]
$char(T) = 0$
\end{theorem}
Thus the mininal polynomial factors the characteristic polynomial.

In fact, using the classification theory of finitely generated modules over a PID (in this case $k[x]$), we can do more:

Using the invariant factor decomposition, we see that $V \cong k[x]/(f_1) \oplus k[x]/(f_2) .. \oplus k[x]/(f_n)$ with $f_1 | f_2 | ... | f_n$. $f_n$ in this case will be the minimal polynomial.

In linear algebra, this means that we can find direct summands $V_i$ for $V$ such that $T$ sends $V_i$ to $V_i$ ($T$ looks block diagonal).For each $V_i$, we have basis for the $T$ on all but last basis is off diagonal 1: just think about how $x$ acts on $k[x]/(f(x))$ with basis $1, x, x^2, ...$. This is the rational canonical form. The minimal polynomial of $T|V_i$ is ofc $f_i$, equaling the characteristic polynomial of $T|V_i$ (just by degree reasons). Note that the first basis vector $v$ has $v, T\ v, T^2 v $ spans $V_i$.

This off diagonal form is called the rational canonical form. Note that this exists for any field $k$.

Now if $k$ is algebraically closed, then we know that we can factor each $f$ to $(x-a_1)^{e_1} (x - a_2)^{e_2}...$,

So we have the case now $T$ has characteristic polynomial (equals minimal polynomial) is $(x-a)^n$. This means that $T ' = T - a Id$ has characteristic polynomial $x^n$. There is a basis here $x^{n-1} = (T')^{n-1} 1,... x = T' 1, 1$, in this basis, $x^{n-1}$ is the eigenvector for $T'$ with eigenvalue $0$, thus it is an eigenvector for $T$ with eigenvalue $a$. Moreoever, the $i$-th basis vector gets annihilated by $(T')^i$ (this is all theory for nilpotent matricies). Thus we see that in this basis, $T'$ can be written as diagonal $0$, one up than diagonal $1$. Therefore $T$ can be written as diagonal $a$, one up that diagonal $1$.

For a more general $T$, then we see that we can find a basis with blocks looking like such above. This is called the Jordan normal form of $T$.

\begin{remark}
Note that this is true for any matrix whose characteristic polynomial factors into linear polynomials. Ofc this is true for any matrix over algebraically closed fields.
\end{remark}

\end{document}


\documentclass{article}

\usepackage[png,comments]{mgltex}
\usepackage{hyperref}

\title{\mglTeX*{} usage sample}
\author{Diego Sejas Viscarra \and Alexey Balakin}
\date{\today}

\mglsettings{
	dir=MGL/,
	scriptsdir=scripts/,
	graphicsdir=graphics/,
	backupsdir=backups/
}

\begin{mglsetupscript}
	define gravity 9.81 # [m/s^2]
\end{mglsetupscript}

\begin{document}

	\maketitle

	\begin{abstract}
		\noindent \mglTeX{} is a \LaTeX{} package that allows the creation of graphics directly from MGL scripts of the MathGL library (by Alexey Balakin) inside documents. The MGL code is extracted, executed (if shell escape is activated), and the resulting graphics are automatically included.

		This document is intended as a sample of the capabilities of \mglTeX{}, as well as a brief introduction to the package, for those who want to start right away to use it, without diving into the a little bit more technical documentation.
	\end{abstract}

	\section{Basics on environments}
	\begin{description}
		\item[mgl] The easiest way to embed MGL code is the \verb|mgl| environment. It extracts its contents to a main script associated to the document.\footnote{Generally, the main script has the same name as the document being compiled. In order to rename it or create a new one, the \texttt{\textbackslash mglname} command can be used.} If shell escape is activated, \LaTeX{} will take care of calling \verb|mglconv| (the MathGL compiler) with the appropriate settings, and the resulting image will be automatically included.

		For example, you could write:
		\begin{verbatim}
			\begin{figure}[!ht]
			  \centering
			  \begin{mgl}[width=0.85\textwidth,height=6cm]
			    call 'prepare1d'
			    subplot 2 1 0 '<_' : title 'Standard data plot'
			    box : axis : grid 'xy' ';k'
			    plot y ’rGb’

			    subplot 2 1 1 '<_' : title 'Region plot'
				  ranges -1 1 -1 1 : origin 0 0
				  new y1 200 'x^3-x' : new y2 200 'x'
				  axis : grid 'xy' 'W'
				  region y1 y2 'ry'
				  plot y1 '2k' : plot y2 '2k'
				  text -0.75 -0.35 '\i{A}_1' 'k' : text 0.75 0.25 '\i{A}_2' 'k'
			  \end{mgl}
			  \caption{A simple plot create by \mglTeX's \texttt{mgl} environment}
			\end{figure}
		\end{verbatim}
		This will produce the following image:
		\begin{figure}[!ht]
			\centering
			\begin{mgl}[width=0.85\textwidth,height=5.5cm]
				call 'prepare1d'
				subplot 2 1 0 '<_' : title 'Standard data plot'
				box : axis : grid 'xy' ';k'
				plot y '2'

				subplot 2 1 1 '<_' : title 'Region plot'
				ranges -1 1 -1 1 : origin 0 0
				new y1 200 'x^3-x' : new y2 200 'x'
				axis 'AKDTVISO' : grid 'xy' ';W'
				region y1 y2 'ry'
				plot y1 '2k' : plot y2 '2k'
				text -0.75 -0.35 '\i{A}_1' 'k' -2 : text 0.75 0.25 '\i{A}_2' 'k' -2
			\end{mgl}
			\caption{A simple plot create by \mglTeX's \texttt{mgl} environment}
		\end{figure}

		Two important aspects of \mglTeX{} can be noted from this example: First, the \verb|mgl| environment accepts the same optional argument as the \verb|\includegraphics| command from the \verb|graphicx| package. Actually, it also accepts other optional arguments, called \verb|gray| (to activate/deactivate gray-scale mode), \verb|mglscale| (to set the factor for scaling the image file), \verb|quality| (to set the quality of the image), \verb|variant| (to chose the variant of the arguments of MGL commands in the script), \verb|imgext| (to specify the extension of the resulting graphic file), and \verb|label| (to specify a name to save the image). Most of these options are available to every \mglTeX{} environment or command to create graphics.

		The second aspect to be noted about the example is that this script calls a MGL function, \verb|prepare1d|, which hasn't been defined yet. \mglTeX{} provides the \verb|mglfunc| environment for this purpose (see below).

		\item[mglfunc] This environment can be used in any part of the \LaTeX{} document; \mglTeX{} takes care of placing the corresponding code at the end of the main script, as has to be done in the MGL language.

		For example, the function \verb|prepare1d| that is called in the script above is defined like this
		\begin{verbatim}
		  \begin{mglfunc}{prepare1d}
		    new y 50 3
		    modify y '0.7*sin(2*pi*x)+0.5*cos(3*pi*x)+0.2*sin(pi*x)'
		    modify y 'sin(2*pi*x)' 1
		    modify y 'cos(2*pi*x)' 2
		  \end{mglfunc}
		\end{verbatim}
		\begin{mglfunc}{prepare1d}
			new y 50 3
			modify y '0.7*sin(2*pi*x)+0.5*cos(3*pi*x)+0.2*sin(pi*x)'
			modify y 'sin(2*pi*x)' 1
			modify y 'cos(2*pi*x)' 2
		\end{mglfunc}
		As you can see, only the body of the function has to be written. The number of arguments of the function can be passed to \verb|mglfunc| as optional argument, like in the code \verb|\begin{mglfunc}[3]{func_with_three_args}|.

		\item[mgladdon] This environment just adds its contents to the main script, without producing any image. It is useful to load dynamic libraries, define constants, etc.

		\item[mglcode] The \verb|mglcode| environment is similar to \verb|mgl|, but it creates its own script, whose name is passed as mandatory argument. The same optional arguments are accepted, except \verb|label| (for obvious reasons).
		\begin{verbatim}
			\begin{figure}[!ht]
			  \begin{mglcode}[scale=0.5]{vectorial_flow}
			    new a 20 30 'sin(pi*x)*sin(pi*y)+cos(2*pi*x*y)'
			    new b 20 30 'cos(pi*x)*cos(pi*y)+cos(2*pi*x*y)'

			    subplot 1 1 0 '' : title 'Flow of vector field' : box
			    flow a b 'v'; value 20
			  \end{mglcode}
			\end{figure}
		\end{verbatim}
		\begin{figure}[!ht]
			\centering
			\begin{mglcode}[scale=0.5]{vectorial_flow}
				new a 20 30 'sin(pi*x)*sin(pi*y)+cos(2*pi*x*y)'
				new b 20 30 'cos(pi*x)*cos(pi*y)+cos(2*pi*x*y)'

				subplot 1 1 0 '' : title 'Flow of a vector field' : box
				flow a b '2v'; value 10
			\end{mglcode}
		\end{figure}

		\item[mglscript] This environment just creates a script, whose name is specified as mandatory argument. It is useful, for example, to create MGL scripts which can later be post-processed by another package, like \verb|listings| or \verb|pygments|.

		For example, the following won't produce any image, just a script:
		\begin{verbatim}
			\begin{mglscript}{Gaston_surface}
			  subplot 1 1 0 '' : title 'Gaston\'s surface'
			  ranges -13 13 -40 40
			  new a 200 200 '-x+(2*0.84*cosh(0.4*x)*sinh(0.4*x))/' \
			    '(0.4*((sqrt(0.84)*cosh(0.4*x))^2+(0.4*sin(sqrt(0.84)*y))))+' \
			    '0.5*sin(pi/2*x)'
			  new b 200 200 '(2*sqrt(0.84)*cosh(0.45*x)*(-(sqrt(0.84)*sin(y)*' \
			    'cos(sqrt(0.84)*y))+cos(y)*sin(sqrt(0.84)*y)))/' \
			    '(0.4*((sqrt(0.84)*cosh(0.4*x))^2+2*(0.4*sin(sqrt(0.84)*x))^2))'
			  new c 200 200 '(2*sqrt(0.84)*cosh(0.45*x)*(-(sqrt(0.84)*cos(y)*' \
			    'cos(sqrt(0.84)*y))-sin(y)*sin(sqrt(0.84)*y)))/' \
			    '(0.4*((sqrt(0.84)*cosh(0.4*x))^2+2*(0.4*sin(sqrt(0.84)*x))^2))'
			  rotate 60 60
			  light on
			  xrange c : yrange b : zrange a : crange c
			  surf c b a '#'; meshnum 100
			\end{mglscript}
		\end{verbatim}
		\begin{mglscript}{Gaston_surface}
			subplot 1 1 0 ''
			ranges -13 13 -40 40
			new a 200 200 '-x+(2*0.84*cosh(0.4*x)*sinh(0.4*x))/(0.4*((sqrt(0.84)*cosh(0.4*x))^2+(0.4*sin(sqrt(0.84)*y))))+0.5*sin(pi/2*x)'
			new b 200 200 '(2*sqrt(0.84)*cosh(0.45*x)*(-(sqrt(0.84)*sin(y)*cos(sqrt(0.84)*y))+cos(y)*sin(sqrt(0.84)*y)))/(0.4*((sqrt(0.84)*cosh(0.4*x))^2+2*(0.4*sin(sqrt(0.84)*x))^2))'
			new c 200 200 '(2*sqrt(0.84)*cosh(0.45*x)*(-(sqrt(0.84)*cos(y)*cos(sqrt(0.84)*y))-sin(y)*sin(sqrt(0.84)*y)))/(0.4*((sqrt(0.84)*cosh(0.4*x))^2+2*(0.4*sin(sqrt(0.84)*x))^2))'
			rotate 60 60
			light on
			xrange c : yrange b : zrange a : crange c
			surf c b a '#'; meshnum 100
			title 'Gaston surface'
		\end{mglscript}

		\item[mglblock] It writes its contents verbatim to a file, specified as mandatory argument, and to the \LaTeX{} document.

		For example:
		\begin{verbatim}
			\begin{mglblock}{fractal}
				list A [0,0,0,.16,0,0,.01] [.85,.04,-.04,.85,0,1.6,.85] [.2,-.26,.23,.22,0,1.6,.07] [-.15,.28,.26,.24,0,.44,.07]
				ifs2d f A 100000
				subplot 2 1 0 '<_' : title 'A fractal fern'
				ranges f(0) f(1) : axis
				plot f(0) f(1) 'G#o '; size 0.05

				subplot 2 1 1 '<_' : title 'Bifurcation plot'
				ranges 0 4 0 1 : axis
				bifurcation 0.005 'x*y*(1-y)' 'R'
			\end{mglblock}
		\end{verbatim}
\begin{mglblock}{fractal}
list A [0,0,0,.16,0,0,.01] [.85,.04,-.04,.85,0,1.6,.85] [.2,-.26,.23,.22,0,1.6,.07] [-.15,.28,.26,.24,0,.44,.07]
ifs2d f A 100000
subplot 2 1 0 '<_' : title 'A fractal fern'
ranges f(0) f(1) : axis
plot f(0) f(1) 'G#o '; size 0.05

subplot 2 1 1 '<_' : title 'Bifurcation plot'
ranges 0 4 0 1 : axis
bifurcation 0.005 'x*y*(1-y)' 'R'
\end{mglblock}
		As you can see, although this is a verbatim-like environment, very long lines of code are split to fit the paragraph. Each line of code is numbered, this can be disabled with the \verb|lineno| option, like \verb|\begin{mglblock}[lineno=false]{fractal}|.

		\item[mglverbatim] This is like \verb|mglblock| environment, but it doesn't produce any script, just typesets the code to the \LaTeX{} document. It accepts the \verb|lineno| option, plus the \verb|label| option, in case you want to associate a name to the code.

		\item[mglcomment] This environment is used to embed comments in the document. You can control whether the contents of this environment are displayed or not, using the \verb|comments| and \verb|nocomments| package options, or the \verb|\mglcomments{on}| and \verb|mglcomments{off}| commands.

		An example of this would be:
		\begin{verbatim}
			\begin{mglcomments}
				This comment will be shown because we used the "comments" package option for mglTeX
			\end{mglcomments}
		\end{verbatim}
\begin{mglcomment}
This comment will be shown because we used the "comments" package option for mglTeX
\end{mglcomment}
		Once again, long lines are broke down to fit the paragraph.
	\end{description}

	\section{Basics on commands}
	\begin{description}
		\item[\textbackslash mglgraphics] This command takes the name of an external MGL script, compiles it, and includes the resulting image. It accespt the same optional arguments as the \verb|mgl| environment, except for \verb|label|, plus a \verb|path| option, which can be used to specify the location of the script. This is useful when you have a script outside of the \LaTeX{} document (sent by a colleague for example), but you don't want to transcript it to your document.

		For example, in order to display the image of the script we created with \verb|mglscript| environment, we write:
		\begin{verbatim}
			\begin{figure}[!ht]
			  \centering
			  \mglgraphics[height=9cm,width=9cm]{Gaston_surface}
			  \caption{Gaston's surface}
			\end{figure}
		\end{verbatim}
		\begin{figure}[!ht]
			\centering
			\mglgraphics[height=9cm,width=9cm]{Gaston_surface}
			\caption{Gaston's surface: Three-dimensional parametric surface}
		\end{figure}

		We could also could compile the script we created with the \verb|mglblock| environment:
		\begin{verbatim}
			\begin{figure}[!ht]
			  \centering
			  \mglgraphics[height=7cm,width=10cm]{fractal}
			  \caption{Examples of fractal behavior}
			\end{figure}
		\end{verbatim}
		\begin{figure}[!ht]
			\centering
			\mglgraphics[height=7cm,width=10cm]{fractal}
			\caption{Examples of fractal behavior}
		\end{figure}

		\item[\textbackslash mglinclude] This is equivalent to the \verb|mglblock| environment, but works for external scripts.

		\item[\textbackslash mglplot] This command allows the fast creation of plots. It takes one mandatory argument, which is a block of MGL code to produce the plot. Accepts the same optional arguments as the \verb|mgl| environment, plus an additional one, \verb|setup|, that can be used to specify a block of code to append, defined inside a \verb|mglsetup| environment (see the example below).

		The \verb|mglsetup| environment can be used if many plots will have the same settings (background color, etc.). Instead of writing the same code over and over again, it can be introduced in that environment, and used with the \verb|\mglplot| command.

		An example of use of the \verb|mglsetup| environment and the \verb|\mglplot| command would be:
		\begin{verbatim}
			\begin{mglsetup}{3d}
			  clf 'W'
			  rotate 50 60
			  light on
			  box : axis : grid 'xyz' ';k'
			\end{mglsetup}
			\begin{figure}[!ht]
			  \centering
			  \mglplot[setup=3d,scale=0.5]{fsurf 'cos(4*pi*hypot(x,y))*exp(-abs(x+y))'}
			\end{figure}
			\begin{figure}[!ht]
			  \centering
			  \mglplot[setup=3d,scale=0.5]{fsurf 'sin(pi*(x+y))'}
			\end{figure}
		\end{verbatim}
		\begin{mglsetup}{3d}
			clf 'W'
			rotate 50 60
			light on : light 0 0 1 0 'w' 0.25
			box : axis : grid 'xyz' ';k'
		\end{mglsetup}
		\begin{figure}[!ht]
			\centering
			\mglplot[setup=3d,scale=0.5]{fsurf 'cos(4*pi*hypot(x,y))*exp(-abs(x+y))'}
		\end{figure}
		\begin{figure}[!ht]
			\centering
			\mglplot[setup=3d,scale=0.5]{fsurf 'sin(pi*(x+y))'}
		\end{figure}
	\end{description}

	There are more environments and commands defined by \mglTeX{}. The ones presented here are the most basic. More on this topic can be found in the documentation.
\end{document}


\chapter{Algebraic Number Theory}
\label{chap:chap-two}
Algebraic number theory is a major branch of number theory that studies algebraic structures related to algebraic integers. Usually, it studies algebraic properties of the algebraic integers' ring such as factorization, the behaviour of ideals, and field extensions. In this chapter, we will introduce some definitions and useful results in algebraic number theory as well as some preliminaries of analytic number theory based on \citep{Xianke2006ANT,cohen1993course,mollin1999algebraic}.

\section{Algebraic Numbers and Number Fields}
We first give the necessary background on algebraic numbers, number fields etc. Let $\alpha\in\mathbb{C}$. Then $\alpha$ is called an \textbf{algebraic number} if there exists $f(x)\in\mathbb{Z}[x]/{0}$ such that $f(\alpha)=0$. The number $\alpha$ is called an \textbf{algebraic integer} if, in addition, one can choose $f$ to be monic.(i.e. with leading coefficient equal to 1).

More generally, we can define the integral element of a ring(See \citep{Xianke2006ANT}) through similar definition.

%\begin{definition}
%Let $\alpha\in\mathbb{C}$ be an algebraic number, and $f(x)$ its minimal polynomial. The conjugates of $\alpha$ are all the $deg(f)$ roots of $f$ in $\mathbb{C}$.
%\end{definition}

A \textbf{number field} is a field containing $\mathbb{Q}$ which, considered
as a $\mathbb{Q}$-vector space, is finite dimensional. The number $d=[K:\mathbb{Q}]=\text{dim}_{\mathbb{Q}}K$ is called the degree of the number field $K$.

The \textbf{signature} of a number field is the pair $(r_1,r_2)$ where $r_1$ is the number of embeddings of $K$ whose image lie in $\mathbb{R}$, and $2r_2$ is the number of non-real complex embeddings, so that $r_1+2r_2=n$. If $T$ is an irreducible polynomial defining the number field $K$ by one of its roots, the signature of $K$ will also be called the signature of $T$.

The following proposition \citep{cohen1993course} shows that there are only two possibilities for the signature of a Galois extensions.
\begin{lemma}\label{lem:signaturegal}
Let $K$ be a Galois extension of $\mathbb{Q}$ of degree $n$. Then,
either $K$ is totally real $(r_1=n)$,or K is totally complex $(r_2=n/2)$ which can occur only if $n$ is even.
\end{lemma}

\section{Discriminants of Elements and Fields}
The definition of discriminants of polynomials can be found in the Appendix \ref{chap:appB} if need some reviews, now we will introduce the definition of discriminant of elements and fields.
Let $K$ be a number field of degree $n$, $\sigma_i$ be the $n$ embeddings of $K$ into $\mathbb{C}$, and $\alpha_j$ be the set of $n$ elements of $K$. Then we have $$\operatorname{Disc}(\alpha_1,\dots,\alpha_n)=\det(\sigma_i(\alpha_j))^2=\det(\operatorname{Tr}_{K/\mathbb{Q}}(\alpha_i\alpha_j))$$
In particular,If $K=\mathbb{Q}(\alpha)$, $f(x)$ is the minimal polynomial of $\alpha$, then $$\operatorname{Disc}(f)=\operatorname{Disc}(\alpha)=\operatorname{Disc}(1,\dots,\alpha^{n-1})$$

we denote by $O_K$ the ring of algebraic(rational) integers of $K$. Then we have that the ring $O_K$ is a free $\mathbb{Z}$-module of rank $n=\operatorname{deg}(K)$. Hence we can define the (absolutely) integral basis as follows:

\begin{definition}
A $\mathbb{Z}$-basis of the free module $O_K$ will be called an (absolutely)\textbf{integral basis} of K. The discriminant of an integral basis is independent of the choice of that basis, and is called the \textbf{discriminant of the field} $K$ and is denoted by $d(K)$.
\end{definition}

Similarly, we can define a \textbf{relatively integral basis}: Let $A$ be a commutative integral domain with 1, $K=\operatorname{Frac}(A)$,$L/K$ is an extension with $[L:K]=n$, $B$ is the integral closure of $A$ in $L$. If $B$ is a free $A$-module , i.e. $B=A \alpha_1\oplus\cdots\oplus A\alpha_n$. Then we call $\alpha_1,\dots,\alpha_n$ the $A$-basis of $B$(resp. integral basis of $L/K$.) Then we have $$\operatorname{Disc}(L/K)=(\operatorname{Disc}(\alpha_1,\dots,\alpha_n)),$$ which is the discriminant of $L/K$.

Then, we will show a important theorem \citep{mollin1999algebraic} regarding the relationship of the discriminant of the minimal polynomial and the discriminant of the field.

\begin{lemma}\label{lem:discpoly-field}
Let $T$ be a monic irreducible polynomial of degree $n$ in $\mathbb{Z}[x]$, $\theta$ a root of $T$, and $K=\mathbb{Q}(\theta)$. If $f=[O_K:\mathbb{Z}[\theta]]$, then $$\operatorname{Disc}(T)=d(K)f^2.$$
\end{lemma}

The number $f$ is called the \textbf{index} of $\theta$ in $O_K$. A theorem for recognizing the integral basis of a field is important. Moreover, we have general results for relative integral basis \citep{Xianke2006ANT}. The following proposition has combined these two cases.

\begin{proposition}
The algebraic numbers $\alpha_1,\dots,\alpha_n$ form an integral basis if and only if they are algebraic integers and if $\operatorname{Disc}(\alpha_1,\dots,\alpha_n)=d(K)$.
More generally, if $L/K$ has integral basis, then $\beta_1,\dots,\beta_n\in B$ form an integral basis if and only if $(\operatorname{Disc}(\beta_1,\cdots,\beta_n))=\operatorname{Disc}(L/K)$.
\end{proposition}

The result related the structure of discriminant of a field due to Stickelberger can not be avoid when we talking about discriminant here:
\begin{lemma}[Stickelberger's criterion]\label{thm:stickelberger}
Let $K$ be a number field, then $$d(K)\equiv 0\text{ or }1(\operatorname{mod} 4)$$
\end{lemma}

The determination of an explicit integral basis and of the discriminant of a number field is not an easy problem, and is one of the main tasks of this article. However one case in which the result is trivial:
\begin{corollary}
Let $f$ be a monic irreducible(i.e. minimal) polynomial in $\mathbb{Z}[x]$, $\theta$ a root of $f$, and $K=\mathbb{Q}(\theta)$. Assume that the discriminant of $f$ is squarefree or is equal to $4d$ where $d$ is squarefree and not congruent to 1 modulo 4. Then the discriminant of K is equal to the discriminant of $f$, and an integral basis of $K$ is given by $1,\theta,\dots,\theta^{n-1}$.
\end{corollary}

Finally, the result to determine the sign of discriminant is useful:
\begin{lemma}
Let $K$ be an algebraic number field, then $$d(K)=(-1)^{r_2}|d(K)|$$
\end{lemma}

\section{Decomposition of Prime Numbers}
For simplicity, we continue to work with a number field $K$ considered as an (finite) extension of $\mathbb{Q}$, and not considered as a relative extension. Many of the results which are explained in that context are still true in the more general case, but some are not. Almost always, these generalizations fail because the ring of integers of the base field is not a PID(Dedekind).
The main results concerning the decomposition of primes are as follows:
\begin{proposition}\label{thm:decomposition}
Let $p$ be a prime number, then there exist positive integers $e_i$ such that $$pO_K=\prod_{i=1}^g \wp_i^{e_i},$$ where $\wp_i$ are all the prime ideals above $p$, i.e. $\wp_i\cap \mathbb{Z}=p\mathbb{Z}$.
\end{proposition}

The integer $e_i$ is called the \textbf{ramification index} of $p$ at $\wp_i$ and is denoted $e(\wp_i|p)$. The degree $f_i$ of the field extension defined by $$f_i=[O_K/\wp_i:\mathbb{Z}/p\mathbb{Z}]$$ is called the \textbf{residue degree} of $p$ and is denoted $f(\wp_i|p)$. $g$ is called the \textbf{decomposition number} of $p$ in $K$.

There is an important relation between these coefficients, which comes to a theorem.
\begin{proposition}
Let $[K:\mathbb{Q}]=n$, then for any $p$, the decomposition in Theorem  \ref{thm:decomposition} satisfies $$\sum_{i=1}^g e_if_i=n.$$
\end{proposition}

Let $pO_K=\prod_{i=1}^g \wp_i^{e_i}$ be the decomposition of a prime $p$. We will say that $p$ is \textbf{inert} if $g=1$ and $e_i=1$,i.e. $pO_K=\wp_i$.
We will say that $p$ \textbf{splits completely} if $g=n$.
Finally, we say that $p$ is \textbf{ramified} if there is an $e_i$ which is greater than or equal to 2 (in other words if $pO_K$ is not squarefree), otherwise we say that $p$ is \textbf{unramified}. Those prime ideals $\wp_i$ such that $e_i>1$ are called the ramified prime ideals of $O_K$. In particular, if $e_1=n$, then we say that $p$ \textbf{ramifies totally}.

From the definitions of these ramification index and decomposition number satisfy chain rule, which is a very important message for us to decompose prime number in a compositum of fields.

In the case when $K/\mathbb{Q}$ is a Galois extension, the result is more specific:
Assume $K/\mathbb{Q}$ is a Galois extension. Then for any $p$, the ramification indices $e_i$ are equal, the residual degrees $f_i$ are equal as well, hence $e f g=n$.
In addition, the Galois group operates \textbf{transitively} on the prime ideals above $p$: i.e. there exists $\sigma\in\operatorname{Gal}(K)$, such that $\sigma(\wp_i)=\wp_j$.

The existence of ramified prime has showed by Minkowski: If $K$ is a number field different from $\mathbb{Q}$, then $|d(K)|>1$. In particular, there exists at least one ramified prime in $K$. What's more, the fundamental ramification theorem\citep{cohen1993course} is as follows:
\begin{proposition}\label{thm:ramification}
Let $p$ be a prime number, then $p$ is ramified in $K$ if and only if $p$ divides the discriminant $d(K)$. In particular, there are only a finite number of ramified primes (exactly $w(d(K))$, where $w(x)$ is the number of distinct prime divisors of an integer $x$).
\end{proposition}

On the contrary, for unramified prime, we have another theorem given by Stickelberger\citep{cohen1993course}.
\begin{proposition}[Stickelbeger]\label{thm:unramified}
If $p$ is an unramified prime in $K$ with $pO_K=\prod_{i=1}^g \wp_i$, we have $$\left(\frac{d(K)}{p}\right)=(-1)^{n-g},$$ for $p=2$, $\left(\frac{d(K)}{2}\right)=(-1)^{n-g}$ is to be seen as the Jacobi-Kronecker symbol(See Appendix \ref{chap:appA}).
\end{proposition}

%\begin{corollary}[quadratic field]
%The decomposition type of a prime number $p$ in a quadratic field $K$ of discriminant $D$ is the %following: if $\left(\frac{D}{p}\right)=-1$, then $p$ is inert. If  $\left(\frac{D}{p}\right)=0$, then $p$ is ramified. Finally, if $\left(\frac{D}{p}\right)=1$, then $p$ splits(completely).
%\end{corollary}

We now consider a more difficult algorithmic problem, that of determining the decomposition of prime numbers in a number field. The basic theorem on the subject, which unfortunately is not completely sufficient(but right for Dedekind domain with power integral basis, even for without essential factor), is as follows.

\begin{proposition}[Kummer]\label{thm:kummer}
Let $K=\mathbb{Q}(\theta)$ be a number field, where $\theta$ is an algebraic integer, whose minimal polynomial is denoted $T(x)$. Let $f$ be the index of $\theta$, i.e. from definition $f=[O_K:\mathbb{Z}[\theta]]$. Then for any prime $p$ not dividing $f$ on can obtain the prime decomposition of $pO_K$ as follows. Assume $$T(x)\equiv \prod_{i=1}^g T_{i}(x)^{e_i} (\operatorname{mod } p)$$ be the decomposition of $T$ into irreducible factors in $\mathbb{F}_p[x]$, where the $T_i$ are also monic. Then $$pO_K=\prod_{i=1}^g\wp_i^{e_i},$$ where $$\wp_i=(p,T_i(\theta))=pO_K+T_i(\theta)O_K$$
Furthermore, the residual index $f_i$ is equal to the degree of $T_i$.
\end{proposition}

\section{Units and Ideal Classes}\label{sec:unitsideal}
Let $K$ be a number field and $O_K$ be the ring of integers of $K$. We say that two (fractional) ideals\footnote{Fractional ideal $I$ in $O_K$ is a non-zero sub-module of $K$ such that there exists a non-zero integer $d$ with $d I$ ideal of $O_K$.} $I$ and $J$ of $K$ are equivalent if there exists $\alpha\in K^*$ such that $J=\alpha I$. The set of equivalence classes is called the \textbf{class group} of $O_K$ and is denoted $Cl(K)$.

Since fractional ideals of $O_K$ form a group it follows that $Cl(K)$ is also a group. The main theorem concerning $Cl(K)$ is that it is finite.

For any number field $K$, the class group $Cl(K)$ is a finite Abelian group, whose cardinality, called the \textbf{class number}, is denoted $h(K)$. Note that $h(K)=1$ if and only if $O_K$ is a PID(UFD).

Denote by $I(K)$ the set of fractional ideals of $K$, and $P(K)$ the set of principal ideals. We clearly have the exact sequence:
$$1\rightarrow P(K)\rightarrow I(K)\rightarrow Cl(K)\rightarrow1.$$

The set of units in $K$ form a multiplicative group which we will denote by $U(K)$. Units are algebraic  integers of norm equal to $\pm1$. The torsion subgroup of $U(K)$, i.e. the group of roots of unity in K, will be denoted by $\mu(K)$.

It is clear that we have the exact sequence:
$$1\rightarrow U(K)\rightarrow K^{\times}\rightarrow P(K)\rightarrow1.$$
To sum up above two sequence, we have new exact sequence as follows:
$$1\rightarrow U(K)\rightarrow K^{\times}\rightarrow P(K)\rightarrow I(K)\rightarrow Cl(K)\rightarrow1.$$

The main result concerning units is the following theorem:
\begin{proposition}[Dirichlet's Unit Theorem]\label{thm:Dirichlet}
Let $(r_1,r_2)$ be the signature of $K$, then $U(K)$ is finitely generated Abelian group of rank $r_1+r_2-1$. i.e. we have a group isomorphism: $$U(K)\cong\mu(K)\times\mathbb{Z}^{r_1+r_2-1},$$ and $\mu(K)$ is a finite cyclic group.
\end{proposition}
If we set $r = r_1+r_2-1$, we see that there exist units $u_1,\dots,u_r$ such that every element $x$ of $U(K)$ can be written in a unique way as $$x=\zeta u_1^{n_1}\cdots u_r^{n_r},$$ where $n_i\in\mathbb{Z}$ and $\zeta$ is a root of unity in $K$.Such a family $(u_i)$ is called a system of \textbf{fundamental units} of $K$.

A very important property is the number is finite, what's more, like we claimed before, the ideal class group for any number field is a finite Abelian group. As for the class number, we can give a certain upper bound of it. First of all, we give the definition of Minkowski bound \citep{mollin1999algebraic}:
\begin{definition}\label{def:minkowski}
If $K$ is a number field, the quantity $$C_K=\left(\frac{4}{\pi}\right)^{r_2}\frac{n!}{n^n}\sqrt{|d(K)|}$$ is called the  \textbf{Minkowski's bound}, where $d(K)$ is the discriminant of $K$ and $[K:\mathbb{Q}]=n$ with signature $\{r_1,r_2\}$.
\end{definition}
The following lemma \citep{mollin1999algebraic} will give us a useful method to determined the class number and class field for $n=[K:\mathbb{Q}]$ is small.
\begin{lemma}
Any ideal class of a number field $K$ has an (integral) ideal $I$, such that $$\operatorname{N}(I)\leq C_K$$
\end{lemma}
From this lemma, we can also get the so-called Hermite's theorem on discriminant: There are only finitely many number fields having a given discriminant $d$.

In fact, we have a following method to determined the class number and class group" Firstly, we should calculated the Minkowski's bound of the number field $K$. From the lemma, we can find all rational primes that $p\leq C_K$. Given the prime decomposition of $pO_K$, then we can compute all prime ideals $\wp$ over $p$. Hence the class group $Cl(K)$ is generated by $A=\{[\wp]|\wp|p\leq C_K\}$, where $[\wp]$ is the ideal class which $\wp$ lies in. If $A$ is not so big, the we can consider the multiple relationship between its elements, then we can get the class group and class number.

\section{Character and Conductor}
A \textbf{character} on a group $G$ is a group homomorphism from $G$ to the multiplicative group of a field( usually complex numbers field). The set $\hat{G}$ of these morphisms forms an abelian group under pointwise multiplication. Sometimes we only consider unitary characters, thus the image is in the unit circle.

Now we consider the special character we mentioned above, \textbf{Dirichlet character}, which is defined as follows:
\begin{definition}
A Dirichlet character is any function $\chi$ from the integers $\mathbb{Z}$ to the complex numbers $\mathbb{C}$ such that $\chi$ has the following properties:
\begin{enumerate}
\item the function is periodic, i.e. $\exists k\in\mathbb{Z^+}$, s.t. $\chi(n)=\chi(n+k),\forall n$.
\item If $\operatorname{gcd}(n,k)>1$, then $\chi(n)=0$; if $\operatorname{gcd}(n,k)=1$, then $\chi(n)\neq0$
\item $\chi(mn)=\chi(m)\chi(n)$ for all integers $m,n$.
\end{enumerate}
\end{definition}
The Dirichlet character has following properties: from the definition, we can directly get $\chi(1)=1$, the character is periodic with period $k$, we say that $\chi$ is a character to the \textbf{modulus} $k$. i.e. we have $$a\equiv b \mod k \Rightarrow \chi(a)=\chi(b)$$
If $\operatorname{gcd}(a,k)=1$, then from Euler theorem, we have $a^{\phi(k)}\equiv 1 \mod k$, therefore we have $\chi(a^{\phi(k)})=\chi(1)=1$, on the other hand, $\chi(a^{\phi(k)})=\chi(a)^{\phi(k)}$. i.e. for all $a$ relatively prime to $k$, $\chi(a)$ is a $\phi(k)$-th complex root of unity.

A character $\chi$ is said to be \textbf{odd} if $\chi(-1)=-1$ and \textbf{even} if $\chi(-1)=1$. A character is called \textbf{principal} if it assumes the value $1$ for arguments coprime to its modulus and otherwise is 0. A character of the (Abelian) field can be viewed as the character of the Galois group of the field.

For example, the character of a quadratic field $K$ is $\hat{K}=\{1,\chi\}$ (see \citep{Xianke2006ANT} etc.). the character $\chi$ is the same to the Legendre-Kronecker symbol (See Appendix \ref{chap:appA}).

Then, we will introduce the conductor. Taking as base the field of rational numbers, the Kronecker–Weber theorem \ref{thm:kronecker} states that an algebraic number field $K$ is abelian over $\mathbb{Q}$ if and only if it is a subfield of a cyclotomic field $\mathbb{Q}(\zeta_n)$. The \textbf{conductor} of $K$ is then the smallest such $n$.

we can also define a conductor of character, i.e. the conductor of a character is the smallest modulus of $\chi$, More precisely, the conductor of a Dirichlet character $\chi$ modulo $k$ is the smallest positive integer $k_0$ which divides $k$ and which has the property that $\chi(n+k_0)=\chi(n)$ for all $n$. For this case, the $\chi$ is called the \textbf{primitive character of conductor} (or modulus) $f_{\chi}$.

The relation between the conductor of characters and Abelian number field is that, the conductor $f$ of the field $K$ is the least common multiple of conductor of character for Galois group of the Abelian number field, i.e. $$f=\operatorname{lcm}_{\chi\in\hat{K}}\{f_{\chi}\}.$$

For example, for real quadratic field, $f$ is the fundamental discriminant of the field. For cyclic cubic field, $f$ is actually $e$ in Theorem \ref{thm:ccpoly}, i.e. the arithmetic square root of the discriminant of the cyclic cubic field.

Let $p$ be an odd prime and $K/\mathbb{Q}$ a cyclic extension of degree $p$. Then it is well known \citep{maki1980determination} that the conductor of $K$ must have the form $f=p^e\cdot q_1q_2\cdot q_n$, where $e=0$ or $2$, $n\geq0$, and the $q_i$ are pairwise distinct rational primes satisfying $q_i\equiv1(\operatorname{mod} p)$ for $i=1,2,\dots,n$. The discriminant of $K$ is just a power of the conductor, $d_K=f^{p-1}$.

A theorem called \textbf{conductor-discriminant formula} related to the conductor of a field and the discriminant of the field was first found by Dedekind. Then at the beginning of 1930's, E. Artin and H. Hasse found this general formula (See \citep{rzedowski2011conductor} etc.) which is showed following:
\begin{proposition}\label{thm:conddisc}
Let $K/F$ be a finite Galois extension of global fields with Galois group $G$, $$d(K/F)=\prod_{\chi\in\hat{G}}f_{\chi}^{\chi(1)},$$
since for abelian field, $\chi(1)=1$, hence for $K$ is an abelian number field, then we have a special form, $$d(K)=(-1)^{r_2}\prod_{\chi\in\hat{G}}f_{\chi}$$
\end{proposition}


%!TEX root = ./egpaper_for_review.tex
\subsection{Datasets}\label{sec:datasets}
\textbf{Social Networks.}\label{sec:nets}
One important application for large scale correlation clustering are social networks.
We consider two of those networks from the Stanford Large Network Dataset Collection\footnote{\url{http://snap.stanford.edu/data/index.html}}.
Both networks are given by weighted directed graphs with edge weights $-1$ and $+1$.
%
The first network is called \emph{Epinions}.
This is a who-trust-whom online social network of a general consumer review site.
Each directed edge $a\to b$ indicates that user $a$ trusts  or does not trust user $b$ by a  positive or negative edge-weight, respectively.
The network contains $131828$ nodes and $841372$ edges from which $85.3\%$ are positively weighted.
%
The second network is called \emph{Slashdot}.
Slashdot is a technology-related news website known for its specific user community.
In 2002 Slashdot introduced the Slashdot Zoo feature which allows users to tag each other as friend or foe.
The network was obtained in November 2008 and contains $77350$ nodes and $516575$ edges of which $76.73\%$ are positively weighted.

We consider the problem to cluster these graphs such that positively weighted edges ($E^+_{\to}$) link inside and negatively weighted edges ($E^-_{\to}$) between clusters.
In other words friends and people who trust each other should be in the same segment and foes and non-trusting people in different clusters.
%
To compensate the large impact of nodes with high degree we can normalize the edge weights such that each person has the same impact on the overall network, by enforcing.
\begin{align}
  \sum_{i\to j \in E_{\to}} |w_{i\to j}| &= 1&\forall i\in V, deg^{\textrm{out}}(i)\geq 1
\end{align}
We define the following energy function
\begin{align}
 J(y) &= \sum_{i\to j \in E^+_{\to}} y_{ij}\cdot w_{i \to j} +  \sum_{i\to j \in E^-_{\to}} (y_{ij}-1)\cdot w_{i \to j} \nonumber\\
      &= \sum_{ij \in E} y_{ij}\cdot \underbrace{(w_{i \to j}+w_{j \to i})}_{w_{ij}} + \textrm{const}
\end{align}
which is zero if the given partitioning does not violate any relation and larger otherwise.
We name these two datasets \emph{social nets} and \emph{normalized social nets}.

\textbf{Network Modularity Clustering.}
As another example for network clustering we use the \emph{modularity-clustering} models from~\cite{kappes-2015-ijcv} which are small but fully connected.

\textbf{2D and 3D Image Segmentation}\label{sec:imseg}
To segment images or volumes into a previously
unknown number of clusters, correlation clustering
has been used~\cite{andres_2011_iccv,kroeger_2012_eccv}.

Starting from a super-pixel/-voxel segmentation,
correlation clustering finds the clustering with the lowest energy.
The energy is based on a likelihood of merging adjacent super-voxels.
Each edge has a probability to keep adjacent segments separate ($p(y_{ij} =1)$)
or to merge them ($p(y_{ij} = 0)$).
The energy function is
\begin{align}
 J(y)  &= \sum_{ij \in E} y_{ij}\cdot \underbrace{  log\left( \frac{p(y_{ij} =0)}{p(y_{ij} =1)}\right) + log \frac{1-\beta}{\beta}  }_{w_{ij}}
\end{align}
where $\beta$ is used as a prior~\cite{andres_2011_iccv}.

We use the publicly available benchmark instances from~\cite{kappes_2013_benchmark_cvpr,kappes-2015-ijcv}.
For 2D images from the Berkeley Segmentation Database~\cite{martin_2001}, we took the segmentation problems called \emph{image-seg}~\cite{andres_2011_iccv,kappes_2013_benchmark_cvpr}.
For 3D volume segmentation we use the models \emph{knott-3d-150}, \emph{-300} and \emph{-450} from~\cite{kroeger_2012_eccv,kappes-2015-ijcv} as well as the large
instance from the \emph{3d-seg} model~\cite{andres_2011_iccv,kappes_2013_benchmark_cvpr}. These instances have underlying cube sizes of  $150^3$, $300^3$, $450^3$, and $900^3$, respectively.
We also requested larger instances from the authors of~\cite{kroeger_2012_eccv} who kindly provided us the dataset~\emph{knott-3d-550} with cube size  $550^3$.
%More information of the size of instances is given in Tab.~\ref{tab:instance_sizes}.


% !TEX root = ../../main.tex
% !TEX spellcheck = en_GB

\section{Implementation}
\label{sec:impl}
The implementation has been done in the framework made by our supervisor Kim Bjerge.
The complete idea of the system has not been implemented on the Blackfin.
What has been implemented on the blackfin is the Instantaneous Frequency algorithm, which determines the main frequency in the signal and a sine generator.
To the framework has been added a function called \mintinline{c}{hilbert()} as can be seen below and and a function called \mintinline{c}{sineGenerator()}.
Before the \mintinline{c}{hilbert()} is called the FFT of the signal will be made using the function

\begin{minted}[breaklines]{c}
void rfft_fr16(const fract16 input[], complex_fract16 output[], const complex_fract16 twiddle_table[], int twiddle_stride, int fft_size, int *block_exponent, int scale_method);
\end{minted}

After the FFT, the \mintinline{c}{hilbert()} will use the FFT signal. In \mintinline{c}{hilbert()} the FFT signal will first be rearranged into the array $zHilbert[N\_FFT]$.
The first value and the $N\_FFT/2$ value will be waited less and therefore are multiplied with $0.5$ using the optimized function $cmlt\_fr16(a,b)$.
From $N\_FFT/2$ and beyond everything is set to zero.
After rearranging the inverse FFT of zHilbert is made and placed in $m\_ifft\_output$.
The inverse FFT is also made using the build in functions.

\begin{minted}[linenos, breaklines, bgcolor=lightgray]{c}
void DynamicFilter::hilbert(){
	// parameters
	int block_exponent;
	fract16 instafreq[N_FFT];
	fract16 meanFreq;
	fract32 temp = 0;
	uint16_t dif;
	complex_fract16 scale;
	scale.re=0.5; scale.im=0.5;
	fract32 temp32[512];

	// Hilbert transform
	zHilbert[0] = cmlt_fr16(m_fft_output[0], scale);

	for (int i = 1; i < N_FFT/2; i++){
		zHilbert[i] = m_fft_output[i];
	}

	zHilbert[N_FFT / 2] = cmlt_fr16(m_fft_output[N_FFT / 2], scale);

	// ifft of the hilbert signal
	ifft_fr16(zHilbert, m_ifft_output, m_twiddle_table, 1, N_FFT, &block_exponent, 1);

	////// instant frequency finding //////
	//first finding the phase
	for (int i = 0; i<N_FFT; i++){
		instafreq[i] = atan2_fr16(m_ifft_output[i].im, m_ifft_output[i].re);
	}

	// unwrapping with threshold 2PI
	temp32[0] = instafreq[0];
	for(int i = 1; i<N_FFT;i++){
		dif = (((int16_t)instafreq[i - 1] - (int16_t)instafreq[i]) + (1 << 15)) % (2 * (1 << 15)); //1<<15 = pi

		temp32[i] = ((int32_t)(dif - (1 << 15)));

		temp32[i] = sub_fr1x32(temp32[i-1],	temp32[i]); // optimization
	}

	// find the diff
	for(int i = 1; i<N_FFT;i++){
		temp32[i-1] = (sub_fr1x32(temp32[i],temp32[i-1])) * fs / (2 * PI_FLOAT); // optimization
	}

	//finding the mean and therefore the value
	for(int i = 100; i < N_FFT-99; i++){
		temp += temp32[i];
	}

	meanFreq = ((temp / (N_FFT-200)) * PI_FLOAT) / (1 << 15);

}
\end{minted}
Now the Instantaneous Frequency finding starts. First the argument of every value of the IFFT signal is found using \mintinline{c}{atan2_fr16}.
Afterwards the remainder is found after the subtraction of two arguments.
Lastly the difference is found and then a mean of the middle values are used to find the meanFreq.

\subsection{Optimized functions}
In the implementation some of the build in functions have been used, these functions are optimized and should use as few clock cycles as possible to execute.
On \cref{tab:optimized_func}  some of the different build-in functions which are used can be seen.

\begin{table}
	\centering
	\begin{tabularx}{\textwidth}{X X}
		\toprule
		\textbf{Function name} & \textbf{Description }\\
		\midrule
		\mintinline[breaklines]{c}{rfft_fr16(input, output, twiddle_table, twiddle_stride, fft_size, *block_exponent, scale_method)} & Calculates the FFT of the input signal\\
		\mintinline[breaklines]{c}{ifft_fr16(input, output, twiddle_table, twiddle_stride, fft_size, *block_exponent, scale_method)} & Calculates the inverse FFT of the input signal. \\
		\mintinline{c}{cmlt_fr16(a, b)} & Multiplies two complex fract16 values. \\
		\mintinline{c}{sub_fr1x32(a, b)}& Subtracts two complex fract32 values. \\
		\mintinline[breaklines]{c}{atan2_fr16(imaginary_part, real_part)} & Find the argument of a complex fract16 value. \\
		\bottomrule
	\end{tabularx}
	\caption{The used optimized functions.}
	\label{tab:optimized_func}
\end{table}

\mintinline{c}{twiddle_table} is a table made in the setup of the program.
It is $W_n = \cos(\frac{2\pi kn}{N})-j\sin(\frac{2\pi kn}{N})$.
It is made so that the FFT and IFFT are executed faster since these function do not have to calculate this part of the equation but can just take the value from the \mintinline{c}{twiddle_table}.
As long as the size of the FFT or IFFT does not change these values in the twiddle factor does not have to be calculated again.

\FloatBarrier


%----------------------------------------------------------------------------------------
% Limitations
%----------------------------------------------------------------------------------------

\section{Limitations}

Although what we have discussed in this paper so far is robust, there are some chinks in Randomization Based Inference’s armor.

\begin{enumerate}
    \item \textbf{Random Data Condition} \newline
	The first and most glaring limitation of RBI is that it is not truly conditionless. The one condition that it does have is that the initial data has to be random. Some basic cases where this is not met is when you have access to the whole population, in which case you do not need randomization based inference, or when collecting data you failed to use a randomization procedure. The latter is the situation we are more focused on in this paper. In general, when a sample fails to be random, it is no longer assumed to be representative of the population.
	We can connect this to randomization based inference in that we are trying to find an asymptotically correct p-value. In order to do this, we have to randomly shuffle the data and extract our test statistic and build the randomization distribution and then calculate the p-value from that. This process becomes invalid when the original data fails to be random because of two key issues. We can start with the simpler one: The original sample contains high levels of bias. Let’s assume that we are trying to figure out if a bill on an upcoming ballot does not have equal support in a community. Instead of using your city hall and a random number generator to sample people, you decide to ask everyone who walks into the local Hobby Lobby. In your mind, this seems reasonable, considering that you don’t know who is going to walk in and what they are thinking about the bill. However, you have failed to consider the population of people who shop at Hobby Lobby. This can introduce bias into your sample. It could be response bias or under-coverage bias (specific groups of people left out). The fatal flaw that both the former and the latter present is that they alter the null hypothesis of your test. If you were to continue with your experiment and use randomization based inference, you won’t be able to trust any of your permuted test statistics and your final p-value due to the bias present. \newline\\
	The second and more complex issue of not obtaining a random sample focuses on the obvious connection between a random sample and randomization based inference. The main point to be made here is that if a sample is not random, we cannot assume it to be representative of the population our sample comes from. In the Hobby Lobby story, the sample taken could be representative of the population. Here, even if some randomized sampling procedure is taken, the sample could still be not random. Typically when we code in R, we use tests like Bartel’s test for randomness to determine if data has been sampled randomly. If the test fails to reject the null hypothesis that the data is random, then we are fair to move forward with randomization-based inference. When the null hypothesis is rejected, randomization-based inference will not work. This is due to the fact that we are typically using a test to make an inference about the population. We use the term correlation, because our tests can’t conclude causation. Regardless of the prior statement, the main problem here is that our random variables, no matter the type of test, are not approximately normally distributed. This is because the Central Limit Theorem needs randomly distributed variables for it to apply. When a sample is not random, the variables we are observing are also not random. This makes the random variable we're observing to be not approximately normally distributed. No matter the test statistic calculated we will not be allowed us to trust our test statistic, causing a breakdown of the entire randomization process. \newline\\
	In summation, in order for our randomization based inference to be of value, we need a sample free of bias and that is random. This ensures that our variables are random variables and we can trust the test statistic created from them.
    \item \textbf{Small Sample Sizes} \newline
	For most tests, there is typically a condition that requires the initial sample to be of an acceptable size. For example, when trying to determine if two different treatment groups have a difference in means that is not equal to zero, we require that for the Central Limit Theorem to work, we need at least 30 data points, assuming our sample is random. Although randomization based inference can generate many permutations of a given sample, the one thing it can’t do is increase the sample size. The randomization based inference does not deal with the counterfactual statement that “if the sample size was larger, we could be more sure of our conclusion”. Instead, the point here is that our randomization distribution using a small original sample size will be less approximately normal than a satisfactory sample size. This affects the robustness of our randomization based inference. Sure, it created something that could pass as normal to any given statistician, but the level of asymptotic certainty we have is in jeopardy.
	\item \textbf{Population Parameter Estimation} \newline
	One of the important aspects of model creation in statistics is the idea of parameter estimation and statistical accuracy. We often fit one model at the beginning of our experiment and then go through rigorous testing and fitting procedures to develop the best model. This best model is not only accurate at its forecasting and initial predictions, but also does not over-fit to the data so that it can be generalized to new data. The limitation we are getting at here is that randomization based inference is not something we can use to develop better population parameter estimates. \newline\\
	In general, we use randomization based inference to help us figure out if the perceived effects we see in our original model are trustworthy. However, if we are doing linear regression, our beta estimates are only as good as the original sample we have. In randomization based inference, we resample data without replacement. This means we assume our null hypothesis is true. However, if we wanted to make sure our sample statistics were better at estimating the true population parameters given our test, we would have to take a different approach. Instead of just randomly shuffling our response variable, we could take all of our observations and pool them back up, then choose one response value at random and assign it to a given observation. We then could put the response value back into the pool of responses and repeat the process. This is sampling with replacement. Instead of building a randomization distribution which looks to estimate the distribution of the given test statistic, this estimates the sampling distribution. This estimated sampling distribution is centered around our original sampling mean and has a standard deviation from our original sample as well. However, with this distribution, we can make confidence intervals that give us more precise estimates of the population parameter. This process is referred to as bootstrapping. In most cases, we should really pair these models so that we can have better model accuracy as well as more clarity around the effect we are testing for. However, the computational acumen required for both tests is quite high. Lastly, the level of interpretability when using both methods of resampling is murky due to the different procedures used. Depending on what your goal is, picking one of these methods will be more useful than including both.
\end{enumerate}


In this appendix we will show in detail some operations on lists built on top of what presented in Section \ref{sec:ch_background_template_metaprogramming} that can be built by using meta-programming in C++ templates. The goal of this appendix is to convince the reader about the level of complexity of using C++ templates to express meta-programming and why it is preferable to use a dedicated meta-compiler.

\section{Element Getter}
\label{sec:app_templates_getter}
Accessing the n-th element of a list defined with templates mimics the behaviour of the its definition in a functional programming languages given below:

\begin{lstlisting}
let rec nth (n : int) (l : List<'a>) : 'a =
  match l,n with
  | x :: xs,0 -> x
  | x :: xs,_ -> nth (n - 1) xs
\end{lstlisting}

\noindent
The recursion base case is when the index we want to access is 0, which means that we want to access the head of the list. In this case we simply return the head by decomposing the list through pattern matching. In the other case we simply make a recursive call by passing the index decreased by 1 and the tail of the list. In template meta-programming, this is translated into a template that performs the same task:

\begin{lstlisting}
template <typename List> struct Nth<LST, 0>
{
    typedef typename List::Head result;
};
\end{lstlisting}

\noindent
As shown in Section \ref{sec:ch_background_template_metaprogramming}, the arguments of the function are passed as arguments of the template itself. This version of the template is specialized for the integer 0, which corresponds to the base case of the recursion. The general case of the recursion has a dedicated template as follows:

\begin{lstlisting}
template <typename List, int N> struct Nth
{
    typedef typename List::Tail Tail;
    typedef typename Nth<Tail, N - 1>::result result;
};
\end{lstlisting}

\noindent
The template contains a type definition for the parameter corresponding to the list tail and another type definition corresponding to the recursive call to another \texttt{Nth} template, this time containing only the tail of the list and the counter decreased by 1. To test this we can use the following sample:

\begin{lstlisting}
template <int N> struct Int
{
  static const int result = N;
};

typedef List<Int<1>, List<Int<2>, List<Int<3>>>> testList;

int main()
{
  cout << Nth<testList, 2>::result::result << endl;
}
\end{lstlisting}

\noindent
Note that we need to access \texttt{result} twice, because the first \texttt{result} is the type of the head of the list generated by template, which is \texttt{Int}. So calling

\begin{lstlisting}
Nth<testList, 2>::result
\end{lstlisting}

\noindent
returns \texttt{Int}, that is a type. If we want to access the value stored in \texttt{Int} then we must access the constant integer \texttt{result} contained in it. Note that if we try to access an invalid index in the list, the compiler will complain because it will try to generate a template with the tail of a list that does not exist. In this way something that in a normal program becomes a runtime error is here treated as a compilation error.

\section{Element Existence}
\label{sec:app_templates_existance}
The code that tests the existence of an element within a list is recursive as well and mimics the behaviour of its functional counterpart:

\begin{lstlisting}
let exists (element: 'a) (l : List<'a>) : 'a =
  match l with
  | [] -> false
  | x :: xs when element = x -> true
  | x :: xs -> exists element xs
\end{lstlisting}

\noindent
The function returns \texttt{false} as a base case when the list is empty, because it means that the whole list has been examined and the element has not been found. The second case is when the head of the list matches the element, which returns \texttt{true}. The last case is used when the head of the list does not match the element, thus we call recursively \texttt{exists} on the tail. In order to implement this function with C++ templates, we need to define two utility templates able to compare two elements:

\begin{lstlisting}
template <class X, class Y> struct Eq { static const bool result = false; };
template <class X> struct Eq<X, X> { static const bool result = true; };
\end{lstlisting}

\noindent
The first template has a result set to \texttt{false} when its arguments are different, while the second template is a specialization of the first one where both the first template argument and the second are the same and its result is \texttt{true}. With this utility templates we can correctly compare the values of a list defined with templates and define the recursive template for the existence function:

\begin{lstlisting}
template <class Element, class List> struct Exists
{
  static const bool result =
    Eq<Element, typename List::Head>::result || Exists<Element, typename List::Tail>::result;
};

template <class Element> struct Exists<Element, NIL>
{
  static const bool result = false;
};
\end{lstlisting}

\noindent
The first template is the general case of the recursion. It uses \texttt{Eq} to test the value of the searched element against the head of the list. It then combines this result with the logical or on \texttt{Exists} run with the remaining tail of the list. The second template is the base case and contains a constant set to \texttt{false}. This corresponds to the base case of the recursive function above.


\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

% Main maths packages
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}

\begin{document}

\subsection*{Math spacing}

Normal space in math mode:

\[1 2\]

Custom spaces in math mode::

% [mu] is the math unit equal to 1/18 em, where em is taken from the math symbols family, according to ShareLaTeX.
\[1\!2\] % -3/18 of \quad (= -3 mu)
\[1\,2\] % 3/18 of \quad (= 3 mu)
\[1\:2\] % 4/18 of \quad (= 4 mu)
\[1\;2\] % 5/18 of \quad (= 5 mu)
\[1\ 2\] % equivalent of space in normal text
\[1\quad2\] % space equal to the current font size (= 18 mu)
\[1\qquad2\] % twice of \quad (= 36 mu)

\subsection*{Phantom spacing}

The command \emph{phantom} creates a horizontal space according the width of the argument.

\[
	\begin{pmatrix}
		123 			& 456\\
		\phantom{12}3	& 4\phantom{56}
	\end{pmatrix}
\]

\end{document}