CSCI 2670 Introduction to Theory of Computing September 23, 2004.

Slides:



Advertisements
Similar presentations
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Advertisements

Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
CS 3240: Languages and Computation Properties of Context-Free Languages.
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
CSCI 2670 Introduction to Theory of Computing September 15, 2004.
CS21 Decidability and Tractability
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
PDAs => CFGs Sipser 2.2 (pages ). Last time…
PDAs => CFGs Sipser 2.2 (pages ). Last time…
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
CS5371 Theory of Computation
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
1 Computer Language Theory Chapter 2: Context-Free Languages.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
CSCI 2670 Introduction to Theory of Computing September 15, 2005.
Context-free Languages
Context-free Languages Chapter 2. Ambiguity.
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Non-CF Languages The language L = { a n b n c n | n  0 } does not appear to be context-free. Informal: A PDA can compare #a’s with #b’s. But by the time.
CSCI 2670 Introduction to Theory of Computing September 13.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
 2004 SDU Lecture8 NON-Context-free languages.  2004 SDU 2 Are all languages context free? Ans: No. # of PDAs on  < # of languages on  Pumping lemma:
Theory of Languages and Automata By: Mojtaba Khezrian.
Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein.
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
Pushdown Automata.
Context-free Languages
Context-Free Grammars
فصل دوم Context-Free Languages
COSC 3340: Introduction to Theory of Computation
Chapter 2 Context-Free Language - 01
COSC 3340: Introduction to Theory of Computation
CS21 Decidability and Tractability
CS21 Decidability and Tractability
Presentation transcript:

CSCI 2670 Introduction to Theory of Computing September 23, 2004

2 Agenda Yesterday –Pushdown automata Today –Quiz –More on pushdown automata –Pumping lemma for CFG’s

September 23, A closer look at the transition rule (r i+1,b)  (r i,w i+1,a), where s i =at and s i+1 =bt for some a,b  ε and t  * –The top symbol is Pushed if a=ε and b  ε Popped if a  ε and b=ε Changed if a  ε and b  ε Unchanged if a=ε and b=ε –Symbols below the top of the stack may be considered, but not changed This is t’s role

September 23, Example Find  for the PDA that accepts all strings in {0,1} * with the same number of 0’s and 1’s 1.Need to keep track of “equilibrium point” with a $ on the stack 2.If stack top is not $, it contains the symbol currently dominating in the string

September 23, Example Find  for the PDA that accepts all strings in {0,1} * with the same number of 0’s and 1’s 3.Push a symbol on the stack as its read if 1.It matches the top of the stack, or 2.The top of stack is $ 4.Pop the symbol off the top of the stack if you read a 0 and the top of stack is 1 or vice versa

September 23, Example ε,ε$ε,ε$ 0,$  0$ 0,0  00 0,11  1 0,1$  $ 1,$  1$ 1,1  11 1,00  0 1,0$  $ ε,$  ε

September 23, Example ε,ε$ε,ε$ 0,$  0$ 0,0  00 0,1  ε 1,$  1$ 1,1  11 1,0  ε ε,$  ε This PDA is equivalent to the one on the previous slide

September 23, 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

September 23, 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 23, 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 23, Idea of PDA construction for A  xBz State control a b AtAt State control a b xBztxBzt

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

September 23, Constructing the PDA Q = {q start, q loop, q accept }  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 23, Constructing the PDA  is comprised of several rules 1.  (q start,ε,ε)=(q loop,S$) -Start with placeholder on the stack and with the start variable 2.  (q loop,a,a)=(q loop,ε) for every a  -Terminals may be read off the top of the stack 3.  (q loop,ε,A)=(q loop,w) for every rule A  w -Implement replacement rules 4.  (q loop,ε,$)=(q accept,ε) -Accept when the stack is empty

September 23, Example S  SS | (S) | () q start q loop q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  ()

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () S$S$ q loop

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop (S)$(S)$

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop S)$S)$ (

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop S SS)$SS)$ (

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop ()S)$()S)$ (

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop )S)$)S)$ ((

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop S)$S)$ (()

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop ())$())$ (()

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop ))$))$ (()(

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop )$)$ (()()

September 23, Example Read (()()) q start q accept ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop $ (()())

September 23, Example Read (()()) q start ε, ε  S$ε, $ εε, $ ε (,(  ε ),)  ε ε,S  SS ε,S  (S) ε,S  () q loop (()()) q accept

September 23, 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 x y z

September 23, The pumping lemma for CFG’s What might be repeated in a CFG? –The variables T R R uvx yz v & y will be repeated simultaneously

September 23, The pumping lemma for CFG’s T R R uvx yz T R u v y z R x y v R

September 23, The pumping lemma for CFG’s T R R uvx yz T R u x z

September 23, 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: 1.For each i  0, uv i xy i z  A 2.|vy| > 0 3.|vxy|  p

September 23, 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 b h 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 23, Proving the pumping lemma for CFG’s Let s be any string in A with length at least p = b |V|+2 and let  be a parse tree for s with the fewest possible nodes –The height of  is at least |V|+2 –The longest path in  has a length of at least |V|+2 Leaf is a terminal and at least |V|+1 variables –Some variable appears twice in the path

September 23, Proving the pumping lemma for CFG’s Let R be the last variable to appear twice on this path –The last two occurrences of R are both at most |V|+1 steps from the leaf T R R uvx yz } At most |V|+1 steps Question: What do we know about uv i xy i z? Answer: It is accepted by the PDA

September 23, Proving the pumping lemma for CFG’s Let R be the last variable to appear twice on this path –The last two occurrences of R are both at most |V|+1 steps from the leaf T R R uvx yz } At most |V|+1 steps Question: What do we know about |vy|? Answer: It is non-empty (because tree has fewest possible nodes)

September 23, Proving the pumping lemma for CFG’s Let R be the last variable to appear twice on this path –The last two occurrences of R are both at most |V|+1 steps from the leaf T R R uvx yz } At most |V|+1 steps Question: What do we know about |vxy|? Answer: It has at most p symbols (because at most |V|+1 steps)

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

September 23, Example (cont.) Show A is not context free, where A={a n |n is prime} Clearly, vy=a k for some k Consider the string uv n+1 xy n+1 z This string add n copies of a k to w – i.e., this is a n+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 23,