Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 91.304 Foundations of (Theoretical) Computer Science Chapter 5 Lecture Notes David Martin (with modifications by Karen Daniels) With thanks.

Similar presentations


Presentation on theme: "1 91.304 Foundations of (Theoretical) Computer Science Chapter 5 Lecture Notes David Martin (with modifications by Karen Daniels) With thanks."— Presentation transcript:

1 1 91.304 Foundations of (Theoretical) Computer Science Chapter 5 Lecture Notes David Martin (with modifications by Karen Daniels) dm@cs.uml.edu With thanks to Giam Pecelli 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 Computation Histories  Recall the notion of configuration: (state, head_position, tape_contents).  In a deterministic TM every transition takes us from one configuration to the next.  The idea of "computation history" is based on sequences of configurations.

3 3 Computation Histories Definition 5.5: Let M be a TM and w a string: -An accepting computation history for M on w is a sequence of configurations C 1, C 2, …, C k, where C 1 is the start configuration of M on w, C k is an accepting configuration of M, and each C i ` C i+1 according to the rules of M. -A rejecting computation history for M on w is defined similarly, except that C k is a rejecting configuration for M.

4 4 Computation Histories Definition 5.6: A linear bounded automaton is a standard TM whose tape head is not allowed to move beyond the tape squares containing the input. Note: If the tape alphabet is larger than the input alphabet, the available memory can be increased by a constant factor - but the amount of memory remains a linear function of the length of the input.

5 5 Linear Bounded Automata  Example: (board work)  They are powerful: the following are LBAs: Decider for A DFA Decider for A CFG Decider for E DFA Decider for E CFG  Every CFL can be decided by an LBA.

6 6 Computation Histories Why bother? LBAs can be shown sufficient for the recognition of almost all "realistic" classes of languages, in particular CFLs: -roughly, your C program will compile (actually, parse, but who's counting?) in a ("small") constant multiple of the number of bytes necessary to store it in memory. Definition: A LBA = { h M, w i | M is an LBA that accepts w} Question: is A LBA decidable? The "general" problem (A TM ) is not…

7 7 Computation Histories Lemma 5.8: Let M be an LBA with q states and g symbols in the tape alphabet. Then there are exactly q*n*g n distinct configurations of M for a tape of length n. Proof. A configuration is uniquely determined 1. by the state M is in (q possibilities), 2. by the head position (n possibilities) and 3. by the tape contents (g n possibilities: g possibilities for each of the n tape positions).

8 8 Computation Histories Theorem 5.9. A LBA is decidable. Proof. We construct the following TM D: 1.On the first tape, store the input h M, w i. 2.On the second tape, copy w. 3.On the third tape write $1 q*n*g n (so, unary: D extracts q and g from M, n from w). Leave the head on the last 1. 4.Using the second tape, simulate M on w. 5.If M halts in the accepting or rejecting state with the head of tape 3 on a 1, accept or reject. 6.After each time an instruction of M is simulated, write a blank on tape 3 and move that head left. 7.If the head of tape 3 reaches $, reject.

9 9 Computation Histories Proof (continued). The reason why this works is that after q*n*g n configurations we must be repeating ourselves, and thus have fallen into a loop.QED

10 10 Computation Histories Theorem 5.10: E LBA = { h M i | M is an LBA where L(M) = ; } is undecidable. ( 0 ) Theorem 5.13: ALL CFG = { h G i | G is a CFG and L(G) = *} is undecidable. ( 0 )

11 11 Computation Histories Proof of 5.10 We'll show that NA TM · m E LBA. (textbook reduces from A TM )  On input h M, w i, the reduction will construct an LBA, say B = B h M,w i, such that M doesn't accept w iff L(B h M,w i ) is empty. We will not run B on anything, but we must show that we can construct such a B via a Turing Machine from any h M, w i.  We construct B so that it will accept input x iff x is an accepting computation history for M on w. An accepting computation history is a finite string of the form # C 1 # C 2 # … # C k # where 1.C 1 is the starting configuration of M with input w 2.for all i, the relation C i ` C i+1 holds, according to M 3.C k is an accepting configuration of M.

