\documentclass[oneside]{amsart}  % {{{1
\usepackage{amssymb, mathtools, enumitem, booktabs, float, caption, tikz}
\usepackage[final]{hyperref, microtype}

% structure symbols
\newcommand{\NN}{\mathbb{N}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\CC}{\mathbb{C}}
\renewcommand{\AA}{\mathbb{A}}
\newcommand{\V}{\mathcal{V}}
\newcommand{\m}[1]{\mathbb{#1}}      % models
\newcommand{\alg}[1]{\m{#1}}         % algebras
\newcommand{\rel}[1]{\mathbf{#1}}    % relational structures
\newcommand{\cl}[1]{\mathcal{#1}}    % classes
\newcommand{\Comp}[1]{\textsf{#1}}   % complexity classes

% theorems and similar environments
\theoremstyle{plain}
  \newtheorem{thm}{Theorem}           \newtheorem*{thm*}{Theorem}
  \newtheorem{claim}{Claim}[thm]      \newtheorem*{claim*}{Claim}
  \newtheorem{conj}[thm]{Conjecture}  \newtheorem*{conj*}{Conjecture}
  \newtheorem{cor}[thm]{Corollary}    \newtheorem*{cor*}{Corollary}
  \newtheorem{lem}[thm]{Lemma}        \newtheorem*{lem*}{Lemma}
  \newtheorem{prop}[thm]{Proposition} \newtheorem*{prop*}{Proposition}
\theoremstyle{definition}
  \newtheorem{defn}[thm]{Definition} \newtheorem*{defn*}{Definition}
  \newtheorem{ex}[thm]{Example}      \newtheorem*{ex*}{Example}
\theoremstyle{remark}
  \newtheorem{rk}[thm]{Remark}  \newtheorem*{rk*}{Remark}
\newcommand{\Case}[1]{\smallskip \textbf{Case #1:}}
\newenvironment{claimproof}
  {
    \begin{proof}[Proof of claim]
    \renewcommand{\qedsymbol}{\ensuremath{\circ}}
  } {
    \end{proof}
  }

% custom commands
\DeclareMathOperator{\Cg}{Cg}
\DeclareMathOperator{\Clo}{Clo}
\DeclareMathOperator{\Con}{Con}
\DeclareMathOperator{\Inv}{Rel}
\DeclareMathOperator{\Pol}{Pol}
\DeclareMathOperator{\Sg}{Sg}
\DeclareMathOperator{\diag}{diag}
\newcommand{\bmat}[1]{ \begin{bmatrix} #1 \end{bmatrix} }
\newcommand{\Bmat}[1]{ \begin{Bmatrix} #1 \end{Bmatrix} }
\newcommand{\pmat}[1]{ \begin{pmatrix} #1 \end{pmatrix} }
\newcommand{\mat}[1]{ \begin{matrix} #1 \end{matrix} }
\newcommand{\vect}[1]{ \left< #1 \right> }
\newcommand{\ds}[1]{ \displaystyle{#1} }
\newcommand{\stack}[2]{\genfrac{}{}{0pt}{}{#1}{#2}}

% tikz
\usetikzlibrary{calc, matrix, positioning}
\newcommand{\TikzCenterNode}{\node (center) at ($(current bounding box.north east)!0.5!(current bounding box.south west)$) {\phantom{$\cdot$}};}

% misc
\renewcommand{\epsilon}{\varepsilon}
\renewcommand{\phi}{\varphi}
\newcommand{\todo}[1]{\noindent\textbf{TODO: #1}}
\renewcommand*{\arraystretch}{1.25} 
\setlist[enumerate]{itemsep=0.5em}
\setlist[itemize]{itemsep=0.5em}

% document specific stuff
% quantum
\newcommand{\bra}[1]{ \left< #1 \right| }
\newcommand{\ket}[1]{ \left| #1 \right> }
\newcommand{\bracket}[2]{ \left< #1 \mid #2 \right> }
\newcommand{\B}{\mathfrak{B}}
\tikzset{gate-c/.style = {draw, circle, inner sep=0.25em}}
\tikzset{gate-r/.style = {draw, rounded corners, rectangle}}
\tikzset{control/.style = {draw, fill, circle, inner sep=0.1em}}
\newcommand{\tikzMeasure}{
  \begin{tikzpicture}[scale=0.2, baseline=0pt]
    \draw (0,0) arc (180-20:20:1);
    \draw[->] (current bounding box.north|-current bounding box.south) -- ++(60:1.5);
  \end{tikzpicture} }

\newcommand{\Start}{\ket{\textnormal{\texttt{start}}}}
\newcommand{\StartBra}{\bra{\textnormal{\texttt{start}}}}
\newcommand{\End}{\ket{\texttt{end}}}
\newcommand{\EndBra}{\bra{\texttt{end}}}
%----------------------------------------------------------------------------}}}1

\begin{document}
% title matter {{{1
\title[Notes on Amplitude Amplification]{Notes on \\ Amplitude Amplification}
\author{Matthew Moore}
\date{\today}
\maketitle
%----------------------------------------------------------------------------}}}1

\subsection*{The Problem}
Suppose that we are given the following.
\begin{itemize}
  \item $\cl{A}$, a quantum circuit using no measurements.
  \item $\Start$ and $\End$, quantum states with $\cl{A}\Start = \End$.
  \item $\ket{\texttt{end}} = \ket{A} + \ket{B}$ with $\bracket{A}{B} = 0$,
    $\bracket{A}{A} = a$, and $\bracket{B}{B} = b = 1-a$.
\end{itemize}
Let us consider $\ket{A}$ as a superposition of all ``correct'' outcomes of
algorithm $\cl{A}$. Upon measuring $\End$, the probability of observing
$\ket{A}$ is $a$. We would like a procedure to increase the probability of
observing $\ket{A}$. 

We assume that we have a basis $(\psi_i)_{i\in I}$ such that $I = A \cup B$ and
a function $\chi:I \to \{0,1\}$ such that $\chi(A) = 1$ and $\chi(B) = 0$.
Define
\[
  \ket{\Psi(\alpha, \beta)}
  = \alpha \ket{A} + \beta \ket{B}
\]
and note that $\ket{\Psi(1,1)} = \End$.

\section*{A solution}
Let $P$ be a permutation matrix such that $P\Start = \ket{1\cdots 1}$ and define
quantum circuits $\widehat{R}_A$ and $R_s$ as below.
\begin{center}
  $\widehat{R}_A \ =$
  \begin{tikzpicture}[font=\scriptsize, yscale=0.5, baseline=(center.base)] % {{{
    \path (0,0) node (r1) {\phantom{$\ket{0}$}}
        ++(1.1,0) coordinate (r1_chi1)
        ++(1,0) coordinate (r1_e)
        ++(1,0) coordinate (r1_chi2)
        ++(1.1,0) node (r1_end) {\phantom{$\ket{0}$}}
          (r1)
        ++(0,-2) node (rn) {\phantom{$\ket{0}$}}
        ++(0,-1) node (z)  {$\ket{0}$};

    \TikzCenterNode
    \path (center-|r1_chi1) node[gate-r, minimum height=5.75em, minimum width=2em] (chi1) {$\chi_\oplus$}
          (center-|r1_chi2) node[gate-r, minimum height=5.75em, minimum width=2em] (chi2) {$\chi_\oplus$}
          (r1_e) ++(0,1) node[gate-c] (phase) {$e^{i\theta}$}
          (z-|r1_e) node[control] (z_control) {}
          (r1_end|-rn) node (rn_end) {\phantom{$\ket{0}$}}
          (r1_end|-z) node (z_end) {$\ket{0}$}
          ($(r1)!0.5!(rn-|chi1.west)+(0.1,0.2)$) node (dots1) {\vdots}
          ($(r1_end)!0.5!(rn_end-|chi2.east)+(-0.15,0.2)$) node (dots2) {\vdots};

    \draw (phase) -- (z_control);
    \path[->] (r1) edge (chi1.west|-r1) 
      (chi1.east|-r1) edge (chi2.west|-r1)
      (chi2.east|-r1) edge (r1_end);
    \path[->] (rn) edge (chi1.west|-rn) 
      (chi1.east|-rn) edge (chi2.west|-rn)
      (chi2.east|-rn) edge (rn_end);
    \path[->] (z) edge (chi1.west|-z) 
      (chi1.east|-z) edge (chi2.west|-z)
      (chi2.east|-z) edge (z_end);
  \end{tikzpicture} % }}}
\hfill
$\widehat{R}_\texttt{s} \ =$
  \begin{tikzpicture}[font=\scriptsize, yscale=0.5, baseline=(center.base)] % {{{
    \path (0,0) node (r1) {\phantom{$\ket{0}$}}
        ++(1.1,0) coordinate (r1_P)
        ++(1,0) coordinate[control] (r1_control)
        ++(1,0) coordinate (r1_Pi)
        ++(1.1,0) node (r1_end) {\phantom{$\ket{0}$}}
          (r1)
        ++(0,-2) node (rn) {\phantom{$\ket{0}$}};

    \TikzCenterNode
    \path (center-|r1_P) node[gate-r, minimum height=4.25em, minimum width=2em] (P) {$P$}
          (center-|r1_Pi) node[gate-r, minimum height=4.25em, minimum width=2em] (Pi) {$P^\dagger$}
          (r1_control|-rn) coordinate[control] (rn_control)
          (r1_control) ++(0,1) node[gate-c] (phase) {$e^{i\tau}$}
          (r1_end|-rn) node (rn_end) {\phantom{$\ket{0}$}}
          ($(r1)!0.5!(rn-|P.west)+(0.1,0.2)$) node (dots1) {\vdots}
          ($(r1_end)!0.5!(rn_end-|Pi.east)+(-0.15,0.2)$) node (dots2) {\vdots};

    \draw (phase) -- (rn_control);
    \path[->] (r1) edge (chi1.west|-r1) 
      (chi1.east|-r1) edge (chi2.west|-r1)
      (chi2.east|-r1) edge (r1_end);
    \path[->] (rn) edge (chi1.west|-rn) 
      (chi1.east|-rn) edge (chi2.west|-rn)
      (chi2.east|-rn) edge (rn_end);
  \end{tikzpicture} % }}}
\end{center}
Define operators
\[
  R_A 
  = \frac{e^{i\theta} - 1}{a} \ket{A}\bra{A} + I,
  \qquad\qquad
  R_\texttt{s}
  = (e^{i\tau} - 1)\Start\StartBra + I
\]
and note that $R_A\ket{\Psi(\alpha,\beta)} = \ket{\Psi(e^{i\theta} \alpha,
\beta)}$. Finally, define $\cl{G} = - \cl{A} \circ R_\texttt{s} \circ
\cl{A}^\dagger \circ R_A$.

\begin{lem} % {{{
$\widehat{R}_A$ computes $R_A$ using 1 ancilla and $\widehat{R}_\texttt{s}$ computes
$R_\texttt{s}$.
\end{lem} % }}}

\begin{lem} \label{lem:grover_recurrence} % {{{
\[
  \cl{G} \ket{\Psi(\alpha,\beta)}
  = - \ket{ \Psi\Big( 
    \big(a e^{i\tau} + b\big) e^{i\theta} \alpha + \big(e^{i\tau} - 1\big) b \beta,\ 
    \big(e^{i\tau} - 1\big) e^{i\theta} a \alpha + \big(b e^{i\tau} + a\big) \beta
    \Big) }.
\]
\end{lem} % }}}

\begin{thm} \label{thm:grover_exact} % {{{
Suppose that $\cl{A}$ acting on $\Start$ produces correct answers with
probability $a\in (0,1)$. The circuit $\cl{G}\circ \cl{A}$ acting on $\Start$ is
exact if and only if $\theta = \tau = \arccos(1 - 1/(2a))$ and $a\in [1/4, 1)$.
\end{thm}
\begin{proof}
From Lemma \ref{lem:grover_recurrence}, we have
\[
  \cl{G} \ket{\Psi(1,1)}
  = - \ket{ \Psi\Big( 
    \big(a e^{i\tau} + b\big) e^{i\theta} + \big(e^{i\tau} - 1\big) b,\ 
    \big(e^{i\tau} - 1\big) e^{i\theta} a + b e^{i\tau} + a
    \Big) }
\]
The probability of observing an incorrect answer when this state is measured is
\[
  b \big( (e^{i\tau} - 1) e^{i\theta} a + b e^{i\tau} + a \big)^2.
\]
$\cl{G}\circ \cl{A}$ is exact if and only if this quantity is equal to $0$.
Setting it equal to 0 and solving for $e^{i\theta}$ and $e^{i\tau}$ (we assume
$a,b\neq 0$) yields
\begin{align*}
  e^{i\theta}
    & = \frac{be^{i\tau}+a}{a(1-e^{i\tau})}
    = \frac{a-b}{2a} + \left( \frac{\sin(\tau)}{2a(1-\cos(\tau))} \right) i
    \qquad\qquad\text{and} \\
  e^{i\tau}
    &= \frac{(e^{i\theta}-1)a}{ae^{i\theta}+b}
    = \frac{a(a-b)(1-\cos(\theta))}{a^2+2ab\cos(\theta)+b^2} + \left( \frac{a\sin(\theta)}{a^2+2ab\cos(\theta)+b^2} \right) i.
\end{align*}
Equivalently,
\begin{align*}
  \cos(\theta) 
    &= \frac{a-b}{2a},
  & \sin(\theta)
    &= \frac{\sin(\tau)}{2a(1-\cos(\tau))}, \\
  \cos(\tau)
    &= \frac{a(a-b)(1-\cos(\theta))}{a^2+2ab\cos(\theta)+b^2},
  & \sin(\tau)
    &= \frac{a\sin(\theta)}{a^2+2ab\cos(\theta)+b^2}.
\end{align*}
Focusing on $\cos(\theta)$, using $b = 1-a$ this implies that $a\in (1/4,1)$.
Substituting the expression for $\cos(\theta)$ into the one for $\cos(\tau)$
yields
\[
  \cos(\tau)
  = \frac{(1/2)(a-b)^2}{a^2+b(a-b)+b^2}
  = \frac{a-b}{2a}
  = \cos(\theta).
\]
Substituting $\cos(\tau) = (a-b)/(2a)$ into the expression for $\sin(\theta)$
yields
\[
  \sin(\theta)
  = \frac{\sin(\tau)}{2a - a + b}
  = \sin(\tau).
\]
It follows from these that $\theta = \tau = \arccos(1-1/(2a))$. All of the
manipulations done were reversible, and equivalent to $\cl{G}\circ \cl{A}$ being
exact, establishing the claimed equivalence.
\end{proof} % }}}

\begin{thm} \label{thm:grover_recur_closed} % {{{
  Let $\theta = \tau = \pi$. Then
\[
  G^k \ket{\Psi(1,1)}
  = \ket{ \Psi\left( 
    \frac{1}{\sqrt{a}} \sin\big( (2k+1)\gamma \big),\ 
    \frac{1}{\sqrt{b}} \cos\big( (2k+1)\gamma \big) 
    \right) }
\]
where $\gamma$ is such that $e^{i\gamma} = \sqrt{b} + i\sqrt{a}$.
\end{thm}
\begin{proof}
  Define sequences $(\alpha_k)_{k\in \NN}$ and $(\beta_k)_{k\in \NN}$ by 
\[
  G^k \ket{\Psi(1,1)} = \ket{\Psi(\alpha_k,\beta_k)}.
\]
From Lemma \ref{lem:grover_recurrence}, these sequences are also defined
recursively by
\begin{align*}
  \alpha_k &= (b-a)\alpha_{k-1} + 2b\beta_{k-1}, & \alpha_0 &= 1, \\
  \beta_k &= -2a\alpha_{k-1} + (b-a)\beta_{k-1}, & \beta_0 &= 1.
\end{align*}
This is a linear homogeneous recurrence, and its equivalent matrix form is
\[
  \pmat{\alpha_k \\ \beta_k}
  = \pmat{b-a & 2b  \\
          -2a & b-a }
    \pmat{\alpha_{k-1} \\ \beta_{k-1}}
  = \pmat{b-a & 2b  \\
          -2a & b-a }^k
    \pmat{1 \\ 1}.
\]
Let $M$ be the matrix. $M$ diagonalizes as $M = PDP^{-1}$ where
\[
  D = \pmat{ \overline{\lambda}^2 & 0 \\ 0 & \lambda^2 },
  \qquad
  P = \frac{1}{\sqrt{a}} \pmat{ i\sqrt{b} & -i\sqrt{b} \\ \sqrt{a} & \sqrt{a} },
  \qquad
  P^{-1} = \frac{1}{2\sqrt{b}} \pmat{ -i\sqrt{a} & \sqrt{b} \\ i\sqrt{a} & \sqrt{b} }
\]
for $\lambda = e^{i\gamma} = \sqrt{b} + i\sqrt{b}$. We have
\begin{align*}
  \pmat{\alpha_k \\ \beta_k}
  &= PD^kP^{-1} \pmat{1 \\ 1}
  = \frac{1}{2\sqrt{b}} PD^k \pmat{\overline{\lambda} \\ \lambda}
  = \frac{1}{2\sqrt{b}} P \pmat{\overline{\lambda}^{2k+1} \\ \lambda^{2k+1}} \\
  &= \frac{1}{2\sqrt{ab}}
    \pmat{ i\sqrt{b} \Big( \overline{\lambda}^{2k+1} - \lambda^{2k+1} \Big) \\
           \sqrt{a} \Big( \overline{\lambda}^{2k+1} + \lambda^{2k+1} \Big) }
  = \pmat{ \frac{1}{\sqrt{a}} \sin\big( (2k+1) \gamma \big) \\
           \frac{1}{\sqrt{b}} \cos\big( (2k+1) \gamma \big) }. \qedhere
\end{align*}
\end{proof} % }}}

\begin{cor} \label{cor:grover_quadratic}  % {{{
Let $m = \lfloor \pi/(4\gamma) \rfloor$ where $\sin(\gamma) = \sqrt{a}$. If
$a\to 0$ as $n\to\infty$ then $\cl{G}^k\circ \cl{A}$ produces correct answers
with $\Theta(1/\sqrt{a})$ iterations of $\cl{A}$ and $\cl{A}^\dagger$.
\end{cor}
\begin{proof}
From Theorem \ref{thm:grover_recur_closed}, the circuit $\cl{G}^k\circ
\cl{A}$ acting on $\Start$ produces correct answers with probability
$\sin((2k+1)\gamma)^2$. We have
\[
  \sin\big( (2k+1)\gamma \big)
  \geq \sin\left( \left( \frac{\pi}{2\gamma} - 1 \right) \gamma \right)
  = \sin\left( \frac{\pi}{2} - \gamma \right)
  = \cos(\gamma).
\]
It follows that $\sin\big( (2k+1)\gamma \big)^2 \geq b = 1-a$. 

Hence the probability that a correct answer is observed when $\cl{G}^k\circ
\cl{A} \Start$ is measured is at least $1-a$, and after $1/(1-a)$ iterations we
can expect to have measured a correct answer. The number of calls to $\cl{A}$
and $\cl{A}^\dagger$ after $1/(1-a)$ iterations of $\cl{G}^k\circ \cl{A}$ is
$(2k+1)/(1-a)$. As $a\to 0$, we have $1-a \to 1$ and $\gamma \to \sqrt{a}$
(since $\sin(\gamma) = \sqrt{a}$). Hence $(2k+1)/(1-a) \to \pi/(2\sqrt{a})+1$,
so the number of iterations of $\cl{A}$ and $\cl{A}^\dagger$ is in
$\Theta(1/\sqrt{a})$.
\end{proof} % }}}
\end{document}
