Education / Quantum Computing

Quantum Computing · Chapter 02

Boolean and Reversible Computation

Presentation slides 24 slides · Fullscreen presentation or print to PDF

In Chapter 1, we saw that a computation is a sequence of transitions between configurations, and that reversing a step is impossible whenever distinct inputs merge into the same output. How can we build general-purpose computations out of elementary steps on bits without losing information?

We first represent data and computational tasks using bits, Boolean functions, and logic circuits. We then examine the physical cost of erasing information and show how to compute any Boolean function using reversible gates.

What must a computation remember in order to undo what it has done?

Inside a digital computer, data of every kind is encoded as strings of zeros and ones, and each step transforms those bits. Yet familiar logic operations routinely discard information by merging different inputs into the same output.

For example, an operation that outputs \(1\) only when two input bits are both \(1\) gives the output \(0\) for three different input pairs: \(00\), \(01\), and \(10\). Once only \(0\) remains, there is no way to tell which input pair produced it. Before we can make such steps reversible, we first need to see how data is encoded in bits and how functions on bits are built from elementary operations.

In this chapter · 4 sections · 12 topics
  1. 2.1 Boolean Functions
    Topics in this section
    1. 2.1.1 Binary encodings
    2. 2.1.2 Boolean functions and truth tables
    3. 2.1.3 Polynomial representation over the binary field
  2. 2.2 Boolean Circuits
    Topics in this section
    1. 2.2.1 Polynomial evaluation by circuits
    2. 2.2.2 NAND universality
    3. 2.2.3 Irreversible Boolean operations
  3. 2.3 Information Erasure
    Topics in this section
    1. 2.3.1 Landauer’s principle
    2. 2.3.2 Logical reversibility and dissipation
    3. 2.3.3 Reversible function embeddings
  4. 2.4 Reversible Gates
    Topics in this section
    1. 2.4.1 Controlled reversible operations
    2. 2.4.2 CNOT, Toffoli, and Fredkin gates
    3. 2.4.3 Workspace and uncomputation
Reading guide · preparation, aims, and assumptions

Build computations from Boolean operations and learn how to preserve the information they would otherwise discard.

Before you begin

Recall that a computation transforms configurations step by step, and that one function can have different implementations.

What you should be able to do

The example to follow

Follow a function value from a truth table to a reversible target update. The same update becomes the oracle in Chapter 7.

Scope and assumptions

Logical reversibility alone does not guarantee low physical dissipation. Landauer’s bound concerns erasure under stated thermodynamic conditions.

2.1

Boolean Functions

Before we can design logic circuits—or worry about whether their gates discard information—we need a precise mathematical language for stating what a computation is supposed to accomplish, independent of how any machine carries it out. Choosing a binary encoding reduces every finite computational task to evaluating a Boolean function on strings of bits. While a truth table specifies such a function completely, it merely lists answers without providing a recipe to calculate them. Translating truth tables into polynomials over the binary field gives us our first systematic bridge from a table of specifications to a step-by-step algebraic calculation.

2.1.1 Binary encodings§

encoding

What does it mean to hand a mathematical problem to a machine that only manipulates zeros and ones? By themselves, bits carry no intrinsic meaning—they are simply two distinguishable states of a physical system. An encoding is the dictionary that assigns meaning to each string of bits. Under a two-bit unsigned binary encoding, the strings \(00\), \(01\), \(10\), and \(11\) represent the integers zero through three; under an eight-bit encoding, the single string \(01000001\) represents either the integer \(65\) in unsigned binary or the capital letter A in the ASCII text standard.

Choosing an encoding is far more than a matter of notation: it directly shapes how we measure computational cost, because an algorithm’s resource use is always evaluated as a function of its input length. To represent a positive integer \(N\) in unary notation—writing \(N\) tally marks on a tape, as in the simple Turing machines of Chapter 1—requires an input of length \(N\). In binary positional notation, by contrast, \(n\) bits can distinguish \(2^n\) values, so the same integer \(N\) requires only about \(\log_2 N\) bits. A procedure that takes \(N\) steps looks fast when measured against an \(N\)-symbol unary string, yet takes exponentially many steps relative to the compact \(\log_2 N\)-bit binary representation.

Once an encoding is fixed, inputs of length \(n\) range over \(2^n\) possible bit strings. Importantly, a genuine algorithm must handle all permitted input lengths \(n\) using one uniform, finite procedure—we are not allowed to smuggle in a newly invented lookup rule for each input size.

One bit string, different interpretationsAn encoding supplies meaning. The bits alone do not tell a machine whether to treat 01000001 as a number or a character. Columns: Bits, Encoding, Meaning. 01000001, Unsigned binary, 65; 01000001, ASCII character, AOne bit string, different interpretationsBitsEncodingMeaning01000001Unsigned binary6501000001ASCII characterA
An encoding supplies meaning. The bits alone do not tell a machine whether to treat \(01000001\) as a number or a character.
Problems
  1. Write \(13\) in binary with four bits, and decode \(1011\) as an unsigned binary integer.

    Show solutionHide solution

    \(13=8+4+1\), so it is \(1101\). The string \(1011\) is \(8+2+1=11\).

  2. An integer \(N\) is written in binary and, alternatively, in unary, as \(N\) marks. For \(N=1000\), compare the two input lengths. How does a procedure that takes \(N\) steps compare with each length?

    Show solutionHide solution

    Since \(2^9=512\leq1000\lt 1024=2^{10}\), binary needs \(10\) bits, while unary needs \(1000\) marks. A procedure taking \(N\) steps is linear in the unary length but exponential in the binary length, about \(2^{10}\) steps for \(10\) bits. The same procedure is “efficient” or not depending on the encoding.

  3. Show that any encoding of the integers \(0,1,\dots,M-1\) by bit strings of one fixed length \(n\) needs \(n\geq\log_2M\).

    Show solutionHide solution

    There are \(2^n\) bit strings of length \(n\). An encoding gives different integers different strings, so it needs at least \(M\) strings: \(2^n\geq M\). Taking logarithms, \(n\geq\log_2M\). Binary achieves this up to rounding up.

2.1.2 Boolean functions and truth tables§

Boolean functiontruth table

Once inputs and outputs are represented in binary, what is the mathematical object a computer actually evaluates? Consider a yes-or-no question about an \(n\)-bit input—for example, whether an \(n\)-bit integer is odd, or whether two bit strings match. Identifying “no” with \(0\) and “yes” with \(1\) turns the task into a Boolean function

\[f:\{0,1\}^n\to\{0,1\},\]

which assigns a single output bit, \(0\) or \(1\), to each of the \(2^n\) possible input strings. What if a calculation produces an \(m\)-bit output, such as the sum of two binary numbers? That multi-bit transformation is simply a list of \(m\) separate Boolean functions \(f_1, f_2, \dots, f_m\), one for each bit of the answer. Understanding single-output Boolean functions therefore suffices to describe any finite computation on bits.

The most direct way to specify a Boolean function \(f\) is to list every possible input string alongside its corresponding output bit. This complete input–output catalog is the truth table of \(f\). For the two-bit operations AND (which outputs \(1\) only when both inputs are \(1\)) and OR (which outputs \(1\) whenever at least one input is \(1\)), the truth tables have four rows:

Input \(xy\)ANDOR
\(00\)\(0\)\(0\)
\(01\)\(0\)\(1\)
\(10\)\(0\)\(1\)
\(11\)\(1\)\(1\)

Does a truth table tell us how to compute \(f\)? It defines what the answer must be for every input, but provides no step-by-step mechanism for calculating it. Moreover, truth tables grow at an explosive rate: an \(n\)-bit function has \(2^n\) rows, so even a \(100\)-bit input would require a table of \(2^{100}\) rows—vastly larger than any physical memory could ever store. To compute functions on many bits, we need a compact rule built from a small set of elementary operations.

AND as a complete input–output specificationThe truth table lists four possible inputs. Only the input 11 produces one; a circuit must implement all four rows. Columns: x, y, x AND y. 0, 0, 0; 0, 1, 0; 1, 0, 0; 1, 1, 1AND as a complete input–output specificationxyx AND y000010100111
The truth table lists four possible inputs. Only the input \(11\) produces one; a circuit must implement all four rows.
Problems
  1. Write the truth table of the majority function on three bits, which outputs \(1\) when at least two of its inputs are \(1\).

    Show solutionHide solution

    \(000\to0\), \(001\to0\), \(010\to0\), \(011\to1\), \(100\to0\), \(101\to1\), \(110\to1\), and \(111\to1\).

  2. How many Boolean functions of two bits are there? List those that output \(1\) on exactly one input.

    Show solutionHide solution

    A truth table has four rows, each with output \(0\) or \(1\), so there are \(2^4=16\) functions. Those with a single \(1\): output \(1\) only on \(11\) (AND), only on \(10\) (\(x\) and not \(y\)), only on \(01\) (not \(x\) and \(y\)), and only on \(00\) (NOR).

  3. Show that there are \(2^{2^n}\) Boolean functions of \(n\) bits. For \(n=10\), show that fewer than one function in a thousand can be described by a string of fewer than \(1014\) bits.

    Show solutionHide solution

    The truth table has \(2^n\) rows, and each row’s output can be chosen independently, giving \(2^{2^n}\) functions. For \(n=10\) that is \(2^{1024}\). The number of bit strings shorter than \(1014\) bits is \(1+2+\dots+2^{1013}=2^{1014}-1\lt 2^{1014}\). Different functions need different descriptions, so at most \(2^{1014}\) functions have such a short description, a fraction below \(2^{1014}/2^{1024}=2^{-10}\lt 1/1000\). Almost every function has no description much shorter than its truth table.

2.1.3 Polynomial representation over the binary field§

arithmetic modulo twoXORdetector

Can we systematically turn any truth table into an algebraic formula? We can, provided we work in arithmetic modulo two, where numbers are reduced to their remainder on division by \(2\) so that \(1+1=0\). Addition modulo two is then the exclusive-OR operation (XOR, written \(a\oplus b\)), which outputs \(1\) when its two bit arguments differ and \(0\) when they are equal. Multiplication on \(\{0,1\}\) satisfies \(0\cdot0=0\), \(0\cdot1=0\), and \(1\cdot1=1\), which is exactly logical AND.

Using only addition and multiplication modulo two, we can build an explicit polynomial for any Boolean function \(f\) row by row. For each input string \(s=(s_1,s_2,\dots,s_n)\) in the truth table, we first construct a detector polynomial \(\delta_s(x)\) that evaluates to \(1\) when the input \(x=(x_1,x_2,\dots,x_n)\) equals \(s\), and evaluates to \(0\) on every other input. How do we test whether a single bit \(x_i\) matches \(s_i\)? When \(s_i=1\), the factor \(x_i\) itself equals \(1\) if and only if \(x_i=1\). When \(s_i=0\), the factor \(1+x_i\) flips the bit modulo two, equaling \(1\) if and only if \(x_i=0\). Multiplying these single-bit tests across all \(n\) positions gives the detector for row \(s\):

\[\delta_s(x)=\prod_{i:\,s_i=1}x_i\prod_{i:\,s_i=0}(1+x_i).\]

Because a product of bits equals \(1\) only when every factor is \(1\), \(\delta_s(x)\) is \(1\) for \(x=s\) and \(0\) for all \(x\neq s\). On two bits \((x,y)\), for example, the detector for the row \(s=01\) is \((1+x)y\).

To obtain the polynomial for \(f(x)\), we simply add modulo two the detectors of all rows \(s\) on which \(f(s)=1\):

\[f(x)=\sum_{s:\,f(s)=1}\delta_s(x)\pmod 2.\]

Why does this sum agree with \(f(x)\) on every input? On any specific input \(x\), every detector \(\delta_s(x)\) with \(s\neq x\) evaluates to \(0\), leaving only \(\delta_x(x)=1\). If \(x\) is a row where \(f(x)=1\), its detector is included in the sum, yielding \(1\); if \(f(x)=0\), that detector is absent, yielding \(0\).

Consider two-bit OR, which equals \(1\) on the three rows \(01\), \(10\), and \(11\). Adding their detectors modulo two and expanding gives

\[(1+x)y+x(1+y)+xy=x+y+3xy=x+y+xy\pmod 2,\]

since \(3\equiv1\pmod2\). Check the input \(11\): whereas ordinary integer addition would give \(1+1+1=3\), arithmetic modulo two gives \(1+1+1=1\pmod2\), matching the OR truth table. By expanding the detectors and simplifying modulo two, every Boolean function can be written as a polynomial in its input bits.

OR written as a polynomial over bitsAll additions are modulo two. The polynomial x+y+xy reproduces OR on Boolean inputs; its interpretation depends on this arithmetic. Columns: x, y, x+y mod 2, xy, x+y+xy mod 2. 0, 0, 0, 0, 0; 0, 1, 1, 0, 1; 1, 0, 1, 0, 1; 1, 1, 0, 1, 1OR written as a polynomial over bitsx, yx+y mod 2xyx+y+xy mod 20, 00000, 11011, 01011, 1011
All additions are modulo two. The polynomial \(x+y+xy\) reproduces OR on Boolean inputs; its interpretation depends on this arithmetic.
Problems
  1. Evaluate \((1+x)(1+y)\) modulo two for all four inputs. Which function is it?

    Show solutionHide solution

    It equals \(1\) only when both factors are \(1\), that is, when \(x=y=0\). For \(00,01,10,11\) the values are \(1,0,0,0\): this is NOR, the negation of OR.

  2. Build the polynomial of XOR from its truth table using detectors, and simplify it.

    Show solutionHide solution

    XOR is \(1\) on the rows \(01\) and \(10\). Their detectors are \((1+x)y\) and \(x(1+y)\), so XOR is \((1+x)y+x(1+y)=y+xy+x+xy=x+y\pmod2\), since \(xy+xy=0\).

  3. Show that the polynomial of the three-bit majority function is \(xy+yz+xz\) modulo two.

    Show solutionHide solution

    Majority is \(1\) on \(011\), \(101\), \(110\), and \(111\). The detectors add to \((1+x)yz+x(1+y)z+xy(1+z)+xyz=yz+xz+xy+4xyz\). Since \(4xyz=0\) modulo two, the polynomial is \(xy+yz+xz\). Check: on \(110\) it gives \(1+0+0=1\), and on \(111\) it gives \(1+1+1=1\).

2.2

Boolean Circuits

A polynomial over the binary field tells us which elementary additions and multiplications combine to produce a Boolean function, but an algebraic formula on the page is still static: it does not specify the order in which operations are carried out or how intermediate values are routed from one step to the next. A Boolean circuit supplies that architecture, turning an algebraic expression into a directed network of wires and logic gates. In this section, we show that circuits can evaluate every Boolean function, prove that a single gate type—the NAND gate—suffices to build any circuit, and then examine the gates themselves, uncovering why the standard building blocks of classical logic inevitably discard information about their inputs.

2.2.1 Polynomial evaluation by circuits§

circuitgatewire

How do we turn an algebraic formula such as the OR polynomial \(z=x+y+xy\pmod 2\) into a concrete, step-by-step calculation? We break the formula into elementary two-bit operations: first compute the product \(u=xy\) using an AND operation and the modulo-two sum \(v=x+y\) using an XOR operation, and then combine those two intermediate bits into the final output \(z=u+v\) using a second XOR operation.

This connected arrangement of elementary operations is a Boolean circuit. Each elementary operation is carried out by a logic gate, and each wire routes a bit from an input—or from the output of one gate—to the input of a subsequent gate; in our OR circuit, internal wires carry the intermediate bits \(u\) and \(v\) from the first stage of gates into the final XOR gate. A wire may also supply a fixed constant bit, \(0\) or \(1\), such as the constant \(1\) needed to flip a bit via \(1+x\). Crucially, no wire in a combinational circuit ever loops back to an earlier gate, ensuring that the gates can be evaluated in a definite stage-by-stage order from inputs to output.

