5 Pages

lec16

Course: CS 322, Fall 2009
School: Washington
Rating:
 
 
 
 
 

Word Count: 3545

Document Preview

322 CSE - Introduction to Formal Methods in Computer Science Pushdown Automata And Context-Free Languages Dave Bacon Department of Computer Science & Engineering, University of Washington Having introduced pushdown automata, we will now show that pushdown automata recognize exactly the class of context free languages. In other words we will prove the theorem Theorem A language is context free if and only...

Register Now

Unformatted Document Excerpt

Coursehero >> Washington >> Washington >> CS 322

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
322 CSE - Introduction to Formal Methods in Computer Science Pushdown Automata And Context-Free Languages Dave Bacon Department of Computer Science & Engineering, University of Washington Having introduced pushdown automata, we will now show that pushdown automata recognize exactly the class of context free languages. In other words we will prove the theorem Theorem A language is context free if and only if some pushdown automaton recognize it. To prove this we will prove each direction of the if and only if separately. We will begin with showing that if a language is context free then some pushdown automaton recognizes it. CFL NPDA I. Okay so we want to show that if a language is context free, then there exists some pushdown automaton which recognizes this language. We will do this by showing how to take a context free grammar for the context free language and construct a NPDA which recognizes the context free language. In other words is A is a context free language, there exists a context free grammar G which generates this language. We will show how to convert the context free grammar G into an NPDA which we call P , which recognizes A. The basic idea of how to construct this NPDA is as follows. Think about some context free grammar G. If we are deriving a string using this grammar, we start with the start variable, and then follow a set of rules to create a string w. But there were many choices of rules we could make at each step in our derivation. Okay, so when we think about these choices, it is natural to think of nondeterminism. Suppose we have a NPDA which nondeterministically chooses to apply one of the valid rules. But where do we put the rules we are deriving? In a NPDA we only have access to the top of the stack. Well now think about left most derivations. In a leftmost derivation you are always replacing variables the farthest to the left. And note that if there are any terminals to the left of the variables you are replacing, no matter what you do, these terminals will be at the start of the string you are deriving. Using this insight we can now figure out how to construct a NPDA which recognizes the language of G. 1. Place a bottom of stack marker onto the stack and then place the start variable on top of the stack. 2. Repeat: (a) If the top of the stack is a variable A, nondeterministically select one of the rules that applies to A and substitute what A turns into using this rule for A. (b) If the top of the stack is a terminal symbol, read the next symbol from the input and compare it to a. If they match continue looping. If they don't match, reject, i.e. let the computation die. (c) If the top of the stack is the bottom of stack variable, then enter the accept state. If more symbols are to be read, then there should be no transitions out of the accept state. Okay, so this is the basic idea of the construction. Now we can make this a little more rigorous. But before we do this, lets develop a little trick: how to create NPDA which instead of replacing the top symbol with a single element from the stack alphabet, replaces the top element with a a string from the stack alphabet. Suppose that we want the NPDA on input symbol a, and stack string s to transition from state q1 to state q2 and replace the string s with xyz. We can do this by adding ancillary states, call them a1 and a2 and creating the transition q1 a,sz G a1 ,y G a2 ,x G q2 Thus we see that this will have exactly the affect we desire. If the input symbol being read is a and the top of the stack is s, then state q1 transitions to state a1 and replaces the top of the stack with z. Then the machine makes a transition to a2 independent of what is on top of the stack, and writes y to the top of the stack. The machine then makes another transition to q2 and pushes x onto the top of the stack. Note that the machine will stay in the state a1 and a2 , since there are no outgoing transitions these will always just die out upon a symbol being read. Okay so now that we see how to do this, lets comment that we will often use this shorthand. Normally, we say things like 2 (r, u) (q, a, s) to mean that the when the machine is in the state q, the next input symbol is a, and the top of the stack is s, then the NPDA may go to the state r and replace a with u. We will now use a shorthand where u can be not just a single symbol for the stack, but a list of symbols to be pushed onto the top of the stack (replacing s). Okay, now lets show how to construct a NPDA which recognizes a grammar G = (V, , R, S). This machine will be M = (Q, , , , q0 , F ). The states of the NPDA are Q = {qs , ql , qa } E where E are the states needed to implement the multi-symbol pushing described above. Wow, kind of cool, just three states (okay and all of those hidden in E.) The start state is q0 = qs and there is only one accept state F = {qa }. The input alphabet will be the same as the grammar's alphabet. The stack alphabet will be = V {$}. We begin by preparing the stack. This means we need to push the string S$ onto the stack where S is the start variable for the grammar. In other words we want to set (qs , , ) = {(ql , S$)} (note that this will require a single extra state to implement pushing a two symbol string onto the top of the stack.) Now we need to figure out how to implement the inner loop of our algorithm specified above. Note that there are two cases we must deal with, one when the top of the stack is a variable and one when the top of the stack is an input string. Let's deal with the case where the top of the stack is a variable first. Okay so at the top of the stack we have a variable. We now need to replace this top of the stack variable with one of the new rules for this variable. Thus we need to define the transition (ql , , A) = {(ql , w)| where A w is a rule in R}. Note here that w is a string of variables and terminals. Next we need to need to deal with the case where the stack has a terminal. In this case we need to read the next symbol of the input and see if it matches. And if it does match we need to pop it off the top of the stack. We can do this via setting (q, a, a) = {(ql , )}. Finally we need to handle the case where the empty stack market it at the top of the stack. In this case we need to transition to the accept state. This can be done via (ql , , $) = {(qa , )}. A. Example Lets show the resulting NPDA state diagram for this derivation from an example grammar G. Let this grammar be S 0S1|T | T 1T 0|0| Lets draw the state diagram, including the ancillary states we need to define the multisymbol stack pushing: ,S G a3 a2 a r { rr { rr {{ ,$ rr {{ rr { rr { ,S1 { { rr a1 { rrrr { {{ rr ,0 {{rrrr ,S {{ r {{ rr B {rr 0 yr ,T G a4 ,T G a5 ql i ,ST ;0,0;1,1;,S;,T ;,T 0 ,1 ,$ G qs qa II. NPDA CFL Having shown that we can convert a CFL into a NPDA which recognizes this language, we will now show how to take a NPDA and convert it into a CFG which recognizes the same language as the NPDA. Let P be the NPDA we are going to convert into a CFG. Before performing this construction, however, we modify P slightly without changing the language it recognizes. In particular we assume that P has a single accept state and that it empties the stack before accepting. How can we modify P such that this is always true? Well first suppose that we use a bottom of stack symbol $ (if our NPDA doesn't use one we can add one.) Then add two new states. The first state will not be an accept state while the second state will be an accept state. Now we make , 3 transitions from the accept state to the non-accept new state (here we mean a transition that on input and top of stack transitions. We then add a self-loop at this state which empties the stack. This is a , a where a -{$}. Then we add a , $ transition to the new accept state. Finally we turn all the old accept states into non-accept states. It is easy to convince yourself that we have turned our NPDA into an equivalent machine which accepts the same language as P . Another assumption we are going to make about P is that it only makes pure push and pop moves. That is we do not allow transition in which a symbol is replaced by another symbol (not the empty string.) We only allow transitions which replace a symbol on the stack from the stack alphabet by or which push onto the top of the stack a new element of the stack alphabet. We can assume this is true, because it is always possible to turn a NPDA which includes push/pop simultaneous moves into one which doesn't include these. We can do this by a sequence of two transitions which go through a new state. The first transition does a pop and the second does a push. Also note that transitions which are s, which just read an input and don't touch the stack can similarly be replaced by transitions and a new state, where we push an arbitrary symbol and pop an arbitrary symbol. Okay so now we're ready to go. We have a NPDA P which, without loss of generality, has a single state, accept empties the stack before accepting, and each transition is either a pure push operation or a pure pop operation. Our NPDA is going to have a variable for every pair of states in P : Apq . This variable will generate all strings that can take our NPDA from p with an empty stack to q with an empty stack. To understand how this variable will work, think about what P must be doing as it goes from p to q. Since every transition mush be a push or a pop, and the stack is empty, the transition from p to q must consist of at least an initial push and a final pop. In other words, in going from p to q, the NPDA must transition through at least one other state, and it must must first perform a transition to a state where it pushes a symbol onto the stack, and must end coming through a transition which pops a symbol off the stack. Now there are two cases to consider. One is when the first symbol pushed onto the stack is the same as the symbol popped at the end of the transition. In this case the stack is empty only at the beginning and end of the computation. In this case we simulate this by the rules Apq aArs b where a is the symbol read on the first transition, b is the symbol read on the second transition, r is the state that p transitions to, and s is the state from which the final transition originates. The other case is that the first symbol pushed onto the stack is not the same symbol popped at the end of the transition. In this case the machine must have been empty at some point during the transition from p to q. Suppose that the stack became empty at state r, then we simulate this possibility by the rule Apq Apr Arq . Okay now lets formally define our CFG. Let P = (Q, , , , q0 , {qa }) be our NPDA with the three properties we listed above. Let G be our CFG with G = (V, , R, S). Our variables are V = {Apq |p, q Q}. Our alphabets are the same and the start variable is Aq0 qa . The rules of G are given by 1. For each p, q, r, s Q, t , and a, b , if (p, a, ) contains (r, t) and (s, b, t) contains (q, ), put the rule Apq aArs b in G. 2. For each p, q, r Q, put the rule Apq Apr Arq in G. 3. For each p Q, put the rule App . We will now prove that our construction works. In other words we will prove that Apq generates x if and only if x can bring our NPDA from p with an empty stack to q with an empty stack. First lets show that if Apq generates x then x can bring P from p to q with the empty stack. Our proof will be by induction on the number of steps in the derivation of x from Apq . Thus the base case is where the derivation has one step. If the derivation has one step, then it must have only terminals on its right-hand side. The only such rule of this form for our construction is the App rule. Clearly takes p with and empty stack to p with an empty stack. Now assume (inductive hypothesis) that if Apq generates x using a derivation of length k, then x can bring P from p to q with the empty stack. We will now show that this is true for derivations of length k. Suppose that Apq x with k + 1 steps. The first step in this derivation is either Apq aArs b or Apq Apr Arq . Suppose that the first step is the former. Then x will be of the form ayb where y is generated by Ars . The derivation of y must take k steps. Thus by the inductive hypothesis, P can take r with an empty stack to s with an empty stack. Because Apq aAr,s b is a rule of G, (p, a, ) contains (r, t) and (s, b, t) contains (q, ), for some stack symbol t . Hence if P starts at p with an empty stack, after reading a it can go to state r and push t onto the stack. Then reading string y can bring it to s and leave t on the stack (using the inductive hypothesis). Then after reading b it can go to state q and pop t off the stack. Therefore x can bring P from p with the empty stack to q with the empty stack. Now consider other other case where the derivation is of the form Apq Apq Arq . Then x must be of the form yz where Apq y and Arq z. Now each of these later two derivations must be of at most k steps. Thus the PDA can take p with the empty stack to r with the empty stack and can take r with the empty stack to q with the empty stack (inductive 4 hypothesis.) Therefore it is easy to see that x can bring the NPDA from p with the empty stack to q with the empty stack. Thus we have shown that if Apq generates x then x can bring P from p with the empty stack to q with the empty stack. Next we need to show that if x can bringP from p with the empty stack to q with the empty stack, then Apq generates x. We will prove this by induction on the number of steps in the computation of P . The base case will be when the computation has 0 steps. If the computation has no steps, it starts and ends in the same state and only has time to read the empty string. But App is one of our rules, so App can generate the empty string. Now assume that for computation of length at most k a string x on P can bring p with the empty stack to q with the empty stack (this is the inductive hypothesis.) Suppose that P has a computation wherein x brings p to q with empty steps in k + 1 computational steps. Suppose first that the stack is empty only at the beginning or end of this computation. Then the symbol that is pushed on the first move is the same as the symbol popped at the last move. Let this symbol be t . Let a be the input read in the first move, b be the in...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Washington - CS - 322
CSE 322 - Introduction to Formal Methods in Computer Science Closure Properties of Context-Free LanguagesDave BaconDepartment of Computer Science & Engineering, University of WashingtonPreviously we showed how regular operations were closed under
Washington - CS - 322
CSE 322 - Introduction to Formal Methods in Computer Science Turing MachinesDave BaconDepartment of Computer Science & Engineering, University of WashingtonToday we finally make it up to.computers! Well at least to the model which best captures w
Washington - CS - 322
CSE 322 - Introduction to Formal Methods in Computer Science DecidabilityDave BaconDepartment of Computer Science & Engineering, University of WashingtonIn the last lecture we introduced the Turing machine. We talked about how it worked, and show
Washington - CS - 322
CSE 322: Formal Models in Computer ScienceMidterm TopicsThe midterm will be Friday, May 9th in class. It will be 50 minutes in length and will be closed book. The midterm will cover everything covered in class up to and including the first half o
Washington - CS - 322
CSE 322: Formal Models in Computer ScienceFinal TopicsThe nal will be Monday, June 9 from 2:30-4:20 in EEB 045. It will be 110 minutes in length and will be closed book. It will cover everything in the class with slightly more coming from the mat
Washington - CS - 322
CSE322: Formal Models in Computer Science Partial Solutions to Sample FinalSpring 2006This handout has (partial) solutions to some of the problems in the sample final exam that was handed out in class on Friday, May 26. I have not given solutions
Washington - CS - 322
1 CSE 322: Formal Models in Computer Science April 2, 2008 HandoutN,S,W,ENNN,EQQQ Fremont Troll o QQQ y QQQ QQQ QQQ N,S,W N QQQ Q@ E G Queen Anne Ave o Villa Sophia o W iRRR y RRR RRR N S RRR W R Space Needle o yNWGas Works Park o
Washington - CS - 322
CSE 322 Introduction to Formal Models in Computer ScienceDefining from In the definition of DFAs, the transition function explicitly describes, for each character a , the name of the state reached on a when started at state q. This is precisely
Washington - CS - 322
Washington - CS - 322
CSE 322: Formal Models in Computer Science Website: http:/www.cs.washington.edu/322 Lecture Times: MWF 1:30-2:30 in EE 045 (in the dungeon of EE.) Instructor: Dave Bacon Office: CSE 460 Email: dabacon@cs.washington.edu Phone: 206-221-6503 Office hour
Washington - CS - 521
CSE 521: Design and Analysis of Algorithms Winter 2005 Course InformationInstructor: TAs:Anna R. Karlin Neva Cherniavsky Ning ChenPGA 594 PGA 378 PGA 310karlin@cs.washington.edu nchernia@cs.washington.edu ning@cs.washington.edu543-9344 685-
Washington - CS - 521
CSE 521: Design and Analysis of Algorithms Assignment #0 January 3, 2005 Due: Wednesday, January 5Reading Assignment: Kleinberg and Tardos, Chapters 1 and 4 Questions: 1. For each of the following topics, indicate your level of comfort on a scale o
Washington - CS - 521
CSE 521: Design and Analysis of Algorithms Assignment #1 January 5, 2005 Due: Wednesday, January 12Reading Assignment: Kleinberg and Tardos, Chapters 1 and 4 Problems:1. Gale and Shapley published their paper on the stable marriage problem in 196
Washington - CS - 521
CSE 521: Design and Analysis of Algorithms Assignment #2 January 12, 2005 Due: Wednesday, January 19 Reading Assignment: K&T, Section 5.1, 5.2, 5.4, 5.6, 5.7, 5.9 Questions: 1. (Kleinberg and Tardos, Chapter 4, Problem 5) Let's consider a long, quiet
Washington - CS - 521
CSE 521: Design and Analysis of Algorithms Assignment #4 January 27, 2005 Due: Wednesday, February 2Reading Assignment: Kleinberg and Tardos, Network Flow, handout on linear programming, section 11.6 in new book. Problems:1. Let G = (V, E) be a g
Washington - CS - 521
CSE 521: Design and Analysis of Algorithms Assignment #5 February 2, 2005 Due: Wednesday, February 9Reading Assignment: Kleinberg and Tardos, Network Flow, handout on linear programming Problems: 1. Your friends have written a very fast piece of ma
Washington - CS - 521
CSE 521: Design and Analysis of Algorithms Assignment #6 Due: Wednesday, February 16Reading Assignment: Linear programming handouts, chapter on randomized algorithms, other randomized algorithms handouts (we'll send out mail about them.) Problems:
Washington - CS - 521
CSE 521: Design and Analysis of Algorithms Assignment #7 Due: Wednesday, Feb 23Problems:1. QuickSelect is the following simple algorithm for finding the k-th smallest element in an unsorted set S. QuickSelect(S, k): (a) Pick a pivot element p uni
Washington - CS - 521
Name:1 2 3 4 total/ 9 /10 /16 /39 /74CSE 521 Final ExamMarch 15, 2004 Instructions: You have 1 hour and 50 minutes to complete the exam. The exam is closed book, closed notes. Please do not turn the page until you are instructed to do so.
Washington - CS - 421
Measuring efficiency: The RAM modelnRAM = Random Access Machine Time # of instructions executed in an ideal assembly languagennComplexity and Representative ProblemsWinter 2005 Paul Beameneach simple operation (+,*,-,=,if,call) takes on
Washington - CS - 421
Undirected Graph G = (V,E)1 2 3 11 10Graph TraversalWinter 2005 Paul Beame12 4 5 6 7 8 13 9Directed Graph G = (V,E)1 2 3 11 12 4 5 6 7 8 13 9n n nGraph TraversalLearn the basic structure of a graph Walk from a fixed starting vertex s to
Washington - CS - 421
Greedy AlgorithmsnHard to define exactly but can give general propertiesn nGreedy AlgorithmsWinter 2005 Paul BeamenSolution is built in small steps Decisions on how to build the solution are made to maximize some criterion without looking t
Washington - CS - 421
Dynamic ProgrammingnDynamic ProgrammingnGive a solution of a problem using smaller sub-problems where all the possible sub-problems are determined in advance Useful when the same sub-problems show up again and again in the solutionDynamic Pro
Washington - CS - 421
Bipartite MatchingnnGiven: A bipartite graph G=(V,E)ME is a matching in G iff no two edges in M share a vertexnNetwork FlowWinter 2005 Paul BeameGoal: Find a matching M in G of maximum possible sizeBipartite MatchingBipartite Matchin
Washington - CS - 421
Dealing with NP-completenessWinter 2005 Paul BeameWhat to do if the problem you want to solve is NP-hardnYou might have phrased your problem too generallyne.g., in practice, the graphs that actually arise are far from arbitrary n maybe they
Washington - CSE - 590
Washington - CSEP - 590
Homeland Security / Cyber Security Autumn 2005N.B. CONTINUALLY IN FLUX Version 24: November 22 Course Requirements: Red Team Exercise (~25%): You are a member of a 5-6 person team of engineers and policy professionals that has been hired by the Depa
Washington - CSEP - 590
Homeland Security / Cyber Security Autumn 2005N.B. CONTINUALLY IN FLUX Version 24: November 22 Course Requirements: Red Team Exercise (~25%): You are a member of a 5-6 person team of engineers and policy professionals that has been hired by the Depa
Washington - CSEP - 590
CSE P 590TU: Homeland Security / Cyber Security Course Grade Histogram for UW Students4.0 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0X X X X X X X X X XX X X X X X X X X XX X X X X X X X X X X X X X X X X X X X X X X X X
Washington - CSEP - 590
Red Team ReportHemavathy Alaganandam Parvez Anandam Jameel Alsalam Yi-Kai Liu Pravin Mittal Elena Rodriguez-Vieitez Santeri VoutilainenUniversity of Washington CSE P 590TU UC Berkeley PP 190/290-009 UCSD CSE 291 (C00) Christine Hartmann-Siantar P
Washington - CSEP - 590
Buffer Overflows: Implications for Civilian CybersecurityAndrew Hoskinsahoskins@microsoft.comMark O. Ihimoyanmark.ihimoyan@microsoft.comAdeel Rasul Iqbalaiqbal@uclink.berkeley.eduKeunwoo Leeklee@cs.washington.eduThanh Nhut Nguyenttnguye