1 / 16

Properties of CFL’s

Properties of CFL’s. Reading: 8.1a and 8.2. Pumping Lemma for CFLs. Let L be a context-free language. Then there exists some positive integer m such that, if s is a string of length at least m, then s can be written as s = uvwxy such that: |vwx| <=m |vx| >0

zenevieva
Download Presentation

Properties of CFL’s

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Properties of CFL’s Reading: 8.1a and 8.2

  2. Pumping Lemma for CFLs • Let L be a context-free language. Then there exists some positive integer m such that, if s is a string of length at least m, then s can be written as • s = uvwxy such that: • |vwx| <=m • |vx| >0 • uviwxiy is also in L for any i >=0

  3. Why is it true? • If the language is finite, then it is regular and also context-free. • If it’s infinite, it still must have a finite number of non-terminals. • So, at least one non-terminal must be used more than once. • If A is used more than once, at least one derivation of it is recursive, and at least one is not (or it would be useless.)

  4. So… • Suppose the rule is A -> vAx A *-> w Then if I can generate s = uvwxy I can also generate s’ = uv2wx2y and uv3wx3y… by using the recursive rule for A more times.

  5. Using the Pumping Lemma to show a language is not CF. • Assume the language is context-free. • Show it does not satisfy the pumping lemma • Conclude (by contradiction) the language could not have been context-free.

  6. Example: axbxcx : x>0 • Opponent chooses m. • I choose s = ambmcm. • Opponent must choose uvwxy so that |vwx| is no more than m but at least one symbol. • There is no way that vwx contains all three characters. It contains either one or two. • Pumping the string up adds more of one or two characters than the third.

  7. Example: L = anbj j = n2 • Opponent chooses m. • I choose string ambm2 • Opponent chooses vwx. • If vwx contains a’s only, I can add to the number of a’s while the number of b’s stays the same. Likewise for b’s only. • If vwx contains a’s and b’s, only interesting case is v is some number of a’s (1<=k<=m) and x is some number of b’s (1<=p<=m). s’ = am+(i-1)k b m2 + (i-1)p • Choose i = 0; s’ = am-k b m2-p (m-k)2 <= (m-1)2 = m2 -2m +1 = m2 -(2m -1) < m2 -p

  8. Closure for CFLs • The family of context-free languages is closed under union: • L1 is a CFL with grammar G1, start symbol S1 • L2 is a CFL with grammar G2, start symbol S2 • Let L3 = L1UL2 • L3(G3) has start symbol S -> S1 | S2

  9. Closure for CFLs • The family of context-free languages is closed under star-closure. • Let L1 be a context-free language with grammar G1 and start symbol S1. • Let L be L1*. Then L(G) = S -> S S1 | λ

  10. Closure for CFL’s • The family of context-free languages is closed under concatenation. • Let L1 be a CFL with grammar G1 and start symbol S1. • Let L2 be a CFL with grammar G2 and start symbol S2. • Let L3 = L1 L2. • Then L3(G3) has start symbol S -> S1 S2.

  11. CFLs are not closed under intersection! • L1 = {anbncm: n,m >=0} • L2 = {anbmcm: n,m >=0} • L1 ∩ L2 = {anbncn: n >=0}

  12. CFL’s are not closed under complementation! • Suppose that CFL’s are closed under complementation. • Let L1 and L2 be CFLs. • L1 ∩ L2 = L1 U L2 • By closure under union and complementation, we get closure under intersection. • But we just showed that CFL’s are not closed under intersection! • Contradiction! So, CFL’s are not closed under complementation.

  13. Regular Intersection • The intersection of a regular language and a context-free language is context-free. • This is called closure under regular intersection. • Idea of proof: Make states equal to the states in the PDA x the states in the DFA.

  14. Proofs Using Closure • Prove that the language L = {w in {a,b,c}* where na(w) = nb(w) = nc(w)} is not context-free. • Assume L is context free. • L∩L(a*b*c*) = anbncn must be context-free by closure under regular intersection. • But it’s not, so L must not be context-free.

  15. Proofs Using Closure • Prove that the language L = {anbn; n>50} is context-free. • Idea: Don’t want to construct! Use closure. • Let L1 = {anbn} L1 is context-free. • Let L2 = {anbn; n<=50} L2 is Regular. • L = L1  L2, which is CF by closure under regular-intersection

  16. Decidable Properties • A CFL is empty if its start symbol is found to be useless. • A CFL is finite if no variable can ever repeat. • Draw the dependency graph of the language. • The language is infinite if and only if the graph contains a cycle.

More Related