The exact same strategy works for any polynomial over the binary field: we multiply variables inside each product term using a cascade of AND gates and add the resulting terms modulo two using a cascade of XOR gates. Because every truth table can be written as a polynomial, it follows immediately that every Boolean function \(f:\{0,1\}^n\to\{0,1\}\) can be computed by a Boolean circuit.

Does this guarantee that every Boolean function has a small circuit? Not at all. Building a polynomial directly from a truth table can produce up to \(2^n\) detector terms, which translates into an exponentially large network of gates. Sometimes algebraic cancellation collapses a huge sum of detectors into a compact circuit—for instance, the \(n\)-bit parity function \(x_1+x_2+\dots+x_n\pmod 2\) equals \(1\) on \(2^{n-1}\) truth-table rows, yet after simplification it requires only \(n-1\) XOR gates. For most Boolean functions, however, no such simplification exists. Showing that every function can be realized by a circuit settles the question of expressiveness; finding the most economical circuit to realize a given function is a central challenge of circuit complexity.

Circuit for x + y + xyInputs x and y each branch to an AND gate and an XOR gate. The AND produces u=xy, the first XOR produces v=x+y, and a second XOR produces z=u+v=x+y+xy. Filled dots connect wires; a crossing without a dot is not a connection.z=x+y+xy over bitsxyANDXORXORu=xyv=x+yz=u+vFilled dots join wires; crossings without dots do not. Here + means XOR.
Circuit for \(z=x+y+xy\). The AND gate computes \(u=xy\), the first XOR computes \(v=x+y\), and the final XOR gives \(z=u+v\). Each input branches to both first-stage gates.
Problems
  1. Evaluate the circuit for \(x+y+xy\), built from one AND gate and two XOR gates, on the input \(10\), giving the bit on every wire.

    Show solutionHide solution

    The AND gate outputs \(u=1\cdot0=0\). The first XOR gate outputs \(x+y=1\). The second XOR gate combines these: \(1+0=1\). The output is \(1\), as OR requires.

  2. Build a circuit for majority, \(xy+yz+xz\), from AND and XOR gates. How many gates does it use?

    Show solutionHide solution

    Three AND gates compute \(xy\), \(yz\), and \(xz\), and two XOR gates add them: first \(xy+yz\), then that sum plus \(xz\). That is five gates in all.

  3. The parity function \(x_1+x_2+\dots+x_n\pmod2\) equals \(1\) on half of its inputs. How many detectors does the truth-table construction add, and how many XOR gates does the simplified polynomial need?

    Show solutionHide solution

    Parity is \(1\) on \(2^{n-1}\) of the \(2^n\) inputs, so the construction adds \(2^{n-1}\) detectors, each a product of \(n\) factors. After simplification the polynomial is just \(x_1+\dots+x_n\), which needs \(n-1\) XOR gates. The general construction proves that a circuit exists, but it can be exponentially wasteful.

2.2.2 NAND universality§

NANDuniversalfan-out

To build circuits for arbitrary Boolean functions, do we really need to manufacture separate hardware gates for AND, XOR, and NOT? Remarkably, a single type of gate is enough. The NAND (“not-AND”) gate outputs the negation of logical AND, written \(\operatorname{NAND}(a,b)=\neg(a\land b)\), where \(a\land b\) denotes the AND of \(a\) and \(b\). Its truth table is the exact opposite of AND: it outputs \(0\) only when both inputs are \(1\) (\(a=b=1\)), and outputs \(1\) on the remaining three input pairs (\(00\), \(01\), and \(10\)).

From NAND alone, we can systematically reconstruct every gate used in polynomial evaluation. First, tying both inputs of a NAND gate to the same bit \(a\) produces logical negation (NOT): since \(a\land a=a\), we have \(\operatorname{NAND}(a,a)=\neg(a\land a)=\neg a\). Second, passing the output of a NAND gate through a NOT gate recovers AND: \(a\land b=\operatorname{NAND}\bigl(\operatorname{NAND}(a,b),\operatorname{NAND}(a,b)\bigr)\). Third, combining four NAND gates yields XOR:

\[t=\operatorname{NAND}(a,b),\quad u=\operatorname{NAND}(a,t),\quad v=\operatorname{NAND}(b,t),\quad a\oplus b=\operatorname{NAND}(u,v).\]

We can verify this four-gate identity directly across all four input pairs. Whenever \(a\) and \(b\) are equal—either \(00\) (where \(t=1\)) or \(11\) (where \(t=0\))—both intermediate wires evaluate to \(u=1\) and \(v=1\), so the final NAND gate outputs \(0\). Whenever \(a\) and \(b\) differ (\(01\) or \(10\)), the first gate gives \(t=1\), causing one of \(u,v\) to be \(0\) and the other to be \(1\), so the final NAND gate outputs \(1\). Because NAND gates can build NOT, AND, and XOR—and can therefore evaluate the polynomial of any Boolean function—the NAND gate is universal for classical computation.

Notice a quiet structural feature that makes these constructions possible: a single wire repeatedly splits so that one bit can feed several gates at once. In our four-NAND circuit for XOR, the inputs \(a\) and \(b\) each branch to two gates, and so does the intermediate wire \(t\). Duplicating a bit across branching wires in this manner is called fan-out. In classical circuits, fan-out is treated as a free wiring operation, since a voltage signal on a wire can easily drive multiple gate inputs—a freedom we will have to re-examine carefully when we move to reversible and quantum circuits.

XOR from four NAND gatesFirst compute t=NAND(a,b). Then u=NAND(a,t) and v=NAND(b,t). The last NAND of u and v yields XOR.abtuva⊕ bThe small output circle denotes negation; filled dots denote branches.
Four NAND gates compute XOR. Branch dots indicate shared classical inputs; small output circles indicate negation.
Problems
  1. Compute \(\operatorname{NAND}(a,b)\) for all four inputs. Use the table to check that \(\operatorname{NAND}\bigl(\operatorname{NAND}(a,b),\operatorname{NAND}(a,b)\bigr)=a\land b\).

    Show solutionHide solution

    \(\operatorname{NAND}\) gives \(1,1,1,0\) on \(00,01,10,11\). Feeding the same bit into both inputs of a NAND gate negates it, so the outer gate turns \(1,1,1,0\) into \(0,0,0,1\), which is AND.

  2. Build OR from NAND gates, and verify the construction on all four inputs.

    Show solutionHide solution

    \(a\lor b=\operatorname{NAND}(\neg a,\neg b)\) with \(\neg a=\operatorname{NAND}(a,a)\): three gates. For \(00\): \(\operatorname{NAND}(1,1)=0\). For \(01\): \(\operatorname{NAND}(1,0)=1\). For \(10\): \(\operatorname{NAND}(0,1)=1\). For \(11\): \(\operatorname{NAND}(0,0)=1\). These are the outputs of OR.

  3. Show that circuits of AND and XOR gates, with no constant inputs, cannot compute NOT, but that adding the constant \(1\) makes the set universal.

    Show solutionHide solution

    On the all-zero input, AND and XOR gates output \(0\) when both their inputs are \(0\). By induction along the circuit, every wire carries \(0\), so the output is \(0\); NOT must output \(1\) on input \(0\). With the constant \(1\), \(\neg x=x\oplus1\), and AND together with NOT builds NAND, which is universal.

2.2.3 Irreversible Boolean operations§

Now that we can build any Boolean function out of elementary gates, let us ask what happens to the input information as a gate acts. When a two-bit AND gate outputs \(1\), its input is uniquely determined: it must have been \(11\). When the gate outputs \(0\), however, three different input pairs—\(00\), \(01\), and \(10\)—all collapse to that single output value. The same loss of distinction occurs in OR, NAND, and XOR: because each of these gates compresses four possible two-bit inputs into just two possible one-bit outputs, different inputs are forced to merge. Reversibility requires that every allowed output identify a unique input, so an unrestricted two-input, one-output gate has no inverse.

When analyzing whether a calculation is reversible, we must always specify which wires are kept in the final state. A gate that loses information in isolation can form part of a one-to-one step if a copy of an input is preserved elsewhere: for instance, if we use fan-out to retain \(x\) on one wire while computing \(s=x\oplus y\) on a second wire, the combined two-bit output \((x,s)\) is completely reversible because we can recover \(y=x\oplus s\). Conversely, keeping two output bits from two input bits does not automatically make a circuit reversible: computing \(x\land y\) on one wire and \(x\lor y\) on another still merges the inputs \(01\) and \(10\) into the same output pair \((0,1)\).

Even more importantly, a circuit whose overall input–output map is one-to-one is not genuinely reversible if it discards intermediate wires or uses irreversible gates internally along the way. A reversible computer—and, ultimately, a quantum computer—demands a stricter standard: a sequence of elementary steps in which every single gate preserves distinctions across the full state of the registers. Can we still compute arbitrary Boolean functions without ever using AND or NAND as a two-to-one erasure? To see how, we turn next to the physical meaning of information erasure and the mathematical technique for embedding any function into a reversible transformation.

Three different inputs mergeThe AND gate maps 00, 01, and 10 to the same output. Output zero cannot identify which of these inputs occurred. 00 → 0; 01 → 0; 10 → 0; 11 → 1.Three different inputs mergeAND0001101101
The AND gate maps \(00\), \(01\), and \(10\) to the same output. Output zero cannot identify which of these inputs occurred.
Problems
  1. For OR on two bits, list the inputs that share each output. Can the inputs be recovered from the output?

    Show solutionHide solution

    Output \(0\) comes only from \(00\); output \(1\) comes from \(01\), \(10\), and \(11\). After an output \(1\), the input cannot be recovered.

  2. A circuit computes \((x,y)\mapsto(x\land y,\;x\lor y)\). Is this map one-to-one? Which inputs collide?

    Show solutionHide solution

    The outputs are \(00\mapsto(0,0)\), \(01\mapsto(0,1)\), \(10\mapsto(0,1)\), and \(11\mapsto(1,1)\). The inputs \(01\) and \(10\) collide, so the map is not one-to-one, even though it produces two bits from two.

  3. The map \((x,y)\mapsto(x,\,x\oplus y)\) is computed by copying \(x\) and feeding \(x\) and \(y\) into an XOR gate, which on its own loses information. Show that the map is one-to-one, and explain where the information discarded by the XOR gate survives.

    Show solutionHide solution

    Given the output \((x,s)\) with \(s=x\oplus y\), we recover \(y=x\oplus s\). So different inputs give different outputs. The XOR gate alone cannot distinguish \(00\) from \(11\), but the copied \(x\) separates them. The information is kept by the fan-out copy, not by the gate.

2.3

Information Erasure

In Section 2.2, we saw that standard Boolean gates like AND and NAND are many-to-one maps that discard information about their inputs. Because every bit in a physical computer is held by the state of a physical system, throwing away logical information has a direct physical consequence. In this section, we state the minimum thermodynamic cost of erasing a bit, separate that fundamental floor from ordinary engineering losses, and show how any Boolean function—even one that merges its inputs—can be embedded into a reversible transformation that keeps the input beside the answer.

2.3.1 Landauer’s principle§

Landauer’s principle

The simplest irreversible operation on a single bit is a reset, which takes a memory cell whose initial value may be \(0\) or \(1\) and forces it into the state \(0\). Why does this logical compression matter to physics? Because the microscopic laws of physics conserve information, compressing two distinguishable physical states of a memory register into a single state cannot simply make the lost distinction vanish; the removed uncertainty must be dumped into the surrounding thermal environment.

In the standard isothermal setting—where a memory register interacts with a thermal reservoir at absolute temperature \(T\)—erasing one equally likely bit without retaining its value elsewhere releases at least

\[Q\geq k_{\mathrm B}T\ln2\]

of heat into the environment on average. This lower bound, discovered by Rolf Landauer in 1961, is Landauer’s principle; here \(T\) is absolute temperature in kelvins and \(k_{\mathrm B}\approx 1.38\times 10^{-23}\text{ J/K}\) is Boltzmann’s constant. At room temperature (\(T=300\text{ K}\)), \(k_{\mathrm B}T\ln2\) is about \(2.9\times 10^{-21}\text{ J}\) per erased bit—tiny compared with the resistive heating of present-day transistors, yet an inescapable physical floor whenever information is destroyed.

Crucially, Landauer’s bound is a thermodynamic price for reducing entropy under stated physical conditions, not an automatic fee charged every time a logic gate acts. A bit already known to be \(0\) can be left untouched at zero minimum cost. If a bit is statistically biased, or if its value is partly or fully correlated with a record kept in another register, less uncertainty is removed and the minimum heat bound is correspondingly smaller—though any physical memory holding that external record will face the same erasure cost if it is later reset.

We will not need a statistical-mechanical derivation of this bound. For our purposes, the essential takeaway is computational: physical erasure is forced only when a calculation merges distinct logical states. If a useful calculation can avoid merging logical states altogether, it avoids forcing information erasure at those steps, even though any imperfect physical device may still dissipate energy for practical engineering reasons.

Further detail: Bennett: Landauer’s principle and reversible computation.

Resetting an unknown bitBoth possible logical inputs are reset to zero. For erasure of one equally likely bit in the standard isothermal setting, the minimum heat delivered to the environment is kBT ln 2. 0 → 0; 1 → 0.Resetting an unknown bitreset010
Both possible logical inputs are reset to zero. For erasure of one equally likely bit in the standard isothermal setting, the minimum heat delivered to the environment is kBT ln 2.
Problems
  1. Compute \(k_{\mathrm B}T\ln2\) at \(T=300\) K, with \(k_{\mathrm B}=1.38\times10^{-23}\) J/K.

    Show solutionHide solution

    \(1.38\times10^{-23}\times300\times0.693\approx2.9\times10^{-21}\) J.

  2. A processor erases \(10^{18}\) bits per second at \(300\) K. What minimum power does Landauer’s principle require? Compare it with a processor that uses \(50\) W.

    Show solutionHide solution

    \(10^{18}\times2.9\times10^{-21}\) J per second is about \(2.9\times10^{-3}\) W, roughly \(3\) mW. A \(50\) W processor dissipates more than ten thousand times this. Today’s heat comes mostly from other losses, not from the erasure limit.

  3. Erasing a bit that is \(0\) with probability \(p\) and \(1\) with probability \(1-p\) has the minimum cost \(H\,k_{\mathrm B}T\ln2\), where \(H=-p\log_2p-(1-p)\log_2(1-p)\). Compute \(H\) for \(p=0.9\), and compare the cost with that of an unbiased bit and a known bit.

    Show solutionHide solution

    \(H=-0.9\log_20.9-0.1\log_20.1\approx0.137+0.332=0.469\). The cost is about \(0.47\,k_{\mathrm B}T\ln2\), roughly half that of an unbiased bit, for which \(H=1\). For a known bit, \(p=1\) gives \(H=0\): nothing uncertain is erased, so no minimum cost applies.

2.3.2 Logical reversibility and dissipation§

logically reversible

If a computation never erases information, does it automatically run without producing heat? Not necessarily. We call a transformation logically reversible when it is one-to-one on its allowed states—meaning, on a finite set of \(n\)-bit strings, that it acts as a permutation of all \(2^n\) strings. Because a logically reversible step never merges distinct states, it avoids the minimum heat cost that information erasure forces. Even so, a real physical device implementing that step may still dissipate energy through electrical resistance, friction, imperfect control, or the speed at which it is driven.

