Inf2A: Converting from NFAs to DFAs and Closure Properties

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

Nondeterministic Finite Automata

Lecture 3: Nondeterministic Finite Automata

Finite Automata and Regular languages

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

CS 455/555: Finite automata

CS 154, Lecture 3: DFA NFA, Regular Expressions

Chapter Five: Nondeterministic Finite Automata

Intro to Theory of Computation

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

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,

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

Constructions on Finite Automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Constructions on Finite Automata

Fooling Sets and. Lecture 5

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Equivalence of DFAs and NFAs

Theory of Languages and Automata

Inf2A: The Pumping Lemma

Closure under the Regular Operations

CS21 Decidability and Tractability

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

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

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

Formal Models in NLP

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

Lecture 1: Finite State Automaton

Finite Automata Part Two

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

CS243, Logic and Computation Nondeterministic finite automata

Non-deterministic Finite Automata (NFAs)

Chapter 6: NFA Applications

CPS 220 Theory of Computation REGULAR LANGUAGES

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

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

Theory of Computation (II) Yijia Chen Fudan University

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

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

Sri vidya college of engineering and technology

Regular Expressions. Definitions Equivalence to Finite Automata

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

Nondeterministic Finite Automata

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

Computer Sciences Department

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

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

Uses of finite automata

Algorithms for NLP

CSE 105 THEORY OF COMPUTATION

Classes and conversions

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

Büchi Automata and their closure properties. - Ajith S and Ankit Kumar

CSE 105 Theory of Computation Professor Jeanne Ferrante

Theory of Computation

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Automata and Languages

Nondeterministic Finite Automata

Finite Automata. Seungjin Choi

September 7, Formal Definition of a Nondeterministic Finite Automaton

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

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

Before we show how languages can be proven not regular, first, how would we show a language is regular?

Lecture 4 Nondeterministic Finite Accepters

CSE 105 THEORY OF COMPUTATION

CS 208: Automata Theory and Logic

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

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

CISC 4090 Theory of Computation

Nondeterministic Finite Automata

Harvard CS 121 and CSCI E-207 Lecture 4: NFAs vs. DFAs, Closure Properties

Regular Languages. Problem Characterize those Languages recognized by Finite Automata.

Nondeterministic finite automata

Lecture 7 Properties of regular languages

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

CMSC 330: Organization of Programming Languages

Nondeterminism. September 7, Nondeterminism

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSE 105 THEORY OF COMPUTATION

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

V Honors Theory of Computation

Introduction to Languages and Computation

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

3515ICT: Theory of Computation. Regular languages

Computational Models - Lecture 5 1

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

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

Computational Models Lecture 2 1

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

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

Automata: a short introduction

Computational Models - Lecture 4

Equivalence of Regular Expressions and FSMs

Transcription:

1/43 Inf2A: Converting from NFAs to DFAs and Stuart Anderson School of Informatics University of Edinburgh October 13, 2009

Starter Questions 2/43 1 Can you devise a way of testing for any FSM M whether L(M) =? 2 Can you devise a way of testing for any pair of FSMs M and M whether L(M) = L(M )?

3/43 Outline 1 NFA - the definitions NFA: Example 2 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA 3 Demonstrating Closure under various operators Closure: Example 4

4/43 A non-deterministic automaton NFA - the definitions NFA: Example a,b a b a 0 1 2 3 Formally: N = ( {0, 1, 2, 3}, {a, b}, 0, {3}, ), where the transition relation is given by the following table: a b 0 {0, 1} {0} 1 {2} 2 {3} 3

NFA - the definitions NFA: Example Non-deterministic Finite Automata Definition: A nondeterministic finite automaton (or NFA) is a tuple N = (Q, Σ, q 0, F, ) consisting of: 1 a finite set Q of states, 2 a finite alphabet Σ, 3 a distinguished starting state q 0 Q, 4 a set F Q of final states (the ones that indicate acceptance), 5 a description of all the possible transitions. must be given by a table that answers the following question: Given a state q and an input symbol a, what are the possible next states? is called the transition function or transition relation. 6/43

