undecidable problems for cfgs
play

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

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


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

  2. 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? 2/21 DFAs D and D ′ accept same TM M and M ′ accept the

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

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

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

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

  7. Undecidable problems for CFGs We will argue that 7/21 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. Undecidable problems for CFGs to G 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 Proof by contradiction A 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 8/21 � G � � G � � M , w � G fails to generate some string if M accepts w

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

  10. Undecidablility via computation histories # q 0 ab%ab#x q 1 b%ab#…#xx%x q acc x# Otherwise, h must be an accepting history, reject transitions of M , accept • If h is not of the form # w 1 # w 2 # … # w k # , accept P Reject except accepting h accept everything tation history h of candidate compu- 10/21 ( M , w ) ⇒ P = on input h (try to spot a mistake in h ) • If w 1 � = q 0 w or w k does not contain q acc , accept • If two consecutive blocks w i # w i + 1 do not follow from the

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

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

  13. Implementing P follow from the transitions of M , accept #xb% q 3 ab #xb q 5 %xb For every position of w i : Remember fjrst 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 If window is illegal, accept; Otherwise reject 13/21 If two consecutive blocks w i # w i + 1 do not Remember offset from # in w i on stack

  14. The computation history method Convert to G accepting computation history of We fjrst construct a PDA P , then convert it to CFG G 14/21 ALL CFG = {� G � | G is a CFG that generates all strings } If ALL CFG can be decided, so can A TM G accepts all strings except � G � ( M , w ) � M , w �

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

  16. Undecidability of PCP Next lecture we will show (using computation history method) The language PCP is undecidable 16/21 PCP = {� T � | T is a collection of tiles that contains a top-bottom match }

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

  18. Ambiguity of CFGs c 3 2 1 ab a ab cc T (collection of tiles) bab 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) 18/21 �− →

  19. Ambiguity of CFGs ab Productions: T (collection of tiles) Terminals: a, b, c, 1, 2, 3 3 2 1 Variables: S , T , B a G (CFG) ab 19/21 bab cc c �− → 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. Ambiguity of CFGs Each sequence of tiles gives a pair of derivations bab cc c ab c ab 1 2 2 (with different parse trees) 20/21 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

  21. Ambiguity of CFGs m 1 B b 2 . . . B b j m j m 2 a 1 T (collection of tiles) b 1 a 2 b 2 a i b i n 1 n 2 n i … b 1 B S T G (CFG) If T can be matched, then G is ambiguous If T cannot be matched, then G is unambiguous If G is ambiguous, then the two parse trees will look like S n 1 a 1 T a 2 . . . T a i n i n 2 21/21 �− → ✓ ✓ 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