\section{Introduction} \label{sec:introduction}

% notation

Let us define a society of $\pop = \{ 1, \ldots, P\}$ composed by $P \geq 1$ populations. Each population consist of a large number of agents, which conform a mass $m^p > 0$, with $p \in \pop$.
Let $S^p = \{ 1, \ldots, n^p \}$ be the set of actions (or pure strategies) available for each agent of the $p\th$ population.
Each agent selects a pure strategy and the resulting state of the population is the usage proportion of each strategy. The set of population states is defined as $X^p = \{ x^p \in \mathbb{R}_+^{n^p} : \sum_{i \in S^p} x_i^p = m^p \}$, where the $i\th$ component of the state, denoted by $x_i^p \in \mathbb{R}_+$, is the mass of players that select the $i\th$ strategy of the population $p$.

Population games (or large games) capture some properties of the interactions of many economic agents, e.g.,

\begin{enumerate}
\item large number of agents.
\item Continuity: The actions of an agent has small impact on the payoff of other agents.
\item Anonymity: means that the utility of each agent only depends on the aggregated actions of the other agents.
\end{enumerate}

Game theory is useful to model decision making of agents that are rational. In game theory rationality is the ability to adopt the best actions to achieve some particular goals. This implies that agents use all the information available to make decisions. Evolutionary games relax the rationality assumption by considering myopic behavior. Thus, we assume that agents choose that actions that seem to improve their fitness, however, these actions might not be optimal (as would be the case for rational agents). Thus, evolutionary games can be useful to analyze the behavior of agents in repeated games, where rationality assumptions cannot be made.

In particular, an economic agent decides whether to modify or not its strategy according to the available information. In this respect, we assume that the agent's behavior satisfies both inertia and myopia properties. On the one hand, inertia
is the tendency to remain at the status-quo, unless there exist motives to do that.
Also, this implies that the strategy adjustment events are rare events.
On the other hand, myopia means that the information used to make decisions is limited, e.g., each user makes decisions based on the current state of the population and do not estimate future actions. These two properties are based on the population games theoretical framework \cite{sandholm_book}
and behavioral economics \cite{gal}.

To accomplish the inertia property, the time between two successive updates of one
agent's strategy is modeled with an exponential distribution (this distribution is used to model the occurrence of rare events).
Thus, strategy actualization events could be characterized by means of stochastic alarm clocks.
Particularly, a rate $R_i$ Poisson alarm clock produces time among rings described by
a rate $R_i$ exponential distribution.
The whole actualization events in the population can be considered as a rate $R=\sum_{j\in \mathcal{V}} R_j$ Poisson alarm clock.
Therefore, the average number of events in a given time interval is $R$ and the probability of selecting the $i^{th}$
agent in a given time instant is
 $\frac{R_i}{R}$ \cite{sandholm_book}.

At each update opportunity (revision opportunity), the $i\th$ agent might compare the average profit of its strategy with the average profit of other strategies. Particularly, an agent might change its strategy with rate $\rho_{ij}$.

 The rate of change $\rho_{ij}$ is determined by a revision protocol, which defines the procedure used by each user to decide whether to change or not its strategy. The scalar $\rho_{ij} (\pi^p, x^p)$ is the \emph{conditional switch rate} from strategy $i$ to strategy $j$ in function of a given payoff vector $\pi$ and a population state $x^p$.

 Using the law of large numbers we can approximate the evolution of the society's state to a dynamical equation defined by
 \begin{equation}\label{eq:mean_dynamic}
  \dot{x}_i^p = \sum_{j\in S^p} x_j^p \rho_{ji} (\pi^p, x^p) - x_i^p \sum_{j\in S^p} \rho_{ij}(\pi^p, x^p).
 \end{equation}
The previous equation is known as the \emph{mean dynamic}, which is used to define  some of the dynamics in the next section.


\documentclass[a4paper,twocolumn]{article}

\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{textcomp}

\usepackage[dvips,pdftex]{geometry}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{pifont}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\ld}{ld}

