\section{Quantum Gates}


In the previous section, we stated that a quantum gate is a linear map. \par
Let's complete that definition.

\definition{}
A quantum gate is a \textit{orthonormal matrix}, which means any gate $G$
satisfies $GG^\text{T} = I$. \par
This implies the following: \par

\begin{itemize}
	\item $G$ is square. In other words, it has as many rows as it has columns. \par
	\note{
		If we think of $G$ as a map, this means that $G$ has as many inputs as it has outputs. \\
		This is to be expected: we stated earlier that quantum gates do not destroy or create qubits.
	}

	\item $G$ preserves lengths; i.e $|x| = |Gx|$. \par
	\note{This ensures that $G\ket{\psi}$ is always a valid state.}
\end{itemize}

(You will prove all these properties in any introductory linear algebra course. \\
This isn't a lesson on linear algebra, so you may take them as given today.)

\generic{Remark:}
Let $G$ be a quantum gate. \par
Since quantum gates are, by definition, \textit{linear} maps,
the following holds: \par

\begin{equation*}
	G\bigl(a_0 \ket{0} + a_1\ket{1}\bigr) = a_0G\ket{0} + a_1G\ket{1}
\end{equation*}

\problem{}<cnot>
Consider the \textit{controlled not} (or \textit{cnot}) gate, defined by the following table: \par
\begin{itemize}
	\item $\text{X}_\text{c}\ket{00} = \ket{00}$
	\item $\text{X}_\text{c}\ket{01} = \ket{01}$
	\item $\text{X}_\text{c}\ket{10} = \ket{11}$
	\item $\text{X}_\text{c}\ket{11} = \ket{10}$
\end{itemize}
In other words, the cnot gate inverts its second bit if its first bit is $\ket{1}$. \par
Find the matrix that applies the cnot gate.

\begin{solution}
	\begin{equation*}
		\text{X}_\text{c} = \left[\begin{smallmatrix}
			1 & 0 & 0 & 0 \\
			0 & 1 & 0 & 0 \\
			0 & 0 & 0 & 1 \\
			0 & 0 & 1 & 0 \\
		\end{smallmatrix}\right]
	\end{equation*}

	\vspace{4mm}

	If $\ket{a}$ is $\ket{0}$, $\ket{a} \otimes \ket{b}$ is
	$
	\left[
	\begin{smallmatrix}
		\left[
		\begin{smallmatrix}
			b_1 \\ b_2
		\end{smallmatrix}
		\right]
		\\ 0 \\ 0
	\end{smallmatrix}
	\right]
	$, and the \say{not} portion of the matrix is ignored.


	\vspace{4mm}

	If $\ket{a}$ is $\ket{1}$, $\ket{a} \otimes \ket{b}$ is
	$
	\left[
	\begin{smallmatrix}
		0 \\ 0 \\
		\left[
		\begin{smallmatrix}
			b_1 \\ b_2
		\end{smallmatrix}
		\right]
	\end{smallmatrix}
	\right]
	$, and the \say{identity} portion of the matrix is ignored.


	The state of $\ket{a}$ is always preserved, since it's determined by the position of
	$\left[\begin{smallmatrix}b_1 \\ b_2\end{smallmatrix}\right]$ in the tensor product.
	If $\left[\begin{smallmatrix}b_1 \\ b_2\end{smallmatrix}\right]$ is on top, $\ket{a}$ is $\ket{0}$,
	and if $\left[\begin{smallmatrix}b_1 \\ b_2\end{smallmatrix}\right]$ is on the bottom, $\ket{a}$ is $\ket{1}$.
\end{solution}




\vfill
\pagebreak



\problem{}<applycnot>
Evaluate the following:
\begin{equation*}
	\text{X}_\text{C}
	\Bigl(
		\frac{1}{2}\ket{00} +
		\frac{1}{2}\ket{01} -
		\frac{1}{2}\ket{10} -
		\frac{1}{2}\ket{11}
	\Bigr)
\end{equation*}


\vfill

\problem{}
If we measure the result of \ref{applycnot}, what are the probabilities of getting each state?

\vfill

\problem{}<cnotflipped>
Finally, modify the original cnot gate so that the roles of its bits are reversed: \par
$\text{X}_\text{c, flipped} \ket{ab}$ should invert $\ket{a}$ iff $\ket{b}$ is $\ket{1}$.


\begin{solution}
	\begin{equation*}
		\text{X}_\text{c, flipped} = \begin{bmatrix}
			1 & 0 & 0 & 0 \\
			0 & 0 & 0 & 1 \\
			0 & 0 & 1 & 0 \\
			0 & 1 & 0 & 0 \\
		\end{bmatrix}
	\end{equation*}
\end{solution}

\vfill
\pagebreak





\definition{}
The \textit{Hadamard Gate} is given by the following matrix: \par
\begin{equation*}
	H = \frac{1}{\sqrt{2}}\begin{bmatrix}
		1 & 1 \\
		1 & -1
	\end{bmatrix}
\end{equation*}
\note{Note that we divide by $\sqrt{2}$, since $H$ must be orthonormal.}

\begin{ORMCbox}{Review: Matrix Multiplication}{black!10!white}{black!65!white}
	Matrix multiplication works as follows:

	\begin{equation*}
		AB =
		\begin{bmatrix}
			1 & 2 \\
			3 & 4 \\
		\end{bmatrix}
		\begin{bmatrix}
			a_0 & b_0 \\
			a_1 & b_1 \\
		\end{bmatrix}
		=
		\begin{bmatrix}
			1a_0 + 2a_1 & 1b_0 + 2b_1 \\
			3a_0 + 4a_1 & 3b_0 + 4b_1 \\
		\end{bmatrix}
	\end{equation*}


	Note that this is very similar to multiplying each column of $B$ by $A$. \par
	The product $AB$ is simply $Ac$ for every column $c$ in $B$:

	\begin{equation*}
		Ac_0 =
		\begin{bmatrix}
			1 & 2 \\
			3 & 4 \\
		\end{bmatrix}
		\begin{bmatrix}
			a_0 \\ a_1
		\end{bmatrix}
		=
		\begin{bmatrix}
			1a_0 + 2a_1 \\
			3a_0 + 4a_1
		\end{bmatrix}
	\end{equation*}

	This is exactly the first column of the matrix product. \par
	Also, note that each element of $Ac_0$ is the dot product of a row in $A$ and a column in $c_0$.
\end{ORMCbox}


\problem{}
What is $HH$? \par
Using this result, find $H^{-1}$.

\begin{solution}
	$HH = I$, so $H^{-1} = H$
\end{solution}

\vfill

\problem{}
What geometric transformation does $H$ apply to the unit circle? \par
\hint{Rotation or reflection? How much, or about which axis?}

\vfill
\pagebreak