7/43 The Language of an NFA NFA - the definitions NFA: Example As opposed to a DFA, an NFA may have several possible computations for the same input string or it may get stuck and have no (complete) computation at all. An NFA N is said to accept a string x if there is at least one computation of N on input x that leads to an accepting final state. The language recognized by an NFA N = (Q, Σ, q 0, F, ) is the language L(N)= { x Σ N accepts x }.

9/43 Example NFA - the definitions NFA: Example a,b a b a 0 1 2 3 Two possible computations of this NFA on input aaaba: 0 a 0 0 a 0 a 0 a 0 a 0 a 1 b 0 b 2 a 0 a 3 The NFA accepts the language { xaba x {a, b} }.

10/43 Example NFA - the definitions NFA: Example 0 9 0 1 0 2 1 1 0 2 1 1 1 0

11/43 NFAs with ε-transitions NFA - the definitions NFA: Example ε-transitions are transitions not triggered by any input symbol. If in a state q an ε-transition to a state q is possible, then whenever the automaton reaches state q in a computation it can immediately proceed to state q without needing any further input. To descibe this formally the function is defined for Σ {ε}. Example: ε ε ε a b a c 0 1 2 3 4 ε An NFA with ε-transitions recognizing the language {ε, c, ac, bac, abac}.

12/43 The languages of NFAs Converting from NFAs to DFAs Example: Converting from an NFA to a DFA Obvious fact 1: Any language recognized by some DFA can also be recognized by some NFA. Obvious fact 2: Any language recognized by some NFA can also be recognized by some NFA with ε-transitions.

14/43 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA Theorem: Any language accepted by some NFA with ε-transitions is also accepted by some DFA. Therefore, every language accepted by an NFA, with or without ε-transitions, is regular.

15/43 Proof: The Powerset Construction Converting from NFAs to DFAs Example: Converting from an NFA to a DFA Let N = (Q, Σ, q 0, F, ) be an NFA. Idea: Simulate all possible computations of N in parallel. Construction: Let M = (S, Σ, s 0, F, δ), where S = P(Q) = {s s Q} (the powerset of Q) s 0 = {q 0 } {q q can be reached from q 0 using only ε-transitions} δ is defined by δ(s, a) = set of all states reachable from a state in s by one a-transition and ε-transitions. F = {s S s F }.

The conversion algorithm Converting from NFAs to DFAs Example: Converting from an NFA to a DFA 1 Construct the start state s 0 consisting of q 0 and all states of N that can be reached from q 0 by one or several ε-transitions. Mark s 0 as unfinished. 2 While there still are unfinished states: 1 Take an unfinished state s. 2 For each a Σ, let δ(s, a) = set of all states reachable from a state in s by one a-transition and ε-transitions = q s set of all states reachable from q by one a-transition and ε-transitions If δ(s, a) is neither finished nor unfinished yet, then mark δ(s, a) as unfinished. 3 Mark s as finished. 3 Mark all states that contain a final state from N as final states of M. 16/43

18/43 An example conversion Converting from NFAs to DFAs Example: Converting from an NFA to a DFA 1 0 1 3 ε ε ε 0 ε 2 0 1 4 5 ε 6 7 0 ε The start state: s 0 = {0, 1, 2}.

19/43 Computing the transition table Converting from NFAs to DFAs Example: Converting from an NFA to a DFA δ 0 1 {0, 1, 2} δ 0 1 {0, 1, 2} {3, 4, 6} {3, 4, 6} δ 0 1 {0, 1, 2} {3, 4, 6} {3, 4, 6} {6, 7} {2, 3, 5, 6} {6, 7} {2, 3, 5, 6} δ 0 1 {0, 1, 2} {3, 4, 6} {3, 4, 6} {6, 7} {2, 3, 5, 6} {6, 7} {2, 3, 5, 6}

