% Part: normal-modal-logic
% Chapter: filtrations
% Section: more-filtrations

\documentclass[../../../include/open-logic-section]{subfiles}

\begin{document}

\olfileid{mod}{fil}{acc}

\olsection{Filtrations and Properties of Accessibility}

\begin{defn}
  Let $\Gamma$ be closed under subformulas and $\mModel{M} =\tuple{W, R, V}$ a
  model. Then we can define conditions on pairs of worlds $u,v$ as given in
  the table of \olref{fig:Cn-filtrations}.
\end{defn}

  \begin{figure}[ht]
    \centering
    \begin{tabular}{|ll|}
      \hline
      \multirow{2}{*}{$C_1(u,v)$:}  &if $\Box!A \in \Gamma$  and $\mSat{M}{\Box!A}[u]$ then $\mSat{M}{!A}[v]$; and \\
      & if $\Diamond!A \in \Gamma$  and $\mSat{M}{!A}[v]$ then $\mSat{M}{\Diamond!A}[u]$; \\
      \hline
      \multirow{2}{*}{$C_2(u,v)$:} &if $\Box!A \in \Gamma$  and $\mSat{M}{\Box!A}[v]$ then $\mSat{M}{!A}[u]$; and \\
      & if $\Diamond!A \in \Gamma$  and $\mSat{M}{!A}[u]$ then $\mSat{M}{\Diamond!A}[v]$; \\
      \hline
      \multirow{2}{*}{$C_3(u,v)$:} &if $\Box!A \in \Gamma$  and $\mSat{M}{\Box!A}[u]$ then $\mSat{M}{\Box!A}[v]$; and \\
      & if $\Diamond!A \in \Gamma$  and $\mSat{M}{\Diamond!A}[v]$ then $\mSat{M}{\Diamond!A}[u]$; \\
      \hline
      \multirow{2}{*}{$C_4(u,v)$:} &if $\Box!A \in \Gamma$  and $\mSat{M}{\Box!A}[v]$ then $\mSat{M}{\Box!A}[u]$; and \\
      & if $\Diamond!A \in \Gamma$  and $\mSat{M}{\Diamond!A}[u]$ then $\mSat{M}{\Diamond!A}[v]$; \\
      \hline
    \end{tabular}
    \caption{Conditions on possible worlds for defining
      filtrations.}\ollabel{fig:Cn-filtrations}
\end{figure}

\begin{thm}\ollabel{thm:more-filtrations}
  Let $\mModel{M} =\tuple{W,R,P}$ be a model, $\Gamma$ closed under
  subformulas. Let $W^*$ and $V^*$ be defined as in
  \olref[fil]{def:filtration}. Then:
  \begin{enumerate}
  \item If $R^*$ is defined as $R^*[u][v]$ if and only if $C_1(uv)
    \land C_2(u,v)$ then $R^*$ is symmetric, and
    $\mModel{M^*} = \tuple{W^*,R^*,V^*}$ is a filtration if $\mModel{M}$
    is symmetric.
  \item If $R^*$ is defined as $R^*[u][v]$ if and only if $C_1(uv)
    \land C_3(u,v)$ then $R^*$ is transitive, and
    $\mModel{M^*}=\tuple{W^*,R^*,V^*}$ is a filtration if $\mModel{M}$
    is transitive.
  \item If $R^*$ is defined as $R^*[u][v]$ if and only if $C_1(uv)
    \land C_2(u,v) \land C_3(u,v) \land C_4(u,v)$ then $R^*$ is
    symmetric and transitive, and $\mModel{M^*}=\tuple{W^*,R^*,V^*}$
    is a filtration if $\mModel{M}$ is symmetric and transitive.
  \item If $R^*$ is defined as $R^*[u][v]$ if and only if $C_1(uv)
    \land C_3(u,v) \land C_4(u,v)$ then $R^*$ is transitive and
    euclidean, and $\mModel{M^*}=\tuple{W^*,R^*,V^*}$ is a filtration
    if $\mModel{M}$ is transitive and euclidean.
  \end{enumerate}
\end{thm}

\begin{proof}
  \begin{enumerate}
    \item It's immediate that $R^*$ is symmetric, since $C_1(u,v)
      \Leftrightarrow C_2(v,u)$ and $C_2(u,v) \Leftrightarrow
      C_1(v,u)$. So it's left to show that if $\mModel{M}$ is
      symmetric then $\mModel{M^*}$ is a filtration through
      $\Gamma$. By condition $C_1(u,v)$ we get that: if $\Box!A \in
      \Gamma$ and $\mSat{M}{\Box!A}[u]$ then $\mSat{M}{!A}[v]$, and if
      $\Diamond!A \in \Gamma$ and $\mSat{M}{!A}[v]$ then
      $\mSat{M}{\Diamond!A}[u]$. So all we need is that $Ruv$ implies
      $R^*[u][v]$.

      So suppose $Ruv$, to show $R^*[u][v]$ we need $C_1(u,v) \land
      C_2(u,v)$. For $C_1$: if $\Box!A \in\Gamma$ and
      $\mSat{M}{\Box!A}[u]$ then also $\mSat{M}{!A}[v]$ (since $Ruv$);
      and similarly if $\Diamond!A \in \Gamma$ and $\mSat{M}{!A}[v]$
      then $\mSat{M}{\Diamond!A}[u]$. For $C_2$: if $\Box!A \in
      \Gamma$ and $\mSat{M}{\Box!A}[v]$ then $Ruv$ implies $Rvu$ by
      symmetry, so that $\mSat{M}{!A}[u]$; similarly if $\Diamond!A
      \in\Gamma$ and $\mSat{M}{!A}[u]$ then $\mSat{M}{\Diamond!A}[v]$
      (since $Rvu$ by symmetry).
    \item Exercise.
    \item Exercise.
    \item Exercise.
  \end{enumerate}
\end{proof}

\begin{prob}
  Complete the proof of \olref[mod][fil]{thm:more-filtrations}.
\end{prob}

This approach does not work in the case of models that are euclidean
or serial and euclidean. Consider the model at the top of
Figure~\olref{fig:ser-eucl}, which is both euclidean and serial. Let
$\Gamma = \{p, \Box p \}$. When taking a filtration through $\Gamma$,
then $[w_1] = [w_3]$ since $w_1$ and $w_3$ are the only worlds that
agree on $\Gamma$. Any filtration will also have the arrow inherited
from $\mModel{M}$, as depicted in Figure~\olref{fig:ser-eucl2}. But we
cannot add arrows to that model in order to make it euclidean, for
then there would be a double arrow between $w_2$ and $w_4$, and hence
also between $w_2$ and $w_5$. But $\Box p$ is true at $w_2$ while $p$
is false at $w_5$.

\begin{figure}[htpb]
  \centering
  \begin{tikzpicture}[node distance=2cm, auto, thick]
    \node (w1) at (0, 0) [label=90:$w_1$, label=below:$\lnot p$]{$\bullet$};
    \node (w2) at (2, 0) [label=90:$w_2$, label=below:$p$]{$\bullet$};
    \draw[->] (w1) to node {} (w2);
    \path node at (0,-1) {$\Box p$};
    \path node at (2,-1) {$\Box p$};
    \node (w3) at (0, -2.5) [label=90:$w_3$, label=below:$\lnot p$]{$\bullet$};
    \node (w4) at (2, -2.5) [label=135:$w_4$,
      label=below:$p$]{$\bullet$}edge [in=60,out=120,loop] ();
    \draw[->] (w3) to node {} (w4);
    \node (w5) at (4, -2.5) [label=90:$w_5$, label=below:$\lnot p$]{$\bullet$};
    \draw[<->] (w4) to node {} (w5) edge [in=30,out=-30,loop] () ;
    \path node at (0,-3.5) {$\Box p$};
    \path node at (2,-3.5) {$\lnot\Box p$};
    \path node at (4,-3.5) {$\lnot\Box p$};
    \draw [rounded corners] (-1,-4) -- ++(6.25,0)  -- ++(0,5) -- ++(-6.25,0) --  cycle;
    % \draw[->, bend left] (w1) to node {$R$} (w2);
    % \draw[->, bend left] (w2) to node {} (w1);
    % \draw [rounded corners] (-1,-1) -- ++(0,2)  -- ++(4.25,0) -- ++(0,-2) --  cycle;
    % \path node at (2.75,0.75) {$\mModel{M}$};
  \end{tikzpicture}
  \caption{A serial and euclidean model.}\ollabel{fig:ser-eucl}
\end{figure}

\begin{figure}[ht]
  \centering
  \begin{tikzpicture}[node distance=2cm, auto, thick]
    \node (w1) at (-0.5, -1) [label=110:{$[w_1]=[w_3]$}, label=below:$\lnot
      p$]{$\bullet$};
    \path node at (-0.5,-2) {$\Box p$};
    \node (w2) at (2, 0) [label=90:$w_2$,
      label=0:{$p, \Box p$}]{$\bullet$};
    \node (w4) at (2, -2.5) [label=210:$w_4$,
      label=below:$p$]{$\bullet$}edge [in=60,out=120,loop] ();
    \draw[->] (w1) to node {} (w2);
    \draw[->] (w1) to node {} (w4);
    \node (w5) at (4, -2.5) [label=90:$w_5$, label=below:$\lnot p$]{$\bullet$};
    \draw[<->] (w4) to node {} (w5) edge [in=30,out=-30,loop] () ;
    \path node at (2, -3.5) {$\lnot\Box p$};
    \path node at (4, -3.5) {$\lnot\Box p$};
    \draw [rounded corners] (-3,-4) -- ++(8.25,0)  -- ++(0,5) -- ++(-8.25,0) --  cycle;
  \end{tikzpicture}
  \caption{The filtration from the model in Figure~\olref{fig:ser-eucl}.}
  \ollabel{fig:ser-eucl2}
\end{figure}

In particular, it is not enough to consider filtrations through
arbitrary $\Gamma$'s closed under subsentences. Instead we need to
consider sets $\Gamma$ that are \emph{modally closed} (see
\olref{def:modallyclosed}). Such sets of sentences are
infinite, and therefore do not lead immediately to the decidability of
the corresponding system.

\begin{thm}
  Let $\Gamma$ be modally closed and $\mModel{M}=\tuple{W,R,V}$. If
  $\mModel{M^*} = \tuple{W^*,R^*,V^*}$ is a coarsest filtration of
  $\mModel{M}$, then $\mModel{M^*}$ is symmetric, transitive or
  euclidean if $\mModel{M}$ is symmetric, transitive, or euclidean,
  respectively.
\end{thm}

\begin{proof}
  The proof of transitivity uses the validity of both \Ax{4} and
  $\mathsf{4_\Diamond}$ in all transitive models, and likewise
  euclideanness uses the fact that both \Ax{5} and
  $\mathsf{5_\Diamond}$ are valid in all euclidean models, and the
  proof of symmetry likewise uses both \Ax{B} and
  $\mathsf{B_\Diamond}$.

  If $\mModel{M^*}$ is a coarsest filtration, then by definition
  $R^*[u][v]$ holds if and only if $C_1(u,v)$. For transitivity,
  suppose $C_1(u,v)$ and $C_1(v,w)$: to show $C_1(u,w)$ suppose
  $\mSat{M}{\Box !A}[u]$; then $\mSat{M}{\Box\Box!A}[u]$; since
  $\Box\Box!A \in \Gamma$ by closure, also by $C_1(u,v)$,
  $\mSat{M}{\Box!A}[v]$ and by $C_1(v,w)$, also $\mSat{M}{!A}[w]$. The
  case for $\Diamond!A$ is similar.
\end{proof}

\part{Problem sets}

\section{Problem set 1: understanding Kripke semantics}

\begin{problem} [60 points]
  Consider the following model ${M}$ for the language
  comprising $p_1, p_2, p_3$ as the only propositional variables:
%% See: http://pdp7.org/blog/?p=133
\begin{center}
  \begin{tikzpicture}[node distance=2cm, auto, thick]
    \node (w1) {$w_1 \, \bullet$} ;
    \node (w2) [right of=w1]
    {$\bullet$};
    \node (w3) [right of=w2] {$\bullet$} edge
    [in=60,out=120,loop] () ;
    \draw[->] (w1) to node {} (w2); \draw[->] (w2) to node {} (w3);
    \draw[->, bend left] (w1) to node [swap] {$w_2$} (w3);
    \path node at ( 4.5,0) {$w_3$};
    \path node at ( 0.25,-0.5) {$p_1$};
    \path node at ( 2,-0.5) {$p_1,p_2$};
    \path node at ( 4,-0.5) {$p_1,p_2,p_3$};
    % \path node at ( 0,-1) [shape=circle,draw] {};
  \end{tikzpicture}
%\node [circle,draw] {a} edge [in=30,out=60,loop] ();
\end{center}
Are the following !!{formula}s and schemas true in the model ${M}$,
i.e., true at every world in ${M}$? Explain.
\begin{enumerate}
\item $p\lif \Diamond p$ (for $p$ atomic);
\item $!A\lif \Diamond !A$ (for $!A$ arbitrary);
\item $\Box p \lif p$ (for $p$ atomic);
\item $\lnot p \lif \Diamond \Box p$ (for $p$ atomic);
\item $\Diamond \Box !A$ (for $!A$ arbitrary);
\item $\Box \Diamond p$ (for $p$ atomic).
\end{enumerate}
\end{problem}

\begin{problem} [20 points]
For each of the following !!{formula}s find a model ${M} = \tuple{W, R V}$ and a
world $w \in W$ such that the !!{formula} fails at $w$:
\begin{enumerate}
\item $p \lif \Box\Box p$;
\item $\Box(p \lor q) \lif (\Box p \lor \Box q)$.
\end{enumerate}
\end{problem}

\begin{problem} [20 points]
For each of the following schemas find a model $\mathbf{M}$ such that
every instance of the schema is true in $\mathbf{M}$:
\begin{enumerate}
\item $!A \lif \Diamond\Diamond !A$;
\item $\Diamond !A \lif \Box !A$.
\end{enumerate}
\end{problem}

\section{Problem set 2: provability}
\setcounter{problem}{0}

\begin{definition}
  Given a normal system $\Sigma$ of modal logic, say that $!A$ is
  \emph{!!{derivable}} in $\Sigma$, written $\Sigma \Proves !A$, if and
  only if there is a proof of $!A$ from axioms in $\Sigma$ using
  \MP{} and \Nec{}. Equivalently, $!A$ belongs to the smallest set of
  sentences containing $\Sigma$ and closed under tautological
  implication and \RK{}.
