22
Lecture Note of 12/22 jinnjy

Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

  • View
    217

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Lecture Note of 12/22

jinnjy

Page 2: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Outline

Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free

Languages Closure Properties of CFL

Page 3: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Chomsky Normal Form

A CFG is in Chomsky normal form if every form is of the form

A BC A a

Notice that we permit the rule S,where S is the start variable

Page 4: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Convert a CFG to an equivalent one in Chomsky Normal Form

1. Add a new start variable

2. Eliminate all rules of the form A .3. Eliminate all unit rules of the form AB.

4. Convert the remaining rules into the proper form.

Sipser’s method.

Page 5: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Convert a CFG to an equivalent one in Chomsky Normal Form (Cont’d)

1. Add a new start variable (optional)

2. Eliminate all rules of the form A .3. Eliminate all unit rules of the form AB.

4. Eliminate useless symbol

5. Convert the remaining rules into the proper form.

Method used in handout.

Page 6: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Convert a CFG to an equivalent one in Chomsky Normal Form (Cont’d) Why not eliminate all unit rules before eliminati

ng all rules? Ans: Unit rules may appear again after all rules are

eliminated.

Page 7: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Ex: 2.15

A BAB | B |

B00 |

Add new start symbol S. And after all unit rules eliminated:

SBAB | 00 |

A BAB | 00 |

B00 |

After all rules eliminated (S) is permitted:

S BAB | 00 | | BA | AB | A | BB | B

A BAB | 00 | BA | AB | A | BB | B

B00

AB appear again!!

Page 8: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Eliminate Useless Symbols We say a symbol X is generating if X can deriv

e some terminal string w, in zero or more steps. EX: Consider

S BC | BB | | 1

BSS

CBD

D is not generating, it can’t derive any terminal string.

C is also non-generating, since it can only change to BD

Page 9: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Algorithm used to Eliminate Nongenerating Symbols Basis: If X is a terminal , X is generating. Induction: Assume there is a production X,

and every symbol appear in is already known to be generating, then A is generating.

Page 10: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Eliminate Useless Symbols We say a variable X is reachable if S can deriv

e some string X, for some and . EX: Consider

S BB | | 1

BSS

DSB

D is not reachable from S.

Page 11: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Algorithm used to Eliminate Nonreachable Symbols Basis: The start symbol S is reachable. Induction: If variable A is reachable, then all sy

mbols appears in the rules of the form A is reachable.

Page 12: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

CYK Algorithm Purpose: Decide whether a string w is in a CFL L, assume

we have a CFG G in Chomsky Normal Form s.t. L(G)=L. Fact: w is in L iff there exists terminal strings x, y s.t. w=xy

and there exists a rule S AB s.t. A can derive x and B can derive y.

Page 13: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

CYK Algorithm Triangular table construction:

X1,n

X1,n-1

X1,2

X1,1

X2,n

X2,2

… …

Xn-1,n

… Xn,n

Page 14: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

D=“On input w=a1a2…an (page 241)1.If w= and S→ is a rule, accept2.For i=1 to n3 For each variable A

4 Test whether A→b is a rule, where b=wi

5 if so, place A in Xii

6.For l=2 to n7. For i=1 to n-l+18. j=i+l-19. For k=i to j-110. For each rule A→BC

11. If Xi, k contains B and

Xk+1, j contains C

Put A in Xi, j

12.If S is in X1,n, ACCEPT;otherwise Reject. “

Page 15: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL
Page 16: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Closure Properties of CFL

CFL is closed under: Union Concatenation Kleene closure(*), and positive closure(+) Homomorphism Reversal

Page 17: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Substitution Substitiution:

Generalization of homomorphism Extensions: ( )

( ) ( ) ( )

( ) { ( )}w L

s

s xa s x s a

s L s w

* * **: 2 2 2s or

Page 18: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL
Page 19: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

CFL is Closed Under Reversal Proof:

Assume L is a CFL with a CFG G=(V,T,P,S) We construct the CFG (V,T,PR,S)for LR:

V,T,S are the same as G For all rules A in P, PR contains the corresponding rul

e: AR

Page 20: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Decision Properties of CFL The following properties are decidable

Emptiness (Is L empty?) Membership (w in L?) Finite/ Infinite (Is L finite?)

Page 21: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL

Decision Properties of CFL The following properties are undecidable

Ambiguity (Is grammar G ambiguous?) Equivalence (L1 = L2?)

Empty Intersection (L1L2 =?) * equivalence (L=* ?) Inherently Ambiguity (Is L ambiguity ambiguous?)

Page 22: Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL