In the previous chapter, we explored finite automata, a computational model with strictly finite memory. We discovered their power but also their inherent limitations, proving that simple languages like are beyond their reach. To overcome these limitations, we need a model with infinite memory, which is the crucial conceptual leap.

This brings us to the Turing Machine (TM), the foundational model of computation that captures the very essence of what it means to be an “algorithm.” Proposed by Alan Turing in 1936, it was designed not to be a practical computer, but to formalize the intuitive process of a human mathematician following a set of rules to solve a problem. A TM consists of a finite-state control unit (like a DFA) and an infinite tape that it can read from, write to, and move along in both directions. This infinite tape is the crucial addition, giving the machine an unlimited memory capacity.

By studying this simple yet powerful device, we can explore the absolute limits of what is computable, setting the stage for understanding which problems can be solved by computers and which cannot.

4.1 Aims

By the end of this chapter, you will be able to:

  • Understand the Formal Definition: Grasp the 7-tuple definition of a Turing Machine and its components, including the crucial role of the infinite tape.
  • Trace Computations: Understand how a TM operates through configurations and computation steps, and how its behavior defines language acceptance.
  • Distinguish Language Classes: Learn the critical difference between recursively enumerable (recognizable) and recursive (decidable) languages, based on the TM’s halting behavior.
  • Design Basic TMs: Develop strategies for designing Turing Machines to solve specific problems, even if informally.
  • Appreciate Universality: Understand the significance of multi-tape TMs, non-deterministic TMs, and the Church-Turing Thesis, which posits that TMs can compute anything that any reasonable computational model can.
  • Grasp TM Encoding: Understand how Turing Machines themselves can be encoded as strings, enabling self-reference and laying the groundwork for proofs of undecidability.

4.2 Excerpt from History: Alan Turing’s Motivation

At the beginning of the 20th century, mathematicians were grappling with the foundations of mathematics, particularly the question of what constitutes an “effective procedure” or an “algorithm.” Alan Turing, in his seminal 1936 paper “On Computable Numbers, with an Application to the Entscheidungsproblem,” sought to formalize this intuitive concept.

Turing’s approach was not to build a physical computer, but to define the class of methods that a human “computer” (a person performing calculations) could execute. He imagined a human mathematician working with a pencil and paper, following a set of rules. His key insights were:

  1. Finite State of Mind: The human brain, though complex, is always in one of a finite number of “states” at any given moment.
  2. Local Observation: The human can only observe and process a finite, bounded amount of information at any given time (e.g., a few symbols on the paper).
  3. Simple Operations: The actions performed are elementary: writing a symbol, erasing a symbol, moving attention to an adjacent spot.
  4. Unlimited Paper: To handle arbitrarily long computations, the paper (memory) must be potentially infinite.

By simplifying these observations, Turing arrived at his abstract machine model, which, despite its simplicity, proved to be incredibly powerful. He showed that any operation involving a finite part of the text could be broken down into a sequence of these elementary operations, thus eliminating the need for complex, arbitrary “basis operations.”

4.3 The Model of the Turing Machine

A Turing machine can be seen as a generalization of a finite automaton, equipped with an infinite memory. Informally, it consists of:

  1. A finite control (or finite-state unit) that holds the program (a finite set of states and transition rules). This is analogous to the CPU of a modern computer.
  2. An infinite tape, divided into cells, which serves as both input medium and memory (working tape). This tape extends infinitely to the right and is delimited on the left by a special boundary symbol.
  3. A read/write head that can move left and right along the tape, one cell at a time. It can read the symbol under it, write a new symbol, and move.

All cells on the tape not yet written to contain a special blank symbol (). An elementary operation (a single step) depends on the machine’s current state and the symbol under the head.

4.3.1 Formal Definition

Definition 4.1 (Turing Machine)

A Turing machine (TM) is a 7-tuple , where:

  1. is a finite, non-empty set of states.
  2. is the input alphabet, which is a finite set of symbols. Crucially, does not contain the special boundary symbol or the blank symbol .
  3. is the tape alphabet, which is a finite set of symbols. It must contain the input alphabet (), and also the special symbols (left end marker) and (blank symbol).
  4. is the transition function. This function defines the machine’s behavior. For a given current state and a symbol read from the tape, specifies:
    • The next state .
    • The symbol to write on the current tape cell.
    • The head movement (Left, Right, No movement). The transition function is not defined for the accepting or rejecting states, as the machine halts upon entering them. A crucial property is that must result in writing and moving right or staying put, preventing the head from moving off the left end of the tape or overwriting the boundary.
  5. is the start state.
  6. is the unique accepting state. If the TM enters this state, it accepts the input and halts.
  7. is the unique rejecting state. If the TM enters this state, it rejects the input and halts.

