\section{\texorpdfstring{Non-uniform computation}{Non-uniform computation}}
\vspace{5mm}
\large
% 7th lecture

\begin{definition}[Uniform computation]
	Uniform models of computation - single algorithm for all inputs. (DTM, NTM, RAM ...)
\end{definition}

\begin{definition}[Non-uniform computation]
	Algorithm may vary for different input lengths.
	However, inputs of the same lengths are handled by the same algorithm.

	For example Boolean circuits.
\end{definition}

\begin{definition}[Boolean circuit]
	Boolean circuit with $n$ inputs (and single output) is an acyclic directed graph with $n$ source virtices.
	Source vertex has $deg_{in}(s) = 0$.
	And single sink vertex $deg_{out}(t) = 0$.

	Source vertices represents the inputs, sink - output.
	All other vertices are gates (NOT, AND, OR).

	AND, OR gates have 2 inputs (in degree).
	NOT has only 1 input.

	Size of the circuit is \# of vertices.
\end{definition}

\begin{note}
	Because of the selected elementary gates, number of edges is bounded by $2n$.
\end{note}

\begin{example}[XOR gate]
	$x_1 XOR x_2$ as a DNF formula:
	\[ (x_1 \land \neg x_2) \lor (\neg x_1 \land x_2) \]

	\includegraphics[scale=0.4]{xor_0.eps}

	Source ~\cite{arora2009computational}.

	Or CNF
	\[ (x_1 \lor x_2) \land (\neg x_1 \lor \neg x_2) \]
\end{example}

\begin{example}
	\[ (x_1 \lor x_2 \lor x_3) \land (x_1 \lor x_2 \lor x_4) \land (x_1 \lor x_2 \lor x_5) \]
	The gate will be the following:

	%lecture 7 25:00
	\includegraphics[scale=0.4]{gate_0.eps}

	Size of the gate is $|C| = 13$.

	However, if we change the definition and allow multiple outputs, size is $|C| = 11$.
	%lecture 7 25:00
	\includegraphics[scale=0.4]{gate_1.eps}
\end{example}

\begin{observation}
	If we allow gates with $k$ inputs or outputs, the equivalent binary circuit will have $(k - 1)$ gates.
	Depth of the tree can be optimized by balancing.

	%lecture 7 26:29
	\includegraphics[scale=0.4]{gate_k.eps}
\end{observation}

\begin{note}
	Having gates with unlimited inputs can result in an exponential blowup.
\end{note}

Q: do we restrict the gates to binary? A: no, but we allow only finite?

\begin{note}
	Circuit with input of size $n$ can be viewed as an device that recognizes Language of binary words of length $n$.

	A sequence $\{C_n\}$ of circuits of various length is a device that recognizes some Language.
	Enormous switch by $n$.
\end{note}

\begin{notation}
	For circuit $C$ and input vector $x: C(x)$ is a value of the output gate.
\end{notation}

\begin{definition}[Family of circuits]
	Let $T$ be a function. A family of circuits of size $T(n)$ is a sequence of circuits $\{C_n\}_{n \in \N}$.
	Where
	\[ \forall n \in \N: C_n\ \text{has n inputs}\ \& |C_n| \leq T(n) \]

	Language $L$ is in class SIZE$(T(n))$ is there exists a family of circuits $\{C_n\}$ of size $T(n)$ such that
	\[ \forall x \in L \iff C_n(x) = 1 \]
\end{definition}

Q: $T$ is a boolean function?

\begin{example}
	\[ L = \{ 1^n |\ n \in \N \} \]
	Then $L \in $ SIZE$(\bigO(n))$.

	The circuit is a conjunction of all inputs.
\end{example}

\begin{example}
	\[ L = \{ (i, j, i + j) |\ i, j \in \N \} \]
	Then $L \in $ SIZE$(\bigO(n))$.

	The circuit performs binary addition of $i$ and $j$, then compare with $i + j$.
	Binary addition can be done by circuit of linear size.
\end{example}

\begin{definition}[$\Ppoly$ class]
	\[ \Ppoly = \bigcup^{\infty} SIZE (n^i) \]
	Class of languages recognizable by families of circuits of polynomial size.
\end{definition}

\begin{definition}[Oblivious DTM]\label{obliv_dtm}
	If $L$ is recognizable by DTM M in time $p(n)$ then it is also recognizable by DTM $M_1$ with single work tape with time complexity $p^2(n)$.
	Moreover, the head movement of $M_1$ are independent of the contents of its tapes but only on the input length ($M_1$ always performs a sequence of left to right and back sweeps of the same form regardless of what is the input).

	Source ~\cite[p. 37]{arora2009computational}.
\end{definition}

\begin{theorem}[$\TP \subseteq \Ppoly$]\label{tp_ppoly}
	$\TP \subseteq \Ppoly$.
\end{theorem}
\begin{proof}
	Idea: for fixed input length $n$ TM can be simulated by polynomial size circuit.
	The only problem is to get the symbol from work/input tape without storing the whole tape.
	Which is solved by the previous configuration with current symbol.

	Let $L \in \TP$ be arbitrary. WLOG there is an oblivious DTM M \cref{obliv_dtm} such that $L = L(M)$.
	$M$ works in time $T(n)$, where $T$ is a polynomial.
	WLOG $T(n)$ is the exact time $M$ needs for computation.
	We can choose $T(n)$ by trying different polynomials in parallel with $M$ using the fact, that polynomials are \emph{time constructible}.

	Knowing that TM did exactly $T(n)$ steps tells us that there were $T(n)$ displays (state, input symbol, work tape symbol).

	Let $|x| = n$ be input, let
	\[ d_1, d_2, \ldots, d_{T(n)} \]
	be binary string encoding displays during the computation of $M$ on $x$.

	% lecture 7 01:20:00
	Since $M$ is \emph{oblivious}, the position of the head $i$ uniquely defines the position $i_v, i_p$.
	Because the position of the head is uniquely determined by the \# of steps.

	$i_v, i_p$ are the display indexes the last time the input head was in the same position and the work head was in the same position as in $d_i$.
	The gates representing the displays $d_{i_v}$ and $d_{i_p}$ are the inputs to the gate $C_i$.
	It can also happen, that next symbol under the head has not been seen during the computation yet.
	For such case, we add one more input $x_j$ - input bit.

	Similarly, $i_p$ should not be defined.
	However, we assume that work tape is blank before the computation and symbol is also blank.

	We should add one more gate that check whether TM finished in accepting state.
	Outputs 1 if was in accepting state and 0 o/w.

	Complexity: $|C_i| = \bigO(1) \Rightarrow |C| = \bigO(T(n))$.
\end{proof}

\begin{corollary}\label{tp_ppoly_cor}
	The family of circuits $\{C_n\}$ from previous theorem not only exists but also can be efficiently constructed.
	% todo missing word in place of ... lecture 7 01:29:50
	Meaning there exists DTM M which on the input $1^n$ (only marks the length) outputs a ... of $C_n$.
	Moreover M works in polynomial time and Log space.

	The only non-trivial thing in circuit construction is to compute indexes $i_v, i_p$ from $i$ and $n$.
	M outputs the circuit $C_i$ in $\bigO(\log n)$ time and space.

	Space is reused therefore total space complexity is also $\bigO(\log n)$.
	However, having $T(n)$ gates time complexity is $\bigO(T(n) \cdot \log n)$ which is polynomial.
\end{corollary}

\begin{note}[$\TP \nsupseteq \Ppoly$]
	$\TP \supseteq \Ppoly$ is not true since every unary language
	\[ L \subseteq \{ 1^n |\ n \in \N \} \]
	is in $\Ppoly$.

	If $1^n \in L \Rightarrow C_n$ is a tree of $\land$.
	Otherwise, $C_n$ outputs 0.

	On the other side
	\[ UHALT = \{ 1^n |\ n\ \text{is a Godel number of}\ \langle M, x \rangle: M(x) \downarrow \} \]
	is not in $\TP$ as it is a variant of Halting problem which is undecidable.

	Q: how can boolean circuit recognize UHALT? How to detect that that TM halts in this case?
\end{note}

\begin{definition}[$\TP$-uniform family circuits]
	A family of circuits $\{C_n\}$ is $\TP$-uniform if there exists DTM M which on input $1^n$ outputs the description of $\{C_n\}$ and works in polynomial time.
\end{definition}

\begin{theorem}[$\TP$-uniform family circuits]
	$L$ is accepted by $\TP$-uniform family of circuits $\iff L \in \TP$.
\end{theorem}
\begin{proof}
	"$\Rightarrow$". For an input $x$ DTM M will simulate DTM $M_g$ which outputs $C_n$ on $1^n$, guaranteed by uniformity.
	Then $M$ simulates $C_n$ on $x$.
	\[ x \in L(M) \iff C_n(x) = 1 \]

	"$\Leftarrow$". Follows from the corollary \cref{tp_ppoly_cor}.
\end{proof}

\begin{definition}[Log Space uniform family circuits]
	A family of circuits $\{C_n\}$ is $\TP$-uniform if there exists DTM M which on input $1^n$ outputs the description of $\{C_n\}$ and works in Log space.
\end{definition}

\begin{theorem}[Log Space uniform family circuits]
	$L$ is accepted by Log Space uniform family of circuits $\iff L \in \TP$.
\end{theorem}
\begin{proof}
	"$\Rightarrow$". For an input $x$ DTM M will simulate DTM $M_g$ which outputs $C_n$ on $1^n$, guaranteed by uniformity.
	Then $M$ simulates $C_n$ on $x$.
	\[ x \in L(M) \iff C_n(x) = 1 \]

	The only difference between current theorem and previous is an assumption on $M_g$.
	However, TM that works in Log space also works in polynomial time.

	"$\Leftarrow$". Follows from the corollary \cref{tp_ppoly_cor}.
\end{proof}

\subsection{Cook-Levin alternative proof}

\begin{definition}[CRT-SAT]
	CRT-SAT is a language of binary strings that encode boolean circuits which for \emph{some} input output 1.
	\[ CRT-SAT = \{ C |\ \exists n: C(n) = 1 \} \]
\end{definition}

\begin{lemma}[CRT-SAT $\in \TNP$]
	CRT-SAT $\in \TNP$.
\end{lemma}
\begin{proof}
	The certificate is the input for which $C(n) = 1$.
	Check by simulating circuit using DTM.
\end{proof}

\begin{lemma}[CRT-SAT $\in \TNP$-hard]
	CRT-SAT $\in \TNP$-hard.
\end{lemma}
\begin{proof}
	Let $L \in \TNP$ arbitrary.

	\[ L \in \TNP \iff \exists DTM M: x \in L \iff \exists b \in \{ 0, 1 \}^{p(n)}: M(x, b) = 1 \]
	M works in polynomial time, $b$ encodes the accepting branch of the NTM computation.

	From $\TP \subseteq \Ppoly$ \cref{tp_ppoly} exists $\{ C_n \}$ which recognizes the same language as $M$.
	For the pair $(x, b)$ of size $n + T(n)$ we have circuit $C_n$:
	\[ C_n(x, b) = 1 \iff M(x, b) = 1 \]

	For fixed $x$ we construct a circuit $C_n^x \in C_n$ by fixing the inputs of $C_n$ to $x$.
	Therefore $C_n^x$ has single input $b$.
	\[ x \in L \iff \exists b: M(x, b) = 1 \iff \exists b: C_n(x, b) = 1 \iff \exists b: C_n^x(b) = 1 \iff C_n^x \in CRT-SAT \]
\end{proof}

\begin{consequence}[CRT-SAT $\in \TNP$-complete]
	CRT-SAT $\in \TNP$-complete, follows from 2 previous lemma.
\end{consequence}

\begin{theorem}[Cook-Levin alternative proof]
\end{theorem}
\begin{proof}
	%Idea: $L \in \TNP \leftpropto CRT-SAT \leftpropto 3-SAT$.
	Idea: $L \in \TNP \to CRT-SAT \to 3-SAT$.

	Let $C$ be a circuit with input vertices $x_1, \ldots, x_n$ and gates $g_1, \ldots, g_n$.
	Where $g_n$ is an output gate.
	The next step is to identify vertices and gates with binary variables.

	Known as Tseitin encoding.
	\begin{itemize}
		\item if $g_i$ is NOT with single input $g_j$ then formula is XOR
			\[ (g_i \lor g_j) \land (\neg g_i \lor \neg g_j) \]

		\item if $g_i$ is AND with inputs $g_j, g_k$ then formula consists of 2 implications
			\[ (g_i \Rightarrow (g_j \land g_k)) \land ((g_j \land g_k) \Rightarrow g_i) \]
			Then convert to CNF
			\[ (g_i \Rightarrow (g_j \land g_k)) = g_i \Rightarrow g_j \land g_i \Rightarrow g_k = (\neg g_i \lor g_k) \land (\neg g_i \lor g_k ) \]
			The second part
			\[ ((g_j \land g_k) \Rightarrow g_i) = (\neg g_j \lor \neg g_k \lor g_i) \]
			Altogether
			\[ (\neg g_i \lor g_k) \land (\neg g_i \lor g_k ) \land (\neg g_j \lor \neg g_k \lor g_i) \]
		\item if $g_i$ is OR with inputs $g_j, g_k$ then formula consists of 2 implications:
			\[ (g_i \Rightarrow (g_j \lor g_k)) \land ((g_j \lor g_k) \Rightarrow g_i) \]
			Then convert to CNF
			\[ (g_i \Rightarrow (g_j \lor g_k)) = (\neg g_i \lor g_j \lor g_k)\]
			The second part
			\[ ((g_j \lor g_k) \Rightarrow g_i) = g_j \Rightarrow g_i \land g_k \Rightarrow g_i = (\neg g_j \lor g_i) \land (\neg g_k \lor g_i) \]
			Altogether
			\[ (\neg g_i \lor g_j \lor g_k) \land (\neg g_j \lor g_i) \land (\neg g_k \lor g_i) \]
		\item unit clause $(g_n)$.
	\end{itemize}
\end{proof}


\documentclass[a5paper]{article}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage[default,osfigures,scale=0.95]{opensans}
\usepackage[margin=2cm]{geometry}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1.2em}

\usepackage{booktabs}
\usepackage{array}
\newcolumntype{L}{>{$}l<{$}}
\usepackage[hidelinks]{hyperref}

\renewcommand{\t}{\tau}
\newcommand{\s}{\sigma}
\newcommand{\R}{\mathbb{R}}
\newcommand{\order}{\text{order}}

\newtheorem{lemma}{Lemma}

\begin{document}

\section*{Group algebra of the permutations of three things}

Finlay Thompson
\bigskip

The permutation group can be generated by two elements, $\t$ and $\s$,
of order two and three respectively.
\begin{align}
    < \t,\s \mid \t^2 = 1,\s^3 = 1, \s\t = \t\s^2 >
\end{align}
These elements generate the six element finite group $S_3$, the
simplest non-Abelian group of permutations.

\begin{table}[h]
\begin{center}
\begin{tabular}{L|LLLLLL}
       & 1       & \t     & \t\s   & \t\s^2 & \s     & \s^2   \\
\hline\addlinespace
1      & 1       & \t     & \t\s   & \t\s^2 & \s     & \s^2   \\
\t     & \t      & 1      & \s     & \s^2   & \t\s   & \t\s^2 \\
\t\s   & \t\s    & \s^2   & 1      & \s     & \t\s^2 & \t     \\
\t\s^2 & \t\s^2  & \s     & \s^2   & 1      & \t     & \t\s   \\
\s     & \s      & \t\s^2 & \t     & \t\s   & \s^2   & 1      \\
\s^2   & \s^2    & \t\s   & \t\s^2 & \t     & 1      & \s     \\
\end{tabular}
\end{center}
\caption{Multiplication table for six elements permutation group on
three elements.}
\end{table}

The group algebra $\R[S_3]$ is a six dimensional, semisimple,
associative algebra, which by Weddeburn's structure theorems, means
that it can be decomposed into three parts, corresponding to the tree
conjugacy classes $\{1\},\{\t,\t\s,\t\s^2\},\{\s,\s^2\}$.
\begin{equation}
    \R[S_3] = \R \oplus \R \oplus M_2(\R)
\label{eq:decomposition}
\end{equation}
The decomposition \autoref{eq:decomposition} can be constructed using
multiplication by three central idempotents.
\begin{align}
    \pi_0 &= \frac{1}{6}(1+\t)(1+\s+\s^2) \\
    \pi_1 &= \frac{1}{6}(1-\t)(1+\s+\s^2) \\
    \pi_2 &= \frac{1}{3}(2-\s-\s^2)
\end{align}
These elements satisfy the equations $\pi_i^2=\pi_i$, $\pi_i\pi_j=0$
when $i\neq j$. The decomposition corresponds to the three irreducible
representations of $S_3$.

The first projection $\pi_0$ maps is acted on uniformly as
the identity, $\rho_0(x)y = y$. This can be seen by, for example:
\begin{align*}
    \t \pi_0 &= \t\frac{1}{6}(1+\t)(1+\s+\s^2) \\
     &= \frac{1}{6}(1+\t)(1+\s+\s^2) \\
     &= \pi_0
\end{align*}
or
\begin{align*}
    \s \pi_0 &= \s\frac{1}{6}(1+\t)(1+\s+\s^2) \\
     &= \frac{1}{6}\s(1+\t)(1+\s+\s^2) \\
     &= \frac{1}{6}(\s+\s\t)(1+\s+\s^2) \\
     &= \frac{1}{6}(\s+\t\s^2)(1+\s+\s^2) \\
     &= \frac{1}{6}(\s(1+\s+\s^2) +\t\s^2(1+\s+\s^2))\\
     &= \frac{1}{6}((1+\s+\s^2) +\t(1+\s+\s^2))\\
     &= \frac{1}{6}(1+\t)(1+\s+\s^2) \\
     &= \pi_0
\end{align*}

The second representation is based on the sign function, that takes
each element to its sign, $\rho_1(x)y = (-1)^{(\order(x)-1)}y$. This
can be seen:
\begin{align*}
    \t \pi_1 &= \t\frac{1}{6}(1-\t)(1+\s+\s^2) \\
     &= \frac{1}{6}(\t-1)(1+\s+\s^2) \\
     &= \frac{-1}{6}(1-\t)(1+\s+\s^2) \\
     &= -\pi_1
\end{align*}
or
\begin{align*}
    \s \pi_1 &= \s\frac{1}{6}(1-\t)(1+\s+\s^2) \\
     &= \frac{1}{6}\s(1-\t)(1+\s+\s^2) \\
     &= \frac{1}{6}(\s-\s\t)(1+\s+\s^2) \\
     &= \frac{1}{6}(\s-\t\s^2)(1+\s+\s^2) \\
     &= \frac{1}{6}(\s(1+\s+\s^2) - \t\s^2(1+\s+\s^2))\\
     &= \frac{1}{6}((1+\s+\s^2) - \t(1+\s+\s^2))\\
     &= \frac{1}{6}(1-\t)(1+\s+\s^2) \\
     &= \pi_1
\end{align*}

The third representation can be understood by considering the two dimensional
subspace of $\{1,\s,\s^2\}_\R$ that is perpendicular to $1 + \s + \s^2$, with
the standard Euclidean metric. The element $\pi_2$ is part of this, and should
be associated to the identity element in $M_2(\R)$. Perpendicular to both
$\pi_2$ and $1+\s+\s^2$ is the element $\s-\s^2$. Considering the span of these
with $\t$ gets us the four dimensional space $M_2(\R)$.

\begin{align*}
\left(\begin{smallmatrix}1&0\\0&1\end{smallmatrix}\right)
    \sim \frac{1}{3}(2 - \s - \s^2) &\quad
\left(\begin{smallmatrix}1&0\\0&-1\end{smallmatrix}\right)
    \sim \frac{\t}{\sqrt3}(\s - \s^2) \\
\left(\begin{smallmatrix}0&1\\1&0\end{smallmatrix}\right)
    \sim \frac{\t}{3}(2 - \s - \s^2) &\quad
\left(\begin{smallmatrix}0&1\\-1&0\end{smallmatrix}\right)
    \sim \frac{1}{\sqrt3}(\s - \s^2)
\end{align*}

\begin{lemma}
    The isomorphism between $M_2(\R)$ and the image of $\pi_2$ contained in
    $\R[S_3]$ is given by:
    \begin{align*}
        E_{00} &\mapsto \frac{1}{6}\left(
          2 - \s - \s^2 + \sqrt 3 \t\s - \sqrt 3 \t\s^2 \right) \\
        E_{11} &\mapsto \frac{1}{6}\left(
          2 - \s - \s^2 - \sqrt 3 \t\s + \sqrt 3 \t\s^2 \right) \\
        E_{01} &\mapsto \frac{1}{6}\left(
          2\t -\t\s -\t\s^2 + \sqrt3\s - \sqrt3\s^2 \right) \\
        E_{10} &\mapsto \frac{1}{6}\left(
          2\t -\t\s -\t\s^2 - \sqrt3\s + \sqrt3\s^2 \right)
    \end{align*}
\end{lemma}

\textbf{Proof:} I will just look at the just two maps to see that they work:

\end{document}


\section{Conclusion}
\label{sec:conclusion}

In the preceding, we have demonstrated a
BIE framework for computing the eigenvalues
of the Stokes operator in the plane which
is robust and scalable.
%
To justify the
approach, we developed a uniqueness theory
for the oscillatory Stokes equations in
exterior domains in analogy with the
discussion of the Helmholtz equation in
\cite{colton1983integral}.
%
This lead to the primary theoretical
results of the paper which show that the
BIEs resulting from double layer and
combined-field representations of the
velocity field are
not invertible precisely when $k^2$ is
an eigenvalue on simply connected
and multiply connected domains, respectively.
%
As in \cite{zhao2015robust}, the costliness
of performing the nonlinear minimization
associated with computing these eigenvalues
can be alleviated by computing instead the
approximate zeros of the discrete Fredholm
determinant.

The results of this paper can be
extended in a number of ways.
%
The theory
extends directly to three dimensions, where
computational efficiency and numerical
implementation will be the primary concern.
%
In the numerical examples above, we
consider only domains with differentiable
boundaries for simplicity.
%
When using the eigenfunctions as a trial
basis for simulating the Navier--Stokes
equations~\cite{batcho1994generalized},
it is necessary to handle domains
with corners because the domains of interest
arise from domain decomposition, e.g.
dividing a larger domain into
quadrilaterals.
Fortunately, there has been recent progress
toward efficient discretization of the
layer potentials of elliptic operators
on domains with corners
\cite{helsing2008corner,serkh2016solution,rachh2017solution,helsing2018integral}
which makes the solution of such problems
tractable.
%
Of course, the theoretical considerations
are different for such domains.
%
Computing the Stokes eigenvalues of regions
with corners is the topic of ongoing
research.

As noted in the introduction, the
eigenvalues of the Stokes operator are
equivalent to the so-called
``buckling'' eigenvalues of the
biharmonic operator on simply connected
domains~\cite{kelliher2009eigenvalues}.
%
This can be seen through the stream function
formulation  of the oscillatory Stokes
equation, i.e. setting $\bu = \nabla^\perp \psi$
where $\psi$ now satisfies

\begin{equation*}
  -\Delta^2 \psi = k^2 \Delta \psi \quad \textrm{in} \quad \Omega\; .
\end{equation*}
Note that the buckling problem enforces the
clamped, or first Dirichlet, boundary
condition on $\psi$

\begin{equation*}
  \psi = \partial_\nu \psi = 0 \; \quad \textrm{on} \quad \Gamma.
\end{equation*}
On a multiply connected domain, there are
Stokes eigenfunctions which do not have a corresponding
clamped stream function, so that the
buckling eigenvalues are a subset of the Stokes
eigenvalues.
By adapting the approach of \cite{rachh2017integral},
a suitable layer potential representation of the
buckling problem can be derived based on the
oscillatory Stokes layer potentials.
%
This is the subject of a follow-up paper which is in
preparation.

There are some interesting questions to answer
on the use of Fredholm determinants in numerical
calculations.
%
As observed in \cite{zhao2015robust}, the
combined-field representation causes some
difficulty in that the Fredholm determinant
is not defined when the single layer, which
is not trace-class, is included.
%
Zhao and Barnett~\cite{zhao2015robust}
suggest looking into
representations of the form $\cI-2\cD
-2i\eta\cS^2-2\cW$,
which would have a well-defined Fredholm
determinant.
%
The relative performance of
such an approach should be explored.
%
Further, as discussed above, the
convergence of the determinant of
integral equations discretized with
panel-corrected schemes (as described in
\cref{sec:numerical}) is yet to be proved.
%
When addressing high frequency problems,
the fast-direct solver used to evaluate
determinants in this paper will no longer
have near-linear scaling~\cite{ho2012fast}.
%
The design of fast-direct solvers in this
regime is the subject of ongoing research, and
to the best of our knowledge, fast determinant
computation at high frequency is an open
question.
%
Finally, it is worth exploring alternatives
to the Fredholm determinant which perform well
for layer potentials that are not trace class
on the boundary or for problems at higher
frequencies.


\section{Reducibility Candidates}
One might ask, what is a good definition of a semantic type? - Rather than
attempting the proof of the fundamental lemma directly and then trying to
extract additional lemmas one might need about the semantic types, we follow
Girard's technique and characterize some key properties our semantic types need
to satisfy. If a semantic type satisfies these key properties, then our proof of the fundamental lemma will be straightforward. To put it differently, defining these key properties, will allow for a  a modular proof of the fundamental lemma.

% \begin{definition}[Reducibility Candidate] $\Gamma \vdash M \in \den{A}$ is a reducibility
%   candidate, if the following conditions hold
%   \begin{itemize}
%   \item $\CR 1:$ If $\Gamma \vdash M \in \den{A}$ then $M \in \SN$. % , i.e. $\den{A} \subseteq \SN$.% \\[0.5em]
%   \item $\CR 2:$ If $\Gamma \vdash M \in \SNe$ then $\Gamma \vdash M \in \den{A}$. % , i.e. $\SNe \subseteq \den{A}$. % \\[0.5em]
%   \item $\CR 3:$ If $\Gamma \vdash M \redSN M'$ and $\Gamma \vdash M' \in \den{A}$ then $\Gamma \vdash M \in \den{A}$, i.e . $\den{A}$ is closed under reduction.
%   \end{itemize}
% \end{definition}

% The last property is often also referred to as \emph{backward closed}. We show that that all semantic types $\den{A}$ satisfy the conditions above.

\begin{theorem}\label{thm:redcand}~
% For all types $C$, $\Gamma \vdash M \den{C}  \in \CR$, i.e. it satisfies the conditions $\CR_1$, $\CR_2$, and $\CR_3$.
  \begin{enumerate}
  \item\label{cr1} \CR 1: If $\inden{\Gamma}{M}{A}$ then $\Gamma \vdash M : A \in \SN$. % , i.e. $\den{A} \subseteq \SN$.% \\[0.5em]
  \item\label{cr2} \CR 2: If $\Gamma \vdash M : A \in \SNe$ then $\inden{\Gamma}{M}{A}$. % , i.e. $\SNe \subseteq \den{A}$. % \\[0.5em]
  \item\label{cr3} \CR 3: If $\Gamma \vdash M \redSN M' : A$ and $\inden{\Gamma}{M'}{A}$ then $\inden{\Gamma}{M}{A}$, i.e. backwards closure.
  \end{enumerate}
\end{theorem}
\begin{proof}
We prove these three properties simultaneously.
\\[1em]
\fbox{\CR \ref{cr1}.  If $\inden{\Gamma}{M}{C}$ then $\Gamma \vdash M : A \in \SN$.}
\\[0.5em]
By induction on the structure of $C$.

\paragraph{Case: $C =\base$}.\\
$\inden{\Gamma}{M}{\base}$ \hfill by assumption \\
$\Gamma \vdash M : \base \in \SN$ \hfill by def. of sem. interpretation for $\base$

\paragraph{Case: $C = A \arrow B$}.
\\
$\Gamma, x{:}A \vdash x : A \in \SNe$ \hfill by def. of $\SNe$\\
$\inden{\Gamma. x{:}A}{x}{A}$ \hfill by IH (\ref{cr2}) \\
% $\Gamma, x{:}A \models x : A$ \hfill by Lemma \ref{lm:closn} (Property \ref{cp2})\\
$\Gamma, x{:}A \ext{\id} \Gamma$ \hfill by def. of context extensions \\
% $\Gamma, x{:}A \models M  : A \arrow B$ \hfill by Semantic Weakening Lemma \ref{lm:sweak}\\
$\inden{\Gamma, x{:}A}{[\id]M~x}{B}$ \hfill by def. of  $\inden{\Gamma, x{:}A}{M}{A \arrow B}$\\
$\Gamma, x{:}A \vdash [\id]M~x : B\in \SN$ \hfill by IH (\CR \ref{cr1})\\
$\Gamma, x{:}A \vdash [\id]M : A \arrow B \in \SN$ \hfill by  Extensionality Lemma \ref{lm:pSN} \\% Lemma \ref{lem:psn} (Property \ref{pp6})\\
$\Gamma \vdash M : A \arrow B\in \SN$ \hfill by Anti-renaming Lemma \ref{lm:anti-renameSN}
\\[1em]
\fbox{\CR \ref{cr2}. If $\Gamma \vdash M : C\in \SNe$ then $\inden{\Gamma}{M}{C}$.}
\\[0.5em]
By induction on $\Gamma \vdash M : C \in \SNe$.

\paragraph{Case: $C=\base$}.\\
$\Gamma \vdash M : C \in \SNe$ \hfill by assumption \\
$\Gamma \vdash M : C \in \SN$ \hfill by def. of $\SN$\\
% $\Gamma \vdash M \hastype \base$ \hfill by assumption \\
$\inden{\Gamma}{M}{\base}$ \hfill by def. of semantic typing

\paragraph{Case: $C = A \arrow B$}.\\
Assume $\Gamma' \ext{\rho} \Gamma$ and $\inden{\Gamma'}{N}{A}$ \\
$\Gamma' \vdash N : A\in \SN$ \hfill by IH (\CR \ref{cr1}) \\
$\Gamma \vdash M : A \arrow B \in \SNe$ \hfill by assumption \\
$\Gamma' \vdash [\rho]M : A \arrow B \in \SNe$ \hfill by Renaming Lemma \ref{lm:renameSN} \\
$\Gamma' \vdash [\rho]M~N : B \in \SNe$ \hfill by def. of $\SNe$\\
$\inden{\Gamma'}{[\rho]M~N}{B}$ \hfill by IH (\CR \ref{cr2})\\
$\inden{\Gamma}{M}{A \arrow B}$ \hfill since $\inden{\Gamma'}{N}{A}$ was arbitrary
\\[1em]
\fbox{\CR \ref{cr3}.   If $\Gamma \vdash M \redSN M' : C$ and $\inden{\Gamma}{M'}{C}$ then $\inden{\Gamma}{M}{C}$}
\\[0.5em]
By induction on $C$.
\paragraph{Case: $C = \base$}.\\[0.5em]
$\Gamma \vdash M' : \base \in \SN$  \hfill since $\inden{\Gamma}{M'}{\base}$\\
$\Gamma \vdash M : \base \in \SN$ \hfill by closure rule for $\SN$\\
$\inden{\Gamma}{M}{\base}$ \hfill by definition of semantic typing