12 12 Computation Histories  One can build the initial string q 0 w into B h M,w i so the check can be performed.  One can check that the last configuration contains the accepting state - just scan down the input string of configurations.  One can check that each configuration follows legally from the previous one: check that they are identical except for the changes implied by the transition function of M. Move back and forth marking with a dot the positions just compared. When we find differences (they can be only over three adjacent characters), we check that they meet the requirements of the transitions of M.

13 13 Computation Histories  If all conditions are satisfied, then B h M,w i accepts this proposed computation history x, otherwise it rejects. It should be reasonably clear that a)Given as input, the reduction can produce a B h M,w i as output with this behavior. b)Such a B h M,w i is always an LBA (why?). And now: 2 NA TM, M doesn't accept w, there is no accepting computation history for M on w, B h M,w i does not accept any input, B h M,w i 2 E LBA QED

14 14 Computation Histories Theorem 5.13 ALL CFG = { h G i | G is a CFG and L(G) = *} is undecidable. Proof. Will show that NA TM · m ALL CFG using computation histories: given h M, w i construct a CFG G h M,w i that generates all strings, M does not accept w. If M does accept w, G h M,w i will not generate one string: the accepting computation history for M on w. We must show that we can construct this G h M,w i via a TM (the reduction) when it is given h M,w i as input. Again, an accepting computation history of M on w is a finite string of the form # C 1 # C 2 # … # C k # where 1.C 1 is the starting configuration of M with input w 2.for all i, the relation C i ` C i+1 holds, according to M 3.C k is an accepting configuration of M

15 15 Computation Histories For a string not to be an accepting configuration history for M on w, at least one of the three conditions must fail. If M does not accept w, no such computation history exists, thus all strings fail, and G h M,w i would generate all strings. We construct the grammar G h M,w i using the results that establish equivalence between CFGs and PDAs (all the constructions are algorithmic - thus TM performable, so we are OK).

16 16 Computation Histories The reduction constructs a PDA D h M,w i. It is nondeterministic, so at start we have 3 branches. This machine will accept strings that are not accepting computation histories: 1. One branch checks if the beginning of the input is C 1. Accepts if not. 2. One branch checks if the end C k contains q accept. Accepts if not. 3. One branch scans the input until it decides (non- deterministically) that is has reached a C i. It pushes the contents of C i onto the stack, and verifies that the stack contents match C i+1 except for the modifications due to the transition. Accepts if not.

17 17 Computation Histories The only problem is that we would be trying to match potentially unbounded strings such as C i # C i+1, and that's something we can't do in a PDA, because stacks are LIFO structures. Yet if adjacent configurations were written in reverse order of each other, it would be easy to do. This turns out to be a non-issue. For each normal accepting computation history # C 1 # C 2 # C 3 # C 4 # … # C k # there is another string that is the same except that it reverses every other component: # C 1 # C 2 R # C 3 # C 4 R # … # C k # So our PDA D h M,w i will just assume that its input is in this form rather than the ordinary form of a computation history. Then we convert our PDA into the CFG G h M,w i, and we're done. QED

18 18 Part of Homework  Prove that EQ CFG is undecidable. Textbook Exercise 5.1, p. 211. Recall:  EQ CFG = { | G and H are CFGs and L(G) = L(H) }

19 19 Landscape at end of Chapter 5 ALL FIN Each point is a language in this Venn diagram. REG RPP CFL CFPP 00 11 NA TM ALL -  1 EQ CFG  0 E LBA  0 ALL CFG  0 ? PCP  0 HALT TM  1 -  0 REGULAR TM  1 EQ TM  1 E TM  1 A TM  1 -  0 A 10  1 - 0 A DFA  0 A NFA  0 A REX  0 E DFA  0 EQ DFA  0 A CFG  0 E CFG  0 A LBA  0