A configuration describes the TM’s complete status at any given moment. It includes the current state, the entire content of the tape, and the position of the read/write head. A common notation for a configuration is , which means:

  • The TM is in state .
  • The tape content is (where and the rest of the tape is blank).
  • The head is currently positioned over the symbol .

A computation step is a relation between configurations, describing how the TM moves from one configuration to the next based on its transition function. For example, if , then .

A computation is a sequence of configurations, starting from an initial configuration (where is the input word). The computation halts if it enters or . Otherwise, it may run indefinitely.

The language accepted by a Turing machine , denoted , is the set of all words for which the computation of on input eventually reaches the accepting state .

4.3.2 Language Classes: Recursively Enumerable vs. Recursive

The behavior of a TM on inputs defines two crucial classes of languages, distinguishing between problems that can be “recognized” and those that can be “decided.”

Definition 4.2 (Recursively Enumerable and Recursive Languages)

  • A language is recursively enumerable (RE) if there exists a TM such that . This means for any , halts and accepts. For , either halts and rejects, or it continues to run indefinitely (does not halt). These languages are also called Turing-recognizable.
    • Intuition: If a word is in the language, the TM will eventually confirm it. If not, the TM might never stop searching for a proof of membership.
  • A language is recursive if there exists a TM that halts on all inputs and . For any input , is guaranteed to halt in either or . These languages are also called decidable or Turing-decidable.
    • Intuition: The TM always gives a definitive “yes” or “no” answer in finite time for any input.

Every recursive language is recursively enumerable. However, as we will see in the next chapter, the reverse is not true; there exist languages that are recursively enumerable but not recursive. A TM that halts on all inputs is a formal model of an algorithm in the strictest sense (a procedure guaranteed to terminate and produce a result).

A TM for

This language consists of strings of 0s whose length is a power of two (e.g., ). Note: .

Strategy: The TM can recognize this language by repeatedly halving the number of 0s.

  1. Initial Check: If the input is empty (), reject. If the input has length 1 (), accept.
  2. Sweep and Mark: Sweep across the tape from left to right. For every two 0s encountered, mark the first one (e.g., replace it with X) and leave the second one. If an odd number of 0s is encountered, reject.
  3. Rewind: If the sweep completes successfully (an even number of 0s were found), rewind the head to the beginning.
  4. Compress: Sweep across the tape again. For every 0, replace it with a blank . For every X, replace it with a 0. This effectively halves the number of 0s. After this pass, compact the 0s to the left side of the tape.
  5. Repeat: Go back to step 2 with the new, shorter string of 0s.
  6. Acceptance: If at any point, the tape contains exactly one 0, accept.

4.4 Variants of Turing Machines

To make designing TMs easier and to better model real computers, we can introduce variants that, while seemingly more powerful, are ultimately equivalent to the basic single-tape TM in terms of what they can compute.

4.4.1 Multi-tape Turing Machines

A -tape Turing Machine is a TM equipped with:

  • A read-only input tape (containing the initial input, delimited by and a right end marker \).
  • read/write “work” tapes, each with its own independent head. These tapes are infinite to the right and delimited by on the left.

Its transition function takes the current state and the symbols under all heads (one input head, work tape heads) to determine:

  • The next state.
  • What to write on each of the work tapes.
  • How to move each of the heads (Left, Right, or No movement).

This model is much more convenient for designing algorithms, as it allows for parallel processing of information and easier manipulation of data.

A 2-tape TM for

This language consists of words where a binary string is followed by and then by an identical copy of .

  1. Initial Scan: Scan the input tape to verify that the input has the form (i.e., exactly one symbol). If not, reject.
  2. Copy : Rewind the input head to the beginning. Copy the prefix (the part before the ) from the input tape onto the first work tape.
  3. Position Heads: Move the input head to the first symbol of (the part after the ). Move the first work tape head to the beginning of the copied .
  4. Compare: Move both the input head and the first work tape head to the right in lockstep, comparing symbols one by one.
  5. Decision:
    • If a mismatch occurs, reject.
    • If both parts are exhausted simultaneously (i.e., both heads reach their respective blank symbols or end markers) with no mismatch, accept.
    • If one part is exhausted before the other, reject (lengths don’t match).

Despite their convenience and apparent parallelism, multi-tape TMs are not more powerful than standard single-tape TMs. They have the same fundamental computational capabilities, differing only in efficiency.

Theorem 4.1 (Equivalence of TM Models)

For every multi-tape TM, there is an equivalent single-tape TM.

4.4.2 The Church-Turing Thesis

The fact that such different models (single-tape, multi-tape, and many others like lambda calculus, register machines, etc.) all turn out to be equivalent in power is not a coincidence. It leads to a foundational principle of computer science.

The Church-Turing Thesis

The intuitive notion of an “algorithm” is captured exactly by the formal model of a Turing machine that always halts.

More broadly, any function that can be computed by an algorithm can be computed by a Turing machine.

