Reversible Computation

3–4 hours ~14 min read

Reversible Computation

Ordinary logic forgets: an AND gate turns two bits into one, and the lost bit must go somewhere — Landauer showed it goes into heat. If we forbid forgetting, computation becomes a permutation of states, information-preserving and (in principle) dissipationless. This reversible model is not a curiosity: it is the exact classical shadow of quantum computing, where every gate is unitary — hence invertible — by the laws of physics. The CNOT and Toffoli gates you build here reappear, unchanged, as quantum gates in Term 2.

Learning Objectives

By the end of this lesson you will be able to:

  1. State and motivate Landauer's principle (kTln2\ge kT\ln 2 of heat per erased bit) and connect logical irreversibility to thermodynamic cost.
  2. Define logical reversibility as bijectivity of the gate's input→output map, and explain why irreversible gates lose information.
  3. Write the truth tables of NOT, CNOT, Toffoli (CCNOT), and Fredkin (CSWAP), and verify each is a bijection (permutation).
  4. Argue that Toffoli is universal for reversible classical computation.
  5. Embed any irreversible function reversibly using ancillas and uncomputation (garbage management), and quantify the qubit/bit overhead.
  6. Explain the bridge to quantum: quantum gates are unitary \Rightarrow reversible; CNOT and Toffoli are quantum gates; reversibility underlies no-cloning and the structure of Term 2.

Intuition

Watch an AND gate run: inputs (1,0)(1,0) give output 00, but so do (0,0)(0,0) and (0,1)(0,1). From the output alone you cannot reconstruct the input — the gate is 2-to-1, it merges states and destroys information. Rolf Landauer's 1961 insight: this logical erasure is not free. Merging two possible states into one halves the system's state space, lowering its entropy by kln2k\ln 2 — and the Second Law demands that entropy be dumped into the environment as heat, kTln2\ge kT\ln 2 per bit erased. Logical irreversibility implies thermodynamic irreversibility.

