Formal Languages and Automata

Similar documents
Foundations of Informatics: a Bridging Course

C6.2 Push-Down Automata

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

MTH401A Theory of Computation. Lecture 17

NPDA, CFG equivalence

Formal Languages, Automata and Compilers

Computational Models - Lecture 4

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

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

Einführung in die Computerlinguistik

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CS Pushdown Automata

Properties of Context-Free Languages

Introduction to Theory of Computing

Pushdown Automata. Reading: Chapter 6

Computational Models - Lecture 5 1

UNIT-VI PUSHDOWN AUTOMATA

Context-Free Languages

Grammars and Context Free Languages

Grammars and Context Free Languages

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

Computability and Complexity

Ogden s Lemma for CFLs

Automata Theory - Quiz II (Solutions)

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, 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,

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

CSCI Compiler Construction

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

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

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

Lecture 2: Regular Expression

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

Theory of Computation Turing Machine and Pushdown Automata

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

Accept or reject. Stack

CSE 105 THEORY OF COMPUTATION

CDM Parsing and Decidability

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

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm

Formal Definition of a Finite Automaton. August 26, 2013

Lecture III CONTEXT FREE LANGUAGES

Lecture 17: Language Recognition

CS481F01 Prelim 2 Solutions

Theory of Computation 8 Deterministic Membership Testing

Properties of Context-Free Languages. Closure Properties Decision Properties

DM17. Beregnelighed. Jacob Aae Mikkelsen

3.13. PUSHDOWN AUTOMATA Pushdown Automata

Chap. 7 Properties of Context-free Languages

Fundamentele Informatica II

Pushdown Automata (2015/11/23)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

5 Context-Free Languages

Theory of Computation - Module 3

What we have done so far

Theory of Computation (II) Yijia Chen Fudan University

Mildly Context-Sensitive Grammar Formalisms: Embedded Push-Down Automata

The Idea of a Pushdown Automaton

Properties of context-free Languages

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Push-down Automata = FA + Stack

ECS 120 Lesson 15 Turing Machines, Pt. 1

Theory of Computation (IV) Yijia Chen Fudan University

Computational Models: Class 5

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

Theory of Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CPS 220 Theory of Computation Pushdown Automata (PDA)

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

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

Equivalence of CFG s and PDA s

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

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

Chapter Five: Nondeterministic Finite Automata

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

CS 455/555: Finite automata

Equivalence of DFAs and NFAs

Theory of Computation

Fooling Sets and. Lecture 5

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y.

CISC 4090 Theory of Computation

CISC4090: Theory of Computation

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

Address for Correspondence

Pushdown Automata (Pre Lecture)

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

Theory of Computation

Pushdown Automata. Chapter 12

Undecidable Problems and Reducibility

Nondeterministic Finite Automata

CSCI 1010 Models of Computa3on. Lecture 17 Parsing Context-Free Languages

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

Computability and Complexity

Page 1. Compiler Lecture Note, (Regular Language) 컴파일러입문 제 3 장 정규언어. Database Lab. KHU

Transcription:

Formal Languages and Automata Lecture 6 2017-18 LFAC (2017-18) Lecture 6 1 / 31

Lecture 6 1 The recognition problem: the Cocke Younger Kasami algorithm 2 Pushdown Automata 3 Pushdown Automata and Context-free Languages 4 Deterministic pushdown automata LFAC (2017-18) Lecture 6 2 / 31

The recognition problem: the Cocke Younger Kasami algorithm Lecture 6 1 The recognition problem: the Cocke Younger Kasami algorithm 2 Pushdown Automata 3 Pushdown Automata and Context-free Languages 4 Deterministic pushdown automata LFAC (2017-18) Lecture 6 3 / 31

The recognition problem: the Cocke Younger Kasami algorithm The Cocke Younger Kasami (CYK) Agorithm The recognition problem in grammars that are in Chomsky Normal Form can be solved using the CYK algorithm in O(n 3 ). If w = a 1 a 2...a n then we build the sets V ij = {A A + a i a i+1...a i+j 1 } inductively, for j = 1,...,n w L(G) S V 1n LFAC (2017-18) Lecture 6 4 / 31

