Increasing the power of FSAs

Similar documents
Pushdown Automata. Chapter 12

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

FINITE STATE AUTOMATA

Part I: Definitions and Properties

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

Languages, regular languages, finite automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Accept or reject. Stack

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

Theory of Computation (IV) Yijia Chen Fudan University

CISC4090: Theory of Computation

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

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

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

Pushdown Automata. Reading: Chapter 6

Computability and Complexity

Fundamentele Informatica II

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

Section: Pushdown Automata

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

ECS 120 Lesson 15 Turing Machines, Pt. 1

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Pushdown Automata (2015/11/23)

Nondeterministic Finite Automata

input tape head moves current state a a

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,

CpSc 421 Final Exam December 15, 2006

Formal Definition of a Finite Automaton. August 26, 2013

MA/CSSE 474 Theory of Computation

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

Computational Models - Lecture 4

Introduction to Theory of Computing

UNIT-VI PUSHDOWN AUTOMATA

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

CS 455/555: Finite automata

Computational Models - Lecture 5 1

Einführung in die Computerlinguistik

MTH401A Theory of Computation. Lecture 17

Automata and Computability. Solutions to Exercises

Lecture 17: Language Recognition

CSE 105 THEORY OF COMPUTATION

Computation Histories

Theory of Computation (Classroom Practice Booklet Solutions)

Theory of Computation

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

C6.2 Push-Down Automata

Lecture 13: Turing Machine

Context-Free Languages

5 Context-Free Languages

Equivalence of CFG s and PDA s

DM17. Beregnelighed. Jacob Aae Mikkelsen

Automata and Computability. Solutions to Exercises

CISC 4090 Theory of Computation

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

Chapter Five: Nondeterministic Finite Automata

CPS 220 Theory of Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

Undecidable Problems and Reducibility

Formal Languages and Automata

Variants of Turing Machine (intro)

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

CSE 105 THEORY OF COMPUTATION

V Honors Theory of Computation

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

Introduction to Turing Machines. Reading: Chapters 8 & 9

Automata and Formal Languages. Push Down Automata. Sipser pages Lecture 13. Tim Sheard 1

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

Homework Assignment 6 Answers

CS21 Decidability and Tractability

Chapter 6. Properties of Regular Languages

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Outline 1 PCP. 2 Decision problems about CFGs. M.Mitra (ISI) Post s Correspondence Problem 1 / 10

Closure under the Regular Operations

CSE 105 THEORY OF COMPUTATION

CISC 4090 Theory of Computation

CA320 - Computability & Complexity

Foundations of Informatics: a Bridging Course

Further discussion of Turing machines

CSE 105 THEORY OF COMPUTATION

Computational Models: Class 5

Uses of finite automata

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

CPS 220 Theory of Computation Pushdown Automata (PDA)

The Idea of a Pushdown Automaton

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

Finite Automata and Regular languages

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

The Pumping Lemma (cont.) 2IT70 Finite Automata and Process Theory

Section 1 (closed-book) Total points 30

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

Automata: a short introduction

Miscellaneous. Closure Properties Decision Properties

Equivalent Variations of Turing Machines

Pumping Lemma for CFLs

Closure under the Regular Operations

Transcription:

PDA 1 Increasing the power of FSAs The mechanical view Input tape Finite state control device Output tape

PDA 2 Now let us enrich it : a Input tape stack memory Finite state control device x q Output tape p A B Z 0

PDA 3 What is a stack? New symbols are inserted to the top The stack is read from the top A read symbol is extracted from the stack LIFO policy Z 0

PDA 4 Example Insert in the following order the symbols a b c Z 0

PDA 5 Example Insert in the following order the symbols a b c a Z 0

PDA 6 Example Insert in the following order the symbols a b c b a Z 0

PDA 7 Example Insert in the following order the symbols a b c c b a Z 0

PDA 8 Example Insert in the following order the symbols a b c c b a Read from the stack Z 0

PDA 9 Example Insert in the following order the symbols a b c c c b a Read from the stack Z 0

PDA 10 Pushdown automata Finite state automata can be enriched with a stack Pushdown Automata (PDA) PDAs differ from finite state machines in two ways: They can use the top of the stack to decide which transivon has to be made They can manipulate the stack as part of performing a transivon

PDA 11 Moves of a PDA Depending on the symbol read from the input (but it could also not read anything) the symbol read from the top of the stack the state of the control device the PDA changes its state moves ahead the scanning head changes the symbol read from the stack with a string α (possibly empty)

PDA 12 Acceptance The input string x is recognized (accepted) if the PDA scans it completely upon reaching the end of x, it is in an accepvng state Input tape stack memory Finite state control device q p A B Z 0

PDA 13 PDA: a first example L={a n b n n>0} a,a/aa b,a ε a,z 0 / BZ 0 q b,a ε 0 q b,b ε 1 q 2 q 3 a,b/ab b,b ε

