
A Universal Turing Machine 1 Conventions and Preliminaries A Turing machine consists of an in¯nitely long tape divided into individual cells, a movable \head" to read and write characters on the cells, and a pro- gram that dictates how the head should react to the machine's potential tape con¯gurations. By convention, the leftmost cell on the tape always contains the special symbol B, which marks the edge of the tape. The remaining tape extends in¯nitely to the right, with each successive cell containing exactly one symbol from the ¯nite alphabet A = fB; a1; a2; : : : ; an; tg, where t is called a blank square. The Turing machine program invokes a ¯nite collection of Turing states Q = fq0; q1; : : : ; qk; qhg, where qh denotes the distinguished halting state. In each step of a computation, the Turing machine reads the symbol underneath its head, writes a symbol in the current cell, changes to a new Turing state, and ¯nally moves the head one cell to the left, right, or remains neutral. The details of this computation process are determined by the program. The input for the Turing machine is represented by the prepared initial pattern on the tape, and the output of the machine is given by the existing symbols on the tape when the machine reaches the halting state qh. We will assume that the input for any Turing machine is always ¯nite in the sense that to the right of some cell in the initial pattern, there will be an in¯nite string of blank cells. The output of the Turing machine may be interpreted in any way we like; we will not use the convention that the output consists only of those symbols residing to the left of the ¯rst blank. Ultimately, we will ¯nd this flexibility convenient when we both input and ¯nally read o® the output from our universal Turing machine. In addition to terminating upon reaching the halting state qh, a Turing machine will also halt if either the procedure for the current state and symbol pair (qi; aj) is not de¯ned in the program, or if the head falls o® the left end of the tape. We designate either of the last two cases to be an error, and we may consider the resulting output to be rubbish. It is also possible that the Turing program may not halt at all. By convention, we will assume that the Turing machine begins in the initial state q0, with the machine head covering the leftmost square, B. 1 Universal Turing Machine Jason Teutsch Formally, a program consists of a collection of transition functions (Q n fqhg) £ A 7! (Q n fq0g) £ A £ fL; N; Rg; where the codomain tells the Turing machine which state to change to, which symbol to write, and whether to move left, right, or neither (L, R, or N) when the machine head encounters a symbol while in a given state. We may thus think of a program as a collection of quintuples of the above form. By convention, the ¯rst line of the program describes what to do with initial state q0 and symbol B. A Turing program is best illustrated with an example. Consider the following program, which inputs a nonempty string without blanks from the alphabet A = ft; 1; 2; 3; Bg. This program outputs that same string with all of the 1's replaced with 2's, and changes the rightmost cell to a \3": hq0; Bi 7! hq0; B;Ri hq0; 1i 7! hq0; 2;Ri hq0; 2i 7! hq0; 2;Ri hq0; 3i 7! hq0; 3;Ri hq0; ti 7! hq1; t;Li hq1; 1i 7! hqh; 3;Ni hq1; 2i 7! hqh; 3;Ni hq1; 3i 7! hqh; 3;Ni Proposition 1.1 Each Turing machine can be encoded by a distinct, ¯nite string of 1's and 0's. Proof: Let M be a Turing machine with alphabet A = fa1; : : : ; ang, Turing states Q = fq0; q1; : : : ; qk; qhg, and individual program line quintuples ¢ = f±1; : : : ; ±rg. De¯ne the unary representation of a natural number n to be the length-n string of 1's, 11| {z::: 1}. We assign a distinct unary representation n to every symbol from the alphabet, including the auxiliary symbols t and B, as follows: t is 1, a1 is 11, a2 is 111, . 2 Universal Turing Machine Jason Teutsch an is| 1 :::{z 1}, and n+1 B is 1| :::{z 1} : n+2 Similarly, we can ¯nd a unary representation for each element in Q: q0 is 1, q1 is 11, . qn is 1| :::{z 1}, and n+1 qh is 1| :::{z 1}. n+2 We will code the direction symbols L, N, and R by 1, 11, and 111, respec- tively. We can thus represent any program line quintuple as a string of 1's and 0's by attaching the unary representation of each element in the ordered tuplet end-to-end, with a 0 to mark the separation between each element in the series. Finally, we can represent the entire series of program lines ¢ as a string of 1's and 0's by writing 00 as a separator between each quintuplet of the Turing program. The Turing machine from the example above thus corresponds to the following sequence of 1's and 0's: 1011111010111110111001011010111011100101110101110111001011110101111011100 101011010100110110111011110110011011101110111101100110111101110111101100. The sequence of 0's and 1's corresponding to a particular Turing machine is called the Turing number of that machine.¥ Corollary 1.2 There are countably many Turing machines. Proof: There are only countably many ¯nite strings of 0's and 1's.¥ 2 Tools We will need to code a few subroutines for use in the construction of our universal Turing machine. 3 Universal Turing Machine Jason Teutsch Lemma 2.1 (copying machine) Let X and Y be symbols on a tape, with X lying to the left of Y and only blanks and 1's written on the cells in between. Assume that the head of the Turing machine is initially covering the cell containing X. Then there is a Turing program that counts the number of contiguous 1's sitting to the immediate right of Y and pastes that same number of 1's to the right of X. We will assume that we start with su±cient blank cells to the right of X to contain the intended string of 1's. This copying process may also be implemented in the reverse direction, from X to Y . Proof: Let X and Y be as above, and let B be a symbol in the alphabet that is distinct from X, Y , t, and 1. The symbol B will be used to keep track of how many cells have been copied. The symbols X and Y will remain stationary throughout this construction. That is, X and Y will be neither written nor erased. The algorithm is as follows: Step 1: Move to the right and stop at the ¯rst 1. Mark this cell with a B. (If no \1" is found, that is, we reach either Y or a blank cell, go to Step 4.) Step 2: Move to the right and stop at the ¯rst blank cell beyond Y . Write a 1 in this cell. Step 3: Move back to the left until the ¯rst B is encountered, then go to Step 1. Step 4: Move to the left, changing B's into 1's until the symbol X is reached, at which point halt. The following time diagram illustrates a sample copy process. Lines (a){ (d) in the sequence shows the tape status at the beginning of Step 1, and the underlined character indicates the position of the the tape head at that moment: (a) 1 X 1 1 1 t 1 1 Y t t t t 1 (b) 1 XB 1 1 t 1 1 Y 1 t t t 1 (c) 1 XBB 1 t 1 1 Y 1 1 t t 1 (d) 1 XBBB t 1 1 Y 1 1 1 t 1 (e) 1 X 1 1 1 t 1 1 Y 1 1 1 t 1 The steps in this process suggest formal program lines for our Turing machine: 4 Universal Turing Machine Jason Teutsch hq0;Xi 7! hq0; X; Ri hq0; 1i 7! hq1; B; Ri hq0; ti 7! hq4; t;Li hq0;Y i 7! hq4; Y; Li hq0;Bi 7! hq0; B; Ri hq1; 1i 7! hq1; 1;Ri hq1; ti 7! hq1; t;Ri hq1;Y i 7! hq2; Y; Ri hq2; 1i 7! hq2; 1;Ri hq2; ti 7! hq3; 1;Li hq3; 1i 7! hq3; 1;Li hq3;Y i 7! hq3; Y; Li hq3;Bi 7! hq0; B; Ni hq4;Xi 7! hqh; X; Ni hq4;Bi 7! hq4; 1;Li ¥ Lemma 2.2 (matching machine) Let X and Y be symbols on a tape, with X lying to the left of Y and only blanks and 1's written on the cells in between. Assume that the head of the Turing machine is initially covering the cell containing X. Then there is a Turing program that compares the number of contiguous 1's sitting to the right of X to the number of contiguous 1's sitting to the right of Y . If these two quantities are the same, then the program terminates in one state. If they are di®erent, then it terminates in another. Proof: Let X and Y be as above, and, as in Lemma 2.1, let B be a symbol in the alphabet that is distinct from X, Y , t, and 1.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages11 Page
-
File Size-