% Created 2022-01-04 Tue 01:03
% Intended LaTeX compiler: pdflatex
\documentclass[presentation]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{awesomebox}
\usepackage{booktabs}
\usepackage{placeins}
\usepackage{siunitx}
\usepackage{minted}
\usetheme[progressbar=frametitle]{metropolis}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{spot}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\usepgfplotslibrary{groupplots}
\newcommand{\gv}[1]{\ensuremath{\mbox{\boldmath$ #1 $}}}
\newcommand{\bv}[1]{\ensuremath{\mathbf{#1}}}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
\newcommand{\abs}[1]{\left\lvert#1\right\rvert}
\newcommand{\bigqm}[1][1]{\text{\larger[#1]{\text{?}}}}
\newcommand{\order}[1]{\mathcal O \left( #1 \right)} % order of magnitude
\definecolor{scarlet}{rgb}{1.0, 0.13, 0.0}
\definecolor{shamrockgreen}{rgb}{0.0, 0.62, 0.38}
\definecolor{royalblue}{rgb}{0.25, 0.41, 0.88}
\definecolor{metropolisorange}{RGB}{235,129,27}
\definecolor{metropolisblue}{RGB}{35,55,59}
\usetheme{default}
\author{\emph{Tejaswin Parthasarathy}, Mattia Gazzola}
\date{\today}
\title{Elastica : Timesteppers}
\subtitle{ME447: Comp. Design \& Dyn. of Soft Syst}
\hypersetup{
 pdfauthor={\emph{Tejaswin Parthasarathy}, Mattia Gazzola},
 pdftitle={Elastica : Timesteppers},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 28.0.50 (Org mode 9.4.6)},
 pdflang={English}}
\begin{document}

\maketitle
\tikzset{>=latex}
\section{Time-marching algorithms}
\label{sec:org3fd3f69}
\begin{frame}[label={sec:orgc24348f}]{Motivation}
\begin{example}[Solve the following ODE]
\[ \frac{dx}{dt} = 2x \quad x(0) = 1 \]
\end{example}
\begin{block}{We can!}
\[ x(t) = e^{2t}\]
\end{block}
\end{frame}

\begin{frame}[label={sec:orgb6c16ac}]{Motivation}
\begin{example}[Solve the following ODE]
\[ \frac{dx}{dt} = \sin(\cos x^{\frac{4}{3}}) + 4\sin^2(t) \quad x(0) = 1 \]
\end{example}

\begin{block}<2->{We can!}
Use a time-marching algorithm that can solve the above equation, albeit numerically
\end{block}
\end{frame}
\begin{frame}[label={sec:org79f0b8c}]{Introduction}
\begin{itemize}
\item As seen in the last lecture, all our (temporal/spatial) rate of frame change
vectors (that effect rotations) are precisely of this form
\end{itemize}

More generally, we can solve problems of the form
\[ \frac{\partial \mathbf{u}}{\partial t} = \mathbf{F}(\mathbf{u}, t) \]
which is a partial differential equation (PDE), wherein \(\mathbf{F}\) is
any arbitrary function.
\end{frame}
\begin{frame}[label={sec:org38ebce7}]{Examples}
\begin{itemize}
\item Population dynamics (Lotka-Volterra)
\[ \begin{aligned}
	  y'_1 &= y_1 (\alpha_1 - \beta_1 y_2) \quad \text{(prey)} \\
	  y'_2 &= y_2 (-\alpha_2 + \beta_2 y_1) \quad \text{(predator)}
	  \end{aligned} \]
\item Chemical reactions (stiff)
\item Newton's equations of motion (our focus)
\[  m\ddot{\gv{x}} = F(\gv{x},t) \]
\end{itemize}
\note{:B\_note:
\begin{itemize}
\item Need not be time variable
\end{itemize}}
\end{frame}
\begin{frame}[label={sec:orgd98aec1}]{Introduction}
\begin{itemize}
\item We investigate three different (classes of) time-marching algorithms for
autonomous problems (?!):
\begin{itemize}
\item Euler's method (or Euler forward/backward)
\item Runge-Kutta-4/RK4 (multi-stage methods)
\item Position Verlet (symplectic, area preserving integrators)
\end{itemize}
\item We develop time marching methods that compute approximations to \(u(t)\)
at specfic time points, \(t^0, t^1, \cdots, t^n\).
\begin{itemize}
\item We only consider a uniform timestep size \(dt  \rightarrow t^n = n \cdot
       dt\).
\end{itemize}
\item Finally, we \emph{compare} these methods based on general and problem-specific properties\ldots{}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:orgb10ecc6}]{Problem statement}
\begin{itemize}
\item Need function \(\gv{u} : [0, T] \to \mathbb{R}^n\) so that
\begin{itemize}
\item \(\gv{u}^{(k)}(t) = \gv{f}(t, \gv{u}, \gv{u}', \cdots , \gv{u}^{(k-1)})\) (\alert{explicit})
\end{itemize}
or
\begin{itemize}
\item \(\gv{f}(t, \gv{u}, \gv{u}', \cdots , \gv{u}^{(k-1)}, \gv{u}^{(k)}) = \gv{0}\) (\alert{implicit})
\end{itemize}
where we find a solution to a \(k\)-th order ordinary differential
equation. Typically \(k = 1,2\)
\item Meaningful only when accompanied by \(k\) initial conditions
\end{itemize}
\end{frame}
\begin{frame}[label={sec:orgfa4ae8a}]{Some properties of ODEs}
\begin{itemize}
\item \alert{Autonomous} ODE?
\begin{itemize}
\item \(\gv{f}\) does not explicitly depend on time \(t\)
\item An ODE can be made autonomous by introducing an extra variable (More on
this later)
\end{itemize}
\item \alert{Linear} ODE?
\begin{itemize}
\item \(\gv{f}(\gv{u}, t) =  \bv{A}(t)\gv{u} + \underbrace{\gv{b}}_{\text{forcing}}\)
\end{itemize}
\item \alert{Linear, homogenous} ODE?
\begin{itemize}
\item \(\gv{f}(\gv{u}, t) =  \bv{A}(t)\gv{u}\)
\end{itemize}
\item \alert{Constant-coefficient} ODE?
\begin{itemize}
\item \(\gv{f}(\gv{u}, t) =  \bv{A}\gv{u}\)
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org2600374}]{Numerical methods: Euler's forward method}
\begin{columns}
\begin{column}{0.5\columnwidth}
\begin{itemize}
\item Simplest timestepping scheme
\item First-order approximation at time \(t_0\)
\begin{itemize}
\item Geometrical description
\item Taylor series expansion
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.4\columnwidth}
\begin{center}
	\begin{tikzpicture}[
	declare function={func(\x)=sin(deg(pi*\x));},
	declare function={funcder(\x)=pi*cos(deg(pi*\x));}]
	\begin{axis}%
		[grid=none,
		axis x line=bottom,
		axis y line=left,
		domain=0.41:0.57,
		xmin=0.38,
		xmax=0.6,
		ymin=0.95,
		ymax=1.01,
		xlabel={$t$},
		ylabel={$u(t)$},
		ticks=none,
		height=1.12\textwidth,
		enlargelimits=false,
		]
		\addplot[smooth, very thick,
		color=metropolisorange]{func(x)};
		% For each in pgfplots is painful, see
		% https://tex.stackexchange.com/q/264168
		\addplot[thick, color=metropolisblue, mark=*] coordinates
		{ (0.41, {func(0.41)}) ({0.45}, {func(0.41) + funcder(0.41)*0.04}) };
		\foreach \a in {0.45, 0.49,..., 0.57}
        {\edef
		\temp{
		% \noexpand\addplot coordinates { (\x,0.96) (\x,1.02)};
		\noexpand\addplot[thick, color=metropolisblue, mark=*] coordinates
		{ (\a, {func(\a - 0.04) + funcder(\a - 0.04)*0.04}) ({\a + 0.04}, {func(\a) + funcder(\a)*0.04}) };
		}\temp
		}

		%\pgfplotsinvokeforeach {0.41, 0.45,..., 0.53}{
		% \addplot{\a*x^2};
		% \addplot coordinates { (#1, {func(#1)}) ({#1 + 0.04}, {func(#1) + funcder(#1)*0.04}) };
		% \addplot coordinates { (#1, #1) (#1 + 0.04, #1 + 0.04) };
		% \draw (axis cs:#1, func(#1)) -- (axis cs:{#1 + 0.04}, {func(#1) + funcder(#1)*0.04});
		% }
	\end{axis}
	\end{tikzpicture}
\end{center}
\end{column}
\end{columns}
\[ u(t_{0}+dt)=u(t_{0})+dt \cdot u'(t_{0})+{\frac {1}{2}}dt^{2} \cdot u''(t_{0})+O(dt^{3}). \]
\begin{itemize}
\item First order because local slope approximation is \(\order{dt}\)
\end{itemize}
\end{frame}

\begin{frame}[label={sec:org3b4075b}]{General explicit time stepping schemes}
\begin{itemize}
\item Explicit schemes approximate the next iterate \(t^{n+1}\) using:
\end{itemize}
\[ \gv{u}^{n+1} = \sum_{i=0}^{k} \alpha_i \gv{u}^{n-i} + \sum_{j=0}^{r} \beta_j \frac{\partial \gv{u}^{n-j}}{\partial t} \]
  which for \(k=1\) and \(r=0\) looks something along these lines:
\[ \gv{u}^{n+1} = \alpha_0 \gv{u}^{n} + \alpha_1 \gv{u}^{n-1} + \beta_0 \frac{\partial \gv{u}^{n}}{\partial t} \]
\begin{itemize}
\item Derivation of schemes other than Euler method follow a similar line of reasoning, while
details vary\footnote{By a \alert{lot}}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org4bc84f4}]{Some more time stepping schemes}
With \(\dot{x} = f(x)\),
\begin{block}{Euler forward}
\[ x^{n+1} = x^{n} + f(x^{n}) \cdot dt \]
\end{block}
\begin{block}{Euler backward}
\[ x^{n+1} = x^{n} + f(x^{n+1}) \cdot dt \]
\end{block}
\begin{columns}
\begin{column}{0.5\columnwidth}
\begin{block}{Midpoint method}
\begin{equation*}
\begin{aligned}
x^{*}&= x^{n} + f({x}^{n}) \cdot \frac{dt}{2} \\
x^{n+1} &= x^{n} + f({x}^{*}) \cdot dt \\
\end{aligned}
\end{equation*}
\end{block}
\end{column}
\begin{column}{0.4\columnwidth}
\begin{center}
	\begin{tikzpicture}[
	declare function={func(\x)=sin(deg(pi*\x));},
	declare function={funcder(\x)=pi*cos(deg(pi*\x));}]
	\begin{axis}%
		[grid=none,
		axis x line=bottom,
		axis y line=none,
		domain=0.43:0.49,
		xmin=0.41,
		xmax=0.51,
		ymin=0.975,
		ymax=1.005,
		ticks=none,
		height=1.1\textwidth,
		enlargelimits=false,
		clip=false]
		\addplot[smooth, very thick,
		color=metropolisorange]{func(x)} node[pos=0.1, above, anchor=south east]
		{{\scriptsize$x(t)$}};

		% Draw derivatve from yn to yn+1 first
		% 0.44 to 0.48
		\addplot[color=metropolisblue, mark=*] coordinates
		{ (0.44, {func(0.44)}) ({0.48},
		{func(0.44) + 0.04*funcder(0.46)-0.004}) }
		node[pos=0, below right, anchor=west]{{\scriptsize $y^n$}}
		node[below right, anchor=north west]{{\scriptsize $y^{n+1}$}}
		node[right, anchor=south west]{Estd.};

		% Draw actual derivatve line
		\addplot[color=royalblue, thick] coordinates
		{ (0.44, {func(0.46) - 0.02*funcder(0.46) }) (0.48,
		{func(0.46) + 0.02*funcder(0.46)}) } node[above]{Actual};

		% Draw connections to ground now
		\addplot[dashed] coordinates
		{ (0.44, {func(0.44)}) (0.44,\pgfkeysvalueof{/pgfplots/ymin})}
		node [above right, anchor=south west]{{\scriptsize$t^{n}$}};

		\addplot[dashed] coordinates
		{ (0.46, {func(0.46)}) (0.46,\pgfkeysvalueof{/pgfplots/ymin})}
		node [below, anchor=north]{{\scriptsize$t^{n} + \frac{dt}{2}$}};

		\addplot[dashed] coordinates
		{ (0.48, {func(0.48)}) (0.48,\pgfkeysvalueof{/pgfplots/ymin})}
		node [above right, anchor=south west]{{\scriptsize$t^{n+1}$}};

	\end{axis}
	\end{tikzpicture}
\end{center}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org3bf8753}]{Some more time stepping schemes}
\begin{block}{Runge Kutta-4}
\begin{equation*}
\begin{aligned}
{k}_1 &= {f}({x}^{n}) \cdot dt \\
{k}_2 &= {f}({x}^{n} + 0.5 \cdot {k}_1)\cdot dt \\
{k}_3 &= {f}({x}^{n} + 0.5 \cdot {k}_2)\cdot dt \\
{k}_4 &= {f}({x}^{n} + {k}_3)\cdot dt \\
{x}^{n+1} &= {x}^{n} + \frac{{k}_1+2{k}_2+2{k}_3+{k}_4}{6}
\end{aligned}
\end{equation*}
\end{block}
\begin{block}{Position/Velocity Verlet}
\begin{itemize}
\item Later on we introduce these two schemes in the context of integrating
second order ODEs
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[label={sec:orgb1d9e79}]{Function evaluations}
\begin{itemize}
\item Our first attempt at comparing schemes is the number of functional
evaluations for one time step\ldots{}
\item Why? \(f(x)\) can be expensive to evaluate (e.g. calculating the effect
of the energy diffusion on millions to billions of
grid points in an astrophysical simulation)
\end{itemize}
\begin{table}[htbp]
\caption{\label{tab_sym_snake_params}Number of function evaluations for schemes}
\centering
\begin{tabular}{lr}
\toprule
Scheme & \(n[f(x)]\)\\
\midrule
Euler fwd & 1\\
Euler bwd & Solve!\\
Midpoint & 2\\
RK4 & 4\\
Verlet* & 1\\
\bottomrule
\end{tabular}
\end{table}
\end{frame}
\begin{frame}[label={sec:orge2303a5}]{Convergence/ Consistency}
Suppose the numerical solution at some time \(t\) is \(\gv{u}\), and the
exact solution at the same time is \(\tilde{\gv{u}}\).
\begin{definition}[Convergence]
A numerical method is said to be convergent if the numerical solution
approaches the exact solution as the step size \(dt\) goes to 0.
\end{definition}
The methods we just looked at are all convergent.
\begin{definition}[Consistency]
A numerical method is said to be consistent if the error, \(e_{dt}:=\lVert\tilde{\gv{u}}-\gv{u} \rVert\) is such that
\[ \lim_{dt \to 0} \frac{e_{dt}}{dt} = 0\]
\end{definition}
\end{frame}
\begin{frame}[label={sec:org2500b2a}]{Order of convergence}
\begin{definition}[Order of accuracy]
The numerical solution \(\gv{u}\) is said to be \(p^{\text{th}}\)-order
accurate if the error, \(e(dt):=\lVert\tilde{\gv{u}}-\gv{u} \rVert\)
is proportional to the step-size \(dt\), to the \(p^{\text{th}}\) power. That
is
\[ e(dt)=\lVert\tilde{\gv{u}}-\gv{u} \rVert\leq C(dt)^{p} \]
where the constant \(C\) is independent of \(dt\) and usually depends on
the solution \(\gv{u}\)
\end{definition}
 In the big O notation an \(p^{\text{th}}\)-order accurate numerical method
 is notated as
\[ \lVert\tilde{\gv{u}}-\gv{u} \rVert = \order{h^p}\]
\end{frame}
\begin{frame}[label={sec:org984fd76}]{Order of convergence : Importance}
\begin{columns}
\begin{column}{0.32\columnwidth}
\begin{block}{First order}
\begin{center}
\begin{tabular}{ll}
\toprule
\(dt\) & \(e(dt)\)\\
\midrule
\(10^{-1}\) & \(1\)\\
\(10^{-2}\) & \(10^{-1}\)\\
\(10^{-3}\) & \(10^{-2}\)\\
\(10^{-4}\) & \(10^{-3}\)\\
\(10^{-5}\) & \(\spot<2>{10^{-4}}\)\\
\bottomrule
\end{tabular}
\end{center}
\end{block}
\end{column}

\begin{column}{0.32\columnwidth}
\begin{block}{Second order}
\begin{center}
\begin{tabular}{ll}
\toprule
\(dt\) & \(e(dt)\)\\
\midrule
\(10^{-1}\) & \(1\)\\
\(10^{-2}\) & \(10^{-2}\)\\
\(10^{-3}\) & \(10^{-4}\)\\
\(10^{-4}\) & \(10^{-6}\)\\
\(10^{-5}\) & \(\spot<2>{10^{-8}}\)\\
\bottomrule
\end{tabular}
\end{center}
\end{block}
\end{column}
\begin{column}{0.32\columnwidth}
\begin{block}{Fourth order}
\begin{center}
\begin{tabular}{ll}
\toprule
\(dt\) & \(e(dt)\)\\
\midrule
\(10^{-1}\) & \(1\)\\
\(10^{-2}\) & \(10^{-4}\)\\
\(10^{-3}\) & \(10^{-8}\)\\
\(10^{-4}\) & \(10^{-12}\)\\
\(10^{-5}\) & \(\spot<2>{10^{-16}}\)\\
\bottomrule
\end{tabular}
\end{center}
\end{block}
\end{column}
\end{columns}
\begin{alertblock}<2->{Better returns for same timestep!}
\end{alertblock}
\end{frame}

\begin{frame}[label={sec:org9ae791f}]{Order of convergence : Implementation}
\begin{block}{Model problem definition}
Let's solve this problem, and test out methods for convergence:
\[ \frac{dy}{dt} = -y \quad,\quad  y(0) = 1 \]
which as we know has the analytical solution \(\tilde{y}(t) = e^{-t}\) \(\rightarrow\)
error known at every \(dt\)

Notice:
\begin{itemize}
\item We choose a simple problem to understand performance/convergence
\begin{itemize}
\item More complicated problems usually follow suit
\end{itemize}
\item We are solving an eigenvalue problem, just like the last lecture (rotations)
\end{itemize}

\alert{ACTIVITY}
\end{block}
\end{frame}
\begin{frame}[label={sec:org2bd73fe}]{Order of accuracy : Results}
% Need to run the notebook first
\begin{center}
	\begin{tikzpicture}
		\begin{loglogaxis}[
			enlargelimits=true,
			grid=both,
			grid style={line width=.1, draw=gray!20},
			major grid style={line width=.2,draw=gray!50},
			xlabel=$dt$,
			ylabel=$e(dt)$,
			height=1.0\textheight
			]
			% Euler backward/forward
			\addplot [mark=*, mark size=2.5, scarlet, very thick]
			table {code/data/euler_bwd_ooa.txt} node [midway, above left, anchor=south east]
			{Euler bwd/fwd};
			\addplot [metropolisblue, dashed, thick]
			table {code/data/euler_bwd_ooa_slopes.txt};

			% Midpoitn
			\addplot [mark=*, mark size=2.5, royalblue, very thick]
			table {code/data/midpoint_method_ooa.txt} node [pos=0.8, below , anchor=north west]
			{Midpoint};
			\addplot [metropolisblue, dashed, thick]
			table {code/data/midpoint_method_ooa_slopes.txt};

			% RK4
			\addplot [mark=*, mark size=2.5, metropolisorange, very thick]
			table {code/data/rk4_ooa.txt} node [midway, below right, anchor=north west]
			{RK4};
			\addplot [metropolisblue, dashed, thick]
			table {code/data/rk4_ooa_slopes.txt};

		\end{loglogaxis}
	\end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[label={sec:orga06aaa8}]{Order of accuracy : Results}
\begin{table}[htbp]
\caption{\label{tab_sym_snake_params}Order of accuracy for different schemes}
\centering
\begin{tabular}{lr}
\toprule
Scheme & \(p\)\\
\midrule
Euler & 1\\
Midpoint & 2\\
RK4 & 4\\
Verlet* & ?\\
\bottomrule
\end{tabular}
\end{table}
\end{frame}
\begin{frame}[label={sec:org70a597c}]{Bottomline}
\begin{itemize}
\item Order of accuracy is a measure of ``goodness'' of algorithm
\item Higher-order accurate algorithms commit less error for a given \(h\).
\item But they are costly (in terms number of function evaluations, and
ultimately number of operations performed)
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org492de25}]{Higher order ODEs}
We consider a harmonic oscillator, i.e. a linear spring-mass system:
\[ \ddot{x} + \omega^2 x = 0\]
\begin{columns}
\begin{column}{0.6\columnwidth}
\begin{itemize}
\item \(\omega^2 = \frac{k}{m} \equiv 1\)
\item Consider \(x(0) = 1, \dot{x}(0) = 0\) (need two ICs)
\item Solution is analytically known to be
\end{itemize}
\[ x(t) = \cos(t) \quad \dot{x}(t) = -\sin(t) \]
\begin{itemize}
\item Notice : solution is bounded
\end{itemize}
\end{column}
\begin{column}{0.4\columnwidth}
\tikzset{boxstyle/.style={draw,outer sep=0pt,thick}}
% https://tex.stackexchange.com/a/13952
\begin{center}
	\begin{tikzpicture}[scale=1]
	\tikzstyle{spring}=[thick,decorate,color=metropolisblue, decoration={zigzag,pre length=4,post length=4,segment length=10}]
	\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=8,minimum height=3]

	\node (M) [boxstyle, minimum width=50, minimum height=50, color=metropolisblue] {$m$};

	\node (ground) [ground,anchor=north,yshift=-10,minimum width=80] at (M.south) {};
	\draw (ground.north east) -- (ground.north west);
	\draw [thick] (M.south west) ++ (8pt,-5pt) circle (5pt) (M.south east) ++ (-8pt,-5pt) circle(5pt);
	% \draw [thick] (M.south west) ++ (8,-5) circle[radius=5pt];
	% \draw [thick]

	\node (wall) [ground, rotate=-90, minimum width=80, xshift=-10, yshift=-80] {};
	\draw (wall.north east) -- (wall.north west);

	% Syntax ($(A)!(C)!(B)$), specifies the projection of (C) on the line
	% from (A) to (B),
	% <name>.<number> syntax https://tex.stackexchange.com/a/426804
	\draw [spring] (M.180) -- ($(wall.north east)!(M.180)!(wall.north west)$)
	node [midway, above]{$kx$};

	% Draw x position beginning and end
	% Interesection of north east ground with horizontal wall and 10 pt line
	\draw [thick, color=metropolisblue] ($(wall.south west)!(ground.north west)!(wall.north west)$) --
	++ (0pt,-5pt) coordinate (c) -- ++(0pt,-5pt);
	\draw [thick, color=metropolisblue, ->] (c) -- ($(M.south west)!(c)!(M.north west)$)
	node[right]{$x$};

	\end{tikzpicture}
\end{center}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org5b1d4e0}]{Conservation laws in typical higher order ODEs}
The system is \alert{Hamiltonian} as the energy is conserved:
\[ \underbrace{H(x(t), \dot{x}(t))}_{\text{Hamiltonian/total energy}} = \underbrace{x^2(t)}_{\text{Potential energy}} +
   \underbrace{\dot{x}^2(t)}_{\text{Kinetic energy}} \equiv 1\]

The solution can be represented in the time domain (left) or in the phase
portrait (right)
\begin{columns}
\begin{column}{0.5\columnwidth}
\begin{center}
	\begin{tikzpicture}
	\begin{axis}%
		[grid=both,
		minor tick num=4,
		grid style={line width=.1pt, draw=gray!10},
		major grid style={line width=.2pt,draw=gray!50},
		axis lines=middle,
		domain=0:7,
		x label style={at={(axis description cs:1.1,0.5)},anchor=east},
		y label style={at={(axis description cs:-0.1,.5)},rotate=90,anchor=south},
		xlabel={$t$},
		ylabel={$u(t)$},
		width=1.1\textwidth,
		title style={at={(0.5,0)},anchor=north,yshift=-0.1},
		title={Time domain},
		enlargelimits=true,
		% enlargelimits={abs=0.2}
		]
		\addplot[samples=200,smooth,metropolisorange,very thick]{cos(deg(x))}
		node[pos=0.1, right]{{\small $x(t)$}};
		\addplot[samples=200,smooth,metropolisblue,very thick]{-sin(deg(x))}
		node[pos=0.99, below left, anchor=north east]{{\small $\dot{x}(t)$}};
	\end{axis}
	\end{tikzpicture}
\end{center}
\end{column}
\begin{column}{0.5\columnwidth}
\begin{center}
	\begin{tikzpicture}
	\begin{axis}%
		[grid=both,
		minor tick num=4,
		grid style={line width=.1pt, draw=gray!10},
		major grid style={line width=.2pt,draw=gray!50},
		axis lines=middle,
		width=1.1\textwidth,
		xmin=-1.1, xmax=1.1, ymin=-1.1, ymax=1.1,
		axis equal,
		x label style={at={(axis description cs:0.98,0.5)},anchor=south east},
		y label style={at={(axis description cs:0.5,0.98)},anchor=west},
		xlabel={\textcolor{metropolisorange}{$x$}},
		ylabel={\textcolor{metropolisblue}{$\dot{x}$}},
		title style={at={(0.5,-0.2)},anchor=south},
		% title style={at={(0.5,0.0)},anchor=north},
		title={Phase portrait},
		enlargelimits=true,
		disabledatascaling
		]
		\draw[very thick, black] (axis cs: 0, 0) circle [radius=1];
		\draw[thick, black, ->] (axis cs:0, 0)--(axis cs:0.707106, 0.707106);
		\draw [thick,->] (0.4,0) arc (0:45:0.4) node [midway, right]{{\scriptsize $t$}};
	\end{axis}
	\end{tikzpicture}
\end{center}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org8359662}]{Conversion to lower order ODE}
Let's convert the second order ODE to two first order ODEs, by considering \(y = \dot{x} \Rightarrow\)
\[ \begin{pmatrix} \dot{x} \\ \dot{y} \end{pmatrix} = \begin{bmatrix} 0 & 1\\-1
   & 0 \end{bmatrix} \begin{pmatrix} {x} \\ {y} \end{pmatrix} \]

\begin{itemize}
\item You can reuse the same schemes!
\item Alternatively, we can develop schemes for the second order equation
directly : \alert{Example using Taylor series}
\end{itemize}

\begin{block}{Position Verlet scheme}
\begin{itemize}
\item For integrating equations similar to \(\ddot{\gv{x}} = \gv{f}(\gv{x})\),
with \(\gv{y} = \dot{\gv{x}}\)
\end{itemize}
\begin{equation*}
\begin{aligned}
\gv{x}^* &= \gv{x}^n + 0.5\cdot dt \cdot \gv{y}^n \\
\gv{y}^{n+1} &= \gv{y}^n + dt \cdot \gv{f}\left( \gv{x}^*\right) \\
\gv{x}^{n+1} &= \gv{x}^* + 0.5\cdot dt \cdot \gv{y}^{n+1}
\end{aligned}
\end{equation*}
\end{block}
\note{:B\_note:
\begin{itemize}
\item Show derivation using
\end{itemize}
\[ f(x+h) = f(x) + f'(x)h + f''(x)h^2/2! + \cdots \quad
	f(x - h) = f(x) - f'(x) h + f''(x)h^2/2! + \cdots \]
and add them up}
\end{frame}
\begin{frame}[label={sec:org61a1641}]{More schemes}
Another example of a scheme for this model equation is
\begin{block}{Velocity Verlet algorithm}
\begin{equation*}
\begin{aligned}
\gv{y}^* &= \gv{y}^n + 0.5\cdot dt \cdot \gv{f}\left( \gv{x}^n\right) \\
\gv{x}^{n+1} &= \gv{x}^{n} + dt \cdot \gv{y}^{*} \\
\gv{y}^{n+1} &= \gv{y}^* + 0.5\cdot dt \cdot \gv{f}\left( \gv{x}^{n+1}\right) \\
\end{aligned}
\end{equation*}
\end{block}
\begin{block}{How do these schemes fare?}
\begin{itemize}
\item Position and Velocity Verlet have \(p = 2\) (second-order accurate) for
both position \(\gv{x}\) and velocity \(\gv{y}\)
\item But Position Verlet has only \alert{one} function evaluation!
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[label={sec:org4f35c6d}]{Energy-preserving/symplectic schemes}
\begin{block}{Why do we even care about these schemes?}
\begin{itemize}
\item Clearly, RK4 has higher order of convergence and it must be better?
\end{itemize}
\end{block}
\begin{block}{Answer}
\begin{itemize}
\item Position and Velocity Verlet schemes are symplectic (area-preserving) schemes
\item They preserve in the phase-portrait of a Hamiltonian system \(\Rightarrow\)
They always conserve energy by design!
\end{itemize}

\alert{ACTIVITY}
\end{block}
\end{frame}
\begin{frame}[label={sec:orga5817e9}]{Energy-preserving/symplectic schemes}
\begin{itemize}
\item The harmonic equation arises from Newton's fundamental laws of motion,
without dissipative forces \(\Rightarrow\) energy needs to be conserved
\item RK4 slowly dissipates energy \(\Rightarrow\) unphysical!
\item Euler forward increases energy without bounds, even when physics dictates
bounded solutions (counter examples?)
\item Verlet schemes conserve energy even for large \(dt\)
\begin{itemize}
\item There are still errors (it still has \(p = 2\) ) in the \emph{phase}
\item \alert{DEMO}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org0a9e1a4}]{But why is it energy preserving?\footnote{Peter Young, \href{https://young.physics.ucsc.edu/242/leapfrog.pdf}{Course Notes:Physics 115/242}}}
\begin{itemize}
\item Because it preserves the area in the \(x-p\) phase space (thus the area-preserving
property seen earlier)
\item Why area preservation? \(\Rightarrow\) \alert{Liouville's theorem}
\item On one application of the time-stepping scheme (map), an initial rectangle
with side lengths \(dx , dp\) gets stretched to a parallelogram with
sides \(dx^\prime, dp^\prime\)
\end{itemize}

\begin{columns}
\begin{column}{0.6\columnwidth}
New area \(dA^\prime = \det \bv{J} dA\), where \(\bv{J}\) is
\[ \bv{J} =	\begin{bmatrix}
	\frac{\partial x^\prime}{\partial x} & \frac{\partial x^\prime}{\partial p}  \\
	\frac{\partial p^\prime}{\partial x} & \frac{\partial p^\prime}{\partial p}  \\
	\end{bmatrix} \]

In the case of symplectic schemes, we require \(\det \bv{J} = 1\)
\end{column}
\begin{column}{0.4\columnwidth}
\begin{figure}[htbp]
\centering
\includegraphics[width=1.0\textwidth]{images/area_preserve.png}
\caption{Area preservation}
\end{figure}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org18a66f7}]{Area preserviation of Verlet and Euler algorithms}
From a different perspective,
\(\begin{pmatrix} \delta x_1 \\ \delta v_1 \end{pmatrix} = \bv{J}\begin{pmatrix} \delta x_0
   \\ \delta v_0 \end{pmatrix}\)
where subscripts denote number of applications of the time-stepping scheme.
Break it down to
\(\bv{J} = \bv{C}\bv{B}\bv{A}\).
\begin{columns}
\begin{column}{0.5\columnwidth}
\begin{alertblock}{Euler forward}
\begin{equation*}
\begin{aligned}
\bv{A} &= \begin{bmatrix} 1 & h\\ hF^\prime(x_0) & 1 \end{bmatrix}\\
\bv{B} &= \begin{bmatrix} 1 & 0\\ 0 & 1 \end{bmatrix} \\
\bv{C} &= \begin{bmatrix} 1 & 0\\ 0 & 1 \end{bmatrix}
\end{aligned}
\end{equation*}
\end{alertblock}
\end{column}
\begin{column}{0.5\columnwidth}
\begin{alertblock}{Position verlet}
\begin{equation*}
\begin{aligned}
\bv{A} &= \begin{bmatrix} 1 & \tfrac{h}{2}\\ 0 & 1 \end{bmatrix}\\
\bv{B} &= \begin{bmatrix} 1 & 0 \\ hF^\prime(x_{1/2}) & 1 \end{bmatrix}\\
\bv{C} &= \begin{bmatrix} 1 & \tfrac{h}{2}\\ 0 & 1 \end{bmatrix}\\
\end{aligned}
\end{equation*}
\end{alertblock}
\end{column}
\end{columns}
Calculate \(\det \bv{J}\)\ldots{}
\end{frame}
\begin{frame}[label={sec:orga4bc767}]{Bottomline}
\begin{itemize}
\item The evolution of dynamics of the soft filament also relies on some form of energy
conservation (translational/rotational/bending/twist/shear/stretch) as the
governing equations are Newton's laws
\item We need symplectic algorithms for maintaining relevance to the physical world
\end{itemize}

\alert{Counterpoint} In reality, there is always dissipation (frictional forces,
 viscous forces, drag forces not included in either of the above, etc.)
\end{frame}
\begin{frame}[label={sec:org907601a}]{Why did forward Euler blow-up?}
\begin{itemize}
\item Because it was unstable\ldots{}related to the stability of a method (alternatively instability)
\end{itemize}
\begin{block}{Euler forward algorithm}
\begin{itemize}
\item Find out what happens to the numerical solution using forward Euler when applied to
\(\dot{y}(t) = \lambda y(t)\)
\item Why? Eigenvalue problem, easy to extend analysis to general matrices
\end{itemize}
\begin{equation*}
\begin{aligned} y_k & = y_{k-1} + h \lambda y_{k-1} \\ &= (1 + h
\lambda)y_{k-1} \\ &= (1 + h \lambda)^{k}y_{0}
\end{aligned}
\end{equation*}
\begin{itemize}
\item So stability \(\Leftrightarrow\) \(\abs{1 + h \lambda} \leq 1\)
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[label={sec:org91666ec}]{Why did forward Euler blow-up?}
\begin{itemize}
\item \(\abs{1 + h \lambda}\) is the \alert{amplification factor}
\item The condition on the amplification factor implies the existence of a
\alert{stability region} in the complex plane
\item \alert{DEMO}
\end{itemize}
% This file was created by matplotlib2tikz v0.7.4.
\begin{center}
\begin{tikzpicture}[scale=0.45]
	\begin{groupplot}[group style={group size=3 by 1}]
	\nextgroupplot[
	title={Euler forward},
	grid=both,
	grid style={line width=.1pt, draw=gray!10},
	major grid style={line width=.2pt,draw=gray!50},
	axis equal,
	xmin=-2.2, xmax=0.2,
	ymin=-1.2, ymax=1.2,
	minor tick num=4,
	xlabel={\(\displaystyle \mathrm{Re}\)},
	ylabel={\(\displaystyle \mathrm{Im}\)},
	enlargelimits=false,
	disabledatascaling
	]

	\draw[very thick, metropolisblue, fill=metropolisorange, fill opacity=0.3]
	(axis cs: -1, 0) circle [radius=1];
	% \addplot [very thick, metropolisorange, fill=metropolisorange, fill opacity=0.3]
	% table {code/data/euler_fwd_stability.txt};

	\nextgroupplot[
	title={Euler backward},
	grid=both,
	grid style={line width=.1pt, draw=gray!10},
	major grid style={line width=.2pt,draw=gray!50},
	axis equal,
	xmin=-0.2, xmax=2.2,
	ymin=-1.2, ymax=1.2,
	minor tick num=4,
	xlabel={\(\mathrm{Re}\)},
	enlargelimits=false,
	disabledatascaling
	]
	% \addplot [fill=metropolisorange, fill opacity=0.3]
	% table [row sep=\\]{
	% -0.5 -1.5\\
	% 2.5 -1.5\\
	% 2.5 1.5\\
	% -0.5 1.5\\
	% -0.5 -1.5};
	\filldraw[fill=metropolisorange, fill opacity=0.3]
	(axis cs: -1, -2) rectangle (3,2);
	\draw[very thick, metropolisblue, fill=white, fill opacity=0.6]
	(axis cs: 1, 0) circle [radius=1];
	% \addplot [thick, metropolisorange] table {code/data/euler_bwd_stability.txt};

	\nextgroupplot[
	title={Runge-Kutta--4},
	grid=both,
	grid style={line width=.1pt, draw=gray!10},
	major grid style={line width=.2pt,draw=gray!50},
	axis equal,
	xmin=-3, xmax=1,
	ymin=-3, ymax=3,
	minor tick num=4,
	xlabel={\(\mathrm{Re}\)},
	enlargelimits=false,
	disabledatascaling,
	]
	\addplot [thick, metropolisblue, fill=metropolisorange,
	fill opacity=0.3] table {code/data/rk4_stability.txt};
	\end{groupplot}
\end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[label={sec:org31e4784}]{What about backward Euler?}
\begin{block}{Backward Euler algorithm}
\begin{itemize}
\item Find out what happens to the numerical solution using backward Euler when applied to
\(\dot{y}(t) = \lambda y(t)\)
\end{itemize}
\begin{equation*}
\begin{aligned} y_k & = y_{k-1} + h \lambda y_{k} \\
y_k (1 - h \lambda) &= y_{k-1} \\
y_k &= \frac{1}{(1 - h \lambda)}y_{k-1} \\
y_k &= \left( \frac{1}{1 - h \lambda} \right)^k y_{0}
\end{aligned}
\end{equation*}
\begin{itemize}
\item So stability \(\Leftrightarrow\) \(\abs{1 - h \lambda} \geq 1\)
\item Backward Euler can be stable even when the ODE is not!
\item \alert{DEMO}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[label={sec:orgc276ff8}]{What about Verlet ?}
\begin{block}{Can it blow up?}
\end{block}
\begin{block}<2->{It can!}
\begin{itemize}
\item But only for non-hamiltonian systems
\item For hamiltonian systems, it always conserves a positive semi-definite
quantity and hence should not blow up
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[label={sec:org70d82df}]{Bottomline}
\begin{itemize}
\item Stability is another measure of how ``good'' a time-marching algorithm is
\item For \alert{explicit} schemes, main concern in time-step selection is usually
\alert{stability} (but also accuracy)
\item For \alert{implicit} schemes, \alert{accuracy} determines the time-step selection
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org58363b5}]{Stiff ODEs}
\begin{block}{What are stiff problems?}
\begin{itemize}
\item Hard to define exactly
\item Usually when there are \alert{multiple time scales} in our problem
\end{itemize}
\end{block}
\begin{alertblock}{DEMO}
\begin{itemize}
\item In the above demo, stiffness results from the presence of a fast decay
component, but slow evolution of the total solution (slow--fast time scale)
\item In the case of a stable ODE system \(\dot{\gv{y}}(t) = \bv{J}_{f}(\gv{y}(t))\)
stiffness can arise if \(\bv{J}_f\) has eigenvalues of very different
magnitude (what is this called again?)
\end{itemize}
\end{alertblock}
\end{frame}
\begin{frame}[label={sec:org0e9270d}]{Stiff ODEs}
\begin{itemize}
\item Why not just \emph{small} or \emph{large} magnitude?
\begin{itemize}
\item Because discrepancy in time scales is the problem
\item If all time scales are similar, then we can deal with that one time
scale (non-dimensionalization of the problem helps)
\item If there are many, then some (usually fast ones) may be considered uninteresting.
\end{itemize}
\end{itemize}
\begin{block}{Explicit methods}
\begin{itemize}
\item What was the problem in applying explicit methods to stiff problems?
\begin{itemize}
\item Fastest time scale governs timestep \(\Rightarrow\) small timesteps
\(\Rightarrow\) inefficient.
\end{itemize}
\item \alert{Accuracy} (in terms of capturing the slow timescale) could be achieved
with large timesteps
\item \alert{Stability} demands a small time step
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[label={sec:org7de5eb0}]{Stiff ODEs}
\begin{block}{Implicit methods}
\begin{itemize}
\item Large time steps?
\begin{itemize}
\item Definitely.
\end{itemize}
\item \alert{Stability} is not a problem
\item \alert{Accuracy} suffers.
\end{itemize}
\end{block}
\begin{block}{So even here we have an issue.}
\end{block}
\begin{block}{Bottomline}
Stiff problems are hard to tackle (there are still ingenious ways to
partially offset the cost of solving a stiff problem)
\end{block}
\end{frame}

\begin{frame}[label={sec:org7b18dab}]{Summary}
\begin{table}[htbp]
\caption{\label{tab_sym_snake_params}Properties of different explicit schemes}
\centering
\begin{tabular}{lrrl}
\toprule
Scheme & \(p\) & \(n[f(x)]\) & Energy preserving?\\
\midrule
Euler & 1 & 1 & No\\
Midpoint & 2 & 2 & No\\
RK4 & 4 & 4 & No\\
Verlet & 2 & 1 & Yes\\
\bottomrule
\end{tabular}
\end{table}
\end{frame}
\begin{frame}[label={sec:org2e22f4e}]{Credits}
\begin{block}{A good chunk of the material in these slides are taken from Prof. Andreas Kloeckner's CS450 lectures}
\end{block}
\end{frame}
\end{document}


\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\title{Judson's Abstract Algebra: Chapter 3}
\date{}

\begin{document}
\maketitle

\section*{1}

Suppose $3x \equiv 2 \mod 7$. Then $x \in \{z: z = 3 + 7n, n \in \mathbb{Z}\}$.

\vspace{\baselineskip}

Suppose $5x + 1 \equiv 13 \mod 23$. Then $x \in \{z: z = 7 + 23n, n \in \mathbb{Z}\}$.

\vspace{\baselineskip}

Suppose $5x + 1 \equiv 13 \mod 26$. Then $x \in \{z: z = 18 + 26n, n \in \mathbb{Z}\}$.

\vspace{\baselineskip}

Suppose $9x \equiv 3 \mod 5$. Then $x \in \{z: z = 2 + 5n, n \in \mathbb{Z}\}$.

\vspace{\baselineskip}

Suppose $5x \equiv 1 \mod 6$. Then $x \in \{z: z = 5 + 6n, n \in \mathbb{Z}\}$.

\vspace{\baselineskip}

Suppose $3x \equiv 1 \mod 6$. There are no solutions.

\section*{6}

Give a multiplication table for the group $U(12)$.

\vspace{\baselineskip}

Note that $U(12) = \{ 1, 5, 7, 11 \}.$

$$
\begin{tabular}{ l | l l l l l }
  * & 1 & 5 & 7 & 11 \\
  \hline
  1 & 1 & 5 & 7 & 11 \\
  5 & 5 & 1 & 11 & 7 \\
  7 & 7 & 11 & 1 & 5 \\
  11 & 11 & 7 & 5 & 1 \\
\end{tabular}
$$

\section*{7}

Let $S = \mathbb{R} \setminus \{ -1 \}$ and define a binary operation on $S$ by $a * b = a + b + ab$. Prove that $(S, *)$ is an abelian group.

\vspace{\baselineskip}

Let $a, b, c \in S$. The identity is 0 since $a * 0 = a + 0 + 0a = a$. The inverse of $a$ is given by

$$ a^{-1} = \frac{-a}{1+a}$$

since

\begin{align*}
a * a^{-1} &= a * \frac{-a}{1+a} \\
&= a + \frac{-a}{1+a} + \frac{-a^2}{1+a} \\
&= \frac{a + a^2}{1+a} - \frac{a + a^2}{1+a} \\
&= 0
\end{align*}

and $a \neq -1$.

Consider

\begin{align*}
(a * b) * c &= (a + b + ab) * c \\
&= a + b + ab + c + c (a + b + ab) \\
&= a + b + c + ab + ac + bc + abc \\
&= a + (b + c + bc) + (ab + ac + abc) \\
&= a + (b * c) + a (b * c) \\
&= a * (b * c).
\end{align*}

This shows associativity.

\section*{8}

Give an example of two elements $A$ and $B$ in $GL_2(\mathbb{R})$ with $AB \neq BA$.

\vspace{\baselineskip}

Consider

$$A=
  \begin{pmatrix}
    1 & 1 \\
    0 & 1
  \end{pmatrix}
  B=
  \begin{pmatrix}
    1 & 0 \\
    1 & 1
  \end{pmatrix}.
$$

Notice

$$AB =
  \begin{pmatrix}
    2 & 1 \\
    1 & 1
  \end{pmatrix}
$$

while

$$BA =
  \begin{pmatrix}
    1 & 1 \\
    1 & 2
  \end{pmatrix}
$$

\section*{9}

Prove that the product of two matrices in $SL_2(\mathbb{R})$ has determinant one.

\vspace{\baselineskip}

Let $A,B \in SL_2(\mathbb{R})$. This follows from the basic property of determinants

$$\det (AB) = \det(A) \det(B) = 1 \cdot 1 = 1.$$

\section*{10}

Prove that the set of matrices of the form
$$
  \begin{pmatrix}
    1 & x & y \\
    0 & 1 & z \\
    0 & 0 & 1
  \end{pmatrix}
$$

is a group under matrix multiplication. This group, known as the \textit{Heisenburg group}, is important in quantum physics. Matrix multiplication in the Heisenberg group is defined by

$$
  \begin{pmatrix}
    1 & x & y \\
    0 & 1 & z \\
    0 & 0 & 1
  \end{pmatrix}
  \begin{pmatrix}
    1 & x' & y' \\
    0 & 1 & z' \\
    0 & 0 & 1
  \end{pmatrix}
=
  \begin{pmatrix}
    1 & x + x' & y + y'+ xz' \\
    0 & 1 & z + z' \\
    0 & 0 & 1
  \end{pmatrix}
$$

The proof that this set of matrices forms a group is straightforward. Associativity follows from the associativity of matrix multiplication. The identity element is the usual identity matrix. Each matrix in the set is upper triangular and has an inverse (if this is not obvious, then the matrices can be easily put in reduced row echelon form).

\section*{11}

Prove that $\det(AB) = det(A)det(B)$ in $GL_2(\mathbb{R})$ Use this result to show that the binary operation in the group $GL_2(\mathbb{R})$ is closed; that is, if $A$ and $B$ are in $GL_2(\mathbb{R})$, then $AB \in GL_2(\mathbb{R})$.

\vspace{\baselineskip}

We already used this basic property of determinants in problem 9. We will prove it for $2 \times 2$ matrices here. Recall the definition of the determinant for a $2 \times 2$ matrix
$$A =
  \begin{pmatrix}
    a & b \\
    c & d \\
  \end{pmatrix}
$$

is given by $\det(A) = ad - bc$.

\vspace{\baselineskip}

Let $A,B$ be $2 \times 2$ matrices where

$$A =
  \begin{pmatrix}
    a & b \\
    c & d \\
  \end{pmatrix}
  B =
  \begin{pmatrix}
    a' & b' \\
    c' & d' \\
  \end{pmatrix}
$$

and

$$AB =
  \begin{pmatrix}
    aa' + bc' & ab' + bd'\\
    a'c + c'd & b'c + dd' \\
  \end{pmatrix}.
$$

Notice that

\begin{align*}
\det(AB) &= (aa' + bc')(b'c + dd') - (ab' + bd')(a'c + c'd) \\
&= aa'b'c + aa'dd' + bc'b'c + bc'dd' - ab'a'c - ab'c'd - bd'a'c - bd'c'd \\
&= (ad - bc) (a'd' - b'c') \\
&= \det(A) \det(B)
\end{align*}

\vspace{\baselineskip}

Let $C,D \in GL_2(\mathbb{R})$. Then $\det(C) \neq 0$ and $\det(D) \neq 0$. By the property proved above $\det{CD} = \det{C}\det{D}$. Since $\det{C} \neq 0$ and $\det{D} \neq 0$ we know that $\det{CD} \neq{0}$ hence $CD \in GL_2(\mathbb{R})$ and $GL_2(\mathbb{R})$ is closed.

\section*{12}

Let $\mathbb{Z}_2^n = \{ (a_1, a_2, ..., a_n) : a_i \in \mathbb{Z}_2 \}$ Define a binary operation on $\mathbb{Z}_2^n$ by

$$(a_1, a_2, ..., a_n) + (b_1, b_2, ..., b_n) = (a_1+b_1, a_2+b_2, ..., a_n+b_n).$$

Prove that $\mathbb{Z}_2^n$ is a group under this operation. This group is important in algebraic coding theory.

\vspace{\baselineskip}

Let $(a_1, a_2, ..., a_n), (b_1, b_2, ..., b_n), (c_1, c_2, ..., c_n) \in \mathbb{Z}_2^n$. Notice that the identity is in $\mathbb{Z}_2^n$ since

$$(a_1, a_2, ..., a_n) + (0, 0, ..., 0) =  (a_1, a_2, ..., a_n).$$

Also note that each element has an inverse

$$(a_1, a_2, ..., a_n) + (-a_1, -a_2, ..., -a_n) = (0, 0, ..., 0).$$

Associativity follows from the associativity of modular arithmetic

\begin{align*}
((a_1, a_2, ..., a_n) + (b_1, b_2, ..., b_n)) + (c_1, c_2, ..., c_n) &= (a_1+b_1, a_2+b_2, ..., a_n+b_n) + (c_1, c_2, ..., c_n) \\
&= ((a_1+b_1) + c_1, (a_2+b_2) + c_2, ..., (a_n+b_n) + c_n) \\
&= (a_1 + (b_1+c_1), a_2 + (b_2+c_2), ..., (a_n + (b_n+c_n)) \\
&= (a_1, a_2, ..., a_n) + ((b_1, b_2, ..., b_n) + (c_1, c_2, ..., c_n)).
\end{align*}

\section*{13}

Show that $\mathbb{R}^{*} = \mathbb{R} \setminus \{ 0 \}$ is a group under the operation of multiplication.

\vspace{\baselineskip}

Let $x \in \mathbb{R}^{*}$. Notice that, since multiplication of two non-zero real numbers is non-zero,$\mathbb{R}^{*}$ is closed. Associativity follows from the associativity of the multiplication of real numbers. The identity is 1. Notice that $x^{-1} = \frac{1}{x}$ since

$$xx^{-1} = x \frac{1}{x} = 1.$$

Hence, $\mathbb{R}^*$ is a group

\section*{14}

Given the groups $\mathbb{R}^*$ and $\mathbb{Z}$ let $G = \mathbb{R} \times \mathbb{Z}$. Define a binary operation $\circ$ on $G$ by $(a,m) \circ (b,n) = (ab, m+n)$. Show that $G$ is a group under this operation.

\vspace{\baselineskip}

This proof is straightforward since the two contributing groups are operated on independently. Associativity follows from the associativity of $\mathbb{R}^*$ and $\mathbb{Z}$. The identity is $(1,0)$. The inverse of $(x, n) \in \mathbb{R}^* \times \mathbb{Z}$ is $(1/x, -n)$.

\section*{15}

The dihedral group of six elements is the smallest non-abelian group. Here is the Cayley table

\begin{tabular}{ l | l l l l l l }
  * & e & a & b & c & d & f \\
  \hline
  e & e & a & b & c & d & f \\
  a & a & e & d & f & b & c \\
  b & b & f & e & d & c & a \\
  c & c & d & f & e & a & b \\
  d & d & c & a & b & f & e \\
  f & f & b & c & a & e & d
\end{tabular}

\section*{16}

Give a specific example of some group $G$ and elements $g, h \in G$ where $(gh)^n \neq g^n h^n$.

\vspace{\baselineskip}

We need to find a group that is not abelian. Consider $GL_2(\mathbb{R})$. Let

$$A =
  \begin{pmatrix}
    1 & 2 \\
    3 & 2
  \end{pmatrix},
  B =
  \begin{pmatrix}
    2 & 1 \\
    2 & 3
  \end{pmatrix}.
$$

Notice that

$$A^{-1} =
  \begin{pmatrix}
    -1/2 & 1/2 \\
    3/4 & -1/4
  \end{pmatrix},
  B^{-1} =
  \begin{pmatrix}
    3/4 & -1/4 \\
    -1/2 & 1/2
  \end{pmatrix}
$$

so $A, B \in GL_2(\mathbb{R})$. Then notice that

$$A^n B^n = \begin{pmatrix}
    102 & 101 \\
    154 & 155
  \end{pmatrix} \neq
    \begin{pmatrix}
    106 & 105 \\
    150 & 151
  \end{pmatrix} = (AB)^n.$$

\section*{18}

Show that there are $n!$ permutations of a set containing $n$ items.

\vspace{\baselineskip}

Consider a permutation of a set as a reordering. For the first element of the reordering there are $n$ options, for the second element there are $n-1$ options, ..., for the $n-1$th element there are 2 options, and for the $n$th element there is 1 option. Hence there are $n(n-1) ... (2)(1) = n!$ permutations of a set with $n$ elements.

\section*{24}

Let $a$ and $B$ be elements in a group $G$. Prove that $ab^na^{-1} = (aba^{-1})^n$ for $n \in \mathbb{Z}$.

\vspace{\baselineskip}

Consider

$$ab^na^{-1} = a b ... b  a^{-1} = a  b a^{-1} a ... a^{-1} a b a^{-1} = (aba^{-1})^n.$$

\section*{25}

Let $U(n)$ be the group of units in $\mathbb{Z}_n$. If $n > 2$, prove that there is an element $k \in U(n)$ such that $k^2 = 1$ and $k \neq 1$.

\vspace{\baselineskip}

Let $n > 2$. There are two parts to the proof. First we will show that $U(n)$ has an even number of elements. Then we will show that if a group has an even number of elements there is $g$ in the group such that $g^2 = e$.

\vspace{\baselineskip}

Recall that for each $x \in \mathbb{Z}_n x \neq 0$ that $x \in U(n)$ if $\gcd(k,n) = 1$. This means that the number of elements in $U(n)$ is given by $\phi(n)$ where $\phi$ is Euler's totient function. Note that for $n > 2$ that $\phi$ is even (see comment below for sketch of proof).

\vspace{\baselineskip}

We use a similar argument to prove the second statement. Assume that a group $G$ has an even number of elements. We can pair each element $g \in G$ with its inverse. Note that $e = e^{-1}$ isn't paired with any other element. Since $G$ has an even number of elements there must be one other element, $a$, such that $a^2 = e$.

\vspace{\baselineskip}

Note that $\phi(mn) = \phi(m) \phi(n)$ and that if $p$ is prime then $\phi(p) = p-1$. Combining these facts and the Fundamental Theorem of Arithmetic yields the desired statement.

\section*{26}

Prove that the inverse of $g1 g2 ... g_n$ is $g_n^{-1} g_{n-1}^{-1} ... g_1^{-1}$.

\vspace{\baselineskip}

Consider

\begin{align*}
(g1 g2 ... g_{n-1} g_n) (g_n^{-1} g_{n-1}^{-1} ... g_2^{-1} g_1^{-1}) &= g1 g2 ... g_{n-1} g_{n-1}^{-1} ... g_2^{-1} g_1^{-1} \\
\vdots \\
&= g_1 g_2 g_2^{-1} g_1^{-1} \\
&= g_1 g_1^{-1} \\
&= e.
\end{align*}

\section*{27}

Prove the remainder of Proposition 3.6: if $G$ is a group and $a,b \in G$, then the equation $xa = b$ has unique solutions in $G$.

\vspace{\baselineskip}

Assume that $xa = b$ has more than one solution. Call two solutions $x_1, x_2$. Note that

\begin{align*}
x_1 a &= b \\
x_1 a a^{-1} &= b a^{-1} \\
x_1 &= b a^{-1}
\end{align*}

and

\begin{align*}
x_2 a &= b \\
x_2 a a^{-1} &= b a^{-1} \\
x_2 &= b a^{-1}
\end{align*}

Then, since the group operation is well-defined $x_1 = x_2$, a contradiction. This proves that solutions to $xa = b$ in $G$ are unique.

\section*{28}

Prove Theorem 3.8. In a group, the usual laws of exponents hold; that is, for all $g, h \in G$,

$$g^m g^n = g^{m+n} \text{ for all } m,n \in \mathbb{Z};$$
$$(g^m)^n = g^{mn} \text{ for all } m,n \in \mathbb{Z};$$
$$(gh)^n = (h^{-1} g^{-1})^{-n} \text{ for all } n \in \mathbb{Z}$$

Furthermore, if $G$ is abelian, then $(gh)^n = g^n h^n$.

\vspace{\baselineskip}

To prove the first statement, notice that (we will index for clarity where $g_i = g$)

$$g^m g^n = g_1 g_2 ... g_m g_1 ... g_n =  g^{m+n}.$$

To prove the second statement consider

$$(g^m)^n = g^m ... g^m.$$

From the first statement it follows that

$$(g^m ... g^m = g^{m+...+m} = g^{mn}.$$

To prove the second statement first note that

$$gh = (h^{-1} g^{-1})^{-1}.$$

It follows from the second statement that

$$(gh)^n = ((h^{-1} g^{-1})^{-1})^n = (h^{-1} g^{-1})^{-n}.$$

Assume $G$ is abelian. Consider

$$(gh)^n = gh .. gh = g...g h...h = g^n h^n.$$

\section*{29}

Prove the right and left cancellation laws for a group $G$; that is , show that in the group $G$, $ba = ca$ implies $b = c$ and $ab = ac$ implies $b = c$ for elements $a,b,c \in G$.

\vspace{\baselineskip}

This is a straightforward application of the existence of inverses in a  group.

Consider

\begin{align*}
ba &= ca \\
baa^{-1} &= caa^{-1} \\
be &= ce \\
b &= c
\end{align*}

\begin{align*}
ab &= ac \\
a^{-1}ab &= a^{-1}ac \\
eb &= ec \\
b &= c
\end{align*}

\section*{30}

Show that if $a^2 = e$ for all elements $a$ in a group $G$, then $G$ must be abelian

\vspace{\baselineskip}

Let $a,b \in G$. Consider

$$(ab)(ab) = e = (aa)(bb)$$
$$abab = aabb$$
$$ ba = ab.$$

\section*{31}

Show that if $G$ is a finite group of even order, then there is an $a \in G$ such that $a$ is not the identity and $a^2 = e$.

\vspace{\baselineskip}

Assume that a group $G$ has an even number of elements. We can pair each element $g \in G$ with its inverse. Note that $e = e^{-1}$ isn't paired with any other element. Since $G$ has an even number of elements there must be one other element, $a$, such that $a^2 = e$.

\section*{32}

Let $G$ be a group and suppose that $(ab)^2 = a^2b^2$ for all $a$ and $b$ in $G$. Prove that $G$ is an abelian group.

\vspace{\baselineskip}

Consider

$$(ab)^2 = a^2b^2$$

$$abab = aa bb$$

multiplying on the left by $a^{-1}$ yields

$$bab = abb$$

and multiplying on the left by $b^{-1}$ yields

$$ba = ab.$$

Hence, $G$ is an abelian group.

\section*{41}

Let $G$ be the group of $2 \times 2$ matrices under addition and

$$ H = \left\{
  \begin{pmatrix}
    a & b \\
    c & d
  \end{pmatrix} : a + d = 0\right\}.
$$

Prove that $H$ is a subgroup of $G$.

\vspace{\baselineskip}

Note that the identity is in $H$ since $0 + 0 = 0$. Consider the sum of two matrices in H

$$\begin{pmatrix}
    a & b \\
    c & d
  \end{pmatrix}
  +
  \begin{pmatrix}
    a' & b' \\
    c' & d'
  \end{pmatrix}
  =
  \begin{pmatrix}
    a + a' & b + b' \\
    c + c' & d + d'
  \end{pmatrix}.
$$

Note that since $a + a' + d + d' = 0$ we know that the sum of the matrices is also a member of $H$. Note that the inverse of a matrix $A \in H$ is given by $-A$. Let

$$A =
  \begin{pmatrix}
    a & b \\
    c & d
  \end{pmatrix}.
$$

Note that since $-a + -d = 0$ that $-A \in H$. This proves that $H$ is a subgroup of $G$.

\section*{44}

Prove that the intersection of two subgroups of a group $G$ is also a subgroup of $G$

\vspace{\baselineskip}

Let $H$ and $K$ be subgroups of $G$. Note that since $H$ and $K$ are subgroups, the identity element is in both and hence the identity is in $H \cap K$. Let $x,y \in H \cap K$. Note that $xy \in H$ since $x,y \in H$ and similarly $xy \in K$ since $x,y \in K$. Therefore, $xy \in H \cap K$. Note that $x^{-1} \in H$ since $x \in H$ and $x^{-1} \in K$ since $x \in K$. Therefore, $x^{-1} \in H \cap K$. This shows that $H \cap K$ is a subgroup of $G$.

\section*{45}

Prove or disprove: if $H$ and $K$ are subgroups of a group $G$, then $H \cup K$ is a subgroup of $G$.

\vspace{\baselineskip}

Consider the following counterexample. Note that $2\mathbb{Z}$ and $3\mathbb{Z}$ are both subgroups of $\mathbb{Z}$ under addition. It is clear that $2\mathbb{Z} \cup 3\mathbb{Z}$ is not a subgroup of $\mathbb{Z}$ because it is not closed under addition. For example $2,3 \in 2\mathbb{Z} \cup 3\mathbb{Z}$ but their sum $5 \not\in 2\mathbb{Z} \cup 3\mathbb{Z}$

\section*{48}

Let $a$ and $b$ be elements of a group $G$. If $a^4b = ba$ and $a^3 = e$, prove that $ab = ba$.

\vspace{\baselineskip}

Consider

\begin{align*}
ba &= a^4b \\
&= a^3 ab \\
&= ab.
\end{align*}

\section*{49}

Note that this is a duplicate of problem 48.

Let $a$ and $b$ be elements of a group $G$. If $a^4b = ba$ and $a^3 = e$, prove that $ab = ba$.
\vspace{\baselineskip}

Consider

\begin{align*}
ba &= a^4b \\
&= a^3 ab \\
&= ab.
\end{align*}

\section*{51}

If $xy = x^{-1} y^{-1}$ for all $x$ and $y$ in $G$, prove that $G$ must be abelian.

\vspace{\baselineskip}

Note

$$x = xe = x^{-1}e = x^{-1}.$$

Consider

$$xy = (xy)^{-1} = y^{-1} x^{-1} = yx.$$

\section*{54}

Let $H$ be a subgroup of $G$. If $g \in G$, show that $gHg^{-1} = \{ghg^{-1}: h \in H \}$ is also a subgroup of $G$.

\vspace{\baselineskip}

Let $g \in G$ and $h_1, h_2 \in H$. Notice that $e = geg^{-1}$ and hence $e \in gHg^{-1}$. Notice that $gHg^{-1}$ is closed since $gh_1g^{-1} g h_2 g^{-1} = g h_1 h_2 g^{-1}$ and $H$ is closed. Note that $g h_1 g^{-1} g h_1^{-1} g^{-1} = e$. Hence, for all $x \in H$ $x^{-1} \in H$ as well. This proves that $gHg^{-1}$ is a subgroup of $G$.

\end{document}


% ===============================================================================
\documentclass[a4paper]{article}
%\documentclass{sig-alternate}
\usepackage{amssymb,amsmath}
\usepackage[margin=0.5in]{geometry}

\newcommand{\I}{\mathbb{I}}
\renewcommand{\vec}[1]{\mathbf{#1}}
\newcommand{\Sim}{\mathrm{Sim}}
\newcommand{\ExpNCall}[1]{\text{Exp-}#1\text{-Call@}k}
\newcommand{\TlessK}{T_{\!\!\:k\text{-}1}}
\def\argmax{\operatornamewithlimits{\!arg \;\! max\,}}

% ===============================================================================
\begin{document}

% ===============================================================================
\appendix
\section{Full derivation}
\subsection{Optimizing objective}
We want to choose $S_k^*$ that maximizes the objective:
\begin{align*}
  \ExpNCall{n}(S_k,\vec{q})
  = \mathbb{E}[R_k\geq n|s_1,\dots,s_k,\vec{q}]
\end{align*}

\noindent
By taking a greedy approach, we select $s_k^*$ given $S_{k-1}^*$:
\begin{align}
  s_k^* & = \argmax_{s_k} \mathbb{E}[R_k\geq n|S_{k-1}^*,s_k,\vec{q}] \nonumber\\
%
  & = \argmax_{s_k} P(R_k\geq n|S_{k-1}^*,s_k,\vec{q}) \label{note1}\\
%
  & = \argmax_{s_k} \!\sum_{T_k} \Bigl( P(t|\vec{q}) \,P(t_k|s_k) \Bigl( \prod_{i=1}^{k-1} P(t_i|s_i^*) \Bigr) \cdot P(R_k\geq n|T_k,S_{k-1}^*,s_k,\vec{q}) \Bigr) \label{note2}\\
%
  & = \argmax_{s_k} \!\sum_{T_k} P(t|\vec{q}) \,P(t_k|s_k) \Bigl( \prod_{i=1}^{k-1} P(t_i|s_i^*) \Bigr) \cdot \Bigl( \mbox{$\underbrace{P(r_k\!\geq\!0|R_{k-\!1}\!\geq\!n,t_k,t)}_{1}$} P(\!R_{k-\!1}\!\geq\!n|\TlessK) \nonumber \\[-1.5mm]
  & \hspace{55mm} + P(r_k=1|R_{k-1}\!=\!n\!-\!1,t_k,t) P(\!R_{k-\!1}\!=\!n\!-\!1|\TlessK) \Big) \label{note3}\\
%
  & = \argmax_{s_k} \Bigg( \sum_{\TlessK} \bigg[ \mbox{$\underbrace{ \!\sum_{t_k} \!\!P(t_k|s_k) }_{1}$} \bigg] P(t|\vec{q}) \Bigl( \prod_{i=1}^{k-1} P(t_i|s_i^*) \Bigr) P(R_{\!k-\!1}\geq\!n|\TlessK) + \nonumber \\[-1.5mm]
  & \hspace{20mm} \sum_{\TlessK} \bigg[ \sum_{t_k} P(t_k|s_k) P(r_k=1|t_k,t) \bigg] P(t|\vec{q}) \Bigl( \prod_{i=1}^{k-1} P(t_i|s_i^*) \Bigr) P(\!R_{k-\!1}\!=\!n\!-\!1|\TlessK) \Bigg) \nonumber\\
%
  & = \argmax_{s_k} \sum_{t} P(t|\vec{q}) P(t_k\!=\!t|s_k) \bigg[ \sum_{t_1, \dots, t_{k-1}}  P(R_{k-\!1}\!=\!n\!-\!1|\TlessK) \prod_{i=1}^{k-1} P(t_i|s_i^*) \bigg] \label{note4}\\
%
  & = \argmax_{s_k} \sum_{t} \!P(t|\vec{q}) P(t_k\!=\!t|s_k) P(R_{k-\!1}\!=\!n\!-\!1|S_{k-1}^*) \label{eq.ncall}
\end{align}

\noindent
Note: \\
(1) Since $( R_k \geq n )$ can only be zero or one in probability. \\
(2) Marginalize out $T_k$. \\
(3) Split $( R_k \geq n )$ into two disjoint events $(r_k \! \geq \! 0, R_{k\!-\!1}\!\geq \!n)$, $(r_k\!=\!1, R_{k\!-\!1}\!=\!n\!-\!1)$, conditioned on $R_{k-1}$. \\
(4) Drop the first line as it does not involve $s_k$ and has no influence in determining $s_k^*$. \\
Note that $\sum_{t_k} \!\! P(t_k|s_k) P(r_k\!\!=\!\!1|t_k,t) = \sum_{t_k} \!\! P(t_k|s_k) \I[t_k\!=\!t] \! = \! P(t_k\!\!=\!\!t|s_k)$, where $t$ is implicitly conditioned and is not explicitly shown here. \\
(5) This objective is recursively defined. \\

By similar reasoning, the probability needed in~\eqref{eq.ncall} is recursively defined as
\begin{align*}
P(R_k=n|S_k,t)=
\begin{cases}
n \geq 1, k > 1:  &  \bigl( 1\!-\!P(t_k\!=\!t|s_k) \bigr) P(R_{k-1}\!=\!n|S_{k-1},t) \nonumber \\
  & \hspace{5mm} + P(t_k\!=\!t|s_k) P(R_{k-\!1}\!=\!n\!-\!1|S_{k-\!1},t) \\
%%
n = 0, k > 1:   & \bigl( 1\!-\!P(t_k\!=\!t|s_k) \bigr) P(R_{k-\!1}\!=\!0|S_{k-\!1},t) \\
%%
n = 1, k = 1:   & P(t_1\!=\!t|s_1) \\
n = 0, k = 1:   & 1 - P(t_1\!=\!t|s_1)
\end{cases}
%       \bigl 1-P(t_1\!=\!t|s_1) \bigr) = \bigl 1-P(t_1\!=\!t|s_1) \bigr) \\
%  & \hspace{2mm} P(R_1\!=\!1|S_1,t) = P(t_1\!=\!t|s_1)
\end{align*}

For expected $n$-call@$k$ where $n \! \leq \! k/2$, by unrolling its recursive definition in \eqref{eq.ncall}, the explicit objective is
\begin{align}
  & s_k^* = \argmax_{s_k} \sum_t \Biggl( P(t|\vec{q}) \, P(t_k=t|s_k) \sum_{j_1, \dots, j_{n-\!1}} \hspace{-14mm} \prod_{\hspace{14.5mm} l \in \{j_1, \dots, j_{n-\!1}\}} \hspace{-14mm} P(t_l\!=\!t|s_l^*) \hspace{-13mm} \prod_{\substack{i=1 \\ \hspace{14mm} i \notin \{j_1, \dots, j_{n-\!1}\}}}^{k-1} \hspace{-13mm} \!\bigl( 1 - P(t_i\!=\!t|s_i^*) \bigr) \!\Biggr) \label{eq.ncall.alt}
\end{align}
where $j_1, \dots, j_{n-1} \in \{1,\ldots,k-1\}$ satisfy
that $j_i < j_{i+1}$ (i.e.,
an ordered permutation of $n-1$ result set indices). \\

Similarly, for expected $n$-call@$k$ where $n \! > \! k/2$, the explicit objective is
\begin{align}
  & s_k^* = \argmax_{s_k} \sum_t \Biggl( P(t|\vec{q}) \, P(t_k=t|s_k) \sum_{j_n, \dots, j_{k-\!1}} \hspace{-14mm} \prod_{\hspace{14.5mm} l \in \{j_n, \dots, j_{k-\!1}\}} \hspace{-14mm} \bigl(1 - P(t_l\!=\!t|s_l^*) \bigr) \hspace{-13mm} \prod_{\substack{i=1 \\ \hspace{14mm} i \notin \{j_n, \dots, j_{k-\!1}\}}}^{k-1} \hspace{-13mm} P(t_i\!=\!t|s_i^*) \!\Biggr) \label{eq.ncall.alt2}
\end{align}
where $j_n, \dots, j_{k-1} \in \{1,\ldots,k-1\}$ satisfy
that $j_i < j_{i+1}$ (i.e.,
an ordered permutation of $k-n$ result set indices).

% ===============================================================================
\subsection{Relation to MMR: expected n-call@k when $n>k/2$}

Assuming that $\forall i \; P(t_i|s_i) \in \{0,1\}$ and $P(t|\vec{q}) \in \{0,1\}$. It is possible to write
\begin{align*}
  \hspace{-13mm} \prod_{\hspace{14.5mm} l \in \{j_n, \dots, j_{k-\!1}\}} \hspace{-14mm} \bigl( 1 - \!P(t_l\!=\!t|s_l^*) \bigr)
  = 1 - \Biggl( 1 - \hspace{-14mm} \prod_{\hspace{14.5mm} l \in \{j_n, \dots, j_{k-\!1}\}} \hspace{-13mm} \bigl( 1 - P(t_l\!=\!t|s_l^*) \bigr) \Biggr)
  = 1 - \Bigl( \max_{l \in \{j_n, \dots, j_{k-\!1}\}} P(t_l\!=\!t|s_l^*) \Bigr)
\end{align*}

This allows us to rewrite~\eqref{eq.ncall.alt2}
\begin{align}
 & s_k^* = \, \argmax_{s_k} \sum_t \Biggl( P(t|\vec{q}) P(t_k\!=\!t|s_k)  \sum_{\hspace{-1mm} j_n, \dots, j_{k-\!1}} \hspace{-13.5mm} \prod_{\substack{i=1 \\ \hspace{14mm} i \notin \{j_n, \dots, j_{k-\!1}\}}}^{k-1} \hspace{-13mm} P(t_i\!=\!t|s_i^*) \nonumber \\[-1.5mm]
 & \hspace{25mm} - \!P(t|\vec{q}) P(t_k\!=\!t|s_k) \sum_{j_n, \dots, j_{k-\!1}} \hspace{-14mm} \prod_{\substack{i=1 \\ \hspace{14mm} i \notin \{j_n, \dots, j_{k-\!1}\}}}^{k-1} \hspace{-13mm} P(t_i\!=\!t|s_i^*) \max_{l \in \{j_n, \dots, j_{k-\!1}\}} P(t_l\!=\!t|s_l^*) \Biggr) \label{eq.ncall.alt3}
\end{align}

Assuming $m$ relevant documents are already selected in the $k-1$ collection, then the top term (specifically $\prod_i$) is non-zero $\binom{m}{n-1}$ times.  For the
bottom term, it takes $n-1$ relevant documents to satisfy its
$\prod_i$, and one additional relevant document to satisfy the
$\max_l$ making it non-zero $\binom{m}{n}$ times.  Factoring out the
$\max$ element from the bottom and pushing the $\sum_t$ inwards (all legal
due to the $\{0,1\}$ subtopic probability assumption),~\eqref{eq.ncall.alt3} becomes
\begin{align}
 s_k^* & = \argmax_{s_k} \left[ \sum_t P(t|\vec{q}) P(t_k\!=\!t|s_k) \binom{m}{n-1} \right]
 - \left[ \sum_t P(t|\vec{q}) P(t_k\!=\!t|s_k) \binom{m}{n} \underbrace{\max_{s_i \in S_{k-1}^*} P(t_i\!=\!t|s_i)}_{1} \right] \nonumber\\
 & = \argmax_{s_k} \binom{m}{n-1} \underbrace{\sum_t P(t|\vec{q}) P(t_k\!=\!t|s_k)}_{\textrm{relevance}: \; \Sim_1(s_k,\vec{q})}
 - \binom{m}{n} \max_{s_i \in S_{k-1}^*} \underbrace{\sum_t P(t_i\!=\!t|s_i) \!P(t|\vec{q}) P(t_k\!=\!t|s_k)}_{\textrm{diversity}: \; \Sim_2(s_k,s_i,\vec{q})} \label{note9}\\
 & = \argmax_{s_k} \!\! \frac{n}{m\!+\!1} \Sim_1(s_k,\vec{q}) - \frac{m\!-\!n\!+\!1}{m+1} \max_{s_i \in S_{k-1}^*} \! \Sim_2(s_k,s_i,\vec{q}) \label{note10}
\end{align}

\noindent
Note: \\
(9) We can rearrange "$\sum_t P(t|\vec{q}) \max_{s_i} \cdots$" as "$\max_{s_i} \sum_t P(t|\vec{q}) \cdots$" since the $\sum_t P(t|\vec{q})$ 'selects' the only $t$ for which $P(t|\vec{q}) = 1$. \\
(10) Normalize by dividing the equation by $\binom{m}{n-1} + \binom{m}{n} = \binom{m+1}{n}$ (Pascal's rule). \\
The result is the same as the case where $n \leq k/2$. \\

The reason that we do not remove the max term in~\eqref{note9} is that this allows us to compare the objective with MMR directly. Also, leaving the max term suggests an approximate form for the case where the subtopic probabilities are non-deterministic (not strictly 0 or 1), and approaches~\eqref{note9} as the probabilities become more deterministic. \\

In practice, under the greedy approach of the expected n-call@k in selecting $S_k^*$, we expect that there are already $n$ relevant documents chosen in the set $S_{k-1}^* = \{s_1^*, \dots, s_{k-1}^*\}$ (where $n << k$). In expectation, $m = n$ and hence the optimizing objective can be thought to be
\begin{align}
 s_k^* = \argmax_{s_k} \!\! \frac{n}{n\!+\!1} \Sim_1(s_k,\vec{q}) - \frac{1}{n+1} \max_{s_i \in S_{k-1}^*} \! \Sim_2(s_k,s_i,\vec{q}) \label{eq.ncall.final}
\end{align}

From~\eqref{eq.ncall.final}, it is simple to see that the diversification level decreases with $n$.

% ===============================================================================
\section{Additional derivation}
\subsection{Alternative derivation for expected 2-call@k}

\begin{align*}
  s_k^* & = \argmax_{s_k} \mathbb{E} \!\left[ R_k \geq 2 \left| S_{k-1}^*, s_k, \vec{q} \right.\right] \\
%%
  & = \argmax_{s_k} \mathbb{E} \!\Bigg[ (r_1=1 \wedge r_2=1) \vee (r_1=0 \wedge r_2=1 \wedge r_3=1) \vee (r_1=1 \wedge r_2=0 \wedge r_3=1) \,\vee \\
  & \hspace{21.7mm} (r_1=0 \wedge r_2=0 \wedge r_3=1 \wedge r_4=1) \vee (r_1=0 \wedge r_2=1 \wedge r_3=0 \wedge r_4=1) \,\vee \\
  & \hspace{21.7mm} (r_1=1 \wedge r_2=0 \wedge r_3=0 \wedge r_4=1) \vee \dots \vee \\
  & \hspace{21.7mm} (r_1=0 \wedge \dots \wedge r_{k-2}=0 \wedge r_{k-1}=1 \wedge r_k=1) \,\vee \\
  & \hspace{21.7mm} (r_1=0 \wedge \dots \wedge r_{k-3}=0 \wedge r_{k-2}=1 \wedge r_{k-1} = 0 \wedge r_k=1) \vee \dots \vee \\
  & \hspace{21.7mm} (r_1=1 \wedge r_2=0 \wedge \dots \wedge r_{k-1}=0 \wedge r_k=1) \Bigg| S_{k-1}^*, s_k, \vec{q} \,\Bigg] \\
%%
  & = \argmax_{s_k} \mathbb{E} \!\Bigg[ (r_1=1 \wedge r_2=1) \vee (r_1=0 \wedge r_2=1 \wedge r_3=1) \vee (r_1=1 \wedge r_2=0 \wedge r_3=1) \,\vee \\
  & \hspace{21.7mm} (r_1=0 \wedge r_2=0 \wedge r_3=1 \wedge r_4=1) \vee (r_1=0 \wedge r_2=1 \wedge r_3=0 \wedge r_4=1) \,\vee \\
  & \hspace{21.7mm} (r_1=1 \wedge r_2=0 \wedge r_3=0 \wedge r_4=1) \vee \dots \vee \\
  & \hspace{21.7mm} \left.\left. \bigvee_{j=1}^{k-1} \left( r_k=1 \wedge \bigwedge_{\substack{i=1 \\ i \neq j}}^{k-1} r_i=0 \wedge r_j=1 \right) \right| S_{k-1}^*, s_k, \vec{q} \,\right] \\
%%
  & = \argmax_{s_k} \sum_{j=1}^{k-1} P \!\!\left(\left. r_k=1 \wedge \bigwedge_{\substack{i=1 \\ i \neq j}}^{k-1} r_i=0 \wedge r_j=1 \right| S_{k-1}^*, s_k, \vec{q} \,\right) \\
  & = \argmax_{s_k} \sum_{j=1}^{k-1} \left( \sum_{t_1, \dots, t_k, t} P(t|\vec{q}) \, P(t_k|s_k) \mathbb{I} [t_k=t] \, P(t_j|s_j^*) \mathbb{I} [t_j=t] \prod_{\substack{i=1 \\ i \neq j}}^{k-1} P(t_i|s_i^*) \mathbb{I} [t_i \neq t] \right) \\
  & = \argmax_{s_k} \sum_t P(t|\vec{q}) \, P(t_k=t|s_k) \sum_{j=1}^{k-1} \left( P(t_j=t|s_j^*) \prod_{\substack{i=1 \\ i \neq j}}^{k-1} \left( 1 - P \! \left( t_i=t|s_i^* \right) \right) \right)
\end{align*}

\noindent
Assuming that $\forall i \; P(t_i|s_i) \in \{0,1\}$ and $P(t|\vec{q}) \in \{0,1\}$, the objective becomes:
\begin{align}
  s_k^* & = \argmax_{s_k} \sum_t P(t|\vec{q}) \, P(t_k = t | s_k) \sum_{j=1}^{k-1} \left( P(t_j=t|s_j^*) \prod_{\substack{i=1 \\ i \neq j}}^{k-1} \left( 1 - P \! \left( t_i=t|s_i^* \right) \right) \right) \nonumber \\
  & = \argmax_{s_k} \sum_t P(t|\vec{q}) \, P(t_k = t | s_k) \sum_{j=1}^{k-1} \left( P(t_j=t|s_j^*) \left[ 1 - \left( 1 - \prod_{\substack{i=1 \\ i \neq j}}^{k-1} \left( 1 - P \! \left( t_i=t|s_i^* \right) \right) \right) \right] \right) \nonumber \\
  & = \argmax_{s_k} \sum_t P(t|\vec{q}) \, P(t_k = t | s_k) \sum_{j=1}^{k-1} \left[ P \! \left( t_j=t|s_j^* \right) - P \! \left( t_j=t|s_j^* \right) \left( 1 - \prod_{\substack{i=1 \\ i \neq j}}^{k-1} \left( 1 - P \! \left( t_i=t|s_i^* \right) \right) \right) \right] \nonumber \\
%%
  & = \argmax_{s_k} \sum_t P(t|\vec{q}) \, P(t_k = t | s_k) \sum_{j=1}^{k-1} P(t_j=t|s_j^*) \nonumber \\
  & \hspace{10mm} - \sum_t P(t|\vec{q}) \, P(t_k = t | s_k) \sum_{j=1}^{k-1} P(t_j=t|s_j^*) \max_{\substack{ i \in [1, k-1] \\ i \neq j}} P(t_i=t|s_i^*) \nonumber
\end{align}

\noindent
Noting that this is of the same form as~\eqref{eq.ncall.alt3}, albeit much simpler.

\end{document}


\section{Methodology}

    \frame{\sectionpage}

    \begin{frame}{Presentation of the econometric model}
\par The model to be generated in this research is based on Ramon A. Castillo's analysis of changes in the macroeconomic environment, where he applies the study of the determinants of remittances and the effects of the sending and receiving or receiving countries.\par

\textbf{Vector Autoregressive Model (VAR).}\par
The VAR or also called multivariate models originate in the eighties with (Sims, 1980), which raises \textit{"the importance of the dynamic relationships of economic phenomena at the macroeconomic level, subsistence of structural models, where there is a simultaneity between economic variables"}.\par
VAR models have proven to be useful in empirical research analysis, when there is evidence of simultaneity between a group of variables, and that their relationships are transmitted over a given period. In addition, "that one of the advantages of these models is that, by not imposing any restriction on the structural version of the model, specification errors are not incurred that may cause empirical work." (Pérez, 2008). A VAR model captures the dynamic interactions of a set of K time series variables.\par

\textbf{Error Correction Model (VEC).}\par
VEC models, unlike VARs, are characterized by containing cointegrated variables, that is:\par
\textit{“Variables that have a long-term equilibrium relationship between them, in which the analysis has been refined, since it includes both the dynamics of adjustment of the variables in the short term, when an unexpected shock occurs that causes another to temporarily move away of its long-term equilibrium relationship, such as the reestablishment of the equilibrium relationship in the long term, the information it provides on the speed of adjustment towards such equilibrium is quite useful; therefore they provide more information than VARs”} (Eilyn and Torres, 2004).\par
If the variables are stationary, it is possible to proceed with the estimation of a VAR model. On the other hand, if the variables are stationary in difference and have a cointegration relationship, then a specification problem is generated in the VAR model, and a VEC must be continued.\par

\textbf{Stationarity and order of integration.}\par
•	The first step in the analysis of the time series is to verify its stationarity. A time series is said to be stationary if it meets the following characteristics.\par
•	Its mean is constant over time.\par
•	Its variance is also constant over time.\par

 \begin{equation}
 var(Y_{t} = E[(Y_{t}-u_{y})^2]=	\sigma^2
 \end{equation}

•	The covariance of order k is not related to time and the distance between the observations is the same.\par

  \begin{equation}
 \gamma_{k}=E[(Y_{t}-u_{y})(Y_{t+k}-u_{y})]
 \end{equation}

This is due to the fact that if a time series does not satisfy the previous characteristics, it is non-stationary. When we speak of an integrated time series, it is a non-stationary series, so the order of integration is the number of times the series has to be differentiated to reach stationarity.\par
When it is not necessary to obtain first differences for the stochastic process to be called zero-order integrated. A non-stationary series, it is necessary to differentiate it so that it is, if it only differs once and stationarity is reached, it is integrated of order one. In general, the order of integration I(d) suggests the number of times they had to apply for the process to be considered stationary.\par
An integrated process I(d) is known as a process that has a unit root, in which differentiation is used to make it stationary. In order to have a formal certainty to define the order of integration of a variable, statistical tests are used to detect the presence of a unit root, which proves the existence of a unit root, such as the Augmented Dickey Fuller and Phillips- Perron.\par
\end{frame}

    \frame{\sectionpage}
    \begin{frame}{Econometric technique to use}

\textbf{Johansen Cointegration Test:}\par
The peculiarity of this method is that it allows more than one cointegration relation in a system of variables. This test can be performed in two different approaches, with eigenvalues or with trace. When cointegration relationships are tested, the VEC model is estimated, the method of which is based on the Johansen methodology, and the steps to follow for said methodology are listed below.\par
\begin{enumerate}
\item Estimate a VAR in levels with the endogenous variables.
\item The optimal number of lags is chosen in the estimation of the VAR. In this sense (Cuevas, 2010) asserts that \textit{“the length of the lag is decisive, because the behavior of the residuals and the empirical results are sensitive to the order of the model (number, of lags selected), as it can cause specification problems".}
\end{enumerate}
\textbf{Information Criteria.}\par
The most used criteria are:\par
• \textbf{Akaike Information Criteria} (AIC):\par
 \begin{equation}
 AIC = Tln|S_{h}(p)|+2pn
 \end{equation}
• \textbf{Schwartz Information Criteria} (SIC):\par
  \begin{equation}
 SIC = Tln|S_{h}(p)|+(pn^2)lnT
 \end{equation}
• \textbf{Hannan-Quinn} (HQ):\par
   \begin{equation}
 HQ(n) = log\sigma^2_{u}(n)+\frac{2logT}{T}n
 \end{equation}
Where:\par
p = number of lags\par
n = number of equations\par
T = number of observations\par
\textbf{Diagnostic tests.}\par
\begin{enumerate}
\item Apply the tests to the residuals to the VAR model. After determining the optimal number of lags for the model, the next step is to run a series of diagnostic tests that determine that the model does not have statistical problems that invalidate the estimation results.\par
\begin{enumerate}
\item The autocorrelation in the residuals suggests that: \textit{“the model is a poor representation of the generated process and that some other representation can be found including variables, lags in the model, extending the time period or getting other data”} (Lutkepohl and Kratzig, 2004). The test most used to test autocorrelation is LM, whose null hypothesis (H0) to be tested is: no serial correlation in the lag of order p.\par
\item. Another test that is essential to evaluate the diagnosis of the model is the absence of heteroscedasticity (non-constant variance) in the residuals. The hypotheses to be tested are\par
\begin{center}
\textbf{H0}: The residuals are homoscedastic \par
\textbf{H1}: The residuals are heteroscedastic.\par
\end{center}
\item Another of the diagnostic tests for the verification of VAR processes refers to the normality of the waste, using the Jarque-Bera test. The hypotheses of this test are the following:\par

\begin{equation}
 H_{0} : E(u_{t}^s)^3 = 0
  \end{equation}
  \begin{equation}
 H_{1} : E(u_{t}^s)^3 \neq 0
 \end{equation}

The null hypothesis is rejected based on the value of the probability JB, given the level of significance with which one works, for example, with a significance level of 5 percent, the null hypothesis will not be rejected if the probability is higher than 0.05, therefore, there is a normal distribution in the residuals.\par
\end{enumerate}
\item At the selected VAR in levels, the cointegration test is applied (minus one to the optimal lag). The particularity of this method is that it allows more than one cointegration relationship in a system of variables. This test can be performed in two different approaches, with eigenvalues or with trace.\par
\end{enumerate}
\end{frame}

    \frame{\sectionpage}
    \begin{frame}{Description of the databases}
The data to be used are focused on the period from January 1996 to December 2019 for the variables presented in the following section. In the same way, the dichotomous variables created for the structural changes that occurred over time are explained.\par
First, the remittances sent are shown in their tiered series:\par
As can be seen in the previous series, there is an accelerated rebound from the first quarter of 2003 until achieving a small stabilization, hence a decrease in the fourth quarter of 2009 to reach the acceleration that we have observed in recent years.  Second, the Gross Domestic Product of Mexico is shown in levels:\par
	In the previous series, the upward trend can be observed from 1996 to 2009, where economic growth is affected by the world economic crisis of that year. The following is the Gross Domestic Product of the United States in levels:\par
The trend is similar to that of Mexico's GDP, but in a smoother way, however, the structural change is noticeable due to the economic crisis of 2009.  Finally, it is shown at the Real Exchange Rate between the Mexican Peso (MXN) and the United States Dollar (USD) in levels:\par
\end{frame}

    \frame{\sectionpage}
    \begin{frame}{Definition of the variables}
In the first place, as the dependent variable, Family Remittances were chosen in their entirety from the first quarter of 1996 to the fourth quarter of 2019. Said database is measured in millions of dollars and was obtained from the Economic Information System of the Banco de México.\par
Second, as an independent variable that represents the recipient country of remittance income, the Gross Domestic Product of Mexico was chosen. Said database is based on 2013 at constant prices and measured in millions of pesos. The data series was obtained from the Instituto Nacional de Estadística y Geografía.\par
Third, as an independent variable that represents the country that issued the remittances, the Gross Domestic Product of the United States was chosen. It is measured in millions of dollars at constant prices. The series was obtained from the Bureau of Economic Analysis. Finally, the Real Exchange Rate Index was taken as the result of the quotient between the exchange rate variations and the Price and Quotation Index with respect to hundred eleven countries. This database was obtained from the Economic Information System of Banco de México.\par
As mentioned in previous sections, the period ranges from the first quarter of 1996 to the fourth quarter of 2019\footnote{Accumulating a total of 96 observations for each variable.} . At the time of analyzing the data series, eight dichotomous variables were elaborated that were taken as exogenous to control the structural changes that occurred over time. \par
In the case of Remittances, the following variables were elaborated:\par
\begin{itemize}
\item \textbf{DREMESASMI:} In the first quarter of 2003, as it was the quarter where the expansion of the domestic market in the country began and there was a decrease in inflation.\par
\item \textbf{DREMESASREC:} In the fourth quarter of 2009 due to the global economic and financial recession that spanned from 2008 to 2009.\par

 Within the Mexican GDP variable, the following variable was elaborated:\par

\item	\textbf{DPIBMEXREC:} In the first quarter of 2009, due to the global economic and financial recession that spanned from 2008 to 2009.\par

 Within the United States GDP variable, the following variable was elaborated:\par

\item \textbf{DPIBEUAREC:} In the second quarter of 2009, due to the global economic and financial recession that spanned from 2008 to 2009.\par

And within the Real Exchange Rate variable, the following variables were elaborated:\par

\item \textbf{DTCREALIG:} In the second quarter of 2002, due to the increase in imports by farmers in the United States and the increase in prices.\par
\item \textbf{DTCREALEST:} In the fourth quarter of 2004, since there was a slight stabilization from that year until 2007.\par
\item \textbf{DTCREALFD:} In the fourth quarter of 2014 due to the strengthening of the US dollar and there was an impact on emerging markets.\par
\item \textbf{DTCREALPP:} In the fourth quarter of 2016, due to the adjustment of oil prices.
 \end{itemize}
\end{frame}


    \filetitle{lognormal}{Characteristics of log-normal distributions returned by filter of forecast}{model/lognormal}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
D = lognormal(M,D,...)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{M} {[} model {]} - Model on which the \texttt{filter} or
  \texttt{forecast} function has been run.
\item
  \texttt{D} {[} struct {]} - Struct or database returned from the
  \texttt{filter} or \texttt{forecast} function.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{D} {[} struct {]} - Struct including new sub-databases with
  requested log-normal statistics.
\end{itemize}

\paragraph{Options}\label{options}

\begin{itemize}
\item
  \texttt{'fresh='} {[} \texttt{true} \textbar{} \emph{\texttt{false}}
  {]} - Output structure will include only the newly computed databases.
\item
  \texttt{'mean='} {[} \emph{\texttt{true}} \textbar{} \texttt{false}
  {]} - Compute the mean of the log-normal distributions.
\item
  \texttt{'median='} {[} \emph{\texttt{true}} \textbar{} \texttt{false}
  {]} - Compute the median of the log-normal distributions.
\item
  \texttt{'mode='} {[} \emph{\texttt{true}} \textbar{} \texttt{false}
  {]} - Compute the mode of the log-normal distributions.
\item
  \texttt{'prctile='} {[} numeric \textbar{} \emph{{[}5,95{]}} {]} -
  Compute the selected percentiles of the log-normal distributions.
\item
  \texttt{'prefix='} {[} char \textbar{} \emph{`lognormal'} {]} - Prefix
  used in the names of the newly created databases.
\item
  \texttt{'std='} {[} \emph{\texttt{true}} \textbar{} \texttt{false} {]}
  - Compute the std deviations of the log-normal distributions.
\end{itemize}

\paragraph{Description}\label{description}


\section{Conventions}
\label{sec:conventions}

Italic is used for scalars and vectors: {\em{$p$}}, $q$.
It is easy to distinguish which are which by context.
Bold maths is used for rank 2 tensors:
$\tenrtwo{I}$,
$\tenrtwo{R}$,
$\tenrtwo{\sigma}$.
Script is used for rank 4 tensors:
$\tenrfour{C}$.

`$\cdot$' denotes dot product, single contraction:
$x^s=\mathbold{R}^c \cdot x^c$.

`:' denotes double product, double contraction:
$\tenrtwo{\sigma} = \tenrfour{C} : \tenrtwo{\epsilon}$.

`$\otimes$' denotes tensor product:
$\mathbold{I}\otimes\mathbold{I}=
\delta_{ij}\delta_{kl}$.

\subsection{Space coarray}
\label{sec:space:coarray}

The space coarray is the centre part of the whole
library.
The idea is that 3D space is partitioned into identical
cells of some sort.
The cells are used to store and update some physically
relevant properties.
An important consideration is how many properties can
a cell store.
At present the coarray is defined as shown in
Eqn. \eqref{eq:coarray}:

\begin{equation}
\texttt{
coarray(l1:u1,l2:u2,l3:u3,props)[col1:cou1,col2:cou2,col3:*]
}
\label{eq:coarray}
\end{equation}
%
where \texttt{l1}\ldots\texttt{u3}
are the lower and the upper
spatial bounds of the array, counted in cells;
\texttt{props} is the number of properties a cell should
hold; \texttt{col1}\ldots\texttt{col3} are the lower
and the upper cobounds of the coarray.
Note that the last codimension is never specified,
i.e. it is always left as an asterix, \texttt{*}, to
allow for different number of images at runtime.

A typical definition of the coarray might look like

\begin{equation}
\texttt{
coarray(1:10,1:10,1:10,2)[1:8,1:8,1:*]
}
\nonumber
\end{equation}
%
which, when run on 512 images, will have the final
codimension of 8.
This array has 2 cell state types, which can be e.g.
the (unique) grain number, and a possible fracture state.

The library has two state types defined:
\texttt{cgca\_state\_type\_grain} for grain states,
i.e. grain numbers, and
\texttt{cgca\_state\_type\_frac} for fracture states.
So \texttt{coarray(:,:,:,cgca\_state\_type\_grain)} is
the local grain array, and
\texttt{coarray(:,:,:,cgca\_state\_type\_frac)} is
the local fracture array.

\subsection{Cellular neighbourhood}

We use a square 3D cellular array.
This means that a cell has a
$3 \times 3 \times 3 - 1 = 26$
cell nearest neighbourhood.
There are a number of problems with such
neighbourhood.
Not all neighbouring cells are `equal'.
If one imagines a $3\times 3 \times 3$ cube
of cubic cells, then the central cell will
have 6 neighbours sharing a face with it,
12 neighbours sharing an edge and 8 neighbours
sharing an edge.
More importantly, there are
three distinct angles between the pairs of the
nearest neighbourhood vectors, i.e. vectors
connecting the centres of the central cell,
and of each neighbouring cell \cite{shterenlikht2013c}.

Perhaps a better idea of a neighbourhood can
be constructed by imagining the central cell
as a 26-faced polyhedra.
Examples are rhombicuboctahedron or
pseudo-rhombicuboctahedron, also called
elongated square gyrobicupola, Johnson solid
J37, see Fig. \ref{fig:j37}.

\begin{figure}
\begin{tabular}{cc}
\includegraphics[width=0.4\textwidth]{octa.jpg}
&
\includegraphics[width=0.4\textwidth]{gyro.png}
\\
(a) & (b)
\end{tabular}
\caption{
26-face polyhedra: (a) Rhombicuboctahedron, an Archimedian
solid, (b) Elongated square gyrobicupola, or
pseudo-rhombicuboctahedron, Johnson solid, J37.
From: http://en.wikipedia.org/wiki/Rhombicuboctahedron and
http://en.wikipedia.org/wiki/Elongated\_square\_gyrobicupola.
}
\label{fig:j37}
\end{figure}

Importantly, the cell state is determined
by the states of its neighbours, not the
other way round.
This helps develop a parallel model using
halo arrays.