\chapter{Wilson loops}\label{ch:WilsonLoops}

A Wilson loop is a gauge-invariant observable,
defined as the expectation value of the character of the representation $\mathcal{R}$ of the gauge group
($U(N)$ in our case):
\begin{equation}
  W_{\mathcal{R}}(C) =  \left\langle \text{tr}_{\mathcal{R}} U \right\rangle, \quad U \in U(N)
  %\dfrac{1}{\text{dim}\, \mathcal{R}}
\end{equation}
where $U$ is a path-ordered exponential of the gauge connection $A_\mu$,
transported along an arbitrary curve $C$ parametrized by $s$:
\begin{equation}
 U = \mathop{\mathrm{P}}\exp
    \left[
	i \int_C ds\,
	  \dot{x}^\mu A_\mu
    \right],
\end{equation}
where the dot denotes derivative respect $s$.

Physically, the Wilson loop operator measures the phase associated with moving a probe particle with charge
$\mathcal{R}$ around a curve $C$ in spacetime.
In particular, the long rectangular Wilson loop in the fundamental representation, the path shown in the figure \ref{fig:WLrectangle},
determines the static quark and antiquark potential:
\begin{equation}
 V_{q\bar{q}} (L) = -\dfrac{1}{T} \lim_{T\rightarrow\infty} \log W_1(C).
\end{equation}
In confined theories such as QCD, the potential is linear,
% $V_{q\bar{q}} (L) \propto L$,
which is referred as the \emph{area law} in terms of the Wilson loop,
$\log W \propto L\times T$,
while in the deconfined phase, the Wilson loop follows the \emph{perimeter law},  $\log W \propto L$.

\begin{figure}[t]
\begin{center}
 \centerline{\includegraphics[width=4cm]{Images/WLrectangle.png}}
\end{center}
\caption{\label{fig:WLrectangle} Trajectory of a probe quark and antiquark separated by distance $L$, and travel $T$ distance in time. }
\end{figure}

We are interested in a supersymmetric extension of the Wilson loop,
such that it is computable through localization, see conditions \eqref{loc:susyCondition}.
We will study the so-called Maldacena-Wilson loop \cite{Maldacena:1998im},
where we add a coupling to the scalars of the vector multiplet:
\begin{equation} \label{maldacenaWL}
 U = \mathop{\mathrm{P}}\exp
    \left[
	\int_C ds\,
	\left(
	  i\dot{x}^\mu A_\mu +|\dot{x}|n^I\Phi_I
	\right)
    \right], \quad I=0,9.
\end{equation}
% where $n^I$ are components of the unit vector that parametrizes $S^5$.
Let us start by reviewing some known results in $\mathcal{N}=4$ SYM and then generalize them to $\mathcal{N}=2^*$.

\section{Wilson loops in $\mathcal{N}=4$ SYM}

The simplest Wilson loop is an infinite straight line.
It is a half-BPS object, meaning it commutes with half of the 32 supercharges of $\mathcal{N}=4$ SYM.
This fact protects the Wilson line from quantum corrections and its value is simply one:
\begin{equation}
 \braket{W_\text{line}} = 1.
\end{equation}

By conformal transformation, the Wilson line can be mapped to a circular Wilson loop.
The result, however, is not the same.
This is often referred to as a conformal anomaly,
and it is due to the fact that large conformal transformations such as inversion are not symmetries in the flat space
(infinity is not a point of $\mathbb{R}^d$).
On the sphere, these are symmetries, hence there is no distinction between a circle and a line, and the
expectation value of either is the same as for a circle on $\mathbb{R}^4$ \cite{Drukker:2000rr}.
The circular Wilson loop, which is also half-BPS, is exactly computable using the localized partition function for the theory on $S^4$,
where the path is the equator of sphere, see figure \ref{fig:equatorWL}.

\begin{figure}[t]
\begin{center}
 \centerline{\includegraphics[width=4cm]{Images/equatorWL.png}}
\end{center}
\caption{\label{fig:equatorWL} The contour of the circular Wilson loop we study is the equator of the hypersphere the theory is defined on.}
\end{figure}

\subsection{Fundamental representation}
The circular Wilson loop in the fundamental representation is mapped to a matrix model expectation value:
\begin{equation}\label{eq:W1mm}
 W_1 = \left< \dfrac{1}{N}\sum_{i=1}^N e^{2\pi a_i} \right>_\text{matrix model},
%  \overset{N \gg 1}{\approx} \int_{-\mu}^{\mu} dx\, \rho(x) \,e^{2\pi x}
\end{equation}
which can be solved exactly for GUE \cite{Drukker:2000rr}:
\begin{equation}
 W_1 = \dfrac{1}{N} L_{N-1}^1 (-\lambda/(4N)) e^\frac{\lambda}{8N},
\end{equation}
where $L$ is the generalized Laguerre polynomial:
\begin{equation}
 L_n^m(x)=\dfrac{x^{-m}  e^x}{n!}\,  \dfrac{d^n}{dx^n}(e^{-x} x^{n+m}).
\end{equation}

In the large $N$ limit and fixed 't Hooft coupling,
\eqref{eq:W1mm} can be written as:
\begin{eqnarray}
 W_1 &=& \int_{-\mu}^{\mu} dx\, \rho(x) \,e^{2\pi x} \label{eq:W1continuous} \\
     &=& \dfrac{2}{\sqrt{\lambda}} I_1 (\sqrt{\lambda}), \quad (N\rightarrow \infty \quad \text{and} \quad \lambda \text{ - fixed})
\end{eqnarray}
where for the last equality, we used the semicircle distribution \eqref{semicircle},
since the Wilson loop insertion to the partition function is subleading in $N$.
$I_1(x)$ is the modified Bessel function:
\begin{equation}
 I_1(x) = \sum_{n=0}^\infty  \dfrac{1}{n! (n+1)!} \left(\dfrac{x}{2}\right)^{2n+1}.
\end{equation}

Historically, the large-$N$ result was initially obtained by Erickson-Semenoff-Zarembo \cite{Erickson:2000af},
by summing over rainbow diagrams in perturbation theory, and they conjectured the Gaussian matrix model structure for $\mathcal{N}=4$ SYM.
Eventually Pestun's work in localization \cite{Pestun:2007rz} proved it.

In the 't Hooft limit, which is the holographic regime,
\begin{equation}\label{W1holographic}
 W_1 = \sqrt{\frac{2}{\pi}} \lambda^{-3/4} e^{\sqrt{\lambda}},
 \quad (N\rightarrow \infty \quad \text{and} \quad \lambda \rightarrow \infty).
\end{equation}
% which matches with the minimal surface of the worldsheet with boundary $C$, drawn by the classical string on the supergravity background.
% We will discuss more on the holographic dual in another chapter.
% The subleading order term comes from the measure of the path integral, and so far,
% it is still an open problem that many attempted to solve (cite Papers).

% The equatorial Wilson loops can be generalized to latitude Wilson loops,
% though the latter are less supersymmetric, and belongs to the family of 1/4 BPS.
% Their exact result can be obtained by just rescaling the 1/2 BPS, by
% $\lambda \rightarrow \lambda \cos^2\theta_0$,
% where the angle $\theta_0$ is the polar angle of the latitude.

\subsection{Higher rank representations}

Exact results for arbitrary representation of $U(N)$ can also be obtained \cite{Fiol:2013hna}.
These are very generic, though,
but the generating function of $k$-antisymmetric representation
\begin{equation}\label{eq:generatingFunctionAk}
 \braket{G_{A_k}(t)}=\sum_{k=0}^{N} t^k \, W_{A_k}
%  G_{A_k} same as G^{-} defined few lines below
\end{equation}
has a nice compact form:
\begin{equation}
 \braket{G_{A_k}(t)}=\text{det}\left(t \delta_{ij}+ L_{i-1}^{j-i}(-\lambda/(4N)) e^{\frac{\lambda}{8N}}\right).
\end{equation}

We study the 't Hooft limit
for the symmetric (+) and the antisymmetric (-) representations.
The generating functions\footnote{
Here, unlike in \eqref{eq:generatingFunctionAk},
we use the expansion parameter $e^{-\nu}$ instead of $t$.}
for the character of these representations are explicitly known:
\begin{equation}
 G^{\pm}(\nu) = \prod_{i=1}^N (1\mp e^{a_i - \nu})^{\mp}.
% Wilson loop in terms of the generating function:
% \left<G^{\pm}(t)\right>=\sum_{k=0}^{N} t^k \, W^{\pm}_k
\end{equation}
Notice that these are also the Bose (+) and Fermi (-) distributions, in terms of the eigenvalues $a_i$.

The standard procedure is to derive the character by inverting the generating function using Cauchy's integral formula:
\begin{equation}\label{eq:characterIntegral}
 \chi_k^\pm \equiv \text{tr}_\pm \,U = \int_{C-i\pi}^{C+i\pi} \dfrac{d\nu}{2\pi i} \, e^{\nu k} G^\pm(\nu),
\end{equation}
where $C>a_i, \forall i$, for the symmetric case, and $C$ is arbitrary for the antisymmetric case.

All we need to do now is to compute the expectation value of the above integral.
We can still employ the semicircle distribution \eqref{semicircle},
and we further take the large representation limit $k \sim N$,
which allows us to use the saddle-point method in \eqref{eq:characterIntegral}, \cite{Hartnoll:2006is}.
The saddle-point equation to solve for $\nu_*$ is
\begin{equation}\label{eq:saddlePointDensity}
 \dfrac{k}{N} = \int_{-\mu}^\mu dx \, \dfrac{\rho(x)}{e^{L(\nu_*-x)}\mp 1},
 \quad (N\rightarrow \infty \quad \text{and} \quad \frac{k}{N} \text{ - fixed}),
\end{equation}
which is analogous to the particle density equation in a Bose/Fermi system.

The final leading solutions for the antisymmetric representation is
\begin{equation}\label{solW-}
 \log W_{k}^-= N \frac{2\sqrt{\lambda }}{3\pi}\,\sin^3\theta,
\end{equation}
where $\cos \theta\equiv \nu_*/\mu$ satisfies the transcendental equation
\begin{equation}\label{eqThetaAntisym}
 \theta -\frac{1}{2}\,\sin 2\theta =\pi \frac{k}{N},
\end{equation}
resulting from \eqref{eq:saddlePointDensity}
after the step-function approximation of the Fermi distribution.

For the symmetric representation, however,
there is no saddle-point solution for \eqref{eq:saddlePointDensity}.
This is the same phenomenon as the Bose-Einstein condensation.
It is possible to analytically continue the solution to the second Riemann sheet, though,
as done in \cite{Hartnoll:2006is},
and the final result is:
\begin{equation}\label{solW+}
 \log W_{k}^+ = 2 N  f\left(\kappa\right),
 \quad  \kappa \equiv \frac{\sqrt{\lambda }\,k}{4 \,N}
\end{equation}
where
\begin{equation}\label{eqfSym}
 f(x) = x\sqrt{1+x^2}+\mathop{\mathrm{arcsinh}}x.
\end{equation}

The drawback of the analytic continuation was that computing large-$N$ corrections became less clear, as attempted in \cite{Faraggi:2014tna}.
In Paper II and Paper IV, we used a more systematic approach.
Paper IV focused exclusively on the symmetric Wilson loop in $\mathcal{N}=4$ SYM,
where subleading corrections in $N$ were computed.
This result is consistent with the expansion of the known exact result for the multiply wrapped fundamental Wilson loop \cite{Kawamoto:2008gp},
which helped to clarify the apparent mismatch observed in \cite{Faraggi:2014tna},
and agrees with the analysis by \cite{Yamaguchi:2007ps} that symmetric representations and the multiply-wound fundamental ones
differ by exponentially-suppressed terms in strong coupling.
Paper IV also derived the strong-coupling corrections,
in response to the strong-coupling expansion done for the antisymmetric case in \cite{Horikoshi:2016hds},
where the Sommerfeld expansion of the Fermi distribution was used.
%k-fundamental obtained by relplacing $\lambda \rightarrow k^2 \lambda$.

\section{Wilson loops in $\mathcal{N}=2^*$ SYM}

The story can be extended to $\mathcal{N}=2^*$ SYM on $S^4$.
Here we have an extra parameter: the scale $MR$.
We will take the decompactification limit $MR \rightarrow \infty$, where interesting phase transitions were seen,
and also, the dual theory is fully known on $\mathbb{R}^4$ \cite{Pilch:2000ue}.
% (the dual on $S^4$ is partially known, \cite{Bobev:2013cja}).

% We work with the equatorial circular Wilson loop and reasonably assume that results in the decompactification limit is universal for any large contour.

\subsection{Fundamental representation}

Since the fundamental Wilson loop is basically an exponentially-weighted integral \eqref{eq:W1continuous},
its value in the strong coupling limit is determined by the largest eigenvalue $\mu$
(recall $\mu\sim\sqrt{\lambda}$, see \eqref{semicircleN=2*}).
Thus, we do not expect its strong coupling corrections to probe the cusps region.
In Paper I, we computed the subleading correction to the endpoint $\mu$,
which lead to the same correction to the Wilson loop (in terms of the perimeter $l=2\pi R$):
\begin{equation}\label{WLFundN2}
 \log W_1= P(\lambda) Ml, \quad P(\lambda) = \frac{\sqrt{\lambda}}{2 \pi} -\frac{1}{2} + \mathcal{O}\left(\dfrac{1}{\sqrt{\lambda}}\right),
 \quad (MR\rightarrow \infty).
\end{equation}
The leading order term is the same as its homologous case in $\mathcal{N}=4$, only rescaled by $MR$ \cite{Buchel:2013id},
as a direct consequence of the semicircle behavior of the bulk distribution \eqref{semicircleN=2*}.
As a consistent check, when $M\rightarrow 0$, the Wilson loop goes to 1, as expected for the $\mathcal{N}=4$ case.
Moreover, we clearly see the perimeter law here since the theory is not confining neither conformal.

\subsection{Symmetric and antisymmetric representations}
In Paper II, result for symmetric and antisymmetric representations were computed,
up to the next-to-leading order in the strong coupling expansion.
The decompactified results at the leading order in $N$ are also the same as the ones in the $\mathcal{N}=4$ case,
but rescaled differently:
\begin{eqnarray}
 \log W_{k}^- &=& N M R\frac{2\sqrt{\lambda }}{3\pi}\,\sin^3\theta,\\
 \log W_{k}^+ &=& 2 N (MR)^2 f\left(\frac{\kappa}{M R}\right),
\end{eqnarray}
where $\theta$ and  $f$ satisfy the same equation as in \eqref{eqThetaAntisym} and \eqref{eqfSym}, respectively.

Now, the interesting part lays in the subleading terms.
Unlike the fundamental representation, the higher rank representations do probe the endpoint distribution of the eigenvalues,
which has periodic cusps with period $MR$, see figure \ref{fig:phaseDiagram}.
The results are:
\begin{equation}\label{WantisymPW}
 \delta \log W_{k}^- = -\dfrac{2\pi^2}{3} \dfrac{N M R}{\lambda^{3/4}}
\begin{cases}
 4\tilde{f}^3 & {\rm }0<\tilde{f}\leq 1
\\
 \tilde{f}^3+6\tilde{f}-\frac{3}{\tilde{f}} & {\rm } 1<\tilde{f}\leq 1+\sqrt{2}
 \\
 \vdots &
\end{cases}, \quad
\tilde{f} = \dfrac{\lambda^{3/4} k }{ 4\sqrt{\pi} N}
\end{equation}
and
\begin{equation}\label{WsymPW}
 \delta \log W_{k}^+ = \dfrac{2^5\pi^{3/2}}{5}\dfrac{N (M R)^2}{\lambda^{3/4}} \left(v^{5/2}+\Theta(v-1)\left(v+\dfrac{2}{3}\right)(v-1)^{3/2}\right),
\end{equation}
where $\Theta(x)$ is the Heaviside function and $v$ is written in terms of the scaling parameter $\tilde{f}$ as
\begin{equation}
  \dfrac{3}{2}\tilde{f} = v^{3/2}-\Theta(v-1)(v-1)^{3/2}, \quad \tilde{f} = \dfrac{\lambda^{3/4} k}{8\sqrt{\pi} M R N}.
\end{equation}
The solutions are plotted in figure \ref{fig:plotsCorrection}.
The phase transitions are of second and third order for the antisymmetric and symmetric representations, respectively,
in the sense that the derivatives of the free energy $F=-\frac{1}{N}\log W$ with respect to $\tilde{f}$ exhibit discontinuity at these orders.

% \begin{figure}[t]
% \begin{center}
%   \includegraphics[width=0.49\textwidth]{Images/AntisymBlack.pdf}
%   \includegraphics[width=0.49\textwidth]{Images/SymBlack.pdf}
% \end{center}
% \caption{\label{fig:plotsCorrection} Strong coupling correction for the (rescaled) log of Wilson loops in
% antisymmetric representation (left) with the critical points at $\{1, 1+\sqrt{2}, 1+\sqrt{2}+\sqrt{3},\ldots\}$,
% and in symmetric representation (right) with the critical point at $2/3$.}
% \end{figure}

\begin{figure}[t]
\begin{center}
 \centerline{ \includegraphics[width=0.8\textwidth]{Images/AntisymBlack.pdf} }
 \centerline{ \includegraphics[width=0.8\textwidth]{Images/SymBlack.pdf} }
\end{center}
\caption{\label{fig:plotsCorrection} Strong coupling correction for (rescaled) log of Wilson loops in
antisymmetric representation (up) with the critical points at $\{1, 1+\sqrt{2}, 1+\sqrt{2}+\sqrt{3},\ldots\}$,
and in symmetric representation (down) with the critical point at $2/3$.}
\end{figure}


\documentclass[../PHYS306Notes.tex]{subfiles}

