\documentclass{article}

\usepackage{xcolor}
\usepackage{mathpartir}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{stmaryrd}
\usepackage{fullpage}
\usepackage{subcaption}
\usepackage{tikz}

\input{macros}
\newcommand{\mypar}[1]{\vspace{0.2cm}\paragraph{#1:} \hfill\vspace{0.1cm}}

\newtheorem{theorem}{Theorem}

\begin{document}
\section{Syntax}
\mypar{Syntax of source language, $F_{MP}^{+}$}
\noindent\begin{tabular}{l r r l}
    Types        & $A, B$   & $::=$ & $\tau~\mid~A \to B~\mid~A \& B~\mid~\textcolor{magenta}{\Tabs{\alpha}{A}{B}}~\mid~\trecord{l}{A}$\vspace{0.3cm}\\
    Monotypes    & $\tau$   & $::=$ & $\nat~\mid~\top~\mid~\textcolor{magenta}{\alpha}~\mid~\tau_1\to\tau_2~\mid~\tau_1\&\tau_2~\mid~\trecord{l}{\tau}$ \vspace{0.3cm}\\
    Expressions  & $E$      & $::=$ & $i~\mid~()~\mid~x~\mid~\abs{x}{E}~\mid~E_1\,E_2~\mid~E_1,,E_2~\mid~E : A~\mid~\record{l}{E}~\mid~E.l$\vspace{0.1cm}\\
                 &          &       & $\textcolor{magenta}{\tabs{\alpha}{A}{E}}~\mid~\textcolor{magenta}{E\,A}$\vspace{0.3cm}\\
    Type context & $\Delta$ & $::=$ & $\bullet~\mid~\Delta,\tentry{\alpha}{A}$
  \end{tabular}
%% \klara{Is there a reason to exclude intersection types from monotypes?}

\mypar{Syntax of target language}
\noindent\begin{tabular}{l r r l}
    Types        & $\rho$   & $::=~$ & $\nat~\mid~\top~\mid~\alpha~\mid~\rho_1 \to \rho_2~\mid~\rho_1 \times \rho_2~\mid~\alpha~\mid~\forall{\alpha}.{\rho}~\mid~\trecord{l}{\rho}$ \vspace{0.3cm}\\
    Expressions  & $e$      & $::=~$ & $i~\mid~()~\mid~x~\mid~\abs{x}{e}~\mid~e_1\,e_2~\mid~e_1 , , e_2~\mid~c\,e~\mid~\Lambda{\alpha}.{e}~\mid~e\,\rho~\mid~\record{l}{e}~\mid~e.l$ \vspace{0.3cm}\\
    Coercions    & $c$      & $::=~$ & $\idC{\rho}~\mid~\topC{\rho}~\mid~\topArrC~\mid~\topAllC~\mid~\distArrC{\rho_1}{\rho_2}{\rho_3}~\mid~\distRecC{l}{\rho_1}{\rho_2}~\mid~\projlC{\rho_1}{\rho_2}~\mid~\projrC{\rho_1}{\rho_2}~\mid$\vspace{0.1cm}\\
                 &          & & $\mpC{c_1}{c_2}~\mid~\compC{c_1}{c_2}~\mid~\pairC{c_1}{c_2}~\mid~\arrC{c_1}{c_2}~\mid~\textcolor{magenta}{\alllC{c}{\rho}}~\mid~\textcolor{magenta}{\allrC{\alpha}{c}}~\mid~\trecord{l}{c}$\vspace{0.3cm}\\
    Type context & $\Phi$   & $::=~$ & $\bullet~\mid~\Phi,\alpha$\vspace{0.1cm}\\
    Term context & $\Psi$   & $::=~$ & $\bullet~\mid~\Psi,\eentry{x}{\rho}$
  \end{tabular}

\vspace{1cm}
\paragraph{Helper definitions:}
Desugaring of new coercion operators into target functions.
\begin{align*}
  \trecord{l}{c}    &= \abs{x}{\record{l}{c\,x}}\\
  \alllC{c}{\rho}   &= \abs{x}{(c\,(x\,\rho))}\\
  \allrC{\alpha}{c} &= \abs{x}{\tabst{\alpha}{c\, x}}
\end{align*}

\section{Declarative Specification}
\subsection{Declarative bidirectional typing}
%% \subsubsection{Declarative bidirectional typing}
\fbox{
\begin{mathpar}
  \inferrule*[right=TS-top]{\wfContext{\Gamma}}{\synthmode{\Gamma}{()}{\top}{()}} \and
  \inferrule*[right=TS-nat]{\wfContext{\Gamma}}{\synthmode{\Gamma}{i}{\nat}{i}} \and
  \inferrule*[right=TS-var]{\wfContext{\Gamma}\\(\eentry{x}{A})\in\Gamma}{\synthmode{\Gamma}{x}{A}{x}} \and
  \inferrule*[right=TS-Rcd]{\synthmode{\Gamma}{E}{A}{e}}{\synthmode{\Gamma}{\record{l}{E}}{\trecord{l}{A}}{\record{l}{e}}}\and
  \inferrule*[right=TS-Proj]{\synthmode{\Gamma}{E}{\trecord{l}{A}}{e}}{\synthmode{\Gamma}{E.l}{A}{e.l}}\and
  \inferrule*[right=TS-app]{\synthmode{\Gamma}{E_1}{A\to B}{e_1}\\ \checkmode{\Gamma}{E_2}{A}{e_2}}{\synthmode{\Gamma}{E_1\,E_2}{B}{e_1\,e_2}} \and
  \inferrule*[right=TS-anno]{\checkmode{\Gamma}{E}{A}{e}}{\synthmode{\Gamma}{E:A}{A}{e}} \and
  \inferrule*[right=TS-merge]{\synthmode{\Gamma}{E_1}{A_1}{e_1}\\ \synthmode{\Gamma}{E_2}{A_2}{e_2}\\ \udisjoint{\Gamma}{A\& B}}{\synthmode{\Gamma}{E_1,,E_2}{A_1\& A_2}{\pairC{e_1}{e_2}}}\and
  %% \nrule{TS-abs}{\checkmode{\Gamma,\tentry{\hat\alpha}{\top},\tentry{\hat\beta}{\top},\eentry{x}{\hat\alpha}}{E}{\hat\beta}{e}{\Gamma',\eentry{x}{\hat\alpha},\Theta}\\\fresh{\hat\alpha,\hat\beta}}{\synthmode{\Gamma}{\abs{x}{E}}{\hat\alpha\to \hat\beta}{\abs{x}{e}}{\Gamma'}}\and
  \inferrule*[right=TS-Tabs]{\synthmode{\Gamma,\tentry{\alpha}{A}}{E}{B}{e}}{\synthmode{\Gamma}{\tabs{\alpha}{A}{E}}{\Tabs{\alpha}{A}{B}}{\Lambda\alpha.e}}\and
  \inferrule*[right=TS-Tapp]{\synthmode{\Gamma}{E}{\Tabs{\alpha}{A}{B}}{e}\\ \disjoint{\Gamma}{A}{A'}}{\synthmode{\Gamma}{E\,A'}{[\substitution{\alpha}{A'}]B}{e\,\toTarget{A'}}}
\end{mathpar}
}
\fbox{
\begin{mathpar}
  \inferrule*[right=TC-abs]{\wfT{\Gamma}{A}\\\checkmode{\Gamma,\eentry{x}{A}}{E}{B}{e}}{\checkmode{\Gamma}{\abs{x}{E}}{A\to B}{\abs{x}{e}}} \and
  \inferrule*[right=TC-sub]{\synthmode{\Gamma}{E}{A}{e}\\ \Subtype{\Gamma}{A}{B}{c}}{\checkmode{\Gamma}{E}{B}{c\,e}}\and
\end{mathpar}
}
%% \fbox{
%% \begin{mathpar}
%%   \inferrule*[right=T-..]{\checkmode{\Gamma,\eentry{x}{A_1}}{E}{A_2}{e}{\Gamma',\eentry{x}{A_1},\Theta}}{\checkmode{\Gamma}{\abs{x}{E}}{A_1\to A_2}{\abs{x}{e}}{\Gamma'}} \and
%%   \inferrule*[right=T-sub]{\synthmode{\Gamma}{E}{A}{e}{\Theta}\\ \ldots }{\checkmode{\Gamma}{E}{B}{c\,e}{\Gamma'}}
%% \end{mathpar}
%% }

\subsection{Declarative Disjointness}
%% \mypar{Disjointness - Declarative}
\fbox{
  \begin{mathpar}
    \inferrule*[right=D-TopL]{ }{\disjoint{\Delta}{\top}{A}} \and
%    \inferrule*[right=D-TopR]{ }{\disjoint{\Delta}{A}{\top}} \and
    %% \inferrule*[right=D-Arr]{\disjoint{\Delta}{A_2}{B_2}}{\disjoint{\Delta}{A_1\to A_2}{B_1\to B_2}} \and
    \inferrule*[right=D-ArrL]{\disjoint{\Delta}{A_2}{B}}{\disjoint{\Delta}{A_1\to A_2}{B}} \and
%    \inferrule*[right=D-ArrR]{\disjoint{\Delta}{A}{B_2}}{\disjoint{\Delta}{A}{B_1\to B_2}} \and
    \inferrule*[right=D-AndL]{\disjoint{\Delta}{A_1}{B} \\ \disjoint{\Delta}{A_2}{B}}{\disjoint{\Delta}{A_1\& A_2}{B}} \and
%    \inferrule*[right=D-AndR]{\disjoint{\Delta}{A}{B_1} \\ \disjoint{\Delta}{A}{B_2}}{\disjoint{\Delta}{A}{B_1\& B_2}} \and
    \inferrule*[right=D-VarL]{\tentry{\alpha}{A}\in{\Delta} \\ \subt{A}{B}}{\disjoint{\Delta}{\alpha}{B}} \and
%    \inferrule*[right=D-VarR]{\tentry{\beta}{B}\in{\Delta} \\ \subt{B}{A}}{\disjoint{\Delta}{A}{\beta}} \and
    \mprset{sep=1em}
    \inferrule*[right=D-AllL]{(\forall \tau,\,\disjoint{\Delta}{\tau}{A}\implies\disjoint{\Delta}{[\alpha\mapsto\tau]B_1}{B_2})}{\disjoint{\Delta}{\Tabs{\alpha}{A}{B_1}}{B_2}}\and
%    \inferrule*[right=D-AllR]{(\forall \tau,\,\disjoint{\Delta}{\tau}{A}\implies\disjoint{\Delta}{B_1}{[\alpha\mapsto\tau]B_2})}{\disjoint{\Delta}{B_1}{\Tabs{\alpha}{A}{B_2}}}\and
    \inferrule*[right=D-Rec]{\disjoint{\Delta}{A}{B}}{\disjoint{\Delta}{\trecord{l}{A}}{\trecord{l}{B}}} \and
    \inferrule*[right=D-NRec]{l_1\neq l_2}{\disjoint{\Delta}{\trecord{l_1}{A}}{\trecord{l_2}{B}}} \and
    \inferrule*[right=D-NatRcd]{ }{\disjoint{\Delta}{\nat}{\trecord{l}{A}}}\and
    \inferrule*[right=D-Sym]{\disjoint{\Delta}{A}{B}}{\disjoint{\Delta}{B}{A}}
    %% \inferrule*[right=D-ax]{\starax{A}{B}}{\disjoint{\Delta}{A}{B}}
  \end{mathpar}
}
\subsubsection{Notes}
\mypar{Subsumption of \textsc{D-Forall} from $F_{i}^{+}$}
Rule \textsc{D-Forall} of $F_{i}^{+}$ is subsumed by our rules:
\[
\inferrule*[right=D-forall]
    {\disjoint{\Delta,\tentry{\alpha}{A_1\& B_1}}{A_2}{B_2}}
    {\disjoint{\Delta}{\Tabs{\alpha}{A_1}{A_2}}{\Tabs{\alpha}{B_1}{B_2}}}
\]
For any well-formed substitution $\wfSubst{\Delta,\tentry{\alpha}{A_1\& B_1}}{\theta\circ[{\alpha}\mapsto{\tau_0}]}$,
it follows by case analysis that $\wfT{\Delta}{\tau_0}$, $\disjoint{\Delta}{\tau_0}{A_1}$ and $\disjoint{\Delta}{\tau_0}{B_1}$.
Applying $\theta\circ[{\alpha}\mapsto{\tau_0}]$ in the premise of \textsc{D-forall}, yields $\disjoint{\theta(\Delta)}{[{\alpha}\mapsto{\tau_0}]{A_2}}{[{\alpha}\mapsto{\tau_0}]{B_2}}$. In our system,
this behaviour is recovered by:
\[
\inferrule*[right=D-allL($\tau_0$)]
           { \inferrule*{\text{given}}{\disjoint{\Delta}{\tau_0}{A_1}}
             \\
             \inferrule*[right=D-allR($\tau_0$)]
                        {
                          \inferrule*{\text{given}}{\disjoint{\Delta}{\tau_0}{B_1}}
                          \\
                          \inferrule*
                              {\text{given}}
                              {\disjoint{\Delta}{[\alpha\mapsto\tau_0]A_1}{[\alpha\mapsto\tau_0]{B_2}}}
                        }
                        {\disjoint{\Delta}{[\alpha\mapsto\tau_0]A_1}{\Tabs{\alpha}{B_1}{B_2}}}
           }
    {\disjoint{\Delta}{\Tabs{\alpha}{A_1}{A_2}}{\Tabs{\alpha}{B_1}{B_2}}}
\]

\subsection{Declarative Subtyping}
\fbox{
  \begin{mathpar}
    \inferrule*[right=S-refl]{ }{\Subtype{\Delta}{A}{A}{\idC{\toTarget{A}}}} \and
    \inferrule*[right=S-trans]{\Subtype{\Delta}{A_1}{A_2}{c} \\ \Subtype{\Delta}{A_2}{A_3}{c'}}{\Subtype{\Delta}{A_1}{A_3}{\compC{c'}{c}}} \\
    \inferrule*[right=S-top]{ }{\Subtype{\Delta}{A}{\top}{\topC{\toTarget{A}}}} \and
    \inferrule*[right=S-topArr]{ }{\Subtype{\Delta}{\top}{\top\to\top}{\topArrC}} \and
    \inferrule*[right=S-topAll]{ }{\Subtype{\Delta}{\top}{\Tabs{\alpha}{A}{\top}}{\topAllC}} \and
    \inferrule*[right=S-and]{\Subtype{\Delta}{A}{B_1}{c_1} \\ \Subtype{\Delta}{A}{B_2}{c_2}}{\Subtype{\Delta}{A}{B_1 \& B_2}{\pairC{c_1}{c_2}}} \and
    \inferrule*[right=S-andL]{ }{\Subtype{\Delta}{A_1\& A_2}{A_1}{\projlC{\toTarget{A_1}}{\toTarget{A_2}}}} \and
    \inferrule*[right=S-andR]{ }{\Subtype{\Delta}{A_1\& A_2}{A_2}{\projrC{\toTarget{A_1}}{\toTarget{A_2}}}} \and
    \inferrule*[right=S-arr]{\Subtype{\Delta}{B_1}{A_1}{c_1}\\ \Subtype{\Delta}{A_2}{B_2}{c_2}}{\Subtype{\Delta}{A_1\to A_2}{B_1\to B_2}{\arrC{c_1}{c_2}}} \and
    \inferrule*[right=S-rcd]{\Subtype{\Delta}{A}{B}{c}}{\Subtype{\Delta}{\trecord{l}{A}}{\trecord{l}{B}}{\trecord{l}{c}}} \and
    \inferrule*[right=S-mp]{\Subtype{\Delta}{A}{B_1\to B_2}{c_1} \\ \Subtype{\Delta}{A}{B_1}{c_2}}{\Subtype{\Delta}{A}{B_2}{\mpC{c_1}{c_2}}} \and
    \inferrule*[right=S-distArr]{ }{\Subtype{\Delta}{(A\to B_1)\&(A\to B_2)}{A\to{B_1\& B_2}}{\distArrC{\toTarget{A}}{\toTarget{B_1}}{\toTarget{B_2}}}} \and
    \inferrule*[right=S-distRcd]{ }{\Subtype{\Delta}{\trecord{l}{A}\&\trecord{l}{B}}{\trecord{l}{A\& B}}{\distRecC{l}{\toTarget{A}}{\toTarget{B}}}} \and
    \inferrule*[right=S-allL]{\disjoint{\Delta}{\tau}{A} \\ \Subtype{\Delta}{[\alpha\mapsto\tau]B}{B'}{c}}{\Subtype{\Delta}{\Tabs{\alpha}{A}{B}}{B'}{\alllC{c}{\tau}}} \and
    \inferrule*[right=S-allR]{\Subtype{\Delta,\tentry{\alpha}{B_1}}{A}{B_2}{c}}{\Subtype{\Delta}{A}{\Tabs{\alpha}{B_1}{B_2}}{\allrC{\alpha}{c}}}
  \end{mathpar}\hfill
}\\
\subsubsection{Notes}
\mypar{Predicative instantiation}
We use predicative type instantiation (rule \textsc{S-allL}) to avoid following kind of non-termination, where $\mathcal{A} :=\Tabs{\alpha}{A}{\alpha\to\alpha}$.
In the premise of rule \textsc{S-allL} below, we use substitution $[\alpha\mapsto\mathcal{A}]$.
\begin{mathpar}
  \inferrule*[right=S-MP]
             {
               \inferrule*[right=S-allL]
                          {\disjoint{\Delta}{\mathcal{A}}{A}
                           \\
                           \inferrule*
                                      {\vdots}
                                      {\Subtype{\Delta}{\mathcal{A}\to\mathcal{A}}{\mathcal{A}\to\mathcal{A}}{?}}
                          }
                          {\Subtype{\Delta}{\mathcal{A}}{\mathcal{A}\to\mathcal{A}}{\alllC{?}{\toTarget{\mathcal{A}}}}}
               \\
               \inferrule*[right=S-refl]
                          { }
                          {\Subtype{\Delta}{\mathcal{A}}{\mathcal{A}}{\idC{\toTarget{\mathcal{A}}}}}
             }
             {\Subtype{\Delta}{\mathcal{A}}{\mathcal{A}}{\mpC{(\alllC{?}{\toTarget{\mathcal{A}}})}{\idC{\toTarget{\mathcal{A}}}}}}
\end{mathpar}

\mypar{Subsumption of \textsc{S-DistAll} and \textsc{S-topAll} from $F_{i}^{+}$}
Rule \textsc{S-DistAll} of $F_{i}^{+}$ is subsumed by our rules:
\begin{mathpar}
  \inferrule*
      {
        \inferrule*
            {
              \inferrule*
                  {
                    \inferrule*
                        {\disjoint{\bullet,\tentry{a}{A}}{a}{A}
                          \\
                         \inferrule*{ }{\Subtype{\bullet,\tentry{a}{A}}{[\alpha\mapsto\alpha]B_1}{B_1}{\idC{\toTarget{B_1}}}}
                        }
                        {\Subtype{\bullet,\tentry{a}{A}}{\Tabs{\alpha}{A}{B_1}}{B_1}{\alllC{\idC{\toTarget{B_1}}}{\alpha}}}
                    \\
                    \vdots
                  }
                  {\Subtype{\bullet,\tentry{a}{A}}{(\Tabs{\alpha}{A}{B_1})\&(\Tabs{\alpha}{A}{B_2})}{B_1}{\compC{(\alllC{\idC{\toTarget{B_1}}}{\alpha})}{\projlC{\Tabst{\alpha}{\toTarget{B_1}}}{\Tabst{\alpha}{\toTarget{B_2}}}}}}
                  \\
                  \vdots
              %% \inferrule*
              %%     { }
              %%     {\Subtype{\bullet,\tentry{a}{A}}{(\Tabs{\alpha}{A}{B_1})\&(\Tabs{\alpha}{A}{B_2})}{B_2}{ }}
            }
            {\Subtype{\bullet,\tentry{a}{A}}{(\Tabs{\alpha}{A}{B_1})\&(\Tabs{\alpha}{A}{B_2})}{B_1\&B_2}{\pairC{\compC{(\alllC{\idC{\toTarget{B_1}}}{\alpha})}{\projlC{\Tabst{\alpha}{\toTarget{B_1}}}{\Tabst{\alpha}{\toTarget{B_2}}}}}{\compC{(\alllC{\idC{\toTarget{B_2}}}{\alpha})}{\projrC{\Tabst{\alpha}{\toTarget{B_1}}}{\Tabst{\alpha}{\toTarget{B_2}}}}}}}
      }
      {\Subtype{\bullet}{(\Tabs{\alpha}{A}{B_1})\&(\Tabs{\alpha}{A}{B_2})}{\Tabs{\alpha}{A}{B_1\&B_2}}{\allrC{\alpha}{\pairC{\compC{(\alllC{\idC{\toTarget{B_1}}}{\alpha})}{\projlC{\Tabst{\alpha}{\toTarget{B_1}}}{\Tabst{\alpha}{\toTarget{B_2}}}}}{\compC{(\alllC{\idC{\toTarget{B_2}}}{\alpha})}{\projrC{\Tabst{\alpha}{\toTarget{B_1}}}{\Tabst{\alpha}{\toTarget{B_2}}}}}}}}
\end{mathpar}

\clearpage
\section{Algorithmic Specification}

\begin{table}[h]
  \begin{tabular}{l r r l}
    Types         & $A, B$   & $::=$ & $\tau~\mid~A \to B~\mid~A \& B~\mid~\textcolor{magenta}{\Tabs{\alpha}{A}{B}}~\mid~\trecord{l}{A}$\vspace{0.1cm}\\
    Monotypes     & $\tau$   & $::=$ & $\xi~\mid~\tau_1\to\tau_2~\mid~\tau_1\&\tau_2~\mid~\trecord{l}{\tau}$ \vspace{0.1cm}\\
    Base types    & $\xi$    & $::=$ & $\nat~\mid~\bool~\mid~\top~\mid~\textcolor{magenta}{\alpha}~\mid~\textcolor{magenta}{\hat{\alpha}}$ \vspace{0.3cm}\\
    Expressions   & $E$      & $::=$ & $i~\mid~\True~\mid~\False~\mid~()~\mid~x~\mid~\abs{x}{E}~\mid~E_1\,E_2~\mid~E_1,,E_2~\mid$\vspace{0.1cm}\\
                  &          &       & $E : A~\mid~\textcolor{magenta}{\tabs{\alpha}{A}{E}}~\mid~\textcolor{magenta}{E\,A}~\mid\record{l}{E}~\mid~E.l$\vspace{0.3cm}\\
    Type context  & $\Delta$ & $::=$ & $\bullet~\mid~\Delta,\tentry{\alpha}{A}~\mid~\Delta,\tentry{\hat{\alpha}}{A}$\vspace{0.3cm}\\
    Queue         & $\mathcal{L},\mathcal{M}$ & $::=$ & $\bullet~\mid~\mathcal{L},A~\mid~\mathcal{L},l$\vspace{0.3cm}\\
    Coercion context & $\mathcal{C}$ & $::=$ & $\bullet~\mid~\arrCC{\mathcal{C}}{c}~\mid~\projlCC{\mathcal{C}}{A}{B}~\mid~\projrCC{\mathcal{C}}{A}{B}~\mid~\mpCC{\mathcal{C}}{\mathcal{M}}{c_1}{A}{B}~\mid~\alllCC{\mathcal{C}}{\tau}~\mid~\recCC{\mathcal{C}}{l}$\vspace{0.3cm}\\
    Type variable substitutions & $\theta$ & $::=$ & $\bullet~\mid~\unification{\alpha}{A},\theta~\mid~\substitution{\alpha}{A},\theta$\vspace{0.3cm}
  \end{tabular}
  \caption{The language of the algorithm}
\end{table}

\subsubsection{Coercion context completion}
\begin{minipage}[t]{0.7\textwidth}
\begin{align*}
  \bullet [c] &= c\\
  (\arrCC{\mathcal{C}}{c'})[c] &= \mathcal{C}[c'\to c]\\
  \projlCC{\mathcal{C}}{A}{B}[c] &= \mathcal{C}[\compC{c}{\projlC{\toTarget{A}}{\toTarget{B}}}]\\
  \projrCC{\mathcal{C}}{A}{B}[c] &= \mathcal{C}[\compC{c}{\projrC{\toTarget{A}}{\toTarget{B}}}]\\
  \mpCC{\mathcal{C}}{\mathcal{M}}{c_1}{A}{B}[c] &= \compC{\distarrowqueueC{\mathcal{M}}{\left(\compC{c}{(\mpC{\projlC{\toTarget{A\to B}}{\toTarget{A}}}{\projrC{\toTarget{A\to B}}{\toTarget{A}}})}\right)}{\toTarget{A\to B}}{\toTarget{A}}}{\pairC{\mathcal{C}[\idC{\toTarget{A\to B}}]}{c_1}}\\
  \alllCC{\mathcal{C}}{\tau}[c] &= \mathcal{C}[\alllC{c}{\toTarget{\tau}}]\\
  \recCC{\mathcal{C}}{l}[c] &= \mathcal{C}[\trecord{l}{c}]
\end{align*}
\end{minipage}

\subsection{Substitutions}
\subsubsection{Applying unification variable substitution...}
\begin{minipage}[t]{0.5\textwidth}
  \mypar{{...on types}}
  \begin{align*}
    [\unification{\alpha}{\tau}]\nat                  &= \nat\\
    [\unification{\alpha}{\tau}]\top                  &= \top\\
    [\unification{\alpha}{\tau}]\alpha                &= \alpha\\
    [\unification{\alpha}{\tau}]\hat\alpha            &= \tau\\
    [\unification{\alpha}{\tau}]\hat\beta             &= \hat\beta\\
    [\unification{\alpha}{\tau}](A\to B)              &= ([\unification{\alpha}{\tau}]A)\to([\unification{\alpha}{\tau}]B)\\
    [\unification{\alpha}{\tau}](A\& B)               &= ([\unification{\alpha}{\tau}]A)\&([\unification{\alpha}{\tau}]B)\\
    [\unification{\alpha}{\tau}](\Tabs{\alpha}{A}{B}) &= \Tabs{\alpha}{[\unification{\alpha}{\tau}]A}{[\unification{\alpha}{\tau}]B}\\
    [\unification{\alpha}{\tau}]\trecord{l}{A}        &= \trecord{l}{[\unification{\alpha}{\tau}]A}
  \end{align*}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
  \mypar{{...on terms}}
  \begin{align*}
    [\unification{\alpha}{\tau}]i &= i\\
    [\unification{\alpha}{\tau}]() &= ()\\
    [\unification{\alpha}{\tau}]x &= x\\
    [\unification{\alpha}{\tau}]\abs{x}{E} &= \abs{x}{[\unification{\alpha}{\tau}]E}\\
    [\unification{\alpha}{\tau}](E_1\,E_2) &= ([\unification{\alpha}{\tau}]E_1)\,([\unification{\alpha}{\tau}]E_2)\\
    [\unification{\alpha}{\tau}](E : A) &= [\unification{\alpha}{\tau}]E : [\unification{\alpha}{\tau}]A\\
    [\unification{\alpha}{\tau}]\tabs{\alpha}{A}{E} &= \tabs{\alpha}{[\unification{\alpha}{\tau}]A}{[\unification{\alpha}{\tau}]E}\\
    [\unification{\alpha}{\tau}](E\,A) &= ([\unification{\alpha}{\tau}]E)\, ([\unification{\alpha}{\tau}]A)\\
    [\unification{\alpha}{\tau}]\record{l}{E} &= \record{l}{[\unification{\alpha}{\tau}]E}\\
    [\unification{\alpha}{\tau}](E.l) &= ([\unification{\alpha}{\tau}]E).l
  \end{align*}
\end{minipage}\\

\noindent
\begin{minipage}[t]{0.47\textwidth}
  \mypar{{...on type contexts}}
  \begin{align*}
    [\unification{\alpha}{\tau}]\bullet &= \bullet\\
    [\unification{\alpha}{\tau}](\Delta,\tentry{\alpha}{A}) &= [\unification{\alpha}{\tau}]\Delta,\tentry{\alpha}{[\unification{\alpha}{\tau}]A}\\
    [\unification{\alpha}{\tau}](\Delta,\tentry{\hat\alpha}{A}) &= [\unification{\alpha}{\tau}]\Delta\\
    [\unification{\alpha}{\tau}](\Delta,\tentry{\hat\beta}{A}) &= [\unification{\alpha}{\tau}]\Delta,\tentry{\hat\beta}{[\unification{\alpha}{\tau}]A}
  \end{align*}
\end{minipage}
\begin{minipage}[t]{0.47\textwidth}
    \mypar{{...on queues}}
  \begin{align*}
    [\unification{\alpha}{\tau}]\bullet &= \bullet\\
    [\unification{\alpha}{\tau}](\mathcal{M},A) &= [\unification{\alpha}{\tau}]\mathcal{M},([\unification{\alpha}{\tau}]A)\\
    [\unification{\alpha}{\tau}](\mathcal{M},l) &= [\unification{\alpha}{\tau}]\mathcal{M},l
  \end{align*}
\end{minipage}\\

\noindent
\begin{minipage}[t]{0.49\textwidth}
  \mypar{...on coercions}
\begin{align*}
  [\unification{\alpha}{\rho}]\idC{\rho'} &= \idC{[\unification{\alpha}{\rho}]\rho}\\
  [\unification{\alpha}{\rho}]\topC{\rho'} &= \topC{[\unification{\alpha}{\rho}]\rho'}\\
  [\unification{\alpha}{\rho}]\topArrC &= \topArrC\\
  [\unification{\alpha}{\rho}]\topAllC &= \topAllC\\
  [\unification{\alpha}{\rho}]\distArrC{\rho_1}{\rho_2}{\rho_3} &= \distArrC{[\unification{\alpha}{\rho}]\rho_1}{[\unification{\alpha}{\rho}]\rho_2}{[\unification{\alpha}{\rho}]\rho_3}\\
  [\unification{\alpha}{\rho}]\distRecC{l}{\rho_1}{\rho_2} &= \distRecC{l}{[\unification{\alpha}{\rho}]\rho_1}{[\unification{\alpha}{\rho}]\rho_2}\\
  [\unification{\alpha}{\rho}]\projlC{\rho_1}{\rho_2} &= \projlC{[\unification{\alpha}{\rho}]\rho_1}{[\unification{\alpha}{\rho}]\rho_2}\\
  [\unification{\alpha}{\rho}]\projrC{\rho_1}{\rho_2} &= \projrC{[\unification{\alpha}{\rho}]\rho_1}{[\unification{\alpha}{\rho}]\rho_2}\\
  [\unification{\alpha}{\rho}](\mpC{c_1}{c_2}) &= \mpC{([\unification{\alpha}{\rho}]c_1)}{([\unification{\alpha}{\rho}]c_2)}\\
  [\unification{\alpha}{\rho}](\compC{c_1}{c_2}) &= \compC{([\unification{\alpha}{\rho}]c_1)}{([\unification{\alpha}{\rho}]c_2)}\\
  [\unification{\alpha}{\rho}]\pairC{c_1}{c_2} &= \pairC{[\unification{\alpha}{\rho}]c_1}{[\unification{\alpha}{\rho}]c_2}\\
  [\unification{\alpha}{\rho}](\arrC{c_1}{c_2}) &= \arrC{([\unification{\alpha}{\rho}]c_1)}{([\unification{\alpha}{\rho}]c_2)}\\
  [\unification{\alpha}{\rho}](\alllC{c}{\rho'}) &= \alllC{([\unification{\alpha}{\rho}]c)}{([\unification{\alpha}{\rho}]\rho')}\\
  [\unification{\alpha}{\rho}](\allrC{\alpha}{c}) &= \allrC{\alpha}{[\unification{\alpha}{\rho}]c}\\
  [\unification{\alpha}{\rho}]\trecord{l}{c} &= \trecord{l}{[\unification{\alpha}{\rho}]c}
\end{align*}
\end{minipage}
\begin{minipage}[t]{0.49\textwidth}
  \mypar{...on coercion contexts}
\begin{align*}
  [\unification{\alpha}{\rho}]\bullet                       &= \bullet\\
  [\unification{\alpha}{\rho}](\arrCC{\mathcal{C}}{c'})     &= \arrCC{([\unification{\alpha}{\rho}]\mathcal{C})}{[\unification{\alpha}{\rho}]c'}\\
  [\unification{\alpha}{\rho}](\projlCC{\mathcal{C}}{A}{B}) &= \projlCC{([\unification{\alpha}{\rho}]\mathcal{C})}{[\unification{\alpha}{\rho}]A}{[\unification{\alpha}{\rho}]B}\\
  [\unification{\alpha}{\rho}](\projrCC{\mathcal{C}}{A}{B}) &= \projrCC{([\unification{\alpha}{\rho}]\mathcal{C})}{[\unification{\alpha}{\rho}]A}{[\unification{\alpha}{\rho}]B}\\
  [\unification{\alpha}{\rho}](\mpCC{\mathcal{C}}{\mathcal{M}}{c_1}{A}{B}) &= \mpCC{([\unification{\alpha}{\rho}]\mathcal{C})}{([\unification{\alpha}{\rho}]\mathcal{M})}{[\unification{\alpha}{\rho}]c_1}{[\unification{\alpha}{\rho}]A}{[\unification{\alpha}{\rho}]B}\\
  [\unification{\alpha}{\rho}](\alllCC{\mathcal{C}}{\rho'}) &= \alllCC{([\unification{\alpha}{\rho}]\mathcal{C})}{[\unification{\alpha}{\rho}]\rho'}\\
  [\unification{\alpha}{\rho}](\recCC{\mathcal{C}}{l})     &= \recCC{([\unification{\alpha}{\rho}]\mathcal{C})}{l}
\end{align*}
\end{minipage}

\subsubsection{Applying type variable substitution...}
\begin{minipage}[t]{0.5\textwidth}
  \mypar{{...on types}}
  \begin{align*}
    [{\alpha}\mapsto{\tau}]\nat                  &= \nat\\
    [{\alpha}\mapsto{\tau}]\top                  &= \top\\
    [{\alpha}\mapsto{\tau}]\alpha                &= \tau\\
    [{\alpha}\mapsto{\tau}]\beta                 &= \beta\\
    [{\alpha}\mapsto{\tau}]\hat\alpha            &= \hat\alpha\\
    [{\alpha}\mapsto{\tau}](A\to B)              &= ([\substitution{\alpha}{\tau}]A)\to([\substitution{\alpha}{\tau}]B)\\
    [{\alpha}\mapsto{\tau}](A\& B)               &= ([\substitution{\alpha}{\tau}]A)\&([\substitution{\alpha}{\tau}]B)\\
    [{\alpha}\mapsto{\tau}](\Tabs{\alpha}{A}{B}) &= \Tabs{\alpha}{[\substitution{\alpha}{\tau}]A}{[\substitution{\alpha}{\tau}]B}\\
    [{\alpha}\mapsto{\tau}]\trecord{l}{A}        &= \trecord{l}{[\substitution{\alpha}{\tau}]A}
  \end{align*}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
  \mypar{{...on terms}}
  \begin{align*}
    [\substitution{\alpha}{\tau}]i &= i\\
    [\substitution{\alpha}{\tau}]() &= ()\\
    [\substitution{\alpha}{\tau}]x &= x\\
    [\substitution{\alpha}{\tau}]\abs{x}{E} &= \abs{x}{[\substitution{\alpha}{\tau}]E}\\
    [\substitution{\alpha}{\tau}](E_1\,E_2) &= ([\substitution{\alpha}{\tau}]E_1)\,([\substitution{\alpha}{\tau}]E_2)\\
    [\substitution{\alpha}{\tau}](E : A) &= [\substitution{\alpha}{\tau}]E : [\substitution{\alpha}{\tau}]A\\
    [\substitution{\alpha}{\tau}]\tabs{\beta}{A}{E} &= \tabs{\beta}{[\substitution{\alpha}{\tau}]A}{[\substitution{\alpha}{\tau}]E}\\
    [\substitution{\alpha}{\tau}](E\,A) &= ([\substitution{\alpha}{\tau}]E)\, ([\substitution{\alpha}{\tau}]A)\\
    [\substitution{\alpha}{\tau}]\record{l}{E} &= \record{l}{[\substitution{\alpha}{\tau}]E}\\
    [\substitution{\alpha}{\tau}](E.l) &= ([\substitution{\alpha}{\tau}]E).l
  \end{align*}
\end{minipage}\\

\noindent
\begin{minipage}[t]{0.47\textwidth}
  \mypar{{...on type contexts}}
  \begin{align*}
    [\substitution{\alpha}{\tau}]\bullet &= \bullet\\
    [\substitution{\alpha}{\tau}](\Delta,\tentry{\alpha}{A}) &= [\substitution{\alpha}{\tau}]\Delta\\
    [\substitution{\alpha}{\tau}](\Delta,\tentry{\beta}{A}) &= [\substitution{\alpha}{\tau}]\Delta,\tentry{\beta}{[\substitution{\alpha}{\tau}]A}\\
    [\substitution{\alpha}{\tau}](\Delta,\tentry{\hat\alpha}{A}) &= [\substitution{\alpha}{\tau}]\Delta,\tentry{\hat\alpha}{[\substitution{\alpha}{\tau}]A}
  \end{align*}
\end{minipage}
\begin{minipage}[t]{0.47\textwidth}
    \mypar{{...on queues}}
  \begin{align*}
    [\substitution{\alpha}{\tau}]\bullet &= \bullet\\
    [\substitution{\alpha}{\tau}](\mathcal{M},A) &= [\substitution{\alpha}{\tau}]\mathcal{M},([\substitution{\alpha}{\tau}]A)\\
    [\substitution{\alpha}{\tau}](\mathcal{M},l) &= [\substitution{\alpha}{\tau}]\mathcal{M},l
  \end{align*}
\end{minipage}\\%\vspace{3pt}

\noindent
\begin{minipage}[t]{0.49\textwidth}
  \mypar{...on coercions}
\begin{align*}
  [\substitution{\alpha}{\rho}]\idC{\rho'} &= \idC{[\substitution{\alpha}{\rho}]\rho}\\
  [\substitution{\alpha}{\rho}]\topC{\rho'} &= \topC{[\substitution{\alpha}{\rho}]\rho'}\\
  [\substitution{\alpha}{\rho}]\topArrC &= \topArrC\\
  [\substitution{\alpha}{\rho}]\topAllC &= \topAllC\\
  [\substitution{\alpha}{\rho}]\distArrC{\rho_1}{\rho_2}{\rho_3} &= \distArrC{[\substitution{\alpha}{\rho}]\rho_1}{[\substitution{\alpha}{\rho}]\rho_2}{[\substitution{\alpha}{\rho}]\rho_3}\\
  [\substitution{\alpha}{\rho}]\distRecC{l}{\rho_1}{\rho_2} &= \distRecC{l}{[\substitution{\alpha}{\rho}]\rho_1}{[\substitution{\alpha}{\rho}]\rho_2}\\
  [\substitution{\alpha}{\rho}]\projlC{\rho_1}{\rho_2} &= \projlC{[\substitution{\alpha}{\rho}]\rho_1}{[\substitution{\alpha}{\rho}]\rho_2}\\
  [\substitution{\alpha}{\rho}]\projrC{\rho_1}{\rho_2} &= \projrC{[\substitution{\alpha}{\rho}]\rho_1}{[\substitution{\alpha}{\rho}]\rho_2}\\
  [\substitution{\alpha}{\rho}](\mpC{c_1}{c_2}) &= \mpC{([\substitution{\alpha}{\rho}]c_1)}{([\substitution{\alpha}{\rho}]c_2)}\\
  [\substitution{\alpha}{\rho}](\compC{c_1}{c_2}) &= \compC{([\substitution{\alpha}{\rho}]c_1)}{([\substitution{\alpha}{\rho}]c_2)}\\
  [\substitution{\alpha}{\rho}]\pairC{c_1}{c_2} &= \pairC{[\substitution{\alpha}{\rho}]c_1}{[\substitution{\alpha}{\rho}]c_2}\\
  [\substitution{\alpha}{\rho}](\arrC{c_1}{c_2}) &= \arrC{([\substitution{\alpha}{\rho}]c_1)}{([\substitution{\alpha}{\rho}]c_2)}\\
  [\substitution{\alpha}{\rho}](\alllC{c}{\rho'}) &= \alllC{([\substitution{\alpha}{\rho}]c)}{([\substitution{\alpha}{\rho}]\rho')}\\
  [\substitution{\alpha}{\rho}](\allrC{\alpha}{c}) &= \allrC{\alpha}{[\substitution{\alpha}{\rho}]c}\\
  [\substitution{\alpha}{\rho}]\trecord{l}{c} &= \trecord{l}{[\substitution{\alpha}{\rho}]c}
\end{align*}
\end{minipage}
\begin{minipage}[t]{0.49\textwidth}
  \mypar{{...on coecion contexts}}
\begin{align*}
  [\substitution{\alpha}{\rho}]\bullet                       &= \bullet\\
  [\substitution{\alpha}{\rho}](\arrCC{\mathcal{C}}{c'})     &= \arrCC{([\substitution{\alpha}{\rho}]\mathcal{C})}{[\substitution{\alpha}{\rho}]c'}\\
  [\substitution{\alpha}{\rho}](\projlCC{\mathcal{C}}{A}{B}) &= \projlCC{([\substitution{\alpha}{\rho}]\mathcal{C})}{[\substitution{\alpha}{\rho}]A}{[\substitution{\alpha}{\rho}]B}\\
  [\substitution{\alpha}{\rho}](\projrCC{\mathcal{C}}{A}{B}) &= \projrCC{([\substitution{\alpha}{\rho}]\mathcal{C})}{[\substitution{\alpha}{\rho}]A}{[\substitution{\alpha}{\rho}]B}\\
  [\substitution{\alpha}{\rho}](\mpCC{\mathcal{C}}{\mathcal{M}}{c_1}{A}{B}) &= \mpCC{([\substitution{\alpha}{\rho}]\mathcal{C})}{([\substitution{\alpha}{\rho}]\mathcal{M})}{[\substitution{\alpha}{\rho}]c_1}{[\substitution{\alpha}{\rho}]A}{[\substitution{\alpha}{\rho}]B}\\
  [\substitution{\alpha}{\rho}](\alllCC{\mathcal{C}}{\rho'}) &= \alllCC{([\substitution{\alpha}{\rho}]\mathcal{C})}{[\substitution{\alpha}{\rho}]\rho'}\\
  [\substitution{\alpha}{\rho}](\recCC{\mathcal{C}}{l})     &= \recCC{([\substitution{\alpha}{\rho}]\mathcal{C})}{l}
\end{align*}
\end{minipage}

\subsection{Judgments}
\mypar{Well-formed substitution (algorithmic)}
\fbox{
\begin{mathpar}
  \inferrule*[right=WFS-nil]{ }{\wfSubst{\Delta}{\bullet}{\bullet}} \and
  \inferrule*[]{\wfSubst{\Delta}{\theta,\unification{\alpha}{A}}{\theta'}}{\wfSubst{\Delta,\tentry{\alpha}{B}}{\theta,\unification{\alpha}{A}}{\theta'}} \and
  \inferrule*{\wfSubst{\Delta}{\theta,\unification{\beta}{A}}{\theta'}}{\wfSubst{\Delta,\tentry{\hat{\alpha}}{B}}{\theta,\unification{\beta}{A}}{\theta'}} \and
  \inferrule*[right=WFS-next]{\wfSubst{\Delta}{\theta}{\theta_1} \\ \theta_1\circ\theta(\algdisjoint{\Delta}{A}{B)}{\theta_2}}{\wfSubst{\Delta,\tentry{\hat{\alpha}}{B}}{\theta,\unification{\alpha}{A}}{\theta_2\circ\theta_1}}
\end{mathpar}
}
\mypar{Unification algorithm}
\fbox{
  \begin{mathpar}
    \inferrule*[right=U-refl]{ }{\unifyB{\Delta}{\xi}{\xi}{\bullet}} \\
    \inferrule*[right=U-VVL]{\wfSubst{\Delta}{[\unification{\alpha}{\hat\beta}]}{\theta}}{\unifyB{\Delta}{\hat\alpha}{\hat\beta}{\theta,{\hat\alpha}\mapsto{\hat\beta}}} \and
    \inferrule*[right=U-VVR]{\wfSubst{\Delta}{[\unification{\beta}{\hat\alpha}]}{\theta}}{\unifyB{\Delta}{\hat\alpha}{\hat\beta}{\theta,{\hat\beta}\mapsto{\hat\alpha}}} \and
    \inferrule*[right=U-NatV]{\wfSubst{\Delta}{[\unification{\alpha}{\nat}]}{\theta}}{\unifyB{\Delta}{\nat}{\hat{\alpha}}{\theta,\unification{\alpha}{\nat}}} \and
    \inferrule*[right=U-VNat]{\wfSubst{\Delta}{[\unification{\alpha}{\nat}]}{\theta}}{\unifyB{\Delta}{\hat{\alpha}}{\nat}{\theta,\unification{\alpha}{\nat}}} \and
    \inferrule*[right=U-CV]{\wfSubst{\Delta}{[\unification{\alpha}{\alpha}]}{\theta}}{\unifyB{\Delta}{\alpha}{\hat{\alpha}}{\theta,\hat{\alpha}\mapsto\alpha}}\and
    \inferrule*[right=U-VC]{\wfSubst{\Delta}{[\unification{\alpha}{\alpha}]}{\theta}}{\unifyB{\Delta}{\hat{\alpha}}{\alpha}{\theta,\hat{\alpha}\mapsto\alpha}}
  \end{mathpar}
}\\
\fbox{
  \begin{mathpar}
    \inferrule{\unifyB{\Delta}{\xi_1}{\xi_2}{\theta}}{\unifyM{\Delta}{\xi_1}{\xi_2}{\theta}}
  \end{mathpar}
}
\mypar{Algorithmic disjointness}

Formula $\notarrow{A}$, in the rules below, means that $A$ is not a function type.\\
\fbox{
\begin{mathpar}
  \inferrule*[right=AD-TopL]{ }{\algdisjoint{\Delta}{\top}{A}{\bullet}} \and
  \inferrule*[right=AD-TopR]{ }{\algdisjoint{\Delta}{A}{\top}{\bullet}} \\
  \inferrule*[right=AD-VarL]{\tentry{\alpha}{A}\in\Delta \\ \algSubRight{\Delta}{\bullet}{A}{B}{c}{\theta}}{\algdisjoint{\Delta}{\alpha}{B}{\theta}} \and
  \inferrule*[right=AD-VarR]{\tentry{\beta}{B}\in{\Delta} \\ \algSubRight{\Delta}{\bullet}{B}{A}{c}{\theta}}{\algdisjoint{\Delta}{A}{\beta}{\theta}} \and
  \inferrule*[right=AD-UVarL]{\tentry{\hat\alpha}{A}\in\Delta \\ \algSubRight{\Delta}{\bullet}{A}{B}{c}{\theta}}{\algdisjoint{\Delta}{\hat\alpha}{B}{\theta}} \and
  \inferrule*[right=AD-UVarR]{\tentry{\hat\beta}{B}\in{\Delta} \\ \algSubRight{\Delta}{\bullet}{B}{A}{c}{\theta}}{\algdisjoint{\Delta}{A}{\hat\beta}{\theta}} \and
  \inferrule*[right=AD-Rcd]{\algdisjoint{\Delta}{A}{B}{\theta}}{\algdisjoint{\Delta}{\trecord{l}{A}}{\trecord{l}{B}}{\theta}} \and
  \inferrule*[right=AD-Nrcd]{l_1 \neq l_2}{\algdisjoint{\Delta}{\trecord{l_1}{A}}{\trecord{l_2}{B}}{\bullet}} \and
  \inferrule*[right=AD-Arr]{\algdisjoint{\Delta}{A_2}{B_2}{\theta}}{\algdisjoint{\Delta}{A_1\to A_2}{B_1\to B_2}{\theta}} \and
  \inferrule*[right=AD-ArrL]{\algdisjoint{\Delta}{A_2}{B}{\theta} \\ \notarrow{B}}{\algdisjoint{\Delta}{A_1\to A_2}{B}{\theta}} \and
  \inferrule*[right=AD-ArrR]{\algdisjoint{\Delta}{A}{B_2}{\theta} \\ \notarrow{A}}{\algdisjoint{\Delta}{A}{B_1\to B_2}{\theta}} \and
  \inferrule*[right=AD-AndL]{\algdisjoint{\Delta}{A_1}{B}{\theta_1} \\ \theta_1(\algdisjoint{\Delta}{A_2}{B)}{\theta_2} \\ \notarrow{B}}{\algdisjoint{\Delta}{A_1\& A_2}{B}{\theta_2\circ\theta_1}} \and
  \inferrule*[right=AD-AndR]{\algdisjoint{\Delta}{A}{B_1}{\theta_1} \\ \theta_1(\algdisjoint{\Delta}{A}{B_2)}{\theta_2} \\ \notarrow{A}}{\algdisjoint{\Delta}{A}{B_1\& B_2}{\theta_2\circ\theta_1}} \and
  \inferrule*[right=AD-All]{\algdisjoint{\Delta,\tentry{\hat\alpha}{A_1\& B_1}}{[\alpha\mapsto\hat\alpha]B_1}{[\alpha\mapsto\hat\alpha]B_2}{\theta}}{\algdisjoint{\Delta}{\Tabs{\alpha}{A_1}{A_2}}{\Tabs{\alpha}{B_1}{B_2}}{\theta}}\and
  \inferrule*[right=AD-AllL]{\algdisjoint{\Delta,\tentry{\hat\alpha}{A}}{[\alpha\mapsto\hat\alpha]B_1}{B_2}{\theta}}{\algdisjoint{\Delta}{\Tabs{\alpha}{A}{B_1}}{B_2}{\theta}}\and
  \inferrule*[right=AD-AllR]{\algdisjoint{\Delta,\tentry{\hat\alpha}{A}}{B_1}{[\alpha\mapsto\hat\alpha]B_2}{\theta}}{\algdisjoint{\Delta}{B_1}{\Tabs{\alpha}{A}{B_2}}{\theta}}\and
  \inferrule*[right=AD-AX]{\starax{A}{B}}{\algdisjoint{\Delta}{A}{B}{\bullet}}
\end{mathpar}
}\\
\fbox{
  \begin{mathpar}
    \inferrule*[right=AX-NatBool]{ }{\starax{\nat}{\bool}}\and
    \inferrule*[right=AX-BoolNat]{ }{\starax{\bool}{\nat}}\and
    \inferrule*[right=AX-RcdNat]{ }{\starax{\trecord{l}{A}}{\nat}}\and
    \inferrule*[right=AX-NatRcd]{ }{\starax{\nat}{\trecord{l}{A}}}\and
    \inferrule*[right=AX-RcdBool]{ }{\starax{\trecord{l}{A}}{\bool}}\and
    \inferrule*[right=AX-BoolRcd]{ }{\starax{\bool}{\trecord{l}{A}}}
    %% \inferrule*{}
  \end{mathpar}
}

\mypar{Internal disjointness}
\fbox{
  \begin{mathpar}
    \inferrule*[right=UD-Nat]{ }{\algUdisjoint{\Delta}{\nat}{\bullet}}\and
    \inferrule*[right=UD-Bool]{ }{\algUdisjoint{\Delta}{\bool}{\bullet}}\and
    \inferrule*[right=UD-Top]{ }{\algUdisjoint{\Delta}{\top}{\bullet}}\and
    \inferrule*[right=UD-Var]{\tentry{\alpha}{A}\in\Delta}{\algUdisjoint{\Delta}{\alpha}{\bullet}}\and
    \inferrule*[right=UD-UVar]{\tentry{\hat\alpha}{A}\in\Delta}{\algUdisjoint{\Delta}{\hat\alpha}{\bullet}}\and
    \inferrule*[right=UD-Rcd]{\algUdisjoint{\Delta}{A}{\theta}}{\algUdisjoint{\Delta}{\trecord{l}{A}}{\theta}}\and
    \inferrule*[right=UD-Arr]{\algUdisjoint{\Delta}{B}{\theta}}{\algUdisjoint{\Delta}{A\to B}{\theta}}\and
    \inferrule*[right=UD-And]{\algdisjoint{\Delta}{A}{B}{\theta}\\\ \theta(\algUdisjoint{\Delta}{A)}{\theta_1}\\\theta(\algUdisjoint{\Delta}{B)}{\theta_2}}{\algUdisjoint{\Delta}{A\& B}{\theta_1\circ\theta_2\circ\theta}}\and
    \inferrule*[right=UD-All]{\algUdisjoint{\Delta,\tentry{\alpha}{A}}{B}{\theta}}{\algUdisjoint{\Delta}{\Tabs{\alpha}{A}{B}}{\theta}}
  \end{mathpar}
}

\begin{figure}[h]
  \caption{Algorithmic subtyping}
  \begin{subfigure}{\textwidth}
    \begin{mathpar}
      \inferrule{\algSubRight{\bullet}{\bullet}{A}{B}{c}{\theta}}{\algSubMain{A}{B}{c}{\theta}}
    \end{mathpar}
    \caption{Main judgment}
  \end{subfigure}

  \begin{subfigure}{\textwidth}
    \begin{mathpar}
      \inferrule*[right=AR-top]
          { }
          {\algSubRight{\Delta}{\mathcal{L}}{A}{\top}{\compC{\toparrowqueue{\mathcal{L}}}{\topC{\toTarget{A}}}}{\bullet}}
      \and
      \inferrule*[right=AR-rcd]
          {\algSubRight{\Delta}{\mathcal{L},l}{A}{B}{c}{\theta}}
          {\algSubRight{\Delta}{\mathcal{L}}{A}{\trecord{l}{B}}{c}{\theta}}
      \and
      \inferrule*[right=AR-and]
          {\algSubRight{\Delta}{\mathcal{L}}{A}{B_1}{c_1}{\theta} \\ \algSubRight{\Delta}{\mathcal{L}}{A}{B_2}{c_2}{\theta}}
          {\algSubRight{\Delta}{\mathcal{L}}{A}{B_1\& B_2}{\compC{\distarrowqueue{\mathcal{L}}{B_1}{B_2}}{\pairC{c_1}{c_2}}}{\theta}}
      \and
      \inferrule*[right=AR-arr]
          {\algSubRight{\Delta}{\mathcal{L},B_1}{A}{B_2}{c}{\theta}}
          {\algSubRight{\Delta}{\mathcal{L}}{A}{B_1\to B_2}{c}{\theta}}
      \and
      \inferrule*[right=AR-all]
          {\algSubRight{\Delta,\tentry{\alpha}{B_1}}{\mathcal{L}}{A}{B_2}{c}{\theta}}
          {\algSubRight{\Delta}{\mathcal{L}}{A}{\Tabs{\alpha}{B_1}{B_2}}{\allrC{\alpha}{c}}{\theta}}
      \and
      \inferrule*[right=AR-base]
          {\algSubLeft{\Delta}{\mathcal{L}}{\bullet}{A}{\bullet}{A}{\xi}{\mathcal{C}}{\theta}}
          {\algSubRight{\Delta}{\mathcal{L}}{A}{\xi}{\mathcal{C}[\idC{\toTarget{A}}]}{\theta}}
    \end{mathpar}
    \caption{Right focus}
  \end{subfigure}

  \begin{subfigure}{\textwidth}
    \begin{mathpar}
      \inferrule*[right=AL-Base]
          {\unifyB{\Delta}{\xi_1}{\xi_2}{\theta}}
          {\algSubLeft{\Delta}{\bullet}{\mathcal{M}}{A_0}{\mathcal{C}}{\xi_1}{\xi_2}{\mathcal{C}}{\theta}}
          \and
      \mprset{vskip=2pt}
      \inferrule*[right=AL-VarArr]
                 {\theta= [\unification{\alpha}{(\hat\alpha_1\to\hat\alpha_2)}] \\ \fresh{\hat\alpha_1, \hat\alpha_2}\\ \Delta = \Delta_1,\tentry{\hat\alpha}{A},\Delta_2\\\\ %(\tentry{\hat\alpha}{A})\in\Delta\\\\
                   \algSubRight{\Delta_1,\tentry{\hat\alpha_1}{\top},\tentry{\hat\alpha_2}{A},\theta(\Delta_2)}{\bullet}{\theta(B_1)}{\hat\alpha_1}{c_1}{\theta_1}\\
                   \theta_1\circ\theta(\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M},B_1}{A_0}{\arrCC{\mathcal{C}}{c_1}}{\hat\alpha_2}{\xi)}{\mathcal{C'}}{\theta_2}
                 }
          {\algSubLeft{\Delta}{B_1,\mathcal{L}}{\mathcal{M}}{A_0}{\mathcal{C}}{\hat\alpha}{\xi}{\mathcal{C'}}{\theta_2\circ\theta_1\circ\theta}}
          \mprset{vskip=}
      \and
      \inferrule*[right=AL-AndL]
          {\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M}}{A_0}{\projlCC{\mathcal{C}}{\toTarget{A_1}}{\toTarget{A_2}}}{A_1}{\xi}{\mathcal{C'}}{\theta}}
          {\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M}}{A_0}{\mathcal{C}}{A_1\& A_2}{\xi}{\mathcal{C'}}{\theta}}
      \and
      \inferrule*[right=AL-AndR]
          {\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M}}{A_0}{\projrCC{\mathcal{C}}{\toTarget{A_1}}{\toTarget{A_2}}}{A_2}{\xi}{\mathcal{C'}}{\theta}}
          {\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M}}{A_0}{\mathcal{C}}{A_1\& A_2}{\xi}{\mathcal{C'}}{\theta}}
      \and
      \inferrule*[right=AL-Rcd]
          {\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M},l}{A_0}{\recCC{\mathcal{C}}{l}}{A}{\xi}{\mathcal{C'}}{\theta}}
          {\algSubLeft{\Delta}{l,\mathcal{L}}{\mathcal{M}}{A_0}{\mathcal{C}}{\trecord{l}{A}}{\xi}{\mathcal{C'}}{\theta}}
      \and
      \inferrule*[right=AL-Arr]
          {\algSubRight{\Delta}{\bullet}{B_1}{A_1}{c_1}{\theta_1}\\ \theta_1(\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M},B_1}{A_0}{\arrCC{\mathcal{C}}{c_1}}{A_2}{\xi)}{\mathcal{C'}}{\theta_2}}
          {\algSubLeft{\Delta}{B_1,\mathcal{L}}{\mathcal{M}}{A_0}{\mathcal{C}}{A_1\to A_2}{\xi}{\mathcal{C'}}{\theta_2\circ\theta_1}}
      \and
      \inferrule*[right=AL-MP]
                 {\algSubRight{\Delta}{\bullet}{A_0}{\arrowqueue{\mathcal{M}}{A_1}}{c_1}{\theta_1}\\
                  \theta_1(\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M}}{A_0}{\mpCC{\mathcal{C}}{\mathcal{M}}{c_1}{\toTarget{A_1}}{\toTarget{A_2}}}{A_2}{\xi)}{\mathcal{C'}}{\theta_2}
                  %% \elab{\mathcal{C'} = \abs{c}{\compC{\distarrowqueueC{\mathcal{M}}{\left(\compC{c}{(\mpC{\projlC{\toTarget{A_1\to A_2}}{\toTarget{A_1}}}{\projrC{\toTarget{A_1\to A_2}}{\toTarget{A_1}}})}\right)}{(A_1\to A_2)}{A_1}}{\pairC{\mathcal{C}[\idC{\toTarget{A_1\to A_2}}]}{c_1}}}}
                 }
          {\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M}}{A_0}{\mathcal{C}}{A_1\to A_2}{\xi}{\mathcal{C'}}{\theta_2\circ\theta_1}}
      \and
      \inferrule*[right=AL-Forall]
                 {\algSubLeft{\Delta,\tentry{\hat{\alpha}}{A}}{\mathcal{L}}{\mathcal{M}}{A_0}{\alllCC{\mathcal{C}}{\hat\alpha}}{[\alpha\mapsto\hat{\alpha}]B}{\xi}{\mathcal{C'}}{\theta}\\
                 \fresh{\hat\alpha}}
                 {\algSubLeft{\Delta}{\mathcal{L}}{\mathcal{M}}{A_0}{\mathcal{C}}{\Tabs{\alpha}{A}{B}}{\xi}{\mathcal{C'}}{\theta}}
    \end{mathpar}
    \caption{Left focus}
  \end{subfigure}
\end{figure}

\section{Guide}
\begin{theorem}
  \newcommand*{\dom}[1]{\mathsf{dom}(#1)}
  If $\wfSubst{\Delta}{\theta}{\theta'}$, then $\dom{\theta}\cap\dom{\theta'}=\emptyset$.
\end{theorem}
\begin{proof}
  \newcommand*{\dom}[1]{\mathsf{dom}(#1)}
  Easy by induction on the well-formed-substitution judgment. The only interesting case is where
  \begin{itemize}
  \item \(\inferrule{\wfSubst{\Delta}{\theta}{\theta_1} \\ \theta_1\circ\theta(\algdisjoint{\Delta}{A}{B)}{\theta_2}}{\wfSubst{\Delta,\tentry{\hat{\alpha}}{B}}{\theta,\unification{\alpha}{A}}{\theta_1\circ\theta_2}}\)
  \end{itemize}
  From the fact that $\hat\alpha\not\in\Delta$ and the two premises of the rule, it follows that $\hat\alpha\not\in\dom{\theta_1}$ and $\hat\alpha\not\in\dom{\theta_2}$.
  From the definition of substitution, we have $\forall\beta,\,\beta\in\dom{\theta_1\circ\theta}\implies\beta\not\in\dom{(\theta_1\circ\theta)(\Delta)}$.
  Therefore, from the second premise it follows that $\beta\not\in\dom{\theta_2}$. Then, $\dom{\theta}\cap\dom{\theta_2}=\emptyset$.\\
  Also, from the induction hypothesis and the first premise of the rule, it follows that $\dom{\theta}\cap\dom{\theta_1}=\emptyset$.\\
  Altogether, we get that $(\dom{\theta}\cup\{\hat\alpha\})\cap\dom{\theta_1\circ\theta_2}=\emptyset$.
\end{proof}
\subsection{Examples}
With
\begin{align*}
  \mathcal{A} &:= \Tabs{\alpha}{\top}{\Tabs{\beta}{\alpha}{\Tabs{\gamma}{\alpha\&\beta}{\gamma\to\alpha\&\beta}}}\\
  \Delta_1    &:= \tentry{\alpha}{\top},\tentry{\beta}{\alpha\&\nat}\\
  \Delta_2    &:= \tentry{\hat\alpha}{\top},\tentry{\hat\beta}{\hat\alpha},\tentry{\hat\gamma}{\hat{\alpha}\&\hat\beta}\\
\end{align*}
we have
\[
\mprset{vskip=0ex}
\inferrule*[right=AR-all*]
 {
   \inferrule*[Right=AR-arr]
    {
      \inferrule*[Right=AR-and]
       {
         \inferrule*
          {\vdots}
         {\algSubRight{\Delta_1}{\beta}{\mathcal{A}}{\alpha}{?_1}{?}}
         \\
         \inferrule*[Right=AR-base]
          {
            \inferrule*[Right=AL-all*]
             {
               \inferrule*[Right=AL-arr]
                {
                  \inferrule*[right=AR-base,leftskip=2cm]
                   {
                     \inferrule*[Right=AL-base]
                      {
                        \inferrule*
                         {
                           \inferrule*
                            {
                              \inferrule*[Right=AD-andR]
                               {
                                 \inferrule*[right=AD-varL,leftskip=2cm]
                                  {
                                    \inferrule*[]
                                     { }
                                     {\algSubRight{\Delta_1,\Delta_2}{}{}{}{}{}}
                                  }
                                  {\algdisjoint{\Delta_1,\Delta_2}{\beta}{\hat\alpha}{?}}
                                 \\
                                 \inferrule*[right=AD-varL,rightskip=3cm]
                                  {\vdots}
                                  {\algdisjoint{\Delta_1,\Delta_2}{\beta}{\hat{\beta}}{?}}
                                 %% \vdots
                               }
                               {\algdisjoint{\Delta_1,\Delta_2}{\beta}{\hat{\alpha}\&\hat\beta}{?}}
                            }
                            {\wfSubst{\Delta_1,\Delta_2}{\unification{\gamma}{\beta}}}
                         }
                         {\unifyB{\Delta_1,\Delta_2}{\beta}{\hat\gamma}{?}}
                      }
                      {\algSubLeft{\Delta_1,\Delta_2}{\bullet}{\bullet}{\beta}{\abs{c}{c}}{\beta}{\hat\gamma}{?}{?}}
                   }
                   {\algSubRight{\Delta_1,\Delta_2}{\bullet}{\beta}{\hat\gamma}{?}{?}}
                  \\
                  \inferrule*[rightskip=2cm]
                   { }
                   {\algSubLeft{}{}{\beta}{\mathcal{A}}{}{}{\nat}{?}{?}}
                }
                {\algSubLeft{\Delta_1,\Delta_2}{\beta}{\bullet}{\mathcal{A}}{\abs{c}{c}}{\hat\gamma\to\hat{\alpha}\&\hat\beta}{\nat}{?}{?}}
             }
             {\algSubLeft{\Delta_1}{\beta}{\bullet}{\mathcal{A}}{\abs{c}{c}}{\mathcal{A}}{\nat}{?}{?}}
          }
          {\algSubRight{\Delta_1}{\beta}{\mathcal{A}}{\nat}{?_2}{?}}
       }
       {\algSubRight{\Delta_1}{\beta}{\Tabs{\alpha}{\top}{\Tabs{\beta}{\alpha}{\Tabs{\gamma}{\alpha\&\beta}{\gamma\to\alpha\&\beta}}}}{\alpha\&\nat}{\pairC{?_1}{?_2}}{?}}
    }
    {\algSubRight{\Delta_1}{\bullet}{\Tabs{\alpha}{\top}{\Tabs{\beta}{\alpha}{\Tabs{\gamma}{\alpha\&\beta}{\gamma\to\alpha\&\beta}}}}{\beta\to\alpha\&\nat}{?}{?}}
 }
 {\algSubRight{\bullet}{\bullet}{\Tabs{\alpha}{\top}{\Tabs{\beta}{\alpha}{\Tabs{\gamma}{\alpha\&\beta}{\gamma\to\alpha\&\beta}}}}{\Tabs{\alpha}{\top}{\Tabs{\beta}{\alpha\&\nat}{\beta\to\alpha\&\nat}}}{?}{?}}
\]
\end{document}


For the moment, assume that we are running in comoving coordinates,
with dark matter particles only (no hydro) and that the particles all exist at level 0.   These assumptions are
encapsulated in the following lines in the inputs file: \\

\noindent {\bf castro.use\_comoving = t} \\
\noindent {\bf castro.do\_dm\_particles = 1} \\
\noindent {\bf amr.max\_level =  0} \\
\noindent {\bf castro.do\_hydro = 0} \\
\noindent {\bf castro.do\_react = 0} \\
\noindent {\bf castro.do\_grav =  1}

\section{Equations}

If we define ${\mathbf x}_i$ and ${\bf u}_i$ as the location and velocity of particle $i$, respectively, then we wish
to solve
\begin{eqnarray}
\frac{d {\mathbf x}_i}{d t} &=& \frac{1}{a} {\mathbf u}_i \\
\frac{d (a {\mathbf u}_i) }{d t} &=& {\mathbf g}_i
\end{eqnarray}
where ${\mathbf g}_i$ is the gravitational force evaluated at the location of particle $i$, i.e.,
${\mathbf g}_i = {\mathbf g}({\mathbf x}_i,t).$

\section{Initializing the Particles}

\noindent There are three different ways in which particles can currently be initialized:

\subsection{Read from an ASCII file}

To enable this option, set \\

\noindent {\bf castro.castro.particle\_init\_type = AsciiFile} \\
\noindent {\bf castro.castro.ascii\_particle\_file =}{\em particle\_file}

Here {\em particle\_file} is the user-specified name of the file.  The first line in this file is
assumed to contain the number of particles.  Each line after that contains  \\

x y z mass xdot ydot zdot \\

Note that the variable that we call the particle velocity, ${\mathbf u} = a {\bf \dot{x}}$,
so we must multiply ${\bf \dot{x}}$, by $a$ when we initialize the particles.

\subsection{Random placement}

To enable this option, set \\

\noindent {\bf castro.castro.particle\_init\_type = Random} \\

\noindent There are then a number of parameters to set, for example: \\

\noindent {\bf castro.particle\_initrandom\_count = 100000}

\noindent {\bf castro.particle\_initrandom\_mass  = 1}

\noindent {\bf castro.particle\_initrandom\_iseed = 15}

\subsection{Cosmological}

To enable this option, set \\

\noindent {\bf castro.castro.particle\_init\_type = Cosmological} \\

\noindent This process is still under development.

\section{Time Stepping}

\noindent There are currently two different ways in which particles can be moved:

\subsection{Random}

\noindent To enable this option, set \\

\noindent {\bf castro.particle\_move\_type = Random} \\

\noindent Update the particle positions at the end of each coarse time step using a
random number between 0 and 1 multiplied by 0.25 dx.

\subsection{Motion by Self-Gravity}

\noindent To enable this option, set \\

\noindent {\bf castro.particle\_move\_type = Gravitational} \\

\subsubsection{Move-Kick-Drift Algorithm}

In each time step:
\begin{itemize}
\item Solve for ${\mathbf g}^n$  (only if multilevel, otherwise use ${\mathbf g}^{n+1}$ from previous step)
\item ${\mathbf u}_i^{\nph} = \frac{1}{a^{\nph}} ( (a^n {\mathbf u}^n_i) + \frac{\dt}{2} \; {\mathbf g}^n_i )$
\item ${\mathbf x}_i^{n+1 } = {\mathbf x}^n_i +  \frac{\dt}{a^{\nph}}  {\mathbf u}_i^{\nph}$
\item Solve for ${\mathbf g}^{n+1}$ using ${\mathbf x}_i^{n+1}$
\item ${\mathbf u}_i^{n+1} = \frac{1}{a^{n+1}} ( (a^{\nph} {\mathbf u}^{\nph}_i) + \frac{\dt}{2} \; {\mathbf g}^{n+1}_i )$
\end{itemize}

Note that at the end of the timestep ${\bf x}_i^{n+1}$ is consistent with ${\bf g}^{n+1}$ becasue
we have not advanced the positions after computing the new-time gravity.  This has the benefit that
we perform only one gravity solve per timestep (in a single-level calculation with no hydro) because
the particles are only moved once.

\subsubsection{Computing {\bf g}}

We solve for the gravitational vector as follows:
\begin{itemize}
\item Assign the mass of the particles onto the grid in the form of density, $\rho_{DM}$.
The mass of each particle is assumed to be uniformly distributed over a cube of side $\Delta x$,
centered at what we call the position of the particle.    We distribute the mass of each
particle to the cells on the grid in proportion to the volume of the intersection of each cell
with the particle's cube.   We then divide these cell values by $\Delta x^3$ so that the
right hand side of the Poisson solve will be in units of density rather than mass.
Note that this is the {\it comoving} density.

\item Solve $\nabla^2 \phi = \frac{4 \pi G}{a} \rho_{DM}$.
We discretize with the standard 7-point Laplacian (5-point in 2D)
and use multigrid with Gauss-Seidel red-black relaxation to solve the equation for $\phi$ at cell centers.

\item Compute the normal component of ${\bf g} = -\nabla \phi$ at cell faces by differencing the adjacent values of $\phi,$
e.g. if $\gb = (g_x, g_y, g_z),$ then we define $g_x$ on cell faces with a normal in the x-direction by computing
$g_{x,i-\myhalf,j,k} = -(\phi_{i,j,k} - \phi_{i-1,j,k}) / \Delta x.$

\item  Interpolate each component of ${\bf g}$ from normal cell faces onto each particle position using
linear interpolation in the normal direction.

\end{itemize}

%\subsection{Predictor-Corrector}
%
%An alternative to the above algorithm would be the following predictor-corrector approach:
%
%\begin{itemize}
%\item Solve for ${\bf g}^n$
%\item ${\bf v}_i^{n+1,*} = {\bf v}^n_i + \dt \; {\bf g}^n$
%\item ${\bf x}_i^{n+1,*} = {\bf x}^n_i + \dt \; {\bf v}_i^n$
%\item Solve for ${\bf g}^{n+1}$ using ${\bf x}_i^{n+1,*}$
%\item ${\bf v}_i^{n+1} = {\bf v}^{n+1,*}_i + \frac{\dt}{2} \; ({\bf g}^{n+1} - {\bf g}^n)$
%\item ${\bf x}_i^{n+1} = {\bf x}^{n+1,*}_i + \frac{\dt}{2} \; ({\bf v}_i^{n+1} - {\bf v}_i^n)$
%\end{itemize}
%
%\noindent This has two issues:
%\begin{itemize}
%\item First, the gravity at the end of the timestep is not consistent with the particle positions at the end of the timestep.
%Thus this will require an additional solve per timestep because we move the particles twice per timestep.
%\item Second, this increases the memory required per particle because we would need to keep both ${\bf v}^n_i$
%and ${\bf v}^{n+1,*}_i$ over the course of a timestep.
%\end{itemize}

\section{Output Format}

\subsection{Checkpoint Files}

The particle positions and velocities are stored in a binary file in each checkpoint directory.
This format is designed for being read by the code at restart rather than for diagnostics. \\

We note that the value of $a$ is also written in each checkpoint directory,
in a separate ASCII file called {\em comoving\_a}, containing only the single value. \\

\subsection{Plot Files}

If {\bf particles.write\_in\_plotfile =} 1 in the inputs file
then the particle positions and velocities will be written in a binary file in each plotfile directory.

In addition, we can also
visualize the particle locations as represented on the grid.  There are two ``derived quantities''
which represent the particles.  Setting \\

\noindent {\bf amr.derive\_plot\_vars = particle\_count particle\_mass\_density} \\
\noindent {\bf amr.plot\_vars = NONE} \\

\noindent in the inputs file will generate plotfiles with only two variables.
{\bf particle\_count} represents the number of particles in a grid cell;
{\bf particle\_mass\_density} is the density on the grid resulting from the particles.

We note that the value of $a$ is also written in each plotfile directory,
in a separate ASCII file called {\em comoving\_a}, containing only the single value. \\

\subsection{ASCII Particle Files}

To generate an ASCII file containing the particle positions and velocities,
one needs to restart from a checkpoint
file but doesn't need to run any steps.  For example, if chk00350 exists, then one can set: \\

\noindent {\bf amr.restart = chk00350} \\
\noindent {\bf max\_step = 350} \\
\noindent {\bf particles.particle\_output\_file =} {\em particle\_output} \\

\noindent which would tell the code to restart from chk00350, not to take any further time steps, and to write an ASCII-format
file called {\em particle\_output}. \\

\noindent This file has the same format as the ASCII input file: \\

\noindent number of particles \\
x y z mass xdot ydot zdot \\

\subsection{Run-time Data Logs}

If you set \\

\noindent {\bf amr.data\_log = }{\em log\_file}  \\

\noindent in the inputs file, then at run-time the code will write a log file with entries every coarse
grid time step, containing \\

\noindent nstep  time   dt   redshift   a

\subsection{Run-time Screen Output}

There are a number of flags that control the verbosity written to the screen at run-time.  These are:

\noindent {\bf amr.v } \\
\noindent {\bf castro.v } \\
\noindent {\bf gravity.v } \\
\noindent {\bf mg.v } \\
\noindent {\bf particles.v } \\

These control printing  about the state of the calculation (time, value of $a$, etc) as well as
timing information.


\documentclass[main.tex]{subfiles}
\begin{document}

\section*{Fri Nov 08 2019}

It can be shown that the equation
%
\begin{align}
  \dv[2]{x^{\mu }}{\tau } + \Gamma^{\mu }_{\alpha \beta } \dv{x^{\alpha }}{\tau } \dv{x^{\beta }}{\tau } = 0
\,,
\end{align}
%
in the low-field limit gives the regular acceleration in a gravitational field.

If we define \(u^{\mu }\) as \(\dv*{x^{\mu }}{\tau }\), we get that the equation is equivalent to
%
\begin{align}
  u^{\alpha } \qty(\pdv{u^{\mu } }{x^{\alpha }} + \Gamma^{\mu }_{\alpha \beta }u^{\beta }) = u^{\alpha } \nabla_{\alpha } u^{\mu } = a^{\mu } = 0
\,.
\end{align}

The acceleration we feel corresponds to the difference between our motion and geodesic motion.

The four-velocity has constant square modulus: either 0, or \(\pm 1\), if we choose an appropriate parametrization. Therefore we can classify geodesics.

\paragraph{Timelike geodesics} have \(u^{\mu } u_{\mu } = -1\), and are related to the motion of a particle. They minimize the proper time \(\dd{\tau} = \sqrt{-\dd{s^2}}\), which is real in this case. We parametrize them by \(\tau \).

\paragraph{Spacelike geodesics} have \(u^{\mu } u_{\mu } = +1\) and can be seen as the shortest path between two points: for them, the integral of \(\dd{s}\) is stationary. We parametrize them by \(s\).

\paragraph{Null geodesics} have \(u^{\mu } u_{\mu } = 0\) are characterized by \(\dd{s}=0\). We parametrize them with some parameter of our choosing, \(\lambda \), which must be independent of proper time or space.

\subsection{Solutions of the geodesic equation}

We treat the problem in the case of a two-dimensional Euclidean plane, using polar coordinates: we know we should find straight lines, but in these coordinates the problem is nontrivial.

The metric is \(\dd{s^2} = \dd{r^2} + r^2 \dd{\theta^2}\), and the nonzero Christoffel symbols are (see exercise 3.3):
%
\begin{align}
  \Gamma^{r}_{\theta \theta } = -r
  \qquad \text{and} \qquad
  \Gamma^{\theta }_{\theta r } =
  \Gamma^{\theta }_{r \theta } = \frac{1}{r}
\,.
\end{align}

Our equation for the \(r\) coordinate is then:
%
\begin{align}
  \dv[2]{r}{s} - r \qty(\dv{\theta }{s})^2 = 0
\,,
\end{align}
%
while for the \(\theta \) coordinate by symmetry we can identify the two terms:
%
\begin{align}
  \dv[2]{\theta }{s} + \frac{2}{r} \dv{r}{s} \dv{\theta }{s} =0
\,.
\end{align}

In general, in an \(n\) dimensional space, motion is defined by \(n\) scalar functions, which can be determined by our \(n\) differential equations with \(2n\) initial conditions.

It is in general useful to find \emph{first integrals}, quantities which are constant along the geodesic.

It can be shown that the second equation can be written as
%
\begin{align}
  \frac{1}{r^2} \dv[]{}{s} \qty(r^2 \dv{\theta }{s}) =0
\,,
\end{align}
%
which gives us the first integral \(A = r^2 \dv*{\theta }{s}\).

\begin{bluebox}
An easy way to see this: the equation can be written, denoting derivatives with respect to \(s\) with a dot, as
%
\begin{align}
\ddot{\theta} + \frac{2 \dot{r} \dot{\theta}}{r} = 0
\,,
\end{align}
%
which we can rearrange as
%
\begin{align}
\frac{ \ddot{\theta}}{\dot{\theta}}
+ 2 \frac{\dot{r}}{r} = 0
\,,
\end{align}
%
or
%
\begin{align}
\dv{}{s} \qty( \log \dot{\theta} + 2 \log r) =
\dv{}{s} \log(\dot{\theta} r^2)
=0
\,,
\end{align}
%
so we have found our integral: the derivative of the logarithm of something is constant iff the thing is constant.
\end{bluebox}

We can always also use the definition of the differential:
%
\begin{align}
    \dd{s^2} = \dd{r^2} + r^2 \dd{\theta^2 }
    \,,
\end{align}
%
so we can insert our integral:
%
\begin{align}
    \dd{s^2} = \dd{r^2} + r^2 \frac{A^2}{r^{4}} \dd{s^2}
\,,
\end{align}
%
so
%
\begin{align}
  \dd{s^2} \qty(1- \frac{A^2}{r^2}) = \dd{r^2}
\,.
\end{align}

This has two solutions, but it can be shown that they give the same result in the end.

We want the trajectory: the locus of the points the geodesic passes through, \(r(\theta )\) or \(\theta (r)\).

We do:
%
\begin{align}
  \dv[]{\theta }{r} = \dv[]{\theta }{s} \dv[]{s}{r} = \frac{A}{r^2} \frac{1}{\sqrt{1- \frac{A^2}{r^2}}}
\,,
\end{align}
%
so we can integrate this:
%
\begin{align}
  \theta  = \int \dd{\theta } = \int
  \frac{A}{r^2} \qty(1 - \frac{A^2}{r^2})^{-1/2} \dd{r}
\,,
\end{align}
%
which comes out to be \(\Delta \theta  = \arccos (A/r)\), which can be inverted to find \(r\cos(\Delta \theta ) = A \): using the trigonometric relation
%
\begin{align}
\cos(x-y) = \cos(x) \cos(y) + \sin(x) \sin(y)
\,,
\end{align}
%
we find that this is equivalent to
%
\begin{align}
  r \cos(\theta ) \cos(\theta_0 ) + r \sin(\theta ) \sin(\theta_0 ) = A
\,,
\end{align}
%
therefore this can be written as \(y = \alpha x + \beta \).

\subsection{Euler-Lagrange equations}

The time interval can be written as
%
\begin{subequations}
\begin{align}
  \tau_{AB} &= \int \dd{\tau } = \int \sqrt{-\dd{s^2}}  \\
  &= \int  \dd{\sigma } \mathscr{L} \qty(x^{\alpha }, \dv{x^{\alpha }}{\sigma })
\,,
\end{align}
\end{subequations}
%
so under a perturbation we get:
%
\begin{subequations}
\begin{align}
  0 &= \delta \tau \\
  &= \int  \dd{\sigma } \qty(
      \pdv{\mathscr{L}}{x^{\alpha }} \delta x^{\alpha }
      + \pdv{\mathscr{L}}{\dv{x^{\alpha }}{\sigma }}
      \dv{ \delta x^{\alpha }}{\sigma }
  )  \\
  &= \int  \dd{\sigma }
  \qty(
      \pdv{\mathscr{L}}{x^{\alpha }} - \dv{}{\sigma } \qty(\pdv[]{\mathscr{L}}{\dv{x^{\alpha }}{\sigma }})
  ) \delta x^{\alpha } =0
\,,
\end{align}
\end{subequations}
%
therefore the integrand must vanish identically: this gives us the Euler-Lagrange equations
%
\begin{align}
  \pdv{\mathscr{L}}{x^{\alpha }}
  - \dv{}{\sigma }
  \pdv{\mathscr{L}}{\dv{x^{\alpha}}{\sigma }}=0
\end{align}

\subsection{Killing vectors}

Symmetries of the metric correspond to conserved quantities if our Lagrangian only depends on the metric.
If the metric does not depend on a coordinate, then the unit vector in that direction is called a Killing vector field.

If we have a Killing vector field, then the momentum along the Killing vector is conserved.

If the Killing coordinate is \(x^{1}\), it can be expressed as
%
\begin{align}
  \pdv{\mathscr L}{\dv{x^{1}}{\sigma }} = \frac{1}{2 \mathscr L} \qty(-2 g_{1 \beta } \dv{x^{\beta }}{\sigma }) = - g_{1 \beta } \dv{x^{\beta }}{\tau }
\,,
\end{align}
%
where we performed a change of variable from the derivation with respect to \(\sigma \) to one with respect to \(\tau \).

This holds because:
%
\begin{align}
\mathscr{L} = \sqrt{- g_{\alpha \beta } \dv{x^{\alpha }}{\sigma } \dv{x^{\beta }}{\sigma }} = \dv{\tau }{\sigma }
\,.
\end{align}

This is usually written as \(\xi^{\mu } u_{\mu } = \const\), which is actually more general.
We can write it with respect to the momentum: \(p^{\mu } \xi_{\mu }\) since we are considering a constant-mass particle.

We can apply this to our 2D example: the metric does not depend on \(\theta \), therefore \(\xi = (0,1)\) is a Killing vector, so \(g_{\theta \mu  } u^{\mu } = r^2 \dv*{\theta }{s} = \const\).

\end{document}


\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{amsmath,textcomp,amssymb,geometry,graphicx,enumerate}
\usepackage{amssymb}
\usepackage{algorithm} % Boxes/formatting around algorithms
\usepackage[noend]{algpseudocode} % Algorithms
\usepackage[usenames,dvipsnames]{color}

\begin{document}

\title{CongressRank: A PageRank Application}
\author{Chandler Chen, David Tseng}
\date{\today}
\maketitle

\section*{Introduction}
When a bill is introduced to Congress, the original proponent is usually called the \textit{sponsor}. Congress members who support the bill can sign onto the bill as a \textit{cosponsor}. The political community places great emphasis on cosponsorships, as it is believed that a bill with more cosponsorships demonstrates a greater support base. Thus, the number of cosponsorships of a bill is an indicator of the popularity of the bill among Congress members. Since a Congress member will only agree to cosponsor a sponsor's bill if he or she agrees with the bill's contents, a cosponsorship can also symbolize the cosponsor's support for and agreement with the sponsor. We believe that by analyzing the network of cosponsorships, we can have a better understanding of the power dynamics and unity within Congress.

In this project, we used PageRank to analyze the cosponsorship graph. PageRank is a ranking algorithm developed to find the stationary distribution of a Markov Chain, where a crawler visits other nodes (where neighboring nodes are chosen uniformly at random) for many iterations. As the number of iterations increases, the percentage of visits a node receives converges to the graph's stationary distribution, and nodes are ranked based on the number of visits they receive. We believe that the rankings generated by PageRank on this graph will be able to rank each member's importance/support within Congress.

% probably be more clear about what you are ranking

% include graphic of edge pointing from cosponsor to sponsor.

\section*{Methods}
In our project, we represented each Congress member as a node. If member $u$ cosponsors member $v$ on a bill, then a directed edge is placed from $u$ to $v$ on the graph. If $u$ cosponsors $v$ on $x$ different bills, there will be $x$ parallel directed edges from $u$ to $v$. Since outgoing edges are chosen uniformly at random in PageRank, if there are more parallel directed edges from $u$ to $v$, the crawler will have a higher probability of visiting $v$ from $u$. Representatives and Senators are analyzed in separate graphs.

We decided to use data from the 114th Congress (2015-2017), since this was the most recent Congress that completed its term. Although the 114th Congress had 100 Senators, 435 Representatives, and 6 non-voting members, there were 7 additional members who left Congress before their term ended. Therefore, we included a total of 548 members (nodes) in our graph. To extract the bill and member data, we used ProPublica's Congress API, which presented us the data in a convenient JSON format. \\

%http://tex.stackexchange.com/questions/160540/how-to-number-figures-continuously-in-documentclassarticle

\textbf{Pseudocode}

\begin{algorithmic}[1]
\Procedure{createGraph}{bills}
\State graph = dictionary initialized to a mapping between each member to an empty list. This will be a mapping between each member to a list of members that he/she cosponsored, i.e., a dictionary mapping each node to a list of adjacent nodes.
\For{bill in bills}
	\For {cosponsor in bill[cosponsors]}
		\State graph[cosponsor].append(sponsor)
	\EndFor
\EndFor
\State \Return graph
\EndProcedure\\

\Procedure{PageRank}{bills, numIterations, p} // bills = list of bills that we are analyzing for our graph. numIterations = total number of visits to be made. p = probability of resetting to a random node.
\State graph = createGraph(bills)
\State membersNumVisits = dictionary initialized to a mapping between each member to 0. This will eventually be a dictionary mapping each member to the number of visits he/she receives during the PageRank algorithm.
\State currentMember = randomly chosen member
\State membersNumVisits[currentMember] += 1
\For {i in range(numIterations)}
	\If {currentMember sponsored no one or Uniform[0,1] $<$ p}
		\State currentMember = randomly chosen member
	\Else
		\State neighbors = graph[currentMember] // list of adjacent nodes
		\State currentMember = randomly chosen member from neighbors, uniformly at random
	\EndIf
	\State membersNumVisits[currentMember] += 1

\EndFor
\State Sort members based on the number of visits, in descending order.
\State \Return membersNumVisits
\EndProcedure
\end{algorithmic}

Above is the pseudocode we used to generate our graph and run our PageRank algorithm. We retrieved the list of bills and their sponsors and cosponsors by using calls to ProPublica's Congress API.

\section*{Experiment 1: Results and Analysis}
For Experiment 1, we included cosponsorships of all bills that were introduced by the 114th Congress, and all of their corresponding sponsors and cosponsors. We set $p$=0.15 (probability of resetting to a random node) and ran the PageRank algorithm for 100,000 steps. If we decrease $p$ to 0.05 or increase $p$ to 0.20, the rankings remain relatively the same. If we further increase $p$ to even higher values, the results become more uniformly random, so we believe it is more meaningful to keep  $p$ at around 0.15.

\begin{table}[h!]
\centering
 \begin{tabular}{|c | c |c |c|}
 \hline
 Rank & Normalized No. Visits & Name & Party \\ [0.5ex]
 \hline
1  & 1.000000 & Diane Black & R \\
2  & 0.812907 & Erik Paulsen & R \\
3  & 0.758962 & Sam Johnson & R \\
4  & 0.744396 & Charles Boustany Jr. & R \\
5  & 0.739433 & Brett Guthrie & R \\
6  & 0.690203 & Christopher Smith & R \\
7  & 0.664008 & Tom Price & R \\
8  & 0.657639 & Paul Gosar & R \\
9  & 0.638455 & Kevin Brady & R \\
10 &  0.625765 &  Peter Roskam & R \\
 \hline

\end{tabular}
\caption{Top 10 ranking of Representatives, using all bills that were introduced}
\label{table:experiment1}
\end{table}

\begin{table}[h!]
\centering
 \begin{tabular}{|c | c |c |c|}
 \hline
 Rank & Normalized No. Visits & Name & Party \\ [0.5ex]
 \hline
1  & 1.000000 & Orrin Hatch &R\\
2  & 0.983083 & Charles Grassley &R\\
3  & 0.800678 & John Thune &R\\
4  & 0.696344  & Benjamin Cardin & D\\
5  & 0.693545  & Mark Kirk & R\\
6  & 0.652788  & John Cornyn & R\\
7  & 0.625090  & Marco Rubio & R\\
8  & 0.620461  & Jerry Moran & R\\
9  & 0.614111  & Mike Lee & R\\
10 &  0.608837 &  Rob Portman & R\\
 \hline

\end{tabular}
\caption{Top 10 ranking of Senators, using all bills that were introduced}
\label{table:experiment1_2}
\end{table}

Tables \ref{table:experiment1} and \ref{table:experiment1_2} list the resulting top 10 Representatives and Senators from our data. The second column displays the number of visits each member received during the course of the PageRank algorithm, normalized by the maximum number received. From our results, it appears that Diane Black and Orrin Hatch are the most popular in their respective chambers. One interesting thing to note is that almost every top 10 member is a Republican, even though we included members from both parties. Since we analyzed all bills that were introduced, this captures the most interactions possible between members via bills. From this analysis, it seems like Republicans were generally more unified compared to Democrats during the 2015-2017 Congress. This makes sense, because Republicans controlled both the House and the Senate during this period of time. Politicians tend to support other politicians in the same party, so therefore the Republicans' advantage in numbers boosted their rankings.

We also noted that some members with leadership positions (such as Nancy Pelosi, Paul Ryan, Mitch McConnell) actually had relatively low rankings. For example, Mitch McConnell ranked 91 within the 100 Senators. It seems like ranking members based on a network of cosponsorships of all bills is not necessarily a good indication of actual influence in Congress. This may be because we included every bill that is introduced, so a person who writes many insignificant bills can accumulate more cosponsorships, leading to skewed results.

\section*{Experiment 2: Results and Analysis}
For our next experiment, we decided to only analyze cosponsorships of bills that were actually signed into law. We ran PageRank on this filtered dataset, using the same parameters as before.

\begin{table}[h!]
\centering
 \begin{tabular}{|c | c |c |c|}
 \hline
 Rank & Normalized No. Visits & Name & Party \\ [0.5ex]
 \hline
1  & 1.000000 &Sam Johnson & R \\
2  & 0.801382 &Bill Posey & R \\
3  & 0.741576 &Carolyn Maloney & D \\
4  & 0.715829 &Terri Sewell & D \\
5  & 0.706899 &Jeff Fortenberry & R \\
6  & 0.590983 &Brett Guthrie & R \\
7  & 0.567227 &Martha McSally & R \\
8  & 0.548026 &Seth Moulton & D \\
9  & 0.507255 &Edward Royce & R \\
10 &  0.337657 & Christopher Smith & R \\
 \hline

\end{tabular}
\caption{Top 10 ranking of Representatives, using only bills that were signed into law.}
\label{table:experiment2}
\end{table}

\begin{table}[h!]
\centering
 \begin{tabular}{|c | c |c |c|}
 \hline
 Rank & Normalized No. Visits & Name & Party \\ [0.5ex]
 \hline
1 & 1.000000 & John Cornyn & R \\
2 & 0.713656 & Roy Blunt & R \\
3 & 0.683725 & Orrin Hatch & R \\
4 & 0.627329 & Dianne Feinstein & D \\
5 & 0.525480 & Mazie Hirono & D \\
6 & 0.492836 & Benjamin Cardin & D \\
7 & 0.421928 & Sheldon Whitehouse & D \\
8 & 0.320936 & Patrick Leahy & D \\
9 & 0.280296 & Heidi Heitkamp & D \\
10& 0.278308 & Rob Portman & R \\  \hline

\end{tabular}
\caption{Top 10 ranking of Representatives, using only bills that were signed into law.}
\label{table:experiment2_2}
\end{table}

Tables \ref{table:experiment2} and \ref{table:experiment2_2} show the results of this experiment. It now appears that Sam Johnson and John Cornyn have the highest ranking in their respective chambers. We note that the proportion of Democrats in the top 10 category is now higher than it was in the previous experiment. One possible explanation is that by only considering cosponsorships on bills that were eventually signed into law, the rankings are more representative of the members' level of influence than their popularity.  This idea is also supported by the fact that people in leadership positions (Paul Ryan, Nancy Pelosi, Mitch McConnell) all have higher rankings here compared to the previous experiment. For example, while Mitch McConnell was ranked 91st previously, he now ranks 15th. This shows that indeed, the second experiment shows more about each member's influence in Congress.
Because the Democrats make up approximately half of the people in the top 10, it seems like the Democrats have almost equal influence as Republicans.

% include example of networkx graph.

%We noted that despite the quantity of bills used in Experiment 1, many of the bills did not even make it past one chamber of Congress. For Experiment 2, we decided that in order to filter out insignificant bills, it might be more meaningful to only look at bills that passed by at least one chamber of Congress. We then ran the experiment the same way.

% results

%To take it further, we decided to finally consider only bills that were actually signed into law. We then ran the experiment the same way as Experiment 1 and 2.

% talk about which p values you used.

\section*{Discussion and Limitations}
There are several limitations to our approaches. One limitation is that although we were only aiming to analyze the 114th Congress, many members were already in Congress before 2015, and they had many more contributions before then. So while our rankings may show some general trends in popularity/support from the interactions in 2015-2017, it does not include interactions between members that were already there before 2015.

Our model is also limited by omitting the relative importance of each considered bill. For instance, H.R.6135-114, a bill \textit{To designate the Federal building and United States courthouse located at 719 Church Street in Nashville, Tennessee, as the "Fred D. Thompson Federal Building and United States Courthouse"} may not be as important as a major defense bill. True, this notion of importance is subjective, so objective importance may be better approximated with the quantifiable amount of discretionary spending put forth in each bill. Even this approach is flawed since large trade deals or important foreign policies may be excluded, but it remains a step in the right direction.
% did not take into account the fact that some bills are more important than others. Weighed each bill the same amount.
% Dicussion: We can see that cosponsorships does not really have a correlation with leadership in Congress.

Overall, despite these limitations, our PageRank algorithm produced some very interesting results. While Republicans may have enjoyed higher levels of popularity in the 114th Congress, Democrats and Republicans shared somewhat equal levels of influence.

%It's interesting to note, that strong correlation fails to exist between the ability to pass bills and having a heavy network of cosponsors within each chamber. Congress members do spend a significant portion of their time gathering cosponsors for their bills, perhaps the time should better be spent on more productive tasks.

% We only looked at 2 years, which is not the same as their actual contributions over time

% experiment 2 shows more about influence than popularity.

\end{document}


\subsection{Proposed approach}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The main purpose of this work is to investigate the feasibility of deep learning approaches for delamination identification in CFRP materials by only utilizing frames of the full wavefield propagation of the guided waves.
Accordingly, two deep learning models based on time data sequence were developed.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure} [!h]
	\centering
	\begin{subfigure}[b]{0.49\textwidth}
		\centering
		\includegraphics[width=.2\textheight]{Fully_ConvLSTM2d_MODEL_updated.png}
		\caption{Convolutional LSTM model}
		\label{fig:convlstm_model}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.49\textwidth}
		\centering
		\includegraphics[width=.2\textheight]{RNN_LSTM_MODEL_updated.png}
		\caption{Time distributed AE model}
		\label{fig:AE_convlstm}
	\end{subfigure}
	\caption{The architecture of the proposed deep learning models.}
	\label{fig:proposed_models}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The developed models presented in Fig.~\ref{fig:proposed_models} have a scheme of Many-to-One sequence prediction, in which it takes \(n\) number of frames representing the waves propagation through time and their interaction with the damage in order to extract the damage features, and finally predicts the delamination location, shape and size in a single output image.

The first proposed model presented in~\ref{fig:convlstm_model}
consists of a three ConvLSTM layers with the filter sizes of 10, 5, and 10 respectively.
The kernel size of the ConvLSTM layers was set to (\(3\times3\)) with a stride of 1 padding was set to "same" which makes the output as same as the input in the case of stride 1.
Furthermore, a \(tanh\) (the hyperbolic tangent) activation function was used at the ConvLSTM layers, which outputs a values in a range between \(-1\) and \(1\).
Moreover, batch normalization~\cite{Santurkar2018} was also applied after each ConvLSTM layer.
The final layer is used a simple 2D convolutional layer followed by a sigmoid activation function which outputs values in a range between \(0\) and \(1\) to indicate the delamination probability.
In this model, we applied a binary cross-entropy as the objective function.
Moreover,Adadelta~\cite{zeiler2012adadelta} optimization technique was utilised that performs back-propagation through time (BPTT)~\cite{goodfellow2016deep}.
Since the sigmoid activation function produces probability values between \(0\) and \(1\), a threshold value must be chosen to classify the output into a damaged or undamaged classes.
Accordingly, the threshold value was set to (\(0.5\)).
The reason for choosing this value for the sigmoid activation function is explained in our previous research work~\cite{ijjeh2021full}.

In the second model presented in~\ref{fig:AE_convlstm} we have applied an autoencoder technique (AE) which is well-known technique for features extraction.
The idea of AE is to compress the input data within the encoding process then learn how to reconstruct it back from the reduced encoded representation (latent space) to a representation that is as close to the original input as possible.
Accordingly, AE reduces data dimensions by learning how to discard the noise in the data.
In this model, we have investigated the use of AE to process a sequence of input frames in order to perform image segmentation operation.
Accordingly, a Time Distributed layer presented in Fig.~\ref{fig:TD} was introduced to the model, in which it distributes the input frames into the AE to keep the independently among frames.
\begin{figure}[!h]
	\centering
	\includegraphics[width=0.5\textwidth]{Time_ditributed_layer.png}
	\caption{Flow of input frames using Time distributed layer}
	\label{fig:TD}
\end{figure}

The AE consists of three parts: the encoder, the bottleneck, and the decoder.
The encoder is responsible for learning how to reduce the input dimensions and compress the input data into an encoded representation.
In Fig.~\ref{fig:AE_convlstm}, the encoder part consists of four levels of downsampling.
The purpose of having different scale levels is to extract feature maps from the input image at different scales.
Every level at the encoder consists of two 2D convolution operations followed by a Batch Normalization then a dropout is applied.
Furthermore, at the end of each level a Maxpooling operation is applied to reduce the dimensionality of the inputs.
The bottleneck presented in Fig.\ref{fig:AE_convlstm} has the lowest level of dimensions of the input data, further it consists of two 2D convolution operations followed by a Batch Normalization.
The decoder part presented in Fig.\ref{fig:AE_convlstm}, is responsible of learning how to restore the original dimensions of the input.
The decoder part consists of two 2D convolutional operations followed by Batch Normalization and Dropout, and an upsampling operation is applied at the end of each decoder level to retrieve the dimensions of its inputs.
Moreover, to enhance the performance learning of the decoder skip connections linking the encoder with the corresponding decoder levels were added.
The outputs sequences of the decoder part is fed into the ConvLSTM2D layer that is utilized to learn long-term spatiotemporal features.
Finally, a 2D convolution operations is applied on the output of the ConvLSTM2d layer followed by a sigmoid activation function.


% !TEX program = pdflatex

\documentclass[11pt]{article}
\usepackage{amsmath,amsfonts,amsthm,amssymb,geometry,dsfont}
\usepackage[usenames,dvipsnames,svgnamesable]{xcolor}
\usepackage[capitalise,noabbrev]{cleveref} %
%\usepackage{natbib,url}
\crefname{equation}{}{} %
\crefname{assumption}{Assumption}{Assumptions}
\crefname{property}{Property}{Properties}
\geometry{left=1in,right=1in,top=0.6in,bottom=1in}
\newcommand{\set}[1]{\ensuremath{\left\{{#1}\right\}}}
\newcommand{\R}{\ensuremath{\mathbb{R}}}
\newcommand{\diff}{\ensuremath{\mathrm{diff}}}
\newcommand{\band}{\ensuremath{\mathrm{band}}}
\newcommand{\toep}{\ensuremath{\mathrm{toep}}}
\newcommand{\tridiag}{\ensuremath{\mathrm{tridiag}}}
\newcommand{\diag}{\ensuremath{\mathrm{diag}}}
\newcommand{\D}[1][]{\ensuremath{\partial_{#1}}}
\newcommand{\indicator}[1]{\ensuremath{\mathds{1}\left\{{#1}\right\}}}
\newcommand{\condexpec}[3][]{\ensuremath{\mathbb{E}_{#1}\left[{#2} \; \middle| \; {#3} \right]}}
\newcommand{\expec}[2][]{\ensuremath{\mathbb{E}_{{#1}}\left[ {#2} \right]}}
\geometry{left=1in,right=1in,top=0.6in,bottom=1in}
\newenvironment{psmallmatrix}
{\left(\begin{smallmatrix}}
	{\end{smallmatrix}\right)}

\theoremstyle{definition}
\newtheorem{example}{Examples}[section]

\bibliographystyle{ecta}
\begin{document}
\title{Notes on Discrete Simulations}
\author{Jess Benhabib, Jesse Perla, and Christopher Tonetti}
\maketitle

\section{Overview}
This package is

\subsection{Linear Differential Equations}

Staley, Luttmer formulation, in log productivity,%
\[
\partial _{t}G\left( z,t\right) =\frac{\sigma ^{2}}{2}\partial
_{z}^{2}G\left( z,t\right) -\mu \partial _{z}G\left( z,t\right) -\alpha
G\left( z,t\right) \left( 1-G\left( z,t\right) \right)
\]%
\[
G\left( t,-\infty \right) =0,\ \ G\left( t,+\infty \right) =1,\ \ \ G\left(
0,z\right) =G_{0}
\]

Transform variables%
\[
\tilde{t}=\alpha t,\ \ \tilde{z}=\frac{\left( 2\alpha \right) ^{.5}}{\sigma }%
\left( z-\mu t\right) ,\ \ H\left( t,z\right) =1-G(t,z)
\]%
we get KPP:%
\begin{equation}
\partial _{t}H\left( t,z\right) =\partial _{z}^{2}H\left( t,z\right)
+H\left( t,z\right) \left( 1-H\left( t,z\right) \right)   \label{H}
\end{equation}%
with solution that depends on initial conditions given by $H\left(
0,z\right) $, and $v$ is th speed of the travelling wave solution to (\ref{H}%
).%
\[
H\left( t,z\right) =W_{v}\left( z-vt\right)
\]%
For a solution we get a travelling wave,
\[
\lim_{x\rightarrow \infty }W_{v}\left( x\right) \sim e^{-\gamma x}
\]%
where $\gamma $ is the smallest $\gamma $ that solves $v=\gamma +\gamma
^{-1}.$

If initial $H\left( 0,z\right) $ is Dirac or a compact perturbation of a
step function, then $v=2$, $\gamma =1,$ and there is a unique travelling
wave function.

If $H\left( 0,z\right) \sim e^{-\gamma x},\ 0<\gamma <1,\ $\ then $\gamma $
solves $v=\gamma +\gamma ^{-1}$ $>2$ as above. ALSO: From Murray,
Mathematical Biology, 1993, Springer, page 280, eq. (11.19): if $\gamma \geq
1,\ $for $H\left( 0,z\right) \sim e^{-\gamma x},$ then $v=2.$

Recovering the untransformed system:

To reverse the transformation to get back to $G\left( t,z\right) $, we have:
\begin{eqnarray}
\ G\left( t,z\right)  &=&1-H(\alpha t,\frac{\left( 2\alpha \right) ^{.5}}{%
\sigma }\left( z-\mu t\right) )\sim e^{-\gamma \tilde{z}}  \label{G1} \\
&=&e^{-\gamma \left( \frac{\left( 2\alpha \right) ^{.5}}{\sigma }\left(
z-\mu t\right) -v\alpha t\right) }=e^{-\gamma \frac{2\alpha }{\sigma }\left(
\left( z-\mu t\right) -v\frac{\sigma }{\left( 2\alpha \right) ^{.5}}\alpha
t\right) }=e^{-\gamma \frac{2\alpha }{\sigma }\left( z-\left( \mu +v\left(
\frac{\alpha }{2}\right) ^{.5}\sigma \right) t\right) }  \label{G2} \\
&=&e^{-\gamma \frac{2\alpha }{\sigma }\left( z-\left( \mu +\left( \gamma +%
\frac{1}{\gamma }\right) \left( \frac{\alpha }{2}\right) ^{.5}\sigma \right)
t\right) }  \label{G3}
\end{eqnarray}%
for $z>\left( \mu +v\left( \frac{\alpha }{2}\right) ^{.5}\sigma \right) t$ $%
\ $\ along the travelling wave.Thus wave speed  for the original system $%
G\left( t,z\right) $ is $\left( \mu +\left( \gamma +\frac{1}{\gamma }\right)
\left( \frac{\alpha }{2}\right) ^{.5}\sigma \right) $ and the exponential
decay rate for log productivity is $\left( \gamma \frac{2\alpha }{\sigma }%
\right) ,$  unless $v=2$ and $\gamma =1$ because $H\left( 0,z\right) \sim
e^{-\gamma x}$ with $\gamma \geq 1,$ and then wave speed is $v=2$ so that $%
\left( \mu +2\left( \frac{\alpha }{2}\right) ^{.5}\sigma \right) =\mu
+\left( 2a\right) ^{.5}\sigma $ along the travelling wave for $z>\left( \mu
+\left( 2a\right) ^{.5}\sigma \right) t,$ and the decay rate of log
productivity distribution is $e^{-\frac{2\alpha }{\sigma }.}$

Note these cdf's for $G\left( t,z\right) $ are in log productivity: $log\
\left( z\right) \sim e^{-\gamma \frac{2\alpha }{\sigma }z},\ x\sim e^{\log
\left( z^{-\gamma \frac{2\alpha }{\sigma }}\right) }\sim z^{-\gamma \frac{%
2\alpha }{\sigma }}.$ For the pareto to have a mean we need $-\gamma \frac{%
2\alpha }{\sigma }.$

Mildred, in her SSRN paper had used the relations from above found in
McKean, Brunet-Derrida, Bramson, Murray and others, to study whether the
drop in recent growth is compatible with decreasing diffusion $\sigma ,$
which also decreases inequality as given by the tail index  $\frac{\gamma
\left( 2\alpha \right) ^{.5}}{\sigma },$ an inverse measure of inequality.
The tail index  however decreases with $\alpha $, compatible with decreasing
imitation  and rising inequality. One can argue therefore that decreasing $%
\alpha $ reflects increasing industry concentration, fostering inequality.
In Jones and Kim however higher growth  due to more leapfrogging and
inventions also generates  higher inequality, while we have recently
observed decreasing growth and higher inequality. Playing with both $\alpha $
and $\sigma $, Mildred could get both an increase in inequality and lower
growth, as in equation (\ref{G3}) above.

%\bibliography{simulation_notes}
\end{document}