Theory of Computation: Lecture 4
Turing machines, configurations, recognizable and decidable languages, basic TM algorithm design, unary powers of two, and the Church-Turing thesis.
From Finite Memory to Work Tape
Finite automata have fixed memory: no matter how long the input is, the machine remembers only one of finitely many states. That is why languages such as
are not regular. The problem itself is easy for an ordinary algorithm: count the symbols, or pair them off. What finite automata lack is memory whose used portion can grow with the input.
Tape. A row of cells used as memory. Each cell stores one symbol. A head points to one cell at a time and can read or overwrite that cell. The input starts in the leftmost cells; the rest of the tape is blank.
Unbounded work memory. Memory with no fixed finite bound on how many tape cells may be used during a computation. Each input still uses only finitely many cells at any finite time, but longer inputs may require more cells.
A finite automaton has a fixed notebook with one page. A Turing machine has a finite program and as much blank paper as the computation needs.
Single-tape encoding. Storing the input, work memory, and output on one tape. Different regions of the tape can be separated by delimiters such as #. Several tapes may be easier to draw, but one tape is enough to represent the same computation.
Turing Machines
Turing machine (TM). A finite-state control attached to an infinite tape. At each step, the machine reads the symbol under its head, writes one tape symbol, moves the head one cell left or right, and enters a new state.
- Finite control. The program has finitely many states, independent of the input length.
- Tape. A one-way infinite sequence of cells, initially holding the input followed by blanks.
- Head. The pointer to the current tape cell. It can read, overwrite, and move left or right.
- Halting states. The accept and reject states stop the computation immediately.
Finite automata read a string once, left to right, and never change it. Turing machines may revisit earlier cells, rewrite symbols, and use blank cells as work space.
Because it can revisit and rewrite cells, a TM can compare the two ends of a string against each other, which a one-pass finite automaton cannot do.
Formal Turing machine. A Turing machine is a 7-tuple
with the following parts:
| Symbol | Role |
|---|---|
| finite set of states | |
| input alphabet, not containing the blank symbol | |
| tape alphabet, with and | |
| transition function | |
| start state, where computation begins | |
| accepting halting state | |
| rejecting halting state, with |
Only non-halting states need transitions:
If , then in state reading , the machine writes , moves one cell right, and enters state . The case is the same except that the head moves left.
At minimum, a TM description must make three distinguished states clear:
| State | Role |
|---|---|
| first state of the computation | |
| halts with answer yes | |
| halts with answer no |
Extra states are working states used before the machine halts.
State graph of a TM. A directed graph drawing of the transition function: the graph and the 7-tuple describe the same machine. Nodes are states, the incoming arrow marks , and an edge label has the form
meaning: if the head reads , write , move in direction , and enter the target state.
A complete machine fits in a small graph. Let decide
the strings made only of 0s. One working state suffices: stay in , walking right over each 0 without changing it, until the head meets the first blank (accept, the input was all 0s) or the first 1 (reject). The blank in this and every later figure is the tape blank .
| Graph feature | Meaning |
|---|---|
| incoming arrow | start state |
| self-loop on | read 0, rewrite it, keep scanning right |
| double circle | accepting halt |
| node | rejecting halt |
| edge label | read , write , move |
In the graph, and are drawn with no outgoing edges.
The input alphabet says what may appear in the original input. The tape alphabet says what the machine may use while computing, including marks such as and the blank symbol .
Configurations and Computation
Configuration. A complete snapshot of a Turing machine computation: current state, current head position, and the finite visible part of the tape.
The notation , with and , means the state is , the visible tape content is with the head on the first symbol of , and every other cell is blank.
If , the head is on the leftmost tape cell. If , the head scans the blank cell immediately after .
Transition between configurations. Suppose the current configuration is , so the head scans and is the symbol immediately to its left.
If , then the next configuration is
The machine overwrites by and moves left, so the head now scans . If , then the next configuration is
At the left edge, a left move keeps the head on the first cell. At the right edge of the shown word, blank cells are added as needed.
Computation. On input , the starting configuration is . Write when configuration yields in one step. The machine repeatedly applies valid transitions until it reaches , reaches , or never halts.
Resolving a run. Take the machine for . On input 00 every step is forced, and the run reaches in three moves:
Each 0 is rewritten as the head steps right; reading the trailing blank in sends to . The same run reads as one tape per configuration, the scanned cell shown inverted:
A single 1 derails the run. On 01 the first 0 is consumed, but reading the 1 in triggers :
Unlike a DFA, a Turing machine does not always produce an answer. It may run forever.
An infinite computation does not have to repeat a configuration. The tape can keep changing, or the head can keep moving into fresh blank cells, so there are infinitely many possible configurations. Repetition is forced only when the computation is confined to finitely many configurations.
Recognizers and Deciders
Turing-recognizable language. A language recognized by some Turing machine : for every input ,
- if , then accepts ;
- if , then rejects or loops forever.
A recognizer is allowed to fail to answer no.
Turing-decidable language. A language decided by some Turing machine : for every input , the machine halts, and it accepts exactly when .
Every decidable language is recognizable: a decider is a recognizer that also halts on all no-instances. The converse is not automatic, because looping is not the same as rejecting.
| Input type | Recognizer for | Decider for |
|---|---|---|
| must accept | must accept and halt | |
| may reject or loop | must reject and halt |
Recognition is a semi-answer: yes is reliable, no may never arrive. Decision is a total yes/no algorithm.
Designing Turing-Machine Algorithms
Turing machines are usually designed at a high level. A step such as "scan right until the next unmarked 1" is valid when it can be implemented by finitely many states moving one cell at a time.
Recipe: designing a TM decider.
- Choose work symbols. Add tape symbols that store progress, such as for a crossed-off input symbol.
- Use sweeps. Move left-to-right or right-to-left while a state records the small finite fact needed for the sweep.
- Maintain an invariant. State what the marks mean after each pass.
- Separate halting cases. Say exactly when the machine accepts and when it rejects.
- Prove termination. For a decider, show that every loop makes finite progress toward a halt.
Example 1. Equal numbers of 0s and 1s.
The language from the opening is not regular, yet it is decidable.
The machine pairs off one 0 with one 1 per sweep until nothing is left. It uses
where and are the halts, temporarily marks a matched symbol, and is the blank. Each edge still reads as , with two shorthands: a comma-separated read set fires on any of the listed symbols, and an omitted write leaves the cell unchanged. So means "on or , leave the cell and move right".
Read the diagram as one repeating loop:
- : pick the leftmost symbol. A
0is erased () and the machine remembers "find a 1" by entering ; a1is erased and it enters to find a0; a leftover is erased and skipped; a means everything is gone, so accept. - / : find the opposite symbol. runs right over
0s andXs to the first1, writes , and turns back in ; is the mirror image. Hitting first means the partner is missing, so reject. - : rewind. Walk left over everything until the blank gap on the left, then step right into for the next sweep.
Each completed loop erases one 0 and one 1, so the counts stay equal exactly when the tape empties cleanly into .
The run on 0110 is traced configuration by configuration, the scanned cell inverted:
Run on 0110
The invariant is that each completed loop removes exactly one 0 and one 1 (one rewritten to in , its partner marked and then erased on the next sweep), so the consumed symbols always hold equally many 0s and 1s. Accepting requires a fully blank tape, which is reachable only when the counts matched; rejecting happens the instant or runs off the end with no partner. Every loop consumes two cells, so the remaining input strictly shrinks and the machine always halts.
The tape converts an unbounded counting problem into a bookkeeping problem: remember progress by writing on the input.
Example 2. Unary powers of two.
Let
A TM can decide by repeatedly testing whether the current number of unmarked zeros is even and then deleting half of them.
- If there are no unmarked zeros, reject.
- Sweep left to right over the unmarked zeros, alternating between keeping one and marking the next one as deleted.
- If exactly one unmarked zero was seen during the pass, accept.
- If an odd number greater than one was seen, reject.
- If an even number was seen, return to the left end and repeat on the unmarked zeros.
Each non-halting pass divides the number of unmarked zeros by . A positive integer eventually reaches exactly when it is a power of two; otherwise, some pass reaches an odd number greater than and rejects. Because the number of unmarked zeros strictly decreases after every non-halting pass, the machine always halts.
Accepted: 0, 00, 0000. Rejected: 000 and 000000; halving six unmarked zeros leaves three, and the next pass sees an odd count greater than one, so it rejects.
The Church-Turing Thesis
Algorithm. An effective finite procedure for solving a problem. Before Turing machines and equivalent models, this was an intuitive idea rather than a formal mathematical object.
Church-Turing thesis. The informal notion of an algorithm coincides with what a Turing machine can compute.
This is not a theorem, because one side is informal. Its force comes from robustness: Turing machines, -calculus, recursive functions, register machines, and ordinary programming languages all define the same class of computable functions. Variants such as multi-tape Turing machines may change efficiency, but not which languages are decidable.
Diophantine equation. A polynomial equation with integer coefficients whose solutions are required to be integers.
For example, has the integer solution , , .
Hilbert's tenth problem asked for an algorithm deciding whether an arbitrary Diophantine equation has an integer solution. Once "algorithm" had a formal meaning, the problem could be answered precisely: Matiyasevich proved in 1970, building on work of Davis, Putnam, and Robinson, that no such algorithm exists.
Turing machines therefore do two jobs at once. They show that simple finite programs with unbounded work tape can decide many non-regular languages, and they provide the language needed to prove that some computational problems have no algorithm at all.