(From Linz 7.1 p. 183 Exercise 4.)

Similar documents
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

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

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

Pushdown Automata. International PhD School in Formal Languages and Applications Rovira i Virgili University Tarragona, Spain

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

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

Scanner. tokens scanner parser IR. source code. errors

Automata and Formal Languages

Intrusion Detection via Static Analysis

Regular Languages and Finite State Machines

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

Automata and Computability. Solutions to Exercises

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions

Chapter 7 Uncomputability

Lempel-Ziv Coding Adaptive Dictionary Compression Algorithm

Fundamentele Informatica II

MACM 101 Discrete Mathematics I

Turing Machines: An Introduction

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

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

Data Structures and Algorithms V Otávio Braga

Compiler I: Syntax Analysis Human Thought

Software Model Checking: Theory and Practice

CAs and Turing Machines. The Basis for Universal Computation

Introduction to Finite Automata

C H A P T E R Regular Expressions regular expression

On Winning Conditions of High Borel Complexity in Pushdown Games

The Halting Problem is Undecidable

Compiler Construction

T Reactive Systems: Introduction and Finite State Automata

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

Push-down Automata and Context-free Grammars

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

7.1 Our Current Model

3515ICT Theory of Computation Turing Machines

Fast nondeterministic recognition of context-free languages using two queues

Omega Automata: Minimization and Learning 1

Algorithms and Data Structures

Regular Expressions and Automata using Haskell

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!

SIF Validation Tool. Wages Protection System Qatar Central Bank& Ministry of Labour And Social Affairs. End User Guide

Stack Allocation. Run-Time Data Structures. Static Structures

Appendix C: Keyboard Scan Codes

Informatique Fondamentale IMA S8

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

Course Manual Automata & Complexity 2015

Administrative Services of Kansas

ASSIGNMENT ONE SOLUTIONS MATH 4805 / COMP 4805 / MATH 5605

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

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

Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP

THEORY of COMPUTATION

How to Make the Most of Excel Spreadsheets

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

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

Regular Languages and Finite Automata

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

Board Notes on Virtual Memory

Automata on Infinite Words and Trees

Overview of E0222: Automata and Computability

Reading 13 : Finite State Automata and Regular Expressions

Windows Performance Monitor Troubleshooting Guide

How to Format a Bibliography or References List in the American University Thesis and Dissertation Template

RULE 1: Additive Identity Property

The Optimum One-Pass Strategy for Juliet

DATA STRUCTURES USING C

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

Levels of Programming Languages. Gerald Penn CSC 324

A laboratory work: A teaching robot arm for mechanics and electronic circuits

Bottom-Up Syntax Analysis LR - metódy

How to Read Music Notation

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

Addressing The problem. When & Where do we encounter Data? The concept of addressing data' in computations. The implications for our machine design(s)

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

BEGINNING ALGEBRA ACKNOWLEDMENTS

NetPortal All your documents, direct to your iphone

Working with Visio Connectors

Table 1 Comparison of DC, Uni-Polar and Bi-polar Stepper Motors

How To Compare A Markov Algorithm To A Turing Machine

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Excel supplement: Chapter 7 Matrix and vector algebra

How to create PDF maps, pdf layer maps and pdf maps with attributes using ArcGIS. Lynne W Fielding, GISP Town of Westwood

Finite Automata and Regular Languages

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

Monitoring and Analyzing Switch Operation

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Konica Minolta s Optimised Print Services (OPS)


GCM for Android Setup Guide

Assignment Kits. Summary Kit Contents Lecture 1: Kit cover sheet (page 40)

Theory of Computation Chapter 2: Turing Machines

Web Data Extraction: 1 o Semestre 2007/2008

Transcription:

Additional NPDA examples (From Lin 7.1 p. 183 Exercise 4.)

Formal Definition Non-Deterministic Pushdown Automaton NPDA M = ( Q, Σ, Γ, δ, q,, 0 F ) Final Set of states states Input alphabet Stack alphabet Transition function Initial state Stack start symbol 2

