\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}


\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.


\documentclass[./Thesis.tex]{subfiles}
\begin{document}

\chapter{Termination}
\label{chap:termination}

\epigraph{
  What can be asserted without evidence can also be dismissed without evidence.
}{Christopher Hitchens \cite{hitchens-quote}}

\begin{code}[hide]
  module Termination where
  open import Relation.Nullary using (¬_)
  open import Relation.Nullary.Decidable using (False)
  open import Relation.Nullary.Negation using (contradiction)
  open import Data.Empty using (⊥)
  open import AKS.Nat using (ℕ; zero; suc; _∸_; _*_; _<_; _≤_; lte; _≟_)
  open import AKS.Nat using (+-comm; suc-injective-≡; n≮0; 0≤n; n<1+n; ≤-refl) renaming (n≤m⇒n<m⊎n≡m to n≤m⇒n<m∨n≡m)
  open import Data.Sum using () renaming (inj₁ to or₁; inj₂ to or₂)
  open import AKS.Binary using (𝔹⁺)
  open 𝔹⁺
  open import AKS.Nat.Divisibility using (_div_; Euclidean; Euclidean✓)
  open Euclidean using () renaming (q to quotient)
  open import Relation.Binary.PropositionalEquality
    using (_≡_; _≢_; module ≡-Reasoning)
    renaming (refl to ≡-refl; sym to ≡-sym; cong to ≡-cong; cong₂ to ≡-cong₂)
  open ≡-Reasoning
  open import Data.Unit using (tt)
  open import Polynomial.Simple.AlmostCommutativeRing.Instances using (module Nat)
  open import Polynomial.Simple.Reflection using (solve)
  open Nat.Reflection using (∀⟨_⟩)
  open import Data.List using ([]; _∷_; List)
  open import Function using (_$_)
  open import AKS.Unsafe using (BOTTOM)
\end{code} % $
\section{A Correctness Interlude}
\label{sec:a-correctness-interlude}
The previous chapter omitted a critical flaw in its analysis. The code below is
rejected by the \Agda{} compiler. The compiler's \textit{termination checker} \cite{agda}
fails as \Agda{} can not infer that the result of non-zero integer division by
$2$ always returns an integer strictly smaller than the input. The termination
checker ensures than every function is total. In other words,
the termination checker disallows infinite loops. This termination proof
is obvious but termination proofs can quickly become complex. In general checking
termination, commonly called the halting problem, is undecidable.
\begin{code}[hide]
  module Bad₁ where
    {-# TERMINATING #-}
\end{code}
\begin{code}
    ⟦_⇑⟧⁺ : ∀ (n : ℕ) {≢0 : False (n ≟ 0)} → 𝔹⁺
    ⟦ suc n ⇑⟧⁺ with suc n div 2
    ... | Euclidean✓ (suc q) 0 _ _ = ⟦ suc q ⇑⟧⁺ 0ᵇ
    ... | Euclidean✓ zero    1 _ _ = 𝕓1ᵇ
    ... | Euclidean✓ (suc q) 1 _ _ = ⟦ suc q ⇑⟧⁺ 1ᵇ
\end{code}
This checker is a keystone of the correctness of the logic of \Agda{}. Consider
the following function with a similar call graph. Instead of the input
decreasing to some base case it doubles with every recursive call. This function can
be used to prove falsehood, thus a logic with unconstrained recursion is
inconsistent.
\begin{code}[hide]
  module Bad₂ where
    {-# TERMINATING #-}
\end{code}
\begin{code}
    increasing : ℕ → ⊥
    increasing n with 2 * n
    ... | q = increasing q

    false : ⊥
    false = increasing 0
\end{code}
In fact, the example above can be simplified in the code below. In English
this code expresses the famous fallacy of circular reasoning ``false is true
because false is true''.
\begin{code}[hide]
  module Bad₃ where
    {-# TERMINATING #-}
\end{code}
\begin{code}
    false : ⊥
    false = false
\end{code}
Thankfully none of these false expressions are accepted by the \Agda{} compiler.
This begs the question how does \Agda{} determine which recursive functions to
accept? Unfortunately the \Agda{} compiler can not solve the halting problem so
it must be restrictive. The compiler only accepts recursive
calls that are \textit{structurally decreasing}, a small
subset of the set of recursive functions. A recursive call is structurally
decreasing if the call occurs on a strict sub expression \cite{agda}. The
expression $\AgdaInductiveConstructor{suc} \, n$ is a strict sub-expression of
$\AgdaInductiveConstructor{suc} \,
  (\AgdaInductiveConstructor{suc} \,
    (\AgdaInductiveConstructor{suc} \, n))
$,
but $\AgdaInductiveConstructor{suc} \, n$ is not a strict sub-expression of
$\AgdaInductiveConstructor{suc} \, n$.
Addition, our first example of recursion, is acceptable as
$n <_{sub} \AgdaInductiveConstructor{suc} \, n$.
\begin{code}[hide]
  module Add where
\end{code}
\begin{code}
    _+_ : ℕ → ℕ → ℕ
    zero + m = m
    (suc n) + m = suc (n + m)
\end{code}
\begin{code}[hide]
  open import AKS.Nat using (_+_)
\end{code}
The following inductive definition of the Fibonacci function
has structurally decreasing calls as
$\AgdaInductiveConstructor{suc} \, n <_{sub} \AgdaInductiveConstructor{suc} \, (\AgdaInductiveConstructor{suc} \, n)$
and
$n <_{sub} \AgdaInductiveConstructor{suc} \, (\AgdaInductiveConstructor{suc} \, n)$.
\begin{code}
  fib : ℕ → ℕ
  fib zero = 0
  fib (suc zero) = 1
  fib (suc (suc n)) = fib (suc n) + fib n
\end{code}
So far all the recursive functions described have been
\textit{primitive recursive} \cite{soare}. This is a large class, but the set of
structurally decreasing functions is larger than the set of primitive
recursive functions. The Ackerrmann function is the canonical example of
function which is not primitive recursive.
\begin{code}
  ack : ℕ → ℕ → ℕ
  ack zero m = suc m
  ack (suc n) zero = ack n (suc zero)
  ack (suc n) (suc m) = ack n (ack (suc n) m)
\end{code}
\Agda{} accepts this definition as the recursive
calls are decreasing lexicographically.
The recursive call in the second case decreases in the first argument so
the second argument increasing is acceptable
$
(n, \, \AgdaInductiveConstructor{suc} \, \AgdaInductiveConstructor{zero})
<_{sub}
(\AgdaInductiveConstructor{suc} \, n, \, \AgdaInductiveConstructor{zero})
$.
For a similar reason the outer call in the third case is acceptable
$
(n, \, \AgdaFunction{ack} \, (\AgdaInductiveConstructor{suc} \, n) \, m)
<_{sub}
(\AgdaInductiveConstructor{suc} \, n, \, \AgdaInductiveConstructor{suc} \, m)
$.
The inner call is acceptable as the second argument decreases while the first
stays constant, this is lexicographic order
$
(\AgdaInductiveConstructor{suc} \, n, \, m)
<_{sub}
(\AgdaInductiveConstructor{suc} \, n, \, \AgdaInductiveConstructor{suc} \, m)
$. \\
\section{Well-Founded Relations}
\label{sec:well-founded-relations}
An astute reader may have noticed a pattern. \Agda{} accepts your recursive
definition if it can infer a structural \textit{well-founded relation}
\cite{soare}. A well-founded relation is a binary relation $\prec$ that has no
infinitely descending chains $\dots \prec x_k \prec \dots \prec x_1 \prec x_0$.
For instance the strict ordering over the naturals is well-founded
as every chain will eventually reach $0$.
\begin{align}
  \label{eqn:wellfounded-natural}
  0 < 1 < 2 < 3 < 4 < 5
\end{align}
The non-strict ordering is not well-founded as an infinite chain of the
reflexivity axiom can be constructed.
\begin{align}
  \label{eqn:non-wellfounded-natural}
  \dots \leq 0 \leq \dots \leq 0 \leq 0
\end{align}
Unfortunately, these relation chains do not capture the full structure of well-founded
relations. A well-founded relation often has multiple elements that could be
appended to the chain. This idea is illustrated in the well-founded tree
rooted at 3 found in figure \ref{fig:wellfounded-tree}.
\begin{figure}[h]
  \centering
  \begin{tikzpicture}
    \Tree
    [.3
      {$0 < 3$}
      [.{$1 < 3$}
        {$0 < 1$}
      ]
      [.{$2 < 3$}
        {$0 < 2$}
        [.{$1 < 2$}
          {$0 < 1$}
        ]
      ]
    ]
  \end{tikzpicture}
  \caption{A well-founded tree }
  \label{fig:wellfounded-tree}
\end{figure}
These trees encapsulate the full structure of a well-ordering relation.
Therefore, if we could express this tree as an \Agda{} datatype, we could supply
our own well-ordering relation even when \Agda{} can not infer it. The final
datatype that represents well-founded trees is somewhat puzzling at first
glance. So to introduce it we start with a sensible datatype and make small
changes to the definition until we have reached the correct representation.
These trees are general trees, trees that can have an arbitrary number
of children. They are often called rose trees in functional programming
literature. They make for a good starting datatype.
\begin{code}[hide]
  module Tree₁ where
\end{code}
\begin{code}
    data RoseTree : Set where
      Node : List RoseTree → RoseTree
\end{code}
We then apply a \textit{continuation passing style} \cite{harper} transformation to the
recursive call. Instead of having a list of children we have a continuation that
can be invoked with the index of the requested child.
\begin{code}[hide]
  module Tree₂ where
\end{code}
\begin{code}
    data RoseTree : Set where
      Node : (ℕ → RoseTree) → RoseTree
\end{code}
Unfortunately, this makes our definition unusable as now every rose tree must have
infinite size. From a \textit{game theotertic} perspective, a consumer may request
the first child of every node repetitively.
\begin{code}
    rosetree-uninhabited : RoseTree → ⊥
    rosetree-uninhabited (Node children) = rosetree-uninhabited (children 0)
\end{code}
Any well founded tree is necessarily finite as each node always has a finite
number of children ``less'' than itself. We can solve this by adding an upper
bound and ensuring that any index is less than the bound.
\begin{code}[hide]
  module Tree₃ where
\end{code}
\begin{code}
    data RoseTree (bound : ℕ) : Set where
      Node : (∀ {lower : ℕ} → lower < bound → RoseTree lower)
           → RoseTree bound
\end{code}
Note that the definition above does not make use of any properties specific to
natural numbers. The definition simply requires a binary relation.
By parameterizing the datatype by the relation we
arrive at our finial definition. This is often called the accessibility
predicate so we update the names accordingly.
\begin{code}
  data Acc {A : Set} (_≺_ : A → A → Set) (bound : A) : Set where
    acc : (∀ {lower : A} → lower ≺ bound → Acc _≺_ lower)
        → Acc _≺_ bound
\end{code}
Continuing with the game theoretic analysis proving a relation is well-founded
for a specific bound is a simple game. A game where the prover
continually asks for a lower bound and wins when it is impossible for the
other player to supply a lower bound. This game plays out below for a bound of $3$.
\begin{code}
  3-well-founded : Acc _<_ 3
  3-well-founded = acc λ l₁<3 → acc λ l₂<l₁ → acc λ l₃<l₂ → acc λ l₄<l₃ →
    contradiction l₄<l₃ (end l₁<3 l₂<l₁ l₃<l₂)
\end{code}
\begin{code}[hide]
    where
\end{code}
\begin{code}
    end : ∀ {l₁ l₂ l₃ l₄} → l₁ < 3 → l₂ < l₁ → l₃ < l₂ → ¬ (l₄ < l₃)
    end {2} {1} {0} {l₄} l₁<3 l₂<l₁ l₃<l₂ l₄<l₃ = contradiction l₄<l₃ n≮0
\end{code}
\section{Win Every Game}
\label{sec:win-every-game}
Now we turn to proving that any natural forms a rooted well-founded tree under the
strict ordering relation. Usually proving a property holds for any $n$ is harder
then proving that property holds for specific $n$. This concept applies to
proving that every natural is well-founded. Specifically our choice of
less than relation is poorly suited for this task. We will define an inductive
ordering relation and show that our original definition of ordering is a
subrelation of the inductive-definition. Then if the inductive definition is
well-founded the subrelation will be as well. This last idea is shown below.
\begin{code}[hide]
  module Sub₁ where
\end{code}
\begin{code}
    subrelation
        : ∀ {A : Set} {_≺₁_ _≺₂_ : A → A → Set} {n}
        → (∀ {a b} → a ≺₂ b → a ≺₁ b)
        → Acc _≺₁_ n
        → Acc _≺₂_ n
    subrelation ≺₂⇒≺₁ (acc down) =
      acc λ x≺₂n → subrelation ≺₂⇒≺₁ (down (≺₂⇒≺₁ x≺₂n))
\end{code}
Next we turn to the inductive ordering relation. The key idea behind this
definition is that each $\AgdaInductiveConstructor{≤-step}$ constructor adds one
to the right bound. The base case is the reflexivity axiom so the number of
$\AgdaInductiveConstructor{≤-step}$ constructors is the distance between the
left and right bound. The old definition internalizes this concept into the
definition as the $k$ in
$a \, \AgdaDatatype{≤} \, b = a \, \AgdaFunction{+} \, k \, \AgdaDatatype{≡} \, b$.
\begin{code}
    data _≤ⁱ_ (n : ℕ) (m : ℕ) : Set where
      ≤-same : n ≡ m → n ≤ⁱ m
      ≤-step : ∀ {o} → suc o ≡ m → n ≤ⁱ o → n ≤ⁱ m

    _<ⁱ_ : ℕ → ℕ → Set
    n <ⁱ m = suc n ≤ⁱ m

    2≤ⁱ4 : 2 ≤ⁱ 4
    2≤ⁱ4 = ≤-step {o = 3} ≡-refl (≤-step {o = 2} ≡-refl (≤-same ≡-refl))
\end{code}
This concept also hints at how to show that the old definition is a subrelation
of the inductive definition. Count $k$ down to $0$ adding a
$\AgdaInductiveConstructor{≤-step}$. We first transform
$a \, \AgdaFunction{+} \, k \, \AgdaDatatype{≡} \, b$ into
$k \, \AgdaFunction{+} \, a \, \AgdaDatatype{≡} \, b$ as $\AgdaFunction{\_+\_}$
is defined on the first argument. So it can simplify terms like
$0 \, \AgdaFunction{+} \, a$ into $a$ automatically.
\begin{code}
    ≤⇒≤ⁱ : ∀ {a b} → a ≤ b → a ≤ⁱ b
    ≤⇒≤ⁱ {a} {b} (lte k a+k≡b) = loop a b k $ begin
      k + a ≡⟨ +-comm k a ⟩ a + k ≡⟨ a+k≡b ⟩ b ∎
      where
      loop : ∀ a b k → k + a ≡ b → a ≤ⁱ b
      loop a b zero 0+a≡b = ≤-same $ begin
        a ≡⟨⟩ 0 + a ≡⟨ 0+a≡b ⟩ b ∎
      loop a (suc b) (suc k) 1+k+a≡1+b = ≤-step ≡-refl $ loop a b k $ begin
        k + a ≡⟨ suc-injective-≡ 1+k+a≡1+b ⟩ b ∎
\end{code}
\begin{code}
    <⇒<ⁱ : ∀ {a b} → a < b → a <ⁱ b
    <⇒<ⁱ {a} {b} a<b = ≤⇒≤ⁱ {suc a} {b} a<b
\end{code}
Next we need to prove that any natural forms a rooted well-founded tree under
the inductively defined ordering. This requires a set of mutually recursive
functions.
\begin{code}
    <ⁱ-well-founded : ∀ {n} → Acc _<ⁱ_ n
    <ⁱ-count-down : ∀ {m n} → m <ⁱ n → Acc _<ⁱ_ m
\end{code}
The first accepts the ``player'' supplied proof that some number $m$
is less than the bound. Then the second function counts $n$ down to $m$ until
they are equal. Then it asks the player for a proof that there is some number
smaller than $m$. Note that every case in $\AgdaFunction{<ⁱ-count-down}$ peals
off exactly one $\AgdaFunction{suc}$ so \Agda{} is able to infer that the
functions are structurally decreasing.
\begin{code}
    <ⁱ-well-founded {n} = acc (λ x<ⁱn → <ⁱ-count-down x<ⁱn)
    <ⁱ-count-down {m} {suc .m} (≤-same ≡-refl) = <ⁱ-well-founded {m}
    <ⁱ-count-down {m} {suc n} (≤-step ≡-refl m≤n) = <ⁱ-count-down {m} {n} m≤n
\end{code}
Lastly we bring all the puzzle pieces together and prove that our original
definition of ordering is well founded.
\begin{code}
    <-well-founded : ∀ {n} → Acc _<_ n
    <-well-founded {n} = subrelation <⇒<ⁱ <ⁱ-well-founded
\end{code}
\begin{code}[hide]
  open Sub₁ using (<-well-founded)
\end{code}
\section{Lie No More}
\label{sec:lie-no-more}
Now we can return to our function that upcasts a natural number to a binary
encoded number. In order to use the mechanism developed above we must first
prove a lemma that integer division by $2$ is strictly less than the input.
Thankfully this lemma is simple enough for an automated ring solver to prove.
\begin{code}
  div-< : ∀ n q r {q≢0 : False (q ≟ 0)} → n ≡ r + 2 * q → q < n
\end{code}
\begin{code}[hide]
  div-< n (suc q) r ≡-refl = lte (q + r) (∀⟨ q ∷ r ∷ [] ⟩)
\end{code}
Next we define a helper function that has an accessibility predicate on the
input. Eventually we lose the game as $\Floor{1 / 2} = 0$ and we can not call
the helper function on $0$ by assumption. Thankfully this lines up perfectly
with our desired base case.
\begin{code}
  ⟦_,_⇑⟧ʰ : ∀ (n : ℕ) (acc : Acc _<_ n) {≢0 : False (n ≟ 0)} → 𝔹⁺
  ⟦ suc n , acc down ⇑⟧ʰ with suc n div 2
  ... | Euclidean✓ (suc q) 0 pf _ = ⟦ suc q , down (div-< (suc n) (suc q) 0 pf) ⇑⟧ʰ 0ᵇ
  ... | Euclidean✓ zero    1 _ _ = 𝕓1ᵇ
  ... | Euclidean✓ (suc q) 1 pf _ = ⟦ suc q , down (div-< (suc n) (suc q) 1 pf) ⇑⟧ʰ 1ᵇ

  ⟦_⇑⟧⁺ : ∀ (n : ℕ) {≢0 : False (n ≟ 0)} → 𝔹⁺
  ⟦ suc n ⇑⟧⁺ = ⟦ suc n , <-well-founded ⇑⟧ʰ
\end{code}
\section{Binary Search}
\label{sec:binary-search}
Consider the following binary search for the value $10$ in the array
$
\rowarrowsep=-2pt
\begin{gmatrix}[b]
  1 & 5 & 8 & 10 & 11 & 20
\end{gmatrix}
$ depicted in equation \ref{eqn:binary-search}. The search starts with the bounds of the entire array
$\textcolor{blue}{[} 0, 5 \textcolor{blue}{]}$.
Then it updates the interval to the left half of the array
$\textcolor{green}{[} 3, 5 \textcolor{green}{]}$.
It finally narrows in on the correct answer the interval
$\textcolor{red}{[} 3, 3 \textcolor{red}{]}$.
As with all the examples described in this chapter this
algorithm terminates because the intervals are decreasing under a well-founded
relation, strict interval inclusion.
\begin{align}
  \label{eqn:binary-search}
  \begin{gmatrix}[b]
    \hspace{0.4em} \Line{blue} &
    1 &
    5 &
    8 &
    \Line{green} \hspace{0.4em} \Line{red} &
    10 &
    \Line{red} &
    11 &
    20 &
    \Line{green} \hspace{0.4em} \Line{blue} \hspace{0.4em}
  \end{gmatrix}
\end{align}
An interval $i_2$ strictly includes
an interval $i_1$ if $i_1$ is a proper subset of $i_2$. If the set is finite
then this relation is clearly well founded. Unfortunately working with sets is
tricky in a type theory. So we limit our definition of an
interval to sets of naturals. Then our intervals are uniquely represented by
their \textit{infimum} (lower bound) and \textit{supremum} (upper bound).
\begin{code}
  record Interval : Set where
    constructor [_,_∣_]
    field
      inf : ℕ
      sup : ℕ
      inf≤sup : inf ≤ sup
  open Interval
\end{code}
Now we have two bounds to manipulate so there are two possible ways to create an
interval smaller than another. Firstly to lower the supremum and secondly to
raise the infimum.
\begin{code}
  data _⊂_ (i₁ : Interval) (i₂ : Interval) : Set where
    downward : inf i₂ ≤ inf i₁ → sup i₁ < sup i₂ → i₁ ⊂ i₂
    upward : inf i₂ < inf i₁ → sup i₁ ≤ sup i₂ → i₁ ⊂ i₂
\end{code}
Often authors prove termination for their binary search algorithm by instead
thinking about how the distance between the left and right bound decreases. We
adopt this technique to show that interval inclusion is a subrelation of
$\AgdaFunction{\_<\_}$. Although it is not technically a subrelation. It is a
subrelation generated by the function $\AgdaFunction{width}$.
\begin{code}
  width : Interval → ℕ
  width i = sup i ∸ inf i

  ⊂⇒< : ∀ {i₁ i₂} → i₁ ⊂ i₂ → width i₁ < width i₂
\end{code}
\begin{code}[hide]
  open import AKS.Unsafe using (trustMe)

  ∸-monoˡ-< : ∀ {l₁ h₁ l₂ h₂} → l₁ ≤ h₁ → l₂ ≤ h₂ → l₂ ≤ l₁ → h₁ < h₂ → h₁ ∸ l₁ < h₂ ∸ l₂
  ∸-monoˡ-< {l₁} {h₁} {l₂} {h₂} l₁≤h₁ l₂≤h₂ l₂≤l₁ h₁<h₂ = lte ((h₂ ∸ l₂) ∸ suc (h₁ ∸ l₁)) trustMe

  ∸-monoʳ-< : ∀ {l₁ h₁ l₂ h₂} → l₁ ≤ h₁ → l₂ ≤ h₂ → l₂ < l₁ → h₁ ≤ h₂ → h₁ ∸ l₁ < h₂ ∸ l₂
  ∸-monoʳ-< {l₁} {h₁} {l₂} {h₂} l₁≤h₁ l₂≤h₂ l₂<l₁ h₁≤h₂ = lte ((h₂ ∸ l₂) ∸ suc (h₁ ∸ l₁)) trustMe

  ⊂⇒< {[ inf-i₁ , sup-i₁ ∣ inf-i₁≤sup-i₁ ]} {[ inf-i₂ , sup-i₂ ∣ inf-i₂≤sup-i₂ ]} (downward inf-i₂≤inf-i₁ sup-i₁<sup-i₂)
    = ∸-monoˡ-< inf-i₁≤sup-i₁ inf-i₂≤sup-i₂ inf-i₂≤inf-i₁ sup-i₁<sup-i₂
  ⊂⇒< {[ inf-i₁ , sup-i₁ ∣ inf-i₁≤sup-i₁ ]} {[ inf-i₂ , sup-i₂ ∣ inf-i₂≤sup-i₂ ]} (upward inf-i₂<inf-i₁ sup-i₁≤sup-i₂)
    = ∸-monoʳ-< inf-i₁≤sup-i₁ inf-i₂≤sup-i₂ inf-i₂<inf-i₁ sup-i₁≤sup-i₂
  -- ⊂⇒< = BOTTOM
\end{code}
As the types of our elements are different we need to generalize
$\AgdaFunction{subrelation}$. We add a function to covert between the types.
Technically the function is a \textit{functor} \cite{awodey}
from the \textit{category} with $\AgdaFunction{\_≺₂\_}$ as morphisms to the
category with $\AgdaFunction{\_≺₁\_}$ as morphisms.
\begin{code}
  subrelation
      : ∀ {A : Set} {B : Set}
          {_≺₁_ : A → A → Set}
          {_≺₂_ : B → B → Set}
          {f : B → A}
          {n : B}
      → (∀ {x y} → x ≺₂ y → f x ≺₁ f y)
      → Acc _≺₁_ (f n)
      → Acc _≺₂_ n
\end{code}
\begin{code}[hide]
  subrelation ≺₂⇒≺₁ (acc down) =
    acc λ x≺₂n → subrelation ≺₂⇒≺₁ (down (≺₂⇒≺₁ x≺₂n))
\end{code}
Although we will not be implementing binary search in this thesis, this concept
will prove useful as it allows us to write terminating code that counts up to
some fixed value.
\begin{code}
  ⊂-well-founded : ∀ {i} → Acc _⊂_ i
  ⊂-well-founded = subrelation ⊂⇒< <-well-founded

  count-up-to : ℕ → List ℕ
  count-up-to n = loop 0 0≤n ⊂-well-founded
\end{code}
\begin{code}[hide]
    where
\end{code}
Counting up is simply always choosing to tighten the left bound of the interval.
Eventually the user reaches the upper bound and interval becomes $[ n, n ]$.
This interval can not be shortened and the recursion terminates as shown below.
\begin{code}
    loop : ∀ (x : ℕ) (x≤n : x ≤ n) (acc : Acc _⊂_ [ x , n ∣ x≤n ]) → List ℕ
    loop x x≤n (acc next) with n≤m⇒n<m∨n≡m x≤n
    ... | or₂ x≡n = x ∷ []
    ... | or₁ x<n = x ∷ loop (1 + x) x<n (next [1+x,n]⊂[x,n])
\end{code}
\begin{code}[hide]
      where
\end{code}
\begin{code}
      [1+x,n]⊂[x,n] : [ 1 + x , n ∣ x<n ] ⊂ [ x , n ∣ x≤n ]
      [1+x,n]⊂[x,n] = upward n<1+n ≤-refl
\end{code}
\begin{code}
  zero-to-three : count-up-to 3 ≡ 0 ∷ 1 ∷ 2 ∷ 3 ∷ []
  zero-to-three = ≡-refl
\end{code}

\end{document}


\section{Fermi break-up simulation for light nuclei.}

\hspace{1.0em}For light nuclei ($A \leq 16$) the values of excitation
energy per nucleon are often comparable with nucleon binding
energy. Thus a light excited nucleus breaks into two or more fragments
with branching given by available phase space.  To describe a process of
nuclear disassembling the so-called Fermi break-up model is used
\cite{Fermi50}, \cite{Kretz61}, \cite{EG67}.  This statistical approach
was first used by Fermi \cite{Fermi50} to describe the multiple
production in high energy nucleon collision.

The initial information for calculation of break-up stage consists from
the atomic mass number $A$, charge $Z$ and number of neutrons $N$ of
residual (e. g. after cascade or fission) nucleus and its excitation
energy $U$. The total energy of nucleus in the rest system will be
$E=U+M(A,Z)$.

\subsection{Masses of nuclei.}

\hspace{1.0em}The tabulated values (calculated according to the liquid drop
model) \cite{CAM57} of mass defects  $\Delta M(A,Z)$
are used to calculate the masses of nuclei $M(A,Z)$ in ground states.

\subsection{ Allowed channel.}

\hspace{1.0em}The channel will be allowed for decay, if the total
kinetic energy $E_{kin}$ of all fragments of the given channel at the
moment of break-up is positive. This energy can be calculated according
to equation:
\begin{equation}
\label{FBS1}E_{kin} = U+M(A,Z)-E_{Coulomb} - \sum_{b=1}^{n}(m_b+\epsilon_{b}),
\end{equation}
$m_{b}$ and $\epsilon_{b}$ are masses and excitation energies of fragments,
respectively, $E_{Coulomb}$ is the Coulomb barrier for the given channel. It
is approximated by
\begin{equation}
\label{FBS2}E_{Coulomb} = \frac{3}{5} \frac{e^2}{r_{0}}(1 +
\frac{V}{V_{0}})^{-1/3}
(\frac{Z^2}{A^{1/3}}-\sum_{b=1}^{n}\frac{Z^2}{A_b^{1/3}}),
\end{equation}
where $V_0$ is the volume of the system corresponding to the normal
nuclear matter density and $\kappa = \frac{V}{V_0}$ is a parameter (
$\kappa = 1$ is used).

\subsection{Break-up probability.}

\hspace{1.0em}The total  probability per unit time for nucleus to
break-up into $n$ componets in the final state (i.e. residual nucleus,
if it will be, nucleons, deutrons, tritons, alphas etc) is given by
\begin{equation}
\label{FBS3}W(E,n) = (V/\Omega)^{n-1}\rho_{n}(E),
\end{equation}
where $\rho_{n}(E)$ is the density of a number of final states, $V$ is
the volume of decaying system and $\Omega = (2\pi h)^{3}$ is the
normalization volume.  The density $\rho_{n}(E)$ can be defined a
product of three factors:
\begin{equation}
\label{FBS4}\rho_{n}(E)=M_{n}(E)S_nG_n.
\end{equation}
The first one is the phase space factor defined as
\begin{equation}
\label{FBS5}M_{n} = \int_{-\infty}^{+\infty}...\int_{-\infty}^{+\infty}
\delta(\sum_{b=1}^{n} {\bf p_{b}}) \delta(E-\sum_{b=1}^{n}\sqrt{p^2+m^2_b})
\prod_{b=1}^{n} d^3p_b,
\end{equation}
where ${\bf p_b}$ are fragments momenta. The second one is the spin
factor
\begin{equation}
\label{FBS6} S_n = \prod_{b=1}^{n}(2s_b+1),
\end{equation}
which gives the number of states with different spin orientations.  The
last one is the permutation factor
\begin{equation}
\label{FBS7}G_n = \prod_{j=1}^{k}\frac{1}{n_j !},
\end{equation}
which takes into account identity of components in final state ($n_j$ is
a number of components of $j$- type particles and $k$ is defined by $n =
\sum_{j=1}^{k}n_{j}$). E.g. if in final state we have $n = 6$ particles
and from them there are $2$-alphas, $3$-nucleons and $1$-deutrons, then
$G_{6} = 1/(2! 3! 1!) = 1/12$.

In non-relativistic case (Eq. ($\ref{FBS10}$) the integration in
Eq. ($\ref{FBS5}$) can be evaluated analiticaly (see e. g. \cite{BBB58})
and the probability for a nucleus with energy $E$ disassembling into $n$
fragments with masses $m_b$, where $b = 1,2,3,...,n$ equals
\begin{equation}
\label{FBS8} W(E_{kin},n) =
S_nG_n (\frac{V}{\Omega})^{n-1}(\frac{1}{\sum_{b=1}^{n}m_b}
\prod_{b=1}^{n}
m_{b})^{3/2}
 \frac{2\pi^{3(n-1)/2}}{\Gamma(3(n-1)/2)}E_{kin}^{3n/2-5/2},
\end{equation}
where $\Gamma(x)$ is the gamma function ($\Gamma(3(n-1)/2 =  (3(n-1)/2
- 1)!$).

\subsection{Fermi break-up model parameter.}

\hspace{1.0em}Thus the Fermi break-up model has only one free parameter
$V$ is the volume of decaying system, which can be calculated as
following:
\begin{equation}
\label{FBS9} V = 4\pi R^3/3 = 4\pi r_{0}^3 A/3,
\end{equation}
where $r_{0} = 1.4 $ fm is used.

\subsection{ Fragment characteristics.}

We take into account the formation of fragments in their ground and
low-lying excited states, which are stable for nucleon
emission. However, several unstable fragments with large lifetimes:
$^{5}He$, $^{5}Li$, $^{8}Be$, $^{9}B$ etc are also considered.  Fragment
characteristics $A_b$, $Z_b$, $s_b$ and $\epsilon_b$ are taken from
\cite{AS81}.

\subsection{ MC procedure.}

\hspace{1.0em}The nucleus break-up is described by the Monte Carlo (MC)
procedure. We randomly (according to probability Eq. ($\ref{FBS8}$) and
condition Eq. ($\ref{FBS1}$)) select decay channel. Then for given
channel we calculate kinematical quantities of each fragment according
to $n$-body phase space distribution:
\begin{equation}
\label{FBS10}M_{n} = \int_{-\infty}^{+\infty}...\int_{-\infty}^{+\infty}
\delta(\sum_{b=1}^{n} {\bf p_{b}}) \delta(\sum_{b=1}^{n}
\frac{p^2_b}{2m_b}-E_{kin})
\prod_{b=1}^{n} d^3p_b.
\end{equation}
The Kopylov's sampling procedure \cite{Kopylov70} is applied.  The angular
distributions for emitted fragments are considered as isotropical.

We take into account that the chargeless fragments are not affected by
Coulomb field. When fragment fly away to infinity its total kinetic
energy can be approximated by the sum of its translational motion and
the contribution to the energy erasing from its Coulomb repulsion.


\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[osf]{libertine}
\usepackage[scaled=0.8]{beramono}
\usepackage[margin=1.5in]{geometry}
\usepackage{url}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{nicefrac}
\usepackage{microtype}
\usepackage{subcaption}
\usepackage{bm}

\usepackage{sectsty}
\sectionfont{\large}
\subsectionfont{\normalsize}

\usepackage{titlesec}
\titlespacing{\section}{0pt}{10pt plus 2pt minus 2pt}{0pt plus 2pt minus 0pt}
\titlespacing{\subsection}{0pt}{5pt plus 2pt minus 2pt}{0pt plus 2pt minus 0pt}

\usepackage{pgfplots}
\pgfplotsset{
  compat=newest,
  plot coordinates/math parser=false,
  tick label style={font=\footnotesize, /pgf/number format/fixed},
  label style={font=\small},
  legend style={font=\small},
  every axis/.append style={
    tick align=outside,
    clip mode=individual,
    scaled ticks=false,
    thick,
    tick style={semithick, black}
  }
}

\pgfkeys{/pgf/number format/.cd, set thousands separator={\,}}

\usepgfplotslibrary{external}
\tikzexternalize[prefix=tikz/]

\newlength\figurewidth
\newlength\figureheight

\setlength{\figurewidth}{8cm}
\setlength{\figureheight}{6cm}

\newlength\squarefigurewidth
\newlength\squarefigureheight

\setlength{\squarefigurewidth}{4cm}
\setlength{\squarefigureheight}{4cm}

\newlength\smallsquarefigurewidth
\newlength\smallsquarefigureheight

\setlength{\smallsquarefigurewidth}{3.25cm}
\setlength{\smallsquarefigureheight}{3.25cm}

\newlength\smallfigurewidth
\newlength\smallfigureheight

\setlength{\smallfigurewidth}{6.25cm}
\setlength{\smallfigureheight}{4cm}

\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}

\newcommand{\acro}[1]{\textsc{\MakeLowercase{#1}}}
\newcommand{\given}{\mid}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\data}{\mc{D}}
\newcommand{\model}{\mc{M}}
\newcommand{\intd}[1]{\,\mathrm{d}{#1}}
\newcommand{\inv}{^{-1}}
\newcommand{\trans}{^\top}
\newcommand{\mat}[1]{\bm{\mathrm{#1}}}
\renewcommand{\vec}[1]{\bm{\mathrm{#1}}}
\newcommand{\R}{\mathbb{R}}
\renewcommand{\epsilon}{\varepsilon}

\DeclareMathOperator{\var}{var}
\DeclareMathOperator{\cov}{cov}
\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}

\begin{document}

\section*{Bayesian model selection}

Consider the regression problem, where we want to predict the values
of an unknown function $y\colon \R^d \to \R$ given examples $\data =
\bigl\{ (\vec{x}_i, y_i) \bigr\}_{i = 1}^N$ to serve as training data.
In Bayesian linear regression, we made the following assumption about
$y(\vec{x})$:
\begin{equation}
  y(\vec{x}) = \phi(\vec{x})\trans \vec{w} + \epsilon(\vec{x}),
\end{equation}
where $\phi(\vec{x})$ is a now explicitly-written feature expansion of
$\vec{x}$.  We proceed in the normal Bayesian way: we place Gaussian
priors on our unknowns, the parameters $\vec{w}$ and the residuals
$\vec{\epsilon}$, then derive the posterior distribution over
$\vec{w}$ given $\data$, which we use to make predictions.

One question left unanswered is how to choose a good feature expansion
function $\phi(\vec{x})$.  For example, a purely linear model could
use $\phi(\vec{x}) = [1, \vec{x}]\trans$, whereas a quadratic model
could use $\phi(\vec{x}) = [1, \vec{x}, \vec{x}^2]\trans$, etc.  In
general, arbitrary feature expansions $\phi$ are allowed.  How can I
select between them?  Even more generally, how do I select whether I
should use linear regression or a completely different probabilistic
model to explain my data?  These are questions of \emph{model
  selection,} and naturally there is a Bayesian approach to it.

Before we continue our discussion of model selection, we will first
define the word \emph{model,} which is often used loosely without
explicit definition.  A model is a parametric family of probability
distributions, each of which can explain the observed data.  Another
way to explain the concept of a model is that if we have chosen a
likelihood $p(\data \given \theta)$ for our data, which depends on a
parameter $\theta$, then the model is the set of all likelihoods (each
one of which is a distribution over $\data$) for every possible value
of the parameter $\theta$.

In the case of linear regression, the weight vector $\vec{w}$ defines
the parametric family, and the model is the set of distributions
\begin{equation*}
  \bigl\{ p(\vec{y} \given \mat{X}, \vec{w}, \sigma^2) \bigr\}
  =
  \bigl\{ \mc{N}(\vec{y}; \mat{X}\vec{w}, \sigma^2 \mat{I}) \bigr\},
\end{equation*}
indexed by all possible $\vec{w}$.  Each one of these is a potential
explanation of the observed values $\vec{y}$ given $\vec{X}$.  In the
case of flipping a coin $n$ times with an unknown bias $\theta$ and
observing the number of heads $x$, the model is
\begin{equation*}
  \bigl\{ p(x \given n, \theta) \bigr\}
  =
  \bigl\{ \mathrm{Binomial}(x, n, \theta) \bigr\},
\end{equation*}
where there is one binomial distribution for every possible $\theta
\in (0, 1)$.  In the Bayesian method, we maintain a belief over which
elements in the model we consider plausible by reasoning about
$p(\theta \given \data)$ via Bayes' theorem.

Suppose now that I have at my disposal a finite set of models
$\{\model_i\}_i$ that I may use to explain my observed data $\data$,
and let us write $\theta_i$ for the parameters of model $\model_i$.
How do we know which model to prefer?  We work out the posterior
probability over the models via Bayes' theorem!  We have:
\begin{equation*}
  \Pr(\model_i \given \data)
  =
  \frac{p(\data \given \model_i)\Pr(\model_i)}
       {\sum_j p(\data \given \model_j)\Pr(\model_j)}.
\end{equation*}
Here $\Pr(\model_i)$ is a prior distribution over models that we have
selected; a common practice is to set this to a uniform distribution
over the models.  The value $p(\data \given \model_i)$ may also be
written in a more-familiar familiar form:
\begin{equation*}
  p(\data \given \model_i)
  =
  \int
  p(\data \given \theta_i, \model_i)
  p(\theta_i \given \model_i)
  \intd{\theta_i}.
\end{equation*}
This is exactly the denominator when applying Bayes' theorem to find
the posterior $p(\theta_i \given \data, \model_i)$!
\begin{equation*}
  p(\theta_i \given \data, \model_i)
  =
  \frac{p(\data \given \theta_i, \model_i) p(\theta_i \given \model_i)}
       {\int
         p(\data \given \theta_i, \model_i)
         p(\theta_i \given \model_i)
         \intd{\theta_i}.
       }
  =
  \frac{p(\data \given \theta_i, \model_i) p(\theta_i \given \model_i)}
       {p(\data \given \model_i)},
\end{equation*}
where we have simply conditioned on $\model_i$ to be explicit.  In the
context of model selection, the term $p(\data \given \model_i)$ is
known as the \emph{model evidence} or simply \emph{evidence.}  One
interpretation of the model evidence is the probability that your
model could have generated the observed data, under the chosen prior
belief over its parameters $\theta_i$.

Suppose now that we have exactly two models for the observed data that
we wish to compare: $\model_1$ and $\model_2$, with corresponding
parameter vectors $\theta_1$ and $\theta_2$ and prior probabilities
$\Pr(\model_1)$ and $\Pr(\model_2)$. In this case it is easiest to
compute the \emph{posterior odds}, the ratio of the models'
probabilities given the data:
\begin{equation*}
  \frac{\Pr(\model_1 \given \data)}
       {\Pr(\model_2 \given \data)}
  = \frac{\Pr(\model_1) p(\data \given \model_1)}
         {\Pr(\model_2) p(\data \given \model_2)}
  = \frac{\Pr(\model_1) \int p(\data \given \theta_1, \model_1)
          p(\theta_1 \given \model_1) \intd{\theta_1}}
         {\Pr(\model_2) \int p(\data \given \theta_2, \model_2)
          p(\theta_2 \given \model_2) \intd{\theta_2}},
\end{equation*}
which is simply the prior odds multiplied by the ratio of the evidence
for each model.  The latter quantity is also called the \emph{Bayes
  factor} in favor of $\model_1$.  Publishing Bayes factors allows
another practitioner to easily substitute their own model priors and
derive their own conclusions about the models being considered.

\subsection*{Example}

Wikipedia gives a truly excellent example of Bayesian model selection
in
practice.\footnote{\url{http://en.wikipedia.org/wiki/Bayes_factor#Example}}
Suppose I am presented with a coin and want to compare two models for
explaining its behavior.  The first model, $\model_1$, assumes that
the heads probability is fixed to $\nicefrac{1}{2}$.  Notice that this
model does not have any parameters.  The second model, $\model_2$,
assumes that the heads probability is fixed to an unknown value
$\theta \in (0, 1)$, with a uniform prior on $\theta$: $p(\theta
\given \model_2) = 1$ (this is equivalent to a beta prior on $\theta$
with $\alpha = \beta = 1$).  For simplicity, we choose a uniform model
prior: $\Pr(\model_1) = \Pr(\model_2) = \nicefrac{1}{2}$.

Suppose we flip the coin $n = 200$ times and observe $x = 115$ heads.
Which model should we prefer in light of this data?  We compute the
model evidence for each model.  The model evidence for $\model_1$ is
quite straightforward, as it has no parameters:
\begin{equation*}
  \Pr(x \given n, \model_1)
  =
  \mathrm{Binomial}(n, x, \nicefrac{1}{2})
  =
  \binom{200}{115}
  \frac{1}{2^{200}}
  \approx
  0.005956.
\end{equation*}
The model evidence for $\model_2$ requires integrating over the
parameter $\theta$:
\begin{align*}
  \Pr(x \given n, \model_2)
  &=
  \int
  \Pr(x \given n, \theta, \model_2)
  p(\theta \given \model2)
  \intd{\theta}
  \\
  &=
  \int_{0}^{1}
  \binom{200}{115}
  \theta^{115}
  (1 - \theta)^{200 - 115}
  \intd{\theta}
  \\
  &=
  \frac{1}{201}
  \approx
  0.004975.
\end{align*}
The Bayes factor in favor of $\model_1$ is approximately $1.2$, so the
data give very weak evidence in favor of the simpler model $\model_1$.

An interesting aside here is that a frequentist hypothesis test would
reject the null hypothesis $\theta = \frac{1}{2}$ at the $\alpha =
0.05$ level. The probability of generating at least 115 heads under
model $\model_1$ is approximately $0.02$ (similarly, the probability
of generating at least 115 tails is also $0.02$), so a two-sided test
would give a $p$-value of approximately $4\%$.

\subsection*{Occam's razor}

One spin on Bayesian decision theory is that it automatically gives a
preference towards simpler models, in line with Occam's razor.  One
way to see this is to consider the model evidence $p(\data \given
\model)$ as a probability distribution over datasets $\data$.  More
complex models can explain more datasets, so the support of this
distribution is wider in the sample space.  But note that the
distribution must normalize over the sample space as well, so we pay a
price for generality.  When moving from a simpler model to a more
complex model, the probability of some datasets that are well
explained by the simpler model must inevitably decrease to ``give up''
probability mass for the newly explained datasets in the widened
support of the more-complex model.  The model selection process then
drives us to select the model that is ``just complex enough'' to
explain the data at hand, an in-build Occam's razor.

In the coin flipping example above, model $\model_1$ can only explain
datasets with empirical heads probability reasonably near
$\frac{1}{2}$.  An observation of 200 heads, for example, would have
astronomically small probability under this model.  The second model
$\model_2$ can explain \emph{any} set of observations by selecting an
appropriate $\theta$.  The price for this generality, though, is that
datasets with a roughly equal number of heads and tails have a smaller
prior probability under the model than before.

\subsection*{Model selection for Bayesian linear regression}

A common application for model selection is for selecting between
feature expansion functions $\phi(\vec{x})$ in Bayesian linear
regression.  Here the model $\model_i$ could for example correspond
to order-$i$ polynomial regression with
\begin{equation*}
  \phi_i(\vec{x})
  =
  [1, \vec{x}, \vec{x}^2, \dotsc \vec{x}^i]\trans.
\end{equation*}
After selecting a set of these models to compare, as well as a prior
probability for each, the only remaining task is to compute the
evidence for each model in observed data $(\mat{X}, \vec{y})$.  In our
discussion of Bayesian linear regression, we have actually already
computed the desired quantity:
\begin{equation*}
  p(\vec{y} \given \mat{X}, \sigma^2, \model_i)
  =
  \mc{N}\bigl(\vec{y};
  \phi_i(\mat{X})\vec{\mu},
  \phi_i(\mat{X})\mat{\Sigma}\phi_i(\mat{X})\trans + \sigma^2\mat{I}\bigr),
\end{equation*}
where I have explicitly written the basis expansion in $\phi_i$.

Note that the model $\phi_i$ can also easily explain all datasets
well-explained by the models $\phi_j$ for $j < i$, by simply setting
the weights on higher-order terms to zero.  Again, however, the
simpler model will be preferred due the Occam's razor effect described
above.

\section*{Bayesian Model Averaging}

Note that a ``full Bayesian'' treatment of a problem would eschew
model selection entirely.  Instead, when making predictions, we should
theoretically use the sum rule to marginalize the unknown model, e.g.:
\begin{equation*}
  p(y_\ast \given \vec{x}_\ast, \data)
  =
  \sum_i
  p(y_\ast \given \vec{x}_\ast, \data, \model_i)
  \Pr(\model_i \given \data).
\end{equation*}
Such an approach is called \emph{Bayesian model averaging.}  Although
this is sometimes seen, model selection is still used widely in
practice.  The reason is that the computational overhead of using a
single model is much lower than having to continually retrain multiple
models, and that Bayesian model averaging uses a mixture distribution
for predictions, which can have annoying analytic properties (for
example, the predictive distribution could be multimodal).

\end{document}


\documentclass[11pt]{article}

\usepackage{texyousei}
\usepackage{tabularx}

\lhead{}
\chead{The Schur Complement for Fractional Sobolev Preconditioning}
\rhead{}

\usepackage{comment}
\excludecomment{oops}

\setlength{\leftmargini}{0.3in}

\DeclarePairedDelimiter{\inner}{\langle}{\rangle}
\newcommand{\ddx}{\frac{d}{dx}}
\newcommand{\ddy}{\frac{d}{dy}}
\newcommand{\ddn}{\frac{d}{dn}}
\newcommand{\ddm}{\frac{d}{dm}}
\newcommand{\sgn}[1]{\ \textrm{sgn}\left(#1\right)}
\newcommand{\calDf}{\mathcal{D}_f}

\begin{document}

\maketitle{The Schur Complement for Fractional Laplacians}{}

\thispagestyle{empty}

\section{Fractional Laplacian inverse approximation}
\label{sec:FractionalLaplacianInverseApproximation}

Recall that we now have a relatively efficient way to invert the fractional Laplacian $\Delta^{s}$ by factoring the inverse as $(\Delta^{-1}) (\Delta^{2 - s}) (\Delta^{-1})$; the two occurrences of $\Delta^{-1}$ are then be assembled as sparse cotan Laplacians, while the middle term has a positive power $2-s$ and can therefore be multiplied using hierarchical matrices. From here on, let $A = \Delta^{s}$, let $A^{-1} = (\Delta^{-1}) (\Delta^{2 - s}) (\Delta^{-1})$, and assume that we can multiply with $A^{-1}$ as a black box.

\section{The Schur complement}

For a general block matrix
$$M =
\left[
\begin{array}{cc}
A & B \\
C & D
\end{array}
\right]
$$
the Schur complement of the block $A$ is defined by $$M / A = D - C A^{-1} B.$$ Note that if $C$ has dimensions $k \times n$, then $M / A$ has dimensions $k \times k$. Then, if $A$ is invertible, then we have the following block expression for the inverse of $M$:
$$
M^{-1} = \left[
\begin{array}{cc}
A^{-1} + A^{-1} B (M / A)^{-1} C A^{-1} & -A^{-1} B (M / A)^{-1} \\
-(M / A)^{-1} C A^{-1} & (M / A)^{-1}
\end{array}
\right]
$$
Thus, in theory, we can invert the whole matrix $M$ by only inverting $A$ and $(M/A)$. (Analogous expressions exist for the complement $(M/D)$, but these expressions are not useful to us.)

\subsection{Application to the fractional Laplacian}

We would like to invert the saddle matrix
$$G =
\left[
\begin{array}{cc}
A & C^T \\
C & 0
\end{array}
\right]
$$
where $C$ is a $k \times 3|V|$ matrix whose rows contain the differentials of $k$ real-valued constraint functions, or alternatively, $C$ is the Jacobian of a constraint function $\Phi : \R^{3|V|} \to \R^k$.

Then, the expression for the complement becomes $$G / A = -C A^{-1} C^{\top}.$$ Note that we only have the ability to multiply $A^{-1}$ with column vectors, so we will have to apply the approximation from Section \ref{sec:FractionalLaplacianInverseApproximation} once per column of $C^{\top}$, or in other words, once per constraint.

As for the inverse, the only block that we need to apply is the top-left block, as this is the only block that contributes to the projected gradient; the other blocks either contribute to Lagrange multipliers that are unneeded for the flow, or are multiplied with entries that are always zero in the input. Thus, we only need the expression for the top-left block, which becomes $$A^{-1} + A^{-1} C^{\top} (M/A)^{-1} C A^{-1}.$$ We cannot assemble this block explicitly (nor would we want to for efficiency reasons), but we can multiply by this block by applying each of the operators in order, producing the expression $$G^{-1} x = A^{-1} x + A^{-1} C^{\top} (M / A)^{-1} C A^{-1} x.$$ This has the appearance of a ``correction'' being applied to the otherwise unconstrained projection $A^{-1} x$. Though $A^{-1}$ occurs 3 times in this expression, we only need to apply $A^{-1}$ twice, since the initial value of $A^{-1}x$ can be reused for both terms.

We do need to invert $(M/A)$, which is a dense matrix. However, it is of size $k \times k$, matching the number of real-valued constraints, so as long as this number is a small constant, the cost is negligible. Importantly, though, this means that this method will not scale to larger numbers of constraints (e.g. one constraint per triangle).

\subsection{Barycenter constraints}

At first, it seems reasonable to include barycenter constraints in the rows of $C$; this matches the way in which we've traditionally organized the saddle matrix in the past. But in fact, there is no need to do this. The above expressions for the Schur complement require that $A$ is invertible, and because $A$ is a fractional Laplacian, this is only true if we augment $A$ itself with barycenter constraints to factor out the null space of translations. This is exactly what we do with the approximation of Section \ref{sec:FractionalLaplacianInverseApproximation} -- we include barycenter constraints on the two integer Laplacians to make them invertible.

As such, including barycenter constraints in $C$ would not only be redundant, but would also require three additional applications of $A^{-1}$ as part of evaluating $A^{-1}C^{\top}$. Conceptually, we can instead organize the saddle matrix this way:
$$
\left[
\begin{array}{cc}
\left[
\begin{array}{cc}
A & B^{\top} \\
B & 0
\end{array}\right] & C^{\top} \\
C & 0
\end{array}
\right]
$$
where $B$ specifically corresponds to the rows for the barycenter constraint, and $C$ contains all the other constraints. Thus, the same saddle matrix is being inverted, but we save on applications of $A^{-1}$ by handling $B$ with the fractional Laplacian itself -- which we would need to do anyway to make it invertible.

\end{document}