Writing Turing machines directly is laborious, but a few techniques make it systematic. This lesson presents them and proves that several natural extensions of the model compute no new functions.
3.1 Auxiliary symbols: a doubling machine
The alphabet may contain symbols other than and . They serve as markers recording which part of the input has already been processed. As an example, we compute . On input with , the output must be .
The machine works in two phases. In the first phase, it repeatedly replaces the leftmost unmarked by and appends a to the right end of the tape contents. After rounds the tape contains . In the second phase, it turns every into , erases the last symbol, and moves left turning every into . The alphabet is :
| — | — | |||
| — | ||||
| — | ||||
| — | — | |||
| — | — | — | ||
| — |
Entries marked — are never used; to make total, set them to , say.
This machine computes .
Let . We show by induction on that the machine reaches the configuration in state with tape written from cell and the head on cell . For this is the initial configuration. Suppose it holds for some . Cell contains : the machine writes and enters , which moves right across to the first blank, at cell , writes there, and enters . In state the head moves left across s and s until it reaches the on cell , and enters on cell . The tape is now , as required.
For , the tape is and the head scans the first , on cell , in state . The machine writes and enters , which turns the remaining s into s and reaches the blank on cell . It then erases cell , which contains , and enters on cell . Note that . State moves left, turning s and s into s, down to cell , and halts on cell . The final tape is on cells , that is .
3.2 Translation invariance
The behavior of a machine depends only on the relative position of the head and the symbols. Formally, for a tape and , let be the translated tape .
If , then for every . Consequently, the computation from a translated configuration is the translation of the original computation, and halts after the same number of steps.
The symbol scanned in the translated configuration is , so the same transition is applied. The new tape coincides with except at where it contains , which is exactly , and the new head position is . The second statement follows by induction on the number of steps.
3.3 Sequential composition
The standard final configuration of a machine is, up to translation, an initial configuration on the output. This allows us to run machines one after the other.
Let and be Turing machines computing and . There is a Turing machine computing .
By Exercise 3.4 below, we may assume that every halting computation of on an input ends in a standard final configuration.
Rename the states of so that they are disjoint from those of , and take the union of the alphabets. The machine has the states of both machines, initial state , halting state , and the transitions of both machines, except that every transition of entering is redirected to . The state is no longer entered; its transitions, now required since it is not the halting state of , are set arbitrarily. Entries for symbols of one machine absent from the alphabet of the other are set arbitrarily; they are never used, since only sees its own symbols, and is started on a tape containing only and .
On input , the machine first behaves like . If , then does not halt, and neither does . If , then enters with a tape containing exactly , starting at the head position . This is the initial configuration of on input , translated by . By Lemma 3.2, the remaining computation is the translation by of the computation of on input . Since translations preserve standard final configurations, halts in a standard final configuration with output if , and otherwise it does not. Hence computes .
Show that for every machine there is a machine with such that every halting computation of on an input ends in a standard final configuration.
Hint
Let maintain two end markers delimiting the part of the tape visited so far, and check, before halting, whether the tape between the markers has the form of an output.
Solution
Let first write a marker on cell and a marker after the input, then simulate . Whenever the simulated head reaches a marker, the marker is moved one cell further (shifting it is easy since it is at the end of the visited zone), and the cell it occupied is treated as blank. When would enter , instead enters a checking phase: it records whether the scanned cell holds a preceded by a blank, then scans the zone between the markers and verifies that it contains exactly one block of s, starting at the remembered position, and blanks elsewhere. If the check succeeds, it erases the markers, returns to the first , and halts. If it fails, it enters a state which moves right forever. Then halts only in standard configurations, and does so exactly when halts in a standard configuration, with the same output.
Composition with functions of several arguments, such as , can be handled similarly, using a machine that copies its input. The details are tedious and teach little. We will obtain closure under composition much more easily from the equivalence with the recursive functions, proved later in this course.
3.4 Multi-tape machines
A natural extension gives the machine several tapes, each with its own head.
A -tape Turing machine is defined as in Definition 2.1, except that the transition function has the form
where means that the head stays in place. A configuration consists of a state, tapes and head positions. By convention all heads start on cell , the input is written on tape as in Definition 2.4, the other tapes are initially blank, and the output is read on tape : the machine computes if it halts with tape and head in a standard final configuration with output , whatever the contents of the other tapes.
Multi-tape machines are much easier to program. For instance, a -tape machine can copy its input to tape in a single left-to-right pass.
Every partial function computed by a -tape Turing machine is computed by a -tape Turing machine.
Let be a -tape machine with alphabet . The idea is to store the tapes on tracks of a single tape. Let the new alphabet be : a cell of the simulating machine contains either a symbol of , or a -tuple of pairs where is the content of the corresponding cell of tape and indicates that the head of tape is at this cell. This alphabet is finite.
first converts cell into this format: it replaces the symbol there by , since all heads of start on cell . Then simulates each step of as follows. The state of is stored in the state of . sweeps over the zone of the tape visited so far, from left to right, and collects in its state the symbols under the marked heads; there are finitely many possibilities, so they can be stored in the state. Knowing the state of and the scanned symbols, determines the transition of . It then sweeps back from right to left, updating the symbol under each marked head and moving each mark by one cell according to the transition. When a mark must move onto a cell containing a plain symbol of — a cell that no head has visited yet — first replaces it by ; this is the correct content, since an unvisited cell of tape still holds its input symbol and an unvisited cell of another tape is blank. Since all heads start on cell and move by one cell at a time, the converted cells always form an interval containing , bordered by plain symbols, so recognizes the ends of the zone it must sweep. When halts, converts the tape back, keeping only track , moves the head to the position of head , and halts.
By induction on the number of steps, after the simulation of steps of , the tracks of contain the tapes of after steps, with the heads correctly marked, and the cells outside the converted zone hold the unvisited part of tape . Hence, if halts, the final tape and head position of are those of tape of , so halts in a standard final configuration exactly when does, with the same output; and if does not halt, neither does .
3.5 Other variants
The same method — encode the richer structure on one tape, simulate step by step — shows that the following variants compute exactly the Turing-computable functions:
- machines whose tape is infinite only to the right (fold the two-way tape on itself, using two tracks);
- machines with a two-dimensional tape (store the finite non-blank region row by row);
- machines with the alphabet only (encode each symbol of a larger alphabet by a fixed-length block of and );
- non-deterministic machines, where is a relation, and a function value is accepted if some computation produces it, provided the function is well defined (simulate all computations in breadth-first order, using a third tape).
Some care is needed with the input and output conventions in each case, but no new idea.
3.6 Exercises
Design a -tape machine computing , and prove it correct.
Solution
Erase the input from left to right, alternating between two states (even number of s erased so far) and (odd). Since has ones, at the first blank the state is if is even and if is odd. In state at the blank, write a single (output ); in state , write , move right, write , move left (output ). Then halt with the head on the first . A formal proof proceeds by induction on the number of erased cells, as in Proposition 3.1.
Describe a -tape machine computing , and estimate its number of steps.
Solution
Use an auxiliary symbol and a marker . First copy to tape without its last , starting on cell , erasing it from tape , and replace the last of (cell ) by . Now tape holds on cells , tape holds ones on cells , and the output will be built on tape from cell on. Each round starts with head on the leftmost of the first block and head on cell : replace this by , move head right past to the first blank after the output zone, then move both heads right together while head reads , writing a with head at each step; finally return head to cell , and head left to the rightmost and one cell further right. When head starts a round on , all rounds are done and the output zone holds ones: append one more (unary convention), go back to cell , and move right erasing the s and , halting on cell , the first cell of . The contents of tape do not matter. The first phase takes steps, and each round steps, since head crosses the output zone twice; the total is steps.
3.7 Notes and references
The simulation of multi-tape machines by single-tape machines, with a quadratic slowdown, is due to Hartmanis and Stearns, who used it in the foundational paper of complexity theory. The study of such simulations and of their cost belongs to complexity theory, where the robustness of the class of polynomial-time computable functions plays the role that the robustness of the computable functions plays here.
- J. Hartmanis, R. E. Stearns, On the computational complexity of algorithms, Transactions of the American Mathematical Society 117 (1965), 285–306.
- M. Sipser, Introduction to the Theory of Computation, 3rd edition, Cengage, 2012, chapter 3.