Lecture 11  2004 SDU Lecture7 Pushdown Automaton.

Slides:



Advertisements
Similar presentations
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Advertisements

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Chapter 5 Pushdown Automata
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
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,
Pushdown Automata Part II: PDAs and CFG Chapter 12.
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.
CFG => PDA Sipser 2 (pages ). CS 311 Fall Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
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
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Lecture Pushdown Automata. stack stack head finite control tape head tape.
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
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.
Equivalence of Pushdown Automata and Context-Free Grammar Prof. Héctor Muñoz-Avila.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Lecture 11UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 11.
Formal Languages, Automata and Models of Computation
Lecture 14UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 14.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
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,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Theory of Computation Automata Theory Dr. Ayman Srour.
Recap: Nondeterministic Finite Automaton (NFA) A deterministic finite automaton (NFA) is a 5-tuple (Q, , ,s,F) where: Q is a finite set of elements called.
Formal Languages, Automata and Models of Computation
Pushdown Automata PDAs
Pushdown Automata PDAs
Chapter 2 Context-Free Language - 01
… NPDAs continued.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Presentation transcript:

Lecture 11  2004 SDU Lecture7 Pushdown Automaton

 2004 SDU 2 Push Down Automaton (PDA) Language Acceptor Model for CFLs It is an NFA with a stack. Finite State control Stack input

 2004 SDU 3 PDA (contd.) In one move the PDA can :  change state,  consume a symbol from the input tape or ignore it  pop a symbol from the stack or ignore it  push a symbol onto the stack or not A string is accepted provided the machine when started in the start state consumes the string and reaches a final state.

 2004 SDU 4 PDA (contd.) If PDA in state q can consume u, pop x from stack, change state to p, and push w on stack We show it as u, x  w p q u, x; w

 2004 SDU 5 Pushdown automata A pushdown automaton is a 6-tuple (Q, , , , q 0, F), where Q, , , F are finite sets, and 1. Q is the set of states, 2.  is the input alphabet, 3.  is the stack alphabet, 4.  : Q        P(Q    ) is the transition function, 5.q 0  Q is the start state, and 6.F  Q is the set of accept states.

 2004 SDU 6 Pushdown automata (cont.) M = (Q, , , , q 0, F) accepts a string w  * if w can be represented as w 1 …w m with w 1, …, w m   and there exist r 0, …, r m  Q and s 0, …, s m    * satisfying the following conditions: 1.r 0 = q 0 and s 0 =  2.For every i, 0  i  m-1, (r i, b)   (r i-1, w i, a), where s i-1 = at and s i = bt for some a, b    and t   * 3.r m  F  Here the stack is read from top to bottom (or left to right). Let M be a PDA, the language recognized by M is defined as L(M)={w | w is accepted by M}.

 2004 SDU 7 PDA, example 1 L = { 0 n 1 n | n  0} Design idea: 1.Use a special symbol $ to mark the bottom of the stack (using  wouldn’t work since  is always there) 2.First put onto the stack all the 0s preceding the 1s 3.Then try to match the stacked 0s with the 1s 4.The input string is in L, if and only if, the bottom $ is the top symbol when all the input symbols have been consumed.

 2004 SDU 8 Example 1 (cont.)  ={0,$}, Q={q 1,q 2,q 3,q 4 }, F = {q 1, q 4 }, q 1 is the start state. We use q 1 to place the $ on the stack, q 2 to read 0s and push them onto the stack (and react to the first 1), and q 3 to read 1s and pop 0s from the stack (and react to the $ by going to accept state q 4 ). As a diagram: q1q1 q4q4 q2q2 q3q3 ,$,$ 0,   0 1,0   , $  

 2004 SDU 9 PDAs Recognize CFLs Theorem. Each context-free language is recognized by a PDA. Proof. Let L be produced by a grammar G = (V, , R, S). Idea. Construct a PDA that performs leftmost derivations. A step of a derivation using A  w is implemented by popping the left-hand side and pushing the right-hand side of the rule onto the stack. The input string is checked whether can be produced by the grammar by comparing the consumed symbol with the produced symbol.

 2004 SDU 10 CFG  PDA Given CFG G = (V, , R, S) Let PDA M = (Q, ,   V  {$}, , q start, {q accept })  Q = {q start, q loop, q accept }  contains transitions for the form 1.  ’ (q start, ,  ) = (q loop, S$) ** 2.  ’ (q loop, , A) = {(q loop, w) | A  w  R } ** 3.For each symbol     (q loop, ,  ) = (q loop,  )  (q loop, , $) = (q accept,  ) q start q loop q accept ,  S$ , $   , A  w ,   **  ’(q, a, b)=(p, w) is a shorthand for a series of transitions, which consumes a, pops b, and pushing the string w, and changes state from q to p.

 2004 SDU 11 CFG  PDA The PDA simulates a leftmost derivation of the string. 1.Place the marker symbol $ and the start variable on the stack. 2.Repeat the following steps forever (a)If the top of stack is a variable symbol A, non-deterministically select one of the rules for A and substitute A by the string on the right-hand side of the rule. (b)If the top of stack is terminal symbol , read the next symbol from the input and compare it to . If they match, repeat. If they do not match, reject on this branch of the non-determinism. (c)If the top of stack is the symbol $, enter the accept state. Doing so accepts the input if it has all been read.

 2004 SDU 12 Example: S  aSb |  q0q0 q1q1 q2q2 q3q3 q4q4 q5q5 ,  ;$ , ,S ,S;b ,  ;S ,  ;a ,$;  b,b;  a,a;  ,S; 

 2004 SDU 13 Idea of PDA  CFG Each PDA P has an equivalent CFG G. First, we simplify our task by modifying P slightly to give it the following three features 1.It has a single accept state, q accept. 2.It empties its stack before accepting. 3.Each transition either pushes a symbol onto the stack (a push move) or pops one off the stack (a pop move), but does not do both at the same time.

 2004 SDU 14 PDA  CFG Suppose P = {Q, , , Δ, q 0, {q accept }}. To construct G: The variables of G are {A pq | p, q  Q}. A pq generates all the strings that can take P from p with an empty stack to q with an empty stack. Two possibilities occur during P ’ s computation on x. Either the symbol popped at the end is the symbol pushed at the beginning or not. First, simulated by Type 1 rules on next slide and the second by Type 2 rules.

 2004 SDU 15 PDA  CFG The start variable is A q0qaccept. Now we describe G ’ s rules.  [Type 1] For each p, q, r, s  Q, d  , and b, c   , if ((p, b,  ), (r, d)) is in Δ and ((s, c, d), (q,  )) is in Δ, put the rule A pq  bA rs c in G.  In other words, find pairs of transitions in the PDA such that the first transition in the pair pushes a symbol t and the second transition pops the same symbol t. Each such pair of transitions gives a Type 1 rule. The states p, q, r, s, and the symbols a, b are determined by looking at the transitions in the pair.

 2004 SDU 16 PDA  CFG  [Type 2] For each p, q, r  Q put the rule A pq  A pr A rq in G.  [Type 3] Finally, for each p  Q put the rule A pp   in G.

 2004 SDU 17 PDA  CGF

 2004 SDU 18 PDA  CFG Statement: A string w is derived by A pq if and only if w takes P from p with empty stack to q with empty stack. Proof.=>By induction on # of steps of derivations. For 1 step derivation, w = , and p = q, obviously true. Suppose it is true for k steps. For k+1 steps, if the first derivation is A pq  A pr A rq, then, w = xy, x is derived by A pr with less then k+1 steps, and y is derived by A rq with less than k+1 steps. By induction hypothesis, x takes P from q with empty stack to r with empty stack, y takes P from r with empty stack to q with empty stack. Then w takes P from p with empty stack to q with empty stack. If the first derivation is A pq  bA rs c, then w=bxc, and because of the existence of this rule, there must be transitions ((p, b,  ), (r, d)) and ((s, c, d), (q,  )) in Δ. Thus by induction hypothesis, x takes P from r with empty stack to s with empty stack, and since at states (p, b,  ) and (s, c, d), P pushes and pops the same symbol, bxc takes P from p with empty stack to q with empty stack.

 2004 SDU 19 PDA  CFG <=By induction on # of state transitions. For 0 transition, it must hold that p = q, and w = , obviously true. Suppose it is true for k transitions. For k+1 transitions, suppose w takes P from p with empty stack to q with empty stack, the first transition must push some symbol d. If the first pushed symbol d is popped out of the stack at the last transition, suppose w = bxc, where b and c are the two symbols consumed by P at the first and last transitions, then x takes P from r with empty stack to s with empty stack, where r and s are the second and the last second states. There must be a rue A pq  bA rs c. By induction hypothesis, A rs derives x. And thus A pq derives w. If the first pushed symbol is popped out of the stack in the middle of the transitions, then there must be a middle state r, such that d is popped out just before P entering state r. Then w = xy, where x takes P from p with empty stack to r with empty stack, and y takes P from r with empty stack to q with empty stack. Then by induction hypothesis, A pr derives x, A rq derives y, and thus A pq derives w = xy by first deriving A pr A rq.