\label{sec:eo}

\subsection{HMC Update}

In this section we describe how even/odd
\cite{DeGrand:1990dk,Jansen:1997yt} preconditioning can be used in the
HMC algorithm in 
presence of a twisted mass term. Even/odd preconditioning is
implemented in the tmLQCD package in the HMC algorithm as well as in
the inversion of the Dirac operator, and can be used optionally.

We start with the lattice fermion action in the hopping parameter
representation in the $\chi$-basis written as
\begin{equation}
  \label{eq:eo0}
    \begin{split}
    S[\chi,\bar\chi,U] = \sum_x & \Biggl\{ \bar\chi(x)[1+2i \kappa\mu\gamma_5\tau^3]\chi(x)  \Bigr. \\
    & -\kappa\bar\chi(x)\sum_{\mu = 1}^4\Bigl[ U(x,\mu)(r+\gamma_\mu)\chi(x+a\hat\mu)\bigr. \\
    & +\Bigl. \bigl. U^\dagger(x-a\hat\mu,\mu)(r-\gamma_\mu)\chi(x-a\hat\mu)\Bigr]
    \Biggr\} \\
    \equiv &\sum_{x,y}\bar\chi(x) M_{xy}\chi(y)\ .
  \end{split}
\end{equation}
For convenience we define
$\tilde\mu=2\kappa\mu$. Using the matrix $M$ one can define the
hermitian (two flavor) operator:
\begin{equation}
  \label{eq:eo1}
  Q\equiv \gamma_5 M = \begin{pmatrix}
    \Qp & \\\
    & \Qm \\
  \end{pmatrix}
\end{equation}
where the sub-matrices $\Qpm$ can be factorised as follows (Schur
decomposition): 
\begin{equation}
  \label{eq:eo2}
  \begin{split}
    Q^\pm &= \gamma_5\begin{pmatrix}
      1\pm i\tilde\mu\gamma_5 & M_{eo} \\
      M_{oe}    & 1\pm i\tilde\mu\gamma_5 \\
    \end{pmatrix} =
    \gamma_5\begin{pmatrix}
      M_{ee}^\pm & M_{eo} \\
      M_{oe}    & M_{oo}^\pm \\
    \end{pmatrix} \\
    & =
    \begin{pmatrix}
      \gamma_5M_{ee}^\pm & 0 \\
      \gamma_5M_{oe}  & 1 \\
    \end{pmatrix}
    \begin{pmatrix}
      1       & (M_{ee}^\pm)^{-1}M_{eo}\\
      0       & \gamma_5(M_{oo}^\pm-M_{oe}(M_{ee}^\pm)^{-1}M_{eo})\\
    \end{pmatrix}\, .
\end{split}
\end{equation}
Note that $(M_{ee}^\pm)^{-1}$ can be
computed to be 
\begin{equation}
  \label{eq:eo3}
  (1\pm i\tilde\mu\gamma_5)^{-1} = \frac{1\mp i\tilde\mu\gamma_5}{1+\tilde\mu^2}.
\end{equation}
Using $\det(Q)=\det(\Qp)\det(\Qm)$ the following relation can be derived
\begin{equation}
  \label{eq:eo4}
  \begin{split}
    \det(\Qpm) &\propto \det(\hQpm) \\
    \hQpm &= \gamma_5(M_{oo}^\pm - M_{oe}(M_{ee}^\pm )^{-1}M_{eo})\, ,
  \end{split}
\end{equation}
where $\hQpm$ is only defined on the odd sites of the lattice. In the
HMC algorithm the determinant is stochastically estimated using pseudo
fermion field $\phi_o$: Now we write the determinant with pseudo
fermion fields:
\begin{equation}
  \begin{split}
    \det(\hQp \hQm) &= \int \mathcal{D}\phi_o\,\mathcal{D}\phi^\dagger_o\
    \exp(-S_\mathrm{PF})\\
    S_\mathrm{PF} &\equiv\ \phi_o^\dagger\ \left(\hQp\hQm\right)^{-1}\phi_o\, ,
  \end{split}
\end{equation}
where the fields $\phi_o$ are defined only on the odd sites of the
lattice. In order to compute the force corresponding to the effective
action $S_\mathrm{PF}$ we need the variation of $S_\mathrm{PF}$ with respect to the gauge fields
(using $\delta (A^{-1})=-A^{-1}\delta A A^{-1}$):
\begin{equation}
  \label{eq:eo5}
  \begin{split}
    \delta S_\mathrm{PF} &= -[\phi_o^\dagger (\hQp \hQm)^{-1}\delta \hQp(\hQp)^{-1}\phi_o +
    \phi_o^\dagger(\hQm)^{-1}\delta \hQm (\hQp \hQm)^{-1} \phi_o ] \\
     &= -[X_o^\dagger \delta \hQp Y_o + Y_o^\dagger \delta\hQm X_o]
  \end{split}
