Nondeterministic Finite Automata

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

Regular Languages and Finite State Machines

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

Finite Automata. Reading: Chapter 2

Automata and Formal Languages

Finite Automata. Reading: Chapter 2

Regular Expressions and Automata using Haskell

Automata on Infinite Words and Trees

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

Reading 13 : Finite State Automata and Regular Expressions

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

C H A P T E R Regular Expressions regular expression

Deterministic Finite Automata

3515ICT Theory of Computation Turing Machines

Compiler Construction

Automata and Computability. Solutions to Exercises

ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear:

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

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

Genetic programming with regular expressions

CS5236 Advanced Automata Theory

Web Data Extraction: 1 o Semestre 2007/2008

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

Introduction to Finite Automata

Scanner. tokens scanner parser IR. source code. errors

Lecture I FINITE AUTOMATA

Finite Automata and Regular Languages

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

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

T Reactive Systems: Introduction and Finite State Automata

6.080/6.089 GITCS Feb 12, Lecture 3

ASSIGNMENT ONE SOLUTIONS MATH 4805 / COMP 4805 / MATH 5605

Regular Languages and Finite Automata

The Halting Problem is Undecidable

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

Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Regular Languages and Finite Automata

Reducing Clocks in Timed Automata while Preserving Bisimulation

CAs and Turing Machines. The Basis for Universal Computation

Boolean Algebra Part 1

Turing Machines: An Introduction

Math Workshop October 2010 Fractions and Repeating Decimals

Functional Dependencies and Finding a Minimal Cover

Overview of E0222: Automata and Computability

Testing LTL Formula Translation into Büchi Automata

Converting Finite Automata to Regular Expressions

Two Way F finite Automata and Three Ways to Solve Them

Math/Stats 425 Introduction to Probability. 1. Uncertainty and the axioms of probability

Mathematics Geometry Unit 1 (SAMPLE)

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

NP-Completeness and Cook s Theorem

Graph Theory Problems and Solutions

6.1 Basic Right Triangle Trigonometry

6.2 Permutations continued

CS 3719 (Theory of Computation and Algorithms) Lecture 4

2.0 Chapter Overview. 2.1 Boolean Algebra

Course Manual Automata & Complexity 2015

INCIDENCE-BETWEENNESS GEOMETRY

CS 103X: Discrete Structures Homework Assignment 3 Solutions

Reliability Guarantees in Automata Based Scheduling for Embedded Control Software

Practice with Proofs

Trigonometric Functions and Triangles

Fundamentele Informatica II

Continued Fractions and the Euclidean Algorithm

The Optimum One-Pass Strategy for Juliet

Introduction to Automata Theory. Reading: Chapter 1

Lesson 18: Looking More Carefully at Parallel Lines

Chapter 3. if 2 a i then location: = i. Page 40

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

Automata, languages, and grammars


I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

1 if 1 x 0 1 if 0 x 1

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Introduction to Turing Machines

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

Omega Automata: Minimization and Learning 1

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

Lecture 2: Regular Languages [Fa 14]

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

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

26 Integers: Multiplication, Division, and Order

12. Parallels. Then there exists a line through P parallel to l.

Properties of Real Numbers

Relational Algebra. Basic Operations Algebra of Bags

Efficient Data Structures for Decision Diagrams

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

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

Lights and Darks of the Star-Free Star

MATH 304 Linear Algebra Lecture 9: Subspaces of vector spaces (continued). Span. Spanning set.

CS 341: Foundations of Computer Science II elearning Section Syllabus, Spring 2015

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification)

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

Section 1.4 Place Value Systems of Numeration in Other Bases

Midterm Practice Problems

Simplifying Algebraic Fractions

Transcription:

Chapter, Part 2 Nondeterministic Finite Automata CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara

Fundamental set operations Let A and B be two languages. In addition to union and intersection, we consider the following set operations: Concatenation of A and B, A B, is {xy x A and y B}, Star of A, A, is {x x 2 x k k 0 and x,..., x k A}. Complement of A, A, is Σ A, i.e., {w w Σ w A}. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 2

Fundamental set operations Let A and B be two languages. In addition to union and intersection, we consider the following set operations: Concatenation of A and B, A B, is {xy x A and y B}, Star of A, A, is {x x 2 x k k 0 and x,..., x k A}. Complement of A, A, is Σ A, i.e., {w w Σ w A}. We will prove that the regular languages are closed under union, intersection, concatenation, star, and complement;, i.e., that if A and B are regular, then A B, A B, A B, A, and A are each regular. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 3

Nondeterministic Finite Automata The nondeterministic finite automaton is a variant of finite automaton with two characteristics: ǫ-transition: state transition can be made without reading a symbol; nondeterminism: zero or more than one possible value may exist for state transition. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 4

An Example Nondeterministic Finite Automaton An NFA that accepts all strings over {0,} that contain a either at the third position from the end or at the second position from the end. 0, q 0,,ε 0, q 2 q 3 q 4 There are two edges labeled coming out of q. There are no edges coming out of q 4. The edge from q 2 is labeled with ǫ, in addition to 0 and. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 5

What the Diagram Says If the node you are in has an outgoing edge labeled ǫ, you may choose to follow it. After receiving a symbol, if the node you are in has multiple outgoing edges labeled with the symbol, you nondeterministically choose one of them and cross it; if there are no choices, stop there. 0, q 0,,ε 0, q 2 q 3 q 4 CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 6

Nondeterministic Finite Automata, Formally A nondeterministic finite automaton is a 5-tuple N = (Q,Σ,δ,q 0,F), whereδ isamappingofq Σ ǫ to2 Q (alternatively, written P(Q)), and Σ ǫ = Σ {ǫ}. For each p Q and each a Σ ǫ, δ(s,a) = R means: upon reading an a the automaton N may transition from state s to any state in R. For ǫ in particular, δ(s,ǫ) = R means: without reading the symbol the automaton N may transition from state s to any state in R. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 7

Acceptance by Nondeterministic Finite Automata N accepts a word w = w w n,w,...,w n Σ if: there exist (p 0,..., p m ),p 0,...,p m Q and y,...,y m Σ ǫ such that w = y y m, p 0 = q 0, p m F, and for every i, i m, p i δ(p i,w i ). CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 8

Transition Function for the Previous Example 0, q 0,,ε 0, q 2 q 3 q 4 state symbol 0 ǫ q {q } {q,q 2 } q 2 {q 3 } {q 3 } { q 3 } q 3 {q 4 } {q 4 } q 4 CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 9

Transition Function for the Previous Example 0, q 0,,ε 0, q 2 q 3 q 4 state symbol 0 ǫ q {q } {q,q 2 } q 2 {q 3 } {q 3 } { q 3 } q 3 {q 4 } {q 4 } q 4 This NFA accepts y = with respect to state sequence (q,q 2,q 3,q 4 ) and decomposition y = ǫ. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 0

Nondeterministic Choices Nondeterministic computation can be thought of as a selfreproducing agent traveling in the state space.. At the start of computation the agent is in the initial state. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara

Nondeterministic Choices Nondeterministic computation can be thought of as a selfreproducing agent traveling in the state space.. At the start of computation the agent is in the initial state. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 2

Nondeterministic Choices 2. Both before and after receiving an input symbol, the agent follows each ǫ-labeled outgoing edge by producing its own clone and sending it along the edge. Thus, the original remains in the current location. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 3

Nondeterministic Choices 2. Both before and after receiving an input symbol, the agent follows each ǫ-labeled outgoing edge by producing its own clone and sending it along the edge. Thus, the original remains in the current location. I'll go to p7. I'll go to p2. I'll go to p5. I'll stay here. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 4

Nondeterministic Choices 3. On receiving an input symbol, say a, (a) If there is only one a-labeled outgoing edge, the agent follows the edge. (b) If there is no a-labeled outgoing edge, the agent evaporates. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 5

Nondeterministic Choices 3. On receiving an input symbol, say a, (a) If there is only one a-labeled outgoing edge, the agent follows the edge. (b) If there is no a-labeled outgoing edge, the agent evaporates. I am gone. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 6

Nondeterministic Choices 3. On receiving an input symbol, say a, (c) If there are k 2 a-labeled outgoing edges, the agent produces k clones, make them cross k of the edges, and cross the remaining one by himself. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 7

Nondeterministic Choices 3. On receiving an input symbol, say a, (c) If there are k 2 a-labeled outgoing edges, the agent produces k clones, make them cross k of the edges, and cross the remaining one by himself. I'll go to p7. I'll go to p2. I'll go to p5. I'll go to p3. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 8

Nondeterministic Choices 4. When two agents collide in a state, they merge themselves into one. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 9

Nondeterministic Choices 4. When two agents collide in a state, they merge themselves into one. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 20

Why Use NFA? For some languages construction is much easier. Below is a DFA that accepts the same language by remembering the last three symbols. 0 0 q 00 0 q 00 0 q 0 q 000 0 0 0 0 q 00 q 0 q 0 q CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 2

Comparison 0 0 q 00 0 q 00 0 q 0 q 000 0 0 0 0 0, q 0,,ε 0, q 2 q 3 q 4 q 00 q 0 q 0 q NFA DFA CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 22

Example An NFA for the language of all strings over {a,b,c} that end with one of ab, bc, and ca. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 23

Example An NFA for the language of all strings over {a,b,c} that end with one of ab, bc, and ca. a,b,c p c p2 b q0 a p3 b p4 c p5 a p6 CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 24

A DFA Version of the Same Language b c b a p a c b b p2 c a q0 a p3 b p4 c c a a b c p5 a c p6 b CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 25

Example 2 An NFA for the language of all strings over {0,} that end with one of 00, 00, and 00. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 26

Example 2 An NFA for the language of all strings over {0,} that end with one of 00, 00, and 00. 0, q 0 0 q,e,e 0 q 2 q 3 q 4 CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 27

Example 3 An NFA for the language of all strings over {a,b,c} for which one of (the number of occurrences of a), (the number of occurrences of b), and (the number of occurrences of c) is a multiple of 3. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 28

Example 3 An NFA for the language of all strings over {a,b,c} for which one of (the number of occurrences of a), (the number of occurrences of b), and (the number of occurrences of c) is a multiple of 3. b,c a a b,c a b,c c,a b b c,a b c,a a,b c c a,b c a,b CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 29

Example 4 An NFA for the language of all strings over {a,b} that contain ababb. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 30

Example 4 An NFA for the language of all strings over {a,b} that contain ababb. a b a a,b b b a,b CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 3

The FA Model Versus NFA Model The NFA simplifies computational design, but the use of nondeterministic selections and ǫ-transitions makes it look very different from FA. Is that really so? CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 32

The FA Model Versus NFA Model The NFA simplifies computational design, but the use of nondeterministic selections and ǫ-transitions makes it look very different from FA. Is that really so? No, the FA model is equivalent to the NFA model. That is, every language accepted by an DFA is accepted by an NFA, vice versa. Obviously, we have: Theorem. Every FA is already an NFA. We will show: Theorem. Every NFA can be converted to an equivalent FA. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 33

Proof The principle is that just before the first symbol is received and after each symbol is read, there will be at most one agent in any state. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 34

Proof The principle is that just before the first symbol is received and after each symbol is read, there will be at most one agent in any state. We will thus consider the set of all states an agent can be in. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 35

Proof (cont d) Let N = (Q,Σ,δ,q 0,F) be an NFA. We will construct a DFA M = (S,Σ,γ,s 0,G). The state set S is P(Q). The initial state s 0 is the set consisting of q 0 and all the states reachable from q 0 by following only ǫ transitions. The final state set G is {A S A F }; i.e., the set of all subsets of Q containing an element of F. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 36

Transition Function The transition function γ is defined as follows: For each A S and for each b Σ, γ(a,b) = p A δ(p,ǫ bǫ ), the collection of all states r that can be reached from a state p in A by following any number of ǫ-arrows, a b-arrow, and then any number of ǫ-arrows. For all w over Σ, w is accepted by N if and only if the new DFA transitions from s 0 to a state in G on input w. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 37

Example An NFA that recognizes the language consisting of all strings over {0,} that contain a at either the third to last position or the second to last position. 0, q 0,,ε 0, q 2 q 3 q 4 CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 38

Conversion to DFA The state set consists of:, {q }, {q 2 }, {q 3 }, {q 4 }, {q,q 2 }, {q,q 3 }, {q,q 4 }, {q 2,q 3 }, {q 2,q 4 }, {q 3,q 4 }, {q,q 2,q 3 }, {q,q 2,q 4 }, {q,q 3,q 4 }, {q 2,q 3,q 4 }, {q,q 2,q 3,q 4 }. F consists of: {q 4 },{q,q 4 },{q 2,q 4 },{q 3,q 4 }, {q,q 2,q 4 },{q,q 3,q 4 },{q 2,q 3,q 4 },{q,q 2,q 3,q 4 }. The initial state is {q }. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 39

Transition State 0 {q } {q } {q,q 2,q 3 } {q,q 2,q 3 } {q,q 3,q 4 } {q,q 2,q 3,q 4 } {q,q 3,q 4 } {q,q 4 } {q,q 2,q 3,q 4 } {q,q 4 } {q } {q,q 2,q 3 } {q,q 2,q 3,q 4 } {q,q 3,q 4 } {q,q 2,q 3,q 4 } The other states are unreachable from the initial state. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 40

234 0 0 23 0 34 0 0 4 CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 4

A Greedy Conversion Algorithm Step For each state p Q and for each symbol a Σ, compute the set R(p,a) of all states that can be reached from state p by: (a) any number of ǫ transitions, (b) one transition labeled by a, and then (c) any number of ǫ transitions. Step 2 Initialize the state collection S as {p 0 }, where p 0 is the set of all states that can be reached from q 0 by following any number of ǫ transitions. Step 3 While S contains a state with no outgoing edges, select an arbitrary member, say r, of S, and do the following: For each symbol a, compute the state r a as q r R(q,a), add r a to S if r a is not already in it, and then draw an arc from r to r a. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 42

Use the previous NFA. Algorithm Execution Example 0, q 0,,ε 0, q 2 q 3 q 4 CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 43

Step state 0 q q q,q 2,q 3 q 2 q 3,q 4 q 3,q 4 q 3 q 4 q 4 q 4 Step 2 Initially S = {{q }}. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 44

Step 3 {q } on 0 changes the state to {q } {q } on changes the state to {q,q 2,q 3 }. New! {q,q 2,q 3 } on 0 changes the state to {q,q 3,q 4 }. New! {q,q 2,q 3 } on changes the state to {q,q 2,q 3,q 4 }. New! {q,q 3,q 4 } on 0 changes the state to {q,q 4 }. New! {q,q 2,q 3 } on changes the state to {q,q 2,q 3,q 4 }. {q,q 2,q 3,q 4 } on 0 changes the state to {q,q 3,q 4 }. {q,q 2,q 3,q 4 } on changes the state to {q,q 2,q 3,q 4 }. {q,q 4 } on 0 changes the state to {q 3}. {q,q 4 } on changes the state to {q,q 2,q 3 }. CSC527, Chapter, Part 2 c 202 Mitsunori Ogihara 45