\subsection{Optimizations}\label{subsec:optimizations}

Rupture incorporates a number of optimizations that allow for faster and more
robust execution of attacks against multiple protocols.

\noindent \textbf{Block alignment.}\label{subsec:blockalign}
In block ciphers, the length of the encrypted text is rounded up to a product of
$\mu$-bits, where $\mu$ is the block size. Consequently, length difference
between two plaintexts does not always result in a similar length difference between the
respective ciphertexts.

We bypass this problem by using known block alignment techniques
\cite{moller2014poodle}. This method demands issuing multiple requests
and including artificial noise. In each request $r_{i, c_j}$
for each candidate $c_j$ in the alphabet, we add increasing artificial
noise of length $i$. That way, $r_{1, c_j}$ will contain one character of
alignment noise, $r_{2, c_j}$ two characters and so forth. Therefore, for some
alignment noise of length $a \in [0, \mu)$ the length of the request with the
correct candidate will be $(\delta*\mu)$ and for all incorrect candidates
$(\delta*\mu)+1$. In that case, the incorrect candidates result in one more
block compared to the correct one. This ensures that one out of $\ceil{\mu /
|r_i|}$ requests will result in a block distinction between the alphabet
candidates.

Figure \ref{fig:block_alignment} depicts the block alignment technique
intuitively.

   \begin{figure}[thpb]
      \centering
          \includegraphics[width=0.48\textwidth]{figures/block_alignment.png}
      \caption{The block alignment method}
      \label{fig:block_alignment}
   \end{figure}

\noindent \textbf{Reflection computation methods.}\label{subsec:reflectionmethods}
So far we have described the need for building and analysing reflections to
distinguish a single candidate in the secret's alphabet $\Sigma$ as the correct
one. In this section, we present two methods for constructing the reflections.

The first method is serial construction described in section
\ref{subsec:rupture_attack_design}. The complexity of this method is
$\mathcal{O}(|\Sigma|)$ and the round ends by finding a character of the secret.

The second method of attack is divide and conquer. The alphabet is now divided
into two subsets $\Sigma_1$ and $\Sigma_2 = \Sigma \setminus \Sigma_1$, where
$|\Sigma_1| = |\Sigma_2| = \ceil{|\Sigma| / 2}$. The reflection string for
$\Sigma_1$ consists of $|\Sigma_1|$ substrings separated by an annotation symbol
$\beta$. Each substring is built by concatenating the known prefix with a
candidate in $\Sigma_1$. For example, if $\Sigma_1$ is $\{``1", ``2"\}$ and the
known prefix is ``abc", using ``-" as $\beta$ the reflection is ``abc1-abc2".
The reflection string for $\Sigma_2$ is constructed similarly.

The end of each round marks the choice of subset $\Sigma_i$ that contains the
correct alphabet symbol. Each round reduces the alphabet by half, so the
complexity of this method is $\mathcal{O}(log|\Sigma|)$. When $|\Sigma_i| = 1$
the attack stage is completed and a character of the secret is decrypted.
Figure \ref{fig:divide_and_conquer} depicts the reflection sequence for the case
when the $\Sigma$ is the set of digits.

   \begin{figure}[thpb]
      \centering
          \includegraphics[width=0.48\textwidth]{figures/divide_and_conquer.png}
      \caption{The divide \& conquer method}
      \label{fig:divide_and_conquer}
   \end{figure}

\noindent \textbf{Request parallelization.}\label{subsec:parallel}
Modern web servers are able to handle multiple parallel requests and
browsers can issue a certain amount of parallel requests per domain. This
functionality enables the adversary to issue multiple parallel requests per
candidate and efficiently reduce the execution time of the attack.

\noindent \textbf{Request soup.}
Previous sections demonstrated the need for multiple requests per reflection
string $r_i$. However, communication is time expensive, so in many cases it is
preferable to issue multiple requests for a candidate and treat them as a set
rather than separately. This is the case for BREACH, where a set consists of
requests for a candidate $s_i$ in alphabet $\Sigma$. Bigger request sets result
in less time delay and the adversary can use the mean length over the number of
requests in the set without caring for each individual request's length.


\chapter{Cost Function}\label{chapter:ref:inversion cost function}
The general form of the cost function minimized in the inversion is given in the form (see also Chapter~\ref{chapter:ref:Drivers})
\begin{equation}\label{REF:EQU:DRIVE:10}
J(m) = J^{reg}(m) + \sum_{f} \mu^{data}_{f} \cdot J^{f}(p^f)
\end{equation}
where $m$ represents the level set function, $J^{reg}$ is the regularization term, see Chapter~\ref{Chp:ref:regularization},
and $J^{f}$ are a set of cost functions for forward models, (see Chapter~\ref{Chp:ref:forward models}) depending on
physical parameters $p^f$.  The physical parameters $p^f$ are known functions
of the  level set function $m$ which is the unknown to be calculated by the optimization process.
$\mu^{data}_{f}$ are trade-off factors. It is pointed out that the regularization term includes additional trade-off factors
The \class{InversionCostFunction} is class to define cost functions of an inversion. It is pointed out that
the \class{InversionCostFunction} class implements the \class{CostFunction} template class, see Chapter~\ref{chapter:ref:Minimization}.

In the simplest case there is a single forward model using a single physical parameter which is
derived form single-values level set function. The following script snippet shows the creation of the
cost function for the case of a gravity inversion:
\begin{verbatim}
p=DensityMapping(...)
f=GravityModel(...)
J=InversionCostFunction(Regularization(...), \
                        mappings=p, \
                        forward_models=f)
\end{verbatim}
The argument \verb|...| refers to an appropriate argument list.

If two forward models are coming into play using two different physical parameters
the \member{mappings} and \member{forward_models} are defined as lists in the following form:
\begin{verbatim}
p_rho=DensityMapping(...)
p_k=SusceptibilityMapping(...)
f_mag=MagneticModel(...)
f_grav=GravityModel(...)

J=InversionCostFunction(Regularization(...), \
                        mappings=[p_rho, p_k], \
                        forward_models=[(f_mag, 1), (f_grav,0)])
\end{verbatim}
Here we define a joint inversion of gravity and magnetic data. \member{forward_models} is given as a list of
a tuple of a forward model and an index which referring to parameter in the \member{mappings} list to be used as an input.
The magnetic forward model \member{f_mag} is using the second parameter (=\member{p_k}) in \member{mappings} list.
In this case the physical parameters are defined by a single-valued level set function. It is also possible
to link physical parameters to components of a level set function:
\begin{verbatim}
p_rho=DensityMapping(...)
p_k=SusceptibilityMapping(...)
f_mag=MagneticModel(...)
f_grav=GravityModel(...)

J=InversionCostFunction(Regularization(numLevelSets=2,...), \
                        mappings=[(p_rho,0), (p_k,1)], \
                        forward_models=[[(f_mag, 1), (f_grav,0)])
\end{verbatim}
The \member{mappings} argument is now a list of pairs where the first pair entry specifies the parameter mapping and
the second pair entry specifies the index of the component of the level set function to be used to evaluate the parameter.
In this case the level set function has two components, where the density mapping uses the first component of the level set function
while the susceptibility mapping uses the second component.

\section{\class{InversionCostFunction} API}\label{chapter:ref:inversion cost function:api}

The \class{InversionCostFunction} implements a \class{CostFunction} class used
to run optimization solvers, see Section~\ref{chapter:ref:Minimization: costfunction class}.
Its API is defined as follows:

\begin{classdesc}{InversionCostFunction}{regularization, mappings, forward_models}
Constructor for the inversion cost function. \member{regularization} sets the regularization to be used, see Chapter~\ref{Chp:ref:regularization}.
\member{mappings} is a list of pairs where each pair comprises of a
physical parameter mapping (see Chapter~\ref{Chp:ref:mapping}) and an index which refers to the component of level set function
defined by the \member{regularization} to be used to calculate the corresponding physical parameter.
If the level set function has a single component the index can be omitted.
If in addition there is a single physical parameter the mapping can be given instead of a list.
\member{forward_models} is a list of pairs where the first pair component is a
forward model (see Chapter~\ref{Chp:ref:forward models}) and the second pair
component refers to the physical parameter in the \member{mappings} list
providing the physical parameter for the model.
If a single physical parameter is present the index can be omitted.
If in addition a single forward model is used this forward model can be
assigned to \member{forward_models} in replacement of a list.
The \member{regularization} and all \member{forward_models} must use the same
\class{ReferenceSystem}, see Section~\ref{sec:ref:reference systems}.
\end{classdesc}

\begin{methoddesc}[InversionCostFunction]{getDomain}{}
returns the \escript domain of the inversion, see~\cite{ESCRIPT}.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getNumTradeOffFactors}{}
returns the total number of trade-off factors.
The count includes the trade-off factors $\mu^{data}_{f}$ for the forward
models and (hidden) trade-off factors in the regularization term,
see Definition~\ref{REF:EQU:DRIVE:10}.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getForwardModel}{\optional{idx=\None}}
returns the forward model with index \member{idx}.
If the cost function contains one model only argument \member{idx} can be omitted.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getRegularization}{}
returns the regularization component of the cost function, see \class{regularization} in Chapter~\ref{Chp:ref:regularization}.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{setTradeOffFactorsModels}{\optional{mu=\None}}
sets the trade-off factors $\mu^{data}_{f}$ for the forward model components.
If a single model is present \member{mu} must be a floating point number.
Otherwise \member{mu} must be a list of floating point numbers.
It is assumed that all numbers are positive.
The default value for all trade-off factors is one.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getTradeOffFactorsModels}{}
returns the values of the trade-off factors $\mu^{data}_{f}$ for the forward model components.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{setTradeOffFactorsRegularization}{\optional{mu=\None}, \optional{mu_c=\None}}
sets the trade-off factors for the regularization component of the cost function.
\member{mu} defines the trade-off factors for the level-set variation part and
\member{mu_c} sets the trade-off factors for the cross-gradient variation part.
This method is a shortcut for calling \member{setTradeOffFactorsForVariation}
and \member{setTradeOffFactorsForCrossGradient} for the underlying the
regularization.
Please see \class{Regularization} in Chapter~\ref{Chp:ref:regularization} for
more details on the arguments \member{mu} and \member{mu_c}.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{setTradeOffFactors}{\optional{mu=\None}}
sets the trade-off factors for the forward model and regularization terms.
\member{mu} is a list of positive floats. The length of the list is the total
number of trade-off factors given by the method \method{getNumTradeOffFactors}.
The first part of \member{mu} defines the trade-off factors $\mu^{data}_{f}$
for the forward model components while the remaining entries define the
trade-off factors for the regularization components of the cost function.
By default all values are set to one.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getProperties}{m}
returns the physical properties from a given level set function \member{m}
using the mappings of the cost function. The physical properties are
returned in the order in which they are given in the \member{mappings} argument
in the class constructor.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{createLevelSetFunction}{*props}
returns the level set function corresponding to set of given physical properties.
This method is the inverse of the \method{getProperties} method.
The arguments \member{props} define a tuple of values for the physical
properties where the order needs to correspond to the order in which the
physical property mappings are given in the \member{mappings} argument in the
class constructor. If a value for a physical property is given as \None the
corresponding component of the returned level set function is set to zero.
If no physical properties are given all components of the level set function
are set to zero.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getNorm}{m}
returns the norm of a level set function \member{m} as a floating point number.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getArguments}{m}
returns pre-computed values for the evaluation of the cost function and its
gradient for a given value \member{m} of the level set function.
In essence the method collects pre-computed values for the underlying
regularization and forward models\footnote{Using pre-computed values can
significantly speed up the optimization process when the value of the cost
function and its gradient are needed for the same level set function.}.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getValue}{m\optional{, *args}}
returns the value of the cost function for a given level set function \member{m}
and corresponding pre-computed values \member{args}.
If the pre-computed values are not supplied \member{getArguments} is called.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getGradient}{m\optional{, *args}}
returns the gradient of the cost function at level set function \member{m}
using the corresponding pre-computed values \member{args}.
If the pre-computed values are not supplied \member{getArguments} is called.
The gradient is represented as a tuple $(Y,X)$ where in essence $Y$ represents
the derivative of the cost function kernel with respect to the level set
function and $X$ represents the derivative of the cost function kernel with
respect to the gradient of the level set function, see
Section~\ref{chapter:ref:inversion cost function:gradient} for more details.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getDualProduct}{m, g}
returns the dual product of a level set function \member{m} with a gradient
\member{g}, see Section~\ref{chapter:ref:inversion cost function:gradient} for more details.
This method uses the dual product of the regularization.
\end{methoddesc}

\begin{methoddesc}[InversionCostFunction]{getInverseHessianApproximation}{m, g \optional{, *args}}
returns an approximative evaluation of the inverse of the Hessian operator of
the cost function for a given gradient \member{g} at a given level set function
\member{m} using the corresponding pre-computed values \member{args}.
If no pre-computed values are present \member{getArguments} is called.
In the current implementation contributions to the Hessian operator from the
forward models are ignored and only contributions from the regularization and
cross-gradient term are used.
\end{methoddesc}

\section{Gradient calculation}\label{chapter:ref:inversion cost function:gradient}
In this section we briefly discuss the calculation of the gradient and the Hessian operator.
If $\nabla$ denotes the gradient operator (with respect to the level set function $m$)
the gradient of  $J$ is given as
\begin{equation}\label{REF:EQU:DRIVE:10b}
\nabla J(m) = \nabla J^{reg}(m) + \sum_{f} \mu^{data}_{f} \cdot \nabla J^{f}(p^f) \; .
\end{equation}
We first focus on the calculation of $\nabla J^{reg}$. In fact the
regularization cost function $J^{reg}$ is given through a cost function
kernel\index{cost function!kernel} $K^{reg}$ in the form
\begin{equation}\label{REF:EQU:INTRO 2a}
J^{reg}(m) = \int_{\Omega} K^{reg} \; dx
\end{equation}
where $K^{reg}$ is a given function of the
level set function $m_k$ and its spatial derivative $m_{k,i}$. If $n$ is an increment to the level set function
then the directional derivative of $J^{ref}$ in the direction of $n$ is given as
\begin{equation}\label{REF:EQU:INTRO 2aa}
<n, \nabla J^{reg}(m)> = \int_{\Omega} \frac{ \partial K^{reg}}{\partial m_k} n_k + \frac{ \partial K^{reg}}{\partial m_{k,i}} n_{k,i} \; dx
\end{equation}
where $<.,.>$ denotes the dual product, see Chapter~\ref{chapter:ref:Minimization}. Consequently, the gradient $\nabla J^{reg}$
can be represented by a pair of values $Y$ and $X$
\begin{equation}\label{ref:EQU:CS:101}
\begin{array}{rcl}
  Y_k & = & \displaystyle{\frac{\partial K^{reg}}{\partial m_k}} \\
   X_{ki} & = & \displaystyle{\frac{\partial K^{reg}}{\partial m_{k,i}}}
\end{array}
\end{equation}
while the dual product $<.,.>$ of a level set increment $n$ and a gradient increment $g=(Y,X)$ is given as
\begin{equation}\label{REF:EQU:INTRO 2aaa}
<n,g> = \int_{\Omega} Y_k n_k + X_{ki} n_{k,i} \; dx
\end{equation}
We also need to provide (an approximation of) the value $p$ of the inverse of the Hessian operator $\nabla \nabla J$
for a given gradient increment $g=(Y,X)$. This means we need to (approximatively) solve the variational problem
\begin{equation}\label{REF:EQU:INTRO 2b}
<n,\nabla \nabla J p > = \int_{\Omega} Y_k n_k + X_{ki} n_{k,i} \; dx
\end{equation}
for all increments $n$ of the level set function. If we ignore contributions
from the forward models the left hand side takes the form
\begin{equation}\label{REF:EQU:INTRO 2c}
<n,\nabla \nabla J^{reg} p > = \int_{\Omega}
\displaystyle{\frac{\partial Y_k}{\partial m_l}} p_l n_k +
\displaystyle{\frac{\partial Y_k}{\partial m_{l,j}}} p_{l,j} n_k +
\displaystyle{\frac{\partial X_{ki}}{\partial m_l}} p_l n_{k,i} +
\displaystyle{\frac{\partial X_{ki}}{\partial m_{l,j}}} p_{l,j} n_{k,i}
\; dx
\end{equation}  We follow the concept as outlined in section~\ref{chapter:ref:inversion cost function:gradient}.
Notice that equation~\ref{REF:EQU:INTRO 2b} defines a system of linear PDEs
which is solved using \escript \class{LinearPDE} class. In the \escript notation we need to provide
\begin{equation}\label{ref:EQU:REG:600}
\begin{array}{rcl}
 A_{kilj} & = &  \displaystyle{\frac{\partial X_{ki}}{\partial m_{l,j}}}  \\
 B_{kil} & = &  \displaystyle{\frac{\partial X_{ki}}{\partial m_l}}   \\
 C_{klj} & = &  \displaystyle{\frac{\partial Y_k}{\partial m_{l,j}}}    \\
  D_{kl} & = & \displaystyle{\frac{\partial Y_k}{\partial m_l}}    \\
\end{array}
\end{equation}
The calculation of the gradient of the forward model component is more complicated:
the data defect $J^{f}$ for forward model $f$ is expressed using a cost function kernel $K^{f}$
\begin{equation}\label{REF:EQU:INTRO 2bb}
J^{f}(p^f) = \int_{\Omega} K^{f} \; dx
\end{equation}
In this case the cost function kernel $K^{f}$ is a function of the
physical parameter $p^f$, which again is a function of the level-set function,
and the state variable $u^f_{k}$ and its gradient $u^f_{k,i}$. For the sake of a simpler
presentation the upper index $f$ is dropped.

The gradient $\nabla_{p} J$ of the  $J$ with respect to
the physical property $p$ is given as
\begin{equation}\label{REF:EQU:costfunction 100b}
<q, \nabla_{p} J(p)> =    \int_{\Omega}
\displaystyle{\frac{\partial K }{\partial u_k }  } \displaystyle{\frac{\partial u_k }{\partial q }  } +
\displaystyle{\frac{\partial K }{\partial u_{k,i} }  } \left( \displaystyle{\frac{\partial u_k }{\partial q }  } \right)_{,i}+
\displaystyle{\frac{\partial K }{\partial p }  }  q \; dx
\end{equation}
for any $q$ as an increment to the physical parameter $p$. If the change
  of the state variable
$u_f$ for physical parameter $p$ in the direction of $q$ is denoted as
\begin{equation}\label{REF:EQU:costfunction 100c}
d_k =\displaystyle{\frac{\partial u_k }{\partial q }  }
\end{equation}
equation~\ref{REF:EQU:costfunction 100b} can be written as
\begin{equation}\label{REF:EQU:costfunction 100d}
<q, \nabla_{p} J(p)> =    \int_{\Omega}
\displaystyle{\frac{\partial K }{\partial u_k }  } d_k +
\displaystyle{\frac{\partial K }{\partial u_{k,i} }  } d_{k,i}+
\displaystyle{\frac{\partial K }{\partial p }  }  q \; dx
\end{equation}
The  state variable are the solution of PDE which in variational from is given
\begin{equation}\label{REF:EQU:costfunction 100}
\int_{\Omega} F_k \cdot r_k +  G_{li} \cdot r_{k,i} \; dx = 0
\end{equation}
for all increments $r$ to the stat $u$. The functions $F$ and $G$ are given and describe the physical
model. They depend of the state variable $u_{k}$ and its gradient $u_{k,i}$ and the physical parameter $p$. The change
$d_k$  of the state
$u_f$ for physical parameter $p$ in the direction of $q$ is given from the equation
\begin{equation}\label{REF:EQU:costfunction 100bb}
 \int_{\Omega}
\displaystyle{\frac{\partial F_k }{\partial u_l }  } d_l r_k +
\displaystyle{\frac{\partial F_k }{\partial u_{l,j}} } d_{l,j} r_k +
\displaystyle{\frac{\partial F_k }{\partial p} }q r_k +
\displaystyle{\frac{\partial G_{ki}}{\partial u_l} } d_l r_{k,i} +
\displaystyle{\frac{\partial G_{ki}}{\partial u_{l,j}} } d_{l,j} r_{k,i}+
\displaystyle{\frac{\partial G_{ki}}{\partial p} } q r_{k,i}
\; dx = 0
\end{equation}
to be fulfilled for all functions $r$. Now let $d^*_k$ be the solution of the
variational equation
\begin{equation}\label{REF:EQU:costfunction 100dd}
 \int_{\Omega}
\displaystyle{\frac{\partial F_k }{\partial u_l }  } h_l d^*_k +
\displaystyle{\frac{\partial F_k }{\partial u_{l,j}} } h_{l,j} d^*_k +
\displaystyle{\frac{\partial G_{ki}}{\partial u_l} } h_l d^*_{k,i} +
\displaystyle{\frac{\partial G_{ki}}{\partial u_{l,j}} } h_{l,j} d^*_{k,i}
\; dx
= \int_{\Omega}
\displaystyle{\frac{\partial K }{\partial u_k }  } h_k +
\displaystyle{\frac{\partial K }{\partial u_{k,i} }  } h_{k,i}  \; dx
\end{equation}
for all increments $h_k$ to the physical property $p$. This problem
is solved using \escript \class{LinearPDE} class. In the \escript notation we need to provide
\begin{equation}\label{ref:EQU:REG:600b}
\begin{array}{rcl}
 A_{kilj} & = &  \displaystyle{\frac{\partial G_{lj}}{\partial u_{k,i}} }  \\
 B_{kil} & = &  \displaystyle{\frac{\partial F_l }{\partial u_{k,i}} }   \\
 C_{klj} & = & \displaystyle{\frac{\partial G_{lj}}{\partial u_k} }    \\
  D_{kl} & = & \displaystyle{\frac{\partial F_l }{\partial u_k }  }   \\
  Y_{k} & = & \displaystyle{\frac{\partial K }{\partial u_k }  }     \\
  X_{ki} & = & \displaystyle{\frac{\partial K }{\partial u_{k,i} }  }    \\
\end{array}
\end{equation}
Notice that these coefficient are transposed to the coefficients used to solve for the
state variables in equation~\ref{REF:EQU:costfunction 100}.

Setting $h_l=d_l$ in equation~\ref{REF:EQU:costfunction 100d} and
$r_k=d^*_k$ in equation~\ref{REF:EQU:costfunction 100b} one gets
\begin{equation}\label{ref:EQU:costfunction:601}
\int_{\Omega}
\displaystyle{\frac{\partial K }{\partial u_k }  } d_k +
\displaystyle{\frac{\partial K }{\partial u_{k,i} }  } d_{k,i}+
\displaystyle{\frac{\partial F_k }{\partial p} } q d^*_k +
\displaystyle{\frac{\partial G_{ki}}{\partial p} } q d^*_{k,i}
\; dx = 0
\end{equation}
which is inserted into equation~\ref{REF:EQU:costfunction 100d} to get
\begin{equation}\label{REF:EQU:costfunction 602}
<q, \nabla_{p} J(p)> =    \int_{\Omega} \left(
\displaystyle{\frac{\partial K }{\partial p }  } - \displaystyle{\frac{\partial F_k }{\partial p} } d^*_k
- \displaystyle{\frac{\partial G_{ki}}{\partial p} }  d^*_{k,i} \right) q \; dx
\end{equation}
We need in fact the gradient of $J^f$ with respect to the level set function which is given as
\begin{equation}\label{REF:EQU:costfunction 603}
<n, \nabla J^f> =    \int_{\Omega} \left(
\displaystyle{\frac{\partial K^f}{\partial p^f}  } - \displaystyle{\frac{\partial F^f_k }{\partial p^f} } d^{f*}_k
- \displaystyle{\frac{\partial G^f_{ki}}{\partial p^f} }  d^{f*}_{k,i} \right)
\cdot \displaystyle{\frac{\partial p^f }{\partial m_l} } n_l \; dx
\end{equation}
for any increment $n$ to the level set function. So in summary we get
\begin{equation}\label{ref:EQU:CS:101b}
\begin{array}{rcl}
  Y_k & = & \displaystyle{\frac{\partial K^{reg}}{\partial m_k}} +
 \sum_{f} \mu^{data}_{f} \left(
\displaystyle{\frac{\partial K^f}{\partial p^f}  } - \displaystyle{\frac{\partial F^f_l }{\partial p^f} } d^{f*}_l
- \displaystyle{\frac{\partial G^f_{li}}{\partial p^f} }  d^{f*}_{l,i} \right)
\cdot \displaystyle{\frac{\partial p^f }{\partial m_k} }

\\
   X_{ki} & = & \displaystyle{\frac{\partial K^{reg}}{\partial m_{k,i}}}
\end{array}
\end{equation}
to represent $\nabla J$ as the tuple $(Y,X)$. Contributions of the forward model to the
Hessian operator are ignored.


The three interpretations of the surface syntax, dubbed \Nname{}, \Tname{},
 and \Aname{}, are defined via three reduction semantics.
 The first three subsections introduce the {\em notions of reduction\/};
 the last one generates the compatible closure with respect to evaluation contexts of
 these relations in a reasonably standard fashion~\cite{barendregt-1981,fff:redex}.

The three semantics utilize some common extensions to the surface syntax
and common meta functions; see figures~\ref{fig:evaluation-language},
\ref{fig:evaluation-metafunctions},\footnote{The judgment $\svalue_0 \in \snat$
   holds when the value $\svalue_0$ is a member of the set of natural numbers,
   and similarly for other objects and sets.
   By convention: a variable without a subscript typically refers to a set, and a
    term containing a set describes a comprehension.
   For example, $(\efun{\svar}{\svalue}) = \eset{(\efun{\svar_i}{\svalue_j}) \mid \svar_i \in \svar \mbox{ and } \svalue_j \in \svalue}$.}
and \ref{fig:delta}.
In particular, each
recognizes the same errors ($\eerr$), uses the same type
constructors ($\stag$) for tag checks,
and assigns the same meaning ($\sdelta$) to primitive
operations.

A program evaluation may signal four kinds of errors, defined in
\figref{fig:evaluation-language}.
First, a dynamic
tag error ($\tagerrorD{}$) is the outcome of an evaluation that applies an
 elimination form to a misshaped argument. For
example, the first projection of an integer signals such an error.
A static tag error ($\tagerrorS{}$) results from similar applications in typed
 code, and from any other redex that contradicts the static typing judgment.
Intuitively, type soundness eliminates the possibility of such contradictions.
Third,
a division-by-zero error ($\divisionbyzeroerror$) may be raised by an
 application of the $\squotient$ primitive; $\squotient$ is one representative
 example of the partial primitives in a full language.
Lastly, a boundary error ($\boundaryerror{\sbset}{\svalue}$)
 indicates a type mismatch between two components and comes with both a set of
 boundaries and a witness value.\footnote{A boundary error is comparable to a
   blame error~\cite{wf-esop-2009}; however, a boundary error emphasizes that
   either an untyped component or a type specification may be at fault.
   Type specifications---whether written by a programmer or inferred~\cite{cc-snapl-2019}---can have bugs.}
The error $\boundaryerror{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}}{\svalue_0}$,
 for example, says that a mismatch between value $\svalue_0$ and type $\stype_0$
 prevented the value sent by the $\sowner_1$ component from entering the $\sowner_0$ component.

\begin{figure}[t]

  \begin{minipage}[t]{0.60\columnwidth}
  \lbl{\fbox{\sevallang{}}}{
    \begin{langarray}
      \eerr & \BNFeq &
        \tagerrorD \mid \tagerrorS \mid
        \divisionbyzeroerror \mid
        \boundaryerror{\sbset}{\svalue}
      \\
      \sexpr & \BNFeq &
        \ldots \mid \eerr
      \\
      \stag & \BNFeq &
        \knat \mid \kint \mid \kpair \mid \kfun
    \end{langarray}
  }

  \end{minipage}\begin{minipage}[t]{0.40\columnwidth}
    \lbl{\fbox{$\stypeenv \sWT \sexpr : \stype$} \missingrules{}}{\vspace{-1mm}\begin{mathpar}
    \inferrule*{
    }{
      \stypeenv_0 \sWT \eerr : \stype_0
    }
  \end{mathpar}}

  \medskip
  \lbl{\fbox{$\stypeenv \sWT \sexpr : \tdyn$} \missingrules{}}{\vspace{-1mm}\begin{mathpar}
    \inferrule*{
    }{
      \stypeenv_0 \sWT \eerr : \tdyn
    }
  \end{mathpar}}

  \end{minipage}

  \Description[Grammar and types for error expressions.]{An extended grammar
    for error expressions, and typing judgments to state that an error is well-typed
    in any context.
  }
  \caption{Syntax for basic errors and type constuctors, common typing judgments}
\label{fig:evaluation-language}
\end{figure}

\begin{figure}[t]\flushleft\(
  \begin{array}{l@{\quad}l}
    \begin{array}{l@{~~}c@{~~}l@{}}
    \fshallow{\stag_0}{\svalue_0} & \feq &
      \left\{\begin{array}{l@{~~}l}
        \makebox[2pt][l]{$\ftrue$}
        \\ & \mbox{\makebox[\widthof{or}][l]{if} $\stag_0 \eeq \knat$ and $\svalue_0 \in \snat$}
        \\ & \mbox{or $\stag_0 \eeq \kint$ and $\svalue_0 \in \sint$}
        \\ & \mbox{or $\stag_0 \eeq \kpair$ and}
        \\ & \quad\, \svalue_0 \in \epair{\svalue}{\svalue} \cup{}
        \\ & \zerowidth{\qquad\, \quad (\emon{\obnd{\sowner}{(\tpair{\stype}{\stype})}{\sowner}}{\svalue})}
        \\ & \mbox{or $\stag_0 \eeq \kfun$ and}
        \\ & \quad\, \svalue_0 \in (\efun{\svar}{\sexpr}) \cup (\efun{\tann{\svar}{\stype}}{\sexpr}) \cup{}
        \\ & \zerowidth{\qquad\, \quad (\emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\svalue})}
        \\
        \zerowidth{\fshallow{\stag_0}{\svalue_1}}
        \\ & \mbox{\makebox[\widthof{or}][l]{if} $\svalue_0 \eeq \ehist{\sbset_0}{\svalue_1}$}
        \\
        \zerowidth{\ffalse}
        \\ & \mbox{otherwise}
      \end{array}\right.
    \end{array}
  &
    \begin{array}{l@{~~}c@{~~}l}
    \tagof{\stype_0} & \feq &
      \left\{\begin{array}{ll}
        \knat & \mbox{if $\stype_0 \eeq \tnat$}
        \\
        \kint & \mbox{if $\stype_0 \eeq \tint$}
        \\
        \kpair & \mbox{if $\stype_0 \in \tpair{\stype}{\stype}$}
        \\
        \kfun & \mbox{if $\stype_0 \in \tfun{\stype}{\stype}\!\!$}
      \end{array}\right.

      \\[3.6cm]

      \frev{\sbset_0} & \feq &
        \eset{\obnd{\sowner_1}{\stype_0}{\sowner_0} \\
      & & \,{}\mid \obnd{\sowner_0}{\stype_0}{\sowner_1} \in \sbset_0}
    \end{array}

  \end{array}\)

  \Description[Three metafunctions.]{Metafunctions for the evaluation language.
    The `tag-match' metafunction matches a type-tag against a value. The
    `floor of` metafunction reduces a type to a type tag. The `rev' metafunction
    reverses the labels in every boundary of a set.
  }
  \caption{Common metafunctions}
  \label{fig:evaluation-metafunctions}
\end{figure}

\begin{figure}[t]\flushleft
  \begin{minipage}[t]{0.48\columnwidth}\(
  \begin{array}{l@{~~}c@{~~}l}
      \sdelta(\sunop, \epair{\svalue_0}{\svalue_1}) & \feq &
        \left\{\begin{array}{l@{~~}l}
          \makebox[2pt][l]{$\svalue_0$}
          \\ & \mbox{if $\sunop \eeq \tinst{\sfst}{\toptional}$}
          \\
          \zerowidth{\svalue_1}
          \\ & \mbox{if $\sunop \eeq \tinst{\ssnd}{\toptional}$}
        \end{array}\right.
  \end{array}\)

  \end{minipage}\begin{minipage}[t]{0.52\columnwidth}\(
  \begin{array}{l@{~~}c@{~~}l}
      \sdelta(\sbinop, \sint_0, \sint_1) & \feq &
       \left\{\begin{array}{l@{~~~}l}
         \makebox[2pt][l]{$\sint_0 + \sint_1$}
         \\ & \mbox{if $\sbinop \eeq \tinst{\ssum}{\stoptional}$}
         \\
         \zerowidth{\divisionbyzeroerror}
         \\ & \mbox{if $\sbinop \eeq \tinst{\squotient}{\stoptional}$}
         \\ & \mbox{and $\sint_1 \eeq 0$}
         \\
         \zerowidth{\floorof{\sint_0 / \sint_1}}
         \\ & \mbox{if $\sbinop \eeq \tinst{\squotient}{\stoptional}$}
         \\ & \mbox{and $\sint_1 \neq 0$}
       \end{array}\right.
  \end{array}\)
  \end{minipage}

  \Description[Two metafunctions]{The `delta' metafunctions assign meaning to
    the primitive operations: `fst' and `snd' get elements from a pair value;
    `sum' and `quotient' perform integer arithmetic.}
  \caption{Specification for primitive operations}
  \label{fig:delta}
\end{figure}

%% ------------------------------------------------------------------------------
\subsection{\Nname{} Notions of Reduction} \label{sub:ho}

\Figref{fig:natural-language} extends the base grammar of evaluation expressions
with monitor wrappers. While the grammar is somewhat liberal, \Nname{} only
ever pairs a function-type boundary with a (possibly-monitored) function value in a
monitor. Thus the monitors that arise during evaluation are members of the
following two mutually-recursive sets:

\smallskip\hspace{-6mm}
\begin{array}[t]{ll}
\begin{array}[t]{lcl}
  \Nstawrapper & \BNFeq & \emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\efun{\svar}{\sexpr}} \\
  & \mid & \emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\Ndynwrapper}
\end{array} &
\begin{array}[t]{lcl}
  \Ndynwrapper & \BNFeq & \emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\efun{\tann{\svar}{\stype}}{\sexpr}} \\
  & \mid & \emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\wideas{\Nstawrapper}{\Ndynwrapper}}
\end{array}
\end{array}
\smallskip

\noindent If any other monitor arises, the notions of reduction raise a static
tag error. These rules appear in the \techreport{} along with a proof that
well-typed expressions never raise static tag errors.

\begin{figure}[t]\flushleft

  \lbl{\fbox{\Nname{} \sevallang{}}}{
    \begin{langarray}
      \svalue & \BNFeq &
        \snat
        \mid \sint
        \mid \epair{\svalue}{\svalue}
        \mid \efun{\svar}{\sexpr}
        \mid \efun{\tann{\svar}{\stype}}{\sexpr}
        \mid \emon{\sbnd}{\svalue}
      \\
      \sexpr & \BNFeq &
        \ldots \mid \emon{\sbnd}{\svalue}
    \end{langarray}
  }

  \smallskip
  \begin{minipage}[t]{0.5\columnwidth}
  \lbl{\fbox{$\stypeenv \sWTN \sexpr : \stype$} \missingrules{}}{\begin{mathpar}
    \inferrule*{
      \stypeenv_0 \sWTN \svalue_0 : \tdyn
    }{
      \stypeenv_0 \sWTN \emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0} : \tfun{\stype_0}{\stype_1}
    }
  \end{mathpar}}

  \end{minipage}\begin{minipage}[t]{0.5\columnwidth}
  \lbl{\fbox{$\tenv \sWTN \sexpr : \tdyn$} \missingrules{}}{\begin{mathpar}
    \inferrule*{
      \tenv_0 \sWTN \svalue_0 : \tfun{\stype_0}{\stype_1}
    }{
      \stypeenv_0 \sWTN \emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0} : \tdyn
    }
  \end{mathpar}}

  \end{minipage}

  \Description[Grammar and typing judgments.]{Extends the evaluation grammar
    with monitor values and adds typing rules for monitors. The typing
    rules are similar to the dyn and stat rules.
  }
  \caption{\Nname{} language extensions}
  \label{fig:natural-language}
\end{figure}

%% -----------------------------------------------------------------------------

\subsubsection{\Nname{}, Statically-Typed} \label{sec:n-static}
The $\sdelta$ metafunction (\figref{fig:delta}) defines the semantics
 of the unary and binary operators.
If $\sdelta$ is undefined for the argument values, a tag error results:

\begin{rrpage}
  \rhsbox{2pt}{\sexpr \nredNS \sexpr}
  \\[-2ex]
  \begin{inlinerrarray}
    \eunopt{\stype_0}{\svalue_0}
    &  \nredNS
    &  \tagerrorS
    \\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is undefined}
    \\[0.3ex]
    \eunopt{\stype_0}{\svalue_0}
    & \nredNS
    & \sdelta(\sunop, {\svalue_0})
    \\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is defined}
    \\[0.3ex]
    \ebinopt{\stype_0}{\svalue_0}{\svalue_1}
    &  \nredNS
    &  \tagerrorS
    \\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is undefined}
    \\[0.3ex]
    \ebinopt{\stype_0}{\svalue_0}{\svalue_1}
    &  \nredNS
    &  \sdelta(\sbinop, {\svalue_0}, {\svalue_1})
    \\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is defined}
  \end{inlinerrarray}
\end{rrpage}

%\noindent Recall that a $\delta$ reduction issues errors for partially-defined primitive
%operations.

Only a typed function or monitor may be applied to an argument in a statically-typed context.
Any other application is a tag error:

\begin{inlinerrarray}
  \eapp{\stype_0}{\svalue_0}{\svalue_1}
  & \nredNS
  & \tagerrorS
  \\\sidecond{if $\svalue_0 \not\in (\efun{\tann{\svar}{\stype}}{\sexpr}) \cup (\emon{\sbnd}{\svalue})$}
\end{inlinerrarray}

\noindent
The application of a typed lambda to an argument is standard:

\begin{inlinerrarray}
       \eapp{\stype_0}{(\efun{\tann{\svar_0}{\stype_1}}{\sexpr_0})}{\svalue_0}
      &  \nredNS
      &  \esubst{\sexpr_0}{\svar_0}{\svalue_0}
\end{inlinerrarray}

\noindent
The application of a monitored, untyped function unfolds the monitor proxy into
two new boundary terms.
One $\ssta$ boundary protects the typed argument
from improper use by the body of the dynamically-typed function; one
$\sdyn$ boundary checks the result:

\begin{inlinerrarray}
  \eapp{\stype_0}{(\emon{\obnd{\sowner_0}{(\tfun{\stype_1}{\stype_2})}{\sowner_1}}{\svalue_0})}{\svalue_1}
      &  \nredNS
      &  \edynb{\sbnd_0}{(\eapp{\tdyn}{\svalue_0}{(\estab{\sbnd_1}{\svalue_1})})}
      \\\sidecond{where \(\sbnd_0 \sassign \obnd{\sowner_0}{\stype_2}{\sowner_1}\)
                    and \(\sbnd_1 \sassign \obnd{\sowner_1}{\stype_1}{\sowner_0}\)}
\end{inlinerrarray}

\noindent
Both boundaries use the type $(\tfun{\stype_1}{\stype_2})$ from
the monitored function and ignore the annotation $\stype_0$ that decorates the application.
The annotations are relevant only for \Tname{} and \Aname{}.

