1 / 34

CSCI 2670 Introduction to Theory of Computing

CSCI 2670 Introduction to Theory of Computing. September 22, 2005. Agenda. Yesterday Pushdown automata Today Equivalence of pushdown automata and CFG’s Pumping lemma for CFG’s. Announcements. Matrix Reloaded tonight! 6:30 in Boyd 328 Free popcorn 25 cent Coke

idalia
Download Presentation

CSCI 2670 Introduction to Theory of Computing

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. CSCI 2670Introduction to Theory of Computing September 22, 2005

  2. Agenda • Yesterday • Pushdown automata • Today • Equivalence of pushdown automata and CFG’s • Pumping lemma for CFG’s September 22, 2005

  3. Announcements • Matrix Reloaded tonight! • 6:30 in Boyd 328 • Free popcorn • 25 cent Coke • Pizza will be ordered at cost if people want September 22, 2005

  4. Equivalence of PDA’s and CFG’s Theorem: A language is context free if and only if some pushdown automaton recognizes it Proved in two lemmas – one for the “if” direction and one for the “only if” direction We will only do the “only if” step – i.e., show that every context-free language has an associated PDA September 22, 2005

  5. CFG’s are recognized by PDA’s Lemma: If a language is context free, then some pushdown automaton recognizes it Proof idea: Construct a PDA following CFG rules September 22, 2005

  6. Have a transition for each rule replacing the variable with its right hand side ε,Aw Finish only if the stack is empty ε, ε S$ ε,$ε qstart qaccept qloop Have a transition that allows us to read each alphabet symbol if it is at the top of the stack Start by pushing the start variable and stack bottom marker a,aε CFG’s are recognized by PDA’s Format of the new PDA September 22, 2005

  7. Constructing the PDA • You can read any symbol in  when that symbol is at the top of the stack • Transitions of the form a,aε • The rules will be pushed onto the stack – when a variable A is on top of the stack and there is a rule Aw, you pop A and push w • You can go to the accept state only if the stack is empty September 22, 2005

  8. State control State control a b a b x B z t A t Idea of PDA construction for AxBz September 22, 2005

  9. ε, εB ε,Az ε, εx Actual construction for AxBz In an abuse of notation, we say (q,ε,A)=(q,xBz) September 22, 2005

  10. Constructing the PDA • Q = {qstart, qloop, qaccept}E, where E is the set of states used for replacement rules onto the stack •  (the PDA alphabet) is the set of terminals in the CFG •  (the stack alphabet) is the union of the terminals and the variables and {$} (or some suitable placeholder) September 22, 2005

  11. Constructing the PDA •  is comprised of several rules • (qstart,ε,ε)=(qloop,S$) • Start with placeholder on the stack and with the start variable • (qloop,a,a)=(qloop,ε) for every a • Terminals may be read off the top of the stack • (qloop,ε,A)=(qloop,w) for every rule Aw • Implement replacement rules • (qloop,ε,$)=(qaccept,ε) • Accept when the stack is empty September 22, 2005

  12. ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε Example • S  SS | (S) | () September 22, 2005

  13. Example • Read (()()) ε,SSS ε,S(S) ε,S() S $ ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε September 22, 2005

  14. Example • Read (()()) ( S ) $ ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε September 22, 2005

  15. Example • Read (()()) S ) $ ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε ( September 22, 2005

  16. Example SS ) $ • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε ( September 22, 2005

  17. Example ( ) S ) $ • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε ( September 22, 2005

  18. Example ) S ) $ • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (( September 22, 2005

  19. Example S ) $ • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (() September 22, 2005

  20. ( ) ) $ Example • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (() September 22, 2005

  21. ) ) $ Example • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()( September 22, 2005

  22. ) $ Example • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()() September 22, 2005

  23. $ Example • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()()) September 22, 2005

  24. Example • Read (()()) ε,SSS ε,S(S) ε,S() ε, ε S$ ε,$ε qstart qloop qaccept (,(ε ),)ε (()()) September 22, 2005

  25. y x z The pumping lemma for RE’s • The pumping lemma for RE’s depends on the structure of the DFA and the fact that a state must be revisited • Only a finite number of states September 22, 2005

  26. T R R u v x y z v & y will be repeated simultaneously The pumping lemma for CFG’s • What might be repeated in a CFG? • The variables September 22, 2005

  27. T R T R R R R u v x y z z u y y v v x The pumping lemma for CFG’s September 22, 2005

  28. T R T R R x u v x y z u z The pumping lemma for CFG’s September 22, 2005

  29. The pumping lemma for CFL’s Theorem: If A is a context-free language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divided into five pieces s=uvxyz satisfying the conditions: • For each i  0, uvixyiz  A • |vy| > 0 • |vxy|  p September 22, 2005

  30. Finding the pumping length of a CFL • Let b equal the longest right-hand side of any rule (assume b > 1) • Each node in the parse tree has at most b children • At most bh nodes are h steps from the start node • Let p equal b|V|+2, where |V| is the number of variables (could be huge!) • Tree height is at least |V|+2 September 22, 2005

  31. Example • Show A is not context free, where A={an|n is prime} Proof: Assume A is context-free and let p be the pumping length of A. Let w=an for any np. By the pumping lemma, w=uvxyz such that |vxy|p, |vy|>0, and uvixyizA for all i=0,2,1…. September 22, 2005

  32. Example (cont.) • Show A is not context free, where A={an|n is prime} Clearly, vy=ak for some k Consider the string uvn+1xyn+1z This string add n copies of ak to w – i.e., this is an+nk Since the exponent is n(1+k) this in not in A, which contradicts the pumping lemma. Therefore, A is not context free. September 22, 2005

  33. Have a fun weekend! September 22, 2005

  34. Let's work on the practice test! September 22, 2005

More Related