\end{equation}
with $X_o$ and $Y_o$ defined on the odd sides as 
\begin{equation}
  \label{eq:eo6}
  X_o = (\hQp \hQm)^{-1} \phi_o,\quad Y_o = (\hQp)^{-1}\phi_o=\hat
  \Qm X_o\ ,
\end{equation}
where $(\hQpm)^\dagger = \hat Q^\mp$ has been used. The variation of
$\hQpm$ reads
\begin{equation}
  \label{eq:eo7}
  \delta \hQpm = \gamma_5\left(-\delta M_{oe}(M_{ee}^\pm )^{-1}M_{eo} -
    M_{oe}(M_{ee}^\pm )^{-1}\delta M_{eo}\right),
\end{equation}
and one finds
\begin{equation}
  \label{eq:eo8}
  \begin{split}
    \delta S_\mathrm{PF} &= -(X^\dagger\delta \Qp Y + Y^\dagger\delta \Qm X) \\
    &= -(X^\dagger\delta \Qp Y +(X^\dagger\delta \Qp Y)^\dagger)
  \end{split}
\end{equation}
where $X$ and $Y$ are now defined over the full lattice as
\begin{equation}
  \label{eq:eo9}
  X = 
  \begin{pmatrix}
    -(M_{ee}^-)^{-1}M_{eo}X_o \\ X_o\\
  \end{pmatrix},\quad
  Y = 
  \begin{pmatrix}
    -(M_{ee}^+)^{-1}M_{eo}Y_o \\ Y_o\\
  \end{pmatrix}.
\end{equation}
In addition $\delta\Qp = \delta\Qm= \delta Q, M_{eo}^\dagger = \gamma_5 M_{oe}\gamma_5$ and
$M_{oe}^\dagger = \gamma_5 M_{eo}\gamma_5$ has been used. Since the bosonic part
is quadratic in the $\phi_o$ fields, the $\phi_o$ are generated at the
beginning of each molecular dynamics trajectory with
\begin{equation}
  \label{eq:eo10}
  \phi_o = \hQp R,
\end{equation}
where $R$ is a random spinor field taken from a Gaussian distribution
with norm one.

\subsubsection{Symmetric even/odd Preconditioning}

One may write instead of eq. (\ref{eq:eo2}) the following symmetrical
factorisation of $\Qpm$:
\begin{equation}
  \label{eq:sym1}
  \Qpm =
  \gamma_5\begin{pmatrix}
    M_{ee}^\pm & 0 \\
    M_{oe}  &  M_{oo}^\pm \\
  \end{pmatrix}
  \begin{pmatrix}
    1       & (M_{ee}^\pm)^{-1}M_{eo}\\
    0       & (1-(M_{oo}^\pm)^{-1} M_{oe} (M_{ee}^\pm)^{-1} M_{eo})\\
  \end{pmatrix}\, .
\end{equation}
Where we can now re-define
\begin{equation}
  \label{eq:sym2}
  \hat Q_\pm = \gamma_5(1-(M_{oo}^\pm)^{-1} M_{oe} (M_{ee}^\pm)^{-1}
  M_{eo}) 
\end{equation}
With this re-definition the procedure is analogous to what we
discussed previously. Only the vectors $X$ and $Y$ need to be modified
to  
\begin{equation}
  \begin{split}
    \label{eq:sym9}
    X &= 
    \begin{pmatrix}
      -(M_{ee}^-)^{-1}M_{eo}(M_{oo}^-)^{-1}X_o \\ X_o\\
    \end{pmatrix},\\
    Y &= 
    \begin{pmatrix}
      -(M_{ee}^+)^{-1}M_{eo}(M_{oo}^+)^{-1}Y_o \\ Y_o\\
    \end{pmatrix}.\\
  \end{split}
\end{equation}
Note that the variation of the action is still given by
\begin{equation}
  \label{eq:sym3}
  \delta S_\mathrm{PF} = -\re(X^\dagger \delta Q_+ Y)\ .
\end{equation}

\subsubsection{Mass non-degenerate flavour doublet}

Even/odd preconditioning can also be implemented for the mass
non-degenerate flavour doublet Dirac operator $D_h$
eq.~(\ref{eq:Dh}). Denoting 
\[
Q^h = \gamma_5 D_h
\]
the even/odd decomposition is as follows
\begin{equation}
  \label{eq:Dheo}
  \begin{split}
    Q^h &=
    \begin{pmatrix}
      (\gamma_5+i\bar\mu\tau^3 -\bar\epsilon\gamma_5\tau^1) & Q^h_{eo}\\
      Q^h_{oe} & (\gamma_5+i\bar\mu\tau^3 -\bar\epsilon\gamma_5\tau^1)\\
    \end{pmatrix} \\
    &=
    \begin{pmatrix}
      Q^h_{ee} & 0 \\
      Q^h_{oe} & 1 \\
    \end{pmatrix}
    \cdot
    \begin{pmatrix}
      1 & (Q^h_{ee})^{-1}Q_{eo} \\
      0 & \hat Q^h_{oo} \\
    \end{pmatrix} \\
  \end{split}
\end{equation}
where $\hat Q^h_{oo}$ is given in flavour space by
\begin{equation*}
  \hat Q^h_{oo} = \gamma_5
  \begin{pmatrix}
    1 + i\bar\mu\gamma_5 -
    \frac{M_{oe}(1-i\bar\mu\gamma_5)M_{eo}}{1+\bar\mu^2-\bar\epsilon^2} & 
    -\bar\epsilon\left(1+\frac{M_{oe}M_{eo}}{1+\bar\mu^2-\bar\epsilon^2}\right) \\
    -\bar\epsilon\left(1+\frac{M_{oe}M_{eo}}{1+\bar\mu^2-\bar\epsilon^2}\right) & 
    1 - i\bar\mu\gamma_5 -
    \frac{M_{oe}(1+i\bar\mu\gamma_5)M_{eo}}{1+\bar\mu^2-\bar\epsilon^2}\\
  \end{pmatrix}
\end{equation*}
with the previous definitions of $M_{eo}$ etc. The inplementation for
the HMC is very similar to the mass degenerate case. $\hat Q^h$ has
again a hermitian conjugate given by
\[
(\hat Q^h)^\dagger = \tau^1\ \hat Q^h\ \tau^1
\]

\subsubsection{Combining Clover and Twisted mass term} \label{sec:clover_twist}

We start again with the lattice fermion action in the hopping
parameter representation in the $\chi$-basis now including the clover
term written as
\begin{equation}
  \label{eq:eosw0}
    \begin{split}
    S[\chi,\bar\chi,U] = \sum_x & \Biggl\{ \bar\chi(x)[1+2\kappa
    c_{SW}T + 2i \kappa\mu\gamma_5\tau^3]\chi(x)  \Bigr. \\
    & -\kappa\bar\chi(x)\sum_{\mu = 1}^4\Bigl[ U(x,\mu)(r+\gamma_\mu)\chi(x+a\hat\mu)\bigr. \\
    & +\Bigl. \bigl. U^\dagger(x-a\hat\mu,\mu)(r-\gamma_\mu)\chi(x-a\hat\mu)\Bigr]
    \Biggr\} \\
    \equiv &\sum_{x,y}\bar\chi(x) M_{xy}\chi(y)\, ,
  \end{split}
\end{equation}
with the clover term $T$. For convenience we define
$\tilde\mu\equiv2\kappa\mu$ and $\tilde c_{SW} = 2\kappa
c_{SW}$. Using the matrix $M$ one can define the 
(two flavor) operator:
\begin{equation}
  \label{eq:eosw1}
  Q\equiv \gamma_5 M = \begin{pmatrix}
    \Qp & \\\
    & \Qm \\
  \end{pmatrix}
\end{equation}
where the sub-matrices $\Qpm$ can be factorised as follows (Schur
decomposition): 
\begin{equation}
  \label{eq:eosw2}
  \begin{split}
    Q^\pm &= \gamma_5\begin{pmatrix}
      1 + T_{ee} \pm i\tilde\mu\gamma_5 & M_{eo} \\
      M_{oe}    & 1 + T_{oo} \pm i\tilde\mu\gamma_5 \\
    \end{pmatrix} =
    \gamma_5\begin{pmatrix}
      M_{ee}^\pm & M_{eo} \\
      M_{oe}    & M_{oo}^\pm \\
    \end{pmatrix} \\
    & =
    \begin{pmatrix}
      \gamma_5M_{ee}^\pm & 0 \\
      \gamma_5M_{oe}  & 1 \\
    \end{pmatrix}
    \begin{pmatrix}
      1       & (M_{ee}^\pm)^{-1}M_{eo}\\
      0       & \gamma_5(M_{oo}^\pm-M_{oe}(M_{ee}^\pm)^{-1}M_{eo})\\
    \end{pmatrix}\, .
\end{split}
\end{equation}
Note that $(M_{ee}^\pm)^{-1}$ cannot be computed as easily as in the
case of Twisted mass fermions without clover term.
Using $\det(Q)=\det(\Qp)\det(\Qm)$ the following relation can be derived
\begin{equation}
  \label{eq:eosw4}
  \begin{split}
    \det(\Qpm) &\propto \det(1+T_{ee} \pm i\tilde\mu\gamma_5)\det(\hQpm) \\
    \hQpm &= \gamma_5((1 + T_{oo} \pm i\tilde\mu\gamma_5) -
             M_{oe}( 1 + T_{ee} \pm i\tilde\mu\gamma_5 )^{-1}M_{eo})\, ,
  \end{split}
\end{equation}
where $\hQpm$ is only defined on the odd sites of the lattice. In the
HMC algorithm the second determinant is stochastically estimated using
pseudo fermion fields $\phi_o$: now we write the determinant with
pseudo fermion fields:
\begin{equation}
  \begin{split}
    \det(\hQp \hQm) &= \int \mathcal{D}\phi_o\,\mathcal{D}\phi^\dagger_o\
    \exp(-S_\mathrm{PF})\\
    S_\mathrm{PF} &\equiv\ \phi_o^\dagger\ \left(\hQp\hQm\right)^{-1}\phi_o\, ,
  \end{split}
\end{equation}
where the fields $\phi_o$ are defined only on the odd sites of the
lattice. From the first factor in the Schur decomposition a second
term needs to be taken into account in the effective action for the
fermion determinant, this reads
\begin{equation}
  \label{eq:swdet}
  \begin{split}
    S_{\det} &=  - \log[\det(1+T_{ee} + i\tilde\mu\gamma_5)\ \cdot\ 
    \det(1+T_{ee} - i\tilde\mu\gamma_5)]\\
    &= -\tr[\log(1+T_{ee} + i\tilde\mu\gamma_5) + \log(1+T_{ee} -
    i\tilde\mu\gamma_5)]\, .\\
  \end{split}
\end{equation}
Note that for $\tilde\mu=0$  $\det(1+T_{ee})$ is real. For
$\tilde\mu\neq0$ however, $\det(1+T_{ee}+i\tilde\mu\gamma_5)$ is the
complex conjugate of $\det(1+T_{ee}-i\tilde\mu\gamma_5)$ as the
product of the two must be real. The latter can be seen from
\[
\begin{split}
  &(1+T_{ee} + i\tilde\mu\gamma_5)\ \cdot\ (1+T_{ee} -
  i\tilde\mu\gamma_5) = \\
  &(1+T_{ee})^2 + \tilde\mu^2\, .\\
\end{split}
\]
In order to compute the force corresponding to the effective
action $S_\mathrm{PF}$ we need the variation of $S_\mathrm{PF}$ with
respect to the gauge fields 
(using $\delta (A^{-1})=-A^{-1}\delta A A^{-1}$):
\begin{equation}
  \label{eq:eosw5}
  \begin{split}
    \delta S_\mathrm{PF} &= -[\phi_o^\dagger (\hQp \hQm)^{-1}\delta \hQp(\hQp)^{-1}\phi_o +
    \phi_o^\dagger(\hQm)^{-1}\delta \hQm (\hQp \hQm)^{-1} \phi_o ] \\
     &= -[X_o^\dagger \delta \hQp Y_o + Y_o^\dagger \delta\hQm X_o]
  \end{split}
\end{equation}
with $X_o$ and $Y_o$ defined on the odd sides as 
\begin{equation}
  \label{eq:eosw6}
  X_o = (\hQp \hQm)^{-1} \phi_o,\quad Y_o = (\hQp)^{-1}\phi_o=\hat
  \Qm X_o\ ,
\end{equation}
where $(\hQpm)^\dagger = \hat Q^\mp$ has been used. The variation of
$\hQpm$ reads
\begin{equation}
  \label{eq:eosw7}
  \begin{split}
    \delta \hQpm = \gamma_5 & \left( \delta T_{oo}-\delta M_{oe}(M_{ee}^\pm )^{-1}M_{eo} -
      M_{oe}(M_{ee}^\pm )^{-1}\delta M_{eo}\right. \\
  &\left. + M_{oe}(M_{ee}^\pm )^{-1} \delta T_{ee} (M_{ee}^\pm )^{-1} M_{eo}\right),
  \end{split}
\end{equation}
and one finds
\begin{equation}
  \label{eq:eosw8}
  \begin{split}
    \delta S_\mathrm{PF} &= -(X^\dagger\delta \Qp Y + Y^\dagger\delta \Qm X) \\
    &= -(X^\dagger\delta \Qp Y +(X^\dagger\delta \Qp Y)^\dagger)
  \end{split}
\end{equation}
where $X$ and $Y$ are now defined over the full lattice as
\begin{equation}
  \label{eq:eosw9}
  X = 
  \begin{pmatrix}
    -(M_{ee}^-)^{-1}M_{eo}X_o \\ X_o\\
  \end{pmatrix},\quad
  Y = 
  \begin{pmatrix}
    -(M_{ee}^+)^{-1}M_{eo}Y_o \\ Y_o\\
  \end{pmatrix}.
\end{equation}
In addition $\delta\Qp = \delta\Qm = \delta Q, M_{eo}^\dagger =
\gamma_5 M_{oe}\gamma_5$ and $M_{oe}^\dagger = \gamma_5
M_{eo}\gamma_5$ has been used.  $\delta Q$
is now the original
\[
\delta Q = \gamma_5
\begin{pmatrix}
  \delta T_{ee} & \delta M_{eo} \\
  \delta M_{oe} & \delta T_{oo} \\
\end{pmatrix}
\]
defined over the full lattice. Since the bosonic part
is quadratic in the $\phi_o$ fields, the $\phi_o$ are generated at the
beginning of each molecular dynamics trajectory with
\begin{equation}
  \label{eq:eosw10}
  \phi_o = \hQp R,
\end{equation}
where $R$ is a random spinor field taken from a Gaussian distribution
with norm one.

The additional bit in the action $S_{\det}$ needs to be treated
seperately. The variation of this part is
\begin{equation}
  \label{eq:eosw11}
  \delta S_{\det} = -\tr \left\{ \left[(1+i\tilde\mu\gamma_5 + T_{ee})^{-1}  +
    (1-i\tilde\mu\gamma_5 + T_{ee})^{-1}\right] \delta T_{ee} \right\} \ . 
\end{equation}
The main difference in between pure Twisted mass fermions and Twisted
mass fermions plus clover term is that the matrices $M_{ee}$ and
$M_{oo}$ need to be inverted numerically. A stable numerical method
for this task needs to be devised.

For the implementation it is useful to compute the term
\begin{equation}
  \label{eq:Tee}
  1+T_{a\alpha,b\beta} = 1 + \frac{i}{2} c_\mathrm{sw}
  \kappa\sigma_{\mu\nu}^{\alpha\beta}F_{\mu\nu}^{\alpha\beta}(x)
\end{equation}  
once for all $x$. This is implemented in {\ttfamily clover\_leaf.c} in
the routine {\ttfamily sw\_term}. The twisted mass term is not
included in this routine, as this would require double the storage for
plus and minus $\mu$, respectively. It is easier to add the twisted
mass term in later on. 

The term in eq.~(\ref{eq:Tee}) correpsonds to a $12\times12$ matrix
in colour and spin which reduces to two complex $6\times6$ matrices
per site because it is block-diagonal in spin (one matrix for the two
upper spin components, one for the two lower ones). 
For each $6\times6$ matrix the off-diagonal $3\times3$
matrices are just hermitian conjugate to each other since $1+T$ is hermitian.
We therefore get away with storing two times three 
$3\times3$ complex matrices. These are stored in the array {\ttfamily
  sw[VOLUME][3][2]} of type {\ttfamily su3}. Here, {\ttfamily
  sw[x][0][0]} is the upper diagonal $3\times3$ matrix, {\ttfamily
  sw[x][1][0]} the upper off-diagnoal $3\times3$ matrix and {\ttfamily
  sw[x][2][0]} the lower diagonal matrix. The lower off-diagonal
matrix would be the inverse of {\ttfamily sw[x][1][0]}. The second
$6\times6$ matrix is stored following the same conventions.

For computing $S_\mathrm{det}$, we take into account the structure
of the $24 \times 24$ flavour, spin and colour matrix:
\begin{equation}
	\label{eq:cloverMee}
	M_{ee}(x) = 
		\begin{pmatrix}
		  A(x) + i\tilde{\mu} & 0 & 0 & 0 \\
		  0 & B(x) - i\tilde{\mu} & 0 & 0 \\
		  0 & 0 & A(x) - i\tilde{\mu} & 0 \\
		  0 & 0 & 0 & B(x) + i\tilde{\mu} \\
		\end{pmatrix}\, ,
\end{equation}
where A and B are the $6 \times 6$ matrices mentioned above and are individually hermitian. 

The implementation {\ttfamily sw\_trace} in {\ttfamily clover\_det.c} populates a temporary $6\times6$ array 
from the {\ttfamily sw} array and adds $+i\mu$ to the diagonal. Using $\det(\gamma_5) = 1$, 
the contribution to the effective action is then:
\begin{equation}
	\label{eq:cloverdet}
	\begin{aligned}
		\log \det(M_{ee}) &= \log\left( |\det( A + i\tilde{\mu} )|^2 \cdot |\det( B + i\tilde{\mu} )|^2 \right) \\
		& = \log\left( |\det( A + i\tilde{\mu} )|^2 \right) + \log \left( |\det( B + i\tilde{\mu} )|^2 \right)\,,
	\end{aligned}
\end{equation}
where the summands are computed individually in a loop.

When it comes to computing the inverse of $1\pm i \mu\gamma_5 +
T_{ee}$, the dependence on the sign of $\mu$ is unavoidable. However,
it is only needed for even (odd) sites, so we can use an array
{\ttfamily sw\_inv[VOLUME][3][2]} of type {\ttfamily su3} to store
e.g. $+\mu$ at even and $-\mu$ at odd sites.

For evaluating the force for $S_\mathrm{det}$ in the function
{\ttfamily sw\_deriv} we have to compute
\begin{equation}
  \label{eq:trdiracdet}
  \tr_\mathrm{dirac}[\ i\sigma_{\mu\nu}(1+T_{ee}(x)\pm
  i\tilde\mu\gamma_5)^{-1}\ ]\, ,
\end{equation}
with $\sigma_{\mu\nu} = i\gamma_\mu\gamma_\nu\ \forall \mu\neq\nu$.
The matrix $(1+T_{ee}(x)\pm i\tilde\mu\gamma_5)^{-1}$ has the general
structure
\[
T_\mathrm{det} = 
\begin{pmatrix}
  u_0 & u_1 & 0 & 0 \\
  u_3 & u_2 & 0 & 0 \\
  0 & 0 & l_0 & l_1 \\
  0 & 0 & l_3 & l_2 \\
\end{pmatrix}\,.
\]
Evaluating eq.~(\ref{eq:trdiracdet}) with matrix $T_\mathrm{det}$ for
$\mu\neq\nu$ leads to the following terms
\begin{eqnarray*}
  \label{eq:trsigma}
  \mu\nu & \\
  01 & -i (( l_1 -u_1) + (l_3-u_3))\\
  02 & (l_1 - u_1) - (l_3 - u_3)\\
  03 & i((l_2-u_2) - (l_0-u_0))\\
  12 & i((l_2+u_2) - (l_0-u_0))\\
  13 & (l_3+u_3) - (l_1 + u_1)\\
  23 & -i(l_3+u_3+l_1+u_1)\,.
\end{eqnarray*}
The force for $S_\mathrm{PF}$ can be computed in exactly the same way,
even if in this case the matrix $T_\mathrm{PF}$ is a full matrix
stemming from 
\begin{equation}
  \label{eq:trdiracpf}
  \tr_\mathrm{dirac}[\ i\sigma_{\mu\nu}(\gamma_5Y(x)\otimes
  X^\dagger(x) + \gamma_5X(x)\otimes Y^\dagger(x))\ ]\equiv
  \tr_\mathrm{dirac}[\ i\sigma_{\mu\nu}\ T_\mathrm{PF}\ ]\, .
\end{equation}
$T_\mathrm{PF}$ is computed in the function {\ttfamily sw\_spinor}.
After multiplying with 
$\sigma_{\mu\nu}$ only the upper left and lower right blocks survive
and the structure stays identical to the case discussed for
$T_\mathrm{det}$. So in both cases, in order to compute the trace, we
have to compute first in the functions {\ttfamily sw\_spinor} and
{\ttfamily sw\_deriv} only
\begin{equation}
  m_i = l_i - u_i\,,\quad p_i = l_i + u_i\quad i = 0,...,3\,.
\end{equation}
The $m_i$ and $p_i$ are then passed on to the function {\ttfamily
  sw\_all} which combines them to the correct insertion matrices,
whereafter the traceless antihermitian part of it is
computed. Finally, $\delta T_{ee}$ is computed and combined with the
insertion matrices.

\subsubsection{Combining Clover and Nondegenerate Twisted mass term}