20 20 A natural undecidable language  Post’s Correspondence Problem concerns dominos of the form a a cb b ab aa where each domino has a “top” and a “bottom” chosen from an underlying alphabet .  An instance of the problem is a finite set P={[t 1,b 1 ], [t 2,b 2 ],..., [t k,b k ]} of dominos Each t i and b i is a nonempty string over  (in other words, a member of  + ) Think of each instance P as an alphabet You can form domino strings over the alphabet P

21 21 Post’s Correspondence Problem  Let ={a,b,c} and P 1 ={[b,ca], [a,ab], [ca,a], [abc,c]}. Sample domino string over P 1 : ca abc a c  A domino string is a match if the concatenation of characters on its top row is equal to the concatenation of characters on its bottom row.  Repetitions of dominos are permitted.  The example above is not a match, because caabc  ac.  But we can find a match using this instance P 1. One thing we know for sure: each match must begin with same char on top & bottom...

22 22 abacaabaabaabcca abcaabaabcaabcabca

23 23 Post’s Correspondence Problem  An instance P contains a match if there is some nonempty domino string formed from P that is a match  Definition PCP = { | P is an instance that contains a match }  Theorem 5.15 PCP   0

24 24 Proof outline Proof Define the Modified PCP: MPCP={ | P is an instance that contains a match that begins with the domino d 1 2 P } We’ll show that A TM · m MPCP · m PCP. Most of the work is in the first reduction, which we’ll call f. The idea is that 2 A TM exactly when M goes from its initial configuration on input w into an accepting one: 2 A TM, q 0 w ` * x q acc y for some x,y 2  * We’ll construct the reduction f so that it transforms into an instance of MPCP in which a match actually describes an accepting computation history of M on w. The match is not a one-for-one rewriting of the computation history, but it's quite close.

25 25 Definition of reduction f A.f: input x B.if x is not of form where M is a TM, then print out some fixed string that we know isn’t in MPCP and halt C.modify M=(Q,,,,q 0,q acc,q rej ) so that: A.it still recognizes the same language as before B.but it never attempts to move left of its leftmost tape cell (substitute right-then-left motion instead) D.construct P={d 1, ,d k } using rules 1-7 (on next slides...) E.print and halt

26 26 Rule 1 of 7: initial configuration  This is the initial domino and it describes M's initial configuration: # #q 0 w#  This is the only domino that is bottom-heavy, meaning that it has more characters on the bottom than on the top  To get a match, there must also be dominos in the kit that are top-heavy to compensate  But most of the dominos will be perfectly balanced  This is the only domino that depends on the string w. The rest are either constant or depend on M alone. d 1 = old config on top new config on bottom

27 27 Example TM M {1,2,3} ={1,2,3,$, t } q0q0 q1q1 q rej q acc / $, R $ / $, R 3 / 3, L 1 / 2, R 2 / 1, L t / 3, R / R unlabeled transitions point to q rej transitions out of q acc and q rej are never actually taken... Here  on transition label represents any character of tape alphabet. Also, / R represents  R.

28 Rule 1: # #q 0 w# Rule 2:q 0 1 q 0 2 q 0 3 q 0 $ q 0 t Right moves$q 1 $q 1 $q 1 $q 1 $q 1 q 1 1 q 1 t q 1 $ 2q 1 3q 1 $q rej q acc 1 q acc 2 q acc 3 q acc $ q acc t 1q acc 2q acc 3q acc $q acc t q acc Rule 3: 1q 1 2 2q 1 2 3q 1 2 $q 1 2 t q 1 2 Left movesq 1 11 q 1 21 q 1 31 q 1 $1 q 1 t 1 1q 1 3 2q 1 3 3q 1 3 $q 1 3 t q 1 3 q acc 13 q acc 23 q acc 33 q acc $3 q acc t 3 Rule 4:1 2 3 $ t Copying1 2 3 $ t Rule 5: Separators# # # t # Rule 6:1q acc q acc 1 2q acc q acc 2 3q acc q acc 3 $q acc q acc $ t q acc q acc t Acceptorsq acc q acc q acc q acc q acc q acc q acc q acc q acc q acc Rule 7:q acc ## Finisher# Example kit for

29 29 Rule 2 of 7: right moves  Suppose (q, a) = (r,b,R). Then we want to ensure that a matched set of dominos can include this computation history snippet: … qa … ` … br … (state is now r, a is now b, moved to the right)  So, for all a,b 2  and q 2 Q-{q rej } and r 2 Q and (q, a) = (r,b,R), we add the following domino to the set P: qa old config br new config  Note: If q rej appears in a configuration, then we want to prevent a match, so we exclude dominos that might help make a partial match grow towards a full match.  Note: If q acc appears in a configuration, then we'll use rules 6 and 7 to proceed towards a match.  Note: #It's in the domino alphabet but not the TM alphabet.