\end{definition}

\begin{problem} [24 points]
  Provide $\Log{K}$-proofs of the following:
\begin{enumerate}
\item $\Diamond \lnot \lfalse \lif (\Box !A \lif \Diamond !A)$;
\item $\Box(!A \lor !B) \lif (\Diamond !A \lor \Box !B)$;
\item $(\Diamond !A \lif \Box !B) \lif \Box(!A \lif !B)$.
\end{enumerate}
\end{problem}

For ease of reference, we restate here \olref{thm:soundness}:

\noindent
\textbf{Soundness Theorem}: if schemas
$!A_1, \dots,!A_n$ are valid in the classes of models
$\mClass{C}_n, \dots,\mClass{C}_n$, respectively, then
$\Log{K}!A_1\dots !A_n \Proves !B$ implies
that $!B$ is valid in the class of models $\mClass{C}_n \cap
\dots \cap \mClass{C}_n$.

\begin{definition}
  An inference rule of the form
\[
{!A_1 \dots !A_n} \over !B \eqno{(*)\hspace{2in}}
\]
is \emph{admissible} in a system $\Sigma$ if and only if, whenever
$\Sigma \Proves !A_i$ for $i =1, \dots,n$, then also $\Sigma
\Proves !B$. In other words, adding the new rule to the system does
not change the set of !!{derivable} !!{formula}s.
\end{definition}

