% To be compiled with pdf LaTeX
% This file is to be included into master file via \input command
% Note that there is no \begin{document} \end{document} brackets!

\newpage
\section{Shack-Hartmann Wavefront sensor modeling}
\label{sec:sh-wfs}

\mbox{}

\subsection{Nomenclature}

\mbox{}

$\bm{s} = (s_{x},s_{y})$ - vector of xy-slope measurements read from one
Shack-Hartmann sensor subaperture, [m or pixels].
\\

$I(x,y)$ - intensity distribution in the detector focal plane, [].
\\

$\langle \bm{s} \bm{s}^{T} \rangle - \langle \bm{s} \rangle
\langle \bm{s} \rangle^{T}$ - covariance matrix of the xy-slope measurements,
[m$^{2}$ or pixel$^{2}$].
\\

$A$ - area of subaperture, [m$^{2}$].
\\

$p$ - detector pixel size, [m].
\\

$n_{ph}$ - number of photons passed through a subaperture, [].
\\

$\sigma_{e}$ - readout noise, [electrons/pixel].
\\

$f_{L}$ - lenslet focal distance, [m]
\\

$\Gamma_{L}$ - angular magnification in the detector exit pupil, [].
\\

$\varepsilon_{Na}$ - angular fwhm size of \texttt{Na} LGS projected to sky as
seen from a subaperture, [rad].
\\

$\varepsilon_{0}$ - angular fwhm size of a point source projected to sky as
seen from a subaperture, [rad].
\\

$\theta_{e}$ - orientation angle of the elongated spot on the detector, [rad].

\subsection{Sensor geometry}
\label{subsec:sh-wfs-geometry}

TBD

\subsection{Propagation from exit pupil to detector}
\label{subsec:sh-wfs-propagation}

\mbox{}

The sampling of the pupil is derived from the sampling in the WFS detector
focal plane.
If $n_d$ is the number of samples across each spot on the detector and the
fwhm of the
diffraction limited spot is sampled with $k$ pixels, then the pupil sampling is
$2Nn_d/k=Nn$, where $N$ is number of subapertures across the pupil diameter,
$n$ is number of pixels across a subaperture diameter.
It is required that either $k$ or $1/k$ is an integer and that $k\leq 2$.
It is worth nothing that a field stop the size of a subaperture
field--of--view is assumed.
The pixel scale  and the field--of--view are given by $\lambda/dk$ and
$n_d\lambda/dk$, respectively, with $\lambda$ the wavefront sensing
wavelength and $d$ the lenslet pitch.

The Shack--Hartmann wavefront sensor (SH--WFS) model
\begin{enumerate}
\item the telescope pupil $\Pi$ is cut in $N\times N$ square pieces of
$n\times n$ pixels corresponding to the $N\times N$ lenslet array, for the
lenslet $(k,l)$ this is $$a_{kl} =
\Pi[kn,\dots,(k+1)n-1][ln,\dots,l(n+1)-1]\quad k,l=0,\dots,N-1,$$
\item each square array is multiplied by a complex phase ramp to keep the
spot at the center of the array in the free aberration case,
$$a_{kl}^\prime(i,j) = a_{kl}(i,j)\exp(\iota \pi (i+j)(n-1)/n^\prime)\quad
i,j=0,\dots,n-1$$ with $n^\prime=2n$ if $n$ is even or  $n^\prime=2n+1$ if $n$
 is odd and $\iota=\sqrt{-1}$,
\item each square array is padded with zeros in both directions up to
$n^\prime$,$$a_{kl}^\prime[n,\dots,n^\prime-1][n,\dots,n^\prime-1]=0,$$
\item a discrete Fourier transform is performed on each zero--padded array,
$$\tilde a_{kl}^\prime = DFT\left\{a_{kl}^\prime\right\},$$
\item each resulting array is reduced to half its size, $$\tilde a_{kl} =
\tilde a_{kl}^\prime[0,\dots,n-1][0,\dots,n-1],$$
\item the spot intensities are computed from the squared modulus of the
reduced arrays, $$b_{kl} = \left| \tilde a_{kl} \right|^2,$$
\item if needed i.e. $k<2$, the intensity map are binned to the detector
array size, $$b_{kl}^\prime(k,l) =
\sum_{i=kn_d}^{(k+1)n_d-1}\sum_{j=ln_d}^{(l+1)n_d-1} b_{kl}(i,j)\quad
k,l=0,\dots,n_d-1 $$
\end{enumerate}

\subsection{Centroiding methods}
\label{subsec:sh-wfs-centroid}

The four spot centroiding methods are considered for the GMT LTAO Shack-Hartmann
sensors:
\begin{enumerate}
	\item \emph{Center of Gravity}: \index{Center of Gravity centroid}
	\begin{equation} \label{eq:CoG}
	\left[ \begin{array}{c} s_{x} \\ s_{y} \end{array} \right] =
	\frac{1}{\sum_{xy} I(x,y)}
	\sum_{xy} \left[ \begin{array}{c} x \\ y \end{array} \right] I(x,y),
	\end{equation}
	where $\bm{s} = (s_{x},s_{y})$ is the slope readout from the spot,
	$I(x,y)$ is the intensity distribution read out from detector pixels,
	summation is done over the pixels in the area occupied by a single spot.
	\item \emph{Weighted Center of Gravity} \index{Weighted Center of Gravity
	centroid} is the Center of Gravity algorithm
	applied to image $I(x,y) I_{0}(x,y)$, where $I_{0}(x,y)$ is a
	\emph{reference image}. \index{reference image}
	\item \emph{Correlation} \index{Correlation centroid} algorithm finds spot
	position as that of maximum of the correlation function
	\begin{equation} \label{eq:corr}
		C(\bm{s}) = \sum_{xy} I(x,y) I_{0}(x-s_{x},y-s_{y}),
	\end{equation}
	where $I_{0}(x,y)$ is a reference image.
	\item \emph{Quad cell} \index{quad cell} centroiding algorithm is used in
	the tip/tilt WFS, which has 4 pixels per spot. The quad cell readout is
	\begin{equation} \label{eq:quad-cell}
		s_{x} = \frac{1}{\sum_{i=1}^{4} I_{i}} (I_{1} + I_{2} - I_{3} - I_{4}),
	\end{equation}
	$$
		s_{y} = \frac{1}{\sum_{i=1}^{4} I_{i}} (I_{1} + I_{3} - I_{2} - I_{4}),
	$$
	where $\{ I_{i} \}_{i=1}^{4}$ are the four intensity reads from the quad
	cell pixels.
\end{enumerate}
Discussion of these centroiding approaches is given in Ref.
\cite{ConanCentroid}.

\subsection{Sensor noise covariance matrix}
\label{subsec:sh-wfs-noise-covariance}

\mbox{}

This section describes the derivation of the noise covariance matrix for a
SH--WFS with a $N_L\times N_L$ lenslet array paving a telescope pupil of
diameter $D$.
The spots of the SH--WFS are assumed to be seeing
limited i.e. $r_0<D/N_L$, $r_0$ is the Fried parameter. Thus, the projected to
sky angular size of the spot formed by a lenslet is
$\varepsilon_0=\lambda/r_0$, $\lambda$ is the WFS operational wavelength.
The spot elongation due to elongated LGS is characterized by the
$(\varepsilon_{Na},\theta_{e})$-pair of the fwhm angular size
along the \texttt{Na} LGS elongation direction and the elongation
orientation angle. Both these parameters depend on the mutual orientation
lenslet and the LLT, altitude and thickness of the \texttt{Na} layer, and the
LLT pointing. The calculation of the $(\varepsilon_{Na},\theta_{e})$-pair is
described in Section \ref{sec:elongation-orientation}.

The spot intensity profile due to the LGS is
assumed to be Gaussian with elliptical cross section and the long ellipse axis
is rotated by angle $\theta_{e}$ with respect to the camera focal plane
xy-coordinates:
\def\nph{n_{ph}}
\begin{equation}
  \label{eq:2}
  I_{S}(x,y) = { \nph \over 2\pi \sigma_x\sigma_y }
  \exp\left( - { x^{\prime 2} + y^{\prime 2} \over 2\sigma_x\sigma_y}\right),
\end{equation}
where subscript $S$ stands for the star image distribution,
$\nph$ is the photon flux through the subaperture,
\def\vr{\bm{r}}
\def\vre{\bm{r_e}}
\begin{eqnarray}
  \label{eq:3}
  x^{\prime} &=& x\cos(\theta_e) - y\sin(\theta_e), \\
  y^{\prime} &=& x\sin(\theta_e) + y\cos(\theta_e),
\end{eqnarray}
$\sigma_x$ and $\sigma_y$ are related to the fwhm of the non-elongated and
elongated spot, respectively, as
\begin{eqnarray}
  \label{eq:6}
  \varepsilon_{x,y} &=& 2\sqrt{2\ln(2)}\sigma_{x,y}, \\
  \varepsilon_{x,y} &=& f_{L} \Gamma_{L} \varepsilon_{0,Na},
\end{eqnarray}
where $f_{L}$ is the lenslet focal distance, $\Gamma_{L}$ is the angular
magnification in the exit pupil where the lenslet array is located.

The spot centroid xy-readout in the lenslet focal plane in case of the
\emph{Center of Gravity} centroiding algorithm \index{Center of Gravity
centroid} is given by
\begin{equation}
  \label{eq:10}
  \bm{s} = \left[ \begin{array}{c} s_{x} \\ s_{y} \end{array} \right] =
  \frac{1} {\iint_A I(x,y) {\rm d}x{\rm d}y}
  \iint_A
  \left[ \begin{array}{c} x \\ y \end{array} \right]
  I(x,y) {\rm d}x{\rm d}y,
\end{equation}
where $I(x,y)$ is the complete intensity distribution in the spot that
includes the star intensity disribution and some other additions,
$A=(D/N_L)^2$ is the lenslet area.

\subsection{Spot intensity distribution}
\label{sec:spot-intensity}

To proceed with computation of the spot
readout covariance assumptions about the spot intensity distribution need to
be made:
\begin{enumerate}
	\item The whole intensity distribution is
	\begin{equation} \label{eq:whole-intensity}
		I(x,y) = I_{S}(x,y) + I_{B}(x,y),
	\end{equation}
	where $I_{S}(x,y)$ is given in Eq. (\ref{eq:2}), $I_{e}(x,y)$ is the
	background image due to sensor readout noise.
	\item $I_{S}(x,y)$ and $I_{B}(x,y)$ are statistically independent, i.e.
	$\langle I_{S}(x,y)I_{B}(x,y) \rangle = 0$.
	\item $\langle I_{B}(x,y) \rangle$ = 0.
	\item All the $I_{S}(x,y)$ distribution energy is concentrated inside region
	$A$, so \\ $ \iint_A I_{S}(x,y) {\rm d}x{\rm d}y \approx \nph = const$.
	\item The random process $I_{B}(x,y)$ is ergodic, so
	$0 = \langle I_{B}(x,y)
	\rangle \approx \iint_{A} I_{B}(x,y) {\rm d}x {\rm d}y$, which, together
	with the previous assumption gives
	$ \iint_A I(x,y) {\rm d}x{\rm d}y \approx \nph $.
	\item Spot cross-talk is negligible, so
  spots from different lenslets are statistically independent. Therefore, the
  full WFS readout covariance matrix is block diagonal with 2x2 blocks
  corresponding to each spot xy-slope covariance.
  \item Pixel intensities are statistically independent, i.e.
  $\langle I(x,y)I(x^{\prime},y^{\prime}) \rangle = 0$.
\end{enumerate}
Eq. (\ref{eq:10}) due to assumptions 5, 6 simplifies to
\begin{eqnarray}
  \label{eq:11}
  \bm{s} =
  \frac{1} {\nph}
  \iint_A
  \left[ \begin{array}{c} x \\ y \end{array} \right]
  I(x,y) {\rm d}x{\rm d}y.
\end{eqnarray}
The covariance of the spot centroid readouts is given by
\begin{equation}
  \label{eq:12}
  \langle \bm{s} \bm{s}^{T} \rangle -
  \langle \bm{s} \rangle \langle \bm{s}^{T} \rangle
\end{equation}
$$
  = {1 \over \nph^2} \iint_A \iint_A
  \left[
  \begin{array}{cc} x_{1} x_{2} & x_{1} y_{2} \\
                    y_{1} x_{2} & y_{1} y_{2} \end{array}
  \right]
  ( \langle I(x_{1},y_{1}) I(x_{2},y_{2}) \rangle
  - \langle I(x_{1},y_{1}) \rangle
    \langle I(x_{2},y_{2}) \rangle )
    {\rm d}x_{1}{\rm d}y_{1} {\rm d}x_{2}{\rm d}y_{2}.
$$
Substututing Eq. (\ref{eq:whole-intensity}) and using assumptions 2, 3, and 7
we simplify this equation to
\begin{equation}
  \label{eq:13}
  \langle \bm{s} \bm{s}^{T} \rangle -
  \langle \bm{s} \rangle \langle \bm{s}^{T} \rangle
\end{equation}
$$
 = {1 \over \nph^2} \iint_A{}
   \left[
   \begin{array}{cc}
	   x^{2} & xy    \\
	   xy    & y^{2}
	 \end{array}
   \right]
   (\sigma_{I}^{2}(x,y)+\sigma_{B}^{2})
   {\rm d}x{\rm d}y,
$$
where
$$
  \sigma_{S}^{2}(x,y) =
  \langle I_{S}^{2}(x,y) \rangle - \langle I_{S}(x,y) \rangle^{2},
$$
is the variance distribution in the star intensity distribution,
$$
  \sigma_{B}^{2} = \langle I^{2}_{B}(x,y) \rangle = const.
$$
is the readout noise variance. Thus the sensor readout covariance has two
terms that can be treated independently.

\subsection{Photon noise}
\label{sec:photon-noise}

The photon noise follows a Poisson statistics distribution with variance
$\sigma_{S}^{2}(x,y) = I_{S}(x,y)$.
Thus the spot centroid readouts covariance in the case of
the photon noise is given by
\begin{equation}
  \label{eq:1}
  \langle \bm{s} \bm{s}^{T} \rangle_{S} -
  \langle \bm{s} \rangle_{S} \langle \bm{s}^{T} \rangle_{S}
\end{equation}
$$ = {1 \over \nph^2} \iint_{A}
   \left[
   \begin{array}{cc}
	   x^{2} & xy \\
	   xy    & y^{2}
	 \end{array}
   \right]
   I_{S}(x,y) \;{\rm d}x {\rm d}y,
$$
where $\nph$ is the number of photons per subaperture, $x$ and $y$ are the
coordinates in the focal plane,
the intensity $I_{S}(x,y)$ in the focal plane given by Eq. (\ref{eq:2}).

Substututing Eq.(\ref{eq:2}) into Eq.~(\ref{eq:1}) and performing the
integration leads to
\begin{equation}
  \label{eq:4}
  \langle \bm{s} \bm{s}^{T} \rangle_{S} -
  \langle \bm{s} \rangle_{S} \langle \bm{s}^{T} \rangle_{S}
