Nondeterministic Finite Automata

Similar documents
Deterministic Finite Automata

Nondeterministic Finite Automata

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

CSC236 Week 11. Larry Zhang

Chapter Five: Nondeterministic Finite Automata

Nondeterministic Finite Automata. Nondeterminism Subset Construction

September 7, Formal Definition of a Nondeterministic Finite Automaton

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Inf2A: Converting from NFAs to DFAs and Closure Properties

Lecture 1: Finite State Automaton

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Formal Language and Automata Theory (CS21004)

Decision, Computation and Language

Java II Finite Automata I

Equivalence of DFAs and NFAs

Nondeterministic Finite Automata

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Non-deterministic Finite Automata (NFAs)

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

Theory of Computation

Intro to Theory of Computation

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

Nondeterministic Finite Automata and Regular Expressions

NFA and regex. the Boolean algebra of languages. regular expressions. Informatics 1 School of Informatics, University of Edinburgh

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Nondeterminism and Epsilon Transitions

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

Theory of Computation (I) Yijia Chen Fudan University

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Automata and Languages

Finite Automata. Finite Automata

CS21 Decidability and Tractability

CS 154, Lecture 3: DFA NFA, Regular Expressions

Lecture 4 Nondeterministic Finite Accepters

Lecture 3: Nondeterministic Finite Automata

Nondeterminism. September 7, Nondeterminism

Deterministic Finite Automata

Fooling Sets and. Lecture 5

Finite Automata (contd)

CMSC 330: Organization of Programming Languages

CS 208: Automata Theory and Logic

Classes and conversions

C2.1 Regular Grammars

Algorithms for NLP

C2.1 Regular Grammars

Finite Automata. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

INF Introduction and Regular Languages. Daniel Lupp. 18th January University of Oslo. Department of Informatics. Universitetet i Oslo

Finite Automata. Seungjin Choi

Chapter Two: Finite Automata

Regular Expressions and Language Properties

Uses of finite automata

CS 121, Section 2. Week of September 16, 2013

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

CS21 Decidability and Tractability

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

Nondeterministic Finite Automata

Theory of Computation (II) Yijia Chen Fudan University

Deterministic Finite Automaton (DFA)

Computational Models Lecture 2 1

CS 322 D: Formal languages and automata theory

Finite Universes. L is a fixed-length language if it has length n for some

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Chapter 2: Finite Automata

CSE 311 Lecture 23: Finite State Machines. Emina Torlak and Kevin Zatloukal

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

Nondeterministic finite automata

Lecture 2: Regular Expression

Extended transition function of a DFA

Finite Automata. Mahesh Viswanathan

(Refer Slide Time: 0:21)

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

Theory of Computation

Finite Automata. Warren McCulloch ( ) and Walter Pitts ( )

Deterministic (DFA) There is a fixed number of states and we can only be in one state at a time

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

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

Computer Sciences Department

Formal Models in NLP

Course 4 Finite Automata/Finite State Machines

CS243, Logic and Computation Nondeterministic finite automata

Constructions on Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Regular Language Equivalence and DFA Minimization. Equivalence of Two Regular Languages DFA Minimization

Regular Expressions. Definitions Equivalence to Finite Automata

Chapter 2. Finite Automata. (part A) (2015/10/20) Hokkaido, Japan

UNIT-III REGULAR LANGUAGES

Chapter 6: NFA Applications

Constructions on Finite Automata

Homomorphisms and Efficient State Minimization

Automata: a short introduction

Transcription:

Nondeterministic Finite Automata COMP2600 Formal Methods for Software Engineering Katya Lebedeva Australian National University Semester 2, 206 Slides by Katya Lebedeva. COMP 2600 Nondeterministic Finite Automata

For a Deterministic Finite Automaton δ(s,a) is a unique state for all s S and for all a Σ. For a Nondeterministic Finite Automaton the transition function δ does not define a unique state, but defines a set of states. It may be the empty set be a singleton set (i.e. set with just one element) contain more than one element An NFA has the ability to be in several states at once. COMP 2600 Nondeterministic Finite Automata 2

Nondeterministic Finite State Automata s 0 0, start s s 2 0, COMP 2600 Nondeterministic Finite Automata 3

State diagram for 0 s 0 0, start s s 2 0, s 0 0 s 0 s s 2 stuck s s 2 accept! s 0 s s 0 s 0 COMP 2600 Nondeterministic Finite Automata 4

Informally, an NFA accepts a string if there exists at least one path in the state diagram that starts in the start state does not get stuck before the entire string has been read ends in the accepting state The fact that some choices of states using the input symbols of the string lead to a nonaccepting state, or do not lead to any state at all does not prevent the string from being accepted by the NFA. The NFA from the previous slide accepts strings that have as the second symbol from the end of the string. COMP 2600 Nondeterministic Finite Automata 5

A Nondeterministic Finite State Automaton (DFA) is a 5-tuple where (Σ,S,s 0,F,δ). Σ is a finite set of input symbols (the alphabet) 2. S is a finite state of states 3. s 0 is the start (or initial) state: s 0 S 4. F is a set of final (or accepting) states: F S 5. δ is a transition function such that δ : S Σ 2 S, i.e. δ takes a state in S and an input symbol in Σ as arguments and returns a subset of S. Notice that the only difference between DFA and NFA is the type of value that δ returns! COMP 2600 Nondeterministic Finite Automata 6

s 0 0, start s s 2 0, The NFA can be specified formally as ({0,},{s 0,s,s 2,},s 0,{s 2 },δ) where the transition function δ is given by the transition table 0 s 0 {s 0 } {s 0,s } s {s 2 } {s 2 } s 2 /0 /0 COMP 2600 Nondeterministic Finite Automata 7

Extended Transition Function s 0 0 s 0 s s 2 stuck s s 2 accept! s 0 s s 0 s 0 COMP 2600 Nondeterministic Finite Automata 8

The extended transition function of a NFA is the function δ : S Σ 2 S defined as follows: for all s S, for all a Σ, for all α Σ δ (s,ε) = {s} δ (s,αa) = p δ (s,α) δ(p, a) I.e. if δ (s,α) = {p, p 2,... p k } then δ (s,αa) = δ(p,a) δ(p 2,a) δ(p k,a) Informally: we first compute δ (s,α) and then follow any transition that is labeled with a from any of these states. COMP 2600 Nondeterministic Finite Automata 9

Input: 0 s 0 0, start s s 2 0,. δ (s 0,ε) = {s 0 } the basis rule! 2. δ (s 0,0) = δ(s 0,0) = {s 0 } 3. δ (s 0,0) = δ(s 0,) = {s 0,s } 4. δ (s 0,0) = δ(s 0,) δ(s,) = {s 0,s } {s 2 } = {s 0,s,s 2 } 5. δ (s 0,0) = δ(s 0,) δ(s,) δ(s 2,) = {s 0,s } {s 2 } /0 = {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 0

Different views of non-determinism The NFA always makes the right choice (of a successor state according to δ) to insure reaching the final state (if possible at all) The NFA simultaneously explores multiple paths At each nondeterministic choice point the NFA spawns off mutiple copies of itself Note: The various path/computations evolve completely independently from each other (this is different from parallel computations which may synchronise at a certain point) COMP 2600 Nondeterministic Finite Automata

Language accepted by an NFA If A N = (Σ,S,s 0,F,δ) is an NFA, then L(A N ) = {w δ (s 0,w) F /0} That is, L(A N ) is the set of strings w in Σ such that δ (s 0,w) contains at least one accepting state. COMP 2600 Nondeterministic Finite Automata 2

Equivalence of DFAs and NFAs It may be easier to construct an NFA than a DFA for a given language. However, every language that can be described by some NFA can also be described by some DFA (and vice versa)!!! If an NFA has n states, the equivalent DFA will have at most 2 n states. In most cases, the DFA has about as many states as the equivalent NFA, but more transitions. COMP 2600 Nondeterministic Finite Automata 3

Proof idea of the equivalence of DFAs and NFAs We have to prove: L(DFA) L(NFA) Whenever we have a DFA A D, we can construct a NFA A N such that L(A D ) = L(A N ). This is easy to show! Why? L(NFA) L(DFA) For every NFA A N there is a DFA A D such that L(A D ) = L(A N ). The proof of this direction involves Subset Construction. COMP 2600 Nondeterministic Finite Automata 4

Subset Construction Intuition The NFA A N can perform more than one computation on a given input string. Construct a DFA A D that runs all these different computations simultaneously: the state that A D is in after having read an initial part of the input string corresponds exactly to the set of all states that A N can reach after having read the same part of the input string COMP 2600 Nondeterministic Finite Automata 5

Idea for the construction of A D from A N A subset of A N s states corresponds to a state in A D : s 0 0 s 0 s s 2 stuck s s 2 accept! s 0 s s 0 s 0 0 {s 0 } {s 0 } {s 0,s } {s 0,s 2 } {s 0,s } COMP 2600 Nondeterministic Finite Automata 6

s 0 0, start s s 2 0, The set of states of the DFA we have to construct is associated with the set of all subsets of the states of the given NFA. /0 {s 0 } {s } {s 2 } {s 0,s } {s 0,s 2 } {s,s 2 } {s 0,s,s 2 } 0 COMP 2600 Nondeterministic Finite Automata 7

s 0 0, start s s 2 0, When we are in no state in the initial NFA, regardless what the input symbol is, we continue to be in no state. 0 /0 /0 /0 {s 0 } {s } {s 2 } {s 0,s } {s 0,s 2 } {s,s 2 } {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 8

s 0 0, start s s 2 0, When we in s 0 in the NFA and the input is 0, the transition function of the NFA takes us to {s 0 }. When we in s 0 in the NFA and the input is, the transition function of the NFA takes us to {s 0,s }. 0 /0 /0 /0 {s 0 } {s 0 } {s 0,s } {s } {s 2 } {s 0,s } {s 0,s 2 } {s,s 2 } {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 9

s 0 0, start s s 2 0, When we in s in the NFA and the input is 0, the transition function of the NFA takes us to {s 2 }. When we in s in the NFA and the input is, the transition function of the NFA takes us to {s 2 }. 0 /0 /0 /0 {s 0 } {s 0 } {s 0,s } {s } {s 2 } {s 2 } {s 2 } {s 0,s } {s 0,s 2 } {s,s 2 } {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 20

s 0 0, start s s 2 0, When we in s 2 in the NFA and the input is 0, the transition function of the NFA takes us to /0 (i.e. it takes us to none of the states of the NFA). When we in s in the NFA and the input is, the transition function of the NFA takes us to /0. 0 /0 /0 /0 {s 0 } {s 0 } {s 0,s } {s } {s 2 } {s 2 } {s 2 } /0 /0 {s 0,s } {s 0,s 2 } {s,s 2 } {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 2

s 0 0, start s s 2 0, Mark the start state. Mark the accepting states. Accepting states are those in which appears at least one accepting state of our NFA. 0 /0 /0 /0 {s 0 } {s 0 } {s 0,s } {s } {s 2 } {s 2 } {s 2 } /0 /0 {s 0,s } {s 0,s 2 } {s 0,s,s 2 } {s 0,s 2 } {s 0 } {s 0,s } {s,s 2 } {s 2 } {s 2 } {s 0,s,s 2 } {s 0,s 2 } {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 22

s 0 0, start s s 2 0, This transition table determines the transition function of our DFA!!! It belongs to a Deterministic Automaton! Each of these sets is a state of our DFA! 0 /0 /0 /0 {s 0 } {s 0 } {s 0,s } {s } {s 2 } {s 2 } {s 2 } /0 /0 {s 0,s } {s 0,s 2 } {s 0,s,s 2 } {s 0,s 2 } {s 0 } {s 0,s } {s,s 2 } {s 2 } {s 2 } {s 0,s,s 2 } {s 0,s 2 } {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 23

s 0 0, start s s 2 0, 0 /0 /0 /0 {s 0 } {s 0 } {s 0,s } {s } {s 2 } {s 2 } {s 2 } /0 /0 {s 0,s } {s 0,s 2 } {s 0,s,s 2 } {s 0,s 2 } {s 0 } {s 0,s } {s,s 2 } {s 2 } {s 2 } {s 0,s,s 2 } {s 0,s 2 } {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 24

s 0 0, start s s 2 0 A A A B B E C D D *D A A E F H *F B E *G D D *H F H 0, 0 A /0 A /0 A /0 B {s 0 } B {s 0 } E {s 0,s } C {s } D {s 2 } D {s 2 } *D {s 2 } A /0 A /0 E {s 0,s } F {s 0,s 2 } H {s 0,s,s 2 } *F {s 0,s 2 } B {s 0 } E {s 0,s } *G {s,s 2 } D {s 2 } D {s 2 } *H {s 0,s,s 2 } F {s 0,s 2 } H {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 25

s 0 0, start s s 2 0 0, A A A B B E C D D *D A A E F H *F B E *G D D *H F H COMP 2600 Nondeterministic Finite Automata 26

COMP 2600 Nondeterministic Finite Automata 27

0 0 A A A B B E 0 start B E F 0 0 C D D H *D A A E F H *F B E *G D D C 0, D 0, A 0, *H F H 0, G COMP 2600 Nondeterministic Finite Automata 28

COMP 2600 Nondeterministic Finite Automata 29

0 0 /0 /0 /0 {s 0 } {s 0 } {s 0,s } {s } {s 2 } {s 2 } {s 2 } /0 /0 {s 0,s } {s 0,s 2 } {s 0,s,s 2 } {s 0,s 2 } {s 0 } {s 0,s } {s,s 2 } {s 2 } {s 2 } {s 0,s,s 2 } {s 0,s 2 } {s 0,s,s 2 } start {s 0 } {s 0,s } {s 0,s } 0 0, {s 0,s,s 2 } {s } {s 2 } /0 0, 0 0 0, 0, {s,s 2 } COMP 2600 Nondeterministic Finite Automata 30

Formally Given A N = (Σ,S N,s 0,F N,δ N ) define A D = (Σ,S D,{s 0 },F D,δ D ) with S D = 2 S N That is S D is the set of all subsets of S N F D = {Q S N Q F N /0} That is F D is all sets of A N s states that include at least one accepting state of A N For each set Q S N and for each input symbol a in Σ δ D (Q,a) = p Qδ N (p,a) That is δ D (Q,a) is the set of states of A N reachable in A N from one of the states in Q via a COMP 2600 Nondeterministic Finite Automata 3

COMP 2600 Nondeterministic Finite Automata 32

0 start {s 0 } {s 0,s } {s 0,s } 0 0 0 {s 0,s,s 2 } 0, 0, {s } {s 2 } /0 0, 0, {s,s 2 } COMP 2600 Nondeterministic Finite Automata 33

Lazy evaluation on subsets for constructing A D We eliminated states that cannot be accessed from the start state! Can we avoid constructing the inaccessible part of the DFA? Yes! As follows: start {s 0 } {s 0,s } {s 0,s } 0 0 {s 0,s,s 2 } 0 0 Basis: The singleton set consisting only of the start state of A N is accessible. Induction: Suppose we determined that the set Q of states is accessible. Then for each input symbol a, compute the set of states δ D (Q,a). These sets of states will also be accessible. COMP 2600 Nondeterministic Finite Automata 34

Comment on the comment during the lecture whether it is δ D or δ N. The point is that we are constructing δ D via δ N. Particularly, for each a Σ, we compute δ D (Q,a) as δ N (p,a). p Q COMP 2600 Nondeterministic Finite Automata 35

s 0 0, start s s 2 0, s 0 is the start state of A N. Therefore, {s 0 } is the start state of A D. Look at the transition diagram of A N. Observe that on 0 there is only one arrow from s 0, and it goes to s 0. Therefore, δ D ({s 0 },0) = {s 0 }. Observe that on there are two arrow from s 0 that go to s 0 and s. Therefore, δ D ({s 0 },) = {s 0,s }. One of the sets we constructed - the set {s 0 } has just been analysed! We only need to analyse {s 0,s } and compute its transitions! COMP 2600 Nondeterministic Finite Automata 36

s 0 0, start s s 2 0, What is δ D ({s 0,s },0)? δ D ({s 0,s },0) = δ N (s 0,0) δ N (s,0) = {s 0 } {s 2 } = {s 0,s 2 } What is δ D ({s 0,s },)? δ D ({s 0,s },) = δ N (s 0,) δ N (s,) = {s 0,s } {s 2 } = {s 0,s,s 2 } COMP 2600 Nondeterministic Finite Automata 37

s 0 0, start s s 2 0, What is δ D ({s 0,s 2 },0)? δ D ({s 0,s 2 },0) = δ N (s 0,0) δ N (s 2,0) = {s 0 } /0 = {s 0 } What is δ D ({s 0,s 2 },)? δ D ({s 0,s 2 },) = δ N (s 0,) δ N (s 2,) = {s 0,s } /0 = {s 0,s } Both sets {s 0 } and {s 0,s } have already be analysed. But we still have set {s 0,s,s 2 } that we accessed on the previous slide and that awaits analysis! COMP 2600 Nondeterministic Finite Automata 38

s 0 0, start s s 2 0, What is δ D ({s 0,s,s 2 },0)? δ D ({s 0,s,s 2 },0) = δ N (s 0,0) δ N (s,0) δ N (s,0) = {s 0 } {s 2 } /0 = {s 0,s 2 } What is δ D ({s 0,s,s 2 },)? δ D ({s 0,s,s 2 },) = δ N (s 0,) δ N (s,) δ N (s 2,) = {s 0,s } {s 2 } /0 = {s 0,s,s 2 } All accessible sets have been analysed! We can draw A D now! COMP 2600 Nondeterministic Finite Automata 39