Instantaneous Description ( q, u, s) ) Current state Remaining input Current stack contents 3

1. Construct NPDA that accepts the language L = {wcw R : w {a, b}} with Σ = {a, b, c} The idea of machine construction*: We construct M that accepts L. It reads w and after seeing c, it reads w R. We will need three states, for reading w, switching to the new state after reading c, and the final accepting state. tt First for each a or b seen we push an a or b respectively onto the stack and stay in state q0. When we encounter a c, we do not push anything on to the stack, but go to the next state, q1. While being in state q1, if we encounter an a or b, we match it with the a or b respectively on the stack and pop one a for each a or one b for each b seen, so that it matches w R against the contents of the stack and the matching starts after it encounters a c. Finally it accepts if the input is done and there are no more a s or b s on the stack. *This is a variation on the example 7.5 on the p. 181 of Lin book, for the language L = {ww R : w {a, b}}

L = NPDA { { } * } R wcw w a,b a, λ b, λ a b b,b b λ a, a λ c, λ λ λ, q 0 q 1 q 2 5

Instantaneous description of the automaton accepting L = {wcw R : w {a, b}} Σ = {a, b, c} Here is the machine definition. M = ({q0, q1, q2}, Σ, {a, b, }, δ, q0,, {q2}) Instantaneous description (ID): (current state, remaining input, stack) δ(q0, a, a) = {(q0, aa)}, δ(q0, b, a) = {(q0, ba)}, δ(q0, a, b) = {(q0, ab)}, δ(q0 0, b, b) = {(q0, 0 bb)}, δ(q0, a, ) = {(q0, a)}, δ(q0, b, ) = {(q0, b)}, δ(q0, c, ) ) = {(q1, )}, ) δ(q0, c, a) = {(q1, a)}, δ(q0, c, b) = {(q1, b)}, δ(q1, a, a) = {(q1, λ)}, δ(q1, b, b) = {(q1, λ)}, δ(q1, λ, ) = {(q2, )}. a, λ a a, a aa b, λ b a, b ab b,b λ b, b bb a,a λ c, λ λ λ, q 0 q 1 q 2

2. Construct NPDA that accepts the language L = {a n b m c n+m : n 0, m 0} with Σ = {a, b, c} The idea of machine construction: We construct M that accepts L. Firstitaccepts it the empty string (n=m=0). Further, for each a seen (if any) it pushes an a onto the stack. Then it pushes an a onto the stack for each b seen (if any). Thus after reading all as and bsin the input, the stack has na (w) + nb (w) as on it. It then pops one a for each c seen guaranteeing that na (w) + nb (w) = nc(w) and they are in the right order. Finally it accepts if the input is done and there are no more as on the stack. M = ({q0, q1, q2, q3, q4}, Σ, {a, }, δ, q0,, {q0, q4 })

NPDA L = { a n b m b n + m : n 0, m 0} a, λ a b, λ a c, a λ λ, λ λ λ, λ λ λ,λ q 0 q 1 q 3 q 2 8

Instantaneous description of the automaton accepting L = {a n b m c n+m : n 0, m 0} Σ = {a, b, c} Machine definition: M = ({q0, q1, q2, q3, q4}, Σ, {a, }, δ, q0,, {q0, q4 }) Instantaneous description (ID): (current state, remaining input, stack) δ(q0, λ, ) = {(q1, )}, δ(q1, a, ) = {(q1, a)}, δ(q1, a, a) = {(q1, aa)}, δ(q1, λ, a) = {(q2, a)}, δ(q1, λ, ) = {(q2, )}, δ(q2, 2 b, ) ) = {(q2, 2 a)}, δ(q2, b, a) = {(q2, aa)}, δ(q2, c, a) = {(q3, λ)}, δ(q3, c, a) ) = {(q3, λ)}, ) δ(q3, λ, ) = {(q4, λ)}. a, λ a b, λ a c, a λ λ, λ λ λ, λ λ λ, q 0 q 1 q 2 q 3 q 2

