Decision, Computation and Language

Similar documents
Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, School of Informatics University of Edinburgh als@inf.ed.ac.

Automata and Computability. Solutions to Exercises

Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Finite Automata. Reading: Chapter 2

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN

Finite Automata. Reading: Chapter 2

CS154. Turing Machines. Turing Machine. Turing Machines versus DFAs FINITE STATE CONTROL AI N P U T INFINITE TAPE. read write move.

Chapter 7 Uncomputability

Turing Machines, Part I

Model 2.4 Faculty member + student

T Reactive Systems: Introduction and Finite State Automata

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

The Halting Problem is Undecidable

Regular Languages and Finite State Machines

Increasing Interaction and Support in the Formal Languages and Automata Theory Course

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 4 Nancy Lynch

Regular Expressions and Automata using Haskell

How To Compare A Markov Algorithm To A Turing Machine

Composability of Infinite-State Activity Automata*

3515ICT Theory of Computation Turing Machines

Increasing Interaction and Support in the Formal Languages and Automata Theory Course

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

Automata and Formal Languages

10CS35: Data Structures Using C

Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!

RULE 1: Additive Identity Property

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 15 april Master Edition

Turing Machines: An Introduction

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

Lecture summary for Theory of Computation

Philadelphia University Faculty of Information Technology Department of Computer Science First Semester, 2007/2008.

Bottom-Up Parsing. An Introductory Example

Data Structures and Algorithms V Otávio Braga

Automata on Infinite Words and Trees

Introduction to Automata Theory. Reading: Chapter 1

Electrical Symbols and Line Diagrams

24 Uses of Turing Machines

Using Hands-On Visualizations to Teach Computer Science from Beginning Courses to Advanced Courses

Theory of Computation Chapter 2: Turing Machines

On Winning Conditions of High Borel Complexity in Pushdown Games

7.1 Our Current Model

Fast nondeterministic recognition of context-free languages using two queues

Informatique Fondamentale IMA S8

Overview of E0222: Automata and Computability

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP

Scanner. tokens scanner parser IR. source code. errors

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

6.080/6.089 GITCS Feb 12, Lecture 3

Computability Theory

Computationally Complete Spiking Neural P Systems Without Delay: Two Types of Neurons Are Enough

Formal Deænition of Finite Automaton. 1. Finite set of states, typically Q. 2. Alphabet of input symbols, typically æ.

Two Way F finite Automata and Three Ways to Solve Them

CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing

Prime Numbers. Difficulties in Factoring a Number: from the Perspective of Computation. Computation Theory. Turing Machine 電 腦 安 全

Theoretical Computer Science (Bridging Course) Complexity

Data Structures Using C++ 2E. Chapter 5 Linked Lists

CS 301 Course Information

CAs and Turing Machines. The Basis for Universal Computation

C H A P T E R Regular Expressions regular expression

Row Echelon Form and Reduced Row Echelon Form

SOLUTION Trial Test Grammar & Parsing Deficiency Course for the Master in Software Technology Programme Utrecht University

Introduction to NP-Completeness Written and copyright c by Jie Wang 1

4.3 TABLE 3 TABLE five

Reading 13 : Finite State Automata and Regular Expressions

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

Notes on Complexity Theory Last updated: August, Lecture 1

Modeling of Graph and Automaton in Database

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

THEORY of COMPUTATION

Computer Architecture Syllabus of Qualifying Examination

CS5236 Advanced Automata Theory

Automata, languages, and grammars

Lecture 2: Universality

UNIVERSIDADE DE SÃO PAULO


Properties of Stabilizing Computations

Programmable Logic Controllers

Two-dimensional Languages

6.3 Conditional Probability and Independence

Intrusion Detection via Static Analysis

PES Institute of Technology-BSC QUESTION BANK

Computational Models Lecture 8, Spring 2009

1 Definition of a Turing machine

FINITE STATE AND TURING MACHINES

NFAs with Tagged Transitions, their Conversion to Deterministic Automata and Application to Regular Expressions

Lecture 1: Systems of Linear Equations

Formal Grammars and Languages

Hint 1. Answer (b) first. Make the set as simple as possible and try to generalize the phenomena it exhibits. [Caution: the next hint is an answer to

2) Write in detail the issues in the design of code generator.

Tutorial 8. NP-Complete Problems

Welcome to... Problem Analysis and Complexity Theory , 3 VU

Arithmetic Coding: Introduction

