Chapter6 Turing Machines 6.1The Standard Turing Machine Definition 1.1 A Turing machine is a quintuple M = (Q, , , , q0 ) where Q is a finite set of states, is a finite set called the tape alphabet, contains a special symbol B that represents a blank, is a subset of {B} called the input alphabet, is a partial function from Q to Q {L, R} called the transition function, and q0 Q is a distinguished state called the start state. 6.1.1 Notation for the Turing Machine We may visualize a Turing Machine as in fig 23. The machine consists of a finite control, which can be in any of a finite set of states. There is a tape divided into squares or cells; each cell can hold any one of a finite number of symbols. Initially, the input, which is a finite length string of symbols chosen from the input alphabet, is placed on the tape. All other tape cells, extending infinitely to the left and right, initially hold a special symbol called the blank. The blank is a tape symbol, and there may be other tape symbols besides the input symbols and the blank, as well. There is a tape head that is always positioned at one of the tape cells. The Turing Machine is said to be scanning that cell. Initially, the tape head is at the left-most cell that holds the input. A move of the Turing Machine is a function of the state of the finite control and the tape symbol scanned. In one move, the Turing Machine will: 1. Change state. The next state optionally may be the same as the current state. 2. Write a tape symbol in the cell scanned. This tape symbol replaces whatever symbol was in that cell. Optionally, the symbol written may be the same as the symbol currently there. 3. Move the tape head left or right. In our formalism we require a move, and do not allow the head to remain stationary. This restriction does not constrain what a Turing Machine can compute, since any sequence of moves with a stationary head could be condensed, along with the next tape head move, into a single state change, a new tape symbol, a move left or right. Figure 23: A Turing Machine Turing machines are designed to perform computations on strings from the input alphabet. A computation begins with the tape head scanning the leftmost tape square and the input string beginning at position one. All tape squares to the right of the input string are assumed to be blank. The Turing machine defined with initial conditions as described above, is referred to as the standard Turing machine. A language accepted by a Turing machine is called a recursively enumerable language. A language accepted by a Turing machine that halts for all input strings is said to be recursive. Example 1.1 The Turing machine COPY fig 24 with input alphabet a, b produces a copy of the input string. That is, a computation that begins with the tape having the form BuB terminates with tape BuBuB . Figure 24: Turing Machine COPY 6.2 Turing Machines as Language Acceptors Example 2.1 The Turing machine accepts the language (a b)* aa(a b)* . The computation q0 BaabbB | Bq1aabbB | Baq 2 abbB | Baaq3bbB examines only the first half of the input before accepting the string aabb. The language (a b)* aa(a b)* is recursive; the computations of M halt for every input string. A successful computation terminates when a substring aa is encountered. All other computations halt upon reading the first blank following the input. Figure 25: TM accepting (a b)* aa(a b)* Example 2.2 The language {a i bi c i | i 0} is accepted by the Turing machine in fig 26. Figure 26: TM accepting a i b i c i A computation successfully terminates when all the symbols in the input string have been transformed to the appropriate tape symbol. 6.3 Alternative Acceptance Criteria Definition 3.1 Let M = (Q, , , , q0 ) be a Turing machine that accepts by halting. A string u * is accepted by halting if the computation of M with input u halts (normally). Theorem 3.1 The following statements are equivalent: i. The language L is accepted by a Turing machine that accepts by final state. ii. The language L is accepted by a Turing machine that accepts by halting. Proof: Let M = (Q, , , , q0 ) be a Turing machine that accepts L by halting The machine M ' = (Q, , , , q0 , Q) in which every state is a final state, accepts L by final state. Conversely, let M = (Q, , , , q0 , F ) be a Turing machine that accepts the language L by final state. Define the machine M ' = (Q q f , , , ' , q0 ) that accepts by halting as follows: i. If (qi , x) is defined, then ' (qi , x) = (qi , x) . ii. For each state qi Q F , if (qi , x) is undefined, then ' (qi , x) = [q f , x, R] . iii. For each x , ' (q f , x) = [q f , x, R] . Computations that accept strings in M and M ' are identical. An unsuccessful computation in M may halt in a rejecting state, terminate abnormally, or fail to terminate. When an unsuccessful computation in M halts, the computation in M ' enters the state q f . Upon entering q f , the machine moves indefinitely to the right. The only computations that halt in M ' are those that are generated by computations of M that halt in an accepting state. Thus L( M ' ) = L( M ) . 6.4 Multitrack Machines A multitrack tape is one in which the tape is divided into tracks. Multiple tracks increase the amount of information that can be considered when determining the appropriate transition. A tape position in a two-track machine is represented by the ordered pair [x, y], where x is the symbol in track 1 and y in track 2. The states, input alphabet, tape alphabet, initial state, and final states of a two-track machine are the same as in the standard Turing machine. A two-track transition reads and rewrites the entire tape position. A transition of a two-track machine is written (qi , [ x, y]) = [q j , [ z , w], d ] , where d {L, R} . The input to a two-track machine is placed in the standard input position in track 1. All the positions in track 2 are initially blank. Acceptance in multitrack machines is by final state. Languages accepted by two-track machines are precisely the recursively enumerable languages. Theorem 4.1 A language L is accepted by a two-track Turing machine if, and only if, it is accepted by a standard Turing machine. Proof: Clearly, if L is accepted by a standard Turing machine it is accepted by a twotrack machine. The equivalent two-track machine simply ignores the presence of the second track. Let M = (Q, , , , q0 , F ) be a two-track machine. A one-track machine will be constructed in which a single tape square contains the same information as a tape position in the two-track tape. The representation of a two-track tape position as an ordered pair indicates how this can be accomplished. The tape alphabet of the equivalent one-track machine M ' consits of ordered pairs of tape elements of M . The input to the two-track machine consists of ordered pairs whose second component is blank. The input symbol a of M is identified with the ordered pair [a, B]ofM ' . The one-track machine. M ' = (Q, {B}, , ' , q0 , F ) with transition function ' (qi , [ x, y ]) = (qi , [ x, y]) accepts L (M ) . 6.5 Two-Way Tape Machines A Turing machine with a two-way tape is identical to the standard model except that the tape extends indefinitely in both directions. Since a two-way tape has no left boundary, the input can be placed anywhere on the tape. All other tape positions are assumed to be blank. The tape head is initially positioned on the blank to the immediate left of the input string. 6.6 Multitape Machines A k -tape machine consists of k tapes and k independent tape heads. The states and alphabets of a multitape machine are the same as in a standard Turing machine. The machine reads the tapes simultaneously but has only one state. This is depicted by connecting each of the independent tape heads to a single control indicating the current state. A transition is determined by the state and symbols scanned by each of the tape heads. A transition in a multitape machine may i. change the state ii. write a symbol on each of the tapes iii. independently reposition each of the tape heads. The repositioning consists of moving the tape head one square to the left or one square to the right or leaving it at its current position. The input to a multitape machine is placed in the standard position on tape 1. All the other tapes are assumed to be blank. The tape heads origanlly scan the leftmost position of each tape. Any tape head attempting to move to the left of the boundary of its tape terminates the computation abnormally. Any language accepted by a k -tape machine is accepted by a 2 k + 1-track machine. Theorem 6.1 The time taken by the one-tape TM N to simulate n moves of a k -tape TM M is O(n 2 ) 6.7 Nondeterministic Turing Machines A nondeterministic Turing machine may specify any finite number of transitions for a given configuration. The components of a nondeterministic machine, with the exception of the transition function, are identical to those of the standard Turing machine. Transitions in a nondeterministic machine are defined by a partial function from Q to subsets of Q {L, R} . Language accepted by a nondeterministic Turing machine is recursively enumerable. 6.8 Turing Machines as Language Enumerators Definition 8.1 A k -tape Turing machine E = (Q, , , , q0 ) enumerates a language L if i. ii. the computation begins with all tapes blank with each transition, the tape head on tape 1(the output tape) remains stationary or moves to the right iii. at any point in the computation, the nonblank portion of tape 1 has the form B # u1 # u2 # # uk # or B# u1 # u2 # # uk # v , where ui L and v * iv. u will be written on the o/p tape 1 preceded and followed by # if, and only if, u L . Example 8.1 The machine E enumerates the language L = {a i bi c i | i 0} . Figure 27: A k-tape TM for L = a i b i c i Lemma 8.1 If L is enumerated by a Turing machine, then L is recursively enumerable. Proof: Assume that L is enumerated by a k -tape Turing machine E . A k +1-tape machine M accepting L can be constructed from E . The additional tape of M is the input tape; the remaining k tapes allow M to simulate the computation of E . The computation of M begins with a string u on its input tape. Next M simulates the computation of E . When the simulation of E writes # , a string w L has been generated . M then compares u with w and accepts u if u = w . Otherwise, the simulation of E is used to generate another string from L and the comparision cycle is repeated. If u L , it will eventually be produced by E and consequently accepted by M. Chapter 7 The Chomsky Hierarchy 7.1 The Chomsky Hierarchy Grammars Languages Accepting Machines Type 0 grammars, Recursively Turing Machine, phrase-structure grammars, unrestricted grammars enumerable nondeterministic languages Turing Machine Type 1 grammars, Context-sensitive Linear-bounded context-sensitive grammars, monoatonic grammars languages automata Type 2 grammars, Context-free Pushdown automata context-free grammars languages Type 3 grammars, Regular languages Deterministic finite regular grammars, automata, left-linear grammars, nondeterministic right-linear grammars finite automata