% vim: ft=tex
\chapter{Quantum Computing}

This chapter gives an introduction to binary quantum computing 
and some basic properties of quantum systems such as measurement
and time evolution. It is based on \cite{nielsen_chuang_2010}
but introduces a notation that will often be different.

\section{Qbits and Gates}
\subsection{Single Qbits}

\begin{definition}
    A qbit is a two-level quantum mechanical system \cite{nielsen_chuang_2010}, i.e. it has the eigenbasis
    $ \{\ket{\uparrow} \equiv \ket{1}, \ket{\downarrow} \equiv \ket{0}\} $
    with $\braket{\uparrow}{\downarrow} = 0$. In the following this basis will be called
    the $Z$ basis in analogy to the conventions used in spin systems ($\sigma_Z$). For some computations
    it can be useful to have component vectors; $\ket{\uparrow} \equiv \left(\begin{array}{c} 0 \\ 1\end{array} \right)$ and 
    $\ket{\downarrow} \equiv \left(\begin{array}{c} 1 \\ 0 \end{array} \right)$
    are used in these cases.
\end{definition}

A gate acting on a qbit is a unitary operator $G \in U(2)$. One can show that
$\forall G \in U(2)$ $G$ can be written as a product of unitary generator matrices
\cite[Chapter 4.2]{nielsen_chuang_2010}\cite[Chapter 4.3]{kaye_ea2007}\cite[Chapter 2]{marquezino_ea_2019};
common choices for the generators are $ X, H, R_{\phi}$ or $Z, H, R_{\phi}$ 
\footnote{Note that the notation in the sources is different. Instead of $R_\phi$ the
    $R_Z(\alpha) = \exp(-\frac{i\alpha}{2}Z)$ and $R_Y(\alpha) = \exp(-\frac{i\alpha}{2}Y)$ 
    rotations are used. However $R_\phi = \exp(-\frac{i\phi}{2}) R_Z(-\phi)$ and
    $R_Y(\alpha) = \cos(\frac{\alpha}{2}) I - i\sin(\frac{\alpha}{2}) Y = S H R_Z  H^\dagger S^\dagger$ \cite{nielsen_chuang_2010}.
}
with 
\label{ref:singleqbitgates}

\begin{equation}
    \begin{aligned}
    & X := \left(\begin{array}{cc} 0 & 1 \\ 1 & 0\end{array}\right) \\
    & Z := \left(\begin{array}{cc} 1 & 0 \\ 0 & -1\end{array}\right) \\
    & H := \frac{1}{\sqrt{2}}\left(\begin{array}{cc} 1 & 1 \\ 1 & -1\end{array}\right) \\
    & R_{\phi} := \left(\begin{array}{cc} 1 & 0 \\ 0 & \exp(i\phi)\end{array}\right)\\
    & I := \left(\begin{array}{cc} 1 & 0 \\ 0 & 1\end{array}\right). \\
    \end{aligned}
\end{equation}

Note that $X = HZH$ and $Z = R_{\pi}$, so the set of $H, R_\phi$ is sufficient. 
Further note that the basis vectors are chosen s.t. $Z\ket{0} = +\ket{0}$ and $Z\ket{1} = -\ket{1}$;
transforming to the other Pauli eigenstates is done using $H$ and $SH$

\begin{equation}
    S := R_{\frac{\pi}{2}} = \left(\begin{array}{cc} 1 & 0 \\ 0 & i\end{array}\right)
\end{equation}
\begin{equation}
    S H Z H^\dagger S^\dagger = S X S^\dagger = Y.
\end{equation}

The following states are the $\pm 1$ eigenstates of the $X,Y,Z$ operators
and will be used in some calculations later:

\begin{equation}
    \begin{aligned}
        &\ket{+_X} \equiv \ket{+} := \frac{1}{\sqrt{2}} (\ket{0} + \ket{1}) \\
        &\ket{-_X} \equiv \ket{-} := \frac{1}{\sqrt{2}} (\ket{0} - \ket{1}) \\
        &\ket{+_Y} := \frac{1}{\sqrt{2}} (\ket{0} + i\ket{1}) \\
        &\ket{-_Y} := \frac{1}{\sqrt{2}} (\ket{0} - i\ket{1}) \\
        &\ket{+_Z} := \ket{0} \\ 
        &\ket{-_Z} := \ket{1} \\
    \end{aligned}
\end{equation}

\subsection{Many-Qbit Systems}
\label{ref:many_qbits}

\begin{postulate}
    A $n$-qbit quantum mechanical state is the tensor product of the $n$ one-qbit 
    states \cite[Postulate 4]{nielsen_chuang_2010}.
\end{postulate}

Let $\ket{0}_s := \left(\begin{array}{c} 1 \\ 0 \end{array} \right)$ and $\ket{1}_s := \left(\begin{array}{c} 0 \\ 1 \end{array} \right)$
be the basis of the one-qbit systems. Then two-qbit basis states are

\begin{equation}
    \ket{0} := \ket{0b00} := \ket{0}_s \otimes \ket{0}_s :=  \left(\begin{array}{c} 1 \\ 0 \\ 0 \\ 0 \end{array} \right)
\end{equation}
\begin{equation}
    \ket{1} := \ket{0b01} := \ket{0}_s \otimes \ket{1}_s :=  \left(\begin{array}{c} 0 \\ 1 \\ 0 \\ 0 \end{array} \right)
\end{equation}
\begin{equation}
    \ket{2} := \ket{0b10} := \ket{1}_s \otimes \ket{0}_s :=  \left(\begin{array}{c} 0 \\ 0 \\ 1 \\ 0 \end{array} \right)
\end{equation}
\begin{equation}
    \ket{3} := \ket{0b11} := \ket{1}_s \otimes \ket{1}_s :=  \left(\begin{array}{c} 0 \\ 0 \\ 0 \\ 1 \end{array} \right).
\end{equation}

The $n$-qbit basis states can be constructed in a similar manner. 
A general $n$-qbit state is now a superposition of the 
integer states

\begin{equation}
    \label{eq:ci}
    \ket{\psi} = \sum\limits_{i = 0}^{2^n - 1} c_i \ket{i}
\end{equation}

with the normation condition
\begin{equation}
    \sum\limits_{i = 0}^{2^n - 1} |c_i|^2 = 1.
\end{equation}

The states $\ket{i}$ for $i = 0, ..., 2^{n}-1$ are called integer states. Note
that integer states are eigenstates of the $Z$ operators.\\
The computational basis is 
$\left\{\ket{i_0} \otimes ... \otimes \ket{i_{n-1}} \middle| i_0, ..., i_{n-1} = 0, 1\right\}$
\cite{nielsen_chuang_2010}.

\begin{definition}
For a single-qbit gate $U$ and a qbit $j = 0, 1, ..., n - 1$ 

    \begin{equation}
        U_j := \left(\bigotimes\limits_{i = 0}^{j - 1} I\right) 
                \otimes U 
                \otimes \left(\bigotimes\limits_{i = j + 1}^{n - 1} I \right)
    \end{equation}
    is acting on qbit $j$ \cite{kaye_ea2007}.
\end{definition}

% XXX
%\newpage

\begin{definition}\label{def:CU}
    For two qbits $i,j = 0, 1, ..., n - 1$, $i \neq j$ and a gate $U_i$ acting on $i$
    the controlled version of $U$ is defined by
    \begin{equation}
        \begin{aligned}\label{eq:CU}
            CU_{i, j} &:= \ket{0}\bra{0}_j\otimes I_i 
                        + \ket{1}\bra{1}_j \otimes U_i \\
                    &:= \left(\bigotimes\limits_{l < j} I\right) 
                            \otimes \ket{0}\bra{0} 
                            \otimes \left(\bigotimes\limits_{j < l < i} I\right) 
                            \otimes I 
                            \otimes \left(\bigotimes\limits_{j > l} I \right)\\
                    &\mbox{  } + \left(\bigotimes\limits_{l < j} I\right) 
                            \otimes \ket{1}\bra{1} 
                            \otimes \left(\bigotimes\limits_{j < l < i} I\right) 
                            \otimes U 
                            \otimes \left(\bigotimes\limits_{j > l} I \right)\\
        \end{aligned}
    \end{equation}

    where without loss of generality $j < i$; the other case is analogous.

    In particular for $X, Z$
    \begin{equation}\label{eq:CX_pr}
        CX(i, j) = \ket{0}\bra{0}_j\otimes I_i + \ket{1}\bra{1}_j \otimes X_i 
    \end{equation}
    \begin{equation}\label{eq:CZ_pr}
        CZ(i, j) = \ket{0}\bra{0}_j\otimes I_i + \ket{1}\bra{1}_j \otimes Z_i .
    \end{equation}

    This follows the definition given in \cite{barenco_ea_1995}.

\end{definition}

In Definition \ref{def:CU} $i$ is called the act-qbit and $j$ the control-qbit. In words
$CU$ applies the gate $U$ to the act-qbit if the control-qbit is in its $\ket{1}$ state.

One can show that the gates in \ref{ref:singleqbitgates} together with an entanglement gate, such as $CX$ or $CZ$ are enough
to generate an arbitrary $n$-qbit gate \cite{nielsen_chuang_2010}\cite[Chapter 4.3]{kaye_ea2007}\cite{barenco_ea_1995}.
The matrix representation of $CX$ and $CZ$ for two qbits is given by

\begin{equation}
    CX_{1, 0} = \left(\begin{array}{cccc} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{array}\right)
\end{equation}
\begin{equation}
    CZ_{1, 0} = \left(\begin{array}{cccc} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & -1 \end{array}\right).
\end{equation}

\subsection{Measurements}

