properties of context-free languages

23
1 Properties of Context-Free Languages Is a certain language context-free? Is the family of CFLs closed under a certain operation?

Upload: krikor

Post on 03-Feb-2016

46 views

Category:

Documents


1 download

DESCRIPTION

Properties of Context-Free Languages. Is a certain language context-free? Is the family of CFLs closed under a certain operation?. Pumping Lemma. Let L be an infinite CFL. Then there exists m  0 such that any w  L with |w|  m can be decomposed as w = uvxyz where: |vy|  1 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Properties of Context-Free Languages

1

Properties of Context-Free Languages

• Is a certain language context-free?

• Is the family of CFLs closed under a certain operation?

Page 2: Properties of Context-Free Languages

2

Pumping Lemma

Let L be an infinite CFL. Then there exists m 0 such that any w L with |w| m can be decomposed as w = uvxyz where:

• |vy| 1

• |vxy| m

• uvixyiz L for all i 0

Page 3: Properties of Context-Free Languages

3

Pumping Lemma

Proof:

The RL case: S * xA * xyA * xyz

The CFL case: S * uAz * uvAyz * uvxyz

Page 4: Properties of Context-Free Languages

4

Moves in the Game

1. The opponent picks m 0.

2. We choose w L with |w| m.

3. The opponent chooses the decomposition w = uvxyz such that |vy| 1 and |vxy| m.

4. We pick i such that uvixyiz L.

Page 5: Properties of Context-Free Languages

5

Example

Prove L = {ww | w {a, b}*} is not a CFL.

Page 6: Properties of Context-Free Languages

6

Moves in the Game

1. The opponent picks m 0.

Page 7: Properties of Context-Free Languages

7

Moves in the Game

1. The opponent picks m 0.

2. We choose w = ambmambm.

Page 8: Properties of Context-Free Languages

8

Moves in the Game

1. The opponent picks m 0.

2. We choose w = ambmambm.

3. The opponent chooses the decomposition w = uvxyz such that |vy| 1 and |vxy| m.

m m m m

a . . . a b . . . b a . . . a b . . . b

u v x y z

Page 9: Properties of Context-Free Languages

9

Moves in the Game

1. The opponent picks m 0.

2. We choose w = ambmambm.

3. The opponent chooses the decomposition w = uvxyz such that |vy| 1 and |vxy| m.

m m m m

a . . . a b . . . b a . . . a b . . . b

u v x y z

4. We pick i such that uvixyiz L.

Page 10: Properties of Context-Free Languages

10

Example

Prove L = {anbncn | n 0} is not a CFL.

Page 11: Properties of Context-Free Languages

11

Linear Context-Free Languages

A CFL L is said to be linear iff there exists a linear CFG G such that L = L(G).

(A grammar is linear iff at most 1 variable can occur on the right side of any production)

Page 12: Properties of Context-Free Languages

12

Pumping Lemma for Linear CFLs

Let L be an infinite linear CFL. Then there exists m 0 such that any w L with |w| m can be decomposed as w = uvxyz where:

• |vy| 1

• |uvyz| m

• uvixyiz L for all i 0

Page 13: Properties of Context-Free Languages

13

Moves in the Game

1. The opponent picks m 0.

2. We choose w L with |w| m.

3. The opponent chooses the decomposition w = uvxyz such that |vy| 1 and |uvyz| m.

4. We pick i such that uvixyiz L.

Page 14: Properties of Context-Free Languages

14

Example

Prove L = {w | na(w) = nb(w)} is not linear.

Page 15: Properties of Context-Free Languages

15

Closure Properties of Context-Free Languages

L1 and L2 are context-free.

How about L1L2, L1L2 , L1L2 , L1, L1* ?

Page 16: Properties of Context-Free Languages

16

Theorem

If L1 and L2 are context-free, then so are L1L2 , L1L2 ,

L1*.

(The family of context-free languages is closed under union, concatenation, and star-closure.)

Page 17: Properties of Context-Free Languages

17

Proof

• G1 = (V1, T1, S1, P1) G2 = (V2, T2, S2, P2)

G3 = (V1V2{S3}, T1T2, S3, P1P2{S3 S1 | S2})

L(G3) = L(G1)L(G2)

Page 18: Properties of Context-Free Languages

18

Proof

• G1 = (V1, T1, S1, P1) G2 = (V2, T2, S2, P2)

G4 = (V1V2{S4}, T1T2, S4, P1P2{S4 S1S2})

L(G4) = L(G1).L(G2)

Page 19: Properties of Context-Free Languages

19

Proof

• G1 = (V1, T1, S1, P1)

G5 = (V1{S5}, T1, S5, P1{S5 S1S5 | })

L(G5) = L(G1)*

Page 20: Properties of Context-Free Languages

20

Theorem

The family of context-free languages is not closed under intersection and complement.

Page 21: Properties of Context-Free Languages

21

Proof

• L1 = {anbncm | n 0, m 0}

L2 = {anbmcm | n 0, m 0}

L = {anbncn | n 0} = L1L2

Page 22: Properties of Context-Free Languages

22

Proof

• L1L2 = L1L2

Page 23: Properties of Context-Free Languages

23

Homework

• Exercises: 2, 7, 8, 9, 14, 15, 16 of Section 8.1.

• Exercises: 2, 4, 10, 15 of Section 8.2.

• Presentations:

Section 12.1: Computability and Decidability + Halting Problem

Section 13.1: Recursive Functions

Post Systems + Church's Thesis

Section 13.2: Measures of Complexity + Complexity Classes