\documentclass[11 pt]{article}
\include{lecture}
\usepackage{subfigure}

\begin{document}
\lecture{4}{9/13/2010}{Elementary Quantum Algorithms}{Kenneth Rudinger}

This lecture introduces several simple quantum algorithms.  The particular algorithms introduced here solve their respective problems faster than their corresponding classical algorithms (deterministic or probabilistic).  Specifically, we examine the Deutsch, Deutsch-Josza, Bernstein-Vazirani, and Simon problems..

\section{Solving Black Box Problems}
For the time being, we concern ourselves only with black box problems.  A black box problem is one in which we are given a function \emph{f}.  All we know for certain about this function is that $\emph{f}:\{0,1\}^n \to \{0,1\}^m$.  It is our goal to determine some property of \emph{f}.  (If we are given further information about this function, we call it a promise function, as some property of the function has been "promised" to us.)  To determine the desired property property, we are given access to a transformation (the black box) which acts on an input of our choosing (residing in $\{0,1\}^n$); the transformation's output is the function in question applied to our input.  However, because valid quantum computations must correspond to invertible (more specifically, unitary) transformations, the black box actually performs the function $\emph{\~f}:\{0,1\}^n \times  \{0,1\}^m \to \{0,1\}^n \times  \{0,1\}^m:(\mathbf{x},\mathbf{y})\to(\mathbf{x},\mathbf{y}\oplus f(\mathbf{x}))$. We denote the unitary transformation that realizes $\emph{\~f}$ by $U_f$.  

One example of such is a transformation where $m=1$.  If we start in the state $\ket{\psi_0}=\ket{x}\ket{0}$, then we see that $U_f\ket{\psi_0}=\ket{x}\ket{f(x)\oplus 0} =\ket{x}\ket{f(x)}$.  We then apply $R_\pi$ to the ancilla qubit, mapping $\ket{x,f(x)}$ to $(-1)^{f(x)}\ket{x,f(x)}$.  Lastly, we apply $U_f$ to the state again, sending the ancilla back to its original state of $\ket{0}$, and keeping the non-ancilla qubits in the state we desired to create, $(-1)^{f(x)}\ket{x}$.    Pictured below is the corresponding circuit.

\begin{equation*}
   \Qcircuit @C=1.5em @R=2.0em 
   {
    \lstick{x_1} &  \qw & \multigate{4}{U_f} & \qw & \qw & \qw& \qw& \qw  &  \qw& \qw &\qw & \qw& \multigate{4}{U_f}& \qw &\qw & \qw		\\
    \lstick{x_2} & \qw & \ghost{U_f} & \qw &\qw & \qw& \qw& \qw  & \qw& \qw& \qw & \qw&\ghost{U_f} &\qw &\qw	&  \qw	\\
    \lstick{...}& \qw & \ghost{U_f} & \qw & \qw& \qw& \qw &  \qw  & \qw& \qw&\qw & \qw& \ghost{U_f} &\qw &\qw	&  \qw\\
    \lstick{x_n} & \qw & \ghost{U_f} & \qw & \qw& \qw &\qw & \qw & \qw&\qw&\qw & \qw& \ghost{U_f} &\qw &\qw	&  \qw \\
    \lstick{\ket{0}} &  \qw & \ghost{U_f} & \qw & \qw& \qw &\gate{R_\pi}  & \qw& \qw& \qw& \qw& \qw& \ghost{U_f} &\qw &\qw	 & \qw\\
  \ket{{\bf x},0} &&&&\ket{{\bf x},f({\bf{x}})} &&&&& (-1)^{f(\mathbf{x})}\ket{\mathbf{x},f(\mathbf{x})} &&&&&&&& (-1)^{f(\mathbf{x})}\ket{\mathbf{x},0}
   }
\end{equation*}\\

\noindent This particular method is referred to as \emph{phase kickback}, as $f(\mathbf{x})$ is encoded in the phase of our final state.

This transformation required two queries of our oracle $U_f$.  Can we achieve this phase kickback with only one query?  It turns out that we can.  Let's instead initialize our ancilla qubit to $\ket{-}$ (Recall: $\ket{-} = \frac{1}{\sqrt{2}}(\ket{0}-\ket{1}) = H\ket{1}$.)  Now when we apply $U_f$, the ancilla remains in the state $\ket{-}$, and we pick up the desired phase, that is: $U_f\ket{x}\ket{-}=(-1)^{f(x)}\ket{x}\ket{-}$.  Thus we can achieve phase kickback with only one query of our oracle, as shown below.

\begin{equation*}
   \Qcircuit @C=1.0em @R=2.0em 
   {
     \lstick{x_1} &  \qw & \multigate{4}{U_f} & \qw & \qw & \qw  &  \qw& \qw &\qw & \qw &\qw \\
    \lstick{x_2} & \qw & \ghost{U_f} & \qw &\qw & \qw  & \qw& \qw& \qw  &\qw &\qw	&    \\
    \lstick{...}& \qw & \ghost{U_f} & \qw & \qw &  \qw  & \qw& \qw&\qw  &\qw &\qw	&       \\
    \lstick{x_n} & \qw & \ghost{U_f} & \qw &\qw \qw & \qw & \qw&\qw&\qw  &\qw &\qw	&        \\
    \lstick{\ket{-}} &  \qw & \ghost{U_f} & \qw &\qw & \qw & \qw&  \qw& \qw &\qw &\qw	 &      \\
  \ket{{\bf x},0}  &&&&&&&&&&& (-1)^{f(\mathbf{x})}\ket{\mathbf{x},0}
   }
\end{equation*}\\

\noindent Keeping in mind this phase kickback trick, we now turn our attention to the four problems mentioned above

\section{Deutsch's Problem}
Consider a function  $f$ such that $\emph{f}:\{0,1\}^n \to \{0,1\}^m$.  (Here, $n=m=1$.)  The question we wish to answer is:  Does $f(0) = f(1)$?  Classically, we must make two queries of our oracle, one to determine $f(0)$, the other to determine $f(1)$.  (Even if we use probabilistic computation instead of deterministic, we are still required to make two queries.)  However, with a quantum circuit, we need only one query.  We will use the phase kickback technique, recalling that:

\begin{align*}
\ket{0}\ket{-}\to(-1)^{f(0)}\ket{0}\ket{-}\\
\ket{1}\ket{-}\to(-1)^{f(1)}\ket{1}\ket{-}
\end{align*}
If we apply the phase kickback to a superposition of these states, we find 
\begin{align*}
\frac{1}{\sqrt{2}} (\ket{0}+\ket{1})\ket{-}\to \frac{1}{\sqrt{2}} ((-1)^{f(0)}\ket{0}+(-1)^{f(1)}\ket{1})\ket{-}
\end{align*}
If $f(0)=f(1)$, then this state reduces to $\pm\frac{1}{\sqrt{2}} (\ket{0}+\ket{1})\ket{-}=\pm\ket{+}\ket{-}$.  If $f(0)\not=f(1)$, the resulting state is $\pm\frac{1}{\sqrt{2}} (\ket{0}-\ket{1})\ket{-}=\pm\ket{-}\ket{-}$.  We note then that these two states are orthogonal.  Therefore, there exists a unitary transformation which will map one of these states to $\ket{0}$ and the other to $\ket{1}$.  This transformation is the Hadamard gate.  Therefore, the resulting quantum circuit is:

\begin{equation*}
   \Qcircuit @C=1.0em @R=2.0em 
   {
     \lstick{\ket{+}} &  \qw & \multigate{1}{U_f} & \qw & \qw & \gate{H}  &  \qw& \qw &\qw & \qw &\meter & \cw\\
    \lstick{\ket{-}} &  \qw & \ghost{U_f} & \qw &\qw & \qw & \qw&  \qw& \qw &\qw &\meter	 & \cw&     \\
  \ket{+,-}  &&&&&&&&&&& (-1)^{f(\mathbf{x})}\ket{\mathbf{x},0}
   }
\end{equation*}\\
Thus if we observe the $\ket{0}$ state, we know that $f(0)=f(1)$, and vice-versa for an observation of the $\ket{1}$.  Therefore, we see that with only one query, we are able to determine the nature of $f$, with 100\% accuracy.

\section{Deutsch-Jozsa Problem}
Now we consider a more general problem, where our function takes a string of $n$ qubits:
\begin{align*}
f:\{0,1\}^n\to\{0,1\}
\end{align*}
Additionally, this is a promise problem; we are told some additional information about $f$.  In this particular case, we know that $f$ is either balanced or constant.  (In the n=1 case, we see that this reduces to just the Deutsch problem.)  It is our task to determine whether $f$ is balanced or constant.  How many queries are required to answer this question correctly?  Deterministically, $2^{n-1}+1$ queries are required.  The number of queries required using a classical randomized algorithm will depend on the allowed error.  If $k$ inputs are chosen at random, $k$ queries will yield a correct answer with error less than or equal to $2^{1-k}$.  (If the function is balanced, we could discover this in a minimum of two queries, if we are lucky.  The most unlucky we can be is to choose $k$ inputs that have the same output, leading us to guess incorrectly that the function is constant.  The probability of choosing $k$ inputs with the same output, and hence guessing wrong, is $2^{1-k}$.)  However, there exists a quantum algorithm which yields 100\% accuracy (modulo experimental error) with only 1 query, providing a tremendous speedup, from exponential to constant!

How does this algorithm work?  Start with an initial state which is a uniform superposition of $n$ qubits, tensored together with one ancilla in the $\ket{-}$ state, or:
\begin{align*}
\ket{\psi_0} = \frac{1}{\sqrt{2^n}} (\sum_{{\bf x} \in \{0,1\}^n} \ket{{\bf x}})\ket{-}
\end{align*}

\noindent Apply $U_f$ to this state.  If $f$ is constant, we find that:

\begin{align*}
U_f\ket{\psi_0} = \pm\frac{1}{\sqrt{2^{n}}}(\sum_{{\bf x} \in \{0,1\}^n} \ket{{\bf x}})\ket{-}
\end{align*}

If $f$ is balanced, $U_f\ket{\psi_0}$ takes on a more complicated form, but as in the Deutsch algorithm, $U_f^{balanced}\ket{\psi_0}$ is orthogonal to $U_f^{constant}\ket{\psi_0}$.  Therefore, all we need is, as before, a unitary transformation that will send $U_f^{balanced}\ket{\psi_0}$ to a string of all 0s.  Again, the Hadamard gate will serve this purpose; applying it to each (non-ancilla) wire yields the desired result.  If $f$ is constant, the final readout will be the all-0 string.  As $U_f^{balanced}\ket{\psi_0}$ is orthogonal to $U_f^{constant}\ket{\psi_0}$, the final readout for a balanced $f$ cannot be the all-0 string.  Thus in one query have we determined the nature of $f$, with 100\% accuracy.  Shown below is the quantum circuit diagram for this algorithm.

\begin{equation*}
   \Qcircuit @C=1.0em @R=2.0em 
   {
     \lstick{\ket{+}} &  \qw & \multigate{4}{U_f} & \qw & \qw &\gate{H}  &  \qw& \qw &\qw & \qw &\meter & \cw\\
    \lstick{\ket{+}} & \qw & \ghost{U_f} & \qw &\qw &\gate{H}  & \qw& \qw& \qw  &\qw &\meter	&  \cw&   \\
    \lstick{...}& \qw & \ghost{U_f} & \qw & \qw &\gate{H}  & \qw& \qw&\qw  &\qw &\meter	&  \cw&     \\
    \lstick{\ket{+}} & \qw & \ghost{U_f} & \qw &\qw &\gate{H} & \qw&\qw&\qw  &\qw &\meter	&  \cw&      \\
    \lstick{\ket{-}} &  \qw & \ghost{U_f} & \qw &\qw & \qw & \qw&  \qw& \qw &\qw &\qw	 & \qw&     \\
    }
    \end{equation*}
\hspace{40 mm}  $\ket{+}^{\otimes{n}}\ket{-}$ \hspace{50 mm} $\ket{0}^{\otimes{n}}\ket{-}$ (If $f$ is balanced.)
\subsection{Note on the Hadamard Gate}
Before proceeding, let us consider the operation of $n$ Hadamard gates on a base state of length $n$: $H^{\otimes n}\ket{x}$.  We see that such an operation has the following action:
\begin{equation}
H^{\otimes n}\ket{x} = \bigotimes_{i=1}^{n}\dfrac{\ket{0}+(-1)^{x_i}\ket{1}}{\sqrt{2}}=\dfrac{1}{\sqrt{2}^n}\sum_y(-1)^{{\bf x}\cdot{\bf y}}\ket{y}
\end{equation}
($\mathbf{x}\cdot\mathbf{y}$ denotes an inner product, that is, $\mathbf{x}\cdot\mathbf{y}=\sum_{i=1}^{n}x_iy_i$.)
Thus by appropriate choice of {\bf x}, we may generate all possible base states in the \{$\ket{+},\ket{-}\}$ basis.  Additionally, we can generate a uniform superposition of states if we choose {\bf x}={\bf 0}.
\section{Bernstein-Vazirani Problem}
Now consider the following function.
\begin{align*}
f:\{0,1\}^n \to \{0,1\}\\
{\bf x} \to ({\bf a} \cdot {\bf x} + b)\pmod{2}\\
({\bf a} \in \{0,1\}^n, b \in \{0,1\})
\end{align*}	
The promise is that $f$ conforms to the above constraints.  Our task is to determine the values of ${\bf a}$ and $b$.  (We note that the Bernstein-Vazirani promise is a restriction on Deutsch-Josza, but the question is harder to solve.)  With a classical deterministic algorithm, $n+1$ queries are required; 1 to determine $b$ (query with ${\bf x} = {\bf 0}$), and $n$ to determine  {\bf a}.  (We also note that is, classically, the optimal algorithm, as $n+1$ bits of information are required.)  A classical randomized algorithm will do no better, also requiring $n+1$ queries.
\begin{exercise}
Show that any classical randomized algorithm that solves the Bernstein-Vazirani problem with reasonable error makes at least $n+1$ queries.
\end{exercise}

Turning to the quantum algorithm, we will discover that there exists a solution that requires only two queries, solving with 100\% accuracy.  As before, one query is required for $b$, but now also only one query is required for {\bf a}.  $b$ is determined in the same manner as in the classical algorithm.  To determine {\bf a}, we initialize to:
\begin{align*}
\ket{\psi_0} = \ket{+}^{\otimes n}\ket{-}
\end{align*}
We note then that:
\begin{align*}
U_f\ket{\psi_0} = \frac{1}{\sqrt{2^n}}(\sum_{{\bf x} \in \{0,1\}^n} (-1)^{f({\bf x})} \ket{x})\ket{-}=\frac{(-1)^b}{\sqrt{2^n}} (\sum_{{\bf x} \in \{0,1\}^n} (-1)^{{\bf a} \cdot {\bf x}} \ket{{\bf x}})\ket{-}
\end{align*}

If we simply apply a Hadamard gate to each non-ancilla qubit, then the final readout will be of $\ket{{\bf a}}$ (along with the ancilla), as illustrated by equation (1).

\begin{equation*}
   \Qcircuit @C=1.0em @R=2.0em 
   {
     \lstick{\ket{+}} &  \qw & \multigate{4}{U_f} & \qw & \qw& \qw & \qw& \qw& \qw& \qw & \qw& \qw & \qw& \qw & \qw &\gate{H}  &  \qw& \qw &\qw & \qw &\meter & \cw\\
    \lstick{\ket{+}} & \qw & \ghost{U_f} & \qw& \qw & \qw& \qw& \qw & \qw& \qw& \qw& \qw & \qw& \qw &\qw &\gate{H}  & \qw& \qw& \qw  &\qw &\meter	&  \cw&   \\
    \lstick{...}& \qw & \ghost{U_f} & \qw & \qw& \qw & \qw& \qw& \qw & \qw& \qw& \qw& \qw & \qw& \qw &\gate{H}  & \qw& \qw&\qw  &\qw &\meter	&  \cw&     \\
    \lstick{\ket{+}} & \qw & \ghost{U_f} &  \qw& \qw & \qw& \qw& \qw & \qw& \qw& \qw& \qw & \qw &\qw &\qw &\gate{H} & \qw&\qw&\qw  &\qw &\meter	&  \cw&      \\
    \lstick{\ket{-}} &  \qw & \ghost{U_f} &  \qw& \qw & \qw& \qw& \qw & \qw& \qw& \qw& \qw & \qw&\qw &\qw & \qw & \qw&  \qw& \qw &\qw &\qw	 & \qw&     \\
    }
    \end{equation*}
\hspace{30 mm}  $\ket{+}^{\otimes{n}}\ket{-}$ \hspace{10 mm} $\frac{(-1)^b}{\sqrt{2}^n} \sum_x{(-1)^{\mathbf{a}\cdot\mathbf{x}}}\ket{\mathbf{x}}\ket{-}$ \hspace{40 mm}$\ket{\mathbf{a}}\ket{-}$

\noindent It turns out that this is the most optimal quantum algorithm for this problem; one cannot do better.

\section{Simon's Algorithm}
Now we examine a function  which maps not to $\{0,1\}$, but to $\{0,1\}^n$ instead.  More specifically

$f:\{0,1\}^n \to \{0,1\}^n$ such that either:

(1) $f$ is one-to-one ($f$ is a permutation.)

or

(2) $\exists {\bf s} \not ={\bf 0} \forall({\bf x},{\bf y})f({\bf x})=f({\bf y})\iff {\bf x}\oplus {\bf y}={\bf s}$  ($f$ is two-to-one.)

(It should be noted that (1) is a special case of (2), with ${\bf s}={\bf 0}$.)  Our goal here is to determine if $f$ falls into category (1) or (2), and also determine the value of {\bf s}.  If one were lucky, and $f$ fell into the second category, one could solve this problem classically with only two queries (by appropriately choosing {\bf x} and {\bf y} such that $f({\bf x})=f({\bf y})$).  However, this is not a reliable method, nor could it tell us if $f$ is one-to-one.  The general lower bound is achieved by picking $k$ possible values for {\bf s} ($k$ different spacings), eliminating ${k\choose 2}$ values for {\bf s}.  Thus the lower bound is approximately $2^{\frac{n}{2}}$ queries.  A randomized algorithm requires $\Omega(2^{\frac{n}{2}})$ queries.  However, there exists a quantum algorithm which can solve this problem in $O(n)$ time.  The demonstration of this technique is forthcoming in the next lecture (Lecture 5).

\end{document}