30 Rule 1: # #q 0 w# Rule 2:q 0 1 q 0 2 q 0 3 q 0 $ q 0 t Right moves$q 1 $q 1 $q 1 $q 1 $q 1 q 1 1 q 1 t q 1 $ 2q 1 3q 1 $q rej q acc 1 q acc 2 q acc 3 q acc $ q acc t 1q acc 2q acc 3q acc $q acc t q acc Rule 3: 1q 1 2 2q 1 2 3q 1 2 $q 1 2 t q 1 2 Left movesq 1 11 q 1 21 q 1 31 q 1 $1 q 1 t 1 1q 1 3 2q 1 3 3q 1 3 $q 1 3 t q 1 3 q acc 13 q acc 23 q acc 33 q acc $3 q acc t 3 Rule 4:1 2 3 $ t Copying1 2 3 $ t Rule 5: Separators# # # t # Rule 6:1q acc q acc 1 2q acc q acc 2 3q acc q acc 3 $q acc q acc $ t q acc q acc t Acceptorsq acc q acc q acc q acc q acc q acc q acc q acc q acc q acc Rule 7:q acc ## Finisher# Example kit for

31 31 Rule 3 of 7: left moves  Suppose (q, a) = (r,b,L). Then we want to ensure that a matched set of dominos can include this computation history snippet: … cqa … ` … rcb … (state is now r, a is now b, moved to the right, c is unchanged)  So, for all a,b,c 2  and q 2 Q-{q acc,q rej } and r 2 Q and (q, a) = (r,b,L), we add the following domino to the set P: cqa old config rcb new config  Note that we don't care what c is; we add in one domino for each choice of c.  Also, remember that M never tries to move left when it's at the left end of the tape. So there always is some character c to the left of the tape head when moving left, and so these dominos account for all of the possible left moves.

32 Rule 1: # #q 0 w# Rule 2:q 0 1 q 0 2 q 0 3 q 0 $ q 0 t Right moves$q 1 $q 1 $q 1 $q 1 $q 1 q 1 1 q 1 t q 1 $ 2q 1 3q 1 $q rej q acc 1 q acc 2 q acc 3 q acc $ q acc t 1q acc 2q acc 3q acc $q acc t q acc Rule 3: 1q 1 2 2q 1 2 3q 1 2 $q 1 2 t q 1 2 Left movesq 1 11 q 1 21 q 1 31 q 1 $1 q 1 t 1 1q 1 3 2q 1 3 3q 1 3 $q 1 3 t q 1 3 q acc 13 q acc 23 q acc 33 q acc $3 q acc t 3 Rule 4:1 2 3 $ t Copying1 2 3 $ t Rule 5: Separators# # # t # Rule 6:1q acc q acc 1 2q acc q acc 2 3q acc q acc 3 $q acc q acc $ t q acc q acc t Acceptorsq acc q acc q acc q acc q acc q acc q acc q acc q acc q acc Rule 7:q acc ## Finisher# Example kit for

33 33 Rule 4 of 7: the faraway tape  The left move and right move dominos determine what happens in the immediate vicinity of the tape head. The rest of the tape is unaffected by the transition.  So, for every a 2 , add this domino to the kit: a

34 Rule 1: # #q 0 w# Rule 2:q 0 1 q 0 2 q 0 3 q 0 $ q 0 t Right moves$q 1 $q 1 $q 1 $q 1 $q 1 q 1 1 q 1 t q 1 $ 2q 1 3q 1 $q rej q acc 1 q acc 2 q acc 3 q acc $ q acc t 1q acc 2q acc 3q acc $q acc t q acc Rule 3: 1q 1 2 2q 1 2 3q 1 2 $q 1 2 t q 1 2 Left movesq 1 11 q 1 21 q 1 31 q 1 $1 q 1 t 1 1q 1 3 2q 1 3 3q 1 3 $q 1 3 t q 1 3 q acc 13 q acc 23 q acc 33 q acc $3 q acc t 3 Rule 4:1 2 3 $ t Copying1 2 3 $ t Rule 5: Separators# # # t # Rule 6:1q acc q acc 1 2q acc q acc 2 3q acc q acc 3 $q acc q acc $ t q acc q acc t Acceptorsq acc q acc q acc q acc q acc q acc q acc q acc q acc q acc Rule 7:q acc ## Finisher# Example kit for

35 35 Rule 5 of 7: the # separators  Add these two dominos to the kit: # # old config # t # new config  These allow the separators to be carried along.  The second domino allows a blank to be added to the right of the tape

36 Rule 1: # #q 0 w# Rule 2:q 0 1 q 0 2 q 0 3 q 0 $ q 0 t Right moves$q 1 $q 1 $q 1 $q 1 $q 1 q 1 1 q 1 t q 1 $ 2q 1 3q 1 $q rej q acc 1 q acc 2 q acc 3 q acc $ q acc t 1q acc 2q acc 3q acc $q acc t q acc Rule 3: 1q 1 2 2q 1 2 3q 1 2 $q 1 2 t q 1 2 Left movesq 1 11 q 1 21 q 1 31 q 1 $1 q 1 t 1 1q 1 3 2q 1 3 3q 1 3 $q 1 3 t q 1 3 q acc 13 q acc 23 q acc 33 q acc $3 q acc t 3 Rule 4:1 2 3 $ t Copying1 2 3 $ t Rule 5: Separators# # # t # Rule 6:1q acc q acc 1 2q acc q acc 2 3q acc q acc 3 $q acc q acc $ t q acc q acc t Acceptorsq acc q acc q acc q acc q acc q acc q acc q acc q acc q acc Rule 7:q acc ## Finisher# Example kit for

37 37 Rule 6 of 7: accepter  For every a 2 , add these two dominos to the kit: aq acc q acc a old config q acc q acc new config  This means that when q acc appears in a configuration, the adjacent characters can be squeezed out, one configuration at a time, leading towards a match  These are the top-heavy dominos to match the initial, bottom-heavy one

38 Rule 1: # #q 0 w# Rule 2:q 0 1 q 0 2 q 0 3 q 0 $ q 0 t Right moves$q 1 $q 1 $q 1 $q 1 $q 1 q 1 1 q 1 t q 1 $ 2q 1 3q 1 $q rej q acc 1 q acc 2 q acc 3 q acc $ q acc t 1q acc 2q acc 3q acc $q acc t q acc Rule 3: 1q 1 2 2q 1 2 3q 1 2 $q 1 2 t q 1 2 Left movesq 1 11 q 1 21 q 1 31 q 1 $1 q 1 t 1 1q 1 3 2q 1 3 3q 1 3 $q 1 3 t q 1 3 q acc 13 q acc 23 q acc 33 q acc $3 q acc t 3 Rule 4:1 2 3 $ t Copying1 2 3 $ t Rule 5: Separators# # # t # Rule 6:1q acc q acc 1 2q acc q acc 2 3q acc q acc 3 $q acc q acc $ t q acc q acc t Acceptors q acc q acc q acc q acc q acc q acc q acc q acc q acc q acc Rule 7:q acc ## Finisher# Example kit for

39 39 Rule 7 of 7: finisher  Add this single domino to the kit: q acc ## #  You just need it. You'll see why…

40 Rule 1: # #q 0 w# Rule 2:q 0 1 q 0 2 q 0 3 q 0 $ q 0 t Right moves$q 1 $q 1 $q 1 $q 1 $q 1 q 1 1 q 1 t q 1 $ 2q 1 3q 1 $q rej q acc 1 q acc 2 q acc 3 q acc $ q acc t 1q acc 2q acc 3q acc $q acc t q acc Rule 3: 1q 1 2 2q 1 2 3q 1 2 $q 1 2 t q 1 2 Left movesq 1 11 q 1 21 q 1 31 q 1 $1 q 1 t 1 1q 1 3 2q 1 3 3q 1 3 $q 1 3 t q 1 3 q acc 13 q acc 23 q acc 33 q acc $3 q acc t 3 Rule 4:1 2 3 $ t Copying1 2 3 $ t Rule 5: Separators# # # t # Rule 6:1q acc q acc 1 2q acc q acc 2 3q acc q acc 3 $q acc q acc $ t q acc q acc t Acceptors q acc q acc q acc q acc q acc q acc q acc q acc q acc q acc Rule 7:q acc ## Finisher# Example kit for

41 41 Example TM {1,2,3} ={1,2,3,$, t } q0q0 q1q1 q rej q acc / $, R $ / $, R 3 / 3, L 1 / 2, R 2 / 1, L t / 3, R / R unlabeled transitions point to q rej transitions out of q acc and q rej are never actually taken...

42 42 Examples  On board. and

43 43 MPCP · m PCP via g 1.g: input where P is a PCP instance and t 1 /b 1 2 P  if input is not in this form then print some string known not to be in PCP and halt 2.Assuming P={t 1 /b 1, , t k /b k }, let Q = { ¤ t 1 / ¤ b 1 ¤, ¤ t 1 /b 1 ¤, ¤ t 2 / b 2 ¤, ¤ t 3 / b 3 ¤, , ¤ t k / b k ¤, + ¦ / ¦ } 3.Print and halt where +, ¦ are not in and *abc = +a+b+c (plusses before) abc* = a+b+c+ (plusses after) *abc* = +a+b+c+ (before & after) different from textbook, where * and 5-pointed star are used

44 44 Purpose of construction  Each domino has some + characters on the top Only one of them has + as the first character on the top and bottom: the one that includes t 1 and b 1  Starting with this domino ¤ t 1 / ¤ b 1 ¤, you end up with an excess of + characters on the bottom The only one that can balance it is + ¦ / ¦  Otherwise, the + characters line up between each character and don’t interfere  The effect is that P contains a match starting with t 1 /b 1 exactly when Q contains any match whatsoever (since any match in it must begin with ¤ t 1 / ¤ b 1 ¤ )  Hence MPCP · m PCP via g

45 45 Landscape at end of Chapter 5 ALL FIN Each point is a language in this Venn diagram. REG RPP CFL CFPP 00 11 NA TM ALL -  1 EQ CFG  0 E LBA  0 ALL CFG  0 ? PCP  0 HALT TM  1 -  0 REGULAR TM  1 EQ TM  1 E TM  1 A TM  1 -  0 A 10  1 - 0 A DFA  0 A NFA  0 A REX  0 E DFA  0 EQ DFA  0 A CFG  0 E CFG  0 A LBA  0


Download ppt "1 91.304 Foundations of (Theoretical) Computer Science Chapter 5 Lecture Notes David Martin (with modifications by Karen Daniels) With thanks."

Similar presentations


Ads by Google