Complexity Theory. Jörg Kreiker. Summer term Chair for Theoretical Computer Science Prof. Esparza TU München

ASSIGNMENT ONE SOLUTIONS MATH 4805 / COMP 4805 / MATH 5605

3.3 Addition and Subtraction of Rational Numbers

Push-down Automata and Context-free Grammars

Transcription:

Decision, Computation and Language Push Down Automata Dr. Muhammad S Khan (mskhan@liv.ac.uk) Ashton Building, Room G22 http://www.csc.liv.ac.uk/~khan/comp218

CSG 2

Transitions 3

Stack Operations for PDA Push Pop Replace No-Change 4

For example: 5

Example: Palindromes 6

An Accepting Computation 7

Example of a Deterministic PDA 8

Another deterministic Example 9

PDA - the automata for CFLs What is: FA to Regular Language, PDA = [ -NFA + a stack ] Why a stack? PDA is to CFL Input string -NFA Accept/reject A stack filled with stack symbols 10

Example Let L wwr = ww r w is in 0+1 CFG for L wwr : S 0S0 1S1 PDA for L wwr : =( V, A, M, δ, q 0, $, q 2 ) = q 0, q 0, q 0, 0,1, 0,1, $, δ, q 0, $, q 2 11

PDA for L wwr 1. δ(q 0,0, $)={(q 0,0)} 2. δ(q 0,1, $)={(q 0,1)} First symbol push on stack 3. δ(q 0,0, 0)={(q 0,0)} 4. δ(q 0,0, 1)={(q 0,0)} 5. δ(q 0,1, 0)={(q 0,1)} 6. δ(q 0,1, 1)={(q 0,1)} 7. δ(q 0,, 0)={(q 1, 0)} 8. δ(q 0,, 1)={(q 1, 1)} 9. δ(q 0,, Z 0 )={(q 1, $)} Grow the stack by pushing new symbols on top of old (w-part) Switch to popping mode (boundary between w and w R ) 10. δ(q 1,0, 0)={(q 1, )} 11. δ(q 1,1, 1)={(q 1, )} 12. δ(q 1,, $)={(q 2, $)} Shrink the stack by popping matching symbols (w R -part) Enter acceptance state 12

PDA as a state diagram δ q i, a, X = q j, Y Current state Next input symbol Current stack top Stack Top Replacement (with string Y) q 0 a, X/Y q j Next state 13

PDA for L wwr : Transition Diagram Grow stack, $/$ 0, $/0 1, $/1 0, 0/0 0, 1/0 1, 0/1 1, 1/1 Pop stack for matching symbols 0, 0/ 1, 1/, $/$, 0/0 q 0, 1/1 q 1, $/$ q 2 = {0, 1} M= {$, 0, 1} Q = {q 0,q 1,q 2 } Switch to popping mode Go to acceptance 14