PDA 14 Example (2) a,a/aa b,a ε a,z 0 / BZ 0 q 0 q 1 b,a ε q 2 b,b ε q 3 a,b/ab b,b ε a a a b b b Z 0

PDA 15 Example (2) a,a/aa b,a ε a,z 0 / BZ 0 q 0 q 1 b,a ε q 2 b,b ε q 3 a,b/ab b,b ε a a a b b b B Z 0

PDA 16 Example (2) a,a/aa b,a ε a,z 0 / BZ 0 q 0 q 1 b,a ε q 2 b,b ε q 3 a,b/ab b,b ε A a a a b b b B Z 0

PDA 17 Example (2) a,a/aa b,a ε a,z 0 / BZ 0 q 0 q 1 b,a ε q 2 b,b ε q 3 a,b/ab b,b ε A A a a a b b b B Z 0

PDA 18 Example (2) a,a/aa b,a ε a,z 0 / BZ 0 q 0 q 1 b,a ε q 2 b,b ε q 3 a,b/ab b,b ε A a a a b b b B Z 0

PDA 19 Example (2) a,a/aa b,a ε a,z 0 / BZ 0 q 0 q 1 b,a ε q 2 b,b ε q 3 a,b/ab b,b ε a a a b b b B Z 0

PDA 20 Example (2) a,a/aa b,a ε a,z 0 / BZ 0 q 0 q 1 b,a ε q 2 b,b ε q 3 a,b/ab b,b ε a a a b b b Z 0

PDA 21 Formally A PDA is a tuple <Q, I, Γ, δ, q 0, Z 0, F> Q is a finite set of states I is the input alphabet Γ is the stack alphabet δ is the transivon funcvon q 0 Q is the inival state Z 0 Γ is inival stack symbol F Q is the set of final states

PDA 22 TransiVon funcvon δ is the transivon funcvon δ: Q (I {ε}) Γ Q Γ * δ(q, i, A)=<p, α> Graphical notavon: q i,a/α p

PDA 23 Remarks Q, I, q 0 and F are defined as in FSAs δ is a parval funcvon Z 0 is the inival symbol of the stack, but it is not essenval It is useful to simplify definivons δ(q, ε, A)=<p, α>? An ε move is a spontaneous move ε does not mean that the input is empty!

PDA 24 Example Again L={a n b n n>0} a,a/aa b,a/ε a,z 0 / AZ 0 q 0 q 1 q 2 q 3 b,a/ε ε, Z 0 / Z 0

PDA 25 Informally A configuravon is a generalizavon of the novon of state A configuravon shows the current state of the control device, the porvon of the input string that starts from the head the stack It is a snapshot of the PDA

PDA 26 Formally A configuravon c is <q, x, γ> q Q is the current state of the control device x I * is the unread porvon of the input string γ Γ * is the string of symbols in the stack Stack convenvon High-lej, low-right The other way around is possible, but it is important to be coherent!

PDA 27 Example c=<q 1, abbb, ABZ 0 > a,a/aa b,a ε a,z 0 / BZ 0 q 0 q 1 b,a ε q 2 b,b ε q 3 A B Z 0 a,b/ab a a a b b b b,b ε

PDA 28 TransiVons TransiVons between configuravons ( ) depend on the transivon funcvon The transivon funcvon shows how to commute from a PDA snapshot to another There are two cases The transivon funcvon is defined for an input symbol The transivon funcvon is defined for an ε move

PDA 29 TransiVons: case 1 δ(q, i, A) = <q,α> is defined c=<q,x,γ> c =<q, x, γ > γ=aβ x=iy then γ = αβ x =y

PDA 30 TransiVons: case 2 δ(q, ε, A) = <q,α> is defined c=<q,x,γ> c =<q, x, γ > γ=aβ then γ = αβ x =x

PDA 31 Important remark An ε move is a spontaneous move If δ(q,ε,a) and A is the top symbol on the stack, the transivon can always be performed If δ(q,ε,a), then i I δ(q,i,a)= If this property was not savsfied, both the transivons would be allowed Nondeterminism

PDA 32 Acceptance condivon Let * be the reflexive transivve closure of the relavon Acceptance condivon: x I * (x L c 0 =<q 0,x,Z 0 > * c F =<q,ε,γ> and q F) Informally, a string is accepted by a PDA if there is a path coherent with x on the PDA that goes from the inival state to the final state The input string has to be read completely

PDA 33 Example L = {wcw R w {a,b} + } We need to use a LIFO policy to memorize w PUSH b,a/ba b,b/bb a,a/aa a,b/ab c,b/b c,a/a a,a/ε b,b/ε ε,z0/z0 q0 q1 q2 POP a,z0/az0 b,z0/bz0

