Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Undecidable.

Similar presentations


Presentation on theme: "CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Undecidable."— Presentation transcript:

1 CSCI 3130: Formal languages and automata theory Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130 The Chinese University of Hong Kong Undecidable problems for CFGs Fall 2011

2 Decidable vs. undecidable “ TM M accepts w” “ TM M accepts some input ” “ TM M and M’ accept same inputs ” undecidable “ TM M halts on w” “ CFG G generates w” “ DFA M accepts w” decidable “CFG G generates all inputs” “CFG G is ambiguous” more? ? “ DFAs M and M’ accept same inputs ”

3 Representing computations q0q0 q1q1 q2q2 q5q5 q3q3 q4q4 q6q6 q7q7 qaqa a/xR %/%R b/xL b/xR a/xL a/aR b/bR a/aR b/bR x/xR a/aL b/bL x/xL ☐/☐R☐/☐R %/%R a/aL b/bL x/xR L 1 = {w % w: w ∈ { a, b }*} abbaa%abbaa q0q0 xbbaa%abbaa q1q1... q1q1 xbbaa%abbaa q2q2 xbbaa%xbbaa q5q5... xxxxx%xxxxx qaqa

4 Configurations A configuration consists of the current state, the head position, and tape contents … aba ☐ q1q1 ab q 1 a q1q1 q acc a/bRa/bR abb q acc … abb ☐ q acc configuration

5 q0a0b0%0a0b0x0q1b0%0a0b0x0b6q1%0a0b0x0b6%0q2a0b0x0b6q5%0x1b0x0q6b0%0x0b0q0a0b0%0a0b0x0q1b0%0a0b0x0b6q1%0a0b0x0b6%0q2a0b0x0b6q5%0x1b0x0q6b0%0x0b0 Computation histories computation history q0q0 q1q1 q2q2 q5q5 q3q3 q4q4 q6q6 q7q7 qaqa a/xR %/%R b/xL b/xR a/xL a/aR b/bR a/aR b/bR x/xR a/aL b/bL x/xL ☐/☐R☐/☐R %/%R a/aL b/bL x/xR x0x0%0x0x0q7x0x0%0x0x0☐aqax0x0%0x0x0q7x0x0%0x0x0☐aqa...

6 Computation histories as strings M accepts wq acc occurs in hist M rejects w q rej occurs in hist q0a0b0%0a0b0x0q1b0%0a0bq0a0b0%0a0b0x0q1b0%0a0b x0x0%0x0x0q7x0x0%0x0x0qax0x0%0x0x0q7x0x0%0x0x0qa... If M halts on w, the computation history of (M, w) is the sequence of configurations C 1,..., C l that M goes through on input w. #q 0 ab%ab#xq 1 b%ab#... #xx%xx ☐ q a # C1C1 C2C2 ClCl The computation history can be written as a string hist over alphabet  ∪ Q ∪ {#} accepting history: rejecting history:

7 Undecidable problems for CFGs We will argue that ALL CFG = { 〈 G 〉 : G is a CFG that generates all strings } The language ALL CFG is undecidable. If ALL CFG can be decided, so can A TM.

8 Undecidable problems for CFGs 〈 M, w 〉 reject if M accepts w accept if M rej/loops w A reject if not accept if G generates all strings 〈G〉〈G〉 A 〈G〉〈G〉 construct G G generates all strings if M rejects or loops on w G fails to generate some string if M accepts w

