Foundations: What It Is, and What It Is Not
Classical bits, gates, and reversibility
The model we generalize, and why quantum gates run backward
Before we generalize anything, let us be precise about the thing we are generalizing. A classical computer is built from logic gates on bits - AND, OR, NOT - and you already know exactly how they behave. This lesson takes that familiar model and pulls out the one property quantum computing will insist on: every gate must be able to run backward.
The assumption to drop
A is just a rule that maps an input bitstring to an output bitstring. The question that will matter for the rest of the course is simple: given only the output, can you always recover the input? Play with the bench below. Pick a gate, read its truth table, then click any output value to run the gate backward and see how many inputs could have produced it.
AND - two bits in, one bit out.
| input | output |
|---|---|
| 00 | |
| 01 | |
| 10 | |
| 11 |
The bench sorts every gate into one of two piles. For AND and OR, several inputs land on the same output - AND sends , and all to - so when you try to run it backward the output cannot tell you which input it came from. That lost information is what makes the gate one-way. For NOT, CNOT and Toffoli, every input has its own private output, so running backward is never ambiguous.
Reversible means bijection
We can make "runs backward" exact. A gate on bits is a function from the possible inputs to outputs on the same bits. It is exactly when no two distinct inputs share an output. But a function from a finite set to itself that never collides must also hit every output - if the inputs map to distinct outputs, they use up all of them. So reversibility is the same as being a , a perfect one-to-one pairing:
This is why AND can never be a quantum gate: it takes two bits to one, so it cannot even be a map from a set to itself, let alone a bijection. NOT is the simplest reversible gate (it just swaps and ). CNOT takes two bits to two bits and flips the second whenever the first is ; on the basis states it copies the first bit onto a blank second bit, and it is its own inverse. Toffoli takes three bits to three, flipping the last only when the first two are both .
Toffoli does everything, reversibly
def is_reversible(gate, n_in):
outputs = [gate(x) for x in range(2 ** n_in)]
# reversible exactly when no two inputs share an output
return len(set(outputs)) == len(outputs)
AND = lambda x: (x >> 1) & (x & 1) # 2 bits in, 1 bit out
NOT = lambda x: x ^ 1 # 1 bit, flips it
CNOT = lambda x: (x & 0b10) | (((x >> 1) ^ x) & 1) # flip low bit if high bit set
print(is_reversible(AND, 2)) # False -> 00, 01, 10 all map to 0
print(is_reversible(NOT, 1)) # True
print(is_reversible(CNOT, 2)) # True -> a bijection on two bitsLock it in
- A gate is reversible when its output always determines its input; quantum gates are always reversible, so the classical model has to be rebuilt in reversible form.
- On bitstrings, reversible is exactly the same as being a bijection - a one-to-one, onto pairing of inputs and outputs.
- AND and OR are irreversible: several inputs collapse to one output, and the lost bit cannot be recovered. NOT, CNOT and Toffoli lose nothing.
- The Toffoli gate is universal for reversible computing, so no ordinary computation is out of reach - it just needs a few helper bits.
Check yourself
Why is the AND gate not reversible?
A gate on n bits is reversible exactly when it is:
Recall: why must quantum gates be reversible, and which 3-bit classical gate is universal for reversible computing?
The constraint, and the gate that makes it painless. Try to state it, then check.
Match each gate to its reversibility status.
irreversible: three inputs collapse onto one output
reversible: it just swaps 0 and 1
reversible: flips the target, copies the control onto a blank bit
universal reversible gate: rebuilds any classical circuit
Primary source
Scott Aaronson - Introduction to Quantum Information Science (lecture notes)The reversibility of computation, the Toffoli gate, and why the quantum model is the reversible generalization of the classical one are laid out early and cleanly. Read the sections on classical reversible circuits before moving on to qubits.
Sources