\documentclass[a4paper]{article}

\usepackage{amsmath,amssymb,amsthm}
\usepackage{braket}
\usepackage[ps2pdf,bookmarks=true,bookmarksnumbered=true]{hyperref}

\input{qcircuit}

\hypersetup{
pdfauthor={Michal Charemza},
pdftitle={Quantum Circuit Diagrams},
pdfsubject={Quantum Computing},
pdfkeywords={quantum, computing, quantum circuit diagram}
}

\begin{document}
\author{Michal Charemza}
\title{Examples of Quantum Circuit Diagrams}
\date{April 2006}
\maketitle
Below some examples of quantum circuit diagrams are given. They are
typset using a modified version of the \LaTeX{} package
\emph{QCircuit}. The source for the present document, the modified
\emph{QCircuit} package, and the project \emph{An Introduction to
  Quantum Computing} from which the diagrams are taken are available
online at http://go.warwick.ac.uk/mtcharemza/pastprojects .


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
   \lstick{\ket{0}}   &   \gate{H}   &   \rstick{\frac{1}{\sqrt{2}}(\ket{0} + \ket{1}) } \qw
}
}
\caption{Example of Hadamard gate acting on one qubit.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
   \lstick{\ket{0}}   &   \targ   &    \rstick{\ket{1}} \qw
}
}
\caption{Example of a \emph{not} gate acting on one qubit.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
   \lstick{\ket{1}}   & \ctrl{1}    & \rstick{\ket{1}} \qw   \\
   \lstick{\ket{0}}   & \targ       & \rstick{\ket{1}} \qw
}
}
\caption{Example of a controlled-\emph{not} gate.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
   \lstick{\frac{1}{\sqrt{2}}\left(\ket{0}+\ket{1}\right)}   &   \measureD{M}   &   \rstick{\text{?}} \cw
}
}
\caption{Example of a measurement. Note that for the input mixed state
$\frac{1}{\sqrt{2}}\left(\ket{0}+\ket{1}\right)$, it is unknown what
the result of the measurement will be. All that is known is that the result
has equal probability of being $\ket{0}$ or $\ket{1}$.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
   \lstick{\ket{1}}   &   \ctrl{1}    &    \rstick{\ket{1}} \qw   \\
   \lstick{\ket{0}}   &   \targ       &    \rstick{\ket{1}} \qw
}
}
\caption{Example of a controlled-\emph{not} gate.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
  \lstick{\frac{1}{\sqrt{2}}\left(\ket{0}+\ket{1}\right)}  & \measureD{M}  & \rstick{\text{?}} \cw
}
}
\caption{Example of a measurement. Note that for the input mixed state
$\frac{1}{\sqrt{2}}\left(\ket{0}+\ket{1}\right)$, it is unknown what
the result of the measurement will be. All that is known is that the result
has equal probability of being $\ket{0}$ or $\ket{1}$.}
\end{figure}

\clearpage


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=0.1em {
   &                                                                  &      &   \multigate{13}{\rule{2em}{0em}C\rule{2em}{0em}}   &         &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &         &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &   \lstick{\raisebox{1.2em}{ $\mathbf{x} \in \mathbb{F}^2_n$} }   &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &    \rstick{\raisebox{1.4em}{$f(\mathbf{x}) \in \mathbb{F}^2_m$}  }   \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &   \qw   &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &         &                                                                      \\
   &                                                                  &      &   \ghost{\rule{2em}{0em}C\rule{2em}{0em}}           &         &    \push{\rule{0.1em}{0em}}
\gategroup{1}{3}{14}{3}{1.5em}{\{}
\gategroup{3}{5}{12}{5}{1.5em}{\}}
}
}
\caption{Boolean circuit performing function $f:\mathbb{F}^2_n \rightarrow \mathbb{F}^2_m$.}
\end{figure}



\begin{figure}[ht]
\centerline{
\Qcircuit @C=1em @!R {
   \lstick{\ket{x}}   &   \qw   &   \ctrl{1}   &   \qw   &   \rstick{\ket{x}}   \qw                     \\
   \lstick{\ket{y}}   &   \qw   &   \ctrl{1}   &   \qw   &   \rstick{\ket{y}}   \qw                     \\
   \lstick{\ket{z}}   &   \qw   &   \targ      &   \qw   &   \rstick{\ket{x \oplus (y \wedge z})} \qw
}
}
\caption{Toffoli gate.}
\end{figure}



