Skip to content

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

It feels obvious that computing throws information away. You feed AND two bits and get one back; the other bit is simply gone. So surely computation is a one-way street? That intuition is half right and half a trap. Some gates do destroy information - and those are exactly the gates a quantum computer cannot use. Others lose nothing and can be undone perfectly. Sorting out which is which is the whole point of this lesson, because quantum gates live entirely in the second camp.

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.

Pick a gate, read its truth table, then click any output to run it backward. If one input lights up, the gate is reversible. If several do, the output does not tell you the input.

AND - two bits in, one bit out.

inputoutput
00
01
10
11
Irreversible. Several inputs share one output, so the output column loses information. You cannot undo it, and no quantum gate can look like this.

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:

On a finite set, being one-to-one and being onto are the same thing, so reversible means bijection.

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

Here is the fact that makes reversible computing possible at all: the Toffoli gate is universal. Any classical circuit, however lossy, can be rebuilt out of Toffoli gates alone by carrying a few extra helper bits - so you never have to give up ordinary computation to stay reversible.[1] That matters because every quantum gate is reversible by construction, as we will see when gates become matrices that rotate a qubit. A quantum computer can run any classical program - it just has to run it the reversible way.
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 bits
Enumerate a gate's truth table and check whether it is a bijection.

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

drop here

irreversible: three inputs collapse onto one output

drop here

reversible: it just swaps 0 and 1

drop here

reversible: flips the target, copies the control onto a blank bit

drop here

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

  1. 1.Scott Aaronson, Introduction to Quantum Information Science lecture notes (qclec.pdf)
  2. 2.Nielsen and Chuang, Quantum Computation and Quantum Information, chapter 1