undecidable problems for cfgs
play

Undecidable Problems for CFGs CSCI 3130 Formal Languages and - PowerPoint PPT Presentation

1/21 Undecidable Problems for CFGs CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2016 2/21 Decidable vs undecidable Decidable Undecidable DFA D accepts w TM M accepts w CFG G generates w TM


  1. 1/21 Undecidable Problems for CFGs CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2016

  2. 2/21 Decidable vs undecidable Decidable Undecidable DFA D accepts w TM M accepts w CFG G generates w TM M halts on w inputs TM M accepts some input same inputs CFG G generates all inputs? CFG G is ambiguous? DFAs D and D ′ accept same TM M and M ′ accept the

  3. 3/21 . . . q a . Representing computations . . L 1 = { w % w | w ∈ { a , b } ∗ } a / a R b / b R x / x R q 0 abb%abb q 2 abb%abb % / % R q 2 q 3 a / a L a / x L b / b L a / a L a / x R q 2 abb%abb x / x R x / x L b / b L q 3 abb%abb % / % R � / � L % / % L q 0 q 1 q 6 q 7 q 6 abb%xbb b / x R b / x L a / a R b / b R x / x R q 1 xxx%xxx � % / % R q a xxx%xxx q 4 q 5 x / x R

  4. 4/21 q acc A configuration consists of current state, head position, and tape contents Configuration (abbreviation) … Configurations … q acc a b a � q 1 ab q 1 a a / b R q 1 a b b � abb q acc

  5. 5/21 Computation histories computation . . . . . . history q a q 0 abb%abb a / a R b / b R x / x R a q 2 bb%abb % / % R q 2 q 3 a / a L abb q 2 %abb a / x L b / b L a / a L a / x R x / x R x / x L b / b L abb% q 3 abb abb q 2 %xbb % / % R � / � L % / % L q 0 q 1 q 6 q 7 b / x R b / x L a / a R xxx%xxx q 1 b / b R x / x R xxx%xx q a x % / % R q 4 q 5 x / x R

  6. 6/21 . The computation history can be written as a string h accepting history: Computation histories as strings M accepts w M rejects w rejecting history: . . C k If M halts on w , the computation history of ( M , w ) is the sequence of configurations C 1 , . . . , C k that M goes through on input w q 0 ab%ab # q 0 ab%ab #x q 1 b%ab # … #xx%x q a x # a q 2 b%ab � �� � � �� � � �� � C 1 C 2 over alphabet Γ ∪ Q ∪ { # } xx%xx q 1 xx%x q a x ⇔ q acc appears in h ⇔ q rej appears in h

  7. 7/21 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 A TM = {� M , w � | M is a TM that rejects or loops on w }

  8. 8/21 Undecidable problems for CFGs G generates all strings if M rejects or loops on w S reject if M accepts w loops on w accept if M rejects or A to G Convert We want to construct a Turing machine S that decides A TM reject otherwise accept if G generates all strings A Suppose some Turing machine A decides ALL CFG Proof by contradiction � G � � G � � M , w � G fails to generate some string if M accepts w

  9. 9/21 Undecidable problems for CFGs Convert to G M accepts w First we construct a PDA P , then convert it to CFG G � G � G fails to generate some string � � M , w � The alphabet of G will be Γ ∪ Q ∪ { # } G will generate all strings except accepting computation histories of ( M , w )

  10. 10/21 except accepting h of M , accept Reject Undecidablility via computation histories Otherwise, h must be an accepting history, reject accept everything candidate computation P history h of ( M , w ) ⇒ # q 0 ab%ab#x q 1 b%ab#…#xx%x q a x# P = on input h (try to spot a mistake in h ) ◮ If h is not of the form # w 1 # w 2 # … # w k # , accept ◮ 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

  11. 11/21 Computation is local . . . Changes between configurations always occur around the head q a a / a R b / b R x / x R q 0 ab%ab % / % R a q 2 b%ab q 2 q 3 a / a L ab q 2 %ab a / x L b / b L a / a L a / x R ab% q 3 ab x / x R x / x L b / b L ab q 2 %xb % / % R � / � L % / % L q 0 q 1 q 6 q 7 b / x R b / x L a / a R xx%xx q 1 b / b R x / x R xx%x q a x % / % R q 4 q 5 x / x R

  12. 12/21 … … Legal and illegal transitions windows … … … … aba … … … a/xL … … … … … … … … … … … … abx … abx … … … illegal windows … … legal windows … … … … … q 3 ab ab q 3 a q 3 a q 3 q 3 a q 3 q 6 ax q 3 q 3 x a q 3 a q 6 ab q 6 q 6 ab aa � a q 3 a xa � a q 6 x

  13. 13/21 Implementing P For every position of w i : Remember first row of window in state Remember second row of window in state #xb% q 3 ab If two consecutive blocks w i # w i +1 do not follow #xb q 5 %xb from the transitions of M , accept Remember ofgset from # in w i on stack Afuer reaching the next # : Pop ofgset from # from stack as you consume input If window is illegal, accept; Otherwise reject

  14. 14/21 The computation history method Convert to G G accepts all strings except accepting 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 computation histories of ( M , w ) � G � � M , w �

  15. 15/21 Post Correspondence Problem baba a cc bab ab c ab c bab a baa ab a bottom? Given an infinite supply of tiles from a particular set, can you match top and bab baba a a baa ab a ab c cc bab Input: A fixed set of tiles, each containing a pair of strings Top and bottom are both abaababccbaba ε ε

  16. 16/21 Undecidability of PCP The language PCP is undecidable PCP = {� T � | T is a collection of tiles that contains a top-bottom match }

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

  18. 18/21 cc 2 1 ab a ab c bab Ambiguity of CFGs First, let’s number the tiles If T cannot be matched, then G is unambiguous If T can be matched, then G is ambiguous G (CFG) T (collection of tiles) 3 �− →

  19. 19/21 a Productions: Variables: S , T , B Ambiguity of CFGs 3 2 1 ab Terminals: a, b, c, 1, 2, 3 ab c cc bab G (CFG) T (collection of tiles) �− → S → T | B T → bab T 1 T → c T 2 T → a T 3 B → cc B 1 B → ab B 2 B → ab B 3 T → bab1 T → c2 T → a3 B → cc1 B → ab2 B → ab3

  20. 19/21 a Productions: Variables: S , T , B Ambiguity of CFGs 3 2 1 ab Terminals: a, b, c, 1, 2, 3 ab c cc bab G (CFG) T (collection of tiles) �− → S → T | B T → bab T 1 T → c T 2 T → a T 3 B → cc B 1 B → ab B 2 B → ab B 3 T → bab1 T → c2 T → a3 B → cc1 B → ab2 B → ab3

  21. 20/21 Ambiguity of CFGs Each sequence of tiles gives a pair of derivations bab cc c ab c ab 1 2 2 (with difgerent parse trees) S ⇒ T ⇒ bab T 1 ⇒ babc T 21 ⇒ babcc221 S ⇒ B ⇒ cc B 1 ⇒ ccab B 21 ⇒ ccabab221 If the tiles match, these two derive the same string

  22. 21/21 . n i Ambiguity of CFGs B B . . B T b j m j a i b i n i … a i S . If T cannot be matched, then G is unambiguous . T (collection of tiles) T G (CFG) If T can be matched, then G is ambiguous T . S If G is ambiguous, then the two parse trees will look like �− → ✓ ✓ n 1 n 2 m 1 a 1 n 1 b 1 a 1 a 2 m 2 a 2 n 2 b 2 b 1 b 2 Therefore n 1 n 2 . . . n i = m 1 m 2 . . . m j , and there is a match

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend