Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 91.304 Foundations of (Theoretical) Computer Science Chapter 3 Lecture Notes (Section 3.1: Turing Machines) David Martin With some modifications.

Similar presentations


Presentation on theme: "1 91.304 Foundations of (Theoretical) Computer Science Chapter 3 Lecture Notes (Section 3.1: Turing Machines) David Martin With some modifications."— Presentation transcript:

1 1 91.304 Foundations of (Theoretical) Computer Science Chapter 3 Lecture Notes (Section 3.1: Turing Machines) David Martin dm@cs.uml.edu With some modifications by Prof. Karen Daniels, Fall 2009 This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by- sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

2 2 “Manners are not taught in lessons,” said Alice. “Lessons teach you to do sums, and things of that sort.” “And you do Addition?” the White Queen asked. “What's one and one and one and one and one and one and one and one and one and one?” “I don't know,” said Alice. “I lost count.” “She can't do Addition,” the Red Queen interrupted. Excerpt: Through the Looking Glass, Lewis Carroll

3 3 Turing machine syntax  Definition A Turing Machine is an automaton M=(Q,,,,q 0,q acc,q rej ) where 1.Q is a finite set of states 2.  is an input alphabet that does not include " t ", the special blank character 3.  is a tape alphabet satisfying 1. t 2  2.  µ  4. :Q £  ! Q £  £ {L,R} is the transition function 5.q 0 is the initial state 6.q acc is the single accepting state 7.q rej is the single rejecting state

4 4 Differences in input mechanism  A TM has a "tape head" that points to exactly one cell on its tape, which extends infinitely to the right At each transition, the TM looks at the current state and the current cell, and decides what new state to move to, what to write on the current cell, and whether to move one cell to the left or one cell to the right Hence the transition function :Q £  ! Q £  £ {L,R}  Each tape cell initially contains the blank character t  Our previous automata (DFAs, NFAs, PDAs) all had a separate read-only input stream  But in a TM, the input is given all at once and just written onto the left end of the tape — overwriting the blanks there a | b | a | b | a | b | t | t | t | t | t | t | t |  in state q 7

5 5 Turing machine computation  As with PDAs, we define a set of instantaneous descriptions (IDs) and then show what memory-state snapshots may follow each other, according to the program M.  First, the snapshots: in a TM, ID(M) =  * Q  * Each element of this set represents the entire tape contents, the current state, and the location of the tape head In example below, the ID is ab q 7 a bab tt  So the character to the right of the state name is the "current" character The tape always has infinitely many blanks on the right; we can write them or omit them as we please a | b | a | b | a | b | t | t | t | t | t | t | t |  in state q 7

6 6 Turing machine computation  Two IDs are related to each other (by ` ) if one can lead to the other according to the  function  So we look at all of the things that  can say, starting with right moves: Suppose (q,b) = (t,c,R) where  R means "right move"  q 2 Q - {q acc, q rej } and b 2 (states in green)  t 2 Q and c 2  Then u qb v ` u ct v where u,v 2  * are undisturbed, the state has changed from q to t, the tape cell has changed from b to c, and the head has moved one character to the right (over the now-changed character)

7 7 Turing machine computation  Left moves Suppose (q,b) = (t,c,L) where  q 2 Q - {q acc, q rej } and b 2 (states in green)  t 2 Q and c 2  Then ua qb v ` u tac v where u,v 2  * and a 2  are undisturbed, the state has changed from q to t, the tape cell has changed from b to c, and the head has moved one character to the left This says that one ID can lead to another ID when  says to move left and there is a character a 2  to the left. What if there is no such character?

8 8 Turing machine computation  Left moves at left edge of tape Suppose (q,b) = (t,c,L) where  q 2 Q - {q acc, q rej } and b 2 (states in green)  t 2 Q and c 2  Then qb v ` tc v where v 2  * is undisturbed, the state has changed from q to t, the tape cell has changed from b to c Where does this put the tape head in this case?  Note we have not explicitly covered the case where (q,b) = (t,c,L) and q 2 {q acc,q rej } Or when we move R instead of L Conclusion: well, if the current ID is u qb v and q 2 {q acc,q rej }, then no "next ID" is possible. We say that the TM halts

9 9 Some Ways to Describe Turing Machine Computation  Implementation-level description  Instantaneous descriptions (IDs) specifying snapshots of tape and read-write head position as computation progresses.  Formal description (7-tuple)  Detailed state diagram.  We’ll discuss all 4 ways using Turing machine M 1 in textbook (p. 138, 139, 145) for language:  We’ll also discuss Turing machine M 2 in textbook (p. 143, 144) for language:

10 10 Implementation-Level Description

11 11 Instantaneous Descriptions (Snapshots) Sample Input: 011000#011000

12 12 8 Formal Description and Detailed State Diagram

13 13 Detailed State Diagram

14 14 Implementation-Level Description

15 15 Formal Description (7-tuple)

16 16 Instantaneous Descriptions (Snapshots) Sample Input: 0000

17 17 Detailed State Diagram

18 18 Language recognized by TM  Finally, we let ` * be the transitive, reflexive closure of `. So if  and  are IDs, the statement  ` *  means "the TM can go from  to  in 0 or more steps"  The language recognized by M is L(M) = { x 2  * | q 0 x ` * u q acc v for some u,v 2  * }  Translation?  Note x 2  *, not  *