The recognition problem: the Cocke Younger Kasami algorithm The Cocke Younger Kasami Algorithm For j = 1: V i1 = {A A + a i } = {A A a i P} For j > 1, V ij : If A + a i a i+1...a i+j 1 : A BC + a i a i+1...a i+j 1 and B + a i a i+1...a i+k 1 (B V ik ) C + a i+k a i+k+1...a i+j 1 (C V i+k j k ) where 1 i n+1 j, 1 k j 1 V ij = j 1 k=1 {A A BC P, B V ik, C V i+k j k } LFAC (2017-18) Lecture 6 5 / 31

The recognition problem: the Cocke Younger Kasami algorithm The Cocke Younger Kasami Algorithm Notation: {A A BC P, B V ik, C V i+k j k } = V ik V i+k j k Then: for 2 j n, 1 i n+1 j : V ij = j 1 (V ik V i+k j k ) k=1 LFAC (2017-18) Lecture 6 6 / 31

The recognition problem: the Cocke Younger Kasami algorithm The Cocke Younger Kasami Algorithm Input: G = (N, T, S, P) in Chomsky Normal Form, w = a 1 a 2...a n Output: w L(G)? for(i=1; i<=n; i++) V i1 = {A A a i P}; for(j=2; j<=n; j++) for (i=1; i<=n+1-j; i++){ V ij = ; for(k=1; k<=j-1; k++) V ij = V ij (V ik V i+k j k ); } if(s V 1n ) w L(G) else w L(G) LFAC (2017-18) Lecture 6 7 / 31

The recognition problem: the Cocke Younger Kasami algorithm Example G = ({S, X, Y, Z},{a, b, c}, S, P), where P: S XY X XY a Y YZ a b Z c w = abc LFAC (2017-18) Lecture 6 8 / 31

The recognition problem: the Cocke Younger Kasami algorithm Example G = ({S, X, Y, Z},{a, b, c}, S, P), where P: S XY X XY a Y YZ a b Z c w = abc V 11 = {X, Y} V 12 = {S, X} V 13 = {S, X} V 21 = {Y} V 22 = {Y} V 31 = {Z} S V 13 abc L(G) LFAC (2017-18) Lecture 6 8 / 31

Lecture 6 1 The recognition problem: the Cocke Younger Kasami algorithm 2 Pushdown Automata 3 Pushdown Automata and Context-free Languages 4 Deterministic pushdown automata LFAC (2017-18) Lecture 6 9 / 31

Pushdown Automata Finite automata + pushdown memory (stack) LFAC (2017-18) Lecture 6 10 / 31

Pushdown automata - definition Definition 1 A pushdown automaton: M = (Q,Σ,Γ,δ, q 0, z 0, F): Q is a finite set of states Σ is the input alphabet Γ is the stack alphabet q 0 Q is the initial state z 0 Γ is the initial symbol in the stack F Q is the set of final states δ : Q (Σ {ǫ}) Γ 2 Q Γ The model is non-deterministic LFAC (2017-18) Lecture 6 11 / 31

Configuration of a Pushdown Automata Configuration: (q, w,γ) Q Σ Γ 1 : γ (first symbol in γ) represents the top of the stack LFAC (2017-18) Lecture 6 12 / 31

Pushdown automata Pushdown Automata Initial configuration: (q 0, w, z 0 ) Q Σ Γ LFAC (2017-18) Lecture 6 13 / 31

The transition relation between configurations Configuration (q, aw, zβ) and (q,α) δ(q, a, z) (q, q Q, a Σ {ǫ}, z Γ, α,β Γ ) LFAC (2017-18) Lecture 6 14 / 31

The transition relation between configurations (q, aw, zβ) (q, w,αβ) LFAC (2017-18) Lecture 6 15 / 31

The transition relation between configurations Let M = (Q,Σ,Γ,δ, q 0, z 0, F) be a pushdown automaton. The transition relation between configurations: (q, aw, zβ) (q, w,αβ) if (q,α) δ(q, a, z) (q, q Q, a Σ {ǫ}, z Γ, α,β Γ ) Computation: the transitive and reflexive closure of the transition relation: C 1,...,C n configurations such that: C 1 C 2... C n written: C 1 + C n if n 2, C 1 C n, if n 1 LFAC (2017-18) Lecture 6 16 / 31

