\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{titling}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage[numbib,nottoc]{tocbibind}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage[numbers]{natbib}
\bibliographystyle{abbrvnat}

\setlist[itemize]{topsep=0pt}
\setlist[enumerate]{topsep=0pt}
\setlength\parindent{0pt}
\setlength{\droptitle}{-1.5cm}

\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}

\newcounter{heuristic} \setcounter{heuristic}{0}
\renewcommand{\theheuristic}{\Alph{heuristic}}

\newenvironment{heuristic}[1]%
{
\refstepcounter{heuristic}
\subsection*{Heuristic \theheuristic: #1}
\vspace{-0.2cm}
}%
{}

\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\title{\vspace{-0.8cm}Vertex Coloring and Applications}
\date{May 5, 2017}
\author{\Large{Shawn Seymour\vspace{0.2cm}}\\Directed Study (MATH 3993)\\University of Minnesota Morris}

\makeatletter
\def\thm@space@setup{\thm@preskip=8pt
\thm@postskip=0pt}
\makeatother

\newtheorem{prop}{Proposition}
\newtheorem{theorem}{Theorem}

\theoremstyle{definition}
\newtheorem{definition}{Definition}

\begin{document}

\maketitle

\setlength{\parskip}{0.3cm}

\section{Introduction}
Consider the map of the 48 contiguous states in the USA. Suppose we would like to color each state such that no two states that share a boundary have the same color. How many colors would it take to do this? This problem can be modeled as a \emph{graph}. In general, we could represent every state with a \emph{vertex} and draw an \emph{edge} between two states that share a border. A graph, denoted $G = (V, E)$, is a set of vertices $V$ and a set of edges $E$. A \emph{simple graph} is a loopless, undirected graph where no two edges connect the same pair of vertices. For our purpose, assume all graphs are simple graphs. This problem, along with many others, can be solved using vertex coloring. We can model the map of the 48 contiguous states as a graph. We can represent every state with a vertex and draw an edge between two states that share a border.

\begin{figure}[H]
\centering
\includegraphics[width=0.7\linewidth]{figures/map-colors.pdf}
\caption{A proper vertex coloring of the 48 contiguous states of the USA}\label{fig:map}
\end{figure}

A \emph{vertex coloring} of a graph $G$ is an assignment of colors to each vertex of a graph. A \emph{proper vertex coloring} assigns colors to a graph $G$ such that no two adjacent vertices share the same color. This can be described as a function $f : V \rightarrow S = \{1, 2, \ldots, k\}$ such that $\forall u,w \in V$, if $(u,w) \in E$, then $f(u) \neq f(w)$. Note that this constraint is the same constraint we applied to our map example. This means we could color our map according to our constraint with a proper vertex coloring. For our purpose, assume we mean proper vertex coloring when referring coloring a graph.

The \emph{chromatic number}, denoted $\chi(G)$, is the minimum number of colors needed to have a proper vertex coloring of a graph $G$. The \emph{vertex coloring problem} (VCP) is to find $\chi(G)$ of any given graph $G$. By applying the vertex coloring problem to our map example, we can determine how many colors one would need to color it with regards to our constraint. An example coloring of our map is shown in Figure \ref{fig:map}. The \emph{k-Colorability problem} asks if a graph can be colored with $k$ colors. If a graph can be colored with $k$ colors, it is said to be \emph{k-colorable}.

\section{Computational Complexity}\label{sec:complexity}
Finding an optimal solution to the vertex coloring problem is not easy. As the VCP is an optimization problem with regards to a constraint, we know it will require heavy computation to find an optimal solution. In mathematics and computer science, we classify computationally complex problems based on type of problem they are and based on how many steps it takes to solve the problem with respect to its input size.

In this section, we will first discuss how to classify hard mathematical problems. Then, we will classify the VCP as a mathematically hard problem and show how this classification can be done.

\subsection{Classifying the Vertex Coloring Problem}
We call any problem that can be answered with ``yes'' or ``no'' a \emph{decision problem}. To classify the vertex coloring problem, we must first introduce some classes, defined by \citet{moret}:

\begin{itemize}
  \item \textbf{P}: Given a decision problem, we can solve the problem in polynomial time.
  \item \textbf{NP}: Given a decision problem, we can verify if a given solution is correct in polynomial time but cannot solve the problem in polynomial time.
  \item \textbf{NP-hard}: Given any problem, it is at least as hard as NP problems. They do not have to be in NP, however, as they do not need to have solutions verifiable in polynomial time.
  \item \textbf{NP-complete}: Given a decision problem, we can transform it to any other NP problem in polynomial time and still verify a given solution in polynomial time.
\end{itemize}

Take note that these classes are not exclusive: any member of P is also a member of NP. NP-complete problems can be thought of as the problems that are both in NP and NP-hard. Although it may seem like all problems that are NP are also NP-complete, this is not the case. There are a select few problems in NP that are not NP-complete or in P. See \citet{ladner1975structure}.

\begin{prop}
The vertex coloring problem is an NP-hard problem.
\end{prop}

It is NP-hard to compute the chromatic number of a graph. This can be proven by showing it is at least as hard as a problem in NP. This is typically done by a reduction (a transformation) to or from 3-SAT, which we'll examine later. This was proven by \citet{garey}.

\begin{prop}\label{prop:k-color-np-complete}
The k-Colorability problem, i.e. can a given graph be colored in k-colors, is NP-complete.
\end{prop}

To prove this, we need to reduce a known NP-complete problem to the vertex coloring problem in polynomial time. By reducing a known NP-complete problem to k-Colorability, we can conclude that k-Colorability is NP-complete as all NP-complete problems are reducible to all other NP-complete problems. See \citet{gareynp}. We will reduce the well-known 3-SAT problem first to the 3-Colorability problem. The 3-Colorability problem asks if a graph can be colored with 3 (or fewer) colors. Obviously, if a graph can be colored with 2 colors it can also be colored with 3.  From here, the reduction from 3-Colorability to k-Colorability follows.

\subsection{Reduction from 3-SAT to 3-Colorability}
Before we prove Proposition \ref{prop:k-color-np-complete}, we must first introduce 3-SAT.  The 3-SAT problem is a decision problem that is a variation of the original NP-complete problem, Boolean satisfiability (SAT). The 3-SAT problem was proven to be NP-complete. See \citet{gareynp}. SAT consists of a conjunction of $m$ clauses, i.e. $C_1 \wedge C_2 \wedge \dots \wedge C_m$. Each clause is a disjunction of at most $n$ literals, i.e. $L_1 \vee L_2 \vee \dots \vee L_n$. Each literal can be a variable or negative of a variable, i.e. $x_1, \neg x_1, x_2, \neg x_2, \dots , x_k, \neg x_k$ where $k$ is the number of distinct literals. Each literal has a value of $true$ or $false$. 3-SAT has exactly 3 literals in each clause $(n = 3)$. We will assume all of our satisfiability problems are in conjunctive normal form (CNF). 3-SAT asks whether the variables can be assigned \emph{true} or \emph{false} in such a way that the whole expression evaluates to \emph{true}. We define SAT and 3-SAT in Definition \ref{def:sat}.

\begin{definition}\label{def:sat}
SAT is a decision problem that decides the truth value of a Boolean function based on the evaluation of the clause. It determines whether there are truth values to each clause in a set of clauses that will return a truth value to the given Boolean function. 3-SAT is a variation of SAT where each clause contains exactly 3 literals.
\end{definition}

To show a reduction from 3-SAT to 3-Colorability, we need to:

\begin{enumerate}
\item Construct an instance of 3-Colorability, given an instance of 3-SAT
\item Show that if the resulting graph is 3-colorable, then the given 3-SAT problem is satisfied
\end{enumerate}

To show this reduction, we'll create an example 3-SAT problem and reduce it to 3-Colorability. This reduction will create a graph \(G = (V, E)\) having \((2n + 3m + 1)\) vertices and \((3n+6m)\) edges. See \citet{moret}. The process for creating the graph, described below, was taken from the proof given by \citet{sharma}.

Let's introduce the following 3-SAT expression $E$:
%
\begin{align*}
E = \left( x_1 \vee \neg x_2 \vee \neg x_3 \right) \wedge \left( \neg x_1 \vee x_2 \vee x_3 \right) \wedge \left( x_1 \vee x_2 \vee x_3 \right)
\end{align*}
%
To create the graph of this 3-SAT problem, we:
\begin{enumerate}
\item Create a \emph{triangle} for each variable, i.e. \(x_i\). Each has a common vertex \(B\), called the base vertex. This base vertex will be colored a color, say \(p_1\), so that the other two vertices correspond to the variable and it's negation.
\item Create a \emph{triangle} for each clause in the formula.
\item Connect each vertex of a clause triangle to the corresponding literal vertex.
\end{enumerate}

Following the above steps, we generate graph $G$, shown in Figure \ref{fig:3sat1}, from our 3-SAT expression $E$.

\begin{figure}[H]
\centering
\includegraphics[scale=0.6]{images/3sat-1.png}
\caption{\(E\) represented as a graph \(G\)}\label{fig:3sat1}
\end{figure}

If we can properly color graph \(G\) with 3 colors, then the original 3-SAT is satisfiable and the truth values of the variables are denoted by the color they received. This graph is \emph{3-colorable} and the coloring is shown in Figure \ref{fig:3sat2}.

\begin{figure}[H]
\centering
\includegraphics[scale=0.6]{images/3sat-2.png}
\caption{A possible 3-coloring of \(G\)}\label{fig:3sat2}
\end{figure}

As we see above, \emph{blue} is used for the base vertex and as part of some of the clause triangles. If we let \emph{yellow} denote \emph{true} and \emph{red} denote \emph{false}, we can see that our original 3-SAT is satisfied:
%
\begin{align*}
E &= \left( T \vee \neg T \vee \neg F \right) \wedge \left( \neg T \vee T \vee F \right) \wedge \left(T \vee T \vee F \right) \\
&= \left( T \vee F \vee T \right) \wedge \left( F \vee T \vee F \right) \wedge \left(T \vee T \vee F \right) \\
&= T \wedge T \wedge T \\
&= True
\end{align*}
%
This shows an example of the reduction from 3-SAT to 3-Colorability. If \(G\) was unable to be colored with 3 colors, then we would know that \(E\) is unable to be satisfied. From here, we can reduce 3-Colorability to 4-Colorability, and then generalize that reduction and reduce 4-Colorability to k-Colorability. The proof and illustration of this can be found in \citet{sharma}.

\section{Heuristics}
As we have seen in section \ref{sec:complexity}, the vertex coloring problem is NP-hard and thus solving it to optimality for any given instance of a graph is computationally ``impossible''. This gives us incentive to use approximation algorithms, called heuristics, to find good, but not necessarily optimal, vertex colorings. We will analyze and compare a few of the popular heuristics for solving the VCP. However, in this section, we will describe the four heuristics to solve the VCP. The input for all heuristics we define is a simple graph, $G = (V, E)$.

\newpage

\heuristic{Greedy}\label{heuristic-greedy}

Heuristic \ref{heuristic-greedy} is a simple greedy algorithm. It is defined in Algorithm \ref{alg:greedy}.

\begin{algorithm}
\caption{Greedy algorithm}\label{alg:greedy}
\begin{algorithmic}[1]
\State Label each vertex in $V$, i.e. $v_1, v_2, \dots, v_n$
\For{each $v \in V$}
\State Assign a color $p_i$ to $v_i$ using the smallest available $p_i$
\EndFor
\end{algorithmic}
\end{algorithm}

\heuristic{Welsh-Powell}\label{heuristic-welsh}

Heuristic \ref{heuristic-welsh} is the greedy algorithm with degree sequencing. Before applying the greedy algorithm, it orders the vertices according to the decreasing value of their degree. This is also known as the Welsh-Powell algorithm, which was defined by \citet{welsh}. It is defined in Algorithm \ref{alg:welsh}.

\begin{algorithm}
\caption{Welsh-Powell algorithm}\label{alg:welsh}
\begin{algorithmic}[1]
\State Label each vertex in $V$, i.e. $v_1, v_2, \dots, v_n$, such that $d_G(v_1) \geq d_G(v_2) \geq \dots \geq d_G(v_n)$
\ForAll{$v \in V$}
\State Assign a color $p_i$ to $v_i$ using the smallest available $p_i$
\EndFor
\end{algorithmic}
\end{algorithm}

\heuristic{DSATUR}\label{heuristic-dsatur}

Heuristic \ref{heuristic-dsatur} is very similar to heuristic \ref{heuristic-welsh}, but colors a graoh based on the \emph{saturation} degree of vertices, which is defined in Definition \ref{def:saturation} \cite{spinrad}. The original DSATUR algorithm was proposed by \citet{brelaz}. It is defined in Algorithm \ref{alg:dsatur}.

\begin{definition}[Saturation degree]\label{def:saturation}
The saturation degree of a vertex is the number of different colors used for vertices adjacency to it.
\end{definition}

\begin{algorithm}
\caption{DSATUR algorithm}\label{alg:dsatur}
\begin{algorithmic}[1]
\State Find the vertex $\in V$ with maximum degree and color it with color $p_1$
\While{There are uncolored vertices}
\State Choose an uncolored vertex with maximum saturation degree
\State If there is a tie, choose the vertex with maximum degree
\State Color the vertex with the least possible number
\EndWhile
\end{algorithmic}
\end{algorithm}

\heuristic{Maximal Independent Set}\label{heuristic-mis}

Heuristic \ref{heuristic-mis} colors a graph by finding maximal independent sets of \(G\). A maximal independent set (MIS) is defined in Definition \ref{def:mis}. This is quite different than our other heuristics as it does not depend on degree. Ideally, we would want to find a maximum independent set, not just a maximal independent set.

Finding a maximum independent set is NP-hard as detailed by \citet{karp1972reducibility}. This means we're including a different NP-hard in an already NP-hard problem. We chose to forgo this in favor of just finding a maximal independent set. We define the heuristic in Algorithm \ref{alg:mis}.

\begin{definition}[Maximal independent set]\label{def:mis}
An independent set is a subset $S$ of vertices in a graph such that no two vertices in the set are adjacent. $S$ is said to be maximal if no vertex outside the set can be added while still being an independent set.
\end{definition}

\begin{algorithm}
\caption{Maximal independent set algorithm}\label{alg:mis}
\begin{algorithmic}[1]
\State $p \leftarrow 1$
\While{$G$ is non-empty}
\State Find a maximal independent set of $G$, i.e. $S_i$
\State Color all vertices in $S_i$ with color $p$
\State Let $G \leftarrow G[V \setminus S_i ] $
\State $p \leftarrow p + 1$
\EndWhile
\end{algorithmic}
\end{algorithm}

\section{Analysis of Heuristics A - D}
Before comparing the heuristics, we first wanted to analyze the heuristics individually and look at the solutions they produce.

\begin{prop}
Heuristic \ref{heuristic-greedy} and Heuristic \ref{heuristic-welsh} produce a feasible, proper coloring of input graph \(G = (V, E)\).
\end{prop}

Let \(G = (V, E)\) be a simple graph. Assume that two vertices, say \(v_1, v_2 \in V\), are connected by an edge \(e_1 \in E\). Assume that \(v_1, v_2\) are colored the same color, say \(p_1\). We know that in both heuristics, we assign the smallest color \(p_i\) that is not being used by any of the neighboring vertices connected by an edge \(e_i\). WLOG, the heuristic would color \(v_1\) color \(p_1\). The next iteration, while vertex \(v_2\) is selected, the heuristic would see color \(p_1\) is assigned to a neighboring vertex \((v_1)\), and assign the next available color \(p_2\). Thus, we've reached a contradiction.

\begin{prop}
Heuristic \ref{heuristic-dsatur} produces a feasible, proper coloring of input graph \(G = (V, E)\).
\end{prop}

Let \(G = (V, E)\) be a simple graph. We color the vertex with the maximum degree color 1. If there are no uncolored vertices, we have properly colored $G$. If there are, then we find an uncolored vertex $v$ with maximum saturation degree. We then color $v$ with the smallest available color. This means we look at the set of all adjacent vertices to $v$ and find the smallest unused color in this set. This means we will never color an adjacent vertex with the same color, and thus, will always result in a proper coloring.

\begin{prop}
Heuristic \ref{heuristic-mis} produces a feasible, proper coloring of input graph \(G = (V, E)\).
\end{prop}

Let \(G = (V, E)\) be a simple graph. Let $p$, the current color, be 1. By definition \ref{def:mis}, we know that no two vertices in a maximal independent set are adjacent. Thus, when we color the vertices in the MIS with the smallest color \(p_1\) for the first iteration, we know that it is properly colored. We then remove the found maximal independent set and increment $p$ to 2. If $G$ is now empty, then $G$ is properly colored. If $G$ is not empty, then we repeat the process except we use color 2. Because we are always incrementing the color for each iteration, we know the MIS found will always be properly colored with a different color than the past MIS.

Now that we know our heuristics produce feasible, proper colorings of a graph, how do we know they do not produce optimal solutions? We show they do not using counterexamples.

\begin{prop}
Heuristic \ref{heuristic-greedy} and Heuristic \ref{heuristic-welsh} do not produce optimal solutions, i.e. they do not always produce a minimum coloring for all graphs.
\end{prop}

We will show this for \emph{heuristic \ref{heuristic-welsh}}. It is trivial to show the same for \emph{heuristic \ref{heuristic-greedy}} as \emph{heuristic \ref{heuristic-welsh}} includes the same steps as \emph{heuristic \ref{heuristic-greedy}}. We will construct a simple graph, \(G = (V, E)\), such that:
%
\begin{align}
|V| &\geq 8 \\
\chi(G) &> \chi^{*}(G)
\end{align}
%
Let \(\chi(G)\) refer to the coloring of \(G\) generated by \emph{heuristic \ref{heuristic-welsh}}. Let \(\chi^{*}(G)\) be the optimal coloring of \(G\). We constructed a simple graph, \(G_1 = (V, E)\), such that \(\Delta(G_1) = 3\) and \(\delta(G_1) = 1\).

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{images/graph-1.png}
\caption{Uncolored original graph \(G_1\)}
\end{figure}

By applying \emph{heuristic \ref{heuristic-welsh}}, we get the following coloring. The numbers indicate the order the vertices were colored in while applying the heuristic. Any vertex of the same degree got assigned arbitrarily. This results in \(\chi(G_1) = 3\).

\begin{multicols}{2}
  \begin{figure}[H]
  \centering
  \includegraphics[scale=0.5]{images/graph-2.png}
  \caption{Coloring of $G_1$ after applying heuristic \ref{heuristic-welsh}}
  \end{figure}

  \begin{figure}[H]
  \centering
  \includegraphics[scale=0.5]{images/graph-3.png}
  \caption{Optimal coloring of graph \(G_1\)}\label{fig:ex1-optimal}
  \end{figure}
\end{multicols}

\begin{definition}[Bipartite graph]
A bipartite graph is one whose vertex set can be partitioned into two subsets X and Y such that each edge has one end in X and one end in Y.
\end{definition}

We can see that $G_1$ is a bipartite graph. Thus, \(G_1\) is 2-colorable as all bipartite graphs are 2-colorable. See \citet{asratian1998bipartite}. This means \(\chi^{*}(G_1) = 2\). \(G_1\) is an example graph that satisfies our given conditions \((1)\) and \((2)\). The optimal coloring is shown in Figure \ref{fig:ex1-optimal}.

Although Heuristic \ref{heuristic-greedy} and Heuristic \ref{heuristic-welsh} do not always produce an optimal coloring for bipartite graphs, Heuristic \ref{heuristic-dsatur} always will produce an optimal coloring (2 colors). Heuristic \ref{heuristic-dsatur}, however, does not produce optimal colorings for all graphs. Both of these results are shown and proven by \citet{brelaz}.

\begin{prop}
Heuristic \ref{heuristic-dsatur} does not produce an optimal solution, i.e. it does not always produce a minimum coloring for all graphs.
\end{prop}

To show this, we've created a graph $G_2 = (V, E)$ for this example. This is shown in.

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{images/dsatur-1.png}
\caption{Uncolored original graph \(G_2\)}\label{fig:ex2-uncolored}
\end{figure}

By applying heuristic \ref{heuristic-dsatur}, we can see that $G_2$ is \emph{4-colorable}. This is shown in Figure \ref{fig:ex2-colored}.

\begin{multicols}{2}
  \begin{figure}[H]
  \centering
  \includegraphics[scale=0.5]{images/dsatur-2.png}
  \caption{Coloring of \(G_2\) after applying heuristic \ref{heuristic-dsatur}}\label{fig:ex2-colored}
  \end{figure}

  \begin{figure}[H]
  \centering
  \includegraphics[scale=0.5]{images/dsatur-3.png}
  \caption{Optimal coloring of \(G_2\)}\label{fig:ex2-optimal}
  \end{figure}
\end{multicols}

This is a non-optimal solution as this graph is \emph{3-colorable}. This means \(\chi^{*}(G_2) = 3\). Thus, we can see that heuristic \ref{heuristic-dsatur} does not always give us an optimal solution. The optimal coloring of $G_2$ is shown in Figure \ref{fig:ex2-optimal}.

\begin{prop}
Heuristic \ref{heuristic-mis} does not produce an optimal solution, i.e. it does not always produce a minimum coloring for all graphs.
\end{prop}

To show this, we will create another example that satisfies conditions \((1)\) and \((2)\) from earlier. We've constructed a graph \(G_3 = (V,E)\) for this example. This is shown Figure \ref{fig:ex3-uncolored}.

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{images/mis-1.png}
\caption{Uncolored original graph \(G_3\)}\label{fig:ex3-uncolored}
\end{figure}

By applying heuristic \ref{heuristic-mis} and finding maximal independent sets, we see that \(G_3\) is \emph{5-colorable}. This is shown Figure \ref{fig:ex3-colored}.

\newpage

\begin{multicols}{2}
  \begin{figure}[H]
  \centering
  \includegraphics[scale=0.5]{images/mis-2.png}
  \caption{Coloring of \(G_3\) after applying heuristic \ref{heuristic-mis}}\label{fig:ex3-colored}
  \end{figure}

  \begin{figure}[H]
  \centering
  \includegraphics[scale=0.5]{images/mis-3.png}
  \caption{Optimal coloring of \(G_3\)}\label{fig:ex3-optimal}
  \end{figure}
\end{multicols}

This is a non-optimal solution. We can see that the subgraph created by vertices \(\{5, 6, 7, 8\}\) is complete and thus we need at least 4 colors. This graph is \emph{4-colorable} however, meaning \(\chi^{*}(G_3) = 4\). Thus, we can see that heuristic \ref{heuristic-mis} does not always give us an optimal solution. The optimal coloring of $G_3$ is shown in Figure \ref{fig:ex3-optimal}.

\begin{prop}
Heuristic \ref{heuristic-greedy} and heuristic \ref{heuristic-welsh} yield an upper bound of \(\Delta + 1\).
\end{prop}

To show this, we will create another example that satisfies conditions \((1)\) and \((2)\) from above. After doing some research into bipartite graphs, we learned that \emph{crown graphs} are excellent at showing how bad greedy heuristics can be, as shown and defined by \citet{kordecki}.

\begin{definition}[Crown Graph]
A crown graph \(CR_n = (V, E)\) is an undirected graph such that \(U = \{u_1, u_2, \dots, u_i\}\) and \(W = \{w_1, w_2, \dots, w_j\}\) where \(V = U \cup W\), \(U \cap W = \emptyset\), and \(|U| = |W|\). There is an edge from \(u_i\) to \(w_j\) whenever \(i \neq j\). A crown graph can also be viewed as a complete bipartite graph where the edges of a perfect matching have been removed.
\end{definition}

We constructed a simple crown graph, \(G_3 = (V, E)\). We've let \(|V| = 10\) for this example.

\begin{figure}[H]
\centering
\includegraphics[scale=0.38]{images/graph-4.png}
\caption{Uncolored original graph \(G_4\)}
\end{figure}

We can see that \(\Delta(G_4) = 4\). We can also see \(d_{G_4}(v) = 4\) for all \(v \in V\). Thus, in both heuristics \ref{heuristic-greedy} and \ref{heuristic-welsh}, the algorithm would pick an order arbitrarily. We can show using this crown graph the worst-case scenario of these heuristics.

\begin{multicols}{2}
  \begin{figure}[H]
  \centering
  \includegraphics[scale=0.38]{images/graph-5.png}
  \caption{Worst-case coloring of \(G_4\)}\label{fig:ex4-colored}
  \end{figure}

  \begin{figure}[H]
  \centering
  \includegraphics[scale=0.38]{images/graph-6.png}
  \caption{Optimal coloring of \(G_4\)}\label{fig:ex4-optimal}
  \end{figure}
\end{multicols}

\vspace{-0.3cm}

As shown in Figure \ref{fig:ex4-colored}, using either heuristic with this ordering, we get \(\chi(G_4) = 5\). This gives us \(\frac{|V|}{2}\) colors. This is the worst-case for a crown graph. See \citet{johnson}. This graph also demonstrates the upper bounds for these heuristics.

Let's take a look at how this looks in general. Let \(P = (V, E)\) be a simple, complete graph. We can see that \(\chi(H) = \Delta(H) + 1\). This is very easy to see in a \emph{complete} graph, where all vertices are connected to every other vertex. This means all vertices have degree \(|V| - 1\). Thus, every time we color a node, a new color is needed. And since we have \(\Delta(P) = |V| - 1\) and \(|V|\) vertices, we will need \(\Delta(P) + 1\) colors. This is stated in \emph{Brooks' Theorem}.

