Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Formal Languages, Grammars and Automata Lecture 4 Helle Hvid Hansen helle@cs.ru.nl http://www.cs.ru.nl/~helle/ Foundations Group – Intelligent Systems Section Institute for Computing and Information Sciences Radboud University Nijmegen 23 May 2014 Helle Hvid Hansen 23 May 2014 FLGA 1 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Recap Lecture 3 Kleene’s Theorem: L is regular ⇐ ⇒ L ∈ L ( DFA ). def L is regular ⇐ ⇒ L = L ( e ) for some regular expression e (lecture 3) ⇐ ⇒ L ∈ L ( NFA - λ ) λ -elim. ⇐ ⇒ L ∈ L ( NFA ) subset constr. ⇐ ⇒ L ∈ L ( DFA ) Thus, to prove that given L is regular, we can either give a reg. expr. or show that L is accepted by some DFA/NFA/NFA- λ . Helle Hvid Hansen 23 May 2014 FLGA 2 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Today • Closure properties of regular languages (ways to prove regularity) • How to prove a language is not regular (Pumping Lemma). Helle Hvid Hansen 23 May 2014 FLGA 3 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Closure Properties of Regular Languages Regular languages are closed under • union: L 1 , L 2 regular ⇒ L 1 ∪ L 2 regular. • concatenation: L 1 , L 2 regular ⇒ L 1 · L 2 regular. • Kleene star: L regular ⇒ L ∗ regular. Proof: (follows directly from definition of regular expressions) Let L 1 = L ( e 1 ) and L 2 = L ( e 2 ). Then • L 1 ∪ L 2 = L ( e 1 + e 2 ) • L 1 · L 2 = L ( e 1 · e 2 ) • L ∗ 1 = L ( e ∗ 1 ) Helle Hvid Hansen 23 May 2014 FLGA 4 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Closure Properties of Regular Languages Regular languages are also closed under ⇒ L = Σ ∗ \ L regular. • complement: L regular ⇐ • intersection: L 1 , L 2 regular ⇒ L 1 ∩ L 2 regular. • reversal: L regular ⇒ L R = { w R | w ∈ L } regular (exercise). Helle Hvid Hansen 23 May 2014 FLGA 5 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Closure Properties of Regular Languages Regular languages are also closed under ⇒ L = Σ ∗ \ L regular. • complement: L regular ⇐ • intersection: L 1 , L 2 regular ⇒ L 1 ∩ L 2 regular. • reversal: L regular ⇒ L R = { w R | w ∈ L } regular (exercise). Proof of closure under complement: ( ⇒ ) Let M = ( Q , q 0 , δ, F ) be a DFA such that L = L ( M ). Taking M = ( Q , q 0 , δ, Q \ F ), then M is a DFA with L ( M ) = L hence L is regular. ( ⇐ ) Follows from L = L and ( ⇒ ). Helle Hvid Hansen 23 May 2014 FLGA 5 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Closure Properties of Regular Languages Regular languages are also closed under ⇒ L = Σ ∗ \ L regular. • complement: L regular ⇐ • intersection: L 1 , L 2 regular ⇒ L 1 ∩ L 2 regular. • reversal: L regular ⇒ L R = { w R | w ∈ L } regular (exercise). Proof of closure under complement: ( ⇒ ) Let M = ( Q , q 0 , δ, F ) be a DFA such that L = L ( M ). Taking M = ( Q , q 0 , δ, Q \ F ), then M is a DFA with L ( M ) = L hence L is regular. ( ⇐ ) Follows from L = L and ( ⇒ ). Note: The definition of M can also be applied to NFAs, but if M is an NFA then it is not necessarily the case that L ( M ) = L . (Why?) Helle Hvid Hansen 23 May 2014 FLGA 5 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Closure Properties of Regular Languages Proof of closure under intersection: Two ways: 1 Use closure under complement, union and De Morgan laws: L 1 ∩ L 2 = L 1 ∪ L 2 Helle Hvid Hansen 23 May 2014 FLGA 6 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Closure Properties of Regular Languages Proof of closure under intersection: Two ways: 1 Use closure under complement, union and De Morgan laws: L 1 ∩ L 2 = L 1 ∪ L 2 2 Idea: Let M i = ( Q i , q i , δ i , F i ) be DFA accepting L i for i = 1 , 2. Run M 1 and M 2 in parallel, and accept a word if both M 1 and M 2 accept. We define the product DFA M = ( Q , q , δ, F ) where Q = Q 1 × Q 2 = { ( p 1 , p 2 ) | p 1 ∈ Q 1 , p 2 ∈ Q 2 } = ( q 1 , q 2 ) q δ (( p 1 , p 2 ) , a ) = ( δ ( p 1 , a ) , δ 2 ( p 2 , a )) = F 1 × F 2 (both components accept) F Then L ( M ) = L ( M 1 ) ∩ L ( M 2 ) = L 1 ∩ L 2 . Helle Hvid Hansen 23 May 2014 FLGA 6 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma How to prove a language is not regular? To prove L is NOT regular, we must show that there is NO finite automaton that accepts L . There are many finite automata to check (infinitely many)... Helle Hvid Hansen 23 May 2014 FLGA 7 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma How to prove a language is not regular? To prove L is NOT regular, we must show that there is NO finite automaton that accepts L . There are many finite automata to check (infinitely many)... Observation: Suppose L = L ( M ) for some DFA with k states. Take a word w = a 1 · · · a n , where a i ∈ Σ, of length n ≥ k , and consider the run on w in M : a k a k +1 a 1 a 2 a n − → q 1 − → · · · − → q k − → · · · − → q n q 0 � �� � k +1 states There must be j , l ∈ { 0 , . . . , k } such that q j = q l . Helle Hvid Hansen 23 May 2014 FLGA 7 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma How to prove a language is not regular? To prove L is NOT regular, we must show that there is NO finite automaton that accepts L . There are many finite automata to check (infinitely many)... Observation: Suppose L = L ( M ) for some DFA with k states. Take a word w = a 1 · · · a n , where a i ∈ Σ, of length n ≥ k , and consider the run on w in M : a k a k +1 a 1 a 2 a n − → q 1 − → · · · − → q k − → · · · − → q n q 0 � �� � k +1 states There must be j , l ∈ { 0 , . . . , k } such that q j = q l . There is a “loop” through q j whose transitions are labelled by a j +1 · · · a l . So: w ∈ L iff a 1 · · · a j ( a j +1 · · · a l ) i a l +1 · · · a n ∈ L for all i ∈ N . We say a j +1 · · · a l is a pumpable substring of w (before index k ). Helle Hvid Hansen 23 May 2014 FLGA 7 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma The Pumping Lemma Pumping Property A language L has the Pumping Property (PP) if there is a k ∈ N such that for all words w ∈ L , if | w | ≥ k then there is a decomposition w = uvz with | uv | = k ′ ≤ k and | v | > 0, k ′ ≤ k w = a 1 · · · a j a j +1 · · · a k ′ a k ′ +1 · · · a n � �� � � �� � � �� � z u v such that for all i ∈ N , uv i z ∈ L . In words, L has the PP if there is a k ∈ N such that all words w ∈ L of length k or more have a pumpable substring before position k in w . Helle Hvid Hansen 23 May 2014 FLGA 8 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma The Pumping Lemma Pumping Property A language L has the Pumping Property (PP) if there is a k ∈ N such that for all words w ∈ L , if | w | ≥ k then there is a decomposition w = uvz with | uv | = k ′ ≤ k and | v | > 0, k ′ ≤ k w = a 1 · · · a j a j +1 · · · a k ′ a k ′ +1 · · · a n � �� � � �� � � �� � z u v such that for all i ∈ N , uv i z ∈ L . In words, L has the PP if there is a k ∈ N such that all words w ∈ L of length k or more have a pumpable substring before position k in w . Pumping Lemma: L is regular ⇒ L has the Pumping Property. So we have: L does not have the PP ⇒ L is not regular. Helle Hvid Hansen 23 May 2014 FLGA 8 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Games with the Demon L does not have the PP: For all k ∈ N there exists a w ∈ L such that | w | ≥ k , and for all decompositions w = uvz with | uv | ≤ k and | v | > 0, there exists an i ∈ N such that uv i z �∈ L . Helle Hvid Hansen 23 May 2014 FLGA 9 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Games with the Demon L does not have the PP: For all k ∈ N there exists a w ∈ L such that | w | ≥ k , and for all decompositions w = uvz with | uv | ≤ k and | v | > 0, there exists an i ∈ N such that uv i z �∈ L . Game between Demon and You: Demon wants to show that PP holds. You want to show that PP does not hold. Helle Hvid Hansen 23 May 2014 FLGA 9 / 12
Introduction Closure Properties Radboud University Nijmegen Pumping Lemma Games with the Demon L does not have the PP: For all k ∈ N there exists a w ∈ L such that | w | ≥ k , and for all decompositions w = uvz with | uv | ≤ k and | v | > 0, there exists an i ∈ N such that uv i z �∈ L . Game between Demon and You: Demon wants to show that PP holds. You want to show that PP does not hold. Demon (“for all”-player) You (“there exists”-player) 1. picks k ∈ N 2. pick w ∈ L : | w | ≥ k 3. picks u , v , z ∈ Σ ∗ : such that ( w = uvz ∧ | uv | ≤ k ∧ | v | > 0) 4. pick i ∈ N 5. Demon wins the game if uv i z ∈ L . You win if uv i z �∈ L . Helle Hvid Hansen 23 May 2014 FLGA 9 / 12
Recommend
More recommend