Recognized language By final states (if F ) L(M) = {w Σ (q 0, w, z 0 ) (q,ǫ,γ), q F, γ Γ } By empty stack (if F = ) L ǫ (M) = {w Σ (q 0, w, z 0 ) (q,ǫ,ǫ), q Q} LFAC (2017-18) Lecture 6 17 / 31

Example Automaton which recognizes the language {a n b n n 1}: M = ({q 0, q 1, q 2 },{a, b},{a, z},δ, q 0, z,{q 2 }) 1 δ(q 0, a, z) = {(q 0, az)} 2 δ(q 0, a, a) = {(q 0, aa)} 3 δ(q 0, b, a) = {(q 1,ǫ)} 4 δ(q 1, b, a) = {(q 1,ǫ)} 5 δ(q 1,ǫ, z) = {(q 2,ǫ)} LFAC (2017-18) Lecture 6 18 / 31

Examples Pushdown automaton which recognizes the language {waw R w {0, 1} } LFAC (2017-18) Lecture 6 19 / 31

Examples Pushdown automaton which recognizes the language {waw R w {0, 1} } Every 0 or 1 read is added to the stack a in the input changes the state LFAC (2017-18) Lecture 6 19 / 31

Examples Pushdown automaton which recognizes the language {waw R w {0, 1} } Every 0 or 1 read is added to the stack a in the input changes the state after reading a, for every symbol read from the input, the same symbol must be removed from the stack M = ({q 0, q 1, q 2 },{0, 1, a},{0, 1, z},δ, q 0, z,{q 2 }) 1 δ(q 0, i, z) = {(q 0, iz)}, (i {0, 1}) 2 δ(q 0, i, j) = {(q 0, ij)}, (i, j {0, 1}) 3 δ(q 0, a, i) = {(q 1, i)} 4 δ(q 1, i, i) = {(q 1,ǫ)} 5 δ(q 1,ǫ, z) = {(q 2,ǫ)} LFAC (2017-18) Lecture 6 19 / 31

Examples Pushdown automaton which recognizes the language {waw R w {0, 1} } Every 0 or 1 read is added to the stack a in the input changes the state after reading a, for every symbol read from the input, the same symbol must be removed from the stack M = ({q 0, q 1, q 2 },{0, 1, a},{0, 1, z},δ, q 0, z,{q 2 }) 1 δ(q 0, i, z) = {(q 0, iz)}, (i {0, 1}) 2 δ(q 0, i, j) = {(q 0, ij)}, (i, j {0, 1}) 3 δ(q 0, a, i) = {(q 1, i)} 4 δ(q 1, i, i) = {(q 1,ǫ)} 5 δ(q 1,ǫ, z) = {(q 2,ǫ)} Pushdown automaton for {ww R w {0, 1} }? LFAC (2017-18) Lecture 6 19 / 31

Examples Pushdown automaton which recognizes the language {waw R w {0, 1} } Every 0 or 1 read is added to the stack a in the input changes the state after reading a, for every symbol read from the input, the same symbol must be removed from the stack M = ({q 0, q 1, q 2 },{0, 1, a},{0, 1, z},δ, q 0, z,{q 2 }) 1 δ(q 0, i, z) = {(q 0, iz)}, (i {0, 1}) 2 δ(q 0, i, j) = {(q 0, ij)}, (i, j {0, 1}) 3 δ(q 0, a, i) = {(q 1, i)} 4 δ(q 1, i, i) = {(q 1,ǫ)} 5 δ(q 1,ǫ, z) = {(q 2,ǫ)} Pushdown automaton for {ww R w {0, 1} }? Pushdown automaton for {ww w {0, 1} }? LFAC (2017-18) Lecture 6 19 / 31

Pushdwon automata with final states and without final states Theorem 1 For any pushdown automaton M with F =, there exists a pushdown automaton M with final states such that L(M ) = L ǫ (M). LFAC (2017-18) Lecture 6 20 / 31

