Quantum Computing · Chapter 02
Boolean and Reversible Computation
What must a computation remember in order to undo what it has done?
Mithilesh Kumar
→ or Space to advance · N for notes · F for fullscreen
2.1
Boolean Functions
We fix what a computation must produce, independent of how a machine produces it.
Binary encodings
Bits are two distinguishable physical states; an encoding is the dictionary that gives strings of bits a meaning.
| Bits | Encoding | Meaning |
|---|---|---|
| 00, 01, 10, 11 | 2-bit unsigned binary | 0, 1, 2, 3 |
| 01000001 | 8-bit unsigned binary | 65 |
| 01000001 | ASCII | A |
The encoding also fixes how cost is measured, because cost is a function of input length. The number \(N\) has length \(N\) in unary but about \(n=\log_2N\) bits in binary, since \(n\) bits distinguish \(2^n\) values.
So an algorithm taking \(N\) steps is linear in the unary length but exponential, \(N\approx2^n\), in the binary length.
An algorithm must be one finite procedure for all input lengths \(n\); a separate lookup rule for each \(n\) is not allowed.
Boolean functions and truth tables
A yes/no question about \(n\)-bit inputs, with no \(=0\) and yes \(=1\), is a Boolean function
Examples: is an \(n\)-bit integer odd? Do two strings match? An \(m\)-bit answer, such as a binary sum, is a list of \(m\) Boolean functions, one per output bit.
A truth table lists the output for every input. It says what the answer is, not how to compute it, and an \(n\)-bit function has \(2^n\) rows: \(2^{100}\) for 100 bits.
| \(xy\) | AND | OR |
|---|---|---|
| 00 | 0 | 0 |
| 01 | 0 | 1 |
| 10 | 0 | 1 |
| 11 | 1 | 1 |
To compute on many bits we need a compact rule built from a few elementary operations.
Arithmetic modulo two
Work with remainders on division by 2, so that \(1+1=0\). On bits:
- addition is exclusive OR (XOR), written \(a\oplus b\): it is 1 exactly when \(a\ne b\);
- multiplication is AND: \(0\cdot0=0\cdot1=0\) and \(1\cdot1=1\);
- \(1+x\) flips the bit \(x\).
To detect one row \(s=(s_1,\ldots,s_n)\) of a truth table, test each bit and multiply the tests:
A product of bits is 1 only when every factor is 1, so \(\delta_s(x)=1\) when \(x=s\) and \(0\) otherwise. For two bits and \(s=01\): \(\delta_{01}=(1+x)y\).
Polynomial representation
Add the detectors of the rows on which \(f\) equals 1:
Correctness: on input \(x\) every detector except \(\delta_x\) is 0, and \(\delta_x\) is in the sum exactly when \(f(x)=1\).
Result
Every Boolean function is a polynomial in its input bits, with arithmetic modulo two.
OR is 1 on rows 01, 10, 11:
Check 11: \(1+1+1=1\pmod2\), as OR requires.
XOR is 1 on rows 01 and 10:
because \(xy+xy=0\). Cancellation can make a polynomial far shorter than its list of detectors.
2.2
Boolean Circuits
We turn polynomials into networks of gates, show that one gate type suffices, and examine what gates do to information.
Circuits evaluate polynomials
To evaluate \(z=x+y+xy\): an AND gate computes \(u=xy\), an XOR computes \(v=x+y\), and a second XOR gives \(z=u+v\).
- A gate performs one elementary operation.
- A wire carries a bit from an input, a constant, or a gate output to later gates.
- No wire loops back, so gates can be evaluated stage by stage.
Any polynomial is evaluated the same way: AND gates form the products, XOR gates add the terms. Hence every Boolean function has a circuit.
Circuit size
Existence is not economy. The detector construction can produce up to \(2^n\) terms, hence exponentially many gates.
Sometimes algebra collapses the sum. Parity
equals 1 on \(2^{n-1}\) rows of its truth table, so its detector sum has \(2^{n-1}\) terms; yet the simplified polynomial needs only \(n-1\) XOR gates in a chain.
For most Boolean functions no such simplification exists. Finding the smallest circuit for a given function is the central problem of circuit complexity.
NAND universality
The gate \(\mathrm{NAND}(a,b)=\neg(a\land b)\) outputs 0 only when \(a=b=1\). From NAND alone we build:
- NOT: \(\mathrm{NAND}(a,a)=\neg a\);
- AND: NOT applied to \(\mathrm{NAND}(a,b)\);
- XOR: \(t=\mathrm{NAND}(a,b)\), \(u=\mathrm{NAND}(a,t)\), \(v=\mathrm{NAND}(b,t)\), output \(\mathrm{NAND}(u,v)\).
NOT, AND and XOR evaluate every polynomial, so NAND is universal for classical computation.
Check of the XOR construction:
| \(ab\) | \(t\) | \(u\) | \(v\) | out |
|---|---|---|---|---|
| 00 | 1 | 1 | 1 | 0 |
| 01 | 1 | 1 | 0 | 1 |
| 10 | 1 | 0 | 1 | 1 |
| 11 | 0 | 1 | 1 | 0 |
Equal inputs give \(u=v=1\), hence output 0; different inputs make exactly one of \(u,v\) zero, hence output 1.
Fan-out
In the four-NAND circuit, \(a\), \(b\) and \(t\) each feed two gates: one wire splits into several. This is fan-out.
Classically it is free: a voltage on a wire can drive several gate inputs, so copying a bit costs nothing in the circuit model.
Reversible circuits must build copying from gates (Section 2.4), and quantum circuits will restrict it further. The freedom assumed here is therefore worth noticing.
Irreversible Boolean operations
An AND output of 1 identifies the input 11, but an output of 0 could come from 00, 01 or 10. OR, NAND and XOR also send four inputs to two outputs, so each merges inputs and has no inverse.
Whether a step is reversible depends on which wires are kept:
| Kept outputs | Reversible? | Reason |
|---|---|---|
| \((x,\;x\oplus y)\) | yes | \(y=x\oplus(x\oplus y)\) is recovered |
| \((x\land y,\;x\lor y)\) | no | 01 and 10 both give \((0,1)\) |
A reversible computer demands more than a one-to-one overall map: every elementary gate must preserve distinctions, with no intermediate wire discarded.
2.3
Information Erasure
We state the physical cost of destroying information, separate it from ordinary dissipation, and show how to compute without erasure.
Landauer’s principle
A reset sends a bit holding 0 or 1 to 0. Microscopic physics conserves information, so the lost distinction must go into the environment.
Landauer’s principle (quoted result)
Erasing one equally likely bit, keeping no record of its value, releases on average at least \(Q\ge k_{\mathrm B}T\ln2\) of heat into surroundings at temperature \(T\).
At \(T=300\) K: \(1.38\times10^{-23}\,\mathrm{J/K}\times300\,\mathrm K\times0.693\approx2.9\times10^{-21}\) J per bit, far below the resistive heating of present transistors, but a floor no design can avoid.
- A bit already known to be 0 can be left alone at no minimum cost.
- A biased bit, or one recorded elsewhere, costs less; resetting the record later costs the same again.
Erasure is forced only when a computation merges distinct logical states.
Logical reversibility and dissipation
A transformation of \(n\)-bit strings is logically reversible if it is one-to-one, that is, a permutation of the \(2^n\) strings.
| Logically reversible map | Irreversible map run slowly | |
|---|---|---|
| Merges states? | never | yes: AND still sends 00, 01, 10 to 0 |
| Landauer cost forced? | no | yes |
| Device may still dissipate? | yes: resistance, friction, speed | yes |
Two questions must be kept apart: whether the map can be inverted, and how much heat a particular device dissipates. Reversibility is a property of the map; this book is about the first question.
Reversible function embeddings
To compute any \(f:\{0,1\}^n\to\{0,1\}\) without erasure, keep the input and add the answer to an extra target bit \(t\):
With \(t=0\) the target becomes \(f(x)\). Applying \(U_f\) twice,
since a bit added to itself is 0. So \(U_f\) is its own inverse, hence a permutation of all \((n+1)\)-bit strings, for every \(f\).
\(U_f\) does not overwrite \(t\); it XORs \(f(x)\) into it. This map will be the standard model of a function oracle in quantum algorithms.
The embedding of AND
| \((x,y,t)\) | \((x,y,t\oplus xy)\) |
|---|---|
| 000 | 000 |
| 001 | 001 |
| 010 | 010 |
| 011 | 011 |
| 100 | 100 |
| 101 | 101 |
| 110 | 111 |
| 111 | 110 |
For \(f(x,y)=xy\), the embedding \((x,y,t)\mapsto(x,y,t\oplus xy)\) swaps 110 and 111 and fixes the other six triples: eight inputs, eight distinct outputs.
AND itself has not become invertible; it still sends three inputs to 0. What is invertible is the larger map, which keeps \((x,y)\) beside the target.
The retained input bits are exactly the information that makes the map one-to-one.
2.4
Reversible Gates
We build reversible embeddings from elementary gates and clear the workspace they leave behind.
Controlled operations and CNOT
Principle: keep a control bit unchanged and let its value choose a reversible update of a target bit.
On one bit the reversible updates are “do nothing” and “flip”. This gives the controlled-NOT:
- With \(b=0\): \((a,0)\mapsto(a,a)\), so CNOT copies a bit onto a fresh 0 (reversible fan-out).
- Twice: \((a,\,b\oplus a\oplus a)=(a,b)\), so CNOT is its own inverse.
| \((a,b)\) | CNOT |
|---|---|
| 00 | 00 |
| 01 | 01 |
| 10 | 11 |
| 11 | 10 |
Both ingredients are needed. Discard the control and we cannot tell whether to flip back. Keep it but reset the target when \(a=1\), and \((1,0)\), \((1,1)\) both become \((1,0)\).
Toffoli and Fredkin gates
NOT adds 1 and CNOT adds one wire to another, so in a NOT/CNOT circuit every wire holds a constant plus a sum of inputs modulo 2. The product \(ab\) never appears: these gates cannot compute AND.
Give the target two controls:
It swaps 110 and 111 and fixes the other six inputs; with \(c=0\) the target becomes \(ab\). Fredkin swaps \(b\) and \(c\) when \(a=1\). Both are their own inverses.
Reversible universality
Toffoli gates can run every classical circuit:
- With target \(c=1\): \(1\oplus ab=\mathrm{NAND}(a,b)\).
- NAND is universal (Section 2.2.2).
- Fan-out: CNOT copies a wire onto a fresh 0.
- Replace each NAND gate by a Toffoli gate acting on a fresh wire set to 1.
This proves existence; the naive translation is rarely the most economical.
Fredkin gates are universal too, given constant 0 and 1 wires:
| Input | Output | Gives |
|---|---|---|
| \((a,b,0)\) | \((a,\,\neg a\land b,\,ab)\) | AND |
| \((a,1,0)\) | \((a,\,\neg a,\,a)\) | NOT, copy |
A swap never changes the number of 1s, which is why Fredkin needs constant inputs to produce NOT.
Workspace
Compute \(xyz\) with Toffoli gates, a workspace bit \(w=0\) and an output bit \(t=0\):
The answer is in \(t\), but \(w\) still holds \(xy\). Two poor options:
- reset \(w\) to 0: this erases unknown information and pays the Landauer cost;
- leave \(w\): memory fills with a record of the history, one fresh bit per gate in a long computation.
Third option: apply the first Toffoli again. Since \(x,y\) are intact, \(w\) becomes \(xy\oplus xy=0\) and \(t\) is untouched:
Uncomputation
General pattern: a reversible circuit \(A\) computes the answer \(f(x)\) and leaves intermediate values \(g(x)\), the garbage.
Run \(A\); copy \(f(x)\) to a fresh register with CNOTs; run \(A^{-1}\), the gates of \(A\) in reverse order. Only the input and the answer remain. Removing \(g(x)\) while \(x\) is present is a permutation, not an erasure; in quantum computation, leftover garbage would also destroy interference (Chapter 3).
Summary
- An encoding turns a task into Boolean functions; cost is measured against input length.
- Every Boolean function is a polynomial modulo two, so it has a circuit; NAND alone suffices, though small circuits are rare.
- Erasing a bit costs at least \(k_{\mathrm B}T\ln2\); erasure is forced only when a computation merges states.
- The embedding \(U_f:(x,t)\mapsto(x,t\oplus f(x))\) computes any \(f\) reversibly; Toffoli gates build it, and uncomputation clears the workspace.