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

% mathbb and mathcal 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

% theorems and similar environments
\theoremstyle{plain}
  \newtheorem{thm}{Theorem}[section]  \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{\Rel}{Rel}
\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
\numberwithin{equation}{section}  % number equations within sections
\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
\usepackage[margin=1in]{geometry}
\usepackage{subcaption}
\DeclareMathOperator{\CSP}{CSP}

% 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} }
%----------------------------------------------------------------------------}}}1

\begin{document}
% fig:phase_est_circuit {{{
\begin{figure}
  \begin{subfigure}{0.57\textwidth}
    % phase estimation circuit {{{
    \begin{tikzpicture}[font=\scriptsize, xscale=1.75]
      \tikzset{Usize/.style = {minimum size=2.75em, inner sep=0em}}
      \path (0,0) node (r1) {$\ket{0}$}
          ++(0.5,0) node[gate-c] (r1H) {$H$}
          ++(4,0) node[gate-r] (r1meas) {\tikzMeasure}
          ++(0.45,0) node (r1end) {}
            (r1)
          ++(0,-0.5) node (dots1) {$\vdots$}
          ++(0,-0.75) node (r2) {$\ket{0}$}
          ++(0,-1)    node (r3) {$\ket{0}$}
          ++(0,-1)    node (rpsi) {$\ket{\psi}$}
            (rpsi)
          ++(1,0) node[gate-c, Usize] (rpsiU0) {$U^{2^0}$}
          ++(0.8,0) node[gate-c, Usize] (rpsiU1) {$U^{2^1}$}
          ++(0.65,0) node (rpsidots)[inner sep=0.1em] {$\;\cdots$}
          ++(0.65,0) node[gate-c, Usize] (rpsiUn) {$U^{2^{n-1}}$};
      \path (r1H|-r2) node[gate-c] (r2H) {$H$}
            (r1H|-r3) node[gate-c] (r3H) {$H$}
            (r1meas|-r2) node[gate-r] (r2meas) {\tikzMeasure}
            (r1meas|-r3) node[gate-r] (r3meas) {\tikzMeasure}
            (r1end|-r2) node (r2end) {}
            (r1end|-r3) node (r3end) {}
            (r1end|-rpsi) node (rpsiend) {}
            (rpsidots|-dots1) node (dots2) {$\vdots$}
            (r1meas|-dots1) node (dots3) {$\vdots$};
      \coordinate (t) at ($(r1)!0.5!(r3)$);
      \node[gate-r, minimum height=7.2em] at ($(t-|rpsiUn)+(0.65,0)$) (Q) {$QFT_n^{-1}$};

      \draw (rpsiU0) -- (rpsiU0|-r3) node[control] {}
            (rpsiU1) -- (rpsiU1|-r2) node[control] {}
            (rpsiUn) -- (rpsiUn|-r1) node[control] {};
      \path[->] (r1) edge (r1H) (r1H) edge (Q.west|-r1end) (Q.east|-r1end) edge (r1meas) (r1meas) edge (r1end)
                (r2) edge (r2H) (r2H) edge (Q.west|-r2end) (Q.east|-r2end) edge (r2meas) (r2meas) edge (r2end)
                (r3) edge (r3H) (r3H) edge (Q.west|-r3end) (Q.east|-r3end) edge (r3meas) (r3meas) edge (r3end);
      \path[->] (rpsi) edge (rpsiU0) (rpsiU0) edge (rpsiU1) (rpsiU1) edge (rpsidots)
                (rpsidots) edge (rpsiUn) (rpsiUn) edge (rpsiend);
    \end{tikzpicture} % }}}
  \end{subfigure}
  \begin{subfigure}{0.4\textwidth}
    { \tiny \begin{align*}
      &\text{QFT}_n^{-1}[1,\dots,n] \\
      & \qquad \cdot \bigg( \prod_{k=0}^{n-1} \Lambda\Big( U^{2^k} \Big)[n-k,n+1,\dots,n+\ell] \bigg) \\
      & \qquad \cdot \Big( H^{\otimes n}\otimes I^{\otimes \ell} \Big) \ket{0\cdots 0} \otimes \ket{\psi}
    \end{align*} }
  \end{subfigure}
  \caption{The quantum circuit for $n$-bit estimation of the eigenvalue
    associated with the eigenvector $\ket{\psi}$ of $U$. The diagrammatic form
    is shown on the left, while the inline form is given on the right
    (measurement operators are omitted). Both utilize the inverse quantum
    Fourier transform as subroutines.}
  \label{fig:phase_est_circuit}
\end{figure}  % }}}

