CS 461 – Sept. 26 CFG correctness Section 2.2 – Pushdown Automata.

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
PDAs => CFGs Sipser 2.2 (pages ). Last time…
PDAs => CFGs Sipser 2.2 (pages ). Last time…
Introduction to Computability Theory
CFG => PDA Sipser 2 (pages ).
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.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
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.
1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
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.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
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.
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.
Chapter 7 PDA and CFLs.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s Pushdown Automata 11.
Lecture Pushdown Automata. stack stack head finite control tape head tape.
CS 461 – Sept. 19 Last word on finite automata… –Scanning tokens in a compiler –How do we implement a “state” ? Chapter 2 introduces the 2 nd model of.
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.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
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.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Formal Languages, Automata and Models of Computation
1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.
Lecture 14 Push Down Automata (PDA) Topics:  Definition  Moves of the PDA  Languages of the PDA  Deterministic PDA’s June 18, 2015 CSCE 355 Foundations.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
CS 461 – Sept. 23 Context-free grammars Derivations Ambiguity Proving correctness.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Pushdown Automata.
CSE 105 theory of computation
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
CS 461 – Sept. 28 Section 2.2 – Pushdown Automata { 0n 1n }
فصل دوم Context-Free Languages
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
Pushdown automata The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

CS 461 – Sept. 26 CFG correctness Section 2.2 – Pushdown Automata

Correctness Given a language L and a grammar G, how do we know if L = L(G)? Must show: 1.L  L(G). All words in L can be derived by grammar. Tell how to derive the words. 2.L(G)  L. All words derived by grammar are in L. Use induction.

First example Show that S  ε | 0S1 is a CFG for the language { 0 n 1 n } Step #1: Any word in 0 n 1 n can be generated by the grammar. We explain the derivation. –Apply the rule 0S1 n times –Finally, apply the ε rule. Step #2: All words generated by the grammar are of the form 0 n 1 n. –Induction on the number of times we use a rule. –S  ε for the basis, and S  0S1 for the inductive step.

Second example L is { even number of 0s } and G is S  ε | S1 | S0S0 Step #1. Suppose w  L. How can G generate w? If w = ε, we’re done. Do the following until w is ε: If w ends with 1s, take them off by virtue of “S1”. Now w ends with 0, so take 2 0’s away by virtue of “S0S0”. We know there must be 2 0’s in w because w had an even number to start with.

Illustration S  ε | S1 | S0S0 Let’s see how we can derive “010100”: The last 2 0s: S  S0S0  ε0ε0 = is is S  S0S0  ε0S10  ε0ε10 = is S  S1  ε1 = 1 We can reconstruct derivation from beginning in form of a tree.

L(G) is in L S  ε | S1 | S0S0 Step #2: Need to show all generated words are in L. Base case: ε is in L. It has even number of 0s. Recursive case. Let w be a word generated by the grammar. Assume it has even # 0s. We can create a larger word by applying rule “S1” or “S0S0”. S1 adds no more 0s. S0S0 adds two 0s. Either way the # of 0s stays even.

Extra example Let’s show that this grammar G S  ε | 0S1 | 00S111 generates the language L = { 0 i 1 j | i  j  1.5i } Step #1: any word in L can be generated –This is the hard part, so let’s motivate the proof with an example or two. Step #2: all words generated are in L –Just induction again.

L is in L(G) S  ε | 0S1 | 00S111 How could we generate ? –We have 5 extra 1s. So we use rule 00S111 five times. –Undoing these steps, # 0s = 11-5*2 = 1 and # 1s = 16-5*3 = 1. Then we use 0S1 once and we are left with ε. Okay, how about ? –We have 4 extra 1s, so use rule 00S111 four times. –Undoing these steps, # 0s = 12-4*2 = 4 and # 1s = 16-4*3 = 4. They match! So use “0S1” 4 times.

Thinking out loud… S  ε | 0S1 | 00S111 Let w = 0 i 1 j  L. In other words, i  j  1.5i Consider the number j – i. This is the number of times to apply rule #3 (00S111). Note that using rule #3 (j – i) times will account for 2(j – i) zeros. Then apply rule #2 (0S1) the “appropriate number” of times. How many? Well, we want i 0’s and we’ve already got 2(j – i), so we need the difference: i – 2(j – i) = 3i – 2j.

Finishing step 1 S  ε | 0S1 | 00S111 Let w = 0 i 1 j  L. In other words, i  j  1.5i Use rule #1 once to start with empty word. Use rule #3 (j – i) times. Use rule #2 (3i – 2j) times. Total # 0s = 3i – 2j + 2(j – i) = i Total # 1s = 3i – 2j + 3(j – i) = j Thus, the word can be generated.

L(G) is in L S  ε | 0S1 | 00S111 Now the easy part. Need to show that when we apply any rule, we preserve: i  j  1.5i Base case: ε has no 0s or 1s. 0  0  1.5*0 √ Recursive case. Let w be generated by the grammar with i 0s and j 1s satisfying i  j  1.5i. If we apply either rule 0S1 or 00S111, we can show (i + 1)  (j + 1)  1.5(i + 1) (i + 2)  (j + 3)  1.5(i + 2) (Need to work out arithmetic.)

Think about… Can you write a CFG for { 0 i 1 j | 0.5i  j  1.5i } ? in other words, the ratio of 1s to 0s must be between ½ and 3/2.

PDAs What is a Pushdown Automaton? Like an FA, but PDA has a stack –Finite number of states –Stack can grow to unlimited depth Transition function often non-deterministic 2 flavors –Accept by happy state –Accept by empty stack (this one has fewer states) Can be tedious to draw, so instead give a table. –What’s new is saying what to do with stack.

Formal definition A PDA has 6 things. –Same five from FA, plus: –Stack alphabet (can be different from Σ) Transition function δ(state, tos, input) = (push/pop, new state) both are optional

{ 0 n 1 n } While reading 0s, push them. If you read 1, change state. Then, as you read 1s, pop 0s off the stack. Watch out for bad input! –Unspecified transition  crash (reject) Now, let’s write this in the form of a table.

PDA δ for { 0 n 1 n } StateReading 0Reading 1 Tos(don’t care)0Empty Input ActionPush 0 Go to state “reading 1” CrashPopCrash Notes: Action depends on input symbol AND what’s on top of stack. Action includes manipulating stack AND/OR changing state.