\begin{postulate}
    Let 
    \begin{equation}\ket{\psi} = \alpha\ket{\phi_1} \otimes \ket{1}_j + \beta\ket{\phi_0} \otimes \ket{0}_j\end{equation} 
    be a  $n$-qbit state
    where $\ket{1}_j, \ket{0}_j$ denote the $j$-th qbit state and $|\alpha|^2 + |\beta|^2 = 1$. 
    Then the measurement of the $j$-th qbit will yield 
    \begin{equation}\ket{\phi_1} \otimes \ket{1}_j\end{equation} 
    with probability $|\alpha|^2$ and 
    \begin{equation}\ket{\phi_0} \otimes \ket{0}_j\end{equation}
    with probability $|\beta|^2$ \cite{nielsen_chuang_2010}.  This is called collapse of the wave function.
\end{postulate}

Measuring a qbit will also yield a classical result $0$ or $1$ with the respective probabilities.
Measurements are always performed in the computational basis, i.e. for a qbit
$i$ $Z_i$ is measured. The $+1$ eigenvalue of $Z_i$ is $\ket{0}_i$, $\ket{1}_i$ for $-1$.

\begin{corrolary}
    In general the measurement of a qbit is not invertible, in particular it cannot be represented as a
    unitary operator.
\end{corrolary}

\begin{proof}
    The measurement is not injective: Measuring both
    $\ket{0}$ and $\frac{1}{\sqrt{2}}(\ket{0} + \ket{1})$ (can) map to $\ket{0}$.

    Any unitary matrix $U$ has the inverse $U^\dagger \equiv U^{-1}$.
\end{proof}

Because a measurement is not unitary it is not a gate in the sense of the definition above. 
In the following discussion the term \textit{measurement gate} will be used from time
to time as a measurement can be treated similarly while doing numerics. 


\section{Quantum Circuits}
\label{ref:quantum_circuits}

As mentioned in \ref{ref:many_qbits} one can approximate an arbitrary $n$-qbit 
gate $U$ as a product of some single-qbit gates and either $CX$ or $CZ$.
Writing (possibly huge) products of matrices is quite unpractical and
unreadable. To address this problem quantum circuits have been introduced.
These represent the qbits as a horizontal line and a gate acting on a qbit is
a box with a name on the respective line. Quantum circuits are read from
left to right. This means that a gate $U_i = Z_i X_i H_i$ has the
circuit representation

\[
\Qcircuit @C=1em @R=.7em {
& \gate{H} & \gate{X} & \gate{Z} &\qw \\
}.
\]

The controlled gates (such as $CX$ and $CZ$) have a vertical line from the control-qbit to
the gate, for instance the circuit for $CZ_{2, 1}CX_{2,0}$ is

\[
\Qcircuit @C=1em @R=.7em {
& \qw & \ctrl{2} & \qw & \qw &\qw \\
& \qw & \qw & \qw & \ctrl{1} &\qw \\
& \qw & \gate{X} & \qw & \gate{Z} &\qw &\rstick{.}\\
}
\]

Several qbits can be abbreviated by writing a slash on the qbit line:

\[
\Qcircuit @C=1em @R=.7em {
    & {/} \qw & \qw & \gate{Z^{\otimes n}} & \qw \\
}
\]


\section{Quantum Algorithms}
\label{ref:quantum_algorithms}

The great hope behind quantum computing is that it will speed up some
computations exponentially using algorithms that utilize the laws of quantum
mechanics. Current algorithms are based upon quantum search and quantum fourier
transform \cite{nielsen_chuang_2010}.  The latter is particularly interesting for
physical problems as it is a key component in the phase estimation algorithm
that can be used to analyze the spectrum of the transfer matrix:

\begin{equation}
    T = \exp(itH)
\end{equation}

The spectrum of $T$ can now be estimated by using the phase estimation circuit

\[
\Qcircuit @C=1em @R=.7em {
    & \lstick{\ket{0}}      & {/^N} \qw & \gate{H^{\otimes n}} & \ctrl{1} & \gate{FT^\dagger} & \qw & \meter & \rstick{x}\\
    & \lstick{\ket{\varphi}} & {/} \qw & \qw & \gate{T} & \qw & {/} \qw & \qw& \rstick{\ket{\varphi}.} \\
}
\]

Where $T\ket{\varphi} = \exp(2\pi i\varphi) \ket{\varphi}$ and the measurement
result $\tilde{\varphi} = \frac{x}{2^n}$ is an estimation for $\varphi$. If
a success rate of $1-\epsilon$ and an accuracy of $| \varphi - \tilde{\varphi}
| < 2^{-m}$ is wanted, then $N = m + \log_2(2 + \frac{1}{2\epsilon})$ qbits are
required \cite{nielsen_chuang_2010}\cite{lehner2019}.

%Another possible way to use quantum computers in physics is to simulate a system's
%time evolution using the transfer matrix. By mapping an interesting system to
%the qbit space and applying the 