% fig:HKP_circuit {{{
\begin{figure}
  \begin{subfigure}{0.4\textwidth}
    % circuit {{{
    \begin{tikzpicture}[font=\scriptsize]
      \path (0,0) node (n1) {$\ket{0}$}
          ++(1,0) node[gate-c] (n1H1) {$H$}
          ++(1,0) coordinate (n1phi)
          ++(1,0) node[gate-c] (n1H2) {$H$}
          ++(1,0) node[gate-r] (n1meas) {\tikzMeasure}
          ++(0.75,0) node (n1end) {}
            (n1)
          ++(0,-0.5) node (ndots1) {$\vdots$}
          ++(0,-0.75) node (nn) {$\ket{0}$}
          ++(0,-0.5) node (m1) {$\ket{0}$}
          ++(0,-0.5) node (mdots1) {$\vdots$}
          ++(0,-0.75) node (mm) {$\ket{0}$};
      \coordinate (t) at ($(n1)!0.5!(mm)$);
      \path (n1H1|-nn) node[gate-c] (nnH1) {$H$}
            (n1phi|-t) node[gate-r, minimum height=10em, minimum width=1.55em] (phi) {$\widehat{\phi}$}
            (n1H2|-nn) node[gate-c] (nnH2) {$H$}
            (n1meas|-nn) node[gate-r] (nnmeas) {\tikzMeasure}
            (n1end|-nn) node (nnend) {}
            (n1end|-m1) node (m1end) {}
            (n1end|-mm) node (mmend) {}
            (n1meas|-ndots1) node (ndots2) {$\vdots$}
            (n1meas|-mdots1) node (mdots2) {$\vdots$};
      \path[->] (n1) edge (n1H1) (n1H1) edge (n1-|phi.west) (phi.east|-n1) edge (n1H2) (n1H2) edge (n1meas) (n1meas) edge (n1end)
                (nn) edge (nnH1) (nnH1) edge (nn-|phi.west) (phi.east|-nn) edge (nnH2) (nnH2) edge (nnmeas) (nnmeas) edge (nnend)
                (m1) edge (m1-|phi.west) (phi.east|-m1) edge (m1end)
                (mm) edge (mm-|phi.west) (phi.east|-mm) edge (mmend);
      \draw[densely dotted] (n1end.north west) -- (n1end.north east-|n1end.east) -- node[auto]{$n$} (nnend.south east-|nnend.east) -- (nnend.south west);
      \draw[densely dotted] (m1end.north west) -- (m1end.north east-|m1end.east) -- node[auto]{$m$} (mmend.south east-|mmend.east) -- (mmend.south west);
    \end{tikzpicture} % }}}
  \end{subfigure}
  \begin{subfigure}{0.3\textwidth}
    $\cl{M}_2 \ ( H^{\otimes n}\otimes I_m ) \ \widehat{\phi} \ ( H^{\otimes n}\otimes I_m )$
  \end{subfigure}
  \caption{A proposed quantum circuit for the Hidden Kernel Problem for
    semilattices. The equivalent inline formula is given to the right. The
    mathematical formalism for measuring a subset of qubits is taking the
    partial trace of the outer product of the output vector over the
    \emph{unmeasured} qubits. This measurement operator is represented by
    $\cl{M}_2$}
  \label{fig:HKP_circuit}
\end{figure}  % }}}

% fig:grover_circuit {{{
\begin{figure}
  % circuit {{{
  \begin{tikzpicture}[font=\scriptsize]
    \path (0,0) node (r1) {$\ket{0}$}
        ++(1,0) node[gate-c] (r1H1) {$H$}
        ++(0.95,0) coordinate (r1U)
        ++(0.95,0) node[gate-c] (r1H2) {$H$}
        ++(1.75,0) coordinate (r1D)
        ++(1.75,0) node[gate-c] (r1H3) {$H$}
        ++(1,0) node (r1dots) {$\cdots$}
        ++(1,0) node[gate-r] (r1meas) {\tikzMeasure}
        ++(0.75,0) node (r1end) {}
          (r1)
        ++(0,-0.6) node (vdots1) {$\vdots$}
        ++(0,-0.85) node (rn) {$\ket{0}$}
        ++(0,-1) node (rn1) {$\ket{1}$};
    \coordinate (tU) at ($(r1)!0.5!(rn1)$);
    \coordinate (tD) at ($(r1)!0.5!(rn)$);
    \path (r1H1|-rn) node[gate-c] (rnH1) {$H$}
          (r1U|-tU) node[gate-r, minimum height=7.9em, minimum width=1.55em] (U) {$U$}
          (r1D|-tD) node[gate-r, minimum height=5.3em] (D) {\tiny $2\ket{0^n}\bra{0^n}-I^{\otimes n}$}
          (r1H1|-vdots1) node (vdots2) {$\vdots$}
          (r1H2|-vdots1) node (vdots3) {$\vdots$}
          (r1H3|-vdots1) node (vdots4) {$\vdots$}
          (r1meas|-vdots1) node (vdots5) {$\vdots$}
          (r1H2|-rn) node[gate-c] (rnH2) {$H$}
          (r1H3|-rn) node[gate-c] (rnH3) {$H$}
          (r1dots|-rn) node (rndots) {$\cdots$}
          (r1meas|-rn) node[gate-r] (rnmeas) {\tikzMeasure}
          (r1H1|-rn1) node[gate-c] (rn1H1) {$H$}
          (r1end|-rn) node (rnend) {}
          (r1dots|-rn1) node (rn1dots) {$\cdots$}
          (r1end|-rn1) node (rn1end) {};
    \path[->] (r1)          edge (r1H1)    (r1H1)    edge (U.west|-r1)
              (U.east|-r1)  edge (r1H2)    (r1H2)    edge (D.west|-r1)
              (D.east|-r1)  edge (r1H3)    (r1H3)    edge (r1dots)
              (r1dots)      edge (r1meas)  (r1meas)  edge (r1end)
              (rn)          edge (rnH1)    (rnH1)    edge (U.west|-rn)
              (U.east|-rn)  edge (rnH2)    (rnH2)    edge (D.west|-rn)
              (D.east|-rn)  edge (rnH3)    (rnH3)    edge (rndots)
              (rndots)      edge (rnmeas)  (rnmeas)  edge (rnend)
              (rn1)         edge (rn1H1)   (rn1H1)   edge (U.west|-rn1)
              (U.east|-rn1) edge (rn1dots) (rn1dots) edge (rn1end);
    \coordinate (t1) at ($(rn1H1.east)!0.5!(U.west|-rn1)$);
    \coordinate (t2) at ($(r1H3.east)!0.5!(r1dots.west)$);
    \coordinate (t3) at ($(t1)!0.5!(t2)$);
    \draw[densely dotted, thick] ($(t1)+(0,-0.45)$) rectangle ($(t2)+(0,0.45)$);
    \node at ($(t3|-rn1)+(0,-0.7)$) {iterate $\approx (\pi/4)\sqrt{N}$ times};
  \end{tikzpicture} % }}}
  \caption{The quantum circuit for Grover's algorithm, with the function $f$
    encoded as the operator $U$. The central component is an amplitude
    amplification procedure which is required to be iterated approximately
    $(\pi/4)\sqrt{N}$ times. Geometrically, a single application corresponds to
    a rotation of a state vector towards the solution vector.}
  \label{fig:grover_circuit}
\end{figure}  % }}}