Pushdwon automata with final states and without final states Theorem 1 For any pushdown automaton M with F =, there exists a pushdown automaton M with final states such that L(M ) = L ǫ (M). If M = (Q,Σ,Γ,δ, q 0, z 0, ), let M = (Q {q f, q 0 },Σ,Γ {z 0 },δ, q 0, z 0,{q f}) with δ : LFAC (2017-18) Lecture 6 20 / 31

Pushdwon automata with final states and without final states Theorem 1 For any pushdown automaton M with F =, there exists a pushdown automaton M with final states such that L(M ) = L ǫ (M). If M = (Q,Σ,Γ,δ, q 0, z 0, ), let M = (Q {q f, q 0 },Σ,Γ {z 0 },δ, q 0, z 0,{q f}) with δ : 1 δ (q 0,ǫ, z 0 ) = {(q 0, z 0 z 0 )} (without reading any symbol, M goes to the initial configuration of M) LFAC (2017-18) Lecture 6 20 / 31

Pushdwon automata with final states and without final states Theorem 1 For any pushdown automaton M with F =, there exists a pushdown automaton M with final states such that L(M ) = L ǫ (M). If M = (Q,Σ,Γ,δ, q 0, z 0, ), let M = (Q {q f, q 0 },Σ,Γ {z 0 },δ, q 0, z 0,{q f}) with δ : 1 δ (q 0,ǫ, z 0 ) = {(q 0, z 0 z 0 )} (without reading any symbol, M goes to the initial configuration of M) 2 δ (q, a, z) = δ(q, a, z), q Q, a Σ {ǫ}, z Γ (M makes the same transitions as M) LFAC (2017-18) Lecture 6 20 / 31

Pushdwon automata with final states and without final states Theorem 1 For any pushdown automaton M with F =, there exists a pushdown automaton M with final states such that L(M ) = L ǫ (M). If M = (Q,Σ,Γ,δ, q 0, z 0, ), let M = (Q {q f, q 0 },Σ,Γ {z 0 },δ, q 0, z 0,{q f}) with δ : 1 δ (q 0,ǫ, z 0 ) = {(q 0, z 0 z 0 )} (without reading any symbol, M goes to the initial configuration of M) 2 δ (q, a, z) = δ(q, a, z), q Q, a Σ {ǫ}, z Γ (M makes the same transitions as M) 3 δ (q,ǫ, z 0 ) = {(q f,ǫ)}, q Q (M goes into a final state only if the stack of M is empty) LFAC (2017-18) Lecture 6 20 / 31

Pushdwon automata with final states and without final states Theorem 2 For every pushdown automaton M with F, there exists a pushdown automaton M with F = such that L ǫ (M ) = L(M). LFAC (2017-18) Lecture 6 21 / 31

Pushdwon automata with final states and without final states Theorem 2 For every pushdown automaton M with F, there exists a pushdown automaton M with F = such that L ǫ (M ) = L(M). If M = (Q,Σ,Γ,δ, q 0, z 0, F), let M = (Q {q ǫ, q 0 },Σ,Γ {z 0 },δ, q 0, z 0, ) LFAC (2017-18) Lecture 6 21 / 31

Proof M = (Q {q ǫ, q 0 },Σ,Γ {z 0 },δ, q 0, z 0, ), with δ : LFAC (2017-18) Lecture 6 22 / 31

Proof M = (Q {q ǫ, q 0 },Σ,Γ {z 0 },δ, q 0, z 0, ), with δ : 1 δ (q 0,ǫ, z 0 ) = {(q 0, z 0 z 0 )} (without reading any symbol, M goes into the initial configuration of M) LFAC (2017-18) Lecture 6 22 / 31

Proof M = (Q {q ǫ, q 0 },Σ,Γ {z 0 },δ, q 0, z 0, ), with δ : 1 δ (q 0,ǫ, z 0 ) = {(q 0, z 0 z 0 )} (without reading any symbol, M goes into the initial configuration of M) 2 a) δ (q, a, z) = δ(q, a, z), q Q, a Σ, z Γ (M makes the same transitions as f M, for any symbol read from the input) b) δ (q,ǫ, z) = δ(q,ǫ, z), if q Q \ F, z Γ (M makes the same ǫ-transitions as M, if the state is non-final ) c) δ (q,ǫ, z) = δ(q,ǫ, z) {(q ǫ,ǫ)}, q F, z Γ (if M goes into a final state, M can go into a special state ) LFAC (2017-18) Lecture 6 22 / 31