\begin{document}
\subsection{Worksheet - Lagrangians for EM fields, Uniqueness}
\begin{p}
From the form of the Lagrangian for a charged particle in an electromagnetic field, find the generalized momentum $\v{p}$.
\end{p}
\begin{s}
As discussed in the lecture, we generalize the potential \[U' = qV - q\dot{\v{r}}\cdot\v{A}\]
and hence construct the Lagrangian:
\[\LL = T - U' = \frac{1}{2}m\dot{\v{r}}^2 - qV + q\dot{\v{r}}\cdot\v{A}\]
The generalized momentum is then given by:
\[\v{p} = \dpd{\LL}{\dot{\v{r}}} = m\dot{\v{r}} + q\v{A}\]
\end{s}

\begin{p}
Find the generalized force for the above system in the x-direction, and the total time derivative of the generalized momentum, $\od{\v{p}}{t}$ (Recall that $\v{A} = \v{A}(x,y,z,t)$)).
\end{p}
\begin{s}
The generalized force in the x direction is given by:
\[F_x = \dpd{\LL}{x} = -q\left(\dpd{V}{x} - \dot{x}\dpd{A_x}{x} - \dot{y}\dpd{A_y}{x} - \dot{z}\dpd{A_z}{x}\right)\]
The total time derivative of the generalized momentum is given by:
\[\dod{}{t}p_x = m\ddot{x} + q\left(\dot{x}\dpd{A_x}{x} + \dot{y}\dpd{A_x}{y} + \dot{z}\dpd{A_x}{z} + \dpd{A_x}{t}\right)\]
Where we have used the chain rule.
\end{s}

\begin{p}
Write the equations of motion in terms of the electric and magnetic fields.
\end{p}
\begin{s}
Combining the two equations above (EL equation), we have:
\[m\ddot{x} = -q\left(\dpd{V}{x} + \dpd{A_x}{t}\right) + q\dot{y}\left(\dpd{A_y}{x} - \dpd{A_x}{y}\right) + q\dot{z}\left(\dpd{A_z}{x} - \dpd{A_x}{z}\right)\]
Recognizing the first term as the electric field term and the second/third terms as $B_z$ and $-B_y$ respectively, we recognize this as the x component of $\dot{\v{r}}\times \left(\curl{\v{A}}\right)$, or the Lorentz Force! The y and z components follow similarly and we recover:
\[m\ddot{\v{r}} = q(\v{E} + \dot{\v{r}}\times\v{B})\]
Which matches up with Newton's Law. Hence, we have been able to extend the Lagrangian formalism to charged particles in electromagnetic fields.
\end{s}

\begin{p}
Consider a charged, relativistic particle in an electric field $\v{E}$. Show that the Lagrangian $\mathcal{L}=-m c^{2} \sqrt{1-v^{2} / c^{2}}-q V+q \v{v} \cdot \v{A},$ with $m$ given by the rest mass, gives the correct (relativistic) equations of motion.
\end{p}
\begin{s}
If we recall from PHYS 200, the momentum generalized to the relativistic case has a Lorentz factor of $\gamma = \frac{1}{\sqrt{1- \frac{v^2}{c^2}}}$, given by:
\[\v{p} = m_0\gamma\v{v}\]
So we require that we get this back from the Lagrangian expression. Checking the generalized momentum, we see:
\[\v{p} = \dpd{\LL}{\v{v}} = -m_0c^2\frac{1}{2}\frac{1}{\sqrt{1-\frac{v^2}{c^2}}}\left(-2\frac{\v{v}}{c^2}\right) = m_0\gamma\v{v}\]
Which lines up with our expectation.
\end{s}

\begin{p}
Show that $\LL = T - U +x^2\dot{x}$ also gives the Newton’s equations of motion. What is the implication for the uniqueness of the Lagrangian then?
\end{p}
\begin{s}
Showing that this satisfies Newton's equations of motion:
\[\dpd{\LL'}{x} = -\dpd{U}{x} + 2x\dot{x}\]
\[\dpd{\LL'}{\dot{x}} = m\dot{x} + x^2 \implies \dod{}{t}\dpd{\LL'}{\dot{x}} = m\ddot{x} + 2x\dot{x}\]
Therefore by the EL equation:
\[\dpd{\LL'}{x} = \dod{}{t}\dpd{\LL}{\dot{x}}\]
\[-\dpd{U}{x} + 2x\dot{x} = m\ddot{x} + 2x\dot{x}\]
So we recover Newton's law:
\[-\dpd{U}{x} = m\ddot{x}\]
This shows that the Lagrangian is not unique. In general, we can always add a total derivative of the form:
\[\dod{}{t}G(q,t)\]
to $\LL$ without changing the equations of motion. To see that this is the case, consider the modified Lagrangian:
\[\LL'(q, \dot{q}, t) = \LL(q, \dot{q}, t) + \dod{}{t}G(q,t)\]
And now computing the action, we have:
\[S'(q, \dot{q}, t) = \int_{t_1}^{t_2}\LL(q, \dot{q}, t)dt + \int_{t_1}^{t_2}\dod{}{t}G(q, t)dt\]
The second term we compute to be $G(q_2, t_2) - G(q_1, t_1)$ which are independent of the trajectory (as the start and endpoints are the same). So this does not affect the overall action, or the trajectory that minimizes the action, or in other words:
\[\delta S' = \delta S\]
\end{s}

\end{document}


% !TEX root = ../bachlor-arbeit.tex
\begin{figure}[H]
    \centering
    \includegraphics[width=.6\linewidth]{bg_basic_nn}
    \caption{The most simple kind of NN is called densely connected or multilayer perceptron. For clarity only connections to the top most node of each layer are shown.}
    \label{fig:bg:basic_nn}
\end{figure}

Artificial Neural Networks (ANN's or short NN's) are a kind of data structure inspired by the biological neurons found in nature. They can be used to find a wide range of input output relations. One classic example is mapping pictures of hand written digits to the actual digits. Rather than explicitly programmed, NN's are trained on a dataset $(X, \, Y)$ of correct input output pairs.

\paragraph{Multilayer Perceptron}
This kind of classic NN consist of single nodes or neurons which are organized into layers. The terms node and neuron can be used interchangeably. Every node is connected to all the nodes of the previous and the next layer. For this reason the network is called dense or densely connected. Each node holds a value called activation $a$ where the activation to the first layer is the input to the network, here:
$(x_1, \, x_2, \, x_3)$.
The nodes are connected by weights $w$ which specify how much one node should influence the next and every node has a bias $b$ to control at what total input activation the node itself should become active.
To calculate the activation of a node, one has to multiply all the activations of the previous layer with their respective weights $w$, add the bias $b$ and finally apply a non-linear activation function $\sigma$.
In order to describe this process mathematically, we are going to use the usual index notation where superscripts specify the layer and subscripts the node. So $a^2_1$ is the activation of the first node in the second layer. To characterize each weight two subscripts are needed, for the end and beginning of the connection. For the example in figure \ref{fig:bg:basic_nn} that gives

\begin{equation} \label{eq:bg:activation_example}
    a^2_1 = \sigma \qty(\sum_i w^2_{1i} \, x_i + b^2_1)
\end{equation}

\noindent
However, it is more convenient to stop considering every node individually and to view the involved quantities as vectors and matrices. So that \eqref{eq:bg:activation_example} can be written as

\begin{equation} \label{eq:bg:activation}
    \vb{a}^l = \sigma \underbrace{
    \qty(\vu{w}^l \vb{a}^{l-1} + \vb{b}^l)
    }_{
    \textstyle
    := \vb z^l
    }.
\end{equation}

That means the activation function $\sigma$ maps the total input of a neuron $\vb z^l$ to the output/activation of that neuron $\vb a^l$. Two examples for activation functions can be seen in Figure \ref{fig:al:act}.

\begin{figure}[H]
\centering
\begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[width=\linewidth]{bg_relu}
    \caption{rectified linear unit (ReLu)}
    \label{}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[width=\linewidth]{bg_sigmoid}
    \caption{sigmoid}
    \label{}
\end{subfigure}
\caption{Two examples of activation functions $\sigma$. Especially the ReLu function has a destinct on and off state similar to a biological neurons.}
\label{fig:al:act}
\end{figure}

\paragraph{Training}~\\
\label{par:training}During training the networks output $\s{NN}(\vb x) := \vb{y}' $ is calculated through repeated use of \eqref{eq:bg:activation} and is then compared with the known correct output $\vb y$ by a cost function $C = C(\vb y, \, \vb y')$. The goal of the training is to minimize this function $C$. The cost function might simply be the mean squared difference between $\vb y$ and $\vb y'$

\begin{equation}
    C_\s{mse}(\vb y, \, \vb y') = \sum_i \qty(y_i - y_i')^2
\end{equation}

\noindent
but there are different cost functions for different kind of outputs. For example, a network which predicts continuous values needs a different cost function than one predicting categories. More on this in section \ref{sec:NN}. Now we can quantify how well the NN is performing and are able to use this information to train the network.
\\

\indent
As stated before, the goal of the training is to minimize the cost function $C$ by changing the weights and biases. This means we are looking for the partial derivatives $\partial C / \partial \hat w^l_{j,k}$ and
$\partial C / \partial b^l_j$. To find these we need the concept of the \textit{error of a single neuron} $\delta^l_j$, where

\begin{equation}
    \delta^l_j := \pdv{C}{z^l_j}.
\end{equation}

This property expresses how much the final cost is affected by a change to the input of neuron $j$ in layer $l$. For the last layer $L$, we can find a simple expression for this property by using the chain rule

\begin{equation} \label{eq:bg:back_prop}
    \delta^L_j = \pdv{C}{z^L_j} = \pdv{C}{a^L_j} \ \pdv{a^L_j}{z^L_j}
    \stackrel{\eqref{eq:bg:activation}}{=}
    \pdv{C}{a^L_j} \ \sigma'(z^L_j).
\end{equation}

Remember, $z^l_j$ is the input to a neuron and $a^l_j$ is the output. That means $\delta^L_j$ is determined by a combination of how much the last output changes the cost function and how much the last input changes the last output. Notice how both these terms are easily accessible. $z^l_j$ was already calculated on the forward pass and the derivatives of the cost and activation functions can be found analytically. By using the gradient operator $\grad$ and the Hadamard product $\odot$, where

\begin{equation}
    \vb a \odot \vb b :=
    \begin{pmatrix}
        a_1 \, b_1 \\
        a_2 \, b_2 \\
        \vdots
    \end{pmatrix},
\end{equation}

we can return to the more convenient vector notation and write

\begin{equation} \label{eq:bg:back1}
    \boldsymbol \delta^L = \grad_a C  \odot \sigma'(\vb z^L).
\end{equation}

Now we know $\boldsymbol \delta$ for the last layer but not for the rest of the network. However, we can express the error of an arbitrary layer $\boldsymbol \delta^l$ by the error in the next layer $\boldsymbol \delta^{l+1}$ through

\begin{equation} \label{eq:bg:back2}
    \boldsymbol \delta^l =
    \qty[(\hat w^{l+1})^\top \, \boldsymbol \delta^{l+1}]
    \odot \sigma'(\vb z^l).
\end{equation}

This equation can be intuitively understood as moving the error
$\boldsymbol \delta^{l+1}$ back one layer by applying $(\hat w^{l+1})^\top$ and then through the activation function of layer $l$ by applying $\sigma'$. In a sense its again "simply" a chain rule. With these two equations, \eqref{eq:bg:back1} and \eqref{eq:bg:back2}, all the errors $\boldsymbol \delta$ in the network are known. Just start with the last layer and work your way backwards. This idea of moving the error backwards is the reason why the algorithm is called \textit{Backpropagation}. \\

\indent
The last thing to do is to relate $\boldsymbol \delta$ back to the original derivatives $\partial C / \partial \hat w^l_{j,k}$ and $\partial C / \partial b^l_j$. Using equation \eqref{eq:bg:activation} gives
\begin{align}
    \partial C / \partial b^l_j &= \delta^l_j \qq{and} \\[5pt]
    \partial C / \partial \hat w^l_{j,k} &= a^{l-1}_k \, \delta^l_j.
\end{align}

Now we could modify the weights after every forward pass by

\begin{equation}
    \hat w^l_{j,k} \leftarrow
    \hat w^l_{j,k} - \eta \  \partial C / \partial \hat w^l_{j,k} \,,
\end{equation}

with the learning rate $\eta$ \label{hyp:learnigrate}.
This method is called \textit{stochastic gradient descent} and because the weights and biases are updated on every training sample the cost function can oscillate strongly.
This is why in practice updates are performed on small \textit{mini-batches}\label{hyp:minibatch} of training samples. This concludes the training of a Multilayer Perceptron. Other Neural Networks are trained in a similar manner. An excellent comprehensive explanation of Backpropergation was published by Nielsen \cite{backprop}.

\paragraph{Convolutional Neural Networks}~\\
An area where NNs have been very successful is image recognition or more general computer vision but the described multilayer perceptron has a number of weaknesses for this kind of task. Let's say our input is a $n$ by $n$ gray scale image. This can be expressed as a $n \cp n$ matrix, flattened and fed into the input layer as seen in figure \ref{fig:bg:flatten}. But now the number of weights to the next layer $\vu{w}^2$ is $n \cdot n \cdot l^2$
which soon becomes unfeasible. As described in the section on \hyperref[sec:notation]{Notation}, $l^2$ is here the number of nodes in the second layer and not $l$ squared.

\begin{figure}[H]
    \centering
    \includegraphics[width=.45\linewidth]{bg_flatten}
    \caption{Flattening of a $3\cp3$ matrix to fit the input of a multilayer perceptron.}
    \label{fig:bg:flatten}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=.6\linewidth]{bg_convnet_T}
    \caption{Two pictures of a T at different positions where the red color signifies a high value in the grayscale image. After the flatten operation seen in figure \ref{fig:bg:flatten} very different nodes are active.}
    \label{fig:bg:convnet_T}
\end{figure}

\indent
Computational limits aside, there is another problem. Imagine an image with the letter T in the top right corner. If this letter moves to a different position, as in figure \ref{fig:bg:convnet_T}, the networks reaction will be completely different because the weights and biases involved are completely different. So the NN cannot learn the concept "letter T" independent of its position in the picture. The information about the distance between pixels is lost.
These problems led to the development of a new kind of layer called \textit{Convolution}. A fixed size squared matrix called \textit{kernel} is shifted over the matrix and at every position the point wise product between kernel and matrix is calculated and summed as shown in figure \ref{fig:bg:conv_example}.
\\

\indent
The result of this operation, called \textit{feature map} of that kernel, is shown in figure \ref{fig:bg:convolution}. Notice how the greatest value of the feature map is at the position of the letter T. So with only a small number of weights the convolution is able to detect the T independent of its position in the image.
This is still slightly misleading because this "T kernel" was intentionally constructed to find the T. In a real convolutional layer the kernel values are trained via Backpropagation similar to the weights of a Multilayer Perceptron as described in the paragraph \hyperref[par:training]{Training}.
\\

\begin{figure}[H]
    \centering
    \includegraphics[width=.6\linewidth]{bg_convolution_example}
    \caption{Example of a convolution. The $3 \times 3$ kernel is shifted over the image one step at the time. The red color in the image represents a pixel value of 1. For example in picture (a) the point wise product between kernel and image is zero everywhere except at two positions where a one in the kernel meets a one in the image. Because there are less valid positions for the kernel than pixels in the image the result is smaller in size.}
    \label{fig:bg:conv_example}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=.6\linewidth]{bg_convolution}
    \caption{Example of a convolution where white pixel are 0 and red pixel are 1. The $3 \times 3$ kernel is shifted over the image and the point wise product between kernel and image is calculated at every step as described in figure \ref{fig:bg:conv_example}. The result is the greatest when the kernel is directly over the letter T.}
    \label{fig:bg:convolution}
\end{figure}

One convolutional layer contains not only one but a number of different kernels $k$. The resulting $k$ feature maps are stacked in the "$z$ direction" so that the shape of the $n \times n$ matrix transforms to $(n-2) \times (n-2) \times k$ when convolved with a $3 \times 3$ kernel. In a convolutional network, short ConvNet, multiple of these layers are used so that it can find "patterns in patterns". For the letter detection example, one could imagine the first layer to detect various edges and the next layer to detect letters in the position of these edges.

\paragraph{Pooling Layers}~\\
For a big image and a large number of kernels the output shape of a convolutional layers is still $\order{(n)^2 \cdot k}$, so quite large. Also, notice how in figure \ref{fig:bg:convolution} the "T kernel's" feature map is not only active at the exact position of the T but in the general region. The solution to this is to downsample the output with a \textit{Pooling Layer}. Here a smaller kernel, usually $2 \times 2$ is shifted over the matrix two steps at a time and at every position an operation is performed to reduce the number of values to one. This could be taking the maximum or the average of that $2 \times 2$ region. This operation reduces the matrix in the x and y dimension by a factor of 2 as shown in figure \ref{fig:bg:pooling}.

\begin{figure}[H]
    \centering
    \includegraphics[width=.6\linewidth]{bg_pooling}
    \caption{Example of a Max Pooling Layer. For every 2 by 2 field the maximum is calculated. After applying first the convolution and then the pooling layer the information "T in the top right corner" is still there and size of the resulting matrix is very manageable.}
    \label{fig:bg:pooling}
\end{figure}
\vspace{1cm}

\paragraph{Example Network Architecture}~\\
\begin{figure}[H]
    \centering
    \includegraphics[width=.8\linewidth]{bg_example_convnet.png}
    \caption{Example for a complete ConvNet. Note that the input is an RGB image so there are three layers in the $z$ dimension corresponding to the different colors. In this case the first layer has 64 kernels of size $3 \times 3 \times 3$. The next convolution then has 128 kernels of size $3 \times 3 \times 64$. The final softmax activation rescales the output so that its sum is 1. \cite{cat}}
    \label{fig:bg:NN_example}
\end{figure}

Now all the building blocks for a complete ConvNet are available. Repeatedly alternating convolution and pooling layers changes the input from wide in x and y dimension and narrow in z to a long z-strip. At the very end this strip is fed into one densely connected layer which is in turn connected to the output neurons. An example architecture of this kind is shown in figure \ref{fig:bg:NN_example}. This network could for example choose one of 1000 labels for the input image like car, human, cat...

\paragraph{1D ConvNets}~\\
The input to the desired algorithm is a target spectrum to which the Network should output some parameters (more on this in the section \ref{sec:NN}). This input data is a function $I(\lambda)$, so only one dimensional, in contrast to an image which is a function $f(x, \, y)$ but all the same ideas apply. Convolutional kernels are sized $1 \times 3 \times z$ and pooling kernels are $1 \times 2 \times z$. Both are  only shifted in one direction as see in figure \ref{fig:bg:1D_conv}. These 1D convolutions might detect features like rising and falling edges and the later layers might combine these features into concepts like peaks and troughs. However, as always in machine learning what the network actually does to reach its objective is not controlled by the programmer.

\begin{figure}[H]
    \centering
    \includegraphics[width=.4\linewidth]{bg_1D_conv}
    \caption{Example of a 1D convolution. A $1 \times 3$ kernel is shifted over a spectrum $I$ discretized at 7 wavelengths}
    \label{fig:bg:1D_conv}
\end{figure}
\vspace{1.5cm}

\paragraph{Dropout Layer} ~\\
In 2014 Srivastava et al.\cite{Srivastava2014} presented a method to prevent overfitting and speed up the training process of large Neural Networks. During training, for each step, they randomly drop a number of neurons in a layer along with all connections to and from these neurons. This prevents the neurons from co-adapting \cite{Srivastava2014} and because there are less weights and biases to tune for each step the training becomes overall faster.
These layers are characterized by their \textit{drop rate} \label{hyp:dropout} that determines what fraction of neurons should be dropped. The process of dropping neurons is shown in figure \ref{fig:bg:dropout}.

\begin{figure}[H]
\centering
\begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[width=.9\linewidth]{bg_no_dropout}
    \caption{no dropout}
    \label{}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[width=.9\linewidth]{bg_dropout}
    \caption{with dropout}
    \label{}
\end{subfigure}
\caption{Example of a dropout applied to the bottom layer. Only two of the neurons remain active and only their weights and biases are modified during this training step. \cite{Srivastava2014}}
\label{fig:bg:dropout}
\end{figure}


\subsection{Interaction between agents}

\subsubsection{Introduction}

Previously actions map to states. Not now.

\subsubsection{More intro}

Previously we modelled utility as a function of variables in control of the agent, or constants. We now add another type of term: variables controlled by other agents.

Consider a simple pair of agents:

\(u_a=f_a(x_a,y_a)\)

\({actions_a}=\{x_a,y_a\}\)

\(u_b=f_b(x_b,y_b)\)

\({actions_b}=\{x_b,y_b\}\)

Each agent’s decision does not affect the other agent. Consider now a utility function:

\(u_a=f_a(x_a,y_a)\)

\({actions_a}=\{{x offer}; {y offer}\}\)

\(u_b=f_b(x_b,y_b)\)

\({actions_b}=\{accept; reject\}\)

Where \(a\) offers a trade to \(b\) and \(b\) accepts or rejects. This is an example of a sequential game. There are many types of game, with differing implications.


\subsection{Group extension}

This defines a group \(G\) from a normal subgroup \(N\) and a quotient group \(Q\).


\chapter{Computational complexity}

There are two computational resources we concern ourselves with:
time and space.
The unit of time is arbitrary.
Number of steps. Each step takes the same amount of time.
Each configuration transition uses the same amount of time.

The time used by that computation is the length of the corresponding path.
Formally the time required by the machine
to move from configuration $a$ to $b$ is
the smallest natural number $n$ such that $\beta^n a = b$.
By definition, the machine \emph{moves in one unit time} from configuration $x$ to $y$ iff $\beta x = y$
so $\beta$ depends on the set of primitive operations we equip the machine with.

The \emph{time-to-termination} of a configuration $x$,
written $\TC \beta x$,
is the smallest natural number $n$ such that $\beta^n x$ is terminal.
The time-to-termination of $x$ is the length of the shortest path from $x$ to a terminal configuration.

The maximum space usage of a computation is
the maximum of the space usages of the vertexes of the corresponding path.
Now suppose that we write $s x$ as the \emph{space usage} of configuration $x$.
The space usage of an initial configuration is the size of the input.
We define $\SC \beta x$,
the \emph{maximum-space-to-termination} of a computation from $x$
as follows:
\begin{equation}
    \SC \beta x = \max_{c \in C \beta x} s c
\end{equation}
where we define
$C \beta x = \{ \beta^k x \,|\, k \in \mathbb N \}$
as the set of all configurations
that can be reached from $x$ by following $\beta$.

\section{Time class}

What can a machine compute in a given number of steps?
Given more time, does a machine compute more?

What is the relationship between the size of the input and the running time?
What is the relation between the size of
an initial configuration and its time-to-termination?
How fast does the time-to-termination grow?

We are talking about a special kind of problems
whose time usage depends only on the length of the input.

A \emph{time class} is a set of all initial configurations that have the same time-to-termination.
Define the \emph{time class $n$ of machine $D$},
written $\Teq D n$ (or just $\Teq n$ when the machine is clear in the context),
as the set of every initial $D$-configuration
whose time-to-termination equals $n$.
Then define $\Teqsum n$, the \emph{max-time class $n$},
as the set of every initial configuration whose time-to-termination is less than $n$:
\begin{equation}
    \Teqsum n = \bigcup_{k = 0}^{n - 1} \Teq k
\end{equation}

For example, if the machine ignores its input and runs in constant time,
$\Teqsum 1 = I$.

\newcommand{\Cset}{\mathbf{C}}
Define $\Cset n$ as the set of every initial configuration whose size is less than $n$.
The \emph{time simplicity function of the machine} is
\begin{equation}
    K n = \frac{\mu(\Teqsum n)}{\mu(\Cset n)}
\end{equation}
(Find a better name?)
Higher $K n$ means faster computation.
The \emph{space simplicity function} of the machine is defined analogously:
\begin{equation}
    J n = \frac{\mu(\mathbf S n)}{\mu(\Cset n)}
\end{equation}

If the alphabet used is the binary alphabet $\{ 0, 1 \}$
and the input is a natural number encoded using the usual binary positional encoding,
then $\mu (C n) = 2^n$ and thus $\mu (\Cset n) = 2^{n + 1} - 1$.

If every instance $x$ of size $\mu x$ is solved by machine
(if the time-to-termination of each initial configuration $x$ of size $\mu x$ is less than $f(\mu x)$)
then we say that the problem is size-bounded by $f$.

Is there an $m$ such that for all $n > m$, we have $\Teq n = \varnothing$?
Only if the machine does not read all its input?

Now we examine the relation between the size of the initial configuration
and the time to termination of that configuration.
Intuitively, when the problem is non-trivial, as the initial configuration grows larger,
the machine should require more time to arrive at the related terminal configuration.
If the problem is non-trivial then a bigger initial configuration
should imply a higher time to termination of that configuration.

The minimum time-to-termination of every initial configuration of size $n$.

The maximum size of every initial configuration with time-to-termination of $n$.

The sets of functions computable by deterministic and nondeterministic machines are the same?

$\Teq n$ may be empty?

$\Teq n$ and the length of.

Define space equivalence class $n$ as $\Seq n$ as the set of
every configuration that has a maximum-space-to-termination of $n$.

Both $\TC$ and $\SC$ are functions.
Are they computable?
$C \beta$ is also a function.

Every configuration following $x_0$ is fully determined by $x_0$.
The computation is fully determined by its first configuration.
A machine is deterministic in the sense that given a configuration,
the computation that proceeds from that configuration is always the same.
What can graph theory say about computation?
What result in graph theory helps us discover something in computation theory?
Weighted graph can model computation with nonuniform transition time.
But for what?
Modeling modern machines with speculative execution?

We say that an algorithm $a$ is in $\TIME(O(f n))$ where $n$ is the length of the input iff
for infinitely many (but not necessarily every) $i$ in each initial configuration
$x \equiv (a,i)$ that eventually terminates, we have $\TC x \in O(f(s x))$.

Determining if a number is divisible by $m$ is a constant-time operation in a machine with alphabet of size $m$,
but is it also constant-time operation in a machine with another base that is coprime to $m$?

\section{Fair coding scheme}

How to code almost anything into a bit string?

How to code members of type $t$ into bits?

How do we constrain the coding function so that meticulous mathematicians
cannot cheat by shifting the computation into the coding function?

Let $\mu t : t \to \Nat$ be the \emph{canonical measure} of an element of the countable type $t$.

Let $c t : t \to \Bits$ be the coding function.
This coding function must be measure-preserving, size-preserving.
Formally the coding function must satisfy
\[
    \mu t x \le \mu t y \iff \mu \Bits (c t x) \le \mu \Bits (c t y)
\]
for each $x : t$ and $y : t$.

\section{Terminology and notation}

A \emph{list} $x$ of $X$ of length $n$ is $[x_0,x_1,\ldots,x_{n-1}]$
where each $x_k$ has the type $X$.
The list $x$ has type $X^*$ (the Kleene closure of $X$).
The empty list is written $[]$.
Lists are also known as \emph{strings}.

An \emph{instance} is a string.
A \emph{problem} is a set of instances.
A problem is also called a \emph{language}.

A \emph{complexity class} is a set of problems.

We write $\TC_M e$ to mean the number of time units required by machine $M$
to evaluate expression $e$.
Sometimes $M$ is omitted so we write only $\TC e$
such as when the machine is not too relevant
or is clear in the context.

To evaluate an expression is to reduce it until it becomes a value.
A value is an expression that reduces to itself.

An \emph{$X$-decider} is an implementation of a function having the type $X \to \mathbb B$.
We say that the decider \emph{accepts} the input $x$ iff $fx$ is true.
The \emph{language} recognized by the decider is the set
\begin{align*}
    \langset f = \{ x ~|~ x : X, ~ fx \}
\end{align*}

We say that $b$ is a time usage lower bound of decider $f$ iff $fx \in \Omega b$.
We say that $b$ is the time usage infimum of that decider iff
for all $c$ that is a time usage lower bound of $f$,
$b$ is a time usage lower bound of $f$ and $b \in \Omega c$.

The \emph{decider set} of a language \(L\) is \(\decset L = \decset L = \{ f ~|~ \langset f = L \}\).
It is the set of all deciders whose language is \(L\).
We say $f \leTC g$ iff $\forall x \in X^* ~ \TC(fx) \in O(\TC(gx))$.

$f$ is a \emph{minimum-time decider} of $L$ iff for each $g \in \decset L$,
it holds that $\forall x \in X^* ~ \TC(fx) \in O(\TC(gx))$.
In other words, such $f$ is an infimum of $\decset L$ according to $\leTC$.

\begin{msco}[nonexistence of time usage supremum]
    $\decset L$ has no supremum according to $\leTC$.
    For each decider $f \in \decset L$, there exists an asymptotically slower $g \in \decset L$.
    \begin{align}
        \forall f \in \decset L ~ \exists g \in \decset L ~ \forall x \in X^* ~ \TC(fx) \in o(gx)
    \end{align}
\end{msco}

\begin{mcor}[decider set equivalence class]
    We can define two deciders as $f$ and $g$
    as equivalent iff for all input $x$,
    their time usage is asymptotically similar.
    \begin{align}
        \mathcal E m p L = \{ f ~|~ \langset f = \decset L, ~ \forall x \in X^* ~ \TC_m(fx) \in \Theta(\TC_m(px)) \}
    \end{align}
\end{mcor}

\begin{msco}[NTIME upper bound]
    Let $N$ be a nondeterministic machine.
    The number of time units required by $N$
    to evaluate $\SDP fx$ is bounded above as follows
    where $n$ is the length of $x$:
    \begin{align}
        \TC_N(\SDP fx) \in O\left(n + \max_{s \sqsubseteq x} (\TC(fs))\right)
    \end{align}
\end{msco}

\begin{msco}[DTIME upper bound]
    Let $D$ be a deterministic machine.
    The number of time units required by $D$
    to evaluate $\SDP fx$ is bounded above as follows
    where $n$ is the length of $x$:
    \begin{align}
        \TC_D(\SDP fx) \in O \left( \sum_{s \sqsubseteq x} \TC(fs) \right)
    \end{align}
\end{msco}

A \emph{$g$-transformer} of a decider $f$ is a function $g : X^* \to X^*$
such that $fx = f(gx)$ for all $x : X^*$.
If $\TC(fx) \in o(\TC(f(gx)))$ then
we call the $g$-transformer a \emph{$g$-speedup}.
On the other hand if $\TC(fx) \in \omega(\TC(f(gx)))$ then
we call the $g$-transformer a \emph{$g$-slowdown}.

\begin{mcon}[DTIME lower bound]
    For each deterministic machine $D$,
    $\TC_D(\SDP fx) \in \Omega(m^n)$ for all $f : X^* \to \mathbb B$
    and $x : X^*$
    where $|X| = m$
    and $|x| = n$.
\end{mcon}

\begin{mcon}[existence of a certain decider]
There exists an alphabet $X$
and an $X^*$-decider $f$ such that
for each list $x : X^*$ of length $n$,
the following two statements hold
\begin{align}
    \TC_D(\SDP fx) &\in \Omega 2^n
    \\
    \TC_N(\SDP fx) &\in O n
\end{align}
where $D$ and $N$ are the deterministic machine
and the nondeterministic machine from the two previous conjectures.
If such $f$ exists, then $\PTIME \neq \NPTIME$.
\end{mcon}

\begin{mcon}
    If $f = f \circ g$ for all $f$ then $g = \id$.
\end{mcon}

\begin{mcon}[existence of a PNP decider]
Such decider cannot have overlapping subproblem
and cannot have optimal substructure.
There is no mathematical identity that allows decider to be computed faster.
If
\begin{align}
    \neg\exists p ~ \forall x \in \{ a | a \in X^*, p a \} ~ \exists y ~ fx = fy
\end{align}
then $f$ exists.
\end{mcon}

Proof by contradiction:
suppose that for every decider,
there exists a mathematical identity that allows it to be computed faster.
\begin{align}
    \forall f ~ \exists p ~ \forall x \in \{ a | a \in X^*, p a \} ~ \exists y ~ fx = fy
\end{align}
Then what?

\section{Machines}

\begin{mdef}[standard machine]
    The standard machine with alphabet $X$
    has the following primitive operation set:

    Every constant of type $X$.

    Every unary operation of type $X \to X$.

    Every binary operation of type $X \to X \to X$.

    Every ternary operation of type $X \to X \to X \to X$.
    One of these ternary operations is the three-way branch operation:
    $pctf$ is $t$ iff $c \neq 0$; $f$ otherwise.

    Function application.

    Function composition.

    Some list operations: $\fnull : X^* \to X$,
    $\fhead : X^* \to X$,
    $\ftail : X^* \to X^*$,
    and $\fcons : X \to X^* \to X^*$.

    A fixed-point combinator $y : \forall a ~ (\alpha \to \alpha) \to \alpha$ satisfying $yf = f(yf)$
    such that the expression $yf$ reduces to $f(yf)$ in one time unit.
\end{mdef}

\section{Recursion}

\begin{mlem}
    The type of the Y-combinator is $\forall a ~ (\alpha \to \alpha) \to \alpha$.
    \begin{proof}
        The definition is $yf = f(yf)$.
        \begin{align}
            f &: \alpha
            \\
            r &: \alpha \to \beta
            \\
            yf &: \beta
            \\
            f &: \beta \to \gamma
            \\
            f(yf) &: \gamma
            \\
            yf : \beta, \ f(yf) : \gamma, \ yf = f(yf) &\implies \beta = \gamma
            \\
            f : \alpha, \ yf : \beta, \ f(yf) : \gamma &\implies f : \beta \to \gamma, \ \alpha = \beta \to \gamma
        \end{align}
    \end{proof}
\end{mlem}

Recursive has to do with fixpoints.

\section{Nondeterminism}

In a nondeterministic machine, $\ambc x y$
has the same effect as reducing $x$ and $y$ in parallel in one unit time.
Let the accepting computation be $z$ where $z$ is either $x$ or $y$.
\begin{align}
    \TC(\ambc xy) &= \TC z
\end{align}

\section{Notation}

$a : A$ or $a \in A$ means the type of $a$ is $A$,
or $a$ is in $A$,
or $a$ is an element of $A$.

$A \to B$ is the type of every function
that takes any $a \in A$ and returns any $b \in B$.

Concatenation means function application:
$fx$ means $f(x)$ in standard mathematical notation.
$fxy$ means $f(x,y)$ in standard mathematical notation,
but the former one is with currying.
$f0$ can mean $f(0,y)$ which is a function of $y$ only.

If $f : A\to B$ and $x:A$, then $fx : B$.

If $f : A\to B\to C$, $x:A$, and $y:B$, then $fxy : C$.

\begin{mcor}[number of deciders]
    Let $|X| = m$.
    The number of total mappings of type $X^n \to \mathbb B$ is
    \begin{align}
        2^{m^n}
    \end{align}
    The number of total mappings of type $(X^0 \cup X^1 \cup \ldots \cup X^n) \to \mathbb B$ is:
    \begin{align}
        \sum_{n=0}^{\infty} 2^{m^n}
    \end{align}
    There are $m^n$ boxes and each box can contain either $\syes$ or $\sno$.
\end{mcor}

\begin{mdef}[Ambiguous operator]
    The \emph{ambiguous operator} $\amb : A^* \to A$
    takes a list and returns an element of that list
    such that the decider containing the amb-expression is led to $\syes$.
\end{mdef}

    The following is a nondeterministic algorithm:
    \begin{align}
        \SDP fx &= gfx[] & \text{where}
        \\
        gfxy &= \fite{\fnull x}{fy}{gf(\ftail x)(\amb[y, \ftail y])}
    \end{align}

\begin{mlem}[existence of decider bounded below by LIN]
There exists a decider that cannot be computed
in less than linear time
by the standard machine.
Formally there exists an $X^*$-decider $f$ such that
for each list $x : X^*$ of length $n$,
$\TC(fx) \in \Theta n$.
\begin{proof}
    Consider the decider that decides whether zero
    is the modulo-$m$ sum of all elements in the input list of $X$s
    where $X$ is a finite subset of $\mathbb N$ of size $m$.

    $f x = [\sum_{k=0}^{n-1} x_k = 0]$
\end{proof}
\end{mlem}

    \begin{align}
        \ambc y &= \fite{\fnull y}{y}{\amb[\fhead y :: \ambc (\ftail y), \ambc (\ftail y)]}
    \end{align}

\begin{mcon}
Corollary:
If $\TC_D(\SDP fx) \in \Omega(2^n \cdot n)$ and $\TC_N(\SDP fx) \in O n$,
there exists a problem that is in NP but not in P;
therefore $P \subset NP$.
\end{mcon}

Prove that the only $g$ that satisfies $fx = f(gx)$ is $\text{id}$.

To prove that $\TC (fx) \in O(gn)$,
write an algorithm that is in that time complexity class.

To prove that $\TC (fx) \in \Omega(gn)$, ...

Function Constancy Check Problem/Function Constancy Decider.

Given an almost constant $X^n$-decider, find the only $x$ that differ.

An $X$-decider is almost constant iff $f^{-1}\syes = \{\}$.

This will also prove P neq NP:
Find $f$ and $g$ such that $\forall x \in X^* ~ fx = gx$ but $\TC_D(fx) \subset \TC_N(gx)$

\section{Computational complexity}

A set is \emph{computable} iff there is an algorithm (a finite description)
for its indicator function.

\section{Lax monoidal functors}

A category $C$ is defined by $\ob C : \Set\alpha$ and $\hom C : \Set(\alpha, \alpha))$ such that
associative and preserve identity
\begin{enumerate}
    \item $(f \circ g) \circ h = f \circ (g \circ h)$ for all $f,g,h : \hom C$.
    \item $1_C \circ f = f \circ 1_C = f$ for all $f : \hom C$.
\end{enumerate}

Functor is $F$:
\begin{enumerate}
    \item $f : (A \to B) \to (FA \to FB)$.
\end{enumerate}

Also known as `monad' in Haskell.

A lax monoidal functor $F$ takes a set.
\begin{enumerate}
    \item Zero element $F_0 : FA$.
    \item Lifting morphism $F_1 : A \to FA$.
    \item Internal operation on Kleisli category $f : FA \to (A \to FB) \to FB$.
\end{enumerate}

\section{Monads}

Let there be the following type functions:
\begin{align}
    \mM A &= \{ \mM_0 \} \cup \{ \mM_1 a ~|~ a \in A \}
 \\ \mL A &= \{ \mL_0 \} \cup \{ \mL_1 h t ~|~ h \in A, ~ t \in \mL A \}
 \\ \mP A &= \{ \mP X ~|~ X \subseteq A \}
\\ \mE AB &= \{ \mE_0 a ~|~ a \in A \} \cup \{ \mE_1 b ~|~ b \in B \}
\end{align}
In Haskell, $\mM$, $\mM_0$, and $\mM_1$ are known as Maybe, Nothing, and Just;
and $\mL$, $\mL_0$, and $\mL_1$ are known as list type function ([]), the empty list ([]), and the list constructor (:).

\begin{align}
    \sigma_M &: MA \to (A \to MB) \to MB
\end{align}

For \mM, $\sigma$ is defined as
\begin{align}
    \sigma \mM_0 f &= \mM_0
    \\ \sigma (\mM_1 a) f &= fa
\end{align}

For \mL, $\sigma$ is defined as
\begin{align}
    \sigma \mL_0 f &= \mL_0
    \\ \sigma (\mL_1 h t) f &= [\amb (fh \cdot \sigma tf)]
\end{align}
where $\amb : \mL A \to A$ is McCarthy's ambiguous operator
and $\cdot$ is list concatenation.
The operator $\amb$ picks an element leading to accepting path
in zero time without computing the other elements.

For \mP, $\sigma$ is defined as
\begin{align}
    \sigma (\mP S) f &= \{ \amb \{ f x ~|~ x \in S \} \}
\end{align}

\section{\mM-extended string}

\begin{align*}
    x_n' &= \begin{cases}
 \mM_1 x_n &: n \text{ is a valid index into input string}
  \\ \mM_0 &: \text{otherwise}
\end{cases}
\end{align*}

\section{Definition of computation via expression reduction}

The grammar for expression:
\begin{align}
    Exp &::= X
      \\ &| -Exp
      \\ &| (Exp)
      \\ &| Exp + Exp
      \\ &| Exp \cdot Exp
\end{align}

A finite countable set $X$.

There are $n^{n \cdot n}$ possible binary operations on a set of $n$ elements.
We assume using space-time-tradeoff that some of them can be performed in constant time.

A \emph{primitive expression} is an expression whose time cost is one unit.
We assume that these are the \emph{only} primitive operations:
\begin{enumerate}
    \item modulo-$m$ arithmetic operations:
            negation ($-a$),
            addition ($a + b$),
            subtraction ($a - b$),
            and multiplication ($a \cdot b$).
    \item every unary operation in $N_m$ and every binary operation in $N_m$
    \item every unary operation in $\mathbb B = \{0,1\}$ and every binary operation in $\mathbb B$
    \item comparison: comparing equality $(=) : X \to X \to \mathbb B$
        and (unsigned) ordering $(<) : X \to X \to \mathbb B$,
        and three-way conditional ($Cctf$: if $c$ then $t$ else $f$ where $t,f:\alpha$ and $c:\mathbb B$).
    \item primitive list operations:
        \begin{enumerate}
            \item \fnull: determining whether a list is empty
            \item \fhead: taking the first element (partial function)
            \item \ftail: taking all but the first element (partial function)
            \item constructing a list by prepending one element to a list (::)
        \end{enumerate}
\end{enumerate}
For each constant expression $e$, $\tau e = 0$.

A \emph{primitive value} is a value whose space cost is one unit.
\begin{align}
    \forall x \in X \quad \sigma x &= 1
    \\ \forall x \in (A,B) \quad \sigma x &= \sigma a + \sigma b
     \\ \forall fx \in \{L a | a \in A\} \cup \{R b | b \in B\} \quad \sigma (fx) &= 1 + \sigma x
\end{align}
Example:
\begin{align}
    \sigma[1,2,3] &= \sigma(1::2::3::[])
               \\ &= \sigma (L1(L2(L3L_0)))
               \\ &= 1 + \sigma 1 + \sigma (L2(L3L_0))
               \\ &= 1 + 1 + 1 + \sigma 2 + \sigma (L3L_0)
               \\ &= 3 + 1 + 1 + \sigma 3 + \sigma L_0
               \\ &= 5 + 1 + 1
               \\ &= 7
\end{align}

For example, the following $f$ performs modulo-$m$ summation:
\begin{align}
     fx &= C (\fnull x) 0 (\fhead x + f(\ftail x))
\end{align}

The space and time cost for reducing an expression is $\sigma E$ and $\tau E$ respectively.

\section{Definitions}

A \emph{problem} is a set of its instances.
An instance is a pair of question and answer.
The question is a string of the input alphabet.
The answer is a string of the output alphabet.
A question may have more than one answer.
Each question must have at least one answer.

An \emph{$\alpha$-machine} has a \emph{transition function}
$t : (S,\mM X) \to \alpha S$
where $S$ is the \emph{state type},
$X$ is the \emph{input alphabet},
and $\alpha$ determines the way the machine performs computation.
$X$ must be finite and countable.
$S$ must be countable.
$S$ may contain a special elements:
the accepting state \syes.
Formally, a \emph{machine} is a 4-tuple $(\alpha,X,S,t)$ where
\begin{align}
    X &: \Fin
 \\ S &: \Set
 \\ t &: (S,\mM X) \to \alpha S
\end{align}

Once something is accepted or rejected, it is final:
\begin{align}
    \forall x \quad t (\syes,x) &= \pi \syes
  \\ \forall x \quad t (\sno,x) &= \pi \sno
\end{align}
where $\pi : S \to \alpha S$ is the $\alpha$-lifting function.

The transition function must be total
and it must be an semi-algorithm;
it must be able to be described
in a finite number of (what?) elementary operations.
It must go into an infinite loop when the answer is no.

A \emph{path} of that machine for input $x = [x_0,\ldots] \in X^*$ is $s = [s_0,\ldots] \in S^*$.
The computation performed by that machine is a repeated application of the transition function:
\begin{align*}
    s_n &= \sigma (t (s_{n-1}, x_n'))
\end{align*}
where $\sigma$ is defined according to $\alpha$
and $x'$ is \mM-extended $x$.
The initial state is $s_0 \in S$.
The path is an \emph{accepting path} iff $\syes$ is in that path.
The machine \emph{accepts} an input iff the path for that input is an accepting path.

The \emph{running time} for that input is the length of the corresponding path.

The \emph{maximum space usage} is: (maximum or supremum?)
\begin{align}
    \max_{x \in s} (\mu x)
\end{align}

Deterministic transition function type is $(S,\mM X) \to S$.
Nondeterministic transition function type is $(S,\mM X) \to \mP S$.

Nondeterministic machine can \emph{look into the future}
to \emph{guess an accepting path};
deterministic machine cannot.
Given the same input, a deterministic machine
will always go through the same path of computation.
Given the same input, a nondeterministic machine
might go through another path of computation.

We say that a language is in $\aTIME f$ iff
there exists a constant $k$ and an $\alpha$-machine
such that the length of the shortest path of that machine
for each acceptable input $x$ is in $O(f(\mu x))$.

\begin{align}
    \DTIME &= \idTIME
 \\ \NTIME &= \mPTIME
\end{align}

\section{Example machines}

This machine accepts all inputs:
\begin{align*}
    S &= \{ \syes \}
    \\ s_0 &= \syes
 \\ t(s,x) &= \pi s
\end{align*}
This machine does not accept any input:
\begin{align*}
    S &= \{ \sno \}
    \\ s_0 &= \sno
 \\ t(s,x) &= \pi s
\end{align*}
This machine accepts the language $\{1\}^*$:
\begin{align*}
    S &= \{ s_0, \syes, \sno \}
    \\ t(s,x) &= \text{case $(s,x)$ of} \begin{cases}
      (s_0, \mM_1 1) &\pi s_0
        \\ (s_0, \mM_0) &\pi \syes
 \\ \text{otherwise} &\pi \sno
\end{cases}
\end{align*}

Assume that $X = \{0,1\}$.
\begin{enumerate}
    \item How many languages can an $\alpha$-machine with $n$ states accept?
    \item How many states are needed for an $\alpha$-machine to recognize a given language?
    \item How many transition functions are possible for a machine with $n$ state?
\end{enumerate}

\section{Languages accepted by a machine}

Let $\mu X = \mu Y = 2$.

Types are measurable:
\begin{align}
    \mu(A\to B) &= \mu A \cdot \mu B
    \\ \mu(A,B) &= \mu A \cdot \mu B
    \\ \mu(\mM A) &= 1 + \mu A
    \\ \mu(\mL A) &= 1 + \mu A \cdot \mu(\mL A)
    \\ \mu(\mP A) &= \mu(2^A) & \text{if $A$ is countable}
\end{align}
Hypernatural measures:
\begin{align}
    \mu A = \omega &\implies \mu(\mM A) = \omega
    \\ \mu A > 0 &\implies \mu(\mL A) = \omega
    \\ \mu A < \omega &\implies \mu(\mP A) = 2^{\mu A}
\end{align}

How many transition functions does a \mM-machine have?

How many languages can be accepted by \mM-machine with $\mu S = 2$?

Suppose that a problem is in NP.
Then there exists a constant $k$ such that
the length of the shortest nondeterministic path
for valid input whose size is in $O(n)$ is in $O(n^k)$.

The time complexity measure of a computation is
the length of the path of that computation.

The set of regular languages is $\DSPACE(O(n)) \cap \DTIME(O(n))$.

\section{Speedup theorem?}

Alphabet size can be exchanged with state size.
Space can be traded for time?

\section{Example: modulo-$m$ subset-sum problem}

$X = \{0,1,2,3,\ldots,m-1\}$.
$\syes$ iff there exists $N \subseteq \mathbb N$ such that
\begin{align}
    \sum_{k \in N} x_k &= 0
\end{align}
where addition is done modulo-$m$.

The modulo-$m$ subset-sum problem is in $\NTIME(O(n))$ and is in $\NSPACE(O(m))$
where $n$ is the length of the input.

\begin{align}
    S &= \{ S_0 \} \cup \{ S_1 n ~|~ n \in X \}
    \\ s_0 &= S_0
\end{align}
$t$:
\begin{align}
    (S_1 0, x) &\to \{ \syes \}
    \\ (S_1 s, \mM_1 x) &\to \{ S_1 s, S_1 (s+x) \}
    \\ (S_0, \mM_1 x) &\to \{ S_0, S_1 x \}
\end{align}

\section{Some Haskell code}

\begin{verbatim}
type Tr s x y = (s, Maybe x) -> (Maybe s, Maybe y)

run :: Tr s x y -> s -> [x] -> [y]
run tr state input =
    let
        run' s xs =
            let
                (mx,xs') = case xs of
                    [] -> (Nothing, [])
                    x : t -> (Just x, t)
                (ms',my) = tr (s,mx)
                ys = case ms' of
                    Just s' -> run' s' xs'
                    Nothing -> []
            in
                maybe id (:) my ys
    in
        run' state input
\end{verbatim}

\section{Example: 3-SAT in NP}

Encode a boolean expression.

$X = \{ T, F, A, 0, 1, 2, N, C, D \}$

The grammar for the input is \verb@inp@:
\begin{verbatim}
inp     ::=     asgs A exp
asgs    ::=     empty | asg asgs
asg     ::=     T | F
exp     ::=     0 | 1 | 2
        |       N exp
        |       C exp exp
        |       D exp exp
\end{verbatim}

$A$ separates the assignment and the expression.

The state type is a tuple of three boolean values.

For example, the expression $v_0 \wedge v_1 \vee \neg v_2$ with truth assignment $(v_0,v_1,v_2) = (T,F,F)$ is encoded as TFFDC01N2.

There are $n$ variables.

SAT is in NP iff SAT is verifiable in P.

Constant space. Linear time.

\section{Is there a bijection?}

\begin{align}
    \mathbb N &\iff 2^\mathbb N
    \\ 0 &\iff \{\}
    \\ 1 &\iff \{0\}
    \\ 2 &\iff \{1\}
    \\ 3 &\iff \{0,1\}
    \\ 4 &\iff \{2\}
    \\ 5 &\iff \{0,2\}
    \\ 6 &\iff \{1,2\}
    \\ 7 &\iff \{0,1,2\}
\end{align}
will enumerate all of $2^\mathbb N$?

But Cantor's theorem.

We can construct $x \in 2^\mathbb N$ that has no counterpart in the above bijection.
Counterintuition of infinity.

Binary numbering of $2^\mathbb N$.


%\documentclass{book}
%\usepackage{amsmath}
%\usepackage{bm}
%\begin{document}

\chapter{Map factor}
\label{chap: map factor}
{\bf \Large
\begin{tabular}{ccc}
\hline
  Corresponding author & : & Seiya Nishizawa\\
\hline
\end{tabular}
}

\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}

\section{Coordinate transform}
A orthogonal rectangular coordinate $(x, y, z)$.
A orthogonal curvilinear coordinate $(\xi, \eta, \zeta)$.

The transform is defined by
\begin{align}
  \bm{e}_\xi &= \pd{x}{\xi}\bm{e}_x + \pd{y}{\xi}\bm{e}_y + \pd{z}{\xi}\bm{e}_z, \\
  \bm{e}_\eta &= \pd{x}{\eta}\bm{e}_x + \pd{y}{\eta}\bm{e}_y + \pd{z}{\eta}\bm{e}_z, \\
  \bm{e}_\zeta &= \pd{x}{\zeta}\bm{e}_x + \pd{y}{\zeta}\bm{e}_y + \pd{z}{\zeta}\bm{e}_z.
\end{align}
Reverse transform is
\begin{align}
  \bm{e}_x &= \pd{\xi}{x}\bm{e}_\xi + \pd{\eta}{x}\bm{e}_\eta + \pd{\zeta}{x}\bm{e}_\zeta, \\
  \bm{e}_y &= \pd{\eta}{y}\bm{e}_\xi + \pd{\eta}{y}\bm{e}_\eta + \pd{\zeta}{y}\bm{e}_\zeta, \\
  \bm{e}_z &= \pd{\zeta}{z}\bm{e}_\xi + \pd{\eta}{z}\bm{e}_\eta + \pd{\zeta}{z}\bm{e}_\zeta.
\end{align}

The Jacobian matrix is $\{\pd{\xi^k}{x^i}\}$.

The reverse transform after the transform of the transform after the reverse transform make a vector to the original vector;
\begin{align}
  \pd{\xi^k}{x^i}\pd{x^i}{\xi^l} &= \delta_l^k, \\
  \pd{x^i}{\xi^k}\pd{\xi^k}{x^j} &= \delta_j^i,
\end{align}
where index which appares upper and lower suffix in a single term implies summation of the term over set ${1,2,3}$ (Einstein notation).

Spatial parial derivative is tranformed with the Jacobian matrix (covariant transform);
\begin{align}
  \pd{}{\xi^k} &= \pd{x^i}{\xi^k}\pd{}{x^i}, \\
  \pd{}{x^i} &= \pd{\xi^k}{x^i}\pd{}{\xi^k}.
\end{align}

Velocity is transformed with the inverse of the Jacobian matrix (cotravariant transform);
\begin{align}
  d\xi^k &= \pd{\xi^k}{x^i} dx^i, \\
  dx^i &= \pd{x^i}{\xi^k} d\xi^k.
\end{align}

The metric tensor, $g_{kl}$ is defined by
\begin{equation}
  g_{kl} = \bm{e}_k \cdot \bm{e}_l
  = \left(\pd{x^i}{\xi_k}\bm{e}_i\right) \cdot \left(\pd{x^j}{\xi_l}\bm{e}_j\right)
  = \pd{x^i}{\xi_k}\pd{x^j}{\xi_l} (\bm{e}_i\cdot\bm{e}_j).
\end{equation}

For orthogonal curvilinear coordinates, the matrix ${g_{kl}}$ is diagonal.
Metric factor, $h_k$ is defined as
\begin{equation}
  h_k^2 = g_{kk} = \sum_i \left(\pd{x^i}{\xi_k}\right)^2.
\end{equation}

Here we define the matrix, $\bm{E}_\xi$ is
\begin{equation}
  \bm{E}_\xi =
  (\bm{e}_\xi \bm{e}_\eta \bm{e}_\zeta)\cdot \bm{H}^{-1}
  = \bm{E}_x \cdot \left\{\pd{x^i}{\xi^k}\right\} \cdot \bm{H}^{-1},
\end{equation}
where $\bm{E}_x = (\bm{e}_x \bm{e}_y \bm{e}_z)$, and
\begin{equation}
  \bm{H} = \left(\begin{array}{ccc} h_1 & 0 & 0\\ 0 & h_2 & 0\\ 0 & 0 & h_3\end{array}\right).
\end{equation}
The vector $\frac{1}{h_k}\bm{e}_k$ is unit vector and orthogonal each other,
so the inverse of the $\bm{E}_\xi$ is $\bm{E}_\xi^T$.
\begin{align}
  \left( \bm{E}_x \cdot \left\{\pd{x^i}{\xi^k}\right\} \cdot \bm{H}^{-1} \right)^{-1} &= \left( \bm{E}_x \cdot \left\{\pd{x^i}{\xi^k}\right\} \cdot \bm{H}^{-1} \right)^T, \nonumber\\
  \bm{H} \cdot \left\{\pd{\xi^k}{x^i}\right\} \cdot \bm{E}_x^{-1} &= \bm{H}^{-1} \cdot \left\{\pd{x^i}{\xi^k}\right\}^T \cdot \bm{E}_x^T, \nonumber
\end{align}
\begin{align}
  \left\{\pd{\xi^k}{x^i}\right\} &= \bm{H}^{-2} \cdot \left\{\pd{x^i}{\xi^k}\right\}^T \cdot \bm{E}_x^T \cdot \bm{E}_x \nonumber \\
  &= \bm{H}^{-2} \cdot \left\{\pd{x^i}{\xi^k}\right\}^T.
\end{align}
That is
\begin{equation}
  \pd{\xi^k}{x^i} = \frac{1}{h_k^2} \pd{x^i}{\xi^k}.
\end{equation}

\section{Governing equations}

\subsection{Continuous equiation}

Divergence of $\rho \bm{u}$ is
\begin{align}
  \pd{}{x^i}(\rho dx^i)
  &= \pd{\xi^k}{x^i}\pd{}{\xi^k}\left(\rho \pd{x^i}{\xi^l}d\xi^l\right) \nonumber \\
  &= \pd{\xi^k}{x^i}\pd{x^i}{\xi^l}\pd{}{\xi^k}(\rho d\xi^l)
    +\rho d\xi^l \pd{\xi^k}{x^i} \frac{\partial^2 x^i}{\partial \xi^k \partial \xi^l} \nonumber\\
  &= \pd{}{\xi^k} (\rho d\xi^k) + \sum_k\frac{1}{h_k^2}\rho d\xi^l \pd{x^i}{\xi^k}\frac{\partial^2 x^i}{\partial \xi^k \partial \xi^l} \nonumber\\
  &= \pd{}{\xi^k} (\rho d\xi^k) + \sum_k \frac{1}{2h_k^2}\rho d\xi^l \pd{}{\xi^l}\left(\pd{x^i}{\xi^k}\right)^2 \nonumber\\
  &= \pd{}{\xi^k} (\rho d\xi^k) + \sum_k \frac{1}{2h_k^2}\rho d\xi^l \pd{}{\xi^l}h_k^2 \nonumber\\
  &= \pd{}{\xi^k} (\rho d\xi^k) + \sum_k \frac{1}{2}\rho d\xi^l \pd{}{\xi^l}\ln h_k^2 \nonumber\\
  &= \pd{}{\xi^k} (\rho d\xi^k) + \rho d\xi^k \pd{}{\xi^k}\ln (\prod_l h_l) \nonumber\\
  &= J \left\{ J^{-1}\pd{}{\xi^k} (\rho d\xi^l) + \rho d\xi^k \pd{}{\xi^k}J^{-1}\right\} \nonumber\\
  &= J \pd{}{\xi^k} (J^{-1}\rho d\xi^k),
\end{align}
where $J$ is the Jacobian of the Jacobian matrix and
\begin{equation}
  J = \frac{1}{\prod_k h_k}.
\end{equation}

The continuous equation is
\begin{equation}
\pd{\rho}{t} + J \pd{}{\xi^k}\frac{\rho d\xi^k}{J} = 0.
\end{equation}

\subsection{Momentum equation}

\begin{equation}
  \pd{\rho d\xi^k}{t} = \pd{\xi^k}{x^i} \pd{\rho dx^i}{t}.
\end{equation}

\begin{description}

\item[Advection term]
\begin{align}
  & \pd{\xi^k}{x^i}\pd{\rho dx^idx^j}{x^j} \nonumber\\
  &= \pd{\xi^k}{x^i}\left(dx^j\pd{\rho dx^i}{x^j} + \rho dx^i\pd{dx^j}{x^j}\right) \nonumber\\
  &= \pd{\xi^k}{x^i}\left(\pd{x^j}{\xi^l}d\xi^l\right)\pd{\xi^m}{x^j}\pd{}{\xi^m}\left(\rho \pd{x^i}{\xi^n}d\xi^n\right)
  + \pd{\xi^k}{x^i}\rho \left(\pd{x^i}{\xi^l}d\xi^l\right)\pd{\xi^m}{x^j}\pd{}{\xi^m}\left(\pd{x^j}{\xi^n}d\xi^n\right) \nonumber\\
  &= d\xi^l\pd{\xi^k}{x^i}\pd{}{\xi^l}\left(\rho \pd{x^i}{\xi^n}d\xi^n\right)
  + \rho d\xi^k\pd{\xi^m}{x^j}\pd{}{\xi^m}\left(\pd{x^j}{\xi^n}d\xi^n\right) \nonumber\\
  &= d\xi^l\pd{\xi^k}{x^i}\left\{\pd{x^i}{\xi^n}\pd{}{\xi^l}\left(\rho d\xi^n\right) + \rho d\xi^n \frac{\partial^2 x^i}{\partial \xi^l \partial \xi^n}\right\}
  + \rho d\xi^k\pd{\xi^m}{x^j} \left( \pd{x^j}{\xi^n}\pd{d\xi^n}{\xi^m} + d\xi^n\frac{\partial^2 x^j}{\partial \xi^m \partial \xi^n} \right) \nonumber\\
  &= d\xi^l\pd{}{\xi^l}\left(\rho d\xi^k\right) + \rho d\xi^l d\xi^n\pd{\xi^k}{x^i} \frac{\partial^2 x^i}{\partial \xi^l \partial \xi^n}
  + \rho d\xi^k\pd{d\xi^m}{\xi^m} + \rho d\xi^kd\xi^n\pd{\xi^m}{x^j}\frac{\partial^2 x^j}{\partial \xi^m \partial \xi^n} \nonumber\\
  &= \pd{}{\xi^l}\left(\rho d\xi^k d\xi^l\right) + \rho d\xi^l d\xi^n\pd{\xi^k}{x^i} \frac{\partial^2 x^i}{\partial \xi^l \partial \xi^n}
   + \rho d\xi^kd\xi^l\pd{\xi^m}{x^i}\frac{\partial^2 x^i}{\partial \xi^l \partial \xi^m} \nonumber\\
  &= J\left\{ J^{-1}\pd{}{\xi^l}(\rho d\xi^k d\xi^l) + \rho d\xi^k d\xi^l\pd{J^{-1}}{\xi^l} \right\}
   + \rho d\xi^ld\xi^m\pd{\xi^k}{x^i}\frac{\partial^2 x^i}{\partial \xi^l \partial \xi^m} \nonumber\\
  &= J \pd{}{\xi^l}{J^{-1}\rho d\xi^k d\xi^l} + \rho d\xi^l d\xi^m\Gamma^k_{lm},
\end{align}
where $\Gamma$ is the Christoffel symbols of the second kind, and
\begin{align}
  \Gamma_{lm}^k
  &= \pd{\xi^k}{x^i} \frac{\partial^2 x^i}{\partial \xi^l \partial \xi^m} \nonumber\\
  &= \frac{1}{2}g^{kn}\left( \pd{g_{mn}}{\xi^l} + \pd{g_{ln}}{\xi^m} - \pd{g_{lm}}{\xi^n}\right) \nonumber\\
  &= \frac{1}{h_k^2}\left( h_k\pd{h_k}{\xi^l}\delta_{km}+h_k\pd{h_k}{\xi^m}\delta_{kl}-h_l\pd{h_l}{\xi^k}\delta_{lm}\right),
\end{align}
where $\{g^{kn}\}$ is inverse matrix of $\{g_{kn}\}$.

\item[Coriolis term]
\begin{align}
  \pd{\xi^k}{x^i} \epsilon^{ijp} f^j \rho dx^p
  &= \epsilon^{klm} \frac{1}{h_kh_lh_m}\hat{f}^l d\xi^m,
\end{align}
where $\epsilon$ is the Levi-Civita symbol,
and
\begin{equation}
  \hat{f}^l = \pd{\xi^l}{x^j} f^j.
\end{equation}

\item[Pressure gradient term]
\begin{align}
  \pd{\xi^k}{x^i} \pd{p}{x^i}
  &= \pd{\xi^k}{x^i}\left(\pd{\xi^l}{x^i}\pd{p}{\xi^l}\right)\nonumber\\
  &= \frac{1}{h_k^2}\pd{x^i}{\xi^k}\pd{\xi^l}{x^i}\pd{p}{\xi^l} \nonumber\\
  &= \frac{1}{h_k^2}\pd{p}{\xi^k}.
\end{align}

\end{description}

After all, momentum equation is
\begin{align}
  \pd{}{t} \rho d\xi^k + J\pd{}{\xi^l} \left( J^{-1} \rho d\xi^k d\xi^l \right)
  + \rho d\xi^l d\xi^m \Gamma_{lm}^k
  + \epsilon^{klm} \frac{1}{h_kh_lh_m}\hat{f}^l \rho d\xi^m = -\frac{1}{h_k^2}\pd{p}{\xi^k} + \rho g^p \pd{\xi^k}{x^p}.
\end{align}

\section{Map factor}
We introduce Map factor $m, n$.
\begin{align}
  \frac{1}{m}\frac{a+z}{a} &= h_1, \\
  \frac{1}{n}\frac{a+z}{a} &= h_2, \\
  1 &= h_3,
\end{align}
where is $a$ is radius of the planet.
Assuming shallow atmospher,
\begin{align}
  m &= h_1, \\
  n &= h_2.
\end{align}

Normalized velocity is defined as
\begin{align}
  \hat{u} &= h_1\frac{d \xi}{dt} = \frac{1}{m}\frac{d \xi}{dt}, \\
  \hat{v} &= h_2\frac{d \eta}{dt} = \frac{1}{n}\frac{d \eta}{dt}, \\
  \hat{w} &= h_3\frac{d \zeta}{dt} = \frac{d \zeta}{dt}.
\end{align}

The continuous equation becomes
\begin{equation}
  \pd{\rho}{t} + mn\pd{}{\xi}\frac{\rho \hat{u}}{n} + mn\pd{}{\eta}\frac{\rho \hat{v}}{m} + \pd{}{\zeta}\rho \hat{w} = 0
\end{equation}

The momentum equations are
\begin{equation}
  \pd{\rho\hat{u}^k}{t}
  + mn\pd{}{\xi}\frac{\rho \hat{u} \hat{u}^k}{n}
  + mn\pd{}{\eta}\frac{\rho \hat{v} \hat{u}^k}{m}
  + \pd{}{\zeta}\rho \hat{w} \hat{u}^k
  + m m_k \rho \hat{u} \hat{u}^k \pd{}{\xi}\frac{1}{m_k}
  + n m_k \rho \hat{v} \hat{u}^k \pd{}{\eta}\frac{1}{m_k}
  - m m_k \rho \hat{u}^2 \pd{}{\xi^k}\frac{1}{m}
  - n m_k \rho \hat{v}^2 \pd{}{\xi^k}\frac{1}{n}
  + \epsilon^{klm} m_l \hat{f}^l \rho \hat{u}^m
  = -m_k \pd{p}{\zeta^k} + \rho g \delta_{3k}
\end{equation}

\begin{align}
  \pd{\rho u}{t} &+ mn\pd{}{\xi}\frac{\rho uu}{n} + mn\pd{}{\eta}\frac{\rho uv}{m} + \pd{}{\zeta}\rho uw \\
  &- f\rho v - mn \rho v\left\{v\pd{}{\xi}\left(\frac{1}{n}\right) - u\pd{}{\eta}\left(\frac{1}{m}\right)\right\} = -m\pd{p}{\xi}, \\
  \pd{\rho v}{t} &+ mn\pd{}{\xi}\frac{\rho uv}{n} + mn\pd{}{\eta}\frac{\rho vv}{m} + \pd{}{\zeta}\rho vw \\
  &+f\rho u + mn \rho u\left\{v\pd{}{\xi}\left(\frac{1}{n}\right) - u\pd{}{\eta}\left(\frac{1}{m}\right)\right\} = -n\pd{p}{\eta}, \\
  \pd{\rho w}{t} &+ mn\pd{}{\xi}\frac{\rho uw}{n} + mn\pd{}{\eta}\frac{\rho vw}{m} + \pd{}{\zeta}\rho ww = -\pd{p}{\zeta} -\rho g.
\end{align}

The thermodynamical and tracer equations
\begin{equation}
  \pd{\rho \phi}{t} + mn\pd{}{\xi}\frac{\rho \hat{u}\phi}{n} + mn\pd{}{\eta}\frac{\rho \hat{v}\phi}{m} + \pd{\rho \hat{w}\phi}{\zeta} = 0.
\end{equation}

%\end{document}


\documentclass[12pt]{rudin}
\usepackage[]{amsmath}
\usepackage[]{exercise}
\usepackage[]{enumitem}
\usepackage[colorlinks=true, linkcolor=blue, urlcolor=blue]{hyperref}

\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}

\renewcommand{\ExerciseName}{Problem}
\renewcommand{\ExerciseHeader}{\noindent\textbf{\ExerciseName\ \ExerciseHeaderNB}\ \ExerciseHeaderTitle\ \ExerciseHeaderOrigin\smallskip}
\renewcommand{\ExerciseHeaderOrigin}{(\ExerciseOrigin)}
\renewcommand{\AnswerHeader}{\bigskip\noindent\textbf{Solution \ExerciseHeaderNB}\newline}

\DeclareMathOperator{\lcm}{lcm}
\let\set\mathbf

\title{Number Theory Midterm I}
\author{RDB}
\date{\today}

\begin{document}

\maketitle

\begin{centering}
    \emph{I feel fine today modulo a slight headache. \\ \hfill --- The
    Hacker's Dictionary}
\end{centering}

\paragraph{INSTRUCTIONS} No outside materials (notes, textbook, internet) or
resources (calculators). Leave your webcam on until you submit and I confirm
that I have your exam.

Good luck!

% 1.
\begin{Exercise}
    Use the Euclidean algorithm to compute the greatest common divisor of 153
    and 64. (5 points)
\end{Exercise}

% 2
\begin{Exercise}
    \begin{enumerate}[label=(\textbf{\alph*})]
        \item State Euclid's lemma. (3 points)
        \item Show that, if a prime $p$ divides $a^2$ for some integer $a$,
            then $p$ divides $a$. (5 points)
    \end{enumerate}
\end{Exercise}

\begin{Answer}
    \begin{enumerate}[label=(\textbf{\alph*})]
        \item If $p | ab$ for a prime $p$ and integers $a$ and $b$, then $p |
            ab$.
        \item If $p | a^2 = a \cdot a$, then $p | a$ or $p | a$. So $p | a$,
            clearly.
    \end{enumerate}
\end{Answer}

% 3.
\begin{Exercise}
    Find the general solution to
    \[
        42x + 35y = 2,
    \]
    if any solutions exist. (10 points)
\end{Exercise}

\begin{Answer}
    The gcd of 42 and 35 is 7, which does not divide 2, so there are no
    solutions.
\end{Answer}

% 4
\begin{Exercise}
    List three solutions to the congruence $2x \equiv 4 \pmod{101}$. Your
    solutions may be congruent mod 101. (10 points)
\end{Exercise}

\begin{Answer}
    An obvious solution is $x = 2$, but there are no others in $\{0, 1, 2,
    \dots, 100\}$, because $\gcd(2, 101) = 1$. We can still get other solutions
    by adding multiples of 101. In particular, $2 + 101 = 103$ and $2 + 202 =
    204$ are also solutions.
\end{Answer}

% 5.
\begin{Exercise}
    Find the general solution to
    \[
        38x + 15y = 1,
    \]
    if any solutions exist. (10 points)
\end{Exercise}

\begin{Answer}
    The gcd of 38 and 15 is 1, so solutions \emph{do} exist. The Euclidean
    algorithm will give $x_0 = 2$ and $y_0 = -5$, so the general solution is
    \[
        x = 2 + 15t; \qquad y = -5 - 38t
    \]
    for an integer $t$.
\end{Answer}

% 6
\begin{Exercise}
    Does the congruence $25 x \equiv 1 \pmod{1000}$ have solutions? If so, how
    many solutions in $\{0, 1, 2, 3, \dots, 999\}$ are there? (10 points)
\end{Exercise}

\begin{Answer}
    No, because $\gcd(25, 1000) = 25$, which does not divide $1$.
\end{Answer}

% 7
\begin{Exercise}
    Show that $\gcd(a, b) = \gcd(a - b, b)$ for any integers $a$ and $b$. (10 points)
\end{Exercise}

\begin{Answer}
    If $d$ is a common divisor of $a$ and $b$, say $a = dk$ and $b = dj$, then
    $a - b = d(k - j)$, so $d$ is a common divisor of $a - b$ and $b$.
    Conversely, if $d$ is a common divisor of $a - b$ and $b$, then it also
    divides $a = (a - b) + b$ by the same argument. Therefore the common
    divisors of $(a, b)$ are the same as the common divisors of $(a - b, b)$,
    and in particular the \emph{greatest} one of them is the same.
\end{Answer}

% 8
\begin{Exercise}
    Show that $2^n \equiv -1 \pmod{3}$ for $n$ odd. (10 points)
\end{Exercise}

\begin{Answer}
    Note that $2 \equiv -1 \pmod{3}$, so $2^n \equiv (-1)^n | \pmod{3}$. If $n$
    is odd $(-1)^n = -1$, so $2^n \equiv -1 \pmod{3}$ for odd $n$.

    Nearly everyone used induction, which was fine, but gross. Here's the best
    induction you could do, I think: If $2^n \equiv -1 \pmod{3}$, then
    \[
        3^{n + 2} \equiv -4 \pmod{3} \equiv -1 \pmod{3}.
    \]
\end{Answer}

% 9
\begin{Exercise}
    Fix integers $a$ and $b$. Suppose that $ax + by = p$ for some integers $x$
    and $y$ and a prime $p$. Prove that $\gcd(a, b)$ is either $1$ or $p$. (10 points)
\end{Exercise}

\begin{Answer}
    By a theorem in class (or writing $a = \gcd(a, b)k$ and $b = \gcd(a, b)j$),
    we see that $\gcd(a, b)$ divides $p$, so it is either $1$ or $p$ since $p$
    is prime.
\end{Answer}

% 10
\begin{Exercise}
    Write $76$ in base $3$. (5 points)
\end{Exercise}

\begin{Answer}
    The largest power to begin with is $3^3 = 27$, and we can fit $2$ of them in:
    \[
        76 - 2 \cdot 3^3 = 22.
    \]
    Repeating:
    \[
        22 - 2 \cdot 3^2 = 4
    \]
    Again:
    \[
        4 - 1 \cdot 3 = 1
    \]
    Finally:
    \[
        1 = 1 \cdot 3^0.
    \]
    So
    \begin{align*}
        76 &= 2 \cdot 3^3 + 2 \cdot 3^2 + 1 \cdot 3^1 + 1 \cdot 3^0 \\
           &= (2211)_3.
    \end{align*}
\end{Answer}

% 11
\begin{Exercise}
    Translate the following numbers from binary into base $10$:
    \begin{enumerate}[label=(\textbf{\alph*})]
        \item $(1)_2$ (1 point)
        \item $(11)_2$ (1 point)
        \item $(111)_2$ (1 point)
        \item $(1111)_2$ (1 point)
        \item Prove, by induction, that
        \[
            (\underbrace{11\cdots 1}_{n})_2 = 2^n - 1
        \]
        for all positive integers $n$. (5 points)
    \end{enumerate}
\end{Exercise}

% 12
\begin{Exercise}
    Write $(1024)_5$ in base 10. (5 points)
\end{Exercise}

\begin{Answer}
    \begin{align*}
        (1024)_5 &= 1 \cdot 5^3 + 0 \cdot 5^2 + 2 \cdot 5^1 + 4 \cdot 5^0 \\
                 &= 125 + 10 + 4 \\
                 &= 139.
    \end{align*}
\end{Answer}

\paragraph{BONUS PROBLEM} The exam is graded out of 102 points, all accounted
for in the previous problems. The following problem is worth an additional 10
points.

\begin{Exercise}
    \begin{enumerate}[label=(\textbf{\alph*})]
        \item Find the general solution to the diophantine equation
            \begin{equation*}
                10x + 11y = 200.
            \end{equation*}
            (2 points)

        \item Show that there exists only a single solution with $x$ and $y$
            both positive. (5 points)

        \item Find that positive solution. (3 points)
    \end{enumerate}
\end{Exercise}

\end{document}


\section{Technical Approach}

\subsection{Theoretical Background}

The full derivation of the micromorphic constitutive equations is very detailed with full derivations being presented in Regueiro~\cite{bib:regueiro_micro10} and the theory manual for the code~\cite{bib:miller17}. Briefly, the equations of motion which must be solved are the balance of linear momentum

\begin{equation}
\sigma_{ji,j} + \rho \left(f_i - a_i\right) = 0\\
\end{equation}

and the balance of the, ``first moment of momentum''

\begin{equation}
\sigma_{ij} - s_{ij} + m_{kji,k} + \rho \left(l_{ji} - \omega_{ji}\right) = 0\\
\end{equation}

where the $\left(\cdot\right)_{,j}$ indicates the derivative with respect to $x$ in the current coordinate system. We note that the terms in the balance equations are volume and area averages of quantities defined in the micro scale (indicated by $\left(\cdot\right)'$) via
\begin{align*}
\rho dv &\defeq \int_{dv} \rho' dv'\\
\sigma_{ji}n_j da &\defeq \int_{da} \sigma_{ji}'n_j'da'\\
\rho f_i dv &\defeq \int_{dv} \rho' f_i' dv'\\
\rho a_i dv &\defeq \int_{dv} \rho' a_i' dv'\\
s_{ij} dv &\defeq \int_{dv} \sigma_{ij}' dv'\\
m_{ijm} n_i da &\defeq \int_{da} \sigma_{ij}' \xi_m n_i' da'\\
\rho l_{ij} dv &\defeq \int_{dv} \rho' f_i' \xi_j dv'\\
\rho \omega_{ij} dv &\defeq \int_{dv} \rho' \ddot{\xi}_i \xi_j dv'\\
\end{align*}

The most striking of the results of these equations is that the Cauchy stress is no longer symmetric. This arises because while we assert that classical continuum mechanics are obeyed at the micro-scale, at the macro scale we must handle moments applied pointwise due to the higher order stress $m_{ijk}$. This couple, along with the micro body couple and micro-spin, results in a generally asymmetric nature.

Conceptually, we can understand the balance of first moment of momentum in the absence of body couples and micro-spin as the statement that the total stress of the body is the volume average of all the micro stresses ($s_{ij}$) added to the couple produced by the micro stresses acting on the lever arm $\xi_i$. The body couple results from a heterogeneous distribution of the body force per unit density and the micro-spin inertia results from the acceleration of the micro position vectors.

We define a mapping between the current and reference configurations for the position of $dv$ and $dv'$ as
\begin{align*}
F_{iI} &\defeq \frac{\partial x_i}{\partial X_I}\\
\xi_i  &\defeq \chi_{iI}\Xi_I = \left(\delta_{iI}+\phi_{iI}\right)\Xi_I\\
\end{align*}

where we note the difference that $F_{iI}$ maps $dX_I$ into $dx_i$ through the differential relationship whereas $\chi_{iI}$ is purely a linear map between the configurations and is not defined through the differential elements.

\subsection{Algorithms}

The equations of motion will be solved using the finite element method in a so-called, ``Total Lagrangian,'' configuration. We do this by mapping the stresses back to the reference configuration (for details see Regueiro~\cite{bib:regueiro_micro10} or the theory manual~\cite{bib:miller17}) to find the balance of linear momentum for a single element $e$

\begin{align*}
\sum_{n=1}^{N^{nodes,e}} c^{n,e}_j \bigg\{&\int_{\partial \hat{\mathcal{B}}^{0,t,e}} \hat{N}^{n,e} F_{jJ} S_{IJ} \hat{J} \left(\frac{\partial X_{I}}{\partial \xi_{\hat{i}}}\right)^{-1} \hat{N}_{\hat{i}} d\hat{A}& + \int_{\hat{\mathcal{B}}^{0,e}} \big\{- \hat{N}^{n,e}_{,I} S_{IJ} F_{jJ} + \hat{N}^{n,e} \rho^0 \left(f_j - a_j\right) \big\} \hat{J} d\hat{V} = \mathcal{F}_j^{n,e}\bigg\}\\
\end{align*}

where we have transformed the equations into the element basis $e_\xi$ (indicated by $\hat{\left(\cdot\right)}$), $N$ is the shape function, $S_{IJ}$ is the second Piola Kirchhoff stress, and $\mathcal{F}_j^{n,e}$ is the residual. Note that this $\xi$ is not the same as the micro-position vector detailed above.

We also write the balance of the first moment of momentum as
\begin{align*}
\sum_{n=1}^{N^{nodes,e}} \eta_{ij}^{n,e} &\bigg\{\int_{\mathcal{B}^{0,e}}  \bigg\{\hat{N}^{n,e} \left(F_{iI} \left(S_{IJ}-\Sigma_{IJ}\right) F_{jJ} + \rho^0\left(l_{ji} - \omega_{ji} \right)\right)  - \frac{\partial \hat{N}^{n,e}}{\partial \xi_{\hat{i}}} \left(\frac{\partial X_{K}}{\partial \xi_{\hat{i}}}\right)^{-1} F_{jJ} \chi_{iI}  M_{KJI} \bigg\} \hat{J} d\hat{V}\\
& + \int_{\partial \mathcal{B}^{0,t,e}} F_{jJ} \chi_{iI}  M_{KJI} \hat{N}^n \hat{J} \left(\frac{\partial X_{K}}{\partial \xi_{\hat{i}}}\right)^{-1} \hat{N}_{\hat{i}} d\hat{A} = \mathcal{M}_{ij}^{n,e} \bigg\}\\
\end{align*}

We will organize these residuals into the residual vector using the following approach for a linear 8 noded hex element
\begin{align*}
\mathcal{R}^e &= \left\{\begin{array}{c}
\mathcal{F}_j^{1,e}\\
\mathcal{M}_j^{1,e}\\
\mathcal{F}_j^{2,e}\\
\mathcal{M}_j^{2,e}\\
\vdots\\
\mathcal{F}_j^{8,e}\\
\mathcal{M}_j^{8,e}\\
\end{array}\right\}
\end{align*}

where
\begin{align*}
\mathcal{M}_J^{n,e} = \left\{\begin{array}{c}
\mathcal{M}_{11}^{n,e}\\
\mathcal{M}_{22}^{n,e}\\
\mathcal{M}_{33}^{n,e}\\
\mathcal{M}_{23}^{n,e}\\
\mathcal{M}_{13}^{n,e}\\
\mathcal{M}_{12}^{n,e}\\
\mathcal{M}_{32}^{n,e}\\
\mathcal{M}_{31}^{n,e}\\
\mathcal{M}_{21}^{n,e}
\end{array}\right\}
\end{align*}

We solve the nonlinear equations using Newton Raphson which means we require the Jacobian. We write the element tangent as
\begin{align*}
\mathcal{J}_{IJ}^e  = \frac{\partial \mathcal{R}_I}{\partial \mathcal{U}_J} &= -\left[\begin{array}{cccccc}
\frac{\partial \mathcal{F}_{1}^{1,e}}{\partial u_1^{1,e}} & \frac{\partial \mathcal{F}_{1}^{1,e}}{\partial u_2^{1,e}} & \frac{\partial \mathcal{F}_{1}^{1,e}}{\partial u_3^{1,e}} & \frac{\partial \mathcal{F}_{1}^{1,e}}{\partial \phi_{11}^{1,e}} & \cdots & \frac{\partial \mathcal{F}_{1}^{1,e}}{\partial \phi_{21}^{8,e}}\\
\frac{\partial \mathcal{F}_{2}^{1,e}}{\partial u_1^{1,e}} & \frac{\partial \mathcal{F}_{2}^{1,e}}{\partial u_2^{1,e}} & \frac{\partial \mathcal{F}_{2}^{1,e}}{\partial u_3^{1,e}} & \frac{\partial \mathcal{F}_{2}^{1,e}}{\partial \phi_{11}^{1,e}} & \cdots & \frac{\partial \mathcal{F}_{1}^{1,e}}{\partial \phi_{21}^{8,e}}\\
\vdots & \vdots & \vdots & \vdots & \ddots & \vdots\\
\frac{\partial \mathcal{M}_{2}^{8,e}}{\partial u_1^{1,e}} & \frac{\partial \mathcal{M}_{2}^{8,e}}{\partial u_2^{1,e}} & \frac{\partial \mathcal{M}_{2}^{8,e}}{\partial u_3^{1,e}} & \frac{\partial \mathcal{M}_{2}^{8,e}}{\partial \phi_{11}^{1,e}} & \cdots & \frac{\partial \mathcal{M}_{1}^{8,e}}{\partial \phi_{21}^{8,e}}\\
\end{array}\right]
\end{align*}

where the superscript numbers indicate the node number. This is a $96 \times 96$ matrix. We then assemble the individual Jacobian and residual for an element to form the global Jacobian and residual.

We write the linearized form of the residual as

\begin{equation}
\mathcal{R}_I^{n+1,k+1} \approx \mathcal{R}_I^{n,k} + \frac{\partial \mathcal{R}_I}{\partial \mathcal{U}_J} \Delta \mathcal{U}_J
\end{equation}

where $n$ is the current pseudo-timestep and $k$ is the iteration number.

We desire the residual at the next iteration to be zero so we write
\begin{equation}
\begin{aligned}
0 &= \mathcal{R}_I^k + \frac{\partial \mathcal{R}_I}{\partial \mathcal{U}_J} \Delta \mathcal{U}_J\\
\Rightarrow\ -\frac{\partial \mathcal{R}_I}{\partial \mathcal{U}_J} \Delta \mathcal{U}_J &= \mathcal{R}_I^k\\
\end{aligned}
\end{equation}

where $\Delta \hat{t}$ is an increment in pseudo-time and $k$ indicates the sub-iteration. We now introduce
\begin{align*}
\Delta \mathcal{U}_J &= \Delta \hat{t} \dot{\mathcal{U}}_J\\
\dot{\mathcal{U}}_J &= \alpha \dot{\mathcal{U}}_J^{k+1} + \left(1-\alpha\right) \dot{\mathcal{U}}_J^{k}
\end{align*}

$\alpha = 0$ indicates an explicit method and $\alpha = 1$ indicates an implicit method. Once a good initial condition has been established, Newton-Raphson iteration is performed to compute the proper value of $\dot{\mathcal{U}}_J^{k+1}$. Iterations will continue until the convergence of the residual vector is achieved.

We note that boundary conditions are enforced by either removing the relevant rows and columns in the residual and Jacobian in the case of a zero boundary condition or by first computing the resultant force, subtracting it from the residual, and then removing the rows and columns in the case of a non-zero boundary condition.

The matrix equation will be solved, at least initially, by using the Newton-Krylov solver contained in the C++ repository. This solver does not use the tangent but rather uses the residual to compute the required steps in the solution. Further efforts should involve implementing the code in a Newton-Raphson solver so that the tangent can be tested as well.

\FloatBarrier


\section{The baseline model}

The utility function is defined as:
\[ u(c_{h,t},l_{h,t}) = \frac{M^{1-\gamma}_{h,t}}{1 - \gamma} \exp{( \pi z_{h,t} + \zeta_{h,t} )} .\]
The preference aggregator (why aggregator) for hours of leisure and consumption is
\[ M_{h,t}(c_{h,t},l_{h,t};z_{h,t},\chi_{h,t}) = \left( \frac{(c_{h,t}^{1 - \phi} - 1)}{1 - \phi} + (\alpha_{h,t}(z_{h,t},\chi_{h,t})) \frac{(l_{h,t}^{1 - \theta} -1)}{ 1 - \theta}\right) \]
$\alpha_{h,t}= \exp{(\psi_0 + \psi_z z_{h,t} + \chi_{h,t})}$

Suppose for now there is no random discrete choice, the inter-temporal budget constraint:
\[ A_{h,t+1} = (1 + r_{t+1}) \left( A_{h,t} + (w_{h,t}^f(H-l_{h,t}) + y_{h,t}^m - c_{h,t} \right)\]
$A_{h,t}$ is the beginning asset holding, $r_t$ is the risk-free interest rate, $F$ is the fixed cost of work, dependent on the age of the youngest child, $a_{h,t}$. Female wages are given by $w_{h,t}^f$ and husband earning $y_{h,t}^m$.

The maximization is done with respect to the following payoffs:
\[\begin{split} \max_{c_t,l_t} & u(c_t,l_t) + \beta V(A_{t+1}) \\
\text{subject to } & A_{t+1} = (1 + r_{t+1}) \left( A_{t} + w_{h,t}^f(H-l_{t}) + y_{h,t}^m - c_{t} \right)
\end{split}\]
The first order condition with respect to $c_t, l_t and A_t$ are \[ \begin{split}
  u_c(c_t,l_t) + \beta (1+r_{t+1}) V'(A_{t+1}) = 0 \\
  u_l(c_t,l_t) + \beta w_{h,t} (1+r_{t+1}) V'(A_{t+1}) = 0 \\
  V'(A_t) = \beta (1+r_{t+1}) V'(A_{t+1}) \\
\end{split} \]
From the model we can have two conditions
\[ \begin{split}
  \textbf{MRS condition:}& \quad w_{ht} u_{c,ht} = l_{c,ht}\\
  \textbf{Euler Equation:}& \quad u_{c,ht} = \beta u_{c,ht+1}, \quad \text{in addition:}\quad u_{l,ht} = u_{l,ht+1} \frac{w_{h,t}}{w_{h,t+1}}
\end{split} \]

\textbf{The regression from MRS}
Therefore from the MRS condition, we have that
\[\begin{split}
   w_{h,t}c_{h,t}^{-\phi} &= \alpha_{h,t}(z_{h,t},\chi_{h,t})) l_{h,t}^{-\theta}  \\
   \log(w_{h,t})& + \phi \log(c_{h,t})  = \psi_0 + \psi_1 z_{h,t} + \xi_{h,t} - \theta \log(l_{h,t})
\end{split} \]
\textbf{The parameters can be identified from MRS:}
\begin{itemize}
  \item We observe the wages, consumptions, leisure time and the exogenous variables: $\{w,c,l,z\}$
  \item From the reduced form regression, we have the preference shocks identified ($\psi_0,\psi_1$) with the assumption that $\xi_{h,t}$ is normal.
  \item We also identify the structural preference parameter $\phi$ and $\theta$.
  \item After we obtain $\hat{\phi},\hat{\theta},\hat{\psi}_0,\hat{\psi}_1$ we cam back out $\hat{M}(c_{h,t},l_{h,t})$
  \item[Question:] {\color{red} Then $\log M(c_{h,t}, l_{h,t}) - \log \hat{M}(c_{h,t},l_{h,t})$ follows the assumed distribution of $\xi_{h,t}$? Is there potential endogeneity problem? ($\xi$ correlated with wage? other explainatory variables?)}
\end{itemize}
\textbf{The Euler equation and what can be identified from it?}
The Euler equation condition is that
\[ \begin{split}
  & \exp{( \pi z_{h,t} + \zeta_{h,t} )} M(c_{h,t},l_{h,t})^{-\gamma} c_{h,t}^{-\phi} \\
  & = \beta (1+r_{t+1}) \exp{( \pi z_{h,t+1} + \zeta_{h,t+1} )} M(c_{h,t+1},l_{h,t+1})^{-\gamma} c_{h,t+1}^{-\phi} \\
  M(c_{h,t},l_{h,t}) & = \left( \frac{(c_{h,t}^{1 - \phi} - 1)}{1 - \phi} + (\alpha_{h,t}(z_{h,t},\chi_{h,t})) \frac{(l_{h,t}^{1 - \theta} -1)}{ 1 - \theta}\right)
\end{split} \]
Log-linearize and plug in the estimated utility to have that
\[ \begin{split}
  \pi z_{h,t} & + \zeta_{h,t} - \phi c_{h,t} - \gamma \log(\hat{M}(c_{h,t},l_{h,t})) \\ & = \log(\beta) + \log(1+r_{t+1}) + \pi z_{h,t+1} + \zeta_{h,t+1} - \gamma \log(\hat{M}(c_{h,t+1},l_{h,t+1})) - \phi c_{h,t+1} \\
  \text{Then we have}& \quad  \pi \Delta z_{h,t} + \Delta \zeta_{h,t} - \hat{\phi} \Delta c_{h,t} - \gamma \Delta \log \hat{M}(c_{h,t},l_{h,t}) + \beta + \log(1+r_t)= 0
\end{split} \]
What parameters we can estimate from the Euler equation
\begin{itemize}
  \item It feels wierd that no transition of $z_{h,t}$ is assumed? But may be we don't need this assumption.
  \item We can estimate the parameters $\pi,\gamma,\beta$ from the data?
  \item {\color{red} The $r_{t}$ is observed? The paper uses group aggregate labour supply or taxation as an IV for this step's identification}
  \item [Comment:] not sure what harm this would bring to estimation...But is this neccesary if we want to aggregate the $M_{h,t}$?
  \item [Question:] Page 16 of paper \cite{Attanasio2015AggregatingSupply}, lower part $M_{h,t}$ is non-linear function and unobserved parameters, so cannot be aggregated??
\end{itemize}

\section{Section with discrete choice}
The additional parameters are $\xi$ and $F(a_{h,t})$ where $F(a_{h,t})$
If there is a discrete choice to participate in labour market, then the utility function is defined as:
\[ u(c_{h,t},l_{h,t},P_{h,t}) = \frac{M^{1-\gamma}_{h,t}}{1 - \gamma} \exp{(\xi P_{h,t} + \pi z_{h,t} + \zeta_{h,t} )} .\]
\[ M_{h,t}(c_{h,t},l_{h,t};z_{h,t},\chi_{h,t}) = \left( \frac{(c_{h,t}^{1 - \phi} - 1)}{1 - \phi} + (\alpha_{h,t}(z_{h,t},\chi_{h,t})) \frac{(l_{h,t}^{1 - \theta} -1)}{ 1 - \theta}\right) \]
$\alpha_{h,t}= \exp{(\psi_0 + \psi_z z_{h,t} + \chi_{h,t})}$
The intertemporal budget constraint is defined as:
\[ A_{h,t+1} = (1 + r_{t+1}) \left( A_{h,t} + \left(w_{h,t}^f(H-l_{h,t}) - F(a_{h,t}) \right)P_{h,t} + y_{h,t}^m - c_{h,t} \right)\]
\textbf{The parameters that we can get from MRS and Euler Equation}
\begin{itemize}
  \item Similarly, estimate the parameters within $M(c_{h,t},l_{h,t})$ function and obtain $\hat{M}(c_{h,t},l_{h,t})$.
  \item The Euler equation is slightly different: \[ \xi \Delta P_{h,t}  \pi \Delta z_{h,t} + \Delta \zeta_{h,t} - \hat{\phi} \Delta c_{h,t} - \gamma \Delta \log \hat{M}(c_{h,t},l_{h,t}) + \beta + \log(1+r_t)= 0\]
  \item $\xi$ is the entry cost?
\end{itemize}
\tbf{Random shocks: what's confusing to me.}
\begin{itemize}
  \item No entry cost of labour market.
  \item The shock $\zeta$ induce increase of current period consumption/labour.
  \item Are $\zeta$ and $\chi$ correlated?
\end{itemize}

\section{My estimation strategy?}
I would propose a 3-step estimation strategy.

\textbf{In the first step}, in addition to estimating $MRS$, I will need to estimate the transition of $z_{it}$ as well.(So that the agents have a prior about the future events.)
From the first step, we obtain the estimator of $\log \hat{M}(c,h)$, and we also have the estimator of $w_{h,t}$. Non-parametrically estimate $c^*(\cdot),l^*(\cdot)$ as functions of $z_{h,t}$.

\textbf{The estimator:}
\begin{itemize}
  \item $c^{*}(z,w,y,A),l^{*}(z,w,y,A)$ with Nadaya-Watson estimator.
  \item $p(z,w,y,A) = Pr(P=1|z,w,y,z)$ with non-parametric estimate.
  \item $f(w'|w,P)$, $f(w'|w)$ estimator: can test whether the wage grows with participation decision(but may be correlated with unobserved variables, not sure what to do with it yet...HELP).
\end{itemize}

\textbf{In the second step}, estimate the entry decision of the labour market.
The agent will choose $P_{h,t}=1$ when $E_{\zeta_{h,t},\xi_{h,t}} v(1,c^*(\cdot),l^*(\cdot),z_{h,t},(\zeta_{h,t},\xi_{h,t})) > E_{\zeta_{h,t},\xi_{h,t}} v(0,c^*(\cdot),l^*(\cdot),z_{h,t},(\zeta_{h,t},\xi_{h,t}))$
Assume that $v(\cdot)$ is the continuation value associated with the parameters.

\textbf{In the third step}, estimate the forward looking continuous choice.
It follows that $c^*(),l^*()$ are the optimal rule.