overview
play

Overview CS20a: summary (Oct 24, 2002) Context-free languages - PDF document

Overview 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


  1. Overview 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 U T S T I T E O F N T I A E C I H N N Computation, Computers, and Programs CFG/PDA R O O I 1 F I O L L A G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences 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 S T I O F N T I A E C I H N N Computation, Computers, and Programs CFG/PDA R O O I 2 F I O L L A G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences 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 S T I O F I N E T A C I N H N Computation, Computers, and Programs CFG/PDA R O O 3 F L I I L O A G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

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

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

  4. Overview 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 U S T T I T E O F N T I A E C I H N N Computation, Computers, and Programs CFG/PDA R O O I 10 I F L O L A G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences 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 S T I O F N T A I E C I H N N Computation, Computers, and Programs CFG/PDA R O O I 11 F I O L L A G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences 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 S T I O F I N E T A C I N H N Computation, Computers, and Programs CFG/PDA O R O 12 F L I I L O A G http://www.cs.caltech.edu/courses/cs20/a/ October 25, 2002 C Y If this page displays slowly, try turning off the “smooth line art” option in Acrobat, under Edit->Preferences

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