% fig:CSP_coloring {{{
\begin{figure}
  \begin{subfigure}{0.35\textwidth}
    % graphs {{{
    \begin{tikzpicture}[font=\scriptsize]
      \tikzset{vertex/.style = {minimum size=0.5em, inner sep=0em, draw, circle}}
      % G
      \path (0,0) node[vertex] (g1) {}
          ++(1.4142/2,-1.4142/2) node[vertex] (g2) {}
          ++(-1.4142/2,-1.4142/2) node[vertex] (g3) {}
          ++(1.4142/2,-1.4142/2) node[vertex] (g4) {}
          ++(1.4142/2,1.4142/2) node[vertex] (g5) {}
          ++(1.4142/2,-1.4142/2) node[vertex] (g6) {}
            (g4) ++ (0,-0.65) node {$\rel{G}$};
      \draw (g1) -- (g2) -- (g3) -- (g4) -- (g5) -- (g2) 
        (g5) -- (g6) (g2) -- (g4) 
        (g3) to[out=-90,in=180] ($(g4)+(0,-0.25)$) to[out=0,in=180+18] (g6);
      % K3
      \path (g1) 
        ++(4,-1.4142-1.732/4) node[vertex, fill=red] (k1) {}
          ++(1,0) node[vertex, fill=blue] (k2) {}
          ++(-1/2,1.732/2) node[vertex, fill=yellow] (k3) {};
      \coordinate (t) at ($(k1)!0.5!(k2)$);
      \node at ($(t)+(0,-0.5)$) {$\rel{K_3}$};
      \draw (k1) -- (k2) -- (k3) -- (k1);
      \draw[->] ($(g5)+(0.5,0.15)$) 
        to[out=30,in=180-30] node[auto,align=center]{exists $\alpha$?}
        ($(g5)+(2.5,0.15)$);
    \end{tikzpicture} % }}}
  \end{subfigure}
  \begin{subfigure}{0.4\textwidth}
    \vfill
    \scriptsize \begin{gather*}
      R_{ij}
      = \begin{cases}
        \big\{ (a,b)\in K_3^2 \mid a\neq b \big\} & \text{if $x_i - x_j$ in $\rel{G}$}, \\[0.25em]
        K_3^2                             & \text{otherwise}
      \end{cases} \\[0.25em]
      \text{constraint } C_{ij} = \big( (x_i, x_j) \;;\; R_{ij} \big) \\[0.25em]
      \cl{C} = \big\{ C_{ij} \mid 1\leq i,j\leq 6 \big\}
    \end{gather*}
    \vfill
  \end{subfigure}
  \caption{The Constraint Satisfaction Problem corresponding to graph
    3-colorability, $\CSP(\rel{K_3})$. The left shows the standard relational
    homomorphism formulation of the problem, and the right shows the equivalent
    system of constraints given as input to $\CSP(\rel{K_3})$, where the 6
    vertices of $\rel{G}$ are labelled with the variables $x_1,\ldots, x_6$.}
  \label{fig:CSP_coloring}
\end{figure}  % }}}
\end{document}