3. Construct NPDA that accepts the language L = {a n b m : n m 3n, n 0} with Σ = {a, b, c}. The idea of machine construction: We will construct M that accepts L. It accepts empty string. The state q0 keeps track of the n as encountered in the first part of the string and provides a chance for state q1 to match the bs to anywhere between n and 3n. It proceeds to state q2 from state q1 if the number of bs encountered is between n and 3n.

NPDA L { n m a b : n m 3n, 0} = n a, λ a, λ a aa b,a λ a, λ aaa b,a λ λ, q 0 q 1 q 2 11

Instantaneous description of the automaton accepting L = {a n b m : n m 3n, n 0} with Σ = {a, b, c}. Machine definition: M = ({q0, q1, q2 }, Σ, {a, b, }, δ, q0,, {q2 }) Instantaneousdescription (ID): (currentstate state, remaininginput input, stack) δ(q0, a, ) = {(q0, a)}, δ(q0, a, ) = {(q0, aa)}, δ(q0, a, ) = {(q0, aaa)}, δ(q0, a, a) = {(q0, aa)}, δ(q0, a, a) = {(q0, aaa)}, δ(q0, a, a) = {(q0, aaaa)}, δ(q0, b, a) = {(q1, λ)}, δ(q1, b, a) = {(q1, λ)}, δ(q1, λ, ) = {(q2, )} a, λ a a, λ aa a, λ aaa a,a a a,a aa a,a aaa b,a λ b,a λ λ, q 0 q 1 q 2

4. Construct NPDA that accepts the language L = {w : n a (w) = n b (w) + 1} with Σ = {a, b, c}. L { w : n ( w ) = n ( w ) +, w { a,b} * } = 1 a b The idea of machine construction: Machine M accepts L and it starts with one extra a on the stack and then uses the machine given in Example 7.4 in the Lin book to tell if the number of as and bsare the same. If they are and we started with one more a on the stack then the condition of L is met. Additionally, if it sees a c, it just reads it and does not modify the stack.

We start with a simpler machine that accepts the language: L w a,b : n ( w n w * = { { } ) = ( )} a( b Here we use Lin solution. He uses 0 to count a s which will be popped when b s bsare found. Assometimes sometimes in some prefix there may be more b s bs than a s we will find no 0 on the stack. In that case 1 is used that later on can be matched with a s.

NPDA for a simpler machine L * = { w { a,b} : n ( w ) = n ( w )} a b a, a,0 0 00 b, 1 b, 0 λ b, 1 11 a, 1 λ q 0 λ, q f

NPDA L { { } = } * w a,b : n ( w ) n ( w )+1 = ) a b λ,λ, q 0 a, a,0 a 0 00 b, 1 b, 0 λ b, 1 11 a, 1 λ λ, q 1 q2

Instantaneous description of the automaton accepting L = {w : n a (w) = n b (w) + 1} with Σ = {a, b, c}. M = ({q0, q1, q2}, Σ, {a, b, }, δ, q0,, {q2}) Instantaneous description (ID): (current state, remaining input, stack) δ(q0,, λ,, ) ) = {(q1, a)}, δ(q1, a, ) = {(q1, a)}, δ(q1, a, a) = {(q1, aa)}, b, 1 δ(q1, a, b) = {(q1, λ)}, b, 0 λ b, 1 11 a, 0 a, 1 λ δ(q1, b, ) ) = {(q1, b)}, a,0 00 δ(q1, b, a) = {(q1, λ)}, δ(q1, b, b) = {(q1, bb)}, λ,λ a λ, δ(q1, λ, ) = {(q2, λ)}, q 0 q 1 q2 δ(q1, c, ) = {(q1, c)}, δ(q1, c, a) = {(qa, a)}, δ(q1, c, b) = {(q1, b)}. In this solution a and b are used as counters instead of 0 and 1.