9 Undecidable problems for CFGs 〈 M, w 〉 〈G〉〈G〉 construct G G fails to generate some string M accepts w The alphabet of G will be  ∪ Q ∪ {#} G will generate all strings except the computation history of (M, w), if it is accepting First we construct a PDA P, then convert it to CFG G

10 Undecidability via computation histories P candidate computation history hist of (M, w) accept everything #q 0 ab%ab#xq 1 b%ab#... #xx%xx ☐ q a # reject except accepting hist On input hist, If w 1 ≠ q 0 w or w k does not contain q a, accept. If two consecutive blocks w i #w i+1 do not follow from the transitions of M, accept. P:P: If hist is not of the form #w 1 #w 2 #...#w k #, accept. Otherwise, hist is an accepting history, so reject. // try to spot a mistake in hist q0q0   

11 #0q0a0b0%0a0b0#0x0q1b0%0a0b0#0x0b6q1%0a0b0#0x0b6%0q2a0b0#0x0b6q5%0x1b0#0x0q6b0%0x0b0#0q0a0b0%0a0b0#0x0q1b0%0a0b0#0x0b6q1%0a0b0#0x0b6%0q2a0b0#0x0b6q5%0x1b0#0x0q6b0%0x0b0 Computation is local Changes between configurations always occur around the head q0q0 q1q1 q2q2 q5q5 q3q3 q4q4 q6q6 q7q7 qaqa a/xR %/%R b/xL b/xR a/xL a/aR b/bR a/aR b/bR x/xR a/aL b/bL x/xL ☐/☐R☐/☐R %/%R a/aL b/bL x/xR #0x0x0%0x0x0q7#0x0x0%0x0x0☐aqa#0x0x0%0x0x0q7#0x0x0%0x0x0☐aqa...

12 Legal and illegal transition windows … 6 a 3 b 0 x 0 … … 0 a 6 b 0 x 0 … 0 legal windows … 6 a 3 b 0 a 0 … … 0 a 6 b 0 q 5 … 0 … 6 a 3 q 2 a 0 … … 0 q 5 a 6 x 0 … 0 … 6 q 2 a 0 b 0 … … 0 a 6 b 0 q 2 … 0 illegal windows … 6 a 3 a 0 ☐ 0 … … 0 x 6 a 0 ☐ 0 … 0 q2q2 q5q5 a/xL … 6 a 3 q 2 a 0 … … 0 q 5 a 6 b 0 … 0 … 6 q 2 q 2 a 0 … … 0 q 2 q 2 x 3 … 0 … 6 a 3 q 2 a 0 … … 0 a 6 q 5 x 0 … 0

13 #0x0b6%0q2a0b#0x0b6q5%0x1b#0x0b6%0q2a0b#0x0b6q5%0x1b Implementing P For every position of w i : Remember first row of window in state After reaching the next # : Pop offset from # from stack as you consume input Remember second row of window in state Remember offset from # in w i on stack If window is illegal, accept; Otherwise reject. offset If two consecutive blocks w i #w i+1 do not follow from the transitions of M, accept:

14 The computation history method G accepts all strings except accepting computation histories of (M, w) We first construct a PDA P, then convert it to CFG G ALL CFG = { 〈 G 〉 : G is a CFG that generates all strings } If ALL CFG can be decided, so can A TM. 〈 M, w 〉 〈G〉〈G〉 construct G

15 The Post Correspondence Problem Input: A set of tiles like this Given an infinite supply of such tiles, can you match top and bottom? bab cc c ab a ab baa a bab cc c ab a ab baa a c ab a baba a baba bab  bab 

16 Undecidability of PCP PCP = { 〈 T 〉 : T is a collection of tiles that contains a top-bottom match } The language PCP is undecidable.

17 Ambiguity of CFGs AMB = {G: G is an ambiguous CFG } We will argue that The language AMB is undecidable. If AMB can be decided, so can PCP.

18 Ambiguity of CFGs Step 1: Number the tiles TG If T can be matched, then G is ambiguous If T cannot be matched, then G is unambiguous (collection of tiles) bab cc c ab a ab 1 23 (CFG)

19 Ambiguity of CFGs TG (collection of tiles) bab cc c ab a ab 1 23 Productions: Terminals: T → bab T 1 B → cc B 1 T → c T 2 B → ab B 2 T → a T 3 B → ab B 3 a, b, c, 1, 2, 3 (CFG) Variables: S, T, B S → T | B

20 Ambiguity of CFGs TG (collection of tiles) bab cc c ab a ab 12 3 Productions: T → bab T 1 Terminals: B → cc B 1 T → c T 2 B → ab B 2 T → a T 3 B → ab B 3 a, b, c, 1, 2, 3 (CFG) Variables: S, T, B S → T | B T → bab1 B → cc1 T → c2 B → ab2 T → a3 B → ab3

21 Ambiguity of CFGs Each sequence of tiles gives two derivations If the tiles match, these two derive the same string bab cc c ab 1 2 c ab 2 S ⇒ T ⇒ bab T 1 ⇒ babc T 21 ⇒ babcc221 S ⇒ B ⇒ cc B 1 ⇒ ccab B 21 ⇒ ccabab221

22 Ambiguity of CFGs If G is ambiguous then ambiguity must look like this TG If T can be matched, then G is ambiguous If T cannot be matched, then G is unambiguous (collection of tiles)(CFG) ✓ S T T a1a1 n1n1 aiai nini T a2a2 n2n2 … S B B b1b1 m1m1 bjbj mjmj B b2b2 m2m2 … Then n 1...n i = m 1 …m j ✓ So there is a match a1b1a1b1 a2b2a2b2 aibiaibi n1n1 n2n2 nini …

23 Undecidability of PCP (optional)

24 Undecidability of PCP We show that PCP = { 〈 T 〉 : T is a collection of tiles that contains a top-bottom match } The language PCP is undecidable. If PCP can be decided, so can A TM.

25 Undecidability of PCP Idea: Matches represent accepting histories 〈 M, w 〉 T (collection of tiles)  #q 0 ab%ab #q 0 a #xq 1 aaaa bbbb #### xq 1 % x%q 2 %% … #q 0 ab%ab#xq 1 b%ab#... #xx%xx ☐ q a # aaaa bbbb M accepts wT contains a match

26 An assumption We will assume that one of the PCP tiles is marked as a starting tile Later we’ll see how to “simulate” the starting tile by an ordinary tile bab cc c ab a ab baa a baba s

27 Undecidability of PCP On input 〈 M, w 〉 we construct these tiles for PCP 〈 M, w 〉 T (collection of tiles) M accepts w #q0w#q0w s x1qix2x3x4x5x1qix2x3x4x5 for each valid window with state q i in top middle x for all x in  ∪ {#} xqaqaxqaqa ☐#☐#☐#☐# qaxqaqaxqa ☐#qix1☐#x2x3☐#qix1☐#x2x3 q a ## # T contains a match

28 Undecidability of PCP #q0w#q0w s tile typepurpose represents initial configuration represent valid transitions between configurations add blank spaces before # if necessary complete match if computation accepts xqaqaxqaqa qaxqaqaxqa q a ## # x x1qix2x3x4x5x1qix2x3x4x5 ☐#☐#☐#☐# ☐#qix1☐#x2x3☐#qix1☐#x2x3

29 Undecidability of PCP accepting computation history #q 0 a%ab#xq 1 %ab#... #xx%xxq 7 ☐ #xx%xx ☐ q a # #q0w#q0w s x ☐#☐#☐#☐# x1qix2x3x4x5x1qix2x3x4x5 ☐#qix1☐#x2x3☐#qix1☐#x2x3 #q0a#q0abab#xq 1 b%ab#... #xx%x xq 7 ☐ # #q 0 ab%ab#xq 1 bab#... #xx%xxq 7 ☐ #xx%x x☐qax☐qa # % %

30 Undecidability of PCP Once the accepting state symbol occurs, the last two tiles can “eat up” the rest of the symbols x xqaqaxqaqa qaxqaqaxqa q a ## # #xx%xx ☐qa☐qa #xx%xxq a #xx%xq a #... #q a ## #xx%xx ☐ q a #xx%xxqaqa #xx%xqaqa #... #q a ##

31 Undecidability of PCP If M rejects on input w, then q rej appears on bottom at some point, but it cannot be matched on top If M loops on w, then matching keeps going forever #q0w#q0w s a1qia3b1b2b3a1qia3b1b2b3 for each valid window of this form x for all x in  ∪ {#} xqaqaxqaqa ☐#☐#☐#☐# qaxqaqaxqa ☐#qia2☐#b1b2☐#qia2☐#b1b2 q a ## #

32 Getting rid of the starting tile We assumed that one tile marked as starting tile We can remove assumption by changing tiles a bit ba bb bcbc a aba s b*a* *b*b c*c*a* *a *a* *a*b*a ** “starting tile” begins with * “final tile” “middle tiles” cca a b* *c

33 Getting rid of the starting tile b*a* *b*b c*c*a* *a *a* *a*b*a ** b* *c ba bb bcbc a aba s bcbc cca a b* *c can only use as starting tile can only use to complete match


Download ppt "CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Undecidable."

Similar presentations


Ads by Google