\documentclass[12pt]{article}
\usepackage{authblk}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{gensymb}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{hyperref}
\usepackage{float}
\usepackage{braket}
\usepackage[margin=1.0in]{geometry}
\usepackage[style=chem-acs,backend=bibtex,articletitle=false]{biblatex}
\graphicspath{ {../../Si_stuff/} }
\bibliography{mybib}

\begin{document}

\newcommand{\ind}{lm\epsilon}

\title{PAWpySeed: A parallelized Python/C package for analyzing
DFT wavefunctions in the PAW formalism}
\author[1]{Kyle Bystrom (kylebystrom@berkeley.edu)}
\affil[1]{UC Berkeley Department of Materials Science and Engineering}
\date{\today}
\maketitle
\abstract{This document serves as a technical reference for PAWpySeed.
The main novel development of PAWpySeed, covered in Section 1,
is the ability to evaluate the overlap operators of Kohn-Sham states
in the PAW formulism which belong to different structures. For examples,
one might want to project a defect level in a point defect structure
onto the bands of the bulk structure. Additional sections will
cover other developments as they are made.}

\section{Overlap Operators in PAW for Different Structures}

The equation of a PAW wavefunction is\cite{blochl}
\begin{equation}
\ket{\psi_{n\mathbf{k}}}=\ket{\widetilde{\psi}_{n\mathbf{k}}}+
\sum_{a,l,m,\epsilon}(\ket{\phi_{a\ind}}-\ket{\widetilde{\phi}_{a\ind}})
\braket{\widetilde{p}_{a\ind}|\widetilde{\psi}_{n\mathbf{k}}}
\label{eq:1}
\end{equation}
where the sum is over the sites $a$ in the structure and a set of
angular and radial quantum numbers $l$, $m$, and $\epsilon$ at each site.
Local and semilocal operators in PAW can be expressed as
\begin{equation}
\widetilde{A}=A+\sum_i\sum_j\ket{\widetilde{p}_i}(\bra{\phi_i}A\ket{\phi_j}
-\bra{\widetilde{\phi_i}}A\ket{\widetilde{\phi_j}})\bra{\widetilde{p}_j}
\label{eq:loc}
\end{equation}
where $i$ and $j$ are abbreviations for a particular index set
$a,l,m,\epsilon$. This overlap operator requires that the augmentation
regions of the two wavefunctions are same. Since these augmentation regions
are defined by the sites in the structure, the structures must be the same,
so a new formalism is necessary to calculate overlap operators for wavefunctions
in different structures.

This section procedes first by deriving the main formula for calculating
the overlap operator for KS states in different structures, and then
presents a runtime scaling table for each operation involved in evaluating
the formula. The algorithm for each operation is then discussed.

\subsection{Derivation of Formula}

The following section derives an equation for the overlap operator between one
Kohn-Sham single particle state of one structure R and one Kohn-Sham single
particle state of another structure S, where R and S share a common lattice
and the DFT wavefunctions are constructed with the same plane-wave PAW basis set.
It should be noted this derivation might better be described as a manipulation
of terms of the PAW pseudo-operator, because its main purpose is to present
the overlap operator in a method convenient for computation rather than to derive
an entirely new expression. The derivation also makes particular note of how
the expression of the overlap operator relates to interfacing with the VASP code,
though the expressions are applicable to any PAW code.

The starting point for this derivation is the transformation operator that
is performed on the pseudowavefunction to obtain the all electron wavefunction
\begin{equation}
T=1+\sum_a\sum_l\sum_m\sum_{\epsilon}(\ket{\phi_{a\ind}}-\ket{\widetilde{\phi}_{a\ind}})
\bra{\widetilde{p}_{a\ind}}=1+\sum_i(\ket{\phi_i}-\ket{\widetilde{\phi}_i})
\bra{\widetilde{p}_i}
\label{eq:T}
\end{equation}
where $\phi_{a\ind}$ are all electron (AE) partial waves, $\widetilde{\phi}_{a\ind}$
are pseudo (PS) partial waves, $\widetilde{p}_{a\ind}$ are projector functions,
$a$ are the site indices of each atom in the structure, and $l$, $m$, and $\epsilon$
specify a spherical harmonic and index which uniquely specify partial wave at a given
index. A summation over $i$ (or $j$, as below) represents a summation over $a$, $l$, $m$,
and $\epsilon$. For further details on the PAW method, including the physical significance
and construction of the partial waves and projector functions, see Blochl's original paper
and Kresse and Joubert's paper relating ultrasoft pseudopotentials and PAW.\cite{blochl,vasp4}
The next step is to define a pseudo operator $\widetilde{A}$ for each operator $A$
such that $\bra{\psi}A\ket{\psi}=\bra{\widetilde{\psi}}\widetilde{A}\ket{\widetilde{\psi}}$.
Because $\ket{\psi}=T\ket{\widetilde{\psi}}$, one can write
\begin{equation}
\widetilde{A}=T^{\dagger}AT
\label{eq:op}
\end{equation}
One can then plug Equation \ref{eq:T} into Equation \ref{eq:op} to find
\begin{equation}
\begin{split}
\widetilde{A} = & [1+\sum_i\ket{\widetilde{p}_i}(\bra{\phi_i}-\bra{\widetilde{\phi}_i})]
A[1+\sum_j(\ket{\phi_j}-\ket{\widetilde{\phi}_j})
\bra{\widetilde{p}_j}]\\
\widetilde{A} = & A+\sum_i\ket{\widetilde{p}_i}(\bra{\phi_i}-\bra{\widetilde{\phi}_i})A
+\sum_j A(\ket{\phi_j}-\ket{\widetilde{\phi}_j})\bra{\widetilde{p}_j}\\
& +\sum_i\sum_j\ket{\widetilde{p}_i}(\bra{\phi_i}-\bra{\widetilde{\phi}_i})A
(\ket{\phi_j}-\ket{\widetilde{\phi}_j})\bra{\widetilde{p}_j}
\end{split}
\label{eq:res}
\end{equation}

Using the following relation,
\begin{equation}
\begin{split}
(\bra{\phi_i}-\bra{\widetilde{\phi}_i})A(\ket{\phi_j}-\ket{\widetilde{\phi}_j})
& =\bra{\phi_i}A\ket{\phi_j}-\bra{\widetilde{\phi}_i}A\ket{\phi_j}
-(\bra{\phi_i}-\bra{\widetilde{\phi}_i})A\ket{\widetilde{\phi}_j}\\
& =\bra{\phi_i}A\ket{\phi_j}-\bra{\widetilde{\phi}_i}A(\ket{\phi_j}-\ket{\widetilde{\phi_j}})
-(\bra{\phi_i}-\bra{\widetilde{\phi}_i})A\ket{\widetilde{\phi}_j}
-\bra{\widetilde{\phi_i}}A\ket{\widetilde{\phi_j}}
\end{split}
\end{equation}

one can rearrange Equation \ref{eq:res} in the manner of Blochl\cite{blochl}:
\begin{equation}
\begin{split}
\widetilde{A}= & A+\sum_i\sum_j[\ket{\widetilde{p}_i}(\bra{\phi_i}A\ket{\phi_j}
-\bra{\widetilde{\phi_i}}A\ket{\widetilde{\phi_j}})\bra{\widetilde{p}_j}] \\
& +\sum_i[(1-\sum_j\ket{\widetilde{p}_j}\bra{\widetilde{\phi}_j})A(\ket{\phi_i}-\ket{\widetilde{\phi_i}})
\bra{\widetilde{p}_i}+\ket{\widetilde{p}_i}
(\bra{\phi_i}-\bra{\widetilde{\phi}_i})A(1-\sum_j\ket{\widetilde{\phi}_j}\bra{\widetilde{p}_j})]
\end{split}
\label{eq:nonloc}
\end{equation}
When the operator $A$ is local, then $\sum_j\ket{\widetilde{\phi}_j}\bra{\widetilde{p}_j}=1$,
so the entire second line of Equation \ref{eq:nonloc} vanishes, giving Blochl's formulation:\cite{blochl}
\begin{equation}
\widetilde{A}=A+\sum_i\sum_j\ket{\widetilde{p}_i}(\bra{\phi_i}A\ket{\phi_j}
-\bra{\widetilde{\phi_i}}A\ket{\widetilde{\phi_j}})\bra{\widetilde{p}_j}
\label{eq:loc1}
\end{equation}

However, while the overlap operator is local, the simplification in Equation \ref{eq:loc1} assumes that
the summations over $i$ and $j$ go over the same species at the same locations in the same lattice;
only the third condition is always satisfied for systems of interest for projections between different
bases. Equation \ref{eq:res} is a more convenient representation than Equation \ref{eq:nonloc} for this
purpose because it is easily seen that all terms between projectors whose augmentation regions do not
overlap vanish. In addition, the POTCAR file in VASP only stores the PS and AE partial waves out to the
edge of the augmentation region, where they are equal but not nonzero, so it is useful to organize the terms
so that they are guaranteed to vanish outside the augmentation regions. Replacing $A$ with unity
allows the overlap between two bands
in different structures $R$ and $S$ with the same lattice to be specified (note that the
summation over $i$ is for structure $R$ and the summation over $j$ is for structure $S$):
\begin{equation}
\begin{split}
\braket{\psi_{Rn_1\mathbf{k}}|\psi_{Sn_2\mathbf{k}}} & =\widetilde{O}+O_1+O_2+O_3\\
\widetilde{O} & =\braket{\widetilde{\psi}_{Rn_1\mathbf{k}}|\widetilde{\psi}_{Sn_2\mathbf{k}}}\\
O_1 & =\sum_i\braket{\widetilde{\psi}_{Rn_1\mathbf{k}}|\widetilde{p}_i}(\bra{\phi_i}-\bra{\widetilde{\phi}_i})
\ket{\widetilde{\psi}_{Sn_2\mathbf{k}}}\\
O_2 & =\sum_j\bra{\widetilde{\psi}_{Rn_1\mathbf{k}}}(\ket{\phi_j}-\ket{\widetilde{\phi}_j})
\braket{\widetilde{p}_j|\widetilde{\psi}_{Sn_2\mathbf{k}}}\\
O_3 & =\sum_i\sum_j\braket{\widetilde{\psi}_{Rn_1\mathbf{k}}|
\widetilde{p}_i}(\bra{\phi_i}-\bra{\widetilde{\phi}_i})
(\ket{\phi_j}-\ket{\widetilde{\phi}_j})\braket{\widetilde{p}_j|\widetilde{\psi}_{Sn_2\mathbf{k}}}
\end{split}
\label{eq:ov1a}
\end{equation}

The pseudowavefunctions can be expanded as a summation of plane waves,
$$\widetilde{\psi}_{n\mathbf{k}}(\mathbf{r})=\sqrt{\frac{\omega_{\mathbf{k}}}{V}}
e^{i\mathbf{k}\cdot \mathbf{r}}\sum_{\mathbf{G}} C_{n\mathbf{k}\mathbf{G}}
e^{i\mathbf{G}\cdot \mathbf{r}}$$
so the overlap between two pseudowavefunctions per unit cell can be written as
$$\widetilde{O}=\braket{\widetilde{\psi}_{n_1\mathbf{k}_1}|\widetilde{\psi}_{n_2\mathbf{k}_2}}
=\delta_{\mathbf{k}_1,\mathbf{k}_2}
\omega_{\mathbf{k}} \sum_{\mathbf{G}} C^*_{n_1\mathbf{k}_1\mathbf{G}}C_{n_2\mathbf{k}_2\mathbf{G}}$$

In VASP, structures with the same energy, k-points, and lattice will have the same basis set,
so this projection is performed simply by reading plane wave coefficients from the VASP WAVECAR file.