\end{equation}
$$
  = {1 \over \nph}
  \left[
  \begin{array}{cc}
	  \sigma_{x}^{2} \cos^{2} \theta_{e} + \sigma_{y}^{2} \sin^{2} \theta_{e} &
	  (\sigma_{x}^{2}-\sigma_{y}^{2}) \cos \theta_{e} \sin \theta_{e} \\
	  (\sigma_{x}^{2}-\sigma_{y}^{2}) \cos \theta_{e} \sin \theta_{e} &
	  \sigma_{x}^{2} \sin^{2} \theta_{e} + \sigma_{y}^{2} \cos^{2} \theta_{e}
	\end{array}
  \right]
$$
$$
  =
  \left[
  \begin{array}{cc}
	  \sigma^{2}_{xx} & \sigma^{2}_{xy} \\
	  \sigma^{2}_{xy} & \sigma^{2}_{yy}
	\end{array}
  \right].
$$

From Eq.(\ref{eq:4}), it is obvious that covariance is null when the
spots are oriented either along the x or y axis or if the fwhms of both x and
y axis are the same.

\subsection{Read-out noise}
\label{sec:read-out-noise}

The read-out noise follows a zero-mean
Gaussian distribution of variance $\sigma^{2}_{B} = \sigma^2_e / p^{2}$,
where $\sigma^{2}_{e}$ is the number of read noise electrons squared per
pixel area $p^2$. Since $\sigma^{2}_{B} = const.$ and, with assumption that $A$
is a square lenslet, we have
$$
  \sigma^{2}_{B} \iint_{A} xy {\rm d}x{\rm d}y = 0,
$$
$$
  \iint_{A} x^{2} {\rm d}x{\rm d}y =
  \iint_{A} y^{2} {\rm d}x{\rm d}y.
$$
Thus the readout noise covariance matrix is diagonal:
\begin{equation} \label{eq:14}
	\langle \bm{s} \bm{s}^{T} \rangle_{B} =
	\left[{}
	\begin{array}{cc}
		\sigma^{2}_{ron} & 0 \\
		0 & \sigma^{2}_{ron} \\
	\end{array}
	\right].
\end{equation}
For a square lenslet of size $d=D/N_L$ we get
\begin{equation} \label{eq:15}
     \sigma_{ron}^2 = \left(\sigma_e \over p \nph \right)^2
     \int_{-d/2}^{d/2} \int_{-d/2}^{d/2} x^2 {\rm d}x{\rm d}y \\
                   = {1\over 12}\left(d^2\sigma_e \over p \nph \right)^2 =
                   {N_d^2\over 12}\left(D\sigma_e \over N_L \nph \right)^2,
\end{equation}
$N_d$ is the total number of pixels used for computing the centroids.

Finally, the sensor readout
noise covariance matrix for one lenslet is a sum of covariance matrices for
photon and readout noises:
\begin{equation}
  \label{eq:16}
  \langle \bm{s} \bm{s}^{T} \rangle_{S+B} -
  \langle \bm{s} \rangle_{S+B} \langle \bm{s}^{T} \rangle_{S+B} =
  \left[
    \begin{array}{cc}
      \sigma^2_{xx} + \sigma_{ron}^2 & \sigma_{xy} \\
      \sigma_{xy} & \sigma^2_{yy} + \sigma_{ron}^2
    \end{array}
  \right].
\end{equation}
For the whole lenslet array, the noise covariance matrix is a block diagonal
with these matrices on the diagonal.


\section{Calculation of a residual nucleus excitation energy.}

\hspace{1.0em}The excitation energy $U$ of the residual nucleus is
defined as the energy above the ground state energy (mass)
$M_{res}(A_{res},Z_{res})$ of residual nucleus with mass number
$A_{res}$ and charge $Z_{res}$.
For the precompound model we need to the number of excitons, which
consist from
$N_p$ is the number of "particles" and $N_{h}$ is the number of
"holes".  The located at $r$ particle and hole energies are
calculated from the Fermi
energy $T_F(r)$.
All cascade nucleons with kinetic energies above $T_{F}$ and less than
$T<T_F+B+V_C+E_{cut}$, where $B(A,Z)$ is binding energy, $V_C$ is
Coulomb energy for proton and $E_{cut}$ is cut energy (it is a model
parameter, $E_{cut}\approx 15$ MeV), are called "particles". The "holes"
are results of cascade interactions, when particles stroke nucleons from
nucleus and they occupy states below $T_{F}$.

Thus in hadron-nucleus and nucleus-nucleus collision cases the number
 of holes can be calculated for
 target nucleus and for projectile nucleus since we know which (projectile or
target) nucleon was stroked and
know the relative (from centrum of nucleus) position of a nucleon. In
this case we are able to calculate difference between scattered
nucleon (the mass of
this nucleon is a table mass) kinetic energy (defined in a nucleus rest
frame) and nucleon Fermi energy at given
relative (from centrum of a nucleus) position of this nucleon. If this
difference is less than the nucleon binding energy in a given nucleus plus
some cut energy, then the nucleon is considered as a particle
absorbed in a nucleus. Due to internuclear potentials other
particles can be also absorbed by a nucleus.