20/43 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA δ 0 1 {0, 1, 2} {3, 4, 6} {3, 4, 6} {6, 7} {2, 3, 5, 6} {6, 7} {6, 7} {2, 3, 5, 6} δ 0 1 {0, 1, 2} {3, 4, 6} {3, 4, 6} {6, 7} {2, 3, 5, 6} {6, 7} {6, 7} {2, 3, 5, 6} {4, 6, 7} {3, 6} {4, 6, 7} {3, 6}

21/43 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA δ 0 1 {0, 1, 2} {3, 4, 6} {3, 4, 6} {6, 7} {2, 3, 5, 6} {6, 7} {6, 7} {2, 3, 5, 6} {4, 6, 7} {3, 6} {4, 6, 7} {6, 7} {2, 5, 6} {3, 6} {2, 5, 6}

22/43 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA δ 0 1 {0, 1, 2} {3, 4, 6} {3, 4, 6} {6, 7} {2, 3, 5, 6} {6, 7} {6, 7} {2, 3, 5, 6} {4, 6, 7} {3, 6} {4, 6, 7} {6, 7} {2, 5, 6} {3, 6} {6, 7} {3, 6} {2, 5, 6}

23/43 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA The final states: δ 0 1 {0, 1, 2} {3, 4, 6} {3, 4, 6} {6, 7} {2, 3, 5, 6} {6, 7} {6, 7} {2, 3, 5, 6} {4, 6, 7} {3, 6} {4, 6, 7} {6, 7} {2, 5, 6} {3, 6} {6, 7} {3, 6} {2, 5, 6} {4, 6, 7} F = {s S s {7} } = { {6, 7}, {4, 6, 7} }.

0 24/43 The resulting DFA Converting from NFAs to DFAs Example: Converting from an NFA to a DFA 0,1 1 {0,1,2} φ 0 1 1 {3,4,6} 0 {6,7} 0 {2,5,6} 1 0 0 0 1 1 {2,3,5,6} {3,6} 1 {4,6.7}

25/43 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA What do we need to show about the Conversion Algorithm? If M is an NFA and M is the DFA derived from M via the conversion algorithm, what should we be able to prove about M and M What technique do you think we need for the proof?

26/43 Outline Converting from NFAs to DFAs Example: Converting from an NFA to a DFA 1 NFA - the definitions NFA: Example 2 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA 3 Demonstrating Closure under various operators Closure: Example 4

27/43 Recall Regular expressions Demonstrating Closure under various operators Closure: Example R L(R) ε {ε} a {a} (for any a Σ) R 1 + R 2 L(R { 1 ) L(R 2 ) R 1 R 2 xy x L(R1 ), y L(R 2 ) } R1 { x1... x n n N 0, x 1,..., x n L(R 1 ) }. We know we can construct an NFA for any Regular Expression.

29/43 Demonstrating Closure under various operators Closure: Example Closure under union and concatenation Theorem: If L 1 and L 2 are regular languages, then the following two languages are also regular: 1 L 1 L 2, 2 L 1 L 2 = { xy x L 1, y L 2 }. Proof: Let R 1, R 2 be regular expressions such that L(R 1 ) = L 1, L(R 2 ) = L 2. Then L 1 L 2 = L(R 1 ) L(R 2 ) = L(R 1 + R 2 ) and L 1 L 2 = L(R 1 )L(R 2 ) = L(R 1 R 2 ).

30/43 Closure under complementation Demonstrating Closure under various operators Closure: Example Theorem: If L Σ is a regular language, then the following language is also regular: L = {x Σ x L}. Proof: Let M be a DFA that recognises L. Let M be the DFA obtained from M by making all states that are not final states of M final states of M and vice versa. Then M recognises L: M accepts string x running M on input x ends in a final state of M running M on input x does not end in a final state of M running M on input x does not end in a final state of M M does not accept x x L.

31/43 Example Demonstrating Closure under various operators Closure: Example b a a a b a b A DFA for the language L = {xaba x {a, b} }. b a a b a b a b A DFA for L. b

