A Multitape Turing Machine (TM) Is a 7-Tuple (Q, , , , Qs, Qaccept, Qreject), Where Q

Total Page:16

File Type:pdf, Size:1020Kb

A Multitape Turing Machine (TM) Is a 7-Tuple (Q, , , , Qs, Qaccept, Qreject), Where Q

COMPSCI 350FC/2005 1 COMPSCI 350 MATHEMATICAL FOUNDATIONS OF COMPUTER SCIENCE

Definition 6 (a) M is a k-tape Turing machine iff M is a 7-tuple (Q, , , , qs, qaccept, qreject), where Q, ,  are finite sets, and 1) Q is the set of states of the machine, 2)  is the input alphabet ( U, the blank symbol, ) 3) is the tape alphabet (U ,   ). 4) : Q1 x   Q x x {L, R}k is the machine’s transition function, where Q1 = Q – { qaccept, qreject }

5) qs Q is the start state, usually taken to be q0 or q1.

6) qaccept Q is the accept state, and 7) qreject Q is the reject state (qS ≠ qaccept ≠ qreject).

(b) M is a multitape Turing machine iff, for some k 1, M is a k-tape Turing machine.

The conventions regulating multitape Turing machines are as follows. A k-tape Turing machine begins in the start state qs looking at the left-most symbol of each tape, with the input placed on the left-hand side of the first of its k tapes and the other tapes blank, all of which are infinite to the right. The machine then updates what is on the tapes in accordance with its transition function . As with one-tape machines, the machine halts when it enters either state qaccept or qreject . If it never enters those states, the computation continues for ever.

Definition 7 M is a nondeterministic Turing machine iff M is a 7-tuple (Q, , ,

, qs, qaccept, qreject), where Q, ,  are finite sets, and 1) Q is the set of states of the machine, 2)  is the input alphabet ( U, the blank symbol, ) 3) is the tape alphabet (U ,   ). 4) : Q1 x   P (Q x x {L, R}) is the machine’s transition function, where Q1 = Q – { qaccept, qreject }

5) qs Q is the start state, usually taken to be q0 or q1.

6) qaccept Q is the accept state, and 7) qreject Q is the reject state (qS ≠ qaccept ≠ qreject).

The conventions regulating nondeterministic Turing machines are as follows. A nondeterministic Turing machine begins in the start state qs looking at the left-most symbol of the input, which is placed on the left-hand side of the tape. The machine then updates what is on the tape in accordance with its transition function making a nondeterministic choice as to which action it takes if there is more than one action it can take with respect to the state it is in and the symbol it is currently scanning. Eg if

 (q1, a) = {(q1, a, R), (q2, b, L)} the machine head can either write ‘a’ and go right into state q1 when scanning an a in state q1 OR it can write ‘b’ and go left into state q2. As with standard Turing machines, the machine halts when it enters either state qaccept or qreject . If it never enters those states, the computation continues for ever. COMPSCI 350FC/2005 2

We can define configurations (cfs) in the usual way, except that cfs for these machines can yield more than one successor cf. We say that a nondeterministic Turing machine M accepts a string w if there is SOME sequence of cfs, beginning with the start cf of M on w, such that each cf yields the next one and such that the last one is an accepting cf.

Equivalence results (Simulation Theorems).

Theorem 3 (a) To every multitape Turing machine there is an equivalent standard single tape Turing machine (ie, one which accepts the same strings, rejects the same strings, and fails to halt on the same strings). (b) To every nondeterministic Turing machine, there is an equivalent standard single tape machine (ie, one which accepts the same strings, rejects the same strings, and fails to halt on the same strings).

Proof: (a) Given a multitape machine M, we construct a standard single tape machine as follows: S: “On input w1 w2 w3 … wn , 1. First represent the contents of the k tapes as follows:

# w1 w2 w3 … wn # U # U # …# U # [The # is a delimiter to separate the contents of the different tapes. S must also keep track of the location of the heads on the different tapes. It does this by underlining the tape symbol s if s is the symbol being scanned on the tape in question. Think of the underlining as constituting a virtual head. The underlined symbols are simply new symbols that have been added to our tape alphabet for the simulating machine. (Sipser’s book uses dotted symbols.) At the start, all but the first tape is blank, hence the U’s.]

2. To simulate a move, S scans its tape from the first # to the (k+1)-st #, in order to determine the symbols under the virtual heads. Then S makes another pass to update the contents of the tape according to the way M’s transition function dictates.

[Thus if M directs the head on tape 1 to write a 1 and go right if it sees an 0; the head on tape 2 to write a 1 and go left if it sees a 0; and the head on tape 3 to write a 0 and go right if it sees a 1; and if the current contents on its three tapes are represented on the single tape of S as follows: #00011010#00#010# , then after the next update the contents on S’s single tape will be: #00111010#01#000# ]

3. If, during updating, S moves one of the virtual heads onto a #, that shows that M needs space to do its computation. In that case, S moves the # and everything between this # and the final # one cell to the right. This leaves it space to complete this step of the simulated computation.

4. If, during this simulation, M goes into the accept state, accept. If M rejects, COMPSCI 350FC/2005 3 reject. Otherwise, continue simulating M.”

By construction, S accepts exactly the strings that M accepts, rejects exactly those that M rejects, and fails to halt on exactly the ones that M fails to halt on.

(b) For the proof of (b), consult the book.

Corollary to Theorem 3: (a) (i) For all languages L, L is Turing-recognisable iff there is a multitape Turing machine that recognises L. (ii) For all languages L, L is Turing-decidable iff there is a multitape Turing machine that decides L (b) (i) For all languages L, L is Turing-recognisable iff there is a nondeterministic Turing machine that recognises L. (ii) For all languages L, L is Turing-decidable iff there is a nondeterministic Turing machine that decides L

The Church-Turing Thesis: Any effective algorithm can be implemented by a (standard) Turing machine. In particular, if L is a language for which there is an algorithm allowing us to pick out all and only the strings in the language, then L is Turing-recognisable. And if L is a language for which there is an algorithm allowing us to determine whether or not a string is in the language, then L is Turing-decidable.

Note that the Church-Turing Thesis is a thesis, not a theorem: it relates an intuitive, informal notion to a precisely defined notion. But there is a lot of evidence for the thesis. As we have already seen, machine models that appear more powerful like the multitape model and the nondeterministic model are in reality no more powerful. And there are a host of other formal definitions of the idea of an algorithm that have similarly been shown to be equivalent to the standard Turing machine model. The biggest current threat to the thesis is coming from the idea of quantum computers that, so some believe, have the ability to solve problems that cannot be solved by Turing machines. (For more information, see ‘The Church-Turing Thesis’, Stanford Encyclopedia of Philosophy, http://plato.stanford.edu/entries/church-turing/)

Encoding Turing machines and a Universal Turing Machine.

By a standard TM we mean a deterministic TM with a single tape that is infinite to the right only. Each standard TM has 7 components, Q, , , , qstart , qaccept , qreject . Since Q, , and  are finite, we could write these as as strings using the symbols in Q, , and and with parentheses, commas, and so on, as punctuation. But the set of all such strings would not then be a language over a single alphabet, since machines may have arbitrarily large state sets and tape alphabets. Instead, we must encode the states and symbols over a fixed alphabet. To do this, we adopt certain conventions, without loss of generality. Assume that there are fixed countably infinite sets Q= {qaccept , qreject , q1, q2, q3, ...} and  = {a1, a2, a3, ...}, such that for every Turing machine, the state set is a finite subset of Qand the tape alphabet (and hence also the input alphabet) is a finite subset of We can COMPSCI 350FC/2005 4 take the blank symbol U to be a designated member of , say a1. In addition, let the start state of every machine be the state q1.

We adopt the following correspondence g between the component symbols of a Turing machine and strings over the one-symbol alphabet {I}, which .  g() i+2 qi I qaccept I qreject II L I R II i+2 ai I

Note that no two members of Qare represented in the same way, nor are any two i i+2 member of , nor, of course, are L and R. (We could have assigned I rather than I to aI [there would have been no ambiguity] but chose to make the method of assignment to the alphabet-symbol exactly the same as for the state-symbols.) We encode Turing machines by using the 2-symbol alphabet {c, 1}. Suppose M is a

Turing machine (Q, , , , q1 , qaccept , qreject ), where

Q  Qand  In that case, Q can be written as

{qi1, qi2, qi3, ..., qik} (where i1 < i2 < ... < ik) and  as {aj1, aj2, aj3, ..., ajl } (where j1 < j2 < ... < jl). Note that since q1 is the start state for all machines, qi1, is always q1. Similarly,  can be written as {at1, at2, at3, ..., atm }. We can encode the different parts of the machine in terms of strings of c and I’s as follows:

= cg(qi1)cg(qi2)c ...cg(qik)c,

<> = cg(at1)cg(at2)c ...cg(atm)c,

<> = cg(aj1)cg(aj2)c ...cg(ajl)c.

We can also define the encoding of the start state, < q1 >, as g(q1), ie III, and similarly for and . (Since we are taking the start state q1 and the two halting states qaccept and qreject as fixed for all machines, these encodings don’t play a significant role.)

To define <> , we first define kl strings, Opr (call them transition strings), with 1≤ p ≤ k and 1 ≤ r ≤ l (there are kl strings since there are kl arguments for , one for each state-symbol pair). Given p and r, such a transition string encodes the operation of the transition function  on the state-symbol pair (qip , a jr ).

If we let  (qip , ajr ) = (qt, am, R), say, then we set Opr = cw1cw2cw3cw4cw5c , where w1 = g(qip), w2 = g(ajr), w3 = g(qt), w4 = g(am), and w5 = g(R).

(Example a: If M = (Q, , , , q1 , qaccept , qreject ), where

Q = {qaccept , qreject , q1},  = {a2, a5 , a7}, and  is as follows: i)  (q1 , a 2) = (q1, a5, R), ii)  (q1 , a 5) = (qreject, a5, R), and iii)  (q1 , a 7) = (qaccept, a5, R) then we have the following three transition strings O11 , O12, and O13, corresponding to i) — iii): COMPSCI 350FC/2005 5 3 4 3 7 2 O11 = cI cI cI cI cI c, 3 7 2 7 2 O12 = cI cI cI cI cI c, 3 9 7 2 O13 = cI cI cIcI cI c. These define the workings of the transition function.) Finally, we can write <> for a string that defines the entire transition function:

cO11O12 ... O1l O2lO22 ... O2l...Ok1Ok2 ...Oklc (Note that the encoding of the function of Example a is: ccI3cI4cI3cI7cI2ccI3cI7cI2cI7cI2ccI3cI9cIcI7cI2cc.) We can now define the encoding of machine M, < M >, as follows:

< M > = cc<>c<>c<>cccc

(as before, given that q1, qaccept, and qreject are fixed for all machines, their encodings don’t play a distinctive role, and we could have done without them when encoding machines). We now construct a Universal Turing machine U. This machine will use the encodings of Turing machines as programs which it will then simulate on certain inputs w to those other machines. Note that such inputs w will also be provided to U in encoded form, as follows. If w = w1...wn, where each wi   (and hence wi  ), then = cg(w1)c... cg(wn)c. In order for U to simulate the working of M on w, it receives as input , the concatenation of and .

Theorem 4 There is a universal Turing machine U (over the language  = {c, I}) such that, presented with as input, where M is a Turing machine and w a string over  U halts in the accept state if M accepts w, halts in the reject state if M rejects w, and doesn’t halt if M doesn’t halt on w. Proof: We construct a universal Turing machine U that is actually a three-tape machine, but since we know that every multitape machine can be simulated by a standard one-tape TM, we know that there is a standard TM that is equivalent to U (ie, accepts what U accepts, rejects what U rejects, and doesn’t halt when U doesn’t halt). The machine uses its three tapes as follows. The first tape contains the encoding of what is on M’s tape, the second tape contains the encoding of M itself (ie, ) and the third tape contains the encoding of the state of M at the current point in the simulated computation.

The machine is started with some string on its first tape and the other tapes blank. U then first moves onto the second tape, and moves to the left of the first tape. (Note that U can easily determine where ends and begins.) 3 U then copies the encoding of the start state q1 of M (that is, the string I ) to the third tape. U first determines whether w is a string over the input alphabet of M. If it isn’t, it enters qreject. If it is, U begins simulating the steps of the computation of M on w on the first tape. Between such simulated steps, U keeps the heads on the second and third tapes at the left ends of those tapes, and the head on the first tape scanning the c that begins the encoded version of the symbol that M would be scanning at the corresponding time. COMPSCI 350FC/2005 6 U now finds on its second tape a block of the form ccIicIjcIkcIlcImcc (representing a i transition) such that I is the string of I’s on the third tape (encoding the state qi-2 that M is in), and Ij is the string to the right of the current head position on the first tape

