\subsection{Original H.530 protocol description}\label{subsec:h5301}
The H.530 protocol tries to address the problem of the Diffie-Hellman communication protocol authentication. As described in \cite[p. 19]{sebmod2018}, without the authentication of half-keys, this protocol could lead to a \textit{man-in-the-middle} attack.
In this exercise, the authentication is based on a third entity \textit{s}, which is trusted by Alice (\textit{A}) and Bob (\textit{B}). Both \textit{A} and \textit{B} share a secret key with the trusted source \textit{s}, so this last entity is in charge of signing \textit{A} and \textit{B} authenticity in order to ensure both parts that the other part is trustworthy.
\begin{figure}[hb]
	\centering
	\input{tex/sequence_diagrams/h530_sequence_diagram}
	\caption{H.530 sequence diagram}
	\label{fig:h530trace}
\end{figure}
\\
As shown in \textit{Figure \ref{fig:h530trace}}, the protocol would be as follows:
\begin{itemize}
	\item First of all, Alice sends a message to Bob with her half-key. The message is signed so that the trustworthy entity can verify the author of that message as Alice.
	\item Bob asks the trustworthy entity about the authenticity of the message. He also includes his half-key and signs the message so that the trustworthy entity can verify the author of this message as Bob.
	\item If both signatures are correct, the trustworthy entity will respond Bob by sending a message in which it states that \textit{A} and \textit{B} are trustworthy. The message will be signed twice in order for both Alice and Bob to be able to verify the third party's verdict.
	\item Finally, when Bob verifies that Alice is trustworthy, he sends her a message with his half-key signed twice, one by the third party entity and the other by Bob himself, using the shared key $g^{XY}$.
	\item If Alice can verify the authenticity of the message, she will be able to send a message to Bob secured by their recently created shared key $g^{XY}$.
\end{itemize}
\subsection{Original H.530 protocol analysis with OFMC and protocol redefinition}\label{subsec:h5302}
As expected, OFMC \cite{sebmod2005} detects an attack, which trace can be found in \textit{Code 1}. This trace describes how a \textit{man-in-the-middle} attack could be done with this protocol:
\begin{itemize}
	\item	Alice shares her half-key, $g^{X_1}$ , with Bob. However, it is intercepted by an intruder.
	\item	The intruder opens the \textbf{first} session with Bob, pretending that he/she is Alice and making up the half-key ($X_2$ is set to 1, so $g^{X_2}=g$) and Alice's signature.
	\item	Bob asks the trustworthy entity to verify the malicious request, attaching to the message his half-key $g^{Y_1}$, but it is also intercepted by the intruder.
	\item	The intruder now reproduces the original message from Alice and sends it to Bob by opening the \textbf{second} session.
	\item	Bob asks again the trustworthy entity to verify this duplicated request, attaching to his message a new half-key, $g^{Y_2}$. The intruder forwards the message to the trustworthy entity and intercepts its response.
	\item	The trustworthy entity confirms that both Alice and Bob can be trusted. However, it does not sign any half-key to be used: Bob does not know that the original key, $g^{X_1}$, is the one that should be trusted.
\end{itemize}
\textit{Figure \ref{fig:h530traceattack}} shows a sequence diagram that illustrates the attack.\\
\begin{figure}[ht!]
	\centering
	\input{tex/sequence_diagrams/h530_attack_sequence_diagram}
	\caption{H.530 attack sequence diagram}
	\label{fig:h530traceattack}
\end{figure}
In \textit{"h530-fix.AnB"}, this issue is solved by making the trustworthy entity to sign not only Alice and Bob's identity but also the half-key $g^{X}$ A have decided to use for this session. With this small change, the security threat disappears: OFMC does not detect any attack.\\
A sequence diagram with the changes made to the protocol is shown in \textit{Figure \ref{fig:h530tracefix}}.
\begin{figure}[ht!]
	\centering
	\input{tex/sequence_diagrams/h530_fix_sequence_diagram}
	\caption{H.530 sequence diagram (fixed)}
	\label{fig:h530tracefix}
\end{figure}
\subsection{Fixed H.530 protocol with untrustworthy third party entity}\label{subsec:h5303}
By doing that, we are saying that the trustworthy entity cannot be trusted anymore: we cannot determine that an identity verification from S is safe.
As expected, once we have changed the entity and examined with OFMC, the simulator detects a potential attack, which steps are shown in \textit{Figure \ref{fig:h530traceS}}.
\begin{figure}[ht!]
	\centering
	\input{tex/sequence_diagrams/h530_fix_sequence_diagram_S}
	\caption{H.530 attack sequence diagram (untrustworthy third party entity)}
	\label{fig:h530traceS}
\end{figure}
\begin{itemize}
	\item	Alice shares her half-key, $g^{X}$, with Bob. However, it is intercepted by an intruder.
	\item	The intruder pretends to be Bob and the third party entity at the same time, sending to Alice a weak half-key $g^{Y=1}=g$. It reuses the signature provided by Alice in the first message and signs the message with their new insecure shared key $g^{XY}=g^X$, which could be simply extracted from Alice's original message. From the point of view of Alice, the message is legit, as it appears to be signed by the trustworthy entity and by Bob with their recently created shared key.
	\item	Alice sends an encrypted message to the intruder, believing that the receiver is Bob. The intruder is able to decrypt the message and reads its content.
\end{itemize}
This attack trace shows that, if the trustworthy server can be substituted by a \textit{man-in-the-middle} attack, it would be possible for an attacker to open a private, secure session with Alice, pretending that it is Bob the one at the other side.


\clearpage
\subsection{Scalar SM3 Acceleration}
\label{sec:scalar:sm3}

\begin{bytefield}[bitwidth={1.05em},endianness={big}]{32}
\bitheader{0-31} \\
\encsmthreepzero
\encsmthreepone
\end{bytefield}

\begin{cryptoisa}
RV32, RV64
    sm3p1 rd, rs1
    sm3p0 rd, rs1
\end{cryptoisa}

These instructions are designed to accelerate the SM3 secure
hash function\cite{ietf:sm3}.
They are based on work done in \cite{MJS:LWSHA:20}, and follow
the same pattern as the scalar SHA2 instructions
(Section \ref{sec:scalar:sha2}).

The instructions implement versions of the $P_0$ and $P_1$
permutations, per the SM3 specification \cite{ietf:sm3}.
RISC-V Sail model code for each instruction is found in figure
\ref{fig:sail:sm3}.

\begin{figure}[h]
\lstinputlisting[language=sail,firstline=98,lastline=106]{../extern/sail-riscv/model/riscv_insts_kext.sail}
\caption{RISC-V Sail model specification for the scalar RV32/RV64 SM3 instructions.}
\label{fig:sail:sm3}
\end{figure}


\documentclass[main_zanardi.tex]{subfiles}

\begin{document}

Zanardi from the University of Southern California.

\section{Distances over quantum state spaces}

\paragraph{What we will talk about}

What is a metric? "Trace norm distance"

Information theore
tical protocol

Battacharya distance; its infinitesimal version: the Fischer metric, the Fubini-Study metric: many body physics, Quantum Phase Transitions.

At zero temperature, we only have the ground state, there is no entropy, so how do transitions work?

The statements preceded by the word "claim" are left as exercises.

\subsection{Quantum theory recap}

We have \emph{states} and \emph{observables}. We call the system $S$, and its associated Hilbert space \(\H\). (No real quantum system is going to be truly isolated).

A state \(\rho\) is a density matrix, an observable is a Hermitian operator over \(\H\).

\begin{equation}
  S(\H) = \qty{\rho |\, \rho \geq 0, \, \Tr \rho = 1}
\end{equation}

Then \(\forall \phi \in \H: \ev{\rho}{\phi} \geq 0\), \(\rho = \rho ^\dag\).

\(\sigma (\rho) = \text{spectrum of } \rho = \qty{p_i}_i\). \(d = \dim (\H)\).

\(p_i \geq 0\), \(\sum_i p_i = 1\).

So quantum theory is just noncommutative probability theory.

\paragraph{Single qubit}.

\(\H \sim \mathbb{C}^2$, $\dim \H = 2$, $\rho = \frac{1}{2} \qty(\mathbb{1} + \vec{\lambda} \cdot \vec{\sigma})\).

\(\vec{\lambda}\) is the Bloch vector, \(\vec{\sigma}\) are the Pauli matrices.
If \(\abs{\vec{\lambda}} = 1\), we have a pure state.

\paragraph{Exercise}
Prove that \(\rho\) being a density matrix is equivalent to \(\abs{\lambda}\leq 1\), and that \(\abs{\lambda} = 1 \iff \rho^2 = \rho \iff \rho = \ketbra{\psi}\).

Creating convex combinations of states should always be allowed,  and we see this in the fact that the space of states is convex.

States are usually decomposable as probabilistic mixtures, which are convex combinations in "Bloch space" (or its generalizations).

\subsection{Telling states apart} We are given two states \(\rho _{1, \, 2}\): what is the measurement which maximizes the probability we will be able to tell one from the other?

Probability vectors: \(\vec{p} = (p_i)\), \(\vec{q} = (q_i)\). We can use the "\(\ell_1\)" metric:

\begin{equation}
  d(p, q) = \sum_i \abs{p_i - q_i}
\end{equation}

Claim: this is a distance.

Can we do the same for quantum states? In general, \([\rho_1,  \rho_2] \neq 0\), we do not have a common eigenbasis. Could we use the Frobenius metric? Eeh, not really.

We have a map from observables to numbers: \(A \rightarrow \Tr \qty(\rho A) = \langle A \rangle_\rho\).

We can do \(\sup{\abs{{\langle A \rangle_{\rho_1} - \langle A \rangle_{\rho_2}}}}\) (Over \(\norm{A} = 1\)).

\begin{equation}
  \norm{A} = \sup_{\psi \neq 0} \frac{\norm{A\psi}}{{\psi}}
\end{equation}

So our distance is

\begin{equation}
  d = \sup_{\norm{A}=1} \abs{\Tr \qty[A(\rho_1 - \rho_2)]}
\end{equation}

We know that

\begin{align}
  \abs{\Tr \qty(AB)} &= \sum_i b_i \ev{A}{i} \\
  &\leq \sum_i \abs{b_i} \ev{A}{i} \\
  &\leq \norm{A} \sum_i \abs{b_i} \\
  &\leq \norm{A} \Tr \abs{B}
\end{align}

Where \(B = \sum_i b_i \ketbra{i}\)),
and we call \(\norm{B}_1 = \Tr \abs{B}\), where the modulus of the operator can be thought of eigenvalue-wise (diagonalizing the operator, and then flipping the sign of all the negative eigenvalues).

So

\begin{equation}
  d \leq \norm{A} \norm{\rho_1 - \rho_2}_1 = \norm{\rho_1 - \rho_2}_1
\end{equation}

Claim: this in an equality (there \emph{always} exists an $A$ to do the job).

Do we get back the classical case if the matrices commute? Claim: yes.

We call \(D(\rho_1, \rho_2) = \frac{1}{2} \norm{\rho_1 - \rho_2}_1\). (since the $d$ we used before is upper-bounded by 2, by the triangular inequality).

"the duals of self-adjoint operators are traceles"?

\paragraph{Measurements}
Von Neumann orthogonal measurement we know about.

Generalized measurement: we have an ancillary system, mearure this system and then trace over it. This is not described by an orthogonal projection:

\paragraph{Positive Operator-Valued Measurement}

We have finitely many \(\qty{E_i}_i\), \(E_i \geq 0\),  \(\sum_i E_i = \mathbb{1}\).

\(\rho \rightarrow p_i = \Tr (\rho E_i)\).

2-element POVM: \(E_{1, \, 2} \geq 0\), we have our states \(\rho_{1, \, 2}\).

Say we get the states with \(50\%\) probability each, and we wish to distinguish them:

\begin{equation}
  P(\text{success}) = \frac{1}{2} \qty[\Tr(E_1 \rho_1) + \Tr(E_2 \rho_2)]
\end{equation}

\begin{equation}
  P(\text{error}) = \frac{1}{2} \qty[\Tr(E_1 \rho_2) + \Tr(E_2 \rho_1)]
\end{equation}

We want to maximize \(P(\text{success})\). We can rewrite it as:

\begin{align}
  P(\text{success}) &= \frac{1}{2} \qty[\Tr(E_1 \rho_1) + \Tr\qty((\mathbb{1} - E_1) \rho_2)] \\
  &= \frac{1}{2}\qty[1 + \Tr \qty(E_1 (\rho_1 - \rho_2))]
\end{align}

to maximize over $E_1$. The optimum (Claim) is

\begin{equation}
  P(\text{success}) = \frac{1}{2}\qty[1 + \frac{1}{2} \norm{\rho_1 + \rho_2}_1]
\end{equation}

Hellstrom optimal measurement?
This is 1 if they are maximally different, $1/2$ if they are indistinguishable.

$E_1$ should be the projection over the positive eigenvalues of the difference between the matrices.

\paragraph{Bhattacharyya distance}

We have two probability vectors \(\vec{p} = \qty(p_i)_i\), \(\vec{q} = \qty(q_i)_i\).
Normalized in the euclidean metric, if we take the square root component by component: \(V_p = \qty(\sqrt{p_i})_i\).

\begin{equation}
  d_B (\vec{p}, \vec{q}) = \cos^{-1} (\vec{V_p}, \vec{V_q})
\end{equation}

Claim: this is a distance.

\begin{equation}
  d_B (\vec{p}, \vec{q}) = \cos^{-1} \qty(\sum_i \sqrt{p_i q_i})
\end{equation}

\paragraph{Quantize it!}

Let us focus on the pure state case:
we have a POVM \(\mathbb{E} = \qty{E_i}\), and two probability distributions \(\rho = \ketbra{\phi}\), \(\sigma = \ketbra{\psi}\)

\begin{equation}
  P_\phi (i) \defeq \Tr (E_i \rho) = \ev{\phi}{E_i}
\end{equation}

and similarly for \(\psi\).

The Bhattacharyya distance is

\begin{equation}
  d_B (\phi, \psi) = \sup _\mathbb{E} d_B\qty(\vec{P_\phi}, \vec{P_\psi})
\end{equation}

Theorem:

\begin{equation}
  d_B (\phi, \psi) = \cos^{-1} \abs{\braket{\phi}{\psi}}
\end{equation}

this is the Fubini-Study metric over a projective Hilbert space.

We can generalize this to differential geometry.

\begin{greenbox}
  In this particular case this can be expressed as
  \(\abs{\braket{\phi}{\psi}} = \sqrt{\Tr \qty(\rho\sigma)}\)
  but the result does not generalize.
\end{greenbox}
\end{document}


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

\section{Objectives of the chapter}
\label{sec-ch4objectiv}

In \Cref{sec-sheath_validation}, we have seen that the plasma-wall interaction observed in the \ac{2D} \ac{PIC} simulations are different from the classical sheath models.
We recall here the main observations of \cref{ch-2}.
We have conducted a parametric study on the wall emissivity by varying the crossover energy $\crover$ in the emission probability
\begin{equation*}
  \proba = \sigo + ( 1 - \sigo) \frac{\ek}{\crover},
\end{equation*}
with $\ek$ the electron kinetic energy.
The \ac{SEE} rate (or yield) $\rate$ is the emission probability $\proba$ averaged over the electron flux at the wall.
With a Maxwellian flux of temperature $\Te$, we have
\begin{equation}  \label{eq-rate2}
  \ratemaxw = \sigo + ( 1 - \sigo) \frac{2 \Te}{\crover}.
\end{equation}
The sheath model with \ac{SEE} predicts a potential drop between the sheath-edge and the wall of \citep{goebel2008,hobbs1967}
\begin{equation} \label{eq-dphi2}
  \dphi = \Te \log \lp [1 - \rate] \sqrt{\frac{m_i}{2 \pi m_e}}  \rp.
\end{equation}

In \cref{ch-2}, \cref{fig-seeparamesMaxw} and \cref{fig-Tevsproba}.{\bf a} (reproduced here in \cref{fig-Tevsproba2} to ease the reading of the chapter) show both the plasma potential $\dphi$ and the \ac{SEE} rate $\rate$ measured in the \ac{PIC} simulations and obtained from \Cref{eq-rate2,eq-dphi2}.
We see that the plasma potential is overestimated for low values of $\rate$ by around 30\%.
Moreover, the \ac{SEE} rate is also overestimated.

\begin{figure}[hbt]
  \centering
  \begin{tabular}{@{} cc}
    \includegraphics[width=0.45\textwidth]{phi_drop_6}
    &
    \subfigure{SEE_rates}{{\scriptsize b}}{20,18}
  \end{tabular}
  \caption{({\bf a}) Plasma potential drop to the wall $\dphi$ normalized by the electron bulk temperature $\Te$ as a function of the electron rate (blue) measured in the \acs{PIC} simulations and (orange) calculated with   \cref{eq-dphi2}; ({\bf b})  the \acs{SEE} rate $\rate$ (blue) measured in the PIC simulation, and (orange)  calculated with \cref{eq-rate2}. }
  \label{fig-Tevsproba2}
\end{figure}

The discrepancy is most certainly due to the isothermal hypothesis.
In \cref{ch-3}, we have developed a sheath model without the isothermal hypothesis, but instead the polytropic state law.
The objective of this chapter is to add to the polytropic sheath model of \cref{ch-3} the electron emission from the wall, in order to better predict the plasma-wall interaction.


\section{Introduction}
  Modern online marketplaces can be roughly categorized as centralized and decentralized.
  Two major examples of each category are \href{http://www.ebay.com}{ebay} and \href{https://openbazaar.org/}{OpenBazaar}.
  The common denominator of established online marketplaces is that the reputation of each vendor and client is either
  expressed in the form of stars and user-generated reviews that are viewable by the whole network, or not expressed at
  all inside the marketplace and instead is entirely built on word-of-mouth or other out-of-band means.

  The goal of "Trust Is Risk" is to offer a decentralized marketplace where the trust each user gives to the rest of the users
  is quantifiable, measurable and expressable in monetary terms. The central concept used throughout this paper is that trust
  is equivalent to risk, or the proposition that $Alice$'s \textit{trust} to another user $Bob$ is defined to be the
  \textit{maximum sum of money} that $Alice$ can lose when $Bob$ is free to choose any strategy he wants. To flesh out this
  concept, we will use \textit{lines of credit} as proposed by Washington Sanchez \cite{loc}, not to be confused with the
  synonymous financial product. Joining the network will be done by explicitly entrusting a certain amount of money to another
  user, say $Bob$. If $Bob$ has already entrusted an amount of money to a third user, $Charlie$, then we indirectly trust
  $Charlie$ since if the latter wished to play unfairly, he could have already stolen the money entrusted to him by $Bob$.
  Thus we can engage in economic interaction with $Charlie$. The currency used is Bitcoin \cite{bitcoin}.
  \medskip \ \\
  \subimport{common/figures/}{simpleexample.tikz} \smallskip \ \\
  We thus propose a new kind of wallet where coins are not stored locally, but are placed in 1-of-2 multisigs, a bitcoin
  construction that permits any one of two pre-designated users to spend the coins contained therein \cite{masteringbitcoin}.
  We will use the notation 1/$\{Alice, Bob\}$ to represent a 1-of-2 multisig that can be spent by either $Alice$ or $Bob$.

  Our approach changes the user experience in a subtle but drastic way. A user no more has to base her trust towards a store
  on stars or ratings which are not expressed in financial units. She can simply consult her wallet to decide whether the
  store is trustworthy and, if so, up to what value, denominated in bitcoin. This system works as follows: Initially $Alice$
  migrates her funds from her private bitcoin wallet to 1-of-2 multisig addresses shared with friends she comfortably trusts.
  We call this direct trust. Our system is agnostic to the means players use to determine who is trustworthy for these direct
  1-of-2 deposits. One novelty of our system is that this dubious kind of trust is confined to the direct neighbourhood of
  each player; indirect trust towards unknown users is calculated by a deterministic algorithm.  For comparison, systems with
  global ratings do not distinguish between neighbours and other users, thus offering dubious trust indications for all users.

  Suppose that $Alice$ is viewing the item listings of vendor $Charlie$. Instead of $Charlie$'s stars, $Alice$ will see a
  positive value that is calculated by her wallet and represents the maximum monetary value that $Alice$ can safely use to
  complete a purchase from $Charlie$. We examine exactly how this value, known as indirect trust, is calculated in Trust Flow
  theorem~\ref{trustflow}. It is important to note here that indirect trust to a specific user is not global but subjective;
  each user views a personalized indirect trust based on the network topology. The indirect trust reported by our system
  maintains the following desired security property: If $Alice$ makes a purchase from $Charlie$, then she is exposed to no
  more risk than she was already taking willingly. The existing willing risk is exactly that which $Alice$ was taking by
  sharing her coins with her trusted friends. We prove this result in the Risk Invariance theorem~\ref{riskinv}. Obviously it
  will not be safe for $Alice$ to buy anything from $Charlie$ or any other vendor if she has entrusted no value to any other
  user.

  We see that in Trust Is Risk the money is not invested at the time of the purchase and directly to the vendor, but at an
  earlier point in time and only to parties that are trustworthy for out of band reasons. The fact that this system can
  function in a completely decentralized fashion will become clear in the following sections. We prove this result in the
  Sybil Resilience theorem~\ref{sybil}.

  There are several incentives for a user to join this network. First of all, she can have access to a store that is
  otherwise inaccessible. Moreover, two friends can formalize their mutual trust by entrusting the same amount to each
  other. A large company that casually subcontracts other companies to complete various tasks can express its trust
  towards them using this method. A government can choose to entrust its citizens with money and confront them using a
  corresponding legal arsenal if they make irresponsible use of this trust. A bank can provide loans as outgoing and
  manage savings as incoming trust and thus has a unique opportunity of expressing in a formal and absolute way its
  credence by publishing its incoming and outgoing trust. Last but not least, the network can be viewed as a possible
  field for investment and speculation since it constitutes a completely new area for financial activity.

  It is worth noting that the same physical person can maintain multiple pseudonymous identities in the same trust network
  and that multiple independent trust networks for different purposes can coexist. On the other hand, the same
  pseudonymous identity can be used to establish trust in different contexts.


\section{Not simply-connected 2D manifolds}


\chapter{Methodology}
\label{ch:methods}

%This chapter should introduce to the theoretical background of your thesis. Any method you use to obtain the results later should be introduced and explained.
This chapter introduces the methods that are applied in this thesis. The first group of methods comprises the used forecasting methods, the second group involves feature selection techniques and the last group covers methods that are used to evaluate forecasts.\\
%This chapter introduces the methods that are applied in this thesis. First, the used forecasting methods are introduced. After that, the used feature selection techniques are explained and also the methods that were applied for error measuring.\\
%In this chapter, the used forecasting methods are explained and why they were used. After that, other methodological aspects of this thesis will be outlined.\\

%Using weather data from ECMWF Copernicus Climate Change Service (C3S).\\
%Using load data from \url{https://data.open-power-system-data.org/}.\\
%First downloaded whole Datasets from 2006-2019, but as the load for germany is properly available since 2015, now reduced dataset to 2015-2019.\\
%Also checked for non-existing values, only 2 last timestamps values for the load are missing.\\

%\section{Data acquisition}
%\label{sec:dataq}
%
%In order to acquire the needed weather data, \gls{ecmwf}'s Python-API is used for automated data acquisition. The API has been extended by some functionality recently and allows to download the data with different extensions. The chosen extension is .nc, because Python's xarray library allows performant access to these files.\\
%
%The used load data has been downloaded from Open Power System Data\footnote{\url{https://data.open-power-system-data.org/time_series/}}. As the format of the downloaded data is .csv, it has also been converted to .nc to obtain performant and uniform access to all data.\\

\section{Forecasting Methods}
\label{sec:forecastmet}

For time series forecasting, often used methods are \eg \gls{arma} models as mentioned in \tcite{Hyndman2018}. This sections will introduce the methods that are applied in this thesis to forecast the electricity load.\\% Forecasting: Principles and Practice\footnote{\url{https://otexts.com/fpp2}}.%, but  also \gls{nn}, where it is common to reduce the number of input variables in order to speed up computation, which is desirable for the huge amount of grid-based data that grows quadratically with size. There are also some papers that use regression models other than \gls{arma} such as \gls{lr}, \gls{mlr} or \gls{svm}. \tcite{Aguiar2016} applies \gls{nn} to do intra-day solar radiation forecasting with a forecasting horizon of 1-6 hours on Gran Canaria and, as in this thesis, grid-based data from \gls{ecmwf} is used.\\

%\subsection{Linear Regression}
\subsection*{ARMA}

The \gls{arma} model is a combination of \acrfull{ar} and \gls{ma} terms. The formal description is given by\\

\begin{equation}
y_t = c+\sum_{i=1}^{p}\phi_iy_{t-i}+\sum_{j=1}^{q}\rho_j\epsilon_{t-j}+\epsilon_t~,
\label{eq:arma}
\end{equation}

with $c$ as a constant, $\epsilon_t$ as noise term with respect to time $t$, $p$ as size of the \gls{ar} part, $q$ as size of the \gls{ma} part, $\phi$ and $\rho$ for the \gls{ar} and \gls{ma} coefficients respectively and $y_t$ as the response variable.\\

\subsection*{ARMAX}

An extension of \gls{arma} is \gls{armax}, which includes an additional term for exogenous variables. This term can be used to include relations to external factors that do not depend on the endogenous data. It is formally described as\\

\begin{equation}
y_t = c+\sum_{i=1}^{p}\phi_iy_{t-i}+\sum_{j=1}^{q}\rho_j\epsilon_{t-j}+\sum_{k=1}^{n}\eta_kx_k+\epsilon_t~.
\label{eq:armax}
\end{equation}

The only difference between \Cref{eq:armax} and \Cref{eq:arma} is the additional term $\sum_{k=1}^{n}\eta_kx_k$ for the \gls{armax} for $n$ included exogenous variables $x$ with $\eta$ as the respective coefficients.\\
%\Cref{eq:armax} almost equals \Cref{eq:arma} for the \gls{arma} model, but here, there is an additional term $\sum_{k=1}^{n}\eta_kx_k$ for $n$ included exogenous variables $x$ with $\eta$ as the respective coefficients.

%\subsubsection{only calendar variables as exogenous inputs}
%
%\subsubsection{additional weather variables as exogenous inputs}

\section{Feature Selection Techniques}
\label{sec:featsel}

Because the used weather data is grid-based, there are two more dimensions than usual, where only one value per time step exists for a variable. This is why feature selection here is more important in order to obtain a reasonable computation time. In the following, the used methods for feature selection are presented.\\

\subsection*{Naive approach}

First, naive techniques are presented, that are used to reduce the huge amount of grid-based weather data. They are reduced along the two spatial dimensions, longitude and latitude, for each step in time, respectively. These are simple functions such as the maximum or the mean. An exemplary formula for reducing the data along longitude and latitude using the mean is given as\\

\begin{equation}
x_t = \frac{1}{l \times m} \sum_{i=1}^{l}\sum_{j=1}^{m}x_{ij}~,
\end{equation}

where $x_t$ is the calculated mean for time $t$, $l$ and $m$ are the size of the data along the axis of the longitude and latitude and $x_{ij}$ is the value of a weather variable at the grid point with longitude $i$ and latitude $j$.

\subsection*{Using Population Data}

Another method involves population data from Eurostat\footnote{\url{https://ec.europa.eu/eurostat/data/database}}. It contains the population of NUTS 3 level regions. The regions are sorted by population and those with the highest population are used to filter the respective grid points that are then used as exogenous variables.\\

%\subsection{Principal Component Analysis}

\section{Forecast Evaluation}
\label{sec:fceval}

In order to estimate whether the used model performs well, it is important to apply suitable metrics to evaluate the results. In the following, the four used metrics are introduced, where for each metric, $k$ is the number of forecast values, $y$ the actual values and $\hat{y}$ the predicted values.\\

\subsection*{Root Mean Squared Error}

The first metric is the \gls{rmse}, which is an often used, scale-dependent accuracy measure that calculates the root of the squared mean of the differences between the forecast and the actual values. It is described by\\

\begin{equation}
RMSE = \sqrt{\frac{1}{k} \sum_{i=1}^{k} (y_i-\hat{y}_i)^2}~.
\label{eq:rmse}
\end{equation}

\subsection*{Mean Absolute Error}

The second metric is the \gls{mae}, which is another scale-dependent accuracy measure that averages absolute errors. The equation for the \gls{mae} is described by\\

\begin{equation}
MAE = \frac{1}{k} \sum_{i=1}^{k} \left|y_i-\hat{y}_i\right|~.
\end{equation}

\subsection*{Mean Percentage Error}

The third metric is the \gls{mpe}, which is a relative measure of the prediction accuracy. Since it is multiplied by 100 after dividing it by the size of the predictions, it is called a percentage error. The equation is\\
%The \gls{mpe} is the computed average of percentage errors by which forecasts of a model differ from actual values of the quantity being forecast

\begin{equation}
MPE = \frac{100}{k} \sum_{i=1}^{k} \frac{y_i-\hat{y}_i}{y_i}~.
\end{equation}

\subsection*{Mean Absolute Percentage Error}

The fourth metric is the \gls{mape}, which is similar to the \gls{mpe}, but takes the absolute value of each single error instead. The equation for the \gls{mape} is given by\\

\begin{equation}
MAPE = \frac{1}{k}\times 100 \sum_{i=1}^{k} \left|\frac{y_i-\hat{y}_i}{y_i}\right|~.
\label{eq:mape}
\end{equation}

%Maybe use Random Forests for variable selection as in Nicoles paper? \Parencite{Ludwig2015}\\

%This is an example for a simple equation without equation numbering.
%$$
%\sum\limits_{i=1}^{n}{x_i}
%$$

%You can also use equation numbering if you need to refer to an equation later \eg \Cref{eq:ex1}.

%\begin{equation}
%a^2 + b^2 = c^2
%\label{eq:ex1}
%\end{equation}
%
%Additionally, simple equations can be put inline with the text, for example, $x \in X$. Remember to set all variables in math font \ie all $x$, $i$ and so on.
%
%\section{Method 2}
%
%\dots


\chapter{The Second Chapter}
\label{sec:second}

\kant[7-11] % Dummy text

\begin{theorem}[{\cite[95]{AM69}}]
    \label{thm:dedekind}
    Let \( A \) be a Noetherian domain of dimension one. Then the following are equivalent:
    \begin{enumerate}
        \item \( A \) is integrally closed;
        \item Every primary ideal in \( A \) is a prime power;
        \item Every local ring \( A_\mathfrak{p} \) \( (\mathfrak{p} \neq 0) \) is a discrete valuation ring.
    \end{enumerate}
\end{theorem}


\documentclass[12pt]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{parskip}
\usepackage{lipsum}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{setspace}
\usepackage[superscript]{cite}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{listings}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ifsym}
\usepackage{tikz}

\begin{document}

	\begin{flushright}
		\today
	\end{flushright}
	{\Large \textbf{Assignment 11}}

	{\large Query Optimization}

	\textsc{Ilaria Battiston - 03723403} \\
	\textsc{Mareva Zenelaj - 03736071}

	\rule{\linewidth}{0.5pt}

	\section{First exercise}

	$m = 3$

	$n = 2$

	$N = m * n = 6$

	$k = 2$

	$p = \frac{\binom{N - k}{k}}{\binom{N}{k}} = \frac{\binom{4}{2}}{\binom{6}{2}} = \frac{6}{15}$

	$\overline{{Yao}}_n^{N,m} (k) = m * {Yao}_n^N (k)$

	since $k \leq N - n$ then ${Yao}_2^6 (2) = 1 - p = 1 - 0.4 = 0.6$

	$\overline{{Yao}}_2^{6,3} (2) = 3 * 0.6 = 1.8$

	\section{Second exercise}

	$m = 3$

	$n = 2$

	$N = m * n = 6$

	$k = 4$

	Since the tuples are not necessarily distinct, we use Cheung's formula.

	$\overline{{Cheung}}_n^{N,m} (k) = m * {Cheung}_n^N (k)$

	where

    ${Cheung}_n^N (k) = [1-\tilde{p}]$

    and $\tilde{p} = \prod_{i=0}^{k-1} \frac{N-n+i}{N+i}$

    $\tilde{p} = \prod_{i=0}^{3} \frac{4+i}{6+i} = \frac{4}{6} * \frac{5}{7} * \frac{6}{8} * \frac{7}{9} = 0.278$

    $\overline{{Cheung}}_2^{6,3} = 3 * (1 - 0.278) = 2.167 $

    \section{Third exercise}

    \begin{center}
    \includegraphics[width=\textwidth]{yao_bernstein_waters.png}
    \end{center}

    Yao and Waters (red and green) results overlap in the graph.

    \section{Fourth exercise}

    \begin{center}
    \includegraphics[width=\textwidth]{cheung_cardenas.png}
    \end{center}

    Below we include all results together:
    \begin{center}
    \includegraphics[width=\textwidth]{all_approx.png}
    \end{center}

\end{document}


\section{Derived proof rules}

\subsection{Base logic}

\ralf{Give the most important derived rules.}

\paragraph{Persistent assertions.}
\begin{defn}
  An assertion $\prop$ is \emph{persistent} if $\prop \proves \always\prop$.
\end{defn}

Of course, $\always\prop$ is persistent for any $\prop$.
Furthermore, by the proof rules given above, $t = t'$ as well as $\ownGGhost{\mcore\melt}$ and $\knowInv\iname\prop$ are persistent.
Persistence is preserved by conjunction, disjunction, separating conjunction as well as universal and existential quantification.

In our proofs, we will implicitly add and remove $\always$ from persistent assertions as necessary, and generally treat them like normal, non-linear assumptions.

\subsection{Program logic}

\ralf{Sync this with Coq.}

Hoare triples and view shifts are syntactic sugar for weakest (liberal) preconditions and primitive view shifts, respectively:
\[
\hoare{\prop}{\expr}{\Ret\val.\propB}[\mask] \eqdef \always{(\prop \Ra \wpre{\expr}{\lambda\Ret\val.\propB}[\mask])}
\qquad\qquad
\begin{aligned}
\prop \vs[\mask_1][\mask_2] \propB &\eqdef \always{(\prop \Ra \pvs[\mask_1][\mask_2] {\propB})} \\
\prop \vsE[\mask_1][\mask_2] \propB &\eqdef \prop \vs[\mask_1][\mask_2] \propB \land \propB \vs[\mask2][\mask_1] \prop
\end{aligned}
\]
We write just one mask for a view shift when $\mask_1 = \mask_2$.
Clearly, all of these assertions are persistent.
The convention for omitted masks is similar to the base logic:
An omitted $\mask$ is $\top$ for Hoare triples and $\emptyset$ for view shifts.

\paragraph{View shifts.}~
The following rules can be derived for view shifts.

\begin{mathparpagebreakable}
\inferH{vs-update}
  {\melt \mupd \meltsB}
  {\ownGGhost{\melt} \vs \exists \meltB \in \meltsB.\; \ownGGhost{\meltB}}
\and
\inferH{vs-trans}
  {\prop \vs[\mask_1][\mask_2] \propB \and \propB \vs[\mask_2][\mask_3] \propC \and \mask_2 \subseteq \mask_1 \cup \mask_3}
  {\prop \vs[\mask_1][\mask_3] \propC}
\and
\inferH{vs-imp}
  {\always{(\prop \Ra \propB)}}
  {\prop \vs[\emptyset] \propB}
\and
\inferH{vs-mask-frame}
  {\prop \vs[\mask_1][\mask_2] \propB}
  {\prop \vs[\mask_1 \uplus \mask'][\mask_2 \uplus \mask'] \propB}
\and
\inferH{vs-frame}
  {\prop \vs[\mask_1][\mask_2] \propB}
  {\prop * \propC \vs[\mask_1][\mask_2] \propB * \propC}
\and
\inferH{vs-timeless}
  {\timeless{\prop}}
  {\later \prop \vs \prop}
\and
\inferH{vs-allocI}
  {\infinite(\mask)}
  {\later{\prop} \vs[\mask] \exists \iname\in\mask.\; \knowInv{\iname}{\prop}}
\and
\axiomH{vs-openI}
  {\knowInv{\iname}{\prop} \proves \TRUE \vs[\{ \iname \} ][\emptyset] \later \prop}
\and
\axiomH{vs-closeI}
  {\knowInv{\iname}{\prop} \proves \later \prop \vs[\emptyset][\{ \iname \} ] \TRUE }

\inferHB{vs-disj}
  {\prop \vs[\mask_1][\mask_2] \propC \and \propB \vs[\mask_1][\mask_2] \propC}
  {\prop \lor \propB \vs[\mask_1][\mask_2] \propC}
\and
\inferHB{vs-exist}
  {\All \var. (\prop \vs[\mask_1][\mask_2] \propB)}
  {(\Exists \var. \prop) \vs[\mask_1][\mask_2] \propB}
\and
\inferHB{vs-box}
  {\always\propB \proves \prop \vs[\mask_1][\mask_2] \propC}
  {\prop \land \always{\propB} \vs[\mask_1][\mask_2] \propC}
 \and
\inferH{vs-false}
  {}
  {\FALSE \vs[\mask_1][\mask_2] \prop }
\end{mathparpagebreakable}

\paragraph{Hoare triples.}
The following rules can be derived for Hoare triples.

\begin{mathparpagebreakable}
\inferH{Ht-ret}
  {}
  {\hoare{\TRUE}{\valB}{\Ret\val. \val = \valB}[\mask]}
\and
\inferH{Ht-bind}
  {\text{$\lctx$ is a context} \and \hoare{\prop}{\expr}{\Ret\val. \propB}[\mask] \\
   \All \val. \hoare{\propB}{\lctx(\val)}{\Ret\valB.\propC}[\mask]}
  {\hoare{\prop}{\lctx(\expr)}{\Ret\valB.\propC}[\mask]}
\and
\inferH{Ht-csq}
  {\prop \vs \prop' \\
    \hoare{\prop'}{\expr}{\Ret\val.\propB'}[\mask] \\
   \All \val. \propB' \vs \propB}
  {\hoare{\prop}{\expr}{\Ret\val.\propB}[\mask]}
\and
\inferH{Ht-mask-weaken}
  {\hoare{\prop}{\expr}{\Ret\val. \propB}[\mask]}
  {\hoare{\prop}{\expr}{\Ret\val. \propB}[\mask \uplus \mask']}
\\\\
\inferH{Ht-frame}
  {\hoare{\prop}{\expr}{\Ret\val. \propB}[\mask]}
  {\hoare{\prop * \propC}{\expr}{\Ret\val. \propB * \propC}[\mask]}
\and
\inferH{Ht-frame-step}
  {\hoare{\prop}{\expr}{\Ret\val. \propB}[\mask] \and \toval(\expr) = \bot}
  {\hoare{\prop * \later\propC}{\expr}{\Ret\val. \propB * \propC}[\mask]}
\and
\inferH{Ht-atomic}
  {\prop \vs[\mask \uplus \mask'][\mask] \prop' \\
    \hoare{\prop'}{\expr}{\Ret\val.\propB'}[\mask] \\
   \All\val. \propB' \vs[\mask][\mask \uplus \mask'] \propB \\
   \physatomic{\expr}
  }
  {\hoare{\prop}{\expr}{\Ret\val.\propB}[\mask \uplus \mask']}
\and
\inferHB{Ht-disj}
  {\hoare{\prop}{\expr}{\Ret\val.\propC}[\mask] \and \hoare{\propB}{\expr}{\Ret\val.\propC}[\mask]}
  {\hoare{\prop \lor \propB}{\expr}{\Ret\val.\propC}[\mask]}
\and
\inferHB{Ht-exist}
  {\All \var. \hoare{\prop}{\expr}{\Ret\val.\propB}[\mask]}
  {\hoare{\Exists \var. \prop}{\expr}{\Ret\val.\propB}[\mask]}
\and
\inferHB{Ht-box}
  {\always\propB \proves \hoare{\prop}{\expr}{\Ret\val.\propC}[\mask]}
  {\hoare{\prop \land \always{\propB}}{\expr}{\Ret\val.\propC}[\mask]}
\and
\inferH{Ht-false}
  {}
  {\hoare{\FALSE}{\expr}{\Ret \val. \prop}[\mask]}
\end{mathparpagebreakable}

\clearpage
\section{Derived constructions}

In this section we describe some derived constructions that are generally useful and language-independent.

\ralf{Describe at least global monoid and invariant namespaces.}
% \subsection{Global monoid}

% Hereinafter we assume the global monoid (served up as a parameter to Iris) is obtained from a family of monoids $(M_i)_{i \in I}$ by first applying the construction for finite partial functions to each~(\Sref{sec:fpfunm}), and then applying the product construction~(\Sref{sec:prodm}):
% \[ M \eqdef \prod_{i \in I} \textdom{GhName} \fpfn M_i \]
% We don't care so much about what concretely $\textdom{GhName}$ is, as long as it is countable and infinite.
% We write $\ownGhost{\gname}{\melt : M_i}$ (or just $\ownGhost{\gname}{\melt}$ if $M_i$ is clear from the context) for $\ownGGhost{[i \mapsto [\gname \mapsto \melt]]}$ when $\melt \in \mcarp {M_i}$, and for $\FALSE$ when $\melt = \mzero_{M_i}$.
% In other words, $\ownGhost{\gname}{\melt : M_i}$ asserts that in the current state of monoid $M_i$, the name $\gname$ is allocated and has at least value $\melt$.

% From~\ruleref{FpUpd} and the multiplications and frame-preserving updates in~\Sref{sec:prodm} and~\Sref{sec:fpfunm}, we have the following derived rules.
% \begin{mathpar}
% 	\axiomH{NewGhost}{
% 		\TRUE \vs \Exists\gname. \ownGhost\gname{\melt : M_i}
% 	}
% 	\and
% 	\inferH{GhostUpd}
%     {\melt \mupd_{M_i} B}
%     {\ownGhost\gname{\melt : M_i} \vs \Exists \meltB\in B. \ownGhost\gname{\meltB : M_i}}
%   \and
%   \axiomH{GhostEq}
%     {\ownGhost\gname{\melt : M_i} * \ownGhost\gname{\meltB : M_i} \Lra \ownGhost\gname{\melt\mtimes\meltB : M_i}}

%   \axiomH{GhostUnit}
%     {\TRUE \Ra \ownGhost{\gname}{\munit : M_i}}

%   \axiomH{GhostZero}
%     {\ownGhost\gname{\mzero : M_i} \Ra \FALSE}

%   \axiomH{GhostTimeless}
%     {\timeless{\ownGhost\gname{\melt : M_i}}}
% \end{mathpar}

% \subsection{STSs with interpretation}\label{sec:stsinterp}

% Building on \Sref{sec:stsmon}, after constructing the monoid $\STSMon{\STSS}$ for a particular STS, we can use an invariant to tie an interpretation, $\pred : \STSS \to \Prop$, to the STS's current state, recovering CaReSL-style reasoning~\cite{caresl}.

% An STS invariant asserts authoritative ownership of an STS's current state and that state's interpretation:
% \begin{align*}
%   \STSInv(\STSS, \pred, \gname) \eqdef{}& \Exists s \in \STSS. \ownGhost{\gname}{(s, \STSS, \emptyset):\STSMon{\STSS}} * \pred(s) \\
%   \STS(\STSS, \pred, \gname, \iname) \eqdef{}& \knowInv{\iname}{\STSInv(\STSS, \pred, \gname)}
% \end{align*}

% We can specialize \ruleref{NewInv}, \ruleref{InvOpen}, and \ruleref{InvClose} to STS invariants:
% \begin{mathpar}
%  \inferH{NewSts}
%   {\infinite(\mask)}
%   {\later\pred(s) \vs[\mask] \Exists \iname \in \mask, \gname.   \STS(\STSS, \pred, \gname, \iname) * \ownGhost{\gname}{(s, \STST \setminus \STSL(s)) : \STSMon{\STSS}}}
%  \and
%  \axiomH{StsOpen}
%   {  \STS(\STSS, \pred, \gname, \iname) \vdash \ownGhost{\gname}{(s_0, T) : \STSMon{\STSS}} \vsE[\{\iname\}][\emptyset] \Exists s\in \upclose(\{s_0\}, T). \later\pred(s) * \ownGhost{\gname}{(s, \upclose(\{s_0\}, T), T):\STSMon{\STSS}}}
%  \and
%  \axiomH{StsClose}
%   {  \STS(\STSS, \pred, \gname, \iname), (s, T) \ststrans (s', T')  \proves \later\pred(s') * \ownGhost{\gname}{(s, S, T):\STSMon{\STSS}} \vs[\emptyset][\{\iname\}] \ownGhost{\gname}{(s', T') : \STSMon{\STSS}} }
% \end{mathpar}
% \begin{proof}
% \ruleref{NewSts} uses \ruleref{NewGhost} to allocate $\ownGhost{\gname}{(s, \upclose(s, T), T) : \STSMon{\STSS}}$ where $T \eqdef \STST \setminus \STSL(s)$, and \ruleref{NewInv}.

% \ruleref{StsOpen} just uses \ruleref{InvOpen} and \ruleref{InvClose} on $\iname$, and the monoid equality $(s, \upclose(\{s_0\}, T), T) = (s, \STSS, \emptyset) \mtimes (\munit, \upclose(\{s_0\}, T), T)$.

% \ruleref{StsClose} applies \ruleref{StsStep} and \ruleref{InvClose}.
% \end{proof}

% Using these view shifts, we can prove STS variants of the invariant rules \ruleref{Inv} and \ruleref{VSInv}~(compare the former to CaReSL's island update rule~\cite{caresl}):
% \begin{mathpar}
%  \inferH{Sts}
%   {\All s \in \upclose(\{s_0\}, T). \hoare{\later\pred(s) * P}{\expr}{\Ret \val. \Exists s', T'. (s, T) \ststrans (s', T') * \later\pred(s') * Q}[\mask]
%    \and \physatomic{\expr}}
%   {  \STS(\STSS, \pred, \gname, \iname) \vdash \hoare{\ownGhost{\gname}{(s_0, T):\STSMon{\STSS}} * P}{\expr}{\Ret \val. \Exists s', T'. \ownGhost{\gname}{(s', T'):\STSMon{\STSS}} * Q}[\mask \uplus \{\iname\}]}
%  \and
%  \inferH{VSSts}
%   {\forall s \in \upclose(\{s_0\}, T).\; \later\pred(s) * P \vs[\mask_1][\mask_2] \exists s', T'.\; (s, T) \ststrans (s', T') * \later\pred(s') * Q}
%   {  \STS(\STSS, \pred, \gname, \iname) \vdash \ownGhost{\gname}{(s_0, T):\STSMon{\STSS}} * P \vs[\mask_1 \uplus \{\iname\}][\mask_2 \uplus \{\iname\}] \Exists s', T'. \ownGhost{\gname}{(s', T'):\STSMon{\STSS}} * Q}
% \end{mathpar}

% \begin{proof}[Proof of \ruleref{Sts}]\label{pf:sts}
%  We have to show
%  \[\hoare{\ownGhost{\gname}{(s_0, T):\STSMon{\STSS}} * P}{\expr}{\Ret \val. \Exists s', T'. \ownGhost{\gname}{(s', T'):\STSMon{\STSS}} * Q}[\mask \uplus \{\iname\}]\]
%  where $\val$, $s'$, $T'$ are free in $Q$.

%  First, by \ruleref{ACsq} with \ruleref{StsOpen} and \ruleref{StsClose} (after moving $(s, T) \ststrans (s', T')$ into the view shift using \ruleref{VSBoxOut}), it suffices to show
%  \[\hoareV{\Exists s\in \upclose(\{s_0\}, T). \later\pred(s) * \ownGhost{\gname}{(s, \upclose(\{s_0\}, T), T)} * P}{\expr}{\Ret \val. \Exists s, T, S, s', T'. (s, T) \ststrans (s', T') * \later\pred(s') * \ownGhost{\gname}{(s, S, T):\STSMon{\STSS}} * Q(\val, s', T')}[\mask]\]

%  Now, use \ruleref{Exist} to move the $s$ from the precondition into the context and use \ruleref{Csq} to (i)~fix the $s$ and $T$ in the postcondition to be the same as in the precondition, and (ii)~fix $S \eqdef \upclose(\{s_0\}, T)$.
%  It remains to show:
%  \[\hoareV{s\in \upclose(\{s_0\}, T) * \later\pred(s) * \ownGhost{\gname}{(s, \upclose(\{s_0\}, T), T)} * P}{\expr}{\Ret \val. \Exists s', T'. (s, T) \ststrans (s', T') * \later\pred(s') * \ownGhost{\gname}{(s, \upclose(\{s_0\}, T), T)} * Q(\val, s', T')}[\mask]\]

%  Finally, use \ruleref{BoxOut} to move $s\in \upclose(\{s_0\}, T)$ into the context, and \ruleref{Frame} on $\ownGhost{\gname}{(s, \upclose(\{s_0\}, T), T)}$:
%  \[s\in \upclose(\{s_0\}, T) \vdash \hoare{\later\pred(s) * P}{\expr}{\Ret \val. \Exists s', T'. (s, T) \ststrans (s', T') * \later\pred(s') * Q(\val, s', T')}[\mask]\]

%  This holds by our premise.
% \end{proof}

% % \begin{proof}[Proof of \ruleref{VSSts}]
% % This is similar to above, so we only give the proof in short notation:

% % \hproof{%
% % 	Context: $\knowInv\iname{\STSInv(\STSS, \pred, \gname)}$ \\
% % 	\pline[\mask_1 \uplus \{\iname\}]{
% % 		\ownGhost\gname{(s_0, T)} * P
% % 	} \\
% % 	\pline[\mask_1]{%
% % 		\Exists s. \later\pred(s) * \ownGhost\gname{(s, S, T)} * P
% % 	} \qquad by \ruleref{StsOpen} \\
% % 	Context: $s \in S \eqdef \upclose(\{s_0\}, T)$ \\
% % 	\pline[\mask_2]{%
% % 		 \Exists s', T'. \later\pred(s') * Q(s', T') * \ownGhost\gname{(s, S, T)}
% % 	} \qquad by premiss \\
% % 	Context: $(s, T) \ststrans (s', T')$ \\
% % 	\pline[\mask_2 \uplus \{\iname\}]{
% % 		\ownGhost\gname{(s', T')} * Q(s', T')
% % 	} \qquad by \ruleref{StsClose}
% % }
% % \end{proof}

% \subsection{Authoritative monoids with interpretation}\label{sec:authinterp}

% Building on \Sref{sec:auth}, after constructing the monoid $\auth{M}$ for a cancellative monoid $M$, we can tie an interpretation, $\pred : \mcarp{M} \to \Prop$, to the authoritative element of $M$, recovering reasoning that is close to the sharing rule in~\cite{krishnaswami+:icfp12}.

% Let $\pred_\bot$ be the extension of $\pred$ to $\mcar{M}$ with $\pred_\bot(\mzero) = \FALSE$.
% Now define
% \begin{align*}
%   \AuthInv(M, \pred, \gname) \eqdef{}& \exists \melt \in \mcar{M}.\; \ownGhost{\gname}{\authfull \melt:\auth{M}} * \pred_\bot(\melt) \\
%   \Auth(M, \pred, \gname, \iname) \eqdef{}& M~\textlog{cancellative} \land \knowInv{\iname}{\AuthInv(M, \pred, \gname)}
% \end{align*}

% The frame-preserving updates for $\auth{M}$ gives rise to the following view shifts:
% \begin{mathpar}
%  \inferH{NewAuth}
%   {\infinite(\mask) \and M~\textlog{cancellative}}
%   {\later\pred_\bot(a) \vs[\mask] \exists \iname \in \mask, \gname.\; \Auth(M, \pred, \gname, \iname) * \ownGhost{\gname}{\authfrag a : \auth{M}}}
%  \and
%  \axiomH{AuthOpen}
%   {\Auth(M, \pred, \gname, \iname) \vdash \ownGhost{\gname}{\authfrag \melt : \auth{M}} \vsE[\{\iname\}][\emptyset] \exists \melt_f.\; \later\pred_\bot(\melt \mtimes \melt_f) * \ownGhost{\gname}{\authfull \melt \mtimes \melt_f, \authfrag a:\auth{M}}}
%  \and
%  \axiomH{AuthClose}
%   {\Auth(M, \pred, \gname, \iname) \vdash \later\pred_\bot(\meltB \mtimes \melt_f) * \ownGhost{\gname}{\authfull a \mtimes \melt_f, \authfrag a:\auth{M}} \vs[\emptyset][\{\iname\}] \ownGhost{\gname}{\authfrag \meltB : \auth{M}} }
% \end{mathpar}

% These view shifts in turn can be used to prove variants of the invariant rules:
% \begin{mathpar}
%  \inferH{Auth}
%   {\forall \melt_f.\; \hoare{\later\pred_\bot(a \mtimes \melt_f) * P}{\expr}{\Ret\val. \exists \meltB.\; \later\pred_\bot(\meltB\mtimes \melt_f) * Q}[\mask]
%    \and \physatomic{\expr}}
%   {\Auth(M, \pred, \gname, \iname) \vdash \hoare{\ownGhost{\gname}{\authfrag a:\auth{M}} * P}{\expr}{\Ret\val. \exists \meltB.\; \ownGhost{\gname}{\authfrag \meltB:\auth{M}} * Q}[\mask \uplus \{\iname\}]}
%  \and
%  \inferH{VSAuth}
%   {\forall \melt_f.\; \later\pred_\bot(a \mtimes \melt_f) * P \vs[\mask_1][\mask_2] \exists \meltB.\; \later\pred_\bot(\meltB \mtimes \melt_f) * Q(\meltB)}
%   {\Auth(M, \pred, \gname, \iname) \vdash
%    \ownGhost{\gname}{\authfrag a:\auth{M}} * P \vs[\mask_1 \uplus \{\iname\}][\mask_2 \uplus \{\iname\}]
%    \exists \meltB.\; \ownGhost{\gname}{\authfrag \meltB:\auth{M}} * Q(\meltB)}
% \end{mathpar}

% \subsection{Ghost heap}
% \label{sec:ghostheap}%

% We define a simple ghost heap with fractional permissions.
% Some modules require a few ghost names per module instance to properly manage ghost state, but would like to expose to clients a single logical name (avoiding clutter).
% In such cases we use these ghost heaps.

% We seek to implement the following interface:
% \newcommand{\GRefspecmaps}{\textsf{GMapsTo}}%
% \begin{align*}
%  \exists& {\fgmapsto[]} : \textsort{Val} \times \mathbb{Q}_{>} \times \textsort{Val} \ra \textsort{Prop}.\;\\
%   & \All x, q, v. x \fgmapsto[q] v \Ra x \fgmapsto[q] v \land q \in (0, 1] \\
%   &\forall x, q_1, q_2, v, w.\; x \fgmapsto[q_1] v * x \fgmapsto[q_2] w \Leftrightarrow x \fgmapsto[q_1 + q_2] v * v = w\\
%   & \forall v.\; \TRUE \vs[\emptyset] \exists x.\; x \fgmapsto[1] v \\
%   & \forall x, v, w.\; x \fgmapsto[1] v \vs[\emptyset] x \fgmapsto[1] w
% \end{align*}
% We write $x \fgmapsto v$ for $\exists q.\; x \fgmapsto[q] v$ and $x \gmapsto v$ for $x \fgmapsto[1] v$.
% Note that $x \fgmapsto v$ is duplicable but cannot be boxed (as it depends on resources); \ie we have $x \fgmapsto v \Lra x \fgmapsto v * x \fgmapsto v$ but not $x \fgmapsto v \Ra \always x \fgmapsto v$.

% To implement this interface, allocate an instance $\gname_G$ of $\FHeap(\textdom{Val})$ and define
% \[
% 	x \fgmapsto[q] v \eqdef
% 	  \begin{cases}
%     	\ownGhost{\gname_G}{x \mapsto (q, v)} & \text{if $q \in (0, 1]$} \\
%     	\FALSE & \text{otherwise}
%     \end{cases}
% \]
% The view shifts in the specification follow immediately from \ruleref{GhostUpd} and the frame-preserving updates in~\Sref{sec:fheapm}.
% The first implication is immediate from the definition.
% The second implication follows by case distinction on $q_1 + q_2 \in (0, 1]$.

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


% -*-latex-*-

\title{Orbiter Technical Notes: Earth Atmosphere Model}
\author{Martin Schweiger}
\date{March 5, 2009}

\documentclass[a4paper]{article}
\usepackage[dvips]{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{times}
\usepackage{cite}

\begin{document}
\bibliographystyle{unsrt}

%\renewcommand{\vec}[1]{\ensuremath{\mathbf{#1}}}

\newcommand{\vR}[1]{\ensuremath{\vec{R}_{#1}}}
\newcommand{\nR}[1]{\ensuremath{|\vR{#1}|}}
\newcommand{\mat}[1]{\ensuremath{\mathsf{#1}}}
\newcommand{\Kelvin}{\ensuremath{\mathrm{K}}}

\maketitle

\section{Introduction}
From Edition 2009, Orbiter supports a choice of different atmosphere models for Earth. In addition to the Edition 2006 legacy model, the default distribution also contains implementations of the Jacchia model \cite{jacchia65, jacchia71, jacchia77} and the NRLMSISE-00 model which is based on the MSISE90 model.

These models address the shortcomings of the 2006 legacy model, in particular the underestimation of density and pressure above 120\,km. Both new models are valid to significantly higher altitudes (2500\,km, compared to 200\,km for the legacy model).

They provide the temperature, particle density for different molecular constituents, total mass density and molecular weight as a function of altitude, in the range from 90 to 2500\,km. For the Jacchia model, the only model parameter is the exospheric temperature, $T_\infty$, which in turn depends on various parameters, such as the relative position of the sun, geomagnetic activity, and solar flux. The NRLMSISE00 model also uses date information to compute variations on different time scales.

\section{Exospheric temperature}
Calculation of $T_\infty$ is required for applying the J77 model. The exospheric temperature is varying with time and position, and must therefore be recalculated for each new density evaluation. The model takes into account solar activity, geomagnetic activity, and a model for the diurnal variations in $T_\infty$.

The J71 model gives specifies the nighttime minimum global exosphere temperature, excluding geomagnetic activity, as
\begin{equation}
T_C = 379.0K + 3.24K \bar{F}_{10.7} + 1.3K(F_{10.7}-\bar{F}_{10.7})
\end{equation}
where $F_{10.7}$ is the daily average solar flux value one day prior, measured at wavelength 10.7\,cm, and $\bar{F}_{10.7}$ is the average value over three solar rotations of 27 days. Units for solar flux values are given in Solar Flux Units of $10^{-22}\,W/(m^2 Hz)$.

In Orbiter, solar flux values based on observations are not taken into account. Instead, a constant flux of
\begin{equation}
F_{10.7} = \bar{F}_{10.7} = 140 \cdot 10^{-22} W/(m^2 Hz)
\end{equation}
is assumed, which reduces the expression for $T_C$ to
\begin{equation}
T_C = 832.6K
\end{equation}
The diurnal model for $T_\infty$ takes into account the local hour angle of the sun with respect to the measurement point, as well as the declination of the sun and the geographic latitude of the measurement point. This model is given by
\begin{equation}
T_1 = T_C \left[ 1 + 0.3 \left( \sin^{2.2}|\theta| + (\cos^{2.2}|\eta| - \sin^{2.2}|\theta|) \cos^{3.0}(\tau/2) \right) \right]
\end{equation}
with
\begin{eqnarray}
\tau &=& H - 37.0^\circ + 6.0^\circ \sin(H+43.0^\circ) \\
\theta &=& \frac{1}{2} (\varphi + \delta_\odot ) \\
\eta &=& \frac{1}{2} (\varphi - \delta_\odot)
\end{eqnarray}
where $\delta_\odot$ denotes the sun's declination, $\varphi$ is the geographic latitude and $H$ the hour angle of the sun with respect to the measurement point, given by
\begin{equation}
H = \alpha - \alpha_\odot
\end{equation}
where $\alpha$ and $\alpha_\odot$ are the right ascension of the measurement point and the sun, respectively.

Finally, geomagnetic activity is taken into account by the Jacchia model by specifying a modification term $\Delta T_\infty$ for $T_\infty$ in the form
\begin{eqnarray}
\Delta T^H_\infty &=& 28.0\Kelvin \cdot K_p + 0.03\Kelvin e^{K_p}\qquad (z > 350\,km) \\
\Delta T^L_\infty &=& 14.0\Kelvin \cdot K_p + 0.02\Kelvin e^{K_p}\qquad (z < 350\,km)
\end{eqnarray}
for two separate altitude regimes, respectively. $K_p$ is the three-hourly planetary geomagnetic index for a time 6.7 hours previous. To provide continuity at z=350\,km, a transition function $f$ is introduced:
\begin{equation}
f = \frac{1}{2} (\tanh(0.04 (z - 350\,km)) + 1)
\end{equation}
The geomagnetic activity correction $\Delta T_\infty$ can then be written as
\begin{equation}
\Delta T_\infty = f \Delta T^H_\infty + (1-f) \Delta T^L_\infty
\end{equation}
In Orbiter, variations in geomagnetic activity are ignored. Instead, a constant geomagnetic index of $K_p = 3.0$ is assumed. This simplifies the correction terms to
\begin{eqnarray}
\Delta T^H_\infty &=& 84.6026\Kelvin \\
\Delta T^L_\infty &=& 42.4017\Kelvin \\
\Delta T_\infty &=& (42.2009 f + 42.4017)\Kelvin
\end{eqnarray}
The final value for the exospheric temperature is then given by
\begin{equation}
T_\infty = T_1 + \Delta T_\infty
\end{equation}
Examples for global distributions of $T_\infty$ are shown in Fig.~\ref{fig:t_infty}, for two different solar declination values ($0^\circ$ and $20^\circ$). Note that the maximum of $T_\infty$ is trailing the Sun's location (indicated by a circle).

\begin{figure}
\includegraphics[width=0.8\textwidth]{exotemp1.eps}
\includegraphics[width=0.8\textwidth]{exotemp2.eps}
\caption{Exospheric temperature distributions as a function of geographic longitude and latitude, for two different declination values of the Sun: $0^\circ$ (top) and $20^\circ$ (bottom). The position of the sun is indicated by a circle.}
\label{fig:t_infty}
\end{figure}

\section{The Jacchia temperature and density model}
The Jacchia model is static and assumes two distinct altitude regimes, where in the lower regime (from 90 to 100\,km) the atmospheric constituents are mixed, and the density is computed by integrating the barometric equation. At altitudes $> 100$\,km, the atmosphere is assumed to be in diffusion equilibrium for each of the individual constituents.

\subsection{Temperature}
The temperature profile obtained from the Jacchia code as a function of altitude for three different values of $T_\infty$ is shown in Fig.~\ref{fig:jacchia_temp}. As can be seen, the temperature profiles are identical up to an altitude of about 100\,km, where the standard US atmospheric model is used. At higher altitudes, the temperatures asymdotically approach the prescribed exospheric temperature.

\begin{figure}
\includegraphics[width=0.8\textwidth]{jacchia_temp.eps}
\caption{J77 temperature profiles as a function of altitude for different values of exospheric temperature $T_\infty$.}
\label{fig:jacchia_temp}
\end{figure}

\subsection{Density}

The Jacchia model requires the integration of a barometric or diffusion equation up to the desired altitude. This method is not computationally efficient if density values at arbitrary altitudes are required. In this case, a reasonable compromise between computational speed and accuracy can be achieved by precomputing lookup tables over the required ranges of altitude $z$ and exospheric temperature $T_\infty$, and interpolating to the actual parameters. Alternatively, a basis expansion in the two parameters can be used. Gill~\cite{gill96} has approximated the J71 density model (denoted here by J71G) by a bi-polynomial expansion of the form
\begin{equation}\label{eq:interpol}
\log \rho(z,T_\infty) = \sum_{i=0}^m \sum_{j=0}^n c_{ij} z^i T_\infty^j
\end{equation}
where $c_{ij}$ are the basis coefficients of the expansion obtained by a least-squares optimisation.

To provide sufficient accuracy while keeping the expansion to a reasonably low order, the temperature and altitude range was divided into sub-regions, and separate basis expansions calculated for each of them. Continuity of the density values and derivatives across region boundaries was ensured by applying appropriate constraints to the least squares fits. The authors present the coefficients for a basis expansion using a 5th degree polynomial in temperature and 6th degree polynomial in altitude for each region.

The density profiles as a function of altitude for three values of $T_\infty$ are shown in Fig.~\ref{fig:dens} for both the J77 and the J71G models.
\begin{figure}
\includegraphics[width=0.5\textwidth]{dens_j77.eps}
\includegraphics[width=0.5\textwidth]{dens_j71g.eps}
\caption{Density profiles for the J77 (left) and J71G model (right) as a function of altitude, for three different values of the exospheric temperature.}
\label{fig:dens}
\end{figure}
The relative difference between the two models is shown in Fig.~\ref{fig:denserr}. It can be seen that the models agree well for medium to high values of $T_\infty$, but diverge significantly for low values. This may be caused by the fact that the interpolated Gill solution is modelling the earlier J71 model rather than J77, so may reflect the difference between the underlying models, rather than an effect of the interpolation approach. As can be seen in the right image, the models only diverge below temperatures of 600\,K, which are not encountered in Orbiter's model for $T_\infty$.
\begin{figure}
\includegraphics[width=0.5\textwidth]{dens_relerr.eps}
\includegraphics[width=0.5\textwidth]{dens_relerr2.eps}
\caption{Relative difference between the J77 and J71G models as a function of altitude, for three different values of the exospheric temperature (left), and for the full temperature range (right).}
\label{fig:denserr}
\end{figure}

\subsection{Pressure}

We obtain atmospheric pressure from density by applying the ideal gas law
\begin{equation}
p = \rho_N k T
\end{equation}
where $\rho_N$ [m$^{-3}$] is the particle density, and $k$ [J/K] is the Boltzmann constant. However, while the original Jacchia model returns $\rho_N$, the interpolated Jacchia-Gill model instead provides the mass density $\rho$. The relationship between $\rho$ and $\rho_N$ is given by
\begin{equation}
\rho_N = \rho \frac{N_A}{M}
\end{equation}
where $N_A$ is Avogadro's constant and $M$ is the molar mass of the gas mixture. The Jacchia model does provide $M$, but as with the density, this requires an expensive numerical integration over altitude. Therefore I present here a polynomial series approximation of $M$ in the parameters $z$ and $T_\infty$ similar to the density expansion of the Jacchia-Gill model (Eq.~\ref{eq:interpol}). Instead of a piecewise patched solution, the parameter range of $90\,km \leq z \leq 2500\,km$ and $500\,K \leq T_\infty \leq 1900\,K$ is mapped with a single series of order 8 in $z$ and order 4 in $T_\infty$. The basis coefficients $c^{(M)}$ were obtained by a least-squares fit and $c$ are listed in Appendix A. The distribution of the interpolation solution of $M$ is shown in Fig.~\ref{fig:molmass}. Below $z=90$\,km the value of $M$ is derived from the US standard atmosphere model.

\begin{figure}
\includegraphics[width=0.5\textwidth]{molmass.eps}
\includegraphics[width=0.5\textwidth]{molmass_err.eps}
\caption{Left: Distribution of molar mass as a function of altitude and exospheric temperature, obtained from a polynomial series expansion. Right: relative error of the series solution compared to the original Jacchia model data.}
\label{fig:molmass}
\end{figure}
The atmospheric pressure values calculated with the J77 model and with the J71G model augmented with the molecular weight interpolation as outlined above are shown in Fig.~\ref{fig:pressure}. The differences between the two models at low values of $T_\infty$ observed for density naturally also appear for the pressure values. Above 600\,K the agreement is very good.

\begin{figure}
\includegraphics[width=0.5\textwidth]{prs_j77.eps}
\includegraphics[width=0.5\textwidth]{prs_j71g.eps}
\caption{Pressure profiles for the J77 (left) and the augmented J71G model (right) as a function of altitude, for three different values of the exospheric temperature.}
\label{fig:pressure}
\end{figure}

\section{The NRLMSISE-00 atmosphere model}
A further atmospheric model supported by Orbiter is the NRLMSISE-00 model, developed by Picone, Hedin and Drob, with a C version by D. Brodowski. It is based on the MSISE90 model, adding some further observation data. MSISE90 provides the neutral temperature and density from ground level to thermospheric altitudes. Unlike the Jacchia models, the low-altitude data are not static, but vary with location. They are based on the MAP Handbook (Labitzke et al. 1985) tabulation of zonal average temperature and pressure by Barnett and Corney. Below 20 km these data were supplemented with averages from the National Meteorological Center (NMC). In addition, pitot tube, falling sphere, and grenade sounder rocket measurements from 1947 to 1972 were taken into consideration. Above 72.5 km MSISE-90 is essentially a revised MSIS-86 model taking into account data derived from space shuttle flights and newer incoherent scatter results.

The input parameters for the NRLMSISE-00 model are altitude, geodetic longitude and latitude, day of year, seconds in day, average and current F10.7 flux, and magnetic index. On output, the model provides temperature at altitude, exospheric temperature, total mass density, and number densities for He, O, N$_2$, O$_2$, Ar, H, N and anomalous oxygen.

The algorithm for calculating $T_\infty$ differs between the J71G and the NRLMSISE-00 model. Figure~\ref{fig:comp_tinfty} compares the $T_\infty$ profiles over a single day (left) and over a year, at UT=0 and UT=12 hours (right). It can be seen that the daily profile of the NRLMSISE-00 model appears more complex, showing less symmetry and a pronounced minimum. The annual NRLMSISE-00 profile displays a higher amplitude and lower average than the J71G model.

\begin{figure}
\includegraphics[width=0.5\textwidth]{tinf_daily.eps}
\includegraphics[width=0.5\textwidth]{tinf_annual.eps}
\caption{Comparison of $T_\infty$ values for the J71G and NRLMSISE-00 models. Left: daily profile on 10 March. Right: annual profile, measured daily at UT=0 and UT=12 hours. For all data, a location of longitude=0 and latitude=0 was used.}
\label{fig:comp_tinfty}
\end{figure}

The temperature profile as a function of altitude for a given data (MJD 54900.5) at latitude=0, longitude=0) for both models is shown in Fig.~\ref{fig:comp_t}.
\begin{figure}
\includegraphics[width=0.5\textwidth]{j71g_nrlmsise00_cmp1.eps}
\caption{Comparison of temperature altitude profiles of J71G and NRLMSISE-00 at MJD=54900.5, longitude=0, latitude=0.}
\label{fig:comp_t}
\end{figure}
The density and pressure altitude profiles for both models at the same time and location are shown in Fig.~\ref{fig:comp_dns_p}. It can be seen that the models generally agree well.
\begin{figure}
\includegraphics[width=0.5\textwidth]{j71g_nrlmsise00_cmp2.eps}
\includegraphics[width=0.5\textwidth]{j71g_nrlmsise00_cmp3.eps}
\caption{Comparison of density and pressure altitude profiles of J71G and NRLMSISE-00 at MJD=54900.5, longitude=0, latitude=0.}
\label{fig:comp_dns_p}
\end{figure}

\section{Comparison with Orbiter 2006 legacy model}
The atmosphere model in Orbiter Edition 2006 (denoted as OB06) uses a simple static, piecewise linear temperature profile. For segments of constant temperature, pressure and density are calculated as
\begin{equation}
p(z)=p_1 e^{-[g_0/(RT)](z-z_1)}, \qquad \rho(z)=\rho_1 e^{-[g_0/(RT)](z-z_1)},
\end{equation}
where $z_1$ is the base altitude of the segment, $p_1$ and $\rho_1$ are the corresponding pressure and density, $R$ is the specific gas constant, set to $R=286.91$\,JK$^{-1}$kg$^{-1}$ for air, and $g_0$ is the gravitational acceleration.
The pressure and density in sections of linearly varying temperature are calculated as
\begin{equation}
p(z)=p_1\left[\frac{T(z)}{T_1}\right]^{-g_0/(aR)},\qquad
\rho(z)=\rho_1\left[\frac{T(z)}{T_1}\right]^{-[(g_0/(aR))+1]}
\end{equation}
where $a$ is the temperature gradient [K/m].

Because the gravitational acceleration $g$ cannot be assumed constant over the altitude range, altitude $z$ must be interpreted as a \emph{geopotential} altitude. Conversion between geometric altiude $z_G$ and geopotential altitude $z$ is given by
\begin{equation}
h = \frac{R}{R+z_g}z_g
\end{equation}
where $R$ is the planet radius.

Similar to the J71G model, OB06 is based on a static standard atmosphere model at low altitudes (below 105\,km). Above this altitude, up to 200\,km, the temperature is assumed to be constant at 225.66\,K. This is equivalent to a very low value of $T_\infty$, and consequently the temperature profiles of the two models diverge rapidly between the two models above 120\,km for more realistic values of $T_\infty$, as shown in Fig.~\ref{fig:ob_j71g_temp}, where a value of $T_\infty=1000$\,K was chosen for the J71G model.

\begin{figure}
\includegraphics[width=0.5\textwidth]{ob_j71g_temp.eps}
\caption{Comparison of temperature distributions between the Orbiter legacy model and the J71G model for $T_\infty=1000$\,K.}
\label{fig:ob_j71g_temp}
\end{figure}
Likewise, the pressure and density profiles of the legacy Orbiter model agree well with the J71G model below 120\,km, while at higher altitudes the Orbiter model continues to follow an exponential decay, while the J71G model maintains significantly higher density and pressure values (Fig.~\ref{fig:ob_j71g_dens_prs}).
As a result, the OB06 model values drop to essentially insignificant values at $z=200$\,km, the default cutoff altitude of the legacy model, while density and pressure remain significant to much higher altitudes for the J71G model.

The transition from the OB06 to the J71G model in Orbiter will therefore lead to significantly higher drag effects from altitudes above 120\,km which will continue substantially above the previous cutoff altitude of 200\,km.

\begin{figure}
\includegraphics[width=0.5\textwidth]{ob_j71g_dens.eps}
\includegraphics[width=0.5\textwidth]{ob_j71g_prs.eps}
\caption{Comparison of density (left) and pressure distributions (right) between the Orbiter legacy model and the J71G model for $T_\infty=1000$\,K.}
\label{fig:ob_j71g_dens_prs}
\end{figure}

\section {Computational complexity}
For a real-time application like Orbiter, the computational efficiency of the atmosphere model is important. Atmosphere data are queried at each time frame by each vessel within the atmosphere range limit of a given celestial body. For densely populated simulation scenarios, a complex atmosphere model may adversely affect performance.

Timing results for the three atmosphere models are shown in Table~\ref{tab:timing}. They show the times for 1000 evaluations of model evaluation at different altitudes. It can be seen that the NRLMSISE-00 model is significantly more expensive than the J71G model by approximately an order of magnitude, and both models are substantially more expensive than the trivial Orbiter legacy model.

It should however be noted that for moderately loaded simulation scenarios, even the more expensive models may not significantly degrade performance. For a test scenario with 50 vessels in the atmosphere, the application of the NRLMSISE-00 model resulted in a drop in frame rate from 130 to 114 frames per second.
\begin{table}
\begin{tabular}{l|lll}
Altitude [km] & 50 & 150 & 1000 \\ \hline
2006 Legacy model & 0.000055 & 0.000056 & - \\
J71G model & 0.000289 & 0.0015 & 0.0020 \\
NRLMSISE-00 model & 0.00384 & 0.0266 & 0.0146
\end{tabular}
\caption{Timing comparison between atmosphere models: Times for 1000 model evaluations at different altitudes.}
\label{tab:timing}
\end{table}

\bibliography{../ref}

\section*{Appendix A}
Basis coefficients $c^{(M)}_{ij}$ for obtaining the logarithmic molar mass $M$ of the atmospheric gas mixture as a function of altitude $z$ (in units of km/1000) and exospheric temperature $T_\infty$ (in units of K/1000).
\begin{equation}
\log_{10}(M(z,T_\infty)) \approx \sum_{i=0}^8 \sum_{j=0}^4 c^{(M)}_{ij} z^i T_\infty^j
\end{equation}
\footnotesize
\begin{tabular}{r|rrrrr}
i/j & 0 & 1 & 2 & 3 & 4 \\ \hline
0 &  3.60906627e+00 & -1.35761290e+01 &  2.55465982e+01 & -1.77204699e+01 &  4.07696683e+00 \\
1 & -1.35606636e+01 &  1.29084956e+02 & -2.84612534e+02 &  2.12822504e+02 & -5.11308350e+01 \\
2 & -1.25207810e+01 & -3.19579690e+02 &  9.77718751e+02 & -8.21851276e+02 &  2.09837747e+02 \\
3 &  6.98268484e+01 &  4.02801988e+02 & -1.69988881e+03 &  1.57164796e+03 & -4.21561534e+02 \\
4 & -8.44186988e+01 & -2.88755547e+02 &  1.67090876e+03 & -1.67274401e+03 &  4.67667119e+02 \\
5 &  4.42735679e+01 &  1.24592950e+02 & -9.68963604e+02 &  1.03850337e+03 & -3.01006087e+02 \\
6 & -7.92712088e+00 & -3.81200493e+01 &  3.34875778e+02 & -3.77385160e+02 &  1.12634338e+02 \\
7 & -1.14988223e+00 &  9.20028301e+00 & -6.52157331e+01 &  7.51024325e+01 & -2.28683127e+01 \\
8 &  4.13670214e-01 & -1.18725773e+00 &  5.60433585e+00 & -6.36983671e+00 &  1.95706136e+00
\end{tabular}

\end{document}


\section{String}

\subsection{Hash}
\lstinputlisting{"./string/hash.cc"}

\subsection{KMP}
\lstinputlisting{"./string/kmp.c"}

\subsection{Suffix Array}
\lstinputlisting{"./string/sa.cc"}


\section{Subroutines for quantum-circuit simulation}
\label{sec:update-algorithms}

We describe algorithms for the four subroutines used in \autoref{sec:simulation}.
Each algorithm takes a LIM-QMDD as input.

            \textbf{\textsf{PartialExpand}: convert an isomorphism node $\phi$ to a Shannon node with isomorphism nodes as children (isomorphism group $G \subseteq \textsf{DT}$).}
        Write $\ket{\phi} = \pi_1 \otimes \pi_{\rm rest} \ket{\psi}$, where $\pi_1 \in G$, $\pi_{\rm rest} \in G^{\otimes m}$ with $m=\index(\phi)$, and where $\psi$ is a Shannon node $\ket{\psi} = \alpha_0\ket{0}\ket{\psi_0} + \alpha_1\ket{1}\ket{\psi_1}$.
       Replace $\phi$ by a Shannon node with as children isomorphism nodes $\pi_{\rm rest}\ket{\psi_j}$ and edge labels $\beta_j = \bra{j} \pi_1 (\alpha_0\ket{0} + \alpha_1\ket{1})$ with subscript $j=0$ (1) indicating the low (high) edge.
%        The correctness of this algorithm follows directly from Lemma \todo[inline]{add}, which states that if $G \subseteq \textsf{DT}$, the children nodes of $\phi$ are isomorphic to the children nodes of $\psi$.
        The LIM-QMDD grows by two nodes every time \textsf{PartialExpand} is applied.

               \textbf{\textsf{Swap}: move qubit $k$ to the most significant position.}
               We describe an algorithm \textsf{SwapAdjacent}$(j, j+1)$ which swaps qubits $j$ and $j+1$.
               By applying this algorithm to the qubit pairs $(k-1, k), (k-2, k-1), \dots, (1, 2)$, the qubit with index $k$ will have moved to the most significant position.
               The algorithm \textsf{SwapAdjacent}$(j, j+1)$ is applied to all nodes $\phi$ with $\index(\phi)=j$ individually.
In case $\phi$ is a Shannon node and so are its children, then we can write
        \[
\ket{\phi} =
\alpha_0\alpha_{00}\ket{00}\ket{\phi_{00}}
+
\alpha_0\alpha_{01}\ket{01}\ket{\phi_{01}}
+
\alpha_1\alpha_{10}\ket{10}\ket{\phi_{10}}
+
\alpha_1\alpha_{11}\ket{11}\ket{\phi_{11}}
\]
so for permuting $\phi$ and its children we only need to reroute edges corresponding to
        \[
\ket{\phi} \mapsto
\alpha_0\alpha_{00}\ket{00}\ket{\phi_{00}}
+
\alpha_0\alpha_{10}\ket{01}\ket{\phi_{10}}
+
\alpha_1\alpha_{01}\ket{10}\ket{\phi_{01}}
+
\alpha_1\alpha_{11}\ket{11}\ket{\phi_{11}}
.
\]
        In case either $\phi$ or one of its children is an isomorphism node, then apply \textsf{PartialExpand} to those nodes to make them Shannon nodes.
        \textsf{SwapAdjacent} adds at most 6 nodes since it calls \textsf{PartialExpand} at most 3 times, so \textsf{Swap} increases the size of the LIM-QMDD by at most a factor of 3.

               \textbf{\textsf{AddLIMQMDD}: given LIM-QMDDs for two $n$-qubit states $\ket{\phi}$ and $\ket{\psi}$, construct a LIM-QMDD for $\ket{\phi} + \ket{\psi}$.}
               If $\phi$ and $\psi$ are both Shannon nodes, write
               $\ket{\phi} = \alpha_0 \ket{0}\otimes\ket{\phi_0} + \alpha_1 \ket{1}\otimes\ket{\phi_1}$
               and
               $\ket{\psi} = \beta_0 \ket{0}\otimes\ket{\psi_0} + \beta_1\ket{1}\otimes\ket{\psi_1}$ and observe that
               \[
               \ket{\phi} + \ket{\psi}=
               \ket{0}\otimes\ket{\eta_0} + \ket{1}\otimes\ket{\eta_1}
               \qquad\textnormal{ where }
               \ket{\eta_j} = \alpha_j\ket{\phi_j} + \beta_j\ket{\psi_j}
               \textnormal{ for $j\in \{0, 1\}$}
               .
           \]
           Now construct LIM-QMDDs for $\ket{\eta_j}$ by calling \textsf{AddLIMQMDD} on $\alpha_j\ket{\phi_j}$ and $\beta_j\ket{\psi_j}$ for both $j=0$ and $j=1$.
A LIM-QMDD for $\ket{\phi} + \ket{\psi}$ is constructed by taking a fresh Shannon node with $\eta_0$ and $\eta_1$ as children on the 0-edge and 1-edge, respectively, and setting the weight of both edges to 1.
        In case at least one of $\phi$ or $\psi$ is not an isomorphism node, apply the \textsf{PartialExpand} procedure to make them into a Shannon node.
        The \textsf{AddLIMQMDD} subroutine has exponential runtime in $n$.

\todo[inline]{Come up with a notation to shorten these algorithms considerably! See my attempt in the parameters of MakeNode. Consider the use of cases in a separate definition or inside the algorithm.}

\textbf{\textsf{SquaredNorm: }return the squared norm $|\langle \psi |\psi \rangle|^2$ of a LIM-QMDD node $\psi$ (unitary isomorphism set $G$).} If $\psi$ is a Shannon node with $\ket{\psi} = \alpha_0 \ket{0}\otimes \ket{\psi_0} + \alpha_1 \ket{1}\otimes\ket{\psi_1}$, then return $|\alpha_0|^2\cdot \textnormal{\textsf{SquaredNorm}}(\psi_0) + |\alpha_1|^2 \textnormal{\textsf{SquaredNorm}}(\psi_1)$, while if it is an isomorphism node with $\ket{\psi} = \pi\ket{\phi}$, with $\pi$ the isomorphism, then return $|\langle \psi|\psi\rangle |^2 = |\langle \phi|\pi^{\dagger} \pi |\phi\rangle|^2 = |\langle \phi | \phi\rangle|^2$. The algorithm is made efficient by dynamic programming, where the norm of a node is computed once and then stored for potential later re-use.