19 19 TM language classes  Definition A language L is Turing- recognizable if there exists a TM M such that L = L(M). Synonym: L is recursively enumerable, abbreviated "r.e."  Definition The class of all Turing- recognizable languages is  1 = { L µ  * | L is Turing-recognizable } The textbook does not assign a name like this; it just says "class of TM-recognizable langs" Beware: The class  1 is not an alphabet like  The naming is unfortunate but better than some of the alternatives

20 20 Deciders  We've seen that when you start a TM with an input x, it can do three distinct things: Accept x Reject x Run forever without accepting or rejecting x  We call this "looping" -- meaning that the TM runs forever. (The "loop" might not be so simple, the point is it runs forever.)  Some TMs always accept or reject and never loop on any input whatsoever. You could easily write an example of one. A TM with this property is called a decider. A decider always halts on every input

21 21 Decidable languages  Definition A language is decidable if there exists a decider TM M such that L = L(M) Synonyms: L is "computable" and "recursive" It is in general not easy to tell if a language is decidable or not  Definition The class of all Turing- decidable languages is  0 = { L µ  * | L is Turing-decidable} Note  0 (decidable) versus  1 (recognizable) versus  (alphabet)

22 22 Decidable versus recognizable  Fact (obvious)  0 µ  1 Every decider is automatically a recognizer too  Fact (not at all obvious)  0   1 This means that there exists some language H 2  1 -  0  H is a language that can be recognized by some TM, but can't be recognized by any TM that always halts!  Fact (not at all obvious)  1  ALL This means that there exists some language H 2 2 ALL -  1  H 2 is a language that can't even be recognized by any TM

23 23 Ultimately ALL FIN Each point is a language in this Venn diagram REG RPP CFL CFPP 00 11

24 24 Reminder  The decidable languages:  0  The recognizable languages:  1

25 25 Closure properties of  0 and  1   1 is closed under [, Å, ¢, ¤, reversal Proofs for [ and Å are similar to the NFA constructions we used, if you use a 2- tape TM Proof for reversal is also easy with a 2- tape TM ¢ and ¤ are somewhat harder   0 is closed under all of these operations and complement as well

26 26  0 closed under complement Proof Suppose L 2  0. Then L=L(M 1 ) for some decider M 1. We want to show there's a decider M 2 such that L(M 2 ) = L c, whence (!) L c 2  0. This is easy: we just set M 2 to be M 1 with q acc and q rej swapped. This works because M 1 never loops (forever) on any input; it always reaches either q acc or q rej, and so M 2 does the opposite thing from M 1 in terms of accepting or rejecting the string.

27 27 Proof does not work for  1  Without the guarantee that M 1 never loops on any input, this conversion does not produce an M 2 such that L(M 2 ) = L(M 1 ) c.  Because if x L(M 1 ), we want x 2 L(M 2 ), but... 2

28 28 Preview:  1 is not closed under complement  The previous discussion just showed that the attempted proof of closure under complement failed It didn't show that  1 is not closed under complement However it is in fact true that  1 is not closed under complement

29 29 Preview: a non-recognizable L  This all means that some L exists that is not recognized by any TM What does it look like? Is it important? YES, because of Church-Turing Thesis  Intuitive notion of algorithms = Turing machine algorithms  To be defined and discussed in Section 3.3


Download ppt "1 91.304 Foundations of (Theoretical) Computer Science Chapter 3 Lecture Notes (Section 3.1: Turing Machines) David Martin With some modifications."

Similar presentations


Ads by Google