Properties of Context-Free Languages 2IT70 Finite Automata and Process Theory Technische Universiteit Eindhoven June 2, 2014
Context-free languages language L is context-free if L = L( G ) for CFG G if L context-free then L = L( P ) for PDA P theorem if L is regular then L is context-free theorem proof DFA D = ( Q , Σ , δ, q 0 , F ) gives PDA P = ( Q , Σ , ∅ , → P , q 0 , F ) a [∅/ ǫ ] → q ′ if δ ( q , a ) = q ′ with q ⊠ � � � 2 IT70 (2014) Properties of Context-Free Languages 2 / 17
Closure properties of context-free languages context-free languages L 1 , L 2 and L theorem (a) the union L 1 ∪ L 2 is also context-free (b) the concatenation L 1 ⋅ L 2 is also context-free (c) the Kleene closure L ∗ is also context-free G 1 , G 2 , G with L( G 1 ) = L 1 , L( G 2 ) = L 2 , L( G ) = L proof assume disjoint sets of variables say G 1 = ( V 1 , Σ , R 1 , S 1 ) , G 2 = ( V 2 , Σ , R 2 , S 2 ) , V 1 ∩ V 2 = ∅ construct new grammar G ′ = ({ S ′ } ∪ V 1 ∪ V 2 , Σ , R ′ , S ′ ) ⊠ 2 IT70 (2014) Properties of Context-Free Languages 3 / 17
Clicker question L111 PDA P 1 = ( Q 1 , Σ , ∆ 1 , → 1 , q 1 0 , F 1 ) accepting L 1 with n states PDA P 2 = ( Q 2 , Σ , ∆ 2 , → 2 , q 2 0 , F 2 ) accepting L 2 with m states Which statement does not hold in general? A. We can construct a PDA for L 1 ∪ L 2 with n + m states B. We can construct a PDA for L 1 ∪ L 2 with n + m + 1 states C. We can construct a PDA for L 1 ⋅ L 2 with n + m states D. We can construct a PDA for L 1 ⋅ L 2 with n + m + 1 states E. Can’t tell 2 IT70 (2014) Properties of Context-Free Languages 4 / 17
Intersection of context-free and regular language context-free language L 1 , regular language L 2 theorem then L 1 ∩ L 2 is context-free PDA P = ( Q 1 , Σ , ∆ , ∅ , → P , q 1 0 , F ) for L 1 proof DFA D = ( Q 2 , Σ , δ, q 2 0 , F 2 ) for L 2 define PDA P ′ = ( Q 1 × Q 2 , Σ , ∆ , ∅ , → P ′ , ( q 1 0 , q 2 0 ) , F 1 × F 2 ) by a [ d / x ] a [ d / x ] → P ′ ( q ′ 1 , q ′ → P q ′ 1 and δ ( q 2 , a ) = q ′ ( q 1 , q 2 ) 2 ) iff q 1 � � 2 τ [ d / x ] τ [ d / x ] → P ′ ( q ′ → P q ′ ( q 1 , q 2 ) 1 , q 2 ) iff q 1 � � 1 claim (( q 1 , q 2 ) , w , z ) ⊢ ∗ q 2 ) ,ε, z ′ ) P ′ (( ¯ q 1 , ¯ iff ( q 1 , w , z ) ⊢ ∗ q 1 ,ε, z ′ ) and ( q 2 , w ) ⊢ ∗ P ( ¯ D ( ¯ q 2 ,ε ) ⊠ 2 IT70 (2014) Properties of Context-Free Languages 5 / 17
Clicker question L112 L 1 ∩ L 2 may not be regular for context-free L 1 and regular L 2 Why is this? A. Regular languages are not closed under intersection B. You cannot intersect a regular and a context-free language C. { a n b n ∣ n ⩾ 0 } ∩ a ∗ b ∗ is not regular D. The complement of a context-free language need not be context-free E. Can’t tell 2 IT70 (2014) Properties of Context-Free Languages 6 / 17
A language that is not context-free { a n b n c n ∣ n ⩾ 0 } is not context-free theorem a -part and c -part too far way 2 IT70 (2014) Properties of Context-Free Languages 7 / 17
The Pumping Lemma for regular languages if L ⊆ Σ ∗ is a regular language then theorem ∃ m > 0 ∶ ∀ w ∈ L , ∣ w ∣ ⩾ m ∶ ∃ x , y , z ∶ w = xy z ∧ ∣ xy ∣ ⩽ m ∧ ∣ y ∣ > 0 ∶ ∀ i ⩾ 0 ∶ xy i z ∈ L 2 IT70 (2014) Properties of Context-Free Languages 8 / 17
Pumping lemma for context-free languages if L ⊆ Σ ∗ is a context-free language then theorem ∃ m > 0 ∶ ∀ w ∈ L , ∣ w ∣ ⩾ m ∶ ∃ u , v , x , y , z ∶ w = uv xy z ∧ ∣ v xy ∣ ⩽ m ∧ ∣ v y ∣ > 0 ∶ ∀ i ⩾ 0 ∶ uv i xy i z ∈ L 2 IT70 (2014) Properties of Context-Free Languages 9 / 17
Clicker question L113 tree T of degree k , with height h , and ℓ leaves Which inequation is generally valid? A. ℓ ⩽ h ∗ ( k − 1 ) + 1 B. k + h ∗ k ⩽ ℓ C. k h ⩽ ℓ D. ⌈ k log ℓ ⌉ ⩽ h E. Can’t tell 2 IT70 (2014) Properties of Context-Free Languages 10 / 17
Auxilliary lemma a tree of height h and degree k has at most k h leaves lemma k h leaves then height at least h corollary 2 IT70 (2014) Properties of Context-Free Languages 11 / 17
Pumping lemma for context-free languages (repeated) if L ⊆ Σ ∗ is a context-free language then theorem ∃ m > 0 ∶ ∀ w ∈ L , ∣ w ∣ ⩾ m ∶ ∃ u , v , x , y , z ∶ w = uv xy z ∧ ∣ v xy ∣ ⩽ m ∧ ∣ v y ∣ > 0 ∶ ∀ i ⩾ 0 ∶ uv i xy i z ∈ L 2 IT70 (2014) Properties of Context-Free Languages 12 / 17
Proof of the pumping lemma S tree T CFG G with at most k symbols on RHS of production rule 2 IT70 (2014) Properties of Context-Free Languages 13 / 17
Proof of the pumping lemma S tree T A u z subtree T ′ A y v subtree T ′′ x ∣ w ∣ ⩾ k # V + 1 , variable A last repeated variable ∗ ∗ ∗ S ⇒ G uAz ⇒ G uvAyz ⇒ G uvxyz 2 IT70 (2014) Properties of Context-Free Languages 14 / 17
Proof of the pumping lemma (cont.) S S S S A A A A u z u z u z u z x A A A y y y v v v x A A y y v v x A v y x pumping of the A − v − A − y subtree 2 IT70 (2014) Properties of Context-Free Languages 15 / 17
Some languages that are not context-free Pumping Lemma: if L ⊆ Σ ∗ is a context-free language then ∃ m > 0 ∶ ∀ w ∈ L , ∣ w ∣ ⩾ m ∶ ∃ u , v , x , y , z ∶ w = uv xy z ∧ ∣ v xy ∣ ⩽ m ∧ ∣ v y ∣ > 0 ∶ ∀ i ⩾ 0 ∶ uv i xy i z ∈ L the language L 1 = { a n b n c n ∣ n ⩾ 0 } is not context-free for any m > 0, consider a m b m c m the language L 2 = { w w ∣ w ∈ { a , b } ∗ } is not context-free for any m > 0, consider a m b m a m b m the language L 3 = { a n ∣ n prime } is not context-free for any m > 0, consider a p for prime p ⩾ m 2 IT70 (2014) Properties of Context-Free Languages 16 / 17
More consequences of the pumping lemma lemma { w ∈ { a , b , c } ∗ ∣ # a ( w ) = # b ( w ) = # c ( w )} is not context-free intersect with a ∗ b ∗ c ∗ ⊠ proof corollary L 1 ∩ L 2 may not be context-free for context-free L 1 and L 2 L 1 = { a n b n c m ∣ n , m ⩾ 0 } , L 2 = { a n b m c m ∣ n , m ⩾ 0 } ⊠ proof 2 IT70 (2014) Properties of Context-Free Languages 17 / 17
Recommend
More recommend