theory of computer science
play

Theory of Computer Science C6. Context-free Languages: Closure & - PowerPoint PPT Presentation

Theory of Computer Science C6. Context-free Languages: Closure & Decidability Gabriele R oger University of Basel April 6, 2020 Pumping Lemma Closure Properties Decidability Summary Pumping Lemma Pumping Lemma Closure Properties


  1. Theory of Computer Science C6. Context-free Languages: Closure & Decidability Gabriele R¨ oger University of Basel April 6, 2020

  2. Pumping Lemma Closure Properties Decidability Summary Pumping Lemma

  3. Pumping Lemma Closure Properties Decidability Summary Overview Languages ε -rules & Grammars Chomsky Regular Normal Form Languages Automata & PDAs Formal Languages Context-free Languages (Pumping Lemma) Context-sensitive & Closure Type-0 Languages Properties Decidability

  4. Pumping Lemma Closure Properties Decidability Summary Pumping Lemma for Context-free Languages We used the pumping lemma from chapter C4 to show that a language is not regular. Is there a similar lemma for context-free languages? Picture courtesy of imagerymajestic / FreeDigitalPhotos.net

  5. Pumping Lemma Closure Properties Decidability Summary Pumping Lemma for Context-free Languages We used the pumping lemma from chapter C4 to show that a language is not regular. Is there a similar lemma for context-free languages? Yes! Picture courtesy of imagerymajestic / FreeDigitalPhotos.net

  6. Pumping Lemma Closure Properties Decidability Summary Pumping Lemma for Context-free Languages Pumping lemma for context-free languages: It is possible to prove a variant of the pumping lemma for context-free languages. Pumping is more complex than for regular languages: word is decomposed into the form uvwxy with | vx | ≥ 1, | vwx | ≤ n pumped words have the form uv i wx i y This allows us to prove that certain languages are not context-free. example: { a n b n c n | n ≥ 1 } is not context-free (we will later use this without proof)

  7. Pumping Lemma Closure Properties Decidability Summary Closure Properties

  8. Pumping Lemma Closure Properties Decidability Summary Overview Languages ε -rules & Grammars Chomsky Regular Normal Form Languages Automata & PDAs Formal Languages Context-free Languages (Pumping Lemma) Context-sensitive & Closure Type-0 Languages Properties Decidability

  9. Pumping Lemma Closure Properties Decidability Summary Closure under Union, Concatenation, Star Theorem The context-free languages are closed under: union concatenation star

  10. Pumping Lemma Closure Properties Decidability Summary Closure under Union, Concatenation, Star: Proof Proof. Closed under union: Let G 1 = � Σ 1 , V 1 , P 1 , S 1 � and G 2 = � Σ 2 , V 2 , P 2 , S 2 � be context-free grammars. W.l.o.g., V 1 ∩ V 2 = ∅ . Then � Σ 1 ∪ Σ 2 , V 1 ∪ V 2 ∪ { S } , P 1 ∪ P 2 ∪ { S → S 1 , S → S 2 } , S � (where S / ∈ V 1 ∪ V 2 ) is a context-free grammar for L ( G 1 ) ∪ L ( G 2 ) (possibly requires rewriting ε -rules). . . .

  11. Pumping Lemma Closure Properties Decidability Summary Closure under Union, Concatenation, Star: Proof Proof (continued). Closed under concatenation: Let G 1 = � Σ 1 , V 1 , P 1 , S 1 � and G 2 = � Σ 2 , V 2 , P 2 , S 2 � be context-free grammars. W.l.o.g., V 1 ∩ V 2 = ∅ . Then � Σ , V 1 ∪ V 2 ∪ { S } , P 1 ∪ P 2 ∪ { S → S 1 S 2 } , S � (where S / ∈ V 1 ∪ V 2 ) is a context-free grammar for L ( G 1 ) L ( G 2 ) (possibly requires rewriting ε -rules). . . .

  12. Pumping Lemma Closure Properties Decidability Summary Closure under Union, Concatenation, Star: Proof Proof (continued). Closed under star: Let G = � Σ , V , P , S � be a context-free grammar where w.l.o.g. S never occurs on the right-hand side of a rule. Then G ′ = � Σ , V ∪ { S ′ } , P ′ , S ′ � with S ′ / ∈ V and P ′ = ( P ∪ { S ′ → ε, S ′ → S , S ′ → SS ′ } ) \ { S → ε } is a context-free grammar for L ( G ) ∗ after rewriting ε -rules.

  13. Pumping Lemma Closure Properties Decidability Summary No Closure under Intersection or Complement Theorem The context-free languages are not closed under: intersection complement

  14. Pumping Lemma Closure Properties Decidability Summary No Closure under Intersection or Complement: Proof Proof. Not closed under intersection: The languages L 1 = { a i b j c j | i , j ≥ 1 } and L 2 = { a i b j c i | i , j ≥ 1 } are context-free. For example, G 1 = �{ a , b , c } , { S , A , X } , P , S � with P = { S → AX , A → a , A → a A , X → bc , X → b X c } is a context-free grammar for L 1 . For example, G 2 = �{ a , b , c } , { S , B } , P , S � with P = { S → a S c , S → B , B → b , B → b B } is a context-free grammar for L 2 . Their intersection is L 1 ∩ L 2 = { a n b n c n | n ≥ 1 } . We have remarked before that this language is not context-free. . . .

  15. Pumping Lemma Closure Properties Decidability Summary No Closure under Intersection or Complement: Proof Proof (continued). Not closed under complement: By contradiction: assume they were closed under complement. Then they would also be closed under intersection because they are closed under union and L 1 ∩ L 2 = L 1 ∪ L 2 . This is a contradiction because we showed that they are not closed under intersection.

  16. Pumping Lemma Closure Properties Decidability Summary Questions Questions?

  17. Pumping Lemma Closure Properties Decidability Summary Decidability

  18. Pumping Lemma Closure Properties Decidability Summary Overview Languages ε -rules & Grammars Chomsky Regular Normal Form Languages Automata & PDAs Formal Languages Context-free Languages (Pumping Lemma) Context-sensitive & Closure Type-0 Languages Properties Decidability

  19. Pumping Lemma Closure Properties Decidability Summary Word Problem Definition (Word Problem for Context-free Languages) The word problem P ∈ for context-free languages is: Given: context-free grammar G with alphabet Σ and word w ∈ Σ ∗ Question: Is w ∈ L ( G )?

  20. Pumping Lemma Closure Properties Decidability Summary Decidability: Word Problem Theorem The word problem P ∈ for context-free languages is decidable. Proof. If w = ε , then w ∈ L ( G ) iff S → ε with start variable S is a rule of G . Since for all other rules w l → w r of G we have | w l | ≤ | w r | , the intermediate results when deriving a non-empty word never get shorter. So it is possible to systematically consider all (finitely many) derivations of words up to length | w | and test whether they derive the word w . Note: This is a terribly inefficient algorithm.

  21. Pumping Lemma Closure Properties Decidability Summary Emptiness Problem Definition (Emptiness Problem for Context-free Languages) The emptiness problem P ∅ for context-free languages is: Given: context-free grammar G Is L ( G ) = ∅ ? Question:

  22. Pumping Lemma Closure Properties Decidability Summary Decidability: Emptiness Problem Theorem The emptiness problem for context-free languages is decidable. Proof. Given a grammar G , determine all variables in G that allow deriving words that only consist of terminal symbols: First mark all variables A for which a rule A → w exists such that w only consists of terminal symbols. Then mark all variables A for which a rule A → w exists such that all nonterminal systems in w are already marked. Repeat this process until no further markings are possible. L ( G ) is empty iff the start variable is unmarked at the end of this process.

  23. Pumping Lemma Closure Properties Decidability Summary Finiteness Problem Definition (Finiteness Problem for Context-free Languages) The finiteness problem P ∞ for context-free languages is: Given: context-free grammar G Question: Is |L ( G ) | < ∞ ?

  24. Pumping Lemma Closure Properties Decidability Summary Decidability: Finiteness Problem Theorem The finiteness problem for context-free languages is decidable. We omit the proof. A possible proof uses the pumping lemma for context-free languages. Proof sketch: We can compute certain bounds l , u ∈ N 0 for a given context-free grammar G such that L ( G ) is infinite iff there exists w ∈ L ( G ) with l ≤ | w | ≤ u . Hence we can decide finiteness by testing all (finitely many) such words by using an algorithm for the word problem.

  25. Pumping Lemma Closure Properties Decidability Summary Intersection Problem Definition (Intersection Problem for Context-free Languages) The intersection problem P ∩ for context-free languages is: context-free grammars G and G ′ Given: Is L ( G ) ∩ L ( G ′ ) = ∅ ? Question:

  26. Pumping Lemma Closure Properties Decidability Summary Equivalence Problem Definition (Equivalence Problem for Context-free Languages) The equivalence problem P = for context-free languages is: context-free grammars G and G ′ Given: Is L ( G ) = L ( G ′ )? Question:

  27. Pumping Lemma Closure Properties Decidability Summary Undecidability: Equivalence and Intersection Problem Theorem The equivalence problem for context-free languages and the intersection problem for context-free languages are not decidable. We cannot show this with the means currently available, but we will get back to this in Part D (computability theory).

  28. Pumping Lemma Closure Properties Decidability Summary Questions Questions?

  29. Pumping Lemma Closure Properties Decidability Summary Summary

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