Proof M = (Q {q ǫ, q 0 },Σ,Γ {z 0 },δ, q 0, z 0, ), with δ : 1 δ (q 0,ǫ, z 0 ) = {(q 0, z 0 z 0 )} (without reading any symbol, M goes into the initial configuration of M) 2 a) δ (q, a, z) = δ(q, a, z), q Q, a Σ, z Γ (M makes the same transitions as f M, for any symbol read from the input) b) δ (q,ǫ, z) = δ(q,ǫ, z), if q Q \ F, z Γ (M makes the same ǫ-transitions as M, if the state is non-final ) c) δ (q,ǫ, z) = δ(q,ǫ, z) {(q ǫ,ǫ)}, q F, z Γ (if M goes into a final state, M can go into a special state ) 3 δ (q,ǫ, z 0 ) = {(q ǫ,ǫ)}, if q F ( case 2(c), if the top of the stack is z 0 ) LFAC (2017-18) Lecture 6 22 / 31

Proof M = (Q {q ǫ, q 0 },Σ,Γ {z 0 },δ, q 0, z 0, ), with δ : 1 δ (q 0,ǫ, z 0 ) = {(q 0, z 0 z 0 )} (without reading any symbol, M goes into the initial configuration of M) 2 a) δ (q, a, z) = δ(q, a, z), q Q, a Σ, z Γ (M makes the same transitions as f M, for any symbol read from the input) b) δ (q,ǫ, z) = δ(q,ǫ, z), if q Q \ F, z Γ (M makes the same ǫ-transitions as M, if the state is non-final ) c) δ (q,ǫ, z) = δ(q,ǫ, z) {(q ǫ,ǫ)}, q F, z Γ (if M goes into a final state, M can go into a special state ) 3 δ (q,ǫ, z 0 ) = {(q ǫ,ǫ)}, if q F ( case 2(c), if the top of the stack is z 0 ) 4 δ (q ǫ,ǫ, z) = {(q ǫ,ǫ)}, if z Γ {z 0 } ( M remains in state q ǫ and pops the top of the stack) LFAC (2017-18) Lecture 6 22 / 31

Lecture 6 Pushdown Automata and Context-free Languages 1 The recognition problem: the Cocke Younger Kasami algorithm 2 Pushdown Automata 3 Pushdown Automata and Context-free Languages 4 Deterministic pushdown automata LFAC (2017-18) Lecture 6 23 / 31

and Context-free Languages The pushdown automaton equivalent to a type 2 grammar Theorem 3 For any type 2 grammar G there exists a pushdown automaton M without final states such that L ǫ (M) = L(G) LFAC (2017-18) Lecture 6 24 / 31

and Context-free Languages The pushdown automaton equivalent to a type 2 grammar Theorem 3 For any type 2 grammar G there exists a pushdown automaton M without final states such that L ǫ (M) = L(G) Let G = (N, T, S, P) The pushdown automaton: M = ({q}, T, N T,δ, q, S, ) where: 1 δ(q,ǫ, A) = {(q,β) A β P}, A N 2 δ(q, a, a) = {(q,ǫ)}, a T 3 δ(q, x, y) =, otherwise w L(G) S + w (q, w, S) + (q,ǫ,ǫ) w L ǫ (M) M simulates the leftmost derivations of G LFAC (2017-18) Lecture 6 24 / 31

and Context-free Languages Example G = ({x},{a, b}, x,{x axb, x ab}) The equivalent pushdown automaton: M = ({q},{a, b},{a, b, x},δ, q, x, ) 1 δ(q,ǫ, x) = {(q, axb),(q, ab)} 2 δ(q, a, a) = {(q,ǫ)} 3 δ(q, b, b) = {(q,ǫ)} LFAC (2017-18) Lecture 6 25 / 31

and Context-free Languages The grammar equivalent to a pushdown automaton Theorem 4 For any pushdown automaton M there exists a grammar G such that L(G) = L ǫ (M) LFAC (2017-18) Lecture 6 26 / 31