Conversely, can a gate that loses logical information—such as a two-input, one-output AND gate or a reset operation—be made reversible simply by operating the hardware slowly and carefully? No. Running an AND gate slowly does not make its output \(0\) reveal whether the input was \(00\), \(01\), or \(10\). Logical reversibility is a mathematical property of the input–output map itself, not of the physical process used to carry it out.

Two questions must therefore be kept cleanly apart: first, whether the mathematical transformation on the state space can be inverted; and second, how much energy a particular physical realization dissipates as heat. Throughout this book, our primary concern is the first question: how to construct computations so that every elementary step can be undone.

Logical and physical questions are separateA reversible truth table settles whether the input is recoverable. It does not specify the energy dissipated by a particular physical device. Columns: Description, Question it answers, What else is needed. Logical map, Can we recover the input?, Full input/output states; Physical process, How much heat is released?, Dynamics and environmentLogical and physical questions are separateDescriptionQuestion it answersWhat else is neededLogical mapCan we recover theinput?Full input/output statesPhysical processHow much heat isreleased?Dynamics and environment
A reversible truth table settles whether the input is recoverable. It does not specify the energy dissipated by a particular physical device.
Problems
  1. Which of these are logically reversible: NOT; AND; \((x,y)\mapsto(x,x\oplus y)\); a reset to \(0\)?

    Show solutionHide solution

    NOT and \((x,y)\mapsto(x,x\oplus y)\) are one-to-one, hence reversible. AND and the reset merge different inputs, so they are not.

  2. A device implements NOT but dissipates \(10^{-18}\) J per operation, while the Landauer bound at \(300\) K is about \(2.9\times10^{-21}\) J. Does the dissipation contradict the reversibility of NOT? Does Landauer’s principle require any dissipation for NOT?

    Show solutionHide solution

    No contradiction: reversibility is a property of the map, and the device may lose energy for other reasons. Landauer’s principle requires no minimum for NOT, since NOT erases nothing. The bound applies only when information is erased.

  3. Show that a reversible map on \(n\)-bit strings is a permutation of the \(2^n\) strings. For \(n=2\), count the reversible maps and compare with the number of all maps from two bits to two bits.

    Show solutionHide solution

    A reversible map is one-to-one on the \(2^n\) strings, and a one-to-one map of a finite set to itself is onto, so it is a permutation. For \(n=2\) there are \(4!=24\) permutations of the four strings, while all maps number \(4^4=256\). Fewer than one map in ten is reversible.

2.3.3 Reversible function embeddings§

target bit

How can we evaluate any Boolean function \(f:\{0,1\}^n\to\{0,1\}\) without erasing information, even when \(f\) is a many-to-one operation like AND or OR that merges its inputs? The key is to keep the input register intact and write the answer into an extra target bit \(t\).

Specifically, we adjoin a single target bit \(t\in\{0,1\}\) to the \(n\)-bit input \(x\) and replace \(f\) by the \((n+1)\)-bit transformation

\[U_f:(x,t)\mapsto(x,\,t\oplus f(x)),\]

where the symbol \(\mapsto\) (“maps to”) gives the rule sending each input state to its output state. The input \(x\) passes through unchanged, while the function value \(f(x)\) is added modulo two to the target bit \(t\). Note that \(U_f\) does not overwrite \(t\) with \(f(x)\); rather, it XORs \(f(x)\) into whatever value \(t\) already holds. When we initialize the target bit to \(t=0\), the target register receives \(0\oplus f(x)=f(x)\).

Why is \(U_f\) guaranteed to be reversible for every Boolean function \(f\)? Apply \(U_f\) twice in succession: because the first register still holds \(x\) after the first step, the second application computes the same bit \(f(x)\) and adds it modulo two a second time,

\[U_f\bigl(U_f(x,t)\bigr)=U_f\bigl(x,\,t\oplus f(x)\bigr)=\bigl(x,\,t\oplus f(x)\oplus f(x)\bigr)=(x,t),\]

since adding any bit to itself modulo two gives \(0\). The map \(U_f\) is therefore its own inverse, which proves that it is one-to-one and onto on all \((n+1)\)-bit strings. For the two-bit AND function \(f(x,y)=xy\), this reversible embedding is \((x,y,t)\mapsto(x,y,t\oplus xy)\), which swaps \(110\) with \(111\) and leaves the other six triples unchanged:

\((x,y,t)\)\((x,y,t\oplus xy)\)\((x,y,t)\)\((x,y,t\oplus xy)\)
\(000\)\(000\)\(001\)\(001\)
\(010\)\(010\)\(011\)\(011\)
\(100\)\(100\)\(101\)\(101\)
\(110\)\(111\)\(111\)\(110\)

Has the AND function itself suddenly become invertible? No: \(f(x,y)=xy\) is unchanged and still merges three input pairs into \(0\). What is invertible is the larger map \(U_f\) on the expanded state space that preserves \((x,y)\) alongside the target. Those retained input bits are not mere bookkeeping—they are the exact information required to make the transformation one-to-one, and the same reversible map \(U_f\) will serve as our standard model of a function oracle in quantum algorithms.

Preserve the input; update the targetConfigurations are written xt, here with f(0)=0 and f(1)=1. U_f flips the target exactly when f(x)=1, and applying it twice returns every configuration. 00 → 00; 01 → 01; 10 → 11; 11 → 10; 00 → 00; 01 → 01; 10 → 11; 11 → 10.Preserve the input; update the targetU_fU_f000110110001101100011011
Configurations are written \(xt\), here with \(f(0)=0\) and \(f(1)=1\). \(U_f\) flips the target exactly when \(f(x)=1\), and applying it twice returns every configuration.
Problems
  1. Write the outputs of \(U_f:(x,y,t)\mapsto(x,y,t\oplus(x\lor y))\) for the four inputs with \(t=0\).

    Show solutionHide solution

    \(000\to000\), \(010\to011\), \(100\to101\), and \(110\to111\): the target receives the OR of the inputs.

  2. For OR, apply \(U_f\) to \((1,0,1)\), then apply it again. A programmer expected the target to contain \(f(1,0)=1\) after the first call. What assumption did they overlook?

    Show solutionHide solution

    The first call gives \((1,0,0)\), since \(1\oplus1=0\). The second gives \((1,0,1)\), restoring the input. The oracle adds the function value modulo two to the existing target; it does not overwrite that target. To read \(f(x)\) directly from the target, initialize it to \(0\).

  3. For a function \(f\) from \(n\)-bit strings to \(m\)-bit strings, define \(U_f(x,t)=(x,t\oplus f(x))\), where \(t\) has \(m\) bits and \(\oplus\) acts bit by bit. Prove that \(U_f\) is its own inverse for every \(f\).

    Show solutionHide solution

    \(U_f(U_f(x,t))=U_f(x,t\oplus f(x))=(x,t\oplus f(x)\oplus f(x))=(x,t)\), because each bit of \(f(x)\) added twice modulo two gives \(0\). So \(U_f\) undoes itself. In particular it is one-to-one, whatever \(f\) is.

2.4

Reversible Gates

Knowing that every Boolean function \(f\) can be embedded into a reversible transformation \(U_f:(x,t)\mapsto(x,\,t\oplus f(x))\) tells us what an overall circuit must achieve, but we still need elementary reversible gates to build that transformation step by step. In this section, we introduce the design principle of controlled reversible operations, show that three-bit Toffoli or Fredkin gates suffice to simulate any Boolean circuit reversibly, and learn how to clean up the temporary intermediate values that a multi-step reversible calculation leaves behind.

2.4.1 Controlled reversible operations§

controltargetCNOT

How can an elementary gate make one bit’s update depend on another bit without losing any information? The general principle is to keep the deciding bit unchanged while letting its value select which reversible operation is applied to the other bit. The preserved wire is called the control, and the updated wire is called the target.

On a single target bit, there are only two reversible operations: doing nothing (the identity) and flipping the bit (NOT). Doing nothing when the control \(a\) is \(0\) and flipping the target \(b\) when the control \(a\) is \(1\) defines the controlled-NOT gate, or CNOT:

\[\operatorname{CNOT}:(a,b)\mapsto(a,\,b\oplus a).\]

When the control is \(0\), the target is untouched (\(00\to00\) and \(01\to01\)); when the control is \(1\), the target flips (\(10\to11\) and \(11\to10\)). Notice in particular that when the target is initialized to \(b=0\), CNOT maps \((a,0)\mapsto(a,a)\): this is how a reversible circuit copies a bit (fan-out), using a CNOT gate and a fresh target wire initialized to \(0\).

Applying CNOT twice in succession restores both bits, \((a,\,b\oplus a\oplus a)=(a,b)\), so CNOT is its own inverse. Why does this controlled construction guarantee reversibility in general? Because the control bit \(c\) survives the gate unchanged, we still know after the gate has acted which reversible operation \(g_c\) was applied to the target, and we can simply apply its inverse \(g_c^{-1}\) to undo the step.

Would the gate remain reversible if we applied a reversible update to the target but discarded the control—or kept the control but used an irreversible reset on the target when \(c=1\)? Neither works: without the control bit we would not know whether to flip the target back, and if the conditional action reset the target to \(0\), the inputs \((1,0)\) and \((1,1)\) would both collapse to \((1,0)\). Both a preserved control and a reversible target update for each control value are required.

A controlled operation has two branchesCNOT keeps the control, the first bit, and flips the target when the control is 1: 10 and 11 exchange. Exactly one arrow enters each configuration, so the step can be undone. 00 → 00; 01 → 01; 10 → 11; 11 → 10.A controlled operation has two branchesCNOT0001101100011011
CNOT keeps the control, the first bit, and flips the target when the control is \(1\): \(10\) and \(11\) exchange. Exactly one arrow enters each configuration, so the step can be undone.
Problems
  1. Apply CNOT with the second bit as control and the first as target to \(00\), \(01\), \(10\), and \(11\).

    Show solutionHide solution

    The map is \((a,b)\mapsto(a\oplus b,b)\): \(00\to00\), \(01\to11\), \(10\to10\), and \(11\to01\).

  2. Apply three CNOT gates in turn to \((a,b)\): control the first bit and target the second, then control the second and target the first, then control the first and target the second. Show that the result is \((b,a)\).

    Show solutionHide solution

    \((a,b)\to(a,\,a\oplus b)\to\bigl(a\oplus(a\oplus b),\,a\oplus b\bigr)=(b,\,a\oplus b)\to\bigl(b,\,b\oplus a\oplus b\bigr)=(b,a)\). Three CNOT gates swap two bits.

  3. A controlled operation keeps a control bit \(c\) and applies a map \(g_c\) to the target. Prove that it is reversible when \(g_0\) and \(g_1\) are both reversible, and give its inverse. Show by an example that it is not reversible if \(g_1\) is a reset.

    Show solutionHide solution

    The inverse keeps \(c\) and applies \(g_c^{-1}\) to the target: since \(c\) is unchanged, it knows which map to undo. If \(g_1\) resets the target to \(0\), the inputs \((1,0)\) and \((1,1)\) both go to \((1,0)\), so the controlled operation is not one-to-one.

2.4.2 CNOT, Toffoli, and Fredkin gates§

ToffoliFredkin

Can we build every reversible Boolean circuit using only NOT and CNOT gates? No: NOT only adds \(1\) modulo two and CNOT only adds one wire’s value to another modulo two, so any circuit built solely from NOT and CNOT gates produces only linear combinations of the input bits modulo two. In particular, such circuits can never form the degree-two product \(ab\) needed for logical AND. To obtain a reversible multiplication gate, we give the target bit two controls instead of one, defining the three-bit Toffoli (or controlled-controlled-NOT) gate:

\[\operatorname{Toffoli}(a,b,c)=(a,b,c\oplus ab).\]

The Toffoli gate flips its target bit \(c\) only when both controls \(a\) and \(b\) equal \(1\), exchanging \(110\leftrightarrow 111\) and leaving the other six three-bit inputs unchanged. With \(c=0\), the target becomes \(ab\) while both inputs survive. Fixing one control to \(1\) reduces the Toffoli gate to CNOT, and fixing both controls to \(1\) reduces it to NOT. Can Toffoli gates simulate every classical Boolean circuit? Setting the target to \(c=1\) yields \(1\oplus ab=\operatorname{NAND}(a,b)\), and we already know from Section 2.2.2 that NAND alone builds every Boolean function. Any wire that needs to branch to multiple gates can be copied onto a fresh \(0\) wire with CNOT. Thus, replacing each NAND gate in a classical circuit with a Toffoli gate targeting a fresh wire initialized to \(1\) makes any circuit reversible, keeping all inputs and intermediate results in clean workspace. As before, this construction proves universality—that a reversible circuit always exists—without claiming that the naive translation is the most economical.

An alternative three-bit universal gate is the controlled-swap, or Fredkin gate, which keeps its control bit \(a\) intact and swaps its two targets \(b\) and \(c\) whenever \(a=1\). Applied to \((a,b,0)\), its third wire becomes \(ab\); applied to \((a,1,0)\), its target wires become \((\neg a,a)\), providing both NOT and a copy of \(a\). With constant \(0\) and \(1\) wires and clean workspace, Fredkin gates are likewise universal for reversible computation.

In circuit diagrams, time runs from left to right along horizontal wires: a filled dot marks a control that triggers on \(1\), a circled plus (\(\oplus\)) marks an XOR target, a pair of crosses (\(\times\)) marks two swapped targets, and a vertical line connects the wires acted on by a single gate. Both the Toffoli gate and the Fredkin gate are their own inverses.

Controlled reversible gatesCNOT has one control and an XOR target. Toffoli has two controls. Fredkin has a control and two swap targets.CNOTabToffoliabcFredkinabcFilled dot: control = 1. Circled plus: XOR target. Crosses: swap.
CNOT, Toffoli, and Fredkin preserve their full inputs in reversible form. Each drawing shows one gate, with time running left to right.
Problems
  1. Apply the Toffoli gate to all eight inputs \((a,b,c)\). Which inputs change?

    Show solutionHide solution

    Only those with \(a=b=1\): \(110\to111\) and \(111\to110\). The other six are unchanged.

  2. Using Toffoli gates and extra bits set to fixed values, compute \(a\land b\), \(\neg a\), and \(a\oplus b\). Specify the inputs of each gate.

    Show solutionHide solution

    \(a\land b\): Toffoli with controls \(a,b\) and a target set to \(0\). \(\neg a\): controls set to \(1,1\) and target \(a\), giving \(a\oplus1\). \(a\oplus b\): controls \(1\) and \(a\) with target \(b\), giving \(b\oplus a\).

  3. Prove that every output bit of a circuit of CNOT and NOT gates is a sum modulo two of input bits, possibly plus \(1\). Conclude that such circuits cannot compute \(a\land b\).

    Show solutionHide solution

    Each input bit has this form. NOT adds \(1\), and CNOT replaces the target by the sum of target and control; both keep the form, so by induction along the circuit every bit has it. If \(a\land b=c_0+c_1a+c_2b\) modulo two, the input \(00\) gives \(c_0=0\), the input \(10\) gives \(c_1=0\), and \(01\) gives \(c_2=0\), but then \(11\) gives \(0\neq1\).

2.4.3 Workspace and uncomputation§

workspaceuncomputationgarbage

Toffoli gates allow us to evaluate any Boolean circuit reversibly, but a multi-step calculation inevitably writes intermediate values into temporary wires along the way. What becomes of those temporary bits once we have the final answer? Suppose we want to compute the three-bit AND \(xyz\) using Toffoli gates and two extra bits initialized to \(0\): a temporary workspace bit \(w\) and an output bit \(t\). The first Toffoli gate uses controls \(x,y\) to write \(w=xy\); the second uses controls \(w,z\) to write \(t=wz=xyz\):

\[(x,y,z,0,0)\to(x,y,z,xy,0)\to(x,y,z,xy,xyz).\]

The desired answer \(xyz\) now sits in \(t\), but the workspace bit \(w\) still holds the intermediate product \(xy\). How should we handle \(w\)? Resetting \(w\) unconditionally to \(0\) would erase unknown information and incur the Landauer heat cost. Leaving \(w\) untouched avoids erasure, but clutters the workspace with a permanent record of the computation’s history—and in a long calculation, every gate would consume another fresh workspace bit.

Reversibility provides a clean third option: apply the first Toffoli gate (with controls \(x,y\) and target \(w\)) a second time. Because \(x\) and \(y\) are still intact and the Toffoli gate is its own inverse, this step adds \(xy\) modulo two into \(w\) once more, returning \(w\) to \(xy\oplus xy=0\) without disturbing the answer in \(t\):

\[(x,y,z,xy,xyz)\to(x,y,z,0,xyz).\]

Clearing temporary registers by running intermediate steps backward is called uncomputation. In general, a forward reversible circuit \(A\) starting from \((x,0,0)\) produces the desired answer \(f(x)\) alongside intermediate workspace values \(g(x)\), often called garbage. By adjoining a fresh output register initialized to \(0\), copying \(f(x)\) into it with CNOT gates, and then running the inverse circuit \(A^{-1}\) (applying the gates of \(A\) in reverse order), we restore every workspace wire to \(0\):

\[(x,0,0;0)\to(x,f(x),g(x);0)\to(x,f(x),g(x);f(x))\to(x,0,0;f(x)).\]

At the end, only the input \(x\) and the copied answer \(f(x)\) remain, while the workspace is clean and ready for reuse. Why go to this trouble? Classically, uncomputation recycles memory and avoids the thermodynamic cost of erasure, since removing a redundant copy \(g(x)\) while \(x\) is still present is a one-to-one permutation rather than a many-to-one reset. Quantum computation adds an even deeper reason: if input-dependent garbage \(g(x)\) is left behind in the workspace, it acts as a record of the computation’s history that prevents the quantum interference on which quantum algorithms depend.

Compute, copy a basis label, and uncomputeA computes an answer in workspace. CNOT records the answer in a clean output. A dagger restores the workspace.x00AA†x0f(x)computecopy labeluncompute
Compute the answer, copy its value to a fresh output, then apply the inverse computation. \(A\) may act on a larger workspace than the two schematic wires shown.

Interactive figure. This circuit converter translates irreversible NAND gates into reversible Toffoli gates with initialized ancilla wires. Step forward through the computation, copy the output, and run the Toffoli stages in reverse to observe workspace uncomputation.

From NAND gates to Toffoli gates

With scripting enabled, this figure converts a NAND circuit gate by gate into Toffoli gates: each \(\operatorname{NAND}(a,b)\) becomes \(\operatorname{Toffoli}(a,b,1)=(a,b,1\oplus ab)\).

Each NAND gate becomes a Toffoli gate whose target starts at \(1\), because \(1\oplus ab=\operatorname{NAND}(a,b)\). Thick teal wires carry \(1\) and thin grey wires carry \(0\). The example circuit is the four-gate XOR built earlier from NAND gates. After the conversion, a CNOT copies the answer and the Toffoli gates run in reverse: this is the uncomputation described above, applied to every intermediate result.
What to observe

Each NAND gate uses a fresh target wire initialized to \(1\). Running the Toffoli stage in reverse after copying the result restores every workspace ancilla to \(1\), leaving only the original inputs and the target answer.

Problems
  1. In the three-bit AND computation with workspace \(w\) and output \(t\), list the five bits \((x,y,z,w,t)\) after each of the three Toffoli gates for the input \((1,1,0)\).

    Show solutionHide solution

    \((1,1,0,0,0)\to(1,1,0,1,0)\to(1,1,0,1,0)\to(1,1,0,0,0)\). The second gate does nothing because \(z=0\), so \(t=0=1\land1\land0\), and the third gate resets \(w\).

  2. Compute the AND of four bits \(x,y,z,u\) with Toffoli gates, two workspace bits that start at \(0\), and one output bit, and return the workspace to \(0\). List the gates in order.

    Show solutionHide solution

    1. Controls \(x,y\), target \(w_1\): \(w_1=xy\). 2. Controls \(w_1,z\), target \(w_2\): \(w_2=xyz\). 3. Controls \(w_2,u\), target \(t\): \(t=xyzu\). 4. Repeat gate 2, resetting \(w_2\). 5. Repeat gate 1, resetting \(w_1\). The uncomputation runs in reverse order, because gate 2 needs \(w_1\) to still hold \(xy\).

  3. A reversible computation \(A\) maps \((x,0,0)\) to \((x,f(x),g(x))\). Show that applying \(A\), then copying the answer register into a fresh register with CNOT gates, then applying \(A^{-1}\), produces \((x,0,0;f(x))\) for every input \(x\).

    Show solutionHide solution

    \(A\) gives \((x,f(x),g(x);0)\). The CNOT gates add \(f(x)\) into the fresh register, giving \((x,f(x),g(x);f(x))\) and leaving the first three registers unchanged. \(A^{-1}\) acts only on those three; since \(A(x,0,0)=(x,f(x),g(x))\), it returns them to \((x,0,0)\). The result is \((x,0,0;f(x))\).

Summary

Questions and worked problems

Attempt each question before opening a hint. Explain your reasoning, then compare it with the solution.

1. Quick check §

Is the map \((x,y)\mapsto(x\lor y,\;x\land y)\) reversible?

Hint 1

List the four outputs.

Hint 2

Look for two inputs with the same output.

Worked solution

No. The inputs \(01\) and \(10\) both give \((1,0)\). Two output bits are not enough when the map merges inputs.

Revisit the relevant explanation

2. Quick check §

Write the binary-field polynomial of each function and check it on all four inputs: (a) \(\operatorname{NAND}(x,y)\); (b) the “equal” function, which is \(1\) exactly when \(x=y\).

Hint 1

NAND is the negation of \(xy\), and negation adds \(1\).

Hint 2

“Equal” is the negation of XOR, which is \(x+y\).

Worked solution

(a) \(\operatorname{NAND}(x,y)=1+xy\). On \(00,01,10\) the product is \(0\), giving \(1\); on \(11\) it gives \(1+1=0\). (b) “Equal” is \(1+x+y\): on \(00\) it is \(1\), on \(01\) and \(10\) it is \(1+1=0\), and on \(11\) it is \(1+1+1=1\). Both agree with the truth tables. Negating a function always means adding \(1\) modulo two, because \(1+0=1\) and \(1+1=0\).

Revisit the relevant explanation

3. Quick check §

Classical circuits copy bits freely by fan-out. Show that a CNOT whose target starts at \(0\) copies its control bit, and that the copying map \((a,0)\mapsto(a,a)\) is part of a reversible map. What does a Toffoli gate do to \((a,1,0)\)?

Hint 1

CNOT sends \((a,b)\) to \((a,b\oplus a)\).

Hint 2

With one control fixed to \(1\), a Toffoli gate acts like a CNOT.

Worked solution

CNOT gives \((a,0)\mapsto(a,0\oplus a)=(a,a)\): the target becomes a copy of the control. The full map \((a,b)\mapsto(a,b\oplus a)\) is reversible, since applying it twice restores both bits. Copying a bit is therefore reversible, provided the copy is written into a bit known to be \(0\). A Toffoli gate on \((a,1,0)\) gives \((a,1,0\oplus a\cdot1)=(a,1,a)\), another copy. Reversible fan-out costs a gate and a fresh bit, rather than being free. In quantum computation the same gate copies basis values, but it will not copy an unknown superposition, a distinction Chapter 6 develops.

Revisit the relevant explanation

4. Worked problem §

Compute the three-bit majority function reversibly: using three Toffoli gates, turn \((x,y,z,t)\) into \((x,y,z,\,t\oplus\mathrm{maj}(x,y,z))\). Check the construction on the inputs \(110\) and \(100\) with \(t=0\).

Hint 1

Majority is \(xy+yz+xz\) modulo two.

Hint 2

Each Toffoli gate adds one product to the target.

Worked solution

Apply Toffoli gates with controls \((x,y)\), \((y,z)\), and \((x,z)\), each targeting \(t\). Together they add \(xy\oplus yz\oplus xz\), the polynomial of majority. On \(110\): \(1\oplus0\oplus0=1\). On \(100\): \(0\oplus0\oplus0=0\). The inputs are kept, so the map is reversible; it is its own inverse.

Revisit the relevant explanation

5. Worked problem §

Find the binary-field polynomial of the three-bit function that is \(1\) exactly when exactly two of its inputs are \(1\). Build it from detectors, simplify, and check it on \(111\), \(110\), and \(100\). Compare it with the majority polynomial \(xy+yz+xz\).

Hint 1

The rows with output \(1\) are \(011\), \(101\), and \(110\).

Hint 2

Expand each detector, such as \((1+x)yz=yz+xyz\), and collect terms modulo two.

Worked solution

The detectors are \((1+x)yz=yz+xyz\), \(x(1+y)z=xz+xyz\), and \(xy(1+z)=xy+xyz\). Their sum is \(xy+yz+xz+3xyz=xy+yz+xz+xyz\) modulo two. On \(111\): \(1+1+1+1=0\), correct because three ones is not exactly two. On \(110\): \(1+0+0+0=1\), correct. On \(100\): all terms vanish, correct. The function differs from majority only on \(111\), where majority is \(1\), and the polynomials differ by exactly the term \(xyz\), the detector-like term that is \(1\) only on \(111\).

Revisit the relevant explanation

6. Worked problem §

Convert the four-NAND XOR circuit of Section 2.2.2 into a reversible computation that leaves only the inputs and the answer. (a) How many Toffoli gates, CNOT gates, and extra bits does the compute–copy–uncompute construction use? (b) Trace every wire for \(a=1\), \(b=0\), and confirm that the workspace returns to its starting values.

Hint 1

Each NAND becomes a Toffoli gate whose target starts at \(1\).

Hint 2

\(t=\operatorname{NAND}(a,b)\), \(u=\operatorname{NAND}(a,t)\), \(v=\operatorname{NAND}(b,t)\), output \(=\operatorname{NAND}(u,v)\).

Worked solution

(a) Four Toffoli gates compute \(t,u,v\) and the XOR value into four bits that start at \(1\). One CNOT copies the answer into a fresh bit that starts at \(0\). Four more Toffoli gates, in reverse order, uncompute. That is eight Toffoli gates, one CNOT, and five extra bits. (b) For \(a=1,b=0\): \(t=\operatorname{NAND}(1,0)=1\), \(u=\operatorname{NAND}(1,1)=0\), \(v=\operatorname{NAND}(0,1)=1\), and the answer bit is \(\operatorname{NAND}(0,1)=1=1\oplus0\). The CNOT copies \(1\) into the fresh bit. Running the Toffoli gates backward restores the answer bit to \(1\), then \(v=1\oplus(0\cdot1)=1\), \(u=0\oplus(1\cdot1)=1\), and \(t=1\oplus(1\cdot0)=1\). All four workspace bits are back at \(1\), and only the inputs and the copied answer \(1\) remain.

Revisit the relevant explanation

7. Worked problem §

A half adder adds two bits, producing a sum bit \(a\oplus b\) and a carry bit \(ab\). Build the reversible map \((a,b,0)\mapsto(a,\;a\oplus b,\;ab)\) from one Toffoli gate and one CNOT. Show that the order of the two gates matters by computing what the other order produces.

Hint 1

The Toffoli gate needs the original \(b\) as a control.

Hint 2

If the CNOT acts first, the second bit holds \(a\oplus b\) when the Toffoli gate reads it.

Worked solution

Apply the Toffoli gate with controls \(a,b\) and target the third bit: \((a,b,0)\to(a,b,ab)\). Then a CNOT from \(a\) to the second bit: \((a,b,ab)\to(a,a\oplus b,ab)\). Check: \(00\to(0,0,0)\), \(01\to(0,1,0)\), \(10\to(1,1,0)\), \(11\to(1,0,1)\), giving sum and carry correctly. In the other order, the CNOT first makes the second bit \(a\oplus b\), and the Toffoli gate then writes \(a(a\oplus b)=a(1+b)=a\land\lnot b\) into the third bit. On input \(11\) that gives carry \(0\), which is wrong. A reversible gate reads its controls at the moment it acts, so the order of gates is part of the circuit’s meaning.

Revisit the relevant explanation

8. Misconception §

A student says: “Uncomputation is just a roundabout way of erasing the workspace, so it must cost at least \(k_{\mathrm B}T\ln2\) per cleared bit.” In the three-bit AND example, explain why returning \(w=xy\) to \(0\) by a second Toffoli gate is not an erasure in Landauer’s sense, and what makes the difference.

Hint 1

An erasure merges distinct states. Does the second Toffoli gate merge any two complete states?

Hint 2

While \(x\) and \(y\) are still present, is \(w\) uncertain?

Worked solution

Landauer’s bound concerns maps that merge distinct states, such as a reset that sends both \(w=0\) and \(w=1\) to \(0\) without keeping the value elsewhere. The second Toffoli gate maps \((x,y,z,xy,xyz)\) to \((x,y,z,0,xyz)\), and as a map on all five bits it is one-to-one: it is its own inverse. It can clear \(w\) only because \(w\) is not independent information: it equals \(xy\), and \(x\) and \(y\) are still present. Uncomputation removes a redundant copy by undoing the step that made it, so nothing is lost. A reset would destroy the value of \(w\) even if \(x\) and \(y\) had already been discarded.

Revisit the relevant explanation

9. Extension §

Build the reversible embedding of OR, \((x,y,t)\mapsto(x,y,t\oplus(x\lor y))\), from CNOT and Toffoli gates, and show that the circuit is its own inverse.

Hint 1

\(x\lor y=x\oplus y\oplus xy\).

Hint 2

Each gate adds something to \(t\) and leaves \(x,y\) unchanged.

Worked solution

CNOT from \(x\) to \(t\), CNOT from \(y\) to \(t\), and Toffoli from \((x,y)\) to \(t\) add \(x\oplus y\oplus xy=x\lor y\) to \(t\). Since none of the gates changes \(x\) or \(y\), running the circuit twice adds \(x\lor y\) twice, which cancels. The circuit is its own inverse, and with \(t=0\) it leaves the answer in \(t\).

Revisit the relevant explanation

10. Extension §

A classical processor runs a computation \(10^9\) times per second, and each run leaves \(1000\) bits of intermediate values that are reset rather than uncomputed. (a) Using \(k_{\mathrm B}T\ln2\approx2.9\times10^{-21}\) J at \(300\) K, find the minimum power Landauer’s principle requires for these resets. (b) Compare it with a typical \(50\) W processor. (c) If the energy cost is so small, why does this course insist on uncomputation?

Hint 1

Bits erased per second: \(10^9\times1000\).

Hint 2

Section 2.4.3 gives a reason that is not about energy.

Worked solution

(a) \(10^{12}\) bits per second times \(2.9\times10^{-21}\) J is about \(2.9\times10^{-9}\) W, roughly three nanowatts. (b) That is about \(10^{10}\) times smaller than \(50\) W. Present-day processors dissipate far more than the Landauer bound for reasons unrelated to logical erasure: resistance, charging wires, and switching speed. (c) The reason for uncomputation here is not energy. In quantum computation, leftover intermediate values are records of the computation’s history, and such records prevent the interference that quantum algorithms rely on. Uncomputation is required for the computation to work at all, whatever it costs in heat.

Revisit the relevant explanation

Where this leads. Chapter 3 compares deterministic, nondeterministic, probabilistic, and quantum transitions on one example, and shows how quantum amplitudes make retained path information important.

Search this book

Search all chapters and appendices.