\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\io}[2]{{\par\noindent\textbf{Input:} #1 \\}{\textbf{Output:} #2 \\}}
\newcommand{\wa}[1]{\textbf{Wolframalpha:} $#1$ \\}
\newcommand{\scriptref}[1]{\textbf{Skriptum.} page #1 \\}
\newcommand{\dt}[1]{\textbf{Deutsch } #1 \\}

\begin{document}
\tableofcontents

\section{Basic Linear Algebra}

\[
    0 := \begin{pmatrix}
        0 & \ldots & 0 \\
        \vdots & \ddots & \vdots \\
        0 & \ldots & 0 \\
    \end{pmatrix}
\] \[
    A = B \Leftrightarrow a_{ij} \in A = b_{ij} \in B
\] \[
    A + 0 = 0 + A = A
    \qquad
    A + (-A) = 0
\] \[
    A \cdot x = b
    \quad\Rightarrow\quad
    x = A^{-1} \cdot b
\] \[
    a_{ij} \in A \Leftrightarrow (-a_{ij}) \in (-A)
\] \[
    A + (B + C) = (A + B) + C
    \qquad
    A(BC) = (AB)C
\] \[
    (\lambda + \mu) \cdot A = \lambda \cdot A + \mu \cdot A
\] \[
    A \text{ has $m$ rows and $n$ columns}
        \Leftrightarrow A \in M(m\times n)
\]

A linear system of equations can be translated to matrizes
directly.
%
\[
    \begin{array}{cccccc}
        -3x & + & -3y & -3z & = & -3 \\
        -2x & + &  2y &   z & = & 0 \\
          x & + & -3y &  3z & = & 0 \\
    \end{array}
\] \[
    \Rightarrow
    A = \left(\begin{array}{cccc}
        -3 & -3 & -3 & -3 \\
        -2 &  2 &  1 & 0 \\
         1 & -3 &  3 & 0 \\
    \end{array}\right)
\]

To create an extended coefficient matrix, you have to add the solutions
as the most right column (thus $\{A, b\}$).
If you want to solve this system, you have to find $x$ in
$A\times x = b$, where $A$ are the coefficients of the system and
$b$ are the solutions.

This can be done by performing arithmetic row-wise operations.
An example is taking the third row minus $\frac12$ times the second
row. The result is a tuple $(0, -4, 2.5, 0)$ which can replace . Each operation returns
a factor (here: $-\frac12$); we will need this for decompositions.
Okay, the result can be taken as new second row. So how is the general
algorithm?

\subsection{Gaussian elimination}
\io{Invertible square matrix}{triangular form}
\wa{\operatorname{RowReduce}[A]}
\scriptref{9}

In a $m\times n$ matrix ($m$ rows, $n$ columns), we want to reach
the structure of an upper triangular matrix. So if the result of such
an operation is $(0, -4, 2.5, 0)$, we will prefer to use it as the
second row (because of the one zero to the left). We will perform operations
until we reach the expected structure; the ''triangular form'' (numerical
analysis) or ''row echelon form'' (abstract algebra).
%
\[
    \left(\begin{array}{cccc}
        -3 & -3 &   -3 & -3 \\
        0  & -4 &  2.5 &  0 \\
        0  &  0 & -0.5 & -1 \\
    \end{array}\right)
\]

This structure can be easily transformed to the solution of the linear
system.
%
\begin{minipage}{0.2\textwidth}\[
    -0.5z = -1
\] \[
    -4y + 2.5 \cdot (-1) = 0
\] \[
    y = \frac54
\]
\end{minipage}\begin{minipage}{0.3\textwidth}
\[
    -3x - \frac{15}{4} = \frac{12}{4}
\] \[
    x = -\frac94
\]\end{minipage}

Otherwise we can continue the elimination algorithm to create an
identity matrix on the left side (columns 1--3 here). This way
we can read the variable values immediately. This algorithm is
called Gauss-Jordan Elimination.

\subsection{Notes}

\begin{itemize}
  \item Pivot elements are the most-left numbers of the rows.
        $-3$, $-4$ and $-0.5$ in the  previous example.
  \item $\rank{A}$ is the number of rows with non-zero pivot elements
        in the triangular matrix of $A$. $\rank{A} = 3$ in the
        previous example.
  \item Sometimes swapping rows is necessary to reach a triangular
        structure.
  \item If there are only non-zero pivots, there is only one solution
        for the linear system. Otherwise we don't know anything about
        solutions.
  \item There are 3 operations that can be performed (elementary row
        operations):
    \begin{itemize}
      \item Swapping rows
      \item multiplication of a row with $\lambda \neq 0$
      \item addition of row i with row j
    \end{itemize}
  \item If there is only one solution the equivalent equation
        ($A\cdot x = 0$) can only be solved by $x = 0$.
  \item The system $Ax = b$ has a solution if
        \[
            \rank{\left(A\mid b\right)} = \rank{(A)}
        \]
  \item There is one unique solution if
        \[
            \rank{\left(A\mid b\right)} = \rank{(A)} = n
        \]
  \item There is one unique solution in a quadratic system if
        $\det{(A)} \neq 0$.
\end{itemize}

\subsection{Matrix multiplication}

\io{Two matrices $A$ and $B$ where
    number of $\text{columns}(A) =$ number of $\text{rows}(B)$
}{One matrix $C$}
\wa{A * B}
\scriptref{5}
%
\[
    A \cdot B = C
\] \[
    \begin{pmatrix}
        2 & 3 & 6 \\
        4 & 5 & 3 \\
    \end{pmatrix}
    \cdot
    \begin{pmatrix}
        1 & 3 \\
        2 & 4 \\
        7 & 8 \\
    \end{pmatrix}
    =
    \begin{pmatrix}
        50 & 66 \\
        35 & 56 \\
    \end{pmatrix}
\]

$50$ is the sum of $2\cdot1 + 3\cdot2 + 6\cdot7$.
Matrix multiplication is \emph{not} commutative.

\subsection{Arithmetic matrix operations}

Matrix additions or operations with a scalar happen element-wise.

\subsection{Set operations}

See figure~\ref{fig:set_operations}. Copyright Wikipedia.
%
\begin{figure}[h]
  \begin{center}
    \includegraphics[scale=0.5]{set_operations.pdf}
    \caption{
        Basic set operations from left to right:
        first row: Intersection ($\cap$), union ($\cup$).
        second row: relative complement ($A \setminus B$),
            complement $U \setminus A$ (U is universal set),
            symmetric difference ($A \Delta B = (A\setminus B) \cup (B
            \setminus A)$)
    }
    \label{fig:set_operations}
  \end{center}
\end{figure}

\subsection{Transposed matrix}

\io{A matrix $A \in M(m\times n)$}{Matrix $A^T \in M(n\times m)$}
\wa{\operatorname{Transpose}[A]}
\scriptref{6}
%
\[
    \begin{pmatrix}
        12 & 6 \\
        2  & 3 \\
        4  & 8 \\
    \end{pmatrix}^T
    =
    \begin{pmatrix}
        12 & 2 & 4 \\
        6 & 3 & 8 \\
    \end{pmatrix}
\] \[
    (a_{ij})^T = (a_{ji})
\] \[
    (A + B)^T = A^T + B^T
\] \[
    (A\cdot B)^T = B^T\cdot A^T
\] \[
    A = A^T \Leftrightarrow A\text{ is a ''symmetrical matrix''}
\]

\subsection{Inverse matrix}

\io{$A \in M(n\times n), \rank{A} = n$}{$C \in M(n\times n)$ if $A$ is regular}
\wa{A^{-1}}
\scriptref{16}

If $A$ has an inverse matrix, $A$ is called ''regular matrix'';
''singular'' otherwise.
%
\[
  \begin{array}{lrcl}
    A\text{ is regular}: & (A \cdot B)^{-1} &=& B^{-1} \cdot A^{-1} \\
    A^{-1}\text{ is regular}: & (A^{-1})^{-1} &=& A \\
    A^T\text{ is regular}: & (A^T)^{-1} &=& (A^{-1})^T \\
  \end{array}
\]
%
\[
    A \in M(n\times n) \quad \Rightarrow A\cdot A^{-1} = I
\]

The inverse matrix of $A$ is $A^{-1}$. This matrix can be found by
solving the system:
%
\[
    (A, I) = \left( \begin{array}{ccc|cccc}
        a_{11} & \ldots & a_{1n} & 1 & 0 & \ldots & 0 \\
        a_{21} & \ldots & a_{2n} & 0 & 1 & \ldots & 0 \\
        \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\
        a_{n1} & \ldots & a_{nn} & 0 & 0 & \ldots & 1 \\
    \end{array} \right)
\]

Once there is an identity matrix on the left side (by elementary row-wise
operations), the inverse matrix can be read from the right side of the
separator.

\section{Decompositions}

\begin{description}
  \item[LUP decomposition]
    $
        PA = LU
    $
  \item[LDU decomposition]
    $
        A = LDU
    $
  \item[LU decomposition with full pivoting]
    $
        PAQ = LU
    $
\end{description}

\subsection{LU decomposition}

\io{$A \in M(m\times n)$}{$L$ and $U$ with $A=LR$}
\wa{\operatorname{LUDecomposition}[]}
\scriptref{18}
%
\[
    A = L \cdot U
    \quad\text{(without swapped rows)}
\]
%
\begin{itemize}
  \item U is matrix A in triangular form
  \item L is a quadratic matrix with ones in the diagonal and below
        negative factors created by row-wise operations performed before.
\end{itemize}

\[
    A = P^T \cdot L \cdot R
    \quad\text{(with swapped rows)}
\]
%
\begin{itemize}
  \item U is matrix A in triangular form
  \item L is a quadratic matrix with ones in the diagonal and below
        negative factors created by row-wise operations performed before.
        While swapping rows, you have to swap all components of the rows
        left to the right ones accordingly.
  \item Permutation matrix $P$ can be created by constructing an identity
        matrix and swapping all rows you did with L. $P^T = P^{-1}$.
\end{itemize}

A solution for $Ax = b$ can be found by applying
\[
    L\cdot y = b
\] \[
    R\cdot x = y
\]

\subsection{QR decomposition}

\io{$A \in M(m\times n), m \geq n$ and linear independent column vectors}
    {$Q(m\times n)$ and $R(n\times n)$ with $A = QR$}
\wa{\operatorname{QRDecomposition}[A]}
\scriptref{58}
%
\begin{enumerate}
  \item Apply Gram-Schmidt-Process to column vectors
  \item $Q = \{q_1, q_2, \ldots\}$
  \item $Q^T A = R \Rightarrow R$
\end{enumerate}
\[
    a
\]

$Q$ is a matrix of orthonormal column vectors and $R$ is an invertible upper
triangular matrix.

\section{Determinant}

\io{$A \in M(n\times n)$}{a scalar}
\wa{\operatorname{Det}[A]}
\scriptref{21}
%
\[
    n=1: \det{A} = (a,) := a
\] \[
    n=2: \det{A} := \begin{vmatrix}
        a_{11} & a_{12} \\
        a_{21} & a_{22} \\
    \end{vmatrix} :=
    a_{11}\cdot a_{22} - a_{12}\cdot a_{21}
\]

For $n=3$, it's recommended to evaluate the determinant by using
the rule of Sarrus.
This can be done by adding as many column duplicates as necessary to
get valid diagonals (simply $2m - 1$). This structure allows you to simply
read all necessary addition and subtraction operations
(see figure~\ref{fig:sarrus}).
%
\begin{figure}[h]
  \begin{center}
    \includegraphics[width=150pt]{sarrus.pdf}
    \caption{Rule of sarrus}
    \label{fig:sarrus}
  \end{center}
\end{figure}

\[
    \det{A} = 1\cdot 1\cdot 1 + 2\cdot 3\cdot(-1) + (-1)\cdot 0\cdot 2
\] \[
    - [(-1) \cdot 1 \cdot (-1)] - [1\cdot 3\cdot 2] - [2\cdot 0\cdot 1]
    = -12
\]
%
The algebraic complement $A_{ij}'$ of $A$ is the determinant
of the $(n-1)\times(n-1)$ matrix created by removing row $i$
and column $j$.
%
\[
    A = (a_{ij}) \in M(n\times n)
\] \[
    \det{A} = \sum_{j=1}^n (-1)^{1+j} a_{1j} A_{ij}'
\]
%
\begin{itemize}
  \item $\det{A^T} = \det{A}$
  \item Entire row or column is zero $\Rightarrow \det{A} = 0$
  \item $A\in M(n\times n), \lambda \in \mathbb{K}:
        \det{(\lambda A)} = \lambda^n \det{A}$
  \item Two rows or columns are identical: $\det{A} = 0$
  \item $\det{(A\cdot B)} = \det{A}\cdot\det{B}$
  \item $\det{(A + B)} \neq \det{A} + \det{B}$
\end{itemize}
%
\[
    A \text{ is regular}
    \Leftrightarrow
    \rank{A} = n
    \Leftrightarrow
    \det{A} \neq 0
\]

\section{Vectors}

\wa{\{\{1\},\{2\},\{3\}\}}
\scriptref{24}
%
\[
    \lambda, \mu \in \mathbb{R}
\]
%
\begin{itemize}
  \item Vector $\vec{v}$ with $\|\vec{v}\| = 0$ is called Null vector.
  \item Vector $\vec{v}$ with $\|\vec{v}\| = 1$ is called Unit vector.
  \item $\vec{a} + 0 = \vec{a}, \quad \vec{a} \cdot 0 = 0$
  \item $\vec{a} + \vec{b} = \vec{b} + \vec{a}$
  \item $(\vec{a} + \vec{b}) + c = \vec{a} + (\vec{b} + c)$
  \item $\|\lambda\cdot \vec{a}\| = |\lambda| \cdot \|\vec{a}\|$
  \item $\lambda\cdot (\vec{a} + b) = \lambda\cdot \vec{a} + \lambda\cdot b$
  \item $(\lambda + \mu)\cdot \vec{a} = \lambda\cdot \vec{a}
        + \mu\cdot \vec{a}$
  \item $\|\vec{a} + \vec{b}\| \leq \|\vec{a}\| + \|\vec{b}\|$
\end{itemize}

\section{Norm (length) of a vector}
%
\io{A vector $\vec{v}$}{A scalar}
\wa{\operatorname{Norm}[\{2,3\}]}
%
\[
    \|\vec{v}\| = \sqrt{\sum_i v_i^2}
\]

\section{Products of vectors}

\subsection{Dot product (of vectors)}

\io{2 arbitrary vectors $\vec{a}$ and $\vec{b}$}{A scalar}
\wa{\operatorname{vector}\{1,2,3\} . \operatorname{vector}\{2,3,4\}}
\scriptref{26}
\dt{''Skalarprodukt''}
%
\[
    \langle a, b\rangle = \|a\|\cdot\|b\| \cdot \cos{\varphi}
\]
%
\begin{itemize}
  \item $\langle \vec{a}, \vec{b}\rangle = \langle \vec{b}, \vec{a}\rangle$
  \item $\langle \vec{a}, \vec{b}+\vec{c}\rangle = \langle \vec{b},
        \vec{a}\rangle + \langle \vec{a},\vec{c}\rangle$
  \item $\langle \vec{a}, \vec{b}\rangle = 0 \Leftrightarrow
        \vec{a}\bot \vec{b}$
  \item $\langle \vec{a}, \vec{a}\rangle = \|\vec{a}\|^2$
  \item $\vec{a} \in \mathbb{R}^3:
        \langle \vec{a},\vec{b} \rangle = a_1b_1 + a_2b_2 + a_3b_3$
  \item $\vec{a} \in \mathbb{R}^3:
        \|\vec{a}\| = \sqrt{\langle \vec{a}, \vec{a}\rangle}
        = \sqrt{a_1^2 + a_2^2 + a_3^3}$
\end{itemize}

\subsection{Cross product}

\io{2 arbitrary vectors $\vec{a}$ and $\vec{b}$}{A scalar $c$}
\wa{\{1,2,3\} \operatorname{cross} \{2,3,4\}}
\scriptref{27}
\dt{''Vektorprodukt''}
%
\[
    \vec{a}, \vec{b}\in\mathbb{R}^3:
        \quad c := \vec{a}\times \vec{b}
\] \[
    c := \|\vec{a}\| \cdot \|\vec{b}\| \cdot \sin{\varphi}
\]
%
Example:
%
\[
    \begin{pmatrix} 2 \\ 4 \\ 5 \end{pmatrix}
        \times
    \begin{pmatrix} 3 \\ 6 \\ 1 \end{pmatrix}
    =
    \begin{pmatrix}
        4\cdot1 - 5\cdot6 \\
        -(2\cdot1 - 5\cdot3) \\
        2\cdot6 - 4\cdot3 \\
    \end{pmatrix}
    =
    \begin{pmatrix}
        -26 \\
        13 \\
        0 \\
    \end{pmatrix}
\]

\subsection{Triple product}

\io{3 arbitrary vectors $\vec{a}$, $\vec{b}$ and $\vec{c}$}{A scalar}
\wa{\{1,2,3\} \operatorname{cross} \{2,3,4\}}
\scriptref{27}
\dt{''Spatprodukt''}
%
\[
    \vec{a}, \vec{b}, \vec{c} \in \mathbb{R}^n
\] \[
    |\langle \vec{a}\times \vec{b}, \vec{c}\rangle|
        = \|\vec{a}\times \vec{b}\| \cdot \|\vec{c}\| \cdot
        \cos{\angle(\vec{a}\times \vec{b}, \vec{c})}
\]

\section{Linear maps}

\begin{itemize}
  \item injective (injections can be undone)
        \[
            \forall x_1, x_2 \in A: f(x_1) = f(x_2)
                \Leftrightarrow x_1 = x_2
        \]
  \item surjective (each element has a root):
        \[
            \forall y \in B: \exists x \in A:
                f(x) = y
        \]
  \item bijective = injective and surjective
\end{itemize}

\begin{figure}[h]
  \begin{center}
    \includegraphics[scale=0.5]{set_relations.pdf}
    \caption{Relations of sets (top to bottom)
        1. injective
        2. surjective
        3. bijective
    }
    \label{fig:set_relations}
  \end{center}
\end{figure}

\section{Vector spaces}

$\mathbb{K}$ is either $\mathbb{R}$ or $\mathbb{C}$.
$\mathbb{P}_m$ is vector space of polynomials with degree
$m$ at maximum.
A non-empty set $V$ is called vector space of $\mathbb{K}$ if

\begin{enumerate}
  \item The sum of $a, b \in V$ is defined and in $V$
  \item The product of $\lambda \in \mathbb{K}$ and $a \in V$
        ($= \lambda \cdot a$) is defined and an element of $V$
\end{enumerate}

\begin{itemize}
  \item null vector: $0 \in V, \forall a \in V: a + 0 = a$
  \item unit vector: $1 \in V, \forall a \in V: a \cdot 1 = a$
  \item negative vector: $(-a) \in V, a + (-a) = 0$
  \item Is $V$ a vector space of $K$. A non-empty subspace $U \subset V$
        is called ''linear subspace of $V$'' if $\lambda \in K$ and
        $a, b \in U$ with
        \[
            a + b \in U,
                \quad \lambda \cdot a \in U
        \]
  \item A line in $\mathbb{R}^2$ and $\mathbb{R}^3$ containing the origin
        are linear subspaces.
  \item A plane in $\mathbb{R}^3$ containing the origin is a linear
        subspace of $\mathbb{R}^3$.
\end{itemize}

\section{Linear independency}

A non-empty subset $U \subset V$ is called \emph{linear independent} if
a finite number of vectors in $U$ are linear independent.
%
\[
    \lambda_1, \ldots, \lambda_m \in K,
    \quad a_1, \ldots, a_m \in V
\]

A vector like
%
\[
    a = \lambda_1 a_1 + \ldots + \lambda_m a_m
\]
%
is called linear combination of vectors ($a_1,\ldots,a_m$). A linear
combination is \emph{trivial} if $\lambda_1 = \ldots = \lambda_m = 0$.

Vectors $a_1,\ldots,a_m$ are linear dependent if there is a non-trivial
linear combination with
%
\[
    \lambda_1 a_1 + \ldots + \lambda_m a_m = 0
\]
%
These vectors are linear independent if
%
\[
    \lambda_1 = 0, \ldots, \lambda_m = 0
\]

Is $U \subset V$ is a non-empty subspace. The set of all linear combinations
of vectors of $U$ ($= L(U)$) is called the spanned space by $a_i \in U$.

\[
    L(U) = \left\{ a = \sum_i \lambda_i a_i,
            \lambda_i \in K, a_i \in U\right\}
\]

Is $U = \{a_1,\ldots,a_m\}$:

\[
    L(U) = L(a_1, \ldots, a_m)
\]

\section{Base of a vector space}

$V$ is a vector space of $K$. A subspace $U \subset V$ of linear
independent vectors is called basis of $V$ if $L(U) = V$.
A vector space with a finite basis is called finite-dimensional.

All bases in a finite-dimensional vector space $V$ have the same number
of vectors. This number is called dimension ($\dim{V}$).

\begin{itemize}
  \item The base of $\mathbb{R}^n$ is $\set{e_1,\ldots,e_n}$.
        $\dim{\mathbb{R}^n} = n$
  \item The base of $\mathbb{P}^m$ is $\set{1, x,\ldots,x^m}$.
        $\dim{\mathbb{P}_m} = m + 1$
\end{itemize}

$V$ is a vector space with basis $B = \set{v_1,\ldots,v_n}$. Each vector
$v \in V$ can be created by unique scalars $\lambda_1,\ldots,\lambda_n$.
%
\[
    v = \lambda_1 v_1 + \ldots + \lambda_n v_n
\]

\section{Diagonalisation}

\io{A diagonalisable matrix $A \in M(n\times n)$}
   {diagonal matrix $D$ with $B = C^{-1}DC$}
\wa{\operatorname{Diagonalize}[A]}
\scriptref{63}

The eigenvalues of a diagonal matrix are the diagonal elements.
$A$ is diagonalisable if $A$ has $n$ linear independent eigenvectors.
$C$ can be created by linear independent eigenvectors of $A$ as
columns in $C$. This structure satisfies $D = C^{-1} AC$.

\section{Eigenvalues}

\io{$A \in M(n\times n)$}{a scalar $\lambda$}
\wa{eigenvalues[A]}
\scriptref{59}
%
\[
    \det{(A - \lambda I)} = 0
\]
with $\lambda$ as unknown variable. If you resolve the determinant,
you will get a polynomial you want to know the Zero of. This polynomial
is called ''characteristic polynomial of $A$''. In a polynomial of
degree $n$ you will get $n$ solutions and therefore $n$ eigenvalues
$\lambda$.
Row swapping is allowed.

$\lambda$ satisfies:
\[
    A\cdot v = \lambda\cdot v
\]

\section{Eigenvectors}

\io{$A \in M(n\times n)$ and eigenvalues $\sigma_{1,\ldots,n}$}
   {$n$ linear independent vectors}
\wa{\operatorname{eigenvectors}[A]}
\scriptref{59}

If $\sigma_{i} \neq \sigma_j \quad\forall i, j \in [1,n], i \neq j$
then linear independence is given for eigenvectors for sure.

\[
    (A - \lambda_i I) \cdot v_i = 0
\]
Solve this equation system for $v_i$ which will be your eigenvector.

\section{Gram-Schmidt process}

\io{2 or more vectors}{as many vectors as given by input}
\wa{\operatorname{Orthogonalize}[\{A,B,C\}]}
\scriptref{56}
%
\[
    w_1 = \frac{1}{\| v_1\|}\cdot v_1
\] \[
    w_i = \frac{1}{\| u_i\|}\cdot u_i, \quad i = 2,\ldots,n
\] \[
    u_i = v_i - \sum_{k=1}^{i-1} \langle v_i, w_k\rangle w_k, \quad i = 2,\ldots,n
\]

\section{Pseudoinverse}

\io{Matrix $A \in M(m\times n)$}{$A^{\#} \in M(n\times m)$}
\wa{\operatorname{PseudoInverse}[A]}
\scriptref{92}
\textbf{More precise name:} Moore-Penrose-Inverse

\begin{enumerate}
    \item Evaluate $A^T\cdot A$
    \item Evaluate $(A^T\cdot A)^{-1}$
    \item Evaluate $(A^T\cdot A)^{-1} \cdot A^T = A^\#$
\end{enumerate}
%
Probably the evaluation of the inverse is impossible. In this case,
the pseudoinverse might be possible to evaluate using the singular
value decomposition (SVD):
\[
    A = U\Sigma V^T
        \Rightarrow A^\# = V\Sigma^\# U^T
\]
%
$\Sigma^\#$ can be created by inverting all singular values
in D: $\sigma_1^{-1}$, $\sigma_2^{-1}$, $\sigma_i^{-1}$.

\section{Singular value decomposition}

\io{Matrix $A \in M(n\times n)$}{Matrices $U$, $\Sigma$, $V$
    where $A = U\Sigma V^T$}
\wa{\operatorname{SVD}[A]}
\scriptref{68}
\dt{Singulärwertzerlegung}
%
\[
    A(m\times n) = U(m\times m) \cdot \Sigma(m\times n)
        \cdot V(n\times n)^T
\]
If $A$ is positiv definit and symmetrical, the procedure is the same like
orthogonal diagonalisation.
%
\begin{enumerate}
    \item Evaluate $A^T\cdot A$
    \item Evaluate die eigenvalues of
          $A^T\cdot A: \lambda_1, \lambda_2, \ldots$
    \item Sort the eigenvalues by value
    \item The singular values $\sigma_1, \sigma_2, \ldots$
          are the squareroots of the eigenvalues $\sqrt{\lambda_1},
          \sqrt{\lambda_2}, \ldots$
    \item Evaluate the eigenvectors $v_1, v_2, \ldots$
    \item Normalize the eigenvectors ($\leftarrow$ length is 1)
    \item Combine the eigenvectors as column vectors $\{v_1, v_2, \ldots\} = V$
    \item Create a $n\times n$ matrix and insert the $\sigma_i$ as
          diagonals:
          \[
            \Sigma =
            \begin{pmatrix}
                \sigma_1 & 0 & 0 \\
                0 & \sigma_2 & 0 \\
                0 & \vdots   & 0 \\
                0 & 0 & \sigma_n \\
            \end{pmatrix}
          \]
    \item Evaluate $u_i = \frac{1}{\sigma_i} \cdot A \cdot v_i$ or find
          other orthonormal vectors
    \item Combine the vectors as column vectors $\{u_1, u_2, \ldots\} = U$
    \item Evaluate $V^T$
\end{enumerate}
%
$U$ and $V$ are not unique.

\section{Gauss-Seidel Iteration}

\io{Linear equation system $(A\mid b)$ and start vector $x_0$}
   {A vector close to the solution of the equation system}
\scriptref{87}

If no start vector is given, $\begin{pmatrix} 1 \\ 0 \\ 1 \end{pmatrix}$ is
prefered.

The Gauss-Seidel-Iteration converges if
\begin{itemize}
  \item either $A$ is positive definit
  \item or for each eigenvector $\lambda$ of $S^{-1} T$
        it states $|\lambda| < 1$
\end{itemize}

\section{Spectral radius}

\io{$A$ of an iteration algorithm}{a scalar}
\scriptref{86}

In the context of iteration algorithms, $A$ is typically
$S^{-1}T$.
%
\[
    \rho(A) := \max_i{|\lambda_i|}
\]
%
with $\lambda_i$ as eigenvalue of $A$.

\section{Condition number}

\io{regular matrix $A \in M(n\times n)$}{a scalar}
%\wa{N/A}
\scriptref{82}

\[
    \operatorname{cond}(A) := \|A^{-1}\| \cdot \|A\|
\] \[
    \|A\|_\infty = \max{\left\{
        \sum_{j=1}^n |a_{ij}|  \mid i = 1,\ldots,n
    \right\}}
\]

\section{Interpolation and Approximation}

\begin{figure}[h]
  \begin{center}
    \includegraphics[scale=0.4]{interpolation.png}
    \caption{Interpolation}
    \label{fig:interpolation}
  \end{center}
\end{figure}
\begin{figure}[h]
  \begin{center}
    \includegraphics[scale=0.4]{approximation.png}
    \caption{Approximation}
    \label{fig:approximation}
  \end{center}
\end{figure}

\section{Cubic Spline Interpolation}

\io{List of $\{x,y\}$ pairs}{A polynomial}
\wa{\operatorname{BSplineCurve}[pts, SplineDegree\rightarrow3]}
\scriptref{115}

\textbf{Is S(x) a cubic spline interpolation?} \\
\begin{itemize}
  \item The function has to be continous. So all functions must stop
        at the same value at the borders.
  \item $f_i'(x_i) = f_{i+1}'(x_i)$ must be satisfied for all $i$
\end{itemize}

\section{Glossary}

\begin{description}
  \item[identity matrix] $a_{ii} := 1, 0$ otherwise
  \item[positiv definit] $A$ is positiv definit if \emph{one} of
    the following requirements is satisfied:
    \begin{equation}
        x^T A x > 0 \quad \forall x \in \mathbb{R}^n, x\neq 0
    \end{equation} \begin{equation}
        \lambda_i > 0 \quad \forall \lambda_i \text{ of } A
    \end{equation} \begin{equation}
        m > 0 \quad \forall m \text{ as minor of } A
    \end{equation} \begin{equation}
        d_i > 0 \quad \forall d \in A_t
    \end{equation}
    with $d$ as the pivot elements of the triangular form
    (\emph{without} row swapping) of $A$.
  \item[regular matrix] $M(m\times n)$ has an inverse matrix
  \item[singular matrix] $M(m\times n)$ has no inverse matrix
  \item[similar matrix] $A, B \in M(n\times n)$ are similar
        if $C \in M(n\times n)$ in $B = C^{-1} AC$ exists;
        $A$ and $B$ have the same characteristic polynomial and
        the same eigenvalues
  \item[spectral radius] $\rho(S^{-1}T) := \max_i{|\lambda_i|}$
  \item[strongly diagonal dominant] \hfill{}
    \[
        |a_{ii}| > \sum_{\substack{j=1 \\ j\neq i}}^n
        |a_{ij}| \quad \forall i = 1,\ldots,n
    \]
  \item[symmetrical matrix]
    $a_{ij} = a_{ji} \quad\forall a \in M(m\times n)$
  \item[permutation] An identity matrix where the same
    elementary row operations of the Gaussian algorithm
    have been applied on
  \item[triangular form]
    %elements below or above diagonal line are all 0
    $a_{ij} = 0 \quad\forall i > j$ or $\forall i < j$
  \item[quadratic matrix] $A \in M(n\times m): n = m$
\end{description}

\end{document}


\newpage
\section{Some popular CNN models}\label{sec:CNNs}
In this section, we will use these convolutional operations
introduced above to give a brief description of some classic convolutional
neural network (CNN) models.
Firstly, CNNs are actually a class of special DNN models. Let us recall the
DNN structure as:
\begin{equation}
\begin{cases}
f^0(x) &= x \\
f^{\ell}(x) &=  \sigma(\theta^\ell (f^{\ell-1})) \quad \ell = 1:L \\
f(x) &= W^L f^{L} + b^L \\
\end{cases},
\end{equation}
where $f^0$ is the original image, $\theta^\ell$ is a linear mapping and $\sigma$ is the activation function
\begin{equation}
\theta^\ell (f^{\ell-1}) = W^\ell f^{\ell-1}(x)  + b^\ell.
\end{equation}
The key features of CNNs are
\begin{enumerate}
	\item Replace the general
linear mapping $\theta^\ell$ by convolution operations with multi-channel.
\item Use multi-resolution of images as shown in the next diagram.
\end{enumerate}
\begin{figure}[H]
	\centering
	\includegraphics[width=.85\textwidth]{figures/multiresolution-CNN}
\end{figure}

Then we will introduce some classical architectures in convolution neural
networks.

\subsection{LeNet-5, AlexNet and VGG}
LeNet-5 \cite{lecun1998gradient} is aconvolutional network designed for handwritten and machine-printed character recognition.  AlexNet \cite{krizhevsky2012imagenet} showed, for the first time, that the features obtained by learning can transcend manually-designed features, breaking the previous paradigm in computer vision. While previous derivatives of AlexNet focused on smaller window sizes and strides in the first convolutional layer, VGG \cite{simonyan2014very} addresses another very important aspect of CNNs: depth.

The  LeNet-5, AlexNet and VGG
can be written as:
\begin{breakablealgorithm}
	\footnotesize
	\caption{$ h = \text{Classic CNN}(f; J,\nu_1, \cdots, \nu_J)$}
	\label{alg:presnet}
	\begin{algorithmic}[1]
		\State Initialization:  $f^{1,0} = f_{\rm in}(f)$.
		%		\State Initialization $u^{1,0}$
		\For{$\ell = 1:J$}
		\For{$i = 1:\nu_\ell$}
		\State Basic Block:
		\begin{equation}\label{ori-ResNet}
		f^{\ell,i} = \sigma \left( \theta^{\ell,i} \ast f^{\ell,i-1}\right)
		\end{equation}
		\EndFor
		%		\State Note: $ u^\ell= u^{\ell,\nu_\ell} $
		\State Pooling(Restriction):
		\begin{equation}
		\label{ori-ResNet0}
		f^{\ell+1,0} = R_\ell^{\ell+1} \ast_2 f^{\ell, \nu_\ell}
		\end{equation}
		\EndFor
		\State Final average pooling layer:
		$h =  R_{\rm ave}( f^{L,\nu_\ell})$.
	\end{algorithmic}
\end{breakablealgorithm}

Here $R_\ell^{\ell+1} \ast_2$ represents for the pooling operation to
sub-sampling these tensors into coarse spatial level (lower resolution).
Here we use $R_\ell^{\ell+1} \ast_2$ to stand for the pooling operation.
In general we can also have
\begin{itemize}
	\item average pooling: fixed kernels such as
	\begin{equation}\label{key}
	R_\ell^{\ell+1}  = \frac{1}{9}
	\begin{pmatrix}
	1 & 1 & 1 \\
	1 & 1 & 1 \\
	1 & 1 & 1
	\end{pmatrix}
	\end{equation}
	\item Max pooling $R_{\rm max}$ as discussed before.
\end{itemize}

In these classic CNN models, they still need some
extra fully connected layers after $h$ as the output of CNNs.
After few layers of fully connected layers, the model is completed by following
a multi-class logistic regression model.

These fully connected layers are removed in ResNet to be described below.

\subsection{ResNet}
The original ResNet developed in~\cite{he2016deep} is one
of the most popular CNN architectures in image classification problems.
\begin{breakablealgorithm}
	\footnotesize
	\caption{$ h = \text{ResNet}(f; J,\nu_1, \cdots, \nu_J)$}
	\label{alg:resnet}
	\begin{algorithmic}[1]
		\State Initialization:  $r^{1,0} = f_{\rm in}(f)$.
		%		\State Initialization $u^{1,0}$
		\For{$\ell = 1:J$}
		\For{$i = 1:\nu_\ell$}
		\State Basic Block:
		\begin{equation}\label{ori-ResNet}
			r^{\ell,i} = \sigma\left(r^{\ell, i-1} + A^{\ell,i} \ast  \sigma \circ B^{\ell,i}\ast r^{\ell,i-1}\right).
		\end{equation}
		\EndFor
		%		\State Note: $ u^\ell= u^{\ell,\nu_\ell} $
		\State Pooling(Restriction):
		\begin{equation}
			\label{ori-ResNet0}
			r^{\ell+1,0} = \sigma \left( R_\ell^{\ell+1} \ast_2  r^{\ell, \nu_\ell} + A^{\ell+1,0} \circ \sigma \circ B^{\ell+1,0} \ast_2 r^{\ell, \nu_\ell} \right).
		\end{equation}
		\EndFor
		\State Final average pooling layer:
		$h =  R_{\rm ave}( r^{L,\nu_\ell})$.
	\end{algorithmic}
\end{breakablealgorithm}
Here $f_{\rm in}(\cdot)$ may depend on different data set and problems
such as $f_{\rm in}(f) = \sigma \circ \theta^0 \ast f $ for CIFAR~\cite{krizhevsky2009learning} and
$f_{\rm in}(f) = R_{\rm max}\circ \sigma \circ \theta^0 \ast  f$ for ImageNet~\cite{deng2009imagenet} as in~\cite{he2016identity}.
In addition $r^{\ell,i} =   r^{\ell, i-1} +  A^{\ell,i} \ast  \sigma \circ B^{\ell,i} \ast \sigma (r^{i-1})$ is often called the basic ResNet block.
Here, $A^{\ell,i}$ with $i\ge0$ and $B^{\ell,i}$ with $i\ge1$ are general $3\times3$ convolutions with zero padding and stride 1.
In pooling block, $\ast _2$ means convolution with stride 2 and $B^{\ell,0}$ is taken as the $3\times3$ kernel with same output channel dimension of $R_\ell^{\ell+1}$
which is taken as $1\times1$ kernel and called as projection operator in \cite{he2016identity}.
During two consecutive pooling blocks, index $\ell$ means the fixed resolution or we $\ell$-th grid level as in multigrid methods.
Finally, $R_{\rm ave}$ ($R_{\rm max}$) means average (max) pooling with different strides which is also dependent on datasets and problems.

\subsection{pre-act ResNet}
The pre-act ResNet~\cite{he2016identity} shares a similar
structure with ResNet.
\begin{breakablealgorithm}
	\footnotesize
	\caption{$ h = \text{pre-act ResNet}(f; J,\nu_1, \cdots, \nu_J)$}
	\label{alg:presnet}
	\begin{algorithmic}[1]
		\State Initialization:  $r^{1,0} = f_{\rm in}(f)$.
		%		\State Initialization $u^{1,0}$
		\For{$\ell = 1:J$}
		\For{$i = 1:\nu_\ell$}
		\State Basic Block:
		\begin{equation}\label{ori-ResNet}
			r^{\ell,i} = r^{\ell, i-1} + A^{\ell,i} \ast  \sigma \circ B^{\ell,i}\ast   \sigma (r^{\ell,i-1}).
		\end{equation}
		\EndFor
		%		\State Note: $ u^\ell= u^{\ell,\nu_\ell} $
		\State Pooling(Restriction):
		\begin{equation}
			\label{ori-ResNet0}
			r^{\ell+1,0} = R_\ell^{\ell+1} \ast_2  r^{\ell, \nu_\ell} + A^{\ell+1,0} \circ \sigma \circ B^{\ell+1,0} \ast_2  \sigma (r^{\ell, \nu_\ell} ).
		\end{equation}
		\EndFor
		\State Final average pooling layer:
		$h =  R_{\rm ave}( r^{L,\nu_\ell})$.
	\end{algorithmic}
\end{breakablealgorithm}
Here pre-act ResNet share almost the same setup with ResNet.

The only difference between ResNet and pre-act ResNet can be viewed as
putting a $\sigma$ in different places.
The connection of those three models are often shown with next diagrams:
\begin{figure}[!htb]
	\begin{center}
		\includegraphics[width=.6\textwidth, height=.13\textheight]{CNN_ResNet}
	\end{center}
	\caption{Comparison of CNN Structures}
\end{figure}

Without loss of generality, we extract the key
feedforward steps on the same grid in different CNN models as follows.
\begin{description}
	\item[Classic CNN]
	\begin{equation}\label{eq:cCNN}
	f^{\ell,i} = \xi^i \circ \sigma (f^{\ell,i-1}) \quad \text{or} \quad f^{\ell,i} = \sigma \circ \xi^{i} (f^{\ell,i-1}) .
	\end{equation}
	\item[ResNet]
	\begin{equation}\label{eq:ResNet}
	r^{\ell,i} = \sigma( r^{\ell,i-1} + A^{\ell,i} \circ \sigma \circ B^{\ell,i}(r^{\ell,i-1})).
	\end{equation}
	\item[pre-act ResNet]
	\begin{equation}\label{eq:pre-act ResNet}
	r^{\ell,i} = r^{\ell,i-1} + A^{\ell,i} \circ \sigma \circ B^{\ell,i}\circ \sigma(r^{\ell,i-1}).
	\end{equation}
\end{description}


\documentclass[12pt]{article}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{graphicx}

% collectivised from: https://www.overleaf.com/learn/latex/Theorems_and_proofs#Theorem_styles
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
%
\begin{document}

Let $G:= (V, E)$ be a bridgless undirected cubic planar graph.
\begin{lemma}
    If $G$ is cubic, then $|V|$ is even.
\end{lemma}

\begin{proof}
    $2|E| = \sum_{v \in V} d(v) = 3|V| $ \\
    As $|E|$ must be integer, it follows that we must be able o divide $|V|$ by 2.
\end{proof}

\begin{lemma}
    If $G$ is cubic, planar and bridgless, then $G$ has a chromatic index of 3.
\end{lemma}

Consider the graph $G':= (V', E')$, obtained from $G$ by removing an edge $xy$, adding a vertex $z$, and adding edges $xz$ and $yz$.
\begin{lemma}
    $G'$ has a chromatic index of 4.
\end{lemma}

\begin{proof}
    As $\Delta(G') = 3$; we prove the $\chi'(G') \le 4$ thanks to Vizing's theorem.\\
    Now consider a matching $M$ of the edges of $E'$. as $|V'| = |V|+1$ is odd, each matching can cover at most $|V|$ vertices,
    so it can at most contains $\tfrac{|V|}{2}$ edges. However, we have $|E'| = \tfrac{3}{2} |V| + 1$ edges, so we must have $\chi'(G') \ge 4$.
\end{proof}

\newpage
\section{On-a-grid graphs}

We know that the concept of directions in a unit-square graphs has proved quite useful. For instance, we know that for $C_4$; all the squares must have their
neighbours in adjacent directions; for a $C_5$; exactly one square has it's neighboursin opposite directions, etc. \\
We propose here a new tool to these particular graphs. It will prove rather useful later to prove a large number of statements.

\begin{definition} [On-a-grid]
    A graph $G$ is said on-a-grid if it is represented such that $\forall e_1, e_2 \in E(G)$, $e_1$ and $e_2$ are either parallels or perpendicular, and no edge is represented including an other.
    Moreover, the length of all the edges is a integer.
\end{definition}

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.2]{tex_images/on_a_grid_g1.png}
    \caption{The graph $G$ is on-a-grid.}
\end{figure}

\begin{remark}
    There is no ambiguity or "hidden" edges; so, for instance, only $10$ edges in Fig. 1.
\end{remark}

\begin{lemma}
    All on-a-grid graphs are triangle-free.
\end{lemma}

\begin{proof}
    A non-degenerate triangle can't have only parallel or perpendicular edges.
\end{proof}

There exists two special lines in the representation of a on-a-grid graph: those such that every edge is parallel to one of them.
These are called the \textit{directions of the grid}.
We will only consider the case where they are represented with a $\tfrac{\pi}{4}$ angle with regard to the usual cartesian system (see Fig.1) as it will be more convenient for the future applications.

\begin{definition}[RL, LR lines]
    We refer to the \textit{directions of the grid} as LR and RL: LR is the one going from down Left to up Right; RL is the other one.
\end{definition}

RL and LR lines will be useful later to consider "layers" of vertices to generate an algorithm to pass from a representation to another
% OR just from squares to on-a-grid, who knows.

\begin{lemma}
    If $G$ is on-a-grid, $\Delta(G) \le 4$.
\end{lemma}

\begin{proof}
    Trivial.
    %Suppose by contradiction that $G$ is on a grid with a vertex $v$ such that $d(v) \ge 5$. \\
    %Call $e_1, .. e_5$ five distinct edges of $G$ containing $v$. \\
    %As every edge is parallel to one of RL or LR it means at least three of the $e_1, .. e_5$ are parallel; suppose it is $e_1, e_2$ and $e_3$.\\
\end{proof}

\begin{definition}[DL, DR, UL, UR directions]
    Let $xy$ be an edge of $G$ we say that $xy$ is in the UR (Up-Right) direction if: $xy$ is parallel to LR and $y$ is higher on the plane than $x$.\\
    We have analogous definitions for UL, DR and  DL.
\end{definition}

\begin{remark}
    if $xy$ is in UR direction, then $yx$ is in DL direction.
\end{remark}

\begin{definition}[upper vertex, upper edge]
    We say that $y$ is a vertex upper than $x$ if there exists a path $xv_1-v_ky$ possibly trivial such that every edge of the path is in direction UL or UR.
    An edge is upper than a vertex $v$ if it contains a vertex upper than $v$.
\end{definition}

We have analogous definition for lower, righter and lefter.

\subsection{From square corner intersection graphs to on-a-grid representation }

\begin{definition}[$P(UR)$]
    Let $P$ be a path in $G$. $P(UR)$ is the number of UR connection in $P$.
\end{definition}

\begin{definition}[on the same RL diagonal] %remark: it could use a lower/higher version. Think of a last layer
    Let $G$ be an intersection graph of a corner square family. Let $x, y$ be two squares of $G$. $x$ and $y$ are said to be on the same RL diagonal
    if the smallest path $P$ from $x$ to $y$ using only UL, UR and DL connections have $P(UR) = P(DL)$.
\end{definition}

See on the Fig. 2 for instance: A, D and F are on the same RL diagonal. Although there exist a path from F to D in 3 UR and 1 DL connection, the smallest one is the trivial FD. \\
We can observe that, if this definition is clear when the squares share a UL connection, it is also true when they are disjoint; in this example, I and G are on the same RL diagonal.\\
We have an analogous definition for squares on the same LR diagonal; here: F, E, I, H for instance.

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.3]{tex_images/same_diagonals.png}
    \caption{Example of corner intersection graph.}
\end{figure}

\begin{definition}[number of diagonals]
    The number of RL diagonals of a square corner intersection graph $G$ is the number regroupements you must make of squares that are on the same RL diagonal in order to take in account every square.

\end{definition}

For instance in Fig. 2 we have 4 RL diagonals, the regroupements being: $\{(A, D, F); (E); (I, G); (H) \}$.\\
We have an analogous definition for the number of LR diagonals; here, there are only 3.

\begin{definition}[order on diagonals]
    Let two RL distinct diagonals $D := \{d_1, d_2, ... d_k \} $ and $E:= \{e_1, ... e_l\}$.   \\
    We say that $D<E$ if:
    $$\forall d_i, e_j, d_{RL}(d_i, e_j) \ge 1$$.
\end{definition}
This will allow us later to choose in which order we will treat the diagonals.

\begin{remark}
    This is not an obvious way
\end{remark}

\begin{definition}[Layer difference]
    Let $x,y$ be two squares on the same RL diagonal. We call $d_{LR}(x,y)$ the LR-layer difference of $x$ and $y$.
    $$ d_{LR}(x,y) = max_P(P(UR)-P(DL))$$
    where $P$ is a path from $x$ to $y$.
\end{definition}

\begin{remark}
    If $x$ and $y$ are neighbours with a UL connection, then $d_{LR}(x,y) = 0$ and $d_{RL}(x,y) = 1$.
\end{remark}

\begin{lemma}
    If $x$ and $y$ are on the same RL diagonal (resp. LR) and $y$ and $z$ are on the same RL diagonal (resp. LR), then $x$ and $z$ are on the same RL (resp. LR) diagonal.
\end{lemma}

\begin{proof}
    Call $P_{xy}$ and $P_{yz}$ the path confirming the definitions. \\
    Then $P := P_{xy}P_{yz}$ confirms the latter.
\end{proof}

%% THE LEMMA IS TO FINISH
\begin{lemma}
    Let $x_1, y_1, x_2, y_2$ be four squares on the same LR diagonal, with $x_i$ intersecting $y_i$ in UL direction, and $d_{RL}(x1, x2) >0$. Then: $$d_{RL}(x_1, y_1) \ge d_{RL}(x_1, x_2),$$
    with the equality being reached when $x_2 = y_1$.
\end{lemma}

\begin{remark}
    This simply means that placing vertex on a line according to $d_{RL}(x, .)$ is enough to verify that no edge is implicit.
\end{remark}

\begin{proof}
    When $x_2 = y_1$ the result is trivial.\\
    Observe that $d_{RL}(y_1, x_2) >= 1$.
    Otherwise,
\end{proof}

\begin{theorem}
    Every corner square graph can be viewed as a on-gird graph.
\end{theorem}

%remark: this do not take in account yet the fact some diagonal may have no vertex neighbouring a previous one.

\begin{proof}
    The proof is done by presenting an algorithm that genereates the on-a-grid graph.\\
    Start by choosing a square $s_1$. Place it on the plane and trace a RL line. Now place all the squares that are on the same RL diagonal; and place them in order to respect the distance $d_LR(x,y)$.
    Finaly, trace all the edges that are supposed to appear. Thanks to lemma 1.4, we know that none of the edges we trace at this step is intersecting an other. \\
    Then we move to the next RL diagonal. We start by placing one square that have a neighbour in the previous diagonal. $s_2$. Then, we can geoemtrically determine the positions of all the squares that have a neighbour both on this diagonal and in the previous.
    For those which do not have any other neighbour already in place, we place them according to the distance previously used. \\
    In the case where, when placing a new diagonal, there is not any vertex that have a neighbour in a previously placed diagonal, then we move to the next diagonal and we will place this one when at least a neighbour is available.

\end{proof}

Let's apply it with the graph shown in Fig. 3:
We can identify 5 RL layers: $\{(A, B, C), (G, F, D), (I, H, E),(J), (K)\}$.\\
Start by placing B. as A and C are on the same RL diagonal, we place them at the same time. As $d_LR(B,C) = 1$, C is placed at a distance of one unit from B.
As $d_LR(A, B) = 2$ (through the path BDFGA), A is placed at a distance of 2 units from B.\\

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.3]{tex_images/example_algorithm.png}
    \caption{Example of application of the algorithm.}
\end{figure}

\subsection{What about the other way?}

\begin{theorem}
    Every on-a-grid graph can be drawn as an intersection graph of squares.
\end{theorem}

\begin{proof}
    Organize the squares by their order on RL parallel line; then from bottom to top. We denote them $v_{i,j}$. $i$ denotes on on which RL-parallel line they are;
    $j$ denotes the order (bottom-top) on the $i$-th line. \\
    The proof consists in an algorithm explaining how to construct the squares. It is done by considering the RL lines one by one.

    Start by representing all the squares on the lowest RL-line. They have a default size of 2; when two vertex are neighbours, merge the corners and centers.
    When two vertices are not neighbours, merge their corners (Fig. 2).
    \begin{figure}[h]
        \centering
        \includegraphics[scale=0.2]{tex_images/on_a_grid_2.png}
        \includegraphics[scale=0.17]{tex_images/on_a_grid_3.png}
        \caption{Lowest RL diagonal treatment.}
    \end{figure}

    Now consider the next RL line. We can observe 4 different cases:
    \begin{itemize}
        \item a: The lines are identical.
        \item b: Some vertex of the previous have no neighbours here.
        \item c: Some vertex on the new line have no neighbours with the previous line.
        \item d: Mixes from b and c.
    \end{itemize}

    %n case of a: simply copy what has been done on the previous line and merge corners with centers accordingly.\\
    %In case of c: \\

\end{proof}

\end{document}


% !TEX root = hott_intro.tex

\section{The circle}

We have seen inductive types, in which we describe a type by its constructors and an induction principle that allows us to construct sections of dependent types. Inductive types are freely generated by their constructors, which describe how we can construct their terms.

However, many familiar constructions in algebra involve the construction of algebras by generators and relations.
For example, the free abelian group with two generators is described as the group with generators $x$ and $y$, and the relation $xy=yx$.

In this chapter we introduce higher inductive types, where we follow a similar idea: to allow in the specification of inductive types not only \emph{point constructors}, but also \emph{path constructors} that give us relations between the point constructors.
The ideas behind the definition of higher inductive types are introduced by studying the simplest non-trivial example: the \emph{circle}.

\subsection{The induction principle of the circle}
The \emph{circle}\index{circle} is defined as a higher inductive type\index{higher inductive type} $\sphere{1}$\index{S 1@{$\sphere{1}$}} that comes equipped with\index{base@{$\base$}}\index{loop@{$\lloop$}}
\begin{align*}
\base & : \sphere{1} \\
\lloop & : \id{\base}{\base}.
\end{align*}
Just like for ordinary inductive types, the induction principle for higher inductive types provides us with a way of constructing sections of dependent types. However, we need to take the \emph{path constructor}\index{path constructor} $\lloop$ into account in the induction principle.

By applying a section $f:\prd{t:\sphere{1}}P(t)$ to the base point of the circle, we obtain a term $f(\base):P(\base)$. Moreover, using the dependent action on paths\index{dependent action on paths} of $f$ of \cref{defn:apd} we also obtain for any dependent function $f:\prd{t:\sphere{1}}P(t)$ a path
\begin{align*}
\apd{f}{\lloop} & : \id{\mathsf{tr}_P(\lloop,f(\base))}{f(\base)}
\end{align*}
in the fiber $P(\base)$.

\begin{defn}
Let $P$ be a type family over the circle. The \define{dependent action on generators}\index{dependent action on generators!for the circle|textbf} is the map\index{dgen_S1@{$\mathsf{dgen}_{\sphere{1}}$}|textbf}
\begin{equation}\label{eq:dgen_circle}
\mathsf{dgen}_{\sphere{1}}:\Big(\prd{t:\sphere{1}}P(t)\Big)\to\Big(\sm{y:P(\base)}\id{\mathsf{tr}_P(\lloop,y)}{y}\Big)
\end{equation}
given by $\mathsf{dgen}_{\sphere{1}}(f)\defeq\pairr{f(\base),\apd{f}{\lloop}}$.
\end{defn}

We now give the full specification of the circle.

\begin{defn}
The \define{circle}\index{circle|textbf} is a type $\sphere{1}$\index{S 1@{$\sphere{1}$}} that comes equipped with\index{base@{$\base$}}\index{loop@{$\lloop$}}
\begin{align*}
\base & : \sphere{1} \\
\lloop & : \id{\base}{\base},
\end{align*}
and satisfies the \define{induction principle of the circle}\index{induction principle!of the circle}, which provides for each type family $P$ over $\sphere{1}$ a map
\begin{equation*}
\ind{\sphere{1}}:\Big(\sm{y:P(\base)}\id{\mathsf{tr}_P(\lloop,y)}{y}\Big)\to \Big(\prd{t:\sphere{1}}P(t)\Big),
\end{equation*}
and a homotopy witnessing that $\ind{\sphere{1}}$ is a section of $\mathsf{dgen}_{\sphere{1}}$
\begin{equation*}
\mathsf{dgen}_{\sphere{1}}\circ \ind{\sphere{1}}\htpy \idfunc
\end{equation*}
for the computation rule\index{computation rules!of the circle}.
\end{defn}

\begin{rmk}
The induction principle of the circle provides us with a dependent function $f:\prd{t:\sphere{1}}P(t)$ equipped with an identification
\begin{equation*}
(f(\base),\apd{f}{\lloop})=(x,p),
\end{equation*}
for any $x : P(\base)$ and $p : \mathsf{tr}_P(\lloop,x)=x$. By \cref{thm:eq_sigma} the identification
$(f(\base),\apd{f}{\lloop})=(x,p)$ is equivalently described as a pair of identifications
\begin{samepage}
\begin{align*}
\alpha & : f(\base)= x \\
\beta & : \mathsf{tr}(\alpha,\apd{f}{\lloop}) = p.
\end{align*}\end{samepage}%
Here, the transport is taken with respect to the family $x\mapsto \mathsf{tr}_P(\lloop,x)=x$.

The identity type $\mathsf{tr}(\alpha,\apd{f}{\lloop}) = p$ is equivalent to the type
\begin{equation*}
\ct{\apd{f}{\lloop}}{\alpha}=\ct{\mathsf{ap}_{\mathsf{tr}_P(\lloop)}(\alpha)}{p}.
\end{equation*}
Indeed, such an equivalence can be constructed by path induction, because types reduce to the type $\apd{f}{\lloop}=p$ when $\alpha\jdeq\refl{f(x)}$. Therefore we obtain from the computation rule of the circle an identification $\alpha:f(\base)=x$, and an identification
\begin{equation*}
\beta':\ct{\apd{f}{\lloop}}{\alpha}=\ct{\mathsf{ap}_{\mathsf{tr}_P(\lloop)}(\alpha)}{p}
\end{equation*}
witnessing that the square
\begin{equation*}
\begin{tikzcd}[column sep=huge]
\mathsf{tr}_P(\lloop,f(\base)) \arrow[d,equals,swap,"\apd{f}{\lloop}"] \arrow[r,equals,"\ap{\mathsf{tr}_P(\lloop)}{\alpha}"] & \mathsf{tr}_P(\lloop,x) \arrow[d,equals,"p"] \\
f(\base) \arrow[r,equals,swap,"\alpha"] & x
\end{tikzcd}
\end{equation*}
commutes.
\end{rmk}

\subsection{The universal property of the circle}

In the following theorem we establish the \define{universal property}\index{universal property!of the circle} of the circle. The proof requires \cref{lem:circle_up_htpy,lem:circle_up_tr_compute}, which we state after we encounter their application.

\begin{thm}\label{thm:circle_up}
For each type $X$, the \define{action on generators}\index{action on generators!for the circle}\index{gen_S1@{$\mathsf{gen}_{\sphere{1}}$}|textbf}
\begin{equation*}
\mathsf{gen}_{\sphere{1}}:(\sphere{1}\to X)\to \sm{x:X}x=x
\end{equation*}
given by $f\mapsto (f(\base),\ap{f}{\lloop})$ is an equivalence.
\end{thm}

\begin{proof}
Let $x:X$ and let $p:x=x$. By \cref{ex:trans_triv} we have an identification
\begin{equation*}
\mathsf{tr\usc{}triv}(\lloop,x):\mathsf{tr}_{W_{\sphere{1}}X}(\lloop,x)=x,
\end{equation*}
from which we obtain a fiberwise equivalence
\begin{equation*}
\varphi : \prd{x:X} (x=x) \to (\mathsf{tr}_{W_{\sphere{1}}X}(\lloop,x)=x)
\end{equation*}
given by $p\mapsto \ct{\mathsf{tr\usc{}triv}(\lloop,x)}{p}$.
Moreover, for any $f:A\to B$, and any $p:x=y$ there is an identification $\ct{\mathsf{tr\usc{}triv}(p,f(x))}{\mathsf{ap}_f(p)}=\apd{f}{p}$, so it follows that the triangle
\begin{equation*}
\begin{tikzcd}[column sep=0]
& (\sphere{1}\to X) \arrow[dl,swap,"\mathsf{gen}_{\sphere{1}}"] \arrow[dr,swap,"\mathsf{dgen}_{\sphere{1}}" near start] \\
\sm{x:X}x=x \arrow[rr,"\total{\varphi}"',"\eqvsym"] & & \sm{x:X} \mathsf{tr}_{W_{\sphere{1}}X}(\lloop,x)=x \arrow[ul,densely dotted,bend right=15,swap,"\ind{\sphere{1}}"]
\end{tikzcd}
\end{equation*}
commutes, and the map $\total{\varphi}$ is a fiberwise equivalence by \cref{thm:fib_equiv}. Since the triangle commutes and $\ind{\sphere{1}}$ is a section of $\mathsf{dgen}_{\sphere{1}}$, it follows that the composite
\begin{equation*}
\rec{\sphere{1}}\defeq \ind{\sphere{1}}\circ \total{\varphi}
\end{equation*}
is a section of $\mathsf{gen}_{\sphere{1}}$. Therefore it remains to show that $\rec{\sphere{1}}$ is also a retraction of $\mathsf{gen}_{\sphere{1}}$, i.e., we have to show that for every $f:\sphere{1}\to X$ there is an identification
\begin{equation*}
\rec{\sphere{1}}(\mathsf{gen}_{\sphere{1}}(f))=f.
\end{equation*}
In \cref{lem:circle_up_htpy} below we establish that
\begin{equation*}
(\mathsf{gen}_{\sphere{1}}(\rec{\sphere{1}}(\mathsf{gen}_{\sphere{1}}(f)))=\mathsf{gen}_{\sphere{1}}(f))\to (\rec{\sphere{1}}(\mathsf{gen}_{\sphere{1}}(f))=f).
\end{equation*}
We get an identification $\mathsf{gen}_{\sphere{1}}(\rec{\sphere{1}}(\mathsf{gen}_{\sphere{1}}(f)))=\mathsf{gen}_{\sphere{1}}(f)$ from the fact that $\rec{\sphere{1}}$ is a section of $\mathsf{gen}_{\sphere{1}}$.
\end{proof}

\begin{lem}\label{lem:circle_up_htpy}
Let $f,g:\sphere{1}\to X$ be two dependent functions. Then there is a map
\begin{equation*}
(\mathsf{gen}_{\sphere{1}}(f)=\mathsf{gen}_{\sphere{1}}(g))\to (f=g)
\end{equation*}
\end{lem}

\begin{proof}
Let $p:\mathsf{gen}_{\sphere{1}}(f)=\mathsf{gen}_{\sphere{1}}(g)$. By function extensionality, it suffices to show that $f\htpy g$. However, since $f\htpy g$ is just the type $\prd{t:\sphere{1}}f(t)=g(t)$, we can construct such a homotopy by $\sphere{1}$-induction. Thus, it suffices to construct a term of type
\begin{equation*}
\sm{p:f(\base)=g(\base)} \mathsf{tr}_{E_{f,g}}(\lloop,p)=p,
\end{equation*}
where $E_{f,g}$ is the family over $\sphere{1}$ given by $t\mapsto f(t)=g(t)$.

We claim that it suffices to construct for each $p:f(\base)=g(\base)$ an equivalence
\begin{equation*}
\Big(\mathsf{tr}_{E_{f,g}}(\lloop,p)=p\Big)\eqvsym\Big(\mathsf{tr}_{L}(p,\ap{f}{\lloop})=\ap{g}{\lloop}\Big),
\end{equation*}
where $L$ is the family over $X$ given by $x\mapsto x=x$.
To see that this suffices, we note that such a fiberwise equivalence induces an equivalence on total spaces, and the total space
\begin{align*}
\sm{p:f(\base)=g(\base)} \mathsf{tr}_{L}(p,\ap{f}{\lloop})=\ap{g}{\lloop},
\end{align*}
and is equivalent to $\mathsf{gen}(f)=\mathsf{gen}(g)$, of which we have assumed a term.

The asserted fiberwise equivalence that we need for this proof to go through requires a sufficient generalization so that it can be constructed by path induction, so it is established separately in \cref{lem:circle_up_tr_compute} below.
\end{proof}

\begin{comment}
Consider $f,g:\sphere{1}\to X$ with a homotopy $H:f\htpy g$. Then we have $H(\base):f(\base)=g(\base)$, and the square
\begin{equation*}
\begin{tikzcd}[column sep=large]
f(\base) \arrow[r,equals,"H(\base)"] \arrow[d,swap,equals,"\ap{f}{\lloop}"] & g(\base) \arrow[d,equals,"\ap{g}{\lloop}"] \\
f(\base) \arrow[r,equals,swap,"H(\base)"] & g(\base)
\end{tikzcd}
\end{equation*}
commutes by the naturality of homotopies, established in \cref{defn:htpy_nat}\index{naturality!of homotopies}. In the following lemma we will relate such squares in two ways to a transport, by generalizing the above situation sufficiently so that path induction becomes applicable. We will use these computations of transports to establish the universal property of the circle.
\end{comment}

With the following lemma we complete the proof of the universal property of the circle.

\begin{samepage}%
\begin{lem}\label{lem:circle_up_tr_compute} ~
\begin{enumerate}
\item Let $f,g:A \to B$, and let $E_{f,g}$ be the family over $A$ given by
\begin{equation*}
E_{f,g}(x)\defeq f(x)=g(x).
\end{equation*}
Then for any $p:x=x'$ in $A$ there is an equivalence
\begin{equation*}
\eqv{(\mathsf{tr}_{E_{f,g}}(p,q)=q')}{(\ct{\ap{f}{p}}{q'}=\ct{q}{\ap{g}{p}})}.
\end{equation*}
for any $q:f(x)=g(x)$ and $q':f(x')=g(x')$. In other words, there is an identification $\mathsf{tr}_{E_{f,g}}(p,q)=q'$ if and only if the square
\begin{equation*}
\begin{tikzcd}
f(x) \arrow[r,equals,"q"] \arrow[d,equals,swap,"\ap{f}{p}"] & g(x) \arrow[d,equals,"\ap{g}{p}"] \\
f(x') \arrow[r,equals,swap,"{q'}"] & g(x')
\end{tikzcd}
\end{equation*}
commutes.
\item Let $L$ be the family over $B$ given by $L(y)\defeq y=y$, and let $q:y=y'$ be an identification in $B$. Then there is an equivalence
\begin{equation*}
\eqv{(\mathsf{tr}_L(q,p)=p')}{(\ct{q}{p'}=\ct{p}{q})}.
\end{equation*}
for any $p:y=y$ and $p':y'=y'$. In other words, there is an identification $\mathsf{tr}_L(q,p)=p'$ if and only if the square
\begin{equation*}
\begin{tikzcd}
y \arrow[r,equals,"p"] \arrow[d,swap,equals,"q"] & y \arrow[d,equals,"q"] \\
y' \arrow[r,equals,swap,"{p'}"] & y'
\end{tikzcd}
\end{equation*}
commutes.
\item Let $f,g:A \to B$, let $p:x=x$ be a loop in $A$, and let $q:f(x)=g(x)$. Then there is an equivalence
\begin{equation*}
\eqv{(\mathsf{tr}_{E_{f,g}}(p,q)=q)}{(\mathsf{tr}_L(q,\ap{f}{p})=\ap{g}{p}).}
\end{equation*}
\end{enumerate}
\end{lem}
\end{samepage}%

\begin{proof}
The first claim follows by path induction on $p$, and the second claim follows by path induction on $q$. The third claim follows by combining the first two, since the types on both sides are equivalent to the type
\begin{equation*}
\ct{\ap{f}{p}}{q}=\ct{q}{\ap{g}{p}}
\end{equation*}
of witnesses that the square
\begin{equation*}
\begin{tikzcd}[column sep=large]
f(x) \arrow[r,equals,"q"] \arrow[d,swap,equals,"\ap{f}{p}"] & g(x) \arrow[d,equals,"\ap{g}{p}"] \\
f(x) \arrow[r,equals,swap,"q"] & g(x)
\end{tikzcd}
\end{equation*}
commutes.
\end{proof}

\begin{exercises}
\item \label{ex:circle_up_pushout}Show that
\begin{equation*}
\begin{tikzcd}[column sep=huge]
X^{\sphere{1}} \arrow[r,"\blank\circ\mathsf{const}_{\base}"] \arrow[d,swap,"\blank\circ\mathsf{const}_{\base}"] & X^\unit \arrow[d,"\blank\circ\mathsf{const}_{\ttt}"] \\
X^\unit \arrow[r,swap,"\blank\circ\mathsf{const}_{\ttt}"] & X^\bool
\end{tikzcd}
\end{equation*}
is a pullback square for each type $X$.
\item \label{ex:circle_dup}In this exercise we establish the \emph{dependent universal property} of the circle, analogous to the proof of \cref{thm:circle_up}.
\begin{subexenum}
\item Let $f,g:\prd{x:A}B(x)$, and let $E_{f,g}$ be the family over $A$ given by
\begin{equation*}
E_{f,g}(x)\defeq f(x)=g(x).
\end{equation*}
Construct for any $p:x=x'$ in $A$ an equivalence
\begin{equation*}
\eqv{(\mathsf{tr}_{E_{f,g}}(p,q)=q')}{(\ct{\apd{f}{p}}{q'}=\ct{\ap{\mathsf{tr}_B(p)}{q}}{\apd{g}{p}})}.
\end{equation*}
for any $q:f(x)=g(x)$ and $q':f(x')=g(x')$.
\item Let $B$ be a family over $A$, and for $l:x=_A x$ let $L_x$ be the family over $B(x)$ given by
\begin{equation*}
L_x(y)\defeq \mathsf{tr}_B(l,y)=y.
\end{equation*}
Furthermore, let $q:y=y'$ be an identification in $B(x)$.
Construct an equivalence
\begin{equation*}
\eqv{(\mathsf{tr}_{L_x}(q,p)=p')}{(\ct{\ap{\mathsf{tr}_B(l)}{q}}{p'}=\ct{p}{q})}.
\end{equation*}
for any $p:\mathsf{tr}_B(l,y)=y$ and $p':\mathsf{tr}_B(l,y')=y'$.
\item Let $f,g:\prd{x:A}B(x)$, let $p:x=x$ be a loop in $A$, and let $q:f(x)=g(x)$.
Construct an equivalence
\begin{equation*}
\eqv{(\mathsf{tr}_{E_{f,g}}(p,q)=q)}{(\mathsf{tr}_{L_x}(q,\apd{f}{p})=\apd{g}{p}).}
\end{equation*}
\item Show that for any $f,g:\prd{t:\sphere{1}}P(t)$ there is a function
\begin{equation*}
\Big(\mathsf{dgen}_{\sphere{1}}(f)=\mathsf{dgen}_{\sphere{1}}(g)\Big)\to (f=g).
\end{equation*}
\item Show that for any type family $P$ over $\sphere{1}$, the \emph{dependent action on generators}
\begin{equation*}
\Big(\prd{t:\sphere{1}}P(t)\Big)\to \sm{u:P(\base)}\mathsf{tr}_P(\lloop,u)=u
\end{equation*}
is an equivalence.
\end{subexenum}
\item \label{ex:circle-connected}Let $P:\sphere{1}\to\prop$ be a family of propositions over the circle. Show that
\begin{equation*}
P(\base)\to\prd{t:\sphere{1}}P(t).
\end{equation*}
In this sense the circle is \emph{connected}.
\item Show that
\begin{equation*}
\prd{x,y:\sphere{1}}\neg\neg(x=y).
\end{equation*}
\item \label{ex:circle_constant}
Show that for any type $X$ and any $x:X$, the map
\begin{equation*}
\rec{\sphere{1}}(x,\refl{x}):\sphere{1}\to X
\end{equation*}
is homotopic to the constant map $\mathsf{const}_x$.
\item \label{ex:circle_connected}
\begin{subexenum}
\item Show that a type $X$ is a set if and only if the map
\begin{equation*}
\lam{x}{t} x : X \to (\sphere{1}\to X)
\end{equation*}
is an equivalence.
\item Show that a type $X$ is a set if and only if the map
\begin{equation*}
\lam{f}f(\base) : (\sphere{1}\to X)\to X
\end{equation*}
is an equivalence.
\end{subexenum}
\end{exercises}

\section{The fundamental cover of the circle}

In this lecture we show that the loop space of the circle is equivalent to $\mathbb{Z}$ by constructing the universal cover of the circle as an application of the univalence axiom.

\subsection{Families over the circle}

The type of small families over $\sphere{1}$ is just the function type $\sphere{1}\to\UU$, so in fact we may use the universal property of the circle to construct small dependent types over the circle.
By the universal property, small type families over $\sphere{1}$ are equivalently described as pairs $(X,p)$ consisting of a type $X:\UU$ and an identification $p:X=X$.
This is where the univalence axiom\index{univalence axiom!families over $\sphere{1}$} comes in. By the map
\begin{equation*}
\mathsf{eq\usc{}equiv}_{X,X}:(\eqv{X}{X})\to (X=X)
\end{equation*}
it suffices to provide an equivalence $\eqv{X}{X}$.

\begin{defn}\label{defn:circle_descent}
Consider a type $X$ and every equivalence $e:\eqv{X}{X}$.
We will construct a dependent type $\mathcal{D}(X,e):\sphere{1}\to\UU$ with an equivalence $x\mapsto x_{\mathcal{D}}:\eqv{X}{\mathcal{D}(X,e,\base)}$ for which the square
\begin{equation*}
\begin{tikzcd}
X \arrow[r,"\eqvsym"] \arrow[d,swap,"e"] & \mathcal{D}(X,e,\base) \arrow[d,"\mathsf{tr}_{\mathcal{D}(X,e)}(\lloop)"] \\
X \arrow[r,swap,"\eqvsym"] & \mathcal{D}(X,e,\base)
\end{tikzcd}
\end{equation*}
commutes. We also write $d\mapsto d_{X}$ for the inverse of this equivalence, so that the relations
\begin{samepage}%
\begin{align*}
(x_{\mathcal{D}})_X & =x & (e(x)_{\mathcal{D}}) & = \mathsf{tr}_{\mathcal{D}(X,e)}(\lloop,x_{\mathcal{D}}) \\
(d_X)_{\mathcal{D}} & =d & (\mathsf{tr}_{\mathcal{D}(X,e)}(d))_X & = e(d_X)
\end{align*}
\end{samepage}%
hold.

The type $\sm{X:\UU}\eqv{X}{X}$ is also called the type of \define{descent data}\index{descent data!for the circle|textbf} for the circle.
\end{defn}

\begin{constr}
By \cref{ex:tr_ap} we have an identification
\begin{equation*}
\mathsf{equiv\usc{}eq}(\ap{P}{\lloop})=\mathsf{tr}_P(\lloop)
\end{equation*}
for each dependent type $P:\sphere{1}\to\UU$. Therefore we see that the triangle\index{desc_S1@{$\mathsf{desc}_{\sphere{1}}$}}
\begin{equation*}
\begin{tikzcd}
& (\sphere{1}\to \UU) \arrow[dl,swap,"\mathsf{gen}_{\sphere{1}}"] \arrow[dr,"\mathsf{desc}_{\sphere{1}}"] \\
\sm{X:\UU}X=X \arrow[rr,swap,"\total{\lam{X}\mathsf{equiv\usc{}eq}_{X,X}}"] & & \sm{X:\UU}\eqv{X}{X}
\end{tikzcd}
\end{equation*}
commutes, where the map $\mathsf{desc}_{\sphere{1}}$ is given by $P\mapsto\pairr{P(\base),\mathsf{tr}_P(\lloop)}$ and the bottom map is an equivalence by the univalence axiom and \cref{thm:fib_equiv}.
Now it follows by the 3-for-2 property that $\mathsf{desc}_{\sphere{1}}$ is an equivalence, since $\mathsf{gen}_{\sphere{1}}$ is an equivalence by \cref{thm:circle_up}.
This means that for every type $X$ and every $e:\eqv{X}{X}$ there is a type family $\mathcal{D}(X,e):\sphere{1}\to\UU$ such that
\begin{equation*}
\pairr{\mathcal{D}(X,e,\base),\mathsf{tr}_{\mathcal{D}(X,e)}(\lloop)}=\pairr{X,e}.
\end{equation*}
Equivalently, we have $p:\id{\mathcal{D}(X,e,\base)}{X}$ and $\mathsf{tr}(p,{\mathsf{tr}_{\mathcal{D}(X,e)}(\lloop)})=e$. Thus, we obtain $\mathsf{equiv\usc{}eq}(p):\eqv{\mathcal{D}(X,e,\base)}{X}$, for which the square
\begin{equation*}
\begin{tikzcd}[column sep=huge]
\mathcal{D}(X,e,\base)\arrow[r,"\mathsf{equiv\usc{}eq}(p)"] \arrow[d,swap,"\mathsf{tr}_{\mathcal{D}(X,e)}(\lloop)"] & X \arrow[d,"e"] \\
\mathcal{D}(X,e,\base)\arrow[r,swap,"\mathsf{equiv\usc{}eq}(p)"] & X
\end{tikzcd}
\end{equation*}
commutes.
\end{constr}

\begin{comment}
\begin{defn}\label{defn:fiber_sequence}
A \define{fiber sequence}
\begin{equation*}
F \hookrightarrow E \twoheadrightarrow B
\end{equation*}
consists of a \define{base type} $B$ with a base point $b_0$ and a dependent type $P:B\to\type$, a type $F$ called the \define{fiber} with an equivalence $\eqv{P(b_0)}{F}$, and a type $E$ called the \define{total space} with a map $p:E\to B$ and an equivalence $e:\eqv{(\sm{b:B}P(b))}{E}$ such that the triangle
\begin{equation*}
\begin{tikzcd}
\Big(\sm{b:B}P(b)\Big) \arrow[rr,"e"] \arrow[dr,swap,"\proj 1"] & & E \arrow[dl,"p"] \\
& B
\end{tikzcd}
\end{equation*}
commutes.
\end{defn}
\end{comment}

\subsection{The fundamental cover of the circle}

The \emph{fundamental cover}\index{fundamental cover!of the circle} of the circle is a family of sets over the circle with contractible total space.
Classically, the fundamental cover is described as a map $\mathbb{R}\to\sphere{1}$ that winds the real line around the circle.
In homotopy type theory there is no analogue of such a construction.

Recall from \cref{ex:succ_equiv} that the successor function $\mathsf{succ}:\Z\to \Z$ is an equivalence. Its inverse is the predecessor function defined in \cref{ex:int_pred}.

\begin{defn}
The \define{fundamental cover}\index{fundamental cover!of the circle|textbf} of the circle is the dependent type $\mathcal{E}_{\sphere{1}}\defeq\mathcal{D}(\Z,\mathsf{succ}):\sphere{1}\to\UU$.\index{Z@{$\Z$}!fundamental cover of S1@{fundamental cover of $\sphere{1}$}}\index{E_S1@{$\mathcal{E}_{\sphere{1}}$}|textbf}
\end{defn}

\begin{rmk}
  The fundamental cover of the circle comes equipped with an equivalence
  \begin{equation*}
    e:\mathbb{Z} \simeq \mathcal{E}_{\sphere{1}}(\mathsf{base})
  \end{equation*}
  and a homotopy witnessing that the square
  \begin{equation*}
    \begin{tikzcd}
      \mathbb{Z} \arrow[r,"e"] \arrow[d,swap,"\mathsf{succ}"] & \mathcal{E}_{\sphere{1}}(\mathsf{base}) \arrow[d,"\mathsf{tr}_{\mathcal{E}_{\sphere{1}}}(\mathsf{loop})"] \\
      \mathbb{Z} \arrow[r,swap,"e"] & \mathcal{E}_{\sphere{1}}(\mathsf{base})
    \end{tikzcd}
  \end{equation*}
  commutes.

  For convenience, we write $k_{\mathcal{E}}$ for the term $e(k):\mathcal{E}_{\sphere{1}}(\mathsf{base})$, for any $k:\mathbb{Z}$.
\end{rmk}

The picture of the fundamental cover is that of a helix\index{helix} over the circle. This picture emerges from the path liftings of $\mathsf{loop}$ in the total space. The segments of the helix connecting $k$ to $k+1$ in the total space of the helix, are constructed in the following lemma.

\begin{lem}
For any $k:\Z$, there is an identification
\begin{equation*}
\mathsf{segment\usc{}helix}_k:(\base,k_{\mathcal{E}})=(\base,\mathsf{succ}(k)_{\mathcal{E}})
\end{equation*}
in the total space $\sm{t:\sphere{1}}\mathcal{E}(t)$.
\end{lem}

\begin{proof}
By \cref{thm:eq_sigma} it suffices to show that
\begin{equation*}
\prd{k:\Z} \sm{\alpha:\base=\base} \mathsf{tr}_{\mathcal{E}}(\alpha,k_{\mathcal{E}})= \mathsf{succ}(k)_{\mathcal{E}}.
\end{equation*}
We just take $\alpha\defeq\lloop$. Then we have $\mathsf{tr}_{\mathcal{E}}(\alpha,k_{\mathcal{E}})= \mathsf{succ}(k)_{\mathcal{E}}$ by the commuting square provided in the definition of $\mathcal{E}$.
\end{proof}

\subsection{Contractibility of general total spaces}
Consider a type $X$, a family $P$ over $X$, and a term $c:\sm{x:X}P(x)$, and suppose our goal is to construct a contraction
\begin{equation*}
  \prd{t:\sm{x:X}P(x)}c=t.
\end{equation*}
Of course, the first step is to apply the induction principle of $\Sigma$-types, so it suffices to construct a term of type
\begin{equation*}
\prd{x:X}{y:P(x)} c = (x,y).
\end{equation*}
In the case where $P$ is the fundamental cover of the circle, we are given an equivalence $e:\eqv{\Z}{\mathcal{E}(\base)}$. Using this equivalence, we obtain an equivalence
\begin{equation*}
  \Big(\prd{y:\mathcal{E}(y)}c=(\mathsf{base},y)\Big)\to \Big(\prd{k:\Z}c=(\mathsf{base},k_{\mathcal{E}})\Big).
\end{equation*}
More generally, if we are given an equivalence $e:\eqv{F}{P(x)}$ for some $x:X$, then we have an equivalence
\begin{equation}
\Big(\prd{y:P(x)}c=(x,y)\Big) \to \Big(\prd{y:F}c=(x,e(y))\Big)
\end{equation}
by precomposing with the equivalence $e$. Therefore we can construct a term of type $\prd{y:P(x)}c=(x,y)$ by constructing a term of type $\prd{y:F}c=(x,e(y))$.

Furthermore, if we consider a path $p:x=x'$ in $X$ and a commuting square
  \begin{equation*}
    \begin{tikzcd}
      F \arrow[r,"e"] \arrow[d,swap,"f"] & P(x) \arrow[d,"\mathsf{tr}_P(p)"] \\
      F' \arrow[r,"{e'}"] & P(x')
    \end{tikzcd}
  \end{equation*}
  where $e$, $e'$, and $f$ are all equivalences, then we obtain a function
  \begin{equation*}
    \psi : \Big(\prd{y:F}c=(x,e(y))\Big)\to \Big(\prd{y':F'}c=(x,e'(y'))\Big).
  \end{equation*}
  The function $\psi$ is constructed as follows. Given $h:\prd{y:F}c=(x,e(y))$ and $y':F'$ we have the path $h(f^{-1}(y')):c=(x,e(f^{-1}(y')))$. Moreover, writing $G$ for the homotopy $f\circ f^{-1} \htpy\idfunc$, we have the path
  \begin{equation*}
    \begin{tikzcd}[column sep=huge]
      {\mathsf{tr}_P(p,e(f^{-1}(y')))} \arrow[r,equals,"{H(f^{-1}(y'))}"] &
      {e'(f(f^{-1}(y')))} \arrow[r,equals,"\ap{e'}{G(y')}"] &
      {e'(y')}.
    \end{tikzcd}
  \end{equation*}
  From this concatenated path we obtain the path
  \begin{equation*}
    \begin{tikzcd}[column sep=14em]
      {(x,e(f^{-1}(y')))} \arrow[r,equals,"{\mathsf{eq\usc{}pair}(p,\ct{H(f^{-1}(y'))}{\ap{e'}{G(y')}})}"] & {(x',e'(y'))}.
    \end{tikzcd}
  \end{equation*}
  Now we define the function $\psi$ by
  \begin{equation*}
    h\mapsto \lam{y'}\ct{h(f^{-1}(y'))}{\mathsf{eq\usc{}pair}(p,\ct{H(f^{-1}(y'))}{\ap{e'}{G(y')}})}.
  \end{equation*}
  Note that $\psi$ is an equivalence, since it is given as precomposition by the equivalence $f^{-1}$, followed by postcomposition by concatenation, which is also an equivalence. Now we state the main technical result of this section, which will help us prove the contractibility of the total space of the fundamental cover of the circle by computing transport in the family $x\mapsto \prd{y:P(x)}c=(x,y)$.

  \begin{defn}
    Consider a path $p:x=x'$ in $X$ and a commuting square
    \begin{equation*}
      \begin{tikzcd}
        F \arrow[r,"e"] \arrow[d,swap,"f"] & P(x) \arrow[d,"\mathsf{tr}_P(p)"] \\
        F' \arrow[r,"{e'}"] & P(x')
      \end{tikzcd}
    \end{equation*}
    with $H:e'\circ f ~ \mathsf{tr}_P(p)\circ e$, where $e$, $e'$, and $f$ are all equivalences. Then there is for any $y:F$ an identification
    \begin{equation*}
      \mathsf{segment\usc{}tot}(y):(x,e(y))=(x',e'(f(y)))
    \end{equation*}
    defined as $\mathsf{segment\usc{}tot}(y)\defeq\mathsf{eq\usc{}pair}(p,H(y)^{-1})$.
  \end{defn}

  \begin{lem}\label{lem:compute-tr-contraction}
    Consider a path $p:x=x'$ in $X$ and a commuting square
    \begin{equation*}
      \begin{tikzcd}
        F \arrow[r,"e"] \arrow[d,swap,"f"] & P(x) \arrow[d,"\mathsf{tr}_P(p)"] \\
        F' \arrow[r,"{e'}"] & P(x')
      \end{tikzcd}
    \end{equation*}
    with $H:e'\circ f ~ \mathsf{tr}_P(p)\circ e$, where $e$, $e'$, and $f$ are all equivalences. Furthermore, let
    \begin{align*}
      h & : \prd{y:F}c=(x,e(y)) \\
      h' & : \prd{y':F'}c=(x',e'(y')).
    \end{align*}
    Then there is an equivalence
    \begin{equation*}
      \Big(\prd{y:F} h'(f(y))=\ct{h(y)}{\mathsf{segment\usc{}tot}(y)}\Big)
      \simeq \Big(\mathsf{tr}_C(p,\varphi(h))= \varphi'(h')\Big).
    \end{equation*}
  \end{lem}

  \begin{proof}
    We first note that we have a commuting square
    \begin{equation*}
      \begin{tikzcd}
        \prd{y:B(x)}c=(x,y) \arrow[r,"\blank\circ e"] \arrow[d,swap,"\mathsf{tr}_C(p)"] & \prd{y:F}c=(x,e(y)) \\
        \prd{y':B(x')}c=(x',y') \arrow[r,swap,"\blank\circ {e'}"] & \prd{y':F'}c=(x',e'(y')) \arrow[u,swap,"\psi"]
      \end{tikzcd}
    \end{equation*}
    where $\psi(h')=\lam{y}\ct{h'(f(y))}{\mathsf{segment\usc{}tot}(y)^{-1}}$. All the maps in this square are equivalences. In particular, the inverses of the top and bottom maps are $\varphi$ and $\varphi'$, respectively. The claim follows from this observation, but we will spell out the details.

    Since any equivalence is an embedding, we see immediately that the type $\mathsf{tr}_C(p)(\varphi(h))=\varphi'(h')$ is equivalent to the type
    \begin{equation*}
      \psi(\mathsf{tr}_C(p)(\varphi(h))\circ e')=\psi(\varphi'(h')\circ e').
    \end{equation*}
    By the commutativity of the square, the left hand side is $h$. The right hand side is $\psi(h')$. Therefore it follows that
    \begin{align*}
      \Big(\mathsf{tr}_C(p)(\varphi(h))=\varphi'(h')\Big)
      & \simeq \Big(h= \lam{y}\ct{h'(f(y))}{\mathsf{segment\usc{}tot}(y)^{-1}}\Big) \\
      & \simeq \Big(h'\circ f \htpy (\lam{y}\ct{h(y)}{\mathsf{segment\usc{}tot}(y)}\Big).\qedhere
    \end{align*}
  \end{proof}

  Applying these observations to the fundamental cover of the circle, we obtain the following lemma that we will use to prove that the total space of $\mathcal{E}$ is contractible.

  \begin{cor}\label{cor:construct-contraction-fundamental-cover}
    In order to show that the total space of $\mathcal{E}$ is contractible, it suffices to construct a function
    \begin{equation*}
      h : \prd{k:\Z}(\base,0_{\mathcal{E}})=(\base,k_{\mathcal{E}})
    \end{equation*}
    equipped with a homotopy
    \begin{equation*}
      H : \prd{k:\Z}h(\mathsf{succ}(k)_{\mathcal{E}})=\ct{h(k)}{\mathsf{segment\usc{}helix}(k)}.
    \end{equation*}
  \end{cor}

  In the next section we establish the dependent universal property of the integers, which we will use with \cref{cor:construct-contraction-fundamental-cover} to show that the total space of the fundamental cover is contractible.

\subsection{The dependent universal property of the integers}
\begin{lem}\label{lem:elim-Z}
Let $B$ be a family over $\Z$, equipped with a term $b_0:B(0)$, and an equivalence
\begin{equation*}
e_k : B(k)\eqvsym B(\mathsf{succ}(k))
\end{equation*}
for each $k:\Z$. Then there is a dependent function $f:\prd{k:\Z}B(k)$ equipped with identifications $f(0)=b_0$ and
\begin{equation*}
f(\mathsf{succ}(k))=e_k(f(k))
\end{equation*}
for any $k:\Z$.
\end{lem}

\begin{proof}
The map is defined using the induction principle for the integers, stated in \cref{lem:Z_ind}. First we take
\begin{align*}
f(-1) & \defeq e^{-1}(b_0) \\
f(0) & \defeq b_0 \\
f(1) & \defeq e(b_0).
\end{align*}
For the induction step on the negative integers we use
\begin{equation*}
\lam{n}e_{\mathsf{neg}(S(n))}^{-1} : \prd{n:\N} B(\mathsf{neg}(n))\to B(\mathsf{neg}(S(n)))
\end{equation*}
For the induction step on the positive integers we use
\begin{equation*}
\lam{n}e(\mathsf{pos}(n)) : \prd{n:\N} B(\mathsf{pos}(n))\to B(\mathsf{pos}(S(n))).
\end{equation*}
The computation rules follow in a straightforward way from the computation rules of $\Z$-induction and the fact that $e^{-1}$ is an inverse of $e$.
\end{proof}

\begin{eg}
For any type $A$, we obtain a map $f:\Z\to A$ from any $x:A$ and any equivalence $e:\eqv{A}{A}$, such that $f(0)=x$ and the square
\begin{equation*}
\begin{tikzcd}
\Z \arrow[d,swap,"\mathsf{succ}"] \arrow[r,"f"] & A \arrow[d,"e"] \\
\Z \arrow[r,swap,"f"] & A
\end{tikzcd}
\end{equation*}
commutes. In particular, if we take $A\jdeq (x=x)$ for some $x:X$, then for any $p:x=x$ we have the equivalence $\lam{q}\ct{p}{q}:(x=x)\to (x=x)$. This equivalence induces a map
\begin{equation*}
k\mapsto p^k : \Z \to (x=x),
\end{equation*}
for any $p:x=x$. This induces the \define{degree $k$ map} on the circle
\begin{equation*}
\mathsf{deg}(k) : \sphere{1}\to\sphere{1},
\end{equation*}
for any $k:\mathbb{Z}$, see \cref{ex:degk}.
\end{eg}

In the following theorem we show that the dependent function constructed in \cref{lem:elim-Z} is unique.

\begin{thm}
  Consider a type family $B:\mathbb{Z}\to\UU$ equipped with $b:B(0)$ and a family of equivalences
  \begin{equation*}
    e:\prd{k:\Z} \eqv{B(k)}{B(\mathsf{succ}(k))}.
  \end{equation*}
  Then the type
  \begin{equation*}
    \sm{f:\prd{k:\Z}B(k)}(f(0)=b)\times\prd{k:\Z}f(\mathsf{succ}(k))=e_k(f(k))
  \end{equation*}
  is contractible.
\end{thm}

\begin{proof}
  In \cref{lem:elim-Z} we have already constructed a term of the asserted type.
  Therefore it suffices to show that any two terms of this type can be identified.
  Note that the type $(f,p,H)=(f',p',H')$ is equivalent to the type
  \begin{equation*}
    \sm{K:f\htpy f'} (K(0)= \ct{p}{(p')^{-1}})\times \prd{k:\Z}K(\mathsf{succ}(k))=\ct{(\ct{H(k)}{\ap{e_k}{K(k)}})}{H'(k)^{-1}}.
  \end{equation*}
  We obtain a term of this type by applying \cref{lem:elim-Z} to the family $C$ over $\Z$ given by $C(k)\defeq f(k)=f'(k)$, which comes equipped with a base point
  \begin{equation*}
    \ct{p}{(p')^{-1}} : C(0),
  \end{equation*}
  and the family of equivalences
  \begin{equation*}
    \lam{\alpha:f(k)=f'(k)}\ct{(\ct{H(k)}{\ap{e_k}{\alpha}})}{H'(k)^{-1}}:\prd{k:\Z}\eqv{C(k)}{C(\mathsf{succ}(k))}.\qedhere
  \end{equation*}
\end{proof}

One way of phrasing the following corollary, is that $\Z$ is the `initial type equipped with a point and an automorphism'.

\begin{cor}
  For any type $X$ equipped with a base point $x_0:X$ and an automorphism $e:\eqv{X}{X}$, the type
  \begin{equation*}
    \sm{f:\Z\to X}(f(0)=x_0)\times ((f \circ \mathsf{succ})\htpy(e\circ f))
  \end{equation*}
  is contractible.
\end{cor}

\subsection{The identity type of the circle}

\begin{lem}\label{thm:circle_fundamental}
The total space $\sm{t:\sphere{1}}\mathcal{E}(t)$ of the fundamental cover of $\sphere{1}$ is contractible.\index{circle!fundamental cover!total space is contractible}
\end{lem}

\begin{proof}
  By \cref{cor:construct-contraction-fundamental-cover} it suffices to construct
  a function
  \begin{equation*}
    h : \prd{k:\Z}(\base,0_{\mathcal{E}})=(\base,k_{\mathcal{E}})
  \end{equation*}
  equipped with a homotopy
  \begin{equation*}
    H : \prd{k:\Z}h(\mathsf{succ}(k)_{\mathcal{E}})=\ct{h(k)}{\mathsf{segment\usc{}helix}(k)}.
  \end{equation*}
  We obtain $h$ and $H$ by the elimination principle of \cref{lem:elim-Z}. Indeed, the family $P$ over the integers given by $P(k)\defeq (\base,0_{\mathcal{E}})=(\base,k_{\mathcal{E}})$ comes equipped with a term $\refl{(\base,0_{\mathcal{E}})}:P(0)$, and a family of equivalences
  \begin{equation*}
    \prd{k:\Z}P(k) \simeq P(\mathsf{succ}(k))
  \end{equation*}
  given by $k,p\mapsto \ct{p}{\mathsf{segment\usc{}helix}(k)}$.
\end{proof}

\begin{comment}
\begin{proof}
We show that the total space satisfies singleton induction (i.e., we apply \cref{thm:contractible}). Let $P$ be a family over the total space of the fundamental cover, and let $p_0:P(\base,0_{\mathcal{E}})$. Our goal is to construct a term of type
\begin{equation*}
\prd{t:\sphere{1}}{x:\mathcal{E}(t)} P(t,x).
\end{equation*}
We do this by induction. For the base case we must construct a term of type
\begin{equation*}
\prd{k:\Z}P(\base,k_{\mathcal{E}}).
\end{equation*}
Since we have the identifications $s_k: (\base,k_{\mathcal{E}})=(\base,\mathsf{succ}(k)_{\mathcal{E}})$, we have the equivalences
\begin{equation*}
\mathsf{tr}_P(s_k) : \eqv{P(\base,k_{\mathcal{E}})}{P(\base,\mathsf{succ}(k)_{\mathcal{E}})}
\end{equation*}
for each $k:\Z$. Thus we obtain a dependent function $f:\prd{x:\mathcal{E}(\base)}P(\base,x)$ satisfying $f(0_{\mathcal{E}})=p_0$ and $f(\mathsf{succ}(k)_{\mathcal{E}})=\mathsf{tr}_P(s_k,f(k_{\mathcal{E}}))$, for each $k:\Z$.

For the loop case we must show that
\begin{equation*}
\mathsf{tr}_Q(\lloop,f)=f,
\end{equation*}
where $Q$ is the family over $\sphere{1}$ given by $Q(t)\defeq \prd{x:\mathcal{E}(t)} P(t,x)$. By function extensionality it suffices to construct a homotopy, and the transport along $\lloop$ in $Q$ computes as
\begin{equation*}
\mathsf{tr}_Q(\lloop,f)(k_{\mathcal{E}})= \mathsf{tr}_P(s_k,f(\mathsf{succ}^{-1}(k)_{\mathcal{E}})).
\end{equation*}
Therefore the following computation completes the proof:
\begin{align*}
\mathsf{tr}_Q(\lloop,f)(k_{\mathcal{E}})
& = \mathsf{tr}_P(s_k,f(\mathsf{succ}^{-1}(k)_{\mathcal{E}})) \\
& = f(\mathsf{succ}(\mathsf{succ}^{-1}(k))_{\mathcal{E}}) \\
& = f(k_{\mathcal{E}}).\qedhere
\end{align*}
\end{proof}
\end{comment}

\begin{thm}\label{thm:eq-circle}
  The family of maps
  \begin{equation*}
    \prd{t:\sphere{1}} (\base=t)\to \mathcal{E}(t)
  \end{equation*}
  sending $\refl{\base}$ to $0_{\mathcal{E}}$ is a family of equivalences. In particular, the loop space of the circle is equivalent to $\Z$.
\end{thm}

\begin{proof}
  This is a direct corollary of \cref{thm:circle_fundamental,thm:id_fundamental}.
\end{proof}

\begin{cor}
  The circle is a $1$-type and not a $0$-type.\index{circle!is a 1-type@{is a $1$-type}|textit}
\end{cor}

\begin{proof}
  To see that the circle is a $1$-type we have to show that $s=t$ is a $0$-type for every $s,t:\sphere{1}$. By \cref{ex:circle-connected} it suffices to show that the loop space of the circle is a $0$-type. This is indeed the case, because $\Z$ is a $0$-type, and we have an equivalence $(\base=\base)\simeq \Z$.

  Furthermore, since $\Z$ is a $0$-type and not a $(-1)$-type, it follows that the circle is a $1$-type and not a $0$-type.
\end{proof}

\begin{exercises}
\item \label{ex:degk}Use the fundamental cover of the circle to show that
\begin{equation*}
\neg\Big(\prd{t:\sphere{1}}\base=t\Big).
\end{equation*}
\item \label{ex:circle_degk}
\begin{subexenum}
\item Show that for every $x:X$, we have an equivalence
\begin{equation*}
\eqv{\Big(\sm{f:\sphere{1}\to X}f(\base)= x \Big)}{(x=x)}
\end{equation*}
\item Show that for every $t:\sphere{1}$, we have an equivalence
\begin{equation*}
\eqv{\Big(\sm{f:\sphere{1}\to \sphere{1}}f(\base)= t \Big)}{\Z}
\end{equation*}
The base point preserving map $f:\sphere{1}\to\sphere{1}$ corresponding to $k:\Z$ is called the \define{degree $k$ map} on the circle, and is denoted by $\mathsf{deg}(k)$.
\item Show that for every $t:\sphere{1}$, we have an equivalence
\begin{equation*}
\eqv{\Big(\sm{e:\eqv{\sphere{1}}{\sphere{1}}}e(\base)= t \Big)}{\bool}
\end{equation*}
\end{subexenum}
\item \label{ex:circle_double_cover} The \define{(twisted) double cover} of the circle is defined as the type family $\mathcal{T}\defeq\mathcal{D}(\bool,\mathsf{neg}):\sphere{1}\to\UU$, where $\mathsf{neg}:\eqv{\bool}{\bool}$ is the negation equivalence of \cref{ex:neg_equiv}.
\begin{subexenum}
\item Show that $\neg(\prd{t:\sphere{1}}\mathcal{T}(t))$.
\item Construct an equivalence $e:\eqv{\sphere{1}}{\sm{t:\sphere{1}}\mathcal{T}(t)}$ for which the triangle
\begin{equation*}
\begin{tikzcd}[column sep=tiny]
\sphere{1} \arrow[rr,"e"] \arrow[dr,swap,"\mathsf{deg}(2)"] & & \sm{t:\sphere{1}}\mathcal{T}(t) \arrow[dl,"\proj 1"] \\
\phantom{\sm{t:\sphere{1}}\mathcal{T}(t)} & \sphere{1}
\end{tikzcd}
\end{equation*}
commutes.
\end{subexenum}
\item Show that $\eqv{(\eqv{\sphere{1}}{\sphere{1}})}{\sphere{1}+\sphere{1}}$. Conclude that a univalent universe containing a circle is not a $1$-type.
\item \label{ex:is_invertible_id_S1}
\begin{subexenum}
\item Construct a family of equivalences
\begin{equation*}
\prd{t:\sphere{1}} \big(\eqv{(t=t)}{\Z}\big).
\end{equation*}
\item Use \cref{ex:circle_connected} to show that $\eqv{(\idfunc[\sphere{1}]\htpy\idfunc[\sphere{1}])}{\Z}$.
\item Use \cref{ex:idfunc_autohtpy} to show that
\begin{equation*}
\eqv{\mathsf{has\usc{}inverse}(\idfunc[\sphere{1}])}{\Z},
\end{equation*}
and conclude that ${\mathsf{has\usc{}inverse}}(\idfunc[\sphere{1}])\not\simeq{\isequiv(\idfunc[\sphere{1}])}$.
\end{subexenum}
\item Consider a map $i:A \to \sphere{1}$, and assume that $i$ has a retraction. Construct a term of type
  \begin{equation*}
    \iscontr(A)+\isequiv(i).
  \end{equation*}
\end{exercises}


% --- [ Type Lattice ] ---------------------------------------------------------

\subsection{Type Lattice}

A type lattice may be thought of as a set of subtyping relationships, represented as a directed graph from the \textit{top} type $\top$ to the \textit{bottom} type $\bot$; where every type is a subtype of $\top$, and no type is a subtype of $\bot$.

\begin{itemize}
	\item $\top$: any type
	\item $\bot$: inconsistent type
\end{itemize}

In the primitive type lattice of TIE (see figure \ref{fig:primitive_type_lattice}) for instance, both signed and unsigned 32-bit integers (\texttt{int32} and \texttt{uint32}, respectively) are subtypes of 32-bit integers (\texttt{num32}) \cite{tie_reverse_engineering_of_types}.

\begin{figure}[htbp]
	\centering
	\includegraphics[width=0.40\textwidth]{inc/tie_primitive_type_lattice.png}
	\caption{Primitive type lattice of TIE.}
	\label{fig:primitive_type_lattice}
\end{figure}

In the context of type recovery, a type lattice may be used to specify the set of possible types for a variable through upper and lower bounds; thus imposing type constraints on the variable.


\subsection{2018 Free-Response Questions}
Questions 1 and 2 are part of the same section and are allotted 30 minutes for completion with the aid of a graphing calculator.
Question 3 through 6 are part of the same section are allotted 1 hour for completion without the aid of a graphing calculator.

\begin{enumerate}
	\item People enter a line for an escalator at  rate modeled by the function $r$ given by
	\begin{equation*}
		r(t) = \begin{cases}
			44\left(\frac{t}{100}\right)^3\left(1-\frac{t}{300}\right)^7 & \text{for } 0 \leq t \leq 300 \\
			0 & \text{for } t > 300,
		\end{cases}
	\end{equation*}
	where $r(t)$ is measured in people per scond and $t$ is measured in seconds.
	As people get on to the escalator, they exit the line at a rate of 0.7 person per second,
	There are 20 people in line at time $t=0$.
	\begin{enumerate}
		\item How many people entered the line for the escalator during the time interval $0 \leq t \leq 300$?
		\item During the time interval $0 \leq t \leq 300$, there are always people in line for the escalator.
			How many people are in line at time $t=300$?
		\item For time $t > 300$, what is the first time $t$ that there are no people in line for the escalator?
		\item For time $0 \leq t \leq 300$, at what time $t$ is the number of people in line at a minimum?
			To the nearest whole number, find the number of people in line at this time.
			Justify your answer.
	\end{enumerate}

	\item Researchers on a boat are investigating plankton cells in a sea.
		At a depth of $h$ meters, the density of plankton cells, in millions of cells per cubic meter, is modeled by $p(h) = 0.2h^2e^{-0.0025h^2}$ for $0 \leq h \leq 30$ and is modeled by $f(h)$ for $h\geq 30$.
		The continuous function $f$ is not explicitly given.
		\begin{enumerate}
			\item Find $p^\prime(25)$.
				Using correct units, interpret the meaning of $p^\prime(25)$ in the context of the problem.
			\item Consider a vertical column of water in this sea with horizontal cross sections of constant area 3 square meters.
				To the nearest million, how many plankton cells are in this column of water between $h=0$ and $h=30$ meters?
			\item There is a function $u$ such that $0 \leq f(h) \leq u(h)$ for all $h \geq 30$ and $\int_{30}^{\infty}{u(h)\d{h}} = 105$.
				The column of water in part (b) is $K$ meters deep, where $K > 30$.
				Write an expression involving one or more integrals that gives the number of plankton cells in the entire column.
				Explain why this number of plankton cells is less than or equal to 2000 million.
			\item The boat is moving on the surface of the sea.
				At time $t \geq 0$, the position of the boat is $(x(t),y(t))$, where $x^\prime(t) = 662\sin{(5t)}$ and $y^\prime(t)=880\cos{(6t)}$.
				Time $t$ is measured in hours, and $x(t)$ and $y(t)$ are measured in meters.
				Find the total distance traveled by the boat over the time interval $0 \leq t \leq 1$.
		\end{enumerate}

		\begin{figure}[H]
			\label{2018_3}
			\centering
			\includegraphics[width=0.5\textwidth]{./additional_materials/2018_3.png}
			\caption{\hyperref{https://apcentral.collegeboard.org/pdf/ap18-frq-calculus-bc.pdf}{}{}{AP Calculus BC 2018 Exam Free-Response Question 3, Graph of $g$}}
		\end{figure}

	\item
		The graph of the continuous function $g$, the derivative of a function $f$, is shown above.
		The function $g$ is piecewise linear for $-5 \leq x < 3$ and $g(x)=2(x-4)^2$ for $3 \leq x \leq 6$.
		\begin{enumerate}
			\item If $f(1)=3$, what is the value of $f(-5)$?
			\item Evaluate $\int_{1}^{6}{g(x)\d{x}}$.
			\item For $-5 < x < 6$, on what open intervals, if any, is the graph of $f$ both increasing and concave up?
				Give a reason for your answer.
			\item Find the $x$-coordinate of each point of inflection of the graph of $f$.
				Give a reason for your answer.
		\end{enumerate}

		\begin{table}[H]
			\begin{center}
				\begin{tabular}{|c||c|c|c|c|c|}
					\hline
					$t$ (years) & 2 & 3 & 5 & 7 & 10 \\
					\hline
					$H(t)$ (meters) & 1.5 & 2 & 6 & 11 & 15 \\
					\hline
				\end{tabular}
			\end{center}
		\end{table}

	\item The height of a tree at time $t$ is given by a twice-differentiable function $H$, where $H(t)$ is measured in meters and $t$ is measured in years.
		Selected values of $H(t)$ are given in the table above.
		\begin{enumerate}
			\item Use the data in the table to estimate $H^\prime(6)$.
				Using correct units, interpret the meaning of $H^\prime(6)$ in the context of the problem.
			\item Explain why there must be at least one time $t$, for $2 \leq t \leq 10$ such that $H^\prime(t) = 2$.
			\item Use a trapezoidal sum with 4 subintervals indicated by the data in the table to approximate the average height of the tree over the time interval $2 \leq 2 \leq 10$.
			\item The height of the tree, in meters, can also be modeled by the function $G$, given by $G(x)=\frac{100x}{1+x}$, where $x$ is the diameter of the base of the tree, in meters.
				When the tree is 50 meters tall, the diameter of the base of the tree is increasing at a rate of 0.03 meters per year.
				According to this model, what is the rate of the change of the height of the tree with respect to time, in meters per year, at the time when the tree is 50 meters tall?
		\end{enumerate}

	\begin{figure}[H]
		\label{2018_5}
		\centering
		\includegraphics[width=0.5\textwidth]{./additional_materials/2018_5.png}
		\caption{\hyperref{https://apcentral.collegeboard.org/pdf/ap18-frq-calculus-bc.pdf}{}{}{AP Calculus BC 2018 Exam Free-Response Question 5}}
	\end{figure}

	\item The graph of the polar curves $r=4$ and $r=3+2\cos{\theta}$ are shown in the figure above.
		The curves intersect at $\theta = \frac{\pi}{3}$ and $\theta = \frac{5\pi}{3}$.
		\begin{enumerate}
			\item Let $R$ be the shaded region inside the graph of $r=4$ and outside the graph of $r=3+2\cos{\theta}$, as shown in the figure above.
				Write an expression involving an integral for the area of $R$.
			\item Find the slope of the line tangent to the graph $r=3+2\cos{\theta}$ at $\theta = \frac{\pi}{2}$.
			\item A particle moves along the portion of the curve  $r=3+2\cos{\theta}$ for $0 < \theta < \frac{\pi}{2}$.
				The particle moves in such a way that the distance between the particle and the origin increases at a constant rate of 3 units per second.
				Find the rate at which the angle $\theta$ changes with respect to time at the instant when the position of the particle corresponds to $\theta = \frac{\pi}{3}$.
				Indicate units of measure.
		\end{enumerate}

	\item The Maclaurin series for $\ln{(1+x)}$ is given by
		\begin{equation*}
			x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \ldots + (-1)^{n+1}\frac{x^n}{n} + \ldots .
		\end{equation*}
		On its interval of convergence, this series converges to $\ln{(1+x)}$.
		Let $f$ be a function defined by $f(x) = x\ln{\left(1+\frac{x}{3}\right)}$.
		\begin{enumerate}
			\item Write the first four nonzero erms and the general term of the Maclaurin series for $f$.
			\item Determine the interval of convergence for $f$.
				Show the work that leads to your answer.
			\item Let $P_4(x)$ be the fourth-degree Taylor polynomial for $f$ about $x=0$.
				Use the alternating series estimation bound to find an upper bound for $\abs{P_4(2)-f(2)}$.
		\end{enumerate}

\end{enumerate}