\documentclass[aps,groupedaddress,onecolumn,11pt,floatfix]{revtex4}

% \ifproofpre{twocolumn version}{onecolumn version}
%   for proof (twocolumn) -- #1
%   for preprint -- #2
\newcommand{\ifproofpre}[2]{#1}

% float placement
\setcounter{topnumber}{99}
\setcounter{bottomnumber}{99}
\setcounter{totalnumber}{99}
\renewcommand{\topfraction}{.99}
\renewcommand{\bottomfraction}{0.99}
\renewcommand{\textfraction}{0.01}
\setcounter{dbltopnumber}{99}
\renewcommand{\dbltopfraction}{.99}
%%\renewcommand{\floatpagefraction}{0.01}
%%\renewcommand{\dblfloatpagefraction}{0.01}

% standard packages
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{isotope}
%%\usepackage{dsfont} % for \mathds{1}
\newcommand{\mathds}{}

% mc packages
\usepackage{wigner}
\usepackage{liealg}

% notation

\newcommand{\MeV}{{\mathrm{MeV}}}
\newcommand{\keV}{{\mathrm{keV}}}
\newcommand{\fm}{{\mathrm{fm}}}

\newcommand{\Nmax}{N_\text{max}}
\newcommand{\Trel}{T_\text{rel}}
\newcommand{\Arel}{A_\text{rel}}

%% \newcommand{\Nrel}{{N_\text{rel}}}
%% \newcommand{\Ncm}{{N_\text{c.m.}}}
%% \newcommand{\nrel}{{n_\text{rel}}}
%% \newcommand{\ncm}{{n_\text{c.m.}}}
%% \newcommand{\lrel}{{l_\text{rel}}}
%% \newcommand{\lcm}{{l_\text{c.m.}}}

% abbreviated
\newcommand{\Nr}{N_r}
\newcommand{\Nc}{N_c}
\newcommand{\nr}{n_r}
\newcommand{\nc}{n_c}
\newcommand{\lr}{l_r}
\newcommand{\lc}{l_c}
\newcommand{\Jr}{J_r}

\newcommand{\unity}{\mathds{1}}
\newcommand{\unitycm}{{\mathds{1}_{\text{c.m.}}}}

\newcommand{\hw}{{\hbar\omega}}
\newcommand{\bint}{{b_{\text{int}}}}
\newcommand{\hwint}{{\hbar\omega_{\text{int}}}}
\newcommand{\Ncut}{{N_\text{cut}}}
\newcommand{\Ncm}{{N_\text{c.m.}}}
\newcommand{\Nex}{{N_\text{ex}}}
\newcommand{\Nv}{{N_v}}

\newcommand{\Einf}{{E_\infty}}
\newcommand{\kinf}{{k_\infty}}
\newcommand{\rinf}{r_\infty}  % used in square, so do not nest braces

\newcommand{\scrN}{{\mathcal{N}}}  % lowercase missing

%% \newcommand{\rp}{r_p}
%% \newcommand{\rn}{r_n}
%% \newcommand{\rm}{r_m}    % symbol clash with \rm font directive

% references
\newcommand{\pref}[1]{(\ref{#1})}

% recoupling

% \overlapZ{j1}{j2}{j3}{J12}{J13}{J}
%%\overlap[3]{\begin{matrix}j_1&&j_2&&j_3\\&\mathclap{J_{12}}\\&&J\end{matrix}}{\begin{matrix}j_1&&j_2&&j_3\\&&\mathclap{J_{13}}\\&&J\end{matrix}}
\newcommand{\overlapZ}[6]{\overlap[3]{\begin{matrix}#1&&#2&&#3\\&\mathclap{#4}\\&&#6\end{matrix}}{\begin{matrix}#1&&#2&&#3\\&&\mathclap{#5}\\&&#6\end{matrix}}}

% \ketcoupled{j1}{j2}{j3}{J12}{J}
\newcommand{\ketcoupled}[5]{\ket[3]{\begin{matrix}#1&&#2&&#3\\&\mathclap{#4}\\&&#5\end{matrix}}}

% \ketcoupledmid{j1}{j2}{j3}{J13}{J}
\newcommand{\ketcoupledmid}[5]{\ket[3]{\begin{matrix}#1&&#2&&#3\\&&\mathclap{#4}\\&&#5\end{matrix}}}

\begin{document}

\title{\texttt{moshinsky}: Moshinsky transformation}

\author{Mark A. Caprio}
\affiliation{Department of Physics, University of Notre Dame, Notre Dame, Indiana 46556-5670, USA}

\date{\today}

\begin{abstract}
\textit{Ab initio} calculations of nuclei face the challenge of
simultaneously describing strong short-range internucleon correlations
and the long-range properties of weakly-bound halo nucleons.  Natural
orbitals, which diagonalize the one-body density matrix, provide a
basis which is better matched to the physical structure of the
many-body wave function.  We demonstrate that the use of natural
orbitals significantly improves convergence for \textit{ab initio}
no-core configuration interaction calculations of the neutron halo
nucleus $\isotope[6]{He}$, relative to the traditional oscillator
basis.
\end{abstract}

\maketitle

%%\section{Introduction}
%%\label{sec-intro}

\section{Moshinsky transformation}

\subsection{Transformation of $LSJT$-scheme matrix elements}

We consider a relative operator $\Arel^{J_0T_0g_0}$ of definite
angular momentum $J_0$, isospin $T_0$ and parity $P_0$, which we will
find it convenient to express
in terms of a grade label $g_0$ as $P_0=(-)^{g_0}$.  The
corresponding operator $A^{J_0T_0P_0}$ on the full two-body fermionic
space, which
 has these same symmetry
properties, is simply $A\equiv\Arel\times\unitycm$.

The Moshinsky brackets $\toverlap{\Nr\lr\Nc\lc;L}{N_1l_1N_2l_2;L}$ are
the unitary transformation brackets relating relative-c.m. states and two-body
states.  In particular, since we are working with fermions, it is
important to realize that the Moshinsky brackets are defined for
\textit{distinguishable} particle states, and we will need to
explicitly account for antisymmetry later.  We follow Negele's
convention of using a parenthesis to denote distinguishable particle
states here, as $\tpket{N_1 l_1 N_2 l_2;LSJTg}$.  Thus, in particular,
\begin{equation}
\label{eqn-moshinsky-xform-ket-dist}
\tpket{N_1 l_1 N_2 l_2;LSJTg}
=\sum_{\substack{\Nr\lr\\\Nc\lc}}
\toverlap{\Nr\lr\Nc\lc;L}{N_1l_1N_2l_2;L}
\,
\tket{\Nr \lr \Nc \lc;LSJTg}.
\end{equation}
There are a few things worth noting in this relation:

(1) The non-orbital angular momentum labels $SJT$ are purely spectator
labels in the summation.

(2) The values for the $l$ labels follow from those for the $N$ labels
by the usual oscillator branching rule [\textit{e.g.}, for the
  relative oscillator labels, $\lr= (\Nr \bmod 2), (\Nr
  \bmod 2)+2,\ldots,\Nr$].  Then the
Moshinsky brackets enforce triangularity constraints $\Delta(\lr\lc L)$
and $\Delta(l_1l_2L)$.

(3) The Moshinsky bracket
preserves total
oscillator quanta
\begin{equation}
\Nr+\Nc = N_1 + N_2 \quad(\equiv N).
\end{equation}
Therefore, in the summation, the values of the indices $\Nr$ and $\Nc$
are in direct correspondence.  That is, if we sum over $\Nr$, then the
summation over $\Nc$ is trivial, and \textit{vice versa}.

(4) The parity of a two-body or relative-c.m.~state is determined by
the total oscillator quantum number.  Consequently, the Moshinsky
bracket also conserves parity.  Again using a grade label $g$ to indicate the parity
[$P=(-)^g$], we have, in terms of relative-c.m.~or two-body labels, respectively,
\begin{equation}
\begin{aligned}
g&\cong \lr + \lc &&\cong \Nr+\Nc &&\cong N\\
g&\cong l_1 + l_2 &&\cong N_1+N_2 &&\cong N,
\end{aligned}
\end{equation}
where congruence indicates equivalence modulo~$2$.  The parity label
is thus redundant to the oscillator labels.  However, we include the
parity labels explicitly on the states in this derivation, since the
classification of states according to their parity subspaces is an
essential aspect of the basis indexing in the implementation of the
Moshinsky transformation.

(5) Although the
Moshinsky bracket is traditionally notated in terms of the
\textit{radial} quantum numbers ($n_1$, $n_2$, $\nr$, and $\nc$), we have
chosen to notate it in terms of the \textit{principal} oscillator
quantum numbers ($N_1$, $N_2$, $\Nr$, and $\Nc$), to better reflect the above
conservation properties.

We express two-body matrix
elements (TBMEs) in terms of relative-c.m.~matrix elements by
transforming the bra and ket spaces separately.
In particular, we relate $JT$-reduced
matrix elements (RMEs) between $LSJT$-scheme states:
\begin{multline}
\label{eqn-moshinsky-xform-op-dist-redundant}
\tprme{N_1' l_1' N_2' l_2';L'S'J'T'g'}{A^{J_0T_0g_0}}{N_1 l_1 N_2 l_2;LSJTg}
\\
=\sum_{\substack{\Nr'\lr'[\Nc'\lc']\\ \Nr\lr\Nc\lc}}
\toverlap{\Nr'\lr'\Nc'\lc';L'}{N_1'l_1'N_2'l_2';L'}
\toverlap{\Nr\lr\Nc\lc;L}{N_1l_1N_2l_2;L}
\\
\times
\trme{\Nr' \Nr' \Nc' \lc';L'S'J'T'g'}{A^{J_0T_0g_0}}{\Nr \lr \Nc \lc; LSJTg}.
\end{multline}
The symmetry properties of the operator enforce $\Delta{J'J_0J}$,
$\Delta{T'T_oT}$, and $g'+g_0+g\cong0$.
 Again, it will be important to realize that, so far,
we have been working with distinguishable-particle states: on the LHS, note that we have
\textit{distinguishable}-particle TBMEs, and, more subtly, we have not
imposed any restrictions on the summation due to antisymmetry
constraints on the labels of relative states.

The particular
Wigner-Eckhart normalization convention adopted for the $JT$-reduced
matrix elements should
be kept in mind, since it enters into the derivation at various points
below, both on the angular momentum side and the isospin side.  Under
the \textit{group theoretic} convention (used by Rose),
\begin{equation}
\label{eqn-we-group}
\me[2]{J'T'\\M_J'M_T'}{A^{J_0T_0}_{M_{J0}M_{T0}}}{JT\\M_JM_T}
=
\cg{J}{M_J}{J_0}{M_{J0}}{J'}{M_J'}
\cg{T}{M_T}{T_0}{M_{T0}}{T'}{M_T'}
\trme{J'T'}{A^{J_0T_0}}{JT},
\end{equation}
 while, under the common \textit{angular momentum} convention of
 Racah (used by Edmonds),
\begin{equation}
\label{eqn-we-racah}
\me[2]{J'T'\\M_J'M_T'}{A^{J_0T_0}_{M_{J0}M_{T0}}}{JT\\M_JM_T}
=
(-)^{2J_0+2T_0} \frac1{\hat{J}'\hat{T}'}
\cg{J}{M_J}{J_0}{M_{J0}}{J'}{M_J'}
\cg{T}{M_T}{T_0}{M_{T0}}{T'}{M_T'}
\trme{J'T'}{A^{J_0T_0}}{JT}.
\end{equation}
Thus, reduced matrix elements under angular momentum (a.m.) and group
theory (g.t.) conventions are related by
\begin{equation}
\trme{J'T'}{A^{J_0T_0}}{JT}_{\text{a.m.}}=
(-)^{2J_0+2T_0} {\hat{J}'\hat{T}'}
\trme{J'T'}{A^{J_0T_0}}{JT}_{\text{g.t.}}.
\end{equation}
For the identity operator,
$\trme{J'T'}{\unity^{00}}{JT}_{\text{g.t.}}= 1$, but
$\trme{J'T'}{\unity^{00}}{JT}_{\text{a.m.}}= {\hat{J}'\hat{T}'}$.

We shall adhere to the group theoretic convention
of~(\ref{eqn-we-group}) below, but beware that
Racah's conventions are widely followed in the shell model literature
(\textit{e.g.}, Talmi and Suhonen).
The phase factors
in~(\ref{eqn-we-racah}), which arise
from the relation between $3j$ symbols and Clebsch-Gordan
coefficients, are only relevant to operators carrying an odd fermion
number and thus do not affect the two-body operators under
consideration here in the Moshinsky transformation.  However, the dimension factors
[$\hat{J}\equiv(2J+1)^{1/2}$] do enter into the derivation below: in
Racah's reduction formula for matrix elements of products of operators
and in the branching from isospin scheme to $pn$ scheme.

Since $A$ is obtained from a \textit{relative} operator
$\Arel$, the relative-c.m.~matrix element imposes the Kronecker delta
constraint $(\Nc'\lc')=(\Nc\lc)$.  It may therefore seem natural to eliminate
the summation over $(\Nc'\lc')$ in~\ref{eqn-moshinsky-xform-op-dist-redundant}, to obtain
\begin{multline}
\label{eqn-moshinsky-xform-op-dist-NcmLcm}
\tprme{N_1' l_1' N_2' l_2';L'S'J'T'g'}{A^{J_0T_0g_0}}{N_1 l_1 N_2
  l_2;LSJTg}
\\
=\sum_{\Nc\lc}\sum_{\substack{\Nr'\lr'\\ \Nr\lr}}
\toverlap{\Nr'\lr'\Nc\lc;L'}{N_1'l_1'N_2'l_2';L'}
\toverlap{\Nr\lr\Nc\lc;L}{N_1l_1N_2l_2;L}
\\
\times
\trme{\Nr' \Nr' \Nc \lc;L'S'J'T'g'}{A^{J_0T_0g_0}}{\Nr \lr \Nc \lc; LSJTg}.
\end{multline}

However, we shall find it useful to base our implementation on the
original expression~\pref{eqn-moshinsky-xform-op-dist-NcmLcm} for the
transformation, which reflects the simple ``matrix-matrix-matrix
multiplication'' structure which one expects of a similarity
transformation.  The constraint that the Moshinsky brackets conserve
$N$ enforces a block-diagonal structure to the transformation
matrices, if we organize our bases by $N$.  While the reduction in
the number of summation indices obtained
in~\pref{eqn-moshinsky-xform-op-dist-NcmLcm} may seem like a
``natural'' simplification, it has the disadvantage that it destroys
the simple matrix-matrix-matrix mutliplication structure.  The RHS
of~\pref{eqn-moshinsky-xform-op-dist-NcmLcm} may still be interpreted
as a \textit{sum}, over $(\Nc\lc)$, of matrix-matrix-matrix products,
where the transformation matrices are indexed by
$(\Nr\lr,N_1l_1N_2l_2)$ at fixed $(\Nc\lc)$, and the untransformed
matrices are indexed by the relative quantum numbers only, as
$(\Nr'\lr',\Nr\lr)$, at fixed $(\Nc\lc)$.  However, this formulation
is not as conducive to making use of the block structure in $N$.

We must still evaluate the relative-c.m.~matrix elements $\trme{\Nr'
  \lr' \Nc \lc;L'S'J'T'g'}{A^{J_0T_0g_0}}{\Nr \lr \Nc \lc; LSJTg}$ in
terms of the underlying relative matrix elements $\trme{\Nr' \Nr'
  ;\lr' S'\Jr'T'g'}{\Arel^{J_0T_0g_0}}{\Nr \lr; \lr S\Jr Tg}$.  These
relative matrix elements are the starting point for the Moshinsky
transformation.  The difference between relative and
relative-c.m.~matrix elements arises from the presence ``spectator''
c.m.~excitations.  Although the operator $A$ acts as the identity on
the c.m.~space (recall $A\equiv\Arel\times\unitycm$), the angular
momentum of the c.m.~excitation affects the value of the
relative-c.m.~matrix element through the angular momentum coupling.

The basic idea is to use
Racah's reduction formula for reduced matrix elements of the product
of two spherical tensor operators acting on two different spaces, to
factorize $\trme{}{A^{J_0}}{}\propto\trme{}{\Arel^{J_0}}{}\trme{}{\unity^{0}}{}$.
If the second operator is the
identity operator, Racah's reduction formula becomes, under the group theoretic convention,
\begin{equation}
\rme[2]{J_1' J_2\\J'}{(A_1^{\lambda}\times\unity^0)^\lambda}{J_1J_2\\J}
=(-)^{J_1'+J_2+J+\lambda}\hat{J}_1'\hat{J}\sixj{J_1'}{J'}{J_2}{J}{J_1}{\lambda}
\trme{J_1'}{A_1^\lambda}{J_1}.
\end{equation}
We shall denote this prefactor for first-system operators by
\begin{equation}
R_{1,\text{g.t.}}(J_1'J';J_1J;J_2\lambda)\equiv(-)^{J_1'+J_2+J+\lambda}\hat{J}_1'\hat{J}\sixj{J_1'}{J'}{J_2}{J}{J_1}{\lambda}.
\end{equation}
Alternatively, under the angular momentum convention,
\begin{equation}
\rme[2]{J_1' J_2\\J'}{(A_1^{\lambda}\times\unity^0)^\lambda}{J_1J_2\\J}
=(-)^{J_1'+J_2+J+\lambda}\hat{J}'\hat{J}\sixj{J_1'}{J'}{J_2}{J}{J_1}{\lambda}
\trme{J_1'}{A_1^\lambda}{J_1}.
\end{equation}

However, to make use of such a factorization in evaluating the
relative-c.m.~matrix element, we must first separate out the angular
momentum of the c.m.~excitation from the other angular momenta in the
coupling, so that it can fulfil the role of the ``second system''
angular momentum.
In general, the
$(12)3-(13)2$ recoupling transformation bracket is given by
\begin{equation}
\overlapZ{j_1}{j_2}{j_3}{J_{12}}{J_{13}}{J}
=(-)^{j_2+j_3+J_{12}+J_{13}}
\hat{J}_{12}\hat{J}_{13}\sixj{j_1}{j_2}{J_{12}}{J}{j_3}{J_{13}}
\equiv Z(j_1j_2j_3;J_{12}J_{13};J),
\end{equation}
where the horizontal alignment of the angular momentum labels on the
LHS is intended to indicate that it is $j_1$ and $j_2$ which couple to give $J_{12}$ in
the bra, but that it is $j_1$ and $j_3$ which couple to give $J_{13}$ in the ket.  We
adopt the letter $Z$ for this $(12)3-(13)2$ ``unitary recoupling
coefficient'', following Millener's usage in the $\grpsu{3}$ scheme,
although in Millener's notation the arrangement of arguments would be
$Z(j_2j_1Jj_3J_{12}J_{13})$, which is somewhat less transparent for
present purposes.
In particular, for the present problem the
angular momenta recouple as
\begin{equation}
\begin{aligned}
\ketcoupled{\lr}{\lc}{S}{L}{J}
&=\sum_{\Jr} \overlapZ{\lr}{\lc}{S}{L}{\Jr}{J}\,\ketcoupledmid{\lr}{\lc}{S}{\Jr}{J}\\
&=\sum_{\Jr}Z(\lr\lc S;L\Jr;J)\,\ketcoupled{\lr}{S}{\lc}{\Jr}{J}
.
\end{aligned}
\end{equation}
We thus have
\begin{multline}
\trme{\Nr' \lr' \Nc \lc;L'S'J'T'g'}{A^{J_0T_0g_0}}{\Nr \lr \Nc \lc; LSJTg}
\\=\sum_{\Jr'\Jr}
Z(\lr'\lc S';L'\Jr';J')
Z(\lr\lc S;L\Jr;J)
R_{1,\text{g.t.}}(\Jr' J';\Jr J;\lc J_0)
\\
\times
\trme{\Nr' \Nr' ;\lr' S'\Jr'T'g'}{\Arel^{J_0T_0g_0}}{\Nr \lr; \lr S\Jr Tg}.
\end{multline}

\subsection{Recoupling to $jjJT$-scheme matrix elements}

\subsection{Accounting for the fermionic nature of the states}

\subsection{Branching to $jjJpn$-scheme matrix elements}

\subsection{Summary of basis indexing schemes}

%%\section*{Acknowledgements}
%%\label{sec-acknowledgements}

\bibliographystyle{apsrev4-1}
%%\bibliographystyle{apsrevm}
\bibliography{master,mc,theory,expt,data,books,proc,misc,natorb}

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

\end{document}


\vsssub
\subsubsection{~The Garden Sprinkler Effect} \label{sub:num_GSE}
\vsssub

\noindent
The higher-order accurate propagation schemes are sufficiently free of
numerical diffusion for the so-called `Garden Sprinkler Effect' (GSE) to
occur, i.e., a continuous swell field disintegrates into a set of discrete
swell fields due to the discrete description of the spectrum
\citep[Fig.~3c]{art:BH87}. Several GSE alleviation methods are available in
\ws, as described in the following sections.


%
%
%
%
%
%
\chapter{Perturbation Treatment in Molecular Quantum Mechanics}
%
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}
%
% what does the perturbation treatment do in the quantum chemistry
%
%
In quantum chemistry, the perturbation treatment is usually employed
to tackle with the weak interactions in the molecular systems. Such
weak interaction can be in variety kinds, such as the vibration of
atom skeleton, or the magnetic susceptibility and
shielding\cite{stevens:550}; or even the time dependent external
field change etc. In general, such physical quantity are very small
so that it's suitable to be the perturbation operator, and the
perturbation treatment can usually yield good results.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The perturbed Hatree-Fock equation in differential form}
%
%  1  start from the Fock equation, the orbital is involved. we
%     do not consider its expansion
%  2  perturbation expansion for the orbital and the orbital energy
%
%
Firstly let's derive the general procedure for the perturbation
treatment in the Hatree-Fock framework\cite{PhysRev.118.167,
Peng_H_W, RevModPhys.32.455}.

As what has been shown in the Hatree-Fock chapter, the general
Hatree-Fock equation in molecular orbital form can be expressed as:
\begin{multline}\label{PTIMQMeq:1}
\hat{H}_{1}(1)\varphi_{i}(1) + \sum_{j}\left[
\left\{\int\varphi^{*}_{j}(2)\varphi_{j}(2)d\tau(2)\frac{1}{r_{12}}\right\}\varphi_{i}(1)
\right] \\
 -
\sum_{j}\left[
\left\{\int\varphi^{*}_{j}(2)\varphi_{i}(2)d\tau(2)\frac{1}{r_{12}}\right\}\varphi_{j}(1)
\right] \\
 = \epsilon_{i}\varphi_{i}(1)
\end{multline}
Here the $j$ goes over all the occupied orbitals. Here for
simplicity we only consider the differential form of Hatree-Fock
equation, the involvement of basis sets are left for the future.

Suggest there's some perturbation in the Fock operator, and it's
assumed to be the one electron operator-where such assumption can
satisfy most of the perturbation cases. In the presence of the
perturbed operator, the molecular orbitals and the its energy levels
will make corresponding change; we can express such changes in
progressive way:
\begin{align}\label{PTIMQMeq:2}
\varphi_{i} &= \varphi^{(0)}_{i} + \lambda\varphi^{(1)}_{i} +
\lambda^{2}\varphi^{(2)}_{i} + \cdots \nonumber \\
\epsilon_{i} &= \epsilon^{(0)}_{i} + \lambda\epsilon^{(1)}_{i} +
\lambda^{2}\epsilon^{(2)}_{i} + \cdots
\end{align}
The new Fock operator can be expressed as:
\begin{equation}\label{PTIMQMeq:3}
\hat{F}^{'} = \hat{F} + \lambda \hat{V}
\end{equation}
Now we go to see how to get the perturbed HF equations.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{First order Hatree Fock perturbed equation}
%
%   to get the first order Fock equation
%
By taking the (\ref{PTIMQMeq:2}) and (\ref{PTIMQMeq:3}) into the
original Hatree-Fock equation (\ref{PTIMQMeq:1}), then by gathering
the terms with same power of $\lambda$, we can get a series of
perturbation equations. The equation scales with $\lambda^{0}$ is:
\begin{equation}\label{PTIMQMeq:4}
\hat{F}\varphi^{(0)}_{i} = \epsilon^{(0)}_{i}\varphi^{(0)}_{i}
\end{equation}
That's the equation for the zero order approximation.

By gathering the terms related to the $\lambda$, we can get the
first order approximation:
\begin{multline}\label{PTIMQMeq:6}
\hat{H}_{1}\varphi^{(1)}_{i} + \hat{V}\varphi^{(0)}_{i} \\
+\sum_{j}\Bigg\{
\int\varphi^{*(0)}_{j}\varphi^{(1)}_{j}d\tau\frac{1}{r_{12}}\varphi^{(0)}_{i}
+
\int\varphi^{*(1)}_{j}\varphi^{(0)}_{j}d\tau\frac{1}{r_{12}}\varphi^{(0)}_{i}
+
\int\varphi^{*(0)}_{j}\varphi^{(0)}_{j}d\tau\frac{1}{r_{12}}\varphi^{(1)}_{i}
\Bigg\} \\
-\sum_{j}\Bigg\{
\int\varphi^{*(0)}_{j}\varphi^{(1)}_{i}d\tau\frac{1}{r_{12}}\varphi^{(0)}_{j}
+
\int\varphi^{*(1)}_{j}\varphi^{(0)}_{i}d\tau\frac{1}{r_{12}}\varphi^{(0)}_{j}
+
\int\varphi^{*(0)}_{j}\varphi^{(0)}_{i}d\tau\frac{1}{r_{12}}\varphi^{(1)}_{j}
\Bigg\} \\
=\epsilon^{(0)}_{i}\varphi^{(1)}_{i} +
\epsilon^{(1)}_{i}\varphi^{(0)}_{i}
\end{multline}
However, we can arrange the above equation into the more convenient
form:
\begin{multline}\label{PTIMQMeq:5}
\hat{F}\varphi^{(1)}_{i} - \epsilon^{(0)}_{i}\varphi^{(1)}_{i} =
\epsilon^{(1)}_{i}\varphi^{(0)}_{i} - \hat{V}\varphi^{(0)}_{i} \\
-\sum_{j}\Bigg\{
\int\varphi^{*(0)}_{j}\varphi^{(1)}_{j}d\tau\frac{1}{r_{12}}\varphi^{(0)}_{i}
+
\int\varphi^{*(1)}_{j}\varphi^{(0)}_{j}d\tau\frac{1}{r_{12}}\varphi^{(0)}_{i}
\\
-
\int\varphi^{*(1)}_{j}\varphi^{(0)}_{i}d\tau\frac{1}{r_{12}}\varphi^{(0)}_{j}
-
\int\varphi^{*(0)}_{j}\varphi^{(0)}_{i}d\tau\frac{1}{r_{12}}\varphi^{(1)}_{j}
\Bigg\}
\end{multline}
Here the items related to the $\varphi^{(1)}_{i}$ are put to the
left of the equation, and the others related to the
$\varphi^{(0)}_{i}$ are put to the right side. Furthermore the
$\hat{F}\varphi^{(1)}_{i}$ is:
\begin{multline}\label{PTIMQMeq:18}
\hat{F}\varphi^{(1)}_{i} = \hat{H}_{1}\varphi^{(1)}_{i} +
\sum_{j}\left[
\left\{\int\varphi^{*(0)}_{j}\varphi^{(0)}_{j}d\tau\frac{1}{r_{12}}\right\}
\varphi^{(1)}_{i}
\right. \\
 -
\left.
\left\{\int\varphi^{*(0)}_{j}\varphi^{(1)}_{i}d\tau\frac{1}{r_{12}}\right\}
\varphi^{(0)}_{j} \right]
\end{multline}
Compared with the (\ref{PTIMQMeq:1}) we have omitted all the
explicit electron labels for simplicity. Besides, the higher order
equations can be obtained in a like manner, but here we concentrate
on the discussion of first order perturbation equation.

By multiply the equation with $\varphi^{*(0)}_{i}$, we can get the
expression for the first order energy for the molecular orbitals:
\begin{multline}\label{PTIMQMeq:13}
\epsilon^{(1)}_{i}=
\int\varphi^{*(0)}_{i}\hat{V}\varphi^{(0)}_{i}d\tau + \\
\sum_{j}\Bigg\{
\int\varphi^{*(0)}_{j}\varphi^{(1)}_{j}d\tau\frac{1}{r_{12}}
    \varphi^{*(0)}_{i}\varphi^{(0)}_{i}d\tau +
\int\varphi^{*(1)}_{j}\varphi^{(0)}_{j}d\tau\frac{1}{r_{12}}
    \varphi^{*(0)}_{i}\varphi^{(0)}_{i}d\tau
\\
-
\int\varphi^{*(1)}_{j}\varphi^{(0)}_{i}d\tau\frac{1}{r_{12}}
    \varphi^{*(0)}_{i}\varphi^{(0)}_{j}d\tau
-
\int\varphi^{*(0)}_{j}\varphi^{(0)}_{i}d\tau\frac{1}{r_{12}}
    \varphi^{*(0)}_{i}\varphi^{(1)}_{j}d\tau
\Bigg\}
\end{multline}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Relations between the perturbed molecular
orbitals}\label{PTIMQM:1}
%
%   consideration about the relations between the wave functions
%
Next we will consider the relations between the $\varphi^{(0)}_{i}$,
$\varphi^{(1)}_{i}$ etc. For the $\varphi^{(0)}_{i}$, it's known
that it equals to the unperturbed HF orbitals:
\begin{align}\label{}
\varphi^{(0)}_{i} &= \varphi_{i}  \nonumber \\
\epsilon^{(0)}_{i} &= \epsilon_{i}
\end{align}
Furthermore, these orbitals can be safely assumed to be orthogonal
with each other:
\begin{equation}\label{}
\int \varphi^{*(0)}_{i}\varphi^{(0)}_{j} d\tau = \delta_{ij}
\end{equation}

For the $\varphi^{(0)}_{i}$, $\varphi^{(1)}_{i}$, we can prove that
they are orthogonal with each other:
\begin{equation}\label{PTIMQMeq:19}
\int \varphi^{*(0)}_{i}\varphi^{(1)}_{i} d\tau = 0
\end{equation}
Such relation can be obtained via the normalization condition of the
$\varphi_{i}$. Suggest that the $\varphi_{i}$ is approximated at the
first order, then we have:
\begin{align}\label{}
\int \varphi^{*}_{i}\varphi_{i} d\tau &= 1  \Rightarrow \nonumber \\
\int \varphi^{*(0)}_{i}\varphi^{(1)}_{i} d\tau  + \int
\varphi^{*(1)}_{i}\varphi^{(0)}_{i} d\tau &= 0
\end{align}
Since that we have:
\begin{equation}\label{}
\int \varphi^{*(0)}_{i}\varphi^{(1)}_{i} d\tau  = \left\{\int
\varphi^{*(1)}_{i}\varphi^{(0)}_{i} d\tau\right\}^{*}
\end{equation}
Then the integral should be some imaginary number so that it can be
set to zero without hurting the generality. Therefore the
orthogonality condition has been proved.

For the $\varphi^{(0)}_{i}$, $\varphi^{(1)}_{k}$ where $k\neq i$, we
can have the relation that:
\begin{equation}\label{PTIMQMeq:9}
\int \varphi^{*(0)}_{i}\varphi^{(1)}_{k} d\tau  + \int
\varphi^{*(1)}_{i}\varphi^{(0)}_{k} d\tau = 0
\end{equation}
This can be achieved through the (\ref{PTIMQMeq:5}). If we take
complex conjugation of the equation in (\ref{PTIMQMeq:5}) and
multiply the $\varphi^{(0)}_{k}$ then to integrate, we can get some
equation:
\begin{multline}\label{PTIMQMeq:7}
\langle\varphi^{(1)}_{i}|\hat{F}|\varphi^{(0)}_{k}\rangle -
\epsilon^{(0)}_{i}\langle\varphi^{(1)}_{i}|\varphi^{(0)}_{k}\rangle
=
- \langle\varphi^{(0)}_{i}|\hat{V}|\varphi^{(0)}_{k}\rangle \\
-\sum_{j}\Bigg\{
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{k}\right)
+
\left(\varphi^{(0)}_{j}\varphi^{(1)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{k}\right)
\\
-
\left(\varphi^{(0)}_{i}\varphi^{(1)}_{j}|\varphi^{(0)}_{j}\varphi^{(0)}_{k}\right)
-
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{j}|\varphi^{(1)}_{j}\varphi^{(0)}_{k}\right)
\Bigg\}
\end{multline}
Here we use the Dirac notion to express the single electron
integral, on the other hand the double electron integral is shorten
as:
\begin{equation}\label{}
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{k}\right)
= \int \int
\varphi^{*(1)}_{j}(1)\varphi^{(0)}_{j}(1)\frac{1}{r_{12}}
\varphi^{*(0)}_{i}(2)\varphi^{(0)}_{k}(2)d\tau_{1}d\tau_{2}
\end{equation}
Such abbreviation is to make the derivation as clear as possible.

On the other hand, if the equation in (\ref{PTIMQMeq:5}) in on
$\varphi^{(1)}_{k}$ and we multiply the $\varphi^{*(0)}_{i}$ then to
make integration, we can get similar equation with
(\ref{PTIMQMeq:7}):
\begin{multline}\label{PTIMQMeq:8}
\langle\varphi^{(0)}_{i}|\hat{F}|\varphi^{(1)}_{k}\rangle -
\epsilon^{(0)}_{k}\langle\varphi^{(0)}_{i}|\varphi^{(1)}_{k}\rangle
=
- \langle\varphi^{(0)}_{i}|\hat{V}|\varphi^{(0)}_{k}\rangle \\
-\sum_{j}\Bigg\{
\left(\varphi^{(0)}_{j}\varphi^{(1)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{k}\right)
+
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{k}\right)
\\
-
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{k}|\varphi^{(0)}_{i}\varphi^{(0)}_{j}\right)
-
\left(\varphi^{(0)}_{j}\varphi^{(0)}_{k}|\varphi^{(0)}_{i}\varphi^{(1)}_{j}\right)
\Bigg\}
\end{multline}
Hence it's easy to see that the right part of (\ref{PTIMQMeq:7}) is
same with the right side of (\ref{PTIMQMeq:8}), therefore we have:
\begin{align}\label{PTIMQMeq:27}
\langle\varphi^{(0)}_{i}|\hat{F}|\varphi^{(1)}_{k}\rangle -
\epsilon^{(0)}_{k}\langle\varphi^{(0)}_{i}|\varphi^{(1)}_{k}\rangle
&=\langle\varphi^{(1)}_{i}|\hat{F}|\varphi^{(0)}_{k}\rangle -
\epsilon^{(0)}_{i}\langle\varphi^{(1)}_{i}|\varphi^{(0)}_{k}\rangle
\nonumber \\
(\epsilon^{(0)}_{i}-\epsilon^{(0)}_{k})
\langle\varphi^{(0)}_{i}|\varphi^{(1)}_{k}\rangle &=
(\epsilon^{(0)}_{k}-\epsilon^{(0)}_{i})
\langle\varphi^{(1)}_{i}|\varphi^{(0)}_{k}\rangle
\end{align}
Then we can get the conclusion in the (\ref{PTIMQMeq:9}).

Nevertheless, in such derivation if the energy level is degenerated
(which means that we have $\epsilon^{(0)}_{k}=\epsilon^{(0)}_{i}$
for the $k\neq i$); we can not get the conclusion of
(\ref{PTIMQMeq:9}) directly from the (\ref{PTIMQMeq:27}). However,
there is another way to derive the relation shown in the
(\ref{PTIMQMeq:9}), which is similar to the way we got the relation
in (\ref{PTIMQMeq:19}).

Once again we use the normalization condition for the $\varphi_{i}$.
Suggest that the $\varphi_{i}$ is approximated at the first order,
then we have:
\begin{align}\label{}
\int \varphi^{*}_{i}\varphi_{k} d\tau = 0 \quad  i\neq k &
\Rightarrow \nonumber \\
\int (\varphi^{*(0)}_{i} + \lambda\varphi^{*(1)}_{i})
(\varphi^{(0)}_{k} + \lambda\varphi^{(1)}_{k}) d\tau &=0 \nonumber
\\
\int\varphi^{*(0)}_{i}\varphi^{(0)}_{k} d\tau  + \lambda(\int
\varphi^{*(0)}_{i}\varphi^{(1)}_{k} d\tau + \int
\varphi^{*(1)}_{i}\varphi^{(0)}_{k} d\tau) + O(\lambda^{2}) &= 0
\end{align}

Because the unperturbed orbitals are orthogonal with each other,
thus $\int\varphi^{*(0)}_{i}\varphi^{(0)}_{k} d\tau = 0$.
Furthermore, since $\lambda$ is some arbitrary number, therefore it
requires that:
\begin{equation}
\int \varphi^{*(0)}_{i}\varphi^{(1)}_{k} d\tau + \int
\varphi^{*(1)}_{i}\varphi^{(0)}_{k} d\tau = 0
\end{equation}
This is just the conclusion in the (\ref{PTIMQMeq:9}). We note that
this proof does not refer to the energy degeneracy so that the
conclusion in the (\ref{PTIMQMeq:9}) is holding in all cases.

All in all, we can get the relations between the first order
correlated orbital of $\varphi^{(1)}_{i}$ and the unperturbed
orbital of $\varphi^{(0)}_{j}$:
\begin{equation}\label{}
\int \varphi^{*(0)}_{i}\varphi^{(1)}_{j} d\tau + \int
\varphi^{*(1)}_{i}\varphi^{(0)}_{j} d\tau = 0
\end{equation}
Here the label of $i$ and $j$ can be any kind of orbitals.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{The first order total energy expression}
%
% consider the total energy expression under the perturbation framework
%
Next we switch to the total energy derivation. According to the
results we have gotten in the HF chapter, the total energy for an
arbitrary $n$ electrons system is:
\begin{multline}\label{PTIMQMeq:10}
E =
\sum_{i}^{n}\langle\varphi_{i}(1)|\hat{H}_{1}(1)|\varphi_{i}(1)\rangle
+
\\
\frac{1}{2}\sum_{i}\sum_{j} \left\{
\int\int\varphi^{*}_{i}(1)\varphi_{i}(1)\frac{1}{r_{12}}
\varphi^{*}_{j}(2)\varphi_{j}(2)d\tau_{1}d\tau_{2}- \right. \\
\left.
\int\int\varphi^{*}_{i}(1)\varphi_{j}(1)\frac{1}{r_{12}}
\varphi^{*}_{j}(2)\varphi_{i}(2)d\tau_{1}d\tau_{2} \right\}
\end{multline}

Similarly, the total energy can be also expanded according to the
order of $\lambda$:
\begin{equation}\label{}
E = E^{(0)} + \lambda E^{(1)} + \lambda^{2}E^{(2)} + \cdots
\end{equation}
Now by taking the expansion for $\varphi$ defined in
(\ref{PTIMQMeq:2}) as well as the total energy expansion into the
(\ref{PTIMQMeq:10}), we can get the perturbation equations for $E$.

The zero order approximation for the total energy equation is:
\begin{multline}\label{PTIMQMeq:11}
E^{(0)} =
\sum_{i}^{n}\langle\varphi^{(0)}_{i}|\hat{H}_{1}|\varphi^{(0)}_{i}\rangle
+
\\
\frac{1}{2}\sum_{i}\sum_{j} \left\{
\int\int\varphi^{*(0)}_{i}\varphi^{(0)}_{i}\frac{1}{r_{12}}
\varphi^{*(0)}_{j}\varphi^{(0)}_{j}d\tau_{1}d\tau_{2}- \right. \\
\left. \int\int\varphi^{*(0)}_{i}\varphi^{(0)}_{j}\frac{1}{r_{12}}
\varphi^{*(0)}_{j}\varphi^{(0)}_{i}d\tau_{1}d\tau_{2} \right\}
\end{multline}
On the other hand, by using the orbital energy we can express it as:
\begin{multline}\label{PTIMQMeq:12}
E^{(0)} = \sum_{i}^{n}\epsilon_{i}^{(0)} -
\frac{1}{2}\sum_{i}\sum_{j} \left\{
\int\int\varphi^{*(0)}_{i}\varphi^{(0)}_{i}\frac{1}{r_{12}}
\varphi^{*(0)}_{j}\varphi^{(0)}_{j}d\tau_{1}d\tau_{2}- \right. \\
\left. \int\int\varphi^{*(0)}_{i}\varphi^{(0)}_{j}\frac{1}{r_{12}}
\varphi^{*(0)}_{j}\varphi^{(0)}_{i}d\tau_{1}d\tau_{2} \right\}
\end{multline}

For the first order approximation, it scales with $\lambda$ and we
can express this term as:
\begin{multline}\label{PTIMQMeq:14}
E^{(1)} =\sum_{i}^{n}
\Bigg\{\langle\varphi^{(1)}_{i}|\hat{H}_{1}|\varphi^{(0)}_{i}\rangle
      +\langle\varphi^{(0)}_{i}|\hat{H}_{1}|\varphi^{(1)}_{i}\rangle +
       \langle\varphi^{(0)}_{i}|\hat{V}|\varphi^{(0)}_{i}\rangle\Bigg\}
\\
+\frac{1}{2}\sum_{i}\sum_{j}\Bigg\{
\left(\varphi^{(1)}_{i}\varphi^{(0)}_{i}|\varphi^{(0)}_{j}\varphi^{(0)}_{j}\right)
+
\left(\varphi^{(0)}_{i}\varphi^{(1)}_{i}|\varphi^{(0)}_{j}\varphi^{(0)}_{j}\right)
\\
+
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{i}|\varphi^{(1)}_{j}\varphi^{(0)}_{j}\right)
+
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{i}|\varphi^{(0)}_{j}\varphi^{(1)}_{j}\right)
\Bigg\} \\
-\frac{1}{2}\sum_{i}\sum_{j}\Bigg\{
\left(\varphi^{(1)}_{i}\varphi^{(0)}_{j}|\varphi^{(0)}_{j}\varphi^{(0)}_{i}\right)
+
\left(\varphi^{(0)}_{i}\varphi^{(1)}_{j}|\varphi^{(0)}_{j}\varphi^{(0)}_{i}\right)
\\
+
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{j}|\varphi^{(1)}_{j}\varphi^{(0)}_{i}\right)
+
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{j}|\varphi^{(0)}_{j}\varphi^{(1)}_{i}\right)
\Bigg\} \\
\end{multline}

This expression is too much complicated. Therefore, by using the
relation we have got before, we try to reduce it into some simpler
form. Firstly, from the (\ref{PTIMQMeq:13}) we can see that the two
electrons integral can be expressed as:
\begin{multline}\label{PTIMQMeq:16}
\sum_{i}\sum_{j}\Bigg\{
\left(\varphi^{(0)}_{j}\varphi^{(1)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{i}\right)
+
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{i}\right)
\\
-
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{i}|\varphi^{(0)}_{i}\varphi^{(0)}_{j}\right)
-
\left(\varphi^{(0)}_{j}\varphi^{(0)}_{i}|\varphi^{(0)}_{i}\varphi^{(1)}_{j}\right)
\Bigg\} \\
= \sum_{i}\Bigg\{\epsilon^{(1)}_{i} -
\langle\varphi^{(0)}_{i}|\hat{V}|\varphi^{(0)}_{i}\rangle\Bigg\}
\end{multline}
By exchanging the label of $i$ and $j$ on the right side of the
above equation (such operation will change nothing), we can get:
\begin{multline}\label{PTIMQMeq:15}
\sum_{i}\sum_{j}\Bigg\{
\left(\varphi^{(0)}_{i}\varphi^{(1)}_{i}|\varphi^{(0)}_{j}\varphi^{(0)}_{j}\right)
+
\left(\varphi^{(1)}_{i}\varphi^{(0)}_{i}|\varphi^{(0)}_{j}\varphi^{(0)}_{j}\right)
\\
-
\left(\varphi^{(1)}_{i}\varphi^{(0)}_{j}|\varphi^{(0)}_{j}\varphi^{(0)}_{i}\right)
-
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{j}|\varphi^{(0)}_{j}\varphi^{(1)}_{i}\right)
\Bigg\} \\
= \sum_{i}\Bigg\{\epsilon^{(1)}_{i} -
\langle\varphi^{(0)}_{i}|\hat{V}|\varphi^{(0)}_{i}\rangle\Bigg\}
\end{multline}
That's half part of the two electron integrals in the
(\ref{PTIMQMeq:14}).

On the other hand, in the (\ref{PTIMQMeq:16}) we can exchange the
electron label in the two electron integrals, that is to make:
\begin{equation}\label{}
(ii|jj) \Rightarrow (jj|ii)
\end{equation}
Certainly such operation will not change the integrals. Thus we can
transform the (\ref{PTIMQMeq:16}) into:
\begin{multline}\label{PTIMQMeq:17}
\sum_{i}\sum_{j}\Bigg\{
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{i}|\varphi^{(0)}_{j}\varphi^{(1)}_{j}\right)
+
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{i}|\varphi^{(1)}_{j}\varphi^{(0)}_{j}\right)
\\
-
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{j}|\varphi^{(1)}_{j}\varphi^{(0)}_{i}\right)
-
\left(\varphi^{(0)}_{i}\varphi^{(1)}_{j}|\varphi^{(0)}_{j}\varphi^{(0)}_{i}\right)
\Bigg\} \\
= \sum_{i}\Bigg\{\epsilon^{(1)}_{i} -
\langle\varphi^{(0)}_{i}|\hat{V}|\varphi^{(0)}_{i}\rangle\Bigg\}
\end{multline}
Now it can see this is the other half part of the two electron
integrals in the (\ref{PTIMQMeq:14}).

All in all, by the expression in (\ref{PTIMQMeq:15}) and
(\ref{PTIMQMeq:17}) the (\ref{PTIMQMeq:14}) can be transformed into:
\begin{equation}\label{PTIMQMeq:22}
E^{(1)} =\sum_{i}^{n} \left\{\epsilon^{(1)}_{i} +
\langle\varphi^{(1)}_{i}|\hat{H}_{1}|\varphi^{(0)}_{i}\rangle
      +\langle\varphi^{(0)}_{i}|\hat{H}_{1}|\varphi^{(1)}_{i}\rangle\right\}
\end{equation}

so far we have gotten some simpler expression for the $E^{(1)}$,
however; the concrete expression for the $\epsilon^{(1)}_{i}$ is not
known yet. Therefore we make to make additional transformation.
First, let's evaluate the integrals below according to the
(\ref{PTIMQMeq:18}):
\begin{multline}\label{PTIMQMeq:20}
\sum_{i}\Bigg\{\langle\varphi^{(0)}_{i}|\hat{F}|\varphi^{(1)}_{i}\rangle
+\langle\varphi^{(1)}_{i}|\hat{F}|\varphi^{(0)}_{i}\rangle\Bigg\}
= \\
\sum_{i}\Bigg\{
\langle\varphi^{(0)}_{i}|\hat{H}_{1}|\varphi^{(1)}_{i}\rangle +
\sum_{j}\Big[
\left(\varphi^{(0)}_{j}\varphi^{(0)}_{j}|\varphi^{(0)}_{i}\varphi^{(1)}_{i}\right)
-
\left(\varphi^{(0)}_{j}\varphi^{(1)}_{i}|\varphi^{(0)}_{i}\varphi^{(0)}_{j}\right)
\Big] \Bigg\} \\
+ \sum_{i}\Bigg\{
\langle\varphi^{(1)}_{i}|\hat{H}_{1}|\varphi^{(0)}_{i}\rangle +
\sum_{j}\Big[
\left(\varphi^{(0)}_{j}\varphi^{(0)}_{j}|\varphi^{(1)}_{i}\varphi^{(0)}_{i}\right)
-
\left(\varphi^{(1)}_{i}\varphi^{(0)}_{j}|\varphi^{(0)}_{j}\varphi^{(0)}_{i}\right)
\Big] \Bigg\}
\end{multline}
Because of the orthogonality between the $\varphi^{(0)}_{i}$ and
$\varphi^{(1)}_{i}$ defined in (\ref{PTIMQMeq:19}), we have:
\begin{equation}\label{}
\langle\varphi^{(0)}_{i}|\hat{F}|\varphi^{(1)}_{i}\rangle =
\epsilon^{(0)}_{i}\langle\varphi^{(0)}_{i}|\varphi^{(1)}_{i}\rangle
= 0
\end{equation}
Therefore the equation of (\ref{PTIMQMeq:20}) can be rearranged
into:
\begin{multline}\label{PTIMQMeq:20}
\sum_{i}\Bigg\{
\langle\varphi^{(0)}_{i}|\hat{H}_{1}|\varphi^{(1)}_{i}\rangle +
\langle\varphi^{(1)}_{i}|\hat{H}_{1}|\varphi^{(0)}_{i}\rangle
\Bigg\}= \\
-\sum_{i}\sum_{j}\Bigg\{
\left(\varphi^{(0)}_{j}\varphi^{(0)}_{j}|\varphi^{(0)}_{i}\varphi^{(1)}_{i}\right)
-
\left(\varphi^{(0)}_{j}\varphi^{(1)}_{i}|\varphi^{(0)}_{i}\varphi^{(0)}_{j}\right)
+ \\
\left(\varphi^{(0)}_{j}\varphi^{(0)}_{j}|\varphi^{(1)}_{i}\varphi^{(0)}_{i}\right)
-
\left(\varphi^{(1)}_{i}\varphi^{(0)}_{j}|\varphi^{(0)}_{j}\varphi^{(0)}_{i}\right)
\Bigg\}
\end{multline}
Here we can exchange the label of $i$, $j$ and then exchange the
electron label, such operation will keep the integrals invariant.
Then we can have:
\begin{multline}\label{PTIMQMeq:20}
\sum_{i}\Bigg\{
\langle\varphi^{(0)}_{i}|\hat{H}_{1}|\varphi^{(1)}_{i}\rangle +
\langle\varphi^{(1)}_{i}|\hat{H}_{1}|\varphi^{(0)}_{i}\rangle
\Bigg\}= \\
-\sum_{i}\sum_{j}\Bigg\{
\left(\varphi^{(0)}_{j}\varphi^{(1)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{i}\right)
-
\left(\varphi^{(0)}_{j}\varphi^{(0)}_{i}|\varphi^{(0)}_{i}\varphi^{(1)}_{j}\right)
+ \\
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{i}\right)
-
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{j}|\varphi^{(1)}_{j}\varphi^{(0)}_{i}\right)
\Bigg\}
\end{multline}
For the integral of
$\left(\varphi^{(0)}_{i}\varphi^{(0)}_{j}|\varphi^{(1)}_{j}\varphi^{(0)}_{i}\right)$,
if we exchange the electron label again, it will be:
\begin{equation}\label{}
\left(\varphi^{(0)}_{i}\varphi^{(0)}_{j}|\varphi^{(1)}_{j}\varphi^{(0)}_{i}\right)=
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{i}|\varphi^{(0)}_{i}\varphi^{(0)}_{j}\right)
\end{equation}

Then finally the (\ref{PTIMQMeq:20}) will be:
\begin{multline}\label{PTIMQMeq:21}
\sum_{i}\Bigg\{
\langle\varphi^{(0)}_{i}|\hat{H}_{1}|\varphi^{(1)}_{i}\rangle +
\langle\varphi^{(1)}_{i}|\hat{H}_{1}|\varphi^{(0)}_{i}\rangle
\Bigg\}= \\
-\sum_{i}\sum_{j}\Bigg\{
\left(\varphi^{(0)}_{j}\varphi^{(1)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{i}\right)
-
\left(\varphi^{(0)}_{j}\varphi^{(0)}_{i}|\varphi^{(0)}_{i}\varphi^{(1)}_{j}\right)
+ \\
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{j}|\varphi^{(0)}_{i}\varphi^{(0)}_{i}\right)
-
\left(\varphi^{(1)}_{j}\varphi^{(0)}_{i}|\varphi^{(0)}_{i}\varphi^{(0)}_{j}\right)
\Bigg\}
\end{multline}

Now we can transform the (\ref{PTIMQMeq:22}) by using the conclusion
we get from the (\ref{PTIMQMeq:21}), as well as the expression for
the $\epsilon^{(1)}_{i}$ in (\ref{PTIMQMeq:13}). Consequently, it
turns out that $E^{(1)}$ finally is:
\begin{equation}\label{}
E^{(1)} = \sum_{i}
\langle\varphi^{(0)}_{i}|\hat{V}|\varphi^{(0)}_{i}\rangle
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Matrix form of the perturbed Hatree-Fock equation}
%
%
%
%
In the above content, we have derived the first order perturbed
Hatree-Fock equation in a very detailed way. However, since in
quantum chemistry we usually use the matrix form of the Hatree-Fock
equation in terms of the basis sets functions; thus it's necessary
to rebuild the perturbed equations into the matrix form based on the
above achievement\cite{stevens:550}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{General procedures}
%
%  general preparation before the derivation,
%  specify the ground states and HF equation as well as how to express the
%  first order correlated molecular orbitals
%
Now we begin to investigate how to make a perturbation treatment on
the base of the linear combination of basis sets functions. In this
case, the unperturbed molecular orbitals is usually expressed as:
\begin{equation}\label{PTIMQMeq:23}
\varphi_{q} = \sum_{p}c_{pq}\chi_{p}
\end{equation}
Where the $\chi_{p}$ is referred as the basis sets functions. Here
we follow the convention that to use $i, j$ etc. to designate the
occupied orbitals, $a, b$ etc. to designate the virtual orbitals and
to use the $p, q$ etc. to refer to the general orbitals. Here it's
better to reform it into the matrix form, that is:
\begin{equation}\label{PTIMQMeq:30}
\varphi_{q} =\begin{bmatrix}
               \chi_{1} & \chi_{2} & \cdots & \chi_{n} \\
             \end{bmatrix}
             \begin{bmatrix}
               c_{1q} \\
               c_{2q} \\
               \cdots \\
               c_{nq} \\
             \end{bmatrix}
\end{equation}
According to the representation theory \ref{REPRESENTATION:1}, such
expression is called coefficients $C$ representation based on the
selected basis functions space of $\chi$.

Now we assume that there's one to one correspondence between the
coefficients representation and the total wave function (so far in
my opinion this assumption does not hurt the generality, in other
words such assumption always holds true). Then by taking the vector
form of the molecular orbitals in (\ref{PTIMQMeq:30}) back into the
original Hatree-Fock equation (\ref{PTIMQMeq:1}), and to multiply
with $\psi_{i}^{*}(1)$ then make integration; we can get the
corresponding matrix form:
\begin{equation}\label{PTIMQMeq:24}
FC_{q} = SC_{q}\epsilon_{q}
\end{equation}
Furthermore, since we can use some unitary matrix to drop the
overlap matrix, then the Hatree-Fock equation can finally be:
\begin{equation}\label{PTIMQMeq:34}
FC_{q} = \epsilon C_{q}
\end{equation}
This equation has been fully discussed in the Hatree-Fock chapter
\ref{HFT}. Here $C_{q}$ denotes the vector of $c_{pq}$ in the
(\ref{PTIMQMeq:23}). The $\epsilon$ is some $n\times n$ diagonal
matrix which characterizes the orbital energy. Later in the content,
we will go on the discussion focusing on the (\ref{PTIMQMeq:34}).

Moreover, the total energy is given as:
\begin{equation}\label{PTIMQMeq:25}
E = \frac{1}{2}\sum_{q}(C_{q}^{+}FC_{q} + \epsilon_{q})
\end{equation}
The (\ref{PTIMQMeq:25}) can be get directly from the addition
between (\ref{PTIMQMeq:11}) and (\ref{PTIMQMeq:12}). For simplicity,
The orbitals can still assumed to be orthogonal with each other,
that means $\langle\varphi_{p}|\varphi_{q}\rangle = \delta_{pq}$.

Now we assume that there's some perturbation in the whole system so
that the it causes corresponding change in the molecular orbital,
the orbital energy and the total energy:
\begin{align}\label{}
\hat{F}^{'} &= \hat{F} + \lambda \hat{V} \Rightarrow \nonumber \\
\varphi_{q} &= \varphi^{(0)}_{q} + \lambda\varphi^{(1)}_{q} +
\lambda^{2}\varphi^{(2)}_{q} + \cdots \nonumber \\
\epsilon_{q} &= \epsilon^{(0)}_{q} + \lambda\epsilon^{(1)}_{q} +
\lambda^{2}\epsilon^{(2)}_{q} + \cdots \nonumber \\
E &= E^{(0)} + \lambda E^{(1)} + \lambda^{2}E^{(2)} + \cdots
\end{align}
We note that this is same with the derivation in the last section.
Here in a like manner we still concentrate on the first order
perturbation effects.

Furthermore, how to express the first order molecular orbital? Since
that all the molecular orbitals are expressed on the space
constituted by the basis sets, thus it's natural to be represented
by the perturbed coefficients:
\begin{align}\label{PTIMQMeq:26}
\varphi^{(0)}_{q} &= \sum_{p}c^{(0)}_{pq}\chi_{p} \nonumber \\
\varphi^{(1)}_{q} &= \sum_{p}c^{(1)}_{pq}\chi_{p}
\end{align}
Here the label of $p$ goes over all the orbitals, including the
occupied ones and the virtual ones. Next, we are going to consider
the relations between the molecular orbitals.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Relation for the perturbed orbitals}
%
%  derive the relation between the perturbed orbitals, in terms of the
%  basis sets functions
%
%
In the section of (\ref{PTIMQM:1}), we have derived some general
relation between the $\varphi^{(1)}_{p}$ and $\varphi^{(0)}_{q}$:
\begin{equation}\label{PTIMQMeq:31}
\int\varphi^{*(1)}_{p}\varphi^{(0)}_{q}d\tau
+\int\varphi^{*(0)}_{p}\varphi^{(1)}_{q}d\tau = 0
\end{equation}
Furthermore, for the case that $p=q$; we have proved that the
integral can be set to $0$:
\begin{equation}\label{}
\int\varphi^{*(1)}_{p}\varphi^{(0)}_{q}d\tau = 0
\end{equation}

By taking the expression of (\ref{PTIMQMeq:26}) into the
(\ref{PTIMQMeq:31}), we can get:
\begin{align}\label{PTIMQMeq:33}
\sum_{r}\sum_{s}(c^{*(1)}_{rp}c^{(0)}_{sq} +
c^{*(0)}_{rp}c^{(1)}_{sq})\langle\chi_{r}|\chi_{s}\rangle &= 0
\Rightarrow\nonumber \\
C^{+(1)}_{p}SC^{(0)}_{q} + C^{+(0)}_{p}SC^{(1)}_{q} &= 0
\end{align}
However, since that in the (\ref{PTIMQMeq:34}) we have ``drop'' the
overlap matrix by multiplying some unitary matrix; that means we
have:
\begin{equation}\label{}
C^{'}_{q} = UC_{q} \quad U^{+}SU = I \Rightarrow
C^{+(1)'}_{p}SC^{(0)'}_{q} = C^{+(1)}_{p}U^{+}SUC^{(0)}_{q} =
C^{+(1)}_{p}C^{(0)}_{q}
\end{equation}
Therefore the (\ref{PTIMQMeq:33}) can be transformed as:
\begin{equation}\label{PTIMQMeq:35}
C^{+(1)}_{p}C^{(0)}_{q} + C^{+(0)}_{p}C^{(1)}_{q} = 0
\end{equation}

Now let's consider the expectation value for an single electron
operator of $\hat{A}$. Based on the perturbed molecular orbital
expression, the expectation value is:
\begin{equation}\label{}
\sum_{i=1}^{n}\langle\varphi_{i}|\hat{A}|\varphi_{i}\rangle =
\sum_{i=1}^{n}\langle\varphi^{(0)}_{i}|\hat{A}|\varphi^{(0)}_{i}\rangle
+ \lambda\sum_{i=1}^{n}\Bigg\{
\langle\varphi^{(1)}_{i}|\hat{A}|\varphi^{(0)}_{i}\rangle +
\langle\varphi^{(0)}_{i}|\hat{A}|\varphi^{(1)}_{i}\rangle \Bigg\}
\end{equation}
Here we suggest there's $n$ occupied orbitals and totally $m$ basis
sets. The expectation is going over all the occupied orbitals. The
expectation value for the $\hat{A}$ is approximated at the first
order.

On the other hand, we can expand the expectation value also in the
progressive order:
\begin{equation}\label{}
\langle A \rangle = \langle A \rangle^{(0)} + \lambda\langle A
\rangle^{(1)} + \cdots
\end{equation}
Obviously the zero order approximation is:
\begin{equation}\label{}
\langle A \rangle^{(0)} =
\sum_{i=1}^{n}\langle\varphi^{(0)}_{i}|\hat{A}|\varphi^{(0)}_{i}\rangle
\end{equation}
And the first order approximation is:
\begin{equation}\label{}
\langle A \rangle^{(1)} = \sum_{i=1}^{n}\Bigg\{
\langle\varphi^{(1)}_{i}|\hat{A}|\varphi^{(0)}_{i}\rangle +
\langle\varphi^{(0)}_{i}|\hat{A}|\varphi^{(1)}_{i}\rangle \Bigg\}
\end{equation}

Now let's further evaluate the first order approximation. By taking
the basis sets into the equation above, it transforms into:
\begin{align}\label{}
\langle A \rangle^{}(1) &= \sum_{i=1}^{n}c^{*(1)}_{ki}c^{(0)}_{ji}
\end{align}

Now it comes up with a question that how to express the relations
for the perturbed orbitals in terms of the basis sets functions?

By taking the expansion of (\ref{PTIMQMeq:23}) into the above
relation, we have:
\begin{equation}\label{}
\sum_{p}c^{*(1)}_{pi}\langle\varphi^{(0)}_{p}|\varphi^{(0)}_{j}\rangle
+
\sum_{q}c^{(1)}_{qj}\langle\varphi^{(0)}_{i}|\varphi^{(0)}_{q}\rangle
= 0
\end{equation}
Since that the unperturbed orbitals satisfy the orthogonal relation,
thus $\langle\varphi^{(0)}_{p}|\varphi^{(0)}_{q}\rangle =
\delta_{pq}$. Hence we have:
\begin{equation}\label{PTIMQMeq:28}
c^{*(1)}_{ji} + c^{(1)}_{ij} = 0
\end{equation}
Generally if $i=j$, then $c^{*(1)}_{ii} + c^{(1)}_{ii} = 0$; that
means the $c^{(1)}_{ii}$ is some imaginary number so that it can be
safely set to $0$.

Now let's go to see how to use the conclusion in (\ref{PTIMQMeq:28})
to get the further information about the density. In the
perturbation treatment, the density can be expressed as:
\begin{equation}\label{}
\rho = \rho^{(0)} + \lambda\rho^{(1)} +\lambda^{2}\rho^{(2)} +
\cdots
\end{equation}
For the orbitals approximated at the first order, according to the
 (\ref{PTIMQMeq:26}) we can express it as:
\begin{align}\label{}
\varphi_{i} &= \varphi^{(0)}_{i} +
\lambda\sum_{p}c^{(1)}_{pi}\varphi^{(0)}_{p} \nonumber \\
\varphi^{*}_{i} &= \varphi^{*(0)}_{i} +
\lambda\sum_{q}c^{*(1)}_{qi}\varphi^{*(0)}_{q}
\end{align}
Then the electron density can be expressed as (suggest that there
are $m$ orbitals, each one is occupied with one electron; the others
are virtual orbitals):
\begin{align}\label{}
\rho &= \rho^{(0)} + \lambda\rho^{(1)} \Rightarrow \nonumber \\
\sum_{i=1}^{m}\varphi^{*}_{i}\varphi_{i}d\tau &=
\sum_{i=1}^{m}\varphi^{*(0)}_{i}\varphi^{(0)}_{i}d\tau + \nonumber \\
&\lambda\Bigg\{\sum_{i=1}^{m}\sum_{p}c^{(1)}_{pi}
\varphi^{*(0)}_{i}\varphi^{(0)}_{p}d\tau  +
\sum_{i=1}^{m}\sum_{q}c^{*(1)}_{qi}
\varphi^{*(0)}_{q}\varphi^{(0)}_{i}d\tau \Bigg\}
\end{align}

Here it's known that the unperturbed density $\rho^{(0)}$ is:
\begin{equation}\label{}
\rho^{(0)} = \sum_{i=1}^{m}\varphi^{*(0)}_{i}\varphi^{(0)}_{i}d\tau
\end{equation}
Therefore the first perturbed density $\rho^{(1)}$ is:
\begin{equation}\label{PTIMQMeq:29}
\rho^{(1)} = \sum_{i=1}^{m}\sum_{p}c^{(1)}_{pi}
\varphi^{*(0)}_{i}\varphi^{(0)}_{p}d\tau  +
\sum_{i=1}^{m}\sum_{q}c^{*(1)}_{qi}
\varphi^{*(0)}_{q}\varphi^{(0)}_{i}d\tau
\end{equation}
Here the label of $i$ goes over all the occupied orbitals, and the
label of $p$, $q$ go over all the orbitals (occupied type as well as
the virtual orbitals).

Now by using the relation in the (\ref{PTIMQMeq:28}), we can further
simplify the expression for the $\rho^{(1)}$. By dividing the sum in
(\ref{PTIMQMeq:29}) into the occupied type and occupied-virtual
type; we can have (suggesting that there are $n$ basis sets so that
totally $n$ orbitals generated in the Hatree-Fock equation):
\begin{multline}\label{}
\rho^{(1)} = \sum_{i=1}^{m}\sum_{j=1}^{m}c^{(1)}_{ji}
\varphi^{*(0)}_{i}\varphi^{(0)}_{j}d\tau +
\sum_{i=1}^{m}\sum_{a=m+1}^{n}c^{(1)}_{ai}
\varphi^{*(0)}_{i}\varphi^{(0)}_{a}d\tau  + \\
\sum_{i=1}^{m}\sum_{j=1}^{m}c^{*(1)}_{ji}
\varphi^{*(0)}_{j}\varphi^{(0)}_{i}d\tau +
\sum_{i=1}^{m}\sum_{a=m+1}^{n}c^{*(1)}_{ai}
\varphi^{*(0)}_{a}\varphi^{(0)}_{i}d\tau
\end{multline}

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

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


\chapter{Implementation Issues}

The following section is provided as a discussion on various aspects of the practical implementation of the \textit{libsafecrypto} library.

\section{Random Number Generation}

The first issue is to understand that a practical secure system cannot obtain true random numbers for cryptographic purposes, particularly with high bandwidth. Therefore a compromise must be obtained using PRNG's that are initialised using a random source. Note that it is also desirable to allow these PRNG's to be initialised in a repeatable manner for test and debug purposes only, but such functionality should NOT be allowed in a production system.

\subsection{Acceptable Random Functions}

As the C Standard \textit{rand()} function makes no guarantees regarding the quality of the random sequences it produces (see SEI CERT MSC30-C or SAFECrypto Coding Rule I.17) it should not be used for secure coding applications. If used it could provide weaknesses due to short cycles and predictability of the number sequence.

On a POSIX system a true entropy source such as \textit{/dev/random} can be used for the creation of strong cryptographic keys. An issue with this as a source of random numbers is speed, particularly as the \textit{/dev/random} device can block if there are insufficient events occuring to drive the generation of random numbers. Therefore such a source of random numbers should be used sparingly, particularly in a server application where it can not guarantee performance.

Therefore in a practical security application it is common to segregate the generation of random numbers into a slow/strong source of entropy and a fast source of entropy that relies upon an algorithm to produce a secure pseudorandom sequence. This fast source of entropy is then initialised using the slow/strong entropy source. A range of random number generators have been developed for cryptographic purposes known as cryptographically secure pseudo random number generator's (CSPRNG's). These CSPRNG's have been developed for the purposes of security applications and as such have been heavily analysed for their suitability and standardized by bodies such as NIST and ANSI.

On a POSIX system the \textit{random()} function can be used as a C standard means of generating a pseudorandom number sequence. However, it should not be used in cryptographic applications, contrary to the examples provided by the SEI CERT Secure Coding Standard in which \textit{random()} is described as a compliant solution. Instead a suitable CSPRNG algorithm should be used such as ChaCha20-CSPRNG or AES CTR\_DRBG (NIST SP 800-90A Rev.1).

\textbf{\textit{NOTE: It would be better if the SAFEcrypto PRNG function allowed an arbitrary number of bits to be extracted. Some of the explanations I've read about random() etc. say that the least significant bits can be periodic, so if you need 4 random bits and keep calling prng\_32() maybe that could be an issue? It would also be more efficient to use all the bits that are generated when using expensive CSPRNG's etc.}}

\subsection{Seeding}

The SEI CERT C Secure Coding Standards have some important recommendations for seeding a random number generator (see MSC32-C or SAFEcrypto Coding Rule C.11). Their compliant POSIX solution is to seed the \textit{random()} function using the current time, but to ensure that current time is scrambled using an XOR of the second and nanosecond variables. If the time is not scrambled it is possible for an attacker to guess the low resolution components of the date (e.g. year, month) and reduce the effort required in a brute force attack.

Alternatively a strong entropy source such as \textit{/dev/random} can be used provided that the seeding operation is not used in a time critical application.

\textbf{\textit{NOTE: In the current SAFEcrypto PRNG the above seeding is currently disabled as it did not work on C90/gnu90 compilers. It currently initialises using time\_t result = time(NULL) - this has got to go! Autotools has since been reconfigured to enforce and create the correct switches for C99/GNU99 compliance, so the SEI recommended method will be used again once I've finished typing this sentence...!}}

\textbf{\textit{NOTE: I'm going to add /dev/random and/or /dev/urandom support to the SAFEcrypto PRNG as an option alongside the SEI CERT seeding method.}}

\section{Scalability}

[Blabber on about vectorisation, making use of 64-bit and 128-bit, falling back to 32-bit as the minimum processor width on low power/resource CPU's]

\section{Adaptive Processing}

[Dynamic choice of coding tools based on system performance and application (e.g. on a stressed server temporarily switch to faster crypto coding tools such as disabling blinding to countermeasure side-channel attacks, more efficient but less statistically good samplers/PRNGs)]

\section{Multithreading}

[Implications of multiple threads on RNG, using worker threads to provide random numbers or vectors with gaussian distribution as background tasks, accelerating schemes using producer/consumer pipes with threadpools, impact on side-channel attacks when multithreading, ]


\documentclass[12pt]{amsart}
\usepackage{geometry} % see geometry.pdf on how to lay out the page. There's lots.
\usepackage{bsymb}
\usepackage{unitb}
\usepackage{calculational}
\usepackage{ulem}
\normalem
\geometry{a4paper} % or letter or a5paper or ... etc
% \geometry{landscape} % rotated page geometry

% See the ``Article customise'' template for some common customisations

\title{}
\author{}
\date{} % delete this line to display the current date

%%% BEGIN DOCUMENT
\begin{document}

\maketitle
\tableofcontents

%\section{}
%\subsection{}

\begin{machine}{train0}

\newset{\TRAIN}
\newset{\BLK}
%\newset{\LOC}
\newset{\LOC}
%\end{set}

%
%\hide{
	\begin{align*}
\variable{		in : \set[\TRAIN]}
	\end{align*}
%}
%

\newevent{enter}

\newevent{leave}

\begin{align*}
\transientB{leave}{tr0}
{ \index{t}{t' = t} }
{	t \in in	}
\end{align*}
\begin{align*}
\dummy{	t,t0,t1,t2,t3 : \TRAIN}
\end{align*}

\begin{align*}
\dummy{	p,q : \BLK}
\end{align*}

\begin{align*}
\variable{	loc : \TRAIN \pfun \BLK}
\end{align*}

\begin{align*}
\invariant{inv2}
%	loc \in in \fun \BLK
{	\dom . loc = in	}
\end{align*}

\begin{align*}
\evassignment{enter}{a1}
{	in' = in \bunion \{ t \}	}
\end{align*}

\begin{proof}{enter/INV/inv2}
	\begin{calculation}
		in'
	\hint{=}{ \ref{a1} }
		in \bunion \{ t \}
	\hint{=}{ \ref{inv2} }
		\dom.loc \bunion \{ t \}
	\hint{=}{ function calculus }
		\dom.loc \bunion \dom.(t \fun ent)
	\hint{=}{ $\dom$ over $|$ }
		\dom.(loc   |   t \fun ent)
	\hint{=}{ \ref{a2} }
		\dom. ( loc' )
	\end{calculation}
\end{proof}

\begin{align*}
\evassignment{enter}{a2}
{	loc' = loc | (t \fun ent)	}
\end{align*}

\begin{proof}{leave/INV/inv2}
	\begin{calculation}
		in'
	\hint{=}{ \ref{a0} }
		in \setminus \{ t \}
	\hint{=}{ \ref{inv2} }
		\dom.loc \setminus \{ t \}
	\hint{=}{ domain of domain subtraction }
		\dom.(\{ t \} \domsub loc)
	\hint{=}{ \ref{a3} }
		\dom. loc'
	\end{calculation}
\end{proof}

\begin{align*}
\evassignment{leave}{a3}
{	loc' = \{ t \} \domsub loc 	}
\end{align*}

\begin{align*}
\cschedule{leave}{c0}
{	t \in in	}
\end{align*}

\begin{align*}
\initialization{in0}
{	in = \emptyset	}
\end{align*}
\begin{align*}
\initialization{in1}
{	loc = \emptyfun	}
\end{align*}

% \with{sets}
\with{sets}
% \with{sets}
\with{functions}
%\with{functions}

\begin{align*}
\indices{leave}{	t: \TRAIN}
\end{align*}

\begin{align*}
\indices{enter}{	t: \TRAIN}
\end{align*}

\begin{align*}
\evassignment{leave}{a0}
%	in' = in | (t \rightarrow \false)
{	in' = in \setminus \{ t \}	}
%	in'.t = \false
\end{align*}

\begin{align*}
\constant{	ent,ext : \BLK}
\end{align*}
\begin{align*}
\constant{	PLF : \set [\BLK]}
\end{align*}

\begin{align*}\assumption{axm0}
{	\BLK = \{ ent, ext \} \bunion PLF }
\end{align*}

\safety{s0}{ \neg t \in in }{ t \in in \land loc.t = ent }
\safety{s1}{ t \in in \land loc.t = ent }{ t \in in \land loc.t \in PLF }
%
\begin{align*}
\constraint{co0}
{	\neg t \in in \land t \in in' \implies  loc'.t = ent } % \lor \neg t \in in'
\end{align*}
%
\begin{proof}{leave/CO/co0}
	\begin{free:var}{t}{t0}
	\begin{calculation}
		\neg t0 \in in \land t0 \in in'
	\hint{=}{ \ref{grd0} }
		\neg t0 = t \land \neg t0 \in in \land t0 \in in'
	\hint{=}{ \ref{a0} }
		\neg t0 = t \land \neg t0 \in in \land t0 \in in \bunion \{ t \}
%	\hint{=}{ $\in$ over singleton }
%		\neg t0 = t \land \neg t0 \in in \land t0 \in in
	\hint{=}{ contradiction }
		\false
	\hint{\implies}{ $\false \implies p$ }
		loc'.t0 = ent
	\end{calculation}
	\end{free:var}
\end{proof}
%
\begin{align*}
\constraint{co1}
{	 t \in in \land loc.t = ent  \land \neg loc.t \in PLF
\implies t \in in' \land (loc'.t \in PLF \lor loc'.t = ent)	}
\end{align*}

\discharge{s0}{co0}
\discharge{s1}{co1}

% test the error message for
%\begin{guard}{co0}
%
%\end{guard}

\begin{align*}
\evguard{leave}{grd0}
{	loc.t = ext \land t \in in	}
\end{align*}

\begin{align*}
\evguard{enter}{grd1}
{	\neg t \in in	}
\end{align*}

\begin{proof}{enter/CO/co0}
	% assume
	% forall
	% case
	% split
	% TODO: add a case distinction that isn't complete
	\begin{free:var}{t}{t0}

	\begin{by:cases}
	\begin{case}{h0}{t0 = t}
	\begin{calculation}
		\neg t0 \in in \land t0 \in in' \implies  loc'.t0 = ent
	\hint{=}{ \eqref{h0} \ref{a1}  }
		\neg t \in in \implies  loc'.t = ent
	\hint{=}{ \ref{a2} }
		\true
%		\qforall{t0}{\neg t0 \in in}{ t0 \in in' \implies  loc'.t0 = ent }
%	\hint{=}{  }
%		\qforall{t0}{\neg t0 \in in \land (t0 = t \lor \neg  t0 = t)}{ t0 \in in' \implies  loc'.t0 = ent }
%	\hint{=}{ }
%		\qforall{t0}{\neg t0 \in in \land t0 = t}{ t0 \in in' \implies  loc'.t0 = ent }
%	\land	\qforall{t0}{\neg t0 \in in \land \neg  t0 = t}{ t0 \in in' \implies  loc'.t0 = ent }
%	\hint{=}{ }
%		(\neg t \in in \land t \in in' \implies  loc'.t = ent )
%	\land	\qforall{t0}{\neg t0 \in in \land \neg  t0 = t}{ t0 \in in' \implies  loc'.t0 = ent }
%	\hint{=}{ \ref{a1} and \ref{a2} }
%		(\neg t \in in \land t \in in \bunion \{ t \} \implies  (loc | t \fun ent).t = ent )
%	\hint{=}{  }
%		\neg t \in in \implies  (loc | t \fun ent).t = ent
%	\hint{=}{  }
%		\neg t \in in \implies  (t \fun ent).t = ent
%	\hint{=}{  }
%		\neg t \in in \implies  ent = ent
%	\hint{=}{  }
%		\true
	\end{calculation}
	\end{case}
	\end{by:cases}
	\end{free:var}
\end{proof}

\begin{proof}{leave/CO/co1}
	\begin{free:var}{t}{t0}
	\begin{calculation}
		t0 \in in' \land (loc'.t0 \in PLF \lor loc'.t0 = ent)
	\hint{=}{  \ref{a0}  and \ref{a3} } % step 1
		t0 \in in \setminus \{ t \}
		\land ( (\{ t \} \domsub loc).t0 \in PLF \lor (\{ t \} \domsub loc).t0 = ent)
	\hint{=}{ }	% step 2
		( t0 \in in \setminus \{ t \}
		\land  ( \{ t \} \domsub loc).t0 \in PLF )
			   \lor ( t0 \in (in \setminus \{ t \} )
		\land (\{ t \} \domsub loc).t0 = ent)
	\hint{=}{ \ref{inv2} }	% step 3
			t0 \in in \setminus \{ t \}
		\land ( loc.t0 \in PLF \lor  loc.t0 = ent)
	\hint{=}{ } % step 4
		t0 \in in \land \neg t0  = t
		\land ( loc.t0 \in PLF \lor  loc.t0 = ent)
	\hint{=}{ \ref{asm2}, \ref{asm4}, \ref{asm3} } % step 5
		t0 \in in \land \neg t0  = t \land \neg loc.t0 = ext
	\hint{=}{  \ref{grd0} } % step 6
	 	t0 \in in \land \neg loc.t0 = ext \land loc.t = ext
	\hint{\follows}{  \ref{grd0}, \ref{asm2} } % step 7
%		\true
	 	t0 \in in \land loc.t0 = ent
	\hint{=}{ \ref{asm2}  } % step 8
	 	t0 \in in \land loc.t0 = ent  \land \neg loc.t0 \in PLF
	\end{calculation}
	\end{free:var}
\end{proof}

\begin{align*}
\invariant{inv1}
{	\qforall{t}{t \in in}{loc.t \in \BLK}	}
\end{align*}

\begin{align*}
\assumption{asm2}
{	\neg ent = ext \land \neg ent \in PLF \land \neg ext \in PLF	}
\end{align*}

\begin{align*}
\assumption{asm3}
{	\qforall{p}{}{ \neg p = ext \equiv p \in \{ent\} \bunion PLF }}
\end{align*}

\begin{align*}
\assumption{asm4}
{	\qforall{p}{}{ \neg p = ent \equiv p \in \{ext\} \bunion PLF }	}
\end{align*}

\begin{align*}
\assumption{asm5}
{	\qforall{p}{}{ p = ent \lor p = ext \equiv \neg p \in PLF }	}
\end{align*}

% \removecoarse{leave}{default} % \weakento{leave}{default}{c0}

\end{machine}

\end{document}