\begin{figure}[ht]
\centerline{
\Qcircuit @C=1em @!R {
   \lstick{\ket{x}}   &   \qw        &   \qw                  &   \ctrl{1}   &   \qw                   &  \ctrl{1}  & \ctrl{2}             &   \qw        &   \rstick{\ket{x}}   \qw                     \\
   \lstick{\ket{y}}   &   \qw        &   \ctrl{1}             &   \targ      &   \ctrl{1}              &  \targ     & \qw                  &   \qw        &   \rstick{\ket{y}}   \qw                     \\
   \lstick{\ket{z}}   &   \gate{H}   &   \gate{F_{\pi / 2}}   &   \qw        &   \gate{F_{3\pi / 2}}   &  \qw       & \gate{F_{\pi / 2}}   &   \gate{H}   &   \rstick{\ket{x \oplus (y \wedge z})} \qw
}
}
\caption{Decomposition of a Toffoli gate.}
\end{figure}



\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
                      &         &                      &              &                            &         &                                     \\
   \lstick{\ket{x}}   &   \qw   &   \qw                &   \ctrl{1}   &   \rstick{\ket{x}}   \qw   &         &                                     \\
   \lstick{\ket{y}}   &   \qw   &   \qw                &   \ctrl{1}   &   \rstick{\ket{y}}   \qw   &         &                                     \\
                      &         &   \lstick{\ket{0}}   &   \targ      &   \qw                      &   \qw   &   \rstick{\ket{x \wedge y}}   \qw   \\
                      &         &                      &              &                            &         &   \push{\rule{0.2em}{0em}}
\gategroup{1}{2}{5}{6}{1.5em}{.}
}
}
\caption{Toffoli gate as an \emph{and} gate.}
\end{figure}




\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
                       &         &                      &           &                 &                                &         &                                   \\
   \lstick{\ket{x}}    &   \qw   &   \qw                &   \targ   &   \ctrl{1}      &   \rstick{\ket{\neg x}}  \qw   &         &                                   \\
   \lstick{\ket{y}}    &   \qw   &   \qw                &   \targ   &   \ctrl{1}      &   \rstick{\ket{\neg y}}  \qw   &         &                                   \\
                       &         &   \lstick{\ket{0}}   &   \qw     &   \targ         &   \targ                        &   \qw   &   \rstick{\ket{x \vee y}}   \qw   \\
                       &         &                      &           &                 &                                &         &   \push{\rule{0.2em}{0em}}
\gategroup{1}{2}{5}{7}{1.5em}{.}
}
}
\caption{A Toffoli gate as an \emph{or} gate.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
                      &         &                      &           &              &                            &        &                              \\
   \lstick{\ket{x}}   &   \qw   &   \qw                &   \qw     &   \ctrl{1}   &   \qw                      &   \qw  &   \rstick{\ket{x}}   \qw     \\
                      &         &   \lstick{\ket{0}}   &   \targ   &   \ctrl{1}   &   \rstick{\ket{1}}   \qw   &        &                              \\
                      &         &   \lstick{\ket{0}}   &   \qw     &   \targ      &   \qw                      &   \qw  &   \rstick{\ket{x}}   \qw     \\
                      &         &                      &           &              &                            &        &   \push{\rule{0.2em}{0em}}
\gategroup{1}{2}{5}{7}{1.5em}{.}
}
}
\caption{Toffoli gate as \emph{fanout}.}
\end{figure}

\clearpage


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=0.1em {
   &                                                                   &                  &   \multigate{21}{\rule{2em}{0em}R\rule{2em}{0em}}   &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &  \rstick{\raisebox{1.4em}{$\ket{f(\mathbf{x})}$}}   \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &   \lstick{\raisebox{1.4em}{$\ket{\mathbf{x}}$}}                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &         &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &         &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghostnowire{\rule{2em}{0em}R\rule{2em}{0em}}     &   \qw   &                                                     \\
   &                                                                   &                  &   \ghostnowire{\rule{2em}{0em}R\rule{2em}{0em}}     &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   & \rstick{\raisebox{1.4em}{garbage bits}}             \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &   \lstick{\raisebox{1.4em}{$\ket{\mathbf{0}}$ (ancilla qubits)}}  &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &                                                     \\
   &                                                                   &                  &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   & \push{\rule{0.1em}{0em}}
\gategroup{1}{3}{14}{3}{1.5em}{\{}
\gategroup{17}{3}{22}{3}{1.5em}{\{}
\gategroup{1}{5}{8}{5}{1.5em}{\}}
\gategroup{11}{5}{22}{5}{1.5em}{\}}
}
}
\caption{Quantum circuit emulating boolean circuit that performs function $f:\mathbb{F}^2_n \rightarrow \mathbb{F}^2_m$.}
\end{figure}