(encoding the symbol aj-2 that M would be scanning at this stage). U then changes the first tape accordingly, replacing Ij with Il, and moving left or right to the preceding or next block of I’s depending on whether m is 1 or 2 (ie, depending on whether Im represents the move L or R). U also puts Ik on the third tape, checking to see whether this is the encoding of state q accept or of qreject .(by checking to see if k = 1 or 2). If it is,

U halts in the appropriate state, ie, in qaccept if k = 1 and qreject.if k = 2. If the third tape does not contain the encoding of a halting state, U simulates another computational step by M. By construction, U accepts if M accepts w; rejects if M rejects w; and doesn’t halt on if M doesn’t halt on w.

Definition 8 Given sets A and B, we say that (i) A and B are equivalent (or: have the same cardinality or the same size) iff there is a bijective function f: A  B. (We sometimes also call such a function a [one-one] correspondence [between A and B].) (ii) A is finite iff either A is empty or is equivalent to {1, , n} for some natural number n. (iii) A is infinite iff A is not finite. (iv) A is countable iff either A is finite or is equivalent to N (where N = the set of natural numbers {1, 2, …}. (v) A is countably infinite iff A is countable and infinite. (vi) A is uncountably infinite iff A is infinite but not countable.

Theorem 5 a) The set of all Turing machines with input alphabets   is countably infinite;

b) the set of all Turing-recognisable languages over alphabets  is countably infinite. Proof: a) Consider all encodings of Turing machines. Replace ‘c’ by ‘2’ and ‘I’ by ‘1’. Then every such encoding becomes a string of 1s and 2s, and so represents a unique natural number in decimal notation. Call this the number code of such a . Only some natural numbers will be codes of the relevant machines, of course. Let m1 be the smallest such number, m2 the next smallest such number, and so on. Then we can let M1 be the machine with number-code m1, M2 be the machine with number-code m2, and so on. Hence the set of all such machines is countably infinite (ie, the same size as N): just take the function f(Mi) = i, which is clearly one- one and onto. b) Consider the sequence of languages (M1), (M2), ..., where (Mi), is the language recognised by Mi (the i-th machine in our listing of Turing machines). By removing languages from this sequence that have already occurred earlier in this sequence, w obtain a non-repeating sequence L1, L2, L3, ... of all and only Turing-recognisable languages. This shows that the set of all such languages is countably infinite.

(Similarly, by restricting machines M to machines with a fixed alphabet   , the same proof shows that the set of all Turing machines over input alphabet  and the set of all Turing-recognisable languages  are both countably infinite.) COMPSCI 350FC/2005 7

Theorem 6. The class of all languages (over some alphabet ) is uncountably infinite. Proof: Consider the set of all strings of length n. It is easy to prove, by induction, that there are 2n of these. We can now list all strings of length 0, then of length 1, then of length 2, etc, in standard lexicographic order as follows. Assume that we have a certain listing of the symbols of , so that we can talk about the first, second, etc, symbol of . We say that string v precedes string w in this lexicographic order if, for some j, the j-th symbol of v comes before the j-th symbol of w and for all i< j, the i-th symbol of v is the same as the i-th symbol of w. Let the listing of all strings over be w1, w2, w3, w4, .... Hence the class of all strings or words over  is countably infinite.

Now suppose, contrary to what we are trying to establish, that the class of all languages (over ) is countably infinite. Then we have a (one-one) correspondence between the class of all such languages and {1, 2, 3, }. For arbitrary n, let Ln be the language corresponding to n in this correspondence. We now construct a new language L as follows:

(*) For each i ≥ 1, put wi in L iff wi  Li (i.e., wi  L iff wi  Li

By construction, L is a language over and so L = Lk for some k  1. Then we can derive a contradiction as follows:

Either wk  Lk or wk  Lk. If wk  Lk, then since Lk = L it follows from (*) that wk 

Lk. But if wk  Lk then, again by (*), wk  L and so wk  Lk after all (since L = Lk).

Hence the assumption that the class of all languages over  is countably infinite results in a contradiction. It follows that the class of all languages over  is not countably infinite. Since it is certainly infinite, it must therefore be uncountably infinite.

Corollary: We already know from Theorem 5 that the class of all Turing- recognisable languages (over ) is only countably infinite. It immediately follows that there are languages over  that are NOT Turing-recognisable.

Recommended publications