NPDAs Accept Context-Free Languages

Slides:



Advertisements
Similar presentations
PDAs Accept Context-Free Languages
Advertisements

Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Costas Busch - RPI1 Undecidable problems for Recursively enumerable languages continued…
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
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.
Fall 2006Costas Busch - RPI1 The Post Correspondence Problem.
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.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
Courtesy Costas Busch - RPI1 Context-Free Languages.
Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
Courtesy Costas Busch - RPI1 Reducibility. Courtesy Costas Busch - RPI2 Problem is reduced to problem If we can solve problem then we can solve problem.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
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 A Non Context-Free Language (We will prove it at the next class)
Fall 2003Costas Busch - RPI1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
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. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Formal Languages, Automata and Models of Computation
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.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Recursively Enumerable and Recursive Languages
G. Pullaiah College of Engineering and Technology
PDAs Accept Context-Free Languages
Busch Complexity Lectures: Turing Machines
Linear Bounded Automata LBAs
Reductions Costas Busch - LSU.
NPDAs Accept Context-Free Languages
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
DPDA Deterministic PDA
Non-Deterministic Finite Automata
Decidable Languages Costas Busch - LSU.
Deterministic PDAs - DPDAs
The Post Correspondence Problem
Elementary Questions about Regular Languages
Non-regular languages
Properties of Context-Free languages
Chapter 2 Context-Free Language - 01
DPDA Deterministic PDA
… NPDAs continued.
Normal Forms for Context-free Grammars
Presentation transcript:

NPDAs Accept Context-Free Languages Costas Busch - RPI

Theorem: Context-Free Languages Languages Accepted by (Grammars) NPDAs Costas Busch - RPI

Convert any context-free grammar to a NPDA with: Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by NPDAs Convert any context-free grammar to a NPDA with: Costas Busch - RPI

Convert any NPDA to a context-free grammar with: Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by NPDAs Convert any NPDA to a context-free grammar with: Costas Busch - RPI

Converting Context-Free Grammars to NPDAs Proof - step 1 Converting Context-Free Grammars to NPDAs Costas Busch - RPI

We will convert any context-free grammar to an NPDA automaton Such that: Simulates leftmost derivations of Costas Busch - RPI

Simulation of derivation Leftmost derivation Input processed Stack contents leftmost variable Stack Simulation of derivation Input Costas Busch - RPI

Simulation of derivation Leftmost derivation string of terminals Stack Simulation of derivation Input end of input is reached Costas Busch - RPI

What is the equivalent NPDA? An example grammar: What is the equivalent NPDA? Costas Busch - RPI

Grammar: NPDA: Costas Busch - RPI

A leftmost derivation: Grammar: A leftmost derivation: Costas Busch - RPI

Derivation: Input Time 0 Stack Costas Busch - RPI

Derivation: Input Time 0 Stack Costas Busch - RPI

Derivation: Input Time 1 Stack Costas Busch - RPI

Derivation: Input Time 2 Stack Costas Busch - RPI

Derivation: Input Time 3 Stack Costas Busch - RPI

Derivation: Input Time 4 Stack Costas Busch - RPI

Derivation: Input Time 5 Stack Costas Busch - RPI

Derivation: Input Time 6 Stack Costas Busch - RPI

Derivation: Input Time 7 Stack Costas Busch - RPI

Derivation: Input Time 8 Stack Costas Busch - RPI

Derivation: Input Time 9 Stack accept Costas Busch - RPI

In general: Given any grammar We can construct a NPDA With Costas Busch - RPI

Constructing NPDA from grammar : For any production For any terminal Costas Busch - RPI

Grammar generates string if and only if NPDA accepts Costas Busch - RPI

For any context-free language there is a NPDA Therefore: For any context-free language there is a NPDA that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs Costas Busch - RPI

Converting NPDAs to Context-Free Grammars Proof - step 2 Converting NPDAs to Context-Free Grammars Costas Busch - RPI

a context-free grammar with For any NPDA we will construct a context-free grammar with Costas Busch - RPI

The grammar simulates the machine Intuition: The grammar simulates the machine A derivation in Grammar : terminals variables Input processed Stack contents Current configuration in NPDA Costas Busch - RPI

Some Necessary Modifications Modify (if necessary) the NPDA so that: 1) The stack is never empty 2) It has a single final state and empties the stack when it accepts a string 3) Has transitions in a special form Costas Busch - RPI

the stack is never empty Modify the NPDA so that the stack is never empty Stack OK OK NOT OK Costas Busch - RPI

Introduce the new symbol to denote the bottom of the stack Costas Busch - RPI

At the beginning push into the stack Original NPDA new initial state original initial state Costas Busch - RPI

replace every instance of with In transitions: replace every instance of with Example: Costas Busch - RPI

Convert all transitions so that: if the automaton attempts to pop or replace it will halt Costas Busch - RPI

l , ® $ Convert transitions as follows: halting state Costas Busch - RPI

2) Modify the NPDA so that it empties the stack and has a unique final state Empty the stack NPDA l ® , l ® , l ® , Old final states Costas Busch - RPI

3) modify the NPDA so that transitions have the following forms: Costas Busch - RPI

Convert: Costas Busch - RPI

Convert: symbols Costas Busch - RPI

Convert: symbols Convert recursively Costas Busch - RPI

Example of a NPDA in correct form: Costas Busch - RPI

The Grammar Construction In grammar : Stack symbol Variables: states Terminals: Input symbols of NPDA Costas Busch - RPI

For each transition We add production Costas Busch - RPI

For all possible states in the automaton For each transition We add productions For all possible states in the automaton Costas Busch - RPI

Stack bottom symbol Start Variable: Start state final state Costas Busch - RPI

Example: Grammar production: Costas Busch - RPI

Example: Grammar productions: Costas Busch - RPI

Example: Grammar production: Costas Busch - RPI

Resulting Grammar: Costas Busch - RPI

Costas Busch - RPI

Derivation of string Costas Busch - RPI

the stack doesn’t change below and then is removed from stack In general: if and only if the NPDA goes from to by reading string and the stack doesn’t change below and then is removed from stack Costas Busch - RPI

Therefore: if and only if is accepted by the NPDA Costas Busch - RPI

there is a context-free grammar that accepts the same language Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs Costas Busch - RPI

Deterministic PDA DPDA Costas Busch - RPI

Deterministic PDA: DPDA Allowed transitions: (deterministic choices) Costas Busch - RPI

(deterministic choices) Allowed transitions: (deterministic choices) Costas Busch - RPI

(non deterministic choices) Not allowed: (non deterministic choices) Costas Busch - RPI

DPDA example Costas Busch - RPI

is deterministic context-free The language is deterministic context-free Costas Busch - RPI

A language is deterministic context-free Definition: A language is deterministic context-free if there exists some DPDA that accepts it Costas Busch - RPI

Example of Non-DPDA (NPDA) Costas Busch - RPI

Not allowed in DPDAs Costas Busch - RPI

NPDAs Have More Power than DPDAs Costas Busch - RPI

Since every DPDA is also a NPDA It holds that: Deterministic Context-Free Languages (DPDA) Context-Free Languages NPDAs Since every DPDA is also a NPDA Costas Busch - RPI

We will show that there exists a context-free language which is not We will actually show: Deterministic Context-Free Languages (DPDA) Context-Free Languages (NPDA) We will show that there exists a context-free language which is not accepted by any DPDA Costas Busch - RPI

is not deterministic context-free The language is: We will show: is context-free is not deterministic context-free Costas Busch - RPI

Language is context-free Context-free grammar for : Costas Busch - RPI

Theorem: The language is not deterministic context-free (there is no DPDA that accepts ) Costas Busch - RPI

Proof: Assume for contradiction that is deterministic context free Therefore: there is a DPDA that accepts Costas Busch - RPI

DPDA with accepts accepts Costas Busch - RPI

Such a path exists because of the determinism DPDA with Such a path exists because of the determinism Costas Busch - RPI

Context-free languages Fact 1: The language is not context-free Regular languages Context-free languages (we will prove this at a later class using pumping lemma for context-free languages) Costas Busch - RPI

Fact 2: The language is not context-free (we can prove this using pumping lemma for context-free languages) Costas Busch - RPI

We will construct a NPDA that accepts: which is a contradiction! Costas Busch - RPI

Replace with Modify Costas Busch - RPI

Connect final states of with final states of The NPDA that accepts Connect final states of with final states of Costas Busch - RPI

Since is accepted by a NPDA it is context-free Contradiction! (since is not context-free) Costas Busch - RPI

Not deterministic context free Therefore: Not deterministic context free There is no DPDA that accepts End of Proof Costas Busch - RPI