\begin{theorem}[Brooks' Theorem]
For any connected undirected graph \(G\) with maximum degree \(\Delta\), the chromatic number of \(G\) is at most \(\Delta\) unless \(G\) is a complete graph or an odd cycle, in which case the chromatic number is \(\Delta + 1\).
\end{theorem}

The proof of Brook's Theorem is shown by \citet{lovasz}. Overall, heuristics can produce undesirable results compared to the optimal solution. In graph \(G_4\), in the worst case, some heuristics produce \(\chi(G_4) = 5\) when \(\chi^{*}(G_4) = 2\) as it is a bipartite graph. This is shown in Figure \ref{fig:ex4-optimal}.

\vspace{-0.1cm}

\section{Results}
Our main goal was to compare these heuristics to find out which heuristic was most effective in efficiently approximating the vertex coloring problem. we wanted to compare both quality (number of colors used) and efficiency (running time). For this study, we decided to omit the maximal independent set heuristic (heuristic \ref{heuristic-mis}) as it was so different from the other 3 as well as including another NP-hard problem. We implemented the three heuristics in Java and ran simulations according to the following:
\begin{itemize}
  \setlength\itemsep{0.4em}
  \item Graphs were randomly generated based on the \emph{Erdős–Rényi} model, given in \citet{erdds1959random}. This model generates a random graph with approximately $p$ percent of edges.
  \item We analyzed graphs with $10\%, 20\%, \ldots, 90\%$ edges. We called this the type of the graph. This gave us both sparse and dense graphs.
  \item Simulations were run on graphs with 5 different amount of vertices: 50, 100, 250, 500, 1000.
\end{itemize}

We used statistical analysis to compare the number of colors used and the running time of each heuristic based on edge percentage (type) and then also looked at how this changed as the number of vertices changed.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{../poster/figures/plot-colors.pdf}
  \caption{Number of colors used for the three heuristics of graphs with 50, 100, 250, 500, \& 1000 vertices}\label{fig:compare-colors}
\end{figure}

Based on computational data of the amount of colors used, as shown in Figure \ref{fig:compare-colors}, we found:
\begin{itemize}
  \item Heuristic \ref{heuristic-greedy} (Greedy) uses on average 2.52 colors more than Heuristic \ref{heuristic-welsh} (Welsh-Powell).
  \item Heuristic \ref{heuristic-welsh} (Welsh-Powell) uses on average 2.79 colors more than Heuristic \ref{heuristic-dsatur} (DSATUR).
\end{itemize}
This led us to the following partial order based on colors used, where $X \preceq Y$ means heuristic $X$ uses significantly more colors than heuristic $Y$.
\begin{center}
  \textbf{Greedy $\preceq$ Welsh-Powell $\preceq$ DSATUR}
\end{center}
As vertices increased, the partial order defined above stays consistent. Heuristic \ref{heuristic-dsatur} (DSATUR) always used the least colors while Heuristic \ref{heuristic-greedy} (Greedy) always used the most.

Based on computational data of the running time, as shown in Figure \ref{fig:compare-time}, we found:
\begin{itemize}
  \item Welsh-Powell is significantly slower than Greedy.
  \item DSATUR is significantly slower than Welsh-Powell.
\end{itemize}
This led us to the following partial order based on running time, where $X \preceq Y$ means heuristic $X$ uses significantly less time than heuristic $Y$.
\begin{center}
  \textbf{Greedy $\preceq$ Welsh-Powell $\preceq$ DSATUR}
\end{center}

\newpage

As the edge percentage increases:
\begin{itemize}
  \item Heuristic \ref{heuristic-dsatur} (DSATUR) running time increases.
  \item Heuristic \ref{heuristic-greedy} (Greedy) and Heuristic \ref{heuristic-welsh} (Welsh-Powell) running time increases until 50\% edges then decreases until 90\% edges.
  \item The difference in running time between DSATUR and Greedy as well as DSATUR and Welsh-Powell grows larger and larger.
\end{itemize}

\begin{figure}[H]
  \includegraphics[width=\linewidth]{../poster/figures/plot-time.pdf}
  \caption{Running time for each edge percentage of graphs with 50, 100, 250, 500, \& 1000 vertices}\label{fig:compare-time}
\end{figure}

\section{Conclusion}
Although we were not able to compare the coloring of the heuristics to the optimal coloring, we were able to determine which heuristics gave the closest to the optimal solution. We found that Heuristic \ref{heuristic-dsatur} (DSATUR) produced the lowest number of colors. However, DSATUR also utilized the most time especially as the edge percentage of the graph grew. This is undesirable, because in large graphs, this defeats our purpose of using heuristics to efficiently approximate the VCP.

Based on our overall results, we would suggest using Heuristic \ref{heuristic-welsh} (Welsh-Powell) for most graphs. This is because the extra time needed from Heuristic \ref{heuristic-greedy} (Greedy) to Heuristic \ref{heuristic-welsh} (Welsh-Powell) to achieve better accuracy is not as significant compared to the extra time needed from Heuristic \ref{heuristic-welsh} (Welsh-Powell) to  Heuristic \ref{heuristic-dsatur} (DSATUR).

\newpage

\bibliography{references}

\end{document}


\lab{The Standard Library}{Standard Library}
\objective{Become familiar with the Python standard library and learn how to import and use modules.}
\label{lab:Standard Library}

\section*{Introduction}

Python is designed to make it easy to implement complex tasks with little code.
To that end, any Python distribution includes several built-in functions for accomplishing common tasks.
In addition, Python is designed to import and reuse Python code written by others.
A Python file that can be imported is called a module.
For example, it is possible to import a Python module that produces graphs and figures.
Any Python distribution includes a collection of modules for accomplishing a variety of tasks.
These modules are called the Python standard library.

In this lab, we describe and explore Python built-in functions and the standard library.
Having a solid foundation in this material will lead to more efficient coding in future labs.

\section*{Python Built-in Functions}

As mentioned, every Python installation will come with several built-in functions.
A listing of all Python built-in functions can be found \href{https://docs.python.org/2/library/functions.html}{here}.
Built-in functions may be used at any time and Python will recognize them.
The following examples of some built-in functions will be useful for future labs.

\begin{lstlisting}
# abs() returns the absolute value of a number
>>> abs(-5)
5

# min() returns the smallest element of a list or string
>>>min([1,2,3])
1
>>> min('xyz')
'x'

# max() returns the largest element of a list or string
>>> max([1,2,3])
3
>>> max('xyz')
'z'

# len() returns the length of a list or string
>>> len([1,2,3])
3
>>> len('abc')
3

# sum() returns the sum of a list
>>> sum([1,2,3])
6

# range(n) returns a list of numbers from 0 to n-1
>>> range(3)
[0,1,2]
\end{lstlisting}

% Problem 1: built-in methods with lists
\begin{problem}
Download \li{spec.py} to use as a solutions script and save it as \li{solutions.py}.
Write a function that accepts a list of numbers as input and returns a list with the minimum, maximum, and average of the original list.
Remember to use floating point division to calculate the average.
\end{problem}

\section*{Names, Namespaces, and Modules}

\subsection*{Names and Namespaces}
All objects created in Python resides in memory.
These objects may be data, data structures, methods, or any other sort of Python object.
A Python name is a reference to a Python object.

A namespace is a dictionary that maps names to Python objects.
For example, in the following code block we create several names.

\begin{lstlisting}
# The number 13 is the object, x is the name.
>>> x = 13

# The number 4 is the object, number_of_students is the name.
>>> number_of_sudents = 4

# This is more complicated. The set of Python statements form an object.
# The name is add_numbers.
>>> def add_numbers(a, b):
...     return a + b
...
# The list is the object, and students is the name.
>>> students = ["John", "Paul", "George", "Ringo"]
\end{lstlisting}

The equal sign assigns an object to a name.
In the previous code the equal sign assigned 13 to the name \li{x}.
%If the object on the right hand side of the equal sign is a name, then the name on the left hand side refers to the same object as the name on the right hand side.
If a name is assigned to another name, that new name refers to the same object that the orignal name refers to.
For example, if as above the name \li{students} is assigned a list of names, and then the name \li{band\_members} is assigned \li{students}, then both \li{band\_members} and \li{students} refer to the same object.

\begin{lstlisting}
>>> students = ["John", "Paul", "George", "Ringo"]
>>> band_members = students

# band_members now referes to the same object as students.
>>> band_members
['John', 'Paul', 'George', 'Ringo']
\end{lstlisting}

Python objects may be mutable or immutable.
An immutable object cannot be altered once created.
A mutable object's value may be changed.
For example, a list is mutable while a tuple is immutable.
\begin{lstlisting}
>>> example_tuple = (1,2)
>>> example_tuple[0] = 3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment

>>> example_list = [1,2]
>>> example_list[0] = 3
>>> example_list
[3,2]
\end{lstlisting}

If two names refer to the same mutable object, then any changes to the object is reflected in both names.
To avoid this, create a copy of an object.
Changes made to the copy will not change the original object.
The way to make a copy of an object varies with object types.
To make a copy of a list, use the \li{list()} built-in method.

\begin{lstlisting}
>>> students = ["John", "Paul", "George", "Pete"]
>>> band_members = students

# Replace 'Pete' with 'Ringo' in band_members
>>> band_members[3] = "Ringo"
>>> print(band_members)
['John', 'Paul', 'George', 'Ringo']

# Since 'students' and 'band_members' refer to the same object,
# 'Ringo' also replaces 'Pete' in students
>>> print(students)
['John', 'Paul', 'George', 'Ringo']

# Make a copy this time
>>> students = ["John", "Paul", "George", "Pete"]
>>> band_members = list(students)
>>> band_members[3] = "Ringo"
>>> print(band_members)
['John', 'Paul', 'George', 'Ringo']
>>> print(students)
['John', 'Paul', 'George', 'Pete']
\end{lstlisting}

% Problem 2: which Python objects are immutable?
\begin{problem}
Python has several methods that seem to change immutable objects.
These methods actually work by making copies of objects. We can determine which object types are mutable and immutable by using the equal sign and ``changing'' the objects.
For example, if two names refer to the same list then changes to the entries of one name show up in the second.

\begin{lstlisting}
>>> list_1 = [1,2,3]
>>> list_2 = list_1
>>> list_1.append(4)
>>> print(list_1)
[1, 2, 3, 4]
>>> print(list_2)
[1, 2, 3, 4]
\end{lstlisting}

Performing a similar operation on a tuple yields a different result.
\begin{lstlisting}
>>> tuple_1 = (1,2,3)
>>> tuple_2 = tuple_1
>>> tuple_1 = tuple_1 + (4,)
>>> print(tuple_1)
(1, 2, 3, 4)
>>> print(tuple_2)
(1, 2, 3)
\end{lstlisting}

Using this technique, determine which Python object types are mutable and which are immutable.
Recall that the Python object types are numbers, strings, lists, tuples, and dictionaries.
Use the following operations to modify each type.
\begin{center}
\begin{tabular}{|c|c|}
\hline
numbers & num += 1 \\
\hline
strings & str1 += `a' \\
\hline
lists & list1.append(1) \\
\hline
tuples & tup1 += (1,) \\
\hline
dictionaries & dic1[1] = `a' \\
\hline
\end{tabular}
\end{center}
\end{problem}

\subsection*{Modules}

In general, a module is a file that contains Python statements.
The Python \li{import} operation loads the statements from a Python file.
When writing scripts and modules, all \li{import} statements occur at the top of the file.

The \li{import} statement first tries to find the Python file specified.
Once found, every statement in the Python file is executed.
Once imported, a module's names are available to the user.

For example, download the file \li{example\_module.py} and save it to a directory.
In a Python interpreter, navigate to a directory where the file is not saved.
If the interpreter then tries to import \li{example\_module}, it throws an error:

\begin{lstlisting}
>>> import example_module
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named example_module
\end{lstlisting}

If the interpreter is running a directory that contains the module, no error is thrown and the module's names become available:

\begin{lstlisting}
>>> import example_module
>>> example_module.add_numbers(1,1)
2
>>> example_module.print_students()
John
Paul
George
Ringo
>>> example_module.students
['John', 'Paul', 'George', 'Ringo']
\end{lstlisting}

If the module is changed after it is imported, use the \li{reload} command to access those changes.
Using the \li{import} command again will not change the module.
For example, if a method called \li{subtract\_numbers} is added to \li{example\_module}, then \li{reload} is used instead of \li{import}.

\begin{lstlisting}
# Add this function to example_module.py and save it.

def subtract_numbers(a,b):
	return a - b
\end{lstlisting}

\begin{lstlisting}
# After modifying example_module.py, try to update the module with 'import'.
>>> import example_module
>>> example_module.subtract_numbers(2,1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'subtract_numbers'

# Now use 'reload' instead of 'import'.
>>> reload(example_module)
>>> example_module.subtract_numbers(2,1)
1
\end{lstlisting}

% Problem 3: create your own module.
\begin{problem}
Create a module called \li{calculator.py}.
Write a function that returns the sum of two arguments, a function that returns the product of two arguments, and a function that returns the square root of a single argument.
(Hint: read the first paragraphs of the next section).

In your solutions file, import the \li{calculator} module.
Using the functions defined in the module, write a new function that calculates the length of the hypotenuse of a right triangle given the lengths of the other two sides.
\end{problem}

\section*{Python Standard Library}

Any Python distribution includes a set of modules that are available for use.
This set of modules is called the Python standard library.
To access a module in the standard library use the \li{import} command with the module name.

A summary of the documentation for these modules, called the docstring, can be read using the \li{\_\_doc\_\_} name.
For example, there is a \li{math} module in the standard library that includes common mathematical functions.
To read the docstring, do the following.
\begin{lstlisting}
>>> import math
>>> math.__doc__
'This module is always available.  It provides access to the\nmathematical functions defined by the C standard.'
\end{lstlisting}
Functions also have docstrings.
\begin{lstlisting}
>>> math.cos.__doc__
'cos(x)\n\nReturn the cosine of x (measured in radians).'
\end{lstlisting}

More extensive documentation is available using the \li{help} built-in function.
Many Python interpreters provide a similar function by using a question mark.
In IPython, the question mark yields:

\begin{lstlisting}
In [0]: import math

In [1]: math?
Type:        module
String form: <module 'math' from '/Users/ACME/anaconda/lib/python2.7/lib-dynload/math.so'>
File:        /Users/ACME/anaconda/lib/python2.7/lib-dynload/math.so
Docstring:
This module is always available.  It provides access to the
mathematical functions defined by the C standard.
\end{lstlisting}

Many interpreters also provide shortcuts for exploring modules.
In IPython if the tab button is pressed after a module name followed by a period, the available functions are displayed.

\begin{lstlisting}
In [1]: import math

# typing math. and then pressing tab gives the available functions.
In [2]: math.
math.acos       math.atanh      math.e          math.factorial
math.hypot      math.log10      math.sin        math.acosh
math.ceil       math.erf        math.floor      math.isinf
math.log1p      math.sinh       math.asin       math.copysign
math.erfc       math.fmod       math.isnan      math.modf
math.sqrt       math.asinh      math.cos        math.exp
math.frexp      math.ldexp      math.pi         math.tan
math.atan       math.cosh       math.expm1      math.fsum
math.lgamma     math.pow        math.tanh       math.atan2
math.degrees    math.fabs       math.gamma      math.log
math.radians    math.trunc

In [2]: math.sqrt?
Type:        builtin_function_or_method
String form: <built-in function sqrt>
Docstring:
sqrt(x)

Return the square root of x.
\end{lstlisting}

\subsection*{The \li{sys} module}

The \li{sys} module includes methods for interacting with the Python interpreter.
The module has a name \li{argv} that is a list of arguments passed to the interpreter when it runs Python scripts.
Consider the following script.

\begin{lstlisting}
# Save this as test_script.py
import sys

print(sys.argv)
\end{lstlisting}

If this script is run from the command line with additional arguments it will print them out.

\begin{lstlisting}
$ python test_script.py I am the walrus
['test_script', 'I', 'am', 'the', 'walrus']
\end{lstlisting}

Note that command line arguments are parsed as strings.
This method can be used to point a Python script to a file to be analyzed.
It can also be used to control a script's behavior.
For example, the following script has two methods, but which one is called depends on the command line arguments.

\begin{lstlisting}
import sys

arg = "an input for a method"

def method1(arg):
	print("-".join(arg))

def method2(arg):
	print(arg.split())

if sys.argv[1] == 1:
	method1(arg)

elif sys.argv[1] == 2:
	method2(arg)
\end{lstlisting}

\subsection*{The \li{time} module}

The \li{time} module includes functions for dealing with time.
In particular, functions in \li{time} access the computer's system clock.
This is useful for precisely measuring how long it takes for code to run.

The \li{time} module includes a function also called \li{time} that measures the number of seconds from a fixed starting point, the ``Epoch''.
For most machines, this starting point will be January 1, 1970.

\begin{lstlisting}
>>> import time

# time.time() returns the number of seconds from January 1, 1970 to the
# time of execution. This command gives a new time every time it is run.
>>> time.time()
1436832057.321525
\end{lstlisting}

In order to measure how long it takes to execute some Python code, a mesurement is taken right before and right after it is run.
Subtracting the first measurement from the second gives the amount of time in seconds that have passed.

\begin{lstlisting}
def time_for_loop():
	# Time how long it takes to go through 10000 iterations using 'range'.
	start = time.time()				# clock the starting time
	for i in range(10000): pass		# perform the operation
	end = time.time()				# clock the ending time
	return end - start				# report the difference
\end{lstlisting}

The standard library also has a module called \li{timeit}.
This library is built to time Python code and has more tools than
\li{time}.
In IPython, \li{timeit} can be used like a built-in function any time with the \li{\%timeit} command.

\begin{lstlisting}
# Put any code or function name after %timeit to time how long it takes to run.
# %timeit will run the code as many times as possible and return the best time.

# Time how long it takes to go through 10000 iterations using 'xrange'.
In [0]: %timeit for i in xrange(10000): pass
1000 loops, best of 3: 303 µs per loop
\end{lstlisting}

% Problem 4: running a file from the command line and timing code segments
\begin{problem}
Download the files \li{matrix\_multiply.py} and \li{matrices.npz}.
The Python file \li{matrix\_multiply.py} is a module that has three methods for multiplying two matrices together, called \li{method1}, \li{method2}, and \li{method3}.
It also has a \li{load\_matrices} method that returns two matrices from \li{matrices.npz}.

Write a function that will do the following:
\begin{enumerate}
\item Import the \li{matrix\_multiply} module.
\item If no command line argument is given, print ``No Input."  If anything other than \li{matrices.npz} is given, print ``Incorrect Input."
\item If \li{matrices.npz} is given as a command line argument, use the \li{load\_matrices} function to load two matrices.
\item Finally, time how long each method takes to multiply the two matrices together. Print the results to the terminal.
\end{enumerate}
\end{problem}


\section{Introduction}

\subsection{History of Cryptocurrencies}

In 1983, David Chaum created ecash \cite{panurach1996money} an anonymous cryptographic electronic money.
This cryptocurrency use \gls{rsa} blind signatures \cite{chaum1983blind} to spend transactions.
Later, in 1989, David Chaum found an electronic money corporation called DigiCash Inc.
It was declared bankruptcy in 1998.

Adam Back developed a \gls{pow} scheme for spam control, Hashcash \cite{back2002hashcash}.
To send an email, the hash of the content of this email plus a nonce has to have a numerical value
smaller than a defined target.
So, to create a valid email, the sender (miner) has to spend a considerable \gls{cpu} resource on it.
Miners should calculate a lot of hash values before finding a valid one.
This idea is used in Bitcoin proof of work because each block has a nonce guessed by the miner and
the hash of the block has to be less than the target value.

Wei Dai proposes b-money \cite{dai1998b} for the first proposal for distributed digital scarcity.
And Hal Finney created Bit Gold \cite{wallace2011rise}, a reusable proof of work for hash cash for
its algorithm of proof of work.

On 31 October 2008, Satoshi Nakamoto registered the website ``bitcoin.org'' and put a link for his
paper \cite{nakamoto2008bitcoin} in a cryptography mailing list.
In January 2009, Nakamoto released the Bitcoin software as an open-source code.
The identity of Satoshi Nakamoto is still unknown.
Since that time, the total market of Bitcoin came to 330 billion dollars in 17 of December of 2018
when its value reached a historic peak of 20 thousand dollars.

Other cryptocurrencies like Ethereum \cite{wood2014ethereum}, Monero \cite{noether2015ring} and
ZCash \cite{hopwood2016zcash} were created after Bitcoin,
but Bitcoin is still the cryptocurrency with the biggest market value.

Ethereum is a cryptocurrency that uses an account model instead of \gls{utxo} used in Bitcoin for its
transaction data structure.
It uses Solidity as its programming language for smart contracts which resembles Javascript,
so it is easier to program in it than in the stack machine programming language of Bitcoin.
Ethereum changed from proof of work (used in Bitcoin) to proof of stake
which is now the default proof mechanism of Ethereum 2.0.

Monero and ZCash are both cryptocurrencies that focus on fungibility, privacy, and decentralization.
Monero uses an obfuscated public ledger, so anyone can send transactions,
but nobody can tell the source, amount or destination.
ZCash uses the concept of zero-knowledge proof called \gls{kzsnark},
which guarantees privacy for its users.

\subsection{Objectives}

Cryptocurrencies are used as money and in smart contracts in a decentralized way.
Because of that, it is not possible to revert a transaction or undo the creation of the smart contract.
There is no legal framework or agent to solve a problem in case of the existence of a bug.
Because of that, the formal proofs are desirable in the cryptocurrency protocol.
So it can avoid big financial loss.

In the case of Bitcoin, if there is some problem in the source code,
it is possible to fix it using soft or hard forks.
In soft fork, there is an upgrade in the software that is compatible with the old software.
So it is possible the existence of old and new nodes in the same Bitcoin network.
In hard forks, all the nodes should be upgraded at the same time.
Because the newer version is not compatible with the older one.
So it is very dangerous to do this kind of fork.
Therefore in Bitcoin, this kind of fork just happened twice by accident.
It happened in 2013, because of the BerkeleyDB issue and it was solved in BIP 0050.
And happened in 2018, because of Denial of Service and inflation vulnerability bug.

In Bitcoin, the uniqueness of transaction \gls{id} was not guaranteed.
To fix this problem, it should put the block number in the coinbase transaction.
This kind of change was solved in a soft fork named SegWit.

In Ethereum, there was a bug in \gls{dao} smart contract.
Malicious users exploited a vulnerability in it with a
total loss of 150 million dollars.
There was a hard fork to undo most of the transactions that exploited this contract.
This kind of hard fork violates the principle that smart contracts should be ruled just by
algorithms without any human intervention.
The old Ethereum blockchain that has not done the fork became the Ethereum Classic.
It is the version of Ethereum that has never done a hard fork before.

The objective of this work is to give a formal definition of what a cryptocurrency should be.
There are some different definitions of a cryptocurrency in this work,
but there are some formal proofs that they are the same.

Given that cryptocurrencies and smart contracts should have guarantees of their correctness,
it is very important to verify their protocols.
The creation of formal methods for Bitcoin protocol and the proof of its correctness are
the objective of this work.

So, we are proposing a model of Bitcoin using an interactive theorem prover and dependently
typed programming language Agda.
We include a formalization of transactions, transactions tree, blocks, blockchain and
how messages are signed.
In this work, we also include functions that transform raw transactions (made with simple types like
lists, naturals) to transactions with dependent types.

\subsection{Related Work}

Beukema \cite{beukema2014formalising} was one of the first to try
to define a formal specification of Bitcoin.
In this works, functions interfaces of Bitcoin and what they should do were defined.
Most of these functions define how the Bitcoin Network protocol should be.
In this work, he does not utilize any programming language with dependent types like Agda or CoQ.
mCRL2, a specification programming language, was used.

Chaudhary and his team \cite{chaudhary2015modeling} have created a model of Bitcoin blockchain
in the model checker UPPAAL.
In his work, they calculate the probability of a malicious attack to succeed in doing a double spend.
For a small number of blocks, it is easier to do this attack.
Because of that, it is usually recommended that the user waits for more blocks confirmations
after a big transaction.

Bastiaan \cite{bastiaan2015preventing} showed a stochastic model of Bitcoin using
continuous Markov chains.
In his work, he proposes a way of avoiding a 51\% attack in the network,
using two-phase proof of work.

Orestis Melkonian \cite{melkonian2019formalizing} in his masters have done the formal specification
of BitML (smart contract language) in Agda.
BitML can be compiled to Script, the smart contract language of Bitcoin.

Kosba \cite{kosba2016hawk} in his work made a programming language called Hawk for smart contracts.
This language uses formal methods to verify privacy using zero-knowledge proofs.
Using this language, the programmer does not have to worry about implementing the cryptography,
because the compiler generates automatically an effective one.

Bhargavan \cite{bhargavan2016formal} translated Solidity and Ethereum bytecode into F*.
He verified that the Ethereum \gls{dao} bug was caught in its translation.
Nowadays, they have an implementation of \gls{evm} and Solidity in OCaml,
but they want to have a full implementation of \gls{evm} in F* too.

Luu \cite{luu2016making} built a symbolic execution tool named OYENTE to look for potential bugs.
In his work, he found a lot of contracts with real bugs.
One of these bugs was the \gls{dao} bug, that caused a loss of 60 million dollars.
He used Z3 to find a potentially dangerous path of code.

Anton Setzer \cite{setzer2018modelling} also contributed to modeling Bitcoin.
He coded in Agda the definitions of transactions and
transactions tree of Bitcoin.
Orestis Melkonian starts to formalize Bitcoin Script.

My work tries to extend the Anton Setzer model and makes it possible to use the Bitcoin protocol
from inputs and outputs from plain text.
For example, the user sends a transaction in plain text to the software and it validates if it is correct.
To use the Anton Setzer model, the user has to send the data and the proof that are both valid.