Lecture 005 - Quantum Gates

Quantum Gates

Classical vs. Quantum Execution Order

Classical vs. Quantum Execution Order

Quantum Cheat Sheet

Quantum Cheat Sheet

Quantum Gates and Their Properties

Quantum Gates and Their Properties

Circuit representation of elementary quantum gates

Circuit representation of elementary quantum gates

We model all instructions (gates) as

\text{Add } F(x_1, x_2, ...) \text{ To Answer}
Name Interpret F
I Add 0 to Ans F() = 0
Not, X Add 1 to Ans F() = 1
Controlled-Not, CNOT, XNOT Add x_1 to Ans F(x_1) = x_1
C_0NOT Add NOT x_1 to Ans F(x_1) = \lnot x_1
Controlled-CNot CCNOT, Toffoli Add x_1 \land x_2 to Ans F(x_1, x_2) = x_1 \land x_2
N/A Add x_1 \lor x_2 to Ans F(x_1, x_2) = x_1 \lor x_2
Swap Swap A with B L/R Shift on 2 bits


Any truth table can be built by circuit

Any circuit can be converted to reversible manner, except for creating zero-ed input.

Theorem: \forall F: \{0, 1\}^n \to \{0, 1\}^m if it is computable with G classical gates, then you can convert to reversible quantum gates with n+m+G qubits and G+n gates, assuming all extra G bits are initialized to 0, left in a garbage state.

Theorem: reduction from turing machine to gates is only polynomial slowdown.

DeMorgan's Law: you only need NOT and one of AND or OR gate to perform all deterministic binary operation (Note that TM-complete also requires random access infinite memory)

CCNOT(X,Y,Z): "Add (X AND Y) To Z", equivalent of AND gate in quantum, but if we allow Z to be 1, it is NAND gate (because we are adding, instead of setting like classical computer).

"Garbage" Collection

Garbage Problem

Why get rid of trash?

Example: say we have a qubit a along with some other qubits q_0, ..., q_n

When all q_0, ..., q_n are deterministic, then we might have the following state: (result of H(0))

\begin{align*} \text{Amplitude}(0, 0...0)=&\sqrt{1/2}\\ \text{Amplitude}(1, 0...0)=&\sqrt{1/2}\\ \end{align*}

Then we do a H gate, we have: (result of H(H(0)) = 0)

\begin{align*} \text{Amplitude}(0, 0...0)=&\frac{1}{2}+\frac{1}{2}=1\\ \text{Amplitude}(1, 0...0)=&\frac{1}{2}-\frac{1}{2}=0\\ \text{Probability}(0, 0...0)=&1^2=1\\ \text{Probability}(1, 0...0)=&0^2=0\\ \end{align*}

which is all good.

However, if at least one of q_0, ..., q_n are non-deterministic garbage, then the amplitude will perhaps look like: (where the first and last bit of trash is entangled with the qubit we care about)

\begin{align*} \text{Amplitude}(0, 1...0)=&\sqrt{1/2}\\ \text{Amplitude}(1, 0...1)=&\sqrt{1/2}\\ \end{align*}

Then we do a H gate, we have

\begin{align*} \text{Amplitude}(0, 1...0)=&\frac{1}{2}\\ \text{Amplitude}(1, 0...1)=&\frac{1}{2}\\ \text{Amplitude}(0, 0...0)=&\frac{1}{2}\\ \text{Amplitude}(1, 0...0)=&-\frac{1}{2}\\ \text{Probability}(0, 1...0)=&\left(\frac{1}{2}\right)^2=\frac{1}{4}\\ \text{Probability}(1, 0...1)=&\left(\frac{1}{2}\right)^2=\frac{1}{4}\\ \text{Probability}(0, 0...0)=&\left(\frac{1}{2}\right)^2=\frac{1}{4}\\ \text{Probability}(1, 0...0)=&\left(-\frac{1}{2}\right)^2=\frac{1}{4}\\ \end{align*}

Note that none of the states above can be merged, therefore we observe 0 and 1 half of the time.

Garbage Removal

Easy. We just reverse (inverse) all the instruction except for the last where we add the answer.

We can always transform classical circuit with G gates to deterministic, reversible, garbage-free gates with \leq 2 \cdot G gates.


When we measure, we use one particle, say |m\rangle, to interact with another partical |v\rangle we want to measure. If we don't keep track of |m\rangle, it will look like we have measured |v\rangle. But what it really does is |m\rangle becomes entangled with |v\rangle, and since we lost track of |m\rangle, it becomes garbage. In math, you can write:

Say you have a qubit you want to measure:

|v\rangle = |Rot_{0^\circ}\rangle + |Rot_{90^\circ}\rangle = |\uparrow\rangle + |\downarrow\rangle = |Rot_{45^\circ}\rangle

Then you collide |v\rangle with |m\rangle, and it produces some maximally entangled particle, say:

|vm\rangle = |Rot_{0^\circ}\rangle|Rot_{0^\circ}\rangle + |Rot_{90^\circ}\rangle|Rot_{90^\circ}\rangle

Let us have a measurement device that measure only qubit |v\rangle in |Rot_{45^\circ}\rangle, |Rot_{135^\circ}\rangle, then we have

\begin{align*} |Rot_{90^\circ}\rangle =& |Rot_{45^\circ}\rangle + |Rot_{135^\circ}\rangle = |\leftarrow\rangle + |\rightarrow\rangle\\ |Rot_{0^\circ}\rangle =& |Rot_{45^\circ}\rangle - |Rot_{135^\circ}\rangle = |\leftarrow\rangle - |\rightarrow\rangle\\ \end{align*}

So we subsitute above into |vm\rangle:

\begin{align*} |vm\rangle =& |Rot_{0^\circ}\rangle|Rot_{0^\circ}\rangle + |Rot_{90^\circ}\rangle|Rot_{90^\circ}\rangle\\ =&(|Rot_{45^\circ}\rangle - |Rot_{135^\circ}\rangle)|Rot_{0^\circ}\rangle + (|Rot_{45^\circ}\rangle + |Rot_{135^\circ}\rangle)|Rot_{90^\circ}\rangle\\ =&|Rot_{45^\circ}\rangle|Rot_{0^\circ}\rangle - |Rot_{135^\circ}\rangle|Rot_{0^\circ}\rangle + (|Rot_{45^\circ}\rangle|Rot_{90^\circ}\rangle + |Rot_{135^\circ}\rangle|Rot_{90^\circ}\rangle\\ \end{align*}

Now, see we have 50\% chance to measure to |Rot_{45^\circ}\rangle or |Rot_{135^\circ}\rangle. But clearly, if we just measure unentangled |v\rangle, we get 100\% chance to |Rot_{45^\circ}\rangle

Takeaway: the "measurement" happen because you don't have access to |m\rangle while trying to understand |v\rangle. (inspired by this video)

Table of Content