The escape hatch: never merge. If a gate's map is a bijection — every output comes from exactly one input — no information is lost, the computation can be run backward, and Landauer's bound for the logic itself drops to zero. The price is that we cannot literally implement AND as a 2-bit→1-bit gate; we must keep enough extra wires to stay invertible. That bookkeeping — ancillas (scratch bits) and uncomputation (cleaning up scratch so it doesn't accumulate as "garbage") — is the entire craft of reversible computing.

Why a quantum course cares: in quantum mechanics, closed-system evolution is unitary, and unitary operators are invertible (U1=UU^{-1}=U^\dagger). So every quantum gate is automatically reversible — there is no quantum AND-as-written, no quantum erasure mid-circuit. Reversible classical logic is exactly the sandbox where you learn to compute without forgetting, before the complex amplitudes of Term 1–2 arrive. The Toffoli gate you meet here is, bit-for-bit, the classical core of a quantum universal gate set.


Theory

1. Landauer's principle

Landauer's principle. Erasing one bit of information in a computation at temperature TT dissipates at least

Emin  =  kBTln2 E_{\min} \;=\; k_B\, T \ln 2

of energy as heat, where kBk_B is Boltzmann's constant.

Why ln2\ln 2. A bit has two equally likely states; its information entropy is log22=1\log_2 2 = 1 bit, or S=kBln2S = k_B\ln 2 in thermodynamic (nat) units. Erasure — forcing the bit to a known value 00 regardless of its prior value — collapses two microstates into one, reducing the bit's entropy by ΔS=kBln2\Delta S = k_B \ln 2. By the Second Law, the total entropy of (bit + environment) cannot decrease, so the environment must absorb at least ΔS\Delta S, releasing heat Q=TΔS=kBTln2Q = T\,\Delta S = k_B T \ln 2. At room temperature T300KT\approx 300\,\mathrm K this is a tiny 2.9×1021J\approx 2.9\times10^{-21}\,\mathrm J — but it is a floor no clever engineering can undercut for an irreversible erasure, and it has been confirmed experimentally [NC §3.2.5].

The lever for computing: logically reversible operations need not erase, so they are not subject to the kTln2kT\ln 2 floor — at least not from the logic. (Real devices still dissipate for other engineering reasons; the principle sets the fundamental limit.) This is the thermodynamic motivation for studying reversible computation, due to Bennett.

2. Logical reversibility

A gate computing g:{0,1}n{0,1}mg:\{0,1\}^n\to\{0,1\}^m is logically reversible iff gg is a bijection — equivalently, n=mn=m and gg is a permutation of {0,1}n\{0,1\}^n, so the input is uniquely recoverable from the output via g1g^{-1}.

  • NOT (x¬xx\mapsto \lnot x) is reversible: it is its own inverse, a 2-element permutation.
  • AND, OR, NAND, XOR (as 212\to1 maps) are not reversible: they are 2-to-1, hence not injective, hence lose information. (NAND's universality — Lesson 1 — is unrelated to its irreversibility.)

The key structural theorem: any nn-bit reversible gate is a permutation of the 2n2^n bit-strings, and conversely every permutation is a reversible gate. Reversible computation is therefore the study of which permutations are realizable from a small gate set — the direct classical analogue of "which unitaries are realizable from a universal quantum gate set" (Term 2.2).

3. The reversible gate zoo

We build reversibility by adding control wires that are passed through untouched, flipping a target only on certain control patterns.

NOT — 1 bit

xNOT0110 \begin{array}{c|c} x & \text{NOT}\\\hline 0 & 1\\ 1 & 0 \end{array}

A transposition; trivially a bijection.

CNOT (controlled-NOT) — 2 bits

Control cc, target tt; flip tt iff c=1c=1. Output (c, tc)(c,\ t\oplus c).

ctct0000010110111110 \begin{array}{cc|cc} c & t & c' & t'\\\hline 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 1\\ 1 & 0 & 1 & 1\\ 1 & 1 & 1 & 0 \end{array}

The map (c,t)(c,tc)(c,t)\mapsto(c,t\oplus c) is its own inverse (apply twice: tcc=tt\oplus c\oplus c=t), so CNOT is reversible. With t=0t=0 fixed it computes (c,0)(c,c)(c,0)\mapsto(c,c) — a fan-out/copy of a classical bit into a fresh wire. (Note: this copies classical bits only; the quantum no-cloning theorem says the same circuit cannot copy an unknown superposition — more below.)

Toffoli / CCNOT (controlled-controlled-NOT) — 3 bits

Two controls a,ba,b, target cc; flip cc iff a=b=1a=b=1. Output (a, b, c(ab))(a,\ b,\ c\oplus(a\land b)).

abcabc000000001001010010011011100100101101110111111110 \begin{array}{ccc|ccc} a & b & c & a' & b' & c'\\\hline 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 1\\ 0 & 1 & 0 & 0 & 1 & 0\\ 0 & 1 & 1 & 0 & 1 & 1\\ 1 & 0 & 0 & 1 & 0 & 0\\ 1 & 0 & 1 & 1 & 0 & 1\\ 1 & 1 & 0 & 1 & 1 & 1\\ 1 & 1 & 1 & 1 & 1 & 0 \end{array}

Again self-inverse. The magic: set the target c=0c=0 and Toffoli outputs (a,b,ab)(a,b,a\land b) — a reversible AND with the inputs preserved. Set c=1c=1 with the same controls and you get aba\land b negated... and combined with the bit-copy from CNOT, this is enough for universality.

Fredkin / CSWAP (controlled-SWAP) — 3 bits

Control cc; swap targets x,yx,y iff c=1c=1.

cxycxy000000001001010010011011100100101110110101111111 \begin{array}{ccc|ccc} c & x & y & c' & x' & y'\\\hline 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 1\\ 0 & 1 & 0 & 0 & 1 & 0\\ 0 & 1 & 1 & 0 & 1 & 1\\ 1 & 0 & 0 & 1 & 0 & 0\\ 1 & 0 & 1 & 1 & 1 & 0\\ 1 & 1 & 0 & 1 & 0 & 1\\ 1 & 1 & 1 & 1 & 1 & 1 \end{array}

Self-inverse, and conservative: it preserves the number of 11s (Hamming weight) in (x,y)(x,y), which models a billiard-ball / charge-conserving physical implementation. With y=0y=0 it computes (c,x,0)(c, c¬?...)(c,x,0)\mapsto(c,\ c\land\lnot? ...) — concretely x=cxx'=c\land x is not quite it; rather with x=1,y=0x=1,y=0 it routes the 11 to xx' or yy' depending on cc, realizing AND and fan-out (Example 1).

4. Toffoli is universal for reversible computation

Theorem. The Toffoli gate (together with the ability to introduce constant ancilla bits set to 00 or 11 and to ignore output "garbage" bits) is universal for reversible classical computation: any Boolean function can be computed by a circuit of Toffoli gates [NC §3.2.5], [Bar95].

Proof sketch. It suffices to realize a functionally complete set (Lesson 1) reversibly with Toffolis:

  • AND: TOFFOLI(a,b,0)=(a,b, ab)\text{TOFFOLI}(a,b,0) = (a,b,\ a\land b). The third output is aba\land b.
  • NOT: TOFFOLI(1,1,x)=(1,1, x1)=(1,1,¬x)\text{TOFFOLI}(1,1,x) = (1,1,\ x\oplus 1) = (1,1,\lnot x) — feed two ancillas set to 11. (Or use a bare NOT gate, itself a special Toffoli with the controls hardwired.)
  • FANOUT/COPY: TOFFOLI(a,1,0)=(a,1, a1)=(a,1,a)\text{TOFFOLI}(a,1,0) = (a,1,\ a\land 1) = (a,1,a) — copy aa to a fresh wire.

Since {AND,NOT}\{\text{AND}, \text{NOT}\} is complete (it gives NAND, hence everything — Lesson 1), and we can COPY to feed a bit to multiple gates, any Boolean circuit can be rebuilt out of Toffolis. The ancillas supply the needed constants and scratch; some output wires hold intermediate "garbage" we clean up next. \blacksquare

A subtlety worth stating: no 22-bit reversible gate is universal in this sense (the 22-bit reversible gates are all linear over F2\mathbb F_2 — XOR-type — and cannot generate the nonlinear AND). You genuinely need a 33-bit gate like Toffoli. This mirrors the quantum fact that entangling two-qubit gates plus single-qubit gates are needed for quantum universality (Term 2.2).

5. Embedding irreversible functions: ancillas, garbage, uncomputation

Given an arbitrary f:{0,1}n{0,1}mf:\{0,1\}^n\to\{0,1\}^m (possibly many-to-one, hence irreversible), how do we compute it reversibly? The standard construction makes ff a permutation on a larger space by carrying the input along:

Uf:(x, y)    (x, yf(x)),x{0,1}n, y{0,1}m. U_f:\quad (x,\ y) \;\longmapsto\; (x,\ y\oplus f(x)), \qquad x\in\{0,1\}^n,\ y\in\{0,1\}^m.

This is a bijection for any ff — its own inverse, since yf(x)f(x)=yy\oplus f(x)\oplus f(x)=y — because we keep xx. Setting y=0y=0 reads out f(x)f(x) in the second register: (x,0)(x,f(x))(x,0)\mapsto(x,f(x)). This is exactly the oracle/query model of Term 3.1 (which is why \oplus appears everywhere in quantum algorithms).

But a circuit computing f(x)f(x) usually generates intermediate scratch g(x)g(x) ("garbage") on ancilla wires:

(x, 0anc, 0out) compute (x, g(x), f(x)). (x,\ 0_{\text{anc}},\ 0_{\text{out}}) \xrightarrow{\ \text{compute}\ } (x,\ g(x),\ f(x)).

Garbage is a problem in two ways: it wastes wires, and — critically for quantum — if those ancillas stay entangled with the answer register, interference (the source of quantum speedup) is spoiled. Bennett's uncomputation trick removes it:

  1. Compute ff forward, producing scratch: (x,0,0)(x,g(x),f(x))(x, 0, 0)\to(x, g(x), f(x)).
  2. Copy out the answer to a fresh clean register with CNOTs: (x,g(x),f(x),0)(x,g(x),f(x),f(x))(x, g(x), f(x), 0)\to(x, g(x), f(x), f(x)).
  3. Uncompute by running the forward circuit in reverse (every reversible gate has an inverse), which restores the scratch to 00 and erases the working copy of f(x)f(x):(x, g(x), f(x), f(x)) reverse compute (x, 0, 0, f(x)). (x,\ g(x),\ f(x),\ f(x)) \xrightarrow{\ \text{reverse compute}\ } (x,\ 0,\ 0,\ f(x)).

Net effect (x,0,0,0)(x,0,0,f(x))(x,0,0,0)\mapsto(x,0,0,f(x)): the answer survives, all scratch is returned to 00 and can be reused, and there is no leftover garbage. The cost is roughly double the gate count (forward + reverse) and a constant-factor increase in wires — a small, polynomial overhead. Crucially, any computation can be made reversible with at most polynomial blow-up in time and space [Ben73], so reversibility costs us nothing in complexity terms — it does not move problems between the classes of the previous lesson.

6. The bridge to quantum computing

This is the payoff. Three facts lock reversible classical logic to quantum computing:

  1. Unitary ⇒ reversible. A quantum gate is a unitary UU with UU=IU^\dagger U = I, so $U^{-1}= U^\dagger$ always exists. Every quantum circuit is therefore reversible; there is no built-in erasure. Mid-circuit "forgetting" only happens at measurement, which is the one non-unitary, irreversible step (Term 1.3). Everything before it is a permutation-like, invertible evolution — exactly the regime you practiced here.

  2. CNOT and Toffoli are quantum gates. Read the truth tables above as the action on computational basis states \lvert\cdot\rangle and they define unitary permutation matrices:

    CNOTc,t=c, tc,TOFFOLIa,b,c=a,b, c(ab). \text{CNOT}\,\lvert c,t\rangle = \lvert c,\ t\oplus c\rangle, \qquad \text{TOFFOLI}\,\lvert a,b,c\rangle = \lvert a,b,\ c\oplus(a\land b)\rangle .

    These same gates run quantum circuits in Term 2.1 · Single-Qubit Gates and beyond — CNOT is the canonical entangler, Toffoli is the workhorse of arithmetic and oracles. The matrices are exactly the permutation matrices of the truth tables.

  3. No-cloning is reversibility's quantum twist. CNOT copies a classical bit (c,0c,c\lvert c,0\rangle\to\lvert c,c\rangle) — yet the no-cloning theorem (Term 2.2) proves no unitary can copy an arbitrary unknown state α0+β1\alpha\lvert0\rangle+\beta\lvert1\rangle. The resolution: linearity. CNOT on a superposition control gives α00+β11\alpha\lvert00\rangle+\beta\lvert11\rangle (an entangled Bell-type state), not the product (α0+β1)2(\alpha\lvert0\rangle+\beta\lvert1\rangle)^{\otimes2}. Reversibility is necessary for unitarity, but unitarity also forbids cloning — a constraint with no classical analogue, and a recurring theme from Term 2 onward.

So the reversible-computing skills here — control wires, ancillas, uncomputation, thinking of computation as a permutation — are not a detour. They are the literal classical substrate of quantum circuits, learned without yet needing complex amplitudes.


Worked Examples

Example 1 — Fredkin computes AND, OR, and fan-out

Set the control to the data and use a constant ancilla. Recall FREDKIN(c,x,y)=(c, x, y)\text{FREDKIN}(c,x,y) = (c,\ x',\ y') swaps x,yx,y iff c=1c=1, so x=(¬c)xcyx' = (\lnot c)\,x \lor c\,y and y=(¬c)ycxy' = (\lnot c)\,y \lor c\,x.

  • AND (cxc\land x): feed (c, x, 0)(c,\ x,\ 0). Then y=(¬c)0cx=cxy' = (\lnot c)\cdot 0 \lor c\cdot x = c\land x. The third output is cxc\land x.
  • OR: feed (c, 1, x)(c,\ 1,\ x). Then $x' = (\lnot c)\cdot 1 \lor c\cdot x = \lnot c \lor (c\land x) = \lnot c \lor x$, and the first kept wire... cleaner is to use De Morgan with AND/NOT, but the AND realization plus a NOT suffices via universality.
  • FAN-OUT of cc: feed (c, 1, 0)(c,\ 1,\ 0). Then x=(¬c)1c0=¬cx' = (\lnot c)\cdot1 \lor c\cdot0 = \lnot c and y=(¬c)0c1=cy' = (\lnot c)\cdot0 \lor c\cdot1 = c. Outputs carry cc and ¬c\lnot c — both copies recoverable.

Fredkin is conservative (Hamming-weight–preserving), so these come "for free" thermodynamically. This is why Fredkin models billiard-ball computing. (Toffoli is the more common building block because its AND is more direct; we verify both in code.)

Example 2 — Uncomputation on a 2-bit function

Let f(x1,x2)=(x1x2)(¬x1)f(x_1,x_2) = (x_1\land x_2)\oplus(\lnot x_1), computed with one scratch wire. Forward circuit on registers (x1,x2, a=0scratch, o=0out)(x_1, x_2,\ a{=}0_{\text{scratch}},\ o{=}0_{\text{out}}):

  1. TOFFOLI(x1,x2,a)\text{TOFFOLI}(x_1,x_2,a): now a=x1x2a = x_1\land x_2. State (x1,x2, x1x2, 0)(x_1,x_2,\ x_1\land x_2,\ 0).
  2. CNOT aoa\to o: o=x1x2o = x_1\land x_2. Then NOT-controlled-by-¬x1\lnot x_1 via TOFFOLI(ˉ,)\text{TOFFOLI}(\bar{}, \dots) — concretely, flip oo when x1=0x_1=0 using an X-then-Toffoli trick. After this, o=(x1x2)¬x1=fo = (x_1\land x_2)\oplus\lnot x_1 = f.

Now the scratch a=x1x20a=x_1\land x_2 \ne 0 is garbage entangled with the inputs. Uncompute:

  1. Reverse step 1: TOFFOLI(x1,x2,a)\text{TOFFOLI}(x_1,x_2,a) again (self-inverse) resets a0a\to 0.

Final state: (x1,x2, 0, f(x1,x2))(x_1, x_2,\ 0,\ f(x_1,x_2)) — inputs intact, scratch clean, answer in oo. We do not uncompute oo, since it holds the wanted result; we uncompute only the scratch. The code below implements this end-to-end and asserts the scratch returns to 00 for all four inputs.


Hands-on (Python)

Self-contained, dependency-free. We represent each gate as a permutation of bit-strings and verify reversibility by checking the permutation is a bijection (and self-inverse). Then we demonstrate uncomputation cleaning up an ancilla.

"""Reversible Computation — gates as bit-string permutations (plain Python)."""

from itertools import product

# ---------------------------------------------------------------------------
# Represent an n-bit state as a tuple of ints in {0,1}. A reversible gate is a
# function state->state; we verify it is a BIJECTION over all 2**n states.
# ---------------------------------------------------------------------------

def NOT(bits):                       # 1-bit:  x -> ¬x
    (x,) = bits
    return (1 - x,)

def CNOT(bits):                      # 2-bit:  (c, t) -> (c, t XOR c)
    c, t = bits
    return (c, t ^ c)

def TOFFOLI(bits):                   # 3-bit:  (a, b, c) -> (a, b, c XOR (a AND b))
    a, b, c = bits
    return (a, b, c ^ (a & b))

def FREDKIN(bits):                   # 3-bit:  (ctrl, x, y) -> swap x,y if ctrl=1
    ctrl, x, y = bits
    return (ctrl, y, x) if ctrl == 1 else (ctrl, x, y)

def all_states(n):
    return list(product((0, 1), repeat=n))

def is_reversible(gate, n):
    """A gate is reversible iff it permutes the 2**n states bijectively."""
    images = [gate(s) for s in all_states(n)]
    return len(set(images)) == 2 ** n           # no two inputs collide => bijection

def is_self_inverse(gate, n):
    return all(gate(gate(s)) == s for s in all_states(n))

for name, gate, n in [("NOT", NOT, 1), ("CNOT", CNOT, 2),
                      ("TOFFOLI", TOFFOLI, 3), ("FREDKIN", FREDKIN, 3)]:
    rev = is_reversible(gate, n)
    inv = is_self_inverse(gate, n)
    print(f"{name:8s} reversible={rev}  self-inverse={inv}")
    assert rev and inv

# Contrast: AND as a 2->1 map is NOT reversible (it collides inputs).
def AND_irreversible(bits):
    a, b = bits
    return (a & b,)                               # 2 bits in, 1 bit out
images = [AND_irreversible(s) for s in all_states(2)]
print(f"\nAND (2->1): distinct outputs = {len(set(images))} of 4 inputs "
      f"-> reversible={len(set(images)) == 4}")   # collides -> not reversible


# ---------------------------------------------------------------------------
# Toffoli is universal: realize AND, NOT, COPY as the lesson's special cases.
# ---------------------------------------------------------------------------
print("\nToffoli realizing classical gates:")
print("  AND(a,b)  via TOFFOLI(a,b,0):", [TOFFOLI((a, b, 0))[2]
                                          for a, b in all_states(2)])   # a AND b
print("  NOT(x)    via TOFFOLI(1,1,x):", [TOFFOLI((1, 1, x))[2]
                                          for (x,) in all_states(1)])   # ¬x
print("  COPY(a)   via TOFFOLI(a,1,0):", [TOFFOLI((a, 1, 0))[2]
                                          for (a,) in all_states(1)])   # = a


# ---------------------------------------------------------------------------
# Uncomputation: compute f(x1,x2) = (x1 AND x2) using a SCRATCH ancilla, copy
# the answer to an output wire, then run the scratch-producing gate in REVERSE
# to clean the ancilla back to 0. Registers: (x1, x2, scratch, out).
# ---------------------------------------------------------------------------
def compute_with_uncompute(x1, x2):
    a, o = 0, 0                                   # scratch=0, out=0
    # 1. forward: scratch <- x1 AND x2  (Toffoli on (x1,x2,scratch))
    _, _, a = TOFFOLI((x1, x2, a))
    # 2. copy answer to out via CNOT(scratch -> out)
    _, o = CNOT((a, o))                           # out = scratch = x1 AND x2
    # 3. UNCOMPUTE: reverse step 1 (Toffoli is self-inverse) -> scratch back to 0
    _, _, a = TOFFOLI((x1, x2, a))
    return x1, x2, a, o                           # expect scratch a == 0

print("\nUncomputation (x1, x2, scratch, out):")
for x1, x2 in all_states(2):
    res = compute_with_uncompute(x1, x2)
    print(f"  in=({x1},{x2}) -> {res}   out=f={res[3]}  scratch_clean={res[2]==0}")
    assert res[2] == 0, "scratch must be uncomputed back to 0"
    assert res[3] == (x1 & x2), "output must equal f(x1,x2)"
print("Scratch returns to 0 for all inputs; answer preserved. ✓")

Expected output:

NOT      reversible=True  self-inverse=True
CNOT     reversible=True  self-inverse=True
TOFFOLI  reversible=True  self-inverse=True
FREDKIN  reversible=True  self-inverse=True

AND (2->1): distinct outputs = 3 of 4 inputs -> reversible=False

Toffoli realizing classical gates:
  AND(a,b)  via TOFFOLI(a,b,0): [0, 0, 0, 1]
  NOT(x)    via TOFFOLI(1,1,x): [1, 0]
  COPY(a)   via TOFFOLI(a,1,0): [0, 1]

Uncomputation (x1, x2, scratch, out):
  in=(0,0) -> (0, 0, 0, 0)   out=f=0  scratch_clean=True
  in=(0,1) -> (0, 1, 0, 0)   out=f=0  scratch_clean=True
  in=(1,0) -> (1, 0, 0, 0)   out=f=0  scratch_clean=True
  in=(1,1) -> (1, 1, 0, 1)   out=f=1  scratch_clean=True
Scratch returns to 0 for all inputs; answer preserved. ✓

The AND(a,b) = [0,0,0,1] line reads off the truth table of AND from Toffoli's third output, and the uncomputation block shows the scratch wire faithfully returning to 00 — the discipline that keeps quantum ancillas disentangled.

Linking to Appendix B. The same gates appear there as matrices (e.g. the explicit CNOT in Appendix B §5). A permutation of basis strings is a permutation matrix — that is precisely why these classical reversible gates are already valid unitary quantum gates.


Exercises

1. (Easy) Self-inverse check. Verify by hand that Toffoli is its own inverse: compute TOFFOLI(TOFFOLI(a,b,c))\text{TOFFOLI}(\text{TOFFOLI}(a,b,c)) symbolically.

Solution

TOFFOLI(a,b,c)=(a,b,c(ab))\text{TOFFOLI}(a,b,c) = (a,b,\,c\oplus(a\land b)). Applying again, the controls a,ba,b are unchanged, so the target becomes $\big(c\oplus(a\land b)\big)\oplus(a\land b) = c\oplus\big((a\land b)\oplus(a\land b)\big) = c\oplus 0 = c.Thus. Thus \text{TOFFOLI}^2 = \text{Id}:selfinverse.: self-inverse. \blacksquare$

2. (Easy–Medium) Landauer arithmetic. A chip irreversibly erases 101210^{12} bits per second at T=300KT=300\,\mathrm K. What is the minimum power dissipated by erasure alone? ($k_B = 1.38\times10^{-23}, \mathrm{J/K}$.)

Solution

Per bit: kBTln2=(1.38×1023)(300)(0.693)2.87×1021Jk_B T\ln 2 = (1.38\times10^{-23})(300)(0.693) \approx 2.87\times10^{-21}\,\mathrm J. Times 101210^{12} erasures/s: Pmin2.9×109W2.9nWP_{\min}\approx 2.9\times10^{-9}\,\mathrm W \approx 2.9\,\mathrm{nW}. Tiny — real chips dissipate ~10910^9 times more for other reasons — but it is a hard floor for irreversible operation, and exactly 00 (from logic) for reversible operation.

3. (Medium) SWAP from CNOTs. Show that SWAP (x,y)(y,x)(x,y)\mapsto(y,x) equals three CNOTs alternating control/target. Verify it is reversible.

Solution

Apply CNOTxy_{x\to y}, then CNOTyx_{y\to x}, then CNOTxy_{x\to y}:

(x,y)(x,xy)((x)(xy), xy)=(y,xy)(y, y(xy))=(y,x). (x,y)\to(x,\,x\oplus y)\to\big((x)\oplus(x\oplus y),\ x\oplus y\big)=(y,\,x\oplus y)\to(y,\ y\oplus(x\oplus y))=(y,x).

Each CNOT is reversible (self-inverse), so their composition is a reversible permutation (it is its own inverse here by symmetry). SWAP itself is obviously a bijection. This identity reappears verbatim for qubits in Term 2. \blacksquare

4. (Medium) Why no 2-bit universal reversible gate. Argue that every 22-bit reversible gate is "linear" (an affine F2\mathbb F_2 map) and therefore cannot, even with constant ancillas on 2 wires, compute the nonlinear AND. (Hence universality needs 3\ge 3 bits, e.g. Toffoli.)

Solution

The 22-bit reversible gates form the symmetric group on 44 states. The ones realizable as bitwise/control logic — NOT, CNOT, SWAP, and compositions — are all affine over F2\mathbb F_2: each output bit is a XOR of input bits plus a constant. Affine maps are closed under composition, and composing affine maps with constant-input wires stays affine. But aba\land b is nonlinear (its algebraic normal form contains the product term abab), so no affine circuit produces it. The nonlinearity requires a gate whose action mixes three wires multiplicatively — Toffoli's c(ab)c\oplus(a\land b) — which is why 33 bits are necessary for universality. (This is the precise classical shadow of needing two-qubit entangling gates for quantum universality.)

5. (Hard) Garbage and interference. Explain, in terms of the embedding Uf:(x,0)(x,f(x))U_f:(x,0)\mapsto(x,f(x)) plus uncomputed scratch, why leftover garbage entangled with the answer would ruin a quantum algorithm, even though it is harmless classically.

Solution

Classically, garbage g(x)g(x) on idle wires is merely wasted space — the answer f(x)f(x) is read out regardless. Quantumly, run UfU_f on a superposition input xαxx\sum_x\alpha_x\lvert x\rangle: without uncomputation the state is xαxxg(x)f(x)\sum_x\alpha_x\lvert x\rangle\lvert g(x)\rangle\lvert f(x)\rangle. The register holding g(x)g(x) is entangled with the index xx, so distinct branches are distinguishable by their garbage and cannot interfere. Quantum speedups (Deutsch–Jozsa, Shor, Grover) rely precisely on amplitudes for different xx interfering in the answer register. Uncomputation resets g(x)0g(x)\to 0 for every branch, yielding $\sum_x\alpha_x\lvert x\rangle\lvert 0\rangle\lvert f(x)\ranglethegarbagefactorsout,brancheswiththesame — the garbage factors out, branches with the same f(x)$ recombine, and interference is restored. That is why Bennett's trick is mandatory, not merely tidy, in quantum algorithms (Term 3.1).

6. (Hard) No-cloning vs. CNOT-copy. CNOT maps c,0c,c\lvert c,0\rangle\to\lvert c,c\rangle, seemingly copying cc. Reconcile this with the no-cloning theorem by computing CNOT on the superposition control ψ=α0+β1\lvert\psi\rangle=\alpha\lvert0\rangle+\beta\lvert1\rangle and target 0\lvert0\rangle.

Solution

By linearity of the unitary CNOT,

CNOT((α0+β1)0)=αCNOT00+βCNOT10=α00+β11. \text{CNOT}\big((\alpha\lvert0\rangle+\beta\lvert1\rangle)\otimes\lvert0\rangle\big) =\alpha\,\text{CNOT}\lvert00\rangle+\beta\,\text{CNOT}\lvert10\rangle =\alpha\lvert00\rangle+\beta\lvert11\rangle.

A genuine clone would be $\lvert\psi\rangle\otimes\lvert\psi\rangle = \alpha^2\lvert00\rangle+\alpha\beta\lvert01\rangle+\alpha\beta\lvert10\rangle+\beta^2\lvert11\rangle$. These agree only when αβ=0\alpha\beta=0, i.e. for the basis states 0\lvert0\rangle or 1\lvert1\rangle — exactly the classical bits CNOT does copy. For a general superposition CNOT produces an entangled state, not two copies. So CNOT copies in the computational basis but cannot clone an unknown state; no contradiction with no-cloning (proved fully in Term 2.2). \blacksquare


Checkpoint

1. State Landauer's principle and the source of the $\ln 2$.

Erasing one bit at temperature TT dissipates kBTln2\ge k_B T\ln 2 as heat. The ln2\ln 2 is the entropy kBln2k_B\ln 2 of one bit's two equally likely states; erasure removes that entropy from the bit, and the Second Law forces it into the environment as heat.

2. Define logical reversibility. Is AND reversible? Is CNOT?

A gate is reversible iff its input→output map is a bijection (a permutation of bit-strings). AND (212\to1) is not — it is 2-to-1 and loses a bit. CNOT, (c,t)(c,tc)(c,t)\mapsto(c,t\oplus c), is a bijection (and self-inverse).

3. How does Toffoli compute a reversible AND, and why is that enough for universality?

TOFFOLI(a,b,0)=(a,b,ab)\text{TOFFOLI}(a,b,0)=(a,b,a\land b) outputs AND while preserving inputs. With Toffoli also giving NOT (controls =1=1) and COPY (one control =1=1, target 00), and {AND,NOT}\{\text{AND},\text{NOT}\} being functionally complete, every Boolean function is buildable — Toffoli is universal for reversible computation.

4. What problem does uncomputation solve, and how?

It removes garbage (intermediate scratch entangled with the answer). After computing ff forward and copying the answer to a clean register, you run the forward circuit in reverse to reset all scratch ancillas to 00, leaving (x,0,f(x))(x,0,f(x)) with reusable, disentangled ancillas.

5. Why is every quantum gate reversible?

A quantum gate is a unitary UU (UU=IU^\dagger U=I), so U1=UU^{-1}=U^\dagger exists — it is always invertible. Closed-system quantum evolution never erases; the only irreversible step is measurement.

6. CNOT copies a classical bit; why is this not cloning?

On basis states CNOT copies (c,0c,c\lvert c,0\rangle\to\lvert c,c\rangle), but by linearity a superposition control yields the entangled α00+β11\alpha\lvert00\rangle+\beta\lvert11\rangle, not the product ψψ\lvert\psi\rangle\otimes\lvert\psi\rangle. Copying basis states is allowed; cloning an unknown superposition is forbidden by no-cloning.


Further Reading

  • [NC §3.2.5] Nielsen & Chuang — reversible computation, Landauer's principle, the Toffoli and Fredkin gates, universality, and the embedding/uncomputation construction. The closest match to this lesson and the bridge into Part II's quantum circuits.
  • [Bar95] Barenco et al., "Elementary gates for quantum computation" — Toffoli/CCNOT decompositions and the gate-universality results, where these classical gates become quantum.
  • [Ben73] C. H. Bennett, "Logical reversibility of computation" — the original ancilla+uncomputation argument that reversibility costs only polynomial overhead. (See [NC §3.2.5] for the textbook account.)
  • [AB §6] Arora & Barak — the circuit model these reversible circuits specialize, for the complexity-preservation claim.

← Prev: Complexity Classes · Up: Term 0 · Next: The State Postulate