\documentclass{amsart}
\usepackage{epsfig}

%sample command

%\begin{figure}
%\centerline{\epsfig{file=fig1.eps,height=3cm}}
%\end{figure}

\newcommand{\coh}{cohomology}
\newcommand{\Hom}{\operatorname{Hom}}
\newcommand{\id}{\operatorname{id}}
%\newcommand{\Ker}{\operatorname{Ker}}
%\newcommand{\Mc}{\overline{\mathcal{M}}}
%\newcommand{\gtmb}{\gtm^\bullet}
%\newcommand{\mgnb}[1]{\overline{\mathcal{M}}_{#1,n}}
%\newcommand{\mgn}[1]{\mathcal{M}_{#1,n}}
%\newcommand{\qis}{quasi-isomorphic}
%\newcommand{\rank}{\operatorname{rank}}
\newcommand{\tr}{\operatorname{tr}}
\newcommand{\Vect}{\operatorname{Vect}}

\newcommand{\nc}{\mathbb{C}}
\newcommand{\gtg}{\mathfrak{g}}
%\newcommand{\nq}{\mathbb{Q}}
\newcommand{\nr}{\mathbb{R}}
%\newcommand{\nz}{\mathbb{Z}}
\newcommand{\OO}{\mathcal{O}}

\newtheorem{thm}{Theorem}[section]
\newtheorem{lm}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
%\newtheorem*{cor}{Corollary}

\theoremstyle{definition}
\newtheorem{df}[thm]{Definition}
\newtheorem{ex}[thm]{Example}
\newtheorem{xca}{Exercise}

\theoremstyle{remark}
\newtheorem{rem}[thm]{Remark}
%\newtheorem*{ack}{Acknowledgment}

\numberwithin{equation}{section}

%    Absolute value notation
\newcommand{\abs}[1]{\lvert#1\rvert}

\begin{document}

\title[Lecture 3]{Lecture 3: Topological Quantum Field Theory and Frobenius Algebras}
\author{Alexander A. Voronov}
%\address{Department of Mathematics\\ M.I.T.,
%2-246\\ 77 Massachusetts Ave.\\ Cambridge, MA 02139-4307}
%\curraddr{}
%\email{voronov@math.mit.edu}
%\urladdr{http://www-math.mit.edu/~voronov/}
%\thanks{Research supported in part by an AMS Centennial Fellowship.}

%\subjclass{Primary 14H10; Secondary 32G15, 55P62}
\date{September 22, 1997}

\maketitle

\section{Topological quantum field theory and Frobenius algebras}

We saw in Lecture 2 that given a modular functor, the vector space
$V_\Sigma$ associated to a Riemann surface depends, up to a scalar,
only on the diffeomorphism class of the Riemann surface $\Sigma$. This
defines what is called a topological quantum field theory. We will be
mostly interested in the situation when the central charge $c = 0$ and
there is a specific operator $|\Sigma\rangle$ (as opposed to a vector
space of such operators) corresponding at least continuously to a
surface $\Sigma$. This all translates as follows into our language.

\begin{df}
A \emph{Topological Quantum Field Theory $($TQFT$)$} is a
correspondence of the same type as a Conformal Field Theory, see
Lecture 1, except that the conformal invariance axiom is replaced with
diffeomorphism invariance: the operator $|\Sigma\rangle$ must be
invariant under diffeomorphisms of the surface $\Sigma$ taking holes
to the corresponding holes and preserving the holomorphic coordinates
there. The normalization axiom is convenient to change so as the
operator corresponding to a cylinder (a sphere with two holes) is
equal to identity.
\end{df}

\begin{thm}[Folklore]
The structure of a TQFT based on vector space $V$ is equivalent to the
structure of a finite-dimensional Frobenius algebra on it. A
\emph{Frobenius algebra} structure on a vector space $V$ means the
structure of a commutative associative algebra with a unit and a
nondegenerate symmetric bilinear form $\langle,\rangle: V \otimes V
\to \nc$ which is invariant with respect to the multiplication: $\langle
ab, c\rangle = \langle a, bc \rangle$.
\end{thm}

\begin{proof}
Let $V$ be the state space of a TQFT. We would like to construct the
structure of a Frobenius algebra on $V$. Consider the following
Riemann surfaces and the corresponding operators, which we denote
$ab$, $\langle a ,b \rangle$, \emph{etc}.
\[
\begin{array}{ccll}
\parbox{2in}{\centerline{\epsfig{width=1.5in,height=.7in,file=pants.eps}}} &
 \quad \longmapsto \quad & V \otimes V \to V, & a \otimes b \mapsto ab
\smallskip\\
\parbox{2in}{\centerline{\epsfig{width=.9in,height=.7in,file=bublik.eps}}} &
 \quad \longmapsto \quad & V \otimes V \to \nc, & a \otimes b \mapsto
\langle a,b \rangle
\medskip\\
\parbox{2in}{\centerline{\epsfig{width=.9in,height=.7in,file=bublik.eps,angle=180}}} &
 \quad \longmapsto \quad & \psi: \nc \to V \otimes V
\medskip\\
\parbox{1.5in}{\centerline{\epsfig{width=1.2in,height=.3in,file=normal.eps}}} &
 \quad \longmapsto \quad & \id: V \to V
\medskip\\
\parbox{1.5in}{\centerline{\epsfig{width=.8in,height=.4in,file=cap1.eps}}} &
 \quad \longmapsto \quad & \tr: V \to \nc
\smallskip\\
\parbox{1.5in}{\centerline{\epsfig{width=.7in,height=.4in,file=cap2.eps}}} &
 \quad \longmapsto \quad & \nc \to V, & 1 \mapsto e
\end{array}
\]

We claim that these operators define the structure of a Frobenius
algebra on $V$. Indeed, the multiplication is commutative, because if
we interchange labels at the legs of a pair of pants we will get a
diffeomorphic Riemann surface. Therefore, the corresponding operator
$a \otimes b \mapsto ba$ will be equal to $ab$. Similarly, the
associativity $(ab)c = a(bc)$ of multiplication is based on the fact
that the following two surfaces are diffeomorphic:
\begin{equation}
\label{coherence}
\parbox{7cm}{\centerline{\parbox{3.6cm}{\epsfig{file=assoc1.eps,width=3.5cm}}
$\cong$
\ \ \
\parbox{3.5cm}{\epsfig{file=assoc2.eps,width=3.5cm}}}}
\end{equation}
The property $ae = ea = a$ of the unit element comes from the
diffeomorphism
\medskip

\centerline{\parbox{3cm}{\epsfig{file=unit.eps,width=2.5cm}} $\cong$
\ \ \ \ \ \
\parbox{3.5cm}{\epsfig{file=normal.eps,width=1.8cm}}}
\smallskip

Thus, we see that $V$ is a commutative associative unital
algebra. Now, the following diffeomorphism
\medskip

\centerline{\parbox{3cm}{\epsfig{file=bublik.eps,
width=1.5cm}} $\cong$
\ \ \ \ \ \
\parbox{3.5cm}{\epsfig{file=form.eps,width=1.8cm}}}
\medskip

\noindent
proves the identity $\langle a , b \rangle = \tr (ab)$, which, along
with the associativity, implies $\langle ab,c \rangle = \langle a,bc
\rangle$. The fact that the inner product $\langle \, , \, \rangle$ is
nondegenerate follows from the diffeomorphism
\bigskip

\centerline{\parbox{3cm}{\epsfig{file=nondeg.eps,
width=2cm}} $\cong$
\ \ \ \ \ \
\parbox{2.5cm}{\epsfig{file=normal.eps,width=1.8cm}},}
\medskip

\noindent
which implies that the composite mapping
\[
\begin{array}{ccccc}
V & \xrightarrow{\id\otimes \psi(1)} & V \otimes V \otimes V &
\xrightarrow{\langle,\rangle \otimes \id} &V,\\
v & \longmapsto & \sum_{i=1}^n v \otimes u_i \otimes v_i & \longmapsto &
\sum_{i=1}^n \langle v, u_i
\rangle v_i
\end{array}
\]
is equal to $\id : V \to V$. This also implies that $\dim V < \infty$,
because the $v_i$'s, $i = 1, \dots, n$, must span $V$. This completes
the construction of the structure of a Frobenius algebra on the state
space $V$ of a TQFT.

Conversely, if we have a finite-dimensional Frobenius algebra $V$, we
can define the structure of a TQFT on the vector space $V$ by (1)
cutting a Riemann surface down into pairs of pants, cylinders, and
caps; (2) defining the operators corresponding to those basic objects
using the multiplication (or its linear dual), the identity map, and
the unit element $e \in V$ (or the dual of the map $\nc \to V $, $ 1
\mapsto e$, as the trace functional), respectively; and (3) using the
sewing axiom. The fact that the composite operator is independent of
the way we cut down the surface follows from \eqref{coherence} and the
associativity of multiplication.
\end{proof}

\begin{xca}
Find a more elegant way (not using any elements of $V$) to show that
$\dim V < \infty$.
\end{xca}
%\bibliographystyle{/usr/local/lib/texmf/tex/latex/packages/amslatex/classes/amsplain}

%\bibliographystyle{amsalpha}

%\bibliography{operads}

\end{document}


\documentclass[12pt]{article}
\usepackage{graphics}
\newcommand{\kg}{\mathrm{kg}}
\newcommand{\m}{\mathrm{m}}
\newcommand{\s}{\mathrm{s}}
\renewcommand{\deg}{\mathrm{deg}}
\newcommand{\cm}{\mathrm{cm}}
\newcommand{\mps}{\m\,\s^{-1}}
\newcommand{\mpss}{\m\,\s^{-2}}
\newcommand{\kgpmmm}{\kg\,\m^{-3}}
\newcommand{\N}{\mathrm{N}}
\newcommand{\J}{\mathrm{J}}
\newcommand{\Npmm}{\N\,\m^{-2}}
\newcommand{\tv}[1]{\mathbf{\vec{#1}}}
\newcommand{\dd}{\mathrm{d}}
\newcommand{\cell}[1]{\texttt{{#1}}}
\newcounter{problem}
\addtolength{\oddsidemargin}{-1in}
\addtolength{\textheight}{\headheight}
\setlength{\headheight}{0in}
\addtolength{\textheight}{\headsep}
\setlength{\headsep}{0in}
\setlength{\marginparwidth}{2in}
\begin{document}

\section*{NYU Physics 1---final exam}

Wednesday 2008 December 17

~ \vfill ~

\section*{Name:}

~ \vfill ~

\begin{equation}
\tv{v} = \frac{\dd}{\dd t}\,\tv{r}
\quad ; \quad
\tv{a} = \frac{\dd}{\dd t}\,\tv{v}
\end{equation}
\begin{equation}
\omega = \frac{\dd}{\dd t}\,\theta
\quad ; \quad
\alpha = \frac{\dd}{\dd t}\,\omega
\end{equation}
\begin{equation}
a_{\mathrm{circ}} = \frac{v^2}{R} = \omega^2\,R
\end{equation}
\begin{equation}
\tv{F} = m\,\tv{a}
       = \frac{\dd}{\dd t}\,\tv{p}
       = \frac{\dd}{\dd t}\,(\gamma\,m\,\tv{v})
\end{equation}
\begin{equation}
\gamma = \frac{1}{\sqrt{1 - \frac{v^2}{c^2}}}
       = \frac{1}{\sqrt{1 - \beta^2}}
\end{equation}
\begin{equation}
\tv{r}\times\tv{F} = \tv{\tau}
                   = \frac{\dd}{\dd t}\,\tv{L}
		   = \frac{\dd}{\dd t}\,(\tv{r}\times\tv{p})
\end{equation}
\begin{equation}
\tv{r}\times\tv{F} = \tv{\tau}
                   = I\,\tv{\alpha}
                   = \frac{\dd}{\dd t}\,\tv{L}
                   = \frac{\dd}{\dd t}\,(I\,\tv{\omega})
\end{equation}
\begin{equation}
|\tv{F}_{\mathrm{grav}}| = \frac{G\,M\,m}{r^2} = m\,g
\end{equation}
\begin{equation}
|\tv{F}_{\mathrm{static}}| \leq \mu\,|\tv{N}|
\quad ; \quad
|\tv{F}_{\mathrm{kinetic}}| = \mu\,|\tv{N}|
\end{equation}
\begin{equation}
U = -\frac{G\,M\,m}{r}
\quad ; \quad
\Delta U = m\,g\,\Delta h
\quad ; \quad
U = \frac{1}{2}\,k\,x^2
\end{equation}
\begin{equation}
K = \frac{1}{2}\,m\,v^2
\quad ; \quad
K = \frac{1}{2}\,I\,\omega^2
\end{equation}

\clearpage

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
What combination of $G$, the speed of light $c$, and some (arbitrary)
mass $M$ has units of \emph{length}?  Use the formulae on the formula
sheet to infer or remind yourself of the units of $G$.

~ \vfill ~

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
What is the mean acceleration $a$ of a dragster that can travel 1/4~mi
in 5.5~s, starting from a dead stop?  Assume that the dragster
accelerates with constant acceleration throughout the 5.5~s (not a
terrible assumption, but not a good one either).  Give your answer in
terms of the gravitational acceleration $g$.

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
A block of mass $m$ sits on a plane inclined at $\theta=20\,\deg$ to
the horizontal.  Between the block and the plane is a coefficient of
friction $\mu=0.9$.  What is the magnitude of the frictional force on
the block?

~ \vfill ~

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
Roughly how many carbon atoms are there in a gallon of gasoline?
State your assumptions clearly.  Recall that the atomic weight of
carbon is 12.

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
A Japanese Shinkansen (bullet train) (of mass $M=10^6~\mathrm{kg}$),
moving at $v_S=300~\mathrm{km\,h^{-1}}$ with respect to the tracks,
hits and collides elastically with a superball (of mass
$m=30~\mathrm{g}$), which is initially at rest.  The front face of the
train is inclined at an angle of $\theta=45~\mathrm{deg}$ to the
horizontal, as shown here in the rest frame of the tracks.\\
\rule{0.1\textwidth}{0pt}
\resizebox{0.8\textwidth}{!}{\includegraphics{../mp/shinkansen.eps}}

\textsl{(a)}~Draw a diagram of the ball--train system, just before the
collision, in the center-of-mass rest frame.  Clearly show the
velocities of the ball and train in this frame.

\textsl{(b)}~Draw a diagram, just after the collision, in the
center-of-mass frame.  Clearly show the velocities.

~ \vfill ~

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
Immediately after being hit, at $t=0$, a cue ball of mass $M$, radius
$R$, and moment of inertia $I=(2/5)\,M\,R^2$ slides along the felt at
speed $v_i$, not rotating at all.  As time goes on, the ball slows
down (because of friction) and, at the same time, starts to spin.
Draw a free-body diagram for the cue ball.  At what time
$t_\mathrm{r}$ does the ball get to the situation of ``rolling without
slipping''?  Assume that there is a coefficient $\mu$ of sliding
friction.

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
A figure skater spins in place on frictionless ice at angular speed
$\omega_i$ with her hands outstretched.  She has a total moment of
inertia $I_i$.  As the skater draws her hands into her body, her
moment of inertia decreases to $I_f=I_i/2$.  Does her kinetic energy
$K$ increase, decrease, or stay the same?  If it increases, where does
the energy come from?  If it decreases, where does the energy go to?
Make sure your explanation is \emph{30 words or less}.

~ \vfill ~

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
Draw a spacetime diagram showing the four events
$A=(c\,t_A,x_A)=0\,\m,0\,\m)$, $B=(1\,\m,1\,\m)$, $C=(1\,\m,0\,\m)$,
and $D=(0\,\m,1\,\m)$.  Clearly label the four events.

Transform these events to a new frame using the Lorentz
Transform
\begin{eqnarray}\displaystyle
c\,t' & = & \gamma\,c\,t - \beta\,\gamma\,   x \nonumber\\
   x' & = & \gamma\,   x - \beta\,\gamma\,c\,t \quad ,
\end{eqnarray}
with $\beta=(3/5)$.  Draw \emph{another} spacetime diagram of the
four events in the \emph{new} frame.

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
What is the magnitude of the 4-vector
$\vec{u}=(\gamma\,c,\gamma\,v_x,\gamma\,v_y,\gamma\,v_z)$?  Simplify
your answer as much as you can.

~ \vfill ~

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
What speed can you make by combining acceleration $g$ and length $R$?
Evaluate your expression for the acceleration due to gravity at the
Earth's surface and the radius of the Earth.  Estimate the radius of
the Earth if you don't know it.

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
Explain, in \emph{less than 30 words} why the astronauts in the Space
Shuttle are (or feel) weightless.

~ \vfill ~

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
Consider a particle subject to a potential energy of the form
\begin{equation}
U = \frac{B}{x^2} - \frac{A}{x} \quad ,
\label{eq:hard}
\end{equation}
where $A$ and $B$ are positive constants.  Sketch the potential
$U(x)$.

By taking derivatives, compute the equilibrium position
$x_\mathrm{eq}$.  That is, compute the $x$ position where there is no
force and the potential is at a minimum.

~ \vfill ~

\end{document}


\subsection{Quantisation}


\section{Related Work}

Other approaches have been propsed to streaming sencil codes for FPGAs.
Kano et al~\cite{sano:2014aa} propose the SCC array, a custom computational machine (CCM) which is worryingly similar to cascade.

Implementing the SSA is conceptually very simple.
Each processing element contains a shift-buffer $B$ of width $2r$, and the stencil computation is reformulated as $f(B_0, B_{r-1}, B_{r}, B_{r+1}, B{2r})$

\begin{figure}
  \centering
  \input{fig/scma}
  \caption{Systolic Computational-Memory Array (SCMA)}
  \label{fig:scma}
\end{figure}


\subsection{Polearms}

\begin{longtable}{|C{2cm} L{2cm} L{2cm} L{8cm}|}
\hline
\large{\textbf{Name}} &
\large{\textbf{Cost}} &
\large{\textbf{Handedness}} &
\large{\textbf{Damage}}
\\ \hline
\WeaponRow{Quarterstaff}{50 m}{Two}{
\textit{Crushing:} $\frac{2d8 \pm modifiers}{5}*Strength$
}{Nothing more than long sticks, \textbf{quarterstaves} are often not considered proper weapons - at least, not ones fit for military use - but are instead relegated to use by martial artists, priests, monks, wizards, guards of poorer towns, and aspiring warriors unable to afford proper weaponry.}
\WeaponRow{Spear}{80 m}{Two}{
\textit{Piercing:} $\frac{2d10 \pm modifiers}{5}*Strength$\hfill \break
\textit{Crushing:} $\frac{1d4 \pm modifiers}{5}*Strength$
}{Effectively long sticks with either pointy ends, or with an attached sharp object, \textbf{spears} are made for stabbing enemies from a distance, and thus penetrate armour effortlessly.}
\WeaponRow{Glaive}{100 m}{Two}{
\textbf{When slashing:} \hfill \break
\textit{Slashing:} $\frac{2d10 \pm modifiers}{5}*Strength$ \hfill \break
\textit{Crushing:} $\frac{1d8 \pm modifiers}{5}*Strength$ \hfill \break
\textbf{When stabbing:} \hfill \break
\textit{Piercing:} $\frac{2d12 \pm modifiers}{5}*Strength$\hfill \break
\textit{Crushing:} $\frac{1d4 \pm modifiers}{5}*Strength$
}{A \textbf{glaive} - or alternatively a \textbf{voulge}, \textbf{naginata} or \textbf{guandao} - is a variation of the spear, where the attached sharp end is enlarged - effectively attaching a dagger or a sword to a stick. Such weapons are good for both thrusting and slicing.}
\WeaponRow{Pollaxe}{110 m}{Two}{
\textbf{When slashing:} \hfill \break
\textit{Slashing:} $\frac{2d8 \pm modifiers}{5}*Strength$ \hfill \break
\textit{Crushing:} $\frac{2d8 \pm modifiers}{5}*Strength$ \hfill \break
\textbf{When stabbing:} \hfill \break
\textit{Piercing:} $\frac{2d10 \pm modifiers}{5}*Strength$\hfill \break
\textit{Crushing:} $\frac{1d4 \pm modifiers}{5}*Strength$
}{A \textbf{pollaxe} - or alternatively a \textbf{halberd} - is basically the combination of an axe and a spear - or more precisely, an axe with an enlonged handle fitting for a spear, with a spike at the very end of the weapon, allowing to fufill the function of both the spear and the axe.}
\end{longtable}


\documentclass{classrep}
\usepackage[utf8]{inputenc}
\frenchspacing

\usepackage{graphicx}
\usepackage[usenames,dvipsnames]{color}
\usepackage[hidelinks]{hyperref}
\usepackage{lmodern}
\usepackage{placeins}
\usepackage{url}
\usepackage{amsmath, amssymb, mathtools}
\usepackage{listings}
\usepackage{fancyhdr, lastpage}

\pagestyle{fancyplain}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\cfoot{\thepage\ / \pageref*{LastPage}}

%--------------------------------------------------------------------------------------%
\studycycle{Applied Information Technology, 2 cycle}
\coursesemester{II}

\coursename{Soft Computing Laboratory}
\courseyear{2021/2022}

\courseteacher{dr inż. Kamil Stokfiszewski}
\coursegroup{Wednesday, 8:30}

\author{%
    \studentinfo[239671@edu.p.lodz.pl]{Jan Karwowski}{239671}\\
    \studentinfo[239676@edu.p.lodz.pl]{Kamil Kowalewski}{239676}\\
}

\title{Assignment 1.: The Delta rule}

\begin{document}
    \maketitle
    \thispagestyle{fancyplain}

    \tableofcontents
    \newpage

    \section{Main goal}
    \label{main_goal} {
        The main goal of this task is to prepare implementation of single linear neuron.
        For training the delta rule has to be used in two variants, the first one is
        with single training patterns and the second one is with multiple training
        patterns.
    }

    \section{Theoretical background}
    \label{theory} {
        \begin{figure}[!htbp]
            \centering
            \includegraphics[width=\textwidth]{img/linear_neuron.png}
            \caption{Simple, linear artificial neuron}
            \label{artificial_neuron}
        \end{figure}
        \FloatBarrier

        The concept of artificial neuron (fig. \ref{artificial_neuron}) and its
        learning method, called ,,delta rule'' was invented many years ago. It is very
        simple and based on dot product of input values and trainable parameters called
        ,,weights''. These weights are modified during training process, to make output
        of neuron closer to the desired value (for particular input). The following
        equation presents delta rule:
        \begin{equation}
            w_{i} = w_{i} + \ni (z - y) x_{i}
        \end{equation}
        where $i$ is the number of input and its corresponding weight, $x_i$ is an
        input, $w_i$ is a weights, $y$ stands for neuron output and $z$ for desired
        output. $\ni$ is a so called ,,learnig rate'', which determines learning speed.
    }

    \section{Implementation details}
    \label{implementation} {
        Program was written in Python programming language and very popular numpy
        library was used as well. Training patterns and weights were stored as vectors
        (one-dimensional arrays) and only required operations were addition and
        multiplication. Since the whole source code consists of no more then few lines
        it definitely does not require more explanation.
    }

    \section{Experiments and results}
    \label{results} {
        This section presents simulation results for single pattern case and multiple
        pattern case. There are six mutable parameters, which was changed between
        experiments:

        \begin{itemize}
            \item the number of neuron's inputs - N
            \item the number of training epochs - K
            \item training step - $\eta$
            \item the interval, which the initial weights should be randomly chosen from -
            $[\omega_{1}, \omega_{2}]$
            \item the interval, which the training pattern's inputs should be randomly
            \item chosen
            from - $[\rho_{1}, \rho_{2}]$
            \item the number of training patterns - P (only for multiple pattern case)
        \end{itemize}

        \subsection{Single pattern experiments}
        \label{results:single} {
            Table \ref{tab:results:single} presents results for series of experiments
            related to single pattern training. Each row corresponds to single
            experiment. Single experiment is a single training attempt, where all the
            parameters are immutable and given number of epochs (training loops) are
            processed.

            \begin{table}[!htbp]
                \centering
                \begin{tabular}{|c|c|c|c|c|c|c|c|}
                    \hline
                    & N & K & $\eta$ & $[\omega_{1}, \omega_{2}]$ & $[\rho_{1},
                    \rho_{2}]$ & $y$ & $z$ \\ \hline
                    1 & 10 & 100 & 0.1 & $[-1,1]$ & $[-1,1]$ & -0.448 & -0.448 \\ \hline
                    2 & 10 & 100 & 0.01 & $[-1,1]$ & $[-1,1]$ & -0.448 & -0.5237 \\ \hline
                    3 & 10 & 100 & 0.001 & $[-1,1]$ & $[-1,1]$ & -0.448 & -0.9791 \\
                    \hline
                    4 & 10 & 10000 & 0.001 & $[-1,1]$ & $[-1,1]$ & -0.448 & -0.488 \\
                    \hline
                    5 & 10 & 100 & 0.9 & $[-1,1]$ & $[-1,1]$ & -0.448 & -5.0504e+19 \\
                    \hline
                    6 & 100 & 100 & 0.1 & $[-1,1]$ & $[-1,1]$ & 0.101 & -7.9471e+29 \\
                    \hline
                    7 & 100 & 100 & 0.01 & $[-1,1]$ & $[-1,1]$ & 0.101 & 0.101 \\ \hline
                    8 & 100 & 100 & 0.01 & $[-100,100]$ & $[-1,1]$ & 0.101 & 0.101 \\
                    \hline
                    9 & 100 & 100 & 0.0001 & $[-100,100]$ & $[-100,100]$ & 10.0999 & 3
                    .0001e+149 \\ \hline
                \end{tabular}
                \caption{Experiment results for single pattern training}
                \label{tab:results:single}
            \end{table}
            \FloatBarrier
        }

        \subsection{Multiple pattern experiments}
        \label{results:multiple} {
            During the second series of experiments, related to multiple pattern
            training, we fixed all parameters except $P$ (number of training patterns)
            to values presented in table\ref{tab:results:multiple:params}. Number of
            training patterns changes between experiments as an explored variable. It
            should be considered in compare to $N$ value(number of inputs), which is
            fixed to 5.

            \begin{table}[!htbp]
                \centering
                \begin{tabular}{|c|c|c|c|c|}
                    \hline
                    N & K & $\eta$ & $[\omega_{1}, \omega_{2}]$ & $[\rho_{1},\rho_{2}]$ \\ \hline
                    5 & 10000 & $0.1$  & $[-1,1]$ & $[-1,1]$ \\ \hline
                \end{tabular}
                \caption{Fixed parameters' values for multiple training pattern
                experiments}
                \label{tab:results:multiple:params}
            \end{table}
            \FloatBarrier

            Results of experiments are presented in tables \ref{tab:results:multiple:m3},
            \ref{tab:results:multiple:m5} and \ref{tab:results:multiple:m6}.

            \begin{table}[!htbp]
                \centering
                \begin{tabular}{|c|c|}
                    \hline
                    z & y \\ \hline
                    -0.3556 & -0.3556 \\
                    -0.629 & -0.629 \\
                    0.8344 & 0.8344 \\ \hline
                \end{tabular}
                \caption{Experiment results for 3 patterns training}
                \label{tab:results:multiple:m3}
            \end{table}
            \FloatBarrier

            \begin{table}[!htbp]
                \centering
                \begin{tabular}{|c|c|}
                    \hline
                    z & y \\ \hline
                    0.3919 & y = 0.3919 \\
                    0.1061 & y = 0.1061 \\
                    0.8705 & y = 0.8705 \\
                    0.0252 & y = 0.0252 \\
                    -0.6448 & y = -0.6448 \\ \hline
                \end{tabular}
                \caption{Experiment results for 5 patterns training}
                \label{tab:results:multiple:m5}
            \end{table}
            \FloatBarrier

            \begin{table}[!htbp]
                \centering
                \begin{tabular}{|c|c|}
                    \hline
                    z & y \\ \hline
                    0.0737 & 0.0726 \\
                    -0.4131 & -0.3817 \\
                    -0.9788 & -1.0094 \\
                    0.7676 & 0.8055 \\
                    0.3128 & 0.3175 \\
                    0.8845 & 0.8322 \\ \hline
                \end{tabular}
                \caption{Experiment results for 6 patterns training}
                \label{tab:results:multiple:m6}
            \end{table}
            \FloatBarrier
        }
    }

    \section{Summary and conclusions}
    \label{summary} {
        Meaning and importance of each training parameter can be found basing on table
        \ref{tab:results:single}. The first four rows presents the impact of learning
        rate. The smaller it is the more time (epochs) is required to train neuron
        effectively. As shown in the fifth row, it must not be too much because
        algorithm may not converge. On the other hand, sometimes it is required to use
        lower learning rate (rows six and seven), because of too complicated
        optimization problem (many many inputs). This is a kind of a trade-off between
        speed and accuracy - lower learning rate requires more epochs to converge but is
        more accurate, higher learning rate converge faster but may be applied only to
        simpler problems. Last two rows are related to initialization intervals. We can
        see that initial weights values may be larger and algorithms still converge. In
        fact, weights are modified in time and become much more closer to the desired
        value in first few steps. The situation changes when we explore inputs initial
        interval. These values, which stays constant during training, are very
        sensitive and should be normalized before training. If they are too much,
        algorithm is not able to converge (learning steps are not precise enough). We
        can try to fix it using very low learning rate, but it may not help.

        In the second series of experiments we focus on relation between number of
        training patterns(M) and number of neuron's inputs (N). Number of inputs was
        fixed to value of 5. Number of training patterns takes three values: 3, 5, and
        6. Observations from experiments, presented in tables
        \ref{tab:results:multiple:m3}, \ref{tab:results:multiple:m5} and
        \ref{tab:results:multiple:m6} are pretty straightforward. Neuron is able to
        learn number of patterns, which is lower or equal to number of input. Where
        there is more "independent" training patterns then inputs, it is not possible
        to find perfect weights' values. It can be easily explained when considered
        artificial neuron training as solving system of $P$ (number of training
        patterns) linear equations with $N$ (number of inputs) variables, where each
        training pattern is a single linear equation. If training patterns are linearly
        independent(which is almost 100\% sure for random patterns), then there is:

        \begin{itemize}
            \item infinite set of solutions for $N > P$
            \item exactly one solution for $N = P$
            \item no solution for $N < P$
        \end{itemize}
    }

    \begin{thebibliography}{0}
        % @formatter:off
        \bibitem{instruction}{Labolatory instruction, URL: https://ftims.edu.p.lodz.pl/pluginfile.php/75436/\\mod\_resource/content/3/soft\_comp\_lab\_01\_DELTA.pdf}
        % @formatter:on
    \end{thebibliography}

\end{document}


% differential drive robot math
\documentclass[11pt]{article}

\usepackage{ebgaramond}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{amsmath}

\usepackage{url}

\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=Python,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3
}

\title{The Kinematics of a Differential Drive Robot}
\author{Iain Brookshaw}

\begin{document}
\maketitle
\begin{abstract}
    Non-holonomic\footnote{Non-holonomic: in this context, a vehicle that may move in one less dimension than the
    system possesses. eg: a car can rotate and move forward, but not "crab" sideways.}, differential drive robots are
    the basis of most mobile robotics; the platform is simple, robust and readily adaptable
    to most indoor applications.

    The kinematics of such platforms is the computation of the location of the robot's base
    from an arbitrary starting point or origin frame; and is an essential step in localizing the robot.
    This document provides an exact solution for 2D differential-drive robot kinematics and is intended as a reference.
\end{abstract}

\section{Introduction}

A differential drive robot has two wheels connected along a common axis to a rigid chassis, with a un-powered castor
or ball-bearing providing a third point of floor contact. It may thus rotate and drive forwards and backwards, but
cannot move sideways.

Each wheel can be controlled  independently and has an encoder attached to the motor drive shaft, allowing accurate
measurement of the wheel's rotational velocity. Using this value, the known radius of the wheel, the known motor
\& gearbox ratio and assuming there is no wheel slip, the linear speed of each wheel ($v_r$ and $v_l$) can be
calculated in meters per second\footnote{The lack of slip assumption is the critical and most often violated
assumption in this method.}.

In these calculations, we are computing the new {\em pose} $[x',y',\theta']$ of the robot at some time $\delta t$ after
the original pose $[x,y,\theta]$. In both cases $x,y$ and $\theta$ are in world coordinates, with $\theta$ being the
angle from the global $X$ axis to the robot's local heading (see Figure \ref{robot}).

\begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{images/robot.png}
    \caption{The differential drive robot, showing the robot pose $[x,y,\theta]$, the left and right wheel velocities
             ($v_l$ and $v_r$), the wheelbase ($l$), the heading ($\theta$) and the local and global coordinate frames}
    \label{robot}
\end{figure}

If these wheel velocities are equal (or approximately equal to a given acceptable step error $\epsilon$), then the new position
is simply\footnote{As they are equal, either $v_l$ or $v_r$ can be used here}:
\begin{eqnarray}
    x' &=& x + v_l / \delta t \\
    y' &=& y + v_l / \delta t \\
    \theta' &=& \theta
\end{eqnarray}

However, if the robot is rotating as well as moving forwards, a more sophisticated approach is needed.

\section{Derivation}

Because the robot is rigid, both wheels rotate around a common point of rotation, the "Instantaneous Center of Curvature"
($ICC$) at the same rotational speed ($\omega$ rad/sec). The $ICC$ exists along a line of length $R$ through the center
of both wheels (see Figure \ref{fig:arc}). This $R$ value is constant for both poses of the robot.

\begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{images/arc.png}
    \caption{The robot rotation over $\delta t$, showing the $ICC$, the angles $\alpha$ and $\beta$ and the
             radius of rotation $R$}
    \label{fig:arc}
\end{figure}

From this we can see that $\omega\times r = v$, where $v$ is the velocity at any point $r$ on the line $R$. As we know
the velocity at the wheels, we can produce two equations for these two unknowns:
\begin{eqnarray}
    \omega(R + l/2) &=& v_r \label{eqn:w_vr} \\
    \omega(R - l/2) &=& v_l \label{eqn:w_vl}
\end{eqnarray}

Rearranging equations \ref{eqn:w_vr} and \ref{eqn:w_vl} gives us the following results for $R$ and $\omega$:

\begin{eqnarray}
    R &=& \frac{\frac{l}{2}(v_l + v_r)}{v_r - v_l} \label{eqn:R} \\
    \omega &=& \frac{v_r - v_l}{l} \label{eqn:w}
\end{eqnarray}

Thus $R$ and $\omega$ are now known.

\subsection{Computing The New Heading}

\begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{images/theta-proof}
    \caption{Illustration of the computation of the computation of $\theta'$, showing the relationship between
    $\alpha$, $\beta$, $\theta$ and $\theta'$ for a robot moving around $ICC$.}
    \label{fig:theta-proof}
\end{figure}

Figure \ref{fig:arc} shows that the angle around the $ICC$ from current pose $ = [x,y,\theta]$ to new pose $ = [x',y',\theta']$ is
$\omega\delta t$, where $\delta t$ is the known time difference between the two poses. From this, we can deduce that
$\theta'$ is:
\begin{equation}
    \theta' = \theta + \omega\delta t \label{eqn:theta}
\end{equation}

We can prove this as follows:

As can be seen in Figure \ref{fig:theta-proof}:
\begin{equation}
    \alpha + \beta = \omega\delta t
\end{equation}
Therefore, through similar triangles:
\begin{eqnarray}
    \theta' - \alpha &=& \pi/2 \nonumber\\
    \theta + \beta &=& \pi/2
\end{eqnarray}
Thus we can solve for $\theta'$:
\begin{eqnarray}
\theta' &=& \theta + \beta + \alpha \nonumber\\
\theta' &=& \theta + \omega\delta t
\end{eqnarray}
All of which are now known quantities.

To compute the remainder of the pose, we first need to compute the position of $ICC$ in world coordinates.

\subsection{Computing The New Pose}

As can be seen in Figure \ref{fig:theta-proof}, the line $R$ forms the hypotenuse of a right-angle triangle
with $ICC$ and the old pose at $[x,y,\theta]$ (see Figure \ref{fig:arc})
From this, we can deduce the following equations:

\begin{eqnarray}
R\cos{\beta} &=& x - ICC_x \label{eqn:Rcos}\\
R\sin{\beta} &=& y - ICC_y \label{eqn:Rsin}
\end{eqnarray}

By recalling that $\beta + \alpha = \omega\delta t$ and by observing that $\theta + \beta = \pi/2$, we can express
equations \ref{eqn:Rcos} and \ref{eqn:Rsin} in terms of $\theta$ thus:

\begin{eqnarray}
R\cos(\theta - \pi/2) &=& x -ICC_x \\
R\sin(\theta - \pi/2) &=& y -ICC_y
\end{eqnarray}

By recalling the following trig-identities:
\begin{eqnarray}
    \cos{a-b} &=& \cos{a}\cos{b} + \sin{a}\sin{b} \nonumber \\
    \sin{a-b} &=& \sin{a}\cos{b} - \sin{b}\cos{a} \nonumber
\end{eqnarray}
and that:
\begin{eqnarray}
    \cos{\pi/2} &=& 0 \nonumber \\
    \sin{\pi/2} &=& 1 \nonumber
\end{eqnarray}
we can solve for $[ICC_x, ICC_y]$:

\begin{eqnarray}
    ICC_x = x - R\sin{\theta} \label{eqn:icc-x} \\
    ICC_x = y + R\sin{\theta} \label{eqn:icc-y} \\
\end{eqnarray}

To reach the new pose, we are rotating around $ICC$ at a radius of $R$ and through an angle $\omega\delta t$. All of these
quantities are now known, thus a standard rotation matrix gives us the new pose (for notational simplicity, let
$\gamma = \omega\delta t$):

\begin{equation}
\begin{bmatrix}x'\\y'\end{bmatrix} = %
\begin{bmatrix}
c_{\gamma} & -s_{\gamma} \\
s_{\gamma} &  c_{\gamma}
\end{bmatrix}
\begin{bmatrix}
x - ICC_x \\
y - ICC_y
\end{bmatrix} +
\begin{bmatrix}
ICC_x\\
ICC_y
\end{bmatrix}
\label{eqn:new-pose}
\end{equation}

Equation \ref{eqn:new-pose} gives the position of the robot in world coordinates $\delta t$ seconds after the last position
computation. This is repeated as necessary to provide the ongoing position of the robot.

% ======================================================================================================================
\newpage
\appendix
\section{Algorithm}

To solve this numerically, we would need to implement the following psudo-code:
\begin{lstlisting}

def update_pose( v_l, v_r, epsilon, delta_t, old_pose ):
    """
    Compute the new pose of the robot from the motor movement
    :param v_l: float - linear velocity of left wheel (m/s)
    :param v_r: float - linear velocity of right wheel (m/s)
    :param epsilon: float - float comparator constant (m/s)
    :param delta_t: float - time step from last update to this (s)
    :param old_pose: tuple (x,y,theta) last update pose (m,m,rad)
    :returns: tuple (x',y',theta') new pose (m,m,rad)
    """

    # do simple case of straight line first
    if _compare_v(v_l, v_r, epsilon):
        return (
            old_pose.y,
            old_pose.x + v_l*delta_t,
            old_pose.theta )

    # now do more complex, rotation around ICC case
    R   = _compute_r(v_l, v_r)
    w   = _compute_omega(v_l, v_r)
    ICC = _compute_icc(R, old_pose)

    new_theta = _compute_new_theta(
        old_pose,
        omega,
        delta_t)

    new_x, new_y = _compute_new_coordinate(
        old_pose,
        omega,
        delta_t,
        ICC)

    return (
        new_x,
        new_y,
        new_theta )
\end{lstlisting}

\section{Variables}

    \begin{tabular}{c p{8cm}}
        $[x, y, \theta]$ & Original pose at time = 0 seconds in global coordinates (meters) and the heading of the robot (radians) \\
        $[x', y', \theta']$ & Final pose at time = $\delta t$ seconds in global coordinates (meters) and the heading of the robot (radians) \\
        $l$ & The robot's wheelbase in meters \\
        $v_l$ & The scalar linear velocity of the left wheel of the robot (meters/second) \\
        $v_r$ & The scalar linear velocity of the right wheel of the robot (meters/second) \\
        $ICC$ & The Instantaneous Center of Curvature -- the point in world coordinates around which the robot is rotating \\
        $\omega$ & The rotational velocity around the $ICC$ in radians/second \\
        $R$ & The distance from the $ICC$ to the robot (meters). This is constant at both time=0 and time=$\delta t$\\
        $\gamma$ & The angle the robot rotates around $ICC$, given by $\omega\delta t$ in radians
    \end{tabular}

% ======================================================================================================================
\begin{thebibliography}{10}
\bibitem{DudekJenkin}
\url{http://www.cs.columbia.edu/~allen/F17/NOTES/icckinematics.pdf}

\bibitem{Hellstrom}
\url{http://www8.cs.umu.se/kurser/5DV122/HT13/material/Hellstrom-ForwardKinematics.pdf}

\bibitem{Christensen}
\url{https://www.cc.gatech.edu/~dellaert/07F-Robotics/Schedule_files/04-Kinematics.pdf}
\end{thebibliography}

\end{document}


% Define document class
\documentclass[twocolumn]{aastex631}

% Filler text
\usepackage{blindtext}
\usepackage{mathrsfs}
\usepackage{amsmath}

\newcommand\pp{p_{\rm min}}

% Begin!
\begin{document}

% Title
\title{From Non-Resonant to Resonant Cosmic Ray Driven Instabilities}

% Author list
\author[0000-0002-2160-7288]{Colby Haggerty}
\correspondingauthor{Colby Haggerty}
\email{colbyh@hawaii.edu}
\affiliation{Institute for Astronomy, University of Hawaii, Honolulu, HI 96822, USA}

\author[0000-0003-0939-8775]{Damiano Caprioli}
\affiliation{Department of Astronomy and Astrophysics, University of Chicago, Chicago, IL 60637, USA}
\affiliation{Enrico Fermi Institute, The University of Chicago, Chicago, IL 60637, USA}

\author{Ellen G. Zweibel}
\affiliation{Department of Physics, University of Wisconsin-Madison, Madison, WI 53706, USA}
\affiliation{Department of Astronomy, University of Wisconsin-Madison, Madison, WI 53706, USA}

% Abstract with filler text
\begin{abstract}
    \blindtext
\end{abstract}

\section{Analytic} \label{sec:analytic}
We consider the dispersion relationship for a plasma composed of 4 different populations: A cold  ion and electron background population, a low density, high energy drifting (CR) ion population and a cold electron population drifting so that there is no net current. The dispersion relationship for this system is discussed in \cite{zweibel03} and is given in the background rest frame as
\begin{equation}
    (\omega + kv_D)^2 + \omega_{ci}\omega\frac{n_{cr}}{n_i}\zeta_{lr}(k) - k^2v_{Ai}^2 = 0
\end{equation}
where $\omega_{ci}$ is the gyro-frequency of the background ions, $n_{cr}$ and $n_i$ are the number density of the background and CRs respectively, $v_{A}$ is the Alfv\'en speed and $\zeta_{lr}$ is defined as
\begin{equation}
    \frac{i\pi}{2}\int_{p_1}^\infty p_1p\phi dp -
    \frac{p_1}{4}\mathscr{P} \int_{0}^\infty  \left [
    (p^2 - p_1^2)\ln \left | \frac{1 \mp p/p_1}{1 \pm p/p_1} \right | \mp 2pp_1 \pm \frac{4}{3}
    \frac{p^3}{p_1}
    \right ] \frac{d\phi}{dp} dp
\end{equation}
where $\mathscr{P}$ denotes the principle part of the integral, $p_1 \equiv m_i \omega_{ci}/k$, i.e. the minimum momentum resonant with a wave number of $k$, and $\phi$ is the distribution of CRs, such that $f_{CR} = n_{cr}\phi(p)$ and $\int_0^\infty 4\pi p^2 \phi dp = 1$.

\section{Introduction} \label{sec:intro}
Lorem Ipsum

\section{Simulations} \label{sec:sims}
To investigate these we use the code \emph{dHybridR} (cite to come?) to run relativistic hybrid simulations (kinetic ions/ fluid charge neutralizing electrons).
Simulations are quasi-1D but account for the three spatial components of the particle momentum and of the electric and magnetic fields.
 Lengths are normalized to the proton skin depth, $c/\omega_p$, where $c$ is the speed of light and $\omega_p\equiv \sqrt{4\pi n_p e^2/m}$ is the proton plasma frequency, with $m$, $e$ and $n_p$ the proton mass, charge and number density.
Time is measured in units of inverse proton cyclotron frequency, $\omega_c^{-1}\equiv mc/eB_0$, where $B_0$ is the strength of the initial magnetic field.
Velocities are normalized to the Alfv\'en speed $v_A\equiv B/\sqrt{4\pi m n}$, and energies and temperatures are given in units of $mv_A^2$.
Fluid electrons are initialized with the same temperature as ions, and have a adiabatic equation of state with an effective index.
The computational box measures $[L_x,L_y]=[10^4, 5] c/\omega_p$, with two cells per ion skin depth, An effective speed of light is set to $c/v_A = 100$, which ultimately sets the condition for the simulation time step $\Delta t=0.0025 \omega_c^{-1}$.

The simulations are periodic in all directions with two over-lapping populations; a thermal background population and a variable cosmic ray (CR) population with different densities and initial distribution functions.
We examine two different distributions of CRs: a "hot" distribution that follows a power law with an index of $-4.5$ drifting with a velocity of $10v_A$ parallel to the magnetic field,

\begin{equation}
f(p)=\begin{cases}
    \frac{3n_{cr}}{8\pi \pp^{3/2}}p^{-4.5}, & p > \pp.\\
    0, & \text{otherwise}.
\end{cases}
\end{equation}

and "beam" distribution that is a Gaussian in momentum space peaked around some beam momentum $p_b$ with a range of positive pitch angels $\mu$ with a linear increase from 0 to 1, $f(p,\mu) = F(p)g(\mu)$ where
\begin{equation}
F(p) = e^{-(p - p_b)/2\Delta p}
\end{equation}

\begin{equation}
g(\mu)=\begin{cases}
    0, & \mu < 0.\\
    \frac{1 + \mu}{3/2}, & 0 \geq \mu .
\end{cases}
\end{equation}

\section{Numeric} \label{sec:numeric}
Lorem

\section{Non-Linear} \label{sec:nonlinear}
Loro

\section{Conclusion} \label{sec:conclusions}
Loro

\section{Body} \label{sec:body}
Loro

\bibliography{Total}

\end{document}


\documentclass[12pt]{article}

\usepackage{array}
\usepackage{adjustbox}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{dirtytalk}
\usepackage[a4paper, total={7in, 9in}]{geometry}
\usepackage{forest}
\usepackage{geometry}
\usepackage{multirow}
\usepackage{skak}
\usepackage{tikz}
\usepackage{titling}
\usepackage{wrapfig}
\usepackage{xcolor}

\usetikzlibrary{patterns}

\def\multichoose#1#2{\ensuremath{\left(\kern-.3em\left(\genfrac{}{}{0pt}{}{#1}{#2}\right)\kern-.3em\right)}}

\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{patterns}

\pgfdeclarepatternformonly{bigger north west lines}{\pgfqpoint{-2pt}{-2pt}}{\pgfqpoint{8pt}{8pt}}{\pgfqpoint{6pt}{6pt}}%
{
  \pgfsetlinewidth{1pt}
  \pgfpathmoveto{\pgfqpoint{0pt}{6pt}}
  \pgfpathlineto{\pgfqpoint{6.2pt}{-0.2pt}}
  \pgfusepath{stroke}
}

\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}
\newcommand*{\SetHeight}[2]{\resizebox{!}{#1}{$#2$}}

\begin{document}
\pagenumbering{gobble}

\title{Math 142 Study Guide}
\date{2016-10-06}
\author{David Alves}

\begin{center}
\large \thetitle \\
by \theauthor \\
\end{center}
\tableofcontents

\section{Notation \& Basics}
\newcommand{\termtable}[1]{
    \def\arraystretch{1.75}
    \begin{tabular}{ r|p{28em} }
    #1
    \end{tabular}
}
\newcommand{\term}[1]{\textbf{#1}&}

\termtable{
    \term{set} A collection of elements where the order doesn't matter and every element is distinct (You can't have two elements that are equal to each other)\\
    \term{list or $k-$tuple} A collection of elements $(a_1, a_2, \ldots, a_k)$ where the order matters and duplicates are allowed. For example $(1, 2)$ is different from $(2,1)$ and $(1,1)$ is a valid list.\\
    \term{$a \in A$} $a$ is an element of the set $A$\\
    \term{$a \notin A$} $a$ is \textbf{not} an element of the set $A$\\
    \term{$|S|$} The number of elements in a set $S$ (\emph{cardinality} of $S$)\\
    \term{$A \cap B$} The \emph{intersection} of $A$ and $B$, namely the set of elements that are in both $A$ and $B$\\
    \term{$A \cup B$} The \emph{union} of $A$ and $B$, namely the set of elements that are either in $A$, in $B$, or in both\\
    \term{$A \subset B$} $A$ is a \emph{subset} of $B$, meaning $A$ contains only elements that are in $B$. (Note for this class $A$ and $B$ can be equal, we are not using \say{proper subset})\\
    \term{$A \times B$} The \emph{cartesian product} of sets $A$ and $B$, namely the set of every possible list $(a, b)$ where $a \in A$ and $b \in B$. Example: $A=\{1,2\}, B=\{3,4\},A \times B = \{(1, 3), (1, 4), (2, 3), (2, 4)\}$\\
    \term{$\emptyset$ or $\{\}$} The empty set, the set with no elements\\
    \term{disjoint} Sets $A$ and $B$ are disjoint if they have no elements in common, meaning $A \cap B = \emptyset$\\
    \term{$\binom{n}{k}$} Number of subsets of size $k$ in a set of $n$ items, $\frac{n!}{k!(n-k)!}$\\

    \term{domain} The set of values that can go into a function. By definition a function can be applied to every element of the domain\\
    \term{codomain} That set of values that can come out of a function\\
    \term{injective} Every element in the codomain is hit at \textbf{most} once\\
    \term{surjective} Every element in the codomain is hit at \textbf{least} once\\
    \term{bijective} Every element of the codomain is hit \textbf{exactly} once (both injective and surjective)\\
    \term{$f : A \rightarrow B$} A function $f$ with domain $A$ and codomain $B$\\
    \term{$[n]$} The set of integers $\{1, 2, \ldots, n-1, n\}$\\
}
\pagebreak
\section{Basic Principles}
\subsubsection{Sum Principle}
\[
    \text{ If }A\text{ and }B\text{ are disjoint, }|A \cup B | = |A| + |B|
\]
If you can pick a fruit \textbf{or} a vegetable, then your total number of choices is the number of fruits plus the total number of vegetables.
\subsubsection{Product Principle}
\[
    |A| \times |B| = |A \times B|
\]
If you have $b$ choices for bread and $f$ choices for filling, there are $b\times f$ possible sandwiches that you can make with one bread and one filling.

\subsubsection{Quotient Principle}
\[
    \text{Partitioning }S\text{ into groups of size }k\text{ gives }\frac{|S|}{k}\text{ groups}
\]
If there are $n$ people at a dance, and they are all dancing in pairs at a certain time, there are $\frac{n}{2}$ pairs.
\pagebreak
\section{Proofs}
\subsection{Induction}
\subsubsection{Template}

\textbf{Problem Statement:} Prove that for all $n \ge 0$, \emph{blah} is true.\\

We prove this by induction. Let $p(n)$ be the statement that $blah$ is true for $n$. We know that $p(0)$ is true because \emph{something something}. We now show that for all $n \ge 0$, if $p(n)$ is true, $p(n+1)$ must be true. \emph{Something something something}, therefore if $p(n)$ is true, $p(n+1)$ must be true for $n\ge 0$. Therefore for all $n \ge 0$, \emph{blah} is true.

\subsubsection{Example}
Show that for all positive integers $n$,

\[
    \big(1 + 2 + \ldots + n\big)^2 = 1^3 + 2^3 + \ldots + n^3
\]

\begin{proof}
    We prove this by induction on the statement $p(k) = \big(1 + 2 + \ldots + k\big)^2 = 1^3 + 2^3 + \ldots + k^3$. For $k = 1$, $p(1)$ gives $1^2 = 1^3$, which is true. For $k > 1$, we show that if $p(k-1)$ is true, then $p(k)$ is true. First note that the sum of integers $1 + 2 + \ldots + x = \frac{x(x+1)}{2} $. Thus $p(k-1)$ can be written as

    \begin{equation}\label{eq:squares1}
    \left(\frac{(k-1)k}{2}\right)^2 = 1^3 + 2^3 + \ldots + (k-1)^3
    \end{equation}

    and $p(k)$ can be written as
    \begin{equation}\label{eq:squares2}
    \left(\frac{k(k+1)}{2}\right)^2 = 1^3 + 2^3 + \ldots + k^3
    \end{equation}

    Subtracting equation \ref{eq:squares1} from equation \ref{eq:squares2} gives

    \begin{equation*}
    \frac{k^2(k+1)^2 - k^2(k-1)^2}{4} = k^3
    \end{equation*}

    Which can be further simplified as follows:

    \begin{equation*}
    \frac{(k^2+2k+1) - (k^2-2k+1)}{4} = k
    \end{equation*}

    or $\frac{4k}{4} = k$. Thus we have shown that if $p(k-1)$ is true, then $p(k)$ is true, which completes the inductive proof.

\end{proof}

\subsubsection{Strong Induction}
Essentially the same as induction, just let $p(n)$ be the statement that \emph{blah} is true for all $k$ where $0 \le k \le n$ instead of only for $n$.

\subsection{Contradiction}
\subsubsection{Template}
\textbf{Problem Statement:} Prove that \emph{blah} is true.\\

We prove this by contradiction. Assume that \emph{blah} is false. Then \emph{something}, which means \emph{something something}. This contradicts our assumption that \emph{blah} is false. Therefore our assumption is incorrect, so \emph{blah} is true.

\subsubsection{Example}
Consider a complete graph on 6 vertices. Color some of the edges white and some of the edges black. Prove that there must be a triangle with all white edges or all black edges somewhere in the graph. (A triangle with all white edges would be some 3 vertices $a,b,c$ such that the edges $(a,b), (a,c), (b,c)$ are all white)
\begin{proof}
Assume that an edge coloring exists such that each edge is either black or white and there are no all-black or all-white triangles. Consider a vertex $v$. $v$ is connected to the other five vertices by five edges. At least three of these edges must share some color $c$. (If more than three share a color, consider only three of them). Let the three vertices connected to $v$ by $c$-colored edges be $x$, $y$, and $z$. Since $(v,x)$ and $(v,y)$ are colored $c$, $(x,y)$ must be non-$c$-colored otherwise $(v,x), (v,y), (x,y)$ would form a $c$-colored triangle which would contradict our assumption. Similarly since $(v,x)$ and $(v,z)$ are $c$-colored, $(x,z)$ must be non-$c$-colored, and since $(v,y)$ and $(v,z)$ are $c$-colored, $(y,z)$ must be a non-$c$-colored. Since $(x,y)$, $(x,z)$, and $(y,z)$ are all non-$c$-colored, it is an all-black or all-white triangle, which contradicts our assumption. Therefore the assumption is incorrect, and there are no edge colorings on such that there are no all-black or all-white triangles.\\
\end{proof}

\colorlet{verylightgray}{black!45}
\begin{center}
\begin{tikzpicture}
\node[shape=circle,draw=black] (A) at (0,0) {$v$};
    \node[shape=circle,draw=black] (B) at (4,0) {$z$};
    \node[shape=circle,draw=black] (C) at (1.24,3.8) {$y$};
    \node[shape=circle,draw=black] (D) at (-3.24, 2.35) {$x$};
    \node[shape=circle,draw=black] (E) at (-3.24, -2.35) { };
    \node[shape=circle,draw=black] (F) at (1.24,-3.8) { } ;

    \path [-,line width=1pt] (A) edge node[left] {} (B);
    \path [-,line width=1pt] (A) edge node[left] {} (C);
    \path [-,line width=1pt] (A) edge node[left] {} (D);
    \path [-,color=verylightgray] (A) edge node[left] {} (E);
    \path [-,color=verylightgray] (A) edge node[left] {} (F);
    \path [-,line width=1pt,style=dashed] (B) edge node[left] {} (C);
    \path [-,line width=1pt,style=dashed] (B) edge node[left] {} (D);
    \path [-,color=verylightgray] (B) edge node[left] {} (E);
    \path [-,color=verylightgray] (B) edge node[left] {} (F);
    \path [-,line width=1pt,style=dashed] (C) edge node[left] {} (D);
    \path [-,color=verylightgray] (C) edge node[left] {} (E);
    \path [-,color=verylightgray] (C) edge node[left] {} (F);
    \path [-,color=verylightgray] (D) edge node[left] {} (E);
    \path [-,color=verylightgray] (D) edge node[left] {} (F);
    \path [-,color=verylightgray] (E) edge node[left] {} (F);
\end{tikzpicture}
\end{center}

\pagebreak
\section{Twelvefold Way with Balls \& Bins}
\newcommand{\twelvecell}[2]{
    \begin{center}
        \minsizebox*{!}{.6cm}{$\displaystyle #1$}
    \end{center}
    #2
}
\newcommand{\twelverow}[1]{
    \centering #1
}

\newcommand{\finishrow}[0]{
    \medskip\\
    \hline
}

\def\arraystretch{1.2}
\lapbox[\width]{-.8cm}{
\begin{tabular}{ m{1.2cm}m{5.2cm}m{5.2cm}m{5.2cm}c }
     & \large\centering General           & \large\centering Injective                  & \large\centering Surjective&\\
     & \small\centering No restrictions & \small\centering At \textbf{most} one ball per bin & \small\centering At \textbf{least} one ball per bin&\\
    \hline

    \twelverow{$a$ balls\\(dist.)\bigskip\\$b$ bins\\ (dist.)} &
    \twelvecell{b^a}{There are $b$ choices for each ball, so by the product principle there are $b^a$ total configurations.}&
    \twelvecell{\prod_{i=0}^{a-1}b-i}{There are $b$ choices for the first ball, $b~-~1$ choices for the second ball (since it can't go in the same one), $b-2$ choices for the third, etc. ($\prod$ is like $\sum$ except you multiply the terms instead of adding them)} &
    \twelvecell{S(a,b)b!}{There are $S(a,b)$ ways to put distinguishable balls into indistinguishable bins by definition, and then $b!$ ways to label the bins after you have placed the balls.}
    \finishrow

    \twelverow{$a$ balls\\(indist.)\bigskip\\$b$ bins\\ (dist.)} &
    \twelvecell{\multichoose{b}{a}=\binom{a+b-1}{a}}{Use $\star$ for a ball and $\vert$ for a divider between bins. There are $b-1$ dividers needed so you have a sequence of $a+b-1$ elements of which $a$ are balls, giving $\binom{a+b-1}{a}$. For example, $(0, 0, 3, 1)$ is $\vert\vert\star\star\star\vert\star$}&
    \twelvecell{\binom{b}{a}}{Number of ways to pick a subset of size $a$ from a set of size $b$. (We are picking $a$ of the bins to contain a single ball while the rest remain empty).}&
    \twelvecell{\binom{a-1}{a-b}}{Use the same stars-and-bars encoding as for general, except since each bin must have one ball, we can leave it out of the encoding. For example, $(3,1,2)$ is encoded as $\star\star\vert\vert\star$}
    \finishrow

    \twelverow{$a$ balls\\(dist.)\bigskip\\$b$ bins\\ (indist.)} &
    \twelvecell{\sum_{i=0}^{b} S(a,i)}{$S(a,i)$ is the number of ways to put $a$ balls into $i$ bins such that all bins contain at least one ball. Sum over all values of $i$ to get the total number of ways to fill $b$ bins without the \say{all bins used} requirement}&
    \twelvecell{
        \begin{aligned}
            b\geq a: 1\\
            b<a: 0
        \end{aligned}
    }{One way if there are enough bins, otherwise zero}&
    \twelvecell{S(a,b)}{$S(a,b)$ is defined to be the number of ways to place $a$ distinguishable balls into $b$ indistinguishable bins. Note that this is also the number of ways to partition a set with $a$ elements into $b$ groups.}
    \finishrow

    \twelverow{$a$ balls\\(indist.)\bigskip\\$b$ bins\\ (indist.)} &
    \twelvecell{\sum_{i=0}^{b} P(a,i)}{$P(a,i)$ is the number of ways to put $a$ balls into $i$ bins such that all bins contain at least one ball. We then sum over all values of $i$ from 0 to $b$ to get the total number of ways to fill $b$ bins without the \say{all bins used} requirement}&
    \twelvecell{
        \begin{aligned}
            b\geq a: 1\\
            b < a: 0
        \end{aligned}
    }{One way if there are enough bins, otherwise zero}&
    \twelvecell{P(a,b)}{This is defined to be the number of ways to place $a$ indistinguishable balls into $b$ indistinguishable bins. Note that this is also the number of ways to partition an integer $a$ into the sum of $b$ integers and the number of Young Diagrams with $a$ boxes and $b$ rows.}
\end{tabular}
}
\section{Equivalence Relations \& Partitions}
\termtable{
    \term{relation} A relation is a subset of $A \times B$. A \say{relation on $A$} is a subset of $A\times A$\\
    \term{equivalence relation} An equivalence relation is a relation that satisfies three properties:
        \begin{itemize}
        \item Reflexive: All pairs of the form $(a, a)$ in $A\times B$ are present in the relation
        \item Symmetric: If $(a, b)$ is in the relation, then $(b, a)$ must be in the equivalence relation.
        \item Transitive: If $(a, b)$ and $(b, c)$ are in the relation, then $(a, c)$ must be in the relation.
        \end{itemize}\\
    \term{partition} A partition of a set $S$ is a set of disjoint subsets of $S$ such that the union of those subsets is equal to $S$. For example, $\{\{1,2,4\},\{3,5\}\}$ is a partition of $[5]$ because $\{1,2,4\} \cup \{3,5\} = [5]$ and $\{1,2,4\} \cap \{3,5\} = \emptyset$.
}

\pagebreak
\section{Pascal's Triangle \& Binomial Theorem}
\begin{center}
\begin{tikzpicture}[
    scale=1,
    tcancel/.append style={draw=#1, cross out, inner sep=1pt}
]
\node at ( 0, 0) {1};
\node at (-1,-1) {1};
\node at ( 1,-1) {1};
\node at (-2,-2) {1};
\node at ( 0,-2) {2};
\node at ( 2,-2) {1};
\node at (-3,-3) {1};
\node at (-1,-3) {3};
\node at ( 1,-3) {3};
\node at ( 3,-3) {1};
\node at ( 0, -4.5) {$\vdots$};
\node at (-6, -6) {1};
\node at (-4.5, -6) {$\ldots$};
\node at (-3, -6) (up2l) {$\binom{n-1}{k-2}$};
\node at (-1, -6) (up1l) {$\binom{n-1}{k-1}$};
\node at ( 1, -6) (up1r) {$\binom{n-1}{k}$};
\node at ( 3, -6) (up2r) {$\binom{n-1}{k+1}$};
\node at ( 4.5, -6) {$\ldots$};
\node at ( 6, -6) {1};
\node at (-7, -7) {1};
\node at (-5.5, -7) {$\ldots$};
\node at (-4, -7) (main2l) {$\binom{n}{k-2}$};
\node at (-2, -7) (main1l) {$\binom{n}{k-1}$};
\node at ( 0, -7) (maincc)  {$\binom{n}{k}$};
\node at ( 0, -6.5) {+};
\node at ( 2, -7) (main1r){$\binom{n}{k+1}$};
\node at ( 4, -7) (main2r){$\binom{n}{k+2}$};
\node at (5.5, -7) {$\ldots$};
\node at ( 7, -7) {1};
%\draw [->, thick] (up2r)--(main2r);
%\draw [->, thick] (up2r)--(main1r);
%\draw [->, thick] (up1r)--(main1r);
\draw [->, thick] (up1r)--(maincc);
\draw [->, thick] (up1l)--(maincc);
%\draw [->, thick] (up1l)--(main1l);
%\draw [->, thick] (up2l)--(main1l);
%\draw [->, thick] (up2l)--(main2l);
\end{tikzpicture}
\end{center}
\subsection{Pascal's Triangle Properties}
\begin{itemize}
\item $k^{\text{th}}$ element of $n^{\text{th}}$ row has value $\binom{n}{k}$
\item Each item is the sum of the two above it: $\binom{n-1}{k-1} + \binom{n-1}{k} = \binom{n}{k}$
\item Sum of $n^{\text{th}}$ row $\sum_{k=0}^{n}\binom{n}{k}=2^n$
\item Sum of even-indexed terms in row $n$ = Sum of odd-indexed terms in row $n$ = Sum of terms in row $n-1$.
\item Sum of diagonal elements (down-and-to-the-left): $\sum_{k=m}^n \binom{k}{m} = \binom{n+1}{m+1}$
\item Sum of diagonal elements (down-and-to-the-right): $\sum_{k=0}^n \binom{m+k}{k} = \binom{m+n+1}{n}$
\end{itemize}
\subsection{Binomial Theorem}
\begin{align*}
    (x+y)^n &= \sum_{k=0}^n \binom{n}{k}x^{n-k}y^k\\
    &= \binom{n}{0}x^n + \binom{n}{1}x^{n-1}y + \binom{n}{2}x^{n-2}y^2 + \ldots\\
\end{align*}

Note that if you set $x=y=1$, this says that the sum of the $n^{\text{th}}$ row  of Pascal's Triangle is $2^n$.
\pagebreak
\section{Catalan Numbers}
\begin{align*}
    C_n &= 1, 1, 2, 5, 14, 42, \ldots\\
    C_n &= \frac{1}{n+1}\binom{2n}{n}\\
    C_{n+1} &= \sum_{k=0}^{n} C_kC_{n-k}\\
\end{align*}
$C_n$ is the number of paths from $(0, 0)$ to $(0, 2n)$ using only diagonally up and diagonally down moves and without crossing X-axis:
\begin{center}
\begin{tikzpicture}
\draw[step=1.0,black,thin,color=black,opacity=.35] (-5,-2) grid (5,4);
\node (S) at (-5, 0) {};
\node (E) at (5, 0) {};
\node (T) at (-5, 5) {};

\draw[pattern=bigger north west lines, pattern color=red!35] (-5,0) rectangle (5,-2) node [midway,fill=white] {Can never go below $y=0$};

\draw [->,line width=1.75,blue] (-8,1.5) -- (-7,2.5) node[midway, black, yshift=-2.4em] {Possible moves};
\draw [->,line width=1.75,red]  (-8,0.5) -- (-7,-.5);

\draw [->,line width=1.75,blue] (-5,0) -- (-4,1);
\draw [->,line width=1.75,red] (-4,1) -- (-3,0);
\draw [->,line width=1.75,blue] (-3,0) -- (-2,1);
\draw [->,line width=1.75,blue] (-2,1) -- (-1,2);
\draw [->,line width=1.75,red] (-1,2) -- (0,1);
\draw [->,line width=1.75,blue] (0,1) -- (1,2);
\draw [->,line width=1.75,blue] (1,2) -- (2,3);
\draw [->,line width=1.75,red] (2,3) -- (3,2);
\draw [->,line width=1.75,red] (3,2) -- (4,1);
\draw [->,line width=1.75,red] (4,1) -- (5,0);
\node [black] at (-5.6,0) {$(0,0)$};
\node [black] at (5.7,0) {$(2n,0)$};
\end{tikzpicture}
\end{center}

$C_n$ is also the number of distinct trees with $n$ nodes (where nodes are read left to right, so for example reflection symmetry doesn't count).
\pagebreak

\section{Principle of Inclusion-Exclusion}
\subsection{General}
The size of the union of $n$ sets $S_1, S_2, \ldots, S_n$ can be computed in terms of intersections of those sets. This is handy when intersections are easier to count than unions.\\

Example for $n=4:$
\newcommand{\dlist}[1]{S_{#1}}
\begin{multline*}
    |\dlist{1} \cup \dlist{2} \cup \dlist{3} \cup \dlist{4}| = |\dlist{1}| + |\dlist{2}| + |\dlist{3}| + |\dlist{4}|\\
    -|\dlist{1} \cap \dlist{2}| - |\dlist{1} \cap \dlist{3}| - |\dlist{1} \cap \dlist{4}| - |\dlist{2} \cap \dlist{3}| - |\dlist{2} \cap \dlist{4}| - |\dlist{3} \cap \dlist{4}|\\
    +|\dlist{1} \cap \dlist{2} \cap \dlist{3}| + |\dlist{1} \cap \dlist{2} \cap \dlist{4}| + |\dlist{1} \cap \dlist{3} \cap \dlist{4}| + |\dlist{2} \cap \dlist{3} \cap \dlist{4}|\\
    -|\dlist{1} \cap \dlist{2} \cap \dlist{3} \cap \dlist{4}|
\end{multline*}
\subsection{Derangements}
\[
    d_n = n!\sum_{i=0}^n \frac{(-1)^i}{i!} = n! - \frac{n!}{1!} + \frac{n!}{2!} - \frac{n!}{3!} +\ldots \approx \frac{n!}{e}
\]
\[
    d_n = (n-1)(d_{n-1} + d_{n-2})
\]

%\[xC^2(x)-C(x) + 1 = 0\]
\pagebreak
\section{Generating Functions}
\subsection{Common Generating Functions}
\begin{equation*}
    \setlength{\jot}{.5cm}
    \begin{aligned}
    \frac{1}{1-x} &= 1 + x + x^2 + x^3 + \ldots & 1, 1, 1, \ldots\\
    \frac{1-x^{n+1}}{1-x} &= 1 + x + x^2 + x^3 + \ldots x^n & \underbrace{1, 1, 1, \ldots}_{n\text{ ones}}\\
    \frac{1}{1+x} &= 1 - x + x^2 - x^3 + \ldots & 1, -1, 1, -1, \ldots\\
    \frac{1}{1-x^k} &= 1 + x^k + x^{2k} + x^{3k} + \ldots & 1, \underbrace{0,0,\ldots,0}_{k-1\text{ zeroes}}, 1, 0,\ldots\\
    \frac{1}{1-ax} &= 1 + ax + a^2x^2 + a^3x^3 + \ldots & 1, a, a^2, \ldots\\
    \end{aligned}
\end{equation*}

\subsection{Extended Binomial Theorem}
\begin{equation*}
    \setlength{\jot}{.5cm}
    \begin{aligned}
    \binom{-n}{k} &= (-1)^k\binom{n+k-1}{k}\\
    \binom{n}{k} &= \frac{n(n-1)(n-2)\ldots(n-k+1)}{k!}
    \end{aligned}
\end{equation*}

\section{Probability}

\termtable{
\term{$\Omega$} \emph{Sample Space}, or set of \emph{outcomes}, e.g. coin flip is ${\{H, T\}}$\\
\term{event $E$} Subset of $\Omega$, e.g. $\{H\} \subset \{H, T\}$\\
\term{$E^C$} The \emph{complement} of an event $E \subset \Omega$, or $\Omega\backslash E$\\
\term{event space} The set of events\\
\term{$P:\{0, 1\}^\Omega \rightarrow [0,1]$ } A \emph{probability measure} is a function with domain (subsets of $\Omega$) to a real number in $[0,1]$ subject to the following rules:
    \begin{enumerate}
    \item $P(\emptyset) = 0$
    \item $P(\Omega) = 1$
    \item if $A$ and $B$ are disjoint, then $P(A\cup B) = P(A) + P(B)$
    \end{enumerate}\\
\term{$P(A|B)$} The \emph{conditional probability} of $A$ given $B$. \[ P(A|B) =\frac{P(A) \cup P(B)}{P(B)} \] \\
\term{random variable} $X: \Omega \rightarrow T$ (usually $T = \mathbb{R}$)\\
\term{distribution of r.v.} For T arbitrary (but discrete) it's a bar graph\\
\term{$E[X]$} The \emph{expectation} given $(T = \mathbb{R})$ is defined as \[ \sum_{x\in T} x P(X=x)\]\\
\term{uniform distribution} All outcomes have equal probability\\
\term{linearity of expectations} $E[X + Y] = E[X] + E[Y]$ Expected number of heads in three flips is equal to number of heads in flip1, number in flip2, number in flip3, therefore $E[X] = 3E[X_i]$ Does not require independence!\\
\term{Baye's theorem} $P(B|A) = \frac{P(B) P(A|B)}{P(A)}$\\
}

\section{Graphs}

\termtable{
\term{simple graph $G$} Set of vertices $V(G)$ and set of edges $E(G)$\\
\term{$V(G)$} The set of vertices in $G$. Can be any set\\
\term{$E(G)$} The set of edges in $G$. An edge is a set of two \emph{distinct} elements of V(G). $\{v_1, v_2\}: v_1 \neq v_2$\\
\term{directed graph} Same as a simple graph, but edges are length-2 lists, so you can have an edge $(v_1, v_2)$ without the reverse edge $(v_2, v_1)$\\
\term{isomorphism} Two graphs are the same if you rename the vertices. Formally, there exists a bijective function $f: V(G_1) \rightarrow V(G_2)$ such that $\{v, w\} \in E(G_1) \iff \{f(v), f(w)\} \in E(G_2)$ (Note: $\iff$ means \say{if and only if})\\
\term{path} A sequence $v_1 \xrightarrow[e_1]{} v_2 \xrightarrow[e_2]{} v_3 \dots v_k$ where no vertex appears twice\\
\term{cycle} A \emph{path} $v_1 \xrightarrow[e_1]{} v_2 \xrightarrow[e_2]{} v_3 \dots v_1$ which ends at the start vertex\\
\term{tree} A graph with no cycles. There are $n^{n-2}$ trees on $n$ vertices (not expected to prove this)\\
\term{bipartite graph} A graph in which no odd-length cycles exist. The vertices can be divided into disjoint subsets $A$ and $B$ such that no two vertices in $A$ are connected by an edge and no two vertices in $B$ are connected by an edge\\
\term{weighted graph} A graph in which each edge has an number\\
\term{$C_n$} A graph on $n$ vertices where all vertices are in one big cycle\\
\term{$K_n$} A \emph{complete} graph on $n$ vertices (all possible edges exist)\\
\term{$K_{n,m}$} A \emph{bipartite} graph with $n$ vertices in one set and $m$ vertices in the other. Every edge between a vertex in $n$ and a vertex in $m$ exists, and no other edges exist.\\
}
\pagebreak
\section{Groups}
A group $G$ is a \textbf{set} with a function $G\times G \rightarrow G$ such that:
\begin{enumerate}
    \item \emph{Identity}: There exists $\textbf{id} \in G$ such that $\textbf{id}*g = g$ for all $g \in G$.
    \item \emph{Closure}: For all $g_1, g_2 \in G$, $g_1*g_2 \in G$
    \item \emph{Associativity}: $(g_1*g_2)*g_3 = g_1*(g_2*g_3)$
    \item \emph{Inverse}: For all $g$, there exists $g^{-1} \in G$ such that $g*g^{-1} = \textbf{id}$
\end{enumerate}

\termtable{
\term{subgroup} A subgroup $H$ of $(G,*)$ is a subset of G which is a group under *.\\
\term{permutation group} A subgroup of $S_n$\\
\term{cyclic group $C_n$} A subset of $S_n$ that rotates the elements. Elements of $C_n$: {permutation that rotates elements by 0, permutation that rotates elements by 1, ...}\\
\term{dihedral group $D_n$} A subset of $S_n$ that rotates and flips the elements. $|D_n| = |C_n|$ because for every element in $C_n$ we can have it unflipped or flipped.
}
\subsection{Examples}
\begin{itemize}
\item $(\mathbb{R},*)$ is not a group because 0 has no inverse.
\item $(\mathbb{R}\backslash\{0\},*)$ is a group with $\textbf{id} = 1$
\item $(\mathbb{R},+)$ is a group with $\textbf{id} = 0$
\item $(\mathbb{R}\backslash\{0\},*)$ is a group with $\textbf{id} = 1$
\item $(\mathbb{Z}\slash 7\mathbb{Z},+)$ is a group with $\textbf{id} = 1$. $\mathbb{Z}\slash 7\mathbb{Z}$ means using modular arithmetic, so $5 + 5 = 3$ (because 10 mod 7 is 3).
\item $(\mathbb{Z}\slash n\mathbb{Z}\backslash\{0\},*)$ is a group with $\textbf{id} = 1$ if and only if $n$ is prime. If $n$ is composite, then there is then for let $f$ be a factor of $n$. There is no $f^{-1}$ because $f$ times anything is never going to be 1.

\end{itemize}

\section{Group Actions}

\termtable{
\term{permutation} A function $g: \{1,2,\dots,n \} \rightarrow \{1,2,\dots,n\} $ which is a bijection. Example: $f(1) = 2, f(2) = 4, f(3) = 3, f(4) = 1$. Can be written $\left(\frac{1234}{2431}\right)$ or $(2431)$\\
\term{$S_n$} The set of all permutations of size $n$. $|S_n| = n!$\\

\term{composition} A composition of permutations $g_1$ and $g_2$ is also a permutation. $g_1(g_2(x))$ is written as $(g_1g_2)(x)$ or $g_1 \circ g_2 (x)$. (Note that you need to apply the permutations from right to left)\\
\term{(id)} The permutation which sends x to itself, e.g. $f(x) = x$\\
\term{associativity} A composition of permutations is associative, meaning $(g_1g_2)g_3 = g_1(g_2g_3)$.\\
\term{inverse} For all $g$, there exists $g^{-1}$ such that $g\circ g^{-1} = \textbf{(id)}$\\
\term{\parbox{4cm}{\raggedleft directed graph notation}}
\begin{tikzpicture}
\node[shape=circle] (A) at (0,0) {$1$};
\node[shape=circle] (B) at (1,.5) {$2$};
\node[shape=circle] (C) at (2,0) {$3$};
\node[shape=circle] (D) at (2.5,0) {$4$};
\draw [->] (A) edge[bend left=10] (B);
\draw [->] (B) edge[bend left=10] (C);
\draw [->] (C) edge[bend left=10] (A);
\draw [->] (D) edge[loop above,looseness=6] (D);
\end{tikzpicture}
Every permutation can be represented as a directed graph where each node has one incoming edge and one outgoing edge. Every node participates in exactly one cycle.
\\
\term{cycle notation} Expresses a permutation in terms of cycles. The above example is written $(123)(4)$. This is very handy for performing multiplication. To multiply $A\times B$, for each number find the next number in the $B$-cycle, then find the number after that in the $A$-cycle, and put that in the result. As soon as you get back to the first number in your cycle, start a new cycle. Example: $\Big[(123)(465)\Big] \times \Big[(13542)(6)\Big] = (1)(2)(34)(56)$ (First digit: $1\rightarrow3$ in $B$, then $3\rightarrow1$ in $A$, so 1 is in a cycle by itself in the result)\\
}

\section{Colorings and Orbits}

\termtable{
\term{coloring} A coloring is a function $f: S \rightarrow C$, where $S$ is a set and $C$ is a set of colors.\\
\term{$\overline{g}$} If $g: [n] \rightarrow [n]$ is a permutation and $f: [n] \rightarrow C$ is a coloring such that $f(i) = c$, $\overline{g}: ([n] \rightarrow C) \rightarrow ([n] \rightarrow C)$ is the function such that $(\overline{g} f)(i)=c$\\
\term{orbit} Orbits are equivalence classes under some set of actions. The orbit of $x \in X$ under $G$ is $\{g(x) \vert g \in G\}$. E.g. (Red, Red, Green) is in the same equivalence class as (Green, Red, Red) and (Red, Green, Red).\\
\term{$Fix(g)$} Set of $x$ such that $g(x)=x$. E.g. if g(x) is the identity permutation on 6 elements, there are 64 possible colorings of the 6 elements such that $g(x) = x$ because $g(x)$ leaves $x$ unchanged for every possible coloring $x$.\\
\term{Polya-Burnside Thm.} \# of orbits $\displaystyle = \frac{1}{|G|} \sum_{g \in G} |Fix(g)|$\\
}

X = set of ALL possible colorings on n items
x = some coloring on n items
$C_n = {1, g, g^2, \dots, g^n-1}$

Group acting on X:
$\sum_{x \in X} \{ (g,x) \vert g(x) = x\}$

For all $x \in Orb(x)$: \# of $g$ such that $g(x)=x'$ is the same

\[
\sum_{x \in X} \frac{|G|}{|Orb(x)|} = |G| \sum_{x \in X} \frac{1}{|Orb(x)|}
\]

\end{document}


\section{Introduction}

One of the most important components of an ecological community is its food web.
Early models of population dynamics generally only considered interactions between
two species (e.g., \citet{canale1970}; \citet{rosenzweig1963}). However, in nature, food webs wherein only
two species influence the behaviour of the network are quite uncommon -- most
networks are far more complex \citep{hastings1991}. Therefore, several researchers asserted
that every food web study should involve at least three species in order to capture that
complexity \citep{price1980, rosenzweig1973}.

At first, the core interest of food web research was in equilibrium analysis, partly based
on the assumption that communities observed in nature represent a stable equilibrium state
\citep{hastings1993}.
However, complex dynamics arise in a system with three or more species, and these are better
described as chaos rather than stable equilibrium.
The simplest definition of chaos is the extreme sensitivity of a system to its
initial conditions \citep{hastings1993}.
\citet{hastings1991}, who studied chaos in a continuous time model of a food web including
three species, contributed considerably to the significance and understanding of this subject.
This study led to many others on food webs dynamics and chaos, which reinforced
the importance of chaos in ecological modelling \citep{blasius1999, gakkhar2012}.

In this article, we provide a replication of the model from \citet{hastings1991} using the
same equations and parameter values.
Replicating a classic study and model like this one is important for many reasons:
1) we can compare the original results with ones obtained using current technologies,
ensuring that they can still be reproduced;
2) we can provide a publicly available and reproducible version of the codes that recreate
the model.
We were able to successfully replicate all figures in the original article using
\textit{Julia v1.3.1}.
All code used to replicate the original model is available alongside this article
(\url{https://github.com/BIO6032/2019_replication_HastingsPowell_1991}).

\section{Methods}

The model formulation used in this paper is the same as in the original
publication. \citeauthor{hastings1991} used a 14 parameter model to represent the three-species
food chain, with $X$, $Y$, and $Z$ as the numbers of the species at the lowest level of
the food chain, of the species that preys upon $X$, and of the species that preys upon
$Y$, respectively.
However, all of their analyses are based on a simpler version of the model with
nondimensional measures of time and population sizes, hence 10 parameters only, with $x$,
$y$ and $z$ as the standardized abundances of the three species.
We chose to present this simpler nondimensional version only in this paper, and we invite
readers to consult \citeauthor{hastings1991}'s paper for more details on the original dimensional
parameters. Our model's formulation is given as:

\begin{equation} \label{eq:1}
  \begin{align}
    dx/dt &= x(1 - x) - f_1(x)y \\
    dy/dt &= f_1(x)y - f_2(y)z - d_1y \\
    dz/dt &= f_2(y)z - d_2z
  \end{align}
\end{equation}

with

\begin{equation} \label{eq:2}
    f_i(u) = a_iu/(1 + b_iu)
\end{equation}

as the functional response.

Parameter values used in this paper are the same as in the original paper
(\autoref{tbl:table1}). However, initial conditions of the simulations (i.e. the values of $x$,
$y$ and $z$ at the start) were not given in the original paper.
This is an important point, as initial conditions strongly affect the simulations,
particularly in the context of chaotic behaviour.
We knew from Fig.3 of the original paper that $x \approx 0.76$.
We tried to approximate $y$ and $z$ by trial and error, and found $x = 0.76$, $y = 0.16$ and
$z = 9.9$ to be an appropriate combination for most cases.
We adapted the initial conditions in some simulations to give the closest matching
graphical result to the original figures.
The conditions used are specified in each figure caption.
We consider this a successful replication, despite the impossibility of using precisely
the same initial conditions.

\begin{table}[!htb]
  \centering
  \caption{Nondimensional parameters and the values used in the simulations}
  \label{tbl:table1}
  \begin{tabular}{c l}
    \hline
    & Values \\
    \hline
    $a_1$ & 5.0 \\
    $b_1$ & 2.0 $\rightarrow$ 6.2 \\
    $a_2$ & 0.1 \\
    $b_2$ & 2.0 \\
    $d_1$ & 0.4 \\
    $d_2$ & 0.01 \\
    \hline
  \end{tabular}
\end{table}

As noted by \citeauthor{hastings1991}, numerical integration is the only way to investigate the
global dynamical behaviour of the system.
We used \textit{Julia v1.3.1} \citep{bezanson2017}, along with packages \verb| DifferentialEquations.jl|
\citep{rackauckas2017} to compute the numerical integrations and \verb|Plots.jl| to represent
our results.
Not knowing the exact algorithm used in the original article, we let the \verb|solve()| function
select the appropriate algorithm to solve our differential equations.
In our implementation, it selected a composite algorithm combining, amongst others,
algorithms Tsit5 and Rosenbrock23.
We did note, however, that setting a specific algorithm such as RK4 sometimes resulted in a similar
behaviour for the system.

To fully replicate key findings of the original paper, we focused on replicating
original figures.
Here we describe the steps we took for Fig. 2, 3, 4 and 5 from the original paper.
Note that Fig. 5A refers to \citeauthor{hastings1991}'s figure, while \autoref{fig:fig5}a
refers to our reproduction.

Original Fig. 2 illustrates the chaotic behaviour of the system in time for each species.
In order to replicate it, we followed \citeauthor{hastings1991}'s method and let our system
run for 10 000 time steps.
We then represented the system's behaviour by plotting the species nondimensional
variables against time (between time steps 5000 and 6500, which eliminates transient
behaviour), as well as a three dimensional phase plot of the three species (for all time
steps). Note that in the case of the three dimensional phase plot, we had to set RK4 as
the solving algorithm, as well as a relative tolerance of $1e-14$; otherwise, the
representation was unexpectedly different from the original paper.
This suggests that the results for this figure in the original article may have been an
artifact.
In order to illustrate the dynamics of the model, we created a Graphics Interchange Format
(GIF) file of the three-dimensional phase plot that showed the trajectories of $x$, $y$
and $z$ for the selected parameters (\url{https://github.com/BIO6032/2019_replication_HastingsPowell_1991/blob/master/article/figures/figure2D.gif}).

Original Fig. 3 shows the divergence of trajectories caused by a small change in initial
conditions when the system exhibits chaotic behaviour.
To replicate the figure, we plotted the trajectory for species $x$ between time steps 0
and 500 starting at $x = 0.77$, then changed the initial $x$ value by 0.01 (to $x = 0.78$)
and plotted the new trajectory for the same interval on the same figure.

Original Fig. 4 illustrates the appearance of chaotic behaviour as a function of changes in
$b_1$. To replicate it, we constructed a bifurcation diagram for species $z$ where we
varied values of $b_1$ from 2.2 to 6.2 in steps of 0.01.
However, our approach was slightly different from the original one.
\citeauthor{hastings1991}'s figure is a special type of bifurcation diagram
representing only the maxima of $z$ as a function of $b_1$, rather than all possible
values in the system's behaviour as in a typical logistic bifurcation diagram.
This raises the problem of correctly identifying the maximum values in the cycling
dynamics. Moreover, \citeauthor{hastings1991} mention removing points resulting from
secondary local maxima, but do not provide details on how to identify these points.
Hence, we adopted the following method:
1) we selected the 1000 last solutions for our system between time steps 1 and 10 000, in
order to eliminate transient behaviour; %Reviewer comment: This is unclear to me. Do you mean time steps 9000-10000? Please clarify.
2) we selected the values that were greater than both their preceding and following
values, which identified local maxima only;
and 3) we only kept values that were greater than a given threshold of the cycle's maximal
amplitude, in order to remove secondary local maxima.
We determined by trial and errors that the best threshold was 66\%, as it best removed
values in apparent second branches of $b_1$ while keeping the values in the primary
branch. We note however that for some values of $b_1$, the true solutions of the system
were unstable and that the system did not reach a cycling behaviour within 10 000 steps.
For these values of $b_1$ (37 values, all between 5.01 and 6.2), we could not present any
values of $z$ in our bifurcation diagram.

\citeauthor{hastings1991} mention in their original paper that they also examined the system's
behaviour when varying $b_2$ instead of $b_1$, although they do not present the results.
We examined the same behaviour by constructing another bifurcation diagram of $z$ for
values of $b_2$ varying from 1.5 to 3.2, using the same method as described above.
We set $b_1 = 3.0$, as it is the example used to illustrate chaotic behaviour throughout
\citeauthor{hastings1991}'s paper.

Original Fig. 5 illustrates another diagnostic feature of chaos, slopes of high magnitude on
a Poincaré map, for values of $b_1$ where the bifurcation diagram suggests chaotic
behaviour. In order to replicate this figure, we solved the system of differential
equations using the abovementioned algorithm RK4, as well as a relative tolerance of
$1e-14$. We used $b_1 = 3.0$ and $b_1 = 6.0$, as in the original paper, to replicate its
subfigures A-B and C-D, respectively.
We defined planes of equation $z = 9.0$ and $z = 3.0$ for those subfigures, respectively,
as these intercepted the "handles" of their respective three-dimensional phase plot.
We defined those "handles" as in \citeauthor{hastings1991}, that is as the region in the
phase plots where z declines from its maxima to its minima.
However, we had to use a tolerance value $\epsilon = 0.05$ in order to identify the points
whose distance from the plane was negligible (i.e. their $z$ values ranging between
8.95-9.05 and 2.95-3.05, respectively), since we were not able to find the phase plots'
exact interception points.
We specified the planes' $x$ and $y$ coordinates to retain only the points that were in
the "handles" (subfigures A,B: $x$ and $y$ ranging between 0.95-0.98 and 0.015-0.040,
respectively; subfigures C,D: $x$ and $y$ ranging between 0.93-1.00 and 0.00-0.09,
respectively).
As in the original paper, we recreated the Poincaré sections (subfigures A,C), by
plotting $y$ against $x$ coordinates of the retained points, and the Poincaré maps
(subfigures B,D), by plotting $x$ coordinates of the retained points $x(n)$
against that of their immediate subsequent retained points $x(n+1)$. Since Hastings and
Powell's Fig. 5E only schematized the plane in the three-dimensional phase plot, we
did not reproduce it.

The objective of this paper being to reproduce the main results of the original paper, we
did not reproduce its Fig. 1, which was only a schematic representation of the
three-species food chain.

\section{Results}

We were able to replicate \citeauthor{hastings1991}'s main findings, even without knowing their
exact algorithm and initial values.
First, our time series of the nondimensional variables (\autoref{fig:fig2}) presents similar
qualitative results as those identified by \citeauthor{hastings1991}.
We observed that the standardized population densities of $x$, $y$, and $z$ (\autoref{eq:1}, \autoref{eq:2})
oscillate with a period of around 125 time steps.
Within a cycle, the population densities of species $x$ and $y$ oscillate while that of
species $z$ grows until it reaches its primary local maximum (see definition in methods),
at which $y$ and $x$ respectively reach their local minimum and maximum values.
$z$ then declines until it reaches its local minimum, forming the "handle" of the teacup
(\autoref{fig:fig2d}), and subsequently beginning a new cycle.
The animated figure we produced illustrates this dynamic (see supp.
online material).
Although slight discrepancies exist between our results and those of \citeauthor{hastings1991},
they did not seem to strongly influence the abovementioned period length, nor the values
of the local maxima and minima of the dimensionless variables.
Indeed, $x$ varies approximately from 0.2 to 1.0, $y$ from 0.0 to 0.4, and $z$ from 7.5 to
10.5 (\autoref{fig:fig2}), as seen in the original paper.

Second, the time series of $x$ from $t = 0$ to $500$ supports the chaotic behaviour of the
system, with slightly different initial conditions leading to increasingly different
trajectories (\autoref{fig:fig3}). The values themselves are almost identical to \citeauthor{hastings1991}'s
until $t \approx 250$, at which point they start to diverge, but this behaviour was to be
expected without the exact same initial conditions.

Third, our bifurcation diagrams (\autoref{fig:fig4}) have the same general shapes as the ones of
\citeauthor{hastings1991}, and are in the same range of $z_{max}$. We identified most of the
local maxima of $z$ found in the original paper for $b_1$ ranging from 2.2 to 6.2.
However, we missed some of them and we found others that were absent in their paper.
For instance, for $b_1$ = 3.1, we found multiple local maxima of $z$, whereas \citeauthor{hastings1991} had only found a dichotomy of values.
The differences are even more apparent in \autoref{fig:fig4}c, which represents a detailed
portion of \autoref{fig:fig4}a. For example, contrary to their findings, we did identify local
maxima values for $b_1$ ranging from 2.30 and 2.35. In other words, we did not observe the
significant gap in the bifurcation diagram that they had found.

Our additional bifurcation diagrams, where we varied $b_2$ instead of $b_1$ (\autoref{fig:figS1}),
confirm that chaos occurs for values other than $b_2$ = 2.0. Chaos is apparent for both
smaller or greater values.
However, while \citeauthor{hastings1991} reported that chaos was more likely for greater values of
$b_2$, our results highlight that $z$ instead converges to a single value and starts to
crash past $b_2$ = 2.35. %Reviewer comment: Please clarify what you mean by "crash" here. e.g. "starts to rapidly approach zero"

Lastly, although \citeauthor{hastings1991} did not specify the equation of the plane that
crosses the trajectories of the phase plot at its "handle", we were able to accurately
replicate their Poincaré section and map for $b_1$ = 3.0 (\autoref{fig:figS1} a,b). The main
discordance lies in the number of points that cross the plane, and consequently on the
apparent smoothness of the plots.
On the other hand, it was harder to precisely replicate the Poincaré map for $b_1$ = 6.0
(\autoref{fig:figS1}d), even though the corresponding reproduced Poincaré section (\autoref{fig:figS1}c)
was similar to the one in \citeauthor{hastings1991}'s paper.

\section{Discussion}

We were able to replicate the chaotic behaviour displayed by \citeauthor{hastings1991}'s model.
The resulting behaviour is indeed very sensitive to the initial conditions, showing
increasingly diverging trajectories (\autoref{fig:fig3}) for slightly different parameters, as well
as unending oscillations (\autoref{fig:fig2}). The bifurcation diagrams (\autoref{fig:fig4}) further confirm
the existence of chaos by illustrating the presence of cyclic behaviour for some values
and chaotic intervals for others, hence the extreme sensitivity of the system to $b_1$
values. As for the Poincaré sections (\autoref{fig:figS1} a,c), \citeauthor{hastings1991} plotted (x,y)
coordinates of points of the phase plots that theoretically coincided with the plane in
the "handle" of the teacup-shaped diagrams.
The Poincaré sections being almost unidimensional, we considered, as explained in the
original paper, a single variable within our Poincaré maps (\autoref{fig:figS1} b,d). The slopes
of these latter graphs therefore also denoted chaos, as specified by \citeauthor{hastings1991}.

For \autoref{fig:fig2} and \autoref{fig:fig3}, the shape of the cycles and oscillations are similar to
\citeauthor{hastings1991}'s.
As mentioned earlier, the slight differences are due to the fact that we could not use the
exact same initial conditions as the original authors.
Such difference is to be expected with a system exhibiting chaotic behaviour and do not
alter the conclusions.

The difference between our \autoref{fig:fig4} and \citeauthor{hastings1991}'s bifurcation diagram is more
intriguing. Admittedly, we could not figure out exactly what \citeauthor{hastings1991}'s method
was, and some elements such as identifying maxima values by increasing $b_1$ first, then
by decreasing it, did not make sense to us.
Our method should be appropriate, theoretically, to select only values that are primary
local maxima, and it did seem to work very well for most $b_2$ values;
yet, the broad range of values that we observed at $b_1$ = 3.1 instead of a dichotomy is
hard to explain.
It seems unlikely that the problem could be related to our arbitrary threshold of 66\% or
to our identification of a local maximum, because we would then either miss some lower
values or have too many, not having more in between.
The timeseries of all values of $z$ (not presented here) for $b_1$ = 3.1 confirms that
there are "intermediate" maxima values, which should be selected by any proper method.
We suggest that the difference might be due to the algorithms used for the numerical
integration in our two studies.
It is possible that the relationship between the parameters at this point is such that a
small difference in algorithm might have an important impact.
It is also possible that their algorithm came up with an unstable solution and a system
that did not reach cycling behaviour, such as ours for certain values past $b_1$ = 5.01,
but that \citeauthor{hastings1991}'s method selected some values anyways, explaining the behaviour
at $b_1$ = 3.1.

While we also found chaos for values of $b_2$ other than the default one of 2.0, both
smaller or greater, we do not totally agree with \citeauthor{hastings1991} that "chaos is more
likely for larger values of $b_2$". As \autoref{fig:figS1} shows %Reviewer comment: missing verb?
, chaos can be quite likely for both
smaller or larger values.
We find important to note, however, that at a certain value of $b_2$, $z$ converges and
starts to crash, thus exhibiting non chaotic behaviour within a given range of $b_1$
values. This crash is to be expected when looking at the original dimensional parameters,
so it is possible that \citeauthor{hastings1991} simply chose not to reach this limit in their
analyses, as they were only interested in biologically reasonable parameters likely to
occur with the three species present.

We believe that our mixed results in attempting to replicate \autoref{fig:figS1} came from the
algorithm we used to identify the points that coincided with the plane.
For instance, we had to specify a tolerance value ($\epsilon$ = 0.05), which defined a region
under and above the plane.
Although we were able to precisely replicate the Poincaré sections for $b_1$ = 3.0
(\autoref{fig:figS1}a) and 6.0 (\autoref{fig:figS1}c), the Poincaré maps need some refinement.
For $b_1$ = 3.0 (\autoref{fig:figS1}b), it lacked some points of the phase plots and included
others that were closed yet non-coincident with the plane.
For $b_1$ = 6.0 (\autoref{fig:figS1}d), the discrepancy was more obvious, and might be due to the
more chaotic behaviour of the system under this parameter value, observed for example from the
larger width of its "handle" (compare axis intervals of \autoref{fig:figS1} a,c).

We have succeeded in replicating \citeauthor{hastings1991}'s model and its main findings, as our
results confirm chaos arising in a three species food chain in continuous time.
In general, the model, including its equations and parameters, was well described by the
authors. The most significant obstacles to reproducibility in \citeauthor{hastings1991}'s paper
were the absence of the values of the initial conditions, which have a huge impact on a
chaotic system, and the insufficient description of certain methods. %Reviewer comment: Be explicit here about what was insufficiently described. E.g. the numerical integration methods.
Consequently, there are slight differences between our results and theirs.
Furthermore, since we tried to keep our implementation as close as possible to the
original one, some steps did rely on arbitrary thresholds (for instance for the primary
local maxima or the boundaries of the Poincaré sections and maps).
Hence, our replication is somewhat inflexible and possibly could not be applied to
a broader range of parameter values.
We suggest that an interesting step forward would be to train machine-learning algorithms,
such as neural networks, to identify chaotic behaviour and its boundaries, in order to
obtain an even better performing implementation.

\section{Author Contributions}
GD, FB and EB performed the first version of the reproduction and wrote the first version of the manuscript. AMD and TP provided guidance and comments during the reproduction, and revised the manuscript. GD performed the final revisions.

\section{Acknowledgments}
This reproduction was realized as part of the \textit{BIO6032 Biologie Computationnelle et Modélisation} course at Université de Montréal.

\newpage

\begin{figure}
  \centering
  \includegraphics[scale=0.7]{figures/fig2.pdf} \caption{Time series of the nondimensional variables (a) $x$, (b) $y$ and (c) $z$, for $t$ ranging from 5000 to 6500 ($x$ = 0.76, $y$ = 0.16, and $z$ = 9.9 as initial conditions). The parameter values used in the simulations are given in \autoref{tbl:table1} ($b_1$ = 3.0). This figure replicates Fig. 2 A,B,C of \citet{hastings1991}.}
  \label{fig:fig2}
\end{figure}

\newpage

\begin{figure}
  \centering
  \includegraphics[scale=0.7]{figures/fig2d.pdf}
  \caption{Three-dimensional phase plot of species $x$, $y$ and $z$ for $t$ ranging from 1 to 10 000 ($x$ = 0.76, $y$ = 0.16, and $z$ = 9.9 as initial conditions). The parameter values used in the simulations are given in \autoref{tbl:table1} ($b_1$ = 3.0). This figure replicates Fig. 2D of \citet{hastings1991}.}
  \label{fig:fig2d}
\end{figure}

\newpage

\begin{figure}
  \centering
  \includegraphics[scale=0.7]{figures/fig3.pdf}
  \caption{Time series of $x$, for $t$ ranging from 0 to 500. The solid and dashed lines have  $x$ = 0.77 and $x$ = 0.78 as initial conditions respectively ($y$ = 0.16 and $z$ = 9.9 as initial conditions are unchanged). The parameter values used in the simulations are given in \autoref{tbl:table1} ($b_1$ = 3.0). This figure replicates Fig. 3 of \citet{hastings1991}.}
  \label{fig:fig3}
\end{figure}

\newpage

\begin{figure}
  \centering
  \includegraphics[scale=0.7]{figures/fig4.pdf}
  \caption{Bifurcation diagrams of the local maxima of $z$ plotted against $b_1$ ranging from (a) 2.2 to 3.2, (b) 3.0 to 6.2, and (c) 2.25 to 2.6. The other parameter values used in the simulations are given in \autoref{tbl:table1} ($x$ = 0.76, $y$ = 0.16, and $z$ = 9.9 as initial conditions). This figure replicates Fig. 4 of \citet{hastings1991}.}
  \label{fig:fig4}
\end{figure}

\newpage

\begin{figure}
  \centering
  \includegraphics[scale=0.7]{figures/fig5.pdf}
  \caption{(a) and (b) Poincaré section and map, respectively, for the parameter values given in \autoref{tbl:table1} ($b_1$ = 3.0).  (c) and (d) Poincaré section and map for the same parameter values except $b_1$ = 6.0. All sets of initial values are unchanged ($x$ = 0.76, $y$ = 0.16, $z$ = 9.9). The solid lines of equation $x(n+1) = x(n)$ are shown in (b) and (d). This figure replicates Fig. 5 of \citet{hastings1991}, except their Fig. 5E, which is partly reproduced in \autoref{fig:fig2d}.}
  \label{fig:fig5}
\end{figure}

\newpage

\begin{figure}
  \centering
  \includegraphics[scale=0.7]{figures/figS1.pdf}
  \caption{Bifurcation diagrams of the local maxima of $z$ plotted against $b_2$ ranging from 1.5 to 3.2. The other parameter values used in the simulations are given in \autoref{tbl:table1} ($x$ = 1.0, $y$ = 1.0, and $z$ = 1.0 as initial conditions, $b_1$ = 3.0).}
  \label{fig:figS1}
\end{figure}