\subsection{Wall lamp}
\paragraph{}
In this example, a wall lamp illustrated in Fig.~\ref{oct_ex:lamp_geo_bc} with gravity only is considered.
The material properties are:  Young’s modulus $E = \SI{20}{\newton \per \square \meter}$, Poisson’s ratio $\nu = 0.3$ and density $\rho = \SI{2}{\kilo \gram \per \cubic \meter}$.
\begin{figure}
    \centering
    \scalebox{0.5}{
        \includegraphics{octree/ex_images/lamp_geo_bc.png}
    }
    \caption[Boundary condition of the wall lamp]{Boundary condition of the wall lamp}
    \label{oct_ex:lamp_geo_bc}
\end{figure}

\paragraph{}
The geometric model is extracted from the AutoCAD as illustrated in Fig.~\ref{oct_ex:lamp_cad}.
\begin{figure}[!ht]
    \centering
    \scalebox{0.5}{
        \includegraphics{octree/ex_images/lamp_cad.png}
    }
    \caption[CAD drawing of the wall lamp]{CAD drawing of the wall lamp}
    \label{oct_ex:lamp_cad}
\end{figure}
%
The background mesh before cutting is shown in Fig.~\ref{oct_ex:lamp_mesh_bg}.
\begin{figure}[!ht]
    \centering
    \begin{subfigure}[b]{0.49\linewidth}
        \centering
        \scalebox{0.65}{
            \includegraphics{octree/ex_images/lamp_mesh_bg.png}
        }
    \end{subfigure}
    \begin{subfigure}[b]{0.49\linewidth}
        \centering
        \scalebox{0.65}{
            \includegraphics{octree/ex_images/lamp_mesh_bg_2.png}
        }
    \end{subfigure}
    \caption[Background mesh of the wall lamp]{Background mesh of the wall lamp; left: background mesh; right: background mesh around the boundary}.
    \label{oct_ex:lamp_mesh_bg}
\end{figure}
%
The generated mesh are plotted in Fig.~\ref{oct_ex:lamp_mesh}.
\begin{figure}[!ht]
    \centering
    \begin{subfigure}[b]{1\linewidth}
        \centering
        \scalebox{0.75}{
            \includegraphics{octree/ex_images/lamp_mesh.png}
        }
    \end{subfigure} \\
    \begin{subfigure}[b]{0.48\linewidth}
        \centering
        \scalebox{0.75}{
            \includegraphics{octree/ex_images/lamp_mesh_front.png}
        }
    \end{subfigure}
    \begin{subfigure}[b]{0.48\linewidth}
        \centering
        \scalebox{0.75}{
            \includegraphics{octree/ex_images/lamp_mesh_back.png}
        }
    \end{subfigure}
    \caption[Mesh of the wall lamp]{Mesh of the wall lamp}
    \label{oct_ex:lamp_mesh}
\end{figure}
%
The displacement is plotted as the deformed shape in Fig.~\ref{oct_ex:lamp_deformed_shape}.
\begin{figure}[!ht]
    \centering
    \scalebox{0.5}{
        \includegraphics{octree/ex_images/lamp_deformed_shape.png}
    }
    \caption[Deformed shape of the wall lamp]{Deformed shape of the wall lamp}
    \label{oct_ex:lamp_deformed_shape}
\end{figure}


\section{\uppercase{Experimental evaluation}}\label{sec:results}

\noindent Several tests were conducted in the simulated environments presented earlier for evaluating the ability of the proposed system to find suitable constellations of sensors for maximizing the observable surface area of a given set of target objects.

In the active perception environment introduced in \cref{fig:active-perception-environment}, it was performed two tests with the sensor deployment shown in \cref{fig:sensors-deployment-active-perception-environment}. In the first test it was estimated the best sensor position for observing a single target object (green starter motor) being occluded by a human hand starting to grasp it. By visually inspecting the scene in \cref{fig:active-perception-1-sensor}, it can be seen that the system chose a very reasonable sensor position, achieving a surface coverage of 27.73\%, despite the heavy occlusions present. Moreover, when expanding the number of sensors to 3 (in the second test), the system managed to select a sensor constellation with a good spatial distribution (shown in \cref{fig:active-perception-3-sensors}) that managed to improve the sensor coverage to 61.91\%.

Moving to the single bin picking environments, presented in \cref{fig:bin-picking-environment,fig:bin-picking-with-occlusions-environment}, it was made four more tests using the deployed sensors seen in \cref{fig:sensors-deployment-bin-picking-environments}. In the first test it was estimated the best position for a single sensor to observe the target object that was inside the stacking box, which had large occlusions on its surroundings, but could be clearly observed from above. As can be seen in \cref{fig:bin-picking-1-sensor}, the system choose a suitable observation sensor that managed to achieve a surface coverage of 45.10\%. When increasing the number of sensors to 5 (in the second test), the system relied on more sensor data and improved the surface coverage to 64.63\%. To make the active perception for this bin picking use case more challenging, it was added three occluding differential gearboxes on top of the target object (scene shown on \cref{fig:bin-picking-with-occlusions-environment}) in order to create large occlusions that significantly reduced the number of useful sensors in the deployed populations (presented in \cref{fig:sensors-deployment-bin-picking-environments}). Analyzing the best sensor position estimated by the system (shown in \cref{fig:sensor-data-processing,fig:bin-picking-with-occlusions-1-sensor}) it can be seen that the pose chosen was very reasonable, achieving a surface coverage of 19.27\%. When increasing the number of sensors to 3, the system deployed a constellation with good spatial distribution and managed to improved the surface coverage percentage of the target object to 31.19\% (as can be seen in \cref{fig:bin-picking-with-occlusions-3-sensors}).

Increasing the level of complexity even further, in the final test it was added three more target objects to the simulation environment (as presented in \cref{fig:multiple-bin-picking-with-occlusions-environment}) and the number of populations with different sensor types was increased to 7 (shown in \cref{fig:sensors-deployment-multiple-bin-picking-environment}). Analyzing \cref{fig:multiple-bin-picking-with-occlusions-10-sensors} in which the system estimated a constellation of 10 sensors to observe the 4 target objects, it can be seen that the system chose 4 sensors on the front wall (which had a better observation area for the target objects in the trolley shelves), 3 on the ceiling (for retrieving sensor data for the target objects on top of the trolley) and then for observing the remaining surface areas of the target objects, it chose one sensor on the left wall, another on the right wall and finally another one on the back wall, reaching 10 sensors in total and achieving a surface coverage of the target objects of 43.93\%.

These 7 constellations of sensors computed using \cref{alg:best-n-views} (which relied on a \gls{ransac} approach), show that the proposed system can estimate a suitable sensor configuration for maximizing the observable surface area of several target objects even on complex environments with significant occlusions. Moreover, the system managed to compute useful solutions in bounded and reasonable time (from less than a second to a few minutes depending on the number and characteristics of the deployed sensors) for a problem that is combinatorial explosive in terms of processing time complexity.

\begin{figure}
	\centering
	\includegraphics[height=.2\textwidth]{best-views-estimation/active-perception/1-sensor/gazebo-corner}\hspace{4em}
	\includegraphics[height=.2\textwidth]{best-views-estimation/active-perception/1-sensor/rviz-front-corner}\\
	\includegraphics[height=.2\textwidth]{best-views-estimation/active-perception/1-sensor/rviz-back-corner}\hspace{2em}
	\includegraphics[height=.2\textwidth]{best-views-estimation/active-perception/1-sensor/rviz-top}
	\caption{Estimation of the best sensor position for the active perception environment with a 27.73\% of surface area coverage (top left showing the Gazebo color rendering and remaining images displaying the best sensor as a large red arrow, the deployed sensors as small coordinate frames and the observed sensor data as green spheres).}
	\label{fig:active-perception-1-sensor}
\end{figure}

\begin{figure}
	\centering
	\includegraphics[height=.2\textwidth]{best-views-estimation/active-perception/3-sensors/gazebo-front-right-corner}\hspace{4em}
	\includegraphics[height=.2\textwidth]{best-views-estimation/active-perception/3-sensors/rviz-front-right}\\
	\includegraphics[height=.2\textwidth]{best-views-estimation/active-perception/3-sensors/rviz-back-left}\hspace{2em}
	\includegraphics[height=.2\textwidth]{best-views-estimation/active-perception/3-sensors/rviz-top}
	\caption{Estimation of the 3 best sensors disposition for the active perception environment with a 61.91\% of surface area coverage.}
	\label{fig:active-perception-3-sensors}
\end{figure}

\begin{figure}
	\centering
	\includegraphics[height=.14\textwidth]{best-views-estimation/bin-picking/1-sensor/gazebo-top}\hspace{2em}
	\includegraphics[height=.14\textwidth]{best-views-estimation/bin-picking/1-sensor/rviz-front}\\
	\includegraphics[height=.2\textwidth]{best-views-estimation/bin-picking/1-sensor/rviz-top-front}\hspace{2em}
	\includegraphics[height=.2\textwidth]{best-views-estimation/bin-picking/1-sensor/rviz-top}
	\caption{Estimation of the best sensor position for the bin picking environment with a 45.10\% of surface area coverage.}
	\label{fig:bin-picking-1-sensor}
\end{figure}

\begin{figure}
	\centering
	\includegraphics[height=.19\textwidth]{best-views-estimation/bin-picking/5-sensors/gazebo-front}\hspace{2em}
	\includegraphics[height=.14\textwidth]{best-views-estimation/bin-picking/5-sensors/rviz-top}\\
	\includegraphics[height=.2\textwidth]{best-views-estimation/bin-picking/5-sensors/rviz-corner}\hspace{2em}
	\includegraphics[height=.14\textwidth]{best-views-estimation/bin-picking/5-sensors/rviz-sensor-data}
	\caption{Estimation of the 5 best sensors disposition for the bin picking environment with a 64.63\% of surface area coverage.}
	\label{fig:bin-picking-5-sensors}
\end{figure}

\begin{figure}
	\centering
	\includegraphics[height=.13\textwidth]{best-views-estimation/bin-picking-with-occlusions/1-sensor/gazebo-top}\hspace{2em}
	\includegraphics[height=.13\textwidth]{best-views-estimation/bin-picking-with-occlusions/1-sensor/rviz-corner}\\
	\includegraphics[height=.2\textwidth]{best-views-estimation/bin-picking-with-occlusions/1-sensor/rviz-front}\hspace{2em}
	\includegraphics[height=.2\textwidth]{best-views-estimation/bin-picking-with-occlusions/1-sensor/rviz-top}
	\caption{Estimation of the best sensor position for the bin picking with occlusions environment with a 19.27\% of surface area coverage.}
	\label{fig:bin-picking-with-occlusions-1-sensor}
\end{figure}

\begin{figure}
	\centering
	\includegraphics[height=.18\textwidth]{best-views-estimation/bin-picking-with-occlusions/3-sensors/gazebo-top}\hspace{2em}
	\includegraphics[height=.2\textwidth]{best-views-estimation/bin-picking-with-occlusions/3-sensors/rviz-front}\\
	\includegraphics[height=.21\textwidth]{best-views-estimation/bin-picking-with-occlusions/3-sensors/rviz-top-back}\hspace{2em}
	\includegraphics[height=.21\textwidth]{best-views-estimation/bin-picking-with-occlusions/3-sensors/rviz-top}
	\caption{Estimation of the 3 best sensors disposition for the bin picking with occlusions environment with a 31.19\% of surface area coverage.}
	\label{fig:bin-picking-with-occlusions-3-sensors}
\end{figure}

\begin{figure}
	\centering
	\includegraphics[width=.44\textwidth]{best-views-estimation/multiple-bin-picking-with-occlusions/10-sensors/gazebo-front}\vspace{2em}
	\includegraphics[width=.25\textwidth]{best-views-estimation/multiple-bin-picking-with-occlusions/10-sensors/rviz-front-corner}\vspace{2em}
	\includegraphics[width=.43\textwidth]{best-views-estimation/multiple-bin-picking-with-occlusions/10-sensors/rviz-front}\vspace{2em}
	\includegraphics[width=.43\textwidth]{best-views-estimation/multiple-bin-picking-with-occlusions/10-sensors/rviz-top}
	\caption{Estimation of the 10 best sensors disposition for the multiple bin picking with occlusions environment with a 43.93\% of surface area coverage.}
	\label{fig:multiple-bin-picking-with-occlusions-10-sensors}
\end{figure}


\section{}
The chiral central charge tells you the heat current.
If you had a single chiral Majorana mode it's half.

\begin{table}
    \centering
    \begin{tabular}{ccccc}
        (1+1)D & $\mathbb{Z}_2$ invariant &
        $\mathcal{I}=P_0 P_\pi$ &
        $G_f = \mathbb{Z}_2^f$ &
        $\psi\to e^{i\theta}\psi$ Class D\\
        (2+1)D & $\mathbb{Z}$ invariant Chern number &
        C &
        $G=U(1)$ &
        [$G_f=U(1)^f$] Class A\\
        & $\mathbb{Z}$ invariant &
        $\nu=2C_{-}$ (sp. Chern # for free fermions) &
        $G_f=\mathbb{Z}_2^f$
    \end{tabular}
    \caption{Free fermion models}
    \label{tab:freefermions}
\end{table}

\begin{question}
    What is a full Majorana measurement?
\end{question}
Measurement of $\gamma_1 \gamma_j \gamma_k \gamma_l$.
Joint fermion parity.

Consider $U(1)_\uparrow$ with Chern number $C_\uparrow$
and $U(1)_\downarrow$ with Chern number $C_\downarrow$
with
$C_{\uparrow} = -C_{\downarrow} = C$.
There is also time-reversal symmetry.

Chern number breaks time-reversal and reflection symmetry.
It breaks time rerseal because the direction of the current on the edge would
have to switch sign.

But if they have opposite Chern number on both sides with two components then
you can.

A two-component system with $C_\uparrow = -C_\downarrow$ can be time-invariant.

Let's study the edge theory in a particular case here.

\subsection{Edge theory for $C_\uparrow=C_\downarrow=1$}
The Hamiltonian would be like
\begin{align}
    H &=
    \sum_k \left[
    |V_\uparrow| k \psi_{\uparrow,k}^\dagger \psi_{\uparrow,k}
    |V_\downarrow| k \psi_{\downarrow,k}^\dagger \psi_{\downarrow,k}
    \right]
\end{align}
Non-trivial topological phases have something interesitng at the edges.
So consider a backscatttering term or a mass term for htis fermion
\begin{align}
    m \psi_\uparrow^\dagger \psi_\downarrow + h.c.
\end{align}
This breans spin consdervation,
which is the relative $U(1)$.
This breaks the $S_z$ spin conservation.
But that's not so surprising because you have an up fermion and that gets
backscattered by a down fermion,
and it's not so surprising that breaks spin conservation.
More interesting,
this term also breaks time-reversal symmetyr.

Let's deine time reversal to hae the following actiona
\begin{align}
    T: \psi_\uparrow &\to \psi_\downarrow\\
    \psi_\downarrow &\to -\psi_\uparrow
\end{align}
which means on a single fermion $T^2=-1$,
and so
\begin{align}
    T^2 &= {(-1)}^F
\end{align}
So you could say this is a $\mathbb{Z}_4^{T,f}$ symmetry.
But there's also a $U(1)^f$ symmetry.
But if you apply one and apply another,
the order matters,
and there's a complex conjugation when you reverse the order.
And you need to mod out to consider equivalence.
So the symmetry of the system is this
\begin{align}
    G_f &=
    \frac{U(1)^f \rtimes Z_4^{T,f}}{\mathbb{Z}_2}.
\end{align}
This is called the class AII symmetry group in the Cartan classification.

Fermionic symmetry group $G_f$.
Consider whath appens when you act the symmetry only on bosonic operators,
then you can ask what symmetry acts on them,
and that allows you to define a bosoinc symmetry gorup
\begin{align}
    G_b &= G_f/\mathbb{Z}_2^f
\end{align}

If you look at the bosoinc symmetry group,
then
\begin{align}
    G_b &=
    U(1) \rtimes \mathbb{Z}_2^T
\end{align}
Under time-reversal symmetry,
\begin{align}
    T (M \psi_\uparrow^\dagger \psi_\downarrow) T^\dagger &=
    - m^* \psi_\downarrow^\dagger \psi_\uparrow
\end{align}
You'd think there's a single total Chern number.
Surprisingly,
there's still something non-trivial left over.
This suggests there's still some non-trivial topological phase still left over
in the system.
You can then consider two copies.
\begin{align}
    C_\uparrow = - C_\downarro = 2
\end{align}
then you can write the same thing,
but there's an extra flavour $s$.
\begin{align}
    H &=
    \sum_{k,s} \left[
    |V_{\uparrow,s}| k \psi_{\uparrow,k,s}^\dagger \psi_{\uparrow,k,s}
    |V_{\downarrow,s}| k \psi_{\downarrow,k,s}^\dagger \psi_{\downarrow,k,s}
    \right]
\end{align}
Under time-reversal,
\begin{align}
    T: \psi_{\uparrow, s} & \to \psi_{\downarrow,s}\\
    \psi_{\downarrow,s} &\to -\psi_{\uparrow,s}
\end{align}
And now you can consdier what terms you can add,
and it turns out you can add a backscaettering term.
\begin{align}
    \delta H_{\textrm{backscattering}} &=
    m\left(
    \psi_{\uparrow,1}^\dagger \psi_{\downarrow, 2}
    - \psi_{\downarrow,1}^\dagger \psi_{\uparrow, 2}
    + \mathrm{h.c.}
    \right)
\end{align}
and now you can open an energy gap.
This suggests the bulk topological phase should have
$\mathbb{Z}_2$ invariant.

This is the bulk-edge correspondence.
You can deduce the bulk properties by looking at he stability of the boundary
modes under action of the symmetry group.

Now we can consider whath appens when this time-reversal symmetry does not have
this minus sign.
Suppose that instead
\begin{align}
    T: \psi_\uparrow &\to \psi_\downarrow\\
    \psi_\downarrow & \to \psi_\uparrow
\end{align}
and so $T^2=+1$.
Then the symmetry groups are
\begin{align}
    G_f &= U(1)^f \rtimes \mathbb{Z}_2^T\\
    G_b &= U(1) \rtimes \mathbb{Z}_2^T
\end{align}
and then $C_\uparrow = C_\downarrow = -1$
and it does not have protected edge modes.
The fact that $G_f$ is different has consequences on what ind of backscattering
terms you can add.

Fermions can ermge in a variety of situations in solid state systems.
I don't have a good example,
but you can have fermions show up in solid state systems.
Of ten this kind of time reversal can be thoguht of as a effectie time reversal
where you combien it wiht some kind of rotation.
This may be the true time reversal plus some rotation,
but we still call it time reversal because it's anti hermitian.

The $\pi$ rotation in $G_f$ becomes the $1$ operation in $G_b$.
This becomes implicit in
\begin{align}
    G_b &= G_f / \mathbb{Z}_2^f
\end{align}
This becomes a trivial operation as far as a boson is concerned.

\begin{question}
    Why do we ultimately have to define $G_b$?
    The first symmetry gourp is $G_f$.
    Why do we not just work with $G_f$?
\end{question}
I didn't use $G_b$ anywhere,
I just noted $G_b$.
And depending on how sophisticated the theroy is,
it could be useful,
but not in this particular scenario.

Let me remind you of the important Kramers theorem.

If $T^2=-1$,
it measn the minimal representation is 2-dimensional,
whichm eans if you have a state on which $T^2$ acts as $-1$,
it has to be a doublet.
The proof is two lines.
Suppose you act $T$ on a state and you don't change it
\begin{align}
    T\ket{\psi} &= \lambda\ket{\psi}\\
    -\ket{\psi} = T^2 = \lambda^* \lambda \ket{\psi}
\end{align}
So therefore,
$T$ msut bring it to another state
\begin{align}
    T\ket{\uparrow} &= \lambda \ket{\downarrow}\\
    T\ket{\downarrow} &= \lambda^' \ket{\uparrow}
\end{align}
and $\lambda\lambda' = -1$.
which is a contradiction.
So that's Kramers theorem.

consider a cylinder with a momentum around a circle $k_y$ and let $x$ e the axis
of the cylinder.

Consider the spectrum of $E$ vs $k_y$.
there are bulk states in tethe valence conduction bands.
You can see that $T: k \to -k$,
because intiuitively time reversal changes the sign of momentum.
Then the possible time-reversal momenta are
\begin{align}
    \vec{k} &=
    \begin{cases}
        (0, 0)\\
        (0, \pi)\\
        (\pi 0)\\
        (0, 0)
    \end{cases}
\end{align}
There's two topological distrinct scenarios that can happen.
Either these states connect up in a non-trivial way.
This merges into the bulk and then this comes out.

Thisis topological.
No matter where I put my chemical otential,
I'mg going to hit exactly 1.
The trivial situation is when Karmers pairs connect up in a non-trial wahuoWe
have these states and I can have ooThe Kramrs degenerate states in time-reversal
omentua connect up.

You can geta band invariant bby mulitplying hte hern nmber through the Brilluoin
zone.

\section{\mathbb{$Z_2$}c  band invariant}
Define
\begin{align}
    W_{mn}(k) &=
    \bra{U_m(k)} T \ket{U_n(-k)}
\end{align}
where $w$ is unitary.

\begin{align}
    w^T(k) = -w(-k)
\end{align}
$\Lambda_a$ = $ trim,
$a+1,\dpts.a$4$
\begin{align}
    \lambda_n = \mathrm{TRIM}\qquad a=1,\ldots, 4\\
    w^T(\Lambda_a) &= -w(`A_a)
\end{align}
and
\begin{align}
    \delta_a &= \frac{\Pf(w(\Lambda_a))}{\sqrt\det(w(\lambda_a))}}
    = \pm 1
\end{align}
Here
\begin{align}
    \pm 1 &= (-1)^{\nu}
    = \prod_{a=1}^{N}
\end{align}
Need $\sqrt{deg{w(k)}}$ continuous everywhere in BZ.
Can do this if Bloch wave functions we defined continuously everywhere.
Possible boundary condition that total Chern number = 0 by $T$.

\subsection{Time-reversal polarization in 1D}
Fu-Kane arXiv 0606336.
Can split up Bloch states of occupied bands in the two classes.
\begin{align}
    \ket{U_m^I(k)}, \ket{U_m^{II}(k)}\\
    T\ket{U_m^I(k)} &= e^{i\chi_m(k)}\ket{u_m^{II}(-k)}.
\end{align}
Define polarization $P_I$ and $P_{II}$ fore each class.
Total polarization
\begin{align}
    P &= P_I + P_{II}
\end{align}
and time-reversal polarization
\begin{align}
    P_T &= P_I - P_{II}
\end{align}
\begin{align}
    \pm 1 &= (-1)^{P_T} = \delta_1 \delta_2
\end{align}
for $\Lambda_1=0$ $\Lambda_2=\pi$ where
\begin{align}
    \delta_{a} &=
    \frac{\Pf(w(\Lambda_a))}{\sqrt{\det(w(\Lambda_a))}}
\end{align}

The physical meaning is this.
$(-1)^{P_T}=-1$ means boundary has a Kramers degeneracy in each end.

\subsection{Back to 2D}
Can think of 2D system as parameterized 1D
\begin{align}
    H_{2d} &=
    \sum_{k_y} H_{1d}\left( k_y \right)
\end{align}
Consider change in $P_T$ from $k_y=0$ to $\pi$.
\begin{align}
    {(-1)}^{P_T(k_y=\pi) - P_T(k_y=0)} &=
    \delta\left( (0, 0) \right)
    \delta\left( (\pi ,0) \right)
    \delta\left( (0, \pi) \right)
    \delta\left( (\pi, \pi) \right)\\
    &=
    {(-1)}^{\nu}
\end{align}
You can think of this as localized Wannier states.

Just like there is a story for insulators as superconductors,
this story also has an analogue for topological superconductors.
Instead of Chern number $\pm 1$,
we can also consider $p+ip$ or $p-ip$.

Consider a different symmetry group
\begin{align}
    G_f = \mathbb{Z}_4^{T,f}
\end{align}
and there's no $U(1)$.
This is called class DIII.
This would be for topological superconductors.
Consider 2 layers.
There is an invariant $\nu$ for the $p+ip$ layer and
$-\nu$ for the $p-ip$ layer.

All this stuff about topological pumps.
The story on why states are protected.
We get the $\mathbb{Z}_$ classification of topological phases.
From a high level it's very similar.

If you're okay,
we can go to (3+1)D.
Once we've done that,
we'll just leave the world of free fermion topological phases
and go on to describe some other kinds of things.

So we wrote down this band invariant $\nu$.
If you go up one dimension you can consider a similar invariant.

For (3+1)D Classs AII,
\begin{align}
    G_f &= \frac{U(1)^f\rtimes \mathbb{Z}^{T,f}}{\mathbb{Z}_2}
\end{align}
and
\begin{align}
    (-1)^\nu &= \prod_{a=1}^8 \delta_a
\end{align}
8 TRIM:
\begin{align}
    \Lambda_a &= \left( \pi s_1, \pi s_2, \pi s_3 \right)
\end{align}

\section{(3+1)D massive Dirac fermion}
It is useful to start in (4+1)D.
\begin{align}
    H &=
    \sum_{a=0}^{4}
    \sum_{k} \psi_k^\dagger d_a(k)\cdot \Gamma^a \psi_k
\end{align}
where $\Gamma^\mu$ are $4\times 4$ Dirac matrices wiht $\mu=0,\ldots,4$.
Then the anticommutation is
\begin{align}
    \left\{ \Gamma^{\mu}, \Gamma^{\nu} \right\} = 2\delta_{\mu\nu} II
\end{align}
This can be  parameterized family of 3 + 1 dimensional models,
parameetrized by a parameter $k_w$.
\begin{align}
    d_a(k) &=\left(
    m +c \sum_{i=1}^{4}\cos(k),
    \sin k_x,
    \sin k_y,
    \sin k_z,
    \sin k_w
    \right)
\end{align}
so
\begin{align}
    H &= \sum_{k_w} H_{3+1Dj}(k_1,k_2,k_3,k_w).
\end{align}
Then we couple this to a background $U(1)$ gauge field.

View $k_w + A_w = \theta$ as a parameter.
I view this fourth dimension as a parameter.
The 4 + 1 D effective action if we integrate out the fermions is basically a
Chern Simons term.
So it's going to give
\begin{align}
    S_{\mathrm{eff}} &=
    \frac{C_2}{24\pi^2}
    \int d^4x\, dt\,
    \epsilon^{\mu\nu\lambda\sigma}
    A_{\mu} \partial_{\nu} A_{\lambda} \partial_{\rho} A_{\sigma}
\end{align}
where $C_2$ is the second Chern number of Bloch states
\begin{align}
    C_2 &=
    \int \mathcal{F}_{\mu\nu} \mathcal{F}_{\lambda\sigma}
    \epsilon^{\mu\nu\lambda\sigma}
\end{align}
where $\mathcal{F}_{\mu\nu}$ is the Berry curvature of the Bloch wave functions.


\section{Systematic uncertainties}
\label{sec:hmhzz_sys}

This section describes the sources and values of theoretical and experimental systematic uncertainties considered in this analysis.

%% =========================================================================================================================
\subsection{Theoretical systematics}

The theoretical modelling uncertainties include the PDF variations, missing QCD higher-order corrections via the variations of factorisation and renormalization scales,
and the parton showering uncertainties.

\subsubsection{Theoretical uncertainties for signal}
\label{sec:hmhzz_theo_signal}

The PDF, QCD scale and parton showering uncertainties affecting the acceptance difference originating from analysis selection for signal are taken into account in different categories.
The acceptance uncertainties are calculated on the acceptance factor which extrapolates from the fiducial space to the full phase space by a simple ratio:
\begin{equation}
        A = \frac{N_{fiducial}}{N_{total}}
\end{equation}

For PDF uncertainties, the standard derivations of 100 PDF replicas of NNPDF3.0 NNLO, as well as comparison to two external PDF sets: MMHT2014 NNLO, CT14 NNLO are considered.
For missing QCD higher-order corrections, the effects are studied with truth events by comparing weights corresponding to
variations of the renormalization and factorization scale factors, up and down by a factor of two, and the envelop of different variations is used.
The parton showering uncertainties are estimated by comparing events with different setting via \textsc{Pythia8}.

Systematic uncertainties are studied for both cut- and MVA- based event categorizations,
for cut-based analysis in two different categories: the inclusive ggF-CBA-enriched and VBF-CBA-enriched category,
and for MVA-based one in three different categories: inclusive ggF-MVA-high, ggF-MVA-low and VBF-MVA-enriched category.
This section shows the MVA-based results as an example.

Table~\ref{tab:acc-ggF-dnn} and ~\ref{tab:acc-VBF-dnn} show the theoretical uncertainties mentioned above for ggF and VBF signal respectively in MVA-based categorization.

\begin{table}[htbp]
  \centering
  \caption{Summary of acceptance uncertainties of PDF, QCD scale and parton shower variations for ggF production. The MVA-based categorization is used.}
  \label{tab:acc-ggF-dnn}
  \begin{spacing}{0.75}
  \begin{tabular}{cccc}
    \toprule
    Categories  & PDF    & QCD Scale  & Parton Shower \\
    \midrule
    ggF-MVA-high  & 0.40\% & 0.06\% & 2.03\% \\
    ggF-MVA-low   & 0.56\% & 0.07\% & 4.86\% \\
    VBF-MVA-enriched  & 0.53\% & 0.09\% & 3.43\% \\
    \bottomrule
  \end{tabular}
  \end{spacing}
\end{table}

\begin{table}[htbp]
  \centering
  \caption{Summary of acceptance uncertainties of PDF, QCD scale and parton shower variations for VBF production. The MVA-based categorization is used.}
  \label{tab:acc-VBF-dnn}
  \begin{spacing}{0.75}
  \begin{tabular}{cccc}
    \toprule
    Categories  & PDF    & QCD Scale  & Parton Shower \\
    \midrule
    ggF-MVA-high  & 0.18\% & 1.20\% & 0.41\% \\
    ggF-MVA-low   & 0.43\% & 0.26\% & 0.36\% \\
    VBF-MVA-enriched  & 0.23\% & 3.19\% & 0.85\% \\
    \bottomrule
  \end{tabular}
  \end{spacing}
\end{table}

%\textbf{Cut-based analysis} \\
%
%Table~\ref{tab:acc-ggF-cut} and ~\ref{tab:acc-VBF-cut} show the theoretical uncertainties for ggF and VBF signals respectively in cut-based categorization.
%The uncertainties are computed in two different categories: the inclusive ggF and VBF category.
%\begin{table}[htbp]
%  \centering
%  \caption{Summary of acceptance uncertainties of PDF, QCD scale and parton shower variations for ggF production. The cut-based categorization is used.}
%  \label{tab:acc-ggF-cut}
%  \begin{tabular}{cccc}
%    \toprule
%    Categories  & PDF    & QCD Scale  & Parton Shower \\
%    \midrule
%    ggF  & 0.44\% & 0.07\% & 0.22\% \\
%    VBF  & 0.61\% & 0.12\% & 3.33\% \\
%    \bottomrule
%  \end{tabular}
%\end{table}
%
%\begin{table}[htbp]
%  \centering
%  \caption{Summary of acceptance uncertainties of PDF, QCD scale and parton shower variations for VBF production. The cut-based categorization is used.}
%  \label{tab:acc-VBF-cut}
%  \begin{tabular}{cccc}
%    \toprule
%    Categories  & PDF    & QCD Scale  & Parton Shower \\
%    \midrule
%    ggF  & 0.18\% & 2.87\% & 0.52\% \\
%    VBF  & 0.08\% & 4.52\% & 0.72\% \\
%    \bottomrule
%  \end{tabular}
%\end{table}

\subsubsection{Theoretical uncertainties for SM background processes}

The theoretical uncertainties of irreducible $ZZ$ backgrounds are considered in terms of both the variations of shape of \mfl distributions
and the acceptance originating from the event selection.

The PDF and QCD scale uncertainties are considered by using the same method as described for signal.
The parton showering uncertainties for those \textsc{Sherpa} samples are evaluated by varying the resummation scale by a factor of 2,
changing the CKKW setting and using different showering option, following the PMG recommendation in Ref.~\cite{twiki_pmgsyst},
and the quadratic sum between the uncertainties in different kinds of showering option is taken as final result of uncertainties.
Moreover, the shape uncertainty associated with electroweak higher-order correction for \qqZZ process is also taken into account.

Same as for signals, these theoretical uncertainties for irreducible backgrounds are studied for both cut- and MVA- based event categorizations.
The value of shape uncertainties vary from less than 1\% at low mass region to 50\% at high mass tail due to large statistic fluctuation.
As for the acceptance uncertainties, the values vary from about 1\% for PDF variations to 40\% for parton showering variations.
The VBF category has relative larger uncertainties.

Table~\ref{tab:acc-all-qqZZ_MVA} summarizes the acceptance uncertainties of PDF, QCD scale, and parton showering variations for the dominant background: \qqZZ.

\begin{table}[htbp]
  \centering
  \caption{Summary of acceptance uncertainties of PDF, scale, and parton showering variations for QCD \qqZZ background. The MVA-based categorization is used.}
  \label{tab:acc-all-qqZZ_MVA}
  \begin{spacing}{0.75}
  \begin{tabular}{cccc}
    \toprule
    Categories  & PDF    & QCD Scale   & Parton showering \\
    \midrule
    ggF-MVA-high  & 1.15\% & 10.16 \% & 3.71\% \\
    ggF-MVA-low   & 1.04\% & 3.26  \% & 3.80\% \\
    VBF-MVA-enriched  & 2.91\% & 27.90 \% & 23.82\% \\
    \bottomrule
  \end{tabular}
  \end{spacing}
\end{table}

%% =========================================================================================================================
\subsection{Experimental systematics}

The signal and background predictions used in this analysis are also affected by various sources of experimental systematic uncertainties.
Similar as described in section~\ref{sec:vbszz_exp_uncer}, the dominant experimental uncertainties in this analysis also come from the energy/momentum scales
and reconstruction and identification efficiencies of the leptons and jets, as well as the luminosity uncertainty.
The systematic uncertainties are calculated using the recommendations from the Combined Performance (CP) groups of ATLAS experiment.
In addition, as mentioned in previous sections, the uncertainties of irreducible background modelling, reducible background shape smoothing procedure and signal yield difference between simulation and parameterization are all taken into account.
%Table~\ref{tab:np_list} summarizes the experimental systematics considered in this analysis that affect either the normalization of total event yield or the shape of \mfl distribution.
The impact of a few largest systematics and their value from statistical fit are studied in section~\ref{sec:hmhzz_result_4l}.

\iffalse
\begin{table}
  \centering
  \caption{
  A list of the experimental systematics considered in this analysis. The NPs have been separated by whether they only
  affect the normalisation (left column) or if they affect the shape (right column) of the \mfl distribution. They are
  further subdivided into the primary objects that they affect.
  }
  \begin{spacing}{0.65}
  \small
  \begin{tabular}{l|l}
    \toprule
    \multicolumn{1}{c}{Normalisation NPs} & \multicolumn{1}{c}{Shape NPs} \\
    \midrule
    \multicolumn{2}{c}{\textbf{Electrons}} \\
    \midrule
    \texttt{EL\_EFF\_ID\_CorrUncertaintyNP[0-15]}               & \texttt{EG\_RESOLUTION\_ALL} \\
    \texttt{EL\_EFF\_ID\_SIMPLIFIED\_UncorrUncertaintyNP[0-17]} & \texttt{EG\_SCALE\_ALLCORR} \\
    \texttt{EL\_EFF\_Iso\_TOTAL\_1NPCOR\_PLUS\_UNCOR}           & \texttt{EG\_SCALE\_E4SCINTILLATOR} \\
    \texttt{EL\_EFF\_Reco\_TOTAL\_1NPCOR\_PLUS\_UNCOR}          & \texttt{EG\_SCALE\_LARCALIB\_EXTRA2015PRE} \\
    ~                                                           & \texttt{EG\_SCALE\_LARTEMPERATURE\_EXTRA2015PRE} \\
    ~                                                           & \texttt{EG\_SCALE\_LARTEMPERATURE\_EXTRA2016PRE} \\
    \midrule
    \multicolumn{2}{c}{\textbf{Muons}} \\
    \midrule
    \texttt{MUON\_EFF\_ISO\_STAT}         & \texttt{MUON\_ID} \\
    \texttt{MUON\_EFF\_ISO\_SYS}          & \texttt{MUON\_MS} \\
    \texttt{MUON\_EFF\_RECO\_STAT}        & \texttt{MUON\_SAGITTA\_RESBIAS} \\
    \texttt{MUON\_EFF\_RECO\_STAT\_LOWPT} & \texttt{MUON\_SAGITTA\_RHO} \\
    \texttt{MUON\_EFF\_RECO\_SYS}         & \texttt{MUON\_SCALE} \\
    \texttt{MUON\_EFF\_RECO\_SYS\_LOWPT}  & ~ \\
    \texttt{MUON\_EFF\_TTVA\_STAT}        & ~ \\
    \texttt{MUON\_EFF\_TTVA\_SYS}         & ~ \\
    \midrule
    \multicolumn{2}{c}{\textbf{Jets}} \\
    \midrule
    ~                            & \texttt{JET\_BJES\_Response} \\
    ~                            & \texttt{JET\_EffectiveNP\_[1-7]} \\
    ~                            & \texttt{JET\_EffectiveNP\_8restTerm} \\
    ~                            & \texttt{JET\_EtaIntercalibration\_Modelling} \\
    ~                            & \texttt{JET\_EtaIntercalibration\_NonClosure\_highE} \\
    ~                            & \texttt{JET\_EtaIntercalibration\_NonClosure\_negEta} \\
    ~                            & \texttt{JET\_EtaIntercalibration\_NonClosure\_posEta} \\
    ~                            & \texttt{JET\_EtaIntercalibration\_TotalStat} \\
    ~                            & \texttt{JET\_Flavor\_Composition} \\
    ~                            & \texttt{JET\_Flavor\_Response} \\
    ~                            & \texttt{JET\_JER\_DataVsMC} \\
    ~                            & \texttt{JET\_JER\_EffectiveNP\_[1-6]} \\
    ~                            & \texttt{JET\_JER\_EffectiveNP\_7restTerm} \\
    ~                            & \texttt{JET\_Pileup\_OffsetMu} \\
    ~                            & \texttt{JET\_Pileup\_OffsetNPV} \\
    ~                            & \texttt{JET\_Pileup\_PtTerm} \\
    ~                            & \texttt{JET\_Pileup\_RhoTopology} \\
    ~                            & \texttt{JET\_PunchThrough\_MC16} \\
    ~                            & \texttt{JET\_SingleParticle\_HighPt} \\
    \midrule
    \multicolumn{2}{c}{\textbf{Other}} \\
    \midrule
    \texttt{HOEW\_QCD\_syst}    & ~ \\
    \texttt{HOEW\_syst}         & ~ \\
    \texttt{HOQCD\_scale\_syst} & ~ \\
    \texttt{PRW\_DATASF}        & ~ \\
    \bottomrule
  \end{tabular}
  \end{spacing}
  \label{tab:np_list}
\end{table}
\fi


\section{UTxO}
\label{sec:utxo}

\subsection{UTxO Transitions}
\label{sec:utxo-trans}

We have added the following helper functions, which are used in defining the
UTxO transition system, see Figure~\ref{fig:functions:insouts}. These include:

\begin{itemize}
  \item the function $\fun{getOut}$ builds a UTxO-type output out of a
  transaction output
  \item the function $\fun{outs}$ builds the MC UTxO entries from the outputs
  of a transaction
\end{itemize}

\begin{figure}[htb]
  \begin{align*}
    & \fun{getOut} \in \TxOut \to \UTxOOut \\
    & \text{tx outputs transformed to UTxO outputs} \\
    & \fun{getOut} ~{txout}~= (\fun{getAddr}~\var{txout}, \fun{getValue}~\var{txout})
    \nextdef
    & \fun{outs} \in \TxBody \to \UTxO \\
    & \text{tx outputs as UTxO} \\
    & \fun{outs} ~\var{txb} =
        \left\{
          (\fun{txid} ~ \var{txb}, \var{ix}) \mapsto \fun{getOut}~\var{txout} ~
          \middle|~
          \var{ix} \mapsto \var{txout} \in \txouts{txb}
        \right\} \\
  \end{align*}
  \caption{Functions on Tx Inputs and Outputs}
  \label{fig:functions:insouts}
\end{figure}

\textbf{Value Operations and Partial Order.}
Some of the UTxO update and precondition functions now operate on the $\Value$
type instead of $\Coin$ (sometimes on a combination of $\Value$ and $\Coin$).
To make this precise, we must define basic operations on $\Value$, which
include, most notably, addition and $\leq$ comparison.

The type $\Value$ has a partial order defined on it in (see~\cite{plutus_eutxo}).
The idea of this partial order, as well as operations like addition and subtraction
of terms of the $\Value$ type, is that a term $v \in \Value$ can be treated
as a total map that maps to the trivial element $\epsilon \in \Token \to \Quantity$
almost everywhere except for a several currency IDs that appear in $\dom~v$.

This way, when adding two terms of type value, $\{ cid1 \mapsto tkns1\}$ and
$\{ cid2 \mapsto tkns2\}$, the result is
\[ \{ cid1 \mapsto (tkns1 + \epsilon), cid2 \mapsto (\epsilon + tkns2)\} \]

which simplifies to

\[ \{ cid1 \mapsto tkns1, cid2 \mapsto tkns2\} \]

This definition of addition is also defined in Section~\ref{sec:notation-shelley}.
Similarly, if we compare these two tokens, we compare them as follows
(element-wise, with $\epsilon$ as the value associated to any currency ID
not present in on of the values),

\[ (\{ cid1 \mapsto tkns1\}~\leq~\{ cid2 \mapsto tkns2\}) \Leftrightarrow \\
   (tkns1 \leq \epsilon~\wedge~ \epsilon \leq tkns2) \]

\textbf{UTxO Helper Functions.}

Figure~\ref{fig:functions:utxo} defines additional calculations needed for the
UTxO transition system with MC:

\begin{itemize}

  \item $\fun{getCoin}$ adds up all the Ada in a given output and returns it as a
  $\Coin$ value

  \item $\fun{utxoAda}$ returns the set of all the outputs in a UTxO with only Ada
  tokens (the other tokens are ignored). This is used in the stake distribution
  calculation at the epoch boundary

  \item
    The $\fun{ubalance}$ function calculates the (aggregated by currency ID and
    Token) sum total of all the value in a given UTxO.

  \item The $\fun{consumed}$ calculation is still the sum of the reward address
   value consumed, the values of the UTxO entries consumed,
   and the value consumed from the deposit pot due
   to the transaction collecting deposit refunds. There is an additional
   summand in this calculation, the value forged by a transaction.
   This calculation now returns a $\Value$.

  \item The $\fun{produced}$ calculation sums up the same things
  as the corresponding $\fun{produced}$ calculation in Shelley.
  This calculation also returns a $\Value$.
\end{itemize}

\textbf{Produced and Consumed Calculations and Preservation of Value.}
Note that
the $\fun{consumed}$ and $\fun{produced}$ calculations both produce a $\Value$.
The reason for this is that the outputs of a transaction, as well as UTxO outputs,
are of the $\Value$ type. The administrative amounts (of the $\Coin$ type)
are converted into MC values for these summations.

While the preservation of value is a single
equality, it is really a comparison of token quantities aggregated by
$\Token$ and by $\CurrencyID$. In particular, ensuring that the produced
amount equals the consumed amount also implies that the total quantity of
Ada tokens is preserved.

\textbf{Forging and the Preservation of Value.}
What does it mean to preserve the value of non-Ada tokens, since they
are put in and taken out of circulation by the users themselves?
This is expressed by including the $\fun{forge}$ value of the transaction
in the preservation of value equation.

The \textit{produced} side of the equation adds up, among other things, the
values in the
outputs that will be added to the ledger UTxO by the transaction. These outputs are
where the
forged value is "put into of circulation", i.e. how it ends up in the UTxO.
Suppose a transaction $tx$ contains a single output $(a, cid \mapsto tkns)$. Suppose
also that it does not
have any inputs spending any UTxO outputs with currency ID $cid$.

A valid transaction $tx$ satisfies the preservation of value
condition by adding the value $cid \mapsto tkns$ to the \textit{consumed} side as well.
To do this, the $tx$ declares that it is forging the tokens $cid \mapsto tkns$
via the $\fun{forge}$ field, i.e. $tx$ must have

\[cid \mapsto tkns\in\fun{forge}~tx\]

The forge field value is then added to the consumed side. This approach
to balancing the POV equation extends
to cases where the transaction might also be consuming some existing $cid$ tokens,
or taking the out of circulation with negative quantities in the forge field.

The forge field value represents the change in total existing tokens of each given currency
as a result of processing the transaction. It is always added to the
\textit{consumed} side of the POV equation because of this side, the signs of the
quantities in the forge field match the signs of the change. That is,
when tokens are added into the UTxO, their quantities are positive, and when they are
taken out of circulation via the forge field, the signs are negative.

Note also that the UTXO rule only checks that the transaction is forging the
amount it has declared using the forge field (and that no Ada is forged).
The forging scripts themselves are not evaluated in this transition rule.
That step is part of witnessing, i.e. the UTXOW rule, see below.

\begin{figure}[htb]
  \emph{Helper Functions}
  \begin{align*}
    & \fun{getCoin} \in \UTxOOut \to \Coin \\
    & \fun{getCoin}~{\var{out}} ~=~\sum_{\mathsf{adaID} \mapsto tkns \in \fun{getValue}~out}
       (\sum_{q \in \range~{tkns}} \fun{co}~q) \\
    & \text{sum total of amount of Ada in an output}
    \nextdef
    & \fun{utxoAda} \in \UTxO \to \powerset{(\Addr \times \Coin)} \\
    & \fun{utxoAda}~{\var{utxo}} ~=~\{~(\fun{getAddr}~\var{out},~\fun{getCoin}~{out})
    ~\vert~ \var{out} \in \range~\var{utxo} ~\} \\
    & \text{returns the outputs in the UTxO with only the Ada coins} \\
    \nextdef
    & \fun{ubalance} \in \UTxO \to \Value \\
    & \fun{ubalance} ~ utxo = \sum_{\wcard\mapsto\var{u}\in~\var{utxo}}
    \fun{getValue}~\var{u} \\
    & \text{UTxO balance} \\
  \end{align*}
  %
  \emph{Produced and Consumed Calculations}
  \begin{align*}
    & \fun{consumed} \in \PParams \to \UTxO \to \StakeCreds \to \Wdrl \to \TxBody \to \Value \\
    & \consumed{pp}{utxo}{stkCreds}{rewards}~{txb} = \\
    & ~~\ubalance{(\txins{txb} \restrictdom \var{utxo})} + \\
    &~~  \fun{coinToValue}(\fun{wbalance}~(\fun{txwdrls}~{txb})~\\
        &~~+~ \keyRefunds{pp}{stkCreds}{txb}) +
        ~\fun{forge}~\var{txb} \\
    & \text{value consumed} \\
    \nextdef
    & \fun{produced} \to \PParams \to \StakePools \to \TxBody \to \Value \\
    & \fun{produced}~\var{pp}~\var{stpools}~\var{txb} = \\
    &~~\ubalance{(\fun{outs}~{txb})}  + \fun{coinToValue}(\txfee{txb} \\
    &~~+ \deposits{pp}{stpools}~{(\txcerts{txb})})\\
    & \text{value produced} \\
  \end{align*}
  \caption{UTxO Calculations}
  \label{fig:functions:utxo}
\end{figure}

\clearpage

\textbf{The UTXO Transition Rule.}
In Figure \ref{fig:rules:utxo-shelley}, we give the UTXO transition rule,
updated for MC support. There are the following changes to the preconditions
of this rule as compared to the original Shelley UTXO rule:

\begin{itemize}
  \item The transaction is not forging any Ada

  \item All outputs of the transaction contain only non-negative quantities
  (this is the $\Value$-type version to the corresponding rule about non-negative
  $\Coin$ amounts in the Shelley ledger rules)

  \item In the preservation of value calculation (which looks the same as in
  Shelly), the value in the $\fun{forge}$ field is taken into account
\end{itemize}

Note that updating the $\UTxO$ with the inputs and the outputs of the transaction
looks the same as in the Shelley rule, however, there is a type-level difference.
Recall that the outputs of a transaction contain a $\Value$ term, rather than
$\Coin$. Moreover, the $\fun{outs}$ map converts $\TxOut$ terms into $\UTxOOut$.

\begin{figure}[htb]
  \begin{equation}\label{eq:utxo-inductive-shelley}
    \inference[UTxO-inductive]
    { \var{txb}\leteq\txbody{tx}
      & \txttl txb \geq \var{slot}
      \\ \txins{txb} \neq \emptyset
      & \minfee{pp}{tx} \leq \txfee{txb}
      & \txins{txb} \subseteq \dom \var{utxo}
      \\
      \consumed{pp}{utxo}{stkCreds}{rewards}~{txb} = \produced{pp}{stpools}~{txb}
      \\
      ~
      \\
      {
        \begin{array}{r}
          \var{slot} \\
          \var{pp} \\
          \var{genDelegs} \\
        \end{array}
      }
      \vdash \var{ups} \trans{\hyperref[fig:rules:update]{up}}{\fun{txup}~\var{tx}} \var{ups'}
      \\
      ~
      \\
      \mathsf{adaID}~\notin \dom~{\fun{forge}~tx} \\
      \forall txout \in \txouts{txb}, ~ \fun{getValue}~txout  ~\geq ~ \epsilon \\~
      \\
      \fun{txsize}~{tx}\leq\fun{maxTxSize}~\var{pp}
      \\
      ~
      \\
      \var{refunded} \leteq \keyRefunds{pp}{stkCreds}~{txb}
      \\
      \var{decayed} \leteq \decayedTx{pp}{stkCreds}~{txb}
      \\
      \var{depositChange} \leteq
        \fun{totalDeposits}~{pp}{stpools}{(\txcerts{txb})} - (\var{refunded} + \var{decayed})
    }
    {
      \begin{array}{r}
        \var{slot}\\
        \var{pp}\\
        \var{stkCreds}\\
        \var{stpools}\\
        \var{genDelegs}\\
      \end{array}
      \vdash
      \left(
      \begin{array}{r}
        \var{utxo} \\
        \var{deposits} \\
        \var{fees} \\
        \var{ups}\\
      \end{array}
      \right)
      \trans{utxo}{tx}
      \left(
      \begin{array}{r}
        \varUpdate{(\txins{txb} \subtractdom \var{utxo}) \cup \fun{outs}{txb}}  \\
        \varUpdate{\var{deposits} + \var{depositChange}} \\
        \varUpdate{\var{fees} + \txfee{txb} + \var{decayed}} \\
        \varUpdate{ups'}\\
      \end{array}
      \right)
    }
  \end{equation}
  \caption{UTxO inference rules}
  \label{fig:rules:utxo-shelley}
\end{figure}

\clearpage

\textbf{Witnessing.}

We have changed the definition of the function
$\fun{scriptsNeeded}$, see Figure~\ref{fig:functions-witnesses}. There is
now an additional category of scripts that are needed for transaction validation,
the forging scripts.

Note that there are no restrictions on the use of forging scripts. Their hashes may
be used as credentials in UTxO entries, certificates, and withdrawals.
Non-MPS type scripts can also be used for forging, e.g. MSig scripts.

Note also that UTxO entries containing MC tokens, just like Shelley UTxO entries,
can be locked by a script. This script will add an additional set of
restrictions to the use of MC tokens (additional to the forging script
requirements, but enforced at spending time). This output-locking script can itself
also be a forging script.

\begin{figure}[htb]
  \begin{align*}
    & \hspace{-1cm}\fun{scriptsNeeded} \in \UTxO \to \Tx \to
      \powerset{\ScriptHash}
    & \text{required script hashes} \\
    &  \hspace{-1cm}\fun{scriptsNeeded}~\var{utxo}~\var{tx} = \\
    & ~~\{ \fun{validatorHash}~a \mid i \mapsto (a, \wcard) \in \var{utxo},\\
    & ~~~~~i\in\fun{txinsScript}~{(\fun{txins~\var{txb}})}~{utxo}\} \\
    \cup & ~~\{ \fun{stakeCred_{r}}~\var{a} \mid a \in \dom (\AddrRWDScr
           \restrictdom \fun{txwdrls}~\var{txb}) \} \\
      \cup & ~~(\AddrScr \cap \fun{certWitsNeeded}~{txb}) \\
      \cup & ~~\dom~(\fun{forge}~{txb}) \\
      & \where \\
      & ~~~~~~~ \var{txb}~=~\txbody{tx} \\
  \end{align*}
  \caption{Scripts Needed}
  \label{fig:functions-witnesses}
\end{figure}

\clearpage


\vssub
\subsection{~Source terms}
\vsssub
\subsubsection{~General concepts}
\vsssub

In deep water, the net source term $S$ is generally considered to consist of
three parts, an atmosphere-wave interaction term $S_{\mathrm{in}}$, which
is usually a positive energy input but can also be negative in the case of swell, a nonlinear wave-wave
interactions term $S_{\mathrm{nl}}$ and a wave-ocean interaction term that is generally dominated by wave breaking
$S_{\mathrm{ds}}$. The input term $S_{\mathrm{in}}$ is dominated by the
exponential wind-wave growth term, and this source term generally describes this
dominant process only. For model initialization, and to provide more realistic
initial wave growth, a linear input term $S_{\mathrm{ln}}$ can also be added in
\ws.

In shallow water additional processes have to be considered, most notably
wave-bottom interactions $S_{\mathrm{bot}}$ \cite[e.g.,][]{pro:Sea78}. In extremely
shallow water, an additional  breaking term ($S_{\mathrm{db}}$) should be considered,
if not well represented in  $S_{\mathrm{ds}}$ \citep[see][]{Filipot&Ardhuin2012}.
Triad wave-wave
interactions ($S_{\mathrm{tr}}$) may also be considered, but present parameterizations have limited accuracy.
Also available in \ws\ are source
terms for scattering of waves by bottom features ($S_{\mathrm{sc}}$), wave-ice
interactions ($S_{\mathrm{ice}}$), reflection off shorelines or floating objects such
as icebergs which can include sources of infragravity wave energy ($S_{\mathrm{ref}}$),  and a general purpose slot for additional, user
defined source terms ($S_{\mathrm{user}}$).

This defines the general source terms used in \ws\ as

%---------------------------------%
% General source term composition %
%---------------------------------%
% eq:general_st

\begin{equation}
S = S_{\mathrm{ln}} + S_{\mathrm{in}} + S_{\mathrm{nl}} + S_{\mathrm{ds}} + S_{\mathrm{bot}} + S_{\mathrm{db}}
    + S_{\mathrm{tr}} +
    S_{\mathrm{sc}} + S_{\mathrm{ice}} + S_{\mathrm{ref}} + S_{\mathrm{user}}\: .
\label{eq:general_st}
\end{equation}

\noindent
Other source terms could be easily added. Those source terms are defined for the
{\em energy} spectra. In the model, however, most source terms are directly
calculated for the action spectrum. The latter source terms are denoted as
$\cS \equiv S/\sigma$.

The explicit treatment of the nonlinear interactions defines third-generation wave
models. Therefore, the options for the calculation of $S_{\mathrm  nl}$ will be
discussed first, starting in section \ref{sec:NL1}. $S_{\mathrm  in}$ and $S_{\mathrm ds}$
represent separate processes, but are often interrelated,
because the balance of these two source terms governs the integral growth
characteristics of the wave energy. Several combinations of these basic source
terms are available, and are described in section~\ref{sec:ST1} and following.
The description of linear input starts in section~\ref{sec:LN1}, and
section~\ref{sec:BT1} and following describe available additional processes, mostly
related to shallow water and sea ice.

%\vspace{\baselineskip} \noindent

A third-generation wave model effectively integrates the spectrum only up to a
cut-off frequency $f_{hf}$ (or wavenumber $k_{hf}$), that is ideally equal to the
highest discretization frequency. In practice the source terms parameterization or the time step used may not allow a proper
balance to be obtained, and thus $f_{hf}$  may be taken within the model frequency range. Above the cut-off frequency a
parametric tail is applied \citep[e.g.,][]{art:WAM88}

%--------------------------------------%
% General tail parameterization E(f,t) %
%--------------------------------------%
% eq:tail_E_f

\begin{equation}
F(f_r,\theta) = F(f_{r,hf},\theta) \left ( \frac{f_r}{f_{r,hf}}
\right ) ^{-m} \label{eq:tail_E_f} ,
\end{equation}

\noindent
which is easily transformed to any other spectrum using the Jacobian
transformations as discussed above. For instance, for the present action
spectrum, the parametric tail can be expressed as (assuming deep water for the
wave components in the tail)

%--------------------------------------%
% General tail parameterization N(k,t) %
%--------------------------------------%
% eq:tail_N_k

\begin{equation}
N(k,\theta) = N(k_{hf},\theta) \left ( \frac{f_r}{f_{r,hf}}
\right ) ^{-m-2} \label{eq:tail_N_k} ,
\end{equation}

\noindent
the actual values of $m$ and the expressions for $f_{r,hf}$ depend on the
source term parameterization used, and will be given below.

%\vspace{\baselineskip} \noindent
Before actual source term parameterizations are described, the definition of
the wind requires some attention. In cases with currents, one can either
consider the wind to be defined in a fixed frame of reference, or in a frame
of reference moving with the current. Both definitions are available in \ws,
and can be selected during compilation. The output of the program, however,
will always be the wind speed which is not in any way corrected for the
current.

%\vspace{\baselineskip} \noindent
The treatment of partial ice coverage (ice concentration) in the source terms
follows the concept of a limited air-sea interface. This means that the momentum
transferred from the atmosphere to the waves is limited. Therefore, input and
dissipation terms are scaled by the fraction of ice concentration. The
nonlinear wave-wave interaction term can be used in areas of open water
and ice \citep{art:PL07}. The scaling is implemented so that it is independent
of the source term selected.


\subsection{Cryptographic Security}
\label{ssec:security}

\chgcomment{Not really sure if we need a specific section on this
but I will keep it for now.}

Security is essential, so we will discuss those results here.

Throughout the procedure, if there is ever cryptographic proof of
malicious action of $P_{i}\in\mathcal{P}$, then $P_{i}$'s stake
will be slashed and the entire process will restart.
This is different from the process described in~\cite{ethdkg};
there, bad actors of $\mathcal{P}$ are excluded from $\mathcal{Q}$
and any bad participant in $\mathcal{Q}$ who refuses to share
the necessary information can have it reconstructed by the other
participants.
We take a stronger stance because we want the threshold at the
beginning [$(t,n)$ where $t = \ceil{2n/3}-1$] to stay the same
throughout the entire process; that is, we require
$\mathcal{P} = \mathcal{Q}$.
As noted above, this is not strictly necessary in the second stage
because we have all of the information necessary to reconstruct
the secret $s_{i}$, but we take a firm stand against malicious
behavior.


\section{Second-order correlation analysis}

In this section, we analyse the effectiveness of the implemented countermeasures against second-order side-channel analysis based on the linear correlation coefficient (CPA). For this study, we will target the Sbox output value and consider a Hamming weight ($HW$) univariate leakage model.

In the remainder of this section, we will use:
\begin{itemize}

\item the centered product combination function $\mathcal{C}(x,y) = (x-\bar{x})(y-\bar{y})$ to preprocess the traces, where $\bar{x}$ (resp. $\bar{y}$) stands for the mean value of $x$ (resp. $y$), computed on all traces in our campaign;

\item the corresponding function $f_{HW}(z) = \sum_m (HW(z \oplus m) - \overline{HW(z\oplus m)})\\(HW(m)-\overline{HW(m)})$ to compute the predictions, where $\overline{HW(m)}$ (resp $\overline{HW(z \oplus m)}$) stands for the mean value of $HW(m)$ (resp. $HW(z\oplus m)$) computed on all possible values of $m$\footnote{Note that all possible values for $m$ are in $[0,255]$.}.
\end{itemize}

As in our first-order correlation analysis, we will split this study in two parts. The first part will consider priviledged knowledge on the mask values. The second part will not take this knowledge into account.

\subsection{Priviledged knowledge}
We first study the setting where the attacker knows the random masks used to compute the permutation.
In order to characterize the effectiveness of a CPA against this implementation, we use the random masks to recompute the permutation $Sh(i)$ for each byte index $i$.

For each byte index $i$, we use the characterization phase to isolate a window $w_{z\oplus m}$ of $11$ points of interest corresponding to the manipulation of the Sbox output $\rmult \times S[P[Sh(i)\oplus K[Sh(i)]] \oplus \rout$, and a window $w_m$ of $11$ points of interest corresponding to the manipulation of the mask value $\rout$. For each couple $(i,j)$ of points in $w_{z\oplus m} \times w_m$, we apply the combination function $\mathcal{C}(i,j)$.

\noindent We then perform an attack targeting the value $Z_{\hat{k}}[i]=S[P[Sh(i)] \oplus K[Sh(i)] \oplus \hat{k}]$, where $\hat{k}$ is an hypothesis on a value of one byte.

\subsubsection{Multiplicatively masked Sbox output}
We suppose the knowledge of the multiplicative mask $\rmult$. This knowledge allows for the prediction of the value $\rmult \times Z_{\hat{k}}[i]$ for any hypothesis $\hat{k}$.
The attack succeeds with around $8.000$ traces to $20.000$ traces.
Figure~\ref{fig:CPA2O_trickedaZ1} illustrates the results using $20.000$ traces.

\begin{figure}[H]
	\centering
	\includegraphics[scale=0.35]{figures/CPA2O_trickedaZ1.png}
	\caption{Correlation coefficients obtained when targeting $\rmult \times S[P[i]\oplus \hat{k}] $, for every value of $\hat{k}$. Correct hypothesis plotted in red. X-axis represents all 121 points combinations.}
	\label{fig:CPA2O_trickedaZ1}
\end{figure}

\subsubsection{Raw Sbox output}
We target the value $Z_{\hat{k}}[i]$ for any hypothesis $k$.
The attack does not succeed using the $100.000$ traces.
Figure~\ref{fig:CPA2O_trickedZ1} illustrates the results using $100.000$ traces.

\begin{figure}[H]
	\centering
	\includegraphics[scale=0.35]{figures/CPA2O_trickedZ1.png}
	\caption{Correlation coefficients obtained when targeting $S[P[i]\oplus \hat{k}] $, for every value of $\hat{k}$. Correct hypothesis plotted in red. X-axis represents all 121 points combinations.}
	\label{fig:CPA2O_trickedZ1}
\end{figure}

\subsection{Unknown permutation, processed traces}
We now study the setting where the attacker does not know the random masks used to compute the permutation.
We preprocess the traces in order to average the leakage over the different byte indices manipulation:
\begin{itemize}
	\item for each index $i$ in $[0,15]$, we define a small window $w_i$ of $\ell$ points around the SNR peak corresponding to the manipulation of $\rmult \times S[P[Sh(i)] \oplus K[Sh(i)]]\oplus \rout$ in the characterization phase. In our experiments, the size of the window was arbitrarily fixed to $\ell=11$.
	\item for each trace in our acquisition campaign, we compute the average window $m$ such that for each time sample $j$, $m[j]=\frac{1}{16}\sum_{i=0}^{15} w_i[j]$. We then consider $m$ as our reduced averaged trace of size $\ell$.
	\item we concatenate to this trace a small window of $\ell$ points around the SNR peak corresponding to the manipulation of $\rout$.
\end{itemize}

\subsubsection{Multiplicatively masked Sbox output}
We suppose the knowledge of the multiplicative mask $\rmult$. This knowledge allows for the prediction of the value $\rmult \times Z_{\hat{k}}[i]$ for any hypothesis $\hat{k}$.
The attack is unsuccessful using $100.000$ traces.

Figure~\ref{fig:CPA2O_averagedaZ1} illustrates the results using $100.000$ traces.
\begin{figure}[H]
	\centering
	\includegraphics[scale=0.35]{figures/CPA2O_averagedaZ1.png}
	\caption{Correlation coefficients obtained when targeting $\rmult \times S[P[i]\oplus \hat{k}] $, for every value of $\hat{k}$. Correct hypothesis plotted in red. X-axis represents all 121 points combinations.}
	\label{fig:CPA2O_averagedaZ1}
\end{figure}

However, we observe that, for certain combinations of points (around abscissa 135), the correct hypothesis is indeed the most likely. Furthermore, the rank convergence of the key, plotted on Figure~\ref{fig:convergence}, might indicate that the attack could be successful when using more traces.

\begin{figure}[H]
	\centering
	\includegraphics[scale=0.35]{figures/convergence.png}
	\caption{Rank of the ten best-ranked keys, by steps of 10000 measurements, from $10.000$ to $100.000$. Correct key plotted in red.}
	\label{fig:convergence}
\end{figure}

\subsubsection{Raw Sbox output}
We target the value $Z_{\hat{k}}[i]$ for any hypothesis $\hat{k}$.
The attack does not succeed using the $100.000$ traces.
Figure~\ref{fig:CPA2O_averagedZ1} illustrates the results using $100.000$ traces.
\begin{figure}[H]
	\centering
	\includegraphics[scale=0.35]{figures/CPA2O_averagedZ1.png}
	\caption{Correlation coefficients obtained when targeting $S[P[i]\oplus \hat{k}] $, for every value of $\hat{k}$. Correct hypothesis plotted in red. X-axis represents all 121 points combinations.}
	\label{fig:CPA2O_averagedZ1}
\end{figure}

\subsection{Unknown permutation, non-processed traces}
For the sake of completeness, we also perform these experiments on raw unprocessed traces. No success is obtained when targeting $Z_{\hat{k}}[i]$ or $\rmult \times Z_{\hat{k}}[i]$.

No attack is successful using $100.000$ traces.

\subsection{Summary}
This section evidences the effectiveness of the implemented countermeasures.
The shuffling countermeasures increases the number of needed measurements by a factor of at least $\frac{100.000}{8.000} = 12,5$. It is however likely that this countermeasure does not suffice when increasing slightly the number of measurements.
The effectiveness of the affine countermeasure is evidenced by the fact that a 2OCPA is achievable targeting the value $\rmult \times S[P[i] \oplus \hat{k}]$
but no attack is found targeting the value $S[P[i] \oplus \hat{k}]$ using $100.000$ traces.

\begin{figure}[h!]
\centering
\begin{tabular}{|c|c|c|c|c|}
  \hline
   & \multicolumn{2}{c|}{Known permutation}&\multicolumn{2}{c|}{Unknown permutation}\\
  \hline
  Known & $\rmult $ &  None  & $\rmult $  &  None \\
  \hline
  \# Traces& $\approx 8.000$ & $ > 100.000$ & $ > 100.000$ & $> 100.000$\\
  \hline
\end{tabular}
\caption{Number of traces needed for a successful second-order attack, in the different settings.}
\end{figure}


\chapter{Reference Manual --- VertEgg Version 0.9}

\section{Overview of the Toolbox}

The VertEgg toolbox  presently contain  the following tools,
grouped here according to functionality.

\begin{itemize}
  \item Initialise VertEgg
    \begin{itemize}
      \item \edb{ve\_init}
      \item \edb{ve\_grid(Hcol, dz)}
    \end{itemize}
  \item Make initial egg distribution
    \begin{itemize}
      \item \edb{spawn(M, Z)}
      \item \edb{ve\_rand(M)}
    \end{itemize}
  \item Compute the stationary solution
    \begin{itemize}
      \item \edb{eggsact(M, K, W, Z)}
      \item \edb{srcsact(K, W, P, alpha)}
      \item \edb{sstate(M, K, W)}
    \end{itemize}
  \item Solve the transient problem numerically
    \begin{itemize}
      \item \edb{fluxlim(A0, K, W, nstep, dt, P, alpha)}
      \item \edb{ftcs(A0, K, W, nstep, dt, P, alpha)}
      \item \edb{lwendrof(A0, K, W, nstep, dt, P, alpha)}
      \item \edb{upstream(A0, K, W, nstep, dt, P, alpha)}
    \end{itemize}
  \item Compute terminal egg velocity
    \begin{itemize}
      \item \edb{dens0(S, T)}
      \item \edb{eggvel(drho, d, mu)}
      \item \edb{eggvelst(S, T, d, Se)}
      \item \edb{molvisc(S, T)}
    \end{itemize}
  \item Analyse distributions
    \begin{itemize}
      \item \edb{eggmom(A, p)}
      \item \edb{ve\_drint(A, z1, z2)}
      \item \edb{ve\_int(A)}
      \item \edb{ve\_mean(A)}
      \item \edb{ve\_std(A)}
      \item \edb{ve\_rmsd(A, B)}
    \end{itemize}
\end{itemize}

\section{Description of the Tools}

{\parindent=0pt

\thead{dens0}{Sigma-T of sea water at zero pressure}

\begin{tdesc}
\item[Usage] \edb{sigma = dens0(S, T)}
\item[Input]
  \begin{vartab}
    \edb{S}  \> : \> Salinity     \>   [psu]   \\
    \edb{T}  \> : \> Temperature  \>   [\degC]
  \end{vartab}
  \edb{S} and \edb{T} may be arrays of the same shape.
\item[Output]
  \begin{vartab}
    \edb{sigma} \> : \> Sigma-T value \>  [\kgpcum]
  \end{vartab}
  \edb{sigma} is an array of the same shape as \edb{S} and \edb{T}.
\item[Description] \mbox{}\\
  \edb{dens0} computes the $\sigma_T$ value (density - 1000)
  of sea water at zero pressure.
  The density is computed by the international equation
  of state for sea water, UNESCO, 1980.
\end{tdesc}

\thead{eggmom}{Moment of egg distribution}

\begin{tdesc}
\item[Usage] \edb{M = eggmom(A, p)}
\item[Input]
  \begin{vartab}
  \edb{A}   \> : \> Egg distribution \>  [eggs/m$^3$] \\
  \edb{p}   \> : \> Order of moment
  \end{vartab}
  \edb{A} must be a matrix where the columns live on egg-points,
  but a row-vector at egg-points is also accepted,
  \edb{size(A) = (Ncell x n)} or \edb{(1 x Ncell)}
\item[Output]
  \begin{vartab}
  \edb{M}  \>  : \> The \edb{p}-th moment of \edb{A} \> [eggs m$^{p-2}$]
  \end{vartab}
  If \edb{A} is a matrix of size \edb{(Ncell x n)}, \edb{M} becomes a
  row-vector of length n containing the moments of
  the columns of \edb{A}. \edb{p} must not be negative.
\item[Description]\mbox{}\\
  Computes the \edb{p}-th moment of the egg-distribution \edb{A},
  \begin{displaymath}
      M = \int^0_{-H} z^p a(z) dz
  \end{displaymath}
   where $a(z)$ is the piecewise constant function
   $a(z) = \edb{A(i)}$ for $\edb{ZF(i+1)} < z < \edb{ZF(i)}$.
   If \edb{A} is a matrix, the moments of the columns are
   calculated.
\end{tdesc}

\thead{eggsact}{Exact stationary solution, const. coeff.}

\begin{tdesc}
\item[Usage] \edb{A = eggsact(M, K, W, Z)}
\item[Input]
  \begin{vartab}
  \edb{M}   \> : \> Vertical integrated concentration \>  [eggs/m$^2$] \\
  \edb{K}   \> : \> Eddy diffusivity     \> [\sqmps] \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps] \\
  \edb{Z} (opt) \> : \> Vertical coordinate  \> [\m]
  \end{vartab}
  \edb{M}, \edb{K}, \edb{W} are scalars. \edb{Z} can be arbitrary array.
  IF \edb{Z} is omitted, \edb{ZE} is used as vertical coordinates.
\item[Output]
  \begin{vartab}
  \edb{A}     \>  : \> Concentration at depth \edb{Z} \> [eggs/m$^3$]
  \end{vartab}
  If \edb{Z} is present, \edb{size(A) = size(Z)},
  otherwise, \edb{size(A) = size(ZE)}.
\item[Description]
   Computes the exact stationary solution of the
   convection diffusion equation with constant
   eddy diffusivity \edb{K} and velocity \edb{W}.
   If \edb{Z} is present, returns array of pointwise values.
   If \edb{Z} is not present, returns exact cell averages.
\end{tdesc}

\thead{eggvel}{Terminal egg velocity}

\begin{tdesc}
\item[Usage] \edb{[W, Re] = eggvel(drho, d, mu)}
\item[Input]
   \begin{vartab}
   \edb{drho}  \> : \> Buoyancy of egg  \> [\kgpcum] \\
   \edb{d}     \> : \> Diameter of egg  \> [\m] \\
   \edb{mu} (opt) \> :
         \> Dynamic molecular viscosity \>   [kgm$^{-1}$s$^{-1}$]
   \end{vartab}
   \edb{drho}, \edb{d} and \edb{mu} can be matrices (of the same shape).
   \edb{mu} can be also be a scalar or omitted.
   The sign of \edb{drho} is positive if the egg is ascending,
   \edb{drho} = Density of water - density of egg. With only two arguments,
   a default value 0.0016 is used for \edb{mu}.
\item[Output]
  \begin{vartab}
  \edb{W}   \> : \> Terminal velocity  \> [\mps] \\
  \edb{Re} (opt) \> : \> Reynolds number
  \end{vartab}
\item[Description]
  Computes the terminal velocity of a small sphere in sea water
  by the formulas in Stokes' or Dallavalles formula.
\end{tdesc}

\thead{eggvelst}{Egg velocity from salinity and temperature}

\begin{tdesc}
\item[Usage] \edb{[W, Re] = eggvelst(S, T, d, Se)}
\item[Input]
  \begin{vartab}
  \edb{S}  \>  : \> Salinity of the environment \> [psu]   \\
  \edb{T}  \>  : \> Temperature                 \> [\degC] \\
  \edb{d}  \>  : \> Egg diameter                \> [m]     \\
  \edb{Se} \>  : \> Egg salinity                \> [psu]
  \end{vartab}
  All arguments can be arrays of the same shape.
  Alternatively \edb{d} and/or \edb{Se} may be scalars.
\item[Output]
  \begin{vartab}
  \edb{W}    \> : \> Terminal velocity  \> [\mps] \\
  \edb{Re} (opt) \> : \> Reynolds number
  \end{vartab}
\item[Description]\mbox{}\\
  Computes the terminal egg velocity given the hydrography
  of the environment and the salinity \edb{Se} where the egg is
  neutral buoyant.
\end{tdesc}

\thead{fluxlim}{Numerical integration of transport equation}

\begin{tdesc}
\item[Usage] \edb{A = fluxlim(A0, K, W, nstep, dt, P, alpha)}
\item[Input]
  \begin{vartab}
  \edb{A0}  \> : \> Start concentration \>  [eggs/m$^3$] \\
  \edb{K}   \> : \> Eddy diffusivity    \>  [\sqmps]  \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps]  \\
  \edb{nstep}  \> : \> Number of integration steps \\
  \edb{dt}     \> : \> Time step           \>  [s] \\
  \edb{P}     (opt) \> : \> Spawning term       \>  [eggs/m$^3$/s] \\
  \edb{alpha} (opt) \> : \> Loss coefficient \> [1/s]
  \end{vartab}
  \edb{A0} lives at the egg-points, \edb{size(A0) = (Ncell x 1)}.
  \edb{K} and \edb{W} live at the flux-points, \edb{size = (Ncell+1 x1)}.
  If \edb{P} and \edb{alpha} are present, they also live at the egg-points.
  If \edb{P} and \edb{alpha} are missing, the source term is ignored.
\item[Output]
  \begin{vartab}
  \edb{A} \>  : \> Result concentration \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at egg-points in the same way as \edb{A0}
\item[Description]\mbox{}\\
  Integrates the convection-diffusion equation by the
  flux-limited method. Starting with the concentration
  in \edb{A0} nstep integration steps  are performed.
  The result is saved in \edb{A}.
\end{tdesc}

\thead{ftcs}{Numerical integration of transport equation}

\begin{tdesc}
\item[Usage] \edb{A = ftcs(A0, K, W, nstep, dt, P, alpha)}
\item[Input]
  \begin{vartab}
  \edb{A0}  \> : \> Start concentration \>  [eggs/m$^3$] \\
  \edb{K}   \> : \> Eddy diffusivity    \>  [\sqmps]  \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps]  \\
  \edb{nstep}  \> : \> Number of integration steps \\
  \edb{dt}     \> : \> Time step           \>  [s] \\
  \edb{P}     (opt) \> : \> Spawning term       \>  [eggs/m$^3$/s] \\
  \edb{alpha} (opt) \> : \> Loss coefficient \> [1/s]
  \end{vartab}
  \edb{A0} lives at the egg-points, \edb{size(A0) = (Ncell x 1)}.
  \edb{K} and \edb{W} live at the flux-points, \edb{size = (Ncell+1 x1)}.
  If \edb{P} and \edb{alpha} are present, they also live at the egg-points.
  If \edb{P} and \edb{alpha} are missing, the source term is ignored.
\item[Output]
  \begin{vartab}
  \edb{A} \>  : \> Result concentration \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at egg-points in the same way as \edb{A0}
\item[Description]\mbox{}\\
  Integrates the convection-diffusion equation by the
  forward time central space (FTCS)  method. Starting
  with the concentration in \edb{A0} nstep integration steps
  are performed. The result is saved in \edb{A}.
\end{tdesc}

\thead{lwendrof}{Numerical integration of transport equation}

\begin{tdesc}
\item[Usage] \edb{A = lwendrof(A0, K, W, nstep, dt, P, alpha)}
\item[Input]
  \begin{vartab}
  \edb{A0}  \> : \> Start concentration \>  [eggs/m$^3$] \\
  \edb{K}   \> : \> Eddy diffusivity    \>  [\sqmps]  \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps]  \\
  \edb{nstep}  \> : \> Number of integration steps \\
  \edb{dt}     \> : \> Time step           \>  [s] \\
  \edb{P}     (opt) \> : \> Spawning term       \>  [eggs/m$^3$/s] \\
  \edb{alpha} (opt) \> : \> Loss coefficient \> [1/s]
  \end{vartab}
  \edb{A0} lives at the egg-points, \edb{size(A0) = (Ncell x 1)}.
  \edb{K} and \edb{W} live at the flux-points, \edb{size = (Ncell+1 x1)}.
  If \edb{P} and \edb{alpha} are present, they also live at the egg-points.
  If \edb{P} and \edb{alpha} are missing, the source term is ignored.
\item[Output]
  \begin{vartab}
  \edb{A} \>  : \> Result concentration \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at egg-points in the same way as \edb{A0}
\item[Description]\mbox{}\\
  Integrates the convection-diffusion equation by the
  Lax-Wendroff method. Starting with the concentration
  in \edb{A0} nstep integration steps are performed. The
  result is saved in \edb{A}.
\end{tdesc}

\thead{molvisc}{Dynamical molecular viscosity of sea water}

\begin{tdesc}
\item[Usage] \edb{mu = molvisc(S, T)}
\item[Input]
  \begin{vartab}
    \edb{S}     \> : \> Salinity     \>   [psu]   \\
    \edb{T}     \> : \> Temperature  \>   [\degC]
  \end{vartab}
  \edb{S} and \edb{T} may be arrays of the same shape.
\item[Output]
  \begin{vartab}
    \edb{mu} \> : \> Dynamic molecular viscosity \>  [kgm$^{-1}$s$^{-1}$]
  \end{vartab}
  \edb{mu} is an array of the same shape as \edb{S} and \edb{T}.
\item[Description] \mbox{}\\
  Computes the dynamic molecular viscosity by formula~\eqref{eq:molvisc}.
\end{tdesc}

\thead{spawn}{Make concentrated egg distribution}

\begin{tdesc}
\item[Usage] \edb{A = spawn(M, Z)}
\item[Input]
  \begin{vartab}
  \edb{M} \> : \> Vertical integrated concentration \>  [eggs/m$^2$] \\
  \edb{Z} \> : \> Spawning depth              \>       [m]
  \end{vartab}
  \edb{M} and \edb{Z} are scalars.
\item[Output]
  \begin{vartab}
  \edb{A}  \> : \> Egg distribution     \>        [eggs/m$^3$]
  \end{vartab}
  \edb{A} is a column vector, living at the egg points.
\item[Description]\mbox{}\\
  Returns a vertical egg distribution \edb{A} with vertical
  integral \edb{M}, concentrated as much as possible around
  depth = \edb{Z}.
  If $\edb{ZE(Ncell)} < \edb{Z} < \edb{ZE(1)}$, then \edb{Z = ve\_mean(A)}.
\end{tdesc}

\thead{srcsact}{Stationary solution, const. coeff., source term}

\begin{tdesc}
\item[Usage] \edb{A = srcsact(K, W, P, alpha, Z)}
\item[Input]
  \begin{vartab}
    \edb{K} \> : \> Eddy diffusivity  \>  [\sqmps] \\
    \edb{W} \> : \> Terminal velocity \>  [\mps] \\
    \edb{P} \> : \> Egg production    \>  [eggs/m$^3$/s] \\
    \edb{alpha} \> : \> Egg loss rate  \>       [1/s] \\
    \edb{Z} (opt) \> : \> Vertical coordinate \>  [m]
  \end{vartab}
  \edb{K}, \edb{W}, \edb{P} and \edb{alpha} are scalars. \edb{Z} can
  be an arbitrary array.
  If \edb{Z} is ommitted, \edb{ZE} is used as vertical coordinate.
\item[Output]
  \begin{vartab}
    \edb{A} \> : \>  Concentration at depth \edb{Z}.  \>   [eggs/m$^3$]
  \end{vartab}
  If \edb{Z} is present, \edb{size(Y) = size(Z)},
  otherwise, \edb{size(Y) = size(ZE)}.
\item[Description]\mbox{}\\
   Computes the exact stationary solution of the
   convection diffusion equation with constant
   eddy diffusivity \edb{K}, velocity \edb{W}, egg production \edb{P}
   and loss rate \edb{alpha}.
   If \edb{Z} is present, returns array of pointwise values.
   If \edb{Z} is not present, returns exact cell averages.
\end{tdesc}

\thead{sstate}{Steady state solution}

\begin{tdesc}
\item[Usage] \edb{A = sstate(M, K, W)}
\item[Input]
  \begin{vartab}
  \edb{M} \>  : \> Vertical integrated concentration \> [eggs/m$^2$] \\
  \edb{K} \>  : \> Eddy diffusivity \> [\sqmps] \\
  \edb{W} \>  : \> Egg velocity   \>  [\mps]
  \end{vartab}
  \edb{M} is scalar, \edb{K} and \edb{W} are column vectors of
  length \edb{Ncell+1}, \edb{K} and \edb{W} live at the flux-points.
\item[Output]
  \begin{vartab}
  \edb{A}    \>  : \> Stationary solution \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at the egg points, \edb{size = (Ncell x 1)}.
\item[Description]\mbox{}\\
  Computes the steady state solution of the convection-
  diffusion equation without source term, with eddy diffusivity
  \edb{K} and egg
  velocity \edb{W} variable in the water column.
  The solution is computed by viewing \edb{K} and \edb{W}
  as piecewise constant on the grid cells.
\end{tdesc}

\thead{upstream}{Numerical integration of transport equation}

\begin{tdesc}
\item[Usage] \edb{A = upstream(A0, K, W, nstep, dt, P, alpha)}
\item[Input]
  \begin{vartab}
  \edb{A0}  \> : \> Start concentration \>  [eggs/m$^3$] \\
  \edb{K}   \> : \> Eddy diffusivity    \>  [\sqmps]  \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps]  \\
  \edb{nstep}  \> : \> Number of integration steps \\
  \edb{dt}     \> : \> Time step           \>  [s] \\
  \edb{P}     (opt) \> : \> Spawning term       \>  [eggs/m$^3$/s] \\
  \edb{alpha} (opt) \> : \> Loss coefficient \> [1/s]
  \end{vartab}
  \edb{A0} lives at the egg-points, \edb{size(A0) = (Ncell x 1)}.
  \edb{K} and \edb{W} live at the flux-points, \edb{size = (Ncell+1 x1)}.
  If \edb{P} and \edb{alpha} are present, they also live at the egg-points.
  If \edb{P} and \edb{alpha} are missing, the source term is ignored.
\item[Output]
  \begin{vartab}
  \edb{A} \>  : \> Result concentration \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at egg-points in the same way as \edb{A0}
\item[Description]\mbox{}\\
  Integrates the convection-diffusion equation by the
  upstream method. Starting with the concentration \edb{A0},
  nstep integration steps are performed. The result is
  saved in \edb{A}.
\end{tdesc}

\thead{ve\_drint}{Integrate over a depth range}

\begin{tdesc}
\item[Usage]  \edb{int = ve\_drint(A, z1, z2)}
\item[Input]
   \begin{vartab}
   \edb{A}  \> : \>  Egg distribution \> [eggs/m$^3$] \\
   \edb{z1} \> : \>  First integration limit \>  [\m] \\
   \edb{z2} \> : \> Second integration limit \> [\m]
   \end{vartab}
   \edb{A} must be a matrix where the columns are
   egg distributions. But a row-vector can also
   be accepted, \edb{size(A) = (Ncell x n)} or \edb{(1 x Ncell)}.
\item[Output]
   \begin{vartab}
   \edb{int} \> : \> Integral of A over depth range \> [eggs/m$^2$]
   \end{vartab}
   If \edb{A} is a matrix of size \edb{(Ncell x m)}, \edb{int} becomes
   a row-vector of length \edb{m} containing the integrals
   of the columns of A.
\item[Description]\mbox{}\\
    Computes the vertical integral
    \begin{displaymath}
      \edb{int} = \int_\edb{z1}^\edb{z2} a(z) dz
    \end{displaymath}
    where $a(z)$ is the piecewice constant function
    $a(z) = \edb{A(i)}$ for $\edb{ZF(i+1)} < z < \edb{ZF(i)}$.
    If \edb{A} is a matrix, the integral is computed for each column
\end{tdesc}

\thead{ve\_grid}{Set up vertical grid}

\begin{tdesc}
\item[Usage]  \edb{ve\_grid(H, dz0)}
\item[Input]
  \begin{vartab}
  \edb{H}        \>  : \> Depth of water column  \> [m] \\
  \edb{dz0}      \>  : \> Grid size              \> [m]
  \end{vartab}
\item[Output]
  None
\item[Description]\mbox{}\\
  Sets up the vertical grid used in VertEgg, given the depth
  \edb{H} of the water column and the grid size \edb{dz0}.
  (Re)defines all global variables.
  The global variables are declared by \edb{ve\_init}.
\end{tdesc}

\thead{ve\_init}{Initialize VertEgg}

\begin{tdesc}
\item[Usage] \edb{ve\_init}
\item[Input] none
\item[Output] none
\item[Description]\mbox{}\\
  Script for initializing VertEgg.
  Declares the global variables, so they become
  available in the workspace.
  The actual values are set by \edb{ve\_grid}.
\end{tdesc}

\thead{ve\_int}{Vertical integral of egg distribution}

\begin{tdesc}
\item[Usage] \edb{M = ve\_int(A)}
\item[Input]
  \begin{vartab}
  \edb{A} \>  : \> Egg distribution  \>  [eggs/m$^3$]
  \end{vartab}
  \edb{A} must be a matrix where the columns live on egg-points,
  but a row-vector at egg-points is also accepted,
  \edb{size(A) = (Ncell x n)} or \edb{(1 x Ncell)}
\item[Output]
  \begin{vartab}
  \edb{M}    \>  : \> The vertical integral \>  [eggs/m$^2$]
  \end{vartab}
  If \edb{A} is a matrix of size \edb{(Ncell x n)}, \edb{M} is a
  row-vector of length \edb{n}.
\item[Description]\mbox{}\\
  Computes the vertical integral of an egg distribution.
  \edb{ve\_int} is a vector function.
\end{tdesc}

\thead{ve\_mean}{Mean depth of an egg distribution}

\begin{tdesc}
\item[Usage] \edb{mu = ve\_mean(A)}
\item[Input]
  \begin{vartab}
  \edb{A}  \> :\>  Egg distribution   \>  [eggs/m$^3$]
  \end{vartab}
  \edb{A} must be a matrix where the columns live on egg-points,
  but a row-vector at egg-points is also accepted,
  \edb{size(A) = (Ncell x n)} or \edb{(1 x Ncell)}
\item[Output]
  \begin{vartab}
  \edb{mu}   \> : \> The center of gravity \>  [m]
  \end{vartab}
  If \edb{A} is a matrix of size \edb{(Ncell x n)}, \edb{mu} is a
  row-vector of length \edb{n}.
\item[Description]\mbox{}\\
  Computes the mean (or center of gravity) of the egg
  egg distribution \edb{A},
  \edb{ve\_mean} is a vector function.
\end{tdesc}

\thead{ve\_rand}{Make random egg distribution}

\begin{tdesc}
\item[Usage] \edb{Y = ve\_rand(M)}
\item[Input]
  \begin{vartab}
  \edb{M}    \>  : \> Vertical integrated concentration \> [eggs/m$^2$]
  \end{vartab}
  \edb{M} is a scalar
\item[Output]
  \begin{vartab}
  \edb{Y}    \>  : \>  Random egg distribution \> [eggs/m$^3$]
  \end{vartab}
  \edb{Y} is vector of size \edb{[Ncell 1]}

\item[Description]\mbox{}\\
  A uniform distribution is used to generate random
  values between 0 and 1. The values are scaled
  to make \edb{ve\_int(Y) = M}.
\end{tdesc}

\thead{ve\_rmsd}{Root mean square deviation}

\begin{tdesc}
\item[Usage] \edb{R = ve\_rmsd(X, Y)}
\item[Input]
  \begin{vartab}
  \edb{X} \> : \> Egg concentration  \>  [eggs/m$^3$] \\
  \edb{Y} \> : \> Egg concentration  \>  [eggs/m$^3$]
  \end{vartab}
  \edb{X} and \edb{Y} may be matrixes of the same size
  with \edb{Ncell} rows. \edb{X} and/or \edb{Y} may also be
  vectors of length \edb{Ncell}.
\item[Output]
  \begin{vartab}
  \edb{R} \>  : \> Root mean square deviation \> [eggs/m$^3$]
  \end{vartab}
  \edb{R} is a row vector with length =
  \edb{max(columns(X), columns(Y))}.
\item[Description]\mbox{}\\
  Computes the root mean square deviation \edb{R}
  between the columns of \edb{X} and \edb{Y}. If one
  argument is a vector, it is compared to
  all columns of the other argument.
  If \edb{X} and \edb{Y} are matrices
  \begin{displaymath}
    \edb{R(j)} =
    \sqrt{\frac{1}{\edb{Ncell}} \sum_\edb{i} (\edb{X(i,j)}-\edb{Y(i,j)})^2} .
  \end{displaymath}
  If \edb{Y} is a vector
  \begin{displaymath}
    \edb{R(j)} =
    \sqrt{\frac{1}{\edb{Ncell}} \sum_\edb{i} (\edb{X(i,j)}-\edb{Y(i)})^2} .
  \end{displaymath}
\end{tdesc}

\thead{ve\_std}{Standard deviation of egg distribution}

\begin{tdesc}
\item[Usage] \edb{s = ve\_std(A)}
\item[Input]
  \begin{vartab}
  \edb{A}    \> : \> Egg distribution  \>  [eggs/m$^3$]
  \end{vartab}
  \edb{A} must be a matrix where the columns live on egg-points,
  but a row-vector at egg-points is also accepted,
  size(A) = (Ncell x n) or (1 x Ncell)
\item[Output]
  \begin{vartab}
  \edb{s}   \>  : \> The standard deviation  \> [m]
  \end{vartab}
  If \edb{A} is a matrix of size (Ncell x n), s is a
  row-vector of length n.
\item[Description]\mbox{}\\
  Computes the standard deviation of an egg
  distribution \edb{A},
  \edb{ve\_std} is a vector function.
\end{tdesc}

} % \parindent=0pt


\section{Geometry}

\subsection{geometry}
\lstinputlisting{../Geometry/geometry.hpp}


\documentclass[aps,showpacs,12pt,onecolumn,prd,superscriptaddress,nofootinbib]{revtex4}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{color}
\usepackage{enumerate}
\usepackage{ulem}

\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand\ud{{\mathrm{d}}}
\newcommand\uD{{\mathrm{D}}}
\newcommand\calO{{\mathcal{O}}}
\newcommand\bfx{\mathbf{x}}
\newcommand{\ov}[1]{\overline{#1}}
\newcommand{\ph}[1]{\phantom{#1}}
\newcommand{\cte}{\mathrm{cte}}
\newcommand{\nn}{\nonumber}
\newcommand{\hatk}{\hat{k}}
\newcommand{\Hz}{\,\mathrm{Hz}}
\newcommand{\sinc}{\,\mathrm{sinc}}
\newcommand{\Msol}{M_{\odot}}
\newcommand{\bsub}{\begin{subequations}}
\newcommand{\esub}{\end{subequations}}
\newcommand\betaL{{\beta_{L}}}
\newcommand\lambdaL{{\lambda_{L}}}
\newcommand\varphiL{{\varphi_{L}}}
\newcommand\psiL{{\psi_{L}}}
\newcommand\C{{\cos(4\psi)}}
\newcommand\mc{{\mathcal{M}}}

\newcommand{\jgb}[1]{{\color{DarkGreen} #1}}

\begin{document}

\title{Astrometry Inference Note}

\author{John G. Baker}
\affiliation{Gravitational Astrophysics Laboratory, NASA Goddard Space Flight Center, 8800 Greenbelt Rd., Greenbelt, MD 20771, USA}

\date{\today}

\begin{abstract}

This is back of the envelope note on estimating incited GW direction by temporally extended GW observation from a moving platform.

\end{abstract}

\pacs{
04.80.Nn, % Gravitational wave detectors and experiments
95.30.Sf, % relativity and gravitation
95.55.Ym, % Gravitational radiation detectors
}

\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Introduction}

The basic idea is that we want to treat a 'synthetic aperature', but with measurements separated by space \emph{and time}. We need to compare the phases at two different spatial observation points to estimate a wavefront incidence angle. Befor doing so, however we need to first realize a time-transfer of the signals to a common time.  The time-transfer depends on the model of the signal and our measured knowledge of it at each time-separated observation.

For now we consider just two epochs of observation non-overlapping in time, but spatially separated because of the motion of the observatory. For this analysis we neglect any direct information about position from within each observation epoch (eg because of the attenna pattern, or finite instrument size) to focus only on the information gained by the instrument's motion.

\section{Minimally evolving source}

For an nearly monochromatic GW source, the signal model is nearly trivial, we will assume that the signal is monochromatic.
(An uncertain frequency drift would seem to break this analysis, as degenerate with the linearly computed phase difference
here, but observing over multiple orbits would break that degeneracy.)

For each epoch $\alpha$ of observation we assume some definition for an epoch-specific reference position $x^i_\alpha$ e.g.
the mean location of the observatory during that epoch and a similar epoch observation time $t_\alpha$.  Through the
observation we can estimate the incident wavefront phase $\varphi\alpha(t_\alpha)$
at that epoch's spacetime reference point.
We can compare the wavefront phases, by projecting them to some common reference time $t_0$ which we are free to select.
For a nearly monochromatic wavefront we estimate reference time phase from observation:
$$
\varphi_\alpha(t_0)\approx\varphi_\alpha(t_\alpha)+\omega_\alpha(t_\alpha)(t_0-t_\alpha) + \mathcal{O}\left(\frac{t_0-t_\alpha}{T_c}\right)
$$
where $\omega_\alpha$ is the signal frequency and $T_c$ is the intrinsic coherence time of the signal.
We won't have perfect knowledge of the epoch's phase and frequency. These will depend on how precisely these can be
inferred during the observation epoch, which in turn will also depend on the epoch SNR $\rho_\alpha$.

We estimate the error in the phase at reference time as
$$
\left(\delta\varphi_\alpha(t_0)\right)^2\approx\left(\delta\varphi_\alpha(t_\alpha)\right)^2+\left(\delta\omega_\alpha(t_0-t_\alpha)\right)^2.
$$
We approximate that the GW phase information content is uniformly distributed according to SNR within the signal so that we can approximate $\delta\varphi_\alpha(t_\alpha)\approx\bar{\delta\varphi}/(\rho_\alpha)$.  (For a chirping signal it might also be appropriate to make this proportional to $1/\omega_\alpha$.)

The estimate for error in the GW frequency estimate builds on that from the phase.  Suppose we split each epoch into two halves, then estimate
$$
\omega_\alpha(t_\alpha)\approx\frac{\varphi_{\alpha R}-\varphi_{\alpha L}}{T_\alpha/2}
$$
where $T_\alpha$ is the duration of the epoch. Again, if there is significant chirp during the epoch, more consideration is needed.  Then, again assuming equal distribution of phase info with $\rho$, and uniform accumulation of $\rho^2$ with time we estimate
$$
\left(\delta\omega_\alpha(t_\alpha)\right)^2\approx\frac{\left(\bar{\delta\varphi}\right)^2}{T_\alpha/2}\left(\frac{1}{\rho^2_{\alpha R}}+\frac{1}{\rho^2_{\alpha L}}\right).
$$
For the non-chirping example, the RHS is optimized when left and right SNRs are each equal to $\rho_\alpha/\sqrt2$.
$$
\delta\omega_\alpha(t_\alpha)\approx\sqrt{\frac{8}{\rho^2_\alpha T_\alpha}}\bar{\delta\varphi}
$$

Now can complete the estimate for the error in the phase at reference time as estimated by the epoch of observation
$$
\left(\delta\varphi_\alpha(t_0)\right)^2\approx\left(\frac{\delta\varphi}{\rho_\alpha}\right)^2\left(1 + 8\frac{\left(t_0-t_\alpha\right)^2 }{T_\alpha}\right).
$$

Now let us construct the angle estimate by comparing the reference phase measurments at epochs $a$ and $b$ between which the constellation has moved by $D=x_b-x_a$. We estimate the triangulation error by
$$
\left(\delta\theta\right)^2 \approx \frac{\lambda^2\left(\varphi_b(t_0)\right)^2+\left(\varphi_b(t_0)\right)^2}{D^2}
$$
where $\lambda$ is the GW wavelength.
Note that we have somewhat conservatively added all error terms in quadrature here. It is likely, though, there may be a common-mode phase errors particularly in the first (explicit phase error) term for each epoch.  Degneracy with intrinsic parameters, for instance, could be common mode.  The analysis assumes such error are not included here.  This likely reduces sensitivity to degeneracy.  In the end, we find that the frequency error terms dominate, where we only more subtle common-mode errors would enter.
If we assume that each epoch's squared SNR is propotional to its duration, then $\rho^2_\alpha=\rho^2(T_\alpha/T)$ where $\rho$ and $T$ are the SNR and duration of the full observation. We thus have
$$
\delta\theta\approx\frac{\lambda\bar{\delta\varphi}}{D}\left(\frac{T}{T_a}+\frac{T}{T-T_a} + 8\frac{\left(t_0-T_a/2\right)^2}{T^2_a} +8\frac{\left(t_0-(T+T_a)/2\right)^2}{(T-T_a)^2}\right)
$$
where we have assumed the epochs are consecutive with epoch $a$ beginning at $t=0$ so $b$ begins at $t=T_a$ and ends at $t=T$. Optimizing, we find minimum error at $T_a=t_0=T/2$, meaning that the minumum error construction is where there are equal durations (and equal SNR) for the two epochs and the phase is compared at the temporal midpoint.  Then,
$$
\bar{\delta\theta}\approx20\frac{\lambda\bar{\delta\varphi}}{D}.
$$
At this optimum, $4/5$ of the estimated comes from the frequency term.

Lastly, a good rough estimate for a good-quality observation is $\bar{\delta\varphi}\approx 1/\rho$, so
$$
\bar{\delta\theta}\approx20\frac{\lambda}{\rho D}.
$$
The factor or 20 is not something we had before.

\end{document}


\subsection{Pool of linear resources}
\label{tuto:pool}

We present an interface and implementation of a pool of linear resources where the
extended scope of the region enforces proper use of the resources.

\cref{intf:pool} contains the interface of the @Pool@ module.
A pool is parameterized by its content. The kind of the pool
depends on the content: linear content implies
a linear pool while unrestricted content yields an unrestricted pool.
The functions @Pool.create@ and @Pool.consume@
build/destroy a pool given creators/destructors for the elements
of the pool.
The function @Pool.use@ is the workhorse of the API, which
borrows a resource from the pool to a callback.
It takes a shared borrow of a pool (to enable concurrent access) and a
callback function.
The callback receives a exclusive borrow of an arbitrary resource from the pool.
The typing of the callback ensures
that this borrow is neither captured nor returned by the function.

This encapsulation is implemented with a universally quantified \emph{kind index variable} $r$.
The signature prescribes the type @&!(aff_r1,'a_1)@ for the
exclusive borrow of the resource with an affine kind at region nesting $r+1$. The return
type of the callback is constrained to kind @'k_2 <= aff_r@
so that the callback certainly cannot return the borrowed argument.
In a specific use of @Pool.use@, the index $r$ gets unified
with the current nesting level of regions so that the region for the
callback effectively gets ``inserted'' into the lexical nesting at the callsite.
%
\cref{ex:pool} shows a simple example using the @Pool@ module.

The implementation in \cref{impl:pool} represents a bag of resources
using a concurrent queue with atomic add and remove operations.
The implementation of the @Pool.create@ and @Pool.consume@
functions is straightforward.
The function @Pool.use@ first draws
an element from the pool (or creates a fresh element),
passes it down to the callback function @f@, and returns
it to the pool afterwards.
For clarity,
we explicitly delimit the region in \cref{line:pool:region} to ensure that
the return value of @f &!o@ does not capture @&!o@.
In practice, the type checker inserts this region automatically.

\begin{figure}[tp]
  \centering
  \begin{subfigure}[t]{0.5\linewidth}
\begin{lstlisting}
type ('a:'k) pool : 'k
create : (unit -> 'a) -> 'a pool
consume : ('a -> unit) -> 'a pool -> unit
use : ('a_1:'k_1),('a_2:'k_2),('k_2 <= aff_r) =>
  &('a_1 pool) -> (&!(aff_r1,'a_1) -{lin}> 'a_2) -{'k_1}> 'a_2
\end{lstlisting}
    \vspace{-8pt}
    \caption{Signature}
    \label{intf:pool}

\begin{lstlisting}
(*Using the pool in queries.*)
let create_user pool name =
  Pool.use &pool (fun connection ->
    Db.insert "users" [("name", name)] connection)

let uri = "postgresql://localhost:5432"
let main users =
  (*Create a database connection pool.*)
  let pool = Pool.create (fun _ -> Db.connect uri) in
  List.parallel_iter (create_user &pool) users;
  Pool.consume (fun c -> Db.close c)
\end{lstlisting}
    \vspace{-8pt}
    \caption{Example of use}
    \label{ex:pool}
  \end{subfigure}
  \hfill
  \begin{subfigure}[t]{0.45\linewidth}
\begin{lstlisting}
type ('a:'k) pool : 'k =
  { spawn: unit -> 'a; queue: 'a CQueue.t }
let create spawn =
  { spawn ; queue = CQueue.create () }
let consume f c = CQueue.iter f c.queue
let use { spawn ; queue } f =
  let o = match CQueue.pop &queue with
    | Some x -> x
    | None () -> spawn ()
  in
  let r = {| f &!o |} in(*@\label{line:pool:region}*)
  CQueue.push o &queue;
  r
\end{lstlisting}
    \vspace{-8pt}
    \caption{Implementation}
    \label{impl:pool}
  \end{subfigure}

  \caption{The \texttt{Pool} module}
  \label{fig:pool}
\end{figure}

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