September 7, Formal Definition of a Nondeterministic Finite Automaton

Similar documents
Theory of Computation (I) Yijia Chen Fudan University

Nondeterminism. September 7, Nondeterminism

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Intro to Theory of Computation

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,

Lecture 3: Nondeterministic Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

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

Chap. 1.2 NonDeterministic Finite Automata (NFA)

CSC236 Week 11. Larry Zhang

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Lecture 1: Finite State Automaton

CS21 Decidability and Tractability

Closure under the Regular Operations

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

CS21 Decidability and Tractability

Finite Automata and Regular languages

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

Non-deterministic Finite Automata (NFAs)

CS243, Logic and Computation Nondeterministic finite automata

Theory of Languages and Automata

Theory of Computation (II) Yijia Chen Fudan University

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

Nondeterministic Finite Automata

Computer Sciences Department

Non-Deterministic Finite Automata

Formal Definition of Computation. August 28, 2013

2017/08/29 Chapter 1.2 in Sipser Ø Announcement:

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Chapter Five: Nondeterministic Finite Automata

Examples of Regular Expressions. Finite Automata vs. Regular Expressions. Example of Using flex. Application

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

Classes and conversions

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

Theory of Computation (IX) Yijia Chen Fudan University

CS 455/555: Finite automata

Decision, Computation and Language

Nondeterministic Finite Automata

Nondeterministic Finite Automata

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

Nondeterministic Finite Automata

Inf2A: Converting from NFAs to DFAs and Closure Properties

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

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

CPS 220 Theory of Computation REGULAR LANGUAGES

Equivalence of DFAs and NFAs

Introduction to Languages and Computation

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

Theory of Computation

Nondeterminism and Epsilon Transitions

Chapter 6: NFA Applications

CSE 105 Homework 3 Due: Monday October 23, Instructions. should be on each page of the submission.

Lecture 4 Nondeterministic Finite Accepters

Context-Free Languages

CSC173 Workshop: 13 Sept. Notes

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

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

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

Automata: a short introduction

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

C2.1 Regular Grammars

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

acs-04: Regular Languages Regular Languages Andreas Karwath & Malte Helmert Informatik Theorie II (A) WS2009/10

C2.1 Regular Grammars

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 35

Finite Automata. Finite Automata

CSE 105 Theory of Computation Professor Jeanne Ferrante

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Nondeterministic finite automata

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Computability Theory

Computational Models Lecture 2 1

Computational Models Lecture 2 1

Chapter Two: Finite Automata

Extended transition function of a DFA

CPSC 421: Tutorial #1

CS 154, Lecture 3: DFA NFA, Regular Expressions

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

CSE 135: Introduction to Theory of Computation Equivalence of DFA and NFA

Theory of Computation (IV) Yijia Chen Fudan University

Deterministic Finite Automaton (DFA)

Incorrect reasoning about RL. Equivalence of NFA, DFA. Epsilon Closure. Proving equivalence. One direction is easy:

CS 208: Automata Theory and Logic

Takeaway Notes: Finite State Automata

Finite Automata. Seungjin Choi

Constructions on Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

Tasks of lexer. CISC 5920: Compiler Construction Chapter 2 Lexical Analysis. Tokens and lexemes. Buffering

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

Finite Automata. Mahesh Viswanathan

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

Transcription:

Formal Definition of a Nondeterministic Finite Automaton September 7, 2014

A comment first The formal definition of an NFA is similar to that of a DFA. Both have states, an alphabet, transition function, one start state, and a collection of accept states

A comment first The formal definition of an NFA is similar to that of a DFA. Both have states, an alphabet, transition function, one start state, and a collection of accept states They differ in one essential way: the transition functions

A comment first The formal definition of an NFA is similar to that of a DFA. Both have states, an alphabet, transition function, one start state, and a collection of accept states They differ in one essential way: the transition functions In a DFA transition function is δ : Q Σ Q; In an NFA it is δ : Q (Σ {ɛ}) P(Q) where P(Q) is the collection of subsets of Q called the power set of Q

Notation For any alphabet Σ, Σ ɛ = Σ {ɛ}

NFA formal definition (Def. 1.37) A nondeterministic finite automaton is a 5-tuple (Q, Σ, δ, q 0, F ) where 1. Q is a finite set of states 2. Σ is a finite alphabet 3. δ : Q Σ ɛ P(Q) is the transition function 4. q 0 Q is the start state 5. F Q is the set of accept states

