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

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

\begin{definition}
    A qbit is a two level quantum mechanical system, i.e. it has the eigenbasis
    $ \{\ket{\uparrow} \equiv \ket{1}, \ket{\downarrow} \equiv \ket{0}\} $
    with $\braket{\uparrow}{\downarrow} = 0$. In the folling this basis will be called
    the $Z$ basis in analogy to the conventions used in spin systems. 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 approximated arbitrarily good as a product of unitary generator matrices
\cite[Chapter 4.3]{kaye_ea2007}\cite[Chapter 2]{marquezino_ea_2019},
common choices for the generators are $ X, H, R_{\phi}$ and $Z, H, R_{\phi}$ with 
\label{ref:singleqbitgates}

\begin{equation}
    X := \left(\begin{array}{cc} 0 & 1 \\ 1 & 0\end{array}\right) 
\end{equation}
\begin{equation}
    Z := \left(\begin{array}{cc} 1 & 0 \\ 0 & -1\end{array}\right) 
\end{equation}
\begin{equation}
    H := \frac{1}{\sqrt{2}}\left(\begin{array}{cc} 1 & 1 \\ 1 & -1\end{array}\right) 
\end{equation}
\begin{equation}
    R_{\phi} := \left(\begin{array}{cc} 1 & 0 \\ 0 & \exp(i\phi)\end{array}\right)
\end{equation}
\begin{equation}
    I := \left(\begin{array}{cc} 1 & 0 \\ 0 & 1\end{array}\right) 
\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}

\subsubsection{Many Qbits}

\begin{postulate}
    A $N$ qbit quantum mechanical state is the tensor product\cite[Definition 14.3]{wuest1995} of the $N$ single qbit 
states.
\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 then be constructed in a similar manner. 
A general $N$ qbit state can then be written as a superposition of the 
integer states:

\begin{equation}
    \ket{\psi} = \sum\limits_{i = 0}^{2^N - 1} c_i \ket{i} 
\end{equation}
\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 $\{\ket{i_0} \otimes ... \otimes \ket{i_{n-1}} | i_0, ..., i_{n-1} = 0, 1\}$.

\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 the $U$ gate acting on qbit $j$.
\end{definition}

\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}\label{eq:CU}
        CU_{i, j} = \ket{0}\bra{0}_j\otimes I_i + \ket{1}\bra{1}_j \otimes U_i 
    \end{equation}

    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}

\end{definition}

In the 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[Chapter 4.3]{kaye_ea2007}\cite{barenco_ea_1995}.
The matrix representation of $CX$ and $CZ$ for two qbits is given by (this is quickly verified by applying the
matrices to the basis states)

\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}

\subsubsection{Measurements}

\textbf{FIXME} I don't like this at all.

\begin{postulate}
    Let 
    $$\ket{\psi} = \alpha\ket{\phi_1} \otimes \ket{1}_j + \beta\ket{\phi_0} \otimes \ket{0}_j$$ 
    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 
    $$\ket{\phi_1} \otimes \ket{1}_n$$ 
    with probability $|\alpha|^2$ and 
    $$\ket{\phi_0} \otimes \ket{0}_n$$
    with probability $|\beta|^2$.  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.

\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 measuerment in 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}

As a measurement is not unitary it is not a gate as in 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 similarely while doing numerics. 

Measurements are always performed in the computational basis, i.e. for a qbit
$i$ $Z_i$ is measured. Let the state to be measured be 

\begin{equation}
    \ket{\psi} = \alpha\ket{0}\otimes\ket{\psi_0} + \beta\ket{1}\otimes\ket{\psi_1}
\end{equation}

then a result $0$ is measured with probability $|\alpha|^2$ and $1$ with probability 
$|\beta|^2 = 1 - |\alpha|^2$. The wave function is then collapsed to 

\begin{equation}
    \begin{aligned}
    \ket{\psi'} = \left\{\begin{array}{c}\ket{0}\otimes\ket{\psi_0}, \mbox{ for a result 0 } \\
        \ket{1}\otimes\ket{\psi_1}, \mbox{ for a result 1 }
    \end{array}\right\}
    \end{aligned}
\end{equation}

\subsection{Quantum Circuits}

Quantum circuits are a simple and well-readable way to express the application 
of several gates on a state. 

\textbf{TODO}