\begin{definition}
  An inference rule of the form $(*)$ is \emph{derivable} in a system
  $\Sigma$ if and only if $\Sigma \Proves !A_1 \lif (!A_2 \to
  ( \cdots (!A_n \lif !B) \cdots)$.
\end{definition}

\begin{problem} [6 points]
  Show that if a rule is derivable in $\Sigma$ then it is admissible
  in $\Sigma$.
\end{problem}

\begin{definition}
  Define a function $\sigma$ from !!{formula}s into !!{formula}s recursively
  by setting:
  \begin{eqnarray*}
    \sigma(p) & = & p ;\\
   \sigma(\lfalse) & = &  \lfalse ;\\
    \sigma(\lnot !A) & = & \lnot\sigma(!A);\\
   \sigma(!A \lif !B) & = & \sigma(!A) \lif \sigma(!B);\\
   \sigma(\Box !A) & = & !A.
  \end{eqnarray*}
  So $\sigma$ erases the outermost occurrence of $\Box$.  For
  instance, compute $\sigma(\Box(\Diamond A \lif \Diamond\Box B))$ and
  $\sigma(\Diamond A \lif \Diamond\Box B)$
% (after re-writing $\Diamond$ as $\lnot\Box\lnot$)
.
\end{definition}

\goodbreak

\begin{problem} [20 points]
  Show that if $\Log{K}\Proves !A$ then $\Log{K}\Proves
  \sigma(!A)$ (use induction on the number of lines in the proof).
    % \footnote{By induction on the number of lines in a proof:
    % $\sigma$ takes $\Ax{K}$ and any tautologies into
    % $\Log{K}$-theorems; and if $!B$ follows from $!A$ by \MP{}
    % or \Nec{} then $\sigma(!B)$ follows from $\sigma(!A)$ (although
    % not necessarily by the same rule).
\end{problem}

\begin{problem} [10 points]
Show that the following inference rules are admissible in
$\Log{K}$:
\[
\begin{array}{*3{>{\displaystyle}c@{\hspace{1in}}}}
(a) \hspace{.125in} {\Diamond!A\over!A}&
(b) \hspace{.125in} {\Box !A \lif \Box !B\over {!A \lif !B}}&
(c) \hspace{.125in} {\Box!A \over !A}.
\end{array}
\]
\end{problem}

If $\Sigma$ and $\Sigma'$ are two systems such that $\Sigma \subseteq
\Sigma'$ then (obviously) every theorem of $\Sigma$ is a theorem of
$\Sigma'$. The situation is different, however, for rules. If a rule
of the form $(*)$ is admissible in $\Sigma$, it does {\em not} follow
that it is admissible in $\Sigma'$ as well: the latter has {\em more
  theorems} than the former, and so the harder it is to show that a
given rule is admissible.

\begin{problem} [10 points]
  Show that $\Log{KB} \Proves \Box(!A \lif \Diamond\Diamond
  !A)$, but $\Log{KB} \Proves/  !A \lif \Diamond\Diamond
  !A$. \emph{Cheat}: for half the credit, use completeness of
  $\Log{KB}$ with respect to symmetric models to show that
  $\Log{KB} \Proves \Box(!A \lif \Diamond\Diamond !A)$.
\end{problem}

\begin{problem} [10 points]
  Show that $\Log{K5}\Proves \Box(!A \lif \Diamond !A)$,
  but $\Log{K5} \Proves/  !A \lif \Diamond
  !A$. \emph{Cheat}: for half the credit, use completeness of
  \Log{K5} with respect to euclidean models to show that
  $\Log{K5} \Proves \Box(!A \lif \Diamond !A)$.
\end{problem}

\begin{problem} [10 points]
  Is the rule $(c)$ above admissible in $\Log{KB}$? in $\Log{K5}$?
\end{problem}

\begin{problem} [10 points]
  We know from Problem 1 that all derivable rules are admissible. Show
  that the converse is not true.
\end{problem}

\section{Problem set 3: $p$-morphisms}
\setcounter{problem}{0}

\begin{definition}
  A frame is \emph{irreflexive} if for any world $w$ in the frame
  it's \emph{not} the case that $R(w,w)$, i.e., no world is accessible
  from itself.
\end{definition}

\begin{definition}
  Given two frames ${F} = ({W}, R)$ and ${G} =
  ({X}, S)$, a $p$-morphism of the first onto the second is a
  function $\pi : {W} \lif {X}$ such that:
  \begin{itemize}
  \item $\pi$ is surjective;
  \item if $R(u,v)$ then $S(\pi(u),\pi(v))$;
  \item if $S(\pi(u),w)$ then there is a $v \in {W}$ such
    that $\pi(v)=w$ and $R(u,v)$.
  \end{itemize}
  Given two models ${M} = ({W}, R, U)$ and ${N} =
  ({X}, S, V)$, a $p$-morphism of the first onto the second is
  a $p$-morphism $\pi$ of the corresponding frames satisfying the
  additional condition that for all $w\in {W}$ and propositional
  variable $p$: $w \in U(p)$ if and only if $\pi(w) \in V(p)$.

\end{definition}

\begin{problem} [10 points]\ollabel{problem:frames}
  Show that there is a $p$-morphism between the following two frames
  ${F}$ and ${G}$, where ${W} = \{w_1, w_2,
  w_3, w_4\}$ and ${X} = \{u_1, u_2 \}$ and $R$ and $S$ are as
  depicted:

\begin{center}
  \begin{tikzpicture}[node distance=2cm, auto, thick]
    \node (w1) {$\bullet$};  %edge [in=55,out=125,loop] ();
    \node (w2) [below of=w1] {$\bullet$};
    \node (w3) [right of=w2] {$\bullet$} ;
%    \node (fake) [right of=w3] {};
    \node (fake) at (4,-1) {};
    \draw[->] (w2) to node {} (w1);
    \node (w4) [below of=w3] {$\bullet$} ; %edge [in=305,out=235,loop] ();
     \draw[->] (w3) to node {} (w4);
     \draw[->, bend left] (w3) to node {} (w2) ;
     \draw[->, bend left] (w2) to node {} (w3) ;
%    \draw[->, bend right] (w3) to node (w2);
     \path node at ( 0.4,0) {$w_1$};
     \path node at ( -0.4,-2) {$w_2$};
     \path node at ( 2.4,-2) {$w_3$};
     \path node at ( 1.6,-4) {$w_4$};

     \draw [rounded corners] (-1,1) -- (-1,-5) -- (3,-5) -- (3,1) --  cycle;

     \path node at (2,0.5) {${F}$};

% \path node at ( 0,-1) [shape=circle,draw] {};
% \node [circle,draw] {a} edge [in=30,out=60,loop] ();

%     \node (u1) [right of=fake] {$\bullet$} edge [in=55,out=125,loop]
%     ();
     \node (u1) [right of=fake] {$\bullet$} edge [in=55,out=125,loop] ();
     \node (u2) [below of=u1] {$\bullet$} ;% edge [in=305,out=235,loop] ();
     \draw[->] (u1) to node {} (u2) ;
     \path node at (6.4,-1) {$u_1$};
     \path node at (6.4,-3) {$u_2$}  ;

     \draw [rounded corners] (4,-5) -- ++(4,0)  -- ++(0,6) -- ++(-4,0) --  cycle;

     \path node at (7,0.5) {${G}$};

  \end{tikzpicture}
\end{center}
\end{problem}

\begin{problem}  [15 points]
  Let the frames ${F}$ and ${G}$ be like in Problem
\olref{problem:frames}, and assume that the language only comprises
propositional variable $p_1, p_2, p_3$ for simplicity.
\begin{enumerate}
\item find valuations $U : \{p_1,p_2,p_3\} \to \Pow{W}$ and $V :
\{p_1,p_2,p_3\} \to \Pow{X}$ such that there is a $p$-morphism
between the models ${M} = ({W}, R, U)$ and ${N} = ({X}, S, V)$.
\item Are there valuations $U$ and $V$ such that the corresponding
  models are not $p$-morphic?
\end{enumerate}
\end{problem}

\begin{problem}  [15 points]
  Let $\pi$ be a $p$-morphism between models ${M} =
  ({W}, R, U)$ and ${N} = ({X}, S, V)$. Show that
  for any !!{formula} $!A$ and world $w \in {W}$,
  \[
  \mSat{M}{!A}[w] \text{ if and only if }
  \mSat{N}{!A}[\pi(w)].
  \]
\end{problem}

\begin{problem}  [15 points]\ollabel{problem:AE}
  Show that for any model ${N}$ on ${G}$ there is a model ${M}$ on
  ${F}$ and a $p$-morphism $\pi$ from ${M}$ onto ${N}$.
\end{problem}

\begin{problem} [10 points]
  Show that the converse to Problem \olref{problem:AE} does not hold,
    i.e., that there is a model on ${F}$ that is not
    $p$-morphic to any model on ${G}$.
\end{problem}

\begin{problem} [10 points]\ollabel{problem:valid}
  Show that if !!a{formula} $!A$ is valid on $\mModel{F}$ then it is
  valid on $\mModel{G}$.\footnote{Warning. This requires showing that
    if $!A$ is true in any model on $\mModel{F}$ then it is true
    in any model on $\mModel{G}$. Use Problem \olref{problem:AE}.}
\end{problem}

\begin{problem} [10 points]
  Show that the converse of Problem \olref{problem:valid} does not hold,
  i.e., that there is !!a{formula} $!A$ that is valid on $\mModel{G}$ but
  not on $\mModel{F}$.\footnote{Hint. Consider !!a{formula} that says: `At any
    non-terminal world: if $!A$ is true and also true at any
    accessible terminal world, then $!A$ is necessary.'
%    $\lnot \Box\lfalse \lif \left[(!A \land \Box(\Box\lfalse \to
%      !A)) \lif \Box!A]$
}
\end{problem}

\begin{problem}  [15 points]
  The schema $T$, i.e., $\Box!A \lif !A$ is valid in a frame
  if and only if the frame is reflexive. Is there a schema that is
  valid in a frame if and only if the frame is \emph{irreflexive}?
\end{problem}

\section{Problem set 4: pebble games over Kripke frames}
\setcounter{problem}{0}

\begin{definition}[Two-pebble games on Kripke structures]
  Given two Kripke models ${M} = \tuple{W, R, U}$ and ${N} = \tuple{X,
    S, V}$ and worlds $u \in W$ and $v \in X$, the \emph{two-pebble
    game} $G({M}, u : {N}, v)$ between Abelard (``Abe the Spoiler'')
  and Elo\"ise (``Elly the Defender'') is defined as follows.

  Abelard and Elo\"ise share two pebbles, which at the beginning of
  the game are placed on the worlds $u$ and $v$.  A \emph{round} in
  the game begins with Abelard's sliding one of the pebbles along the
  accessibility relation ($R$ in ${M}$ or $S$ in ${N}$).  Elo\"ise
  likewise responds by sliding the other pebble along $S$ or $R$,
  respectively. In this way, two worlds $u'$ and $v'$ are identified
  such that $Ruu'$ and $Svv'$. If neither player wins the game at this
  round (as explained below), then both players advance and play a
  round of the game $G({M}, u' : {N}, v')$. Suppose the pebbles are on
  worlds $u \in W$ and $v\in X$; this configuration is assessed as a
  \emph{win} in the game $G({M}, u : {N}, v)$ for one or the other
  players based on whether the following conditions hold:
  \begin{enumerate}
  \item If there is an atomic sentence $p$ true at $u$ and false at
    $v$, or vice-versa, it's an automatic win for Abelard.
    \item If the worlds $u$ and $v$ are both terminal, it's an
      automatic win for Elo\"ise.
  \item If at any point Elo\"ise cannot slide her pebble to match
    Abelard's move, he wins.
  \item If the game goes on forever, that counts as a win for
    Elo\"ise.
  \end{enumerate}
\end{definition}

 \begin{definition}
   A \emph{strategy} for either player in the game $G({M}, u :
   {N}, v)$ is just a function prescribing a response to each
   possible move of the other player. A \emph{winning strategy} is
   strategy that guarantees a win for the player following it.
 \end{definition}

\begin{problem}
  Show that if Abelard does \emph{not} have a winning strategy in the game
  $G({M}, u : {N}, v)$ then for any modal !!{formula}
  $!A$ we have $\mSat{M}{!A}[u]$ if and only if
  $\mSat{N}{!A}[v]$.
\end{problem}

\end{document}


\documentclass[12pt]{cdblatex}
\usepackage{exercises}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% --------------------------------------------------------------------------------------------
\section*{Exercise 4.4 Reformatting simple expressions}

\begin{cadabra}

   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   \nabla{#}::Derivative.

   def reformat (obj,scale):

       {x^{a},A_{a b},B_{a b},C_{a b},g^{a b}}::SortOrder.  # choose a sort order

       foo  = Ex(str(scale))          # create a scale factor
       bah := @(foo) @(obj).          # apply the scale factor, clears all fractions

       distribute     (bah)           # only required if (bah) contains brackets
       sort_product   (bah)
       rename_dummies (bah)
       canonicalise   (bah)
       factor_out     (bah,$x^{a?}$)

       ans := @(bah) / @(foo).        # undo previous scaling

       return ans

   # ---------------------------------------------------------------

   # a messy unformatted expression

   expr := + (1/3) A_{a b} x^{a} x^{b}
           + (1/9) B_{e c} x^{c} x^{e}
           - (1/5) C_{p c} B_{d q} g^{c d} x^{p} x^{q}.  # cdb (ex-0404.100,expr)

   # reformat terms and tidy fractions

   expr = reformat (expr,45)                             # cdb(ex-0404.101,expr)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \Dmath*{ g = \Cdb*[\V{15pt}\hfill]{ex-0404.100}
              = \Cdb*{ex-0404.101} }
\end{dgroup*}

\end{document}


\section {Foundations of dataflow analysis}
\setlength{\parindent}{0pt}
(Prepared by Vardhan Jain)

\vspace{0.3cm}

\subsection{Advantages of common Dataflow Analysis framework}
\begin{itemize}
    \item \textbf{Prove properties for an entire family of problems} : We prove properties for the framework
    and basically we have proven properties for different dataflow analysis problems together.
    \item \textbf{Aids in software engineering} : We can write the basic logic in a base class and all our data
    flow analysis algorithms can be derived from that base class. We won't have to repeat the same logic.
\end{itemize}

\subsection{Dataflow Analysis problems \textbf{($F$, $V$, \^{})} are defined by}
\begin{itemize}
    \item \textbf{A semilattice ($V$, \^{})} : Semilattice is defined by the domain of values represented by $V$ and
    the meet operator \^{} represented by the caret symbol.
    \item \textbf{A family of transfer functions $F:V\rightarrow V$} : A transfer function is defined as a function that takes value
    from the set of values $V$ and returns value in the same set of values $V$. $F$ represents family of all such possible functions.
    They need to satisfy certain properties in order to be admissible.
\end{itemize}
\subsection{Semilattice}
A semilattice S = \textless a set of values $V$, a meet operator \^{} where the meet operator \^{} \textgreater  has the following properties:
\begin{itemize}
    \item \textbf{Idempotent} x \^{} x = x
    \item \textbf{Commutative} x \^{} y = y \^{} x
    \item \textbf{Associative}  x \^{} (y \^{} z) = (x \^{} y) \^{} z
\end{itemize}
Examples of meet operator \^{} - set-union, set-intersection, and, or, min, max \\
Some non-examples of meet operator are add, subtract, multiply, divide etc.

\subsection{Semilattice examples}
V = \{x {\textbar} x is the subset of \{$d_{1}$, $d_{2}$, $d_{3}$\}\}, \^{} $\triangleq$ set-union,
Ordering $\leq$ $\triangleq$ $\supseteq$. Figure \ref{fig:semilattice_union} shows the semilattice diagram, the nodes represent the values and the edge represent the ordering. If there is an edge from a to b then a $\geq$ b. More precisely there is a path from node a to node b iff a $\geq$ b. This is a partial ordering as not all values are comparable. Meet of two values $v_{1}$ and $v_{2}$ can be inferred from the semilattice diagram as the first common descendant node of nodes with values $v_{1}$ and $v_{2}$.\par
Another example contains values as 2-tuples booleans. The four possible values are \{true, true\}, \{false, true\}, \{true, false\} and \{false, false\}. The semilattice diagram is shown in figure \ref{fig:semilattice_and}. Here \^{} is logical AND.
\begin{figure}
    \centering
    \includegraphics[width=1\linewidth]{images/semilatticeSetUnion.png}
    \caption{Set union semilattice example}
    \label{fig:semilattice_union}
\end{figure}
\begin{figure}[h!]
\caption{Boolean tuples logical AND semilattice example}
\begin{center}
\begin{tikzpicture}[-latex ,auto ,node distance =3.5cm and 5cm ,on grid ,
    semithick ,
    state/.style ={ rectangle ,top color =white , bottom color = blue!20 ,
    draw, blue , text=blue , scale = 0.7 ,minimum width =3.5 cm, minimum height = 1.5 cm}]
    \node[state] (A){} node [label = {}, rectangle split,rectangle split parts=2]{%
      \{true, true\}%
      };
    \node[state] (B) [below left = of A]{} node [label = {},rectangle split,rectangle split parts=2] [below left = of A] {%
      \{false, true\}%
      };
    \node[state] (D) [below right =of A]{} node [label = {},rectangle split,rectangle split parts=2] [below right = of A] {%
      \{true, false\}%
      };
    \node[state] (E) [below left =of D]{} node [label = {},rectangle split,rectangle split parts=2] [below left = of D] {%
      \{false, false\}%
      };
    \path[->] (A) edge node [above = 0.3 cm] {} (D);
    \path[->] (A) edge node [above = 0.3 cm] {} (B);
    \path[->] (B) edge  (E);
    \path[->] (D) edge  (E);

\end{tikzpicture}
\end{center}
\label{fig:semilattice_and}
\end{figure}

\subsection{Semilattice properties}
\begin{itemize}
    \item x \^{} y is the first common descendant of x and y.
    \item Define top value T such that x \^{} T = x for all x
    \item Define bottom ($\bot$) such that x \^{} $\bot$ = $\bot$ for all x
    \item Semilattice diagram = picture of partial orders

\end{itemize}

% \subsection{Example of \^{} and $\leq$}
% Set-union


\section{Exercise}  %Jonathan / b-j8518 /Jul 19
\subsection{Problem 6 (Homework 3)}
For $\phi \in {\rm DNN}_l$, $\phi$ is a continuous and piecewise linear function. $\mathbb{R}^d = \bigcup_i \bar{D}_i$, $D_i$ is a polyhedron. $\phi$ is linear on $D_i$. Plot some of these functions for $d=2$.

A neural network with ReLU activation functions produces a piecewise linear functions:
$NN(x,\theta)$ is piecewise in $x$.
Why is this a piecewise linear function?
\begin{equation}\label{eq:DNN}
NN(x,\theta) = W_l \sigma (\cdots W_3 \sigma(W_2 \sigma (W_1 x+b_1) +b_2)+b_3 \cdots)+b_l
\end{equation}
Notice that
\begin{itemize}
\item linear map is piecewise linear,
\item and ReLU function is piecewise linear.
\item Composition of piecewise linear functions are piecewise linear. (Not trivial)
\end{itemize}
You should convince you self the third result is true. Being piecewise linear is the same thing that Hessian is zero or almost everywhere.
The whole point of this exercise is to study the piecewise linear functions which are results from neural network process \eqref{eq:DNN}.

For example, Consider the grid as follows.
\begin{figure} [H]%\label{mugrid-bi}
\begin{center}
\setlength{\unitlength}{0.445mm}
\begin{picture}(40,40)(40,0)
\linethickness{0.1mm}
\multiput(0,40)(15,0){3}{\line(0,-1){30}}
\multiput(0,10)(0,15){3}{\line(1,0){30}}
\put(0,10){\line(1,1){30}}
\put(15,10){\line(1,1){15}}
\put(0,25){\line(1,1){15}}
\end{picture}
\end{center}
\end{figure}
And consider functions that piecewise linear on each triangles.
In finite element, we consider piecewise linear functions which are linear on a `nice' set of polygon that tile the plane.
Now we show how to implement it. There is a network we will plot.
\begin{python}
import torch
import torch.nn as nn
from torch.autograd import Variable
import matplotlib as plt

import numpy as np

class TestNet(nn.Module):
	def __init__(self):
		super(TestNet, self):__init__()
		self.function = nn.Sequential(nn.Linear(2, 25), nn.ReLU(), nn.Linear(25, 25), nn.ReLU(), nn.Linear(25, 1))
	def forward(self, x):
		return self.finction(x)

def main():
	net = TestNet()
	dy = 0.05
	dx = 0.05
	size = 400
	df_x = torch.zeros(size, size)
	df_y = torch.zeros(size, size)
	for i in range(size):
		for i in range(size)
			q = Variable(torch.Tensor([-1 + (i + 0.5) * dx, -1 + (j + 0.5) * dy]), requires_grad=True)
			output = net(q)
			df = torch.autograd.grad(output, q)
			df_x[i, j] = df[0][0]
			df_y[i, j] = df[0][1]
		df_x = (df_x - torch.min(df_x)) / (torch.max(df_x) - torch.min(df_x))
		df_y = (df_y - torch.min(df_y)) / (torch.max(df_y) - torch.min(df_y))
		df_color = torch.zeros(size, size, 3)
		df_color[:, :, 0] = df_x
		df_color[:, :, 1] = df_y
		plt.imshow(df_color)
		locs._labels = plt.xticks()
		locs = locs[1:]
		new_labels = []
		for i in locs:
			new_labels.append(-1.0 + i * dx)
		plt.xticks(locs, new_labels)
		plt.yticks(locs, new_labels)
		plt.show()
\end{python}

\subsection{Tips for Final Project} %Jonathan / b-j8526 /Jul
In this section, we will introduce some tools that might be used in the final project. PyTorch has a library here call \emph{torchvision.models}. PyTorch also implement all of the model in the list for you, so you don't need to build it yourselves.
\begin{itemize}
\item AlexNet
\item VGG
\item ResNet
\item SqueezeNet
\item DenseNet
\item Inception v3
\item GoogLeNet
\item ShuffleNet v2
\item MobileNet v2
\item ResNeXt
\item Wide ResNet
\item MNASNet
\end{itemize}
However, all of the models implemented here are built for ImageNet, which is a dataset consisting much bigger images than CIFAR10.

For example, if we look at one of the models, the VGG16 model. You can create a model:
\begin{python}
import torchvision.models as models
model = models.vgg16()
\end{python}
You can use \emph{print(model)} to see the list of the layers implemented.
\begin{figure}
\begin{center}
\includegraphics[scale=0.5]{../figures/497Proj_vgg16}
\end{center}
\end{figure}
You may notice that this is pretty deep, and there is a lot of max pooling layers. Each of max pooling step will decrease the size of the image by factor 2. If you plug in the CIFAR10
image which is $32\times 32$, then after a couple of these max pooling, it will be a single pixel. So the point is the model is too deep for CIFAR10. Because this model is implemented for ImageNet and too big, you can just take the model and implement it. But it's better to use this model as a template for VGG and make it smaller for CIFAR10. Use fewer channels in each convolution and use fewer layers.

The other model is the ResNet model. We can print the list of the layers in ResNet in the same way.
This is a bit more complicated and also written for ImageNet. You should reduce number of channels and number of layers, and keep the same structure.


% !TEX root = ../00_thesis.tex

%-------------------------------------------------------------------------------
\section{Appendix -- Worst-case Latency Analysis}
\label{append:drp_WCanalysis}
%-------------------------------------------------------------------------------

%\subsubsection{Worst-case analysis of the source delay}
\fakepar{Worst-case analysis of the source delay}
\begin{definition}[Source delay -- $\delta_{source}$]
The source delay is the elapsed time from
a packet being written in \bolt by the source \apsrc
until
the end of the \opflush operation where it is read out of \bolt by the source \cpsrc.
For a flow \flowi, it is denoted by $\delta_{source, \,i}$.
\end{definition}

\begin{lemma}\label{lem:delta_source}
For any flow \flowi, the source delay is upper-bounded by
\begin{equation}
\label{eq:delta_source}
\delta_{source, \,i} \; \leq \; C_w + T_f^s + C_f
\end{equation}
\end{lemma}

\begin{proof}%
Let us recall that a \opflush is a sequence of \opread operations. When the \bolt queue is found empty, the \opflush is terminated and no other \opread is performed until the next \opflush (refer to \ref{subsec:boltAPI} for details).
Therefore, if the \bolt queue is empty and a \opwrite operation terminates just after a \opflush is triggered, that \opflush immediately terminates and the packet is delayed until to the end of the next \opflush.
Possible jitter on the \opwrite operation pattern does not have any influence on the worst-case for $\delta_{source, \,i}$.
This worst-case scenario for the source delay is illustrated on Fig.~\ref{fig:delta_source_time_graph}. \
\end{proof}

\begin{figure}[h!]
\centering
\includegraphics[scale=1]{delta_source_time_graph}
\caption{Worst-case analysis of the source delay.
\capt{A packet is written as early as possible such that it misses a \opflush and must wait until the next one.}}
\label{fig:delta_source_time_graph}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%======================
%%%%%%%%%%%%%%%%%%%%%%%%%%

\fakepar{Worst-case analysis of the network delay}
\begin{definition}[Network delay -- $\delta_{network}$]
The network delay is the elapsed time from
a packet being available for communication at the source \cpsrc
until
the end of the communication round where it is served by the wireless protocol (i.e., when it is available at the destination \cpdst).
For a flow \flowi, it is denoted by $\delta_{network, \,i}$.
\end{definition}

\begin{lemma}\label{lem:delta_network}
For any flow \flowi, the network delay is upper-bounded by
\begin{equation}
\label{eq:delta_network}
\delta_{network, \,i} \; \leq \; T_i + D_i + \floor*{\frac{\jitteri + C_f - C_r}{T_f^s}}\cdot T_f^s
\end{equation}
\end{lemma}
\begin{proof}%
As presented in \cref{subsec:details_blink}, \blink guarantees that every packet matching the \emph{expected arrival} is served in a round that terminates before the network deadline $D_i$; \ie the \emph{delay of an expected packet} is no more than $D_i$.

However, the actual arrival of packets at the source \cpsrc does not match the expected arrival in general, but results from \opflush operations, which occur every $T_f^s$ time unit.
Hence, a packet may arrive \emph{earlier} than the next expected packet. That mismatch between the two arrival times (actual and expected) adds up with the delay of the expected packet (i.e., $D_i$).

Let us consider first that the flow \flowi has no jitter (\ie $\jitteri =0$) and let $m$ be the mismatch between actual and expected arrival time at \cpsrc. $m$ cannot be larger than the flow's minimum message interval $\periodi$
\[
m \;\leq\; \periodi
\]
The intuition is given with \cref{fig:delta_network_time_graph1}. See the caption for details.

\begin{figure}[h!]
\centering
\includegraphics[scale=1]{delta_network_time_graph1}
\caption{Worst-case analysis of the network delay without jitter.
\capt{Because of the \bolt queue being empty, packet \textbf{A} misses the first flush operation (similarly as in \cref{fig:delta_source_time_graph}), hence the slot allocated to \flowi in round \textbf{1} is wasted. Due to packets released from other flows in the meantime, packet \textbf{B} is flushed directly in the operation preceding round \textbf{3}, in which flow \flowi is allocated a new slot. However, as packet \textbf{A} is still in queue, packet \textbf{B} is not served right away but is delayed until the next allocated slot (\ie in round \textbf{6}). This creates a mismatch of \periodi for packet \textbf{B}.
Furthermore, the mismatch cannot get bigger; assume \textbf{B} were to be available at \cpsrc earlier (\ie one flush operation before, at least), because the time interval between \textbf{A} and \textbf{B} must be at least \periodi, \textbf{A} would arrive earlier as well.
Hence, \textbf{A} would not miss the slot in round \textbf{1}, \textbf{B} would be served in round \textbf{3},
and thus it would yield a smaller mismatch for packet \textbf{B}.}}
\label{fig:delta_network_time_graph1}
\end{figure}

Now, if flow \flowi has also jitter \jitteri, this may entail a bigger mismatch. Actual "arrival" of packets (\ie the epoch when a packet is available for communication at the source \cpsrc, according to the definition of the network delay) can occur only every $T_f^s$ (\ie at the end of one \opflush operation). Therefore, one can see that jitter may induce an extra delay, or mismatch, of roughly $\floor*{\jitteri/T_f^s}\cdot T_f^s$. A more precise analysis of the flushing dynamics (see \cref{fig:delta_network_time_graph2} for details) entails that, overall, the worst-case mismatch $m$ is bounded by

\begin{align}
\label{eq:mismatch}
m \; \leq \;\; &
	T_i + \floor*{\frac{\jitteri + C_f - C_r}{T_f^s}}\cdot T_f^s\\
\intertext{and finally,}
\notag
\delta_{network, \,i} \; \leq \;\; &
	D_i + m \\
\notag
\delta_{network, \,i} \; \leq \;\; &
	T_i + D_i + \floor*{\frac{\jitteri + C_f - C_r}{T_f^s}}\cdot T_f^s \quad \
\end{align}
\end{proof}

\begin{figure}[h!]
\centering
\includegraphics[scale=1]{delta_network_time_graph2}

\caption{Influence of jitter on the network delay.
\capt{Let us have a closer look at packet \textbf{B} from the previous figure, positioned as early as possible (\ie if it were earlier, so would be \textbf{A}, which would then not miss its slot in round \textbf{1}).
Due to jitter, \textbf{B} is released earlier, say by a amount $j$. This can yield packet \textbf{B'} (\textbf{B} with jitter) to be read out in a previous \opflush operation. In the worst-case, packet \textbf{B'} is read out one operation earlier as soon as $j$ is bigger than $T_f^s - C_f + C_r$, which increases the mismatch $m$ by $T_f^s$. Similarly, $m$ increases by $k \cdot T_f^s$ when $j$ reached  $k \cdot T_f^s - C_f + C_r$, which yields $k = \floor*{\frac{j + C_f - C_r}{T_f^s}}$ and concludes to equation \eqref{eq:mismatch}.
}}
\label{fig:delta_network_time_graph2}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%======================
%%%%%%%%%%%%%%%%%%%%%%%%%%

\fakepar{Worst-case analysis of the destination delay}

\begin{definition}[Destination delay -- $\delta_{dest}$]
The destination delay is the elapsed time from
a packet being available at the destination \cpdst
until
the end of the \opflush operation where it is read out of \bolt by the destination \apdst (i.e., when it is available for the application).
For a flow \flowi, it is denoted by $\delta_{dest, \,i}$.
\end{definition}

\newpage
\noindent

\begin{lemma}\label{lem:delta_destination}
For any flow \flowi, the destination delay is upper-bounded by
\begin{equation}
\label{eq:delta_destination}
\delta_{dest, \,i} \; \leq \; \nslotsmax*C_w - (\nslotsmax-1)* C_r + T_f^d + C_f
\end{equation}
\end{lemma}

\begin{proof}
The situation is similar as for the source delay, except
that \cpdst writes every $T_{net}$ time unit (\ie after each round) all the packets it received during the last round, which can be as many as \nslotsmax packets.
%\cp writes packets to \bolt sequentially after each communication rounds, where they stay until they are flushed out by AP.
The maximal delay for a packet occurs when it is written too late to be read out during an ongoing \opflush and must wait for the next one.

A careful analysis of the \bolt dynamics shows that the \opread operation is slightly shorter than \opwrite \cite{sutton2015Bolt} (i.e., $C_r < C_w$, see Table \ref{table:simulation_parameters}). Hence, the more packets are written at once by \cpdst, the later a \opflush can start and still miss the last written packet. The worst-case is illustrated on Fig.~\ref{fig:delta_destination_time_graph}. \
\end{proof}

\begin{figure}[h!]
\centering
\includegraphics[scale=1]{delta_destination_time_graph}
\caption{Worst-case analysis of the destination delay.
\capt{A packet is written as early as possible such that it misses a \opflush and must wait until the next one.}}
\label{fig:delta_destination_time_graph}
\end{figure}


\section{Latent Dirichlet Allocation (LDA)}

This is a C implementation of latent Dirichlet allocation (LDA), a
model of discrete data which is fully described in Blei et al. (2003)
(http://www.cs.berkeley.edu/~blei/papers/blei03a.pdf).

LDA is a hierarchical probabilistic model of documents.  Let \alpha be
a scalar and \beta_{1:K} be K distributions of words (called "topics").
As implemented here, a K topic LDA model assumes the following
generative process of an N word document:

          1. \theta | \alpha ~ Dirichlet(\alpha, ..., \alpha)

          2. for each word n = {1, ..., N}:

             a. Z_n | \theta ~ Mult(\theta)

             b. W_n | z_n, \beta ~ Mult(\beta_{z_n})

This code implements variational inference of \theta and z_{1:N} for a
document, and estimation of the topics \beta_{1:K} and Dirichlet
parameter \alpha.

\subsection{Data format}

Under LDA, the words of each document are assumed exchangeable.  Thus,
each document is succinctly represented as a sparse vector of word
counts. The data is a file where each line is of the form:

     [M] [term_1]:[count] [term_2]:[count] ...  [term_N]:[count]

where [M] is the number of unique terms in the document, and the
[count] associated with each term is how many times that term appeared
in the document.  Note that [term_1] is an integer which indexes the
term; it is not a string.

\subsection{Configuration}

\begin{description}
	\item[var max iter (integer; default: -1)]
	The maximum number of iterations of coordinate ascent variational
	inference for a single document.  A value of -1 indicates "full"
	variational inference, until the variational convergence
	criterion is met.

	\item[var convergence] (float; default: 1e-6)]
	The convergence criteria for variational inference.  Stop if
	(score_old - score) / abs(score_old) is less than this value (or
	after the maximum number of iterations).  Note that the score is
	the lower bound on the likelihood for a particular document.

	\item[em max iter] (integer; default: 100)]
	The maximum number of iterations of variational EM.

	\item[em convergence (float; default: 1e-4)]
	The convergence criteria for varitional EM.  Stop if (score_old -
	score) / abs(score_old) is less than this value (or after the
	maximum number of iterations).  Note that "score" is the lower
	bound on the likelihood for the whole corpus.

	\item[alpha (string: `fit' or `estimate'; default: estimate)]
	If set to [fixed] then alpha does not change from iteration to
	iteration.  If set to [estimate], then alpha is estimated along
	with the topic distributions.
\end{description}

\subsection{Running}

\subsubsection{Topic estimation}

Estimate the model by executing:

     lda est [alpha] [k] [settings] [data] [random/seeded/*] [directory]

The term [random/seeded/*] > describes how the topics will be
initialized.  "Random" initializes each topic randomly; "seeded"
initializes each topic to a distribution smoothed from a randomly
chosen document; or, you can specify a model name to load a
pre-existing model as the initial model (this is useful to continue EM
from where it left off).  To change the number of initial documents
used, edit lda-estimate.c.

The model (i.e., \alpha and \beta_{1:K}) and variational posterior
Dirichlet parameters will be saved in the specified directory every
ten iterations.  Additionally, there will be a log file for the
likelihood bound and convergence score at each iteration.  The
algorithm runs until that score is less than "em_convergence" (from
the settings file) or "em_max_iter" iterations are reached.  (To
change the lag between saved models, edit lda-estimate.c.)

The saved models are in two files:

     <iteration>.other contains alpha.

     <iteration>.beta contains the log of the topic distributions.
     Each line is a topic; in line k, each entry is log p(w | z=k)

The variational posterior Dirichlets are in:

     <iteration>.gamma

The settings file and data format are described below.

\subsubsection{Inference}

To perform inference on a different set of data (in the same format as
for estimation), execute:

     lda inf [settings] [model] [data] [name]

Variational inference is performed on the data using the model in
[model].* (see above).  Two files will be created : [name].gamma are
the variational Dirichlet parameters for each document;
[name].likelihood is the bound on the likelihood for each document.

\subsection{Results}

\subsubsection{Printing topics}

The Python script topics.py lets you print out the top N
words from each topic in a .beta file.  Usage is:

     python topics.py <beta file> <vocab file> <n words>

\begin{lstlisting}
#! /usr/bin/python

# usage: python topics.py <beta file> <vocab file> <num words>
#
# <beta file> is output from the lda-c code
# <vocab file> is a list of words, one per line
# <num words> is the number of words to print from each topic

import sys

def print_topics(beta_file, vocab_file, nwords = 25):

    # get the vocabulary

    vocab = file(vocab_file, 'r').readlines()
    # vocab = map(lambda x: x.split()[0], vocab)
    vocab = map(lambda x: x.strip(), vocab)

    # for each line in the beta file

    indices = range(len(vocab))
    topic_no = 0
    for topic in file(beta_file, 'r'):
        print 'topic %03d' % topic_no
        topic = map(float, topic.split())
        indices.sort(lambda x,y: -cmp(topic[x], topic[y]))
        for i in range(nwords):
            print '   %s' % vocab[indices[i]]
        topic_no = topic_no + 1
        print '\n'

if (__name__ == '__main__'):

    if (len(sys.argv) != 4):
       print 'usage: python topics.py <beta-file> <vocab-file> <num words>\n'
       sys.exit(1)

    beta_file = sys.argv[1]
    vocab_file = sys.argv[2]
    nwords = int(sys.argv[3])
    print_topics(beta_file, vocab_file, nwords)
\end{lstlisting}


\documentclass{article}

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

\usepackage{amsthm}
\newtheorem{defn}{Definition}

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

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

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

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

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

\newlength\figurewidth
\newlength\figureheight

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

\newlength\squarefigurewidth
\newlength\squarefigureheight

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

\newlength\smallsquarefigurewidth
\newlength\smallsquarefigureheight

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

\newlength\smallfigurewidth
\newlength\smallfigureheight

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

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

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

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

\begin{document}

\section*{Conditioning on Outputs of Linear Operators}

Suppose we have a function $f\colon \mc{X} \to \R$ with a Gaussian
process prior distribution:
\begin{equation*}
  p(f) = \mc{GP}(f; \mu, K).
\end{equation*}
We have discussed how to perform inference about $f$ when given
(noisy) observations of the function at a set of points $\mat{X}$:
$\data = (\mat{X}, \vec{y})$.  Here we are going to expand the types
of observations we may use during \acro{GP} inference.

\subsection*{Functionals and linear functionals}

Specifically, we are going to consider so-called \emph{linear
  functionals} of $f$.  A \emph{functional} is a function $L[f]$ that
takes as an input a function $f$ and returns a scalar.  (Functionals
are sometimes called ``functions of functions.'')  A very simple
example of a functional is the \emph{point-evaluation functional.}
Let $x \in \mc{X}$ be an arbitrary fixed point in the domain.  We
define a corresponding functional $L_x$ by
\begin{equation*}
  f \mapsto L_x[f] = f(x).
\end{equation*}
So, given a function $f$, the point-evaluation functional $L_x$ simply
evaluates $f$ at $x$ and returns the result.  This is a functional we
are very accustomed to using.

A functional is said to be $\emph{linear}$ when it satisfies a simple
linearity property.  Specifically, let $a \in \R$ be an arbitrary
scalar constant and let $f$ and $g$ be two arbitrary functions.  A
functional $L$ is linear if the following equality always holds:
\begin{equation*}
  L[af + g] = aL[f] + L[g].
\end{equation*}
It is easy to see that the point-evaluation functional $L_x$ is
linear:
\begin{equation*}
  L_x[af + g]
  =
  (af + g)(x)
  =
  af(x) + g(x)
  =
  aL_x[f] + L_x[g].
\end{equation*}

There are several other quite-common linear functionals that we are
familiar with.  The two we will discuss here are integration against
an arbitrary function $p(x)$:
\begin{equation*}
  f \mapsto I_p[f] = \int_{\mc{X}} f(x) p(x) \intd{x},
\end{equation*}
and (partial) differentiation at a point $x$:
\begin{equation*}
  f \mapsto D_{x, i}[f] = \frac{\partial f(z)}{\partial z_i} \biggr\rvert_{z = x}.
\end{equation*}

\subsection*{Conditioning on linear functionals}

It turns out that we can once again exploit the closure of the
Gaussian distribution to linear transformations to condition a
\acro{GP} on $f$ on the observation of any linear functional of $f$!
This will allow us to both perform inference about $f$ given
observations of, for example, derivatives of $f$, and also to perform
inference about linear functionals of $f$ directly.  This will provide
us with a Bayesian mechanism for estimating integrals (a task
traditionally called \emph{quadrature}).

Suppose we have an unknown function $f\colon \mc{X} \to \R$ with the
Gaussian process prior above:
\begin{equation*}
  p(f) = \mc{GP}(f; \mu, K),
\end{equation*}
and let $L$ be a linear functional.  We will write $\ell = L[f]$.
Just as Gaussian distributions are closed under linear
transformations, so are Gaussian processes closed under the evaluation
of linear functionals!  The prior distribution for $\ell$ is a
Gaussian distribution:
\begin{equation*}
  p(\ell)
  =
  \mc{N}\bigl(\ell; L[\mu], L^2[K]\bigr)
\end{equation*}
where
\begin{equation*}
  L^2[K]
  =
  L\Bigl[L\bigl[K(\cdot, x')\bigr]\Bigr]
  =
  L\Bigl[L\bigl[K(x, \cdot)\bigr]\Bigr].
\end{equation*}
This result is essentially equivalent to the result for linear
transformations of Gaussian-distributed vectors we have been using
thus far, written with different notation.  Notice also that if we
consider the point-evaluation functional $L_x$, we recover a basic
result:
\begin{equation*}
  p\bigl(f(x) \given x\bigr)
  =
  \mc{N}\bigl(f(x); L_x[\mu], L_x^2[K]\bigr);
  =
  \mc{N}\bigl(f(x); \mu(x), K(x, x)\bigr).
\end{equation*}
Considering the integration functional, we obtain a perhaps
more-interesting result:
\begin{equation*}
  p\biggl(\int f(x) p(x) \intd{x} \biggr)
  =
  \mc{N}\biggl(\int f(x) p(x) \intd{x}; \int \mu(x) p(x) \intd{x}, \iint K(x, x') p(x) p(x') \intd{x} \intd{x'} \biggr).
\end{equation*}
Therefore a Gaussian process distribution on $f$ implies a Gaussian
distribution on its integral against an arbitrary function $p(x)$!
Further, the problem of estimating the integral of the (perhaps quite
complicated) function $f$ has been reduced to the perhaps-simpler
problem of integrating the mean and covariance functions $\mu$ and
$K$.  This is the main idea behind \emph{Bayesian quadrature,} also
called \emph{Bayesian Monte Carlo.}

Given an observation of $L[f] = \ell$, we may condition our prior on
this observation in a manner equivalent to that used to derive the
posterior distribution of $f$.  Let $\mat{X}$ be an arbitrary set of
input locations.  As before, we write the joint distribution between
$\ell$ and $\vec{f} = f(\mat{X})$:
\begin{equation*}
  p\Biggl(
  \begin{bmatrix}
    \vec{f}
    \\
    \ell
  \end{bmatrix}
  \given
  \vec{X}
  \Biggr)
  =
  \mc{N}
  \Biggl(
  \begin{bmatrix}
    \vec{f}
    \\
    \ell
  \end{bmatrix}
  ;
  \begin{bmatrix}
    \vec{\mu}
    \\
    L[\mu]
  \end{bmatrix}
  ,
  \begin{bmatrix}
    \mat{K} & \text{?}
    \\
    \text{?} & L^2[K]
  \end{bmatrix}
  \Biggr),
\end{equation*}
where we have defined:
\begin{equation*}
  \vec{\mu} = \mu(\mat{X})
  \qquad
  \mat{K} = K(\mat{X}, \mat{X}).
\end{equation*}
To fill in the missing observations, we need to know the covariance
between $\ell$ and the $i$th function value $f_i = f(\vec{x}_i)$.  Here
we can exploit the linearity of covariance:
\begin{equation*}
  \cov(f_i, \ell)
  =
  \cov\bigl(L_{\vec{x}_i}[f], L[f]\bigr)
  =
  L_{\vec{x}_i}\Bigl[L\bigl[
      \cov(f, f)
  \bigr]\Bigr]
  =
  L_{\vec{x}_i}\Bigl[L\bigl[
      K
  \bigr]\Bigr]
  =
  L\bigl[K(\vec{x}_i, \cdot)\bigr].
\end{equation*}
Now we have the general result
\begin{equation*}
  p\Biggl(
  \begin{bmatrix}
    \vec{f}
    \\
    \ell
  \end{bmatrix}
  \given
  \vec{X}
  \Biggr)
  =
  \mc{N}
  \Biggl(
  \begin{bmatrix}
    \vec{f}
    \\
    \ell
  \end{bmatrix}
  ;
  \begin{bmatrix}
    \vec{\mu}
    \\
    L[\mu]
  \end{bmatrix}
  ,
  \begin{bmatrix}
    \mat{K} & L\bigl[K(\mat{X}, \cdot)\bigr]
    \\
    L\bigl[K(\cdot, \mat{X})\bigr] & L^2[K]
  \end{bmatrix}
  \Biggr).
\end{equation*}
Finally, we may condition this joint distribution on the observed
value $\ell = L[f]$ to find the posterior of $\vec{f}$, which will be
an updated multivariate Gaussian distribution.  Because the set of
points $\mat{X}$ was arbitrary, we may conclude that the posterior
distribution is also a Gaussian process.  The posterior mean and
covariance functions are
\begin{align*}
  \mu_{f \given \ell}(\vec{x})
  &=
  \mu(\vec{x})
  +
  \frac{L\bigl[K(\vec{x}, \cdot)\bigr]}{L^2[K]}
  \bigl(\ell - L[\mu]);
  \\
  K_{f \given \ell}(\vec{x}, \vec{x}')
  &=
  K(\vec{x}, \vec{x}')
  -
  \frac{L\bigl[K(\vec{x}, \cdot)\bigr]L\bigl[K(\cdot, \vec{x}')\bigr]}{L^2[K]}.
\end{align*}
We can easily extend this result to include multiple observations of
functionals and also to incorporate Gaussian noise on each of these
observations.

An example is shown in Figure \ref{example}, where we condition a
Gaussian process prior on the integral observation $\int_{0}^{10} f(x)
\intd{x} = 5$.  Notice that the posterior samples all have integral
exactly equal to 5.

\begin{figure}
  \centering
  \input{figures/samples_example_1.tex}
  \input{figures/integral_posterior.tex}
  \caption{Above: a Gaussian process prior on a function $f$ with mean
    zero and squared exponential covariance.  Below: the posterior
    distribution on $f$ after conditioning on the obesrvation
    $\int_{0}^{10} f(x) \intd{x} = 5$.  The posterior samples all have
    integral identically equal to 5.}
  \label{example}
\end{figure}

\section*{Bayesian Quadrature}

Above, we conditioned a Gaussian process on an integral observation.
In \emph{Bayesian quadrature,} we do the opposite: given (potentially
noisy) observations of a function $\data = (\mat{X}, \vec{y})$, we
perform inference about an integral of interest, for example the
expectation of $f$ under a distribution $p$:
\begin{equation*}
  I_p[f] = \int f(x) p(x) \intd{x}.
\end{equation*}
The traditional method for estimating integrals of this form is
\emph{Monte Carlo} estimation, where we sample some points $\{ x_i
\}_{i = 1}^N$ from the distribution $p(x)$ and estimate
\begin{equation*}
  \int f(x) p(x) \intd{x}
  \approx
  \sum_{i = 1}^N f(x_i).
\end{equation*}

In Bayesian quadrature, we place a Gaussian process prior on $f$,
which we condition on the observations $\data$.  Notice that the input
locations $\mat{X}$ do not need to be random samples from $p$, but
rather we are allowed to evaluate $f$ anywhere.  The result is the posterior
\begin{equation*}
  p(f \given \data)
  =
  \mc{GP}(f; \mu_{f \given \data}, K_{f \given \data}).
\end{equation*}
Following the above, we may also derive the posterior distribution
of the expectation $I_p[f]:$
\begin{equation*}
  p\bigl(I_p[f] \given \data \bigr)
  =
  \mc{N}
  \biggl(
  I_p[f];
  \int \mu_{f \given \data}(x) p(x) \intd{x},
  \iint K_{f \given \data}(x, x') p(x) p(x') \intd{x} \intd{x'}
  \biggr).
\end{equation*}
For some choices of the prior prior mean and covariance functions
$\mu$ and $K$ and the distribution $p$, we may compute the required
integrals exactly, giving a closed-form expression for the posterior
distribution of the integral of interest.

Why is this useful?  The main advantages to this approach are that we
may explicitly model the structure of $f$ via the covariance function
$K$, and that the posterior variance of the integral may be used to
derive an active sampling scheme, revealing the most-informative
points to evaluate the function so as to estimate the integral with
the highest precision.  Note that the posterior variance of the
integral only depends on where we sample the function, and not the
actual values we observe.  This property can be exploited to design
optimal quadrature rules.

\end{document}


Numerical solutions to problems in quantum physics are important, given the limited availability of exact solutions. Many such models and methods exist when dealing with many-body systems, and have been shown to provide good estimates of physical behaviour~\cite{BK:Krauth_2006}. Techniques such as Monte Carlo methods, exact diagonalisation, and DMRG are used to solve a wide variety of many-body problems, but often fail to capture the full system dynamics of such problems~\cite{NUM:Schollwock_rmp_2005}. For understanding the behaviour of systems such as Bose--Einstein condensates, the use of these methods is rather limited. For DMRG, the complexity of the problem grows quickly with increasing dimensionality and renders this technique unusable. Exact diagonalisation requires a linearised system to obtain realistic solutions, and also grows significantly in complexity with increased dimensionality. Monte Carlo methods generally do not allow for real-time dynamics, or allow one to calculate the underlying wavefunction.

To obtain solutions to BEC problems we make use of a mean-field approach, outlined previously in Sec.~\ref{sub:gpederiv}. Using the GPE and performing a numerical integration allows for almost all examinable dynamics that are valid in the mean-field limit. It can be noted though that the computational cost increases significantly with increased dimensions, and is already non-trivial for two-dimensions. The following chapter will introduce the necessary requirements to numerically solve quantum problems using state-of-the-art computational methods.

We will begin with an introduction to the time evolution of a quantum state. We then discuss the use of the time evolution approach to find the ground state of a quantum system using imaginary time evolution. After this necessary mathematical introduction we will discuss the implementation of both real and imaginary time evolution using the Fourier split-operator (split-step) algorithm. We give error bounds for the algorithm, and discuss its use in the context of solving for Hamiltonian dynamics. Though the discussed algorithm is well suited to solving quantum dynamics, the computational cost can be quite high, especially for systems with large grid sizes.

We next discuss ways to overcome this through the use of high performance computing methods, and introduce the concept of graphical processing unit (GPU) computing. We present many of the necessary considerations for mapping a computational problem onto GPUs. Making use of GPUs to numerically solve the Schr\"odinger equation with the Fourier split-operator method, we present the problem of coherent atomic transport. We introduce the ``matter-wave spatial adiabatic passage'' technique, with the goal of coherently transporting an atom between trapping potentials with high fidelity. The design of the model system is presented, and the results are shown.

We finish the chapter by introducing the developed algorithms for condensate systems. Performance metrics and considerations are given in the context of solving the Gross--Pitaevskii equation in the presence of vortices.

\section{Time evolution}\label{sec:timeev}
Given a quantum state, to examine the dynamics requires an understanding of how it evolves in time. Assuming a quantum state at time $t_0$ to be defined as $|\Psi(t_0) \rangle$, and a state at time $t$ to be $|\Psi(t) \rangle$, the two states can be connected with a unitary evolution operator as
\begin{equation}
    |\Psi(t) \rangle = \mathscr{U}(t,t_0) | \Psi(t_0) \rangle,
\end{equation}
where we have assumed that $t > t_0$. One can write the wavefunction of a quantum system as the linear superposition of a set of basis states $|\Psi_m\rangle$ as
\begin{equation}\label{eqn:psicomplete}
    |\Psi \rangle = \displaystyle\sum\limits_{m} C_m |\Psi_m \rangle,
\end{equation}
with coefficients $C_m$. The unitary evolution operator can be written as
\begin{align}
   \mathscr{U}(t,t_0) &= \exp\left(-\frac{i\mathcal{H}(t - t_0)}{\hbar} \right) \\ &= \exp\left(\frac{-\text{i}\mathcal{H}\delta t}{\hbar}\right),
\end{align}
\iffalse
\begin{align}
   \mathscr{U}(t,t_0) &= \exp\left(-\frac{i}{\hbar}\displaystyle\int\limits_{t_0}^{t}\mathcal{H}\text{d}t\right),
\end{align}
\fi
where $\mathcal{H}$ is the Hamiltonian of the system, and $\delta t = t - t_0$. %For an incremental change $\delta t$ such that $t = t_0 +\delta t$ the above operator can be replaced by the form
%\begin{align}\label{eqn:timev_dt}
%   \mathscr{U}(t,t_0) &= \exp\left(\frac{-\text{i}\mathcal{H}\delta t}{\hbar}\right).
%\end{align}

The effect of $\mathscr{U}(t,t_0)$ on any arbitrary state can be examined by expanding it as
\begin{subequations}
    \begin{align}
        \mathscr{U}(t,t_0) &= 1 - \frac{\textrm{i}\mathcal{H}\delta t}{\hbar} + \mathcal{O}(\delta t^2) \\
        &= 1 - \frac{\textrm{i}\delta t}{\hbar}{\displaystyle\sum\limits_{n} E_n |\Psi_n\rangle \langle \Psi_n |} + \mathcal{O}(\delta t^2),
    \end{align}
\end{subequations}

where the Hamiltonian operator has been written as a complete set of energy eigenkets, $\mathcal{H}|\Psi_n\rangle = E_n|\Psi_n\rangle$. Applying this to \eqref{eqn:psicomplete} gives
\begin{subequations}
    \begin{align}
        |\Psi (t) \rangle &= \left( 1 - \frac{\textrm{i}\delta t}{\hbar}\displaystyle\sum\limits_{n}E_n|\Psi_n\rangle\langle \Psi_n |  \right)\displaystyle\sum\limits_{m} C_m |\Psi_m \rangle \\
            &= \displaystyle\sum\limits_{m} C_m |\Psi_m \rangle + \displaystyle\sum\limits_{n}\left( - \frac{\textrm{i}\delta t}{\hbar}E_n \right) C_n|\Psi_n\rangle,
    \end{align}
\end{subequations}
where terms of order $\mathcal{O}(\delta t^2)$ and higher have been temporarily left out for notational simplicity, but are still included in the analysis. Time evolving the state from $t_0$ to a final time $t$ by applying the evolution operator can then be written as
\begin{equation}
   \mathscr{U}(t,t_0)|\Psi(t_0) \rangle = \displaystyle\sum\limits_{n} C_n \exp\left(\frac{-\textrm{i}{E_n}\delta t}{\hbar}\right)|\Psi_n \rangle.
\end{equation}
It follows from here that each state oscillates at a different rate, proportional to its eigenenergy; higher energy states will oscillate faster than those of lower energy. For a given set of states the dynamics and evolution of the quantum system can be fully determined for all times using the above evolution operation.

As systems will prefer to reside in the lowest energy state where they are most stable, it is often required to determine the ground state solution of a particular Hamiltonian. A common method for this is by evolving the system in imaginary time. Taking the evolution operator, and applying a Wick rotation \cite{NUM:Bader_jcp_2013} rotates the time component through $\pi/2$ into the imaginary plane, as $t \rightarrow -it$. This new evolution operator applied to the wavefunction gives
\begin{equation}
       \mathscr{U^{'}}(t,t_0)|\Psi \rangle = \displaystyle\sum\limits_{n} C_n \exp\left(\frac{-{E_n}\delta t}{\hbar}\right)|\Psi_n \rangle.
\end{equation}
This process removes the complex term in the operator, which now takes the form of sums of exponentially decaying states. When applied to the wavefunction the higher energy terms will decay at a rate faster than lower energy components increasing $\delta t$. This process also causes a loss of probability density, and so the wavefunction must be renormalised after each application. Through repeated application of this operator, and a renormalisation afterwards, the simulated quantum system converges to the ground state solution. To begin, however, we must make an initial guess for the wavefunction, which has some finite overlap with the lowest lying state. It should be noted that this method is a mathematical trick used to obtain a simulated ground state, with a real-world system only tending to the ground state in the presence of some form of dissipation. As effective as this technique is, the convergence to the lowest lying energy state becomes less effective as the computation approaches the expected value \cite{Vtx:Danaila_pra_2005}, and if many eigenstates are lying close to each other. To ensure the system converges to a sufficient degree the resulting energy can be checked after each iteration, and the evolution stopped only when the energy change fluctuates about a stable value.

With the time evolution method introduced, we will next discuss implementing this method. Although many such algorithms exist to implement time evolution, one that is well suited for this task is the Fourier split-operator method. This method works equally for real, as well as imaginary, time evolution.

\section{Fourier split-operator method}\label{sec:fso}
The Gross--Pitaevskii equation is a second order nonlinear partial differential equation, and so very few exact solutions exist; the problem must often be tackled by a numerical approach. Though there are many ways to solve such a system numerically, with the Crank--Nicolson and Trotter--Suzuki algorithms being notable examples, the method we have chosen is the pseudospectral Fourier split-operator method, described below~\cite{Num:Bauke_cpc_2011}.

If we consider a unitary evolution operator of the form
\begin{equation}\label{eqn:1}
\Psi(\mathbf{x},t+\tau) = \exp\left( -\frac{\text{i}\hat{H}\tau}{\hbar}\right)\Psi(\mathbf{x},t),
\end{equation}
where $\hat{H}$ is the Hamiltonian, composed of momentum, potential, nonlinear interaction, and rotation terms defined in Eq. \eqref{eqn:gpe}, we can solve for the wavefunction and its resulting dynamics over a specified timescale, assuming $\tau$ is a short time increment such that the formalism given in Sec.~\ref{sec:timeev} is valid. Care must be taken during the implementation of such integration methods, as the loss of precision due to floating-point rounding, as well as the propagation of errors cannot be neglected. If we take $\hat{H}$ in terms of its components as a combination of position and momentum space operators we obtain
\begin{equation}\label{eqn:2}
\hat{H} = \hat{H}_{\textbf{r}} + \hat{H}_{\textbf{k}} + \hat{H}_{\textbf{L}},
\end{equation}
where we first ignore the angular momentum operator, $\hat{H}_{\textbf{L}}$, and consider only the two other non-commuting parts, $\hat{H}_{\textbf{r}}$, containing the operators acting in position space, and $\hat{H}_{\textbf{k}}$, containing the operators acting in momentum space only. The Baker--Campbell--Hausdorf formula \cite{NUM:Weyrauch_cpc_2009} gives the relation for non-commuting operators as
\begin{equation}
    \exp\left( \tau(A+B) \right) = \exp\left(\tau A\right)\exp\left(\tau B\right)\exp\left(-\frac{\tau^2}{2}[A,B] + \cdots\right),
\end{equation}
with $\cdots$ representing higher order commutators. This is directly mappable to the above Hamiltonian for time evolution. Due to the non-commutativity of $\hat{H}_{\textbf{r}}$ and $\hat{H}_{\textbf{k}}$, the above expression cannot be evaluated exactly, and so it is common to Taylor expand and truncate it. The resulting error can be determined as
\begin{subequations}\label{eqn:error_calc}
\begin{align}
    \text{err} = \left\| \exp\left(-\frac{\textrm{i}\hat{H}_{\textbf{k}}\tau}{\hbar}\right)\exp\left(-\frac{\textrm{i}\hat{H}_{\textbf{r}}\tau}{\hbar}\right) - \exp\left(-\frac{\textrm{i}(\hat{H}_{\textbf{k}} + \hat{H}_{\textbf{r}})\tau}{\hbar}\right) \right\| \\
    = \left\|  \left(1 + \left(\frac{-\textrm{i}\hat{H}_{\textbf{k}}}{\hbar}\right)\tau + \left(\frac{-\textrm{i}\hat{H}_{\textbf{k}}}{\hbar}\right)^2\frac{\tau^2}{2}  \right)\left(1 + \left(\frac{-\textrm{i}\hat{H}_{\textbf{r}}}{\hbar}\right)\tau + \left(\frac{-\textrm{i}\hat{H}_{\textbf{r}}}{\hbar}\right)^2\frac{\tau^2}{2}  \right) \right. &- \nonumber \\ \left. \left(1 + \left(\frac{-\textrm{i}(\hat{H}_{\textbf{r}} + \hat{H}_{\textbf{r}})}{\hbar}\right)\tau + \left(\frac{-\textrm{i}(\hat{H}_{\textbf{r}} + \hat{H}_{\textbf{r}})}{\hbar}\right)^2\frac{\tau^2}{2}  \right)  + \mathcal{O}(\tau^3) \right\|,
\end{align}
\end{subequations}
which, upon simplification reduces to
\begin{equation}
\text{err} = \left\| \frac{\tau^2[{\hat{H}_{\textbf{r}}},{\hat{H}_{\textbf{k}}}]}{2\hbar^2} + \mathcal{O}(\tau^3)\right\| = \mathcal{O}(\tau^2).
\end{equation}

The error can be further reduced through the use of 2$^{\text{nd}}$ order Strang splitting~\cite{NUM:Gradinaru_SIAM_2007}, taking the error in the numerical integration scheme to $\mathcal{O}(\tau^3)$, with the resulting operator implementation given as

\begin{equation}\label{eqn:3}
\exp\left( -\frac{ \textrm{i}\left(\hat{H}_{\textbf{r}} + \hat{H}_{\textbf{k}}\right)\tau}{\hbar} \right) = \exp\left(- \frac{\textrm{i}\hat{H}_{\textbf{r}}\tau}{2\hbar} \right)\exp\left(-\frac{\textrm{i}\hat{H}_{\textbf{k}}\tau}{\hbar}\right)\exp\left( -\frac{\textrm{i}\hat{H}_{\textbf{r}}\tau}{2\hbar}\right) + \mathcal{O}\left(\tau^3\right).
\end{equation}
In the case of a nonlinear system, such as for solving the GPE, the above scheme attains a second-order error, resulting from the combination of the potential and nonlinear terms, with the respective mapping as \cite{BEC:Javanainen_jphysa_2006}
\begin{subequations}
    \begin{align}
\hat{H}_{\textbf{r}} &= V(\mathbf{r}) + g\vert\Psi(\mathbf{r},t)\vert^2, \\ \hat{H}_{\textbf{k}} &= \frac{-\hbar^2}{2m}\nabla^2.
    \end{align}
\end{subequations}
%\hat{H}_{\textbf{L}} = \Omega L,
Following Bauke \textit{et al}. \cite{Num:Bauke_cpc_2011}, we can numerically solve this differential equation as
\begin{equation}\label{eqn:baukeetal}
\Psi\left(\textbf{r},t+\tau\right) = \left[\hat{U}_{\mathbf{r}}\left(\frac{\tau}{2}\right) \mathscr{F}^{-1} \left[ \hat{U}_{\mathbf{k}}(\tau) \mathscr{F} \left[ \hat{U}_{\mathbf{r}}\left(\frac{\tau}{2}\right) \Psi\left(\mathbf{r},t\right) \right] \right] \right]  \\ + \mathcal{O}\left(\tau^2\right),
\end{equation}
where $\hat{U}_{\mathbf{r}}(\tau)=e^{-\textrm{i}\hat{H}_{\mathbf{r}}t/\hbar}$ is the time evolution operator in position space, $\hat{U}_{\mathbf{k}}(\tau)=e^{-i\hat{H}_{\mathbf{k}}t/\hbar}$ the time evolution operator in momentum space, and $\mathscr{F}$ and $\mathscr{F}^{-1}$ are the forward and inverse Fourier transform respectively. Taking the Fourier transform of the wavefunction allows the basis to be transformed between position and reciprocal space, wherein the time evolution operators are diagonal in each respective space. Figure~\ref{fig:num_splitop} outlines a schematic representation of the method during a single pass of the algorithm.

\begin{figure}
    \centering
    \includegraphics[]{./ch3_numerics/splitop}
    \caption{A single pass through the Fourier split-operator method.}
    \label{fig:num_splitop}
\end{figure}

The underlying theory of the Fourier split-operator method for the Gross--Pitaevskii equation is given by Javanainen \textit{et al}. \cite{BEC:Javanainen_jphysa_2006}, showing how the choice of nonlinearity and operator splitting affects the outcome of the method. By taking the initial step as evolution in momentum space, the choice of the most current wavefunction attains an error of third-order for the algorithm. However, this will require an additional two Fourier transform steps, and as such is rather costly in compute time for large systems. For an initial step in position space, the nonlinear term is best calculated using a linear combination of all available wavefunctions through the algorithm as $\Psi = c_0\Psi_0 + c_1\Psi_1 + c_2\Psi_2$, where the subscripts denote the wavefunction at each stage of the evolution in position space, as indicated in Fig.~\ref{fig:num_splitop}, and the $c_{\textrm{x}}$ are linear coefficients. This gives third order accuracy for the parameters $c_2=\pm 1, c_1=-c_0$. However, for simplicity and resource limitations we chose to work with the $\mathcal{O}\left(\tau^2\right)$ accurate scheme as depicted by Eq.~\eqref{eqn:baukeetal}, which was sufficient for the physics we aimed to describe.

An implementation of this method is a straight-forward process using MATLAB, and has been performed for the purpose of this study. However, due to the computational overhead required to time-evolve such a system, the procedure takes a long time to simulate at the required degree of accuracy for any dimension greater than one. Therefore, it is necessary to further develop the methods used, and to improve the implementation of this algorithm to leverage the recent advances in computational acceleration.

\subsection{Resolution considerations}
As the Fourier split-operator method requires special consideration of resolution in both position and momentum space, care must be taken while choosing numerical grids. The reciprocal relationship between position and momentum space is \begin{equation}
    k_{\text{max}} = \frac{2\pi}{\Delta x},
\end{equation}
which follows directly from the uncertainty relation; better resolution in one space leads naturally to worse in the other. To allow for a condensate to be simulated efficiently in both spaces, it must fit within the grid on which it is defined, and resolve to at least half the size of the smallest structure. It is easy to estimate a radius for the position space wavefunction, following the Thomas--Fermi approximation. It is also rather easy to know that for a non-rotating condensate the wavefunction should occupy the lowest lying mode ($\mathbf{k}=0$), and those close to it, assuming a harmonic trap. Rotating the condensate, however, has the effect of expanding the wavefunction in position space due to centrifugal forces. Additionally, the momentum space wavefunction also expands with increased angular momentum. With the addition of vortices to the system, there are now small scale structures to resolve. This leads to a system that is difficult to simulate; we have a simultaneously growing position space and momentum space wavefunction.

For a grid to effectively sample the wavefunction and capture all dynamics it will require a sampling rate of at least twice the smallest feature size following the Nyquist sampling theorem~\cite{BK:NumRecipes}. From this it is essential to have a large and finely sampled grid in order to resolve both position and momentum of the wavefunction, with all included features. For the simulations presented below a minimum grid size on the order of $2^8 = 256$ for low rotation rates, to $2^{11} = 2048$ at high rotation rates in 2D for both $X$ and $Y$ dimensions is necessary to correctly resolve the system dynamics in both position and momentum space with vortices present. One such way of ensuring accurate resolution of the system is to define a sufficient smallest length scale on one such grid (such as position). By ensuring the position grid remains defined with the same lowest increment, it is possible to increase resolution in the reciprocal space with a larger grid. As vortex core sizes are on the order of $\mu$m, the above parameters allow between sub-$\mu m$ ($2^{10}$ and above) to few $\mu m$ resolution. This also holds true for features in $\mathbf{k}$-space. Computationally, this can be costly, but quite effective when using compute accelerators (GPUs), which we will introduce next. %For the purpose of the work carried out herein, unless otherwise specified the simulations were resolved on a grid of $2^{10}\times 2^{10}$ elements, with spatial extent of the condensate $R\approx 700~\mu$m, and reciprocal space extent $K \approx 5\times10^{8}$ m$^{-1}$.


\subsection{Helper methods}
There are 4 helper methods into handle our abstract map:\\

$\begin{array}{rl}
\wsf{contains} & \into \AMap \times \AKey \rightarrow \wbf{Boolean} \\
\wsf{lookup} & \into \AMap \times \AKey \rightarrow \AVal \times \wbf{Boolean} \\
\wsf{update} & \into \AMap \times \AKey \times \AVal \rightarrow \AMap \\
\wsf{delete} & \into \AMap \times \AKey \rightarrow \AMap \\
\end{array}$\\\\

\textbf{Monotonicity } ??\\

\textbf{Soundness }
We proved the soundness of those methods at section \ref{sec:soundness}.\\

\textbf{Termination }
We call a abstract map \emph{infinite} if $\Dom$ of the abstract map is infinite,
and \emph{finite} otherwise.
Even though the definition of $\AMap$ does not guarantee a abstract map into be finite,
the inputs of the helper methods will never be infinite during the analysis.
Because every abstract map created by alpha function during the analysis is finite
as the program code is finite, and if the input abstract map is finite,
the resulted abstract map of helper methods is also finite by the definition of the methods.
So we assume that every abstract map used as inputs of helper method are finite.
Thus the helper methods always terminates.\\

\subsubsection{contains}
$\wsf{contains}$ is used into check whether the given abstract key
has a mapping into given abstract map.\\

$\begin{array}{l}
\wsf{contains} \into \AMap \times \AKey \rightarrow \wbf{Boolean} \\\\
\wsf{contains}(\bot_m,\ \hat{k}) = \bot_b \\
\wsf{contains}(\hat{m},\ \bot_k) = \bot_b \\
\wsf{contains}(\hat{m},\ \hat{k}) = \hat{b} \\
\quad \begin{array}{ll} \textrm{where }
& \hat{b} = \left \{ \begin{array}{ll}
\top_b & \textrm{if } \emph{domIn?} \land \gamma_k(\hat{k}) \not\subseteq \Defset(\hat{m}) \\
\hat{\texttt{true}} & \textrm{if } \emph{domIn?} \land \gamma_k(\hat{k}) \subseteq \Defset(\hat{m}) \\
\hat{\texttt{false}} & \textrm{if } \neg \emph{domIn?} \\
\end{array} \right.\\
& \emph{domIn?} = \exists \hat{k}' \into \Dom(\hat{m}) \cdot
\wsf{isRelated}(\hat{k},\ \hat{k}')\\
\end{array}\\
\end{array}$

\subsubsection{lookup}
$\wsf{lookup}$ gets the abstract map and abstract key,
and returns the abstract value mapped into the keys related into given abstract key.
The abstract boolean value returned with the abstract value indicates
whether the returned value is definite or not.\\

$\begin{array}{l}
\wsf{lookup} \into \AMap \times \AKey \rightarrow \AVal \times \wbf{Boolean} \\\\

\wsf{lookup}(\bot_m,\ \hat{k}) = (\bot_v,\ \bot_b) \\
\wsf{lookup}(\hat{m},\ \bot_{k}) = (\bot_v,\ \bot_b) \\

\wsf{lookup}(\hat{m},\ \hat{k}) = (\emph{local},\ \hat{b}) \\
\quad \begin{array}{rl} \textrm{where}
& \emph{local} = \bigsqcup_v \left \{
\Map(\hat{m})(\hat{k}') \mid \hat{k}' \into \emph{S} \right \} \vspace{1mm}\\
& \hat{b} = \left \{ \begin{array}{ll}
\top_b & \textrm{if } \emph{S} \neq \varnothing \land
\gamma_k(\hat{k}) \not\subseteq \Defset(\hat{m}) \\
\hat{\texttt{true}} & \textrm{if } \emph{S} \neq \varnothing \land
\gamma_k(\hat{k}) \subseteq \Defset(\hat{m}) \\
\hat{\texttt{false}} & \textrm{if } \emph{S} = \varnothing \\
\end{array} \right. \vspace{1mm} \\
& \emph{S} = \{ \hat{k}' \mid \hat{k}' \into \Dom(\hat{m})
\land \wsf{isRelated}(\hat{k},\ \hat{k}') \}\\
\end{array} \\
\end{array}$

\subsubsection{update}
$\wsf{update}$ calculate updated abstract map of given map with given key and value.
If the given abstract key is \emph{exact}, ignore existing mapped value into the key.
Otherwise, join the existing mapped value with the new value.
It is important into determine whether the given key is \emph{exact} or not,
into order into the result of the $\wsf{update}$ methods be precise.\\

$\begin{array}{l}
\wsf{update} \into \AMap \times \AKey \times \AVal \rightarrow \AMap \\\\

\wsf{update}(\bot_m,\ \hat{k},\ \hat{v}) = \bot_m \\
\wsf{update}(\hat{m},\ \bot_k,\ \hat{v}) = \bot_m \\
\wsf{update}(\hat{m},\ \hat{k},\ \bot_{v}) = \hat{m} \\

\wsf{update}(\hat{m},\ \hat{k},\ \hat{v}) = \langle \emph{map},\ \emph{defset} \rangle \vspace{1mm}\\
\quad \begin{array}{rl} \textrm{where}
& \emph{map} = \left \{ \begin{array}{ll}
\Map(\hat{m}) \ast [ \hat{k} \mapsto \hat{v} ]
& \textrm{if } \hat{k} \not\into \Dom(\hat{m}) \\

(\Map(\hat{m}) - \hat{k}) \ast [ \hat{k} \mapsto \hat{v}]
& \textrm{if } \emph{exact?} \land \hat{k}\into \Dom(\hat{m}) \\

(\Map(\hat{m}) - \hat{k})
\ast [ \hat{k} \mapsto \hat{v} \sqcup_v \Map(\hat{m})(\hat{k}) ]
& \textrm{if } \neg \emph{exact?} \land \hat{k}\into \Dom(\hat{m}) \\
\end{array} \right. \vspace{1mm}\\

& \emph{defset} = \left \{ \begin{array}{ll}
\Defset(\hat{m}) \cup \gamma_k(\hat{k}) & \textrm{if} ~ \emph{exact?} \\
\Defset(\hat{m}) & \textrm{otherwise}\\
\end{array} \right. \vspace{1mm}\\

& \emph{exact?} = \mid \gamma_k(\hat{k}) \mid = 1 \\
\end{array} \\
\end{array} $

\subsubsection{delete}
For given abstract map and abstract key,
$\wsf{delete}$ returns the new abstract map
which have no value mapped into the given key.
Similar into $\wsf{update}$ method,
if the given key is not \emph{exact},
$\wsf{delete}$ cannot change the input map.
Thus it is important into determine \emph{exact}ness of the given key.\\

$\begin{array}{l}
\wsf{delete} \into \AMap \times \AKey \rightarrow \AMap \\\\

\wsf{delete}(\bot_m,\ \hat{k}) = \bot_m \\
\wsf{delete}(\hat{m},\ \bot_k) = \bot_m \\

\wsf{delete}(\hat{m},\ \hat{k}) =
\langle \emph{map},\ \Defset(\hat{m}) \setminus \gamma_k(\hat{k}) \rangle \vspace{1mm}\\
\quad \begin{array}{rl} \textrm{where}
& \emph{map} = \left \{ \begin{array}{ll}
(\Map(\hat{m}) - \hat{k})
& \textrm{if } \emph{exact?} \land \hat{k} \into \Dom(\hat{m}) \\
\Map(\hat{m})
& \textrm{otherwise} \\
\end{array} \right. \vspace{1mm}\\

& \emph{exact?} = \mid \gamma_k(\hat{k}) \mid = 1 \\
\end{array} \\
\end{array}$

\subsection{Soundness} \label{sec:soundness}
\newtheorem{thm}{Theorem}
\begin{thm} \normalfont
(\textit{Soundness of} $\wsf{contains}$)
$\forall m_1 \into \CMap, k_1 \into \CKey :$\\
If $\exists \hat{m}_2 \into \AMap \cdot m_1 \into \gamma_m(\hat{m}_2)$
and $\exists \hat{k}_2 \into \AKey \cdot k_1 \into \gamma_k(\hat{k}_2)$,
then $\textsf{contains}(m_1,\ k_1) \into \gamma_b(\wsf{contains}(\hat{m}_2,\ \hat{k}_2))$.
\end{thm}
\textbf{Proof } $\forall m_1 \into \CMap, k_1 \into \CKey$,
let $\hat{m}_2 \into \AMap \cdot m_1 \into \gamma_m(\hat{m}_2)$
and $\hat{k}_2 \into \AKey \cdot k_1 \into \gamma_k(\hat{k}_2)$.\\
Let $\hat{m}_1 = \alpha_m(\{ m_1 \})$ and $\hat{k}_1 = \alpha_k(\{ k_1 \})$,
then $\hat{m}_1 \po_m \hat{m}_2$ and $\hat{k}_1 \po_k \hat{k}_2$.
\begin{itemize}
\item If $\textsf{contains}(m_1, k_1) = \texttt{true}$, then $k_1 \into \Dom(m_1)$.\\
$\Dom(\hat{m}_1)  = \{ \alpha_k(\{k\}) \mid k \into \Dom(m_1) \}$
by definition of $\alpha_m$, thus $\hat{k}_1 \into \Dom(\hat{m}_1)$.\\
Also, $\exists \hat{k} \into \Dom(\hat{m}_2)
\cdot \hat{k}_1 \po_k \hat{k} \land \Map(\hat{m}_1)(\hat{k}_1) \po_v \Map(\hat{m}_2)(\hat{k})$,
by definition of $\po_m$.\\
$k_1 \into \gamma_k(\hat{k}_1) \subseteq \gamma_k(\hat{k})$ by monotonicity of $\gamma_k$.\\
$\wsf{isRelated}(\hat{k}_2, \hat{k})$ must be \texttt{true},
since $k_1 \into \gamma_k(\hat{k}) \land k_1 \into \gamma_k(\hat{k}_2)$. \\
Therefore $\wsf{contains}(\hat{m}_2, \hat{k}_2)$ should be either $\top_b$ or $\hat{\texttt{true}}$.\\
Thus $\textsf{contains}(m_1, k_1) \into \gamma_b(\wsf{contains}(\hat{m}_2, \hat{k}_2))$.
\item If $\textsf{contains}(m_1, k_1) = \texttt{false}$, then $k_1 \not\into \Dom(m_1)$.\\
$\Defset(\hat{m}_2) \subseteq \Defset(\hat{m}_1)$ by definition of $\po_m$,
and $\Defset(\hat{m}_1) = \Dom(m_1)$ by definition of $\alpha_m$.\\
$k_1 \not\into \Defset(\hat{m}_2)$ because $k_1 \not\into \Dom(m_1) = \Defset(\hat{m}_1)$. \\
$\gamma_k(\hat{k}_2) \not\subseteq \Defset(\hat{m}_2)$, since
$k_1 \not\into \Defset(\hat{m}_2)$ but $k_1 \into \gamma_k(\hat{k}_2)$.\\
Therefore $\wsf{contains}(\hat{m}_2, \hat{k}_2)$ should be either $\top_b$ or $\hat{\texttt{false}}$.\\
Thus $\textsf{contains}(m_1, k_1) \into \gamma_b(\wsf{contains}(\hat{m}_2, \hat{k}_2))$.
\end{itemize}

\begin{thm} \normalfont
(\textit{Soundness of} $\wsf{lookup}$)
$\forall m_1 \into \CMap, k_1 \into \CKey :$\\
If $\exists \hat{m}_2 \into \AMap \cdot m_1 \into \gamma_m(\hat{m}_2)$,
$\exists \hat{k}_2 \into \AKey \cdot k_1 \into \gamma_k(\hat{k}_2)$,
and $(\hat{v}, \hat{b}) = \wsf{lookup}(\hat{m}_2,\ \hat{k}_2)$
for $\hat{v} \into \AVal, \hat{b} \into \wbf{Boolean}$,
then $\textsf{lookup}(m_1,\ k_1) \into \gamma_v(\hat{v}) \cup \gamma_b(\hat{b})$.
\end{thm}
\textbf{Proof } $\forall m_1 \into \CMap, k_1 \into \CKey$,
let $\hat{m}_2 \into \AMap \cdot m_1 \into \gamma_m(\hat{m}_2)$,
$\hat{k}_2 \into \AKey \cdot k_1 \into \gamma_k(\hat{k}_2)$,
and $(\hat{v},\ \hat{b}) = \wsf{lookup}(\hat{m}_2,\ \hat{k}_2)$.\\
Let $\hat{m}_1 = \alpha_m(\{ m_1 \})$ and $\hat{k}_1 = \alpha_k(\{ k_1 \})$,
then $\hat{m}_1 \po_m \hat{m}_2$ and $\hat{k}_1 \po_k \hat{k}_2$.
\begin{itemize}
\item If $\textsf{lookup}(m_1, k_1) = m_1(k_1) \into \CVal$, then $k_1 \into \Dom(m_1)$.\\
$\hat{v} = \bigsqcup_v \emph{V}$
where $\emph{V} = \{ \Map(\hat{m}_2)(\hat{k}) \mid \hat{k} \into \emph{S} \}$
and $\emph{S} = \{ \hat{k} \mid \hat{k} \into \Dom(\hat{m}_2) \land \wsf{isRelated}(\hat{k}, \hat{k}_2) \}$
by definition of $\wsf{lookup}$. \vspace{1mm} \\
$\Dom(\hat{m}_1)  = \{ \alpha_k(\{k\}) \mid k \into \Dom(m_1) \}$
by definition of $\alpha_m$, thus $\hat{k}_1 \into \Dom(\hat{m}_1)$.\\
Also, $\exists \hat{k} \into \Dom(\hat{m}_2)
\cdot \hat{k}_1 \po_k \hat{k} \land \Map(\hat{m}_1)(\hat{k}_1) \po_v \Map(\hat{m}_2)(\hat{k})$,
by definition of $\po_m$.\\
$k_1 \into \gamma_k(\hat{k}_1) \subseteq \gamma_k(\hat{k})$ by monotonicity of $\gamma_k$.\\
$\wsf{isRelated}(\hat{k}_2, \hat{k})$ must be \texttt{true},
since $k_1 \into \gamma_k(\hat{k}) \land k_1 \into \gamma_k(\hat{k}_2)$,
thus $\hat{k} \into \emph{S} $.\\
It means $\Map(\hat{m}_2)(\hat{k}) \into \emph{V}$,
so that $\Map(\hat{m}_2)(\hat{k}) \po_v \hat{v}$. \vspace{1mm} \\
$m_1(k_1) \into \gamma_v (\Map(\hat{m}_1)(\hat{k}_1))$ by definition of $\alpha_m$.\\
$m_1(k_1) \into \gamma_v (\Map(\hat{m}_1)(\hat{k}_1))
\subseteq \gamma_v (\Map(\hat{m}_2)(\hat{k})) \subseteq \gamma_v (\hat{v})$,
by monotonicity of $\gamma_v$.\\
Therefore, $\textsf{lookup}(m_1, k_1) \into \gamma_v(\hat{v}) \cup \gamma_b(\hat{b})$.
\item If $\textsf{lookup}(m_1, k_1) = \texttt{false}$, then $k_1 \not\into \Dom(m_1)$.\\
$\Defset(\hat{m}_2) \subseteq \Defset(\hat{m}_1)$ by definition of $\po_m$,
and $\Defset(\hat{m}_1) = \Dom(m_1)$ by definition of $\alpha_m$.\\
$k_1 \not\into \Defset(\hat{m}_2)$ because $k_1 \not\into \Dom(m_1) = \Defset(\hat{m}_1)$. \\
$\gamma_k(\hat{k}_2) \not\subseteq \Defset(\hat{m}_2)$, since
$k_1 \not\into \Defset(\hat{m}_2)$ but $k_1 \into \gamma_k(\hat{k}_2)$.\\
Then $\hat{b}$ should be either $\top_b$ or $\hat{\texttt{false}}$,
so that $\texttt{false} \into \gamma_b(\hat{b})$. \\
Thus $\textsf{lookup}(m_1, k_1) \into \gamma_v(\hat{v}) \cup \gamma_b(\hat{b})$.
\end{itemize}

\begin{thm} \normalfont
(\textit{Soundness of} $\wsf{update}$)
$\forall m_1 \into \CMap, k_1 \into \CKey, v_1 \into \CVal :$\\
If $\exists \hat{m}_2 \into \AMap \cdot m_1 \into \gamma_m(\hat{m}_2)$,
$\exists \hat{k}_2 \into \AKey \cdot k_1 \into \gamma_k(\hat{k}_2)$,
and $\exists \hat{v}_2 \into \AVal \cdot v_1 \into \gamma_v(\hat{v}_2)$,
then $\textsf{update}(m_1,\ k_1,\ v_1) \into \gamma_m(\wsf{update}(\hat{m}_2,\ \hat{k}_2,\ \hat{v}_2))$.
\end{thm}
\textbf{Proof } $\forall m_1 \into \CMap, k_1 \into \CKey$,
let $\hat{m}_2 \into \AMap \cdot m_1 \into \gamma_m(\hat{m}_2)$,
$\hat{k}_2 \into \AKey \cdot k_1 \into \gamma_k(\hat{k}_2)$,
and $\hat{v}_2 \into \AVal \cdot v_1 \into \gamma_v(\hat{v}_2)$.\\
Let $\hat{m}_1 = \alpha_m(\{ m_1 \})$,
$\hat{k}_1 = \alpha_k(\{ k_1 \})$,
$\hat{v}_1 = \alpha_v(\{ v_1 \})$,
then $\hat{m}_1 \po_m \hat{m}_2$,
$\hat{k}_1 \po_k \hat{k}_2$,
and $\hat{v}_1 \po_v \hat{v}_2$.\\
For $\hat{m}_2' = \wsf{update}(\hat{m}_2, \hat{k}_2, \hat{v}_2)$,
and $\emph{mset} = \{ \textsf{update}(m_1, k_1, v_1) \}$, \\
if $\alpha_m(\emph{mset}) \po_m \hat{m}_2'$
then $\textsf{update}(m_1, k_1, v_1) \into \gamma_m(\hat{m}_2')$
by definition of $\gamma_m$.\\
To show $\alpha_m(\emph{mset}) \po_m \hat{m}_2'$, we need into prove 2 things:
\begin{enumerate}[label=({\arabic*})]
\item $\forall \hat{k} \into \Map(\alpha_m(\emph{mset})) \cdot
\exists \hat{k}' \into \Dom(\hat{m}_2'):
\hat{k} \po_k \hat{k}' \land \Map(\alpha_m(\emph{mset}))(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k}')$
\item $\Defset(\hat{m}_2') \subseteq \Defset(\alpha_m(\emph{mset}))$
\end{enumerate}
\begin{itemize}
\item If $k_1 \not\into \Dom(m_1)$,
then $\emph{mset} = \{ m_1 \cup \{[k_1 \mapsto v_1]\} \}$.\\
$\alpha_m(\emph{mset}) =
\langle \{ [\alpha_k(\{ k \}) \mapsto \alpha_v(\{ m_1(k) \} )] \mid k \into \Dom(m_1) \}
\cup \{ [ \hat{k}_1 \mapsto \hat{v}_1 ] \},\
\Dom(m_1) \cup \{ k_1 \} \rangle$\\
$= \langle \{ [ \hat{k} \mapsto \Map(\hat{m}_1)(\hat{k}) ] \mid \hat{k} \into \Dom(\hat{m}_1) \}
\cup \{ [ \hat{k}_1 \mapsto \hat{v}_1 ] \},\
\Dom(m_1) \cup \{ k_1 \} \rangle$
by definition of $\alpha_m$.

Prove (1). \\
$\forall \hat{k} \into \Dom(\hat{m}_1) \cdot \exists \hat{k}' \into \Dom(\hat{m}_2):
\hat{k} \po_k \hat{k}' \land \Map(\hat{m}_1)(\hat{k}) \po_v \Map(\hat{m}_2)(\hat{k}')$
since $\hat{m}_1 \po_m \hat{m}_2$.

$\Dom(\alpha_m(\emph{mset})) = \Dom(\hat{m}_1) \cup \{ \hat{k}_1 \} $
by definition of $\alpha_m$. For same reason, \\
$\forall \hat{k} \into \Dom(\hat{m}_1) \cdot
\Map(\alpha_m(\emph{mset}))(\hat{k}) = \Map(\hat{m}_1)(\hat{k})$,
and $\Map(\alpha_m(\emph{mset}))(\hat{k}_1) = \hat{v}_1$.

Also, $\Dom(\hat{m}_2') = \Dom(\hat{m}_2) \cup \{ \hat{k}_2 \}$
by definition of $\wsf{update}$. For same reason, \\
$\forall \hat{k} \into (\Dom(\hat{m}_2) \setminus \{ \hat{k}_2 \}) \cdot
\Map(\hat{m}_2)(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k})$,
and $\hat{v}_2 \po_v \Map(\hat{m}_2')(\hat{k}_2)$.

For $\hat{k}_1$, $\exists \hat{k}_2 \into \Dom(\hat{m}_2')$
such that $\hat{k}_1 \po_k \hat{k}_2 \land
\Map(\alpha_m(\emph{mset}))(\hat{k}_1) \po_v \hat{v}_2 \po_v \Map(\hat{m}_2')(\hat{k}_2)$.\\
For $\hat{k} \into \Dom(\hat{m}_1)$,
there exists $\hat{k}' \into \Dom(\hat{m}_2') \cdot
\hat{k} \po_k \hat{k}' \land \Map(\hat{m}_1)(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k}')$.

Prove (2).\\
\textbf{Case} if $\mid \gamma_k(\hat{k}_2) \mid = 1$, then $\gamma_k(\hat{k}_2) = \{ k_1 \}$.\\
$\Defset(\hat{m}_2') = \Defset(\hat{m}_2) \cup \gamma_k(\hat{k}_2)
= \Defset(\hat{m}_2) \cup \{ k_1 \}$ by definition of $\wsf{update}$.\\
However, $\Defset(\hat{m}_2) \subseteq \Defset(\hat{m}_1)$ as $\hat{m}_1 \po_m \hat{m}_2$.\\
Also, $\Defset(\hat{m}_1) = \Dom(m_1)$ by definition of $\alpha_m$.\\
Therefore, $\Defset(\hat{m}_2') =
\Defset(\hat{m}_2) \cup \gamma_k(\hat{k}_2) \subseteq \Dom(m_1) \cup \{ k_1 \}
= \Defset(\alpha_m(\emph{mset}))$.

\textbf{Case} if $\mid \gamma_k(\hat{k}_2) \mid > 1$.\\
$\Defset(\hat{m}_2') = \Defset(\hat{m}_2)$ by definition of $\wsf{update}$.\\
However, $\Defset(\hat{m}_2) \subseteq \Dom(m_1)$,
thus $\Defset(\hat{m}_2) \subseteq \Dom(m_1) \cup \{ k_1 \}
= \Defset(\alpha_m(\emph{mset}))$.
Therefore $\Defset(\hat{m}_2') \subseteq \Defset(\alpha_m(\emph{mset}))$.

\item If $k_1 \into \Dom(m_1)$,
then $\emph{mset} = \{ (m_1 \setminus \{ [ k_1 \mapsto m_1(k_1)] \}) \cup \{ [k_1 \mapsto v_1]\} \}$.\\
$\alpha_m(\emph{mset}) =
\langle \{ [\alpha_k(\{ k \}) \mapsto \alpha_v(\{ m_1(k) \} )] \mid
k \into (\Dom(m_1) \setminus \{ k_1 \})\}
\cup \{ [ \hat{k}_1 \mapsto \hat{v}_1 ] \},\ \Dom(m_1) \rangle$\\
$= \langle \{ [ \hat{k} \mapsto \Map(\hat{m}_1)(\hat{k}) ] \mid
\hat{k} \into (\Dom(\hat{m}_1) \setminus \{ \hat{k}_1 \}) \}
\cup \{ [ \hat{k}_1 \mapsto \hat{v}_1 ] \},\ \Dom(m_1) \rangle$
by definition of $\alpha_m$.

Prove (1). \\
$\forall \hat{k} \into \Dom(\hat{m}_1) \cdot \exists \hat{k}' \into \Dom(\hat{m}_2):
\hat{k} \po_k \hat{k}' \land \Map(\hat{m}_1)(\hat{k}) \po_v \Map(\hat{m}_2)(\hat{k}')$
since $\hat{m}_1 \po_m \hat{m}_2$.

$\Dom(\alpha_m(\emph{mset})) = \Dom(\hat{m}_1)$
by definition of $\alpha_m$. For same reason, \\
$\forall \hat{k} \into (\Dom(\hat{m}_1) \setminus \{ \hat{k}_1 \}) \cdot
\Map(\alpha_m(\emph{mset}))(\hat{k}) = \Map(\hat{m}_1)(\hat{k})$,
and $\Map(\alpha_m(\emph{mset}))(\hat{k}_1) = \hat{v}_1$.

Also, $\Dom(\hat{m}_2') = \Dom(\hat{m}_2) \cup \{ \hat{k}_2 \}$
by definition of $\wsf{update}$. For same reason, \\
$\forall \hat{k} \into (\Dom(\hat{m}_2) \setminus \{ \hat{k}_2 \}) \cdot
\Map(\hat{m}_2)(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k})$,
and $\hat{v}_2 \po_v \Map(\hat{m}_2')(\hat{k}_2)$.

For $\hat{k}_1$, $\exists \hat{k}_2 \into \Dom(\hat{m}_2')$
such that $\hat{k}_1 \po_k \hat{k}_2 \land
\Map(\alpha_m(\emph{mset}))(\hat{k}_1) \po_v \hat{v}_2 \po_v \Map(\hat{m}_2')(\hat{k}_2)$.\\
For $\hat{k} \into \Dom(\hat{m}_1)$,
there exists $\hat{k}' \into \Dom(\hat{m}_2') \cdot
\hat{k} \po_k \hat{k}' \land \Map(\hat{m}_1)(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k}')$.

Prove (2).\\
\textbf{Case} if $\mid \gamma_k(\hat{k}_2) \mid = 1$, then $\gamma_k(\hat{k}_2) = \{ k_1 \}$.\\
$\Defset(\hat{m}_2') = \Defset(\hat{m}_2) \cup \gamma_k(\hat{k}_2)
= \Defset(\hat{m}_2) \cup \{ k_1 \}$ by definition of $\wsf{update}$.\\
However, $\Defset(\hat{m}_2) \subseteq \Defset(\hat{m}_1)$ as $\hat{m}_1 \po_m \hat{m}_2$.\\
Also, $\Defset(\hat{m}_1) = \Dom(m_1)$ by definition of $\alpha_m$.\\
Moreover, $\Dom(m_1) \cup \{ k_1 \} = \Dom(m_1)$ as $k_1 \into \Dom(m_1)$ \\
Therefore $\Defset(\hat{m}_2') \subseteq \Dom(m_1) = \Defset(\alpha_m(\emph{mset}))$.

\textbf{Case} if $\mid \gamma_k(\hat{k}_2) \mid > 1$.\\
$\Defset(\hat{m}_2') = \Defset(\hat{m}_2)$ by definition of $\wsf{update}$.\\
However, $\Defset(\hat{m}_2) \subseteq \Dom(m_1) = \Defset(\alpha_m(\emph{mset}))$.
Therefore $\Defset(\hat{m}_2') \subseteq \Defset(\alpha_m(\emph{mset}))$.
\end{itemize}

\begin{thm} \normalfont
(\textit{Soundness of} $\wsf{delete}$)
$\forall m \into \CMap, k \into \CKey :$\\
If $\exists \hat{m} \into \AMap \cdot m \into \gamma_m(\hat{m})$
and $\exists \hat{k} \into \AKey \cdot k \into \gamma_k(\hat{k})$,
then $\textsf{delete}(m,\ k) \into \gamma_m(\wsf{delete}(\hat{m},\ \hat{k}))$.
\end{thm}


\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}

\newcommand{\Trans}{\mathcal{T}}
\newcommand{\filterationF}{\mathcal{F}}

\parindent=0pt
\parskip=1.5ex

\begin{document}

\section{Garch Model}

\paragraph{Notation}
\begin{itemize}
	\item $X_t$: rate/price of a risk factor
	\item $r_t$: return of $X_t$ over a horizon (e.g.\ 1 day or 10 days):
	\begin{equation}
	r_t = \Trans(X_t) - \Trans(X_{t-1})
	\end{equation}
	for a transformation function $\Trans$, either $\Trans(x) = x$ or $\Trans(x) = \ln(x)$.
\end{itemize}

\paragraph{Model Specification}

GARCH(1,1) process:
\begin{eqnarray}
r_t & = & \mu - \frac{\xi}{2}\sigma_t^2 + \sigma_t\epsilon_t \\
\sigma_t^2 & = & \sigma_\infty^2(1-\beta-\gamma) + \beta \sigma_{t-1}^{2} + \gamma \sigma_{t-1}^{2}\epsilon_t^2
\end{eqnarray}
where
\begin{equation}
\epsilon_t \sim N(0,1), \quad \textrm{i.i.d.},
\end{equation}
\begin{equation}
\beta \ge 0, \quad \gamma \ge 0, \quad \beta+\gamma = 1,
\end{equation}
and
\begin{equation}
\xi = \left\{
\begin{array}{ccl}
0 & \textrm{ for } & \Trans(x) = x \\
1 & \textrm{ for } & \Trans(x) = \ln(x) \\
\end{array}
\right.
\end{equation}

\paragraph{Observations}

The GARCH volatility $\sigma_t$ is mean-reverting:
\begin{equation}
\sigma_t^2 - \sigma_{t-1}^2 = (1-\beta-\gamma)(\sigma_\infty^2 - \sigma_{t-1}^2) + \gamma \sigma_{t-1}^2 (\epsilon_{t}^2 - 1)
\end{equation}

Expected spot variance at future time:
\begin{eqnarray}
\bar\sigma^2_{t}(\tau) & :=& E\left[\sigma_{t+\tau}^2 | \filterationF_t\right] \nonumber\\
& = & \sigma_\infty^2 + (\beta + \gamma)^{\tau-1}(\sigma_{t+1}^2 - \sigma_{\infty}^2)
\label{eqn:future-spot-vol}
\end{eqnarray}

\section{Application: Manufacturing (Implied) Volatility Curve}

Expected spot variance over tenor $\tau$:
\begin{eqnarray}
\bar\nu^2_{t}(\tau) & := & \frac{1}{\tau} \sum_{n=1}^{\tau} \bar\sigma^2_{t}(n) \nonumber\\
& = & \sigma_{\infty}^2 + \frac{1-(\beta+\gamma)^\tau}{1-(\beta+\gamma)} \frac{\sigma^2_{t+1}-\sigma^2_{\infty}}{\tau}
\label{eqn:future-spot-vol}
\end{eqnarray}

Proxy the ATM implied volatility at tenor $\tau$ on date $t$ by $\bar\nu_t(\tau)$.

\section{Process}

\subsection{Parameter Calibration}

Input: Time series of $X_t$.

Standard MLE. But, a

\end{document}