Properties of Context-Free Languages 2IT70 Finite Automata and - - PowerPoint PPT Presentation

properties of context free languages 2it70 finite
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Properties of Context-Free Languages 2IT70 Finite Automata and Process Theory

Technische Universiteit Eindhoven June 2, 2014

slide-2
SLIDE 2

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

slide-3
SLIDE 3

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

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

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

slide-17
SLIDE 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