PDAs Accept Context-Free Languages

Slides:



Advertisements
Similar presentations
Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
Advertisements

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.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
1 NFAs accept the Regular Languages. 2 Equivalence of Machines Definition: Machine is equivalent to machine if.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Prof. Busch - LSU1 NFAs accept the Regular Languages.
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.
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.
Formal Languages, Automata and Models of Computation
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
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.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Introduction to Approximation Algorithms
Deterministic Finite Automata And Regular Languages.
Context-Free Languages
G. Pullaiah College of Engineering and Technology
Models of Computation.
PDAs Accept Context-Free Languages
Non Deterministic Automata
More NP-complete Problems
Reductions.
NPDAs Accept Context-Free Languages
CSE 105 theory of computation
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
NPDAs Accept Context-Free Languages
Pushdown Automata Reading: Chapter 6.
DPDA Deterministic PDA
Non-Deterministic Finite Automata
Deterministic PDAs - DPDAs
Chapter 2 Context-Free Language - 01
DPDA Deterministic PDA
CS21 Decidability and Tractability
… NPDAs continued.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Pushdown automata The Chinese University of Hong Kong Fall 2011
NFAs accept the Regular Languages
Normal Forms for Context-free Grammars
Presentation transcript:

PDAs Accept Context-Free Languages

Theorem: Context-Free Languages (Grammars) Languages Accepted by PDAs

Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any context-free grammar to a PDA with:

Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any PDA to a context-free grammar with:

Convert Context-Free Grammars to PDAs Proof - step 1 Convert Context-Free Grammars to PDAs

Take an arbitrary context-free grammar We will convert to a PDA such that:

Conversion Procedure: For each For each production in terminal in Add transitions

Example Grammar PDA

PDA simulates leftmost derivations Grammar Leftmost Derivation PDA Computation Scanned symbols Stack contents

Production applied Grammar Leftmost Derivation Variables Leftmost or terminals Leftmost variable Terminals Production applied Variables or terminals Variable Terminals

Production applied Transition applied Grammar Leftmost Derivation PDA Computation Production applied Transition applied

and remove it from stack Grammar Leftmost Derivation PDA Computation Transition applied Read from input and remove it from stack

Last Transition applied Grammar Leftmost Derivation PDA Computation Last Transition applied All symbols have been removed from top of stack

And so on…… The process repeats with the next leftmost variable Production applied And so on……

Example: Input Time 0 Stack

Derivation: Input Time 1 Stack

Derivation: Input Time 2 Stack

Derivation: Input Time 3 Stack

Derivation: Input Time 4 Stack

Derivation: Input Time 5 Stack

Derivation: Input Time 6 Stack

Derivation: Input Time 7 Stack

Derivation: Input Time 8 Stack

Derivation: Input Time 9 Stack

Derivation: Input Time 10 Stack accept

Grammar Leftmost Derivation PDA Computation

In general, it can be shown that: Grammar generates string If and Only if PDA accepts Therefore

Convert PDAs to Context-Free Grammars Proof - step 2 Convert PDAs to Context-Free Grammars

Take an arbitrary PDA We will convert to a context-free grammar such that:

First modify PDA so that: 1. The PDA has a single accept state 2. Use new initial stack symbol # 3. On acceptance the stack contains only stack symbol # 4. Each transition either pushes a symbol or pops a symbol but not both together

1. The PDA has a single accept state Old accept states New accept state PDA l ® , l ® , l ® ,

2. Use new initial stack symbol # Top of stack old initial stack symbol auxiliary stack symbol new initial stack symbol PDA PDA still thinks that Z is the initial stack

3. On acceptance the stack contains only stack symbol # PDA Empty stack Old accept state New accept state PDA

4. Each transition either pushes a symbol or pops a symbol but not both together PDA PDA

PDA PDA Where is a symbol of the stack alphabet

PDA is the final modified PDA Note that the new initial stack symbol # is never used in any transition

Example:

Grammar Construction Variables: States of PDA

PDA Kind 1: for each state Grammar

PDA Kind 2: for every three states Grammar

PDA Kind 3: for every pair of such transitions Grammar

PDA Initial state Accept state Grammar Start variable

Example: PDA

Grammar Kind 1: from single states

Kind 2: from triplets of states Start variable

Kind 3: from pairs of transitions

Suppose that a PDA is converted to a context-free grammar We need to prove that or equivalently

We need to show that if has derivation: (string of terminals) Then there is an accepting computation in : with input string

We will actually show that if has derivation: Then there is a computation in :

Therefore: Since there is no transition with the # symbol

Lemma: If (string of terminals) then there is a computation from state to state on string which leaves the stack empty:

Proof Intuition: Type 2 Case 1: Type 3 Case 2:

Type 2 Case 1: Stack height Input string Generated by Generated by

Type 3 Case 2: Stack height Input string Generated by

Formal Proof: We formally prove this claim by induction on the number of steps in derivation: number of steps

Induction Basis: (one derivation step) A Kind 1 production must have been used: Therefore, and This computation of PDA trivially exists:

Induction Hypothesis: derivation steps suppose it holds:

Induction Step: derivation steps We have to show:

derivation steps Type 2 Case 1: Type 3 Case 2:

Type 2 Case 1: steps We can write At most steps At most steps

From induction hypothesis, in PDA: From induction hypothesis, in PDA: At most steps At most steps From induction hypothesis, in PDA: From induction hypothesis, in PDA:

since

Type 3 Case 2: steps We can write At most steps

From induction hypothesis, the PDA has computation: At most steps From induction hypothesis, the PDA has computation:

Type 3 Grammar contains production And PDA Contains transitions

We know We also know Therefore:

since END OF PROOF

So far we have shown: With a similar proof we can show Therefore:

This Summary is an Online Content from this Book: Michael Sipser, Introduction to the Theory of Computation, 2ndEdition It is edited for Computation Theory Course 6803415-3 by: T.Mariah Sami Khayat Teacher Assistant @ Adam University College For Contacting: mskhayat@uqu.edu.sa Kingdom of Saudi Arabia Ministry of Education Umm AlQura University Adam University College Computer Science Department المملكة العربية السعودية وزارة التعليم جامعة أم القرى الكلية الجامعية أضم قسم الحاسب الآلي