We know which particle leaves a nucleus. We can reduce the leaving
particle energy by the effective potential ("recoil" energy of nucleus after
left particle \cite{FRRS96}
  and rescale (taking into account "recoil" momentum of left particle)
   its momentum.
The nucleus excitation energy
can be calculated by summing of 4-momenta of
particles, which belong to a nucleus. Then excitation energy of
a nucleus can be calculated by adding a "recoil" energy and
subtracting of the ground state nucleus energy
(calculated using a liquid drop model)$M_{res}(A_{res},Z_{res}$
from the c.m. total energy $E_{res}(A_{res},Z_{res})$ of the
rest nucleus system:
\begin{equation}
\label{EEC1}U=E_{res}(A_{res},Z_{res})+ E_{recoil} -M_{res}(A_{res},Z_{res}).
\end{equation}


\documentclass{llncs}
\pagestyle{plain}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{comment}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{stmaryrd}
\usepackage{wasysym}
\usepackage{mathpartir}
\usepackage{rotating}
\usepackage{tcolorbox}
\newcommand{\interp}[1]{\llbracket #1 \rrbracket}
\newcommand{\maps}{\colon}
\renewcommand{\:}{\colon}
\newcommand{\FinSet}{\mathrm{FinSet}}
\newcommand{\Set}{\mathrm{Set}}
\newcommand{\Cat}{\mathrm{Cat}}
\newcommand{\Calc}{\mathrm{Calc}}
\newcommand{\Mon}{\mathrm{Mon}}
\newcommand{\BoolAlg}{\mathrm{BoolAlg}}
\renewcommand{\Form}{\mathrm{Form}}
\newcommand{\leftu}{\mathrm{left}}
\newcommand{\rightu}{\mathrm{right}}
\newcommand{\send}{\mathrm{send}}
\newcommand{\recv}{\mathrm{recv}}
\newcommand{\comm}{\mathrm{comm}}
\renewcommand{\quote}[1]{``#1"}
\newcommand{\deref}[1]{\mathrm{eval}(#1)}
\newcommand{\op}{\mathrm{op}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\pic}{$\pi$-calculus}
\newcommand{\rhoc}{$\rho$-calculus}
\newcommand{\lamc}{$\lambda$-calculus}
\newcommand{\bc}{\mathbin{\mathbf{::=}}}
\newcommand{\bm}{\mathbin{\mathbf\mid}}
\newcommand{\quotep}[1]{\mathsf{@}#1}
\newcommand{\red}{\rightarrow}
\newcommand{\scong}{\mathbin{\equiv}}
\newcommand{\pzero}{\mathbin{0}}

\makeatletter
\gdef\tshortstack{\@ifnextchar[\@tshortstack{\@tshortstack[c]}}
\gdef\@tshortstack[#1]{%
  \leavevmode
  \vtop\bgroup
    \baselineskip-\p@\lineskip 3\p@
    \let\mb@l\hss\let\mb@r\hss
    \expandafter\let\csname mb@#1\endcsname\relax
    \let\\\@stackcr
    \@ishortstack}
\makeatother

\title{Logic, resource, and reflection}
\author{
L.G. Meredith\inst{1}\\
\and
Michael Stay\inst{2}\\
\and
Christian Williams\inst{3}
}
\institute{
  {RChain Cooperative}\\
  \email{\fontsize{8}{8}\selectfont lgreg.meredith@rchain.coop}
  \and
  {Pyrofex Corp.}\\
  \email{\fontsize{8}{8}\selectfont stay@pyrofex.net}
  \and
  {University of California, Riverside}\\
  \email{\fontsize{8}{8}\selectfont cwill041@ucr.edu}
}
\begin{document}
\maketitle
\begin{abstract}
\noindent
  We present an algorithm for deriving a spatial-behavioral type
  system and term assignment algorithm from a formal presentation of a
  interactive computational calculus. This turns out to identify a
  species of category which we offer an axiomatic characterization of
  interaction categories.
\end{abstract}

%% TODO List:
%% Type introduction rules for collection types (LGM)
%% Equational scheme for @ in the classical setting (LGM)
%% Categorical semantics (MS)
%% Soundness and completeness results (MS)
%% Cut elimination theorem (LGM)
%% Examples (LGM & MS)
%%   formulae that are true for all K's -- this justifies working at this level of generality
%%     execution-based isolation
%%     security-based isolation
%%   formulae that are true for specific K's (LGM & MS)

\section{Introduction and motivation}

In groundbreaking work, Abramsky, Gay, and Nagarajan put forward the
idea of interaction categories to give a categorical framework for
interactive models of computing.\cite{DBLP:conf/nato/AbramskyGN96}
Indeed, interactive models of computation are relatively new and offer
distinct insights because they include the computational environment
as part of the computational model. Examples include the {\pic}, in
fact, all the mobile process calculi, as well as the
{\lamc}. \cite{milner91polyadicpi}\cite{Barendregt84} However,
interaction categories take inspiration from linear logic rather than
to say axiomatically what interaction is.

We put forward a simple, intuitive axiomatic characterization of
interaction and use this to derive not only a logic but a proof theory
and term assignment algorithm for all systems satisfying these
axioms. The resulting structure identifies a species of category and
we offer this as an axiomatic characterization of interaction
categories.

\subsection{Intuitions}

The key idea in this construction is to use both the evaluation
context of Meredith and Stay \cite{DBLP:journals/corr/StayM15}, and
computational reflection, similar to what is found in Meredith and
Radestock \cite{DBLP:journals/entcs/MeredithR05}, to build a proof
theory for an interactive rewrite system. The proof theory enjoys a
cut elimination property that corresponds exactly with the notion of
computation embodied in the interactive rewrite system.

The requirement that the rewrite system is interactive means the left
hand side of every rewrite rule will necessarily be a term built from
a term constructor, say $\mathsf{K}$, taking at least two terms as
arguments. That is, when viewed as a piece of syntax it is at least a
tuple of terms. This bipartite split is what characterizes
interaction. One of the arguments is the program and one is the
environment. For example, in {\lamc} application functions
in the role of $\mathsf{K}$, and the term in function position is
usually considered the program, while the term in argument position
constitutes an environment. In the {\pic} parallel composition
functions in the role of $\mathsf{K}$ while either parand can be
considered program and the other environment.

Given an interactive rewrite system, we can introduce an evaluation
context to control evaluation and force a distinction between a frozen
or reified computation (referred to as a tensor) and an active
computation (referred to as a cut). Specifically, a cut forms the
redex with an evaluation context supplied, and the tensor is denied
the evaluation context, effectively rendering it a data structure. Of
course, the data is inaccessible until there is a means to unpack
it. We introduce a new term to the system (referred to as a par term)
as the principal means to extract the data from a tensor. In fact, we
introduce two different kinds of par terms, one for wiring evaluation
in parallel and one in series. More on this in subsequent sections.

The use of the term constructor that forms a redex as a data structure
is the essential use of reflection. The lack of a reduction context
gives us the ability to suspend computation. Having suspended it, we
reify computation as data, and use par to unpack the data making up
the computation. Completing the circle, we introduce a means for
having tensors and pars interact with each other (referred to as the tensor-par cut
rule) which constitutes the means to reflect computational data back into
actual computations.

It turns out that denying the evaluation context is not the only way
to suspend computation. We can also form contexts. In this case, we
only admit 1-holed contexts, ranged over by $\chi$. With contexts we can
define a notion of rely-guarantee, two notions actually (indicated by
the operations $(- \rhd -)$ and $(- \lhd -)$), as a redex term constructor
might not be commutative.

\begin{eqnarray*}
\tau \rhd_{\mathsf{K}} \tau' & \triangleq & \{ u \; | \; \exists t. u = \mathsf{!}\mathsf{K}^{r}(t, \boxempty),\forall u' : \tau. (\exists \rho : u@u' \rightarrow v) \Rightarrow v:\tau' \} \\
\tau' \lhd_{\mathsf{K}} \tau & \triangleq & \{ t \; | \; \exists u. t = \mathsf{K}^{l}(\boxempty, u)\mathsf{!},\forall t' : \tau. (\exists \rho: t@t' \rightarrow v) \Rightarrow v : \tau' \}
\end{eqnarray*}

In the sequel we drop the subscript on the triangles if it's understood from
context. We use the notation $\chi @ t$ to mean the term formed by
substituting $t$ for hole in $\chi$. Thus, $\mathsf{K}(t, \boxempty)@u = \mathsf{K}(t, \boxempty)[u/\boxempty] = \mathsf{K}(t,u)$ and similarly, $\mathsf{K}(\boxempty, u)@t = \mathsf{K}(\boxempty, u)[t/\boxempty] = \mathsf{K}(t,u)$

To give some examples, the comm rule of {\rhoc} is given by

\begin{equation*}
  \mathsf{for}( y \leftarrow x )P \quad | \quad x\mathsf{!}(Q) \rightarrow P\{ @Q/y \}
\end{equation*}

In this case $\mathsf{K}$ is parallel composition, and the revised, resource
constrained comm rule, looks like

\begin{equation*}
  \mathsf{R} | \mathsf{for}( y \leftarrow x )P \quad | \quad x\mathsf{!}(Q) \rightarrow P\{ @Q/y \}
\end{equation*}

In the lambda calculus, $\beta$-reduction is given by

\begin{equation*}
  (\lambda x.M)N \rightarrow M\{ N/x \}
\end{equation*}

$\mathsf{K}$ is application, and the revised, resource constrained $\beta$-reduction is given by

\begin{equation*}
  \mathsf{R}((\lambda x.M)N) \rightarrow M\{ N/x \}
\end{equation*}

In what follows we will focus on calculi that don't employ binding
operators and so-called nominal phenomena. This is not to say that we
can't handle nominal phenomena, just that the content is already
complex enough and we want to focus on the core ideas.

\subsubsection{Rewrites, reductions, and composition of theories}
The proof theory we develop is only sound for the free models. If the
model comes equipped with a ``edge'' of its own, this may result in
reductions invisible to the rely-guarantee construction. Likewise, we
require theories that have no ``second-order'' contentions in the
rewrites. That is, the left-hand side of each rule must be
unique. Notice that this does not say that the theory is free of
races.

This restriction has implications for composition of theories. So, for
example, imagine that we are composing two copies of the
$\rho$-combinator theory, say a red one and a black one, but that we
wish to identify the message combinator of both, call it yellow. Then
the red duplicator par yellow message rule is distinct from the black
duplicator par yellow message rule, and as such this composition of
theories satisfies the restriction.

\subsection{Related work}
In many ways this work is inspired by and derives from domain theory
in logical form (DTLF).\cite{DBLP:journals/apal/Abramsky91} In much
the same way that DTLF takes as input a notion of computation encoded
in a domain theory and produces a logical system encoding the same
notion of computation, but from the logical view, this is an algorithm
that takes as input a notion of computation encoded as a Lawvere
theory (\cite{DBLP:journals/entcs/HylandP07}) and produces a new
Lawvere theory that is resource constrained and enjoys a type system
that guarantees a range of security and liveness properties, while at
the same time having the tightest possible conformance to the original
notion of computation. In particular, the resulting type theory is
also a logic enjoying a notion of cut-elimination and proof
normalization that matches exactly with the operational semantics of
the original theory. As such, it automatically enjoys a Curry-Howard
correspondence.

Other inspiration and guidance come from the two major branches in the
development of behavioral types. One branch derives from the spatial
logics of Caires \cite{DBLP:conf/fossacs/Caires04}, et al, while the
other derives from the session types of Wadler, et
al. \cite{DBLP:journals/jfp/Wadler14} The former is predominantly
model theory based, while the latter is predominantly proof theory
based. In the spatial logics branch the negation is largely set-based,
while in the session types work the negation is related to the
reduction of terms. This construction brings both branches together
and offers both model theory and proof theory that enjoys a full
abstraction-like property.

The discussion would not be complete without mentioning
blockchain. While the idea of resource limiting computation certainly
has a long and illustrious history, inspired by catalysts in chemical
and biochemical reactions, it has immediate practical application in
blockchain platforms such as RChain and Ethereum. Here, the
programming model is throttled by the existence of a resource. The
cost of obtaining that resource constitutes a prophylactic against
denial-of-service attacks. Specifically, an attacker attempting to
deploy computations that run forever or take up infinite storage must
pay for the corresponding infinite resources necessary to enable the
infinite computations.

\subsection{Notation}
We use

\begin{itemize}
  \item $\Gamma , \Delta , \Xi$  to range over type contexts;
  \item $\rhd , \lhd$ for left and right residuation;
  \item $(-)_{\perp}$ and $ _{\perp}(-)$  for left and right negations;
  \item $!(-)$ and $(-)!$  for left and right abstractions;
  \item $\rho$ to range over rewrite rules;
  \item $\chi$ to range over contexts;
  \item $\bindnasrepma, \otimes, \sqcap, \sqcup$ for logical connectives derived from $\mathsf{K}$; $\sqcap$ serial, $\otimes$ parallel
  \item both double and single sided $\vdash$ for typing judgments;
  \item $\Rightarrow$ for meta level logical implication.
\end{itemize}

\section{Construction}
To illustrate the general construction we apply it to the simplest
possible interactive rewrite theory, consisting of a single sort, $T$,
for term, a single constant, $\mathsf{c}$, and a single term constructor $\mathsf{K}$, along
with left and right identities for $\mathsf{K}$ (which are, of course,
constants). It has a single rewrite rule, $\rho$.

We add a resource, $\mathsf{R}$, which can be thought of as either an evaluation
context, or as a constant. In the resourced theory, the rewrite rule
only applies in an evaluation context.

Then we add a notion of 1-holed context. We add a new sort, $X$, then a
constant for the hole, together with left and right maps for placing
the hole in either side of $\mathsf{K}$, along with left and right maps $!(-)$ and
$(-)!$ essentially for treating contexts as abstractions. We add a map
$@(-,-)$ for substituting a term into a context marked as an
abstraction.

It is important to note that we do not allow the rewrite rule to
operate on contexts. Thus, there are two ways to suspend computation:
withholding a resource, or forming an abstraction.  Input to the
algorithm It is to be understood that the initial theory is provided
as input to the system. As mentioned earlier, this is an algorithm
that takes as input a notion of computation encoded as a Lawvere
theory and produces a new Lawvere theory that is resource constrained
and enjoys a type system that guarantees a range of security and
liveness properties.

\subsection{Input to the algorithm}
For this algorithm to work we must encode a model of computation as an
\emph{input to the algorithm}. To this end we keep in mind that
structured operational semantics (aka SOS) format has been the tool of
choice for the theoretical computer science community for several
decades. Further, Milner's elaboration of this format is pivotal as it
aligns theoretical computer science with classical mathematics. To
wit, in Milner's format an operational semantics consists of three
data:

\begin{itemize}
  \item grammar for an abstract syntax
  \item a structural equivalence
  \item a set of rewrite rules
\end{itemize}

This presentation format corresponds to an elaboration of modern
presentations of algebraic theories in terms of \emph{generators} and
\emph{relations}. Specifically, the grammar for the abstract syntax
corresponds to the generator, and the structural equivalence
corresponds to the relations. What is new and different about
computational models and makes them distinct from classical
presentations of algebraic theories is the existence of the rewrite
rules. While the relations may be seen as bi-directional rewrite
rules, the rules describing the operational semantics, or how terms in
the grammar evolve and thus realize a computation, are uni-directional
and typically represent some aspect of computation that has
thermodynamic consequences (such as forgetting state).

This format is extremely rich and describes a wide range of theories
that we hope to cover with the LADL algorithm. However, we begin with
a more modest presentation of models of computational theories that
can be mapped to the Milner format for SOS.

Specifically, we encode term calculi as second order algebraic
theories. This allows us to express syntax that includes binding
operators, such as is found in {\lamc} or {\pic} or {\rhoc} and get
notions of $\alpha$-equivalence and capture-avoiding substitution all
``for free.'' To build a theory that also includes rewrite rules, we
begin with a theory of reflexive directed multigraphs:

\begin{itemize}
  \item one sort $T$
  \item function symbols $\mathsf{s}, \mathsf{t}: T \rightarrow T$
  \item equations $\mathsf{ss} = \mathsf{ts} = \mathsf{s}$, $\mathsf{st} = \mathsf{tt} = \mathsf{t}$
\end{itemize}

To this theory, we add function symbols for each term constructor and
reduction rule.  We also add equations for the source and target of
each reduction rule.  For example, we can model the $\mathsf{SKI}$ combinator
calculus by adding

\begin{itemize}
  \item $S, K, I : 1 \rightarrow T$
  \item $(- -) : T^{2} \rightarrow T$
  \item $\sigma : T^{3} \rightarrow T$
  \item $\kappa : T^{2} \rightarrow T$
  \item $\iota : T \rightarrow T$
  \item $\mathsf{s}\sigma(x, y, z) = (((S x) y) z$
  \item $\mathsf{t}\sigma(x, y, z) = ((x z) (y z))$
  \item $\mathsf{s}\kappa(x, y) = ((K x) y)$
  \item $\mathsf{t}\kappa(x, y) = x$
  \item $\mathsf{s}\iota(x) = (I x)$
  \item $\mathsf{t}\iota(x) = x$
\end{itemize}

We'll use the following symbols to talk about a generic term calculus
with at least one binary term constructor and one rewrite rule that
uses the term constructor as its source.

\begin{itemize}
  \item $\mathsf{c}, \mathsf{l}_{\mathsf{K}}, \mathsf{r}_{\mathsf{K}} : 1 \rightarrow T$
  \item $\mathsf{K} : T^{2} \rightarrow T$
  \item $\rho : T^{2} \rightarrow T$             %%//( \x -> M N) → M{N/x}     for( y <- x )P | x!(Q) → P{@Q/y}$
  \item $\mathsf{K}(l_{\mathsf{K}}, u) = u$
  \item $\mathsf{K}(t, \mathsf{r}_{\mathsf{K}}) = t$
  \item $ t : [?], u : [?]\Vdash \cdot \vdash \mathsf{s}(\rho(t,u)) = \mathsf{K}(t, u)$
  \item $t : [?], u : [?]\Vdash \cdot \vdash \mathsf{t}(\rho(t,u)) = f(t,u)$
\end{itemize}

Note that $\mathsf{K}$ may not be commutative, so we ask for either a left
identity, $\mathsf{l}_{\mathsf{K}}$, or a right identity, $\mathsf{r}_{\mathsf{K}}$, or if we have both they must
coincide.

We proceed in stages, producing first a resourced version of the
theory that requires an evaluation context to run the rewrite rule,
then producing a contextualized version of the theory.

\subsubsection{Resourced theory}

%% TODO comment on fhat

\begin{itemize}
  \item $\mathsf{c}, \mathsf{l}_{\mathsf{K}}, \mathsf{r}_{\mathsf{K}} : 1 \rightarrow T$
  \item $\mathsf{K} : T^{2} \rightarrow T$
  \item $\mathsf{R} : T \rightarrow T$
  \item $\bindnasrepma_{\rho} : T^{2} \rightarrow T$
  \item $\sqcup_{\rho} : T^{2} \rightarrow T$
  \item $\rho : T^{2} \rightarrow T$             %%//( \x \rightarrow M N) → M{N/x}     for( y <- x )P | x!(Q) → P{@Q/y}
  \item $\mathsf{K}(\mathsf{l}_{\mathsf{K}}, u) = u$
  \item $\mathsf{K}(t, \mathsf{r}_{\mathsf{K}}) = t$
  \item $\mathsf{s}(\rho(t,u)) = \mathsf{R}\mathsf{K}(t, u)$
  \item $\mathsf{t}(\rho(t,u)) = \hat{f}(t,u)$                    %%// deleting Rs from fhat gives f
\end{itemize}

\subsubsection{Contextualized Resourced theory}
%We add a new sort, $X$, and the following maps
We transition to a contextualized version of the resourced theory by
assuming that $T$ is exponentiable and availing ourselves of the
mechanics of second order algebraic theories. This gives us access to
variables, meta-variables, and a capture-avoiding substitution.

%% TODO a version of @ where we can apply a term to a context and get a context
%% Check equations involving @_box

\begin{itemize}
  \item $\mathsf{c}, \mathsf{l}_{\mathsf{K}}, \mathsf{r}_{\mathsf{K}} : 1 \rightarrow T$
  \item $\mathsf{K} : T^{2} \rightarrow T$
%  \item $\boxempty : \NN \rightarrow X$
%  \item $\mathsf{K}_{\boxempty}^{l} : X \times T \rightarrow X$
%  \item $\mathsf{K}_{\boxempty}^{r} : T \times X \rightarrow X$
  \item $!(-) : T^{T}  \rightarrow T$
  \item $(-)! : T^{T}  \rightarrow T$
  \item $@ : T^{2} \rightarrow T$
  \item $@_{\boxempty}^{l} : T^{T} \times T \rightarrow T$
  \item $@_{\boxempty}^{r} : T \times T^{T} \rightarrow T^{T}$
  \item $@_{\boxempty\boxempty} : (T^{T})^{2} \rightarrow T^{T}$
  \item $\mathsf{R} : T \rightarrow T$
  \item $\bindnasrepma_{\rho} : T^{2} \rightarrow T$
  \item $\sqcup_{\rho} : T^{2} \rightarrow T$
  \item $\rho : T^{2} \rightarrow T$             %%//( \x -> M N) -> M{N/x}     for( y <- x )P | x!(Q) -> P{@Q/y}
  \item $\mathsf{s}(\rho(t,u)) = \mathsf{R}\mathsf{K}(t, u)$
  \item $\mathsf{t}(\rho(t,u)) = \hat{f}(t,u)$          %%// deleting Rs from fhat gives f
  %% \item $\hat{\rho}_{l} : T \times T^{T} \rightarrow T$             %%//( \x -> M N) -> M{N/x}     for( y <- x )P | x!(Q) -> P{@Q/y}
  %% \item $\hat{\rho}_{r} : T^{T} \times T \rightarrow T$             %%//( \x -> M N) -> M{N/x}     for( y <- x )P | x!(Q) -> P{@Q/y}
  \item $\mathsf{K}(\mathsf{l}_{\mathsf{K}}, u) = u$
  \item $\mathsf{K}(t, \mathsf{r}_{\mathsf{K}}) = t$
  %% \item $@(\boxempty !,t) = t$
  %% \item $@(!\boxempty,t) = t$
  %% \item $@_{\boxempty}^{l}(\boxempty ,t) = t$
  %% \item $@_{\boxempty\boxempty}(\boxempty,\chi) = \chi$
  %% \item $@(\mathsf{K}_{\boxempty}^{l} (\chi, t)!, u) = \mathsf{K}(@_{\boxempty}(\chi, u), t)$
  %% \item $@(!\mathsf{K}_{\boxempty}^{r} (t, \chi), u) = \mathsf{K}(t, @_{\boxempty}(\chi, u))$
  %% \item $@(\mathsf{K}_{\boxempty}^{l} (\chi, t)!, \chi')! = \mathsf{K}(@_{\boxempty\boxempty}(\chi, \chi'), t)$
\end{itemize}

As mentioned before, the basic notion of arrow is given by

\begin{eqnarray*}
  \tau \rhd_{\mathsf{K}} \tau' & \triangleq  & \{ u \; | \; \exists t. u = !\mathsf{K}^{r}(t, \boxempty),\forall u':\tau. (\exists \rho : u@u'\rightarrow v) \Rightarrow v:\tau' \} \\
  \tau'\lhd_{\mathsf{K}} \tau & \triangleq  & \{ t \; | \; \exists u. t = \mathsf{K}^{l}(\boxempty, u)!,\forall t':\tau. (\exists \rho : t@t'\rightarrow v) \Rightarrow v:\tau'\}
\end{eqnarray*}

However, they can be generalized to

\begin{eqnarray*}
  \tau \rhd_{\mathsf{K}} \tau' & \triangleq  & \{ u \; | \; \exists t, \chi. u = !\mathsf{K}^{r}(t, \chi),\forall u':\tau. (\exists \rho : u@u'\rightarrow v) \Rightarrow v:\tau' \} \\
  \tau'\lhd_{\mathsf{K}} \tau & \triangleq  & \{ t \; | \; \exists u, \chi. t = \mathsf{K}^{l}(\chi, u)!,\forall t':\tau. (\exists \rho : t@t'\rightarrow v) \Rightarrow v:\tau'\}
\end{eqnarray*}

which allows the hole to be buried, rather than at the top level,

\subsection{Types}
\begin{mathpar}
  \inferrule* [lab=type] {} { \tau \bc  \top  | \tau \rhd \tau | \tau \lhd \tau | \mathsf{C} | \{\} | \tau \cup \tau | \mathsf{R}\tau | \mathsf{K}(\tau,\tau) | \rho_{\otimes}(\tau,\tau) | \rho_{\bindnasrepma}(\tau,\tau) | \rho_{\sqcap}(\tau,\tau) | \rho_{\sqcup}(\tau,\tau) }
\end{mathpar}

\subsubsection{Abbreviations}
\begin{eqnarray*}
  \tau^{\perp} & = & \tau \rhd \mathsf{r}_{\mathsf{K}} \\
  \tau^{\circ} & = & \tau \rhd \{\} \\
  ^{\perp}\tau & = & \mathsf{l}_{\mathsf{K}} \lhd \tau \\
  ^{\circ}\tau & = & \{\} \lhd \tau
\end{eqnarray*}

\section{Intuitionistic Term assignment}

\begin{table}[htp]
  \center{
    \fbox{
      \begin{tabular}{c|c|c}
        & structure & destructure \\
        \hline
        parallel & tensor ($\otimes$) & par ($\bindnasrepma$) \\
        \hline
        serial & serialize ($\sqcap$) & deserialize ($\sqcup$) \\
      \end{tabular}
    }
  }
  \caption{Wiring operations}
\end{table}

\subsection{Terms, their types and cuts}
\begin{mathpar}
  \inferrule* [lab=constants] {} { \Vdash  \vdash \mathsf{c} : \mathsf{C}} \\

  \inferrule* [lab=$\rho_{\otimes}$]{ \Vdash \Gamma \vdash t : \tau  \quad  \Vdash \Delta \vdash u : \tau'}{ \Vdash \Gamma, \Delta \vdash \mathsf{K}(t, u) : \rho_{\otimes}(\tau, \tau')}

  \inferrule* [lab=$\rho_{\bindnasrepma}$]{ \Vdash \Gamma \vdash t : \tau, u : \tau'}{ \Vdash  \Gamma \vdash \bindnasrepma_{\rho} (t, u) : \rho_{\bindnasrepma}(\tau, \tau')} \\

\inferrule* [lab=$\rho_{\sqcap}$]{ \Vdash \Gamma \vdash t : \tau, u : \tau'}{ \Vdash \Gamma \vdash \mathsf{K}(t,u) : \rho_{\sqcap}(\tau,\tau')}

\inferrule* [lab=$\rho_{\sqcup}$]{ \Vdash \Gamma \vdash t : \tau, u : \tau'}{ \Vdash \Gamma \vdash \sqcup_{\rho}(t,u) : \rho_{\sqcup}(\tau,\tau')} \\

\inferrule* [lab=$\rho_{\bindnasrepma \perp \otimes}$]{ \Vdash \Gamma \vdash \bindnasrepma_{\rho} (t_{1}, t_{2}) : \rho_{\bindnasrepma}(\tau_{1} \rhd \tau_{i}^{\perp}, \tau_{2} \rhd \tau_{i}) \quad  \Vdash \Delta \vdash \mathsf{K}(t_{3}, t_{4}) : \rho_{\otimes}(\tau_{1}, \tau_{2}) }{ \Vdash \Gamma, \Delta \vdash \mathsf{R}(\mathsf{K}(\mathsf{R}(\mathsf{K}(t_{1}, t_{3})), \mathsf{R}(\mathsf{K}(t_{2}, t_{4})))) : \mathsf{r}_{\mathsf{K}}}

%% \tau \rhd \tau' = { u | \exists t,\chi. u = !\mathsf{K}_{\boxempty}^{r}(t, \chi),\forall u':\tau. (\exists \rho: u@u' \rightarrow v) \Rightarrow v:\tau' }
%% \tau\perp = \tau \rhd \mathsf{r}_{\mathsf{K}} = { u | \exists t,\chi. u = !\mathsf{K}_{\boxvoid}^{r}(t, \chi),\forall u':\tau. (\exists \rho: u@u' \rightarrow v) \Rightarrow v:\mathsf{r}_{\mathsf{K}} }

\inferrule* [lab=$\rho_{\perp}$]{ \Vdash \Gamma \vdash t' : \tau^{\perp}\quad  \Vdash \Delta \vdash t : \tau }{ \Vdash \Gamma, \Delta \vdash \mathsf{R}(\mathsf{K}(t',t)) : \mathsf{r}_{\mathsf{K}}}

\end{mathpar}
\subsection{Contexts, their types and cuts}
Below we identify the formation of each kind of context: tensor-parallel, tensor-serial, par-parallel, and par-serial.

\subsubsection{Axiom}

\begin{mathpar}
  \inferrule* [lab=axiom] {} { \Vdash x : \tau \vdash x : \tau} \\
  \inferrule* [lab=${\rightarrow}^{l}$]{\Vdash \Gamma, x : \tau \vdash \mathsf{t}( \rho( t, \boxempty ) ) : \tau' }{\Vdash \Gamma \vdash !\mathsf{K}( t, x ) : \tau \rhd \tau'} \\
  \inferrule* [lab=${\rightarrow}^{r}$]{\Vdash \Gamma, x : \tau \vdash \mathsf{t}( \rho( \boxempty, u ) ) : \tau' }{\Vdash \Gamma \vdash \mathsf{K}( x, u )! : \tau \lhd \tau'}
\end{mathpar}

\subsubsection{Weakening}

\begin{mathpar}
  \inferrule* [lab=weakening] {\Vdash \Gamma \vdash \chi : \tau}{\Vdash x : \tau', \Gamma \vdash \chi : \tau}
\end{mathpar}

\subsubsection{Left and right context formation and cut}

\begin{mathpar}
  \inferrule* [lab=$\lhd$] {\Vdash \Gamma, x : \tau  \vdash \chi : \tau'} {\Vdash \Gamma \vdash \chi ! : \tau' \lhd \tau}

  \inferrule* [lab=$\rhd$] {\Vdash \Gamma, x : \tau  \vdash \chi : \tau'} {\Vdash \Gamma \vdash !\chi : \tau \rhd \tau'} \\

  \inferrule* [lab=$\rho_{\boxempty \perp \lhd}$] {\Vdash \Gamma \vdash \mathsf{K}(x,u)! : \tau' \lhd \tau \quad  \Vdash \Delta \vdash t : \tau}{\Vdash \Gamma, \Delta \vdash \mathsf{R}(\mathsf{K}(t,u)) : \tau'}

  \inferrule* [lab=$\rho_{\boxempty \perp \rhd}$] {\Vdash \Gamma \vdash !\mathsf{K}(t,x) : \tau \rhd \tau'\quad  \Vdash \Delta \vdash u : \tau} {\Vdash \Gamma, \Delta \vdash \mathsf{R}(\mathsf{K}(t,u)) : \tau'}\\
  \inferrule* [lab=$\rho_{\sqcup \perp \sqcap}$]{\Vdash \Gamma \vdash \sqcup_{\rho} (t_{1}, t_{2}) : \rho_{\sqcup}(\tau_{2} \rhd \tau_{1}^{\perp}, \tau_{2})  \quad \Vdash \Delta \vdash \mathsf{K}(t_{3}, t_{4}) : \rho_{\sqcap}(\tau_{3} \rhd \tau_{1}, \tau_{3})}{\Vdash \Gamma, \Delta \vdash \mathsf{R}(\mathsf{K}(\mathsf{R}(\mathsf{K}(t_{1}, t_{2})), \mathsf{R}(\mathsf{K}(t_{3}, t_{4})))) : \mathsf{r}_{\mathsf{K}}}
\end{mathpar}

%%               --------------- axiom
%%               |- 0 : hat( 0 )
%%    ------------------------------------- weakening
%%    [] : hat( m )( x, T ) |- 0 : hat( 0 )
%% -------------------------------------------------- rho->l    ------------------------------- axiom
%% |- !K( k( x ), [] ) : hat( m )( x, T ) |> hat( 0 )           |- m( x, a ) : hat( m )( x, T )
%% --------------------------------------------------------------------------------------------
%%                       |- R( K( k( x ), m( x, a ) ) ) : hat( 0 )

\subsection{Classical Term assignment}
In the classical setting we transform double-sided sequents

\begin{mathpar}
  \inferrule* [lab=axiom] {} {\boxempty : \tau \vdash \boxempty : \tau}
\end{mathpar}

to single sided sequents

\begin{mathpar}
  \inferrule* [lab=axiom] {} { \vdash \blacksquare : \tau^{\perp}, \boxempty : \tau}
\end{mathpar}

And the interpretation of “,” is tensor, which is just the $\mathsf{K}$ constructor.

$\mathsf{K}( \boxempty : \tau^{\perp}, \boxempty : \tau )$

Expanding this out and instantiating $\mathsf{K}$ to application, we would get

$\mathsf{App}( \boxempty : \tau \rhd \mathsf{l}_{\mathsf{K}}, \boxempty : \tau )$

This yields exactly the property we are demanding.

More formally, we adapt the Lawvere theory as follows.

We add new sorts, $X^{\circ}$, and $X^{\bullet}$, $X^{\circ\bullet}$, and the following maps

\begin{itemize}
  \item $\mathsf{c}, \mathsf{l}_{\mathsf{K}}, \mathsf{r}_{\mathsf{K}} : 1 \rightarrow T$
  \item $\mathsf{K} : T^{2} \rightarrow T$
  \item $\mathsf{K}_{A} : 1 \rightarrow X^{\circ\bullet}$
  \item $\mathsf{K}_{\boxempty\blacksquare} : X^{\circ} \times X^{\bullet} \rightarrow X^{\circ\bullet}$
  \item $\mathsf{K}_{\boxempty}^{l} : T \times X^{\circ\bullet} \rightarrow X^{\circ\bullet}$
  \item $\mathsf{K}_{\boxempty}^{r} :  X^{\circ\bullet} \times T \rightarrow X^{\circ\bullet}$
  \item $?(-) : X^{\circ\bullet}  \rightarrow X^{\circ}$
  \item $(-)? : X^{\circ\bullet}  \rightarrow X^{\bullet}$
  \item $!(-) : X^{\circ}  \rightarrow T$
  \item $(-)! : X^{\bullet}  \rightarrow T$
  \item $@ : T^{2} \rightarrow T$
  \item $@_{\boxempty}^{l} : X^{\circ} \times T \rightarrow T$
  \item $@_{\blacksquare}^{l} : X^{\bullet} \times T \rightarrow T$
  \item $@_{\boxempty}^{r} : T \times X^{\circ} \rightarrow X^{\circ}$
  \item $@_{\blacksquare}^{r} : T \times X^{\bullet} \rightarrow X^{\bullet}$
  \item $@_{\boxempty\boxempty} : (X^{\circ})^{2} \rightarrow X^{\circ}$
  \item $@_{\blacksquare\blacksquare} : (X^{\bullet})^{2} \rightarrow X^{\bullet}$
  \item $\mathsf{R} : T \rightarrow T$
  \item $\bindnasrepma_{\rho} : T^{2} \rightarrow T$
  \item $\sqcup_{\rho} : T^{2} \rightarrow T$
  \item $\rho : T^{2} \rightarrow T$             %%//( \x -> M N) -> M{N/x}     for( y <- x )P | x!(Q) -> P{@Q/y}
  \item $\mathsf{s}(\rho(t,u)) = \mathsf{R}\mathsf{K}(t, u) $
  \item $\mathsf{t}(\rho(t,u)) = f(t,u)$                      %%// f can mention R, e.g. if R is not a linear resource
  \item $\mathsf{K}(\mathsf{l}_{\mathsf{K}}, u) = u$
  \item $\mathsf{K}(t, \mathsf{r}_{\mathsf{K}}) = t$
  \item $@(\boxempty!,t) = t$
  \item $@(!\boxempty,t) = t$
  \item $@(\blacksquare ?,t) = t$
  \item $@(?\blacksquare,t) = t$
  % need to add polarities to these equations
  \item $@(\mathsf{K}_{\boxempty}^{l} (\chi, t)!, u) = \mathsf{K}(@(\chi, u), t)$
  \item $@(!\mathsf{K}_{\boxempty}^{r} (t, \chi), u) = \mathsf{K}(t, @(\chi, u))$
\end{itemize}

\begin{eqnarray*}
  \tau \RHD_{\mathsf{K}} \tau' & \triangleq  & \{ u \; |\; \exists t, \chi. u = ?\mathsf{K}^{r}(t, \chi),\forall u':\tau. (\exists \rho : u@u'\rightarrow v) \Rightarrow v:\tau' \} \\
  \tau'\LHD_{\mathsf{K}} \tau & \triangleq  & \{ t \; |\; \exists u, \chi. t = \mathsf{K}^{l}(\chi, u)?,\forall t':\tau. (\exists \rho : t@t'\rightarrow v) \Rightarrow v:\tau'\}
\end{eqnarray*}

In the sequel we will use the notation $\Gamma^{\circ}$ (respectively,
$\Delta^{\circ}$) to mean that the type context $\Gamma$ contains
exactly one term containing $\boxempty$ and no terms containing
$\blacksquare$. Dually, we will use the notation $\Gamma^{\bullet}$
(respectively, $\Delta^{\bullet}$) to mean that the type context
$\Gamma$ contains exactly one term containing $\blacksquare$ and no
terms containing $\boxempty$.

\subsection{Types}
We introduce additional arrow types to mirror the introduction of $?$.

\begin{mathpar}
  \inferrule* [lab=type] {} { \tau \bc  \top  | \tau \rhd \tau | \tau \lhd \tau | \tau \RHD \tau | \tau \LHD \tau | \mathsf{C} | \{\} | \tau \cup \tau | \mathsf{R}\tau | \mathsf{K}(\tau,\tau) | \rho_{\otimes}(\tau,\tau) | \rho_{\bindnasrepma}(\tau,\tau) | \rho_{\sqcap}(\tau,\tau) | \rho_{\sqcup}(\tau,\tau) }
\end{mathpar}

\subsection{Terms, their types and cuts}

\begin{mathpar}
  \inferrule* [lab=constant] {} {\vdash \mathsf{c} : \mathsf{C}}

  \inferrule* [lab=$\rho_{\otimes}$] {\vdash \Gamma, t : \tau   \vdash u : \tau', \Delta} {\vdash \Gamma, \mathsf{K}(t, u) : \rho_{\otimes}(\tau, \tau'), \Delta}

  \inferrule* [lab=$\rho_{\bindnasrepma}$] {\vdash \Gamma, t : \tau, u : \tau'} {\vdash \Gamma, \bindnasrepma_{\rho}(t, u) : \rho_{\bindnasrepma}(\tau, \tau')}

  \inferrule* [lab=$\rho_{\bindnasrepma\perp\otimes}$] {\vdash \Gamma, \bindnasrepma_{\rho} (t', u') : \rho_{\bindnasrepma}(\tau^{\perp}, \tau'^{\perp})  \vdash \mathsf{K}(t, u) : \rho_{\otimes}(\tau, \tau'), \Delta}{\vdash \Gamma, \mathsf{R}(\mathsf{K}(\mathsf{R}(\mathsf{K}(t', t)), \mathsf{R}(\mathsf{K}(u', u)))) : \mathsf{r}_{\mathsf{K}}, \Delta}

  \inferrule* [lab=$\rho_{\sqcap}$] {\vdash \Gamma, t : \tau, u : \tau'}{\vdash \Gamma, \mathsf{K}(t,u) : \rho_{\sqcap}(\tau,\tau')}

  \inferrule* [lab=$\rho_{\sqcup}$] {\vdash \Gamma, t : \tau, u : \tau'} {\vdash \Gamma, \sqcup(t,u) : \rho_{\sqcup}(\tau,\tau')}

  \inferrule* [lab=$\rho_{\perp}$] {\vdash\Gamma,  t' : \tau^{\perp}  \vdash t : \tau, \Delta }{\vdash \Gamma, \mathsf{R}(\mathsf{K}(t',t)) : \mathsf{r}_{\mathsf{K}}, \Delta}
