# Lecture 005 - Quantum Gates

## 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

## Computability

Any truth table can be built by circuit

• with $n \cdot m \cdot 2^n$ gates

• or with $m \cdot 2^n/n$ gates (C. Shannon) 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$ qbits 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)

• one should be able to construct a NAND gate, so you can then build a XOR gate. With XOR and AND you can build a half-adder. Combine half-adders to build a full-adder.

• Any NAND-based circuit can be rebuilt using NORs exclusively and vice versa.

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).

• inverse is itself

• it is an AND gate when Z is 0

• it is an NAND gate when Z is 1

## "Garbage" Collection

### Garbage Problem

Why get rid of trash?

• wasting spacetime to keep temporary variables from last computation, since they can only be used once set to zero

• garbage prevents cancelation of amplitudes in joined quantum state

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:

\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

\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:

\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.

• Precondition: all tmp variables initialized to zero

• Intermediate: answer is good, but tmp variables are garbage

• Postcondition: answer is good, all tmp variables set to zero

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

Table of Content