Education / Quantum Computing

Quantum Computing · Chapter 01

Logic and Computability

Presentation slides 25 slides · Fullscreen presentation or print to PDF

Quantum computing proposes a new model of computation. When the idea of computation was being developed, it was necessary to define it purely as a sequence of logical operations. As computation is done by a physical device, this process has to be physical. Since quantum mechanics describes all physical processes, computation becomes quantum mechanical. How, then, does this differ from our usual notion of computing devices? To understand this, this chapter builds the necessary ideas leading up to a quantum model of computation.

We first define what computation is and describe the various models of computation and their limits. We then introduce reversible computation, which paves the way for quantum computation.

Can mathematical reasoning be given foundations whose reliability can itself be established?

The notion of computability finds its origin in establishing the reliability of mathematical reasoning. The purpose of mathematics is to provide objective grounds for establishing truth through the following scheme: choose your domain and fix your axioms and rules of inference. Now, everything related to the domain must be settled by starting with the axioms and following the rules.

For example, fix your domain to be the set of integers. Your axioms are all the axioms about integers (known as Peano's axioms of arithmetic). Let's make the statement, "The sum of two even integers is even." Starting with \(2a\) and \(2b\), the axioms allow us to write \(2a + 2b = 2(a + b)\), which shows that the sum is even. So, we are able to settle this question. Can we settle all statements that one can frame about integers?

In this chapter · 4 sections · 11 topics
  1. 1.1 Formal Reasoning and Decision Problems
    Topics in this section
    1. 1.1.1 Axioms, inference rules, and proofs
    2. 1.1.2 Hilbert’s program and consistency
    3. 1.1.3 Proof checking, proof search, and decision
  2. 1.2 Models of Computation
    Topics in this section
    1. 1.2.1 Algorithms and termination
    2. 1.2.2 Configurations and transitions
    3. 1.2.3 Turing machines and universal computation
  3. 1.3 Computability and Its Limits
    Topics in this section
    1. 1.3.1 The Church–Turing thesis
    2. 1.3.2 The halting problem
    3. 1.3.3 Undecidability and incompleteness
  4. 1.4 From Computability to Reversibility
    Topics in this section
    1. 1.4.1 Deterministic and reversible transitions
    2. 1.4.2 Information loss in computation
Reading guide · preparation, aims, and assumptions

Define what a mechanical procedure can do before asking what changes in quantum computing.

Before you begin

No formal logic is assumed. Be comfortable following a short algebraic argument.

What you should be able to do

The example to follow

Follow Euclid’s algorithm: the answer is preserved even though distinct inputs can merge.

Scope and assumptions

The halting theorem concerns a general always-correct terminating procedure; it does not prevent analyzing individual programs.

1.1

Formal Reasoning and Decision Problems

To answer this, we must first say exactly what a proof is. Making the rules explicit then raises two questions: whether the rules themselves can be trusted, and whether following them could be left to a mechanical procedure. The second turns the question we started with into a question about procedures.

1.1.1 Axioms, inference rules, and proofs§

axiomrules of inference

A proof separates two distinct tasks: choosing starting assumptions and drawing valid consequences from them. The assumptions are axioms; the permitted deduction steps are rules of inference. For instance, given the statement \(P\) and the rule “\(P\) implies \(Q\),” we are permitted to infer \(Q\).

Coming up with a proof requires creative exploration: you have to navigate an enormous space of possibilities, try intermediate ideas, and find a path that connects your assumptions to the target claim. Checking an existing proof, by contrast, requires no guesswork at all. You simply inspect each statement in order, confirming that it is either an accepted axiom or the result of applying an allowed rule to earlier lines.

This is the foundational bridge to computation. Once proofs are expressed in precise notation, verifying them requires no human intuition—a proof is simply a finite object that an algorithm can inspect symbol by symbol. The checker’s job is strictly mechanical: it verifies that the conclusion follows from the chosen axioms, leaving the question of whether those axioms accurately describe reality for another day.

Interactive figure. This proof checker steps line by line through a formal derivation from stated axioms. Generate a candidate proof and run the checker to see how it verifies each line by matching earlier formulas against modus ponens.

A proof as a network of justified steps

A proof is a network of justified stepsStatements P and P implies Q lead by modus ponens to Q. Q and Q implies R lead to R. Each edge records a dependency, not a passage of time.A proof is a network of justified stepsPP implies Qmodus ponensQQ implies RR
Each arrow shows a dependency between proof steps. In the example, the same inference rule first gives \(Q\) from \(P\), then \(R\) from \(Q\). A new random proof uses only modus ponens, starting from randomly chosen axioms. The numbered list is the same proof written as a sequence, which a checker reads line by line.
What to observe

Only axiom lines are accepted outright. For every subsequent line, the checker locates two earlier lines of the form \(X\) and \(X\Rightarrow Y\) and verifies symbol by symbol that the new line is \(Y\).

Problems
  1. From the axioms \(P\), “\(P\) implies \(Q\),” and “\(Q\) implies \(R\),” with modus ponens as the only rule of inference, write a proof of \(R\). Give the justification of each line.

    Show solutionHide solution

    1. \(P\) (axiom). 2. \(P\) implies \(Q\) (axiom). 3. \(Q\) (modus ponens, lines 1 and 2). 4. \(Q\) implies \(R\) (axiom). 5. \(R\) (modus ponens, lines 3 and 4). Each line is either an axiom or follows from earlier lines by the rule, so a checker can verify the proof line by line.

  2. Prove that the sum of an even integer and an odd integer is odd, giving the justification for each step.

    Show solutionHide solution

    Let the even integer be \(2a\) and the odd integer \(2b+1\), with \(a\) and \(b\) integers (definitions of even and odd). Then \(2a+(2b+1)=2(a+b)+1\) (associativity and the distributive law). Since \(a+b\) is an integer, \(2(a+b)+1\) has the form of an odd integer (definition of odd). Hence the sum is odd.

  3. A checker accepts every line of a proof. Show by an example that the conclusion can still be false, and say exactly what the accepted proof establishes.

    Show solutionHide solution

    Take the axiom “every integer is even.” Applying it to \(3\) gives the line “\(3\) is even,” which the checker accepts as an instance of the axiom. The conclusion is false because the axiom is false. An accepted proof establishes only that the conclusion follows from the axioms by the rules. Whether the axioms are true, or at least consistent, is a separate question that the checker does not settle.

1.1.2 Hilbert’s program and consistency§

consistentfinitary methods

Once we write down explicit rules, an algorithm can easily check whether an argument follows them. But this raises a deeper, more dangerous question: are the rules themselves trustworthy? Could a set of seemingly innocent axioms and deduction steps secretly allow us to prove both a statement and its exact opposite? A logical system that never generates such a contradiction is called consistent. Without consistency, mathematical reasoning collapses—if a system can prove both \(P\) and “not \(P\),” the rules allow you to derive literally any claim, true or false, rendering all proofs meaningless.

In the early twentieth century, David Hilbert set out to put all of mathematics on an unshakeable foundation. His strategy was radical: turn mathematics upon itself. While a mathematical theorem might speak about infinitely many numbers or vast geometric spaces, the written proof of that claim is always finite—just a concrete string of symbols on a page. Hilbert realized that proofs could therefore be studied as physical, mathematical objects in their own right. He proposed using safe, transparent reasoning about finite symbols—known as finitary methods—to prove that the formal rules could never lead to a contradiction.

This grand ambition—known as Hilbert’s program—separated mathematics into two levels: the formal deductions carried out inside the system, and the reasoning about those proofs from the outside. But securing the reliability of mathematical logic sparked an equally profound question about its automation: if proof checking is purely mechanical, can a procedure always determine whether a given statement has a proof at all? Answering that requires us to examine the critical gap between checking a proof and searching for one.

Hilbert’s program: proving consistencyInside the formal system, axioms and rules derive valid theorems like 2+2=4. A contradiction like 0=1 must be impossible. Hilbert’s program studies the rules from the outside to prove that the contradiction branch is permanently closed.Hilbert’s program: proving consistencyAxiomsStarting assumptionsdeductionValid Theorems(e.g. 2 + 2 = 4)✓ PermittedContradiction(e.g. 0 = 1)✗ Forbiddenguarantees this branch never occursHILBERT’S METAMATHEMATICS (OUTSIDE VIEW)Analyzes the rules as physical symbol moves to prove that “0 = 1” is impossible.
Axioms and deduction rules generate valid theorems (such as \(2 + 2 = 4\)), but must never produce a contradiction (such as \(0 = 1\)). Hilbert’s program stands outside the system, analyzing the finite rules of the game to mathematically guarantee that a contradiction is impossible.
Problems
  1. A system has the axioms \(P\) and “\(P\) implies not \(P\),” and the rule modus ponens. Is it consistent?

    Show solutionHide solution

    No. From \(P\) and “\(P\) implies not \(P\),” modus ponens gives “not \(P\).” The system proves both \(P\) and its negation.

  2. Suppose a system also has the rule “from \(A\) and not \(A\), infer any statement \(B\).” Show that if the system is inconsistent, it proves every statement.

    Show solutionHide solution

    Inconsistency means that the system proves some \(A\) and also not \(A\). Applying the rule to these two proofs gives a proof of any statement \(B\) we choose. An inconsistent system of this kind proves everything, so its theorems carry no information.

  3. Hilbert hoped to prove that systems are consistent. Show that a consistency proof carried out inside the same system \(S\) could not settle the doubt, by showing that an inconsistent \(S\) of the kind in the previous problem proves the statement “\(S\) is consistent.”

    Show solutionHide solution

    If \(S\) is inconsistent, it proves every statement it can express, including the statement “\(S\) is consistent.” So a proof of that statement within \(S\) is exactly what an inconsistent \(S\) would also produce, and it cannot by itself show that \(S\) is consistent. This is why Hilbert sought a consistency proof using only weaker, finitary reasoning that is easier to trust than the system being justified.

1.1.3 Proof checking, proof search, and decision§

proof searchdecision procedure

Imagine someone hands you a proposed proof for a mathematical statement \(P\). As we have seen, a computer can mechanically check each deduction line by line. If every step obeys the rules, the argument is accepted and \(P\) is proven. But what if the checker rejects the argument? A flaw in the proof only discredits that specific attempt—it does not mean \(P\) is false. Another, more subtle proof might easily succeed. Checking settles whether a supplied argument is valid, but it leaves open whether the statement itself is provable.

Now suppose you are given a statement \(P\) with no proof at all. Can a machine discover one from scratch? Because formal proofs are finite strings of symbols written in a fixed alphabet, a computer can systematically generate every conceivable text string, ordered by length: first strings of one symbol, then two, then three, and so on. Running our mechanical checker on each candidate in sequence creates an automatic proof search. If a valid proof of \(P\) exists, this exhaustive search is guaranteed to eventually construct it, confirm it, and halt with “yes.”

The trouble arises when a statement has no proof. Each rejected candidate merely rules out one string; it never proves that all future candidates will fail. Because there are infinitely many strings to test, the machine has no stopping condition—it simply loops forever, unable to distinguish between a proof that is just around the corner and a proof that does not exist. This reveals the critical distinction between searching and deciding. A true decision procedure for a decision problem cannot loop indefinitely: it must terminate in a finite number of steps on every input, delivering a definitive “yes” or “no.”

Could a more sophisticated method succeed where brute-force enumeration fails? Perhaps an algorithm could inspect the axioms and the target statement directly, bypassing exhaustive search altogether. The failure of one search strategy does not mean every strategy must fail. But to determine whether an all-powerful decision procedure is possible, we first need a rigorous, mathematical definition of what an “algorithm” actually is. That necessity brings us directly to the foundations of computation.

Problems
  1. Strings over the alphabet \(\{a,b\}\) are listed by length, starting with the empty string, and alphabetically within each length. Write the first seven strings, and give the position of \(ab\).

    Show solutionHide solution

    The list begins: the empty string, \(a\), \(b\), \(aa\), \(ab\), \(ba\), \(bb\). The string \(ab\) is fifth.

  2. A proof search lists candidate strings over a two-symbol alphabet in this order and checks each one. If the shortest proof of a statement has length \(5\), at most how many candidates are checked before a proof is found? Why can such a bound not be computed in advance for an arbitrary statement?

    Show solutionHide solution

    There are \(2^k\) strings of length \(k\), so the strings of length at most \(5\) number \(1+2+4+8+16+32=63\). The search finds a proof among the first \(63\) candidates. The bound needs the length of the shortest proof, which is unknown in advance, and if no proof exists the search never stops, so no bound applies at all.

  3. Suppose a theory is consistent, its axioms can be listed by an algorithm, and it is complete: for every sentence \(P\), it proves \(P\) or it proves not \(P\). Show that searching for a proof of \(P\) and a proof of not \(P\) in alternation is a decision procedure for provability.

    Show solutionHide solution

    Check candidates in turn, alternating between proofs of \(P\) and proofs of not \(P\). By completeness, one of them has a proof, so the search stops after finitely many steps. If it finds a proof of \(P\), then \(P\) is provable. If it finds a proof of not \(P\), then \(P\) is not provable, since by consistency the theory cannot prove both. The procedure always stops with the correct answer. The argument needs completeness, which fails for arithmetic by the incompleteness theorem.

1.2

Models of Computation

Whether an automatic procedure can decide mathematical truth depends entirely on what a “procedure” is allowed to do. To make that notion precise, we begin with an algorithm humanity has trusted for millennia—Euclid’s algorithm for finding greatest common divisors. By breaking Euclid’s process down, we will see that every computation is simply a sequence of transitions between snapshots called configurations. Stripping those steps down to their barest physical essentials brings us to the Turing machine: a model simple enough to analyze with absolute mathematical rigor, yet powerful enough that a single machine can simulate any computer ever built.

1.2.1 Algorithms and termination§

Euclid’s algorithminvariant

Consider a task we can easily carry out by hand: finding the greatest common divisor of \(48\) and \(18\). Euclid’s algorithm solves this by repeatedly replacing a pair of positive integers \((a, b)\) by the second number and the remainder on division:

\[(48,18)\longrightarrow(18,12)\longrightarrow(12,6)\longrightarrow(6,0).\]

Once the second number hits zero, the procedure returns \(6\). The arithmetic is straightforward, but whenever we claim to possess an algorithm, two fundamental questions demand proof: why is the final answer correct? and why must the procedure eventually stop?

The first question concerns correctness. When dividing \(a\) by \(b\), we write \(a = qb + r\), with \(0 \leq r < b\). Notice that any divisor that divides both \(a\) and \(b\) must also divide their remainder \(r = a - qb\). Conversely, any divisor that divides both \(b\) and \(r\) must also divide \(a = qb + r\). Replacing \((a, b)\) by \((b, r)\) therefore preserves their set of common divisors without losing or introducing any factors. The greatest common divisor is an invariant: it stays strictly constant across every step of the run. When the algorithm finally arrives at the pair \((g, 0)\), the greatest common divisor of \(g\) and \(0\) is trivially \(g\). Because the invariant was preserved at every step, \(g\) must be the true greatest common divisor of the starting pair.

The second question concerns termination. An invariant alone only guarantees that if the algorithm stops, the answer will be right—it does not prove the algorithm will ever finish. (For instance, an infinite loop that endlessly prints \((48, 18)\) preserves the invariant, but it never produces an answer.) Euclid’s algorithm is guaranteed to terminate because at each step, the second entry \(b\) is replaced by the remainder \(r\), and the remainder is strictly smaller than \(b\) while remaining non-negative (\(0 \leq r < b\)). A strictly decreasing sequence of non-negative integers cannot continue forever; it must eventually reach zero.

These are completely separate arguments. An algorithm requires both a reason to trust its result (correctness via an invariant) and a reason to expect that result in finite time (termination via a strictly decreasing metric).

Interactive figure. This table traces Euclid’s greatest-common-divisor algorithm step by step on a pair \((a,b)\). Run the division steps on \((48,18)\) and on the Fibonacci pair \((89,55)\) to observe the preserved divisor invariant and the rate of remainder descent.

Run Euclid’s algorithm

Euclid’s algorithm: what stays fixed, what decreasesThe pairs 48,18; 18,12; 12,6; and 6,0 all have greatest common divisor six, shown as a constant band. Bars below show the second entry falling from 18 to 12 to 6 to zero, the nonnegative measure that proves termination.Euclid’s algorithm: what stays fixed, what decreases(48, 18)(18, 12)(12, 6)(6, 0)invariant: gcd(a,b)=6 at every stepb = 18b = 12b = 6b = 0measure b (nonnegative)b = 0: stopPreservation gives correctness; decrease gives termination.
Each row is one configuration of the run. The greatest common divisor stays the same in every row, while the second entry, drawn as a bar, decreases through nonnegative integers until it is zero. These are separate reasons for correctness and termination. Try other entries, such as \(89\) and \(55\).
What to observe

From \((48,18)\), three remainder steps reach \((6,0)\) while keeping \(\gcd(a,b)=6\) invariant on every row. Consecutive Fibonacci inputs such as \((89,55)\) produce quotients of \(1\) at every step, yielding the slowest possible descent.

Problems
  1. Run Euclid’s algorithm on \((91,35)\), writing each division and each pair.

    Show solutionHide solution

    \(91=2\cdot35+21\), \(35=1\cdot21+14\), \(21=1\cdot14+7\), and \(14=2\cdot7+0\). The pairs are \((91,35)\to(35,21)\to(21,14)\to(14,7)\to(7,0)\), so the greatest common divisor is \(7\).

  2. Run Euclid’s algorithm on \((21,13)\). How many divisions does it take, and why does this pair make the second entry decrease slowly?

    Show solutionHide solution

    \(21=1\cdot13+8\), \(13=1\cdot8+5\), \(8=1\cdot5+3\), \(5=1\cdot3+2\), \(3=1\cdot2+1\), \(2=2\cdot1+0\): six divisions, and the greatest common divisor is \(1\). Every quotient but the last is \(1\), so each remainder is the difference of the two previous numbers, the smallest decrease possible. The entries run backward through the Fibonacci numbers \(21,13,8,5,3,2,1\).

  3. Give a procedure on pairs of positive integers that keeps the greatest common divisor unchanged at every step but never stops, and another that always stops but can return a wrong answer. What does this show about the two arguments for Euclid’s algorithm?

    Show solutionHide solution

    Replacing \((a,b)\) by \((b,a)\) keeps the greatest common divisor unchanged but never reduces anything, so it runs forever. Replacing \((a,b)\) by \((b,0)\) and returning \(b\) always stops, but from \((4,6)\) it returns \(6\), while the greatest common divisor is \(2\). Preserving the answer does not imply termination, and termination does not imply a correct answer. Euclid’s algorithm needs both arguments: the invariant and the decreasing second entry.

1.2.2 Configurations and transitions§

configurationtransitionrun

Imagine pausing a computation halfway through—for instance, freezing Euclid’s algorithm at the pair \((18, 12)\), just before the next division. What is the absolute minimum information you would need to record so that someone else could resume the work without missing a beat? You need the numbers currently held in memory, and you need to know which instruction to carry out next. You do not need the historical path that brought you there.

That complete, self-contained snapshot of a computational process is called its configuration. What belongs inside a configuration depends entirely on where the machine is allowed to pause. If we only pause between full division steps, recording the integer pair is sufficient because the next instruction is always fixed. But if we pause mid-division inside a physical processor, the pair alone is not enough: the configuration must also store intermediate registers, carry bits, and the current line of the instruction counter.

A single step that updates one configuration into the next is called a transition. Beginning from an initial input, the computation advances through a sequence of discrete configurations:

\[C_0 \longrightarrow C_1 \longrightarrow C_2 \longrightarrow \cdots \longrightarrow C_{\text{final}}.\]

This entire sequence is called a run. A deterministic algorithm supplies an unambiguous rulebook: given any valid configuration, the next transition is uniquely determined. When the run enters a designated stopping configuration, the computation halts and outputs its result.

Notice a subtle asymmetry: while a deterministic configuration uniquely determines where to go next, it does not necessarily reveal where you came from. In Euclid’s algorithm, both the starting pair \((48, 18)\) and the starting pair \((30, 18)\) step directly into \((18, 12)\). Looking at \((18, 12)\) alone, you cannot reconstruct which pair started the run. The forward step is deterministic, but it is not reversible. This distinction between forward execution and backward reversibility will prove fundamental when we examine information loss and the foundations of quantum computation.

Configurations contain what is needed to continueA configuration consists of stored data, control state, and position in the instructions. A transition produces the next complete configuration, and repeated transitions form a run.Configurations contain what is needed to continueConfiguration Cₜstored datacontrol state / next instructiontransitionConfiguration Cₜ₊₁updated dataupdated control positionA run: C₀→ C₁→ C₂→⋯ (until a halting condition is reached)
A configuration includes enough information to resume the computation. A transition updates that information; a run is a sequence of these updates.
Problems
  1. Euclid’s algorithm divides by repeated subtraction. It is paused in the middle of dividing \(48\) by \(18\), after one subtraction has given \(30\). What must the configuration record so that the computation can resume?

    Show solutionHide solution

    It must record the current value \(30\), the divisor \(18\), the number of subtractions made so far, \(1\), and the fact that the computation is in the middle of a division rather than at the start of a new step. The earlier pairs need not be recorded.

  2. Write the run of Euclid’s algorithm from \((30,18)\) as a sequence of configurations. Find two other pairs whose runs reach \((18,12)\) after one step.

    Show solutionHide solution

    The run is \((30,18)\to(18,12)\to(12,6)\to(6,0)\). Any pair \((18q+12,18)\) with \(q\geq0\) gives the remainder \(12\) on division by \(18\): for example \((48,18)\) and \((66,18)\), and also \((12,18)\), for which the quotient is \(0\).

  3. Describe all pairs from which Euclid’s algorithm reaches \((18,12)\) in one step. What does the answer imply about running the algorithm backward?

    Show solutionHide solution

    A step sends \((a,b)\) to \((b,r)\), so we need \(b=18\) and remainder \(r=12\) on dividing \(a\) by \(18\): \(a=18q+12\) for some integer \(q\geq0\). There are infinitely many such pairs, one for each \(q\). From \((18,12)\) alone we cannot recover the previous pair; we would also need the quotient \(q\), which the algorithm discards.

1.2.3 Turing machines and universal computation§

Turing machinetapeheadcontrol staterule tablehalting stateuniversal machine

In Euclid’s algorithm, an instruction such as “divide \(a\) by \(b\)” seems elementary, but it still hides significant complexity: division is itself a multi-step routine of subtractions, shifts, and comparisons. If we want to prove mathematical theorems about the limits of computation in general, we cannot rely on convenient, high-level commands. We must break computation down into its simplest, irreducible physical operations.

In 1936, Alan Turing formalized this idea with the theoretical model now known as a Turing machine. A Turing machine strips computing down to four basic components:

  • A tape divided into discrete cells extending as far as needed, each holding a single symbol from a finite alphabet (or a blank symbol \(\square\)).
  • A read/write head positioned over exactly one cell at any given moment.
  • A finite control state that keeps track of the machine’s internal status.
  • A fixed rule table (or transition function). For each combination of current control state and symbol read by the head, the table specifies three atomic actions: which symbol to write, which direction to move the head (one cell left or right), and which control state to enter next.

When the machine enters a designated halting state, it stops, leaving its final answer written on the tape. A configuration of a Turing machine is completely specified by the contents of its tape, the position of the head, and its current control state.

Turing’s most transformative breakthrough was recognizing that a rule table is itself finite data. Because it consists of a finite list of discrete rules, we can encode the entire machine as a single string of symbols on a tape. This means one machine can read the encoded description of any other machine, along with an input, and faithfully imitate its behavior step by step. A machine designed to carry out this simulation is called a universal machine.

The universal machine unifies hardware and software: code is simply data. A computer program can accept another program as input, simulate it, analyze it, or even process its own description. This power of self-reference is neither mystical nor paradoxical—it is simply a finite procedure inspecting a finite string of text. Yet, as we will see next, this exact self-referential capability reveals the ultimate boundaries of what algorithms can decide.

Interactive figure. This state-and-tape simulator executes a Turing machine one transition at a time. Select a problem, step the tape head through the state diagram, and compare single-pass acceptance on \(1^n\) with back-and-forth marking on palindromes.

A Turing machine at work

A Turing machine: tape, head, and finite controlA tape holds blanks and a finite block of ones. The head reads one cell. In state q, reading 1 leaves 1, moves right and remains in q; reading blank enters halt. A universal machine instead reads an encoded rule table and input and simulates it.A Turing machine: tape, head, and finite controlTape: no fixed bound on available cells…□111□…read / write headFinite control: qq, 1→ write 1; right; qq, □→ haltExample rule table (□ = blank)Universal simulationEncoded program Pand input xUniversal machineSimulates the stepsof P on x
The pointer marks the cell under the head; shaded cells have been visited. Below the tape is the machine’s finite control drawn as a state diagram. Circles are control states, a double circle is a halting state, and each arrow is one rule. An arrow labeled \(1\to1,\ R\) means: when reading 1, write 1, move right, and follow the arrow. □ is a blank; L, R, S mean left, right, and stay; “same” means the symbol read is written back unchanged. The highlighted arrow is the rule just used. New random problem builds another machine, such as a pattern search, a divisibility test, a palindrome or parenthesis checker, or a copier, with a fresh input. The line under the diagram writes the same rules as a string. A universal machine reads such a string together with an input and imitates these steps; it need not halt if the simulated run does not halt.
What to observe

At each step, the current state and scanned tape symbol select a single outgoing transition arrow. Reading \(n\) ones takes \(n+1\) steps, whereas marking symbols from both ends sweeps across the tape repeatedly and takes \(O(n^2)\) steps.

Problems
  1. A machine has a running state \(q\) and a halting state \(h\). In \(q\), reading \(1\), it writes \(1\), moves right, and stays in \(q\); reading a blank, it halts. Started on the leftmost \(1\) of a tape holding \(111\), list its configurations until it halts.

    Show solutionHide solution

    Number the cells \(1,2,3,\dots\). The configurations are: tape \(111\), head at cell \(1\), state \(q\); head at cell \(2\), state \(q\); head at cell \(3\), state \(q\); head at cell \(4\), which is blank, state \(q\); then the machine halts in state \(h\) with the head at cell \(4\). The tape never changes.

  2. Change the machine so that, reading a blank in state \(q\), it writes \(1\) and halts. What does the new machine compute on a block of \(n\) ones, and how many steps does it take?

    Show solutionHide solution

    It moves right over the \(n\) ones and writes a \(1\) in the first blank cell, so the block grows to \(n+1\) ones: in unary notation, it computes \(n+1\). It takes \(n\) moves and one final write, \(n+1\) steps in all.

  3. Design a machine that, started on the leftmost symbol of a block of ones, halts in a state marked “even” if the block has an even number of ones and “odd” otherwise. Give its rule table and trace it on \(111\).

    Show solutionHide solution

    Use two running states, \(E\) (an even number of ones read so far) and \(O\) (odd), starting in \(E\). In \(E\) reading \(1\): move right and enter \(O\). In \(O\) reading \(1\): move right and enter \(E\). In \(E\) reading a blank: halt in “even.” In \(O\) reading a blank: halt in “odd.” On \(111\) the states are \(E\to O\to E\to O\), and the blank is read in \(O\), so the machine halts in “odd.”

1.3

Computability and Its Limits

With the Turing machine in hand, we can finally confront the foundational question from Section 1.1: can an automatic procedure settle every mathematical problem? Before drawing sweeping conclusions from a single model, however, we must ask whether our model is too restrictive—could some other conceivable computing device calculate functions that a Turing machine cannot? The Church–Turing thesis explains why the answer is no: every reasonable model of mechanical calculation computes the exact same class of functions. Armed with that universality, we uncover a concrete question that no algorithm can ever decide—whether an arbitrary program halts—and trace its consequences directly back to logic, where undecidability and Gödel’s incompleteness theorems shatter Hilbert’s dream of a complete, self-justifying foundation for arithmetic.

1.3.1 The Church–Turing thesis§

lambda calculusChurch–Turing thesis

We have defined computation using a remarkably primitive device: a tape, a read/write head, and a finite rule table. Why should a limitation of this bare-bones machine tell us anything about the limits of calculation in general? Could a richer, more sophisticated mathematical model compute functions that a Turing machine cannot?

In the 1930s, several mathematicians independently proposed completely different formalisms for computation. Alonzo Church’s lambda calculus dispensed with tapes and state machines altogether, defining computation through rules for substituting and evaluating function expressions. Kurt Gödel and Stephen Kleene developed recursive functions, building calculations out of basic arithmetic operations and composition rules. Later decades added register machines, cellular automata, and modern programming languages.

Despite their radically different designs, every one of these formal models turns out to compute the exact same class of functions as Turing machines. Any calculation carried out in lambda calculus, recursive functions, or a modern programming language can be simulated step by step on a Turing machine, and vice versa. Because each of these models is a precisely defined mathematical system, their equivalence is not a philosophical opinion—it is a rigorous mathematical theorem proved by explicit simulation.

The Church–Turing thesis takes the crucial next step: it states that any calculation that can be carried out by an effective mechanical method can be carried out by a Turing machine. Notice why this is called a thesis rather than a theorem. While a Turing machine is a formally defined mathematical object, “effective mechanical method” is an informal, intuitive notion of what a step-by-step procedure can do. We cannot write a formal proof equating an informal intuition to a mathematical definition; instead, the proven equivalence of every formal model ever proposed provides overwhelming evidence that the Turing machine captures the full reach of mechanical calculation. Whenever we prove a theorem that no Turing machine can solve a given problem, the Church–Turing thesis tells us that no algorithm of any kind can solve it either.

Crucially, the Church–Turing thesis is a statement about computability—whether a function can be computed in finite time at all—not about efficiency, which asks how much time or memory the calculation requires. This distinction is vital for quantum computing. In the standard quantum model, the allowed physical operations have precise mathematical descriptions that a classical Turing machine can simulate in principle, albeit often at an astronomical cost in time and memory. Consequently, quantum computers do not violate the Church–Turing thesis: they cannot compute functions that are uncomputable by a Turing machine. Rather, their power lies in dramatically reducing the computational resources needed for certain problems that are already computable—a difference we will explore when we turn to quantum algorithms.

Formal model equivalence and the Church–Turing thesisTuring machines, lambda calculus, and recursive functions compute the same class of functions. Their formal equivalence is proved. Identifying this class with every effective mechanical procedure is the Church–Turing thesis.Formal model equivalence and the Church–Turing thesisTuring machinesLambda calculusRecursive functionsSame computable functions: equivalence of formal modelsInformal notion of an effective procedureChurch–Turing thesisEquivalence concerns computability, not equal running time.
The solid arrows connect formal models that can simulate one another. They compute the same functions, though they may take different amounts of time. The dashed arrow marks the further claim of the Church–Turing thesis: these models capture what we mean informally by an effective method.
Problems
  1. A programming language \(L\) can simulate every Turing machine, and a Turing machine can simulate every program of \(L\). Which functions does \(L\) compute? Is this conclusion a theorem or an instance of the Church–Turing thesis?

    Show solutionHide solution

    Exactly the Turing-computable functions. Both simulations are mathematical constructions between two precisely defined models, so the conclusion is a theorem. The thesis is not needed.

  2. Classify each statement as a theorem or as the Church–Turing thesis: (a) lambda calculus and Turing machines compute the same functions; (b) every function computable by an effective mechanical method is Turing-computable; (c) every recursive function is Turing-computable.

    Show solutionHide solution

    (a) and (c) are theorems: they compare precisely defined models. (b) is the thesis: “effective mechanical method” is an informal idea, so the statement cannot be proved as a theorem about defined objects.

  3. Show that some functions from nonnegative integers to \(\{0,1\}\) are computed by no Turing machine. Turing machines can be listed as \(M_0,M_1,M_2,\dots\), since each has a finite description.

    Show solutionHide solution

    Define \(f(n)=1\) if \(M_n\), run on input \(n\), halts with output \(0\), and \(f(n)=0\) otherwise. For every \(n\), \(f(n)\) differs from the output of \(M_n\) on \(n\), or \(M_n\) fails to produce \(0\) or \(1\) there. So \(f\) is computed by no machine in the list, that is, by no Turing machine. By the Church–Turing thesis, no effective mechanical method computes it either.

1.3.2 The halting problem§

halting problem

Given a computer program and its input, can we always determine in advance whether the run will eventually stop or continue forever? For many specific programs, the answer is straightforward: in Section 1.2.1 we proved that Euclid’s algorithm always terminates by tracking a strictly decreasing nonnegative integer, and it is just as easy to spot a simple infinite loop. Simply running a program for a fixed number of steps—say, a million or a trillion—is not a general test, because if the program is still running when the timer expires, we only know that it has not halted yet, not whether it will halt on the very next step or loop forever. Can a cleverer algorithm inspect any program and input and always decide whether the computation halts?

Suppose, for the sake of contradiction, that such a universal halting decider exists. Call it \(H(P, x)\), where \(P\) is the text description of a program and \(x\) is its input. Because \(H\) is assumed to be a genuine decision procedure, it must terminate in a finite number of steps on every pair \((P, x)\), answering “halts” if \(P\) eventually stops on input \(x\) and “does not halt” if \(P\) runs forever on \(x\).

Because programs are simply finite strings of data (as we saw with the universal machine in Section 1.2.3), we can use \(H\) as a subroutine inside a new, adversarial program \(D\). The program \(D\) accepts a single string \(p\)—representing a program description—as its input and carries out two instructions:

  1. First, \(D\) runs \(H(p, p)\): it asks the decider what happens when the program described by \(p\) is given its own text description as input.
  2. Second, \(D\) deliberately does the exact opposite of \(H\)’s prediction. If \(H(p, p)\) answers “halts,” \(D\) intentionally enters an endless loop. If \(H(p, p)\) answers “does not halt,” \(D\) immediately halts. (If \(p\) is not a valid program description, \(D\) simply halts.)

Because \(D\) is built entirely out of explicit, mechanical operations, \(D\) is itself a valid program with its own finite text description, which we call \(d\). Now feed \(d\) as the input to \(D\), and ask: what does \(H(d, d)\) predict about the run \(D(d)\)?

Either answer destroys the decider. If \(H(d, d)\) answers “halts,” then \(D(d)\) receives that prediction, follows its second rule, and enters an infinite loop—so \(D(d)\) never halts, contradicting \(H\)’s answer. Conversely, if \(H(d, d)\) answers “does not halt,” then \(D(d)\) follows its second rule and immediately stops—so \(D(d)\) halts, again contradicting \(H\)’s answer. Since constructing \(D\) from \(H\) used only standard programming operations, the contradiction proves that our starting assumption is impossible: no general algorithm \(H\) can exist. This landmark theorem is the undecidability of the halting problem.

Keep the exact scope of this theorem in mind. It does not prevent us from proving that individual programs terminate—we already proved termination for Euclid’s algorithm—nor does it forbid automated verification tools that decide halting for broad families of well-structured programs while answering “unknown” on cases they cannot resolve. What is mathematically impossible is a single, universal algorithm that always terminates with a definite, correct yes-or-no verdict for every program and input.

The halting contradiction: run D on its own descriptionAssume H always halts and correctly predicts halting. Program D calls H(p,p) and does the opposite. With p equal to d, the description of D, either prediction about D(d) is contradicted by its prescribed behavior.The halting contradiction: run D on its own descriptionAssume H always halts and correctly predicts halting.PROGRAM D(p)Input pCall H(p,p)“halts”Loop forever“does not halt”HaltD follows fixed instructions: it opposes the prediction.Now set p=d, the description of D.H(d,d) predicts this very run; either answer is contradicted.
Assume \(H\) always finishes and predicts correctly. Program \(D\) follows its prediction and takes the opposite action. Now give \(D\) its own description \(d\). \(H(d,d)\) is predicting this very run, so either answer is contradicted by what \(D\) does.
Problems
  1. Decide, by inspecting each program, whether it halts on the input \(x=5\): (a) while \(x\gt 0\), set \(x:=x-1\); (b) while \(x\neq0\), set \(x:=x-2\); (c) repeat forever: do nothing.

    Show solutionHide solution

    (a) halts: \(x\) decreases to \(0\). (b) does not halt: \(x\) takes the values \(5,3,1,-1,\dots\) and never equals \(0\). (c) does not halt. Particular programs can often be decided by inspection; the halting theorem rules out one procedure that works for every program.

  2. A proposed halting test runs a program for a million steps. It answers “halts” if the program stops and “never halts” otherwise. Give a program on which this test is wrong. Would replacing a million by a larger fixed number repair it?

    Show solutionHide solution

    A program that counts down from \(1{,}000{,}001\), one decrement per step, and then stops will outlast the test. For any fixed cutoff \(B\), a countdown longer than \(B\) gives the same counterexample. A timeout shows only that the program has not halted yet; it does not prove that it never will.

  3. Show that no algorithm decides, for every program \(P\), whether \(P\) halts when given the input \(0\). Use the undecidability of the halting problem: from a pair \((P,x)\), construct a program that ignores its own input.

    Show solutionHide solution

    Given \((P,x)\), let \(P^\prime\) be the program that ignores its input and runs \(P\) on \(x\). Then \(P^\prime\) halts on \(0\) exactly when \(P\) halts on \(x\), and \(P^\prime\) can be written down from \(P\) and \(x\) by an algorithm. If some algorithm decided halting on input \(0\), applying it to \(P^\prime\) would decide whether \(P\) halts on \(x\), for every pair. That would solve the halting problem, which is impossible. So no such algorithm exists.

1.3.3 Undecidability and incompleteness§

undecidable problemincomplete theorysecond incompleteness theorem

We can now bring the computational limits of Section 1.3.2 directly back to the logical questions of Section 1.1. In doing so, we must distinguish two fundamental boundaries that apply to different kinds of objects. An undecidable problem is a limit on algorithms: it is a decision problem (such as the halting problem) for which no single procedure always terminates with the correct yes-or-no answer. An incomplete theory, by contrast, is a limit on proofs within a fixed axiom system: it is a formal theory in which some statement \(P\) can neither be proved nor refuted from the axioms—that is, neither \(P\) nor its negation \(\neg P\) has a formal proof.

Although undecidability concerns procedures and incompleteness concerns axiom systems, the two limits are deeply intertwined. Recall from Section 1.1.3 that if a consistent theory with mechanically listable axioms were complete—proving either \(P\) or \(\neg P\) for every statement \(P\)—we could build a decision procedure simply by enumerating candidate proofs until either a proof of \(P\) or a proof of \(\neg P\) appeared. Because the step-by-step execution of a Turing machine can be expressed as a statement about integers, a complete and consistent axiom system for arithmetic would allow us to decide whether any program halts! Since the halting problem is undecidable, no such axiom system can be complete.

More precisely, the Gödel–Rosser theorem (first proved by Kurt Gödel in 1931 and strengthened by J. Barkley Rosser in 1936) applies to any formal theory that is consistent, whose axioms can be effectively listed by an algorithm, and that is expressive enough to formulate basic arithmetic on the integers (such as Peano arithmetic). Any theory meeting these three conditions is necessarily incomplete: it contains an arithmetic sentence \(P\) for which neither \(P\) nor \(\neg P\) is provable.

Can we repair this gap simply by adding the undecided sentence \(P\) as a new axiom? Adding \(P\) settles \(P\) itself, of course—but as long as the enlarged axiom system remains consistent and mechanically listable, the Gödel–Rosser theorem applies all over again, producing a brand-new undecided sentence. Every hypothesis of the theorem is essential: simple logical theories that cannot express full arithmetic can be both consistent and complete, whereas an inconsistent theory trivially proves every sentence.

Finally, Gödel’s second incompleteness theorem delivers the verdict on Hilbert’s consistency program from Section 1.1.2. Under the same conditions, a consistent theory strong enough to describe arithmetic and its own proof-checking rules cannot prove the formal sentence asserting its own consistency. While a stronger mathematical theory can prove that a weaker one is consistent, doing so merely shifts our reliance onto the stronger theory’s axioms.

For our study of computation, the lesson is clear: making logical and computational rules explicit enables mechanical verification and universal simulation, while simultaneously revealing absolute boundaries that no algorithm—classical or quantum—can cross. Within the vast domain of tasks that do admit algorithms, however, a new physical question awaits: when a computation runs on a physical device, what happens to the information it processes along the way?

Undecidability and incompleteness concern different objectsUndecidability excludes an always-correct total algorithm for a specified decision problem. Incompleteness says that in a consistent effective theory with enough arithmetic there is a sentence P such that neither P nor not P has a proof.Undecidability and incompleteness concern different objectsUNDECIDABILITYObject: a decision problemNo algorithm always haltswith the correct yes/no answer.INCOMPLETENESSObject: a fixed theory TFor some sentence P,T proves neither P nor ¬ P.Example: the general halting problemT: consistent, effective,and sufficiently strong for arithmetic
On the left, we ask whether an algorithm can decide a problem for every input. On the right, we ask what a particular theory can prove. The incompleteness result requires the stated conditions on that theory. An unsuccessful search alone establishes neither result.
Problems
  1. A theory has the single axiom \(P\) and the rule modus ponens, and its sentences are built from \(P\) and \(Q\). Is \(Q\) provable? Is not \(Q\) provable? Is the theory complete?

    Show solutionHide solution

    From \(P\) alone, modus ponens yields nothing new, so the theorems are just \(P\). Neither \(Q\) nor not \(Q\) is provable, so \(Q\) is undecided and the theory is incomplete. This toy theory is incomplete for a trivial reason: it says nothing about \(Q\).

  2. A sentence \(G\) is neither provable nor refutable in a consistent theory \(T\). Show that both \(T\) with \(G\) added as an axiom and \(T\) with not \(G\) added are consistent. You may use the fact that if \(T\) with an added axiom \(A\) proves a contradiction, then \(T\) proves not \(A\).

    Show solutionHide solution

    If \(T\) with \(G\) added were inconsistent, \(T\) would prove not \(G\), refuting \(G\), contrary to assumption. If \(T\) with not \(G\) added were inconsistent, \(T\) would prove not not \(G\), that is, \(G\), again contrary to assumption. So both extensions are consistent, and the axioms of \(T\) alone do not decide \(G\).

  3. Suppose an algorithm extends a consistent, effectively axiomatized theory of arithmetic step by step, each time adding a sentence that the current theory leaves undecided. Show that the combined theory, with all the added axioms together, is still incomplete if it is consistent.

    Show solutionHide solution

    The added axioms are produced by an algorithm, so the combined list of axioms can still be listed by an algorithm: list the original axioms and run the extension procedure, interleaving the two. The combined theory is therefore effectively axiomatized, contains arithmetic, and is consistent by assumption. The incompleteness theorem applies to it, so it too leaves some sentence undecided. Adding axioms by any algorithm can never reach completeness.

1.4

From Computability to Reversibility

Undecidability defines the outer boundary of what algorithms can solve at all. Within the domain of problems that can be solved, however, implementing an algorithm on a physical machine raises a new question: what does each step of a procedure do to the information it is given? As we previewed with Euclid’s algorithm in Section 1.2.2, knowing how to step forward does not automatically tell us how to step backward. Examining what is lost during an ordinary calculation—and how to prevent that loss—leads us from classical computability to reversible computation, the direct gateway to quantum mechanics.

1.4.1 Deterministic and reversible transitions§

deterministicone-to-onebijectionlogical reversibility

In a deterministic computation, the future is never ambiguous: each running configuration has a single, uniquely determined next configuration, while a halting configuration simply stops. Whenever the computation can continue, the present snapshot completely fixes what happens next.

Does knowing the later configuration also tell us which earlier configuration produced it? Determinism makes no such promise. Recall the transitions from Euclid’s algorithm that we encountered in Section 1.2.2:

\[(30,18)\longrightarrow(18,12),\qquad(48,18)\longrightarrow(18,12).\]

If we inspect the calculation when it holds the pair \((18,12)\), we know exactly how to continue the run to \((12,6)\) and then \((6,0)\). Yet from \((18,12)\) alone, it is impossible to tell whether the previous pair was \((30,18)\), \((48,18)\), or any other pair \((18q+12,18)\). Distinct computational histories have merged into a single configuration, discarding the quotient \(q\) that distinguished them.

To undo a step and run a computation backward, we must be able to recover the exact earlier configuration from the resulting configuration alone. That requires a stricter condition than determinism: different inputs must always produce different outputs. A transition rule with this property is called one-to-one, and logical reversibility requires every elementary step of a computation to obey this condition.

When a one-to-one transition also reaches every configuration in a fixed state space, it forms a bijection: a one-to-one correspondence in which every configuration has both a unique successor and a unique predecessor. On such a state space, the reverse transformation is itself a well-defined deterministic rule everywhere.

Knowing what happens next is therefore only half the story. We must now ask whether ordinary calculations that seem to throw information away can be redesigned so that no histories ever merge.

Deterministic does not imply reversibleTwo distinct configurations may each have one successor yet share that successor, preventing unique reversal. A one-to-one transition retains distinct resulting states so each has a unique predecessor.Deterministic does not imply reversibleDeterministic, many-to-oneOne-to-one, reversible on its imageABCABA′B′C alone does not identify A or B.Each result identifies its predecessor.
On the left, each input has a unique successor, but \(C\) has two possible predecessors. On the right, each output identifies one predecessor. Reversibility imposes a condition on the backward direction as well.
Problems
  1. A rule on the configurations \(A,B,C,D\) sends \(A\to B\), \(B\to C\), \(C\to D\), and \(D\to B\). Is it deterministic? Which configurations have more than one predecessor, and which have none?

    Show solutionHide solution

    It is deterministic: each configuration has exactly one successor. \(B\) has two predecessors, \(A\) and \(D\), and \(A\) has none. The rule is not reversible.

  2. Run the same rule for six steps from each of \(A\), \(B\), \(C\), and \(D\). Which starting configurations end at the same configuration after six steps?

    Show solutionHide solution

    From \(A\): \(A,B,C,D,B,C,D\), ending at \(D\). From \(B\): \(B,C,D,B,C,D,B\), ending at \(B\). From \(C\), the run ends at \(C\), and from \(D\) at \(D\). The runs from \(A\) and from \(D\) both end at \(D\), so the configuration after six steps does not determine where the run started.

  3. Prove that a deterministic, one-to-one rule on finitely many configurations is onto, and that every run of such a rule eventually returns to its starting configuration.

    Show solutionHide solution

    A one-to-one rule sends the \(N\) configurations to \(N\) different configurations, so every configuration is reached: the rule is onto. Now follow a run \(c_0,c_1,c_2,\dots\). With finitely many configurations, some configuration repeats; let \(c_i=c_j\), with \(i\lt j\) and \(i\) as small as possible. If \(i\gt 0\), then \(c_{i-1}\) and \(c_{j-1}\) have the same successor, so by one-to-oneness \(c_{i-1}=c_{j-1}\), a repeat with a smaller first index. Hence \(i=0\): the run returns to \(c_0\).

1.4.2 Information loss in computation§

many-to-one

At first glance, most everyday calculations appear inherently irreversible because the functions they compute are many-to-one. Consider the logical AND operation on two bits: it returns \(0\) on three different inputs—\(00\), \(01\), and \(10\)—and returns \(1\) only on \(11\). If a logic gate overwrites its inputs and keeps only the single answer bit \(0\), there is no way to recover which of the three inputs occurred.

Yet obtaining an answer need not mean throwing away the input that produced it. If instead of keeping \(f(x)\) alone we retain the input alongside the output, forming the pair \((x,f(x))\), then different inputs \(x\) always yield different output pairs—even when \(f\) itself is many-to-one. For AND, keeping both input bits and writing their conjunction into an extra target bit (initialized to \(0\)) maps the four starting configurations \(000\), \(010\), \(100\), and \(110\) to four distinct outputs: \(000\), \(010\), \(100\), and \(111\).

Of course, simply adding extra storage is not yet a complete computational architecture. To compute reversibly in practice, we must build complex operations out of reversible elementary gates, specify the initial values of any extra workspace bits, and clear temporary intermediate results without erasing them and losing information. Designing those gates and uncomputing temporary workspace is the central task of Chapter 2.

Why should we go to such lengths to avoid erasing information? The reason is physical as well as logical. As we noted at the opening of this chapter, every computation is carried out by a physical system. At the smallest scales, the laws of quantum mechanics that govern isolated physical systems run backward just as deterministically as they run forward; between observations, their evolution loses no information. Any computer built to harness quantum mechanics must therefore reach useful answers through reversible transformations. We have moved from the foundational question of computability—“Can this task be computed at all?”—to the physical question that launches the next chapter: “How can its computation preserve information?”

Interactive figure. This diagram maps inputs to outputs for finite Boolean functions and shows the effect of retaining the input register. Compare a 2-bit-to-1-bit map with an equal-width map, then toggle Keep the input too to see how colliding arrows separate.

Does a Boolean function lose information?

Retaining inputs preserves the distinctions AND discardsOrdinary AND maps inputs 00, 01, and 10 to zero and 11 to one. Retaining x and y and placing their AND into a target initially zero gives distinct three-bit outputs. The full reversible update is x,y,t to x,y,t XOR xy.Retaining inputs preserves the distinctions AND discardsRetain only AND(x,y)Retain inputs and update a target0001101101000000010010100100110111Shown: target t initially 0Full update: (x,y,t)→(x,y,t⊕ xy); applying it twice restores the input.
Each arrow sends an input to its output. The checker visits the inputs in order and stops as soon as two arrows reach the same output: then the output does not tell us which input occurred, and the function is irreversible. If no two arrows meet, every output identifies its input. If, in addition, every possible output is reached, the function is a bijection. Keep the input too replaces \(f(x)\) by the pair \((x,f(x))\), which never merges two inputs. Reversible gates turn this idea into a construction that uses an extra target bit and XOR.
What to observe

A map from 2 bits to 1 bit sends 4 inputs into 2 outputs, so collisions are unavoidable. Retaining the input embeds each \(x\) into \((x,f(x))\), whose first coordinate distinguishes distinct inputs and makes the map one-to-one.

Problems
  1. Which of these operations on two bits lose information: \((x,y)\mapsto x\land y\); \((x,y)\mapsto(x,x\oplus y)\); \((x,y)\mapsto(y,x)\); \((x,y)\mapsto x\oplus y\)?

    Show solutionHide solution

    \(x\land y\) loses information: \(00\), \(01\), and \(10\) all give \(0\). The XOR \(x\oplus y\) alone also loses it: \(00\) and \(11\) both give \(0\). The maps \((x,x\oplus y)\) and \((y,x)\) are one-to-one: \((x,x\oplus y)\) is undone by applying it again, and the swap by swapping back.

  2. Keep both inputs and store the AND in an extra bit \(t\) that starts at \(0\): \((x,y,t)\mapsto(x,y,t\oplus(x\land y))\). List the outputs for the four inputs with \(t=0\), and show that the map can be undone.

    Show solutionHide solution

    The outputs are \(000\), \(010\), \(100\), and \(111\). Applying the map again gives \(t\oplus(x\land y)\oplus(x\land y)=t\), so every input is restored: the map is its own inverse, even though AND itself loses information.

  3. A computation maps \(n\)-bit inputs to a single output bit. Show that at least \(2^{n-1}\) inputs share an output. If the computation keeps some bits besides its output, how many must it keep, at least, to become one-to-one, and how many always suffice?

    Show solutionHide solution

    There are \(2^n\) inputs and two outputs, so by the pigeonhole principle one output is shared by at least \(2^{n-1}\) inputs. To be one-to-one, the outputs must take at least \(2^n\) different values, which needs at least \(n\) bits in total: the answer bit and at least \(n-1\) further bits. Keeping all \(n\) input bits always suffices, since the input can then be read off directly. Whether \(n-1\) kept bits are enough depends on the function.

Related appendix: Automata and memory. Additional formal models are discussed in Grammars and lambda calculus.

Further reading: Turing’s On Computable Numbers, with an Application to the Entscheidungsproblem introduces the machine model and proves that the logical decision problem cannot be solved by a general procedure. Rosser’s Extensions of Some Theorems of Gödel and Church shows that consistency suffices for the first incompleteness result, replacing a stronger assumption in Gödel’s original proof. Bennett’s Logical Reversibility of Computation shows how computations can be simulated using reversible steps.

Summary

Questions and worked problems

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

1. Quick check §

A proof search over a three-symbol alphabet has checked every candidate of length at most \(10\), including the empty string, without finding a proof. How many candidates is that, and what does the failure establish?

Hint 1

There are \(3^k\) strings of length \(k\).

Hint 2

Unprovability is a claim about proofs of every length.

Worked solution

\(1+3+\dots+3^{10}=(3^{11}-1)/2=88{,}573\) candidates. The failure shows only that the statement has no proof of length at most \(10\). A longer proof may exist, and no finite search can establish that none does.

Revisit the relevant explanation

2. Quick check §

A Turing machine is paused mid-run. You are told the tape contents \(\square111\square\) and that the head is on the second \(1\), but not the control state. The machine has states \(q_0\) (moving right over ones) and \(q_1\) (moving left back to the start). Can you resume the computation? What must a configuration contain?

Hint 1

Would the next step be the same in \(q_0\) and in \(q_1\)?

Hint 2

A configuration must determine the next step without extra information.

Worked solution

No. In \(q_0\) the next step moves the head right; in \(q_1\) it moves left. The tape and head position alone leave the next step undetermined. A configuration of a Turing machine is the triple of tape contents, head position, and control state, which together are exactly enough to resume. For Euclid’s algorithm, paused at the start of its repeated step, the pair alone sufficed because the next instruction was always the same. What a configuration must include depends on where the computation is allowed to pause.

Revisit the relevant explanation

3. Quick check §

The rule \(n\mapsto\lfloor n/2\rfloor\) (halve and round down) acts on the numbers \(0,1,\dots,7\). Is it deterministic? Is it one-to-one? Show how to keep one extra bit so that the step can be undone, and say what that bit records.

Hint 1

Which pairs of inputs give the same output?

Hint 2

The lost information is whether \(n\) was even or odd.

Worked solution

It is deterministic: each \(n\) has exactly one result. It is not one-to-one: \(2k\) and \(2k+1\) both go to \(k\), so \(0,1\mapsto0\), \(2,3\mapsto1\), and so on. Keep the remainder \(n\bmod2\) as an extra bit: \(n\mapsto(\lfloor n/2\rfloor,\,n\bmod2)\). Now \(n=2\lfloor n/2\rfloor+(n\bmod2)\) recovers the input, so the extended step is one-to-one. The extra bit records exactly the information the original step discarded, the last binary digit of \(n\).

Revisit the relevant explanation

4. Worked problem §

Run Euclid’s algorithm on \((377,233)\). Count the divisions, record each quotient, and explain separately why the answer is correct and why the run stops.

Hint 1

\(377=1\cdot233+144\).

Hint 2

These are consecutive Fibonacci numbers.

Worked solution

The remainders are \(144,89,55,34,21,13,8,5,3,2,1,0\): twelve divisions, with quotient \(1\) every time except the last, which is \(2\). The greatest common divisor is \(1\). It is correct because each step keeps the set of common divisors unchanged, an invariant. The run stops because the second entry strictly decreases through nonnegative integers. Quotients of \(1\) make that decrease as slow as possible.

Revisit the relevant explanation

5. Worked problem §

Design a Turing machine that adds one to a binary number. The head starts on the rightmost digit, in state \(q\). Reading \(1\): write \(0\), move left, stay in \(q\). Reading \(0\) or a blank: write \(1\) and halt. Trace it on \(1011\) and on \(111\). How many steps does an \(n\)-digit input take in the worst case?

Hint 1

Adding one turns trailing ones into zeros and the first zero into a one.

Hint 2

The worst case is an input of all ones.

Worked solution

On \(1011\): read \(1\), write \(0\), move left (tape \(1010\)); read \(1\), write \(0\), move left (\(1000\)); read \(0\), write \(1\), halt (\(1100\)). Three steps, and \(1100\) is \(12=11+1\). On \(111\): three steps turn the ones into zeros, then the head reads the blank to the left, writes \(1\), and halts, giving \(1000\), which is \(8=7+1\), after four steps. In general the machine takes one step per trailing \(1\), plus one, so the worst case is \(n+1\) steps, for an input of all ones. The same finite rule table handles inputs of every length, which is the point of the model.

Revisit the relevant explanation

6. Worked problem §

Euclid’s algorithm stops because the second entry decreases. Show something stronger: after any two steps, the second entry is less than half of what it was. Use this to bound the number of divisions for a pair \((a,b)\) with \(b\le233\), and compare with the run on \((377,233)\).

Hint 1

From \((a,b)\) the next two pairs are \((b,r_1)\) and \((r_1,r_2)\). Consider separately \(r_1\le b/2\) and \(r_1>b/2\).

Hint 2

If \(r_1>b/2\), the division of \(b\) by \(r_1\) has quotient \(1\).

Worked solution

If \(r_1\le b/2\), then \(r_2<r_1\le b/2\). If \(r_1>b/2\), then \(r_1\) goes into \(b\) once, so \(r_2=b-r_1<b/2\). Either way \(r_2<b/2\). So every two divisions at least halve the second entry. Starting from \(b\le233<2^8\), after \(16\) divisions the second entry is below \(233/2^8<1\), so it is \(0\): at most \(16\) divisions. The run on \((377,233)\) uses \(12\), close to this bound, because consecutive Fibonacci numbers have every quotient equal to \(1\), the slowest case. The bound grows with the number of digits of \(b\), not with \(b\) itself, a first example of measuring the resources an algorithm needs.

Revisit the relevant explanation

7. Worked problem §

Show that no algorithm can decide, for every program \(P\) and input \(x\), whether \(P\) ever prints the word “hello” when run on \(x\). Use the undecidability of the halting problem: from a pair \((P,x)\), build a program \(P'\) that prints “hello” exactly when \(P\) halts on \(x\).

Hint 1

\(P'\) should run \(P\) on \(x\) with all of \(P\)’s own output suppressed.

Hint 2

If a “hello” detector existed, what would it do on \(P'\)?

Worked solution

Let \(P'\) simulate \(P\) on \(x\), discarding everything \(P\) would print, and print “hello” once the simulation halts. If \(P\) halts on \(x\), then \(P'\) prints “hello”. If not, the simulation runs forever and \(P'\) never prints anything. Building \(P'\) from \((P,x)\) is a mechanical rewriting of a finite description. Suppose an algorithm \(D\) decided whether a program prints “hello”. Then “build \(P'\), then run \(D\) on \(P'\)” would always finish and would answer whether \(P\) halts on \(x\). No such procedure exists, so \(D\) cannot exist. This pattern, turning a halting question into a question about another property, shows that many questions about program behavior are undecidable.

Revisit the relevant explanation

8. Misconception §

A student argues: “The halting problem is undecidable, so no algorithm can tell whether Euclid’s algorithm halts on \((48,18)\).” Explain what is wrong. Then describe an algorithm that answers correctly for one fixed program and input, and say why this does not contradict the theorem.

Hint 1

The theorem is about one procedure that works for every pair.

Hint 2

For a single question with answer “yes” or “no,” one of two trivial programs answers correctly.

Worked solution

The theorem excludes one algorithm that finishes with the correct answer for every program and input. It says nothing against settling particular cases. Euclid’s algorithm halts on \((48,18)\); we proved it halts on every pair of positive integers. More strikingly, every single question “does \(P\) halt on \(x\)?” is answered correctly by one of the two programs “print yes” and “print no.” One of them is right, even if we do not know which. Undecidability means that no single procedure, given \((P,x)\) as input, always finds the right answer. The difficulty lies in uniformity across all inputs, not in any one instance.

Revisit the relevant explanation

9. Extension §

Make each step of Euclid’s algorithm reversible by recording its quotient. Show that \((b,r)\) and \(q\) determine the previous pair, and find how many quotients a run on \((377,233)\) must keep.

Hint 1

The previous pair was \((a,b)\) with \(a=qb+r\).

Hint 2

Use the run from the worked problem.

Worked solution

From \((b,r)\) and \(q\), the previous first entry is \(a=qb+r\), so the previous pair \((a,b)\) is recovered. A run that keeps all its quotients can be undone step by step. The run on \((377,233)\) keeps twelve quotients, eleven \(1\)s and one \(2\). Reversibility costs extra memory that grows with the length of the run.

Revisit the relevant explanation

10. Extension §

Suppose, contrary to fact, that a halting decider \(H(P,x)\) existed. Show that it would turn proof search into a decision procedure for provability in a theory whose proofs can be checked mechanically: given a statement \(S\), build the program that searches for a proof of \(S\) and halts when it finds one. What would that imply for the incompleteness result of Section 1.3.3?

Hint 1

The search program halts exactly when a proof of \(S\) exists.

Hint 2

With a decider for provability, try \(S\) and its negation.

Worked solution

Let \(Q_S\) list candidate strings by length, check each, and halt on the first valid proof of \(S\). It halts exactly when \(S\) is provable. Running \(H(Q_S,\text{empty input})\) would always finish and report whether \(S\) is provable, so provability would be decidable. This is consistent with Section 1.1.3: the search alone may run forever, and \(H\) would supply the missing ability to recognize that it never ends. It would not remove incompleteness. Deciding whether \(S\) is provable is different from proving \(S\): with \(H\) we could recognize a sentence that is neither provable nor refutable, but it would remain unsettled by the axioms. The argument shows that provability is no harder to decide than halting, so the obstacle met in proof search is the same kind of obstacle the halting theorem identifies.

Revisit the relevant explanation

Where this leads. Reversible circuit design replaces such information-losing steps with reversible constructions.

Search this book

Search all chapters and appendices.