This is not a theorem that can be proven mathematically, but rather a fundamental thesis that has been universally accepted due to overwhelming evidence and lack of counterexamples. It asserts that any problem that can be solved by any reasonable computational device, now or in the future, can also be solved by a Turing machine. It provides the solid foundation for proving that certain problems are unsolvable: if we can prove they are not solvable by a Turing machine, we can be confident they are not solvable by any algorithm at all.


4.5 Non-deterministic Turing Machines

Just as with finite automata, we can introduce non-determinism into Turing machines. A non-deterministic Turing machine (NTM) has a transition function that, for a given state and tape symbol, can specify a set of possible moves, rather than a single unique move.

An NTM accepts an input if at least one of its possible computation paths leads to the accepting state. This is often described as the machine “guessing” the correct path, or exploring all possible paths simultaneously (like in a multiverse of computations). If no path leads to acceptance, the input is rejected.

Theorem 4.2 (Equivalence of NTMs and DTMs)

For every non-deterministic TM, there is an equivalent deterministic TM.


4.6 Encoding of Turing Machines

Just as a program written in a high-level language can be compiled into machine code (a sequence of bits), any Turing machine can be encoded as a string over a finite alphabet (e.g., ). This encoding allows us to treat Turing machines themselves as data that can be processed by other Turing machines.

Definition 4.5 (Encoding of a TM)

For any TM , we can construct a string that uniquely describes it.

A common encoding scheme involves assigning unique binary codes to each state, tape symbol, and head movement direction. Then, each transition rule can be encoded by concatenating the codes for . Finally, the entire TM is encoded by concatenating the codes for all its transitions, along with information about the number of states and tape symbols, separated by special delimiters (e.g., ).

For example, if we have codes for states , symbols , and movements , a transition could be encoded as: Code(q_current) # Code(symbol_read) # Code(q_next) # Code(symbol_write) # Code(move_direction) The entire TM would then be a concatenation of these transition encodings, prefixed by information about the TM’s overall structure.

This encoding is crucial because it allows us to treat Turing machines as inputs to other Turing machines. This self-referential capability is profoundly powerful, enabling a TM to analyze, simulate, or even modify other TMs. This opens the door to asking questions like: “Can a TM decide if another given TM will halt on a given input?” This leads directly to the concept of a Universal Turing Machine and the proof of the Halting Problem’s undecidability in the next chapter.

The set of all such encodings, , is a language over . Since these encodings are binary strings, they can be ordered canonically. This allows us to speak of the -th Turing machine, , which is the TM whose encoding is the -th string in in canonical order.


Summary

  • The Turing Machine is the fundamental formal model of an algorithm, consisting of a finite control, an infinite tape for memory and input, and a read/write head.
  • Recursive (decidable) languages are those for which a TM exists that halts on all inputs, providing a definitive “yes” or “no” answer. Recursively enumerable (recognizable) languages are those for which a TM halts and accepts if the input is in the language, but may run indefinitely otherwise.
  • Variants like multi-tape and non-deterministic TMs are more convenient for algorithm design but are computationally equivalent to the standard single-tape model. This equivalence supports the Church-Turing Thesis, a foundational axiom stating that TMs capture the intuitive notion of computability.
  • All TMs can be encoded as strings, allowing them to be used as inputs to other TMs. This self-referential property is key to understanding the limits of computation and the existence of undecidable problems.

Previous Chapter: Chapter 3 - Finite Automata Next Up: Chapter 5 - Computability

Exercises

Exercise 4.1 (Non-Regularity Proof)

Prove that the language is not regular.

Exercise 4.2 (TM Design Sketch)

Sketch the design of a Turing Machine for the language .

Exercise 4.3 (Multi-tape TM Design)

Describe informally how a 2-tape TM could accept the language .


Key Takeaways

  • Turing Machines as Universal Models: The TM is the most widely accepted formal model for algorithms, capable of performing any computation that a modern computer can. Its infinite tape provides unlimited memory, overcoming the limitations of finite automata.
  • Decidability vs. Recognizability: A crucial distinction exists between recursive (decidable) languages (for which a TM always halts, giving a definitive yes/no) and recursively enumerable (recognizable) languages (for which a TM halts and accepts only if the input is in the language, possibly running forever otherwise).
  • Equivalence of TM Variants: Multi-tape and non-deterministic Turing machines, while offering practical advantages in design and potentially efficiency, are fundamentally equivalent in computational power to the basic single-tape deterministic Turing machine. This supports the robustness of the TM model.
  • The Church-Turing Thesis: This foundational axiom states that any intuitively computable function can be computed by a Turing machine. It forms the bedrock for proving the limits of computation.
  • Encoding TMs: The ability to encode Turing machines as strings allows them to be treated as data, enabling self-reference and leading to profound results about computability, such as the existence of universal TMs and undecidable problems.