The remaining four rules define the behavior of $\sdyn$ boundaries.
 These rules initially check a dynamically-typed value against a static type
 using the $\sshallow$ metafunction.
For functions, a successful check entails the creation of a new monitor:

\begin{inlinerrarray}
      \edynb{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0}
      &  \nredNS
      &  \emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0}
      \\\sidecond{if $\fshallow{\ftagof{\tfun{\stype_0}{\stype_1}}}{\svalue_0}$}
\end{inlinerrarray}

\noindent
For pairs, \Nname{} creates a new typed pair containing new $\sdyn$ boundaries.
The evaluation of these boundaries validates the elements of the original,
 untyped pair:

\begin{inlinerrarray}
  \edynb{\obnd{\sowner_0}{(\tpair{\stype_0}{\stype_1})}{\sowner_1}}{\epair{\svalue_0}{\svalue_1}}
      &  \nredNS
      &  \epair{\edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}}{\edynb{\obnd{\sowner_0}{\stype_1}{\sowner_1}}{\svalue_1}}
\end{inlinerrarray}

\noindent For base types, a successful check is a complete proof that the
 value matches the type:

\begin{inlinerrarray}
       \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\sint_0}
      &  \nredNS
      &  \sint_0
      \\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\sint_0}\)}
\end{inlinerrarray}

\noindent
Otherwise, if the $\sshallow$ check fails, the reduction ends in a type mismatch.
The error message reports the current boundary and the incompatible value:

\begin{inlinerrarray}
       \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
      &  \nredNS
      &  \boundaryerror{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}}{\svalue_0}
      \\\sidecond{if \(\neg \fshallow{\ftagof{\stype_0}}{\svalue_0}\)}
\end{inlinerrarray}

%% -----------------------------------------------------------------------------
\subsubsection{\Nname{}, Dynamically-Typed}

Applications of primitives end in a dynamic tag error if $\sdelta$ is
 undefined for the given values:

\begin{rrpage}
  \rhsbox{2pt}{\sexpr \nredND \sexpr}
  \\[-2ex]
  \begin{inlinerrarray}
    \eunopt{\tdyn}{\svalue_0} &  \nredND &  \tagerrorD
      \\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is undefined}
      \\[0.3ex]
       \eunopt{\tdyn}{\svalue_0}
      &  \nredND
      &  \sdelta(\sunop, {\svalue_0})
      \\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is defined}
      \\[0.3ex]
       \ebinopt{\tdyn}{\svalue_0}{\svalue_1}
      &  \nredND
      &  \tagerrorD{}
      \\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is undefined}
      \\[0.3ex]
       \ebinopt{\tdyn}{\svalue_0}{\svalue_1}
      &  \nredND
      &  \sdelta(\sbinop, {\svalue_0}, {\svalue_1})
      \\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is defined}
  \end{inlinerrarray}
\end{rrpage}

Function application follows the tag of the operator:
 substitution for an untyped function,
 decomposition for a monitor,
 and a tag error for anything else:

\begin{inlinerrarray}
      \eapp{\tdyn}{\svalue_0}{\svalue_1}
      & \nredND
      & \tagerrorD
      \\\sidecond{if $\svalue_0 \not\in (\efun{\svar}{\sexpr}) \cup (\emon{\sbnd}{\svalue})$}
      \\[0.3ex]
       \eapp{\tdyn}{(\efun{\svar_0}{\sexpr_0})}{\svalue_0}
      &  \nredND
      &  \esubst{\sexpr_0}{\svar_0}{\svalue_0}
      \\[0.3ex]
       \eapp{\tdyn}{(\emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0})}{\svalue_1}
      &  \nredND
      &  \estab{\sbnd_0}{(\eapp{\stype_1}{\svalue_0}{(\edynb{\sbnd_1}{\svalue_1})})}
      \\\sidecond{where \(\sbnd_0 \sassign \obnd{\sowner_0}{\stype_1}{\sowner_1}\)
                  and \(\sbnd_1 \sassign \obnd{\sowner_1}{\stype_0}{\sowner_0}\)}
\end{inlinerrarray}

\noindent
In the monitor case, a $\sdyn$ boundary checks the
 argument and a $\ssta$ boundary protects the result.

The rules for $\ssta$ boundaries protect typed values from untyped contexts.
Protection is crucial for typed functions because an untyped context may
 supply type-incorrect arguments:

\begin{inlinerrarray}
      \estab{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0}
      &  \nredND
      &  \emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0}
      \\\sidecond{if $\fshallow{\ftagof{\tfun{\stype_0}{\stype_1}}}{\svalue_0}$}
\end{inlinerrarray}

\noindent
For typed pairs, a traversal protects higher-order members:

\begin{inlinerrarray}
  \estab{\obnd{\sowner_0}{(\tpair{\stype_0}{\stype_1})}{\sowner_1}}{\epair{\svalue_0}{\svalue_1}}
      &  \nredND
      &  \epair{\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}}{\estab{\obnd{\sowner_0}{\stype_1}{\sowner_1}}{\svalue_1}}
\end{inlinerrarray}

\noindent
Base values do not require protection:

\begin{inlinerrarray}
       \estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\sint_0}
      &  \nredND
      &  \sint_0
      \\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\sint_0}\)}
\end{inlinerrarray}

\noindent
Any other combination of type and value indicates a type mismatch within a
 statically-typed component, and results in a static tag error:

\begin{inlinerrarray}
       \estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
      &  \nredND
      &  \tagerrorS
      \\\sidecond{if \(\neg \fshallow{\ftagof{\stype_0}}{\svalue_0}\)}
\end{inlinerrarray}

\noindent
The $\ssta$ rules do not output a boundary error because a type mismatch in
typed code contradicts the static typing judgment, which is meant to be an
invariant.

%% -----------------------------------------------------------------------------
\subsection{\Tname{} Notion of Reduction} \label{sub:first}

\Figref{fig:transient-language} extends the base evaluation language with
 pre-values, heaps, and tag-check expressions.
The goal is to allocate one
 instance of every function and pair on a value heap.
Technically, a value heap $\vstore$ maps addresses ($\eloc$) to pre-values ($\sprevalue$).
A blame heap $\bstore$ maps addresses to sets of boundaries according to the
 blame strategy of Transient Reticulated~\cite{vss-popl-2017,v-thesis-2019}.
A check expression
 $(\echecktwo{\stoptional}{\sexpr}{\eloc})$ validates the result of an
 elimination form: $\stoptional$ is the expected type, $\sexpr$ is the
 result, and $\eloc$ is the address of the previously-eliminated value.
The typing judgments {$\vstoretype; \stypeenv \sWTT \sexpr : \stag$} and
 {$\vstoretype; \stypeenv \sWTT \sexpr : \tdyn$} validate type-tags.
Both judgments accept all kinds of values and have analogous rules;
 refer to the \techreport{} for details.

The figure also defines three meta-functions: $\fmapref{\cdot}{\cdot}$,
$\fmapreplace{\cdot}{\cdot}{\cdot}$, and $\fmapupdate{\cdot}{\cdot}{\cdot}$.
The first gets an item from a finite map,
 the second replaces a blame heap entry,
 and the third extends a blame heap entry.
Because maps are sets, set union suffices to add new entries.