Now we have
\[
\hat Q^h_{oo} = \gamma_5(M_{oo}^h -
(M_{oe}^h\ (M_{ee}^h)^{-1}\ M_{eo}^h)\,,
\]
with
\begin{equation}
  M_{oo|ee}^h = 1+T_{oo|ee}+i\bar\mu\gamma_5\tau^3-\bar\epsilon\tau^1\,.
\end{equation}

The clover part $1+T_{ee}$ is identical to the one in the $N_f=2$
flavour case and stored in the array {\ttfamily sw}. 

Because $1+T_{ee}$ is hermitian, we can invert $M_{ee}^h$ by
\begin{equation}
  \label{eq:ndSdet}
  (1+T_{ee}+i\bar\mu\gamma_5\tau^3-\bar\epsilon\tau^1)^{-1} =
  \frac{(1+T_{ee}-i\bar\mu\gamma_5\tau^3+\bar\epsilon\tau^1)}
  {(1+T_{ee})^2 + \bar\mu^2 - \bar\epsilon^2}\,.
\end{equation}
In practice we compute $((1+T_{ee})^2 + \bar\mu^2 -
\bar\epsilon^2)^{-1}$ and store the result in the first {\ttfamily
  VOLUME/2} elements of the array {\ttfamily sw\_inv}. Wherever the
clover terms needs to be applied we then multiply with  $((1+T_{ee})^2
+ \bar\mu^2 - \bar\epsilon^2)^{-1}$ and then with the nominator in
eq.~(\ref{eq:ndSdet}). One could save computing time here for the
price of using more memory by storing the full inverse. Actually, it
would be only slightly more than in the two flavour case: in addition
we would only have to store $\bar\epsilon((1+T_{ee})^2
+ \bar\mu^2 - \bar\epsilon^2)^{-1}$. This would also allow to re-use a
lot of the $N_f=2$ flavour implementation.

The determinant we have to compute is
\[
\det(Q^h) =
\det[\gamma_5(1+T_{ee}+i\bar\mu\gamma_5\tau^3-\bar\epsilon\tau^1)]\
\det[\hat Q^h_{oo}].
\]

Again, the first factor can be computed as $S_\mathrm{det}$, for which we take into
account the structure of the $24 \times 24$ flavour, spin and colour matrix:
\begin{equation}
	\label{eq:cloverMee_eps}
	M^h_{ee}(x) = 
		\begin{pmatrix}
		  A(x) + i\bar{\mu} & 0 & -\bar{\epsilon} & 0 \\
		  0 & B(x) - i\bar{\mu} & 0 & -\bar{\epsilon} \\
		  -\bar{\epsilon} & 0 & A(x) - i\bar{\mu} & 0 \\
		  0 & -\bar{\epsilon} & 0 & B(x) + i\bar{\mu} \\
		\end{pmatrix}\, ,
\end{equation}
where A and B are the $6 \times 6$ matrices mentioned in sub-section 
\ref{sec:clover_twist} and are individually hermitian. 

The determinant of the $24 \times 24$ matrix can be simplified by writing it as follows
in $12 \times 12$ blocks in flavour:
\begin{equation*}
	\begin{aligned}
	\det(M^h_{ee}) &= 
		\det 
			\begin{pmatrix}
				K & D \\
				D & K^\dagger
			\end{pmatrix} =
			\det \left[ \begin{pmatrix}
				K & D - K D^{-1} K^\dagger \\
				D & 0
			\end{pmatrix} \cdot
			\begin{pmatrix}
				1 & D^{-1} K^\dagger \\
				0 & 1
			\end{pmatrix} \right] \\
	&= - \det(D) \cdot \det( D - K D^{-1} K^\dagger ) \\
	&= \det( K K^\dagger - D^2 ) \\
	&= \det( A^2 + \bar{\mu}^2 - \bar{\epsilon}^2 ) \cdot \det( B^2 + \bar{\mu}^2 - \bar{\epsilon}^2 ) \,,
	\end{aligned}
\end{equation*}
where the sign in the second line comes from the first term and in the third line the
proportionality of $D$ to the identity matrix was used.

The implementation {\ttfamily sw\_trace\_nd} in {\ttfamily clover\_det.c} populates
a temporary $6\times6$ array from the {\ttfamily sw} array, squares it and
and adds $\bar{\mu}^2 - \bar{\epsilon}^2$ to the diagonal. Using $\det(\gamma_5) = 1$, 
the contribution to the effective action is then:
\begin{equation}
	\label{eq:cloverdet_nd}
		\log \det(M_{ee}) = \log\left( \det( A^2 + \bar{\mu}^2 - \bar{\epsilon}^2 ) \cdot \det( B^2 + \bar{\mu}^2 - \bar{\epsilon}^2 ) \right).
\end{equation}

For the variation of this term we have to compute now
\begin{equation}
  \label{eq:ndtrdiracdet}
  \tr_\mathrm{dirac, flavour}[\ i\sigma_{\mu\nu}(1+T_{ee}(x) +
  i\bar\mu\gamma_5\tau^3 - \bar\epsilon\tau^1)^{-1}\ ]\, ,
\end{equation}
which is equal to
\begin{equation}
 \tr_\mathrm{dirac,flavour}\left[\ i\sigma_{\mu\nu}
   \frac{(1+T_{ee}-i\bar\mu\gamma_5\tau^3+\bar\epsilon\tau^1)}
  {(1+T_{ee})^2 + \bar\mu^2 - \bar\epsilon^2}\ \right]\,.
\end{equation}
The trace in flavour simplifies the computation to
\begin{equation}
 \tr_\mathrm{dirac}\left[\ i\sigma_{\mu\nu}
   \frac{2(1+T_{ee})}
  {(1+T_{ee})^2 + \bar\mu^2 - \bar\epsilon^2}\ \right]\,.
\end{equation}
This can be treated analogously to the degenerate case described
above.

\subsection{Inversion}

In addition to even/odd preconditioning in the HMC algorithm as
described above, it can also be used to speed up the inversion of the
fermion matrix. 

Due to the factorization (\ref{eq:eo2}) the full fermion matrix can be
inverted by inverting the two matrices appearing in the factorization
\[
\begin{pmatrix}
  M_{ee}^\pm & M_{eo} \\
  M_{oe}    & M_{oo}^\pm \\
\end{pmatrix}^{-1}
=
\begin{pmatrix}
  1       & (M_{ee}^\pm)^{-1}M_{eo}\\
  0       & (M_{oo}^\pm-M_{oe}(M_{ee}^\pm)^{-1}M_{eo})\\
\end{pmatrix}^{-1}
\begin{pmatrix}
  M_{ee}^\pm & 0 \\
  M_{oe}   & 1 \\
\end{pmatrix}^{-1}\, .
\]
The two factors can be simplified as follows:
\[
\begin{pmatrix}
  M_{ee}^\pm & 0 \\
  M_{oe}   & 1 \\
\end{pmatrix}^{-1}
=
\begin{pmatrix}
      (M_{ee}^\pm)^{-1} & 0 \\
      -M_{oe} (M_{ee}^{\pm})^{-1}  & 1 \\
    \end{pmatrix}
\]
and 
\[
\begin{split}
  &\begin{pmatrix}
    1       & (M_{ee}^\pm)^{-1}M_{eo}\\
    0       & (M_{oo}^\pm-M_{oe}(M_{ee}^\pm)^{-1}M_{eo})\\
  \end{pmatrix}^{-1}
  \\=&
  \begin{pmatrix}
    1       & -(M_{ee}^\pm)^{-1}M_{eo}(M_{oo}^\pm-M_{oe}(M_{ee}^\pm)^{-1}M_{eo})^{-1}  \\
    0       & (M_{oo}^\pm-M_{oe}(M_{ee}^\pm)^{-1}M_{eo})^{-1}\\
  \end{pmatrix}\, .
\end{split}
\]
The complete inversion is now performed in two separate steps: First
we compute for a given source field $\phi=(\phi_e,\phi_o)$ an intermediate 
result $\varphi=(\varphi_e,\varphi_o)$ by:
\[
\begin{pmatrix}
  \varphi_e \\ \varphi_o\\
\end{pmatrix}
=
\begin{pmatrix}
  M_{ee}^\pm & 0 \\
  M_{oe}   & 1 \\
\end{pmatrix}^{-1}
\begin{pmatrix}
  \phi_e \\ \phi_o \\
\end{pmatrix}
=
\begin{pmatrix}
  (M_{ee}^\pm)^{-1} \phi_e \\ 
  -M_{oe}( M_{ee}^\pm)^{-1} \phi_e + \phi_o \\
\end{pmatrix}\, .
\]
This step requires only the application of $M_{oe}$ and
$(M_{ee}^\pm)^{-1}$, the latter of which is given by Eq~(\ref{eq:eo3}).
The final solution $\psi=(\psi_e,\psi_o)$ can then be computed with
\[
\begin{pmatrix}
  \psi_e \\ \psi_o \\
\end{pmatrix}
=
\begin{pmatrix}
  1       & (M_{ee}^\pm)^{-1}M_{eo}\\
  0       & (M_{oo}^\pm-M_{oe}(M_{ee}^\pm)^{-1}M_{eo})\\
\end{pmatrix}^{-1}
\begin{pmatrix}
  \varphi_e \\ \varphi_o \\
\end{pmatrix}
=
\begin{pmatrix}
  \varphi_e - (M_{ee}^\pm)^{-1}M_{eo}\psi_o \\ \psi_o \\
\end{pmatrix}\, ,
\]
where we defined
\[
\psi_o = (M_{oo}^\pm-M_{oe}(M_{ee}^\pm)^{-1}M_{eo})^{-1} \varphi_o\, .
\]
Therefore the only inversion that has to be performed numerically is
the one to generate $\psi_o$ from $\varphi_o$ and this inversion
involves only an operator that is better conditioned than the original
fermion operator.

Even/odd preconditioning can also be used for the mass non-degenerate
Dirac operator $D_h$ eq.~(\ref{eq:Dh}). The corresponding equations
follow immediately from the previous discussion and the definition
from eq.~(\ref{eq:Dheo}).

\subsubsection{Inverting $M$ on $\phi_o$}

In case inverting the full matrix $M$ is much faster than inverting
the even/odd preconditioned matrix -- as might be the case with
deflation, one may use for symmetric even/odd preconditioining
\begin{equation}
  (\hat M^\pm)^{-1}\phi_o\ =\ P_{l\to o}\ (M_\pm)^{-1}\ P_{o\to l}\
  M^\pm_{oo}\ \phi_o
\end{equation}
Where $P_{l\to o}$ projects the odd sides of a full spinor and
$P_{o\to l}$ reverses this by filling up with zeros. $M_\pm$ is here just
$\gamma_5 Q_\pm$. For asymmetric even/odd preconditioning the formula
reads
\begin{equation}
  (\hat M^\pm)^{-1}\phi_o\ =\ P_{l\to o}\ (M_\pm)^{-1}\ P_{o\to l}\
  \phi_o\, .
\end{equation}
It is based on the observation that
\[
M^{-1} = 
\begin{pmatrix}
  A_{ee} & A_{eo} \\
  A_{oe} & A_{oo} \\
\end{pmatrix}
\]
with (skipping the $\pm$ index for brevity)
\[
\begin{split}
  A_{ee}\quad &=\quad (1- M_{ee}^{-1} M_{eo} M_{oo}^{-1} M_{oe})^{-1}\ M_{ee}^{-1} \\
  A_{eo}\quad &=\quad -M_{ee}^{-1}\ M_{eo}\ A_{oo} \\
  A_{oe}\quad &=\quad -M_{oo}^{-1}\ M_{oe}\ A_{ee} \\
  A_{oo}\quad &=\quad (1- M_{oo}^{-1} M_{oe} M_{ee}^{-1} M_{eo})^{-1}\ M_{oo}^{-1} \\
\end{split}
\]
\endinput

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