PDA 34 PDA vs FSA (1) We know that a n b n cannot be recognized by any FSA Pumping Lemma but it can be recognized by a PDA Every regular language can be recognized by a PDA Given an FSA A=<Q,I,δ,q 0,F> it is straighporward to build a PDA A =<Q,I,Γ,δ,q 0,Z 0,F > such that L(A)=L(A )

PDA 35 PDA vs FSA (2) PDAs are more expressive than FSAs a n b n Regular languages wcw R Languages recognized by PDAs

PDA 36 Loops in PDAs Unlike FSAs, PDAs may not necessarily stop ajer a finite number of moves Loops of ε-moves are possible Example: a,z 0 AZ 0 ε,a ΑΑ Yet, looping PDAs do not add expressive power to the class of PDAs We can get rid of such PDAs Let s see how q

Loop-free PDA <q,x,α> * d <q,y,β> means that <q,x,α> * <q,y,β> and, for β=zβ, δ(q,ε,z)= * d is a sequence of moves that needs a symbol to proceed A PDA is loop free if and only if x I * q γ such that <q 0,x,Z 0 > * d <q,ε,γ> it always reads the whole input string and then stops i.e., it is unable to loop indefinitely with ε-moves Every PDA can be transformed into an equivalent loop-free PDA PDA 37

PDA 38 Complement The class of languages recognized by PDAs is closed under complement The complement can be built by eliminavng loops adding error states taking care of ε-moves connecvng final and nonfinal states swapping final and non-final states

PDA 39 Loop-free PDAs Loop eliminavon is essenval, otherwise the end of the string might never be reached What if there are sequences of ε-moves traversing some final and some non-final states (and the input is envrely read)? We might want to force acceptance only at the end of a (necessarily finite) sequence of ε-moves Otherwise swapping final and non-final states to obtain the complement will not work With these precauvons, we are sure that either the PDA or its complement will accept the string

PDA 40 Union The class of languages recognized by PDAs is not closed under union There is no PDA that recognizes {a n b n n 1} {a n b 2n n 1}, but {a n b n n 1} is recognizable by PDA {a n b 2n n 1} is recognizable by PDA IntuiVve sketch of proof If the stack is empved with n b s, then, if there are other b s, n is forgoven If the stack is half empved with the b s, then, if there are no more b s, it is impossible to know whether the stack contains n symbols

PDA 41 Other operavons The class of languages recognized by PDAs is not closed under intersecvon A B=(A c B c ) c Since PDA languages are closed under complement, if they were closed under intersecvon, they should be closed under union as well The class of languages recognized by PDAs is not closed under difference A B=A-B c Since PDA languages are closed under complement, if they were closed under difference, they should be closed under intersecvon as well

PDA 42 DefiniVon A PD transducer (PDT) is a tuple <Q, I, Γ, δ, q 0, Z 0, F, O, η> Q is a finite set of states F Q is the set of final states O is the output alphabet η: Q (I {ε}) Γ O * δ(q,i,a)=<p,α> η(q,i,a)=w q i,a/α,w p

PDA 43 Remarks Q, I, Γ, δ, q 0, Z 0 and F are defined as in acceptor PDAs η is defined only where δ is defined The stack can be necessary for two reasons: The language to be recognized requires it The translavon requires it

PDA 44 ConfiguraVon A configuravon c is <q, x, γ, z> q Q is the current state of the control device x I * is the unread porvon of the input string γ Γ * is the string of symbols in the stack z is the string already wriven on the output tape

PDA 45 TransiVons c=<q, x, γ, z> c =<q, x, γ, z > Case 1: δ(q, i, A) = <q,α> is defined and η(q, i, A)=w γ=aβ x=iy then γ = αβ x =y z =zw Case 2: δ(q, ε, A) = <q,α> is defined and η(q, ε, A)=w γ=aβ x=y then γ = αβ x =y z =zw

PDA 46 Acceptance condivon x I * (x L z= τ(x) c 0 =<q 0,x,Z 0, ε> * c F =<q,ε,γ,z> and q F) NoVce that the translavon of x is defined only if the string x is accepted

PDA 47 Example L={wc w {a,b} + } and τ(wc)=w R a,z 0 / AZ 0,ε a,a/ AA,ε a,b/ AB,ε b,z 0 / BZ 0,ε b,b/ BB,ε b,a/ BA,ε ε,a/ ε, a ε,b/ ε, b c,a/ ε, a ε,z 0 / Z 0,ε q 0 c,b/ ε, b q q 2 1

PDA 48 PDAs and compilers PDAs are at the heart of compilers Stack memory has a LIFO policy LIFO is suitable to analyze nested syntacvc structures ArithmeVcal expressions Compound instrucvons AcVvaVon records

PDA 49 Example PDA to recognize well parenthesized strings (()(()())) OK )())())) NO (,P/ PP ),P/ ε (,Z 0 / PZ 0 ε,z 0 / Z q 0 0 q q 2 1 Homework: try to build a PDA that recognizes the complement of this language