It is important to simplify the calculation of the other terms in equation \ref{eq:ov1a} as much
as possible because their calculation can be quite computationally intensive, and the number of
necessary calculations for projecting onto an entire basis set can scale with the number
of sites times the size of the basis set. One major simplification is that if a site $a$ in structure
$R$ and site $b$ in structure $S$ have the same species and position, $a$ and $b$ will only have
overlapping augmentation regions with each other and no other sites. Then, defining $O_{1a}$
as the summation over on-site terms for the identical sites $a$ and $b$ in $O_1$:
$$O_{1a}+O_{2a}+O_{3a}=\sum_{l,m}\sum_{\epsilon_1}\sum_{\epsilon_2}
\braket{\widetilde{\psi}_{Rn_1\mathbf{k}}|\widetilde{p}_{a\ind _1}}
(\braket{\phi_{a\ind _1}|{\phi_{a\ind _2}}}
-\braket{\widetilde{\phi}_{a\ind _1}|\widetilde{\phi}_{a\ind _2}})
\braket{\widetilde{p}_{a\ind _2}|\widetilde{\psi}_{Sn_2\mathbf{k}}}$$
which is the local operator solution derived by Blochl. All three terms must
be evaluated in full for the other sites, but terms in $O_3$ where $i$ and $j$ correspond
to sites with nonoverlapping augmentation spheres vanish. Therefore, if $M_{RS}$ is the set
of identical sites in the structures $R$ and $S$, $N_R$ and $N_S$ are the sets of sites
in $R$ and $S$ not in $M_{RS}$, and $N_{RS}$ is the set of \emph{pairs} of sites not in
$M$ with overlapping augmentation regions, then
\begin{align}
\braket{\psi_{Rn_1\mathbf{k}}|\psi_{Sn_2\mathbf{k}}}&=\widetilde{O}+O_M+O_R+O_S+O_N\\
O_M&=\sum_{a\in M_{RS}}\sum_{l,m}\sum_{\epsilon_1}\sum_{\epsilon_2}
\braket{\widetilde{\psi}_{Rn_1\mathbf{k}}|\widetilde{p}_{a\ind _1}}
(\braket{\phi_{a\ind _1}|{\phi_{a\ind _2}}}
-\braket{\widetilde{\phi}_{a\ind _1}|\widetilde{\phi}_{a\ind _2}})
\braket{\widetilde{p}_{a\ind _2}|\widetilde{\psi}_{Sn_2\mathbf{k}}}\\
O_R&=\sum_{i\in N_R}\braket{\widetilde{\psi}_{Rn_1\mathbf{k}}|\widetilde{p}_i}
(\bra{\phi_i}-\bra{\widetilde{\phi}_i})
\ket{\widetilde{\psi}_{Sn_2\mathbf{k}}}\\
O_S&=\sum_{j\in N_S}\bra{\widetilde{\psi}_{Rn_1\mathbf{k}}}(\ket{\phi_j}
-\ket{\widetilde{\phi}_j})
\braket{\widetilde{p}_j|\widetilde{\psi}_{Sn_2\mathbf{k}}}\\
O_N&=\sum_{i,j\in N_{RS}}\braket{\widetilde{\psi}_{Rn_1\mathbf{k}}|
\widetilde{p}_i}(\bra{\phi_i}-\bra{\widetilde{\phi}_i})
(\ket{\phi_j}-\ket{\widetilde{\phi}_j})
\braket{\widetilde{p}_j|\widetilde{\psi}_{Sn_2\mathbf{k}}}
\label{eq:overlap}
\end{align}

\begin{table}
\centering
\caption{Runtime scaling functions for each component of the code and
definitions for shorthand symbols to express runtime. Approximate
scales with the number of electrons are also shown.
*The frequency refers to how often the routine is called. "Per band"
indicates that the routine runs once every time a band from one structure
is projected onto all the bands of a basis structure. "Per structure"
indicates that the routine is a "setup" routine that must be called once
for each structure and corresponding band structure to do perform projections. "Per lattice"
operations are required once per unique lattice used.
"Per structure pair" is the same as "per structure" except that the routine
is only run once for a pair of structures with the same lattice and plane-wave
basis set, the bands of one such structure to be used as a basis set for the other.
**Number of sites flexibly refers to the number of sites relevant to the calculation,
which worst-case scales with the total number of sites in the structure. For example,
calculating $O_M$ and $O_N$ only require the sites in sets $M$ and $N_RS$, respectively.}
\label{tab:runtime}

\begin{tabular}{|c|c|c|}
\hline
Computational Task & $\Theta$ & Frequency*\\
\hline
$\widetilde{O}$ & $BKSW \sim n^2$ & per band\\
$O_M$ & $BKSNP \sim n^2$ & per band\\
$O_R$ and $O_S$ & $BKSNP \sim n^2$ & per band\\
$O_N$ & $BKSNP \sim n^2$ & per band\\
$\braket{\widetilde{p}_i|\widetilde{\psi}_{n\mathbf{k}}}$ & $BKSF\mathrm{log}(F)
\sim n^2\mathrm{log}(n)$ & per structure\\
$(\bra{\phi_i}-\bra{\widetilde{\phi}_i})
\ket{\widetilde{\psi}_{n\mathbf{k}}}$ & $BKSNPW \sim n^3$ & per structure\\
spherical Bessel transform partial waves & $NPG\mathrm{log}(G) \sim n$ & per structure pair\\
project plane waves onto partial waves & $EPKW \sim n$ & per lattice\\
projections for overlapping aug spheres & $NPL \sim n$ & per structure pair\\
\hline
\end{tabular}

\begin{tabular}{c|c}
Symbol & Definition\\
\hline
B & number of bands\\
E & number of elements\\
F & size of FFT grid\\
G & size of partial wave radial grid\\
K & number of k-points\\
L & size of Legendre-Gauss grid around ions\\
N & number of sites**\\
P & number of projector functions\\
S & number of spin states\\
W & number of plane waves\\
n & number of electrons (approximate scaling)
\end{tabular}
\end{table}

\subsection{Overlap of Pseudowavefunction ($\widetilde{O}$)}

The pseudowavefunction is expanded as a sum of plane waves:

\begin{equation}
\widetilde{\psi}_{n\mathbf{k}} =\frac{1}{\sqrt{V}}\sum_{\mathbf{G}}
C_{n\mathbf{k}\mathbf{G}}e^{i\mathbf{k'}\cdot \mathbf{r}}
\label{eq:pswf}
\end{equation}

where $V$ is the volume of the unit cell, $\mathbf{k}$ is the k-point,
$n$ is the band index, $\mathbf{r}$ is the position, and $C_{n\mathbf{k}\mathbf{G}}$
are the plane-wave coefficients for the plane-waves with vector $\mathbf{k+G}$.

Since plane waves are orthogonal and normalized to $V$ when integrated over the
unit cell, the overlap of two pseudowavefunctions is evaluated easily
by summing over plane-wave coefficients as described in the derivation section
above.

\subsection{Concentric Augmentation Spheres ($O_M$}

Integrals of the type $\braket{\widetilde{\psi}_{Rn_1\mathbf{k}}|\widetilde{p}_{a\ind _1}}$
between a pseudowavefunction and projector function are evaluated using a real-space
FFT grid, as with VASP with LREAL=TRUE.\cite{vasp} Integrals of the
type $\braket{\phi_{a\ind _1}|{\phi_{a\ind _2}}}$ between partial waves
are evaluated by simple radial integration. This is possible because the augmentation
spheres are concentric, so the spherical harmonics for the partial waves
are orthonormal.

\subsection{Partial Waves Overlapping with Pseudowavefunction ($O_R$, $O_S$)}

These integrals are a little bit trickier because it is necessary to project
a smoothly varying pseudowavefunction onto a rapidly varying AE partial wave.
Performing such projections can become prohibitively computationally expensive
for large cells.
Taking advantage of the orthogonality of plane waves, this projection can be
done in real space. Since a plane wave can be expanded around an arbitrary origin
in space (to a phase factor) using Rayleigh expansion:

\begin{equation}
e^{i\mathbf{k} \cdot \mathbf{r}} = 4\pi \sum_{l=0}^{\infty}\sum_{m=-l}^{l}
i^l j_l(kr)Y_l^{m*}(\mathbf{\hat{k}})Y_l^m(\mathbf{\hat{r}})
\label{eq:pwexp}
\end{equation}

partial waves can be Fourier transformed into reciprocal space by evaluating
overlap integrals with spherical Bessel functions. This is done using the
$O(NlogN)$ NUMSBT algorithm developed by Talman.\cite{TALMAN} Then, all
frequency components greater than the FFT grid density can be set to 0
because those plane-waves are orthogonal to the finite plane-wave
basis set of the pseudowavefunctions,
and the partial waves can be transformed back into real space, also using
the NUMSBT algorithm. This results in a smooth partial waves
for which $(\bra{\phi_i}-\bra{\widetilde{\phi}_i})\ket{\widetilde{\psi}_{n\mathbf{k}}}$
can be evaluated in real space.

\subsection{Partial Wave Overlap on Non-Orthgonal Augmentation Spheres ($O_N$)}

The $O_N$ term appears similar to the $O_M$ term, except that the integrals
$(\bra{\phi_i}-\bra{\widetilde{\phi}_i})(\ket{\phi_j}-\ket{\widetilde{\phi}_j})$
are more difficult to evaluate because the partial waves are centered
at different sites. However, transforming these partial waves into
reciprocal space using the spherical Bessel transform allows the
overlap integrals to be evaluated using Equation (47) in Talman's
NUMSBT paper.\cite{TALMAN}.

\printbibliography

\end{document}


\subsection{\tt MobileParticle}
\index{MobileParticle}
MobileParticles are single \idx{point defects}, i.e., they are represented with three coordinates only. They can be either self point defects (interstitials or vacancies) or impurities (carbon, helium, etc). For each impurity or element $A$, a mobile particle with each of the 5 different positions explained in section~\ref{sec:position} can also be found.

MobileParticle parameters, for a given species $A$ are the following ones:
\begin{description}
\item [A(migration)] An arrhenius with the \idx{diffusivity}.
\item [A(formation)] An arrhenius with the  \idx{formation energy} in the bulk.
\end{description}

The events that a MobileParticle can perform are:
\begin{description}
\item[\idx{Migration}] Standard.
\item[\idx{Break-up}] For instance, $AI \rightarrow AM + MI$, being $M$ the material. The formation parameters are used to define the break-up frequencies, but $E_\mathrm{binding}(AI) = E_f(AM) + E_f(MI) - E_f(AI)$.
\item[\idx{Frank-Turnbull}] For instance, $AM  \rightarrow AI +VM$ or $AM \rightarrow AV + MI$. Formation values are used to compute such break-up frequencies.
\end{description}

If the \idx{charge model} is activated, additional state charges can be defined for each particle. For instance

\begin{description}
\item [AM(state.charge)] AM 0
\item [AI(state.charge)] \verb+AI_0+ 0 \verb+AI_-+ -1
\end{description}

The \idx{levels} in the \idx{band gap} for the transitions between charges have also to be defined.

\begin{lstlisting}
float AI(e(-1,0))   .5
\end{lstlisting}

And, finally, a frequency to \idx{update} the charge state between different states is required.

\begin{lstlisting}
arrhenius AI(update) { 1 0.7 }
\end{lstlisting}


%
% %CopyrightBegin%
%
% Copyright Ericsson AB 2017. All Rights Reserved.
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
%     http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% %CopyrightEnd%
%

\chapter{Summary of \Erlang\ expressions}

\label{chapter:summary-exprs}

This is a summary of the expressions of \Erlang.  Each group of
expressions is annotated with a precedence.
\begin{itemize}
\item $\alpha^{+}$ means a nonempty comma-separated sequence of $\alpha$.
\item $\alpha^{@}$ means a nonempty semicolon-separated sequence of $\alpha$.
\item $\alpha\mid\beta$ means either $\alpha$ or $\beta$.
\item $[\alpha]$ means $\alpha$ or nothing.
\item $(\alpha)$ means $\alpha$.
\item $\TZ{E}_p$ means an expression with precedence $p$ or less.
\item \TZ{A} means an atom.
\item \TZ{A} means an integer literal.
\item \TZ{L} means an atomic literal.
\item \TZ{V} means a variable.
\item \TZ{P} means a pattern.
\item \TZ{G} means a guard.
\end{itemize}

\begin{center}
\begin{tabular}{@{}rlllll@{}}
\hline
10 & \multicolumn{2}{l}{\T{catch $\Z{E}_{12}$}} & & & \S\ref{section:catch} \\ \hline
 9 & \T{\Z{P} = $\Z{E}_{\ifStd10\fi\ifOld11\fi}$} & & & & \S\ref{section:match-expr} \\ \hline
 8 & \T{$\Z{E}_9$ = $\Z{E}_{10}$} & & & & \S\ref{section:send-expr} \\ \hline
 7 & \T{$\Z{E}_6$ < $\Z{E}_6$} & \T{$\Z{E}_6$ =< $\Z{E}_6$} & \T{$\Z{E}_6$ > $\Z{E}_6$} & \T{$\Z{E}_6$ >= $\Z{E}_6$} & \S\ref{section:relational} \\
   & \T{$\Z{E}_6$ =:= $\Z{E}_6$} & \T{$\Z{E}_6$ =/= $\Z{E}_6$} & \T{$\Z{E}_6$ == $\Z{E}_6$} & \T{$\Z{E}_6$ /= $\Z{E}_6$} & \S\ref{section:relational} \\ \hline
 6 & \T{$\Z{E}_5$ ++ $\Z{E}_6$} & \T{$\Z{E}_5$ -- $\Z{E}_6$} & & & \S\ref{section:listconc-exprs} \\ \hline
 5 & \T{$\Z{E}_5$ + $\Z{E}_4$} & \T{$\Z{E}_5$ - $\Z{E}_4$} & \T{$\Z{E}_5$ bor $\Z{E}_4$} & \T{$\Z{E}_5$ bxor $\Z{E}_4$} & \S\ref{section:additive} \\
   & \T{$\Z{E}_5$ bsl $\Z{E}_4$} & \T{$\Z{E}_5$ bsr $\Z{E}_4$} & & & \S\ref{section:shift} \\
   & \T{$\Z{E}_9$ or $\Z{E}_8$} & \T{$\Z{E}_9$ xor $\Z{E}_8$} & & &\S\ref{section:additive} \\ \hline
 4 & \T{$\Z{E}_4$ * $\Z{E}_3$} & \T{$\Z{E}_4$ / $\Z{E}_3$} & & & \S\ref{section:multiplicative} \\
   & \ifStd \T{$\Z{E}_4$ // $\Z{E}_3$} & \fi \T{$\Z{E}_4$ div $\Z{E}_3$} & \ifStd \T{$\Z{E}_4$ mod $\Z{E}_3$} & \fi \T{$\Z{E}_4$ rem $\Z{E}_3$} & \ifOld & & \fi \S\ref{section:multiplicative} \\
   & \T{$\Z{E}_4$ band $\Z{E}_3$} & & & & \S\ref{section:multiplicative} \\
   & \T{$\Z{E}_8$ and $\Z{E}_7$} & & & & \S\ref{section:multiplicative} \\ \hline
 3 & \T{+ $\Z{E}_2$} & \T{- $\Z{E}_2$} & \T{bnot $\Z{E}_2$} & \T{not $\Z{E}_2$} & \S\ref{section:unary} \\ \hline
 2 & \T{\char`\#\Z{A}.\Z{A}} & \multicolumn{3}{l}{\T{\char`\#\Z{A}\{$(\text{\T{\Z{A}=$\Z{E}_{12}$}})^{+}$\}}} & \S\ref{section:record-exprs} \\
   & \T{$\Z{E}_2$\char`\#\Z{A}.\Z{A}} & \multicolumn{3}{l}{\T{$\Z{E}_2$\char`\#\Z{A}\{$(\text{\T{\Z{A}=$\Z{E}_{12}$}})^{+}$\}}} & \S\ref{section:record-exprs} \\ \hline
 1 & \T{\Z{A}($\Z{E}_{12}^{+}$)} & \T{$\Z{E}_0$($\Z{E}_{12}^{+}$)} & \T{$\Z{E}_0$:$\Z{E}_0$($\Z{E}_{12}^{+}$)} & & \S\ref{section:application-exprs} \\ \hline
 0 & \multicolumn{4}{l}{\T{\Z{V}}} & \S\ref{section:variables-eval} \\
   & \multicolumn{4}{l}{\T{\Z{L}}} & \S\ref{section:atomic-literals} \\
   & \multicolumn{4}{l}{\T{\{$\Z{E}_{12}^{+}$\}}} & \S\ref{section:tuple-skeletons} \\
   & \T{[]} & \multicolumn{3}{l}{\T{[$\Z{E}_{12}^{*}$|$\Z{E}_{12}$]}} & \S\ref{section:list-skeletons} \\
   & \multicolumn{4}{l}{\T{[$\Z{E}_{12}$||$(\text{\T{\Z{P}<-$\Z{E}_{12}$}}\mid\Z{E}_{12})^{+}$]}} & \S\ref{section:list-comprehensions} \\
   & \multicolumn{4}{l}{\T{begin $\Z{E}_{12}^{+}$ end}} & \S\ref{section:block-exprs} \\
\ifStd
   & \multicolumn{4}{l}{\T{all_true $\Z{E}_{12}^{+}$ end}} & \S\ref{section:alltrue-exprs} \\
   & \multicolumn{4}{l}{\T{some_true $\Z{E}_{12}^{+}$ end}} & \S\ref{section:sometrue-exprs} \\
   & \multicolumn{4}{l}{\T{cond $(\text{\T{$\Z{E}_{12}$ -> $\Z{E}_{12}^{+}$}})^{@}$ end}} & \S\ref{section:cond-expr} \\
\fi
   & \multicolumn{4}{l}{\T{if $(\text{\T{\Z{G} -> $\Z{E}_{12}^{+}$}})^{@}$ end}} & \S\ref{section:if-expr} \\
   & \multicolumn{4}{l}{\T{case $\Z{E}_{12}$ of $(\text{\T{\Z{P} $[\text{\T{when \Z{G}}}]$ -> $\Z{E}_{12}^{+}$}})^{@}$ end}} & \S\ref{section:case-expr} \\
   & \multicolumn{4}{l}{\T{receive $(\text{\T{\Z{P} $[\text{\T{when \Z{G}}}]$ -> $\Z{E}_{12}^{+}$}})^{@}$ $[\text{\T{after $\Z{E}_{12}$ -> $\Z{E}_{12}^{+}$}}]$ end}} & \S\ref{section:receive-expr} \\
\ifStd
   & \multicolumn{4}{l}{\T{try $\Z{E}_{12}^{+}$ catch $(\text{\T{\Z{P} $[\text{\T{when \Z{G}}}]$ -> $\Z{E}_{12}^{+}$}})^{@}$ end}} & \S\ref{section:try-expr} \\
\fi
   & \multicolumn{4}{l}{\T{fun \Z{A}/\Z{I}}} & \S\ref{section:fun-exprs} \\
   & \multicolumn{4}{l}{\T{fun $(\text{\T{($\Z{P}^{+}$) $[\text{\T{when \Z{G}}}]$ -> $\Z{E}_{12}^{+}$}})^{@}$ end}} & \S\ref{section:fun-exprs} \\
\ifOld
   & \multicolumn{4}{l}{\T{query [$\Z{E}_{12}$||$(\text{\T{\Z{P}<-$\Z{E}_{12}$}}\mid\Z{E}_{12})^{+}$] end}} & \S\ref{section:query-exprs} \\
\fi
   & \multicolumn{4}{l}{\T{($\Z{E}_{12}$)}} & \S\ref{section:paren-expr} \\ \hline
\end{tabular}
\end{center}


\documentclass{article}
\usepackage[]{float,latexsym,times}
\usepackage{amsfonts,amstext,amsmath,amssymb,amsthm}
\usepackage{mathrsfs}
\usepackage{bbm}
\usepackage{mathtools} % for dcases
\usepackage{paralist}  % for inparaenum
\usepackage{blkarray}  % for block matrices
\usepackage{pgf,tikz}
\usepackage{MnSymbol}  % \lsem, \rsem.

\usepackage[margin=0.8in]{geometry}
\usepackage{hyperref}

\newcommand{\ignore}[1]{}

% Math notation
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\bigset}[1]{\big\{#1\big\}}
\newcommand{\Bigset}[1]{\Big\{#1\Big\}}
\newcommand{\slfrac}[2]{\left. #1 \middle/ #2 \right.}
\newcommand{\ceil}[1]{\left\lceil #1 \right\rceil}
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newcommand{\round}[1]{\left\lsem\, #1 \,\right\rsem}

% Probability notation
\renewcommand{\mspace}[1]{\mathscr{#1}}
\newcommand{\algebra}[1]{\mathscr{#1}}
\newcommand{\prob}[1]{\mathbf{#1}}
\newcommand{\cond}[2]{\left. {#1} \, \middle | \, {#2} \right.}
\newcommand{\ci}{\perp\!\!\!\perp}             % Conditional independence.
%\renewcommand{\Pr}{\operatorname{\mathbf{P}}}  % probability measure
\DeclareMathOperator{\EV}{\mathbf{E}}          % expected value
\DeclareMathOperator{\Var}{\mathbf{Var}}       % variance
\DeclareMathOperator{\Cov}{\mathbf{Cov}}       % covariance

% Probability distributions
\newcommand{\Binomial}{\mathrm{Bin}}

% Well-known sets
\newcommand{\tinyinfty}{\infty} % or {\scriptscriptstyle \infty}
\newcommand{\tinyzero}{0} % or {\scriptscriptstyle 0}
\newcommand{\One}{\mathchoice{\rm 1\mskip-4.2mu l}{\rm 1\mskip-4.2mu l}{\rm 1\mskip-4.6mu l}{\rm 1\mskip-5.2mu l}}
\newcommand{\Naturals}{\mathbb{N}}
\newcommand{\Reals}{\mathbb{R}}

% Styles
\renewcommand{\le}{\leqslant}
\renewcommand{\leq}{\leqslant}
\renewcommand{\ge}{\geqslant}
\renewcommand{\geq}{\geqslant}
\newcommand{\overwr}{\leftarrow}

% Short-hand notation
\newcommand{\cA}{\mathcal{A}}
\newcommand{\cG}{\mathcal{G}}
\newcommand{\cH}{\mathcal{H}}
\newcommand{\cI}{\mathcal{I}}
\newcommand{\cJ}{\mathcal{J}}

% Document-specific

% Spaces of:
\newcommand{\Sutype}{\mathcal{U}} % Unit types
\newcommand{\Sctype}{\mathcal{C}} % Camp types
\newcommand{\Sgtype}{\mathcal{G}} % Unit groups
\newcommand{\Satype}{\mathcal{A}} % Armies

% Properties
\DeclareMathOperator{\He}{{\sf He}} % Health.
\DeclareMathOperator{\DLow}{\underline{\sf Dm}} % Low damage.
\DeclareMathOperator{\DHigh}{\overline{\sf Dm}} % High damage.
\DeclareMathOperator{\A}{{\sf A}} % Generic attribute.
\DeclareMathOperator{\Acc}{{\sf Acc}} % Accuracy.
\DeclareMathOperator{\Spl}{{\sf Spl}} % Splash chance.
\DeclareMathOperator{\Red}{{\sf Red}} % Damage reduction.
\DeclareMathOperator{\Exp}{{\sf Exp}} % Experience.

% Theorems
\newtheorem{assumption}{Assumption}
\newtheorem{remark}{Remark}
\newtheorem{proposition}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{algorithm}{Algorithm}
\numberwithin{equation}{section}

\newenvironment{example}
  {\paragraph*{Example.}\begin{itemize}\item[]}
  {\end{itemize}}

\title{Divining the Combat System in the Settlers Online}
\date{}

%-------------------------------------------------------------------------------------------------%
\begin{document}

\maketitle

\paragraph*{Foreword.}
This paper is a short summary of how the combat mechanics work in the Settlers Online---based on scattered and scarce pieces of information from the forums from the developers, as well as testing on the main and pre-staging servers. Whenever a certain piece of information is not verified, it will be explicitly noted.

As an aside, the authors consider the adventure combat model only, and discard the expedition combat model as trivial and uninteresting.

\section{Units}
Each unit has a \emph{type}, prescribing the base attributes governing their behavior in a battle. These are:
\begin{itemize}
    \item hit points, which we will denote with $\He $;
    \item experience, $\Exp $---the amount of experience points the attacker gets when this unit is killed;
    \item low and high damage, denoted $\DLow $ and $\DHigh $, respectively;
    \item accuracy, $\Acc $, which is the probability of dealing high damage rather than low damage;
    \item splash chance, $\Spl $---probability that the inflicted damage will spill over to the next defender.
\end{itemize}
All of them, except for $\Acc $ and $\Spl $ are integer-valued.
%
Furthermore, each of the attributes can have \emph{modifiers}. Modifiers come in two flavors: absolute value modifier (additive modifier), and relative/rate modifier (multiplicative modifier). If $\A $ is the base value of any attribute, and ($x$, $r$) is the pair additive modifier/multiplicative modifier, then
\[
    \A + \round{r \A } + x
\]
will be the effective value of the attribute (c.f.\ \cite{dev-halloween:2018}), where $(r \A )$ is rounded for integer-valued attributes. How exactly it is rounded may depending on what $r$ is and which attribute we are talking about.

Based on some---not particularly extensive---testing (but with no reference to official sources) the authors believe that the rounding happens this way (here $r$ is the rate modifier):
\begin{itemize}
    \item $\He $ modifiers are rounded toward zero (down if $r > 0$, up if $r < 0$)---tested for $r > 0$, speculation otherwise;
    \item $\Exp $ modifiers are applied to groups rather than individual units, and are rounded toward zero (down if $r > 0$, up if $r < 0$)---tested for $r > 0$, speculation otherwise;
    \item $\DLow $ and $\DHigh $ modifiers are rounded away from zero (up if $r > 0$, down if $r < 0$)---tested for $r < 0$, speculation otherwise;
    \item $\Acc $ is not rounded---pure speculation;
    \item $\Spl $ is not rounded---pure speculation.
\end{itemize}

When there is more than one modifier, they stack as follows \cite{dev-halloween:2018}. If a base attribute $\A $ is being modified by two modifier pairs, $(x, r)$ and $(y, s)$, then
\[
    \A + \round{(r + s) \A } + (x + y)
\]
will be the effective value of the attribute.

The governing feature of the entire combat system is:
\begin{assumption}
    Units within an army attack sequentially, one at a time.
\end{assumption}
\begin{assumption}
    Opposing armies attack each other simultaneously: if a unit has survived to a stage when they are supposed to attack, they are guaranteed the opportunity to attack regardless of whether or not they are killed in this stage.
\end{assumption}

\begin{example}
    Two defending units---first with $4$ hit points, second with $6$ hit points---are attacked by a group with $\DHigh = 5$, $\DLow = 3$ and $\Spl = 0$.
    We will illustrate the consequences of changing the order of attack. To that end, consider two scenarios: the attacker deals \begin{inparaenum}[(i)]\item high, low, low; and \item low, low, high \end{inparaenum}.

    In the first case the defender's hit points will be $(4, 6) \to (0, 6) \to (0, 3) \to (0, 0)$.

    In the second case the defender's hit points will be $(4, 6) \to (1, 6) \to (0, 6) \to (0, 1)$.
\end{example}

\begin{example}
    Three units, $u_1$, $u_2$, and $u_2$, attack an enemy unit $v$. Let the attacker have $10\%$ damage bonus; let $v$ have $25$ hit points and damage reduction of $30\%$.

    Suppose first two attackers deal base high damage of $13$ each, and the last attacker deals base low damage of $6$. The inflicted damage from $u_1$ and $u_2$ will then be
    \[
        13 + \round{(0.1 - 0.3) \cdot 13} = 13 - \ceil{2.6} = 13 - 3 = 10
    \]
    each. Similarly, the inflicted damage from $u_3$ will be
    \[
        6 - \ceil{(0.2) \cdot 6} = 4.
    \]
    Thus the total damage will be $(10 + 10 + 4) = 24$, and $v$ will survive with $1$ hit point left.

    Note that if one dropped the assumption that units attacked sequentially, the inflicted damage would have been
    \[
        (13 + 13 + 6) - \ceil{(0.2) \cdot (13 + 13 + 6)} = 32 - 7 = 25
    \]
    instead, and $v$ would have died.
\end{example}

\section{To Splash or Not To Splash}\label{sec:splash}

Splash damage (as opposed to truncated---usual---damage) is the case when overshoot damage is spilled over to the next defending unit.
%
\begin{example}
    Suppose there are no damage modifiers, and $u$ attacks $v$---which has only $20$ hit points left---with $100$ damage. In either case $v$ will be killed. If this was a \emph{splash damage} attack, the remaining $80$ damage will be inflicted onto the next unit. If this was a \emph{truncated damage} attack, the remaining $80$ damage will be lost (discarded).
\end{example}

While this works nicely when damage modifiers are equal between groups, the moment damage modifiers are no longer homogeneous a big question arises: how does this difference affect overshoot damage?

The answer to this question is, perhaps, the weakest point of this work: not only is it not documented officially (according to the authors' knowledge), but it has not been tested either (partly because watchtower damage reduction has been removed from the game, and coming up with a conclusive setup seemed too challenging). In short, the following is merely a description of how the authors chose to implement it, and may have little to no relevance to the game.

Suppose a unit $u$ attacks group $G$ followed by group $H$. Let $(\underline{d}_G, \overline{d}_G)$ and $(\underline{d}_H, \overline{d}_H)$ denote the effective (after all bonuses have been applied) damage of $u$ vs.\ $G$ and $H$, respectively.
Denote the damage ratios with
\[
    \underline{r} = \frac{\underline{d}_H}{\underline{d}_G}
    \qquad \text{and} \qquad
    \overline{r} = \frac{\overline{d}_H}{\overline{d}_G}.
\]
Let $\o $ be the overshoot damage when $G$ is killed. If $G$ was killed with a low damage splash hit, then the damage spilled onto $H$ will be $\floor{\underline{r} \, \cdot \o }$. If the damage was high, the corresponding value will be $\floor{\overline{r} \, \cdot \o }$ instead.

\section{Special Abilities and Battle Structure}
In this section we briefly discuss battle or unit characteristics, modifiers, and abilities, that affect the normal course of the battle.

All modifiers to $\He $, $\Exp $, $\DLow $, and $\DHigh $ are stored separately from the base values. Effective values for $\He $ are calculated before the battle begins. Effective values for $\DLow $ and $\DHigh $ are calculated prior to each combat round.
Modifiers to $\Acc $ and $\Spl $, on the other hand, are applied before the battle directly to the base value which is then clipped to the interval $[0, 1]$.

Before the battle starts, there are two stages:
\begin{enumerate}[(i)]
    \item Pre-battle bonus stage: each army's bonuses are applied.
    \item Pre-battle penalty stage: each army's penalties are applied.
\end{enumerate}
This ordering ensures, for example, that if one army has explosive ammunition (granting friendly ranged units \emph{attack weakest target} ability) and the other has intercept (stripping enemy units of \emph{attack weakest target} ability), intercept will take precedence, and all of the units in the first army will \emph{not} have \emph{attack weakest target}.

\section{Combat Sequence}

In this section let $\He ^*$, $\DLow ^*$, $\DHigh ^*$, $\Acc ^*$, and $\Spl ^*$ denote the modified attributes (base values after the modifiers have been applied).

While the base damage dealt by any unit is independent of any other unit, the effective damage is not.
However, if the defending unit has $h$ hit points, it will take at least $k = \ceil{h / \DHigh ^*}$ units to eliminate it, implying that the first $k$ attacks \emph{will} be independent.
%
Having said that, the course of attack is outlined in the following algorithm.
\begin{algorithm}
    Consider a group $G = (u_1, u_2, \cdots , u_n)$ attacking an army $\cA = (v_1, v_2, \cdots , v_m)$.
    %
    Set $i = 1$ and $j = 1$, the (one-based) index of the attacking and defending units, respectively. Let $h = \He ^* (v_1)$ be the health of the first defending unit.
    %
    \begin{enumerate}
        \item \label{step:first_conservative} Let $\DHigh _j ^*$ and $\DLow _j ^*$ be the effective high and low damage against the current defending unit, and let $k = \ceil{h / \DHigh _j ^*}$ be the least number of attacking units required to kill the defender.

        \item If $k$ is greater than $(n - i + 1)$---the remaining units in the attacking group---update $k \overwr (n - i + 1)$.

        \item Generate $X \sim \mathrm{Bin} \left(k, \Acc ^* \right)$, the number of units dealing high damage, and let $d = \DHigh _j ^* \cdot \, X + \DLow _j ^* \cdot \, (k - X)$.

        \item Update $i \overwr i + k$ (point to the next attacking unit).

        \item Update $(h, d) \overwr (h - d, d - h)$ (damage the current defending unit, and store potential overshoot damage).

        \item If $h < 0$ (the current defending unit has been killed and there is still leftover damage), generate $Y \sim \mathrm{Bin} \left(1, \Spl _u \right)$, the chance of splash damage (note that it is not necessary if $h = 0$). Otherwise set $Y = 0$.

        \item If $Y = 0$ (no splash), update $d \overwr 0$ (no overshoot damage).

        \item While $h \leq 0$:
        \begin{enumerate}
            \item update $j \overwr j + 1$ (proceed to the next defending unit);
            \item if $j = m + 1$, terminate: the entire army $\cA $ has been eliminated;
            \item let $r$ denote the splash ratio factor between $v_j$ and $v_{j - 1}$ as explained in section \ref{sec:splash};
            \item update $h \overwr \He ^* (v_j)$ and $d \overwr \floor{r \cdot d}$;
            \item update $(h, d) \overwr (h - d, d - h)$ (damage the next defending unit, and store potential overshoot damage).
        \end{enumerate}

        \item \label{step:last_conservative} If $i = n + 1$, terminate: the entire group $G$ has attacked, and exactly $(j - 1)$ units from $\cA $ have been killed; the $j$-th unit in $\cA $ has only $h$ hit points left.

        \item Otherwise repeat steps \ref{step:first_conservative}--\ref{step:last_conservative}.
    \end{enumerate}
\end{algorithm}

\begin{thebibliography}{9}
    \bibitem{dev-halloween:2018} Official forums. \textit{[Dev Diary] Halloween 2018}, {https://forum.thesettlersonline.net/threads/25261\#post287808}.
\end{thebibliography}

\end{document}


%\documentclass[aps,showpacs,prb,floatfix,twocolumn]{revtex4}
\documentclass[aps,prb,floatfix,epsfig,singlecolumn,showpacs,preprintnumbers]{revtex4}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath,amssymb,graphicx,bm,epsfig}
\usepackage{color}
\usepackage{braket}

\newcommand{\eps}{\epsilon}
\newcommand{\vR}{{\mathbf{R}}}
\newcommand{\vF}{{\mathbf{F}}}
\renewcommand{\vr}{{\mathbf{r}}}
\newcommand{\hr}{{\hat{\textbf{r}}}}
\newcommand{\vk}{{\mathbf{k}}}
\newcommand{\vdelta}{{\mathbf{\delta}}}
\newcommand{\vK}{{\mathbf{K}}}
\newcommand{\vG}{{\mathbf{G}}}
\newcommand{\vq}{{\mathbf{q}}}
\newcommand{\vQ}{{\mathbf{Q}}}
\newcommand{\vPhi}{{\mathbf{\Phi}}}
\newcommand{\vS}{{\mathbf{S}}}
\newcommand{\cG}{{\cal G}}
\newcommand{\cR}{{\cal R}}
\newcommand{\cF}{{\cal F}}
\newcommand{\cT}{{\cal T}}
\newcommand{\cO}{{\cal O}}
\newcommand{\cH}{{\cal H}}
\newcommand{\cJ}{{\cal J}}
\newcommand{\cD}{{\cal D}}
\newcommand{\cU}{{\cal U}}
\newcommand{\cL}{{\cal L}}
\newcommand{\Tr}{\mathrm{Tr}}
\renewcommand{\a}{\alpha}
\renewcommand{\b}{\beta}
\newcommand{\g}{\gamma}
\renewcommand{\d}{\delta}
\newcommand{\npsi}{\underline{\psi}}
\renewcommand{\Im}{\textrm{Im}}
\renewcommand{\Re}{\textrm{Re}}
\newcommand{\cA}{{\cal A}}
\newcommand{\vcA}{\vec{\cal A}}
\newcommand{\vcB}{\vec{\cal B}}
\newcommand{\vcC}{\vec{\cal C}}
\newcommand{\cB}{{\cal B}}
\newcommand{\cC}{{\cal C}}
\usepackage{hyperref}

\begin{document}

\title{Some notes on the Free Energy in DFT+DMFT}
\author{Kristjan Haule}
\affiliation{Department of Physics, Rutgers University, Piscataway, NJ 08854, USA}
\date{\today}

%\begin{abstract}
%\end{abstract}
\pacs{71.27.+a,71.30.+h}
\date{\today}
\maketitle

\section{How is Free energy implemented?}

The details of the algorithm are published in
\href{http://journals.aps.org/prl/abstract/10.1103/PhysRevLett.115.256402}{Phys. Rev. Lett. 115, 256402 (2015)}.
Here we just mention some implementation details, which are not
completely detailed there.

The total energy is printed in column six of \textit{info.iterate}. We
compute it by
\begin{eqnarray}
E_6=E^H[\rho]+E^{XC}[\rho]+E_{nuc}-\Tr((V_H+V_{XC})\rho)+
\textcolor{red}{\Tr(\varepsilon^{DFT}_\vk \rho)}+
\textcolor{blue}{E_{imp}^{pot}-\Phi^{DC}[n_{imp}]}
\end{eqnarray}
The blue terms are computed from the impurity quantities, and the
black and red
are computed from the lattice quantities. The black are evaluated in \textit{lapw0} and \textit{lapwc}. The red
terms are evaluated in \textit{dmft2}.

The free energy is printed in column seven and eight of
\textit{info.iterate}. The seventh column is computed by
\begin{eqnarray}
F_7=E^H[\rho]+E^{XC}[\rho]+E_{nuc}-\Tr((V_H+V_{XC})\rho)
+\textcolor{red}{\Tr\log( G)+\mu N-\Tr\log(G_{loc})+\Tr((\varepsilon_{imp}+V_{DC})n_{loc})}
\\
+\textcolor{blue}{E_{imp}^{pot}
+\Tr\left((\Delta-\omega_n\frac{d\Delta}{d\omega_n})G_{imp}\right)
-\Phi^{DC}[n_{imp}]}
-\textcolor{green}{T S_{imp}}
\end{eqnarray}
The blue terms are computed from the impurity quantities, and the
black and red
are computed from the lattice quantities. The black are evaluated in \textit{lapw0} and \textit{lapwc}. The red
terms are evaluated in \textit{dmft2}. The green term is missing in
\textit{info.iterate} and needs to be computed at postprocessing as
explained in the above PRL.

The eight column is computed by
\begin{eqnarray}
F_8=E^H[\rho]+E^{XC}[\rho]+E_{nuc}-\Tr((V_H+V_{XC})\rho)
+\textcolor{red}{\Tr\log( G)+\mu N-\Tr((\Sigma-V_{DC})G_{loc})}
\\
+\textcolor{blue}{E_{imp}^{pot}
+\Tr\left((\Delta-\omega_n\frac{d\Delta}{d\omega_n})G_{imp}\right)
-\Tr\log(G_{imp})+\Tr(\varepsilon_{imp}n_{imp})+\Tr(\Sigma_{imp}G_{imp})
-\Phi^{DC}[n_{imp}]}
-\textcolor{green}{T S_{imp}}
\end{eqnarray}

The difference between the seventh and eight column is then
\begin{eqnarray}
F_8-F_7 =
\textcolor{red}{\Tr\log(G_{loc})-\Tr(\Sigma G_{loc})-\Tr(\varepsilon_{imp}n_{loc})}
-\textcolor{blue}{\Tr\log(G_{imp})+\Tr(\Sigma G_{imp})+\Tr(\varepsilon_{imp}n_{imp})}
\end{eqnarray}

\end{document}


\section{Tendermint consensus algorithm} \label{sec:tendermint}

\newcommand\Disseminate{\textbf{Disseminate}}

\newcommand\Proposal{\mathsf{PROPOSAL}}
\newcommand\ProposalPart{\mathsf{PROPOSAL\mbox{-}PART}}
\newcommand\PrePrepare{\mathsf{INIT}} \newcommand\Prevote{\mathsf{PREVOTE}}
\newcommand\Precommit{\mathsf{PRECOMMIT}}
\newcommand\Decision{\mathsf{DECISION}}

\newcommand\ViewChange{\mathsf{VC}}
\newcommand\ViewChangeAck{\mathsf{VC\mbox{-}ACK}}
\newcommand\NewPrePrepare{\mathsf{VC\mbox{-}INIT}}
\newcommand\coord{\mathsf{proposer}}

\newcommand\newHeight{newHeight} \newcommand\newRound{newRound}
\newcommand\nil{nil} \newcommand\id{id} \newcommand{\propose}{propose}
\newcommand\prevote{prevote} \newcommand\prevoteWait{prevoteWait}
\newcommand\precommit{precommit} \newcommand\precommitWait{precommitWait}
\newcommand\commit{commit}

\newcommand\timeoutPropose{timeoutPropose}
\newcommand\timeoutPrevote{timeoutPrevote}
\newcommand\timeoutPrecommit{timeoutPrecommit}
\newcommand\proofOfLocking{proof\mbox{-}of\mbox{-}locking}

\begin{algorithm}[htb!] \def\baselinestretch{1} \scriptsize\raggedright
	\begin{algorithmic}[1]
		\SHORTSPACE
		\INIT{}
		\STATE $h_p := 0$
		\COMMENT{current height, or consensus instance we are currently executing}
		\STATE $round_p := 0$   \COMMENT{current round number}
		\STATE $step_p  \in \set{\propose, \prevote, \precommit}$
		\STATE $decision_p[] := nil$
		\STATE $lockedValue_p := nil$
		\STATE $lockedRound_p := -1$
		\STATE $validValue_p := nil$
		\STATE $validRound_p := -1$
		\ENDINIT
		\SHORTSPACE
		\STATE \textbf{upon} start \textbf{do} $StartRound(0)$
		\SHORTSPACE
		\FUNCTION{$StartRound(round)$} \label{line:tab:startRound}
		\STATE $round_p \assign round$
		\STATE $step_p \assign \propose$
		\IF{$\coord(h_p, round_p) = p$}
		\IF{$validValue_p \neq \nil$} \label{line:tab:isThereLockedValue}
		\STATE $proposal \assign validValue_p$ \ELSE \STATE $proposal \assign
		getValue()$
		\label{line:tab:getValidValue}
		\ENDIF
		\STATE \Broadcast\ $\li{\Proposal,h_p, round_p, proposal, validRound_p}$
		\label{line:tab:send-proposal}
		\ELSE
		\STATE \textbf{schedule} $OnTimeoutPropose(h_p,
		round_p)$ to be executed \textbf{after} $\timeoutPropose(round_p)$
		\ENDIF
		\ENDFUNCTION

		\SPACE
		\UPON{$\li{\Proposal,h_p,round_p, v, -1}$ \From\ $\coord(h_p,round_p)$
			\With\ $step_p = \propose$} \label{line:tab:recvProposal}
			\IF{$valid(v) \wedge (lockedRound_p = -1  \vee lockedValue_p = v$)}
			\label{line:tab:accept-proposal-2}
				\STATE \Broadcast \ $\li{\Prevote,h_p,round_p,id(v)}$
				\label{line:tab:prevote-proposal}
			\ELSE
			\label{line:tab:acceptProposal1}
				\STATE \Broadcast \ $\li{\Prevote,h_p,round_p,\nil}$
				\label{line:tab:prevote-nil}
			\ENDIF
				\STATE $step_p \assign \prevote$ \label{line:tab:setStateToPrevote1}
		\ENDUPON

		\SPACE
		\UPON{$\li{\Proposal,h_p,round_p, v, vr}$ \From\ $\coord(h_p,round_p)$
			\textbf{AND} $2f+1$ $\li{\Prevote,h_p, vr,id(v)}$  \With\ $step_p = \propose \wedge (vr \ge 0 \wedge vr < round_p)$}
		\label{line:tab:acceptProposal}
		\IF{$valid(v) \wedge (lockedRound_p \le vr
			\vee lockedValue_p = v)$} \label{line:tab:cond-prevote-higher-proposal}
			\STATE \Broadcast \ $\li{\Prevote,h_p,round_p,id(v)}$
			\label{line:tab:prevote-higher-proposal}
		\ELSE
			\label{line:tab:acceptProposal2}
			\STATE \Broadcast \ $\li{\Prevote,h_p,round_p,\nil}$
			\label{line:tab:prevote-nil2}
		\ENDIF
		\STATE $step_p \assign \prevote$ \label{line:tab:setStateToPrevote3}
		\ENDUPON

		\SPACE
		\UPON{$2f+1$ $\li{\Prevote,h_p, round_p,*}$ \With\ $step_p = \prevote$ for the first time}
		\label{line:tab:recvAny2/3Prevote}
		\STATE \textbf{schedule} $OnTimeoutPrevote(h_p, round_p)$ to be executed \textbf{after}  $\timeoutPrevote(round_p)$ \label{line:tab:timeoutPrevote}
		\ENDUPON

		\SPACE
		\UPON{$\li{\Proposal,h_p,round_p, v, *}$ \From\ $\coord(h_p,round_p)$
			\textbf{AND} $2f+1$ $\li{\Prevote,h_p, round_p,id(v)}$  \With\ $valid(v) \wedge step_p \ge \prevote$ for the first time}
		\label{line:tab:recvPrevote}
		\IF{$step_p = \prevote$}
			\STATE $lockedValue_p \assign v$                \label{line:tab:setLockedValue}
			\STATE $lockedRound_p \assign round_p$   \label{line:tab:setLockedRound}
			\STATE \Broadcast \ $\li{\Precommit,h_p,round_p,id(v))}$
			\label{line:tab:precommit-v}
			\STATE $step_p \assign \precommit$ \label{line:tab:setStateToCommit}
		\ENDIF
		\STATE $validValue_p \assign v$ \label{line:tab:setValidRound}
		\STATE $validRound_p \assign round_p$ \label{line:tab:setValidValue}
		\ENDUPON

		\SHORTSPACE
		\UPON{$2f+1$ $\li{\Prevote,h_p,round_p, \nil}$
			\With\ $step_p = \prevote$}
			\STATE \Broadcast \ $\li{\Precommit,h_p,round_p, \nil}$
			\label{line:tab:precommit-v-1}
			\STATE $step_p \assign \precommit$
		\ENDUPON

		\SPACE
		\UPON{$2f+1$ $\li{\Precommit,h_p,round_p,*}$ for the first time}
		\label{line:tab:startTimeoutPrecommit}
			\STATE \textbf{schedule} $OnTimeoutPrecommit(h_p, round_p)$ to be executed \textbf{after} $\timeoutPrecommit(round_p)$

		\ENDUPON

		\SPACE
		\UPON{$\li{\Proposal,h_p,r, v, *}$ \From\ $\coord(h_p,r)$ \textbf{AND}
			$2f+1$ $\li{\Precommit,h_p,r,id(v)}$ \With\ $decision_p[h_p] = \nil$}
		\label{line:tab:onDecideRule}
			\IF{$valid(v)$} \label{line:tab:validDecisionValue}
				\STATE $decision_p[h_p] = v$ \label{line:tab:decide}
				\STATE$h_p \assign h_p + 1$ \label{line:tab:increaseHeight}
				\STATE reset $lockedRound_p$, $lockedValue_p$, $validRound_p$ and $validValue_p$ to initial values
				and empty message log
				\STATE $StartRound(0)$
			\ENDIF
		\ENDUPON

		\SHORTSPACE
		\UPON{$f+1$ $\li{*,h_p,round, *, *}$ \textbf{with} $round > round_p$}
		\label{line:tab:skipRounds}
			\STATE $StartRound(round)$ \label{line:tab:nextRound2}
		\ENDUPON

		\SHORTSPACE
		\FUNCTION{$OnTimeoutPropose(height,round)$} \label{line:tab:onTimeoutPropose}
		\IF{$height = h_p \wedge round = round_p \wedge step_p = \propose$}
			\STATE \Broadcast \ $\li{\Prevote,h_p,round_p, \nil}$
		 	\label{line:tab:prevote-nil-on-timeout}
		 	\STATE $step_p \assign \prevote$
		 \ENDIF
		 \ENDFUNCTION

		\SHORTSPACE
		\FUNCTION{$OnTimeoutPrevote(height,round)$} \label{line:tab:onTimeoutPrevote}
		\IF{$height = h_p \wedge round = round_p \wedge step_p = \prevote$}
			\STATE \Broadcast \ $\li{\Precommit,h_p,round_p,\nil}$
			\label{line:tab:precommit-nil-onTimeout}
			\STATE $step_p \assign \precommit$
		\ENDIF
		\ENDFUNCTION

		\SHORTSPACE
		\FUNCTION{$OnTimeoutPrecommit(height,round)$} \label{line:tab:onTimeoutPrecommit}
		\IF{$height = h_p \wedge round = round_p$}
			\STATE $StartRound(round_p + 1)$ \label{line:tab:nextRound}
		\ENDIF
		\ENDFUNCTION
	\end{algorithmic} \caption{Tendermint consensus algorithm}
	\label{alg:tendermint}
\end{algorithm}

In this section we present the Tendermint Byzantine fault-tolerant consensus
algorithm. The algorithm is specified by the pseudo-code shown in
Algorithm~\ref{alg:tendermint}. We present the algorithm as a set of \emph{upon
rules} that are executed atomically\footnote{In case several rules are active
at the same time, the first rule to be executed is picked randomly. The
correctness of the algorithm does not depend on the order in which rules are
executed.}. We assume that processes exchange protocol messages using a gossip
protocol and that both sent and received messages are stored in a local message
log for every process. An upon rule is triggered once the message log contains
messages such that the corresponding condition evaluates to $\tt{true}$. The
condition that assumes reception of $X$ messages of a particular type and
content denotes reception of messages whose senders have aggregate voting power at
least equal to $X$. For example, the condition $2f+1$ $\li{\Precommit,h_p,r,id(v)}$,
evaluates to true upon reception of $\Precommit$ messages for height $h_p$,
a round $r$ and with value equal to $id(v)$ whose senders have aggregate voting
power at least equal to $2f+1$. Some of the rules ends with "for the first time" constraint
to denote that it is triggered only the first time a corresponding condition evaluates
to $\tt{true}$. This is because those rules do not always change the state of algorithm
variables so without this constraint, the algorithm could keep
executing those rules forever. The variables with index $p$ are process local state
variables, while variables without index $p$ are value placeholders. The sign
$*$ denotes any value.

We denote with $n$ the total voting power of processes in the system, and we
assume that the total voting power of faulty processes in the system is bounded
with a system parameter $f$.  The algorithm assumes that $n > 3f$, i.e., it
requires that the total voting power of faulty processes is smaller than one
third of the total voting power. For simplicity we present the algorithm for
the case $n = 3f + 1$.

The algorithm proceeds in rounds, where each round has a dedicated
\emph{proposer}. The mapping of rounds to proposers is known to all processes
and is given as a function $\coord(h, round)$, returning the proposer for
the round $round$ in the consensus instance $h$. We
assume that the proposer selection function is weighted round-robin, where
processes are rotated proportional to their voting power\footnote{A validator
with more voting power is selected more frequently, proportional to its power.
More precisely, during a sequence of rounds of size $n$, every process is
proposer in a number of rounds equal to its voting power.}.
The internal protocol state transitions are triggered by message reception and
by expiration of timeouts. There are three timeouts in Algorithm \ref{alg:tendermint}:
$\timeoutPropose$, $\timeoutPrevote$ and $\timeoutPrecommit$.
The timeouts prevent the algorithm from blocking and
waiting forever for some condition to be true, ensure that processes continuously
transition between rounds, and guarantee that eventually (after GST) communication
between correct processes is timely and reliable so they can decide.
The last role is achieved by increasing the timeouts with every new round $r$,
i.e, $timeoutX(r) = initTimeoutX + r*timeoutDelta$;
they are reset for every new height (consensus
instance).

Processes exchange the following messages in Tendermint: $\Proposal$,
$\Prevote$ and $\Precommit$. The $\Proposal$ message is used by the proposer of
the current round to suggest a potential decision value, while $\Prevote$ and
$\Precommit$ are votes for a proposed value. According to the classification of
consensus algorithms from \cite{RMS10:dsn}, Tendermint, like PBFT
\cite{CL02:tcs} and DLS \cite{DLS88:jacm}, belongs to class 3, so it requires
two voting steps (three communication exchanges in total) to decide a value.
The Tendermint consensus algorithm is designed for the blockchain context where
the value to decide is a block of transactions (ie. it is potentially quite
large, consisting of many transactions). Therefore, in the Algorithm
\ref{alg:tendermint} (similar as in \cite{CL02:tcs}) we are explicit about
sending a value (block of transactions) and a small, constant size value id (a
unique value identifier, normally a hash of the value, i.e., if $\id(v) =
\id(v')$, then $v=v'$). The $\Proposal$ message is the only one carrying the
value; $\Prevote$ and $\Precommit$ messages carry the value id.  A correct
process decides on a value $v$ in Tendermint upon receiving the $\Proposal$ for
$v$ and $2f+1$ voting-power equivalent $\Precommit$ messages for $\id(v)$ in
some round $r$. In order to send $\Precommit$ message for $v$ in a round $r$, a
correct process waits to receive the $\Proposal$ and $2f+1$ of the
corresponding $\Prevote$ messages in the round $r$. Otherwise,
it sends $\Precommit$ message with a special $\nil$ value.
This ensures that correct processes can $\Precommit$ only a
single value (or $\nil$) in a round.  As
proposers may be faulty, the proposed value is treated by correct processes as
a suggestion (it is not blindly accepted), and a correct process tells others
if it accepted the $\Proposal$ for value $v$ by sending $\Prevote$ message for
$\id(v)$; otherwise it sends $\Prevote$ message with the special $\nil$ value.

Every process maintains the following variables in the Algorithm
\ref{alg:tendermint}: $step$, $lockedValue$, $lockedRound$, $validValue$ and
$validRound$. The $step$ denotes the current state of the internal Tendermint
state machine, i.e., it reflects the stage of the algorithm execution in the
current round. The $lockedValue$ stores the most recent value (with respect to
a round number) for which a $\Precommit$ message has been sent. The
$lockedRound$ is the last round in which the process sent a $\Precommit$
message that is not $\nil$. We also say that a correct process locks a value
$v$ in a round $r$ by setting $lockedValue = v$ and $lockedRound = r$ before
sending $\Precommit$ message for $\id(v)$. As a correct process can decide a
value $v$ only if $2f+1$ $\Precommit$ messages for $\id(v)$ are received, this
implies that a possible decision value is a value that is locked by at least
$f+1$ voting power equivalent of correct processes. Therefore, any value $v$
for which $\Proposal$ and $2f+1$ of the corresponding $\Prevote$ messages are
received in some round $r$ is a \emph{possible decision} value. The role of the
$validValue$ variable is to store the most recent possible decision value; the
$validRound$ is the last round in which $validValue$ is updated. Apart from
those variables, a process also stores the current consensus instance ($h_p$,
called \emph{height} in Tendermint), and the current round number ($round_p$)
and attaches them to every message. Finally, a process also stores an array of
decisions, $decision_p$ (Tendermint assumes a sequence of consensus instances,
one for each height).

Every round starts by a proposer suggesting a value with the $\Proposal$
message (see line \ref{line:tab:send-proposal}). In the initial round of each
height, the proposer is free to chose the value to suggest. In the
Algorithm~\ref{alg:tendermint}, a correct process obtains a value to propose
using an external function    $getValue()$ that returns a valid value to
propose. In the following rounds, a correct proposer will suggest a new value
only if $validValue = \nil$; otherwise $validValue$ is proposed (see
lines~\ref{line:tab:isThereLockedValue}-\ref{line:tab:getValidValue}).
In addition to the value proposed, the $\Proposal$ message also
contains the $validRound$ so other processes are informed about the last round
in which the proposer observed $validValue$ as a possible decision value.
Note that if a correct proposer $p$ sends $validValue$ with the $validRound$ in the
$\Proposal$, this implies that the process $p$ received $\Proposal$ and the
corresponding $2f+1$ $\Prevote$ messages for $validValue$ in the round
$validRound$.
If a correct process sends $\Proposal$ message with $validValue$ ($validRound > -1$)
at time $t > GST$, by the \emph{Gossip communication} property, the
corresponding $\Proposal$ and the $\Prevote$ messages will be received by all
correct processes before time $t+\Delta$. Therefore, all correct processes will
be able to verify the correctness of the suggested value as it is supported by
the $\Proposal$ and the corresponding $2f+1$ voting power equivalent $\Prevote$
messages.

A correct process $p$ accepts the proposal for a value $v$  (send $\Prevote$
for $id(v)$) if an external \emph{valid} function returns $true$ for the value
$v$, and if $p$ hasn't locked any value ($lockedRound = -1$) or $p$ has locked
the value $v$ ($lockedValue = v$); see the line
\ref{line:tab:accept-proposal-2}.  In case the proposed pair is $(v,vr \ge 0)$ and a
correct process $p$ has locked some value, it will accept
$v$ if it is a more recent possible decision value\footnote{As
explained above, the possible decision value in a round $r$ is the one for
which $\Proposal$ and the corresponding $2f+1$ $\Prevote$ messages are received
for the round $r$.}, $vr > lockedRound_p$,  or if $lockedValue = v$
(see line~\ref{line:tab:cond-prevote-higher-proposal}).  Otherwise, a correct
process will reject the proposal by sending $\Prevote$ message with $\nil$
value. A correct process will send $\Prevote$ message with $\nil$ value also in
case $\timeoutPropose$ expired (it is triggered when a correct process starts a
new round) and a process has not sent $\Prevote$ message in the current round
yet (see the line \ref{line:tab:onTimeoutPropose}).

If a correct process receives $\Proposal$ message for some value $v$ and $2f+1$
$\Prevote$ messages for $\id(v)$, then it sends $\Precommit$ message with
$\id(v)$. Otherwise, it sends $\Precommit$ $\nil$. A correct process will send
$\Precommit$ message with $\nil$ value also in case $\timeoutPrevote$ expired
(it is started when a correct process sent $\Prevote$ message and received any
$2f+1$ $\Prevote$ messages)  and a process has not sent $\Precommit$ message in
the current round yet (see the line \ref{line:tab:onTimeoutPrecommit}).  A
correct process decides on some value $v$ if it receives in some round $r$
$\Proposal$ message for $v$ and $2f+1$ $\Precommit$ messages with $\id(v)$ (see
the line \ref{line:tab:decide}).  To prevent the algorithm from blocking and
waiting forever for this condition to be true, the Algorithm
\ref{alg:tendermint} relies on $\timeoutPrecommit$. It is triggered after a
process receives any set of $2f+1$ $\Precommit$ messages for the current round.
If the $\timeoutPrecommit$ expires and a process has not decided yet, the
process starts the next round (see the line \ref{line:tab:onTimeoutPrecommit}).
When a correct process $p$ decides, it starts the next consensus instance
(for the next height). The \emph{Gossip communication} property ensures
that $\Proposal$ and $2f+1$ $\Prevote$ messages that led $p$ to decide
are eventually received by all correct processes, so they will also decide.

\subsection{Termination mechanism}

Tendermint ensures termination by a novel mechanism that benefits from the
gossip based nature of communication (see \emph{Gossip communication}
property).  It requires managing two additional variables, $validValue$ and
$validRound$ that are then used by the proposer during the propose step as
explained above.   The $validValue$ and $validRound$ are updated to $v$ and $r$
by a correct process in a round $r$ when the process receives valid $\Proposal$
message for the value $v$ and the corresponding $2f+1$ $\Prevote$ messages for
$id(v)$ in the round $r$ (see the rule at line~\ref{line:tab:recvPrevote}).

We now give briefly the intuition how managing and proposing $validValue$
and $validRound$ ensures termination. Formal treatment is left for
Section~\ref{sec:proof}.

The first thing to note is that during good period, because of the
\emph{Gossip communication} property, if a correct process $p$ locks a value
$v$ in some round $r$, all correct processes will update $validValue$ to $v$
and $validRound$ to $r$ before the end of the round $r$ (we prove this formally
in the Section~\ref{sec:proof}). The intuition is that messages that led to $p$
locking a value $v$ in the round $r$ will be gossiped to all correct processes
before the end of the round $r$, so it will update $validValue$ and
$validRound$ (the line~\ref{line:tab:recvPrevote}). Therefore, if a correct
process locks some value during good period, $validValue$ and $validRound$ are
updated by all correct processes so that the value proposed in the following
rounds will be acceptable by all correct processes. Note
that it could happen that during good period, no correct process locks a value,
but some correct process $q$ updates $validValue$ and $validRound$ during some
round. As no correct process locks a value in this case, $validValue_q$ and
$validRound_q$ will also be acceptable by all correct processes as
$validRound_q > lockedRound_c$ for every correct process $c$ and as the
\emph{Gossip communication} property ensures that the corresponding $\Prevote$
messages that $q$ received in the round $validRound_q$ are received by all
correct processes $\Delta$ time later.

Finally, it could happen that after GST, there is a long sequence of rounds in which
no correct process neither locks a value nor update $validValue$ and $validRound$.
In this case, during this sequence of rounds, the proposed value suggested by correct
processes was not accepted by all correct processes. Note that this sequence of rounds
is always finite as at the beginning of every
round there is at least a single correct process $c$ such that $validValue_c$
and $validRound_c$ are acceptable by every correct process. This is true as
there exists a correct process $c$ such that for every other correct process
$p$, $validRound_c > lockedRound_p$ or $validValue_c = lockedValue_p$. This is
true as $c$ is the process that has locked a value in the most recent round
among all correct processes (or no correct process locked any value). Therefore,
eventually $c$ will be the proper in some round and the proposed value will be accepted
by all correct processes, terminating therefore this sequence of
rounds.

Therefore, updating $validValue$ and $validRound$ variables, and the
\emph{Gossip communication} property, together ensures that eventually, during
the good period, there exists a round with a correct proposer whose proposed
value will be accepted by all correct processes, and all correct processes will
terminate in that round. Note that this mechanism, contrary to the common
termination mechanism illustrated in the
Figure~\ref{ch3:fig:coordinator-change}, does not require exchanging any
additional information in addition to messages already sent as part of what is
normally being called "normal" case.


\documentclass{beamer}
\usepackage{csquotes}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes.geometric, calc}
\usepackage{amsmath}
\usepackage{listings, xcolor}
\usepackage{lmodern}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{caption}
\usepackage{icomma}
\usepackage{bigstrut}
\usepackage{geometry}
\usepackage{subfigure}
\usepackage{algorithmic}

\DeclareMathOperator*{\argmin}{argmin}
\captionsetup[figure]{labelformat=empty}

\usetheme{metropolis}           % Use metropolis theme
\title{Update: NN project}
\date{\today}
\author{Robert M. Porsch}
\institute{Center for Genomic Science}
\begin{document}
\maketitle

\begin{frame}[t]{Training, Development, Testing}
  \begin{columns}[t]
    \begin{column}{0.5\textwidth}
      Simulation Data 1:\\
      \begin{itemize}
        \item $\sim2,000$ samples
        \item 40 different simulated phenotypes
        \item based on 1000 Genome project
        \item $MAF\geq1\%$
      \end{itemize}
    \end{column}
    \begin{column}{0.5\textwidth}
     Simulation Data 2:
     \begin{itemize}
       \item $\sim300,000$ samples
       \item 4 different simulated phenotypes
       \item based on UKB
        \item $MAF\geq1\%$
     \end{itemize}
    \end{column}
  \end{columns}
  Issues: sample size limitations for development/testing dataset
\end{frame}

\begin{frame}[t]{On the issue of clumping}
  \begin{itemize}
    \item Clumping can be seen as a variable selection methods (with the parameter p1, p2, r2 and window size)
    \item Tests for a linear relationship between SNP and phenotype
  \end{itemize}
  So when is this becoming a problem?
  \begin{itemize}
    \item nonlinearity
    \item interactions
    \item additional hypterparameter to optimize
  \end{itemize}
\end{frame}

\begin{frame}[t]{On the sucess of clumping}
  \begin{columns}
    \begin{column}{0.5\textwidth}
      \begin{figure}[htpb]
        \centering
        \includegraphics[width=0.8\linewidth]{./clumped_1kg_lasso.png}
        \caption{Clumped Lassosum}
      \end{figure}
    \end{column}
    \begin{column}{0.5\textwidth}
      \begin{figure}[htpb]
        \centering
        \includegraphics[width=0.8\linewidth]{./not_clumped_1kg_lasso.png}
        \caption{NOT Clumped Lassosum}
      \end{figure}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}[t]{NN are difficult to fit}
  \begin{columns}
    \begin{column}{0.5\textwidth}
      \begin{figure}[htpb]
        \centering
        \includegraphics[width=0.8\linewidth]{keras_model_ukb_nn}
        \caption{Complex model (85,60,60,60)}
      \end{figure}
    \end{column}
    \begin{column}{0.5\textwidth}
      \begin{figure}[htpb]
        \centering
        \includegraphics[width=0.8\linewidth]{keras_model_ukb_nn_small}
        \caption{Simple model (60)}
      \end{figure}
    \end{column}
  \end{columns}
  \begin{itemize}
    \item Complexity becomes difficult to train (learning rate)
    \item The phenotype is linear
  \end{itemize}
\end{frame}

\begin{frame}[t]{Sometimes you need to think}
  \begin{columns}
    \begin{column}{0.5\textwidth}
      \begin{figure}[htpb]
        \centering
        \includegraphics[width=0.8\linewidth]{keras_model_ukb_linear.png}
        \caption{Linear Model on the UKB}
      \end{figure}
    \end{column}
    \begin{column}{0.5\textwidth}
      \begin{figure}[htpb]
        \centering
        \includegraphics[width=0.8\linewidth]{./keras_model_ukb_nn_small.png}
        \caption{Small NN model on the UKB}
      \end{figure}
    \end{column}
  \end{columns}
  \begin{itemize}
    \item Drop out layer regularizes efficiently
    \item During validation dropout is deactivated
  \end{itemize}
\end{frame}

\begin{frame}[t]{On Sample Size}
  \begin{columns}
    \begin{column}{0.5\textwidth}
      \begin{figure}[htpb]
        \centering
        \includegraphics[width=0.8\linewidth]{./keras_model_ukb_nn_small.png}
        \caption{Small NN model on the UKB}
      \end{figure}
    \end{column}
    \begin{column}{0.5\textwidth}
      \begin{figure}[htpb]
        \centering
        \includegraphics[width=0.8\linewidth]{./keras_model_1kg_nn_small.png}
        \caption{Small NN model on the 1KG}
      \end{figure}
    \end{column}
  \end{columns}
  \begin{itemize}
    \item less overfitting
    \item results remain accurate despite low sample size
  \end{itemize}
\end{frame}

\begin{frame}[t]{Evaluation}
  \begin{itemize}
    \item Trivial problem given a linear simulated phenotype
    \item Now-complexity
  \end{itemize}
\end{frame}

% \begin{frame}[t]{UKB Data}
%   I also made use of the UKB with the following phenotypes:
%   \begin{itemize}
%     \item height
%     \item IQ
%   \end{itemize}
%   Data was split into training and dev set using caucsian samples only.
%   Dev set was set to be at least $10,000$ samples.
%
%   Some potential problems with the data structure:
%   \begin{itemize}
%     \item data was not shuffled
%     \item currently data was not adjusted for potential confounders (unclear how important)
%   \end{itemize}
% \end{frame}
%
% \section{Fully connected LD Layer: FullDa}
%
% \begin{frame}[t]{Architecture}
%   \begin{columns}[t]
%     \begin{column}{0.5\textwidth}
%       Layer 1:
%       \begin{algorithmic}
%         \STATE initialize $Z$
%         \FOR{v = LD-Blocks}
%         \STATE $z_v = W^{[1]}_vX_v$
%         \STATE $a_v = g(z_v)$
%         \STATE $APPEND(Z, z_v)$
%         \ENDFOR
%       \end{algorithmic}
%       Layer $2$:\\
%       \begin{itemize}
%         \item fully connected layers to output
%         \item $L_1$ regularization in $l=1,2$
%         \item dropout with $p=0.8$
%       \end{itemize}
%     \end{column}
%     \begin{column}{0.5\textwidth}
%       Optimization:
%       \begin{itemize}
%         \item AdaGrad
%         \item Mini-Batch gradient decent with $m=100$
%         \item no early stopping ($epochs=100$)
%       \end{itemize}
%     \end{column}
%   \end{columns}
% \end{frame}
%
% \begin{frame}[t]{Model Overview}
%   \begin{figure}[htpb]
%     \centering
%     \includegraphics[width=0.8\linewidth]{./tensormodel.png}
%   \end{figure}
% \end{frame}
%
% \begin{frame}[t]{Some results}
%   \begin{figure}[htpb]
%     \centering
%     \includegraphics[width=0.8\linewidth]{performance.png}
%     \caption{Example performance on phenotype 1}
%   \end{figure}
%   \begin{itemize}
%     \item high variance problem
%     \item disappointing performance in development set
%     \item performance similar to LassoSum
%   \end{itemize}
% \end{frame}
%
% \section{Clumped NN}
%
% \begin{frame}[t]{Architecture}
%   Similar architecture but with additional clumping step
%
%   \begin{enumerate}[(i)]
%     \item run GWAS on training set
%     \item perform clumping ($r^2=0.5, p_1 = 0.01, p_2 = 0.1$)
%       \begin{itemize}
%         \item Results in 72 SNPs
%       \end{itemize}
%     \item feed clumped genotype matrix into fully connected NN $L=3$
%       \begin{itemize}
%         \item $n^{[1]}_h=60, n^{[2]}_h=60, n^{[3]}_h=1$
%         \item dropout layer after $l=1$ and $l=2$
%       \end{itemize}
%   \end{enumerate}
%   No early stopping, ($epochs=100$), mini-batch with $m=100$
% \end{frame}
%
% \begin{frame}[t]{Results}
%   \begin{figure}[htpb]
%     \centering
%     \includegraphics[width=0.8\linewidth]{./keras_model.png}
%   \end{figure}
%   \begin{itemize}
%     \item Similar performance to the LD-connected NN
%     \item high variance problem
%   \end{itemize}
% \end{frame}
%
% \begin{frame}[t]{Conclusions}
%   \begin{itemize}
%     \item Stronger regularization is required
%     \item Currently there is no hyper-parameter optimization
%     \item Larger dataset should be used (requires some re-write of the data import)
%     \item Current literature: More and more paper on penalized regression for genetic risk prediction (mostly Lasso)
%   \end{itemize}
% \end{frame}
\end{document}


\section{Conclusion}

% haben gezeigt dass unser Ansatz funktioniert ...
% schön wäre, wenn man einen derartigen Verifikations Schritt in Compiler Toolchains integrieren könnte um damit Binaries automatisiert auf derartige Fehler zu überprüfen ...
% aber leider nicht praktikabel, da viel zu lange Laufzeit ...
% Future Work: Encoding optimieren, Laufzeit minimieren, evtl. auf "echte" Prozessoren anwenden ...

In this thesis we explored the potential of bounded model checking for verifying concurrent programs
including the target architecture's memory ordering habits.
Due to the complexity of actual processors, we devised a highly simplified virtual machine model
% to deliver a proof-of-concept
% We therefore devised a highly simplified virtual machine model
% imitating the behaviour of current x86 implementations.
and showed that the addition of store buffers is sufficient to imitate the behaviour of current x86 implementations.
% An encoding for this specific machine model was developed.
% Execution of arbitrary programs
% An encoding for the execution of arbitrary programs was developed

After designing a formal framework for the execution of arbitrary programs on this virtual machine model,
% encodings in two different SMT formats were developed and
encodings of the corresponding model checking problems in two different SMT formats were developed.
% we developed a tool for automating the encoding and evaluation of the resulting model checking problems in two different SMT formats
% To simplify experimentation
We then implemented ConcuBinE, a tool for automating the encoding and evaluation of generated SMT formulas using state-of-the-art solvers.

Even though experiments show the basic feasibility of our approach, the huge runtimes for even small examples puts its practicability in question.
% However, we would like to see the inclusion of such a verification step in compiler toolchains
% However, we still believe it as an opportunity to integrate such a verification step into compiler toolchains to fully proof the
However, we still see it as an opportunity to integrate a similar checking procedure into compiler toolchains, automatically verifying the binaries of critical software with regards to the target architecture's memory ordering model and other specifics.

Future work could therefore involve optimizing the encoding,
% designing an intermediate language for specifying assertions,
devising a method for specifying assertions,
developing a procedure to additionally compute the WCET for automatically determining the upper bound and applying the presented principles to a real architecture like Intel's or AMD's x86 processors.


\chapter{Summary and future perspectives}\label{chapter:ch6}

This work explored the dynamic features of brain function in young adolescents and how they are affected in individuals who were born preterm. To this end, both task-based and resting-state fMRI paradigms were analysed, and one methodological advancement was developed to bring the advantages of dynamic approaches also to task-based studies. Here, I summarise our main findings and identify potential avenues for future work that builds upon the analyses and clinical contributions presented so far.

\section{Summary of findings}

\textbf{Resting-state brain dynamics in preterm-born young adolescents:} We investigated, for the first time, the development of blood oxygenation level dependent (BOLD) signal variability and co-activation patterns (CAPs) in young adolescents born prematurely as compared to fullterm-born controls. To address the issue of high dimensionality in voxelwise BOLD variability maps, we employed a partial least squares correlation (PLSC) approach to identify multivariate patterns of alterations across groups and how they relate to life course measures, namely age at assessment; gestational age; and an interaction between the two. We used a similar PLSC approach to identify differences in CAP expression between the groups and their relationship with the aforementioned life course variables. Through this approach, we discovered that the development of BOLD signal variability is indeed altered in the preterm group in a broad pattern distributed across several areas of the brain, but especially in the bilateral hipoccampi and salience network including bilateral insulae and anterior cingulate cortex (ACC). Since the ACC has been recently identified in other studies as having altered connectivity in preterm-born individuals, we investigated this region further by performing an ACC-based CAPs analysis to uncover dynamic functional connectivity patterns that arise across age. Similarly to the BOLD variability analysis, we found different trajectories of CAP development in both groups.  Indeed, the change in the balance between  internally- and externally-oriented networks across age is more accentuated in the preterm group. Taken together, our observations suggest that the preterm-born brain triggers neurological compensation mechanisms that start during the highly dynamic age range of early adolescence and fail to find an optimal balance.

\textbf{Reality Filtering task processing in preterm-born young adolescents:} To test whether pre\-term-born young adolescents would be able to complete a task that relies on a particularly vulnerable region in this population (the orbitofrontal cortex, OFC), we performed a reality filtering experiment. By looking into how brain activation changed depending on the type of stimulus being shown and comparing the preterm and control groups, we found that despite being able to perform the task with comparable accuracy to the fullterm group, the levels of OFC activation in the preterm group are lower. Moreover, no other regions were significantly more activated in the preterm than in controls. This suggests that preterm-born individuals may have developed mechanisms to optimise OFC activity such that they are still able to perform the task without depending on the same level of activation as the control group.

\textbf{Time-resolved task-driven modulations of brain connectivity:}
We thus proceeded to investigate how brain organisation changes over time as a result of task performance in the preterm population. Given their higher risk of attentional and socio-emotional deficits, we elaborated a task that includes a movie watching aspect and an emotion regulation one. To explore this rich data set we first developed a time-resolved method to recover task-driven co-activation patterns (PPI-CAPs) and analyse their relationships with the seed, task, or an interaction between the two. We initially validate this framework in an adult data set. Once the methodology was stable, we applied it to the preterm data and extended the method to allow group comparisons. Here, we identified a series of dorsal anterior cingulate cortex (ACC)-based co-activation patterns that vary differently in preterms and controls according to the task. Interestingly, a new pattern including the limbic network emerged from this data which had not been found in the CAP analysis from Chapter \ref{chapter:ch3}, which was based on resting-state data. This is in line with existing evidence that the limbic network is involved in emotion processing. Together, these results highlight the relevance of studying brain dynamics in clinical populations. The code developed to perform the analysis described in this work has been made available on \url{https://github.com/lorenafreitas/PPI_CAPs}

\section{Perspective for future research}

\subsection*{Linking dynamic brain function and clinical outcomes}
The studies presented in this thesis characterise dynamic features of brain function in preterm-born young adolescents and how they compare to fullterm-born individuals at his age. Several of these involve areas known to be part of high-order functional networks (see, for example, chapter \ref{chapter:ch3}). An interesting follow-up will thus be to see how the markers unveiled here relate to clinical outcomes such as attention levels, working memory, executive functions, etc. In fact, this data is available from the \textit{Building the Path to Resilience in Preterm-Born Infants} project, of which this work is a constituting part. This would thus be a natural and feasible development for the near future.

\subsection*{Mindfulness meditation as a potential intervention in preterm young adolescents}

 Although interventions for premature babies have been routinely implemented with a positive effect on cognition and  motor abilities \citep{Ferreira2020}, so far there is no consensus regarding procedures applied at later stages in life. Socio-emotional and executive function skills are, however, still in plain development during childhood and adolescence, suggesting that this age may still be within the intervention window.

Mindfulness meditation is a form of mind training to develop a reflective (as opposed to reflexive) way of responding to both internal or external events \citep{Bishop2004} that involves attention, attitude and intention. As \citep{Kabat-Zinn1994} describes it, it involves "paying attention (Attention), in a particular way (Attitude), on purpose (Intention), in the present moment, and non-judgmentally". Studies on its benefits for physical and mental health as well as its neurocognitive mechanisms have gained increased popularity in investigations involving adults, children and adolescents. In fact, even short sessions of meditation given to inexperienced participants have been deemed enough to improve attention levels \citet{Norris2018, Jankowski2020}. Moreover, regular practice has been shown to have long-term effects on attention \citep{Zanesco2018} and brain funtion. Benefits such as the ones described above have put meditation in the spotlight as a potential intervention in clinical practice \citep{Simkin2014,Zhang2018}.

In young populations, mindfulness meditation training has emerged as a potential tool to help manage a wide variety of symptoms including disruptive behaviour \citep{Perry-Parrish2016} and lack of attention \citep{Zhang2018}. A study involving typically developing children at 11 years old showed that 8 weeks of mindfulness training already has the potential to improve attentional self-regulation \citep{Felver2017}. Another, found that meditation programs can enhance cognitive and social-emotional development in young populations \citep{Schonert-Reichl2015}. Taken together, these results further suggest a link between these cognitive domains and that mindfulness meditation may be an avenue for intervention in clinical populations.

The \textit{Building the Path to Resilience in Preterm-Born Infants} project, of which this thesis is part, has acquired functional and structural MRI data from the preterm-born young adolescents studied here after 8 weeks of mindfulness training. Crucially, mindfulness has recently been found to relate to dynamic --- as opposed to static --- features of neural function and neural network interactions over time \citep{Marusak2018}. This highlights PPI-CAPs as a compelling avenue to explore the effects of mindfulness meditation as a potential intervention for young adolescents born prematurely, as its focus is precisely to uncover dynamic aspects of brain function during performance of a task.

\subsection*{PPI-CAPs as markers for neurofeedback}
FMRI Neurofeedback (NF) is a technique in which real-time information about someone's own brain activity is fed back to them, which gives them  the chance to attempt to control it. It has been found to be a promising means to reshape neural activity, and has been used as an intervention tool in several neurological and psychiatric disorders \citep{Guntensperger2017, Misaki2019} including in adolescent clinical populations \citep{Alegria2017}. Most relevant for this work is its potential for self-driven modulation of emotion processing domains, both in adult \citep{Koush2017,Lorenzetti2018} as well as children and adolescent populations \citep{CohenKadosh2016}. In most of these studies, a seed region is selected for which information on activation levels is provided to the user, who then tries to modulate that brain area's activity.

Recently, \citet{Koush2017} showed that it is also possible to gain control over entire networks related to emotion regulation using a connectivity-neurofeedback approach. This opens a promising avenue for future research built on the basis of this thesis. In Chapter \ref{chapter:ch5}, we introduced Psychophysiological Interaction of Co-Activation Patterns (PPI-CAPs) as a seed-based method to investigate time-resolved changes in effective connectivity also in a task-based environment. With this method, we have investigated differences in dynamic brain function during the performance of a task in the preterm group as compared to fullterm-born controls. The very PPI-CAPs which are less elicited by the clinical population could potentially be used as an NF target in future studies. In this paradigm, an initial run could be performed to identify target PPI-CAPs --- that is, those which were most differently expressed between groups. Then, subsequent runs would be carried out where the subject's goal is to attempt to reproduce that pattern. It is important to note, however, that although fMRI NF has been show to successfully modulate activation and connectivity in the brain, and to lead to behavioural changes, how this translates into clinically significant improvements remains debatable \citep{Thibault2018}.

\subsection*{ Extensions for PPI-CAPs}

As described in more detail in section \ref{sec:extensions_ppicaps} of Chapter \ref{chapter:ch5} (Potential extensions of the PPI-CAPs approach), there are several ways in which this methodology could be extended to capture additional information on the dynamic features brain function. Of  note, rather than approaching brain function as a series of separately elicited brain sates \citep{Leonardi2014,Gonzalez-Castillo2015a, Freitas2020}, one could think of it as several patterns that may overlap with each other in dynamic ways \citep{Karahanoglu2013,Karahanoglu2015a}. The so-called \textit{innovation signals} from \citet{Karahanoglu2013}'s work reflect moments in which there are significant \textit{changes} in activation intensity of certain brain areas, rather than pure amplitude.
One could thus apply the frame selection and clustering steps on these signals to yield \textit{innovation-driven} PPI-CAPs (or PPI-\textit{i}CAPs), which would represent spatial patterns of voxels whose signals \textit{transition} simultaneously. Backprojecting these would then recover their time courses, thus revealing moments when different combinations of those patterns may overlap.

Another attractive route for extension would be to consider the introduction of temporal relationships between successive time points. This has been shown to be a promising avenue both when considering sequential \citep{Eavani2013,Chen2016, Vidaurre2017} or overlapping \citep{Sourty2016, Bolton2018a} brain states. For instance in the case of the present work, given that the results from Chapter \ref{chapter:ch5}.1 which revealed default mode network (PPI-CAP\textsubscript{3}), fronto-parietal network (PPI-CAP\textsubscript{1} and PPI-CAP\textsubscript{2}) and salience network (PPI-CAP\textsubscript{2}) contributions during movie-watching, causal interplays between these networks could be assessed in the context of the so-called triple network model \citep{Menon2011}.

So far, PPI-CAPs address temporal dynamics alone, without taking into consideration how to optimally tackle the spatial dimension of the data. One extension could thus be to inject a spatial prior in deriving PPI-CAPs \citep{Zhuang2018}, or to study the spatial variability of task-related functional activity patterns in more detail \citep{Kiviniemi2011}. This could be achieved by separately considering, for each PPI-CAP, the pools of frames linked to given task contexts, and carrying out statistical comparisons at this level \citep{Amico2014}.

Finally, one could investigate measures that are more sophisticated than pure occurrences as features of interest \citep{Chen2015, Bolton2020}, or broaden the analysis of PPI-CAPs to a meta-state perspective \citep{Miller2016,Vidaurre2017}, where a meta-state would symbolise a particular combination of expression and polarity of the investigated patterns.

The ultimate goal is to apply novel tools to better understand brain function both in health individuals and in clinical cohorts. I believe that the future avenues presented here would help provide a more accurate picture of brain function dynamics and have great potential to address these populations.

\subsection*{Probing into structure-function relationships}
While the main goal of this thesis was to focus on the relevance of functional brain dynamics for the study of preterm birth, it is important to consider that the brain's underlying structural architecture clearly affects not only static measures of brain function \citep{Honey2009} but also dynamic ones \citep{Hansen2015}. However, for reasons that remain to be explored --- and may include non-linear neural processing in specific brain areas as well as confounding physiological artefacts --- the BOLD signal contains information that does not simply reproduce that of brain structure. Therefore, analysing both together may bring relevant, additional information which previous studies had missed. For instance, \citet{Amico2018} demonstrated how an approach combining multimodal canonical correlation as well as joint independent component analysis can be used to investigate structural-functional alterations by recovering task-sensitive “hybrid” patterns of connectivity that represent subjects' connectivity fingerprint.

Graph signal processing (GSP) has recently emerged in the neuroimaging field as a novel framework for brain data analysis that integrates brain structure and function (see \citet{Huang2018} for a broad overview). In this scheme, brain structure defines a graph representation where brain regions are the nodes and white matter tracts are the edges, while each frame of fMRI activity is a temporal sample of a signal living on this graph. More recently, this concept has has seen an interesting extension in which high quality activity time courses within the white matter are derived through the combination of a voxel-wise structural graph, and of grey matter activity \citep{Tarun2020}.

To the best of our knowledge, graph analyses on preterm-born populations to date have solely considered either structure or function individually. Therefore, this remains a promising avenue to obtain a better-informed picture of brain function in prematurity.

\subsection*{A note on addressing the global challenge of prematurity}
An important issue in the study of the neurodevelopmental effects of preterm birth is that, although most of the global burden of preterm birth is shouldered by low- and middle-income countries (LMICs), only a tiny portion of the currently available research evidence for their prevention and treatment come from these settings \citep{Smid2016}. However, since high-income countries tend to offer more funding for research and in many cases have better facilities at researchers' disposal, investigations in these regions of potential biomarkers for targeted intervention that improves clinical outcomes in this population are also of utmost importance. Once non-invasive interventions such as the ones the \textit{Building the Path to Resilience in Preterm-Born Infants} project --- of which this thesis is a constituting part --- aims to investigate are found, the need for expensive equipment such as MRI machines will prove less essential, and LMIC populations will also benefit from them.

% https://www.who.int/news-room/fact-sheets/detail/preterm-birth

\clearpage