# Second Quantization

 **Morten Hjorth-Jensen**, [National Superconducting Cyclotron Laboratory](http://www.nscl.msu.edu/) and [Department of Physics and Astronomy](https://www.pa.msu.edu/), [Michigan State University](http://www.msu.edu/), East Lansing, MI 48824, USA and Department of Physics, University of Oslo, N-0316 Oslo, Norway

Date: **28th Indian-Summer School on Ab Initio Methods in Nuclear Physics**

## Second quantization

**Second quantization.**

* Second quantization and operators, two-body operator with examples

* Wick's theorem

* Thouless' theorem and analysis of the Hartree-Fock equations using second quantization

* Examples on how to use bit representations for Slater determinants

## Second quantization
We introduce the time-independent  operators
$a_\alpha^{\dagger}$ and $a_\alpha$   which create and annihilate, respectively, a particle
in the single-particle state
$\varphi_\alpha$.
We define the fermion creation operator
$a_\alpha^{\dagger}$

$$
\begin{equation}
	a_\alpha^{\dagger}|0\rangle \equiv  |\alpha\rangle  \label{eq:2-1a} \tag{1},
\end{equation}
$$

and

$$
\begin{equation}
	a_\alpha^{\dagger}|\alpha_1\dots \alpha_n\rangle_{\mathrm{AS}} \equiv  |\alpha\alpha_1\dots \alpha_n\rangle_{\mathrm{AS}} \label{eq:2-1b} \tag{2}
\end{equation}
$$

## Second quantization
In Eq. ([eq:2-1a](#eq:2-1a))
the operator  $a_\alpha^{\dagger}$  acts on the vacuum state
$|0\rangle$, which does not contain any particles. Alternatively, we could define  a closed-shell nucleus or atom as our new vacuum, but then
we need to introduce the particle-hole  formalism, see the discussion to come.

In Eq. ([eq:2-1b](#eq:2-1b)) $a_\alpha^{\dagger}$ acts on an antisymmetric $n$-particle state and
creates an antisymmetric $(n+1)$-particle state, where the one-body state
$\varphi_\alpha$ is occupied, under the condition that
$\alpha \ne \alpha_1, \alpha_2, \dots, \alpha_n$.
It follows that we can express an antisymmetric state as the product of the creation
operators acting on the vacuum state.

$$
\begin{equation}
	|\alpha_1\dots \alpha_n\rangle_{\mathrm{AS}} = a_{\alpha_1}^{\dagger} a_{\alpha_2}^{\dagger} \dots a_{\alpha_n}^{\dagger} |0\rangle \label{eq:2-2} \tag{3}
\end{equation}
$$

## Second quantization
It is easy to derive the commutation and anticommutation rules  for the fermionic creation operators
$a_\alpha^{\dagger}$. Using the antisymmetry of the states
([eq:2-2](#eq:2-2))

$$
\begin{equation}
	|\alpha_1\dots \alpha_i\dots \alpha_k\dots \alpha_n\rangle_{\mathrm{AS}} =
		- |\alpha_1\dots \alpha_k\dots \alpha_i\dots \alpha_n\rangle_{\mathrm{AS}} \label{eq:2-3a} \tag{4}
\end{equation}
$$

we obtain

$$
\begin{equation}
	 a_{\alpha_i}^{\dagger}  a_{\alpha_k}^{\dagger} = - a_{\alpha_k}^{\dagger} a_{\alpha_i}^{\dagger} \label{eq:2-3b} \tag{5}
\end{equation}
$$

## Second quantization
Using the Pauli principle

$$
\begin{equation}
	|\alpha_1\dots \alpha_i\dots \alpha_i\dots \alpha_n\rangle_{\mathrm{AS}} = 0 \label{eq:2-4a} \tag{6}
\end{equation}
$$

it follows that

$$
\begin{equation}
	a_{\alpha_i}^{\dagger}  a_{\alpha_i}^{\dagger} = 0. \label{eq:2-4b} \tag{7}
\end{equation}
$$

If we combine Eqs. ([eq:2-3b](#eq:2-3b)) and ([eq:2-4b](#eq:2-4b)), we obtain the well-known anti-commutation rule

$$
\begin{equation}
	a_{\alpha}^{\dagger}  a_{\beta}^{\dagger} + a_{\beta}^{\dagger}  a_{\alpha}^{\dagger} \equiv
		\{a_{\alpha}^{\dagger},a_{\beta}^{\dagger}\} = 0 \label{eq:2-5} \tag{8}
\end{equation}
$$

## Second quantization
The hermitian conjugate  of $a_\alpha^{\dagger}$ is

$$
\begin{equation}
	a_{\alpha} = ( a_{\alpha}^{\dagger} )^{\dagger} \label{eq:2-6} \tag{9}
\end{equation}
$$

If we take the hermitian conjugate of Eq. ([eq:2-5](#eq:2-5)), we arrive at

$$
\begin{equation}
	\{a_{\alpha},a_{\beta}\} = 0 \label{eq:2-7} \tag{10}
\end{equation}
$$

## Second quantization
What is the physical interpretation of the operator $a_\alpha$ and what is the effect of
$a_\alpha$ on a given state $|\alpha_1\alpha_2\dots\alpha_n\rangle_{\mathrm{AS}}$?
Consider the following matrix element

$$
\begin{equation}
	\langle\alpha_1\alpha_2 \dots \alpha_n|a_\alpha|\alpha_1'\alpha_2' \dots \alpha_m'\rangle \label{eq:2-8} \tag{11}
\end{equation}
$$

where both sides are antisymmetric. We  distinguish between two cases. The first (1) is when
$\alpha \in \{\alpha_i\}$. Using the Pauli principle of Eq. ([eq:2-4a](#eq:2-4a)) it follows

$$
\begin{equation}
		\langle\alpha_1\alpha_2 \dots \alpha_n|a_\alpha = 0 \label{eq:2-9a} \tag{12}
\end{equation}
$$

The second (2) case is when $\alpha \notin \{\alpha_i\}$. It follows that an hermitian conjugation

$$
\begin{equation}
		\langle \alpha_1\alpha_2 \dots \alpha_n|a_\alpha = \langle\alpha\alpha_1\alpha_2 \dots \alpha_n|  \label{eq:2-9b} \tag{13}
\end{equation}
$$

## Second quantization
Eq. ([eq:2-9b](#eq:2-9b)) holds for case (1) since the lefthand side is zero due to the Pauli principle. We write
Eq. ([eq:2-8](#eq:2-8)) as

$$
\begin{equation}
	\langle\alpha_1\alpha_2 \dots \alpha_n|a_\alpha|\alpha_1'\alpha_2' \dots \alpha_m'\rangle =
	\langle \alpha_1\alpha_2 \dots \alpha_n|\alpha\alpha_1'\alpha_2' \dots \alpha_m'\rangle \label{eq:2-10} \tag{14}
\end{equation}
$$

Here we must have $m = n+1$ if Eq. ([eq:2-10](#eq:2-10)) has to be trivially different from zero.

## Second quantization
For the last case, the minus and plus signs apply when the sequence
$\alpha ,\alpha_1, \alpha_2, \dots, \alpha_n$ and
$\alpha_1', \alpha_2', \dots, \alpha_{n+1}'$ are related to each other via even and odd permutations.
If we assume that  $\alpha \notin \{\alpha_i\}$ we obtain

$$
\begin{equation}
	\langle\alpha_1\alpha_2 \dots \alpha_n|a_\alpha|\alpha_1'\alpha_2' \dots \alpha_{n+1}'\rangle = 0 \label{eq:2-12} \tag{15}
\end{equation}
$$

when $\alpha \in \{\alpha_i'\}$. If $\alpha \notin \{\alpha_i'\}$, we obtain

$$
\begin{equation}
	a_\alpha\underbrace{|\alpha_1'\alpha_2' \dots \alpha_{n+1}'}\rangle_{\neq \alpha} = 0 \label{eq:2-13a} \tag{16}
\end{equation}
$$

and in particular

$$
\begin{equation}
	a_\alpha |0\rangle = 0 \label{eq:2-13b} \tag{17}
\end{equation}
$$

## Second quantization
If $\{\alpha\alpha_i\} = \{\alpha_i'\}$, performing the right permutations, the sequence
$\alpha ,\alpha_1, \alpha_2, \dots, \alpha_n$ is identical with the sequence
$\alpha_1', \alpha_2', \dots, \alpha_{n+1}'$. This results in

$$
\begin{equation}
	\langle\alpha_1\alpha_2 \dots \alpha_n|a_\alpha|\alpha\alpha_1\alpha_2 \dots \alpha_{n}\rangle = 1 \label{eq:2-14} \tag{18}
\end{equation}
$$

and thus

$$
\begin{equation}
	a_\alpha |\alpha\alpha_1\alpha_2 \dots \alpha_{n}\rangle = |\alpha_1\alpha_2 \dots \alpha_{n}\rangle \label{eq:2-15} \tag{19}
\end{equation}
$$

## Second quantization
The action of the operator
$a_\alpha$ from the left on a state vector  is to  remove  one particle in the state
$\alpha$.
If the state vector does not contain the single-particle state $\alpha$, the outcome of the operation is zero.
The operator  $a_\alpha$ is normally called for a destruction or annihilation operator.

The next step is to establish the  commutator algebra of $a_\alpha^{\dagger}$ and
$a_\beta$.

## Second quantization
The action of the anti-commutator
$\{a_\alpha^{\dagger}$,$a_\alpha\}$ on a given $n$-particle state is

$$
a_\alpha^{\dagger} a_\alpha \underbrace{|\alpha_1\alpha_2 \dots \alpha_{n}\rangle}_{\neq \alpha} = 0 \nonumber
$$

$$
\begin{equation}
	a_\alpha a_\alpha^{\dagger} \underbrace{|\alpha_1\alpha_2 \dots \alpha_{n}\rangle}_{\neq \alpha} =
	a_\alpha \underbrace{|\alpha \alpha_1\alpha_2 \dots \alpha_{n}\rangle}_{\neq \alpha} =
	\underbrace{|\alpha_1\alpha_2 \dots \alpha_{n}\rangle}_{\neq \alpha} \label{eq:2-16a} \tag{20}
\end{equation}
$$

if the single-particle state $\alpha$ is not contained in the state.

## Second quantization
 If it is present
we arrive at

$$
a_\alpha^{\dagger} a_\alpha |\alpha_1\alpha_2 \dots \alpha_{k}\alpha \alpha_{k+1} \dots \alpha_{n-1}\rangle =
	a_\alpha^{\dagger} a_\alpha (-1)^k |\alpha \alpha_1\alpha_2 \dots \alpha_{n-1}\rangle \nonumber
$$

$$
= (-1)^k |\alpha \alpha_1\alpha_2 \dots \alpha_{n-1}\rangle =
	|\alpha_1\alpha_2 \dots \alpha_{k}\alpha \alpha_{k+1} \dots \alpha_{n-1}\rangle \nonumber
$$

$$
\begin{equation}
	a_\alpha a_\alpha^{\dagger}|\alpha_1\alpha_2 \dots \alpha_{k}\alpha \alpha_{k+1} \dots \alpha_{n-1}\rangle = 0 \label{eq:2-16b} \tag{21}
\end{equation}
$$

From Eqs. ([eq:2-16a](#eq:2-16a)) and  ([eq:2-16b](#eq:2-16b)) we arrive at

$$
\begin{equation}
	\{a_\alpha^{\dagger} , a_\alpha \} = a_\alpha^{\dagger} a_\alpha + a_\alpha a_\alpha^{\dagger} = 1 \label{eq:2-17} \tag{22}
\end{equation}
$$

## Second quantization
The action of $\left\{a_\alpha^{\dagger}, a_\beta\right\}$, with
$\alpha \ne \beta$ on a given state yields three possibilities.
The first case is a state vector which contains both $\alpha$ and $\beta$, then either
$\alpha$ or $\beta$ and finally none of them.

## Second quantization
The first case results in

$$
\begin{eqnarray}
	a_\alpha^{\dagger} a_\beta |\alpha\beta\alpha_1\alpha_2 \dots \alpha_{n-2}\rangle = 0 \nonumber \\
	a_\beta a_\alpha^{\dagger} |\alpha\beta\alpha_1\alpha_2 \dots \alpha_{n-2}\rangle = 0 \label{eq:2-18a} \tag{23}
\end{eqnarray}
$$

while the second case gives

$$
\begin{eqnarray}
	 a_\alpha^{\dagger} a_\beta |\beta \underbrace{\alpha_1\alpha_2 \dots \alpha_{n-1}}_{\neq \alpha}\rangle &=&
	 	|\alpha \underbrace{\alpha_1\alpha_2 \dots \alpha_{n-1}}_{\neq  \alpha}\rangle \nonumber \\
	a_\beta a_\alpha^{\dagger} |\beta \underbrace{\alpha_1\alpha_2 \dots \alpha_{n-1}}_{\neq \alpha}\rangle &=&
		a_\beta |\alpha\underbrace{\beta \alpha_1\alpha_2 \dots \alpha_{n-1}}_{\neq \alpha}\rangle \nonumber \\
	&=& - |\alpha\underbrace{\alpha_1\alpha_2 \dots \alpha_{n-1}}_{\neq \alpha}\rangle \label{eq:2-18b} \tag{24}
\end{eqnarray}
$$

## Second quantization
Finally if the state vector does not contain $\alpha$ and $\beta$

$$
\begin{eqnarray}
	a_\alpha^{\dagger} a_\beta |\underbrace{\alpha_1\alpha_2 \dots \alpha_{n}}_{\neq \alpha,\beta}\rangle &=& 0 \nonumber \\
	a_\beta a_\alpha^{\dagger} |\underbrace{\alpha_1\alpha_2 \dots \alpha_{n}}_{\neq \alpha,\beta}\rangle &=&
		a_\beta |\alpha \underbrace{\alpha_1\alpha_2 \dots \alpha_{n}}_{\neq \alpha,\beta}\rangle = 0 \label{eq:2-18c} \tag{25}
\end{eqnarray}
$$

For all three cases we have

$$
\begin{equation}
	\{a_\alpha^{\dagger},a_\beta \} = a_\alpha^{\dagger} a_\beta + a_\beta a_\alpha^{\dagger} = 0, \quad \alpha \neq \beta \label{eq:2-19} \tag{26}
\end{equation}
$$

## Second quantization
We can summarize  our findings in Eqs. ([eq:2-17](#eq:2-17)) and ([eq:2-19](#eq:2-19)) as

$$
\begin{equation}
	\{a_\alpha^{\dagger},a_\beta \} = \delta_{\alpha\beta} \label{eq:2-20} \tag{27}
\end{equation}
$$

with  $\delta_{\alpha\beta}$ is the Kronecker $\delta$-symbol.

The properties of the creation and annihilation operators can be summarized as (for fermions)

$$
a_\alpha^{\dagger}|0\rangle \equiv  |\alpha\rangle,
$$

and

$$
a_\alpha^{\dagger}|\alpha_1\dots \alpha_n\rangle_{\mathrm{AS}} \equiv  |\alpha\alpha_1\dots \alpha_n\rangle_{\mathrm{AS}}.
$$

from which follows

$$
|\alpha_1\dots \alpha_n\rangle_{\mathrm{AS}} = a_{\alpha_1}^{\dagger} a_{\alpha_2}^{\dagger} \dots a_{\alpha_n}^{\dagger} |0\rangle.
$$

## Second quantization
The hermitian conjugate has the folowing properties

$$
a_{\alpha} = ( a_{\alpha}^{\dagger} )^{\dagger}.
$$

Finally we found

$$
a_\alpha\underbrace{|\alpha_1'\alpha_2' \dots \alpha_{n+1}'}\rangle_{\neq \alpha} = 0, \quad
		\textrm{in particular } a_\alpha |0\rangle = 0,
$$

and

$$
a_\alpha |\alpha\alpha_1\alpha_2 \dots \alpha_{n}\rangle = |\alpha_1\alpha_2 \dots \alpha_{n}\rangle,
$$

and the corresponding commutator algebra

$$
\{a_{\alpha}^{\dagger},a_{\beta}^{\dagger}\} = \{a_{\alpha},a_{\beta}\} = 0 \hspace{0.5cm}
\{a_\alpha^{\dagger},a_\beta \} = \delta_{\alpha\beta}.
$$

## Second quantization
A very useful operator is the so-called number-operator.  Most physics cases  we will
study in this text conserve the total number of particles.  The number operator is therefore
a useful quantity which allows us to test that our many-body formalism  conserves the number of particles.
In for example $(d,p)$ or $(p,d)$ reactions it is important to be able to describe quantum mechanical states
where particles get added or removed.
A creation operator $a_\alpha^{\dagger}$ adds one particle to the single-particle state
$\alpha$ of a give many-body state vector, while an annihilation operator $a_\alpha$
removes a particle from a single-particle
state $\alpha$.

## Second quantization
Let us consider an operator proportional with $a_\alpha^{\dagger} a_\beta$ and
$\alpha=\beta$. It acts on an $n$-particle state
resulting in

$$
\begin{equation}
	a_\alpha^{\dagger} a_\alpha |\alpha_1\alpha_2 \dots \alpha_{n}\rangle =
	\begin{cases}
		0  &\alpha \notin \{\alpha_i\} \\
		\\
		|\alpha_1\alpha_2 \dots \alpha_{n}\rangle & \alpha \in \{\alpha_i\}
	\end{cases}
\label{_auto1} \tag{28}
\end{equation}
$$

Summing over all possible one-particle states we arrive at

$$
\begin{equation}
	\left( \sum_\alpha a_\alpha^{\dagger} a_\alpha \right) |\alpha_1\alpha_2 \dots \alpha_{n}\rangle =
	n |\alpha_1\alpha_2 \dots \alpha_{n}\rangle \label{eq:2-21} \tag{29}
\end{equation}
$$

## Second quantization
The operator

$$
\begin{equation}
	\hat{N} = \sum_\alpha a_\alpha^{\dagger} a_\alpha \label{eq:2-22} \tag{30}
\end{equation}
$$

is called the number operator since it counts the number of particles in a given state vector when it acts
on the different single-particle states.  It acts on one single-particle state at the time and falls
therefore under category one-body operators.
Next we look at another important one-body operator, namely $\hat{H}_0$ and study its operator form in the
occupation number representation.

## Second quantization
We want to obtain an expression for a one-body operator which conserves the number of particles.
Here we study the one-body operator for the kinetic energy plus an eventual external one-body potential.
The action of this operator on a particular $n$-body state with its pertinent expectation value has already
been studied in coordinate  space.
In coordinate space the operator reads

$$
\begin{equation}
	\hat{H}_0 = \sum_i \hat{h}_0(x_i) \label{eq:2-23} \tag{31}
\end{equation}
$$

and the anti-symmetric $n$-particle Slater determinant is defined as

$$
\Phi(x_1, x_2,\dots ,x_n,\alpha_1,\alpha_2,\dots, \alpha_n)= \frac{1}{\sqrt{n!}} \sum_p (-1)^p\hat{P}\psi_{\alpha_1}(x_1)\psi_{\alpha_2}(x_2) \dots \psi_{\alpha_n}(x_n).
$$

## Second quantization
Defining

$$
\begin{equation}
	\hat{h}_0(x_i) \psi_{\alpha_i}(x_i) = \sum_{\alpha_k'} \psi_{\alpha_k'}(x_i) \langle\alpha_k'|\hat{h}_0|\alpha_k\rangle \label{eq:2-25} \tag{32}
\end{equation}
$$

we can easily  evaluate the action of $\hat{H}_0$ on each product of one-particle functions in Slater determinant.
From Eq. ([eq:2-25](#eq:2-25))  we obtain the following result without  permuting any particle pair

$$
\begin{eqnarray}
	&& \left( \sum_i \hat{h}_0(x_i) \right) \psi_{\alpha_1}(x_1)\psi_{\alpha_2}(x_2) \dots \psi_{\alpha_n}(x_n) \nonumber \\
	& =&\sum_{\alpha_1'} \langle \alpha_1'|\hat{h}_0|\alpha_1\rangle
		\psi_{\alpha_1'}(x_1)\psi_{\alpha_2}(x_2) \dots \psi_{\alpha_n}(x_n) \nonumber \\
	&+&\sum_{\alpha_2'} \langle \alpha_2'|\hat{h}_0|\alpha_2\rangle
		\psi_{\alpha_1}(x_1)\psi_{\alpha_2'}(x_2) \dots \psi_{\alpha_n}(x_n) \nonumber \\
	&+& \dots \nonumber \\
	&+&\sum_{\alpha_n'} \langle \alpha_n'|\hat{h}_0|\alpha_n\rangle
		\psi_{\alpha_1}(x_1)\psi_{\alpha_2}(x_2) \dots \psi_{\alpha_n'}(x_n) \label{eq:2-26} \tag{33}
\end{eqnarray}
$$

## Second quantization
If we interchange particles $1$ and $2$  we obtain

$$
\begin{eqnarray}
	&& \left( \sum_i \hat{h}_0(x_i) \right) \psi_{\alpha_1}(x_1)\psi_{\alpha_1}(x_2) \dots \psi_{\alpha_n}(x_n) \nonumber \\
	& =&\sum_{\alpha_2'} \langle \alpha_2'|\hat{h}_0|\alpha_2\rangle
		\psi_{\alpha_1}(x_2)\psi_{\alpha_2'}(x_1) \dots \psi_{\alpha_n}(x_n) \nonumber \\
	&+&\sum_{\alpha_1'} \langle \alpha_1'|\hat{h}_0|\alpha_1\rangle
		\psi_{\alpha_1'}(x_2)\psi_{\alpha_2}(x_1) \dots \psi_{\alpha_n}(x_n) \nonumber \\
	&+& \dots \nonumber \\
	&+&\sum_{\alpha_n'} \langle \alpha_n'|\hat{h}_0|\alpha_n\rangle
		\psi_{\alpha_1}(x_2)\psi_{\alpha_1}(x_2) \dots \psi_{\alpha_n'}(x_n) \label{eq:2-27} \tag{34}
\end{eqnarray}
$$

## Second quantization
We can continue by computing all possible permutations.
We rewrite also our Slater determinant in its second quantized form and skip the dependence on the quantum numbers $x_i.$
Summing up all contributions and taking care of all phases
$(-1)^p$ we arrive at

$$
\begin{eqnarray}
	\hat{H}_0|\alpha_1,\alpha_2,\dots, \alpha_n\rangle &=& \sum_{\alpha_1'}\langle \alpha_1'|\hat{h}_0|\alpha_1\rangle
		|\alpha_1'\alpha_2 \dots \alpha_{n}\rangle \nonumber \\
	&+& \sum_{\alpha_2'} \langle \alpha_2'|\hat{h}_0|\alpha_2\rangle
		|\alpha_1\alpha_2' \dots \alpha_{n}\rangle \nonumber \\
	&+& \dots \nonumber \\
	&+& \sum_{\alpha_n'} \langle \alpha_n'|\hat{h}_0|\alpha_n\rangle
		|\alpha_1\alpha_2 \dots \alpha_{n}'\rangle \label{eq:2-28} \tag{35}
\end{eqnarray}
$$

## Second quantization
In Eq. ([eq:2-28](#eq:2-28))
we have expressed the action of the one-body operator
of Eq. ([eq:2-23](#eq:2-23)) on the  $n$-body state in its second quantized form.
This equation can be further manipulated if we use the properties of the creation and annihilation operator
on each primed quantum number, that is

$$
\begin{equation}
	|\alpha_1\alpha_2 \dots \alpha_k' \dots \alpha_{n}\rangle =
		a_{\alpha_k'}^{\dagger}  a_{\alpha_k} |\alpha_1\alpha_2 \dots \alpha_k \dots \alpha_{n}\rangle \label{eq:2-29} \tag{36}
\end{equation}
$$

Inserting this in the right-hand side of Eq. ([eq:2-28](#eq:2-28)) results in

$$
\begin{eqnarray}
	\hat{H}_0|\alpha_1\alpha_2 \dots \alpha_{n}\rangle &=& \sum_{\alpha_1'}\langle \alpha_1'|\hat{h}_0|\alpha_1\rangle
		a_{\alpha_1'}^{\dagger}  a_{\alpha_1} |\alpha_1\alpha_2 \dots \alpha_{n}\rangle \nonumber \\
	&+& \sum_{\alpha_2'} \langle \alpha_2'|\hat{h}_0|\alpha_2\rangle
		a_{\alpha_2'}^{\dagger}  a_{\alpha_2} |\alpha_1\alpha_2 \dots \alpha_{n}\rangle \nonumber \\
	&+& \dots \nonumber \\
	&+& \sum_{\alpha_n'} \langle \alpha_n'|\hat{h}_0|\alpha_n\rangle
		a_{\alpha_n'}^{\dagger}  a_{\alpha_n} |\alpha_1\alpha_2 \dots \alpha_{n}\rangle \nonumber \\
	&=& \sum_{\alpha, \beta} \langle \alpha|\hat{h}_0|\beta\rangle a_\alpha^{\dagger} a_\beta
		|\alpha_1\alpha_2 \dots \alpha_{n}\rangle \label{eq:2-30a} \tag{37}
\end{eqnarray}
$$

## Second quantization
In the number occupation representation or second quantization we get the following expression for a one-body
operator which conserves the number of particles

$$
\begin{equation}
	\hat{H}_0 = \sum_{\alpha\beta} \langle \alpha|\hat{h}_0|\beta\rangle a_\alpha^{\dagger} a_\beta \label{eq:2-30b} \tag{38}
\end{equation}
$$

Obviously, $\hat{H}_0$ can be replaced by any other one-body  operator which preserved the number
of particles. The stucture of the operator is therefore not limited to say the kinetic or single-particle energy only.

The opearator $\hat{H}_0$ takes a particle from the single-particle state $\beta$  to the single-particle state $\alpha$
with a probability for the transition given by the expectation value $\langle \alpha|\hat{h}_0|\beta\rangle$.

## Second quantization
It is instructive to verify Eq. ([eq:2-30b](#eq:2-30b)) by computing the expectation value of $\hat{H}_0$
between two single-particle states

$$
\begin{equation}
	\langle \alpha_1|\hat{h}_0|\alpha_2\rangle = \sum_{\alpha\beta} \langle \alpha|\hat{h}_0|\beta\rangle
		\langle 0|a_{\alpha_1}a_\alpha^{\dagger} a_\beta a_{\alpha_2}^{\dagger}|0\rangle \label{eq:2-30c} \tag{39}
\end{equation}
$$

## Second quantization
Using the commutation relations for the creation and annihilation operators we have

$$
\begin{equation}
a_{\alpha_1}a_\alpha^{\dagger} a_\beta a_{\alpha_2}^{\dagger} = (\delta_{\alpha \alpha_1} - a_\alpha^{\dagger} a_{\alpha_1} )(\delta_{\beta \alpha_2} - a_{\alpha_2}^{\dagger} a_{\beta} ), \label{eq:2-30d} \tag{40}
\end{equation}
$$

which results in

$$
\begin{equation}
\langle 0|a_{\alpha_1}a_\alpha^{\dagger} a_\beta a_{\alpha_2}^{\dagger}|0\rangle = \delta_{\alpha \alpha_1} \delta_{\beta \alpha_2} \label{eq:2-30e} \tag{41}
\end{equation}
$$

and

$$
\begin{equation}
\langle \alpha_1|\hat{h}_0|\alpha_2\rangle = \sum_{\alpha\beta} \langle \alpha|\hat{h}_0|\beta\rangle\delta_{\alpha \alpha_1} \delta_{\beta \alpha_2} = \langle \alpha_1|\hat{h}_0|\alpha_2\rangle \label{eq:2-30f} \tag{42}
\end{equation}
$$

## Two-body operators in second quantization
Let us now derive the expression for our two-body interaction part, which also conserves the number of particles.
We can proceed in exactly the same way as for the one-body operator. In the coordinate representation our
two-body interaction part takes the following expression

$$
\begin{equation}
	\hat{H}_I = \sum_{i < j} V(x_i,x_j) \label{eq:2-31} \tag{43}
\end{equation}
$$

where the summation runs over distinct pairs. The term $V$ can be an interaction model for the nucleon-nucleon interaction
or the interaction between two electrons. It can also include additional two-body interaction terms.

The action of this operator on a product of
two single-particle functions is defined as

$$
\begin{equation}
	V(x_i,x_j) \psi_{\alpha_k}(x_i) \psi_{\alpha_l}(x_j) = \sum_{\alpha_k'\alpha_l'}
		\psi_{\alpha_k}'(x_i)\psi_{\alpha_l}'(x_j)
		\langle \alpha_k'\alpha_l'|\hat{v}|\alpha_k\alpha_l\rangle \label{eq:2-32} \tag{44}
\end{equation}
$$

## Operators in second quantization
We can now let $\hat{H}_I$ act on all terms in the linear combination for $|\alpha_1\alpha_2\dots\alpha_n\rangle$. Without any permutations we have

$$
\begin{eqnarray}
	&& \left( \sum_{i < j} V(x_i,x_j) \right) \psi_{\alpha_1}(x_1)\psi_{\alpha_2}(x_2)\dots \psi_{\alpha_n}(x_n) \nonumber \\
	&=& \sum_{\alpha_1'\alpha_2'} \langle \alpha_1'\alpha_2'|\hat{v}|\alpha_1\alpha_2\rangle
		\psi_{\alpha_1}'(x_1)\psi_{\alpha_2}'(x_2)\dots \psi_{\alpha_n}(x_n) \nonumber \\
	& +& \dots \nonumber \\
	&+& \sum_{\alpha_1'\alpha_n'} \langle \alpha_1'\alpha_n'|\hat{v}|\alpha_1\alpha_n\rangle
		\psi_{\alpha_1}'(x_1)\psi_{\alpha_2}(x_2)\dots \psi_{\alpha_n}'(x_n) \nonumber \\
	& +& \dots \nonumber \\
	&+& \sum_{\alpha_2'\alpha_n'} \langle \alpha_2'\alpha_n'|\hat{v}|\alpha_2\alpha_n\rangle
		\psi_{\alpha_1}(x_1)\psi_{\alpha_2}'(x_2)\dots \psi_{\alpha_n}'(x_n) \nonumber \\
	 & +& \dots \label{eq:2-33} \tag{45}
\end{eqnarray}
$$

where on the rhs we have a term for each distinct pairs.

## Operators in second quantization
For the other terms on the rhs we obtain similar expressions  and summing over all terms we obtain

$$
\begin{eqnarray}
	H_I |\alpha_1\alpha_2\dots\alpha_n\rangle &=& \sum_{\alpha_1', \alpha_2'} \langle \alpha_1'\alpha_2'|\hat{v}|\alpha_1\alpha_2\rangle
		|\alpha_1'\alpha_2'\dots\alpha_n\rangle \nonumber \\
	&+& \dots \nonumber \\
	&+& \sum_{\alpha_1', \alpha_n'} \langle \alpha_1'\alpha_n'|\hat{v}|\alpha_1\alpha_n\rangle
		|\alpha_1'\alpha_2\dots\alpha_n'\rangle \nonumber \\
	&+& \dots \nonumber \\
	&+& \sum_{\alpha_2', \alpha_n'} \langle \alpha_2'\alpha_n'|\hat{v}|\alpha_2\alpha_n\rangle
		|\alpha_1\alpha_2'\dots\alpha_n'\rangle \nonumber \\
	 &+& \dots \label{eq:2-34} \tag{46}
\end{eqnarray}
$$

## Operators in second quantization
We introduce second quantization via the relation

$$
\begin{eqnarray}
	&& a_{\alpha_k'}^{\dagger} a_{\alpha_l'}^{\dagger} a_{\alpha_l} a_{\alpha_k}
		|\alpha_1\alpha_2\dots\alpha_k\dots\alpha_l\dots\alpha_n\rangle \nonumber \\
	&=& (-1)^{k-1} (-1)^{l-2} a_{\alpha_k'}^{\dagger} a_{\alpha_l'}^{\dagger} a_{\alpha_l} a_{\alpha_k}
		|\alpha_k\alpha_l \underbrace{\alpha_1\alpha_2\dots\alpha_n}_{\neq \alpha_k,\alpha_l}\rangle \nonumber \\
	&=& (-1)^{k-1} (-1)^{l-2}
	|\alpha_k'\alpha_l' \underbrace{\alpha_1\alpha_2\dots\alpha_n}_{\neq \alpha_k',\alpha_l'}\rangle \nonumber \\
	&=& |\alpha_1\alpha_2\dots\alpha_k'\dots\alpha_l'\dots\alpha_n\rangle \label{eq:2-35} \tag{47}
\end{eqnarray}
$$

## Operators in second quantization
Inserting this in ([eq:2-34](#eq:2-34)) gives

$$
\begin{eqnarray}
	H_I |\alpha_1\alpha_2\dots\alpha_n\rangle
	&=& \sum_{\alpha_1', \alpha_2'} \langle \alpha_1'\alpha_2'|\hat{v}|\alpha_1\alpha_2\rangle
		a_{\alpha_1'}^{\dagger} a_{\alpha_2'}^{\dagger} a_{\alpha_2} a_{\alpha_1}
		|\alpha_1\alpha_2\dots\alpha_n\rangle \nonumber \\
	&+& \dots \nonumber \\
	&=& \sum_{\alpha_1', \alpha_n'} \langle \alpha_1'\alpha_n'|\hat{v}|\alpha_1\alpha_n\rangle
		a_{\alpha_1'}^{\dagger} a_{\alpha_n'}^{\dagger} a_{\alpha_n} a_{\alpha_1}
		|\alpha_1\alpha_2\dots\alpha_n\rangle \nonumber \\
	&+& \dots \nonumber \\
	&=& \sum_{\alpha_2', \alpha_n'} \langle \alpha_2'\alpha_n'|\hat{v}|\alpha_2\alpha_n\rangle
		a_{\alpha_2'}^{\dagger} a_{\alpha_n'}^{\dagger} a_{\alpha_n} a_{\alpha_2}
		|\alpha_1\alpha_2\dots\alpha_n\rangle \nonumber \\
	&+& \dots \nonumber \\
	&=& \sum_{\alpha, \beta, \gamma, \delta} ' \langle \alpha\beta|\hat{v}|\gamma\delta\rangle
		a^{\dagger}_\alpha a^{\dagger}_\beta a_\delta a_\gamma
		|\alpha_1\alpha_2\dots\alpha_n\rangle \label{eq:2-36} \tag{48}
\end{eqnarray}
$$

## Operators in second quantization
Here we let $\sum'$ indicate that the sums running over $\alpha$ and $\beta$ run over all
single-particle states, while the summations  $\gamma$ and $\delta$
run over all pairs of single-particle states. We wish to remove this restriction and since

$$
\begin{equation}
	\langle \alpha\beta|\hat{v}|\gamma\delta\rangle = \langle \beta\alpha|\hat{v}|\delta\gamma\rangle \label{eq:2-37} \tag{49}
\end{equation}
$$

we get

$$
\begin{eqnarray}
	\sum_{\alpha\beta} \langle \alpha\beta|\hat{v}|\gamma\delta\rangle a^{\dagger}_\alpha a^{\dagger}_\beta a_\delta a_\gamma &=&
		\sum_{\alpha\beta} \langle \beta\alpha|\hat{v}|\delta\gamma\rangle
		a^{\dagger}_\alpha a^{\dagger}_\beta a_\delta a_\gamma \label{eq:2-38a} \tag{50} \\
	&=& \sum_{\alpha\beta}\langle \beta\alpha|\hat{v}|\delta\gamma\rangle
		a^{\dagger}_\beta a^{\dagger}_\alpha a_\gamma a_\delta \label{eq:2-38b} \tag{51}
\end{eqnarray}
$$

where we  have used the anti-commutation rules.

## Operators in second quantization
Changing the summation indices
$\alpha$ and $\beta$ in ([eq:2-38b](#eq:2-38b)) we obtain

$$
\begin{equation}
	\sum_{\alpha\beta} \langle \alpha\beta|\hat{v}|\gamma\delta\rangle a^{\dagger}_\alpha a^{\dagger}_\beta a_\delta a_\gamma =
		 \sum_{\alpha\beta} \langle \alpha\beta|\hat{v}|\delta\gamma\rangle
		  a^{\dagger}_\alpha a^{\dagger}_\beta  a_\gamma a_\delta \label{eq:2-38c} \tag{52}
\end{equation}
$$

From this it follows that the restriction on the summation over $\gamma$ and $\delta$ can be removed if we multiply with a factor $\frac{1}{2}$, resulting in

$$
\begin{equation}
	\hat{H}_I = \frac{1}{2} \sum_{\alpha\beta\gamma\delta} \langle \alpha\beta|\hat{v}|\gamma\delta\rangle
		a^{\dagger}_\alpha a^{\dagger}_\beta a_\delta a_\gamma \label{eq:2-39} \tag{53}
\end{equation}
$$

where we sum freely over all single-particle states $\alpha$,
$\beta$, $\gamma$ og $\delta$.

## Operators in second quantization
With this expression we can now verify that the second quantization form of $\hat{H}_I$ in Eq. ([eq:2-39](#eq:2-39))
results in the same matrix between two anti-symmetrized two-particle states as its corresponding coordinate
space representation. We have

$$
\begin{equation}
	\langle \alpha_1 \alpha_2|\hat{H}_I|\beta_1 \beta_2\rangle =
		\frac{1}{2} \sum_{\alpha\beta\gamma\delta}
			\langle \alpha\beta|\hat{v}|\gamma\delta\rangle \langle 0|a_{\alpha_2} a_{\alpha_1}
			 a^{\dagger}_\alpha a^{\dagger}_\beta a_\delta a_\gamma
			 a_{\beta_1}^{\dagger} a_{\beta_2}^{\dagger}|0\rangle. \label{eq:2-40} \tag{54}
\end{equation}
$$

## Operators in second quantization
Using the commutation relations we get

$$
\begin{eqnarray}
	&& a_{\alpha_2} a_{\alpha_1}a^{\dagger}_\alpha a^{\dagger}_\beta
		a_\delta a_\gamma a_{\beta_1}^{\dagger} a_{\beta_2}^{\dagger} \nonumber \\
	&=& a_{\alpha_2} a_{\alpha_1}a^{\dagger}_\alpha a^{\dagger}_\beta
		( a_\delta \delta_{\gamma \beta_1} a_{\beta_2}^{\dagger} -
		a_\delta  a_{\beta_1}^{\dagger} a_\gamma a_{\beta_2}^{\dagger} ) \nonumber \\
	&=& a_{\alpha_2} a_{\alpha_1}a^{\dagger}_\alpha a^{\dagger}_\beta
		(\delta_{\gamma \beta_1} \delta_{\delta \beta_2} - \delta_{\gamma \beta_1} a_{\beta_2}^{\dagger} a_\delta -
		a_\delta a_{\beta_1}^{\dagger}\delta_{\gamma \beta_2} +
		a_\delta a_{\beta_1}^{\dagger} a_{\beta_2}^{\dagger} a_\gamma ) \nonumber \\
	&=& a_{\alpha_2} a_{\alpha_1}a^{\dagger}_\alpha a^{\dagger}_\beta
		(\delta_{\gamma \beta_1} \delta_{\delta \beta_2} - \delta_{\gamma \beta_1} a_{\beta_2}^{\dagger} a_\delta \nonumber \\
		&& \qquad - \delta_{\delta \beta_1} \delta_{\gamma \beta_2} + \delta_{\gamma \beta_2} a_{\beta_1}^{\dagger} a_\delta
		+ a_\delta a_{\beta_1}^{\dagger} a_{\beta_2}^{\dagger} a_\gamma ) \label{eq:2-41} \tag{55}
\end{eqnarray}
$$

## Operators in second quantization
The vacuum expectation value of this product of operators becomes

$$
\begin{eqnarray}
	&& \langle 0|a_{\alpha_2} a_{\alpha_1} a^{\dagger}_\alpha a^{\dagger}_\beta a_\delta a_\gamma
		a_{\beta_1}^{\dagger} a_{\beta_2}^{\dagger}|0\rangle \nonumber \\
	&=& (\delta_{\gamma \beta_1} \delta_{\delta \beta_2} -
		\delta_{\delta \beta_1} \delta_{\gamma \beta_2} )
		\langle 0|a_{\alpha_2} a_{\alpha_1}a^{\dagger}_\alpha a^{\dagger}_\beta|0\rangle \nonumber \\
	&=& (\delta_{\gamma \beta_1} \delta_{\delta \beta_2} -\delta_{\delta \beta_1} \delta_{\gamma \beta_2} )
	(\delta_{\alpha \alpha_1} \delta_{\beta \alpha_2} -\delta_{\beta \alpha_1} \delta_{\alpha \alpha_2} ) \label{eq:2-42b} \tag{56}
\end{eqnarray}
$$

## Operators in second quantization
Insertion of
Eq. ([eq:2-42b](#eq:2-42b)) in Eq. ([eq:2-40](#eq:2-40)) results in

$$
\begin{eqnarray}
	\langle \alpha_1\alpha_2|\hat{H}_I|\beta_1\beta_2\rangle &=& \frac{1}{2} \big[
		\langle \alpha_1\alpha_2|\hat{v}|\beta_1\beta_2\rangle- \langle \alpha_1\alpha_2|\hat{v}|\beta_2\beta_1\rangle \nonumber \\
		&& - \langle \alpha_2\alpha_1|\hat{v}|\beta_1\beta_2\rangle + \langle \alpha_2\alpha_1|\hat{v}|\beta_2\beta_1\rangle \big] \nonumber \\
	&=& \langle \alpha_1\alpha_2|\hat{v}|\beta_1\beta_2\rangle - \langle \alpha_1\alpha_2|\hat{v}|\beta_2\beta_1\rangle \nonumber \\
	&=& \langle \alpha_1\alpha_2|\hat{v}|\beta_1\beta_2\rangle_{\mathrm{AS}}. \label{eq:2-43b} \tag{57}
\end{eqnarray}
$$

## Operators in second quantization
The two-body operator can also be expressed in terms of the anti-symmetrized matrix elements we discussed previously as

$$
\begin{eqnarray}
	\hat{H}_I &=& \frac{1}{2} \sum_{\alpha\beta\gamma\delta}  \langle \alpha \beta|\hat{v}|\gamma \delta\rangle
		a_\alpha^{\dagger} a_\beta^{\dagger} a_\delta a_\gamma \nonumber \\
	&=& \frac{1}{4} \sum_{\alpha\beta\gamma\delta} \left[ \langle \alpha \beta|\hat{v}|\gamma \delta\rangle -
		\langle \alpha \beta|\hat{v}|\delta\gamma \rangle \right]
		a_\alpha^{\dagger} a_\beta^{\dagger} a_\delta a_\gamma \nonumber \\
	&=& \frac{1}{4} \sum_{\alpha\beta\gamma\delta} \langle \alpha \beta|\hat{v}|\gamma \delta\rangle_{\mathrm{AS}}
		a_\alpha^{\dagger} a_\beta^{\dagger} a_\delta a_\gamma \label{eq:2-45} \tag{58}
\end{eqnarray}
$$

## Operators in second quantization
The factors in front of the operator, either  $\frac{1}{4}$ or
$\frac{1}{2}$ tells whether we use antisymmetrized matrix elements or not.

We can now express the Hamiltonian operator for a many-fermion system  in the occupation basis representation
as

$$
\begin{equation}
	H = \sum_{\alpha, \beta} \langle \alpha|\hat{t}+\hat{u}_{\mathrm{ext}}|\beta\rangle a_\alpha^{\dagger} a_\beta + \frac{1}{4} \sum_{\alpha\beta\gamma\delta}
		\langle \alpha \beta|\hat{v}|\gamma \delta\rangle a_\alpha^{\dagger} a_\beta^{\dagger} a_\delta a_\gamma. \label{eq:2-46b} \tag{59}
\end{equation}
$$

This is the form we will use in the rest of these lectures, assuming that we work with anti-symmetrized two-body matrix elements.

## Particle-hole formalism
Second quantization is a useful and elegant formalism  for constructing many-body  states and
quantum mechanical operators. One can express and translate many physical processes
into simple pictures such as Feynman diagrams. Expecation values of many-body states are also easily calculated.
However, although the equations are seemingly easy to set up, from  a practical point of view, that is
the solution of Schroedinger's equation, there is no particular gain.
The many-body equation is equally hard to solve, irrespective of representation.
The cliche that
there is no free lunch brings us down to earth again.
Note however that a transformation to a particular
basis, for cases where the interaction obeys specific symmetries, can ease the solution of Schroedinger's equation.

But there is at least one important case where second quantization comes to our rescue.
It is namely easy to introduce another reference state than the pure vacuum $|0\rangle $, where all single-particle states are active.
With many particles present it is often useful to introduce another reference state  than the vacuum state$|0\rangle $. We will label this state $|c\rangle$ ($c$ for core) and as we will see it can reduce
considerably the complexity and thereby the dimensionality of the many-body problem. It allows us to sum up to infinite order specific many-body correlations.  The particle-hole representation is one of these handy representations.

## Particle-hole formalism
In the original particle representation these states are products of the creation operators  $a_{\alpha_i}^\dagger$ acting on the true vacuum $|0\rangle $.
Following Eq. ([eq:2-2](#eq:2-2)) we have

$$
\begin{eqnarray}
 |\alpha_1\alpha_2\dots\alpha_{n-1}\alpha_n\rangle &=& a_{\alpha_1}^\dagger a_{\alpha_2}^\dagger \dots
					a_{\alpha_{n-1}}^\dagger a_{\alpha_n}^\dagger |0\rangle  \label{eq:2-47a} \tag{60} \\
	|\alpha_1\alpha_2\dots\alpha_{n-1}\alpha_n\alpha_{n+1}\rangle &=&
		a_{\alpha_1}^\dagger a_{\alpha_2}^\dagger \dots a_{\alpha_{n-1}}^\dagger a_{\alpha_n}^\dagger
		a_{\alpha_{n+1}}^\dagger |0\rangle  \label{eq:2-47b} \tag{61} \\
	|\alpha_1\alpha_2\dots\alpha_{n-1}\rangle &=& a_{\alpha_1}^\dagger a_{\alpha_2}^\dagger \dots
		a_{\alpha_{n-1}}^\dagger |0\rangle  \label{eq:2-47c} \tag{62}
\end{eqnarray}
$$

## Particle-hole formalism
If we use Eq. ([eq:2-47a](#eq:2-47a)) as our new reference state, we can simplify considerably the representation of
this state

$$
\begin{equation}
	|c\rangle  \equiv |\alpha_1\alpha_2\dots\alpha_{n-1}\alpha_n\rangle =
		a_{\alpha_1}^\dagger a_{\alpha_2}^\dagger \dots a_{\alpha_{n-1}}^\dagger a_{\alpha_n}^\dagger |0\rangle  \label{eq:2-48a} \tag{63}
\end{equation}
$$

The new reference states for the $n+1$ and $n-1$ states can then be written as

$$
\begin{eqnarray}
	|\alpha_1\alpha_2\dots\alpha_{n-1}\alpha_n\alpha_{n+1}\rangle &=& (-1)^n a_{\alpha_{n+1}}^\dagger |c\rangle
		\equiv (-1)^n |\alpha_{n+1}\rangle_c \label{eq:2-48b} \tag{64} \\
	|\alpha_1\alpha_2\dots\alpha_{n-1}\rangle &=& (-1)^{n-1} a_{\alpha_n} |c\rangle
		\equiv (-1)^{n-1} |\alpha_{n-1}\rangle_c \label{eq:2-48c} \tag{65}
\end{eqnarray}
$$

## Particle-hole formalism
The first state has one additional particle with respect to the new vacuum state
$|c\rangle $  and is normally referred to as a one-particle state or one particle added to the
many-body reference state.
The second state has one particle less than the reference vacuum state  $|c\rangle $ and is referred to as
a one-hole state.
When dealing with a new reference state it is often convenient to introduce
new creation and annihilation operators since we have
from Eq. ([eq:2-48c](#eq:2-48c))

$$
\begin{equation}
	a_\alpha |c\rangle  \neq 0 \label{eq:2-49} \tag{66}
\end{equation}
$$

since  $\alpha$ is contained  in $|c\rangle $, while for the true vacuum we have
$a_\alpha |0\rangle  = 0$ for all $\alpha$.

The new reference state leads to the definition of new creation and annihilation operators
which satisfy the following relations

$$
\begin{eqnarray}
	b_\alpha |c\rangle  &=& 0 \label{eq:2-50a} \tag{67} \\
	\{b_\alpha^\dagger , b_\beta^\dagger \} = \{b_\alpha , b_\beta \} &=& 0 \nonumber  \\
	\{b_\alpha^\dagger , b_\beta \} &=& \delta_{\alpha \beta} \label{eq:2-50c} \tag{68}
\end{eqnarray}
$$

We assume also that the new reference state is properly normalized

$$
\begin{equation}
	\langle c | c \rangle = 1 \label{eq:2-51} \tag{69}
\end{equation}
$$

## Particle-hole formalism
The physical interpretation of these new operators is that of so-called quasiparticle states.
This means that a state defined by the addition of one extra particle to a reference state $|c\rangle $ may not necesseraly be interpreted as one particle coupled to a core.
We define now new creation operators that act on a state $\alpha$ creating a new quasiparticle state

$$
\begin{equation}
	b_\alpha^\dagger|c\rangle  = \Bigg\{ \begin{array}{ll}
		a_\alpha^\dagger |c\rangle  = |\alpha\rangle, & \alpha > F \\
		\\
		a_\alpha |c\rangle  = |\alpha^{-1}\rangle, & \alpha \leq F
	\end{array} \label{eq:2-52} \tag{70}
\end{equation}
$$

where $F$ is the Fermi level representing the last  occupied single-particle orbit
of the new reference state $|c\rangle $.

The annihilation is the hermitian conjugate of the creation operator

$$
b_\alpha = (b_\alpha^\dagger)^\dagger,
$$

resulting in

$$
\begin{equation}
	b_\alpha^\dagger = \Bigg\{ \begin{array}{ll}
		a_\alpha^\dagger & \alpha > F \\
		\\
		a_\alpha & \alpha \leq F
	\end{array} \qquad
	b_\alpha = \Bigg\{ \begin{array}{ll}
		a_\alpha & \alpha > F \\
		\\
		 a_\alpha^\dagger & \alpha \leq F
	\end{array} \label{eq:2-54} \tag{71}
\end{equation}
$$

## Particle-hole formalism
With the new creation and annihilation operator  we can now construct
many-body quasiparticle states, with one-particle-one-hole states, two-particle-two-hole
states etc in the same fashion as we previously constructed many-particle states.
We can write a general particle-hole state as

$$
\begin{equation}
	|\beta_1\beta_2\dots \beta_{n_p} \gamma_1^{-1} \gamma_2^{-1} \dots \gamma_{n_h}^{-1}\rangle \equiv
		\underbrace{b_{\beta_1}^\dagger b_{\beta_2}^\dagger \dots b_{\beta_{n_p}}^\dagger}_{>F}
		\underbrace{b_{\gamma_1}^\dagger b_{\gamma_2}^\dagger \dots b_{\gamma_{n_h}}^\dagger}_{\leq F} |c\rangle \label{eq:2-56} \tag{72}
\end{equation}
$$

We can now rewrite our one-body and two-body operators in terms of the new creation and annihilation operators.
The number operator becomes

$$
\begin{equation}
	\hat{N} = \sum_\alpha a_\alpha^\dagger a_\alpha=
\sum_{\alpha > F} b_\alpha^\dagger b_\alpha + n_c - \sum_{\alpha \leq F} b_\alpha^\dagger b_\alpha \label{eq:2-57b} \tag{73}
\end{equation}
$$

where $n_c$ is the number of particle in the new vacuum state $|c\rangle $.
The action of $\hat{N}$ on a many-body state results in

$$
\begin{equation}
	N |\beta_1\beta_2\dots \beta_{n_p} \gamma_1^{-1} \gamma_2^{-1} \dots \gamma_{n_h}^{-1}\rangle = (n_p + n_c - n_h) |\beta_1\beta_2\dots \beta_{n_p} \gamma_1^{-1} \gamma_2^{-1} \dots \gamma_{n_h}^{-1}\rangle \label{2-59} \tag{74}
\end{equation}
$$

Here  $n=n_p +n_c - n_h$ is the total number of particles in the quasi-particle state of
Eq. ([eq:2-56](#eq:2-56)). Note that  $\hat{N}$ counts the total number of particles  present

$$
\begin{equation}
	N_{qp} = \sum_\alpha b_\alpha^\dagger b_\alpha, \label{eq:2-60} \tag{75}
\end{equation}
$$

gives us the number of quasi-particles as can be seen by computing

$$
\begin{equation}
	N_{qp}= |\beta_1\beta_2\dots \beta_{n_p} \gamma_1^{-1} \gamma_2^{-1} \dots \gamma_{n_h}^{-1}\rangle
		= (n_p + n_h)|\beta_1\beta_2\dots \beta_{n_p} \gamma_1^{-1} \gamma_2^{-1} \dots \gamma_{n_h}^{-1}\rangle \label{eq:2-61} \tag{76}
\end{equation}
$$

where $n_{qp} = n_p + n_h$ is the total number of quasi-particles.

## Particle-hole formalism
We express the one-body operator $\hat{H}_0$ in terms of the quasi-particle creation and annihilation operators, resulting in

$$
\begin{eqnarray}
	\hat{H}_0 &=& \sum_{\alpha\beta > F} \langle \alpha|\hat{h}_0|\beta\rangle  b_\alpha^\dagger b_\beta +
		\sum_{\begin{array}{c} \alpha > F \\ \beta \leq F \end{array}} \left[
		\langle \alpha|\hat{h}_0|\beta\rangle b_\alpha^\dagger b_\beta^\dagger +
		\langle \beta|\hat{h}_0|\alpha\rangle b_\beta  b_\alpha \right] \nonumber \\
	&+& \sum_{\alpha \leq F} \langle \alpha|\hat{h}_0|\alpha\rangle -
		\sum_{\alpha\beta \leq F} \langle \beta|\hat{h}_0|\alpha\rangle
		b_\alpha^\dagger b_\beta \label{eq:2-63b} \tag{77}
\end{eqnarray}
$$

The first term  gives contribution only for particle states, while the last one
contributes only for holestates. The second term can create or destroy a set of
quasi-particles and
the third term is the contribution  from the vacuum state $|c\rangle$.

## Particle-hole formalism
Before we continue with the expressions for the two-body operator, we introduce a nomenclature we will use for the rest of this
text. It is inspired by the notation used in quantum chemistry.
We reserve the labels $i,j,k,\dots$ for hole states and $a,b,c,\dots$ for states above $F$, viz. particle states.
This means also that we will skip the constraint $\leq F$ or $> F$ in the summation symbols.
Our operator $\hat{H}_0$  reads now

$$
\begin{eqnarray}
	\hat{H}_0 &=& \sum_{ab} \langle a|\hat{h}|b\rangle b_a^\dagger b_b +
		\sum_{ai} \left[
		\langle a|\hat{h}|i\rangle b_a^\dagger b_i^\dagger +
		\langle i|\hat{h}|a\rangle b_i  b_a \right] \nonumber \\
	&+& \sum_{i} \langle i|\hat{h}|i\rangle -
		\sum_{ij} \langle j|\hat{h}|i\rangle
		b_i^\dagger b_j \label{eq:2-63c} \tag{78}
\end{eqnarray}
$$

## Particle-hole formalism
The two-particle operator in the particle-hole formalism  is more complicated since we have
to translate four indices $\alpha\beta\gamma\delta$ to the possible combinations of particle and hole
states.  When performing the commutator algebra we can regroup the operator in five different terms

$$
\begin{equation}
	\hat{H}_I = \hat{H}_I^{(a)} + \hat{H}_I^{(b)} + \hat{H}_I^{(c)} + \hat{H}_I^{(d)} + \hat{H}_I^{(e)} \label{eq:2-65} \tag{79}
\end{equation}
$$

Using anti-symmetrized  matrix elements,
bthe term  $\hat{H}_I^{(a)}$ is

$$
\begin{equation}
	\hat{H}_I^{(a)} = \frac{1}{4}
	\sum_{abcd} \langle ab|\hat{V}|cd\rangle
		b_a^\dagger b_b^\dagger b_d b_c \label{eq:2-66} \tag{80}
\end{equation}
$$

## Particle-hole formalism
The next term $\hat{H}_I^{(b)}$  reads

$$
\begin{equation}
	 \hat{H}_I^{(b)} = \frac{1}{4} \sum_{abci}\left(\langle ab|\hat{V}|ci\rangle b_a^\dagger b_b^\dagger b_i^\dagger b_c +\langle ai|\hat{V}|cb\rangle b_a^\dagger b_i b_b b_c\right) \label{eq:2-67b} \tag{81}
\end{equation}
$$

This term conserves the number of quasiparticles but creates or removes a
three-particle-one-hole  state.
For $\hat{H}_I^{(c)}$  we have

$$
\begin{eqnarray}
	\hat{H}_I^{(c)}& =& \frac{1}{4}
		\sum_{abij}\left(\langle ab|\hat{V}|ij\rangle b_a^\dagger b_b^\dagger b_j^\dagger b_i^\dagger +
		\langle ij|\hat{V}|ab\rangle b_a  b_b b_j b_i \right)+  \nonumber \\
	&&	\frac{1}{2}\sum_{abij}\langle ai|\hat{V}|bj\rangle b_a^\dagger b_j^\dagger b_b b_i +
		\frac{1}{2}\sum_{abi}\langle ai|\hat{V}|bi\rangle b_a^\dagger b_b. \label{eq:2-68c} \tag{82}
\end{eqnarray}
$$

## Particle-hole formalism
The first line stands for the creation of a two-particle-two-hole state, while the second line represents
the creation to two one-particle-one-hole pairs
while the last term represents a contribution to the particle single-particle energy
from the hole states, that is an interaction between the particle states and the hole states
within the new vacuum  state.
The fourth term reads

$$
\begin{eqnarray}
	 \hat{H}_I^{(d)}& = &\frac{1}{4}
	 	\sum_{aijk}\left(\langle ai|\hat{V}|jk\rangle b_a^\dagger b_k^\dagger b_j^\dagger b_i+
\langle ji|\hat{V}|ak\rangle b_k^\dagger b_j b_i b_a\right)+\nonumber \\
&&\frac{1}{4}\sum_{aij}\left(\langle ai|\hat{V}|ji\rangle b_a^\dagger b_j^\dagger+
\langle ji|\hat{V}|ai\rangle - \langle ji|\hat{V}|ia\rangle b_j b_a \right). \label{eq:2-69d} \tag{83}
\end{eqnarray}
$$

The terms in the first line  stand for the creation of a particle-hole state
interacting with hole states, we will label this as a two-hole-one-particle contribution.
The remaining terms are a particle-hole state interacting with the holes in the vacuum state.
Finally we have

$$
\begin{equation}
	\hat{H}_I^{(e)} = \frac{1}{4}
		 \sum_{ijkl}
		 \langle kl|\hat{V}|ij\rangle b_i^\dagger b_j^\dagger b_l b_k+
	        \frac{1}{2}\sum_{ijk}\langle ij|\hat{V}|kj\rangle b_k^\dagger b_i
	        +\frac{1}{2}\sum_{ij}\langle ij|\hat{V}|ij\rangle \label{eq:2-70d} \tag{84}
\end{equation}
$$

The first terms represents the
interaction between two holes while the second stands for the interaction between a hole and the remaining holes in the vacuum state.
It represents a contribution to single-hole energy  to first order.
The last term collects all contributions to the energy of the ground state of a closed-shell system arising
from hole-hole correlations.

## Summarizing and defining a normal-ordered Hamiltonian

$$
\Phi_{AS}(\alpha_1, \dots, \alpha_A; x_1, \dots x_A)=
            \frac{1}{\sqrt{A}} \sum_{\hat{P}} (-1)^P \hat{P} \prod_{i=1}^A \psi_{\alpha_i}(x_i),
$$

which is equivalent with $|\alpha_1 \dots \alpha_A\rangle= a_{\alpha_1}^{\dagger} \dots a_{\alpha_A}^{\dagger} |0\rangle$. We have also

9
2

<
<
<
!
!
M
A
T
H
_
B
L
O
C
K

$$
\delta_{pq} = \left\{a_p, a_q^\dagger \right\},
$$

and

9
4

<
<
<
!
!
M
A
T
H
_
B
L
O
C
K

$$
|\Phi_0\rangle = |\alpha_1 \dots \alpha_A\rangle, \quad \alpha_1, \dots, \alpha_A \leq \alpha_F
$$

## Summarizing and defining a normal-ordered Hamiltonian

9
6

<
<
<
!
!
M
A
T
H
_
B
L
O
C
K

$$
\left\{a_p, a_q^\dagger \right\} = \delta_{pq}, p, q > \alpha_F
$$

with         $i,j,\ldots \leq \alpha_F, \quad a,b,\ldots > \alpha_F, \quad p,q, \ldots - \textrm{any}$

$$
a_i|\Phi_0\rangle = |\Phi_i\rangle, \hspace{0.5cm} a_a^\dagger|\Phi_0\rangle = |\Phi^a\rangle
$$

and

$$
a_i^\dagger|\Phi_0\rangle = 0 \hspace{0.5cm}  a_a|\Phi_0\rangle = 0
$$

## Summarizing and defining a normal-ordered Hamiltonian
**One- and two-body operators.**

The one-body operator is defined as

$$
\hat{F} = \sum_{pq} \langle p|\hat{f}|q\rangle a_p^\dagger a_q
$$

while the two-body opreator is defined as

$$
\hat{V} = \frac{1}{4} \sum_{pqrs} \langle pq|\hat{v}|rs\rangle_{AS} a_p^\dagger a_q^\dagger a_s a_r
$$

where we have defined the antisymmetric matrix elements

$$
\langle pq|\hat{v}|rs\rangle_{AS} = \langle pq|\hat{v}|rs\rangle - \langle pq|\hat{v}|sr\rangle.
$$

## Summarizing and defining a normal-ordered Hamiltonian
We can also define a three-body operator

$$
\hat{V}_3 = \frac{1}{36} \sum_{pqrstu} \langle pqr|\hat{v}_3|stu\rangle_{AS}
                a_p^\dagger a_q^\dagger a_r^\dagger a_u a_t a_s
$$

with the antisymmetrized matrix element

$$
\begin{equation}
            \langle pqr|\hat{v}_3|stu\rangle_{AS} = \langle pqr|\hat{v}_3|stu\rangle + \langle pqr|\hat{v}_3|tus\rangle + \langle pqr|\hat{v}_3|ust\rangle- \langle pqr|\hat{v}_3|sut\rangle - \langle pqr|\hat{v}_3|tsu\rangle - \langle pqr|\hat{v}_3|uts\rangle.
\label{_auto2} \tag{85}
\end{equation}
$$

## Hartree-Fock in second quantization and stability of HF solution
We wish now to derive the Hartree-Fock equations using our second-quantized formalism and study the stability of the equations.
Our ansatz for the ground state of the system is approximated as (this is our representation of a Slater determinant in second quantization)

$$
|\Phi_0\rangle = |c\rangle = a^{\dagger}_i a^{\dagger}_j \dots a^{\dagger}_l|0\rangle.
$$

We wish to determine $\hat{u}^{HF}$ so that
$E_0^{HF}= \langle c|\hat{H}| c\rangle$ becomes a local minimum.

In our analysis here we will need Thouless' theorem, which states that
an arbitrary Slater determinant $|c'\rangle$ which is not orthogonal to a determinant
$| c\rangle ={\displaystyle\prod_{i=1}^{n}}
a_{\alpha_{i}}^{\dagger}|0\rangle$, can be written as

$$
|c'\rangle=exp\left\{\sum_{a>F}\sum_{i\le F}C_{ai}a_{a}^{\dagger}a_{i}\right\}| c\rangle
$$

## Hartree-Fock in second quantization and Thouless' theorem

Let us give a simple proof of Thouless' theorem. The theorem states that we can make a linear combination av particle-hole excitations  with respect to a given reference state $\vert c\rangle$. With this linear combination, we can make a new Slater determinant $\vert c'\rangle $ which is not orthogonal to
$\vert c\rangle$, that is

$$
\langle c|c'\rangle \ne 0.
$$

To show this we need some intermediate steps. The exponential product of two operators  $\exp{\hat{A}}\times\exp{\hat{B}}$ is equal to $\exp{(\hat{A}+\hat{B})}$ only if the two operators commute, that is

$$
[\hat{A},\hat{B}] = 0.
$$

## Thouless' theorem

If the operators do not commute, we need to resort to the [Baker-Campbell-Hauersdorf](http://www.encyclopediaofmath.org/index.php/Campbell%E2%80%93Hausdorff_formula). This relation states that

$$
\exp{\hat{C}}=\exp{\hat{A}}\exp{\hat{B}},
$$

with

$$
\hat{C}=\hat{A}+\hat{B}+\frac{1}{2}[\hat{A},\hat{B}]+\frac{1}{12}[[\hat{A},\hat{B}],\hat{B}]-\frac{1}{12}[[\hat{A},\hat{B}],\hat{A}]+\dots
$$

From these relations, we note that
in our expression  for $|c'\rangle$ we have commutators of the type

$$
[a_{a}^{\dagger}a_{i},a_{b}^{\dagger}a_{j}],
$$

and it is easy to convince oneself that these commutators, or higher powers thereof, are all zero. This means that we can write out our new representation of a Slater determinant as

$$
|c'\rangle=exp\left\{\sum_{a>F}\sum_{i\le F}C_{ai}a_{a}^{\dagger}a_{i}\right\}| c\rangle=\prod_{i}\left\{1+\sum_{a>F}C_{ai}a_{a}^{\dagger}a_{i}+\left(\sum_{a>F}C_{ai}a_{a}^{\dagger}a_{i}\right)^2+\dots\right\}| c\rangle
$$

## Thouless' theorem

We note that

$$
\prod_{i}\sum_{a>F}C_{ai}a_{a}^{\dagger}a_{i}\sum_{b>F}C_{bi}a_{b}^{\dagger}a_{i}| c\rangle =0,
$$

and all higher-order powers of these combinations of creation and annihilation operators disappear
due to the fact that $(a_i)^n| c\rangle =0$ when $n > 1$. This allows us to rewrite the expression for $|c'\rangle $ as

$$
|c'\rangle=\prod_{i}\left\{1+\sum_{a>F}C_{ai}a_{a}^{\dagger}a_{i}\right\}| c\rangle,
$$

which we can rewrite as

$$
|c'\rangle=\prod_{i}\left\{1+\sum_{a>F}C_{ai}a_{a}^{\dagger}a_{i}\right\}| a^{\dagger}_{i_1} a^{\dagger}_{i_2} \dots a^{\dagger}_{i_n}|0\rangle.
$$

The last equation can be written as

$$
\begin{equation}
|c'\rangle=\prod_{i}\left\{1+\sum_{a>F}C_{ai}a_{a}^{\dagger}a_{i}\right\}| a^{\dagger}_{i_1} a^{\dagger}_{i_2} \dots a^{\dagger}_{i_n}|0\rangle=\left(1+\sum_{a>F}C_{ai_1}a_{a}^{\dagger}a_{i_1}\right)a^{\dagger}_{i_1}
\label{_auto3} \tag{86}
\end{equation}
$$

$$
\begin{equation}
 \times\left(1+\sum_{a>F}C_{ai_2}a_{a}^{\dagger}a_{i_2}\right)a^{\dagger}_{i_2} \dots |0\rangle=\prod_{i}\left(a^{\dagger}_{i}+\sum_{a>F}C_{ai}a_{a}^{\dagger}\right)|0\rangle.
\label{_auto4} \tag{87}
\end{equation}
$$

## New operators

If we define a new creation operator

$$
\begin{equation}
b^{\dagger}_{i}=a^{\dagger}_{i}+\sum_{a>F}C_{ai}a_{a}^{\dagger}, \label{eq:newb} \tag{88}
\end{equation}
$$

we have

$$
|c'\rangle=\prod_{i}b^{\dagger}_{i}|0\rangle=\prod_{i}\left(a^{\dagger}_{i}+\sum_{a>F}C_{ai}a_{a}^{\dagger}\right)|0\rangle,
$$

meaning that the new representation of the Slater determinant in second quantization, $|c'\rangle$, looks like our previous ones. However, this representation is not general enough since we have a restriction on the sum over single-particle states in Eq. ([eq:newb](#eq:newb)). The single-particle states have all to be above the Fermi level.
The question then is whether we can construct a general representation of a Slater determinant with a creation operator

$$
\tilde{b}^{\dagger}_{i}=\sum_{p}f_{ip}a_{p}^{\dagger},
$$

where $f_{ip}$ is a matrix element of a unitary matrix which transforms our creation and annihilation operators
$a^{\dagger}$ and $a$ to $\tilde{b}^{\dagger}$ and $\tilde{b}$. These new operators define a new representation of a Slater determinant as

$$
|\tilde{c}\rangle=\prod_{i}\tilde{b}^{\dagger}_{i}|0\rangle.
$$

## Showing that $|\tilde{c}\rangle= |c'\rangle$

We need to show that $|\tilde{c}\rangle= |c'\rangle$. We need also to assume that the new state
is not orthogonal to $|c\rangle$, that is $\langle c| \tilde{c}\rangle \ne 0$. From this it follows that

$$
\langle c| \tilde{c}\rangle=\langle 0| a_{i_n}\dots a_{i_1}\left(\sum_{p=i_1}^{i_n}f_{i_1p}a_{p}^{\dagger} \right)\left(\sum_{q=i_1}^{i_n}f_{i_2q}a_{q}^{\dagger} \right)\dots \left(\sum_{t=i_1}^{i_n}f_{i_nt}a_{t}^{\dagger} \right)|0\rangle,
$$

which is nothing but the determinant $det(f_{ip})$ which we can, using the intermediate normalization condition,
normalize to one, that is

$$
det(f_{ip})=1,
$$

meaning that $f$ has an inverse defined as (since we are dealing with orthogonal, and in our case unitary as well, transformations)

$$
\sum_{k} f_{ik}f^{-1}_{kj} = \delta_{ij},
$$

and

$$
\sum_{j} f^{-1}_{ij}f_{jk} = \delta_{ik}.
$$

## Wrapping it up

Using these relations we can then define the linear combination of creation (and annihilation as well)
operators as

$$
\sum_{i}f^{-1}_{ki}\tilde{b}^{\dagger}_{i}=\sum_{i}f^{-1}_{ki}\sum_{p=i_1}^{\infty}f_{ip}a_{p}^{\dagger}=a_{k}^{\dagger}+\sum_{i}\sum_{p=i_{n+1}}^{\infty}f^{-1}_{ki}f_{ip}a_{p}^{\dagger}.
$$

Defining

$$
c_{kp}=\sum_{i \le F}f^{-1}_{ki}f_{ip},
$$

we can redefine

$$
a_{k}^{\dagger}+\sum_{i}\sum_{p=i_{n+1}}^{\infty}f^{-1}_{ki}f_{ip}a_{p}^{\dagger}=a_{k}^{\dagger}+\sum_{p=i_{n+1}}^{\infty}c_{kp}a_{p}^{\dagger}=b_k^{\dagger},
$$

our starting point. We have shown that our general representation of a Slater determinant

$$
|\tilde{c}\rangle=\prod_{i}\tilde{b}^{\dagger}_{i}|0\rangle=|c'\rangle=\prod_{i}b^{\dagger}_{i}|0\rangle,
$$

with

$$
b_k^{\dagger}=a_{k}^{\dagger}+\sum_{p=i_{n+1}}^{\infty}c_{kp}a_{p}^{\dagger}.
$$

## Thouless' theorem

This means that we can actually write an ansatz for the ground state of the system as a linear combination of
terms which contain the ansatz itself $|c\rangle$ with  an admixture from an infinity of one-particle-one-hole states. The latter has important consequences when we wish to interpret the Hartree-Fock equations and their stability. We can rewrite the new representation as

$$
|c'\rangle = |c\rangle+|\delta c\rangle,
$$

where $|\delta c\rangle$ can now be interpreted as a small variation. If we approximate this term with
contributions from one-particle-one-hole (*1p-1h*) states only, we arrive at

$$
|c'\rangle = \left(1+\sum_{ai}\delta C_{ai}a_{a}^{\dagger}a_i\right)|c\rangle.
$$

In our derivation of the Hartree-Fock equations we have shown that

$$
\langle \delta c| \hat{H} | c\rangle =0,
$$

which means that we have to satisfy

$$
\langle c|\sum_{ai}\delta C_{ai}\left\{a_{a}^{\dagger}a_i\right\} \hat{H} | c\rangle =0.
$$

With this as a background, we are now ready to study the stability of the Hartree-Fock equations.

## Hartree-Fock in second quantization and stability of HF solution
The variational condition for deriving the Hartree-Fock equations guarantees only that the expectation value $\langle c | \hat{H} | c \rangle$ has an extreme value, not necessarily a minimum. To figure out whether the extreme value we have found  is a minimum, we can use second quantization to analyze our results and find a criterion
for the above expectation value to a local minimum. We will use Thouless' theorem and show that

$$
\frac{\langle c' |\hat{H} | c'\rangle}{\langle c' |c'\rangle} \ge \langle c |\hat{H} | c\rangle= E_0,
$$

with

$$
{|c'\rangle} = {|c\rangle + |\delta c\rangle}.
$$

Using Thouless' theorem we can write out ${|c'\rangle}$ as

$$
\begin{equation}
 {|c'\rangle}=\exp\left\{\sum_{a > F}\sum_{i \le F}\delta C_{ai}a_{a}^{\dagger}a_{i}\right\}| c\rangle
\label{_auto5} \tag{89}
\end{equation}
$$

$$
\begin{equation}
=\left\{1+\sum_{a > F}\sum_{i \le F}\delta C_{ai}a_{a}^{\dagger}
a_{i}+\frac{1}{2!}\sum_{ab > F}\sum_{ij \le F}\delta C_{ai}\delta C_{bj}a_{a}^{\dagger}a_{i}a_{b}^{\dagger}a_{j}+\dots\right\}
\label{_auto6} \tag{90}
\end{equation}
$$

where the amplitudes $\delta C$ are small.

## Hartree-Fock in second quantization and stability of HF solution

The norm of $|c'\rangle$ is given by (using the intermediate normalization condition $\langle c' |c\rangle=1$)

$$
\langle c' | c'\rangle = 1+\sum_{a>F}
\sum_{i\le F}|\delta C_{ai}|^2+O(\delta C_{ai}^3).
$$

The expectation value for the energy is now given by (using the Hartree-Fock condition)

1
4
0

<
<
<
!
!
M
A
T
H
_
B
L
O
C
K

$$
\frac{1}{2!}\sum_{ab>F}
\sum_{ij\le F}\delta C_{ai}\delta C_{bj}\langle c |\hat{H}a_{a}^{\dagger}a_{i}a_{b}^{\dagger}a_{j}|c\rangle+\frac{1}{2!}\sum_{ab>F}
\sum_{ij\le F}\delta C_{ai}^*\delta C_{bj}^*\langle c|a_{j}^{\dagger}a_{b}a_{i}^{\dagger}a_{a}\hat{H}|c\rangle
+\dots
$$

## Hartree-Fock in second quantization and stability of HF solution
We have already calculated the second term on the right-hand side of the previous equation

$$
\begin{equation}
\langle c | \left(\{a^\dagger_i a_a\} \hat{H} \{a^\dagger_b a_j\} \right) | c\rangle=\sum_{pq} \sum_{ijab}\delta C_{ai}^*\delta C_{bj} \langle p|\hat{h}_0 |q\rangle
            \langle c | \left(\{a^{\dagger}_i a_a\}\{a^{\dagger}_pa_q\}
             \{a^{\dagger}_b a_j\} \right)| c\rangle
\label{_auto7} \tag{91}
\end{equation}
$$

$$
\begin{equation}
 +\frac{1}{4} \sum_{pqrs} \sum_{ijab}\delta C_{ai}^*\delta C_{bj} \langle pq| \hat{v}|rs\rangle
            \langle c | \left(\{a^\dagger_i a_a\}\{a^{\dagger}_p a^{\dagger}_q a_s  a_r\} \{a^{\dagger}_b a_j\} \right)| c\rangle ,
\label{_auto8} \tag{92}
\end{equation}
$$

resulting in

$$
E_0\sum_{ai}|\delta C_{ai}|^2+\sum_{ai}|\delta C_{ai}|^2(\varepsilon_a-\varepsilon_i)-\sum_{ijab} \langle aj|\hat{v}| bi\rangle \delta C_{ai}^*\delta C_{bj}.
$$

## Hartree-Fock in second quantization and stability of HF solution

$$
\frac{1}{2!}\langle c |\left(\{a^\dagger_j a_b\} \{a^\dagger_i a_a\} \hat{V}_N  \right) | c\rangle  =
\frac{1}{2!}\langle c |\left( \hat{V}_N \{a^\dagger_a a_i\} \{a^\dagger_b a_j\} \right)^{\dagger} | c\rangle
$$

which is nothing but

$$
\frac{1}{2!}\langle c |  \left( \hat{V}_N \{a^\dagger_a a_i\} \{a^\dagger_b a_j\} \right) | c\rangle^*
=\frac{1}{2} \sum_{ijab} (\langle ij|\hat{v}|ab\rangle)^*\delta C_{ai}^*\delta C_{bj}^*
$$

or

$$
\frac{1}{2} \sum_{ijab} (\langle ab|\hat{v}|ij\rangle)\delta C_{ai}^*\delta C_{bj}^*
$$

where we have used the relation

$$
\langle a |\hat{A} | b\rangle =  (\langle b |\hat{A}^{\dagger} | a\rangle)^*
$$

due to the hermiticity of $\hat{H}$ and $\hat{V}$.

## Hartree-Fock in second quantization and stability of HF solution
We define two matrix elements

$$
A_{ai,bj}=-\langle aj|\hat{v} bi\rangle
$$

and

$$
B_{ai,bj}=\langle ab|\hat{v}|ij\rangle
$$

both being anti-symmetrized.

## Hartree-Fock in second quantization and stability of HF solution

With these definitions we write out the energy as

$$
\begin{equation}
\langle c'|H|c'\rangle = \left(1+\sum_{ai}|\delta C_{ai}|^2\right)\langle c |H|c\rangle+\sum_{ai}|\delta C_{ai}|^2(\varepsilon_a^{HF}-\varepsilon_i^{HF})+\sum_{ijab}A_{ai,bj}\delta C_{ai}^*\delta C_{bj}+
\label{_auto9} \tag{93}
\end{equation}
$$

$$
\begin{equation}
\frac{1}{2} \sum_{ijab} B_{ai,bj}^*\delta C_{ai}\delta C_{bj}+\frac{1}{2} \sum_{ijab} B_{ai,bj}\delta C_{ai}^*\delta C_{bj}^*
+O(\delta C_{ai}^3),
\label{_auto10} \tag{94}
\end{equation}
$$

which can be rewritten as

$$
\langle c'|H|c'\rangle = \left(1+\sum_{ai}|\delta C_{ai}|^2\right)\langle c |H|c\rangle+\Delta E+O(\delta C_{ai}^3),
$$

and skipping higher-order terms we arrived

$$
\frac{\langle c' |\hat{H} | c'\rangle}{\langle c' |c'\rangle} =E_0+\frac{\Delta E}{\left(1+\sum_{ai}|\delta C_{ai}|^2\right)}.
$$

## Hartree-Fock in second quantization and stability of HF solution
We have defined

$$
\Delta E = \frac{1}{2} \langle \chi | \hat{M}| \chi \rangle
$$

with the vectors

$$
\chi = \left[ \delta C\hspace{0.2cm} \delta C^*\right]^T
$$

and the matrix

$$
\hat{M}=\left(\begin{array}{cc} \Delta + A & B \\ B^* & \Delta + A^*\end{array}\right),
$$

with $\Delta_{ai,bj} = (\varepsilon_a-\varepsilon_i)\delta_{ab}\delta_{ij}$.

## Hartree-Fock in second quantization and stability of HF solution
The condition

$$
\Delta E = \frac{1}{2} \langle \chi | \hat{M}| \chi \rangle \ge 0
$$

for an arbitrary  vector

$$
\chi = \left[ \delta C\hspace{0.2cm} \delta C^*\right]^T
$$

means that all eigenvalues of the matrix have to be larger than or equal zero.
A necessary (but no sufficient) condition is that the matrix elements (for all $ai$ )

$$
(\varepsilon_a-\varepsilon_i)\delta_{ab}\delta_{ij}+A_{ai,bj} \ge 0.
$$

This equation can be used as a first test of the stability of the Hartree-Fock equation.

## Operators in second quantization
In the build-up of a shell-model or FCI code that is meant to tackle large dimensionalities
is the action of the Hamiltonian $\hat{H}$ on a
Slater determinant represented in second quantization as

$$
|\alpha_1\dots \alpha_n\rangle = a_{\alpha_1}^{\dagger} a_{\alpha_2}^{\dagger} \dots a_{\alpha_n}^{\dagger} |0\rangle.
$$

The time consuming part stems from the action of the Hamiltonian
on the above determinant,

$$
\left(\sum_{\alpha\beta} \langle \alpha|t+u|\beta\rangle a_\alpha^{\dagger} a_\beta + \frac{1}{4} \sum_{\alpha\beta\gamma\delta}
                \langle \alpha \beta|\hat{v}|\gamma \delta\rangle a_\alpha^{\dagger} a_\beta^{\dagger} a_\delta a_\gamma\right)a_{\alpha_1}^{\dagger} a_{\alpha_2}^{\dagger} \dots a_{\alpha_n}^{\dagger} |0\rangle.
$$

A practically useful way to implement this action is to encode a Slater determinant as a bit pattern.

## Operators in second quantization
Assume that we have at our disposal $n$ different single-particle orbits
$\alpha_0,\alpha_2,\dots,\alpha_{n-1}$ and that we can distribute  among these orbits $N\le n$ particles.

A Slater  determinant can then be coded as an integer of $n$ bits. As an example, if we have $n=16$ single-particle states
$\alpha_0,\alpha_1,\dots,\alpha_{15}$ and $N=4$ fermions occupying the states $\alpha_3$, $\alpha_6$, $\alpha_{10}$ and $\alpha_{13}$
we could write this Slater determinant as

$$
\Phi_{\Lambda} = a_{\alpha_3}^{\dagger} a_{\alpha_6}^{\dagger} a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle.
$$

The unoccupied single-particle states have bit value $0$ while the occupied ones are represented by bit state $1$.
In the binary notation we would write this   16 bits long integer as

$$
\begin{array}{cccccccccccccccc}
{\alpha_0}&{\alpha_1}&{\alpha_2}&{\alpha_3}&{\alpha_4}&{\alpha_5}&{\alpha_6}&{\alpha_7} & {\alpha_8} &{\alpha_9} & {\alpha_{10}} &{\alpha_{11}} &{\alpha_{12}} &{\alpha_{13}} &{\alpha_{14}} & {\alpha_{15}} \\
{0} & {0} &{0} &{1} &{0} &{0} &{1} &{0} &{0} &{0} &{1} &{0} &{0} &{1} &{0} & {0} \\
\end{array}
$$

which translates into the decimal number

$$
2^3+2^6+2^{10}+2^{13}=9288.
$$

We can thus encode a Slater determinant as a bit pattern.

## Operators in second quantization
With $N$ particles that can be distributed over $n$ single-particle states, the total number of Slater determinats (and defining thereby the dimensionality of the system) is

$$
\mathrm{dim}(\mathcal{H}) = \left(\begin{array}{c} n \\N\end{array}\right).
$$

The total number of bit patterns is $2^n$.

## Operators in second quantization
We assume again that we have at our disposal $n$ different single-particle orbits
$\alpha_0,\alpha_2,\dots,\alpha_{n-1}$ and that we can distribute  among these orbits $N\le n$ particles.
The ordering among these states is important as it defines the order of the creation operators.
We will write the determinant

$$
\Phi_{\Lambda} = a_{\alpha_3}^{\dagger} a_{\alpha_6}^{\dagger} a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle,
$$

in a more compact way as

$$
\Phi_{3,6,10,13} = |0001001000100100\rangle.
$$

The action of a creation operator is thus

$$
a^{\dagger}_{\alpha_4}\Phi_{3,6,10,13} = a^{\dagger}_{\alpha_4}|0001001000100100\rangle=a^{\dagger}_{\alpha_4}a_{\alpha_3}^{\dagger} a_{\alpha_6}^{\dagger} a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle,
$$

which becomes

$$
-a_{\alpha_3}^{\dagger} a^{\dagger}_{\alpha_4} a_{\alpha_6}^{\dagger} a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle=-|0001101000100100\rangle.
$$

## Operators in second quantization
Similarly

$$
a^{\dagger}_{\alpha_6}\Phi_{3,6,10,13} = a^{\dagger}_{\alpha_6}|0001001000100100\rangle=a^{\dagger}_{\alpha_6}a_{\alpha_3}^{\dagger} a_{\alpha_6}^{\dagger} a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle,
$$

which becomes

$$
-a^{\dagger}_{\alpha_4} (a_{\alpha_6}^{\dagger})^ 2 a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle=0!
$$

This gives a simple recipe:
* If one of the bits $b_j$ is $1$ and we act with a creation operator on this bit, we return a null vector

* If $b_j=0$, we set it to $1$ and return a sign factor $(-1)^l$, where $l$ is the number of bits set before bit $j$.

## Operators in second quantization
Consider the action of $a^{\dagger}_{\alpha_2}$ on various slater determinants:

$$
\begin{array}{ccc}
a^{\dagger}_{\alpha_2}\Phi_{00111}& = a^{\dagger}_{\alpha_2}|00111\rangle&=0\times |00111\rangle\\
a^{\dagger}_{\alpha_2}\Phi_{01011}& = a^{\dagger}_{\alpha_2}|01011\rangle&=(-1)\times |01111\rangle\\
a^{\dagger}_{\alpha_2}\Phi_{01101}& = a^{\dagger}_{\alpha_2}|01101\rangle&=0\times |01101\rangle\\
a^{\dagger}_{\alpha_2}\Phi_{01110}& = a^{\dagger}_{\alpha_2}|01110\rangle&=0\times |01110\rangle\\
a^{\dagger}_{\alpha_2}\Phi_{10011}& = a^{\dagger}_{\alpha_2}|10011\rangle&=(-1)\times |10111\rangle\\
a^{\dagger}_{\alpha_2}\Phi_{10101}& = a^{\dagger}_{\alpha_2}|10101\rangle&=0\times |10101\rangle\\
a^{\dagger}_{\alpha_2}\Phi_{10110}& = a^{\dagger}_{\alpha_2}|10110\rangle&=0\times |10110\rangle\\
a^{\dagger}_{\alpha_2}\Phi_{11001}& = a^{\dagger}_{\alpha_2}|11001\rangle&=(+1)\times |11101\rangle\\
a^{\dagger}_{\alpha_2}\Phi_{11010}& = a^{\dagger}_{\alpha_2}|11010\rangle&=(+1)\times |11110\rangle\\
\end{array}
$$

What is the simplest way to obtain the phase when we act with one annihilation(creation) operator
on the given Slater determinant representation?

## Operators in second quantization
We have an SD representation

$$
\Phi_{\Lambda} = a_{\alpha_0}^{\dagger} a_{\alpha_3}^{\dagger} a_{\alpha_6}^{\dagger} a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle,
$$

in a more compact way as

$$
\Phi_{0,3,6,10,13} = |1001001000100100\rangle.
$$

The action of

$$
a^{\dagger}_{\alpha_4}a_{\alpha_0}\Phi_{0,3,6,10,13} = a^{\dagger}_{\alpha_4}|0001001000100100\rangle=a^{\dagger}_{\alpha_4}a_{\alpha_3}^{\dagger} a_{\alpha_6}^{\dagger} a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle,
$$

which becomes

$$
-a_{\alpha_3}^{\dagger} a^{\dagger}_{\alpha_4} a_{\alpha_6}^{\dagger} a_{\alpha_{10}}^{\dagger} a_{\alpha_{13}}^{\dagger} |0\rangle=-|0001101000100100\rangle.
$$

## Operators in second quantization
The action

$$
a_{\alpha_0}\Phi_{0,3,6,10,13} = |0001001000100100\rangle,
$$

can be obtained by subtracting the logical sum (AND operation) of $\Phi_{0,3,6,10,13}$ and
a word which represents only $\alpha_0$, that is

$$
|1000000000000000\rangle,
$$

from $\Phi_{0,3,6,10,13}= |1001001000100100\rangle$.

This operation gives $|0001001000100100\rangle$.

Similarly, we can form $a^{\dagger}_{\alpha_4}a_{\alpha_0}\Phi_{0,3,6,10,13}$, say, by adding
$|0000100000000000\rangle$ to $a_{\alpha_0}\Phi_{0,3,6,10,13}$, first checking that their logical sum
is zero in order to make sure that orbital $\alpha_4$ is not already occupied.

## Operators in second quantization
It is trickier however to get the phase $(-1)^l$.
One possibility is as follows
* Let $S_1$ be a word that represents the $1-$bit to be removed and all others set to zero.

In the previous example $S_1=|1000000000000000\rangle$
* Define $S_2$ as the similar word that represents the bit to be added, that is in our case

$S_2=|0000100000000000\rangle$.
* Compute then $S=S_1-S_2$, which here becomes

$$
S=|0111000000000000\rangle
$$

* Perform then the logical AND operation of $S$ with the word containing

$$
\Phi_{0,3,6,10,13} = |1001001000100100\rangle,
$$

which results in $|0001000000000000\rangle$. Counting the number of $1-$bits gives the phase.  Here you need however an algorithm for bitcounting. Several efficient ones available.

## Exercises
**Exercise 1.**

This exercise serves to convince you about the relation between
two different single-particle bases, where one could be our new Hartree-Fock basis and the other a harmonic oscillator basis.

Consider a Slater determinant built up of single-particle orbitals $\psi_{\lambda}$,
with $\lambda = 1,2,\dots,A$. The unitary transformation

$$
\psi_a  = \sum_{\lambda} C_{a\lambda}\phi_{\lambda},
$$

brings us into the new basis.
The new basis has quantum numbers $a=1,2,\dots,A$.
Show that the new basis is orthonormal.
Show that the new Slater determinant constructed from the new single-particle wave functions can be
written as the determinant based on the previous basis and the determinant of the matrix $C$.
Show that the old and the new Slater determinants are equal up to a complex constant with absolute value unity.
(Hint, $C$ is a unitary matrix).

Starting with the second quantization representation of the Slater determinant

$$
\Phi_{0}=\prod_{i=1}^{n}a_{\alpha_{i}}^{\dagger}|0\rangle,
$$

use Wick's theorem to compute the normalization integral
$\langle\Phi_{0}|\Phi_{0}\rangle$.

## Exercises
**Exercise 2.**

Calculate the matrix elements

$$
\langle \alpha_{1}\alpha_{2}|\hat{F}|\alpha_{1}\alpha_{2}\rangle
$$

and

$$
\langle \alpha_{1}\alpha_{2}|\hat{G}|\alpha_{1}\alpha_{2}\rangle
$$

with

1
8
6

<
<
<
!
!
M
A
T
H
_
B
L
O
C
K

1
8
7

<
<
<
!
!
M
A
T
H
_
B
L
O
C
K

1
8
8

<
<
<
!
!
M
A
T
H
_
B
L
O
C
K

$$
\hat{G} = \frac{1}{2}\sum_{\alpha\beta\gamma\delta}
\langle \alpha\beta |\hat{g}|\gamma\delta\rangle
a_{\alpha}^{\dagger}a_{\beta}^{\dagger}a_{\delta}a_{\gamma} ,
$$

and

$$
\langle \alpha\beta |\hat{g}|\gamma\delta\rangle=
\int\int \psi_{\alpha}^{*}(x_{1})\psi_{\beta}^{*}(x_{2})g(x_{1},
x_{2})\psi_{\gamma}(x_{1})\psi_{\delta}(x_{2})dx_{1}dx_{2}
$$

Compare these results with those from exercise 3c).

## Exercises
**Exercise 3.**

Show that the onebody part of the Hamiltonian

$$
\hat{H}_0 = \sum_{pq} \langle p|\hat{h}_0|q\rangle a^{\dagger}_p a_q,
$$

can be written, using standard annihilation and creation operators, in normal-ordered form as

$$
\hat{H}_0 = \sum_{pq} \langle p|\hat{h}_0|q\rangle \left\{a^\dagger_p a_q\right\} +
             \sum_i \langle i|\hat{h}_0|i\rangle.
$$

Explain the meaning of the various symbols. Which reference
vacuum has been used?

## Exercises
**Exercise 4.**

Show that the twobody part of the Hamiltonian

$$
\hat{H}_I = \frac{1}{4} \sum_{pqrs} \langle pq|\hat{v}|rs\rangle a^\dagger_p a^\dagger_q a_s  a_r,
$$

can be written, using standard annihilation and creation operators, in normal-ordered form as

$$
\hat{H}_I =\frac{1}{4} \sum_{pqrs} \langle pq|\hat{v}|rs\rangle \left\{a^\dagger_p a^\dagger_q a_s  a_r\right\}
            + \sum_{pqi} \langle pi|\hat{v}|qi\rangle \left\{a^\dagger_p a_q\right\}
            + \frac{1}{2} \sum_{ij}\langle ij|\hat{v}|ij\rangle.
$$

Explain again the meaning of the various symbols.

This exercise is optional: Derive the normal-ordered form of the threebody part of the Hamiltonian.

$$
\hat{H}_3 = \frac{1}{36} \sum_{\substack{pqr \\ stu}}
                 \langle pqr|\hat{v}_3|stu\rangle a^\dagger_p a^\dagger_q a^\dagger_r a_u a_t a_s,
$$

and specify the contributions to the twobody, onebody and the scalar part.

## Exercises
**Exercise 5.**

The aim of this exercise is to set up specific matrix elements that will turn useful when we start our discussions of the nuclear shell model. In particular you will notice, depending on the character of the operator, that many matrix elements will actually be zero.

Consider three $N$-particle  Slater determinants  $|\Phi_0$, $|\Phi_i^a\rangle$ and $|\Phi_{ij}^{ab}\rangle$, where the notation means that
Slater determinant $|\Phi_i^a\rangle$ differs from $|\Phi_0\rangle$ by one single-particle state, that is a single-particle
state $\psi_i$ is replaced by a single-particle state $\psi_a$.
It is often interpreted as a so-called one-particle-one-hole excitation.
Similarly, the Slater determinant $|\Phi_{ij}^{ab}\rangle$
differs by two single-particle states from $|\Phi_0\rangle$ and is normally thought of as a two-particle-two-hole excitation.
We assume also that $|\Phi_0\rangle$ represents our new vacuum reference state
and the labels $ijk\dots$ represent single-particle states below the Fermi level and $abc\dots$ represent states above the Fermi level, so-called particle states.
We define thereafter a general onebody normal-ordered (with respect to the new vacuum state) operator
as

$$
\hat{F}_N=\sum_{pq}\langle p |f |\beta\rangle \left\{a_{p}^{\dagger}a_{q}\right\}  ,
$$

with

$$
\langle p |f| q\rangle=\int \psi_{p}^{*}(x)f(x)\psi_{q}(x)dx ,
$$

and a general normal-ordered two-body operator

$$
\hat{G}_N = \frac{1}{4}\sum_{pqrs}
\langle pq |g| rs\rangle_{AS} \left\{a_{p}^{\dagger}a_{q}^{\dagger}a_{s}a_{r}\right\} ,
$$

with for example the direct matrix element given as

$$
\langle pq |g| rs\rangle=
\int\int \psi_{p}^{*}(x_{1})\psi_{q}^{*}(x_{2})g(x_{1}, x_{2})\psi_{r}(x_{1})\psi_{s}(x_{2})dx_{1}dx_{2}
$$

with $g$ being invariant under the interchange of the coordinates of two particles.
The single-particle states $\psi_i$ are not necessarily eigenstates of $\hat{f}$.  The curly brackets mean that the operators are normal-ordered with respect to the new vacuum reference state.

How would you write the above Slater determinants in a second quantization formalism, utilizing the fact that we have defined a new reference state?

Use thereafter Wick's theorem to find the expectation values of

$$
\langle \Phi_0 \vert\hat{F}_N\vert\Phi_0\rangle,
$$

and

$$
\langle \Phi_0\hat{G}_N|\Phi_0\rangle.
$$

Find thereafter

$$
\langle \Phi_0 |\hat{F}_N|\Phi_i^a\rangle,
$$

and

$$
\langle \Phi_0|\hat{G}_N|\Phi_i^a\rangle,
$$

Finally, find

$$
\langle \Phi_0 |\hat{F}_N|\Phi_{ij}^{ab}\rangle,
$$

and

$$
\langle \Phi_0|\hat{G}_N|\Phi_{ij}^{ab}\rangle.
$$

What happens with the two-body operator if we have a transition probability  of the type

$$
\langle \Phi_0|\hat{G}_N|\Phi_{ijk}^{abc}\rangle,
$$

where the Slater determinant to the right of the operator differs by more than two single-particle states?

## Exercises
**Exercise 6.**

Write a program which sets up all possible Slater determinants given $N=4$ eletrons which can occupy
the atomic single-particle states defined by the $1s$, $2s2p$ and $3s3p3d$ shells. How many single-particle
states $n$ are there in total?  Include the spin degrees of freedom as well.
We include here a python program which may aid in this direction. It uses bit manipulation functions from <http://wiki.python.org/moin/BitManipulation>.

```
import math

"""
A simple Python class for Slater determinant manipulation
Bit-manipulation stolen from:

http://wiki.python.org/moin/BitManipulation
"""

# bitCount() counts the number of bits set (not an optimal function)

def bitCount(int_type):
    """ Count bits set in integer """
    count = 0
    while(int_type):
        int_type &= int_type - 1
        count += 1
    return(count)

# testBit() returns a nonzero result, 2**offset, if the bit at 'offset' is one.

def testBit(int_type, offset):
    mask = 1 << offset
    return(int_type & mask) >> offset

# setBit() returns an integer with the bit at 'offset' set to 1.

def setBit(int_type, offset):
    mask = 1 << offset
    return(int_type | mask)

# clearBit() returns an integer with the bit at 'offset' cleared.

def clearBit(int_type, offset):
    mask = ~(1 << offset)
    return(int_type & mask)

# toggleBit() returns an integer with the bit at 'offset' inverted, 0 -> 1 and 1 -> 0.

def toggleBit(int_type, offset):
    mask = 1 << offset
    return(int_type ^ mask)

# binary string made from number

def bin0(s):
    return str(s) if s<=1 else bin0(s>>1) + str(s&1)

def bin(s, L = 0):
    ss = bin0(s)
    if L > 0:
        return '0'*(L-len(ss)) + ss
    else:
        return ss

class Slater:
    """ Class for Slater determinants """
    def __init__(self):
        self.word = int(0)

    def create(self, j):
        print "c^+_" + str(j) + " |" + bin(self.word) + ">  = ",
        # Assume bit j is set, then we return zero.
        s = 0
        # Check if bit j is set.
        isset = testBit(self.word, j)
        if isset == 0:
            bits = bitCount(self.word & ((1<<j)-1))
            s = pow(-1, bits)
            self.word = setBit(self.word, j)

        print str(s) + " x |" + bin(self.word) + ">"
        return s

    def annihilate(self, j):
        print "c_" + str(j) + " |" + bin(self.word) + ">  = ",
        # Assume bit j is not set, then we return zero.
        s = 0
        # Check if bit j is set.
        isset = testBit(self.word, j)
        if isset == 1:
            bits = bitCount(self.word & ((1<<j)-1))
            s = pow(-1, bits)
            self.word = clearBit(self.word, j)

        print str(s) + " x |" + bin(self.word) + ">"
        return s

# Do some testing:

phi = Slater()
phi.create(0)
phi.create(1)
phi.create(2)
phi.create(3)

print

s = phi.annihilate(2)
s = phi.create(7)
s = phi.annihilate(0)
s = phi.create(200)
```

## Exercises: Using sympy to compute matrix elements
**Exercise 7.**

Compute the matrix element

$$
\langle\alpha_{1}\alpha_{2}\alpha_{3}|\hat{G}|\alpha_{1}'\alpha_{2}'\alpha_{3}'\rangle,
$$

using Wick's theorem and express the two-body operator
$G$ in the occupation number (second quantization)
representation.

## Exercises: Using sympy to compute matrix elements
The last exercise can be solved using the symbolic Python package called *SymPy*. SymPy is a Python
package for general purpose symbolic algebra. There is a physics module with several interesting submodules.
Among these, the submodule called *secondquant*, contains several  functionalities that allow us to test
our algebraic manipulations using Wick's theorem and operators for second quantization.

```
from sympy import *
from sympy.physics.secondquant import *

i, j = symbols('i,j', below_fermi=True)
a, b = symbols('a,b', above_fermi=True)
p, q = symbols('p,q')
print simplify(wicks(Fd(i)*F(a)*Fd(p)*F(q)*Fd(b)*F(j), keep_only_fully_contracted=True))
```

The code defines single-particle states above and below the Fermi level, in addition to the genereal symbols
$pq$ which can refer to any type of state below or above the Fermi level. Wick's theorem is implemented between
the creation and annihilation operators *Fd* and *F*, respectively. Using the simplify option, one can lump together several Kronecker-$\delta$ functions.

## Exercises: Using sympy to compute matrix elements
We can expand the above Python code by defining one-body and two-body operators using  the following SymPy code

```
# This code sets up a two-body Hamiltonian for fermions
from sympy import symbols, latex, WildFunction, collect, Rational
from sympy.physics.secondquant import F, Fd, wicks, AntiSymmetricTensor, substitute_dummies, NO

# setup hamiltonian
p,q,r,s = symbols('p q r s',dummy=True)
f = AntiSymmetricTensor('f',(p,),(q,))
pr = NO((Fd(p)*F(q)))
v = AntiSymmetricTensor('v',(p,q),(r,s))
pqsr = NO(Fd(p)*Fd(q)*F(s)*F(r))
Hamiltonian=f*pr + Rational(1)/Rational(4)*v*pqsr
print "Hamiltonian defined as:", latex(Hamiltonian)
```

Here we have used the *AntiSymmetricTensor* functionality, together with normal-ordering defined by the *NO* function.
Using the *latex* option, this program produces the following output

$$
f^{p}_{q} \left\{a^\dagger_{p} a_{q}\right\} - \frac{1}{4} v^{qp}_{sr} \left\{a^\dagger_{p} a^\dagger_{q} a_{r} a_{s}\right\}
$$

## Exercises: Using sympy to compute matrix elements
We can now use this code to compute the matrix elements between two two-body Slater determinants using Wick's theorem.

```
from sympy import symbols, latex, WildFunction, collect, Rational, simplify
from sympy.physics.secondquant import F, Fd, wicks, AntiSymmetricTensor, substitute_dummies, NO, evaluate_deltas
# setup hamiltonian
p,q,r,s = symbols('p q r s',dummy=True)
f = AntiSymmetricTensor('f',(p,),(q,))
pr = NO((Fd(p)*F(q)))
v = AntiSymmetricTensor('v',(p,q),(r,s))
pqsr = NO(Fd(p)*Fd(q)*F(s)*F(r))
Hamiltonian=f*pr + Rational(1)/Rational(4)*v*pqsr
c,d = symbols('c, d',above_fermi=True)
a,b = symbols('a, b',above_fermi=True)

expression = wicks(F(b)*F(a)*Hamiltonian*Fd(c)*Fd(d),keep_only_fully_contracted=True, simplify_kronecker_deltas=True)
expression = evaluate_deltas(expression)
expression = simplify(expression)
print "Hamiltonian defined as:", latex(expression)
```

The result is as expected,

$$
\delta_{a c} f^{b}_{d} - \delta_{a d} f^{b}_{c} - \delta_{b c} f^{a}_{d} + \delta_{b d} f^{a}_{c} + v^{ab}_{cd}.
$$

## Exercises: Using sympy to compute matrix elements
We can continue along these lines and define a normal-ordered Hamiltonian with respect to a given reference state.
In our first step we just define the Hamiltonian

```
from sympy import symbols, latex, WildFunction, collect, Rational, simplify
from sympy.physics.secondquant import F, Fd, wicks, AntiSymmetricTensor, substitute_dummies, NO, evaluate_deltas
# setup hamiltonian
p,q,r,s = symbols('p q r s',dummy=True)
f = AntiSymmetricTensor('f',(p,),(q,))
pr = Fd(p)*F(q)
v = AntiSymmetricTensor('v',(p,q),(r,s))
pqsr = Fd(p)*Fd(q)*F(s)*F(r)
#define the Hamiltonian
Hamiltonian = f*pr + Rational(1)/Rational(4)*v*pqsr
#define indices for states above and below the Fermi level
index_rule = {
     'below':  'kl',
     'above':  'cd',
     'general': 'pqrs'
     }
Hnormal = substitute_dummies(Hamiltonian,new_indices=True, pretty_indices=index_rule)
print "Hamiltonian defined as:", latex(Hnormal)
```

which results in

$$
f^{q}_{p} a^\dagger_{q} a_{p} + \frac{1}{4} v^{sr}_{qp} a^\dagger_{s} a^\dagger_{r} a_{p} a_{q}
$$

## Exercises: Using sympy to compute matrix elements
In our next step we define the reference energy $E_0$ and redefine the Hamiltonian by subtracting the reference energy and collecting the coefficients for all normal-ordered products (given by the *NO* function).

```
from sympy import symbols, latex, WildFunction, collect, Rational, simplify
from sympy.physics.secondquant import F, Fd, wicks, AntiSymmetricTensor, substitute_dummies, NO, evaluate_deltas
# setup hamiltonian
p,q,r,s = symbols('p q r s',dummy=True)
f = AntiSymmetricTensor('f',(p,),(q,))
pr = Fd(p)*F(q)
v = AntiSymmetricTensor('v',(p,q),(r,s))
pqsr = Fd(p)*Fd(q)*F(s)*F(r)
#define the Hamiltonian
Hamiltonian=f*pr + Rational(1)/Rational(4)*v*pqsr
#define indices for states above and below the Fermi level
index_rule = {
     'below':  'kl',
     'above':  'cd',
     'general': 'pqrs'
     }
Hnormal = substitute_dummies(Hamiltonian,new_indices=True, pretty_indices=index_rule)
E0 = wicks(Hnormal,keep_only_fully_contracted=True)
Hnormal = Hnormal-E0
w = WildFunction('w')
Hnormal = collect(Hnormal, NO(w))
Hnormal = evaluate_deltas(Hnormal)
print latex(Hnormal)
```

which gives us

$$
- f^{i}_{i} + f^{q}_{p} a^\dagger_{q} a_{p} - \frac{1}{4} v^{ii}_{ii} - \frac{1}{4} v^{ii}_{ii} + \frac{1}{4} v^{sr}_{qp} a^\dagger_{r} a^\dagger_{s} a_{q} a_{p},
$$

again as expected, with the reference energy to be subtracted.

## Exercises: Using sympy to compute matrix elements
We can now go back to exercise 7 and define the Hamiltonian and the second-quantized representation of a  three-body Slater determinant.

```
from sympy import symbols, latex, WildFunction, collect, Rational, simplify
from sympy.physics.secondquant import F, Fd, wicks, AntiSymmetricTensor, substitute_dummies, NO, evaluate_deltas
# setup hamiltonian
p,q,r,s = symbols('p q r s',dummy=True)

v = AntiSymmetricTensor('v',(p,q),(r,s))
pqsr = NO(Fd(p)*Fd(q)*F(s)*F(r))
Hamiltonian=Rational(1)/Rational(4)*v*pqsr
a,b,c,d,e,f = symbols('a,b, c, d, e, f',above_fermi=True)

expression = wicks(F(c)*F(b)*F(a)*Hamiltonian*Fd(d)*Fd(e)*Fd(f),keep_only_fully_contracted=True, simplify_kronecker_deltas=True)
expression = evaluate_deltas(expression)
expression = simplify(expression)
print latex(expression)
```

resulting in nine terms (as expected),

$$
- \delta_{a d} v^{cb}_{ef} - \delta_{a e} v^{cb}_{fd} + \delta_{a f} v^{cb}_{ed} - \delta_{b d} v^{ac}_{ef} - \delta_{b e} v^{ac}_{fd} + \delta_{b f} v^{ac}_{ed} + \delta_{c d} v^{ab}_{ef} + \delta_{c e} v^{ab}_{fd} - \delta_{c f} v^{ab}_{ed}
$$

## Exercises: Derivation of Hartree-Fock equations
**Exercise 8.**

What is the diagrammatic representation of the HF equation?

$$
-\langle\alpha_{k}|u^{HF}|\alpha_{i}\rangle+\sum_{j=1}^{n}
\left[\langle\alpha_{k}\alpha_{j}|\hat{v}|\alpha_{i}\alpha_{j}\rangle-
\langle\alpha_{k}\alpha_{j}|v|\alpha_{j}\alpha_{i}\rangle\right]=0
$$

(Represent $(-u^{HF})$ by the symbol $---$X .)

## Exercises: Derivation of Hartree-Fock equations
**Exercise 9.**

Consider the ground state $|\Phi\rangle$
of a bound many-particle system of fermions. Assume that we remove one particle
from the single-particle state $\lambda$ and that our system ends in a new state
$|\Phi_{n}\rangle$.
Define the energy needed to remove this particle as

$$
E_{\lambda}=\sum_{n}\vert\langle\Phi_{n}|a_{\lambda}|\Phi\rangle\vert^{2}(E_{0}-E_{n}),
$$

where $E_{0}$ and $E_{n}$  are the ground state energies of the states
$|\Phi\rangle$  and  $|\Phi_{n}\rangle$, respectively.
 * Show that

$$
E_{\lambda}=\langle\Phi|a_{\lambda}^{\dagger}\left[
a_{\lambda},H \right]|\Phi\rangle,
$$

where $H$ is the Hamiltonian of this system.
 * If we assume that $\Phi$ is the  Hartree-Fock result, find the

relation between $E_{\lambda}$ and the single-particle energy
$\varepsilon_{\lambda}$
for states $\lambda \leq F$ and $\lambda >F$, with

$$
\varepsilon_{\lambda}=\langle\lambda|\hat{t}+\hat{u}|\lambda\rangle,
$$

and

$$
\langle\lambda|\hat{u}|\lambda\rangle=\sum_{\beta \leq F}
\langle\lambda\beta|\hat{v}|\lambda\beta\rangle.
$$

We have assumed an antisymmetrized matrix element here.
Discuss the result.

The Hamiltonian operator is defined as

$$
H=\sum_{\alpha\beta}\langle\alpha|\hat{t}|\beta\rangle a_{\alpha}^{\dagger}a_{\beta}+
\frac{1}{2}\sum_{\alpha\beta\gamma\delta}\langle\alpha\beta|\hat{v}|\gamma\delta\rangle a_{\alpha}^{\dagger}a_{\beta}^{\dagger}a_{\delta}a_{\gamma}.
$$


```python
%matplotlib inline
from IPython.display import display,Math
from sympy import *
init_session()
```

```python
from ipywidgets import interact
from ipywidgets import interact,Dropdown,IntSlider
D = 24
@interact
def _(n="0",d=IntSlider(value=1,min=1,max=D,step=1)):
    n = eval(n)
    nb = bin(n)[2:]
    nb1 = nb[0:-d] # オーバーフロー分
    nb2 = nb[-d:]  # 残り
    n2 = bin(n%(2**d))[2:]
    n2len = len(str(n2))
    n2str = '0'*(d-n2len) + n2
    return display(Math("{0:d} = \\color{{red}}{{{1:s} }}\\color{{blue}}{{{2:s} }}_2\\rightarrow {3:s}_2 = {4:d} \quad({5:d}ビット)".format(n,nb1,nb2,n2str,n%(2**d),d)))
```

```python
m = 10.5
m10 = str(m) # 表示用
m_int = int(m) # 整数部
m_rest = m-m_int # 小数部
m_str = bin(m_int)[2:] # 整数部表示用
if m_rest > 0: # 小数あり
    M = 5 # 最大小数桁数
    k = 0
    m_str += "."
    while (k<M) and (m_rest>0):
        m_rest *= 2
        if m_rest >= 1:
            m_str += "1"
            m_rest -= 1
        else:
            m_str += "0"
        k+=1
if m_rest == 0: # 厳密値かどうか
    display(Math("{0:s}={1:s}_{{ 2 }}".format(m10,m_str)))
else:
    display(Math("{0:s}\\fallingdotseq{1:s}_{{ 2 }}".format(m10,m_str)))

```

```python
from ipywidgets import interact
from ipywidgets import interact,Dropdown,IntSlider
D=1
M=15
@interact
def _(m=(0,D,0.01)):
    m10 = str(m) # 表示用
    m_int = int(m) # 整数部
    m_rest = m-m_int # 小数部
    m_str = bin(m_int)[2:] # 整数部表示用
    if m_rest > 0: # 小数あり
        k = 0
        m_str += "."
        while (k<M) and (m_rest>0):
            m_rest *= 2
            if m_rest >= 1:
                m_str += "1"
                m_rest -= 1
            else:
                m_str += "0"
            k+=1
    if m_rest == 0: # 厳密値かどうか
        return display(Math("{0:s}={1:s}_{{ 2 }}".format(m10,m_str)))
    else:
        return display(Math("{0:s}\\fallingdotseq{1:s}_{{ 2 }}".format(m10,m_str)))

    return display(Math("{0:d} = \\color{{red}}{{{1:s} }}\\color{{blue}}{{{2:s} }}_2\\rightarrow {3:s}_2 = {4:d} \quad({5:d}ビット)".format(n,nb1,nb2,n2str,n%(2**d),d)))

```

```python
from ipywidgets import interact,Dropdown,IntSlider
from IPython.display import HTML
@interact
def _(r=(0,255,1),g=(0,255,1),b=(0,255,1)):
    clist = [hex(r)[2:],hex(g)[2:],hex(b)[2:]]
    color = ""
    for chex in clist:
        if len(chex) < 2:
            color += "0"
        color += chex
    return HTML('<font size=4 color="#{0:s}">この色は {0:s} に対応する色です．</font>'.format(color))
```

```python

```


# OSCR preconditioned high-frequency scattering

### Background

*Please note that this notebook is adjusted for larger workstations. To run it on a small laptop adjust the wavenumber parameter ``k`` to a very small value (e.g. ``k = 5``).*

A typical application for BEM is the high-frequency scattering of an incoming wave $u^\text{inc}$ from a sound-hard obstacle $\Omega$.

Consider the exterior Helmholtz problem:

$$
\begin{align}
\Delta u^\text{+} + k^2u^\text{+} &= 0,\quad\text{in }\Omega^\text{+}\\
\frac{\partial u^\text{+}}{\partial\nu} &= -\frac{\partial u^\text{inc}}{\partial\nu},\quad\text{on }\Gamma\\
\lim_{|\mathbf{x}|\rightarrow+\infty}|\mathbf{x}|\left(\nabla u^\text{+}\cdot \frac{\mathbf{x}}{|\mathbf{x}|}-\mathrm{i}ku^\text{+}\right)&=0
\end{align}
$$

Here, $u^+$ is the scattered field, and hence the total field is $u = u^\text{+}+u^{inc}$. The scattered field $u^\text{+}$ can be
represented as
$$
u^{+} = \mathcal{K}\phi,
$$
where $\mathcal{K}$ is the double layer potential operator defined by
$$
\left[\mathcal{K}\phi\right](\mathbf{x}) = \int_{\Gamma}g(\mathbf{x},\mathbf{y})\phi(\mathbf{y})\mathrm{d}\mathbf{y}
$$
with $g(\mathbf{x},\mathbf{y}) = \frac{\mathrm{e}^{\mathrm{i}k|\mathbf{x}-\mathbf{y}|}}{4\pi|\mathbf{x}-\mathbf{y}|}$. Here, $\phi=\gamma_0u$ is the Dirichlet trace of the total field.

The Burton–Miller formulation to compute $\phi$ is given by
$$
\left(\tfrac{1}{2}\mathsf{Id}-\mathsf{K}+\eta\mathsf{W}\right)\phi = \gamma_0 u^\text{inc}+\eta \gamma_1u^\text{inc}
$$
for some $\eta\neq 0$. Here, $\mathsf{Id}$, $\mathsf{K}$ and $\mathsf{W}$ are the identity, double layer and hypersingular boundary operators.

A perfect choice for $\eta$ is the exterior Neumann-to-Dirichlet map $\mathsf{NtD}$ with the property
$$
\tfrac{1}{2}\mathsf{Id}-\mathsf{K}-\mathsf{NtD}\circ\mathsf{W} = \mathsf{Id}.
$$
However, this is a complicated non-local operator.  The idea of OSRC is to use the pseudodifferential operator approximation
$$
\mathsf{NtD}\approx \frac{1}{\mathrm{i}k}\left(1+\frac{\Delta_{\Gamma}}{(k+\mathrm{i}\epsilon)^2}\right)^{-\frac{1}{2}}
$$
for a regularization parameter $\epsilon>0$ and to localize the squareroot operator by a Padé approximation. Details of this OSRC preconditioning are given in Antoine & Darbase (2007).

Bempp implements approximate Dirichlet-to-Neumann and Neumann-to-Dirichlet maps. This notebook demonstrates how to use these for high-frequency scattering computations.

### Implementation

In the following we implement an OSRC Burton–Miller formulation for high-frequency scattering. We start with the usual imports.

```python
import bempp.api
import numpy as np
```

The following defines the wavenumber k and the Dirichlet and Neumann data of the incident plane wave.

```python
k = 20

def dirichlet_fun(x, n, domain_index, result):
    result[0] = np.exp(1j * k * x[0])

def neumann_fun(x, n, domain_index, result):
    result[0] = 1j * k * n[0] * np.exp(1j * k * x[0])
```

For this example we will use an elongated ellipsoid. The element size is chosen to roughly correspond to 10 elements per wavelength. The function space consists of continuous, piecewise linear basis functions. The OSRC preconditioner only works for continuous function spaces as it assembles a Laplace–Beltrami operator.

```python
h = 2*np.pi/(10 * k)
grid = bempp.api.shapes.ellipsoid(3, 1, 1, h=h)
space = bempp.api.function_space(grid, "P", 1)
print("The space has {0} dofs".format(space.global_dof_count))
```

    The space has 2477 dofs

We can now form the Burton–Miller operator.

```python
identity = bempp.api.operators.boundary.sparse.identity(
    space, space, space)
dlp = bempp.api.operators.boundary.helmholtz.double_layer(
    space, space, space, k)
hyp = bempp.api.operators.boundary.helmholtz.hypersingular(
    space, space, space, k, use_slp=True)
ntd = bempp.api.operators.boundary.helmholtz.osrc_ntd(space, k)

burton_miller = .5 * identity - dlp - ntd * hyp
```

In the above operator assembly we were allowed to directly multiply operators. Bempp automatically assembles the correct mass matrix transformations for this product to make sense. For the assembly of the hypersingular operator we used the parameter ``use_slp=True``. This will cause the hypersingular operatorto be assembled in terms of an underlying Helmholtz single layer operator. This approach takes more memory but the H-matrix assembly is significantly faster.

We next assemble the right-hand side.

```python
dirichlet_grid_fun = bempp.api.GridFunction(space, fun=dirichlet_fun)
neumann_grid_fun = bempp.api.GridFunction(space, fun=neumann_fun)
rhs_fun = dirichlet_grid_fun - ntd * neumann_grid_fun
```

We can now solve the Burton–Miller formulation using GMRES. We use a strong form discretisation: this automatically performs mass matrix preconditioning.

```python
total_field, info, it_count = bempp.api.linalg.gmres(
    burton_miller, rhs_fun, use_strong_form=True,
    return_iteration_count=True)

print("The linear system was solved in {0} iterations".format(it_count))
```

    The linear system was solved in 6 iterations

We now want to plot the radar cross section in the $z=0$ plane. To compute it we use the far-field operators implemented in Bempp.

```python
%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import pylab
pylab.rcParams['figure.figsize'] = (8.0, 8.0)

theta = np.linspace(-np.pi/2, np.pi/2, 400)
points = np.array([np.cos(theta), np.sin(theta), np.zeros(len(theta))])

dlp_far_field = bempp.api.operators.far_field.helmholtz.double_layer(
    space, points, k)
far_field = dlp_far_field * total_field
max_incident = np.abs(dirichlet_grid_fun.coefficients).max()
radiation_pattern = (np.abs(far_field/max_incident)**2).ravel()
db_pattern = 10 * np.log10(4 * np.pi * radiation_pattern)

plt.polar(theta, db_pattern)
plt.title('RCS (DB)')
```


```python
# Values of a healthy heart
V = 5
Rs = 17.5
Rp = 1.79
Kr = 2.8
Kl = 1.12

# Values of a heart with heart fealure
# Rs = 6.82
# Rp = 1.36
# Kr = 4.72
# Kl = 9.5

# Values of a heart with hypertension
# Rs = 40.5
# Rp = 3.21
# Kr = 3
# Kl = 1.7
```

```python
from sympy import Symbol

# Definition of variables
Csa = Symbol('Csa')
Csv = Symbol('Csv')
Cpa = Symbol('Cpa')
Cpv = Symbol('Cpv')
```

```python
# Definition of equations
Tsa = Csa/Kr+Csa*Rs
Tsv = Csv/Kr
Tpa = Cpa/Kl+Cpa*Rp
Tpv = Cpv/Kl

Tsum = Tsa+Tsv+Tpa+Tpv
```

```python
from sympy.utilities.lambdify import lambdify

# Volumes
Vsa = Tsa*V/Tsum
Vsv = Tsv*V/Tsum
Vpa = Tpa*V/Tsum
Vpv = Tpv*V/Tsum
Vsum = Vsa+Vsv + Vpa+Vpv
Vtot = lambdify((Csa,Csv,Cpa,Cpv),
            Vsum)
```

```python
# Pressures
Psa = Tsa*V/ (Csa*Tsum)
Psv = Tsv*V/ (Csv*Tsum)
Ppa = Tpa*V/ (Cpa*Tsum)
Ppv = Tpv*V/ (Cpv*Tsum)
```

```python
from sympy.utilities.lambdify import lambdify
# Objective Function
f_obj = V/(Tsum)
f = lambdify((Csa, Csv, Cpa, Cpv), f_obj)
```

```python
from sympy.tensor.array import derive_by_array

# Partial derivatives of objective function
partial = derive_by_array(f_obj, (Csa, Csv, Cpa, Cpv))
grad = lambdify((Csa, Csv, Cpa, Cpv),
            partial)
```

```python
# Tolerance - num iterations
# tol = 0.001
n = 10000

# Start seed for the random function
# np.random.seed(1)
```

```python
import numpy as np

# Generate random values for init Cpa, Cpv, Csa, Csv
x = np.random.rand(4)

min_val = 5000000
min_x = x
```

```python
while(n > 0):
    # Check all x are positive
    for val in x:
        if val < 0:
            val = abs(val)

    # Check the volume restriction
    act_v = Vtot(x[0],x[1],x[2],x[3])

    if act_v != V:
        y = V*np.ones(4)
        diff = np.abs(np.subtract(x,y))
        val, idx = min((val,idx) for (idx,val) in enumerate(diff))
        x[idx] = val

    # Calculate gradient given the points
    g = grad(x[0],x[1],x[2],x[3])

    # Calculate the value of the objective function
    act = f(x[0],x[1],x[2],x[3])

    if(act< min_val):
        min_val = act
        min_x = x

    # Modify the actual value depending the gradient
    val, idx = max((val, idx) for (idx, val) in enumerate(g))
    x[idx] = abs(x[idx]+val)
    n = n - 1

print(' Csa: {} \n Csv: {} \n Cpa: {} \n Cpv: {} \n'.format(
          min_x[0], min_x[1], min_x[2], min_x[3]))

```

     Csa: 0.7830958927947904
     Csv: 0.00029997638464297934
     Cpa: 0.4825289899818529
     Cpv: 0.2756002171370858

```python

```