\section{HXH}

Let's return to the quantum circuit diagrams we discussed a few pages ago. \par
Keep in mind that we're working with quantum gates and proper half-qubits---not classical bits, as we were before.

\definition{Controlled Inputs}
A \textit{control input} or \textit{inverted control input} may be attached to any gate. \par
These are drawn as filled and empty circles in our circuit diagrams:

\null\hfill
\begin{minipage}{0.48\textwidth}
	\begin{center}
		\begin{tikzpicture}[scale=0.8]
			\node[qubit] (a) at (0, 0) {$\ket{0}$};
			\node[qubit] (b) at (0, -1) {$\ket{0}$};

			\draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{0}$};
			\draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{0}$};

			\draw[wire]
			($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) --
			($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
			;
			\draw[wirejoin]
				($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
				circle[radius=0.1] coordinate(dot)
			;
			\qubox{a}{1}{a}{2}{$X$}

			\node[gray] at ($([shift={(0,-0.75)}] dot)$) {Non-inverted control input};
		\end{tikzpicture}
	\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.48\textwidth}
	\begin{center}
		\begin{tikzpicture}[scale=0.8]
			\node[qubit] (a) at (0, 0) {$\ket{0}$};
			\node[qubit] (b) at (0, -1) {$\ket{0}$};

			\draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{1}$};
			\draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{0}$};

			\draw[wire]
			($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) --
			($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
			;
			\draw[wireijoin]
				($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
				circle[radius=0.1] coordinate(dot)
			;
			\qubox{a}{1}{a}{2}{$X$}

			\node[gray] at ($([shift={(0,-0.75)}] dot)$) {Inverted control input};
		\end{tikzpicture}
	\end{center}
\end{minipage}
\hfill\null
\vspace{2mm}

An $X$ gate with a (non-inverted) control input behaves like an $X$ gate if \textit{all} its control inputs are $\ket{1}$,
and like $I$ otherwise. An $X$ gate with an inverted control inputs does the opposite, behaving like $I$ if its input is $\ket{1}$
and like $X$ otherwise. The two circuits above illustrate this fact---take a look at their inputs and outputs.

\vspace{2mm}
Of course, we can give a gate multiple controls. \par
An $X$ gate with multiplie controls behaves like an $X$ gate if...
\begin{itemize}
	\item all non-inverted controls are $\ket{1}$, and
	\item all inverted controls are $\ket{0}$
\end{itemize}
...and like $I$ otherwise.

\problem{}
What are the final states of the qubits in the diagram below?

\begin{center}
	\begin{tikzpicture}[scale = 1.0]
		\node[qubit] (a) at (0, 0) {$\ket{1}$};
		\node[qubit] (b) at (0, -1) {$\ket{0}$};
		\node[qubit] (c) at (0, -2) {$\ket{1}$};
		\node[qubit] (d) at (0, -3) {$\ket{0}$};

		\draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {?};
		\draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {?};
		\draw[wire] (c) -- ([shift={(3, 0)}] c.center) node[qubit] {?};
		\draw[wire] (d) -- ([shift={(3, 0)}] d.center) node[qubit] {?};

		\draw[wire]
		($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) --
		($([shift={(1,0)}] d)!0.5!([shift={(2,0)}] d)$)
		;
		\draw[wirejoin]
			($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$)
			circle[radius=0.1] coordinate(dot)
		;
		\draw[wireijoin]
			($([shift={(1,0)}] c)!0.5!([shift={(2,0)}] c)$)
			circle[radius=0.1] coordinate(dot)
		;
		\draw[wirejoin]
			($([shift={(1,0)}] d)!0.5!([shift={(2,0)}] d)$)
			circle[radius=0.1] coordinate(dot)
		;
		\qubox{b}{1}{b}{2}{$X$}
	\end{tikzpicture}
\end{center}

\vfill
\pagebreak

\problem{}
Consider the diagram below, with one controlled $X$ gate: \par
\note[Note]{The CNOT gate from \ref{cnot} is a controlled $X$ gate.}

\begin{center}
	\begin{tikzpicture}[scale=0.8]
		\node[qubit] (a) at (0, 0) {$\ket{a}$};
		\node[qubit] (b) at (0, -1) {$\ket{b}$};

		\draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {};
		\draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {};

		\draw[wire]
		($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) --
		($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
		;
		\draw[wirejoin]
			($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
			circle[radius=0.1] coordinate(dot)
		;
		\qubox{a}{1}{a}{2}{$X$}
	\end{tikzpicture}
\end{center}

Find a matrix $\text{X}_\text{c}$ that represents this gate, so that $\text{X}_\text{c}\ket{ab}$ works as expected.

\begin{solution}
	\begin{equation*}
		\text{X}_\text{c} = \begin{bmatrix}
			1 & 0 & 0 & 0 \\
			0 & 0 & 0 & 1 \\
			0 & 0 & 1 & 0 \\
			0 & 1 & 0 & 0
		\end{bmatrix}
	\end{equation*}
	Note that this is also the solution to \ref{cnotflipped}.
\end{solution}

\vfill

\problem{}
Now, evaluate the following. Remember that
$\ket{+} = \frac{1}{\sqrt{2}}\Bigl(\ket{0} + \ket{1}\Bigr)$ and
$\ket{-} = \frac{1}{\sqrt{2}}\Bigl(\ket{0} - \ket{1}\Bigr)$

\null\hfill
\begin{minipage}{0.48\textwidth}
	\begin{center}
		\begin{tikzpicture}[scale=0.8]
			\node[qubit] (a) at (0, 0) {$\ket{0}$};
			\node[qubit] (b) at (0, -1) {$\ket{1}$};

			\draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{a}$};
			\draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{b}$};

			\draw[wire]
			($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) --
			($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
			;
			\draw[wirejoin]
				($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
				circle[radius=0.1] coordinate(dot)
			;
			\qubox{a}{1}{a}{2}{$X$}
		\end{tikzpicture}
	\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.48\textwidth}
	\begin{center}
		\begin{tikzpicture}[scale=0.8]
			\node[qubit] (a) at (0, 0) {$\ket{0}$};
			\node[qubit] (b) at (0, -1) {$\ket{+}$};

			\draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{a}$};
			\draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{b}$};

			\draw[wire]
			($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) --
			($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
			;
			\draw[wirejoin]
				($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
				circle[radius=0.1] coordinate(dot)
			;
			\qubox{a}{1}{a}{2}{$X$}
		\end{tikzpicture}
	\end{center}
\end{minipage}
\hfill\null

\vspace{5mm}

\null\hfill
\begin{minipage}{0.48\textwidth}
	\begin{center}
		\begin{tikzpicture}[scale=0.8]
			\node[qubit] (a) at (0, 0) {$\ket{-}$};
			\node[qubit] (b) at (0, -1) {$\ket{1}$};

			\draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{a}$};
			\draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{b}$};

			\draw[wire]
			($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) --
			($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
			;
			\draw[wirejoin]
				($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
				circle[radius=0.1] coordinate(dot)
			;
			\qubox{a}{1}{a}{2}{$X$}
		\end{tikzpicture}
	\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.48\textwidth}
	\begin{center}
		\begin{tikzpicture}[scale=0.8]
			\node[qubit] (a) at (0, 0) {$\ket{+}$};
			\node[qubit] (b) at (0, -1) {$\ket{-}$};

			\draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{a}$};
			\draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{b}$};

			\draw[wire]
			($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) --
			($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
			;
			\draw[wirejoin]
				($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$)
				circle[radius=0.1] coordinate(dot)
			;
			\qubox{a}{1}{a}{2}{$X$}
		\end{tikzpicture}
	\end{center}
\end{minipage}
\hfill\null

\hint{
	Note that some of these states are entangled. The circuit diagrams are a bit misleading:
	we can't write an entangled state as two distinct qubits!

	\vspace{2mm}

	So, don't try to find $\ket{a}$ and $\ket{b}$. \par
	Instead find $\ket{ab} = \psi_0\ket{00} + \psi_1\ket{01} + \psi_2\ket{10} + \psi_3\ket{11}$, and factor it into $\ket{a} \otimes \ket{b}$ if you can.
}

\begin{solution}
	In all the below equations, let $\tau = \frac{1}{\sqrt{2}}$.
	\begin{itemize}[itemsep = 1mm]
		\item $
			\text{X}_\text{c}\ket{01}
			= \ket{11}
		$

		\item $
			\text{X}_\text{c}\ket{0+}
			= \tau\ket{00}  + \tau\ket{11}
		$ \note[Note]{This state is entangled!}

		\item $
			\text{X}_\text{c}\ket{-1}
			= -\tau\ket{10} + \tau\ket{11}
			= (-\ket{-}) \otimes \ket{1}
		$

		\item $
			\text{X}_\text{c}\ket{+-}
			= \frac{1}{2}(\ket{00} - \ket{01} + \ket{10} - \ket{11})
			= \ket{+-}
		$
	\end{itemize}
\end{solution}

\vfill
\pagebreak

\generic{Remark:}
Now, consider the following circuit:

\begin{center}
	\begin{tikzpicture}[scale=0.8]
		\node[qubit] (a) at (0, 0) {$\ket{0}$};
		\node[qubit] (b) at (0, -1) {$\ket{1}$};

		\draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {$\ket{a}$};
		\draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {$\ket{b}$};

		\qubox{b}{1}{b}{2}{$H$}
		\qubox{b}{3}{b}{4}{$H$}

		\draw[wire]
		($([shift={(2,0)}] a)!0.5!([shift={(3,0)}] a)$) --
		($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$)
		;
		\draw[wirejoin]
			($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$)
			circle[radius=0.1] coordinate(dot)
		;
		\qubox{a}{2}{a}{3}{$X$}

	\end{tikzpicture}
\end{center}

We already know that $H$ is its own inverse: $HH = I$. \par
Applying $H$ to a qubit twice does not change its state.

\note{
	Recall that $H = \frac{1}{\sqrt{2}}\left[\begin{smallmatrix} 1 & 1 \\ 1 & -1 \end{smallmatrix}\right]$
}


\vspace{2mm}

So, we might expect that the two circuits below are equivalent: \par
After all, we $H$ the second bit, use it to control an $X$ gate, and then $H$ it back to its previous state.

\null\hfill
\begin{minipage}{0.48\textwidth}\begin{center}
	\begin{tikzpicture}[scale=0.8]
		\node[qubit] (a) at (0, 0) {$\ket{0}$};
		\node[qubit] (b) at (0, -1) {$\ket{1}$};

		\draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {$\ket{a}$};
		\draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {$\ket{b}$};

		\qubox{b}{1}{b}{2}{$H$}
		\qubox{b}{3}{b}{4}{$H$}

		\draw[wire]
		($([shift={(2,0)}] a)!0.5!([shift={(3,0)}] a)$) --
		($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$)
		;
		\draw[wirejoin]
			($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$)
			circle[radius=0.1] coordinate(dot)
		;
		\qubox{a}{2}{a}{3}{$X$}

	\end{tikzpicture}
\end{center}\end{minipage}
\hfill
\begin{minipage}{0.48\textwidth}\begin{center}
	\begin{tikzpicture}[scale=0.8]
		\node[qubit] (a) at (0, 0) {$\ket{0}$};
		\node[qubit] (b) at (0, -1) {$\ket{1}$};

		\draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {$\ket{c}$};
		\draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {$\ket{d}$};

		\draw[wire]
		($([shift={(2,0)}] a)!0.5!([shift={(3,0)}] a)$) --
		($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$)
		;
		\draw[wirejoin]
			($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$)
			circle[radius=0.1] coordinate(dot)
		;
		\qubox{a}{2}{a}{3}{$X$}

	\end{tikzpicture}
\end{center}\end{minipage}
\hfill\null

\vspace{2mm}

This, however, isn't the case: \par
If we compute the state $\ket{ab}$ in the left circuit, we get $[0.5, ~0.5, -0.5, ~0.5]$ (which is entangled), \par
but the state $\ket{cd}$ on the right is $\ket{11} = [0,0,0,1]$. \par
\note{This is easy to verify with a few matrix multiplications.}


\vspace{4mm}

How does this make sense? \par
Remember that a two-bit quantum state is \textit{not} equivalent to a pair of one-qubit quantum states.
We must treat a multi-qubit state as a single unit.

Recall that a two-bit state $\ket{ab}$ comes with four probabilities:
$\mathcal{P}(\texttt{00})$, $\mathcal{P}(\texttt{01})$, $\mathcal{P}(\texttt{10})$, and $\mathcal{P}(\texttt{11})$.
If we change the probabilities of only $\ket{a}$, \textit{all four of these change!}


\vfill

Because of this fact, \say{controlled gates} may not work as you expect. They may seem
to \say{read} their controlling qubit without affecting its state, but remember---a
controlled gate still affects the \textit{entire} state. As we noted before, it is
not possible to apply a transformation to one bit of a quantum state.


\begin{center}
	\begin{tikzpicture}[scale=1]
		\node[qubit] (a) at (0, 0) {\texttt{1}};
		\node[qubit] (b) at (0, -1) {\texttt{0}};

		\draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {\texttt{0}};
		\draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {\texttt{1}};

		\ghostqubox{a}{1}{b}{2}{$T_1$}
		\ghostqubox{a}{2}{b}{3}{$T_2$}
		\ghostqubox{a}{3}{b}{4}{$T_3$}

	\end{tikzpicture}
\end{center}

\vfill
\pagebreak