32/43 Demonstrating Closure under various operators Closure: Example Closure under intersection and difference Theorem: If L 1 and L 2 are regular languages, then the following two languages are also regular: 1 L 1 L 2, 2 L 1 \ L 2 = { x x L 1 and x L 2 }. Proof: We use the facts that L 1 L 2 = ( L 1 L 2 ) (by DeMorgan s rule) and L 1 \ L 2 = L 1 L 2 = ( L 1 L 2 ).

33/43 Constructions Demonstrating Closure under various operators Closure: Example Problem: Suppose we are given DFAs for L 1 and L 2. How do we construct DFAs for L 1, L 1 L 2, L 1 L 2, L 1 \ L 2?

34/43 Complementation Demonstrating Closure under various operators Closure: Example We have already seen a construction. Union 1 Compute an NFA with ε-transitions. 2 Convert it to a DFA. Intersection and difference Combine the constructions for complementation and union.

36/43 Example Demonstrating Closure under various operators Closure: Example b a a a,b a b a a b a p0 p1 p2 p3 q0 q1 q2 q3 b M 1 b b a b q4 a,b M 2 Construct a DFA for L(M 1 ) L(M 2 ) = ( L(M 1 ) L(M 2 ) ).

37/43 Example (cont d) Demonstrating Closure under various operators Closure: Example Step 1: Construct DFAs for L(M 1 ) and L(M 2 ). b a a a,b a b a a b a p0 p1 p2 p3 q0 q1 q2 q3 b b b a b q4 a,b

38/43 Example (cont d) Demonstrating Closure under various operators Closure: Example Step 2: Construct an NFA with ε-transitions for L(M 1 ) L(M 2 ). b a a 0 ε ε p0 a p1 b p2 a p3 b b a,b q0 a q1 b q2 a q3 b a b q4 a,b

39/43 Example (cont d) Demonstrating Closure under various operators Closure: Example Step 3: Convert the NFA with ε-transitions for L(M 1 ) L(M 2 ) to a DFA. δ a b {0, p0, q0} {p1, q1} {p0, q4} {p1, q1} {p1, q4} {p2, q2} {p0, q4} {p1, q4} {p0, q4} {p1, q4} {p1, q4} {p2, q4} {p2, q2} {p3, q3} {p0, q4} {p2, q4} {p3, q4} {p0, q4} {p3, q3} {p1, q3} {p2, q3} {p3, q4} {p1, q4} {p2, q4} {p1, q3} {p1, q3} {p2, q3} {p2, q3} {p3, q3} {p0, q3} {p0, q3} {p1, q3} {p0, q3}

40/43 Example (cont d) Demonstrating Closure under various operators Closure: Example Step 4: Complement the DFA for L(M 1 ) L(M 2 ). Result: ( Q, Σ, {0, p0, q0}, { {p3, q3} } ), δ, where Q = { {0, p0, q0}, {p1, q1}, {p0, q4}, {p1, q4}, {p2, q2}, {p2, q4}, {p3, q3}, {p3, q4}, {p1, q3}, {p2, q3}, {p0, q3} },

41/43 Union vs. Intersection vs. Difference Demonstrating Closure under various operators Closure: Example The automata we construct for L(M 1 ) L(M 2 ), L(M 1 ) L(M 2 ), and L(M 1 ) \ L(M 2 ) only differ in their final states: Intersection: Final states (of the powerset automaton) are states that contain a final state of M 1 and a final state of M 2. Union: Final states (of the powerset automaton) are states that contain a final state of M 1 or a final state of M 2. Difference: Final states (of the powerset automaton) are states that contain a final state of M 1 but not a final state of M 2.

42/43 Kleene s theorem tell us that regular expressions and FSAs describe the same class of languages. NFA/DFA equivalence tells us that in this case nondeterminism doe not change the class of languages recognised (see later). Closure results tell us we can augment regular expressions with many operators that allow us to express regular sets succinctly without going outside languages recognisable by FSMs.