\paragraph{Case: $C = A \arrow B$}.
\\[0.5em]
Assume $\Gamma' \ext{\rho} \Gamma$,~$\inden{\Gamma'}{N}{A}$ \\
$\inden{\Gamma'}{M'[\rho]~N}{B}$ \hfill by assumption $\inden{\Gamma}{M'}{A \arrow B}$\\
$\Gamma \vdash M \redSN M' : A \arrow B$ \hfill by assumption \\
$\Gamma' \vdash [\rho]M \redSN [\rho]M' : A \arrow B$ \hfill by Renaming Lemma \ref{lm:renameSN}\\
$\Gamma' \vdash [\rho]M~N \redSN [\rho]M'~N : B$ \hfill by $\redSN$\\
$\inden{\Gamma}{[\rho]M~N}{B}$ \hfill by IH (\CR\ref{cr3})\\
$\inden{\Gamma}{M}{A \arrow B}$ \hfill since $\inden{\Gamma'}{N}{A}$ was arbitrary\\

\end{proof}

\section{Proving strong normalization}
As mentioned before, we prove that if a term is well-typed, then it is strongly normalizing in  two steps:

\begin{description}
\item[Step 1] If $\inden{\Gamma}{M}{A}$ then $\Gamma \vdash M : A \in \SN$.
\item[Step 2] If $\Gamma \vdash M : A$ and $\inden{\Gamma'}{\sigma}{\Gamma}$ then $\inden{\Gamma'}{[\sigma] M}{A}$.
\end{description}

The first part described in Step 1, is satisfied by the fact that $\inden{\Gamma}{M}{A}$ must be a reducibility candidate (Theorem \ref{thm:redcand}) and  by \CR \ref{cr1})  all terms in $\denot{A}$ are strongly normalizing. We now prove the second step, which is often referred to as the \emph{Fundamental Lemma}.
It states that if $M$ has type $A$ and we can provide ``good'' instantiation $\sigma$, which provides terms which are themselves normalizing for all the free variables in $M$, then $\inden{\Gamma}{[\sigma]M}{A}$.

\begin{lemma}[Fundamental lemma]
If $\Gamma \vdash M : A$ and $\inden{\Gamma'}{\sigma}{\Gamma}$
then $\inden{\Gamma'}{[\sigma]M}{A}$.
\end{lemma}
\begin{proof}
By induction on $\Gamma \vdash M : A$.

\paragraph{Case} $\D = \ianc{\Gamma(x) = A}{\Gamma \vdash x : A}{}$
\\[1em]
$\inden{\Gamma'}{\sigma}{\Gamma}$ \hfill by assumption \\
$\inden{\Gamma'}{[\sigma]x}{A}$ \hfill by definition of $[\sigma]x$ and $\inden{\Gamma'}{\sigma}{\Gamma}$

\paragraph{Case} $\D = \ibnc{\Gamma \vdash M : A \rightarrow B}{\Gamma \vdash N : A}{\Gamma \vdash M\;N : B}{}$
\\
$\inden{\Gamma'}{\sigma}{\Gamma}$ \hfill by assumption \\
$\inden{\Gamma'}{[\sigma]M}{A \rightarrow B}$ \hfill by IH\\
$\inden{\Gamma'}{[\sigma]N}{A}$ \hfill by IH\\
$\inden{\Gamma'}{[\sigma]M\;[\sigma]N}{B}$ \hfill by $\inden{\Gamma'}{[\sigma]M}{A \rightarrow B}$\\
$\inden{\Gamma'}{[\sigma](M\;N)}{B}$ \hfill by subst. definition \\

\paragraph{Case} $\D = \ianc{\Gamma, x:A \vdash M:B}{\Gamma \vdash \lambda x.M : A \rightarrow B}{}$
\\
$\inden{\Gamma'}{\sigma}{\Gamma}$ \hfill by assumption \\
Assume $\Gamma'' \ext{\rho} \Gamma'$ and $\Gamma'' \vdash N : A$  \\
$\inden{\Gamma''}{[\rho] \sigma}{\Gamma}$ \hfill by weakening \\
$\inden{\Gamma''}{([\rho]\sigma, N/x)}{\Gamma, x:A}$ \hfill by definition of semantic substitutions\\
$\inden{\Gamma''}{[[\rho]\sigma, N/x]M}{B}$ \hfill by IH \\
$\Gamma'' \vdash (\lambda x.[[\rho]\sigma,x/x]M)\;N \redSN [[\rho]\sigma, N/x]M$ \hfill by reduction $\redSN$ \\
$(\lambda x.[[\rho]\sigma,x/x]M) = [[\rho]\sigma](\lambda x.M)$ \hfill by subst. def\\
$\inden{\Gamma''}{([[\rho]\sigma]\lambda x.M)\;N}{B}$ \hfill by $\CR 3$ \\
$\inden{\Gamma'}{[\sigma](\lambda x.M)}{A \arrow B}$ \hfill since $\Gamma'' \ext{\rho} \Gamma'$ and $\Gamma'' \vdash N : A$  was arbitrary

\end{proof}

\begin{corollary}
If $\Gamma \vdash M : A$ then $\Gamma \vdash M : A \in \SN$.
\end{corollary}

\begin{proof}
Using the fundamental lemma with the identity substitution $\inden{\Gamma}{\textsf{id}}{\Gamma}$, we obtain  $\inden{\Gamma}{M}{A}$. By $\CR 1$, we know $\Gamma \vdash M \in \SN$.
\end{proof}

\newpage

\section{Extension: Unit type}
\label{sec:unit}
We will now extend our simply-typed lambda-calculus the unit type, written as $\one$.

\[
\begin{array}{llcl}
\mbox{Types}  & A & \bnfas & \ldots \mid \one\\
\mbox{Terms}  & M & \bnfas & \ldots \mid ()
\end{array}
\]

In particular, we extend our type-directed reduction rules and allow any term $M$ of type $\one$ to be reduced to $()$.

\[
  \begin{array}{c}
\ianc{M \not= ()}{\Gamma \vdash M \red () : \one}    {}
  \end{array}
\]

We extend our definition of $\SN$ and $\redSN$ as follows:

\[
  \begin{array}{c}
\ianc{}{\Gamma \vdash () : \one \in \SN}    {} \qquad
\ianc{\Gamma \vdash M : \one}{\Gamma \vdash M \redSN () : \one}{}
  \end{array}
\]

We omit here the extensions in the proofs about $\SN$, in particular the renaming, anti-renaming and substitution lemmas.

As $\one$ is simply a new base type, we simply say

\begin{center}
\begin{tabular}{lcl}
$\inden{\Gamma}{M}{\one}$ & iff & $\Gamma \vdash M : \one \in \SN$
\end{tabular}
\end{center}

We revisit our previous theorem \ref{thm:redcand} and highlight the cases for unit.

\begin{theorem*}
\CR 1: If $\inden{\Gamma}{M}{A}$ then $\Gamma \vdash M : A \in \SN$. % , i.e. $\den{A} \subseteq \SN$.%
\end{theorem*}

\begin{proof}
Induction on type $A$.

\paragraph{Case} $A = \one$.
\\[1em]
$\Gamma \vdash M : \one \in \SN$ \hfill by def. of $\inden{\Gamma}{M}{A}$

\end{proof}

\begin{theorem*}
\CR 2: If $\Gamma \vdash M : A \in \SNe$ then $\inden{\Gamma}{M}{A}$. % , i.e. $\SNe \subseteq \den{A}$. %
\end{theorem*}
\begin{proof}
Induction on $A$.

\paragraph{Case} $A = \one$.
\\[1em]
$\Gamma \vdash M : \one \in \SNe$ \hfill by assumption \\
$\Gamma \vdash M : \one \in \SN$ \hfill by def. of $\SN$\\
$\inden \Gamma M \one$ \hfill by def. of semantic interpretation of $\one$

\end{proof}

\begin{theorem*}
 \CR 3: If $\Gamma \vdash M \redSN M' : A$ and $\inden{\Gamma}{M'}{A}$ then $\inden{\Gamma}{M}{A}$, i.e. backwards closure.
\end{theorem*}
\begin{proof}
Induction on $A$.

\paragraph{Case} $A = \one$
\\[1em]
$\Gamma \vdash M' : \one \in \SN$ \hfill by assumption $\inden{\Gamma}{M'}{\one}$ \\
$\Gamma \vdash M \redSN M' : \one$ \hfill by assumption
$\Gamma \vdash M : \one \in \SN$ \hfill by def. of $\SN$

\end{proof}

We can now revisit the fundamental lemma.

 \begin{lemma}[Fundamental lemma]
 If $\Gamma \vdash M : C$ and $\inden{\Gamma'}{\sigma}{\Gamma}$
 then $\inden{\Gamma'}{[\sigma]M}{C}$.
 \end{lemma}
 \begin{proof}
 By induction on $\Gamma \vdash M : C$.

\paragraph{Case} $\D = \ianc{}{\Gamma \vdash () : \one}{}$
\\[1em]
$\Gamma \vdash () : \one \in \SN$ \hfill by def. of $\SN$\\
$\inden \Gamma {()} \one$ \hfill by def. of $\mathcal{R}_\one$\\

\end{proof}


\documentclass[../report/main.tex]{subfiles}

\begin{document}

% The asterix after \subsection disables section numbering
\subsection*{Algorithm Description}

This algorithm starts the salesman at a random city in the tour and repeatedly visits the nearest city until all have been visited. We implemented this algorithm in Python 3.5.  We first encountered the nearest neighbor algorithm when researching general TSP algorithms at ~\cite{wikipediaTSP} . We learned more through it's specific Wikipedia article at ~\cite{wikipediaNN} .

\subsection*{Algorithm Discussion}

We chose nearest neighbor because it is essentially greedy which makes a good choice for being efficient and quick. We found that this algorithm satisfies the 1.25 requirement for most cases.  Additionally, because it runs "fairly" fast for most input sizes, we were able to set it up to try each possible starting point.  For larger input sizes we had the algorithm write results every time it found a newer/better route.  This allowed us to find an acceptable route under 3 minutes (though there may have been better routes with unlimited time).  For the three example cases 2-opt found routes between 15\% and 22\% over optimal.  The algorithm runs in O($n^2$) time.

\subsection*{Algorithm Pseudo-code}

\begin{verbatim}
Nearest_Neighbor():
    cities = []
    // each city object has id, x and y attributes
    read data from input file into the cities array

    adjMatrix=[len(cities)][len(cities)]
    for i = 0 to len(cities) - 1:
        for j = i + 1 to len(cities):
            ij = dist(cities[i][j])
            adjMatrix[i][j] = ij
            adjMatrix[i][j] = ji

    min_tour_dist = MAX_INT
    min_tour_order = []

    for i = 0 to len(cities) - 1:
        tour_cities = copy of cities array values w/o references to orig array
        tour_order = []

        tour_order.append(tour_cities[i].id)
        tour_cities.remove(tour_cities[i])
        tour_distance = 0

        while tour_cities length > 0:
            cur_city = cities[tour_order[len(tour_order) - 1]]
            min_dist = MAX_INT
            min_city = -1

            for j = 0 to len(tour_cities) - 1:
                this_dist = adjMatrix[cur_city.id][tour_cities[j].id]

                if this_dist == -1:
                    this_dist = cartesian dist between cur_city and tour_cities[j]
                    adjMatrix[cur_city.id][tour_cities[j].id] = this_dist
                    adjMatrix[tour_cities[j].id][cur_city.id] = this_dist

                if this_dist < min_dist:
                    min_dist = this_dist
                    min_city = tour_cities[j]

            tour_order.append(min_city.id)
            tour_cities.remove(min_city)
            tour_distance = tour_distance + min_dist
        u = cities[tour_order[0].id]
        v = cities[tour_order[len(tour_order) - 1]].id
        this_dist = adjMatrix[u][v]
        if this_dist == -1:
            this_dist = distance between cities[tour_order[0]]
                        and cities[tour_order[len(tour_order) - 1]]
            adjMatrix[u][v] = this_dist
            adjMatrix[u][v] = this_dist

        tour_distance = tour_distance + this_dist

        if tour_distance < min_tour_dist:
            min_tour_dist = tour_distance
            min_tour_order = copy of tour_order's array by value

            write the output file to the path specified
\end{verbatim}

\end{document}


\chapter{First Notions of Category Theory}
\thispagestyle{empty}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\epigraph{“The human mind has never invented a labor-saving machine equal to algebra.” }{\textit{Stephan Banach (1925)}}

For us Category Theory is an area of interest on its own rights, rather than merely an elegant tool. Thus, we will introduce this theory with a point of view that emphasize the intuitive ideas behind each notion.\\

With this objective in mind, we will get into the habit of introducing the first examples even before introducing the formal definitions. Thus, when the formal definition is introduced it becomes meaningful.\\

The fundamental idea of Category Theory is that many properties can be unified if expressed in arrow diagrams. Intuitively, a diagram is a directed graph, such that each way of going from a node to another are equals. For example, the diagram:

\[
  \begin{tikzcd}
    & b \arrow[rd, "g"]& \\
    a\arrow[ru, "f"] \arrow[rr, "h", dashed] && c
  \end{tikzcd}
\]
Means that $f\circ g = h$. This approach to mathematics emphasises  at the relationships between elements, rather than at the structure of the elements themselves. In general, dashed lines means that the existence of that particular arrow is uniquely determined by the solid arrow presents in the diagram.\\

In this first chapter we introduce the notion of category and some useful properties. The principal references for this chapter are \cite{mac2013categories} and \cite{riehl2017category}. To show how categories can be used for programming we will illustrate several concepts with the programming language Haskell. Haskell references can be checked in \cite{milewski2018category}.

\section{Metacategories}
We will start by defining a concept independent of the set theory axioms: the concept of \emph{metacategory}. Then, categories will arise from studying these concepts within set theory. We follow  \cite{mac2013categories} for these definitions.\\

Traditionally, mathematics is based on the set theory. When we start set theory it is not necessary (it is not possible) to define what a set is. It is similar with the concepts of element and belonging, which are basic to set theory. Category theory can also be used to found mathematics. This theory provide meaning based on other concepts such as object, arrow or composition rather than sets or belonging. \\

\begin{definition} \label{def:metagraph}
  A \emph{metagraph} consist of \emph{objects}: $a,b,c..$ and \emph{arrows} $f,g,h...$. There are also two pairings: $\dom$ and $\codom$. This pairings assigns each arrow with an object. An arrow $f$ with $\dom(f)=a$ and $\codom(f)=b$ is usually denoted as $f:a\to b$.\\
\end{definition}

\begin{definition}
  A metacategory  is a metagraph with two additional operations and two properties:
  \begin{itemize}
  \item Operations:
    \begin{itemize}

    \item \emph{Identity}: assigns to each object $a$ an arrow $1_a:a\to a$.
    \item \emph{Composition}: assigns to each pair of arrows $f,g$ with $\codom(f)=\dom(g)$ and arrow $g\circ f$ such that the diagram:

      \[
        \begin{tikzcd}
          & b \arrow[rd, "g"]& \\
          a\arrow[ru, "f"] \arrow[rr, "g\circ f",swap, dashed] && c
        \end{tikzcd}
      \]

      commutes. The arrow $g\circ f$ is called the \emph{composite} of $f$  and $g$.
    \end{itemize}

  \item Properties:
    \begin{itemize}
    \item \emph{Associative}: given arrows $f,g,h$, we have that,
      $$(g\circ f) \circ h = g \circ (f \circ h).$$
    \item \emph{Unit}: given an object $a$, and arrows $f,g$ such that $\dom (f)= a$ and $\codom (g) = a$, we have that,
      $$1_a \circ g = g, \qquad f \circ 1_a = f.$$
    \end{itemize}
  \end{itemize}
  In the context of categories and metacategories, arrows are often called \emph{morphisms}.
\end{definition}

We have just define what a  metacategory is without any need of set and elements. In most cases we will rely in a set theory interpretation of this definitions, as most examples (specially with our interest in computational example) will rely on this theory. Nonetheless, whenever possible, we will define the concepts working only in terms of objects and arrows.\\

% Diagramas de existencia condicionada.!!
% We will also need diagrams that represents the existence of arrows due to the existence other arrows. , given objects $a,b,c$ and arrows $d$

\section{Set theory categories}
Despite being an alternative foundation of mathematics, in general we will work with categories interpreted with notions of set theory. Unless otherwise stated, we will use the Zermelo-Fraenkel-Gödel axiomatics with Axiom of Choice. In this we are going to difference between \emph{small sets} and \emph{classes}. Sets that are not small are called \emph{large sets}. We recommend \cite{kunen2014set} for more information.\\

We have no interest in this work in the reformulation of axioms. Note that  we have defined a meta-category without the need for notions of sets. In the same way,  many definitions and propositions relating to this theory can be considered without the need for notions of sets.\\

From now on, we will work based on set theory. Despite that, it is useful to take into account that most of the concept here presented can be defined without making use of this Theory.

\begin{definition}
  A category (resp. graph) is an interpretation of a metacategory (resp. metagraph) within a set theory.
\end{definition}

\footnote{{\color{black} There is a discussion here that must be addressed at the end}}That is, a graph/category is a pair $(O,A)$ where a collection $O$ consisting of all objects as well as a collection $A$ consisting of all arrows. Their elements hold the same properties that objects and arrows hold on metacategories / metagraph.\\

We will focus on the category. First, we define the function homeset of a category $C=(O,A)$, wrote as $\hhom_{C}$, as the function:
\begin{align*}
  && \hhom_{C}: O \times O &\mapsto \mathcal{P}(A)&\\
  \displaystyle &\ &(a,b)&\mapsto \{f\in A | f:a\to b\}&
\end{align*}

We will refer to the collection of objects of a category $C$ as $Ob(C)$ and the collection of arrows as $Ar(C)$. When there is no possibility of confusion we will state $c\in C$ meaning either $c\in Ob(C)$ or $c\in Ar(C)$.

\begin{definition}
  We say that a category is \emph{small} if the collection of objects is given by a set (instead of a proper class). We say that a category is \emph{locally small} if every homesets is a set.
\end{definition}

We proceed to introduce a comprehensive list of examples, so that it is already introduced in subsequent chapters.
\begin{example}

  \begin{itemize}  \
  \item The elementary categories:
    \begin{itemize}
    \item The category $0 = ( \emptyset, \emptyset)$ where every property of metacategories is trivially satisfied.
    \item The category $1 = (\{e\},\{1_e\})$.
    \item The category $2 = (\{a,b\},\{1_a,1_b,f:a\to b\})$\label{2-category}
    \end{itemize}

  \item Discrete categories: are categories where every arrow is an identity arrow. This are sets regarded as categories, in the following sense: every discrete category $C=(A, \{1_a : a \in A\})$ is fully identified by its set of object.
  \item Monoids and Groups: A monoid is a category with one object (regarding the monoid of the arrows). In the same way, if we requires the arrows to be invertible, we can see a group as a single-object category.
  \item Preorder: From a preorder $(A, \le)$ we can define a category $C = (A, B)$ where $B$ has an arrow $e: a \to b$ for every $a,b\in A$ such that $a \le B$. The identity arrow is the arrow that arise from the reflexive property of the preorders.

  \item Large categories: these categories have a large set of objects. For example:
    \begin{itemize}
    \item The category $Top$ that has as objects all small topological spaces and as arrow continuous mappings.
    \item The category $Set$ that has as objects all small sets and as arrows all functions between them. We can also consider the category $Set_*$ of pointed small sets (sets with a distinguish point), and functions between them that maps preserving the marked point. This category, when restricted to finite sets, is known as $FinSet$.
    \item The category $Vect$ That has as object all small vector spaces and as arrows all the linear functions.
    \item The category $Grp$ that has as object all small vector group and as arrows all the homomorphism.
    \item The category $Top_*$ that has as object all small topological spaces with a distinguished point, and as arrows all the continuous functions that maps each distinguished points into distinguished points. Similarly we can consider $Set_*$ or $Grp_*$.
    \item The category $Grph$ that has as objects all small graphs, and as arrows all graphs morphisms.
    \end{itemize}

  \item The category $Hask$ of all Haskell types and all possible functions between two types.\\

  \end{itemize}
  Note that, for example, as natural numbers can be seen as either a set or a preorder, they also can be seen as a discrete category or a preorder category.
\end{example}

Simple enough categories can be easily described with graphs: there are as many objects as nodes in the diagram and an arrow in the category for each:
\begin{itemize}
\item Arrow in the graph.
\item Composition of existing arrows.
\item Every node (identity arrow usually omitted in diagrams).
\end{itemize}

For example, we can fully represent the $2$ category with the diagram:

\[
  \begin{tikzcd}
    a\arrow[rr, "g"] && c\\
  \end{tikzcd}
\]

\subsection{Properties}

We can see that is common in mathematics to have an object of study (propositional logic clauses, groups, Banach spaces or types in Haskell). Once the purpose of studying these particular sets of objects is fixed, it is also common to proceed to consider the transformations between these objects (partial truth assignments, homomorphisms, linear bounded functionals or  functions in Haskell).\\

In categories, we have a kind of different approach to the subject. Instead of focusing on the objects themselves, we focus on how do they relate to each other. That is, we focus on the study of the arrows and how they composes. Therefore we can consider equal two objects that has the same relations with other objects. This inspire the next definition:

\begin{definition}\cite[Definition 1.1.9]{riehl2017category}
  Given a category $C=(O,A)$, a morphism $f: a \to b \in A$ is said to have a \emph{left inverse} (resp. \emph{right inverse}) if there exists a $g: b \to a \in A$ such that morphism $g \circ f = 1_b$ (resp. $f \circ g = 1_a$). A morpishm is an \emph{isomorphism} if it has both left and right inverse, sloppily called the \emph{inverse}. Two object are isomorphic is there exists an isomorphism between them.
\end{definition}

Is easy to follow that if a morphism has a left and a right inverse, they must be the same, thus implying the uniqueness of the inverse. Also one can see that this functions define, by precomposition, bijections between $\hhom(a,c)$ and $\hhom(b,c)$ for all $c\in O$.\\

We will now proceed to talk about certain arrows and objects that have properties that distinguish them from others.  The most useful example to gain an intuition of these properties is that of the $FinSet$ category, of all finite sets and functions between them.  Considering special arrows:\\

\begin{definition} An arrow $f$ is  \emph{monic} (resp. \emph{epic}) if it is \emph{left-cancelable} (resp. \emph{right-cancelable}), i.e.  $f\circ g = f \circ h \implies g = h$ (resp. $g\circ f = h \circ f \implies g = h$).
\end{definition}

In $FinSet$ these arrows are the injective functions (resp. surjective). Considering special objects:

\begin{definition}
  an object $a$ is \emph{terminal} (resp. \emph{initial}) if for every object $b$ there exists an unique arrow $f:b\to a$ (resp. $f:a\to b$).  An object that is both terminal and initial is called \emph{zero}.
\end{definition}

In $FinSet$ the initial object is the  empty set and the terminal object the one point set.

\begin{proposition}\label{terminal-proposition}
  Every two terminal object are isomorphic.
\end{proposition}
\begin{proof}
  Every terminal object has only one arrow from itself to itself, and necessarily this arrow has to be the identity. Let $a, b$ be terminal object and $f:a\to b$ and $g:b\to a$ be the only arrows with that domain and codomain. Then $f\circ g : a \to a \implies f \circ g = 1_a$. Analogously $g \circ f = 1_b$.\\
\end{proof}

% \subsubsection{Duality}
Another important property is the \emph{duality property}. This property tell us that for every theorem that we prove for categories, there exist another theorem that is automatically also true, by inverting the direction of the arrows. To formalize this idea, we define the concept of \emph{opposite category}.

\begin{definition}\cite[Definition 1.2.1]{riehl2017category}
  Let $C$ be any category. The opposite category $C^{op}$ has:
  \begin{itemize}
  \item the same objects as $C$,
  \item an arrow $f^{op}:b \to a\in C^{op}$ for each arrow $f: a\to b \in C$, so that the domain of $f^{op}$ is defined as the codomain of $f$ and viceversa.
  \end{itemize}
  The remaining structure of the category $C^{op}$ is given as follows:
  \begin{itemize}
  \item For each object $a$, the arrow $1_a^{op}$ serves as its identity in $C^{op}$.
  \item We observe that $f^{op}$ and $g^{op}$ are composable when $f$ and $g$ are, and define $f^{op} \circ g^{op} = (g \circ f)^{op}$.
  \end{itemize}
\end{definition}

The intuition is that we have the same category, only that all arrows are turned around. We can see that  for each theorem $T$ that we prove, we have reinterpretation that theorem to the opposite category. Intuitively this theorem is an equal theorem in which all the arrows have been turned around. For example: the proposition
\ref{terminal-proposition} can be reworked as:

\begin{proposition}\label{prop:initial}
  Every two initial object are isomorphic.
\end{proposition}

That is because being initial is the dual property of being terminal, that is, if $a\in C$ is a terminal object then $a\in C^{op}$ is an initial object. The property ``being isomorphic'' is its own dual.

\subsection{Transformation in categories}

% \subsubsection{Functors}
One of the main ways of defining a category is considering as object every small set with an structure (e.g. groups, monoids, vector spaces), and as morphism all functions that preserve structure. Then, we may also follow our study defining the structure preserving transformation of categories.

\begin{definition}
  Given two categories $C, B$, a \emph{functor} $F: B \to C$ is a pair of functions $F=(F':Ob(C)\to Ob(B),F'':Ar(C)\to Ar(B))$ (the \emph{object functor} and the \emph{arrow functor} respectively) in such a way that:
  $$F''(1_c) = 1_{F'c}, \ \forall c \in Ob(C), \qquad F''(f\circ g) = F''f \circ F''g, \ \ \forall f:a\to b,g: b\to c  \in Ar(C).$$

\end{definition}

Roughly speaking,  a functor is a morphism of categories. When there is no ambiguity we will represent both $F'$ and $F''$ with a single symbol $F$ acting on both objects and arrows. Also, it can be seen in the definition that whenever possible the parentheses of the functor will be dropped. This loss of parentheses will be replicated throughout the text, whenever possible.\\

\begin{remark}
  A functor $F$ can be defined only pointing out how it maps arrows, as how $F$ maps object can be defined with how it map identity arrows.
\end{remark}
Lets provide some examples of functors:\\

\begin{example}\
  \begin{itemize}
  \item {Forgetfull functor}: We have a variety of categories consisting of structures with sets as objects and functions that hold structure such as arrows (eg Top, Grp or Vect).\\

    Let $C$ one of such  categories, then we have a functor $F:C\to Set$ that maps each object to its underlying set and each arrow to the equivalent arrow between sets. That is, this functor forgets about the structure that is present in $C$.\\

    Additionally, we will often have functors defined $F:C\to Set$. For some cases of $C$ it also happen that the image of $Ob(C)$ by $F'$ has some more structure on it. In that case we will say that $F$ is an enriched functor for that cases.\\

    Another similar case of Forgetful functor is $\mathcal{U}:Cart \to Grph$ that maps each (small) category to their \emph{underlying} graph.
  \item Fundamental group: In the context of algebraic topology we have the functor of the fundamental group $\Pi_1: Top_* \to Grp$. The most famous property of this function is that

   \begin{displayquote}
      ``Given continuous application $ f,g:X \to Y$ between two topological spaces induces an application of the group of loops of $X$ on the group of loops of $Y$ such that $\Pi_1(f \circ g) = \Pi_1(f) \circ \Pi_1(g)$.''
   \end{displayquote}

    that is, the functoriality of the function (taking also into account the fact that the identity of topological spaces is mapped to the identity of group).

  \item Stone-\v{C}ech compactification\label{example:stone-cech}:  From the realm of functional análisis we have the following theorem:

    \begin{theorem} Let $\mathbb{K}=\mathbb R $ or $\mathbb C$ and let $\Omega$ be a completely regular Hausdorff topological space. Then there exists a compact Hausdorff topological space $\beta \Omega$ and a homeomorphism $\Phi$, from $\Omega$ to a dense subset of $\beta\Omega$. Moreover, for every continuous and bounded function $f: \Omega \to K$ there exists a unique $\overline{f} \in C(\beta \Omega)$ such that $\overline{f}\circ \Phi = f$ and the application $f \to \overline{f}$ is an isomorphism. Finally, $\beta \Omega$ is uniquely determined up to isomorphism by the above properties.
    \end{theorem}

    \begin{proof}
      We define the functional $\Delta: \Omega \to \Omega^{**}$   such that $\Delta(t)=\delta_t$ where $\delta_t(f) = f(t)$ is Dirac's operator .  It is enough to take as $\beta \Omega$ the closure of $\Delta(\Omega)$ in the induced weak-topology $\omega^*$ of $\Omega^{**}$ (since in the weak topology we have that a bounded closed is compact).

      Given a continuous and bounded function $f:\Omega \to\mathbb K$ we can define the function $\overline{f}$ by injection of $\Omega$ and then limit to maintain continuity (which will exist by compactness and boundedness of $f$). Thus the maximum of $\overline{f}$ can be reached by a sequence of points injected from  $\Omega^{**}$ obtaining that
      $${\displaystyle\max\left\{|\ \overline{f}\ (s)\ | : s \in \beta\Omega\right\} = \sup\left\{| f(s) |: s \in \Omega\right\}}.$$

      The application $f \mapsto \overline{f}$ is therefore an isometric isomorphism. Thanks to this isometric isomorphism the function spaces and by the Banach-Stone theorem\cite[Theorem 3]{banach1932theorie} we have uniqueness up to isomorphisms.
    \end{proof}

    Based on this theorem we can define a functor  $\beta:Hauss \to Comp$ where $Hauss$ is the category of Completely regular Haussdorff  Spaces and continuous functions, and $Comp$ the category of Compact Haussdorff Spaces along with continuous function. This functor:
    \begin{itemize}
    \item Take an object $\Omega \in Hauss$ to $\beta(\Omega) = \beta\Omega$:
    \item Take an arrow $f:\Omega \to \Omega'\in Hauss$ to $\Delta(f)$ and the complete it by continuity as in the previous proof.
    \end{itemize}

    % {\color{red} Question}: I want to include this example of functor in order to later reuse it in universality section (opening of chapter 2).\\

    % I'm having a bit of trouble doing this though, as I do not see how does it maps arrows. I have found this proof of its functoriality:

    % \begin{displayquote}
    %   As is usual for universal constructions like this, the extension property makes $\Beta$ a functor from $Top$ (the category of topological spaces) to $CHaus$ (the category of compact Hausdorff spaces).
    % \end{displayquote}

    % However, I was hoping to provide a more elemental proof, so I will continue looking. If nothing is founded, there will be no problem to drop this example, or to explain directly when extension property is explained.
    % {\color{red} End Question}

  \item Group actions:\label{group-action} Every group action can be seen as a functor from a Group to a Set.\\

    Let $G$ be a group seen as a category with only one element and let $X$ be a set seen as a discrete category. Then, an action is a representation of the group of the endomorphism of the set, that is, an action $\alpha$ associate each element of the group with an function $\alpha(g):X\to X$ such that the product of element of the group is maintain via composition. That is for $g\in Ar(G)$ we have that $\alpha(g) \in Ar(X)$  and for all $ g,f\in Ar(G):$
    $$\alpha(g\circ f) = \alpha(g) \circ \alpha(f).$$

    Notice that, by the definition of $G$, the composition $g\circ f$ actually correspond to the product in $G$.

    Note that is a group seen as a category the product is the composition thus having the functoriality.\\

  \item \texttt{Maybe} Method in Haskell \cite[Section 7.1]{milewski2018category}: In Haskell the definition of Maybe is a mapping from a type $a$ to a type $\maybe  a$. We define the BN notation used in the example in \ref{def:BN-Notation}.

    \begin{center}
      \begin{lstlisting}[language=Haskell,caption={Declaration of Maybe},captionpos=b]
        data Maybe a = Nothing | Just a
      \end{lstlisting}
    \end{center}

    Note that \texttt{Maybe a} is not a type but a function of types. In order for it to be an endofunctor of the $Hask$ category we will need for it to also map function. Let $f: a \to b\in Hask$, then we define the function
    $$\maybe  f: \maybe a \to \maybe b$$
    such that
    $$(\maybe  f) (Nothing) = Nothing, \qquad (\maybe f) (Just\  a) = Just\  f(a).$$
    Note that $(\maybe id_a) (\maybe a) = Nothing\  |\  Just\  id_a(a) =  \maybe a$.
  \end{itemize}
\end{example}

We can now construct the category of all small categories $Cat$. This category has as object all small categories and as arrows all functor between them. Note that $Cat$ does not contain itself, since it is a large category.\\

We can consider some properties in functors. Note that we can consider a functor $T:C\to D$ as a set function over homeset, that is, a function:
$$T:\hhom_C(a,b) \to \{Tf: Ta \to Tb | f \in C\} \subset \hhom_D(Ta,Tb)$$

\begin{definition}
  A functor $T:C\to D$ is \emph{full} if it is surjective as a function over homesets, i.e. if the function $T:\hhom_C(a,b) \to  \hhom_D(Ta,Tb)$  is surjective for every $a,b \in C$. A functor is \emph{faithfull} if it is injective over homesets.
\end{definition}

We can consider functors $T:C^{op} \to D$. It is customary to refer to this type of functions a \emph{contravariant} functor from $C$ to $D$ and regular functors $F:C\to D$ as \emph{covariant}.

% \subsubsection{Natural Transformations}

We shall continue defining natural transformation. In the words of Saunders Mac Lane:

\begin{displayquote}
  ``Category has been defined in order to define functor and functor has been defined in order to define natural transformation.''
\end{displayquote}

One can see a functor $T:C\to D$ as a representation of a category in another, in the sense that a functor provide a picture of the category $C$ in $D$. Further into this idea, we can consider how to transform these drawings into each other.

\begin{definition}
  Given two functor $T,S:C\to D$, a \emph{natural transformation} $\tau : T \Rightarrow S$ is a function from $Ob(C)$ to $Ar(D)$ such that for every arrow $f:c \to c' \in C$ the following diagram commutes:
  \[
    \begin{tikzpicture}
      \node {\begin{tikzcd}[column sep=20mm]
          Tc\ar[r,"\tau c"]\ar[d,"Tf"] & Sc\ar[d,"Sf"]\\
          Tc'\ar[r,"\tau c'"] & Sc'\ .
        \end{tikzcd}};
    \end{tikzpicture}
  \]

 A natural transformation where every arrow $\tau c$ is invertible is called a \emph{natural equivalence} and the functors are \emph{naturally isomorphic}.
\end{definition}
\begin{remark}
  In come context, subindex $\tau_c$ are used to note natural transformation, specially when working in composition with other arrows.
\end{remark}

That is a natural transformation is a map from pictures of $C$ in to pictures of $D$. Note that a natural transformation acts only on the domain of objects. Lets provide some examples.\\

When we have to define natural transformations  it will often be useful to define each arrow individually. In this case, with the same notation as in the definition,  we will note $\tau c = \tau_c: Tc \to Sc$.

\begin{example}\
  \begin{itemize}
  \item The opposite group: We can define the opposite functor $(\cdot)^{op}: Grp \to Grp$ that maps $(G, *)$ to $(G; *^{op})$ where $a*^{op}b= b*a$ and maps a morphism $f: G \to G'$ to $f^{op}(a) = f(a)$ and have that
    $$ f^{op}(a*^{op}b) = f(b*a) = f(b)*f(a) = f^{op}(a) *^{op} f^{op}(b).$$

    Denoting the identity function $Id:Grp\to Grp$, we have a natural transformation $\tau:Id \Rightarrow (\cdot)^{op}$ defined by $\tau_G(a)=a^{-1}$ for all $a\in G$.

  \item In Haskell, the $\operatorname{safeHead}$ \cite[Section 10.1]{milewski2018category} function between the $\operatorname{List}$ functor and the $\maybe$ functor. To be precise,
    \begin{itemize}
    \item The $\operatorname{list}$ functor maps the type $a$ to the type $[a]$ and assigns each function $f:a\to b$ to $f':[a]\to [b]$ that applies $f$ elements wise (on empty list it does nothing).
      \begin{lstlisting}[language=Haskell,captionpos=b]
        data List a = Nil | Cons a ( List a)
      \end{lstlisting}
    \item  With this definition, we can define the natural transformation $\operatorname{SafeHead}: \operatorname{List} \to \operatorname{Maybe}$ as:
      \begin{lstlisting}[language=Haskell,captionpos=b]
        safeHead :: [a] -> Maybe a
        safeHead [] = Nothing
        safeHead (x : xs) = Just x
      \end{lstlisting}

      or in category notation:  $\tau : List \to Maybe$ such that, for every type $a$:
      $$\tau a ([]) = \operatorname{Nothing}, \qquad \tau a (x:xs) = \operatorname{Just} x.$$
    \end{itemize}
  \end{itemize}
\end{example}

\subsection{Constructions}
In this last subsection we will introduce some standard construction on categories, along with some examples of these constructions.

\subsubsection{Product Category}
We present now one of the most usual construction in mathematics: the product. We will additionally consider the ``universal'' properties of product on the next chapter.

\begin{definition}
  Let $B,C$ be categories. Then the \emph{product category} $B\times C$ is the category that has as objects the pairs $\{\langle b,c\rangle : b \in Ob(B), c\in Ob(C)\}$ and as arrows the pairs of arrows $\{\langle f,g\rangle: f \in Ar(B), g\in Ar(C)\}$. The composition of arrows is defined by the elementwise composition.
\end{definition}

It is clear that we can define two functors $P: B\times C \to B$ and $Q: B \times C \to C$ that restricts the category to each of its component parts (functorial axioms follow immediately). Moreover, we can see that any functor $F:D\to B\times C$ will be uniquely identified by its composition with $P$ and $Q$.\\

Complementary, for any two functors $F:D\to B, G:D\to C$ we can define a functor $F \times G : D \to B\times C$ that maps $(F\times G) \langle f,g\rangle = \langle Fg, Gg\rangle$. Expressed as a diagram:

\[
  \begin{tikzcd}
    {} & D
    \arrow[swap, "F"]{ddl}
    \arrow[dashed, "F\times G"]{dd}
    \arrow["G"]{ddr}\\
    {} & \\
    B & B \times C
    \arrow["P"]{l}
    \arrow["Q"]{r} & C
  \end{tikzcd}
\]

A functor $F: B^{op}\times C \to D$ is called  a \emph{bifunctor}. Arguably the most important bifunctor is the $\hhom_C$ function. Given a category $C$ we can see $\hhom_C: C^{op}\times C \to Set$ as a bifunctor such that for all $a,b \in Ob(C)$:
\[
  \hhom_C(\cdot,\cdot)(a,b) = \hhom_C (a,b)
\]
for the objects. For the arrows, for all $f:a\to a', g:b\to b' \in C$ and for all $h\in \hhom_C(a',b)$:
\begin{align*}
  \hhom_C(f^{op},g): \hhom_C (a',b)  & \to \hhom_C(a,b'), \\
  \hhom_C(f^{op},g) (h)   &= g \circ h \circ f.
\end{align*}

From this bifunctor for every  $c\in Ob(C),g:d\to d' \in C, h\in \hhom_C(c,d)$ we can define two functors:
\begin{itemize}
\item  The functor $\hhom_C(c, \cdot):C\to Set$ such that for all $d \in Ob(C)$:
  \[
   \hhom_C(c,\cdot) = \hhom_C (c,d),
 \]
 and
  \begin{align*}
    \hhom_C(c,g): \hhom_C (a,d) & \to \hhom_C(a,d'),\\
    \hhom_C(c,g) (h)   &= g \circ h .
  \end{align*}
This functor is often called the \emph{post-composition} functor.
\item  Analogously, we can define the contravariant functor $\hhom_C(\cdot, c):C^{op}\to Set$, defined analogously.This functor is often called the \emph{pre-composition} functor.
\end{itemize}
\subsubsection{Functor Categories}
We continue by defining functor categories, that is, categories where we consider the functors as objects and natural transformation as arrows in some sense. This concept will be instrumental in further consideration in the domain of functional programming (in particular, in the definition of a monad).\\

Before explaining composition between natural transformation, it is useful to present the following diagram. Let $B,C$ be categories, $F,G:B\to C$ be functors and $\tau:F\to G$ a natural transformation. It is common to represent this structure with:
\[
  \begin{tikzcd}[column sep=huge]
    A
    \arrow[bend left=40]{r}[name=F,label=above:$\scriptstyle F$]{}
    \arrow[bend right=40]{r}[name=G,label=below:$\scriptstyle G$]{} &
    B
    \arrow[shorten <=3pt,shorten >=3pt,Rightarrow,to path={(F) -- node[label=right:$\tau$] {} (G)}]{}
  \end{tikzcd}
\]

Let us define the composition of two natural transformation. We will start defining the composition of two natural tranformations $\sigma, \tau$ as:

\[
  \begin{tikzcd}[column sep=huge]
    A
    \arrow[bend left=60]{r}[name=F,label=above:$\scriptstyle F$]{}
    \arrow{r}[name=G,label=right above:$\scriptstyle G$]{}
    \arrow[bend right=60]{r}[name=H,label=below:$\scriptstyle H$]{}  &
    B
    \arrow[shorten <=3pt,shorten >=2pt,Rightarrow,to path={(F) -- node[label=left:$\tau$] {} (G)}]{}
    \arrow[shorten <=3pt,shorten >=2pt,Rightarrow,to path={(G) -- node[label=left:$\sigma$] {} (H)}]{}
  \end{tikzcd}
\]

Due to this representation, this composition of natural transformations is called \emph{vertical composition}, in opposition to the \emph{horizontal composition} (def. \ref{horizontal-composition}).

\begin{definition}\label{vertical-composition}
  Let $C$ and $B$ be two categories, $R,S,T : C \to B$ be functors, and let $\tau: R \to S$, $\sigma:S\to T$. We define the composition $(\tau \cdot \sigma)c = \tau c\cdot \sigma c$.
\end{definition}

To see that $(\tau \cdot \sigma)$ is a natural transformation it suffices the following diagram \cite{stack-composition-natural}:

\[
\begin{tikzcd}[row sep = 1.4cm, column sep = 1.4cm]
  R c
  \arrow[lddr, to path= { --
    ([xshift=-1ex]\tikztostart.west)
    -| ([xshift=-2ex]\tikztotarget.west)
    |- (\tikztotarget)}]
  \arrow[d, swap, "\sigma c"]
  \arrow[r, "R f"]
  & R c'
  \arrow[d, "\sigma c'"]
  \arrow[rddl, to path= { --
    ([xshift=1ex]\tikztostart.east)
    -| ([xshift=2ex]\tikztotarget.east)
    -- (\tikztotarget)}, "\sigma \circ \tau c'"]
  \\
  S c
  \arrow[d, swap, "\tau c "]
  \arrow[r, "S f "] & S(c')
  \arrow[d, "\tau c'"] \\
  T c
  \arrow[r, "T f"] & T c'
\end{tikzcd}
\]

\begin{definition}
  Let $B,C$ be categories. We define the Functor category from $C$ to $B$ as $B^C$ as  the category with all functors $F:C \to B$ as object, natural transformation as arrows, and composition as defined in definition \ref{vertical-composition}.
\end{definition}

We now present some examples to provide some intuition about when this type of construction.

\begin{example}\
  \begin{itemize}
  \item The category of group actions over sets: As we have seen in example \ref{group-action} each group action over a set is a functor. Let $G$ be a group and $S$ be a set, both seen as categories and discrete categories. Then we can consider the category  $S^G$, that has as object every group action of $G$ over $S$ and as arrow the morpishm of actions.\\

  \item  In example \ref{2-category} we define the $2$ category and  can consider therefore the category of functor from $2$ to $C$. This category is called the arrow category, as we can see that there is a functor from $2$ to $C$ as functor for each arrow in $C$ and conversely.\\

    This example displays a interesting idea: we can consider small collection of object as functions/functors. This idea can as well be seen when we define a pair of real numbers as any function $f:\{0,1\} \to \R$. Should we want, for example, to consider all the squares in a category $C$, we might as well define the category square $Sqr$ and consider every functor $F:Sqr \to C$.\\
    \begin{figure}[!h]
      \[
        \begin{tikzpicture}
          \node {\begin{tikzcd}[column sep=20mm]
              a\ar[r,"f"]\ar[d,"g"] & a'\ar[d,"h"]\\
              b\ar[r,"k"] & b'
            \end{tikzcd}};
        \end{tikzpicture}
      \]
      \caption*{The square category.}
    \end{figure}

    Note that the elements $F:Sqr \to C$ are the collections of the arrows of the arrow category of $C$.

  \item We can use this construction to study the category $C^C$ of endofunctors of a particular category $C$. This case is particularly interesting while studying the endofunctors present in $Hask^{Hask}$ and later consider the Monad as a programming structure.
  \end{itemize}
\end{example}

Note that this is not the only way in which to define the composition of natural transformations can be defined. In fact, we can define another functor category. In this case we compose two natural transformation as in:

\[
  \begin{tikzcd}[column sep=huge]
    B
    \arrow[bend left=40]{r}[name=F,label=above:$\scriptstyle F$]{}
    \arrow[bend right=40]{r}[name=G,label=below:$\scriptstyle G$]{} &
    C
    \arrow[bend left=40]{r}[name=F',label=above:$\scriptstyle F'$]{}
    \arrow[bend right=40]{r}[name=G',label=below:$\scriptstyle G'$]{}&
    D
    \arrow[shorten <=3pt,shorten >=3pt,Rightarrow,to path={(F) -- node[label=right:$\tau$] {} (G)}]{}
    \arrow[shorten <=3pt,shorten >=3pt,Rightarrow,to path={(F') -- node[label=right:$\sigma$] {} (G')}]{}
  \end{tikzcd}
\]

Let us formalize this composition:
\begin{definition}\label{horizontal-composition}
  Let $B,C,D$ be categories, $F,G: B \to C, F',G':C\to D$ be functors, and let $\tau: F \to G$, $\sigma:F'\to G'$. We define the horizontal composition $(\tau \circ \sigma): F\circ F' \to G\circ G'$ by: $$(\sigma \circ \tau) c = \sigma F c \circ G' \tau c$$  for all $c\in B$.
\end{definition}

In this case we can see that the composition of two natural transformation is indeed a natural transformation due to the commutativity of:

\[
  \begin{tikzpicture}
    \node {\begin{tikzcd}[column sep=20mm]
        F'Fc      \ar[r,"\sigma F c"]
        \ar[d,"F'\tau c"]
        \ar[dr,"(\sigma\circ \tau)c"]
        & G'Fc\ar[d,"G'\tau c"]\\
        F'Gc\ar[r,"\sigma Gc'"] & G'Gc'
      \end{tikzcd}};
  \end{tikzpicture}
\]

With this definition of composition we can consider another different category: the category of all functors of all (small) categories, that is, the category that has all the functors as object, and has the natural transformation with horizontal composition as arrows.\\

When we have to consider both compositions at the same time we denote the vertical composition with $\tau \cdot \sigma$ and horizontal composition with $\tau \circ \sigma$ , as in  \cite{mac2013categories}. Lastly we have to consider how this composition relate to each other. This is seen in the \emph{interchange law}, also known as  \emph{Godement relation}:\\

\begin{proposition}
  Let $A,B,C$ be categories, let $F,G,H:A\to B$ and  $F',G',H':B\to C$ be functors and $\tau: F \to G,\sigma:G\to H,\tau': F' \to G'$ and $\sigma' : G'\to H'$ be natural transformations. Then let:
  $$(\sigma' \circ \sigma)\cdot (\tau' \circ \tau) = (\sigma' \cdot \tau')\circ (\sigma\cdot \tau)  $$
\end{proposition}
\begin{proof}
  We have a structure like

  \[
    \begin{tikzcd}[column sep=huge]
      A
      \arrow[bend left=60]{r}[name=F,label=above:$\scriptstyle F$]{}
      \arrow{r}[name=G,label=right above:$\scriptstyle G$]{}
      \arrow[bend right=60]{r}[name=H,label=below:$\scriptstyle H$]{}  &
      B
      \arrow[bend left=60]{r}[name=F',label=above:$\scriptstyle F'$]{}
      \arrow{r}[name=G',label=right above:$\scriptstyle G'$]{}
      \arrow[bend right=60]{r}[name=H',label=below:$\scriptstyle H'$]{}  &
      C
      \arrow[shorten <=3pt,shorten >=2pt,Rightarrow,to path={(F) -- node[label=left:$\tau$] {} (G)}]{}
      \arrow[shorten <=3pt,shorten >=2pt,Rightarrow,to path={(G) -- node[label=left:$\sigma$] {} (H)}]{}
      \arrow[shorten <=3pt,shorten >=2pt,Rightarrow,to path={(F') -- node[label=left:$\tau'$] {} (G')}]{}
      \arrow[shorten <=3pt,shorten >=2pt,Rightarrow,to path={(G') -- node[label=left:$\sigma'$] {} (H')}]{}
    \end{tikzcd}
  \]

  From the  naturality of $\tau'$ we have that for all $c\in A$:
  \begin{align*}
    ((\sigma'\cdot \tau')\circ (\sigma\cdot \tau))(c)
    & = H' ((\sigma\cdot \tau) c ) \circ (\sigma'\cdot \tau') (F c)  \\
    & = H' ( \sigma c \circ \tau c) \circ (\sigma' (Fc)\circ \tau' (F c) )  \\
    & = H' ( \sigma c) \circ H'(\tau c) \circ \sigma' (Fc)\circ \tau' (F c)   \\
    &  = H' ( \sigma c) \circ
      \sigma'Gc \circ G' \tau cH'(\tau c) \circ \sigma' (Fc)
      \circ \tau' (F c)   \\
    &  = (\sigma' \circ \sigma) (c) \circ  (\tau \circ \tau) (c)   \\
    &  = ((\sigma' \circ \sigma) \cdot  (\tau' \circ \tau)) (c).
  \end{align*}
\end{proof}

To finally consider the relation between products, and the functor category we can see that given three small categories $A,B,C$ we have a bijection:

$$\hhom_{Cat}(A\times B, C) \cong \hhom_{Cat}(A, C^B).$$

This fact will be taken into account further in the text, as this will mean that the functor $\cdot \times B: Cat \to Cat$ has a right adjoint.
\subsubsection{Comma Category}

To define the comma category, we shall define the category $(b \downarrow S)$ of objects $S$-under $b$, sketch the dual notion, and generalize this two concepts with the comma category.\\

Given a functor $F:B\to C$ an object $b\in B$ is $F-$under another object $c\in C$ if there exists an arrow $f:c\to Fb \in C$. This can be represented as

$$
\begin{tikzcd}
  c
  \ar[d,"f"]\\
  Fb
\end{tikzcd}
$$

and thus the name of $F$-under.

\begin{definition}
  Let $B,C$ be  categories and $S:B\to C$ be a functor. For every $c\in Ob(C)$ we can define the category $(c \downarrow S)$ that has as objects all pairs $(b,f) \in Ob(B)\times Ar(C)$ where $f:c\to Sb$, and as arrows $h:(d,f) \to (d',f')$ the arrows $h:d\to d'\in Ar(B)$ such that $f' = Sh\circ f$.
\end{definition}

The property that each arrow should satisfy can be represented as:
\[
  \begin{tikzpicture}
    \node {\begin{tikzcd}
        & c\ar[ddl, "f"]\ar[ddr,"f'",swap] & \\
        &&\\
        Sd\ar[rr, "Sh", swap] & & Sd'
      \end{tikzcd}};
  \end{tikzpicture}
\]

\begin{example} Let $U:Grp \to Set$ be the forgetful functor, and let $X\in Ob(Set)$. We can consider $(X\downarrow U)$ where every object is a function of Sets $f: X\to U G$ for a group $G$.
\end{example}

One can easily now deduce the dual concept of the category $(S\uparrow b)$ represented by: \\
\begin{center}
  objects: $
  \begin{tikzcd}
    c
    \\
    Fb\ar[u,"f"]
  \end{tikzcd}
  $;$\qquad$ arrows: $\begin{tikzcd}
    & c & \\
    &&\\
    Sd\ar[rr, "Sh", swap]\ar[uur, "f"] & & Sd'\ar[uul,"f'",swap]
  \end{tikzcd}$.
\end{center}

Categories $S\uparrow b$ where $S= id$ are particularly useful, and will be studied more thoroughly in Chapter \ref{chap:5}.

\begin{definition}\label{def:slice-cat}
  let $C$ be a category and $a$ be an object of $C$. We define the \emph{slice category} $C/a$ as:
  $$C/a :=(a\uparrow 1_C).$$
\end{definition}

Now suppose that we have three categories $B,C,D$ and two functors $S,T$ such that
\[
  \begin{tikzcd}
    B \ar[r, "S"] & C & D\ar[l, "T", swap]
  \end{tikzcd}
\]

We might want to consider the relations objects of $B$ and $D$, for that we have the comma category:

\begin{definition}
  Let $B,C,D$ be categories and to $S:B\to C,T: C\to D$. We define the coma category $(S\downarrow T)$ as the category that has as object the triples $(b,d,f)$ with $b\in Ob(B), d\in Ob(D), f:Sb\to Td\in Ar(C)$ and consider as arrows the pairs $(g,h):(b,d,f)\to (b',d',f')$ with $g:b\to b'\in Ar(B), h:d\to d'\in Ar(D)$ such that $Th \circ f = f' \circ Sg$.
\end{definition}

We can represent the previous definition by:
\begin{center}
  objects: $
  \begin{tikzcd}
    Sb\ar[d,"f"]
    \\
    Td
  \end{tikzcd}
  $;$\qquad$ arrows: $\begin{tikzcd}
    Sb\ar[d,"f"]\ar[r,"Sg"] & Sb' \ar[d,"f'"]
    \\
    Td\ar[r,"Sh"] & Td'
  \end{tikzcd}$.
\end{center}

The name comma category comes from is alternative notation $(S\downarrow T) = (S,T)$. We prefer the $(S\downarrow T)$ as it is more clear, nonetheless it is clear that before modern text editor became popular, the original comma notation had a big plus.


%!TEX root =  ../main.tex

\subsection{Separating $x$ and $y$}

\objective{Use parametric functions to determine a path and velocity}

Physics teaches us that it is often preferable to separate $x$ and $y$, and to
consider them both functions of $t$ and not one a function of the other.  This is
typically done because gravity (which Einstein showed to be the same as
acceleration, and hence is a quadratic equation) pull in one dimension, while
the others are simple linear equations.

Another benefit to parameterizing an equation, is that we also can \emph{when}
something happened.  So far, we have been differentiating $y$ with respect to
$x$, but what if we want to know how quickly $y$ is changing over time?

\personfeature[0in]{\chapdir/pics/Maria_Gaetana_Agnesi_(1836).png}{Maria Gaetana Agnesi}{1718-1799}{was an Italian mathematician, philosopher, theologian and humanitarian. She was the first woman to write a mathematics handbook and the first woman appointed as a Mathematics Professor at a university.  The parametric curve $$y=\frac{8a^3}{x^2+4a^2}$$ (The Witch of Agnesi) is named after her.\href{https://en.wikipedia.org/wiki/Maria_Gaetana_Agnesi}{Wikipedia}}

\subsubsection{Parameter Domain}
Parameters (most often $t$) also have a domain.  In science, it is often quite
irrelevant to reference any of the variable before the experiment begins or
after it ends.  If an object is thrown on Earth, and we model its path with an
upside-down parabola, what happens before $t=0$ or after it hits the ground
is meaningless.  Parameters' domains provide a natural and intuitive way to
model this limited domain.

\index{TI-8*!zoom standard}
Pay careful attention to the WINDOW on your TI-8*.  In RADIANS mode, the
default (i.e. ZOOM-STANDARD) parameter domain is $[0,2\pi]$.

\subsubsection{Eliminating the Parameter}
Sometimes, we still want to construct a typical equation from a parametric
set.  This is called \textbf{eliminating the parameter}.  In chapter 10, we will
learn many trigonometric identities to remove sines and cosines of $t$, but in
this section on algebraic functions, we will restrict ourselves to
\textbf{substitution} and \textbf{elimination}.

\subsubsection{Implicit Differentiation}\index{derivative!notation}
Until now, we have been solely using LeGrange notation for derivatives, e.g.
$y'$ (pronounced, ``$y$ prime'').  However, this isn't always helpful, especially
if we want to know what we have been differentiating with respect to.  Until now,
that hasn't mattered!  Now we might be looking for the differential of $y$ with
respect to $x$, or with respect to $t$.

A differential is a measure of sensitivity to change.  How much does $y$ alter,
given minuscule nudges to $x$ (or $t$).  This differential can also be written with the
letter `d', and so ``the differential of $y$ over the differential of $x$'' can symbolized
as $\frac{dy}{dx}$.  It can also be used like a function, to say ``take the derivative with
respect to $x$ of ...'', as in $\frac{d}{dx}\left( y\right)$.

This fractional way of writing derivatives is called \textbf{Leibniz's notation}, after
Gottfried Leibniz.  It helps show how we can find the derivative of a parametric equation.
If we seek $\frac{dy}{dx}$, that is equivalent to $\cfrac{\frac{dy}{dt}}{\frac{dx}{dt}}, \frac{dx}{dt}\ne
0$.

\index{derivative!higher order}
Derivatives of derivatives (called \textbf{higher order derivative}) were written
with more tick-marks (e.g. $f''(x), f'''(x)$, etc.) or parenthetical numbers (e.g. $f^{(2)}(x),
f^{(3)}(x)$, etc.) in Lagrange notation.  For Leibnitz's, they get more complicated:
$\cfrac{d\left(\frac{d\left(\frac{dy}{dx}\right)}{dx}\right)}{dx} =
\left(\frac{d}{dx}\right)^3y = \frac{d^3y}{dx^3}$.


\input{../header_class}

%---------- start document ---------- %
 \section{group -- algorithms for finite groups}\linkedzero{group}
 \begin{itemize}
   \item {\bf Classes}
   \begin{itemize}
     \item \linkingone{group}{Group}
     \item \linkingone{group}{GroupElement}
     \item \linkingone{group}{GenerateGroup}
     \item \linkingone{group}{AbelianGenerate}
   \end{itemize}
 \end{itemize}

\C

 \subsection{\negok Group -- group structure}\linkedone{group}{Group}
 \initialize
  \func{Group}{\hiki{value}{class},\ \hikiopt{operation}{int}{-1}}{Group}\\
  \spacing
  % document of basic document
  \quad Create an object which wraps \param{value} (typically a ring or a field)
  only to expose its group structure. \\
  \spacing
  % added document
  \quad The instance has methods defined for (abstract) group.
  For example, \linkingtwo{group}{Group}{identity} returns the identity element of the group from wrapped \param{value}.\\
  \spacing
  % input, output document
  \quad \param{value} must be an instance of a class expresses group structure.
  \param{operation} must be 0 or 1;
  If \param{operation} is 0, \param{value} is regarded as the additive group.
  On the other hand, if \param{operation} is 1, \param{value} is considered as the multiplicative group.
  The default value of \param{operation} is 0.\\
  \negok You can input an instance of \linkingone{group}{Group} itself as \param{value}.
  In this case, the default value of \param{operation} is the attribute \linkingtwo{group}{Group}{operation} of the instance.
  \begin{at}
    \item[entity]\linkedtwo{group}{Group}{entity}:\\ The wrapped object.
    \item[operation]\linkedtwo{group}{Group}{operation}:\\ It expresses the mode of operation;
$0$ means additive, while $1$ means multiplicative.
  \end{at}
  \begin{op}
    \verb+A==B+ & Return whether A and B are equal or not.\\
    \verb+A!=B+ & Check whether A and B are not equal.\\
    \verb+repr(A)+ & representation\\
    \verb+str(A)+ & simple representation\\
  \end{op}
\begin{ex}
>>> G1=group.Group(finitefield.FinitePrimeField(37), 1)
>>> print G1
F_37
>>> G2=group.Group(intresidue.IntegerResidueClassRing(6), 0)
>>> print G2
Z/6Z
\end{ex}%Don't indent!
  \method
  \subsubsection{setOperation -- change operation}\linkedtwo{group}{Group}{setOperation}
   \func{setOperation}{\param{self},\ \hiki{operation}{int}}{(None)}\\
   \spacing
   % document of basic document
   \quad Change group type to additive ($0$) or multiplicative ($1$).\\
   \spacing
   % added document
   %\spacing
   % input, output document
   \quad \param{operation} must be 0 or 1.\\
 \subsubsection{\negok createElement -- generate a GroupElement instance}\linkedtwo{group}{Group}{createElement}
   \func{createElement}{\param{self},\ \param{*value}}{\out{GroupElement}}\\
   \spacing
   % document of basic document
   \quad Return \linkingone{group}{GroupElement} object whose group is \param{self}, initialized with \param{value}.\\
   \spacing
   % added document
   \quad \negok This method calls \param{self}.\linkingtwo{group}{Group}{entity}.createElement.\\
   \spacing
   % input, output document
   \quad \param{value} must fit the form of argument for \param{self}.\linkingtwo{group}{Group}{entity}.createElement.\\
  \subsubsection{\negok identity -- identity element}\linkedtwo{group}{Group}{identity}
   \func{identity}{\param{self}}{\param{GroupElement}}\\
   \spacing
   % document of basic document
   \quad Return identity element (unit) of group.\\
   \spacing
   % added document
   \quad Return zero (additive) or one (multiplicative) corresponding to \linkingtwo{group}{Group}{operation}.
   \negok This method calls \param{self}.\linkingtwo{group}{Group}{entity}.identity or \linkingtwo{group}{Group}{entity} does not have the attribute then returns one or zero.
   \spacing
   % input, output document
  \subsubsection{grouporder -- order of the group}\linkedtwo{group}{Group}{grouporder}
   \func{grouporder}{\param{self}}{\param{long}}\\
   \spacing
   % document of basic document
   \quad Return group order (cardinality) of \param{self}.\\
   \spacing
   % added document
   \quad \negok This method calls \param{self}.\linkingtwo{group}{Group}{entity}.grouporder, card or \_\_len\_\_.\\
   We assume that the group is finite, so returned value is expected as some long integer.
   If the group is infinite, we do not define the type of output by the method.
   \spacing
   % input, output document
\begin{ex}
>>> G1=group.Group(finitefield.FinitePrimeField(37), 1)
>>> G1.grouporder()
36
>>> G1.setOperation(0)
>>> print G1.identity()
FinitePrimeField,0 in F_37
>>> G1.grouporder()
37
\end{ex}%Don't indent!
\C

 \subsection{GroupElement -- elements of group structure}\linkedone{group}{GroupElement}
 \initialize
  \func{GroupElement}{\hiki{value}{class},\ \hikiopt{operation}{int}{-1}}{GroupElement}\\
  \spacing
  % document of basic document
  \quad Create an object which wraps \param{value} (typically a ring element or
  a field element) to make it behave as an element of group.\\
  \spacing
  % added document
  \quad The instance has methods defined for an (abstract) element of group.
  For example, \linkingtwo{group}{GroupElement}{inverse} returns the inverse element of \param{value} as the element of group object.\\
  \spacing
  % input, output document
  \quad \param{value} must be an instance of a class expresses an element of group structure.
  \param{operation} must be $0$ or $1$;
  If \param{operation} is $0$, \param{value} is regarded as the additive group.
  On the other hand, if \param{operation} is $1$, \param{value} is considered as the multiplicative group.
  The default value of \param{operation} is $0$.\\
  \negok You can input an instance of \linkingone{group}{GroupElement} itself as \param{value}.
  In this case, the default value of \param{operation} is the attribute \linkingtwo{group}{GroupElement}{operation} of the instance.
  \begin{at}
    \item[entity]\linkedtwo{group}{GroupElement}{entity}:\\ The wrapped object.
    \item[set]\linkedtwo{group}{GroupElement}{set}:\\ It is an instance of \linkingone{group}{Group}, which expresses the group to which \param{self} belongs.
    \item[operation]\linkedtwo{group}{GroupElement}{operation}:\\ It expresses the mode of operation;
$0$ means additive, while $1$ means multiplicative.
  \end{at}
  \begin{op}
    \verb+A==B+ & Return whether A and B are equal or not.\\
    \verb+A!=B+ & Check whether A and B are not equal.\\
    \verb+A.ope(B)+ & Basic operation (additive $+$, multiplicative $*$)\\
    \verb+A.ope2(n)+ & Extended operation (additive $*$, multiplicative $**$)\\
    \verb+A.inverse()+\linkedtwo{group}{GroupElement}{inverse} & Return the inverse element of \param{self}\\
    \verb+repr(A)+ & representation\\
    \verb+str(A)+ & simple representation\\
  \end{op}
\begin{ex}
>>> G1=group.GroupElement(finitefield.FinitePrimeFieldElement(18, 37), 1)
>>> print G1
FinitePrimeField,18 in F_37
>>> G2=group.Group(intresidue.IntegerResidueClass(3, 6), 0)
IntegerResidueClass(3, 6)
\end{ex}%Don't indent!
  \method
  \subsubsection{setOperation -- change operation}\linkedtwo{group}{GroupElement}{setOperation}
   \func{setOperation}{\param{self},\ \hiki{operation}{int}}{(None)}\\
   \spacing
   % document of basic document
   \quad Change group type to additive ($0$) or multiplicative ($1$).\\
   \spacing
   % added document
   %\spacing
   % input, output document
   \quad \param{operation} must be $0$ or $1$.\\
 \subsubsection{\negok getGroup -- generate a Group instance}\linkedtwo{group}{GroupElement}{getGroup}
   \func{getGroup}{\param{self}}{\out{Group}}\\
   \spacing
   % document of basic document
   \quad Return \linkingone{group}{Group} object to which \param{self} belongs.\\
   \spacing
   % added document
   \quad \negok This method calls \param{self}.\linkingtwo{group}{GroupElement}{entity}.getRing or getGroup.\\
   \negok In an initialization of \linkingone{group}{GroupElement}, the attribute \linkingtwo{group}{GroupElement}{set} is set as the value returned from the method.\\
   \spacing
   % input, output document
  \subsubsection{order -- order by factorization method}\linkedtwo{group}{GroupElement}{order}
   \func{order}{\param{self}}{\param{long}}\\
   \spacing
   % document of basic document
   \quad Return the order of \param{self}.\\
   \spacing
   % added document
   \quad \negok This method uses the factorization of order of group.\\
   \negok We assume that the group is finite, so returned value is expected as some long integer.
   \negok If the group is infinite, the method would raise an error or return an invalid value.\\
   \spacing
   % input, output document
  \subsubsection{t\_order -- order by baby-step giant-step}\linkedtwo{group}{GroupElement}{t\_order}
   \func{t\_order}{\param{self},\ \hikiopt{v}{int}{2}}{\param{long}}\\
   \spacing
   % document of basic document
   \quad Return the order of \param{self}.\\
   \spacing
   % added document
   \quad \negok This method uses Terr's baby-step giant-step algorithm.\\
   This method does not use the order of group.
   You can put number of baby-step to \param{v}.
   \negok We assume that the group is finite, so returned value is expected as some long integer.
   \negok If the group is infinite, the method would raise an error or return an invalid value.\\
   \spacing
   % input, output document
   \quad \param{v} must be some int integer.\\
\begin{ex}
>>> G1=group.GroupElement(finitefield.FinitePrimeFieldElement(18, 37), 1)
>>> G1.order()
36
>>> G1.t_order()
36
\end{ex}%Don't indent!
\C

 \subsection{\negok GenerateGroup -- group structure with generator}\linkedone{group}{GenerateGroup}
 \initialize
  \func{GenerateGroup}{\hiki{value}{class},\ \hikiopt{operation}{int}{-1}}{GroupElement}\\
  \spacing
  % document of basic document
  \quad Create an object which is generated by \param{value} as the element of group structure. \\
  \spacing
  % added document
  \quad This initializes a group `including' the group elements, not a group with generators, now.
  We do not recommend using this module now.
  The instance has methods defined for an (abstract) element of group.
  For example, \linkingtwo{group}{GroupElement}{inverse} returns the inverse element of \param{value} as the element of group object.\\
  The class inherits the class \linkingone{group}{Group}.\\
  \spacing
  % input, output document
  \quad \param{value} must be a list of generators.
  Each generator should be an instance of a class expresses an element of group structure.
  \param{operation} must be $0$ or $1$;
  If \param{operation} is $0$, \param{value} is regarded as the additive group.
  On the other hand, if \param{operation} is $1$, \param{value} is considered as the multiplicative group.
  The default value of \param{operation} is $0$.\\
\begin{ex}
>>> G1=group.GenerateGroup([intresidue.IntegerResidueClass(2, 20),
... intresidue.IntegerResidueClass(6, 20)])
>>> G1.identity()
intresidue.IntegerResidueClass(0, 20)
\end{ex}%Don't indent!
\C

 \subsection{AbelianGenerate -- abelian group structure with generator}\linkedone{group}{AbelianGenerate}
 \initialize
  \quad The class inherits the class \linkingone{group}{GenerateGroup}.\\

  \subsubsection{relationLattice -- relation between generators}\linkedtwo{group}{AbelianGenerate}{relationLattice}
   \func{relationLattice}{\param{self}}{\out{\linkingone{matrix}{Matrix}}}\\
   \spacing
   % document of basic document
   \quad Return a list of relation lattice basis as a square matrix each of whose column vector is a relation basis.\\
   \spacing
   % added document
   \quad The relation basis, $V$ satisfies that $\prod_{i} \mbox{generator}_i V_i=1$.
   \spacing
   % input, output document
  \subsubsection{computeStructure -- abelian group structure}\linkedtwo{group}{AbelianGenerate}{computeStructure}
   \func{computeStructure}{\param{self}}{\param{tuple}}\\
   \spacing
   % document of basic document
   \quad Compute finite abelian group structure.\\
   \spacing
   % added document
   \quad If \param{self} $G \simeq \oplus_i <h_i>$, return [($h_1$, ord($h_1$)),..($h_n$, ord($h_n$))] and $^\# G$,
   where $<h_i>$ is a cyclic group with the generator $h_i$.\\
   \spacing
   % input, output document
   \quad The output is a tuple which has two elements;
   the first element is a list which elements are a list of $h_i$ and its order,
   on the other hand, the second element is the order of the group.
\begin{ex}
>>> G=AbelianGenerate([intresidue.IntegerResidueClass(2, 20),
... intresidue.IntegerResidueClass(6, 20)])
>>> G.relationLattice()
10 7
 0 1
>>> G.computeStructure()
([IntegerResidueClassRing,IntegerResidueClass(2, 20), 10)], 10L)
\end{ex}%Don't indent!
\C
%---------- end document ---------- %

\input{../footer}