c6 1 pumping lemma
play

C6.1 Pumping Lemma Languages Automata & PDAs Formal Languages - PowerPoint PPT Presentation

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


  1. Theory of Computer Science April 6, 2020 — C6. Context-free Languages: Closure & Decidability Theory of Computer Science C6.1 Pumping Lemma C6. Context-free Languages: Closure & Decidability C6.2 Closure Properties Gabriele R¨ oger C6.3 Decidability University of Basel April 6, 2020 C6.4 Summary Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 1 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 2 / 29 C6. Context-free Languages: Closure & Decidability Pumping Lemma C6. Context-free Languages: Closure & Decidability Pumping Lemma Overview Languages ε -rules & Grammars Chomsky Regular Normal Form C6.1 Pumping Lemma Languages Automata & PDAs Formal Languages Context-free Languages (Pumping Lemma) Context-sensitive & Closure Type-0 Languages Properties Decidability Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 3 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 4 / 29

  2. C6. Context-free Languages: Closure & Decidability Pumping Lemma C6. Context-free Languages: Closure & Decidability Pumping Lemma Pumping Lemma for Context-free Languages 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. We used the pumping lemma from ◮ Pumping is more complex than for regular languages: chapter C4 to show that a language is ◮ word is decomposed into the form uvwxy not regular. Is there a similar lemma for context-free languages? 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. Yes! ◮ example: { a n b n c n | n ≥ 1 } is not context-free (we will later use this without proof) Picture courtesy of imagerymajestic / FreeDigitalPhotos.net Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 5 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 6 / 29 C6. Context-free Languages: Closure & Decidability Closure Properties C6. Context-free Languages: Closure & Decidability Closure Properties Overview Languages ε -rules & Grammars Chomsky Regular Normal Form C6.2 Closure Properties Languages Automata & PDAs Formal Languages Context-free Languages (Pumping Lemma) Context-sensitive & Closure Type-0 Languages Properties Decidability Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 7 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 8 / 29

  3. C6. Context-free Languages: Closure & Decidability Closure Properties C6. Context-free Languages: Closure & Decidability Closure Properties Closure under Union, Concatenation, Star Closure under Union, Concatenation, Star: Proof Proof. Theorem Closed under union: The context-free languages are closed under: Let G 1 = � Σ 1 , V 1 , P 1 , S 1 � and G 2 = � Σ 2 , V 2 , P 2 , S 2 � ◮ union be context-free grammars. W.l.o.g., V 1 ∩ V 2 = ∅ . ◮ concatenation Then � Σ 1 ∪ Σ 2 , V 1 ∪ V 2 ∪ { S } , P 1 ∪ P 2 ∪ { S → S 1 , S → S 2 } , S � ◮ star (where S / ∈ V 1 ∪ V 2 ) is a context-free grammar for L ( G 1 ) ∪ L ( G 2 ) (possibly requires rewriting ε -rules). . . . Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 9 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 10 / 29 C6. Context-free Languages: Closure & Decidability Closure Properties C6. Context-free Languages: Closure & Decidability Closure Properties Closure under Union, Concatenation, Star: Proof Closure under Union, Concatenation, Star: Proof Proof (continued). Proof (continued). Closed under concatenation: Closed under star: Let G 1 = � Σ 1 , V 1 , P 1 , S 1 � and G 2 = � Σ 2 , V 2 , P 2 , S 2 � Let G = � Σ , V , P , S � be a context-free grammar be context-free grammars. W.l.o.g., V 1 ∩ V 2 = ∅ . where w.l.o.g. S never occurs on the right-hand side of a rule. Then G ′ = � Σ , V ∪ { S ′ } , P ′ , S ′ � with S ′ / Then � Σ , V 1 ∪ V 2 ∪ { S } , P 1 ∪ P 2 ∪ { S → S 1 S 2 } , S � ∈ V and P ′ = ( P ∪ { S ′ → ε, S ′ → S , S ′ → SS ′ } ) \ { S → ε } (where S / ∈ V 1 ∪ V 2 ) is a context-free grammar for L ( G 1 ) L ( G 2 ) is a context-free grammar for L ( G ) ∗ after rewriting ε -rules. (possibly requires rewriting ε -rules). . . . Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 11 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 12 / 29

  4. C6. Context-free Languages: Closure & Decidability Closure Properties C6. Context-free Languages: Closure & Decidability Closure Properties No Closure under Intersection or Complement 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. Theorem ◮ For example, G 1 = �{ a , b , c } , { S , A , X } , P , S � with The context-free languages are not closed under: P = { S → AX , A → a , A → a A , X → bc , X → b X c } ◮ intersection is a context-free grammar for L 1 . ◮ complement ◮ 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. . . . Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 13 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 14 / 29 C6. Context-free Languages: Closure & Decidability Closure Properties C6. Context-free Languages: Closure & Decidability Decidability No Closure under Intersection or Complement: Proof Proof (continued). Not closed under complement: C6.3 Decidability 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. Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 15 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 16 / 29

  5. C6. Context-free Languages: Closure & Decidability Decidability C6. Context-free Languages: Closure & Decidability Decidability Overview Word Problem Languages ε -rules & Grammars Chomsky Regular Normal Form Definition (Word Problem for Context-free Languages) Languages The word problem P ∈ for context-free languages is: Automata & PDAs Formal Languages Given: context-free grammar G with alphabet Σ Context-free and word w ∈ Σ ∗ Languages (Pumping Question: Is w ∈ L ( G )? Lemma) Context-sensitive & Closure Type-0 Languages Properties Decidability Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 17 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 18 / 29 C6. Context-free Languages: Closure & Decidability Decidability C6. Context-free Languages: Closure & Decidability Decidability Decidability: Word Problem Emptiness Problem Theorem The word problem P ∈ for context-free languages is decidable. Proof. Definition (Emptiness Problem for Context-free Languages) If w = ε , then w ∈ L ( G ) iff S → ε with start variable S The emptiness problem P ∅ for context-free languages is: is a rule of G . Given: context-free grammar G Since for all other rules w l → w r of G we have | w l | ≤ | w r | , Is L ( G ) = ∅ ? Question: 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. Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 19 / 29 Gabriele R¨ oger (University of Basel) Theory of Computer Science April 6, 2020 20 / 29

Recommend


More recommend