\end{mathpar}

\subsection{Contexts, their types and cuts}

\subsubsection{Axiom}

% Need to add the ? introduction rules

\begin{mathpar}
  \inferrule* [lab=axiom] {} {\vdash \blacksquare : \tau^{\perp}, \boxempty : \tau} \\

  \inferrule* [lab=whynotleft] {\vdash \Gamma^{\bullet}, \boxempty : \tau_{1}, \chi^{\bullet} : \tau_{2}, \Delta^{\circ}, } {\vdash \Gamma^{\bullet}, \chi^{\bullet}? : \tau_{1} \RHD \tau_{2}, \Delta^{\circ}}

  \inferrule* [lab=whynotright] {\vdash \Gamma^{\circ}, \blacksquare : \tau_{1}, \chi^{\circ} : \tau_{2}, \Delta^{\bullet}} {\vdash \Gamma^{\circ}, ?\chi^{\circ} : \tau_{1} \LHD \tau_{2}, \Delta^{\bullet}} \\

  \inferrule* [lab=ofcourseleft] {\vdash \Gamma^{\circ}, \blacksquare : \tau_{1} , \chi^{\circ} : \tau_{2}, \Delta^{\bullet}}{\vdash \Gamma^{\circ}, !\chi : \tau_{1} \lhd \tau_{2}, \Delta^{\bullet}} \\

  \inferrule* [lab=ofcourseright] {\vdash \Gamma^{\bullet}, \boxempty : \tau_{1} , \chi^{\bullet} : \tau_{2}, \Delta^{\circ}}{\vdash \Gamma^{\bullet}, \chi! : \tau_{1} \rhd \tau_{2}, \Delta^{\circ}} \\

  \inferrule* [lab=$\rho_{\otimes}\perp\lhd$] {\vdash \Gamma, \mathsf{K}(\boxempty,u)! : \tau' \lhd \tau,  \vdash t : \tau, \Delta } {\vdash \Gamma, \mathsf{R}(\mathsf{K}(t,u)) : \tau', \Delta}

  \inferrule* [lab=$\rho_{\otimes}\perp\rhd$] {\vdash \Gamma, !\mathsf{K}(t,\boxempty) : \tau \rhd \tau',  \Delta \vdash u : \tau}{\vdash \Gamma, \mathsf{R}(\mathsf{K}(t,u)) : \tau', \Delta} \\

  \inferrule* [lab=$\rho_{\sqcap\perp\sqcup}$] {\vdash \Gamma, \sqcup\rho (t, u) : \rho_{\sqcup}(\tau_{3} \rhd \tau_{1}^{\perp}, u:\tau_{3})  \vdash \mathsf{K}(t', u') : \rho_{\sqcap}(\tau_{2} \rhd \tau_{1}, \tau_{2}), \Delta } {\vdash \Gamma, \mathsf{R}(\mathsf{K}(\mathsf{R}(\mathsf{K}( t, u)), \mathsf{R}(\mathsf{K}(t', u'))) : \mathsf{r}_{\mathsf{K}}, \Delta}
\end{mathpar}

\section{Examples}
\subsection{Applying the algorithm}
Now that we've worked out the type system in general above, we need to redo this example using the refined notation.

Below we give an example of the construction applied to the rho-combinators.
\subsubsection{Rho combinators}
Here is a relatively standard SoS presentation of the combinatorial system.

\begin{mathpar}
  \inferrule* [lab=atom] {} { P \bc 0 \;|\; \mathsf{m}(a,\quotep{P}) \;|\; \mathsf{d}(a,b,c) \;|\; \mathsf{k}(a) \;|\; \mathsf{fw}(a,b) \;|\; \mathsf{b}_{\mathsf{r}}(a,b) \;|\; \mathsf{b}_{\mathsf{l}}(a,b) \;|\; \mathsf{s}(a,b,c) }
  \and
  \inferrule* [lab=process] {} {\bm \; *a \;|\; P|P}
  \and
  \inferrule* [lab=nominal] {} {a \bc \quotep{P}}
\end{mathpar}

Rewrite rules
\[\begin{array}{rl}
\mathsf{d}(a,b,c) | \mathsf{m}(a,\quotep{P}) & \red \mathsf{m}(b,\quotep{P}) | \mathsf{m}(c,\quotep{P}) \\
\mathsf{k}(a) | \mathsf{m}(a,\quotep{P}) & \red 0 \\
\mathsf{fw}(a,b) | \mathsf{m}(a,\quotep{P}) & \red \mathsf{m}(b,\quotep{P}) \\
\mathsf{b}_{\mathsf{r}}(a,b) | \mathsf{m}(a,\quotep{P}) & \red \mathsf{fw}(b,\quotep{P}) \\
\end{array} \quad \quad
\begin{array}{rl}
  \mathsf{b}_{\mathsf{l}}(a,b) | \mathsf{m}(a,\quotep{P}) & \red \mathsf{fw}(\quotep{P},b) \\
  \mathsf{s}(a,b,c) | \mathsf{m}(a,\quotep{P}) & \red \mathsf{fw}(b,c) \\
  *(a) | \mathsf{m}(a,\quotep{P}) & \red P
\end{array}\]
\begin{mathpar}
  \inferrule* {{P} \red {P}'} {{{P} | {Q}} \red {{P}' | {Q}}}
  \and
  \inferrule* {{{P} \scong {P}'}, {{P}' \red {Q}'}, {{Q}' \scong {Q}}}{{P} \red {Q}}
\end{mathpar}

\begin{definition}
  The {\em structural congruence} $\equiv$
  between processes \cite{SangiorgiWalker} is the least congruence
  satisfying the commutative monoid laws
  (associativity, commutativity and $\pzero$ as identity) for parallel
  composition $|$ and $*(@(P)) \equiv P$.
\end{definition}

To interpret this presentation as a multi-sorted Lawvere theory per
the input format given above, we start with the Lawvere theory of
reflexive directed multigraphs and add new sorts, function symbols,
and equations.  The theory of reflexive directed multigraphs has

\begin{itemize}
  \item one sort $P$
  \item function symbols $\mathsf{s}, \mathsf{t} : P \rightarrow P$
  \item equations
    \begin{itemize}
      \item $\mathsf{s} \circ \mathsf{s} = \mathsf{t} \circ \mathsf{s} = \mathsf{s}$,
      \item $\mathsf{t} \circ \mathsf{t} = \mathsf{s} \circ \mathsf{t} = \mathsf{t} $
    \end{itemize}
\end{itemize}

We adjoin a sort $N$ for names. We express each of the syntactic generators as function symbols, thus $0 : 1 \rightarrow P$, $m : N x N \rightarrow P$, $@:P \rightarrow N$, $*:N \rightarrow P$, $|:P x P \rightarrow  P$, etc. The base case rewrite rules are given in terms of the $\mathsf{s}$ and $\mathsf{t}$ functions, thus

\begin{eqnarray*}
  \mathsf{s}( d(a, b, c) | m(a,d) \red m(b,d) | m(c,d) ) & = & d(a, b, c) | m(a,d) \\
  \mathsf{t}( d(a, b, c) | m(a,d) \red m(b,d) | m(c,d) ) & = & m(b,d) | m(c,d)
\end{eqnarray*}

Note that rewrites do not occur within a name because there is no rule for making $\mathsf{s}$ and $@$ commute with each other.
The inference rule $P \red P' \Rightarrow P|Q \red P'|Q$ is encoded as an equation involving $\mathsf{s}$, $\mathsf{t}$, and $|$:

\begin{eqnarray*}
  \mathsf{s}( P | Q ) & = & \mathsf{s}(P) | \mathsf{s}(Q) \\
  \mathsf{t}( P | Q ) & = & \mathsf{t}(P) | \mathsf{t}(Q)
\end{eqnarray*}

Structural congruence is encoded as equations:

\begin{eqnarray*}
  0 | P & = & P \\
  P | Q & = & Q | P \\
 (P | (Q | R)) & = & ((P | Q) | R) \\
  *@P & = & P
\end{eqnarray*}

\subsubsection{Typing a rho combinator process}

\begin{mathpar}
%%               --------------- axiom
%%               |- 0 : hat( 0 )
%%    ------------------------------------- weakening
%%    [] : hat( m )( x, T ) |- 0 : hat( 0 )
%% -------------------------------------------------- rho->l    ------------------------------- axiom
%% |- !K( k( x ), [] ) : hat( m )( x, T ) |> hat( 0 )           |- m( x, a ) : hat( m )( x, T )
%% --------------------------------------------------------------------------------------------
%% |- R( K( k( x ), m( x, a ) ) ) : hat( 0 )
\inferrule* [right=cut] {\inferrule* [right=$\rho^{l}$]{\inferrule* [right=weakening] {\inferrule* [right=axiom] {} {\vdash 0 : \hat{\mathsf{0}}}} {\boxempty : \hat{\mathsf{m}}( x, T ) \vdash 0 : \hat{\mathsf{0}}}}{\vdash !\mathsf{K}(\mathsf{k}( x ), \boxempty ) : \hat{\mathsf{m}}( x, T ) \rhd \hat{\mathsf{0}}} \quad \inferrule* [right=axiom] {} {\vdash \mathsf{m}( x, a ) : \hat{\mathsf{m}}( x, T )}} {\vdash \mathsf{R}( \mathsf{K}( \mathsf{k}( x ), \mathsf{m}( x, a ) ) ) : \hat{\mathsf{0}}}
\end{mathpar}

%% Given that congruence is equality, the final inference rule is an identity.
\subsubsection{SKI}
Below, we give an explicit example of the construction applied to the $\mathsf{SKI}$ calculus.

%% Reduction contexts for tensor vs cut, with idempotent commutative monoids for collection
%% T

%% S, K, I, {}: 1 \rightarrow T
%% R: T \rightarrow T
%% (- -), \cup : T^{2} \rightarrow T
%% // Pars & plusses come from LHS with \geq 2 holes
%% \bindnasrepma\sigma: T^{3} \rightarrow T
%% \bindnasrepma\kappa: T^{2} \rightarrow T
%% \oplus\sigma : T^{3} \rightarrow T
%% \oplus\kappa : T^{2} \rightarrow T

%% RR = R
%% R(x y) = (Rx y)
%% \cup, {} associative, commutative, unital, idempotent

%% \sigma : (((RS x) y) z) \rhd ((Rx z) (y z))
%% \kappa : ((rK x) y) \rhd Rx
%% \iota : (RI x) \rhd Rx

%% [[-]]: Coll + (Term + Pars) \rhd Coll \circ (Term + Pars)

%% Types
%% \tau ::=  T | \tau \rhd \tau | S | K | \mid | {} | R\tau | (\tau \tau) | \tau \cup \tau | \sigma\bindnasrepma(\tau,\tau,\tau,\tau,\tau,\tau) | \sigma\oplus(\tau,\tau,\tau) | (kappa versions of \bindnasrepma\oplus)

%% We use the abbreviations
%% \sigma\otimes(A,B,C) \triangleq (((S A\rhd B\rhd C) A\rhd B) A)
%% \sigma&(A,B,C,C') \triangleq (((S A\rhd B\rhd C' \rhd C) A\rhd B) A)

%% Inference rules

%% \Gamma \vdash x: A\rhd B\rhd C  \Delta \vdash y: A\rhd B,  \Xi \vdash z: A
%% ------------------------------------------------------------------------------- \sigma tensor
%% \Gamma, \Delta, \Xi \vdash (((S x) y) z): \sigma\otimes(A,B,C)

%% \Gamma \vdash x: A\Rightarrow D\Rightarrow E\Rightarrow F, y: B\Rightarrow D\Rightarrow E, z: C\Rightarrow D
%% --------------------------------------------------------- \sigma par
%% \Gamma \vdash \bindnasrepma\sigma (x, y, z): \sigma\bindnasrepma(A,B,C,D,E,F)

%% \Gamma \vdash \bindnasrepma\sigma (x, y, z): \sigma\bindnasrepma(A,B,C,D,E,F)  \Delta \vdash (((S x') y') z'): \sigma\otimes(A,B,C)
%% ----------------------------------------------------------------------------------- \sigma par-tensor-cut
%% \Gamma, \Delta \vdash R(((S (x x')) (y y')) (z z')): RF
%% F is the property we'd like to hold at the end.

%% \Gamma \vdash x: A\rhd B\rhd C'\rhd C, y: A\rhd B, z: A
%% ---------------------------------------------- \sigma with
%% \Gamma, \Delta, \Xi \vdash (((S x) y) z): \sigma_{&} (A,B,C',C)

%% \Gamma \vdash x: A\rhd B\rhd C, y: A\rhdB, z: A
%% ------------------------------------------ \sigma plus
%% \Gamma \vdash \oplus(x, y, z): \sigma\oplus(A,B,C)

%% \Gamma \vdash (((S x) y) z): \sigma&(A,B,C',C)   \Delta \vdash \oplus(x', y', z'): \sigma\oplus(A',B',C')
%% --------------------------------------------------------------------------------  \sigma with-plus-cut
%% \Gamma, \Delta \vdash R((((S x) y) z) (((S x') y') z')): RC

%% C is the property we'd like to hold at the end.

%% \Gamma \vdash x: A\rhd B\rhd C  \Delta \vdash y: A\rhd B,  \Xi \vdash z: A
%% ----------------------------------------------------- \sigma cut is the special case of \sigma\otimes with \bindnasrepma\sigma (I, I, I)
%% \Gamma, \Delta, \Xi \vdash (((RS x) y) z): RC

\pagebreak
\rotatebox{90}{
  \begin{tcolorbox}
    \begin{mathpar}
%% (((S x) y) z) => ((x z)(y z))

%% [] : A |> B |> C |- [] : A |> B |> C    [] : A |- [] : A         [] : A |> B |- [] : A |> B    [] : A |- [] : A
%% ------------------------------------------------------ cut     -------------------------------------------- cut
%%     [] : A |> B |> C, [] : A |- R([] []) : B |> C                      [] : A |> B, [] : A |- R([] []) : B
%% ------------------------------------------------------------------------------------------------------ cut
%% [] : A |> B |> C, []: A, [] : A |> B, [] : A |- R(R([] []) R([] [])) : C
%% ------------------------------------------------------------------------ rho->l
%% [] : A |> B |> C, [] : A |> B, [] : A |- !R(R(R(S []) []) []) : A |> C
%% ---------------------------------------------------------------------- extensionality
%% [] : A |> B |> C, [] : A |> B |- R(R(S []) []) : A |> C
%% ------------------------------------------------------- currying
%% [] : A |> B |> C |- !R(R(S []) []) : (A |> B) |> A |> C
%% ------------------------------------------------------- extensionality
%% [] : A |> B |> C |- R(S []) : (A |> B) |> A |> C
%% ------------------------------------------------ currying
%% |- !R(S []) : (A |> B |> C) |> (A |> B) |> A |> C
%% ------------------------------------------------- extensionality
  %% |- S : (A |> B |> C) |> (A |> B) |> A |> C

%
\inferrule* [right=extensionality] {\inferrule* [right=currying] {\inferrule* [right=extensionality] {\inferrule* [right=currying] {\inferrule* [right=extensionality] {\inferrule* [right=$\rightarrow^{l}$] {\inferrule* [right=cut] {\inferrule* [right=cut] {\inferrule* [right=axiom] {} {\boxempty : A \rhd B \rhd C \vdash \boxempty A \rhd B \rhd C} \quad\quad \inferrule* [right=axiom] {} {\boxempty : A \vdash \boxempty : A}} {\boxempty : A \rhd B \rhd C, \boxempty : A \vdash \mathsf{R}(\boxempty \boxempty) : B \rhd C} \quad\quad \inferrule* [right=cut] {\inferrule* [right=axiom] {} {\boxempty : A \rhd B \vdash \boxempty A \rhd B} \quad\quad \inferrule* [right=axiom] {} {\boxempty : A \vdash \boxempty : A}} {\boxempty : A \rhd B, \boxempty : A \vdash \mathsf{R}(\boxempty \boxempty) : B}} {\boxempty : A \rhd B \rhd C, \boxempty : A, \boxempty : A \rhd B, \boxempty : A \vdash \mathsf{R}(\mathsf{R}(\boxempty \boxempty) R(\boxempty \boxempty)) : C}} {\boxempty : A \rhd B \rhd C, \boxempty : A \rhd B, \boxempty : A \vdash !\mathsf{R}(\mathsf{R}(\mathsf{R}(\mathsf{S} \boxempty) \boxempty) \boxempty) : \rhd A \rhd C}} {\boxempty : A \rhd B \rhd C, \boxempty : A \rhd B, \boxempty : A \vdash \mathsf{R}(\mathsf{R}(\mathsf{S} \boxempty) \boxempty) : \rhd A \rhd C}} {\vdash !\mathsf{R}(\mathsf{R}(\mathsf{S} \boxempty) \boxempty) : (A \rhd B \rhd C) \rhd (A \rhd B) \rhd A \rhd C}} {\boxempty : A \rhd B \rhd C \vdash \mathsf{R}(\mathsf{S} \boxempty) : (A \rhd B \rhd C) \rhd (A \rhd B) \rhd A \rhd C}} {\vdash !\mathsf{R}(\mathsf{S} \boxempty) : (A \rhd B \rhd C) \rhd (A \rhd B) \rhd A \rhd C}} {\vdash \mathsf{S} : (A \rhd B \rhd C) \rhd (A \rhd B) \rhd A \rhd C}
    \end{mathpar}
  \end{tcolorbox}
}

\pagebreak
\section{Some useful properties and their proofs}
%% TBD

\section{Main theorems}
In this section, we prove a cut-elimination theorem.
\subsection{Cut-elimination}
Every proof that uses a cut can be transformed into a proof that does
not use a cut.  Compilation from contextualized resource theory back
to original theory. In {\lamc} and {\pic}, $\mathsf{K}$ is
not directly interpreted as application or parallel,
respectively. Instead, it turns into a data type so we can extract the
info using a par term introduced in the contextualized resource
theory.  In $\rho$, there's no need because it's reflective.  But either
way, the term calculi are powerful enough to support the embedding of
the new terms back into the original.

It remains to show that the embedding is full and faithful.

\section{Trampolines: implementing $\bindnasrepma_{\rho}$ and $\sqcup_{\rho}$ in the host theory}

The aim of the LADL programme is to generate a type system for a resource constrained version of a modern programming language algorithmically. Adding new terms to such a language, such as $\bindnasrepma_{\rho}$ and $\sqcup_{\rho}$ is disruptive and suboptimal. However, when the input to the algorithm is a computationally complete theory, like SKI or the rho-combinators, it is possible to implement $\bindnasrepma_{\rho}$ and $\sqcup_{\rho}$ as terms in the original theory and thus treat the type system as only talking about the original theory (modulo the resource constraint).

\section{Categorical construction}

% objects are types like on line 356
% morphisms are witnesses of entailment.  These are generated by the inference rules.
% If the witnesses contain enough information to reconstruct the proof, then we can say they are proofs.

% In the intuitionistic version, the left-hand side of an entailment
% is a typing context for the holes on the right.
% Composition is substitution.

% In the classical version, all LHSs of entailments are empty, so we are only
% generating morphisms out of the unit for tensor
% Morphisms come from annotating an entailment with a source and target type
% consistent with the entailment.
% e.g axiom gives four morphisms
% I -> A* tensor A
% A -> A
% A* -> A*
% A* tensor A -> I

\section{Conclusion and future work}

The aim of this construction is to generate a logic and its proof
theory from a notion of computation expressed as a graph-enriched
Lawvere theory. The logic respects both a Curry-Howard correspondence,
as well as realizability. Additionally, it enjoys a cut-elimination
property, and proof normalization corresponds precisely to the
operational semantics of the notion of computation provided in the
graph-enriched Lawvere theory.

We have not addressed nominal aspects of rewrite systems such as the
{\lamc} or the {\pic}. We note that there are two very
promising directions. One is captured in Clouston's work on nominal
Lawvere theories. \cite{DBLP:journals/jcss/Clouston14} The other is
expressed in Fiore's work on HOAS. \cite{DBLP:conf/csl/FioreH10} It
also bears mentioning that we can generate the names used by such a
nominal theory using reflection, ala Meredith and
Radestock. \cite{DBLP:conf/tgc/MeredithR05}

Also, in the spirit of Meredith and Radestock, we can seek to minimize
risk taken on in the theory in the form of “outside
influences.”Specifically, the evaluation context, $R$ does not have to
come from some external theory. It is possible to have two different
``copies'' of the same theory and have the $R$ of one come from terms
of the other and vice versa, in a mutually recursive definition.

\bibliographystyle{amsplain}
\bibliography{ladl}
\end{document}


\section{Syntax}

\subsection{Preconditions}

A function precondition is part of its declaration:

\begin{lstlisting}
double square_root(double x)
  expects{x>=0};
\end{lstlisting}

When an operation has multiple preconditions they can be combined with boolean operators.

\begin{lstlisting}
class my_vector {
//...
  double get_at(int i)
    expects{i>=0 && i<size && vec!=nullptr};
//...
private:
  double * vec;
  int size;
};
\end{lstlisting}

The \cppkey{expects} clause may contain any expression that is contextually
convertible to \cppkey{bool}. However, no side effects should be allowed in such
predicates.

\begin{lstlisting}
void f(int i) expects{i}; // OK
void g(int i) expects{i++}; // Ill-formed
\end{lstlisting}

In particular, an expression in a precondition may invoke functions as long as
they do not have side effects.

\begin{lstlisting}
class my_vector {
//...
  double get_at(int i)
    expects{ valid_index(i) && valid_vec() };
//...
  bool valid_index(i) const { return i>=0 && i<size; }
  bool valid_vec() const { return vec!=nullptr; }
private:
  double * vec;
  int size;
};
\end{lstlisting}

\subsection{Postconditions}

Any operation specification may have in its declaration a list of
postconditions that the developer guarantees to be held after the operation
execution.

\begin{lstlisting}
class string {
  //...
  void reserve(size_type res_arg = 0)
    expects{res_arg < max_size()}
    ensures{capacity() >= res_arg};
  //...
};
\end{lstlisting}

Expressions in a postcondition follow the same rules than expression in preconditions.

In the context of a postcondition the function name refers to the returned
value of the function.

\begin{lstlisting}
double square_root(double x)
  expects{x>=0.0}
  ensures{square_root>=0.0};
\end{lstlisting}

When a value may change during function execution previous value may referred
through operator \cppid{pre}.

\begin{lstlisting}
double increment(int & x)
  ensures{x == pre(x) + 1};
\end{lstlisting}

Operator \cppkey{pre} can also be applied to \cppid{*this}.

\begin{lstlisting}
class point {
  //...
  void move(double deltax, double deltay)
    ensures{x == pre(x) + deltax && y = pre(y) + deltay};
\end{lstlisting}


\section{Semileptonic decays in EvtGen}
\label{semileptonic}
\index{semileptonic decays}

\label{Semileptonic decays}
\subsection{Introduction}
We summarize the treatment of semileptonic decays in
EvtGen.  A framework is setup such that the implementation of
a model for semileptonic form factors requires only the
coding of the form factors themselves.  Currently, we consider
semileptonic decays from pseudoscalar mesons into
pseudoscalar, vector, or tensor meson daughters.
In section~\ref{sec:conventions} we define the
conventions used in the implementation of semileptonic
decays.  Section~\ref{sec:framework} describes the framework
from which semileptonic form factor models can be built.  An
example of such a model is given in section~\ref{sec:examples}.
Finally, we list the form factor models implemented in EvtGen
in section~\ref{sec:models}.

\subsection{Semileptonic conventions}
\label{sec:conventions}
\index{Semileptonic decay conventions}
We have tried to follow standard descriptions of semileptonic
form factors in EvtGen.
For decays of
pseudoscalar mesons to pseudoscalar daughters, we describe the
form factors as
\begin{eqnarray}
<S(k) \vert V_{\mu} \vert P(p) > & = &\biggl \{ (p+k)_{\mu} -
{{m_P^2 - m_S^2} \over {q^2}} q_{\mu} \biggr \} f_+(q^2) \\
&+&
\biggl \{  {{m_P^2 - m_S^2} \over {q^2}} q_{\mu} \biggr \} f_0(q^2)
\nonumber
\end{eqnarray}
$P$ denotes the parent (pseudoscalar) meson ($B$, $D$ or $B_s$) and
$S$ denotes a pseudoscalar daughter ($D$, $K$, or $\pi$).  In this
form, we have the constraint $f_+(0) = f_0(0)$.

\noindent
For decays to vector mesons, we use the form
\begin{eqnarray}
<V(k) \vert (V-A)_{\mu} \vert P(p) > & = &
 \epsilon^*_{\mu} (m_P+m_V) {\rm A}_1(q^2)
- (p+k)_{\mu} ( \epsilon^* p) { { {\rm A}_2(q^2)} \over {(m_P + m_V)}} \\
&-& q_{\mu} ( \epsilon^* p) { {2 m_V} \over {q^2}} \bigl ({\rm A}_3(q^2)
- i{\rm A}_0(q^2) \bigr ) \nonumber
\\
&+&\epsilon_{\mu \nu \rho \sigma} \epsilon^{* \nu} p^{\rho} k^{\sigma}
{ {2 {\rm V}(q^2)} \over { m_P + m_V} } \nonumber
\end{eqnarray}
Where $V$ denotes a vector daughter meson ($D^*$, $K^*$ or $\rho$)
and ${\rm A}_3$ is defined as
\begin{equation}
{\rm A}_3(q^2) = {{m_P+ m_V} \over {2 m_V}} {\rm A}_1(q^2) -
{{m_P- m_V} \over {2 m_V}} {\rm A}_2(q^2)
\end{equation}
where ${\rm A}_0 (0) = {\rm A}_3(0)$. \nonumber

\noindent For semileptonic decays to tensor mesons ($D_2^*$), to
be denoted as $T$, we use the form
\begin{eqnarray}
<T(k) \vert (V-A)_{\mu} \vert P(p) > &=& ih(q^2) \epsilon_{\mu \nu \lambda \rho}
\epsilon^{* \nu \alpha} p_{\alpha} (p+k)^{\lambda} (p-k)^{\rho} -
k(q^2) \epsilon^{*}_{\mu \nu} p^{\nu} \\
& + &b_+(q^2) \epsilon^*_{\alpha \beta} p^{\alpha} p^{\beta} (p+k)_{\mu} -
b_-(q^2) \epsilon^*_{\alpha \beta} p^{\alpha} p^{\beta} (p-k)_{\mu}
\nonumber
\end{eqnarray}

\subsection{Semileptonic framework}
\label{sec:framework}
There are two abstract classes responsible for the semileptonic decay
framework.  The first of these is
{\tt EvtSemiLeptonicFF}, which
provides the framework for the calculations of form factors.  There
are three member functions:
\index{{\tt EvtSemiLeptonicFF}}
\begin{itemize}
\item \begin{verbatim} virtual void getscalarff( int parent, int daught,
                       double t, double mass, double *fpf,
                       double *fmf )
\end{verbatim}
\item \begin{verbatim}  virtual void getvectorff( int parent, int daught,
                       double t, double mass, double *a1f,
                       double *a2f, double *vf, double *a0f )
\end{verbatim}
\item \begin{verbatim}  virtual void gettensorff( int parent, int daught,
                       double t, double mass, double *hf,
                       double *kf, double *bpf, double *bmf )
\end{verbatim}
\end{itemize}
\noindent All form factors models should include a class
derived from {\tt EvtSemiLeptonicFF},  which
will implement the relevant member functions of
{\tt EvtSemiLeptonicFF}.

\noindent These form factor implementations are used by classes
derived from the abstract class {\tt EvtSemiLeptonicAmp},
which contains the member function:
\index{{\it EvtSemiLeptonicAmp}}
\begin{itemize}
\item \begin{verbatim}   virtual void CalcAmp( EvtParticle *parent,
            EvtSemiLeptonicFF *FormFactors  )
\end{verbatim}
\end{itemize}
Classes to calculate the amplitude for semileptonic pseudoscalar to
pseudoscalar, pseudoscalar to vector, and
pseudoscalar to tensor decays are
{\tt EvtSemiLeptonicScalarAmp},
{\tt EvtSemiLeptonicVectorAmp}, and
{\tt EvtSemiLeptonicTensorAmp},
respectively.  These routines are passed form factors which
must follow the conventions described in section~\ref{sec:conventions}.
An example of how to use this framework is presented in
section~\ref{sec:examples}.

\subsection{Examples}
\label{sec:examples}
\index{EvtHQET}
Above we have defined the conventions followed in the standard
semileptonic framework of EvtGen.  Here we show how new
form factor models can be easily implemented.  We take as an
example a heavy quark effictive theory model of
$B \rightarrow D^* \ell \nu$ form factors, where $\ell$ is
either an electron or muon.  In this decay we can write the
form factors as:
\begin{equation}
A_1 = {{h_{A_1}(w)} \over {R^*}} \biggl ( 1 - { {q^2} \over {(M_B + M_{D^*})^2}}
\biggr )
\end{equation}
\begin{equation}
V = R_1 {{h_{A_1}(w)} \over {R^*}}
\end{equation}
\begin{equation}
A_2 = R_2 {{h_{A_1}(w)} \over {R^*}}
\end{equation}
\noindent where
\begin{equation}
h_{A_1}(w) = h_{A_1}(1) \biggl (1 - \rho_{A_1}^2(w-1) \biggr ),
\end{equation}
\begin{equation}
R^* = { {2.0 (M_B M_{D^*})^{1/2}} \over {(M_B+M_{D^*})}},
\end{equation}
\noindent and
\begin{equation}
w = { {M_B^2 + M_{D^*}^2 -q^2} \over { 2 M_B M_{D^*}} }
\end{equation}
\noindent To implement a decay model using these form factors
we must write two classes
\begin{itemize}
\item
\begin{verbatim}
class EvtHQETFF : public EvtSemiLeptonicFF {

public:
  EvtHQETFF(double hqetrho2, double hqetr1, double hqetr2);

  void getvectorff( int parent, int daught,
                       double t, double mass, double *a1f,
                       double *a2f, double *vf, double *a0f );

private:
  double r1;
  double rho2;
  double r2;
};
\end{verbatim}
\item
\begin{verbatim}
class EvtHQET:public  EvtDecayTBase<EvtHQET>  {

public:

  static void getName(char *name,int &narg);

  void Decay(EvtParticle *p);
  void InitProbMax();
  void Init();

private:
  EvtSemiLeptonicFF *hqetffmodel;
  EvtSemiLeptonicAmp *calcamp;
};
\end{verbatim}
\end{itemize}
\noindent This class is to implement $B \rightarrow D^* \ell \nu$
decays, so only the vector form factor routine must be
provided.  The constuctor allows R1, R2 and $\rho^2$ to
be passed in as a run time arguement.  We will discuss this
point more below.  The implementation of {\tt EvtHQETFF} is
quite simple:
\begin{verbatim}
EvtHQETFF::EvtHQETFF(double hqetrho2, double hqetr1, double hqetr2) {

  rho2 = hqetrho2;
  r1 = hqetr1;
  r2 = hqetr2;
  return;
}

void EvtHQETFF::getvectorff( int parent, int daught,
                       double t, double mass, double *a1f,
                             double *a2f, double *vf, double *a0f ){

  double mb=EvtPDL::nom_mass(parent);
  double w = ((mb*mb)+(mass*mass)-t)/(2.0*mb*mass);

// Form factors have a general form, with parameters passed in
// from the arguements.

  double rstar = ( 2.0*sqrt(mb*mass))/(mb+mass);
  double ha1 = 1-rho2*(w-1);

  *a1f = (1.0 - (t/((mb+mass)*(mb+mass))))*ha1;
  *a1f = (*a1f)/rstar;
  *a2f = (r2/rstar)*ha1;
  *vf = (r1/rstar)*ha1;
  *a0f = 0.0;

  return;
 }
\end{verbatim}
The {\tt getvectorff} routine takes the parent meson,
daughter vector meson, $q^2$ ({\tt t}), and the daughter meson
mass.  The form factors $A_1$, $A_2$, $V$ and $A_0$ are
returned.

\noindent The {\tt EvtHQET} class is also quite easy to
implement.  As with other classes which handle decay
models, it is derived from {\tt EvtDecayAmp}, which
is described elsewhere.  The class
should provide a {\tt Decay} routine as well as
{\tt getName}, {\tt Init}, {\tt clone}
and {\tt InitProbMax} routines.  Additionally,
the form factor model and amplitude calculation
implementations are handled as memeber data.  The
{\tt EvtHQET} implementation is:
\begin{verbatim}
void EvtHQET::getName(char *model_name,int &narg){

  strcpy(model_name,"HQET");
}

EvtDecayBase* EvtHQET::clone(){

  return new EvtHQET;

}

void EvtHQET::Decay( EvtParticle *p ){

  p->init_daughters(ndaug,daug);
  calcamp->CalcAmp(p,hqetffmodel);
}

void EvtHQET::InitProbMax() {

  SetProbMax(20000.0);
}

void EvtHQET::Init(){

  if ( ndaug!=3 ) {
     report(ERROR,"EvtGen") << "Wrong number of daughters in EvtHQET.cc\n";
  }

  hqetffmodel = new EvtHQETFF(args[0],args[1],args[2]);
  calcamp = new EvtSemiLeptonicVectorAmp;
}
\end{verbatim}
This class would be virtually unchanged for different
form factor models.  In {\tt Decay}, after initialization
of the daughter particles, {\tt CalcAmp} (in this case
from {\tt EvtSemiLeptonicVectorAmp} is called.  If the
standard form factor parameterizations are used, this
routine does not need to be rewriten.  The {\tt Init}
function is responsible for two things.  First the correct
form factor model must be initialized.  As {\tt EvtHQETFF}
takes arguements, these must be passed into
the constructor.  The arguements are otherwise private to the
{\tt EvtHQET} model.  Second, the {\tt CalcAmp} function
must be properly initialized such that the amplitude
is calculated for vector daughter mesons.  For models with form
factors for daughter mesons of different spins, the meson
spin ({\tt EvtPDL::spin(daug[0])} should be used to decide
how to initialize {\tt calcamp}.

\noindent With the existing framework, the implementation of
new form factor models should be quite simple.  The majority of
the work is in the coding of the form factors themselves

\subsection{Available models}
\label{sec:models}
\noindent There are several semileptonic form factor models
implemented within EvtGen and the {\tt EvtSemiLeptonicAmp}
framework.  In this section we describe the basic features of
each, including the modes available in each model and what
arguements must be passed in.  This is by no means a complete
list of all possible semileptonic models, and the authors would
welcome any additional form factor models implemented.

\subsubsection{EvtSLPole}
\label{sect:EvtSLPole}
\index{EvtSLPole}
\begin{itemize}
\item A general pole form is implemented for each form factor, using
the form
\begin{equation}
F = { {F(0)} \over { (1.0 + a { {q^2} \over {M^2} } + b { {q^4} \over {M^4} })^p}}
\end{equation}
where $M$ is the mass of the parent meson.
\item Leptons available: $e$, $\mu$, and $\tau$.
\item Arguements: For each form factor there are four arguements, $F(0)$,
$a$, $b$, and $p$.  Note that $p$ can be a non-integer.
\begin{itemize}
\item For scalar daughters the arguements should be ordered
as \\
$F(0)_{f_+}~ a_{f_+}~ b_{f_+}~ p_{f_+}~ F(0)_{f_0}~ a_{f_0}~ b_{f_0}p_{f_0}$.
\item For vector daughters the arguements should be ordered
as \\
$F(0)_{A_1}~ a_{A_1}~ b_{A_1}~p_{A_1}~F(0)_{A_2}~ a_{A_2}~ b_{A_2}~p_{A_2}~
F(0)_{V}~ a_{V}~ b_{V}~ p_{V}~
F(0)_{A_0}~ a_{A_0}~ b_{A_0}~p_{A_0}$
\item For tensor daughters the arguements should be ordered
as  \\
$F(0)_{k}~ a_{k}~ b_{k}~p_{k}~F(0)_{h}~ a_{h}~ b_{h}~p_{h}~F(0)_{b_+}~ a_{b_+}~ b_{b_+}~
p_{b_+}~F(0)_{b_-}~ a_{b_-}~ b_{b_-}~p_{b_-}$
\end{itemize}
\item In DECAY.DEC
\begin{verbatim}
0.0210   D+     e-   anti-nu_e          SLPOLE .... arguements;
\end{verbatim}
\end{itemize}

\subsubsection{EvtISGW2}
\index{EvtISGW2}
\index{ISGW2}
\begin{itemize}
\item Implementation of form factors defined from
Scora and Isgur~\cite{Scora95}.
\item Leptons available: $e$, $\mu$, and $\tau$.
\item Arguements: None
\item In DECAY.DEC
\begin{verbatim}
0.0210   D+     e-   anti-nu_e          ISGW2;
\end{verbatim}
\end{itemize}
\noindent We have implemented decays of $B$,$D$,$D_s$, and $B_s$
mesons as described by Scora and Isgur.

\subsubsection{EvtISGW}
\begin{itemize}
\item Implementation of form factors defined from
Isgur, Scora, Grinstein, and Wise~\cite{Isgur89a}.
\item Leptons available: $e$ and $\mu$ only.
\item Arguements: None
\item In DECAY.DEC
\begin{verbatim}
0.0210   D+     e-   anti-nu_e          ISGW;
\end{verbatim}
\end{itemize}
%\noindent Refer to Tables~\ref{table:bdecays} to~\ref{table:ddecays}
%for a list of
%available decays.

\subsubsection{EvtHQET}
\index{EvtHQET}
\begin{itemize}
\item Simple implementation of form factors within
HQET using a linear form for $\rho^2$.  This model is described
in more detail above.
\item Leptons available: $e$ and $\mu$ only.
\item Arguements:$\rho^2$, $R1$, and $R2$.
\item In DECAY.DEC
\begin{verbatim}
0.050   D*+     e-   anti-nu_e          HQET 0.92 1.18 0.72;
\end{verbatim}
\end{itemize}
\noindent This model is most useful for the decay $B \rightarrow D^* \ell \nu$,
however no assumptions are made about either the parent meson or the
daughter meson.  Any pseudoscalar semileptonic decay to a vector meson
could be modeled using these form factors.

%\begin{table}
%\begin{center}
%\begin{tabular}{|c|c|c|c|} \hline
%Decay                                           & ISGW2 & ISGW & HQET \\ \hline \hline
%$B \rightarrow D \ell \nu$                      & Y     & Y    &       \\
%$B \rightarrow D^* \ell \nu$                    & Y     & Y    & Y    \\
%$B \rightarrow D_1 \ell \nu$                    & Y     & Y    &      \\
%$B \rightarrow D_0^* \ell \nu$                  & Y     & Y    &      \\
%$B \rightarrow D_1^{\prime} \ell \nu$           & Y     & Y    &      \\
%$B \rightarrow D_2^* \ell \nu$                  & Y     & Y    &      \\
%$B \rightarrow D({\rm 2S}) \ell \nu$            & Y     & Y    &      \\
%$B \rightarrow D^*({\rm 2S}) \ell \nu$          & Y     & Y    &      \\
%$B \rightarrow \pi \ell \nu$                    & Y     & Y    &      \\
%$B \rightarrow \eta^{(\prime)} \ell \nu$        & Y     & Y    &      \\
%$B \rightarrow \rho (\omega) \ell \nu$          & Y     & Y    &      \\
%$B \rightarrow a_0 (f_0^{(\prime)})\ell \nu$    & Y     & Y    &      \\
%$B \rightarrow a_1 (f_1^{(\prime)})\ell \nu$    & Y     & Y    &      \\
%$B \rightarrow a_2 (f_2^{(\prime)})\ell \nu$    & Y     & Y    &      \\
%$B \rightarrow b_1 (h_1^{(\prime)}) \ell \nu$   & Y     & Y    &      \\
%$B \rightarrow \pi({\rm2S}) (\eta) \ell \nu$    & Y     & Y    &      \\
%$B \rightarrow \rho({\rm2S}) (\omega) \ell \nu$ & Y     & Y    &      \\ \hline
%\end{tabular}
%\end{center}
%\caption{List of available $B$ semileptonic decays for
%each form factor model currently implemented in EvtGen.  Isospin
%partners are usually implied.  Some models may not include
%form factors to properly handle decays to $\tau$ leptons.
%An ``Y'' is given to a decay if that model was implemented with
%that particular decay in mind.  For example the HQET model is
%meant primarily for $B \rightarrow D^* \ell \nu$, however any
%pseudoscalar decay to a vector meson could be handled with the
%proper constants passed in from DECAY.DEC.}
%\label{table:bdecays}
%\end{table}

%\begin{table}
%\begin{center}
%\begin{tabular}{|c|c|c|c|} \hline
%Decay                                           & ISGW2 & ISGW & HQET \\ \hline \hline
%\end{tabular}
%\end{center}
%\caption{List of available $D$ semileptonic decays for
%each form factor model currently implemented in EvtGen.  Isospin
%partners are usually implied.}
%\label{table:ddecays}
%\end{table}


\section{Base Logic}
\label{sec:base-logic}

The base logic is parameterized by an arbitrary camera $\monoid$ having a unit $\munit$.
By \lemref{lem:camera-unit-total-core}, this means that the core of $\monoid$ is a total function, so we will treat it as such in the following.
This defines the structure of resources that can be owned.

As usual for higher-order logics, you can furthermore pick a \emph{signature} $\Sig = (\SigType, \SigFn, \SigAx)$ to add more types, symbols and axioms to the language.
You have to make sure that $\SigType$ includes the base types:
\[
	\SigType \supseteq \{ \textlog{M}, \Prop \}
\]
Elements of $\SigType$ are ranged over by $\sigtype$.

Each function symbol in $\SigFn$ has an associated \emph{arity} comprising a natural number $n$ and an ordered list of $n+1$ types $\type$ (the grammar of $\type$ is defined below, and depends only on $\SigType$).
We write
\[
	\sigfn : \type_1, \dots, \type_n \to \type_{n+1} \in \SigFn
\]
to express that $\sigfn$ is a function symbol with the indicated arity.

Furthermore, $\SigAx$ is a set of \emph{axioms}, that is, terms $\term$ of type $\Prop$.
Again, the grammar of terms and their typing rules are defined below, and depends only on $\SigType$ and $\SigFn$, not on $\SigAx$.
Elements of $\SigAx$ are ranged over by $\sigax$.

\subsection{Grammar}\label{sec:grammar}

\paragraph{Syntax.}
Iris syntax is built up from a signature $\Sig$ and a countably infinite set $\Var$ of variables (ranged over by metavariables $\var$, $\varB$, $\varC$).
Below, $\melt$ ranges over $\monoid$ and $i$ ranges over $\set{1,2}$.

\begin{align*}
  \type \bnfdef{}&
      \sigtype \mid
      0 \mid
      1 \mid
      \type + \type \mid
      \type \times \type \mid
      \type \to \type
\\[0.4em]
  \term, \prop, \pred \bnfdef{}&
      \var \mid
      \sigfn(\term_1, \dots, \term_n) \mid
      \textlog{abort}\; \term \mid
      () \mid
      (\term, \term) \mid
      \pi_i\; \term \mid
      \Lam \var:\type.\term \mid
      \term(\term)  \mid
\\&
      \textlog{inj}_i\; \term \mid
      \textlog{match}\; \term \;\textlog{with}\; \Ret\textlog{inj}_1\; \var. \term \mid \Ret\textlog{inj}_2\; \var. \term \;\textlog{end} \mid
%
      \melt \mid
      \mcore\term \mid
      \term \mtimes \term \mid
\\&
    \FALSE \mid
    \TRUE \mid
    \term =_\type \term \mid
    \prop \Ra \prop \mid
    \prop \land \prop \mid
    \prop \lor \prop \mid
    \prop * \prop \mid
    \prop \wand \prop \mid
\\&
    \MU \var:\type. \term  \mid
    \Exists \var:\type. \prop \mid
    \All \var:\type. \prop \mid
%\\&
    \ownM{\term} \mid \mval(\term) \mid
    \always\prop \mid
    \plainly\prop \mid
    {\later\prop} \mid
    \upd \prop
\end{align*}
Well-typedness forces recursive definitions to be \emph{guarded}:
In $\MU \var. \term$, the variable $\var$ can only appear under the later $\later$ modality.
Furthermore, the type of the definition must be \emph{complete}.
The type $\Prop$ is complete, and if $\type$ is complete, then so is $\type' \to \type$.

Note that the modalities $\upd$, $\always$, $\plainly$ and $\later$ bind more tightly than $*$, $\wand$, $\land$, $\lor$, and $\Ra$.

\paragraph{Variable conventions.}
We assume that, if a term occurs multiple times in a rule, its free variables are exactly those binders which are available at every occurrence.

\subsection{Types}\label{sec:types}

Iris terms are simply-typed.
The judgment $\vctx \proves \wtt{\term}{\type}$ expresses that, in variable context $\vctx$, the term $\term$ has type $\type$.

A variable context, $\vctx = x_1:\type_1, \dots, x_n:\type_n$, declares a list of variables and their types.
In writing $\vctx, x:\type$, we presuppose that $x$ is not already declared in $\vctx$.

\judgment[Well-typed terms]{\vctx \proves_\Sig \wtt{\term}{\type}}
\begin{mathparpagebreakable}
%%% variables and function symbols
	\axiom{x : \type \proves \wtt{x}{\type}}
\and
	\infer{\vctx \proves \wtt{\term}{\type}}
		{\vctx, x:\type' \proves \wtt{\term}{\type}}
\and
	\infer{\vctx, x:\type', y:\type' \proves \wtt{\term}{\type}}
		{\vctx, x:\type' \proves \wtt{\term[x/y]}{\type}}
\and
	\infer{\vctx_1, x:\type', y:\type'', \vctx_2 \proves \wtt{\term}{\type}}
		{\vctx_1, x:\type'', y:\type', \vctx_2 \proves \wtt{\term[y/x,x/y]}{\type}}
\and
	\infer{
		\vctx \proves \wtt{\term_1}{\type_1} \and
		\cdots \and
		\vctx \proves \wtt{\term_n}{\type_n} \and
		\sigfn : \type_1, \dots, \type_n \to \type_{n+1} \in \SigFn
	}{
		\vctx \proves \wtt {\sigfn(\term_1, \dots, \term_n)} {\type_{n+1}}
	}
%%% empty, unit, products, sums
\and
	\infer{\vctx \proves \wtt\term{0}}
        {\vctx \proves \wtt{\textlog{abort}\; \term}\type}
\and
	\axiom{\vctx \proves \wtt{()}{1}}
\and
	\infer{\vctx \proves \wtt{\term}{\type_1} \and \vctx \proves \wtt{\termB}{\type_2}}
		{\vctx \proves \wtt{(\term,\termB)}{\type_1 \times \type_2}}
\and
	\infer{\vctx \proves \wtt{\term}{\type_1 \times \type_2} \and i \in \{1, 2\}}
		{\vctx \proves \wtt{\pi_i\,\term}{\type_i}}
\and
        \infer{\vctx \proves \wtt\term{\type_i} \and i \in \{1, 2\}}
        {\vctx \proves \wtt{\textlog{inj}_i\;\term}{\type_1 + \type_2}}
\and
        \infer{\vctx \proves \wtt\term{\type_1 + \type_2} \and
        \vctx, \var:\type_1 \proves \wtt{\term_1}\type \and
        \vctx, \varB:\type_2 \proves \wtt{\term_2}\type}
        {\vctx \proves \wtt{\textlog{match}\; \term \;\textlog{with}\; \Ret\textlog{inj}_1\; \var. \term_1 \mid \Ret\textlog{inj}_2\; \varB. \term_2 \;\textlog{end}}{\type}}
%%% functions
\and
	\infer{\vctx, x:\type \proves \wtt{\term}{\type'}}
		{\vctx \proves \wtt{\Lam x. \term}{\type \to \type'}}
\and
	\infer
	{\vctx \proves \wtt{\term}{\type \to \type'} \and \wtt{\termB}{\type}}
	{\vctx \proves \wtt{\term(\termB)}{\type'}}
%%% monoids
\and
        \infer{}{\vctx \proves \wtt\melt{\textlog{M}}}
\and
	\infer{\vctx \proves \wtt\melt{\textlog{M}}}{\vctx \proves \wtt{\mcore\melt}{\textlog{M}}}
\and
	\infer{\vctx \proves \wtt{\melt}{\textlog{M}} \and \vctx \proves \wtt{\meltB}{\textlog{M}}}
		{\vctx \proves \wtt{\melt \mtimes \meltB}{\textlog{M}}}
%%% props and predicates
\\
	\axiom{\vctx \proves \wtt{\FALSE}{\Prop}}
\and
	\axiom{\vctx \proves \wtt{\TRUE}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\term}{\type} \and \vctx \proves \wtt{\termB}{\type}}
		{\vctx \proves \wtt{\term =_\type \termB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop \Ra \propB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop \land \propB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop \lor \propB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop * \propB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop \wand \propB}{\Prop}}
\and
	\infer{
		\vctx, \var:\type \proves \wtt{\term}{\type} \and
		\text{$\var$ is guarded in $\term$} \and
		\text{$\type$ is complete and inhabited}
	}{
		\vctx \proves \wtt{\MU \var:\type. \term}{\type}
	}
\and
	\infer{\vctx, x:\type \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\Exists x:\type. \prop}{\Prop}}
\and
	\infer{\vctx, x:\type \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\All x:\type. \prop}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\melt}{\textlog{M}}}
		{\vctx \proves \wtt{\ownM{\melt}}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\melt}{\type} \and \text{$\type$ is a camera}}
		{\vctx \proves \wtt{\mval(\melt)}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\always\prop}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\plainly\prop}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\later\prop}{\Prop}}
\and
	\infer{
		\vctx \proves \wtt{\prop}{\Prop}
	}{
		\vctx \proves \wtt{\upd \prop}{\Prop}
	}
\end{mathparpagebreakable}

\subsection{Proof Rules}
\label{sec:proof-rules}

The judgment $\vctx \mid \prop \proves \propB$ says that with free variables $\vctx$, proposition $\propB$ holds whenever assumption $\prop$ holds.
Most of the rules will entirely omit the variable contexts $\vctx$.
In this case, we assume the same arbitrary context is used for every constituent of the rules.
%Furthermore, an arbitrary \emph{boxed} proposition context $\always\pfctx$ may be added to every constituent.
Axioms $\vctx \mid \prop \provesIff \propB$ indicate that both $\vctx \mid \prop \proves \propB$ and $\vctx \mid \propB \proves \prop$ are proof rules of the logic.

\judgment{\vctx \mid \prop \proves \propB}
\paragraph{Laws of intuitionistic higher-order logic with equality.}
This is entirely standard.
\begin{mathparpagebreakable}
\infer[Asm]
  {}
  {\prop \proves \prop}
\and
\infer[Cut]
  {\prop \proves \propB \and \propB \proves \propC}
  {\prop \proves \propC}
\and
\infer[Eq]
  {\vctx,\var:\type \proves \wtt\propB\Prop \\ \vctx\mid\prop \proves \propB[\term/\var] \\ \vctx\mid\prop \proves \term =_\type \term'}
  {\vctx\mid\prop \proves \propB[\term'/\var]}
\and
\infer[Refl]
  {}
  {\TRUE \proves \term =_\type \term}
\and
\infer[$\bot$E]
  {}
  {\FALSE \proves \prop}
\and
\infer[$\top$I]
  {}
  {\prop \proves \TRUE}
\and
\infer[$\wedge$I]
  {\prop \proves \propB \\ \prop \proves \propC}
  {\prop \proves \propB \land \propC}
\and
\infer[$\wedge$EL]
  {\prop \proves \propB \land \propC}
  {\prop \proves \propB}
\and
\infer[$\wedge$ER]
  {\prop \proves \propB \land \propC}
  {\prop \proves \propC}
\and
\infer[$\vee$IL]
  {\prop \proves \propB }
  {\prop \proves \propB \lor \propC}
\and
\infer[$\vee$IR]
  {\prop \proves \propC}
  {\prop \proves \propB \lor \propC}
\and
\infer[$\vee$E]
  {\prop \proves \propC \\
   \propB \proves \propC}
  {\prop \lor \propB \proves \propC}
\and
\infer[$\Ra$I]
  {\prop \land \propB \proves \propC}
  {\prop \proves \propB \Ra \propC}
\and
\infer[$\Ra$E]
  {\prop \proves \propB \Ra \propC \\ \prop \proves \propB}
  {\prop \proves \propC}
\and
\infer[$\forall$I]
  { \vctx,\var : \type\mid\prop \proves \propB}
  {\vctx\mid\prop \proves \All \var: \type. \propB}
\and
\infer[$\forall$E]
  {\vctx\mid\prop \proves \All \var :\type. \propB \\
   \vctx \proves \wtt\term\type}
  {\vctx\mid\prop \proves \propB[\term/\var]}
\\
\infer[$\exists$I]
  {\vctx\mid\prop \proves \propB[\term/\var] \\
   \vctx \proves \wtt\term\type}
  {\vctx\mid\prop \proves \exists \var: \type. \propB}
\and
\infer[$\exists$E]
  {\vctx,\var : \type\mid\prop \proves \propB}
  {\vctx\mid\Exists \var: \type. \prop \proves \propB}
% \and
% \infer[$\lambda$]
%   {}
%   {\pfctx \proves (\Lam\var: \type. \prop)(\term) =_{\type\to\type'} \prop[\term/\var]}
% \and
% \infer[$\mu$]
%   {}
%   {\pfctx \proves \mu\var: \type. \prop =_{\type} \prop[\mu\var: \type. \prop/\var]}
\end{mathparpagebreakable}
Furthermore, we have the usual $\eta$ and $\beta$ laws for projections, $\textlog{abort}$, sum elimination, $\lambda$ and $\mu$.

\paragraph{Laws of (affine) bunched implications.}
\begin{mathpar}
\begin{array}{rMcMl}
  \TRUE * \prop &\provesIff& \prop \\
  \prop * \propB &\proves& \propB * \prop \\
  (\prop * \propB) * \propC &\proves& \prop * (\propB * \propC)
\end{array}
\and
\infer[$*$-mono]
  {\prop_1 \proves \propB_1 \and
   \prop_2 \proves \propB_2}
  {\prop_1 * \prop_2 \proves \propB_1 * \propB_2}
\and
\inferB[$\wand$I-E]
  {\prop * \propB \proves \propC}
  {\prop \proves \propB \wand \propC}
\end{mathpar}

\paragraph{Laws for the plainness modality.}
\begin{mathpar}
\infer[$\plainly$-mono]
  {\prop \proves \propB}
  {\plainly{\prop} \proves \plainly{\propB}}
\and
\infer[$\plainly$-E]{}
{\plainly\prop \proves \always\prop}
\and
\begin{array}[c]{rMcMl}
  (\plainly P \Ra \plainly Q) &\proves& \plainly (\plainly P \Ra Q) \\
\plainly ( ( P \Ra Q) \land (Q \Ra P ) ) &\proves& P =_{\Prop} Q
\end{array}
\and
\begin{array}[c]{rMcMl}
  \plainly{\prop} &\proves& \plainly\plainly\prop \\
  \All x. \plainly{\prop} &\proves& \plainly{\All x. \prop} \\
  \plainly{\Exists x. \prop} &\proves& \Exists x. \plainly{\prop}
\end{array}
%\and
%\infer[PropExt]{}{\plainly ( ( P \Ra Q) \land (Q \Ra P ) ) \proves P =_{\Prop} Q}
\end{mathpar}

\paragraph{Laws for the persistence modality.}
\begin{mathpar}
\infer[$\always$-mono]
  {\prop \proves \propB}
  {\always{\prop} \proves \always{\propB}}
\and
\infer[$\always$-E]{}
{\always\prop \proves \prop}
\and
\begin{array}[c]{rMcMl}
  (\plainly P \Ra \always Q) &\proves& \always (\plainly P \Ra Q) \\
  \always{\prop} \land \propB &\proves& \always{\prop} * \propB
\end{array}
\and
\begin{array}[c]{rMcMl}
  \always{\prop} &\proves& \always\always\prop \\
  \All x. \always{\prop} &\proves& \always{\All x. \prop} \\
  \always{\Exists x. \prop} &\proves& \Exists x. \always{\prop}
\end{array}
\end{mathpar}

\paragraph{Laws for the later modality.}
\begin{mathpar}
\infer[$\later$-mono]
  {\prop \proves \propB}
  {\later\prop \proves \later{\propB}}
\and
\infer[$\later$-I]
  {}
  {\prop \proves \later\prop}
\and
\begin{array}[c]{rMcMl}
  \All x. \later\prop &\proves& \later{\All x.\prop} \\
  \later\Exists x. \prop &\proves& \later\FALSE \lor {\Exists x.\later\prop}  \\
  \later\prop &\proves& \later\FALSE \lor (\later\FALSE \Ra \prop)
\end{array}
\and
\begin{array}[c]{rMcMl}
  \later{(\prop * \propB)} &\provesIff& \later\prop * \later\propB \\
  \always{\later\prop} &\provesIff& \later\always{\prop} \\
  \plainly{\later\prop} &\provesIff& \later\plainly{\prop}
\end{array}
\end{mathpar}

\paragraph{Laws for resources and validity.}
\begin{mathpar}
\begin{array}{rMcMl}
\ownM{\melt} * \ownM{\meltB} &\provesIff&  \ownM{\melt \mtimes \meltB} \\
\ownM\melt &\proves& \always{\ownM{\mcore\melt}} \\
\TRUE &\proves&  \ownM{\munit} \\
\later\ownM\melt &\proves& \Exists\meltB. \ownM\meltB \land \later(\melt = \meltB)
\end{array}
% \and
% \infer[valid-intro]
% {\melt \in \mval}
% {\TRUE \vdash \mval(\melt)}
% \and
% \infer[valid-elim]
% {\melt \notin \mval_0}
% {\mval(\melt) \proves \FALSE}
\and
\begin{array}{rMcMl}
\ownM{\melt} &\proves& \mval(\melt) \\
\mval(\melt \mtimes \meltB) &\proves& \mval(\melt) \\
\mval(\melt) &\proves& \always\mval(\melt)
\end{array}
\end{mathpar}

\paragraph{Laws for the basic update modality.}
\begin{mathpar}
\inferH{upd-mono}
{\prop \proves \propB}
{\upd\prop \proves \upd\propB}

\inferH{upd-intro}
{}{\prop \proves \upd \prop}

\inferH{upd-trans}
{}
{\upd \upd \prop \proves \upd \prop}

\inferH{upd-frame}
{}{\propB * \upd\prop \proves \upd (\propB * \prop)}

\inferH{upd-update}
{\melt \mupd \meltsB}
{\ownM\melt \proves \upd \Exists\meltB\in\meltsB. \ownM\meltB}

\inferH{upd-plainly}
{}
{\upd\plainly\prop \proves \prop}
\end{mathpar}
The premise in \ruleref{upd-update} is a \emph{meta-level} side-condition that has to be proven about $a$ and $B$.
%\ralf{Trouble is, we do not actually have $\in$ inside the logic...}

\subsection{Consistency}

The consistency statement of the logic reads as follows: For any $n$, we have
\begin{align*}
  \lnot(\TRUE \proves (\later)^n\spac\FALSE)
\end{align*}
where $(\later)^n$ is short for $\later$ being nested $n$ times.

The reason we want a stronger consistency than the usual $\lnot(\TRUE \proves \FALSE)$ is our modalities: it should be impossible to derive a contradiction below the modalities.
For $\always$ and $\plainly$, this follows from the elimination rules.
For updates, we use the fact that $\upd\FALSE \proves \upd\plainly\FALSE \proves \FALSE$.
However, there is no elimination rule for $\later$, so we declare that it is impossible to derive a contradiction below any number of laters.

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "iris"
%%% End: