CS375: Logic and Theory of Computing

Similar documents
CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing

Foundations of Informatics: a Bridging Course

CSE 105 THEORY OF COMPUTATION

Section: Pushdown Automata

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,

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

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

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

input tape head moves current state a a

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

Pushdown Automata (2015/11/23)

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

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

Intro to Theory of Computation

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

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

NPDA, CFG equivalence

Please give details of your answer. A direct answer without explanation is not counted.

Properties of Context Free Languages

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

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

Fundamentele Informatica II

Accept or reject. Stack

MA/CSSE 474 Theory of Computation

UNIT-VI PUSHDOWN AUTOMATA

CS Pushdown Automata

Theory of Computation (IV) Yijia Chen Fudan University

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

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition

SCHEME FOR INTERNAL ASSESSMENT TEST 3

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Einführung in die Computerlinguistik

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

Computability and Complexity

(pp ) PDAs and CFGs (Sec. 2.2)

Pushdown Automata. Chapter 12

Pushdown Automata (PDA) The structure and the content of the lecture is based on

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

CDM Parsing and Decidability

Pushdown Automata. Reading: Chapter 6

Theory of Computation - Module 3

CFGs and PDAs are Equivalent. We provide algorithms to convert a CFG to a PDA and vice versa.

Theory of Computation

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

(pp ) PDAs and CFGs (Sec. 2.2)

The Idea of a Pushdown Automaton

CISC4090: Theory of Computation

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

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

Introduction to Theory of Computing

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Theory of Computation (Classroom Practice Booklet Solutions)

CISC 4090 Theory of Computation

CSE 105 THEORY OF COMPUTATION

Context-Free Languages

Section 1 (closed-book) Total points 30

Pushdown Automata (Pre Lecture)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Push-down Automata = FA + Stack

Miscellaneous. Closure Properties Decision Properties

Sheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

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

Rumination on the Formal Definition of DPDA

Theory of Computation Turing Machine and Pushdown Automata

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

Properties of Context-Free Languages. Closure Properties Decision Properties

INSTITUTE OF AERONAUTICAL ENGINEERING

PUSHDOWN AUTOMATA (PDA)

5 Context-Free Languages

Context-free Languages and Pushdown Automata

CS500 Homework #2 Solutions

Automata Theory - Quiz II (Solutions)

CPS 220 Theory of Computation Pushdown Automata (PDA)

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

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Undecidable Problems and Reducibility

The Pumping Lemma. for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.

Automata and Computability. Solutions to Exercises

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

Fundamentele Informatica 3 Antwoorden op geselecteerde opgaven uit Hoofdstuk 7 en Hoofdstuk 8

Automata and Computability. Solutions to Exercises

Theory of Computation

Pushdown Automata: Introduction (2)

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

Languages, regular languages, finite automata

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

Deterministic PDA s. Deepak D Souza. 08 Nov Department of Computer Science and Automation Indian Institute of Science, Bangalore.

CpSc 421 Final Exam December 15, 2006

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

CS481F01 Solutions 6 PDAS

Ogden s Lemma for CFLs

Transcription:

CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 1

Tale of Contents: Week 1: Preliminaries (set alger relations, functions) (read Chapters 1-4) Weeks 3-6: Regular Languages, Finite Automata (Chapter 11) Weeks 7-9: Context-Free Languages, Pushdown Automata (Chapters 12) Weeks 10-12: Turing Machines (Chapter 13) 2

Tale of Contents (conti): Weeks 13-14: Propositional Logic (Chapter 6), Predicate Logic (Chapter 7), Computational Logic (Chapter 9), Algeraic Structures (Chapter 10) 3

7. Context-Free Languages & Pushdown Automata- Pushdown Automata Transform an empty-stack PDA to a C-F grammar such that language accepted y the PDA is the same as language generated y the C-F grammar C-F grammar 4

Relationship etween accepting and generating: How would a PDA accept a symol a in an input string? B w = a Must have i x (State j could e the same as state i, and B can not e Ʌ ) j How would a CFG generate a string with a symol a in it? Must have w = a B a w1 (B is a non-terminal, w1 is a string of terminals and/or non-terminals ut do not contain and w1 could e Ʌ) 5

Relationship etween accepting and generating: How would a PDA accept a symol a in an input string as follows? w = a Must have i B x (State j could e the same as state i, and B can not e Ʌ ) j How would a CFG generate a symol a in an input string as follows? Must have w = a B a (B is a non-terminal) 6

Relationship etween accepting and generating: How would a PDA accept a string a c? B w = a c Must have x i j c, B x k (State j could e the same as state i, and B can not e Ʌ ) How would a CFG generate a string a c? w = a c Must have Bik a Bjk (Bik and Bjk are non-terminals, and Bjk could e Ʌ) 7

Transform an empty-stack PDA to a C-F grammar Basic idea: Define non-terminals Bij for the CFG that can generate all strings w that: upon reading w on the input tape of the PDA will take you from state i to state j in the PDA and have a net result of ping B off the stack In essence, B is eventually replaced y w It may take many moves to get there. 8

Transform an empty-stack PDA to a C-F grammar B (B is removed) i w j B ij w (leftmost derivation) 9

Transform an empty-stack PDA to a C-F grammar Type 1: PDA instruction a is the string accepted Grammar Production B ij a B can reach an emptystack status 10

Transform an empty-stack PDA to a C-F grammar Type 1: The string accepted PDA instruction Grammar Production B ij a Example:, 1 2 B 1 2 12 11 B 12 a

Transform an empty-stack PDA to a C-F grammar Type 2: PDA instruction Grammar Production B ik a B jk for each state k B B accepted string is a followed y whatever is accepted etween state j and state k 12

Transform an empty-stack PDA to a C-F grammar PDA instruction Grammar Production B ik ab jk for each state k Example: 1 B nop 2, B 3 c, B 4 B B14 ab24 13 ab 23 13

Transform an empty-stack PDA to a C-F grammar Type 3: PDA instruction Grammar Production B il ac jk B kl for each state k and l B C B B 14

Transform an empty-stack PDA to a C-F grammar PDA instruction Grammar Production B il ac jk B kl for each state k and l Example: B B C B 1 B Push(C) 2, C 3 c, B 4 B13 a C 23 B14 a C23B34 15

Transform an empty-stack PDA to a C-F grammar Type 4: PDA instruction The production that will generate the string accepted y the PDA etween state i and state j Grammar Production S ij for each ( S is start state j symol) Could lead to an empty-stack status 16

Transform an empty-stack PDA to a C-F grammar Type 4: PDA instruction Grammar Production S ij for each state j Example: start 1 nop 2 c, 3 S 13 13 a 23 (Type 2) 17

Example. Transform the following empty-stack PDA into a C-F grammar. Solution: Type 4 The start state 0 with on the stack gives: S 01 18

Example. Transform the following empty-stack PDA into a C-F grammar. Solution: Type 1 The operation (1,,, 1) gives a 11 19

Example. Transform the following empty-stack PDA into a C-F grammar. Solution: Type 1 The operation (1, A,, 1) gives A a 11 20

Example. Transform the following empty-stack PDA into a C-F grammar. Solution: Type 2 The nop operation (0, A, nop, 1) gives A01 aa 11 21

Example. Transform the following empty-stack PDA into a C-F grammar. Solution: Type 3 The push operation (0,, push(a), 0) gives aa 01 0111 22

Empty-stack PDA: C-G Grammar: S 01 11 a A 11 a A 01 aa 11 aa 01 0111 Leftmost derivation S 01 aa 01 11 aaa 11 11 aaa 11 aaaa The language accepted y this PDA has one element only: aaaa 23

Empty-stack PDA: C-G Grammar: S 01 11 a A 11 a A aa 01 aa 11 01 0111 (0, aaa ) (0, aa A) (1, a A) (1, ) Accepted 24 A

Example. Find a grammar for the language L = {w { }* na(w) = n(w)} y (1) constructing an empty-stack PDA to accept L and then (2) transforming it into a C-F grammar. Solution: (1) To accept lamda and to reach empty-stack status To ensure # of a s and # of s are the same 25

Note the following two PDAs are equivalent: Solution 2 of HW6, #4 26

Solution: (1) Consider: aaaaa Accepted Hence, the aove PDA accepts L 27 B A A Stack is empty

Solution: (2) PDA Transformed into C - F grammar : S aa B A aaa Type =? B a B B 28

Solution: (2) PDA Transformed into C - F grammar : S aa B A aaa Type =? B a B B 29

Solution: (2) PDA Transformed into C - F grammar : S A B aa aa a B A B B Type =? 30

Solution: (2) PDA Transformed into C - F grammar : S A B aa aa a B A B B Type =? 31

Solution: (2) PDA Transformed into C - F grammar : S A B aa aa a B A B B University of Kentucky Type =? 3/22/2017 32

Solution: (2) PDA Transformed into C - F grammar : S A B aa aa a B A B B 33 Type =?

Solution: (2) PDA Transformed into C - F grammar : S A B aa aa a B A B B Type =? 34

Solution: (2) PDA Transformed into C - F grammar : S A B aa aa a B A B B Type =? 35

Solution: (2) PDA Transformed into C - F grammar S A B aa aa a B A B B : Simplified CFG : S aas BS A aaa B a BB 36

Solution: (2) Simplified CFG : S aas BS A aaa B a BB Derivation of aaa : S aas aaaas aaas aaaaas aaaas aaas aaa 37

Nondeterministic PDAs are more powerful than deterministic PDAs. An example is to consider the language of even Palindromes (such as: aaaaaa) over { }. A context-free grammar for the language is given y S Λ asa S Left half and right half are symmetric Any PDA to accept the language must make a nondeterministic decision to start comparing the 2nd half of a string with the reverse of the first half. 38

Example: consider the following PDA a a, a, Start 0 1 2,, a,,, nop nop nop,, push ( ), push ( ), a push ( ) This non-deterministic PDA accepts the language of even palindromes over { } 39

Example: consider the following PDA Why is this an non-deterministic PDA? a a, a, Start 0,, a,,, nop nop nop 1 2,, push ( ), push ( ), a push ( ) 40

Example: Does it accept consider even the palindromes following PDA over { }? a a, a, Start 0,, a,,, nop nop nop 1 2,, push ( ), push ( ), a push ( ) Consider (0, a ) If we make a guess here (0, a) (0, a) (0, a) (0, Ʌ a) (1, a) (1, a) (1, a) 41 (1, Ʌ, ) (2, Ʌ, Ʌ)

Example: The PDA may consider guess the the following middle wrong: PDA a a, a, Start 0,, a,,, nop nop nop 1 2,, push ( ), push ( ), a push ( ) Consider (0, a ) If the PDA made a guess here (0, a) (0, a) (0, Ʌ a) (1, a) (1, a) 42 It gets stuck here!

Example: This PDA can consider only accept the following even palindromes: PDA a a, a, Start 0,, a,,, nop nop nop 1 2,, push ( ), push ( ), a push ( ) Consider (0, aa ) (0, a a) (0, aa) (0, aa) (0, aa) (0, aa) (0, Ʌ, aaa) 43 (1, Ʌ, aaa) It gets stuck here!

There is in general no way to translate a nondeterministic PDA (NPDA) into a deterministic one. Indeed, there is no DPDA which recognizes the language of even palindromes. That is why we can say that NPDAs are more powerful than DPDAs. However, we can define a similar language L1 over {, $} which can e recognized y a DPDA: L1 = { w$w R w ϵ { }* } 44

Example: consider the following PDA A DPDA for L1: a a, a, Start 0 $, $, a $,,, nop nop nop 1 2,, push ( ), push ( ), a push ( ) Consider (0, a$ ) Is this PDA indeed deterministic? (0, $ a) (0, $ a) (0, $ a) (1, a) (1, a) (1, a) What do you see here? 45 (1, Ʌ, ) (2, Ʌ, Ʌ)

Note that 1. Final-state acceptance and empty-stack acceptance are equivalent only for NPDAs 2. Final-state acceptance and empty-stack acceptance are not equivalent for DPDAs. For DPDAs, the class of languages defined y final-state acceptance is igger. Why? 46

Recall: The following is a C-F grammar for the language of even palindromes over { } S Λ asa S Using the CFG to PDA algorithm, we can transform the grammar into an empty-stack NPDA as follows: (0,, 0) (0,,,, 0) (0, Λ, S,, 0) (0, Λ, S,, push(a), push(s), push(a), 0) (0, Λ, S,, push(), push(s), push(), 0) 47

Question: Is this empty-stack NPDA (0,, 0); (0,,,, 0); (0, Λ, S,, 0); (0, Λ, S,, push(a), push(s), push(a), 0); (0, Λ, S,, push(), push(s), push(), 0) equivalent to the following final-state NPDA? P1 P2 a a, a, Start 0 1, 2,, a, nop nop nop, push ( ), push ( ), a push ( ) 48

Question: Or, is this empty-stack PDA P1 a, a,, Start 0,, push (, a),, push (,, ) equivalent to the following final-state PDA? P2 a a, a, Start, push ( ) 0, push ( ) 1, 2,, a, nop nop nop, a push ( ) 49

It is easy to see that P1 accepts even palindromes a, a,, Start 0,, push (, a),, push (,, ) Consider (0, a ) (0, Ʌa ) (0, a aa) (0, a) (0, Ʌ a) (0, a) (0, a) (0, Ʌ a) (0, a) (0, a) (0, Ʌ a) (0, a) (0, a) (0, a) (0, Ʌ, Ʌ) Accepted 50 P1

P1 can only accept even palindromes a, a,, Start 0,, push (, a),, push (,, ) Consider (0, aa ) (0, Ʌaa ) (0, aa aa) (0, a a) (0, Ʌa a) (0, a aaa) (0, aa) (0, Ʌ aa) (0, aa) (0, aa) (0, Ʌ a) (0, aa) (0, aa) It gets stuck here! 51

Since P2 accepts and can only accept even palindromes over { }, P1 and P2 are equivalent. The question then is: can P1 and P2 e transformed to a C-F grammar for the language of even palindromes over { }? S Λ asa S 52

How to handle Type 3 PDA instructions for P1: a, a,, Start 0,, push (, a),, push (,, ) Consider the following situation: P1,, push (, a) 0 0 Y a a Y 53 a Y a Y Y

How to handle Type 3 PDA instructions for P1: a, a,, Start 0,, push (, a),, push (,, ) Consider the following situation: P1,, push (, a) 0 0 a, a 0 0 0 Y a a Y 54 a Y a Y Y

How to handle Type 3 PDA instructions for P1: a, a,, Start 0,, push (, a),, push (,, ) Consider the following situation: P1,, push (, a) 0 0 a, a 0 0 0 A A 55

Summarize: CFGs and PDAs have equivalent expressive powers. More formally,... Theorem. For every CFG G, there is a PDA P such that L(G) = L(P). In addition, for every PDA P, there is a CFG G such that L(P) = L(G). Thus, L is CF iff there is a (non-deterministic) PDA P such that L = L(P). CF languages are exactly those languages that are accepted y (non-deterministic) PDAs. 56

Summarize: A CF language is called a deterministic final-state CF language if it can e recognized y a deterministic final-state PDA Even palindromes: not a deterministic final-state CFL a NPDA Start, push ( ) 0, push ( ),, a,,, nop nop nop, a push ( ) 1 2, 57

Summarize: L1 over {, $} is a deterministic final-state CFL: L1 = { w$w R w ϵ { }* } a DPDA Start, push ( ) 0, push ( ) $, $, a $,,, nop nop nop, a push ( ) 1 2, 58

End of Context-Free Language and Pushdown Automata II 59