\begin{figure}[t]
  \begin{minipage}[t]{0.42\columnwidth}
    \lbl{\fbox{\Tname{} \sevallang{}}}{
      \begin{langarray}
        \eloc & \BNFeq    & % \locations
          \textrm{\scountable{} set of heap locations}
        \\
        \svalue & \BNFeq &
          \sint \mid \snat \mid \eloc
        \\
        \sprevalue & \BNFeq &
          {\efun{\svar}{\sexpr}}
          \mid {\efun{\tann{\svar}{\stype}}{\sexpr}}
          \mid {\epair{\svalue}{\svalue}}
        \\
        \sexpr & \BNFeq &
          \ldots \mid \eloc \mid \echecktwo{\stoptional}{\sexpr}{\eloc}
        \\
        \vstore & \BNFeq &
          \powerset{(\vrecord{\eloc}{\sprevalue})}
        \\
        \bstore & \BNFeq &
          \powerset{(\brecord{\eloc}{\sbset})}
        \\
        \vstoretype & \BNFeq &
          \snil \mid \fcons{\tann{\eloc}{\stoptional}}{\vstoretype}
      \end{langarray}
    }

  \end{minipage}\begin{minipage}[t][][c]{0.70\columnwidth}
    \vspace{-3mm}
    \begin{flushleft}\(\begin{array}[t]{l@{~~}c@{~~}l}
      \fmapref{\vstore_0}{\svalue_0} & \feq &
      \left\{\begin{array}{l@{\quad}l}
        \sprevalue_0 & \mbox{if $\svalue_0 \in \eloc$ and $(\vrecord{\svalue_0}{\sprevalue_0}) \in \vstore_0$}
        \\
        \svalue_0 & \mbox{if $\svalue_0 \not\in \eloc$}
      \end{array}\right.
      \\[4mm]
      \fmapref{\bstore_0}{\svalue_0} & \feq &
      \left\{\begin{array}{l@{\quad}l}
        \sbset_0 & \mbox{if $\svalue_0 \in \eloc$ and $(\brecord{\svalue_0}{\sbset_0}) \in \bstore_0$}
        \\
        \semptymap & \mbox{otherwise}
      \end{array}\right.
      \\[4mm]
      \fmapreplace{\bstore_0}{\svalue_0}{\sbset_0} & \feq &
      \left\{\begin{array}{l@{\quad}l}
        \zerowidth{\eset{\vrecord{\svalue_0}{\sbset_0}} \cup {(\bstore_0 \setminus (\vrecord{\svalue_0}{\sbset_1}))}}
        \\
        & \mbox{if $\svalue_0 \in \eloc$ and $(\vrecord{\svalue_0}{\sbset_1}) \in \bstore_0$}
        \\
        \bstore_0 & \mbox{otherwise}
      \end{array}\right.
      \\[6mm]
      \fmapupdate{\bstore_0}{\svalue_0}{\sbset_0} & \feq &
        \quad \fmapreplace{\bstore_0}{\svalue_0}{\bappend{\sbset_0}{\fmapref{\bstore_0}{\svalue_0}}}
  \end{array}\)\end{flushleft}

  \end{minipage}

  \lbl{\fbox{$\vstoretype; \stypeenv \sWTT \sexpr : \stag$} \missingrules{}}{\begin{mathpar} %  (selected rules)
%    \inferrule*{
%      \vstoretype_0; \fcons{\tann{\svar_0}{\stype_0}}{\stypeenv_0} \sWTT \sexpr_0 : \stag_0
%    }{
%      \vstoretype_0; \stypeenv_0 \sWTT \efun{\tann{\svar_0}{\stype_0}}{\sexpr_0} : \kfun
%    }
%
    \inferrule*{
      \vstoretype_0; \fcons{\tann{\svar_0}{\tdyn}}{\stypeenv_0} \sWTT \sexpr_0 : \tdyn
    }{
      \vstoretype_0; \stypeenv_0 \sWTT \efun{\svar_0}{\sexpr_0} : \kfun
    }

    \inferrule*{
      \vstoretype_0; \stypeenv_0 \sWTT \sexpr_0 : \stag_0
    }{
      \vstoretype_0; \stypeenv_0 \sWTT \echecktwo{\stype_0}{\sexpr_0}{\eloc_0} : \tagof{\stype_0}
    }

    \inferrule*{
      \vstoretype_0; \stypeenv_0 \sWTT \sexpr_0 : \tdyn
    }{
      \vstoretype_0; \stypeenv_0 \sWTT \echecktwo{\stype_0}{\sexpr_0}{\eloc_0} : \tagof{\stype_0}
    }

  \end{mathpar}}

  \medskip
  \lbl{\fbox{$\vstoretype; \stypeenv \sWTT \sexpr : \tdyn$} \missingrules{}}{\begin{mathpar} %  (selected rules)
    \inferrule*{
      \vstoretype_0; \fcons{\tann{\svar_0}{\tdyn}}{\stypeenv_0} \sWTT \sexpr_0 : \tdyn
    }{
      \vstoretype_0; \stypeenv_0 \sWTT \efun{\svar_0}{\sexpr_0} : \tdyn
    }

    \inferrule*{
      \vstoretype_0; \fcons{\tann{\svar_0}{\stype_0}}{\stypeenv_0} \sWTT \sexpr_0 : \stag_0
    }{
      \vstoretype_0; \stypeenv_0 \sWTT \efun{\tann{\svar_0}{\stype_0}}{\sexpr_0} : \tdyn
    }

    \inferrule*{
      \tann{\eloc_0}{\tdyn} \in \vstoretype_0
    }{
      \vstoretype_0; \stypeenv_0 \sWTT \eloc_0 : \tdyn
    }

  \end{mathpar}}

  \Description[Grammar, metafunctions, and typing judgments.]{A grammar
   defines heap locations, heap-allocated values, heaps, tag-check expressions,
   blame heaps, and heap typings. Four metafunctions help with heap references
   and updates. Two new typing judgments match an expression to a type tag.
  }
  \caption{\Tname{} language extensions and metafunctions}
  \label{fig:transient-language}
\end{figure}

%% -----------------------------------------------------------------------------
\subsubsection{\Tname{}}
The first rule allocates a new heap address for a pre-value:

\begin{rrpage}
  \rhsbox{-2pt}{\conf{\sexpr}{\vstore}{\bstore} \nredTX \conf{\sexpr}{\vstore}{\bstore}}
  \\[-2.5ex]
  \begin{inlinerrarray}
    \conf{\sprevalue_0}{\vstore_0}{\bstore_0}
    &  \nredTX
    &  \conf{\eloc_0}{(\eset{\vrecord{\eloc_0}{\sprevalue_0}} \cup \vstore_0)}{(\eset{\brecord{\eloc_0}{\semptymap}} \cup {\bstore_0})}
    \\\sidecond{where $\ffresh{\eloc_0}{\vstore_0\mbox{ and }\bstore_0}$}
  \end{inlinerrarray}
\end{rrpage}

A pair projection extracts a component from a (heap allocated) value.
Because projection is an elimination form, the next step is to tag-check the
 result against the expected type:

\begin{inlinerrarray}
  \conf{(\eunopt{\stype_0}{\svalue_0})}{\vstore_0}{\bstore_0}
    &  \nredTX
    &  \conf{\tagerrorS}{\vstore_0}{\bstore_0}
    \\\sidecond{if $\sdelta(\sunop, {\vstore_0(\svalue_0)})$ is undefined}
    \\
    \conf{(\eunopt{\tdyn}{\svalue_0})}{\vstore_0}{\bstore_0}
    &  \nredTX
    &  \conf{\tagerrorD}{\vstore_0}{\bstore_0}
    \\\sidecond{if $\sdelta(\sunop, {\vstore_0(\svalue_0)})$ is undefined}
    \\
    \conf{(\eunopt{\stoptional}{\eloc_0})}{\vstore_0}{\bstore_0}
    &  \nredTX
    &  \conf{(\echecktwo{\stoptional}{\sdelta(\sunop, \vstore_0(\eloc_0))}{\eloc_0})}{\vstore_0}{\bstore_0}
    \\\sidecond{if $\sdelta(\sunop, \vstore_0(\eloc_0))$ is defined}
\end{inlinerrarray}

Binary operations yield new integers, and therefore do not require result checks:

\begin{inlinerrarray}
  \conf{(\ebinopt{\stype_0}{\svalue_0}{\svalue_1})}{\vstore_0}{\bstore_0}
    &  \nredTX
    &  \conf{\tagerrorS}{\vstore_0}{\bstore_0}
    \\\sidecond{if \(\sdelta(\sbinop, \svalue_0, \svalue_1)\) is undefined}
    \\
    \conf{(\ebinopt{\tdyn}{\svalue_0}{\svalue_1})}{\vstore_0}{\bstore_0}
    &  \nredTX
    &  \conf{\tagerrorD}{\vstore_0}{\bstore_0}
    \\\sidecond{if \(\sdelta(\sbinop, \svalue_0, \svalue_1)\) is undefined}
    \\
    \conf{(\ebinopt{\toptional}{\sint_0}{\sint_1})}{\vstore_0}{\bstore_0}
    &  \nredTX
    &  \conf{\sdelta(\sbinop, \sint_0, \sint_1)}{\vstore_0}{\bstore_0}
    \\\sidecond{if \(\sdelta(\sbinop, \sint_0, \sint_1)\) is defined}
\end{inlinerrarray}

The application of a typed function first confirms the tag of the argument value
 against the domain of the function.
If they match, the rule:
 (1) extends the blame for the argument with reversed boundaries, to record the
 flow into the function;
 (2) substitutes the argument into the function body;
 and (3) guards the result expression with a codomain check for the expected type:

\begin{inlinerrarray}
    \conf{(\eapp{\stoptional}{\eloc_0}{\svalue_0})}{\vstore_0}{\bstore_0}
    &  \nredTX
    & \conf{(\echecktwo{\stoptional}{\esubst{\sexpr_0}{\svar_0}{\svalue_0}}{\eloc_0})}{\vstore_0}{\fmapupdate{\bstore_0}{\svalue_0}{\frev{\bstore_0(\eloc_0)}}}
    \\\sidecond{if $\fmapref{\vstore_{0}}{\eloc_0}=\efun{\tann{\svar_0}{{\stype_0}}}{\sexpr_0}$
                and $\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\end{inlinerrarray}

\noindent If the domain check fails, then \Tname{} reports a boundary error
containing $\svalue_0$ and the boundaries associated with the procedure
$\fmapref{\vstore_0}{\eloc_0}$:

\begin{inlinerrarray}
    \conf{(\eapp{\stoptional}{\eloc_0}{\svalue_0})}{\vstore_0}{\bstore_0}
    &  \nredTX
    & \conf{\boundaryerror{\fmapref{\bstore_0}{\eloc_0}}{\svalue_0}}{\vstore_0}{\bstore_0}
    \\\sidecond{if $\fmapref{\vstore_{0}}{\eloc_0}=\efun{\tann{\svar_0}{{\stype_0}}}{\sexpr_0}$
                and $\neg \fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\end{inlinerrarray}

The application of an untyped function in a typed context inserts a check that the function
 computes a value matching the expected type.  In anticipation of a possible check error, the
 rule updates the blame map:

\begin{inlinerrarray}
    \conf{(\eapp{\stype_0}{\eloc_0}{\svalue_0})}{\vstore_0}{\bstore_0}
    & \nredTX
    & \conf{(\echecktwo{\stype_0}{\esubst{\sexpr_0}{\svar_0}{\svalue_0}}{\eloc_0})}{\vstore_0}{\fmapupdate{\bstore_0}{\svalue_0}{\frev{\fmapref{\bstore_0}{\eloc_0}}}}
    \\\sidecond{if \(\fmapref{\vstore_{0}}{\eloc_0}=\efun{\svar_0}{\sexpr_0}\)}
\end{inlinerrarray}

\noindent In an untyped context, the reduction merely performs the required substitution:

\begin{inlinerrarray}
    \conf{(\eapp{\tdyn}{\eloc_0}{\svalue_0})}{\vstore_0}{\bstore_0}
    &  \nredTX
    & \conf{(\esubst{\sexpr_0}{\svar_0}{\svalue_0})}{\vstore_0}{\bstore_0}
    \\\sidecond{if \(\fmapref{\vstore_{0}}{\eloc_0}=\efun{\svar_0}{\sexpr_0}\)}
\end{inlinerrarray}

\noindent
Invalid applications signal a static or dynamic tag error, depending on the context:

\begin{inlinerrarray}
    \conf{(\eapp{\stype_0}{\svalue_0}{\svalue_1})}{\vstore_0}{\bstore_0}
    &  \nredTX
    & \conf{\tagerrorS}{\vstore_0}{\bstore_0}
    \\\sidecond{if \(\fmapref{\vstore_{0}}{\svalue_0} \not\in (\efun{\svar}{\sexpr}) \cup (\efun{\tann{\svar}{\stype}}{\sexpr})\)}
    \\
    \conf{(\eapp{\tdyn}{\svalue_0}{\svalue_1})}{\vstore_0}{\bstore_0}
    &  \nredTX
    & \conf{\tagerrorD}{\vstore_0}{\bstore_0}
    \\\sidecond{if \(\fmapref{\vstore_{0}}{\svalue_0} \not\in (\efun{\svar}{\sexpr}) \cup (\efun{\tann{\svar}{\stype}}{\sexpr})\)}
\end{inlinerrarray}

A $\sdyn$ boundary checks the tag of a value.
If successful, the value crosses the boundary and the blame map records the event.
Otherwise, the rule reports the current boundary:

\begin{inlinerrarray}
    \conf{(\edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})}{\vstore_0}{\bstore_0}
    & \nredTX
    & \conf{\svalue_0}{\vstore_0}{(\fmapupdate{\bstore_0}{\svalue_0}{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}})}
    \\\sidecond{if $\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
    \\
    \conf{(\edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})}{\vstore_0}{\bstore_0}
    & \nredTX
    & \conf{\boundaryerror{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}}{\svalue_0}}{\vstore_0}{\bstore_0}
    \\\sidecond{if $\neg\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\end{inlinerrarray}

A $\ssta$ boundary must check the tag of a value to guard against incorrect
 types.
If the type is incorrect, evaluation ends in a static tag error.

\begin{inlinerrarray}
    \conf{(\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})}{\vstore_0}{\bstore_0}
    & \nredTX
    & \conf{\svalue_0}{\vstore_0}{(\fmapupdate{\bstore_0}{\svalue_0}{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}})}
    \\\sidecond{if $\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
    \\
    \conf{(\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})}{\vstore_0}{\bstore_0}
    & \nredTX
    & \conf{\tagerrorS}{\vstore_0}{\bstore_0}
    \\\sidecond{if $\neg\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\end{inlinerrarray}

The rules for check expressions are similar to those for $\sdyn$ boundaries,
 but have additional information about the source of the target value.
A check for the dynamic type $\tdyn$ is a no-op:

\begin{inlinerrarray}
    \conf{(\echecktwo{\tdyn}{\svalue_0}{\eloc_0})}{\vstore_0}{\bstore_0}
    & \nredTX
    & \conf{\svalue_0}{\vstore_0}{\bstore_0}
\end{inlinerrarray}

\noindent
Any other check expression matches the value against the type.
If the check fails, the error reports the boundary information for both the
value and the $\eloc_0$ address because either set may contain the boundary at
the root of the issue:

\begin{inlinerrarray}
    \conf{(\echecktwo{\stype_0}{\svalue_0}{\eloc_0})}{\vstore_0}{\bstore_0}
    &  \nredTX
    & \conf{\svalue_0}{\vstore_0}{(\fmapupdate{\bstore_0}{\svalue_0}{\fmapref{\bstore_0}{\eloc_0}})}
    \\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}\)}
    \\
    \conf{(\echecktwo{\stype_0}{\svalue_0}{\eloc_0})}{\vstore_0}{\bstore_0}
    & \nredTX
    & \conf{\boundaryerror{\bappend{\fmapref{\bstore_0}{\svalue_0}}{\fmapref{\bstore_0}{\eloc_0}}}{\svalue_0}}{\vstore_0}{\bstore_0}
    \\\sidecond{if \(\neg \fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}\)}
\end{inlinerrarray}

%% -----------------------------------------------------------------------------
\subsection{\Aname{} Notions of Reduction} \label{sub:wrapper}

\Figref{fig:amnesic-language} adds monitors and trace wrappers to
 the base evaluation language, along with metafunctions to
 extend, inspect, and remove the trace history associated with a value.
During evaluation, \Aname{} limits the number of wrappers on a value
 by removing monitors when the value flows to an untyped component.
An originally-untyped value gets at most one trace and one temporary ``outer'' monitor.
An originally-typed value gets at most two monitors---one permanent ``inner''
 and one temporary ``outer''---and one trace.
Using the abbreviation $(\ehopt{\sbset}{\svalue})$ for an optionally-traced
 value (bottom of \figref{fig:amnesic-language}), these wrapped values
 match the following grammars during evaluation:

\medskip\hspace{-6mm}
\begin{array}[t]{ll}
\begin{array}[t]{lcl}
  \Astawrapper
   & \BNFeq & \emon{\sbnd}{(\ehopt{\sbset}{\epair{\svalue}{\svalue}})} \\[1pt]
   & \mid   & \emon{\sbnd}{(\ehopt{\sbset}{\efun{\svar}{\sexpr}})} \\[1pt]
   & \mid   & \emon{\sbnd}{(\ehopt{\sbset}{(\emon{\sbnd}{\epair{\svalue}{\svalue}})})} \\[1pt]
   & \mid   & \zerowidth{\emon{\sbnd}{(\ehopt{\sbset}{(\emon{\sbnd}{\efun{\tann{\svar}{\stype}}{\sexpr}})})}}
\end{array}
\begin{array}[t]{lcl}
  \Adynwrapper
  & \BNFeq & \ehist{\sbset}{\sint} \\
  & \mid & \ehist{\sbset}{\epair{\svalue}{\svalue}} \\
  & \mid & \ehist{\sbset}{\efun{\svar}{\sexpr}} \\
  & \mid & \ehopt{\sbset}{(\emon{\sbnd}{\epair{\svalue}{\svalue}})} \\
  & \mid & \ehopt{\sbset}{(\emon{\sbnd}{\efun{\tann{\svar}{\stype}}{\sexpr}})}
\end{array}
\end{array}
\smallskip

\noindent The number of boundaries in a trace may grow without bound.

\begin{figure}[t]
  \begin{minipage}[t]{0.4\columnwidth}
  \lbl{\fbox{\Aname{} \sevallang{}}}{
    \begin{langarray}
      \svalue & \BNFeq &
        \snat
        \mid \sint
        \mid \epair{\svalue}{\svalue}
        \mid \efun{\svar}{\sexpr}
        \mid \efun{\tann{\svar}{\stype}}{\sexpr}
        \mid
      \\ & &
        \emon{\sbnd}{\svalue}
        \mid \etrace{\sbset}{\svalue} \mid u
      \\
      \sexpr & \BNFeq &
        \ldots
        \mid \emon{\sbnd}{\svalue}
        \mid \etrace{\sbset}{\svalue} \mid
      \\
      & & \esuffix{\sbset}{\sexpr}
    \end{langarray}
  }

  \bigskip
  \lbl{\fbox{$\stypeenv \sWTA \sexpr : \stype$} \missingrules{}}{\begin{mathpar}
    \inferrule*{
      \stypeenv_0 \sWTA \svalue_0 : \tdyn
    }{
      \stypeenv_0 \sWTA \emon{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0} : \stype_0
    }
  \end{mathpar}}

  \end{minipage}\begin{minipage}[t][][c]{0.6\columnwidth}
    \vspace{-3mm}
    \begin{flushleft}\(\begin{array}[t]{l@{~}c@{~}l}
    \faddtrace{\sbset_0}{\svalue_0} & \feq &
     \left\{\begin{array}{ll}
        \svalue_0
        \\ & \mbox{if $\sbset_0 \eeq \emptyset$}
        \\
        \zerowidth{\ehist{(\sbset_0 \cup \sbset_1)\,}{\svalue_1}}
        \\ & \mbox{if $\svalue_0 \eeq \ehist{\sbset_1}{\svalue_1}$}
        \\
        \zerowidth{\ehist{\sbset_0}{\svalue_0}}
        \\ & \mbox{if $\svalue_0 \not\in \ehist{\sbset}{\svalue}$ and $\sbset_0 \neq \emptyset\!\!\!\!$}
      \end{array}\right.
      \\[13mm]
    \fgettrace{\svalue_0} & \feq &
      \left\{\begin{array}{ll}
        \sbset_0
        & \mbox{if $\svalue_0 \eeq \ehist{\sbset_0}{\svalue_1}$}
        \\
        \emptyset
        & \mbox{if $\svalue_0 \not\in \ehist{\sbset}{\svalue}$}
      \end{array}\right.
      \\[5mm]
    \fremtrace{\svalue_0} & \feq &
      \left\{\begin{array}{ll}
        \svalue_1
        & \mbox{if $\svalue_0 \eeq \ehist{\sbset_0}{\svalue_1}$}
        \\
        \svalue_0
        & \mbox{if $\svalue_0 \not\in \ehist{\sbset}{\svalue}$}
      \end{array}\right.
  \end{array} \) \end{flushleft}
  \end{minipage}

  \lbl{\fbox{$\tenv \sWTA \sexpr : \tdyn$} \missingrules{}}{\begin{mathpar}
    \inferrule*{
      \tenv_0 \sWTA \svalue_0 : \stype_0
    }{
      \stypeenv_0 \sWTA \emon{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0} : \tdyn
    }

    \inferrule*{
      \tenv_0 \sWTA \svalue_0 : \tdyn
    }{
      \stypeenv_0 \sWTA \ehist{\sbset_0}{\svalue_0} : \tdyn
    }

    \inferrule*{
      \tenv_0 \sWTA \sexpr_0 : \tdyn
    }{
      \stypeenv_0 \sWTA \esuffix{\sbset_0}{\sexpr_0} : \tdyn
    }
  \end{mathpar}}

  \bigskip
  \lbl{~}{\(\quad
    (\ehopt{\sbset_0}{\svalue_1}) \eeq \svalue_0 \sabbreveq
        \mbox{$\fremtrace{\svalue_0} \eeq \svalue_1$ and $\fgettrace{\svalue_0} \eeq \sbset_0$}
  \)}

  \Description[Grammar, metafunctions, and typing judgments.]{A grammar adds
    monitor values, trace values, and trace expressions. Three metafunctions
    add, get, and remove a trace around a value. Two typing judgments accomodate
    monitor and trace wrappers. Lastly, there is an abbreviation for optionally-traced
    values.
  }
  \caption{\Aname{} language extensions, metafunctions, and $\ehopt{\!}{\!}$ abbreviation}
  \label{fig:amnesic-language}
\end{figure}

\subsubsection{\Aname{}, Statically-Typed}

Two groups of rules handle primitive operations.
One group applies the $\sdelta$ metafunction:

\begin{rrpage}
  \rhsbox{2pt}{\sexpr \nredAS \sexpr}
  \\[-2ex]
\begin{inlinerrarray}
  \eunopt{\stype_0}{\svalue_0}
    &  \nredAS
    &  \tagerrorS
    \\\sidecond{if \(\svalue_0 \not\in (\emon{\obnd{\sowner}{(\tpair{\stype}{\stype})}{\sowner}}{\svalue})\)
                and \(\sdelta(\sunop, {\svalue_0})\) is undefined}
    \\[0.3ex]
    \eunopt{\stype_0}{\svalue_0} &  \nredAS &  \sdelta(\sunop, {\svalue_0})
    \\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is defined}
    \\[0.3ex]
    \ebinopt{\stype_0}{\svalue_0}{\svalue_1}
    &  \nredAS
    &  \tagerrorS
    \\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is undefined}
    \\[0.3ex]
    \ebinopt{\stype_0}{\svalue_0}{\svalue_1}
    &  \nredAS
    &  \sdelta(\sbinop, \svalue_0, \svalue_1)
    \\\sidecond{if \(\sdelta(\sbinop, \svalue_0, \svalue_1)\) is defined}
\end{inlinerrarray}
\end{rrpage}

\noindent
The other group handles monitored pair values:

\begin{inlinerrarray}
  \efst{\stype_0}{(\emon{\obnd{\sowner_0}{(\tpair{\stype_1}{\stype_2})}{\sowner_1}}{\svalue_0})}
      &  \nredAS
      &  \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{(\efst{\tdyn}{\svalue_0})}
      \\[0.3ex]
      \esnd{\stype_0}{(\emon{\obnd{\sowner_0}{(\tpair{\stype_1}{\stype_2})}{\sowner_1}}{\svalue_0})}
      &  \nredAS
      &  \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{(\esnd{\tdyn}{\svalue_0})}
\end{inlinerrarray}

\noindent
The projection of an element from a monitored pair creates a boundary
term to check the untyped value.
The new boundary uses the annotation $\stype_0$ from the operator,
 exactly like \Tname{}.
Type $\stype_0$ may be weaker than the corresponding type in the monitor,
 but this weaker guarantee is all that the context explicitly relies on.

An invalid application in typed code yields a tag error:

\begin{inlinerrarray}
  \eapp{\stype_0}{\svalue_0}{\svalue_1}
  & \nredAS
  & \tagerrorS
  \\\sidecond{if $\svalue_0 \not\in (\efun{\tann{\svar}{\stype}}{\sexpr}) \cup (\emon{\sbnd}{\svalue})$}
\end{inlinerrarray}

\noindent
The application of an un-monitored function proceeds by substitution:

\begin{inlinerrarray}
  \eapp{\stype_0}{(\efun{\tann{\svar_0}{{\stype_1}}}{\sexpr_0})}{\svalue_0}
  &  \nredAS
  &  \esubst{\sexpr_0}{\svar_0}{\svalue_0}
\end{inlinerrarray}

\noindent
The application of a monitored function unfolds into two boundaries:

\begin{inlinerrarray}
  \eapp{\stype_0}{(\emon{\obnd{\sowner_0}{(\tfun{\stype_1}{\stype_2})}{\sowner_1}}{(\svalue_0)})}{\svalue_1}
      &  \nredAS
      &  \edynb{\sbnd_0}{(\eapp{\tdyn}{\svalue_0}{(\estab{\sbnd_1}{\svalue_1})})}
      \\\sidecond{where \(\sbnd_0 \sassign \obnd{\sowner_0}{\stype_0}{\sowner_1}\)
                  and \(\sbnd_1 \sassign \obnd{\sowner_1}{\stype_1}{\sowner_0}\)}
\end{inlinerrarray}

\noindent
One boundary protects the argument
 using the domain type $\stype_1$ from the monitor,
 and the other validates the result using the type annotation $\stype_0$ from
 the application.
As with monitored pairs, the annotation $\stype_0$ may be weaker
 than the monitor's type $\stype_2$ but suffices for the context.

Lastly, the rules for $\sdyn$ boundaries demonstrate \Aname{}'s first-order
 type-enforcement strategy.
If an untyped function or pair reaches a matching boundary, the following rule
 creates a new monitor without checking the elements of a pair:

\begin{inlinerrarray}
       \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
      &  \nredAS
      &  \emon{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
      \\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\svalue_0}\)
                  and \(\fremtrace{\svalue_0} \in (\efun{\svar}{\sexpr}) \cup \epair{\svalue}{\svalue} \cup (\emon{\sbnd}{\svalue})\)}
\end{inlinerrarray}

\noindent
Base values are permitted to flow to the client context if they match the
boundary type.
The rule removes any trace wrapper because the match fully checks the type:

\begin{inlinerrarray}
       \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{(\ehopt{\sbset_0}{\sint_0})}
      &  \nredAS
      &  \sint_0
      \\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\sint_0}\)}
\end{inlinerrarray}

\noindent
If a value reaches an incompatible boundary, then \Aname{} reports both the
current boundary and any boundaries in the value's trace:

\begin{inlinerrarray}
       \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
      &  \nredAS
      &  \boundaryerror{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}} \cup \sbset_0}{\fremtrace{\svalue_0}}
      \\\sidecond{if \(\neg\fshallow{\ftagof{\stype_0}}{\svalue_0}\)
                  and \(\sbset_0 \eeq \fgettrace{\svalue_0}\)}
\end{inlinerrarray}

\subsubsection{\Aname{}, Dynamically-Typed}

Trace-wrapped expressions and values can appear (only) in dynamically-typed contexts;
 thus every rule needs to handle possibly-traced values.

The first rule merges a trace expression onto a value:

\begin{rrpage}
  \rhsbox{1pt}{\sexpr \nredAD \sexpr}
  \\[-1.7ex]
  \begin{inlinerrarray}
       \eprehist{\sbset_0}{\svalue_0} &  \nredAD & \faddtrace{\sbset_0}{\svalue_0}
  \end{inlinerrarray}
\end{rrpage}

For un-monitored pairs, \Aname{} applies $\sdelta$ to project an element and
 propagates the trace boundaries from the pair onto the element:

\begin{inlinerrarray}
  \eunopt{\tdyn}{\svalue_0}
      & \nredAD
      & \tagerrorD
      \\\sidecond{where $\svalue_1 \sassign \fremtrace{\svalue_0}$
                  and $\svalue_1 \not\in {(\emon{\obnd{\sowner}{\tpair{\stype}{\stype}}{\sowner}}{\svalue})}$
                  and $\sdelta(\sunop, \svalue_1)$ is undefined}
      \\[0.3ex]
      \eunopt{\tdyn}{\svalue_0}
      & \nredAD
      & \faddtrace{\fgettrace{\svalue_0}}{\sdelta(\sunop, {\svalue_1})}
      \\\sidecond{where $\svalue_1 \sassign \fremtrace{\svalue_0}$
                  and $\sdelta(\sunop, {\svalue_1})$ is defined}
\end{inlinerrarray}

\noindent
Binary operations compute a new value, so traces on the inputs are
 irrelevant to the result:

\begin{inlinerrarray}
  \ebinopt{\tdyn}{\svalue_0}{\svalue_1}
      & \nredAD
      & \tagerrorD
      \\ \sidecond{if \(\sdelta(\sbinop, \fremtrace{\svalue_0}, \fremtrace{\svalue_1})\) is undefined}
      \\[0.3ex]
       \ebinopt{\tdyn}{\svalue_0}{\svalue_1}
      & \nredAD
      & \sdelta(\sbinop, {\svalue_2}, {\svalue_3})
      \\\sidecond{where $\svalue_2 \sassign \fremtrace{\svalue_0}$
                  and $\svalue_3 \sassign \fremtrace{\svalue_1}$
                  and $\sdelta(\sbinop, {\svalue_2}, {\svalue_3})$ is defined}
\end{inlinerrarray}

The projection of an element from a monitored pair creates a new boundary
 that protects the element using the type from the monitor.
The trace of the element is extended with the trace (if any) from the pair:

\begin{inlinerrarray}
  \efst{\tdyn}{(\ehopt{\sbset_0}{(\emon{\obnd{\sowner_0}{(\tpair{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0})})}
      &  \nredAD
      &  \eprehist{\sbset_0}{(\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{(\efst{\stype_0}{\svalue_0})})}
      \\[0.3ex]
       \esnd{\tdyn}{(\ehopt{\sbset_0}{(\emon{\obnd{\sowner_0}{(\tpair{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0})})}
      &  \nredAD
      &  \eprehist{\sbset_0}{(\estab{\obnd{\sowner_0}{\stype_1}{\sowner_1}}{(\esnd{\stype_1}{\svalue_0})})}
\end{inlinerrarray}

For un-monitored functions, \Aname{} propagates the function's trace to both the
result and the argument value.
The boundaries around the latter are reversed because the argument flows into
the function body:

\begin{inlinerrarray}
       \eapp{\tdyn}{(\ehopt{\sbset_0}{(\efun{\svar_0}{\sexpr_0})})}{\svalue_0}
      &  \nredAD
      &  \eprehist{\sbset_0}{(\esubst{\sexpr_0}{\svar_0}{\svalue_1})}
      \\\sidecond{where \(\svalue_1 \sassign \faddtrace{\frev{\sbset_0}}{\svalue_0}\)}
\end{inlinerrarray}

\noindent
For monitored functions, the argument aquires the monitor's reversed trace information
 and is validated against the domain of the monitor's type.
The result of a monitored application is protected using the monitor's codomain
 and its trace is extended.

\begin{inlinerrarray}
  \eapp{\tdyn}{(\ehopt{\sbset_0}{(\emon{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})})}{\svalue_1}
      &  \nredAD
      &  \eprehist{\sbset_0}{(\estab{\sbnd_0}{(\eapp{\stype_2}{\svalue_0}{(\edynb{\sbnd_1}{\svalue_2})})})}
      \\\sidecond{where \(\stype_0 \eeq \tfun{\stype_1}{\stype_2}\)
                  and \(\sbnd_0 \sassign \obnd{\sowner_0}{\stype_2}{\sowner_1}\)
                  and \(\sbnd_1 \sassign \obnd{\sowner_1}{\stype_1}{\sowner_0}\)}
      \\\sidecond{and \(\svalue_2 \sassign \faddtrace{\frev{\sbset_0}}{\svalue_1}\)}
\end{inlinerrarray}

\noindent
Applying any other kind of value to an argument results in a tag error:

\begin{inlinerrarray}
      \eapp{\tdyn}{\svalue_0}{\svalue_1}
      & \nredAD
      & \tagerrorD
      \\\sidecond{if $\svalue_0 \not\in (\efun{\svar}{\sexpr}) \cup (\emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\svalue})$}
\end{inlinerrarray}

When a statically-typed function or pair flows to an untyped context for the first time,
 \Aname{} creates a new monitor (to protect either the function, or functions
 within the pair):

\begin{inlinerrarray}
       \estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
      &  \nredAD
      & \emon{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
      \\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\svalue_0}\) and \(\svalue_0 \in {(\efun{\tann{\svar}{{\stype}}}{\sexpr})} \cup {\epair{\svalue}{\svalue}}\)}
\end{inlinerrarray}

\noindent
When a monitored value flows to an untyped component, \Aname{} replaces
 the monitor wrapper with a trace wrapper.
If the monitored value is an untyped function or pair, then it flows
 un-monitored back to the untyped client.
If the value is a monitored-and-typed function or pair, then it retains its
 inner monitor:

\begin{inlinerrarray}
  \estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{(\emon{\sbnd_1}{\svalue_0})}
      &  \nredAD
      &  \eprehist{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}, \sbnd_1}}{\svalue_0}
      \\\sidecond{if $\fshallow{\tagof{\stype_0}}{(\emon{\sbnd_1}{\svalue_0})}$}
\end{inlinerrarray}

\noindent
Typed base values may flow to untyped clients.
Any other $\ssta$ boundary contradicts static typing:

\begin{inlinerrarray}
       \estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\sint_0}
      &  \nredAD
      &  \sint_0
      \\\sidecond{if $\fshallow{\tagof{\stype_0}}{\sint_0}$}
      \\
       \estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
      &  \nredAD
      &  \tagerrorS
      \\\sidecond{if $\neg\fshallow{\tagof{\stype_0}}{\svalue_0}$}
\end{inlinerrarray}

%% -----------------------------------------------------------------------------
\subsection{From Notions of Reduction to Semantics} \label{sec:reduction-lifting}

Aside from the global heaps in \Tname{}, the standard operations of
 compatible closure ($\rrarrow_{\mathsf{\xsym}}$)
 and reflexive-transitive closure ($\rredX$)
 suffice to define three reduction relations;
 refer to a standard text for background
 or the \techreport{} for details:

\smallskip\(
 \hfill
 \rredN ~~~~~=~~~~~ \rrarrow^{*}_{(\nredNS \cup\, \nredND)}
 \qquad\qquad\quad
 \rredT ~~~~~=~~~~~ \rrarrow^{*}_{\nredTX}
 \qquad\qquad\quad
 \rredA ~~~~~=~~~~~ \rrarrow^{*}_{(\nredAS \cup\, \nredAD)}
 \hfill
\)\smallskip

%    \fdiverge{\sexpr_0}{\rredX} & \forall\,\sexpr_1~.~\sexpr_0 \rredX \sexpr_1 \implies \exists\,\sexpr_2~.~\sexpr_1 \credX \sexpr_2

To enable uniform statements about the reduction relations,
 let $\scriptstyle\mathsf{\xsym}$ range over the set $\scriptstyle\eset{\mathsf{\nsym}, \mathsf{\tsym}, \mathsf{\asym}}$
 and let $\sexpr_0 \rredT \sexpr_1$ iff there exists maps $\vstore_1$ and $\bstore_1$
 such that $\conf{\sexpr_0}{\semptymap}{\semptymap} \rredT \conf{\sexpr_1}{\vstore_1}{\bstore_1}$
 is defined.
In this manner, the term $\sexpr_0 \rredX \sexpr_1$ has meaning for each of
 the three reduction relations.
Similarly, we write $\stypeenv_0 \sWTT \sexpr_0 : \stag_0$
 rather than $\vstoretype_0; \stypeenv_0 \sWTT \sexpr_0 : \stag_0$
 when the heap typing is clear from context.

A reduction relation diverges on an expression,
 written ``$\fdiverge{\sexpr_0}{\rredX}$,'' if there is an infinite chain
 $\sexpr_0 \rrarrow_{\mathsf{\xsym}} \sexpr_1 \rrarrow_{\mathsf{\xsym}} \cdots$
 of reductions starting from $\sexpr_0$ (or $\conf{\sexpr_0}{\semptymap}{\semptymap}$ for \Tname{}).


% !TEX root=/home/tavant/these/manuscript/src/manuscript.tex

\section{Conclusion}
  Azimuthal instabilities have been observed in the \ac{PIC} simulations presented here, as well as by several groups of the community \citep{hara2019a,janhunen2018,taccogna2019}.
  As their nature remains unclear, we investigated in this chapter the \ac{PIC} simulation results in order to obtain more insights on their nature and their behavior.
  The theoretical dispersion relations for the \ac{ECDI} and the \ac{IAW} have been used in both their simplified and general forms.
  The general form of the dispersion relation uses the particle velocity distribution function directly measured in the \ac{PIC} simulations.
  The solver develop and used used is presented in \cref{sec-DR-solver}.

  At the beginning, the resonances typical of the \ac{ECDI} are observed.
  After about $0.7\,\micro\second$, they disappear, evolving towards the \ac{IAW} dispersion relation.
  However, we show that the evolution from the \ac{ECDI} to the \ac{IAW}  is not due to the larger radial wavenumber, as we observe no radial pattern in the simulation.
  Instead, it might be due to non-linear resonance broadening and electron demagnetization.

  \vspace{1ex}
  We also observed low frequency modulations of the amplitude of the instability.
  This oscillation is believed to be driven by the ion dynamic of the ion-wave trapping.
  Indeed, the oscillation period is of the order of $\tau=1.5\,\micro\second$, which is four times the ion bouncing period.

  The oscillation of the growth rate is also observed with the dispersion relation when the ion temperature is used and that ions are supposed Maxwellian.
  However, when the ion velocity distribution function measured in the \ac{PIC}  simulation is used, the growth rate stays almost constant, with small oscillations.
  The growth rate in the simulation is estimated with the wave equation.
  The measured growth rate is in better agreement with the dispersion relation assuming Maxwellian distribution function, compared to the one using the VDF measured int he PIC simulation.

  The origin of the discrepancy is unclear, as there are several possible reason.
  Firstly, to obtain the dispersion relations used here, we assumed small oscillations.
  However, the quasi-steady state is governed by non-linear phenomena, which probably have an affect the dispersion relation.
  Secondly, the estimation of the growth rate in the simulation uses a crude estimation of impact of the axial direction and the convection model on the wave.
  Lastly, the general dispersion relation solver use here has not been validated with distribution functions of complex shape, as the one observed in \cref{fig-ivdfs_pic_time}.
  A proper cross-validation with other solvers using complex distribution function is needed to confirm the result obtained.
  Another approach for the dispersion relation solver is to fit the VDF using a sum of analytic functions.
  Usually, one or few simple distribution functions are used, such as done by \citet{ronnmark1982}.
  A general algorithm finding the best fit in a large ensemble of analytic functions could be used to analyze more complex distribution function as the one observed here in the PIC simulation.

  \vspace{1ex}
  The results observed here are globally similar with the other simulation results of the community discussed in \cref{subsec-indroECDI}.
  However, some differences remain, in particular during the non-linear stage.
  In order to conclude on the origins of the discrepancies, a precise comparison between the simulation codes and the parameters used will be conducted.
  A Benchmark is currently in construction, to compare some of these codes on the radial-azimuthal geometry similarly to the work done on the axial-azimuthal domain \citep{charoy2019}.


\chapter{Abstrations of Jaseci}
\section{Graphs, the Friend that Never Gets Invited to the Party}
There's something quite strange that has happend with our \gls{common languages} over the years, ...decades. When you look at it, almost every data structure we programmers use to solve problems can be modeled formally as a graph, or a special case of a graph, (save perhaps hash tables). Think about it, stacks, lists, queues, trees, heaps, and yes, even graphs, can be modeled with graphs. But, low and behold, no common language ustilizes the formal semantics of a graph as its first order abstraction for data or memory. I mean, isn't it a bit odd that practically every data structure covered in the language-agnostic classic foundational work \textit{Introduction to Algorithms}~\cite{intro_to_algo} can most naturally be be reasoned about as a graph, yet none of the common languages have built in and be designed around this primitive. I submit that the graph semantic is stupidly rich, very nice for us humans to reason about, and, most importantly for the purpose of Jaseci, is inherently well suited for the conceptualization and reasoning about computational problems, especially AI problems.
\par
There are a few arguments that may pop into mind at this point of my conjecture.
\begin{itemize}
    \item ``Well there are graph libraries in my favorite language that implement graph symantics, why would I need a language to force the concept upon me?''
          or
    \item ``Duh! Interacting with all data and memory through graphical abstractions will make the language ssllooowww as hell since memory in hardware is essitially a big array, what is this dude talking about!?!?''
\end{itemize}
\par
For the former of these two challenges, I counter with two points. First, the core design languages are always based upon their inherent abstractions. With graphs not being one such abstraction, the language's design will not be optimized to empower programmers to nimbly do gymnastics with the rich language symantics that correspond to the rich semantics graphs offer (You'll see what I mean in later chapters). And second, libraries suck (See~\ref{rant:librariessuck}).
\par
For the latter question, I'd respond, ``Have you SEEN the kind of abstractions in modern languages!?!? It's rediculous, lets look at python dictionaries, actually scratch that, lets keep it simple and look at dynamic typing in general. The runtime complexity to support dynamic typing is most certainly hgiher than what would be needed to support graph symantics. Duh right back at'ya!''
\subsection{Yes, But What Kind of Graphs}

There are many categories of graphs to consider when thinking about the abstractions to support in Jaseci. There are rules to be defined as to the availabe semantics of the graphs. Should all graphs be \gls{directed graphs}, should we allow the creation of \gls{undirected graphs}, what about parallel edges or \gls{multigraphs}, are those explicitly expressible or discouraged / banned, can we express \gls{hypergraphs}, and what combination of these graphical sematics should be able to be manifested and manipulated through the programming model. At this point I can feel your eyes getting droopy and your mind moving into that intermediary state between concious and sleeping, so let me cut to the answer.
\par
\printfigGraphTypes
In Jaseci, we elect to assume the following semantics:
\begin{enumerate}
    \item Graphs are directed (as per Figure~\ref{fig:directedgraph}) with a special case of a doubly directed edge type which can be utilized practically as an undirected edge (imagine fusing the two edges between nodes 3 and 4 in the figure).
    \item Both nodes and edges have their own distinct identities (i,e. an edge isn't representable as a pairing of two nodes). This point is important as both nodes and edges can have \gls{contexts}.
    \item Multigraphs (i.e., parallel edges) are allowed, including self-loop edges (as per Figure~\ref{fig:multigraph}).
    \item Graphs are not required to be acyclic.
    \item No hypergraphs, as I wouldn't want Jaseci programmers heads to explode.

\end{enumerate}
\emph{As an aside, I would describe Jaseci graphs as strictly unstrict directed multigraphs that leverages the semantics of parallel edges to create a laymans `undirected edge' by shorthanding two directed edges pointed in opposite directions between the same two nodes.}
\par
\begin{nerd}
    I'd formally describe a Jaseci Graph as an $7$-tuple $(N,E,C,s,t,c_N,c_E)$, where
    \begin{enumerate}
        \item $N$ is the set of nodes in a graph
        \item $E$ is the set of edges in a graph
        \item $C$ is the set of all contexts
        \item $s$: $E \rightarrow V$, maps the source node to an edge
        \item $t$: $E \rightarrow V$,  maps the target node to an edge
        \item $c_N$: $N \rightarrow C$, maps nodes to contexts
        \item $c_E$: $E \rightarrow C$, maps edges to contexts
    \end{enumerate}
    An undriected edge can then be formed with a pair of edges $(x, y)$ if three conditions are met,
    \begin{enumerate}
        \item $x, y \in E$
        \item $s(x) = t(y)$, and $s(y) = t(x)$
        \item $c_E(x) = c_E(y)$
    \end{enumerate}
\end{nerd}
\par
If you happend to have read that formal definition and didn't enter deep comatose you may be wondering ``Whoa, what was that context stuff that came outta nowhere! What's this guy trying to do here, sneaking a new concept in as if it was already introduced and described.''
\par
Worry not friend, lets discuss.
\subsection{Putting it All Into Context}

A key principle of Jaseci is to reshape and reimagine how we view data and memory. We do so by fusing the concept of data wit the intuitive and rich semantics of graphs as the lowest level primitive to view memory.

\begin{nerd}
    A context is a representation of data that can be expressed simply as a $3$-tuple $(\sum_K,\sum_V,p_K)$, where
    \begin{enumerate}
        \item $\sum_K$ is a finite alphabet of keys
        \item $\sum_V$ is a finite alphabet of values
        \item $p_K$ is the pairing of keys to values
    \end{enumerate}
\end{nerd}
\section{Walkers}
\section{Abilities}
\section{Other Abstractions Not Yet Actualized in Current Jaseci}


\documentclass[12pt]{article}
\pagestyle{empty}
\usepackage[margin=1in]{geometry}

\newcommand{\half}{{\ensuremath\textstyle\frac12}}
\newcommand{\subsub}[2]{{\ensuremath{#1}_{_{{#2}}}}}

\begin{document}

\section*{Energy Bookkeeping in the AMUSE Multiples Module}

The basic sequence of events in managing a multiple interaction is as
follows:

\begin{enumerate}

\item A pair of stars is identified as interacting in the top-level
  ``gravity'' dynamical code.  Optionally, the multiples module may
  include other top-level neighbors in the interaction.

\item All top-level stars involved are removed from the gravity code.
  If indices $I$ and $J$ count top-level objects in the interaction
  and $K$ refers to other top-level objects, then the energy removed
  from the gravity code is
  $$
	\Delta E_{rem} = E_0 + \phi_{rem},
  $$
  where
  $$
	E_0 = \half\sum_I\,\subsub{m}{I}\subsub{v}{I}^2
		 ~+~ \sum_I\sum_{J>I}\subsub{\phi}{IJ}
  $$
  is the total internal energy of the interacting subsystem,
  $$
	\subsub{\phi}{IJ} = -\frac{G\subsub{m}{I}\subsub{m}{J}}
				  {\subsub{r}{IJ}}\,,
  $$
  and
  $$
	\phi_{rem} = -\sum_I\sum_K\,\subsub{\phi}{IK}
  $$
  is the external potential on the subsystem due to the rest of the
  top-level stars.  The interacting stars are subsequently integrated
  as an isolated small-N system.

\item The subsystem is given substructure by restoring the binary
  information stored in the multiples data structure.  Let $E_{mul,I}$
  be the total internal energy associated with the initial top-level
  object $I$.  Then, when the internal structure is reinstated, the
  new energy of the interacting subsystem is
  $$
	E_1 = E_0 + \sum_I\,E_{mul,I} + \Delta\phi_1,
  $$
  where
  $$
	\Delta\phi_1 = \sum_I\sum_{i\in I}\sum_{j\in J>I}\,
						\subsub{\phi}{ij}
			- \sum_I\sum_{J>I}\subsub{\phi}{IJ}
  $$
  is the tidal potential energy change associated with resolving all
  multiples.  Here, indices $i$ and $j$ range over ``leaf'' stars in
  the subsystem, and the notation $i\in I$ means that leaf $i$ is part
  of top-level node $I$.  Note that $\Delta\phi_1$ includes only
  potentials between leaves in different top-level nodes.  Potentials
  between leaves in the same node $I$ are included in $E_{mul,I}$.  In
  a scattering experiment, $\Delta\phi_1$ is minimized by expanding
  the top-level system to ``scattering'' distance before reinstating
  the binary substructure.  We do not calculate it directly in
  practice, although it useful to retain it for purposes of
  discussion.

\item We run the interacting subsystem to completion as a scattering
  experiment.  The energy of the subsystem at the end is
  $$
	E_2 = E_1 + \Delta E_{int},
  $$
  where $\Delta E_{int}$ is the (normally small) integration error
  associated with the small-N integrator.

\item We then reclaim and remove all stable multiples, leaving us with
  a new top-level energy of the interacting subsystem
  $$
	E_3 = E_2 - \sum_F\,E_{mul,F} - \Delta\phi_2,
  $$
  where $E_{mul,F}$ is as defined above, with the sum now running over
  the top-level particles in the final configuration, and
  $\Delta\phi_2$ is defined analogously to $\Delta\phi_1$.

\item The top-level system is then rescaled at constant energy $E_3$
  back into a volume comparable to that of the initial interaction.
  Binary nodes that are too large are removed and corrected for at
  this point, modifying $E_3$, $E_{mul}$, and $\Delta\phi_2$.

\item Finally, the top-level nodes are reinserted into the gravity
  module.  The total energy added is
  $$
	\Delta E_{ins} = E_3 + \phi_{ins},
  $$
  where $\phi_{ins}$ is defined analogously to $\phi_{rem}$.

\end{enumerate}

Thus the total energy change in the top-level system due to the entire
sequence of events just outlined is
\begin{eqnarray*}
	\Delta E_{top} &=& \Delta E_{ins} - \Delta E_{rem} \\
		      &=& \phi_{ins} - \phi_{rem}
				+ \sum_I\,E_{mul,I} - \sum_F\,E_{mul,F}
 				+ \Delta\phi_1 - \Delta\phi_2
				+ \Delta E_{int} \\
		      &=& \Delta\phi_{top} - \Delta E_{mul}
 				+ \Delta\phi_1 - \Delta\phi_2
				+ \Delta E_{int},
\end{eqnarray*}
so, in terms of the total energies associated with the gravity and
small-N modules,
$$
	\Delta\left(E_{top}+E_{mul}\right)
		= \Delta\phi_{top} + \Delta\phi_1 - \Delta\phi_2
				  + \Delta E_{int},
$$
where all the terms on the right-hand side are tidal corrections or
integration errors and are (in principle) small.  We currently adopt
the strategy of simply accumulating and monitoring the sum of the
tidal terms, as
$$
	\phi_{tidal} = \sum_{encounters}\left(\Delta\phi_{top}
					    + \Delta\phi_1
					    - \Delta\phi_2\right),
$$
in which case the quantity
$$
	E_{top} + E_{mul} - \phi_{tidal}
$$
should be conserved, up to integration errors in the top-level and
small-N modules.

Assuming that all bookkeeping is done correctly, we can determine the
internal tidal terms from
$$
	\Delta\phi_1 - \Delta\phi_2 = E_3 - E_0 + \Delta E_{mul}
						- \Delta E_{int}.
$$
We monitor this quantity to ensure that it is small, as expected.

\end{document}


%\subsection{Simulation Results Using a Single %Agent}\label{subsec:SingleAgentSingleSourceResults}
For the subsequent discussion, we use the abbreviations TTD: Time To Decision, SD: Standard Deviation, FPR: False Positive Rate, FNR: False Negative Rate.

\subsection{Varying the initial distribution of the agent belief}\label{subsubsec:VaryingPriorShape}
\input{Chapters/MultiAgentTargetDetection/Results/VaryingPrior.tex}
\break

\subsection{Varying cumulative initial belief that the target is present}\label{subsubsec:VaryingPriorCumulative}
\input{Chapters/MultiAgentTargetDetection/Results/VaryingInitialBeliefPresent.tex}
\break

\subsection{Varying sensor model parameters}\label{subsubsec:MicalibratedSensor}
\input{Chapters/MultiAgentTargetDetection/Results/MicalibratedSensor.tex}
\break

\subsection{Varying number of targets present in the region}\label{subsubsec:VaryingNoTargets}

%\input{Chapters/MultiAgentTargetDetection/Results/MultipleTargetResults.tex}
%\break

\input{Chapters/MultiAgentTargetDetection/Results/MultipleTargetResultsPortrait.tex}
\break


\SecDef{intro}{Introduction}

In the traditional symmetric cryptography, an adversary has access only to the inputs and outputs of a cryptographic primitive. This model is called the \emph{black-box} model. Relaxation of this model is called \emph{grey-box} and in it attacker may also obtain side-channel or fault information from the cryptographic implementation.
In the extreme \emph{white-box} model the adversary is given full access to the implementation which contains secret keys. He can use both static and dynamic analysis as well as fault analysis in order to break the cryptosystem, e.g. to extract embedded secret keys. Implementations secure in such model have many applications in industry. However, creating such implementations turns out to be a very challenging if not an impossible task.

In 2002, Chow \etal{}~\cite{ChowAES,ChowDES} proposed first white-box implementations of the AES and DES block ciphers. The main idea is to represent small parts of a block cipher as look-up tables and compose them with randomized invertible mappings to hide the secret key information. Each such look-up table by itself does not give any information about the key. In order to attack such scheme, multiple tables must be considered. Another approach was proposed by Bringer \etal{}~\cite{cryptoeprint:2006:468}. Instead of look-up tables, the cipher is represented as a sequence of functions over $\fielde{n}$ for some $n$, with some additional computations as noise. These functions are then composed with random linear mappings to hide the secret key, similarly to the Chow \etal{} approach.

Unfortunately, both approaches fell to practical attacks~\cite{AttackBillet,AttackMulder,AttackLepoint}. Consequent attempts to fix them were not successful~\cite{Dual,Xiao}. Moreover, Michiels~\etal{}~\cite{AttackMichiels} generalized the attack by Billet \etal{}~\cite{AttackBillet} and showed that the approach of Chow~\etal{} is not secure for any SPN cipher with MDS matrices. This follows from the efficient cryptanalysis of any SASAS structure~\cite{SASAS}. Recently several white-box schemes based on the ASASA structure were proposed~\cite{ASASAdesign}. However the strong white-box scheme from that paper was broken~\cite{ASASA2,GPT15,BKP17} (which also broadens the white-box attacker's arsenal even further). Another recent approach consists in obfuscating a block cipher implementation using candidates for indistinguishability obfuscation (e.g.~\cite{iOcand}).

Besides academia, there are commercial white-box solutions that are used in real products. The design behind those implementations is kept secret, thus adding \emph{security-by-obscurity} protection. Nevertheless, Bos \etal{} \cite{AttackBos} proposed a framework for attacks on white-box implementations which can automatically break many white-box implementations. The idea is to apply techniques from grey-box analysis (i.e. side-channel attacks) but using more precise data traces obtained from the implementation. The attack is called \emph{differential computation analysis} (DCA). Sasdrich~\etal{}~\cite{Sasdrich} pointed out that the weakness against the DCA attack can be explained using the Walsh transform of the encoding functions. Banik~\etal{}~\cite{Subhadeep} analyzed software countermeasures against the DCA attack and proposed another automated attack called Zero Difference Enumeration attack. More recently, Bock~\etal{}~\cite{InternalEncodings} analyzed internal encodings in white-box implementations. Consequently, Rivain and Wang~\cite{WangEncodings} provided in-depth analysis and showed that internal encodings can be easily broken in most cases, improved the attack complexities and proposed a new collision attack.

In light of such powerful automated attack the question arises: how to create a whitebox scheme secure against the DCA attack? The most common countermeasure against side-channel attacks is masking, which is a form of secret sharing. It is therefore natural to apply masking to protect white-box implementations. We define masking to be any obfuscation method that encodes each original bit by a relatively small amount of bits. Such masking-based obfuscation may be more practical in contrast to cryptographic obfuscation built from current indistinguishability obfuscation candidates~\cite{iOcand,5GEN}.

\subsection{Our Contribution}

This chapter studies the possibility of using masking schemes in the white-box setting. We restrict the analysis to implementations in the form of Boolean circuits.

We develop a more generic DCA framework and describe multiple generic attacks against masked implementations. The attacks show that the classic Boolean masking (\txor{}-sharing) is inherently weak. Previous and new attacks are summarized in \TabRef{attacks}. We remark that conditions for different attacks vary significantly and the attacks should not be compared solely by time complexity. For example, the fault-based attacks are quite powerful, but it is relatively easy to protect an implementation from these attacks. From the attacks we conclude that more general nonlinear encodings are needed and we deduce constraints that a secure implementation must satisfy. We believe that these results provide new insights on the design of white-box implementations. Note that a basic variant of the (generalized) linear algebra attack was independently proposed by Goubin~\etal{}~\cite{cryptoexperts}.

\FigTex{attacks.tex}

A code implementing the described attacks and protections from \ChapRef{wbc} is publicly available at~\cite{OurWhiteboxCode}:
\begin{center}
    \url{https://github.com/cryptolu/whitebox}
\end{center}

\subsection{Outline}
The general attack setting and attacks are described in \SecRef{dca}. Combinatorial and algebraic attacks in the DCA setting are described in \SecRef{combinatorial} and \SecRef{algebraic} respectively. In \SecRef{fault} I suggest fault-based attacks.
Finally, I conclude in \SecRef{conclusions}.


\section{Generating functions: a unified approach to combinatorial problems - Solving linear recurrences}\label{generatingFunctions}

Hallo

\subsection{Generating functions: first examples}

\subsection{Formal power series}

\subsection{When are formal power series invertible?}

\subsection{Derivation of formal power series}

\subsection{Binomial theorem for negative integer exponents}

\subsection{Solving the Fibonacci recurrence relation}

\subsection{Generating functions of linear recurrence relations are rational}

\subsection{Solving linear recurrence relations: general case}

\subsection{Exercises}