Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Similar documents
Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen

Context-Free and Noncontext-Free Languages

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Theory of Computation (IV) Yijia Chen Fudan University

Introduction to Theory of Computing

CISC4090: Theory of Computation

Automata Theory. CS F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages. David Galles

Computational Models - Lecture 4

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Context-Free Languages

Pushdown Automata (Pre Lecture)

Einführung in die Computerlinguistik

Context-Free Languages (Pre Lecture)

Lecture 17: Language Recognition

SCHEME FOR INTERNAL ASSESSMENT TEST 3

DM17. Beregnelighed. Jacob Aae Mikkelsen

MA/CSSE 474 Theory of Computation

5 Context-Free Languages

Cliff s notes for equivalence of CFLs and L(PDAs) LisaCFL L = L(M) for some PDA M L=L(M)forsomePDAM L = L(G) for some CFG G

PUSHDOWN AUTOMATA (PDA)

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA)

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Computational Models - Lecture 5 1

Computability and Complexity

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)

Properties of Context-Free Languages

Pushdown Automata. Reading: Chapter 6

Introduction to Formal Languages, Automata and Computability p.1/42

CpSc 421 Final Exam December 15, 2006

Lecture III CONTEXT FREE LANGUAGES

Pushdown Automata: Introduction (2)

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 tree u,

Theory of Computation

Final exam study sheet for CS3719 Turing machines and decidability.

CA320 - Computability & Complexity

Automata Theory (2A) Young Won Lim 5/31/18

Pushdown Automata (2015/11/23)

CPS 220 Theory of Computation Pushdown Automata (PDA)

Foundations of Informatics: a Bridging Course

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

CISC 4090 Theory of Computation

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

CSE 355 Test 2, Fall 2016

(pp ) PDAs and CFGs (Sec. 2.2)

Computational Models: Class 5

2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a

CPS 220 Theory of Computation

3.13. PUSHDOWN AUTOMATA Pushdown Automata

Theory of Computation Turing Machine and Pushdown Automata

Finite Automata and Regular languages

Pumping Lemma for CFLs

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Pushdown Automata. Chapter 12

3130CIT Theory of Computation

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?

Automata Theory - Quiz II (Solutions)

Formal Languages, Automata and Compilers

(pp ) PDAs and CFGs (Sec. 2.2)

Computational Models - Lecture 5 1

CFG and PDA accept the same languages

Chapter 6. Properties of Regular Languages

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

CSE 105 THEORY OF COMPUTATION

This lecture covers Chapter 6 of HMU: Pushdown Automata

Context-Free Languages

CSE 105 THEORY OF COMPUTATION

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

NPDA, CFG equivalence

Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

Closure under the Regular Operations

CS Pushdown Automata

This lecture covers Chapter 7 of HMU: Properties of CFLs

CS 341 Homework 16 Languages that Are and Are Not Context-Free

THEORY OF COMPUTATION

CS20a: summary (Oct 24, 2002)

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

Chapter 3. Regular grammars

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Solution Scoring: SD Reg exp.: a(a

Push-down Automata = FA + Stack

Computational Models - Lecture 4 1

CISC 4090 Theory of Computation

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

The Pumping Lemma for Context Free Grammars

Context Free Languages: Decidability of a CFL

Automata and Computability. Solutions to Exercises

UNIT-VI PUSHDOWN AUTOMATA

Uses of finite automata

3.10. TREE DOMAINS AND GORN TREES Tree Domains and Gorn Trees

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

Automata and Computability. Solutions to Exercises

Part I: Definitions and Properties

Properties of Context-Free Languages. Closure Properties Decision Properties

Theory of Computation (II) Yijia Chen Fudan University

Theory of Computation - Module 3

Fundamentele Informatica II

Transcription:

Pushdown Automata We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata. Next we consider a more powerful computation model, called a pushdown automaton, by adding the storage device of a stack. The stack allows read and write access, but only to the top, or last, symbol. It is of finite but unbounded size. Input tape a a b a b a a a Reading head b Finite control q5 q0 q1 a a q4 q3 q2 b b Stack a

Pushdown Automata (cont.) Each computation step by a pushdown automaton depends on (i) the current state, (ii) the next input symbol, and (iii) the top symbol(s) on the stack. Let Σ ɛ denote the set Σ {ɛ}. Definition A pushdown automaton is a tuple where M = (Q,Σ,Γ,q 0,T, ), Q is finite set of states, Σ is an alphabet (the input symbols), Γ is an alphabet (the stack symbols), q 0 Q is the start state, T Q is the set of final or accept states, and is a finite subset of (Q Σ ɛ Γ ) (Q Γ ), called the transition relation. Pushdown automata are nondeterministic. The transition relation can also be defined as a subset of (Q Σ ɛ Γ ɛ ) (Q Γ ɛ ). This slightly more restrictive definition does not limit the expressive power of the computation model.

Transitions A transition ((p,a,β),(q,γ)) indicates that the pushdown automaton may change from state p to state q, provided the next input symbol is a and β is on top of the stack. In addition, β is replaced by γ at the top of the stack. A transition ((p,u,ɛ),(q,a)) pushes a single symbol a onto the stack. A transition ((p,u,a),(q,ɛ)) pops a symbol a off the stack. More general transitions can always be represented by a sequence of pop and push operations. A configuration for a pushdown automaton is a triple of type Q Σ Γ, where the first component represent the current state, the second component the unread portion of the input tape, and the third component the contents of the stack (read topdown). A configuration (p, x, α) yields another configuration (q,y,β), written (p,x,α) (q,y,β), if there is a transition ((p,a,γ),(q,η)) such that x = ay, γ is a prefix of α, and β is obtained from α by replacing the prefix β by η.

Computations A computation by a pushdown automaton is a sequence of configurations C = C 0 C 1 C n = C. We also say that the configuration C yields C, and write C C. A string w Σ is said to be accepted by a pushdown automaton M if, and only if, there is a computation from a start configuration (s,w,ɛ) to a configuration (p,ɛ,ɛ), where p is an accept state of M. The language accepted by M is the set L(M) of all strings accepted by M.

Example Let M be a pushdown automaton (Q,Σ,Γ,q 0,T, ), where Q = {s,f}, Σ = {a,b,c}, Γ = {a,b}, T = {f}, and contains the following transitions: ((s,a,ɛ),(s,a)), ((s,b,ɛ),(s,b)), ((s,c,ɛ),(f,ɛ)), ((f,a,a),(f,ɛ)), and ((f,b,b),(f,ɛ)). This pushdown automaton accepts the language L = {wcw R : w {a,b} }.

Another Example The following pushdown automaton accepts the language {w {a,b} : w has the same number of a s and b s}. We have M = ((Q,Σ,Γ,q 0,T, ), where K = {s,q,f}, Σ = {a,b}, Γ = {a,b,c}, T = {f}, and contains the following transitions: ((s,ɛ,ɛ),(q,c)), ((q,a,c),(q,ac)), ((q,a,a),(q,aa)), ((q,a,b),(q,ɛ)), ((q,b,c),(q,bc)), ((q,b,b),(q,bb)), ((q,b,a),(q,ɛ)), and ((q,ɛ,c),(f,ɛ)).

Context-Free Languages Theorem A language is accepted by a pushdown automaton if, and only if, it is context-free. Proof sketch. We first show that each context-free language is accepted by some pushdown automaton. Let G = (V,Σ,R,S) be a context-free grammar. We define a corresponding pushdown automaton M = ({p,q},σ,v Σ,p,{q}, ), where contains the following transitions: ((p,ɛ,ɛ),(q,s)), ((q,ɛ,a),(q,x)), for each rule A x in R, and ((q,a,a),(q,ɛ)), for each symbol a Σ. This automaton mimics a leftmost derivation of a string in L(G), and L(M) = L(G).

Next we show that each language accepted by a pushdown automaton is context-free. Let M = (Q,Σ,Γ,q 0,T, ) be a pushdown automaton. We assume that T contains only one accept state, say f, and that each transition either pushes a single symbol onto the stack or pops one off the stack. We construct a context-free grammar G for M. The variables of G are written as A pq, where p and q are states of M. The rules of G are designed so that from A pq one can derive exactly those strings that drive the automaton M from state p with empty stack to state q with empty stack: A pq aa rs b, where contains transitions ((p,a,ɛ),(r,c)) and ((s,b,c),(q,ɛ)), for some c Γ; A pq A pr A rq, where p,q,r K; and A pp ɛ, where p K. The start variable of G is S = A sf, and it can be shown that L(G) = L(M).

Closure Properties Theorem The intersection of a context-free language and a regular language is context-free. Proof sketch. Let L be a context-free language accepted by a PDA M 1 = (Q 1,Σ,Γ 1,s 1,F 1, 1,) and R be a regular language accepted by a DFA M 2 = (Q 2,Σ,s 2,F 2,δ). We design a PDA M = (Q,Σ,Γ,s,F, ) that simulates M 1 and M 2 in parallel: Q = Q 1 Q 2, Γ = Γ 1, s = (s 1,s 2 ), F = F 1 F 2, and = {(((q 1,q 2 ),a,β),((p 1,δ(q 2,a)),γ)) : ((q 1,a,β),(p 1,γ)) 1,q 2 K 2 } {(((q 1,q 2 ),ɛ,β),((p 1,q 2 ),γ)) : ((q 1,ɛ,β),(p 1,γ)) 1,q 2 K 2 }. It can be shown that L(M) = L(M 1 ) L(M 2 ).

Pumping Lemma Infinite context-free languages display more subtle periodicity patterns than regular languages. Theorem If L is a context-free language then there is an integer n L 1 (the pumping length) such that any string w L with w n L can be written as w = uvxyz, where (i) vy > 0, (ii) vxy n L, and (iii) for each i 0, uv i xy i z L. Proof sketch. Let L be a context-free language and G be a context-free grammar (V,Σ,S,R) such that L(G) = L. Let l be the maximum number of symbols on the right-hand side of a rule in R. We may assume that l 2. No node in a parse tree for G can have more than l children. Thus, if a parse tree has height h, its yield is a string of length no more than l h. We choose n L to be the number l V Σ +1. Let w be a string in L with w n L. We have to show that w can be divided into five parts,

w = uvxyz, such that conditions (i), (ii), and (iii) are satisfied. Let T be a parse tree for w with the smallest number of nodes. Since T must be of height at least V Σ +1, we may infer that any longest (root-to-leaf) path in T contains at least V Σ +1 nodes labeled by nonterminals. Some nonterminal must occur more than once on this path. Let A be a nonterminal that occurs repeatedly among the last V Σ +1 nodes on a selected longest path. We have the following situation: S T A T T A u v x y z That is, from S we can derive the string uaz, whereas from A we can derive both x and vay.

Consequently, from S we can obtain all strings of the form uv i xy i z in Σ. The two strings v and y can not both be empty, as T was assumed to be a smallest parse tree with yield w. Moreover, we picked repeated occurrences of A within the bottom V Σ +1 nodes, and hence vxy n L.

Non-Context-Free Languages The Pumping Lemma can be used to show that certain languages, including the set {a n b n c n : n 0} and the set {ww : w {a,b} }, are not context-free. This also implies that context-free languages do not satisfy certain closure properties. Theorem Proof. The class of context-free languages is not closed under intersection or complement. The languages {a n b n c m : m,n 0} and {a m b n c n : m, n 0} are context-free, but their intersection, the set {a n b n c n : n 0}, is not. Thus, context-free languages are not closed under intersection. Since intersection of sets can be expressed in terms of complement and union, we may infer that context-free languages are not closed under complement either.