Example 2: language of balanced paranthesis Grow stack (, $ / ( (, ( / ( ), ( / Pop stack for matching symbols ), ( / = { (, ) } M = {$, ( } Q = {q 0,q 1,q 2 }, $ / $, $ / $ q 0 q 1 q 2, $ / $ (, ( / ( (, $ / ( Go to acceptance (by final state) when you see the stack bottom symbol Switch to popping mode To allow adjacent blocks of nested parenthesis 15

Language of balanced parenthesis (another design) (,$ / ( $ (,( / ( ( ), ( / = { (, ) } M = {$, ( } Q = {q 0,q 1 } start,$/ $ q 0,$/ $ q 1 16

Acceptance by There are two types of PDAs that one can design: PDAs that accept by final state: For a PDA P, the language accepted by P, denoted by L(P) by final state, is: {w (q 0,w,$) ---* (q,, A) }, s.t., q F Checklist: - input exhausted? - in a final state? PDAs that accept by empty stack: For a PDA P, the language accepted by P, denoted by N(P) by empty stack, is: {w (q 0,w,$) ---* (q,, ) }, for any q Q. Checklist: - input exhausted? - is the stack empty? 17

Example: L of balanced parenthesis PDA that accepts by final state An equivalent PDA that accepts by empty stack (,$ / ( $ (,( / ( ( ), ( / P F : P N : (,Z 0 / ( Z 0 (, ( / ( ( ), ( /,Z 0 / start,$/ $ q 0,$/ $ q 1 start,$/ $ q 0 How will these two PDAs work on the input: ( ( ( ) ) ( ) ) ( ) 18

PDAs accepting by final state and empty stack are equivalent P F <= PDA accepting by final state P F = (Q F,, M, δ F,q 0,$,F) P N <= PDA accepting by empty stack P N = (Q N,, M, δ N,q 0,$) Theorem: (P N ==> P F ) For every P N, there exists a P F s.t. L(P F )=L(P N ) (P F ==> P N ) For every P F, there exists a P N s.t. L(P F )=L(P N ) 19

CFGs = PDAs CFLs PDA by final state PDA by empty stack? CFG 20

INPUT OUTPUT Converting CFG to PDA This is same as: implementing a CFG using a PDA Main idea: The PDA simulates the leftmost derivation on a given w, and upon consuming it fully it either arrives at acceptance (by empty stack) or non-acceptance. w PDA (acceptance by empty stack) accept reject implements CFG 21

Converting a CFG into a PDA This is same as: implementing a CFG using a PDA Main idea: The PDA simulates the leftmost derivation on a given w, and upon consuming it fully it either arrives at acceptance (by empty stack) or nonacceptance. Steps: 1. Push the right hand side of the production onto the stack, with leftmost symbol at the stack top 2. If stack top is the leftmost variable, then replace it by all its productions (each possible substitution will represent a distinct path taken by the non-deterministic PDA) 3. If stack top has a terminal symbol, and if it matches with the next symbol in the input string, then pop it State is inconsequential (only one state is needed) 22

Formal construction of PDA from CFG Before: A Given: G= (V,T,P,S) Output: P N = ({q}, T, V U T, δ, q, S) δ: Before: a For all A V, add the following transition(s) in the PDA: δ(q,,a) = { (q, ) A P} For all a T, add the following transition(s) in the PDA: δ(q,a,a)= { (q, ) } Note: Initial stack symbol (S) same as the start variable in the grammar After: After: a a pop 23

Example: CFG to PDA G = ( {S,A}, {0,1}, P, S) P= S AS A 0A1 A1 01 PDA = ({q}, {0,1}, {0,1,A,S}, δ, q, S) δ: δ(q,, S) = { (q, AS), (q, )} δ(q,, A) = { (q,0a1), (q,a1), (q,01) } δ(q, 0, 0) = { (q, ) } δ(q, 1, 1) = { (q, ) },S / S 1,1 / 0,0 /,A / 01,A / A1,A / 0A1,S /,S / AS q How will this new PDA work? Lets simulate string 0011 24

Simulating string 0011 on the new PDA PDA (δ): δ(q,, S) = { (q, AS), (q, )} δ(q,, A) = { (q,0a1), (q,a1), (q,01) } δ(q, 0, 0) = { (q, ) } δ(q, 1, 1) = { (q, ) } Stack moves (shows only the successful path):,s / S 1,1 / 0,0 /,A / 01,A / A1,A / 0A1,S /,S / AS q Leftmost deriv.: S => AS => 0A1S => 0011S => 0011 S A S 0 A 1 S A 1 S 0 1 1 S 1 1 S 1 S S Accept by empty stack 0 0 1 1 S AS 0A1S 0011S 0011 25

Converting a PDA into a CFG Main idea: Reverse engineer the productions from transitions If δ(q,a,z) => (p, Y 1 Y 2 Y 3 Y k ): 1. State is changed from q to p; 2. Terminal a is consumed; 3. Stack top symbol Z is popped and replaced with a sequence of k variables. Action: Create a grammar variable called [qzp] which includes the following production: [qzp] => a[py 1 q 1 ] [q 1 Y 2 q 2 ] [q 2 Y 3 q 3 ] [q k-1 Y k q k ] Proof discussion (in the book) 26

Two ways to build a CFG Build a PDA Construct CFG from PDA (indirect) Derive CFG directly (direct) Similarly Two ways to build a PDA Derive a CFG Construct PDA from CFG (indirect) Design a PDA directly (direct) 27

This PDA for L wwr is non-deterministic Grow stack 0, $/0 1, $/1 0, 0/0 0, 1/0 1, 0/1 1, 1/1 Pop stack for matching symbols 0, 0/ 1, 1/ Why does it have to be nondeterministic? q 0, $/$ q 1, $/$ q 2, 0/0, 1/1 Accepts by final state Switch to popping mode To remove guessing, impose the user to insert c in the middle 28

Summary PDAs for CFLs and CFGs Non-deterministic Deterministic PDA acceptance types 1. By final state 2. By empty stack PDA Transition diagram Equivalence of CFG and PDA CFG PDA construction PDA CFG construction 29