Example NFA (Example 1.38) Recall the NFA N 1, Figure 1: 0,1 0,1 1 q 1 q ɛ,0 2 q 1 3 q 4 Figure : Nondeterministic Finite Automaton N 1

Example NFA (Example 1.38) Recall the NFA N 1, Figure 1: 0,1 0,1 1 q 1 q ɛ,0 2 q 1 3 q 4 Figure : Nondeterministic Finite Automaton N 1 N 1 = (Q, Σ, δ, q 1, F ) where:

Example NFA (Example 1.38) Recall the NFA N 1, Figure 1: 0,1 0,1 1 q 1 q ɛ,0 2 q 1 3 q 4 Figure : Nondeterministic Finite Automaton N 1 N 1 = (Q, Σ, δ, q 1, F ) where: 1. Q = {q 1, q 2, q 3, q 4 }

Example NFA (Example 1.38) Recall the NFA N 1, Figure 1: 0,1 0,1 1 q 1 q ɛ,0 2 q 1 3 q 4 Figure : Nondeterministic Finite Automaton N 1 N 1 = (Q, Σ, δ, q 1, F ) where: 1. Q = {q 1, q 2, q 3, q 4 } 2. Σ = {0, 1}

Example NFA (Example 1.38) Recall the NFA N 1, Figure 1: 0,1 0,1 1 q 1 q ɛ,0 2 q 1 3 q 4 Figure : Nondeterministic Finite Automaton N 1 N 1 = (Q, Σ, δ, q 1, F ) where: 1. Q = {q 1, q 2, q 3, q 4 } 2. Σ = {0, 1} 3. δ is given in the table: δ 0 1 ɛ q 1 {q 1 } {q 1, q 2 } q 2 {q 3 } {q 3 } q 3 {q 4 } q 4 {q 4 } {q 4 }

Example NFA (Example 1.38) Recall the NFA N 1, Figure 1: 0,1 0,1 1 q 1 q ɛ,0 2 q 1 3 q 4 Figure : Nondeterministic Finite Automaton N 1 N 1 = (Q, Σ, δ, q 1, F ) where: 1. Q = {q 1, q 2, q 3, q 4 } 2. Σ = {0, 1} 3. δ is given in the table: δ 0 1 ɛ q 1 {q 1 } {q 1, q 2 } q 2 {q 3 } {q 3 } q 3 {q 4 } q 4 {q 4 } {q 4 } 4. q 1 is the start set; 5. F = {q 4 }

Computation performed by an NFA Let N = (Q, Σ, δ, q 0, F ) be an NFA and w a string over Σ. We say that N accepts w if we can write w as w = w 1 w 2... w m, y i Σ ɛ, 1 i m, and a sequence of states r 0, r 1,..., r m exists in Q such that: 1. r 0 = q 0 2. r i+1 δ(r i, w i+1 ), for i = 0, 1,..., m 1 3. r m F

Computation performed by an NFA Let N = (Q, Σ, δ, q 0, F ) be an NFA and w a string over Σ. We say that N accepts w if we can write w as w = w 1 w 2... w m, y i Σ ɛ, 1 i m, and a sequence of states r 0, r 1,..., r m exists in Q such that: 1. r 0 = q 0 2. r i+1 δ(r i, w i+1 ), for i = 0, 1,..., m 1 3. r m F Condition 1 says that the machine starts its computation in the start state

Computation performed by an NFA Let N = (Q, Σ, δ, q 0, F ) be an NFA and w a string over Σ. We say that N accepts w if we can write w as w = w 1 w 2... w m, y i Σ ɛ, 1 i m, and a sequence of states r 0, r 1,..., r m exists in Q such that: 1. r 0 = q 0 2. r i+1 δ(r i, w i+1 ), for i = 0, 1,..., m 1 3. r m F Condition 1 says that the machine starts its computation in the start state Condition 2 says that state r i+1 is one of the allowable new states when N is in state r i and reads w i+1. Note that δ(r i, w i+1 ) is a set

Computation performed by an NFA Let N = (Q, Σ, δ, q 0, F ) be an NFA and w a string over Σ. We say that N accepts w if we can write w as w = w 1 w 2... w m, y i Σ ɛ, 1 i m, and a sequence of states r 0, r 1,..., r m exists in Q such that: 1. r 0 = q 0 2. r i+1 δ(r i, w i+1 ), for i = 0, 1,..., m 1 3. r m F Condition 1 says that the machine starts its computation in the start state Condition 2 says that state r i+1 is one of the allowable new states when N is in state r i and reads w i+1. Note that δ(r i, w i+1 ) is a set Condition 3 says that the machine accepts the input if the last state is in the accept state set.

Equivalence of NFA and DFA DFAs and NFAs recognize the same class of languages

Equivalence of NFA and DFA DFAs and NFAs recognize the same class of languages This equivalence is both surprising and useful

Equivalence of NFA and DFA DFAs and NFAs recognize the same class of languages This equivalence is both surprising and useful 1. It is surprising because NFAs appears to have more power than DFA, so we might expect that NFA recognizes more languages

Equivalence of NFA and DFA DFAs and NFAs recognize the same class of languages This equivalence is both surprising and useful 1. It is surprising because NFAs appears to have more power than DFA, so we might expect that NFA recognizes more languages 2. It is useful because describing an NFA for a given language sometimes is much easier than describing a DFA

Theorem 1.39 Every nondeterministic finite automation (NFA) has an equivalent deterministic finite automaton (DFA). Proof idea: Convert the NFA into an equivalemt DFA that simulates the NFA

Theorem 1.39 Every nondeterministic finite automation (NFA) has an equivalent deterministic finite automaton (DFA). Proof idea: Convert the NFA into an equivalemt DFA that simulates the NFA The approach is to pretend to be an DFA simulating an NFA. How would you simulate an NFA if you were pretending to be a DFA? What does one need to keep track of as the input is processed?

Theorem 1.39 Every nondeterministic finite automation (NFA) has an equivalent deterministic finite automaton (DFA). Proof idea: Convert the NFA into an equivalemt DFA that simulates the NFA The approach is to pretend to be an DFA simulating an NFA. How would you simulate an NFA if you were pretending to be a DFA? What does one need to keep track of as the input is processed? In the examples of NFA we kept track of various branches of the computation by placing tokens on each state that could be activated at given points in the input

Theorem 1.39 Every nondeterministic finite automation (NFA) has an equivalent deterministic finite automaton (DFA). Proof idea: Convert the NFA into an equivalemt DFA that simulates the NFA The approach is to pretend to be an DFA simulating an NFA. How would you simulate an NFA if you were pretending to be a DFA? What does one need to keep track of as the input is processed? In the examples of NFA we kept track of various branches of the computation by placing tokens on each state that could be activated at given points in the input Tokens were updated by moving, adding, and removing them according to the way NFA operates

Theorem 1.39 Every nondeterministic finite automation (NFA) has an equivalent deterministic finite automaton (DFA). Proof idea: Convert the NFA into an equivalemt DFA that simulates the NFA The approach is to pretend to be an DFA simulating an NFA. How would you simulate an NFA if you were pretending to be a DFA? What does one need to keep track of as the input is processed? In the examples of NFA we kept track of various branches of the computation by placing tokens on each state that could be activated at given points in the input Tokens were updated by moving, adding, and removing them according to the way NFA operates Hence, all we needed to keep track of is the set of states with tokens on them

Conclusion An NFA with k states has 2 k subsets of states Each subset correspond to one of the possibilities that DFA must remember. So, the DFA simulating an NFA with k states has 2 k states The only thing we need now is to figure out which are the start state, the accept states, and transition function

The formal proof Let N = (Q, Σ, δ, q 0, F ) be the NFA recognizing the language A. We construct the DFA M recognizing A. Before doing the full construction, consider first the easier case when N has no ɛ transitions. Constructing M = (Q, Σ, δ, q 0, F )

The formal proof Let N = (Q, Σ, δ, q 0, F ) be the NFA recognizing the language A. We construct the DFA M recognizing A. Before doing the full construction, consider first the easier case when N has no ɛ transitions. Constructing M = (Q, Σ, δ, q 0, F ) 1. Q = P(Q); every state of M is a set of states of N

The formal proof Let N = (Q, Σ, δ, q 0, F ) be the NFA recognizing the language A. We construct the DFA M recognizing A. Before doing the full construction, consider first the easier case when N has no ɛ transitions. Constructing M = (Q, Σ, δ, q 0, F ) 1. Q = P(Q); every state of M is a set of states of N 2. For R Q and a Σ let δ (R, a) = {q Q q δ(r, a) for some r R} Note: δ (R, a) = r R δ(r, a)

The formal proof Let N = (Q, Σ, δ, q 0, F ) be the NFA recognizing the language A. We construct the DFA M recognizing A. Before doing the full construction, consider first the easier case when N has no ɛ transitions. Constructing M = (Q, Σ, δ, q 0, F ) 1. Q = P(Q); every state of M is a set of states of N 2. For R Q and a Σ let δ (R, a) = {q Q q δ(r, a) for some r R} Note: δ (R, a) = r R δ(r, a) 3. q 0 = {q 0}; M starts computing in the same state as N

The formal proof Let N = (Q, Σ, δ, q 0, F ) be the NFA recognizing the language A. We construct the DFA M recognizing A. Before doing the full construction, consider first the easier case when N has no ɛ transitions. Constructing M = (Q, Σ, δ, q 0, F ) 1. Q = P(Q); every state of M is a set of states of N 2. For R Q and a Σ let δ (R, a) = {q Q q δ(r, a) for some r R} Note: δ (R, a) = r R δ(r, a) 3. q 0 = {q 0}; M starts computing in the same state as N 4. F = {R Q R contains an accept state of N} that is, the machine M accepts if one of the possible states that N could be in at this point is an accept state

Consider the ɛ transitions Notation: for any R Q define E(R) to be the collection of states that can be reached from R by going only along ɛ transitions, including the members of R themselves. Formally: E(R) = R {q Q r R δ(r, ɛ) = q} Note: any q E(R) can be reached from R by traveling along 0 or more ɛ arrows.

Modifications Modify δ to place additional tokens on all states that can be reached by going along ɛ arrows after every step. This effect is achieved by replacing δ(r, a) by E(δ(r, a)) in definition of δ. That is δ (R, a) = {q Q q E(δ(r, a)) for some r R}

Modifications Modify δ to place additional tokens on all states that can be reached by going along ɛ arrows after every step. This effect is achieved by replacing δ(r, a) by E(δ(r, a)) in definition of δ. That is δ (R, a) = {q Q q E(δ(r, a)) for some r R} Modify the start state of M to put tokens initially on all states that can be reached from q 0 along ɛ transitions, i.e., q 0 = E({q 0})

Note M thus constructed obviously simulates N At every step in the computation of M it clearly enters a state that corresponds to the subset of states that N could be in at that point

Corollary 1.40 A language is regular iff some NFA recognizes it Proof: If a language A is recognized by an NFA then A is recognized by the DFA equivalent, hence, A is regular If a language A is regular, it means that it is recognized by a DFA. But any DFA is also an NFA hence, the language is recognized by an NFA

Example conversion NFA to DFA Consider the NFA N 4 described in Figure 2: a 1 b ɛ a a,b 2 3 Figure : The NFA N 4

Example conversion NFA to DFA Consider the NFA N 4 described in Figure 2: a 1 b ɛ a a,b 2 3 Figure : The NFA N 4 Formal description of N 4 N 4 = ({1, 2, 3}, {a, b}, δ, 1, {1}) where δ is given in the table: δ a b ɛ 1 {2} {3} 2 {2, 3} {3} 3 {1}

Construction of D 4 = (Q, {a, b}, δ, q 0, F ) Since N 4 s set of states is Q = {1, 2, 3} Q = {, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}} The start state of Q : the set of states reachable from 1 (the start state of N 4 ) traveling by ɛ: E({1}) = {1, 3} The accept state of Q : are those states of Q that contain the accept states of Q: i.e., F = {{1}, {1, 2}, {1, 3}, {1, 2, 3}}

Transition function δ : P(Q) Σ P(Q), where for each q P(Q) and x Σ we have δ (q, x) P(Q)

Constructing D 4 s transitions State : goes to on both a, b, i.e., δ (, a) = δ (, b) = State {1}: goes to on a and to {2} on b State {2}: goes to {2, 3} on a and to {3} on b State {1, 2}: goes to {2, 3} on a and to {2, 3} on b And so on, for each state

Putting all together Figure 3 shows the resulting DFA D 4 equivalent to NFA N 4 {3} b a,b a {1, 3} {1} a b a b {2, 3} {2} a b b a {1, 2, 3} {1, 2} b a a,b Figure : DFA D 4 equivalent to NFA N 4

Simplifying D 4 The automaton D 4 may be simplified by observing that no arrows point at the states {1} and {1, 2}. Removing these states we obtain the automaton in Figure 4 a {1, 3} b b a {2} a {3} b {2, 3} b a b a,b a {1, 2, 3} Figure : The simplified version of D 4