cs20a summary oct 24 2002
play

CS20a: summary (Oct 24, 2002) Context-free languages Grammars G = - PowerPoint PPT Presentation

CS20a: summary (Oct 24, 2002) Context-free languages Grammars G = (V, T, P, S) Pushdown automata N-PDA = CFG D-PDA < CFG Today What languages are context-free? Pumping lemma (similar to pumping lemma for regular


  1. CS20a: summary (Oct 24, 2002) • Context-free languages – Grammars G = (V, T, P, S) • Pushdown automata – N-PDA = CFG – D-PDA < CFG • Today – What languages are context-free? • Pumping lemma (similar to pumping lemma for regular languages) • Ogden’s lemma T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 1 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  2. Regular languages • Intuition: if a FA accepts a string that is “long enough,” it must repeat a state – But it can’t remember that the state was repeated – So it can be forced to repeat the state over and over aj+1,...,ak a1,...,aj ak+1,...,am q0 qj=qk qm T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 2 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  3. Pumping lemma for regular languages Lemma (the Pumping Lemma) • Let L be a regular set. • There is a constant n s.t. for any z where | z | ≥ n , then z can be written z = uvw , where – | uv | ≤ n – | v | ≥ 1 – For all i ≥ 0, uv i w ∈ L – n is bounded by | Q | T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 3 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  4. Pumping lemma for CFL Lemma Let L be a CFL. Then there is a constant n such that for any string z ∈ L where | z | ≥ n , then z = uvxyz and • | vx | ≥ 1 • | vwx | ≤ n • uv i wx i y ∈ L for i ≥ 0 T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 4 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  5. Pumping lemma • Suppose L is in Chomsky Normal Form – A � a – A � BC T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 5 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  6. Derivation trees S Path Path length = i 2i symbols T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 6 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  7. Size of derivation trees Theorem S Path Each derivation tree with max path length = i generates a word of at most 2i-1 symbols Path length = i S Base case: a 2i symbols S Step: Max path length = i - 1 2i-2 symbols T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 7 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  8. Pumping S A S Pump A A u v y x A A u y v w x v w x T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 8 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  9. Pumping example 1 The language L = { a i b i c i | i ∈ N } is not context-free. Proof • Suppose it is, and let n be the constant in the pumping lemma. • Consider a string z = a n b n c n ∈ L , and write it as z = uvwxy • By the P.L. | vx | ≥ 1 and | vwx | ≤ n • Then vx can't contain a 's, b 's, and c 's • So uv i wx i y will change counts of at most 2 sym- bols, which is a contradiction. T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 9 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  10. Pumping lemma is too weak The language L = { a i b j c k d l | i = 0 ∨ j = k = l } is not context-free. • Attempt 1 – Consider a string z = b j c k d l ∈ L , and write it as z = uvwxy – Then vwx might contain only b 's, no use • Attempt 2 – Consider a string z = a i b j c k d l – Then vwx might contain only a 's, no use T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 10 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  11. Ogden’s lemma Ogden's Lemma Let L be a CFL. Then there is a constant n , then for any z ∈ L we can mark n or more positions of z = uvwxy , such that: • v and x have at least one marked symbol • vwx has at most n marked symbols • uv i wx i y ∈ L for i ≥ 0 T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 11 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  12. Building a path Proof Let G be a grammar for L −{ ǫ } in Chomsky normal form, with k productions. Let n = 2 k + 1. Construct a path P by the following algorithm: Base Add the root to P Step Let r be the last vertex on P – If r is a terminal, stop – If r has two children, pick the one that has the most marked descendents and add it to r . T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 12 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  13. Building the path Branch points Constructed path P b b b * * * * * * * Marked symbols T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 13 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  14. Branch points • A point r in P is called a branch point if both chil- dren have marked descendents. • Each branch point in P has at least half as many marked descendents as the previous branch point. • Since there are at least n marked symbols in z , there are at least k + 1 branch points in P . • Two of the branch points must have the same la- bel. T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 14 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  15. An example (part 1) The language L = { a i b j k l | i, j, k are different } is not context-free. • Let n be the constant on Ogden's lemma • Consider z = a n b n + n ! c n + 2 n ! • Mark all the a 's, and let z = uvwxy • If either v or x contains two different symbols, then pumping will destroy the symbol order • Otherwise, at least on of v or x contains a 's (since a 's are marked) T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 15 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

  16. An example (part 2) • Consider the case where v ∈ a + and x ∈ b ∗ (other cases are similar) • Let p = | v | , so p divides n !; let pq = n ! • Then z ′ = wv 2 q + 1 wx 2 q + 1 y is in L • But a 2 q + 1 = a 2 pq + p = a 2 n ! + p • So, z ′ has (n + 2 n ! ) a 's; it also has (n + 2 n ! ) c 's, a contradiction. T U T E I O T S F N T I E A C I H N N Computation, Computers, and Programs CFG/PDA R O O 16 I F L I L O G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 A C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend