Properties of Context-Free Languages 2IT70 Finite Automata and - - PowerPoint PPT Presentation
Properties of Context-Free Languages 2IT70 Finite Automata and - - PowerPoint PPT Presentation
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
Context-free languages
language L is context-free if L = L(G) for CFG G theorem if L context-free then L = L(P) for PDA P theorem if L is regular then L is context-free proof DFA D = (Q, Σ, δ, q0, F ) gives PDA P = (Q, Σ, ∅, →P, q0, F ) with q
a[∅/ǫ]
- → q′ if δ(q,a) = q′
⊠
2 IT70 (2014) Properties of Context-Free Languages 2 / 17
Closure properties of context-free languages
theorem context-free languages L1, L2 and L (a) the union L1 ∪ L2 is also context-free (b) the concatenation L1 ⋅ L2 is also context-free (c) the Kleene closure L∗ is also context-free proof G1, G2, G with L(G1) = L1, L(G2) = L2, L(G) = L assume disjoint sets of variables say G1 = (V1, Σ, R1, S1 ), G2 = (V2, Σ, R2, S2 ), V1 ∩ V2 = ∅ construct new grammar G ′ = ({S′} ∪ V1 ∪ V2, Σ, R′, S′ )
⊠
2 IT70 (2014) Properties of Context-Free Languages 3 / 17
Clicker question L111
PDA P1 = (Q1, Σ, ∆1, →1, q1
0, F1 ) accepting L1 with n states
PDA P2 = (Q2, Σ, ∆2, →2, q2
0, F2 ) accepting L2 with m states
Which statement does not hold in general?
- A. We can construct a PDA for L1 ∪ L2 with n + m states
- B. We can construct a PDA for L1 ∪ L2 with n + m + 1 states
- C. We can construct a PDA for L1 ⋅ L2 with n + m states
- D. We can construct a PDA for L1 ⋅ L2 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
theorem context-free language L1, regular language L2 then L1 ∩ L2 is context-free proof PDA P = (Q1, Σ, ∆, ∅, →P, q1
0, F) for L1
DFA D = (Q2, Σ, δ, q2
0, F2) for L2
define PDA P′ = (Q1 × Q2, Σ, ∆, ∅, →P′, (q1
0,q2 0), F1 × F2) by
(q1,q2)
a[d/x]
- → P′ (q′
1,q′ 2) iff q1 a[d/x]
- → P q′
1 and δ(q2,a) = q′ 2
(q1,q2)
τ[d/x]
- → P′ (q′
1,q2) iff q1 τ[d/x]
- → P q′
1
claim ((q1,q2),w,z) ⊢∗
P′ ((¯
q1, ¯ q2),ε,z′) iff (q1,w,z) ⊢∗
P (¯
q1,ε,z′) and (q2,w) ⊢∗
D (¯
q2,ε) ⊠
2 IT70 (2014) Properties of Context-Free Languages 5 / 17
Clicker question L112
L1 ∩ L2 may not be regular for context-free L1 and regular L2 Why is this?
- A. Regular languages are not closed under intersection
- B. You cannot intersect a regular and a context-free language
- C. {anbn ∣ 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
theorem {anbncn ∣ n ⩾ 0} is not context-free a-part and c-part too far way
2 IT70 (2014) Properties of Context-Free Languages 7 / 17
The Pumping Lemma for regular languages
theorem if L ⊆ Σ∗ is a regular language then ∃m > 0 ∶ ∀w ∈ L, ∣w ∣ ⩾ m ∶ ∃x,y,z ∶ w = xy z ∧ ∣xy ∣ ⩽ m ∧ ∣y ∣ > 0 ∶ ∀i ⩾ 0 ∶ xy iz ∈ L
2 IT70 (2014) Properties of Context-Free Languages 8 / 17
Pumping lemma for context-free languages
theorem 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 iz ∈ 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. kh ⩽ ℓ
- D. ⌈ klog ℓ⌉ ⩽ h
- E. Can’t tell
2 IT70 (2014) Properties of Context-Free Languages 10 / 17
Auxilliary lemma
lemma a tree of height h and degree k has at most kh leaves corollary kh leaves then height at least h
2 IT70 (2014) Properties of Context-Free Languages 11 / 17
Pumping lemma for context-free languages (repeated)
theorem 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 iz ∈ 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 A A u z v y x
tree T subtree T ′ subtree T ′′
∣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.)
u z v y x S A A S A u z x u z v y v y x S A A A u z v y v y v y x S A A A A
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 iz ∈ L
the language L1 = {anbncn ∣ n ⩾ 0} is not context-free for any m > 0, consider ambmcm the language L2 = {w w ∣ w ∈ {a,b}∗ } is not context-free for any m > 0, consider ambmambm the language L3 = {an ∣ n prime } is not context-free for any m > 0, consider ap 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 proof intersect with a∗b∗c∗
⊠
corollary L1 ∩ L2 may not be context-free for context-free L1 and L2 proof L1 = {anbncm ∣ n,m ⩾ 0}, L2 = {anbmcm ∣ n,m ⩾ 0}
⊠
2 IT70 (2014) Properties of Context-Free Languages 17 / 17