Motivation
To show that a problem has an algorithm, we can describe a method and implement it as a program. To prove that no algorithm exists, we need a precise definition of the computations that an algorithm may perform. A Turing machine (TM) provides a simple mathematical model for studying computability and, later, computational complexity.
The tape and the finite control
A TM generalizes an endlicher Automat (EA) by allowing its tape to serve as memory. It consists of:
- a finite control, containing the program and current state;
- a tape that is infinite to the right;
- a read/write head that can move one cell left, one cell right, or stay in place.
Cell contains the left boundary symbol . On input , the initial tape is
The symbol denotes a blank cell. The head initially scans . The left boundary cannot be overwritten, and the head cannot move to its left.
Figure 4.1: finite control, tape, and read/write head; book p. 95.
Formal definition
Following Definition 4.1, a TM is a 7-tuple
| Component | Meaning |
|---|---|
| Finite set of states | |
| Input alphabet, with | |
| Working alphabet: , , and | |
| Initial state | |
| Accepting state | |
| Rejecting state | |
| Transition function |
The transition function is
For a non-halting state , the instruction
means: read , replace it by , change the state to , and move according to .
boundary condition
There are no transitions from or : entering either state ends the computation. Acceptance and rejection do not require the head to be at a particular cell or to have read the entire input.
Configurations
A configuration records the current state, tape contents, and head position.
The state symbol is inserted immediately before the symbol currently scanned. For example,
describes state , tape contents , and a head scanning at position .
The start configuration on input is
Reading the notation
In , the tape contains and the head scans the third input symbol, . The symbol records the state; it is not written on the tape. Trailing blanks are usually omitted. For the empty input, is shorthand for , with the head still scanning .
Step relation
The one-step relation is
If the head scans , the four cases in the book are:
- Stay in place: if , then
- Move left: if , then
- Move right within the represented tape: if and , then
- Move right beyond the last represented cell: if , then
In the last case, the new cell already exists on the infinite tape; its blank symbol is now included in the finite description. The left-move rule applies only where a cell exists to the left, as guaranteed by the boundary condition.
Figure 4.3: (a) stay, (b) left, (c) right, and (d) right onto a previously unrepresented blank; book p. 98.
The reflexive and transitive closure means zero or more steps:
In particular, allows zero steps.
Computations and halting
A computation is a potentially infinite sequence of configurations in which each successive pair satisfies . A computation on input starts at and either continues forever or ends in a halting state.
| Outcome | Description |
|---|---|
| Accepting | Ends in |
| Rejecting | Ends in |
| Infinite | Never reaches either halting state |
Since is a function, each input determines exactly one computation. A non-accepting computation can be rejecting or infinite.
The language consists of all inputs accepted by . The languages that can be accepted by Turing machines are exactly the recursively enumerable languages.
Non-acceptance and rejection
Rejection means that the machine halts in . A machine that runs forever also fails to accept, but produces no rejecting answer. This distinction matters when defining decidability.
Computing functions
To compute a function , the book requires
Thus, for every input, the machine halts in , leaves directly after the boundary symbol, and returns the head to cell . The rest of the tape is blank.
A function is totally computable (total berechenbar) if a TM computes it in this sense.
Output convention
Recognizing a language only requires reaching on members; the head position and remaining tape contents are unrestricted. Computing requires the particular final configuration for every input.
Example: finding the middle symbol
Figure 4.5: the TM for ; book p. 101.
This example recognizes
These are exactly the words of odd length with a in the middle. For example, , , and belong to ; , , and every even-length word do not.
The machine uses
The product alphabet adds marked versions of each input symbol:
Stacked symbols
Each or is one tape symbol, written in stacked format. The upper entry preserves the original bit; the lower entry records a left-side mark or a right-side mark . It is not a binomial coefficient or a pair of adjacent cells.
Phase 1: check the length
Starting just to the right of , alternate between and whenever a bit is read:
After reading a prefix of even length, the state is ; after an odd-length prefix, it is . At the first blank, an even-length input is rejected. An odd-length input enters , with the head on its last bit.
Phase 2: mark from both ends
The machine repeatedly marks the rightmost unmarked bit with and the leftmost unmarked bit with . The unmarked interval shrinks by two per complete round, so an odd-length input eventually leaves one middle bit.
| State | Role |
|---|---|
| Mark the rightmost unmarked bit with , then move left | |
| Check whether an unmarked bit remains to its left | |
| Scan left to the -marked prefix or | |
| Mark the leftmost unmarked bit with | |
| Scan right to the -marked suffix | |
| Inspect the bit that has just been identified as the middle |
For , the marking and scanning transitions are
At the marked boundaries,
and
If encounters an -marked cell or immediately after the rightmost bit was marked, no unmarked bit remains. That newly -marked bit is the middle. The machine moves right and tests its preserved value:
The diagram omits unreachable argument pairs. They can be completed by transitions to while respecting the boundary condition.
Computation on
The length check gives
The marking rounds proceed as follows. This table summarizes tape regions; it does not display individual configurations.
| Complete rounds | Bits marked on the left | Unmarked interval | Bits marked on the right |
|---|---|---|---|
| None | None | ||
The remaining middle bit is marked with , inspected, and restored to :
Thus . Every scan is finite, and every completed marking round shrinks the unmarked interval. The machine therefore always halts and decides .
Finding the middle preserves the input
The and marks retain the original bits. The machine checks the middle bit without comparing the left and right halves. The original input can still be recovered by removing the marks.