\begin{figure}[ht]
\centerline{
\Qcircuit @C=0.4em @R=0.1em {
                                                   &      &      &   \qw   &   \multigate{21}{\rule{2em}{0em}R\rule{2em}{0em}}   &   \qw   &   \ctrl{23}   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \multigate{21}{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}   &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \ctrl{23}   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \ctrl{23}   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \ctrl{23}   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \ctrl{23}   &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \ctrl{23}   &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \ctrl{23}   &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
   \lstick{\raisebox{1.4em}{$\ket{\mathbf{x}}$}}   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \ctrl{23}   &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &   \rstick{\raisebox{1.4em}{$\ket{\mathbf{x}}$}}      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &         &               &               &               &               &               &               &               &               &          &   \ghostnowire{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}     &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &         &               &               &               &               &               &               &               &               &          &   \ghostnowire{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}     &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &         &   \ghostnowire{\rule{2em}{0em}R\rule{2em}{0em}}     &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &         &          &      &                                                      \\
                                                   &      &      &         &   \ghostnowire{\rule{2em}{0em}R\rule{2em}{0em}}     &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &         &          &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
   \lstick{\raisebox{1.4em}{$\ket{\mathbf{0}}$}}   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &   \rstick{\raisebox{1.4em}{$\ket{\mathbf{0}}$}}      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \ghost{\rule{2em}{0em}R\rule{2em}{0em}}           &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \ghost{\rule{1.8em}{0em}R^{-1}\rule{1.8em}{0em}}           &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &         &   \push{\rule{0em}{2em}}                            &         &               &               &               &               &               &               &               &               &          &   \push{\rule{0em}{1em}}                                     &         &          &      &                                                      \\
                                                   &      &      &   \qw   &   \qw                                               &   \qw   &   \targ       &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \qw                                                        &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \qw                                               &   \qw   &   \qw         &   \targ       &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \qw                                                        &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \qw                                               &   \qw   &   \qw         &   \qw         &   \targ       &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \qw                                                        &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \qw                                               &   \qw   &   \qw         &   \qw         &   \qw         &   \targ       &   \qw         &   \qw         &   \qw         &   \qw         &   \qw    &   \qw                                                        &   \qw   &    \qw   &      &                                                      \\
   \lstick{\raisebox{1.4em}{$\ket{\mathbf{0}}$}}   &      &      &   \qw   &   \qw                                               &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \targ       &   \qw         &   \qw         &   \qw         &   \qw    &   \qw                                                        &   \qw   &    \qw   &      &   \rstick{\raisebox{1.4em}{$\ket{f(\mathbf{x})}$}}   \\
                                                   &      &      &   \qw   &   \qw                                               &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \targ       &   \qw         &   \qw         &   \qw    &   \qw                                                        &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \qw                                               &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \targ       &   \qw         &   \qw    &   \qw                                                        &   \qw   &    \qw   &      &                                                      \\
                                                   &      &      &   \qw   &   \qw                                               &   \qw   &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \qw         &   \targ       &   \qw    &   \qw                                                        &   \qw   &    \qw   &      &   \push{\rule{0.01em}{0em}}
\gategroup{1}{3}{14}{3}{1.5em}{\{}
\gategroup{17}{3}{22}{3}{1.5em}{\{}
\gategroup{24}{3}{31}{3}{1.5em}{\{}
\gategroup{1}{18}{14}{18}{1.5em}{\}}
\gategroup{17}{18}{22}{18}{1.5em}{\}}
\gategroup{24}{18}{31}{18}{1.5em}{\}}
}
}
\caption{Quantum circuit emulating boolean circuit that performs function $f:\mathbb{F}^2_n \rightarrow \mathbb{F}^2_m$. Note that this circuit preserves input and ancilla qubits.}

\end{figure}

\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
                                 &                          &                          &                 &              &              &                  &                                    &   \mbox{Alice}   \\
   \lstick{a\rule{0.5em}{0em}}   &   \control \cw \qwx[2]   &   \cw                    &   \cw           &   \cw        &   \cw        &   \cw            &   \cw                              &   \lstick{a}     \\
   \lstick{b\rule{0.5em}{0em}}   &   \cw                    &   \control \cw \qwx[1]   &   \cw           &   \cw        &   \cw        &   \cw            &   \rstick{\rule{0.5em}{0em}} \cw   &   \lstick{b}     \\
   \lstick{A\rule{0.5em}{0em}}   &   \gate{F}               &   \targ                  &   \qw \qwx[1]   &              &              &                  &   \push{\rule{0em}{1.5em}}         &                  \\
                                 &                          &                          &   \qwx[1]       &              &              &                  &                                    &                  \\
                                 &                          &                          &   \qwx[1]       &              &              &                  &                                    &   \mbox{Bob}     \\
   \push{\rule{0em}{1.5em}}      &                          &                          &                 &   \ctrl{1}   &   \gate{H}   &   \measureD{M}   &   \cw                              &   \lstick{a}     \\
   \lstick{B\rule{0.5em}{0em}}   &   \qw                    &   \qw                    &   \qw           &   \targ      &   \qw        &   \measureD{M}   &   \push{\rule{0em}{1.5em}}  \cw    &   \lstick{b}
\gategroup{1}{1}{4}{8}{.7em}{.}
\gategroup{6}{1}{8}{8}{.7em}{.}
}
}
\caption{Superdense coding.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
                                           &              &              &                  &                 &                 &                           &                           &                                &   \mbox{Alice}   \\
   \lstick{\ket{\psi} \rule{0.5em}{0em}}   &   \ctrl{1}   &   \gate{H}   &   \measureD{M}   &   \cw           &   \cw \cwx[1]   &                           &                           &                                &                  \\
   \lstick{A\rule{0.5em}{0em}}             &   \targ      &    \qw       &   \measureD{M}   &   \cw \cwx[1]   &   \cwx[1]       &                           &                           & \push{\rule{0em}{1.5em}}       &                  \\
                                           &              &              &                  &   \cwx[1]       &   \cwx[1]       &                           &                           &                                &                  \\
                                           &              &              &                  &   \cwx[1]       &   \cwx[1]       &                           &                           &                                &   \mbox{Bob}     \\
                                           &              &              &                  &   \cwx[1]       &                 &   \cw                     &   \control \cw  \qwx[2]   & \cw                            &                  \\
                                           &              &              &                  &                 &   \cw           &   \control \cw  \qwx[1]   &   \cw                     & \cw                            &                  \\
   \lstick{B\rule{0.5em}{0em}}             &   \qw        &   \qw        &   \qw            &   \qw           &   \qw           &   \targ                   &   \gate{F}                & \push{\rule{0em}{1.5em}} \qw   &   \ket{\psi}
\gategroup{1}{1}{3}{9}{.7em}{.}
\gategroup{5}{1}{8}{9}{.7em}{.}
}
}
\caption{Quantum teleportation.}

\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
                                                      &            &   \multigate{4}{QFT_{\mathbb{F}_{2}^{m}}}   &   \qw      &                                                                                                                                                         \\
                                                      &            &   \ghost{QFT_{\mathbb{F}_{2}^{m}}}          &   \qw      &                                                                                                                                                         \\
  \lstick{\raisebox{1.2em}{ $\ket{\mathbf{x}}$}~~ }   &            &   \ghost{QFT_{\mathbb{F}_{2}^{m}}}          &   \qw      &   \rstick{\raisebox{1.2em}{~ $\frac{1}{\sqrt{2^m}}\displaystyle\sum_{\mathbf{y}\in\mathbb{F}_{2}^{m}}(-1)^{\mathbf{x}.\mathbf{y}}\ket{\mathbf{y}}$} }   \\
                                                      &   \vdots   &                                             &   \vdots   &                                                                                                                                                         \\
                                                      &            &   \ghost{QFT_{\mathbb{F}_{2}^{m}}}          &   \qw      &   \push{\rule{0em}{0.1em}}
\gategroup{1}{1}{5}{1}{0.5em}{\{}
\gategroup{1}{5}{5}{5}{0.5em}{\}}
}
}
\caption{Quantum Fourier transform in $\mathbb{F}_{2}^{m}$.}

\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=1.5em {
                                                       &            &   \gate{\rule{2em}{0em}H\rule{2em}{0em}}   &   \qw      &                                                                                                                                                         \\
                                                       &            &   \gate{\rule{2em}{0em}H\rule{2em}{0em}}   &   \qw      &                                                                                                                                                         \\
   \lstick{\raisebox{1.2em}{ $\ket{\mathbf{x}}$}~~ }   &            &   \gate{\rule{2em}{0em}H\rule{2em}{0em}}   &   \qw      &   \rstick{\raisebox{1.2em}{~ $\frac{1}{\sqrt{2^m}}\displaystyle\sum_{\mathbf{y}\in\mathbb{F}_{2}^{m}}(-1)^{\mathbf{x}.\mathbf{y}}\ket{\mathbf{y}}$} }   \\
                                                       &   \vdots   &                                            &   \vdots   &                                                                                                                                                         \\
                                                       &            &   \gate{\rule{2em}{0em}H\rule{2em}{0em}}   &   \qw      &   \push{\rule{0em}{0.1em}}
\gategroup{1}{1}{5}{1}{0.5em}{\{}
\gategroup{1}{5}{5}{5}{0.5em}{\}}
}
}
\caption{Decomposition of QFT in $\mathbb{F}_{2}^{m}$.}
\end{figure}

\begin{figure}[ht]
\centerline{
\Qcircuit @C=1.5em @R=1em {
   \lstick{\ket{\psi}}   &   \ctrl{1}   &   \targ       & \ctrl{1}  &   \rstick{\ket{\phi}} \qw   \\
   \lstick{\ket{\phi}}   &   \targ      &   \ctrl{-1}   & \targ     &   \rstick{\ket{\psi}} \qw
}
}
\caption{Swap of two qubits.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=1em @R=0.75em {
   \lstick{\ket{x_{m-1}}}   &   \gate{H}  &   \gate{\phi}   &   \gate{\phi}   &   \qw      &   \gate{\phi}   &   \qw        &   \qw           &   \qw      &   \qw           &   \qw        &   \qw     &   \qw           &   \qw        &   \rstick{\ket{y_0}} \qw       \\
   \lstick{\ket{x_{m-2}}}   &   \qw       &   \ctrl{-1}     &   \qw           &   \qw      &   \qw           &   \gate{H}   &   \gate{\phi}   &   \qw      &   \gate{\phi}   &   \qw        &   \qw     &   \qw           &   \qw        &   \rstick{\ket{y_1}} \qw       \\
   \lstick{\ket{x_{m-3}}}   &   \qw       &   \qw           &   \ctrl{-2}     &   \qw      &  \qw            &   \qw        &   \ctrl{-1}     &   \qw      &   \qw           &   \gate{H}   &   \qw     &   \gate{\phi}   &   \qw        &   \rstick{\ket{y_2}} \qw       \\
   \lstick{\vdots }         &             &                 &                 &   \ddots   &                 &              &                 &   \ddots   &                 &              &   \ddots  &                 &              &   \rstick{\vdots }             \\
   \lstick{\ket{x_{0}}}     &   \qw       &   \qw           &   \qw           &   \qw      &   \ctrl{-4}     &    \qw       &   \qw           &   \qw      &   \ctrl{-3}     &   \qw        &   \qw     &   \ctrl{-2}     &   \gate{H}   &   \rstick{\ket{y_{m-1}}} \qw
}
}
\caption{Decomposition of QFT in $\mathbb{Z}_{2^m}$.}
\end{figure}


\begin{figure}[ht]
\centerline{
\Qcircuit @C=2em @R=0.9em {
                                            &            &   \multigate{4}{H_m}   &   \multimeasureD{4}{M}   &   \cw      &                                             \\
                                            &            &   \ghost{H_m}          &   \ghost{M}              &   \cw      &                                             \\
   \lstick{\raisebox{1.2em}{$\ket{0}$~~}}   &            &   \ghost{H_m}          &   \ghost{M}              &   \cw      &   \rstick{\raisebox{1.2em}{~~$\ket{y}$} }   \\
                                            &   \vdots   &                        &                          &   \vdots   &                                             \\
                                            &            &   \ghost{H_m}          &   \ghost{M}              &   \cw      &   \push{\rule{0em}{0.5em}}
\gategroup{1}{6}{5}{6}{.7em}{\}}
\gategroup{1}{1}{5}{1}{.7em}{\{}
}
}
\caption{Circuit that generates random numbers.}
\end{figure}

\end{document}