CSE 135: Introduction to Theory of Computation Optimal DFA

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

Minimization of DFAs

Lecture 5: Minimizing DFAs

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

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

Chapter 2: Finite Automata

More on Finite Automata and Regular Languages. (NTU EE) Regular Languages Fall / 41

Finite Automata and Regular Languages

Formal Language and Automata Theory (CS21004)

Notes on State Minimization

We define the multi-step transition function T : S Σ S as follows. 1. For any s S, T (s,λ) = s. 2. For any s S, x Σ and a Σ,

Chapter 2: Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

COMP4141 Theory of Computation

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 5 : DFA minimization

Lecture 1: Finite State Automaton

Java II Finite Automata I

3515ICT: Theory of Computation. Regular languages

Constructions on Finite Automata

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

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

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

Subset construction. We have defined for a DFA L(A) = {x Σ ˆδ(q 0, x) F } and for A NFA. For any NFA A we can build a DFA A D such that L(A) = L(A D )

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

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

What we have done so far

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,

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

Introduction to Formal Languages, Automata and Computability p.1/51

CS 154, Lecture 4: Limitations on DFAs (I), Pumping Lemma, Minimizing DFAs

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

Finite State Automata

Constructions on Finite Automata

Computational Models - Lecture 3 1

2. Elements of the Theory of Computation, Lewis and Papadimitrou,

Deterministic finite Automata

CS154. Non-Regular Languages, Minimizing DFAs

Computational Models - Lecture 4

Computational Models: Class 3

Finite Automata - Deterministic Finite Automata. Deterministic Finite Automaton (DFA) (or Finite State Machine)

Equivalence. See section 4.4 of the text

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

Finite Automata. Seungjin Choi

Computational Models - Lecture 3 1

Regular expressions and Kleene s theorem

Computability and Complexity

Nondeterministic Finite Automata

Finite Automata and Formal Languages TMV026/DIT321 LP Testing Equivalence of Regular Languages

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

DD2371 Automata Theory

1 Showing Recognizability

CMPSCI 250: Introduction to Computation. Lecture #32: The Myhill-Nerode Theorem David Mix Barrington 11 April 2014

ACS2: Decidability Decidability

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

NPDA, CFG equivalence

CSE 105 THEORY OF COMPUTATION

Outline. Summary. DFA -> Regex. Finish off Regex -> e-nfa -> NFA -> DFA -> Regex Minimization/equivalence (Myhill-Nerode theorem)

CSE 105 THEORY OF COMPUTATION

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

Homomorphisms and Efficient State Minimization

2. Syntactic Congruences and Monoids

Finite Automata. Theorems - Unit I SUSAN ELIAS. Professor Department of Computer Science & Engineering Sri Venkateswara College of Engineering

arxiv:cs/ v1 [cs.cc] 9 Feb 2007

Equivalence. See section 4.4 of the text

CSE 105 THEORY OF COMPUTATION

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

DM17. Beregnelighed. Jacob Aae Mikkelsen

Undecidable Problems and Reducibility

Decidability and Undecidability

Chapter Two: Finite Automata

Computational Models - Lecture 4 1

Inf2A: The Pumping Lemma

Extended transition function of a DFA

CSCE 551 Final Exam, Spring 2004 Answer Key

Computational Models - Lecture 3

DFA to Regular Expressions

CS 154. Finite Automata, Nondeterminism, Regular Expressions

CS 154 Introduction to Automata and Complexity Theory

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

Uses of finite automata

Theory of Computation

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

1 More finite deterministic automata

(pp ) PDAs and CFGs (Sec. 2.2)

CS 455/555: Finite automata

0.1 Minimizing Finite State Machines

Equivalence of DFAs and NFAs

Chapter Five: Nondeterministic Finite Automata

Lecture 3: Nondeterministic Finite Automata

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

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

Lecture 17: Language Recognition

DISTINGUISHABILITY AND COMPLETENESS OF CRISP DETERMINISTIC FUZZY AUTOMATA

Chapter 6: NFA Applications

Two Way Deterministic Finite Automata

Homework Assignment 6 Answers

Inf2A: Converting from NFAs to DFAs and Closure Properties

Finite Automata and Regular languages

Transcription:

CSE 35: Introduction to Theory of Computation Optimal DFA Sungjin Im University of California, Merced 2-9-25

Optimal Algorithms for Regular Languages Myhill-Nerode Theorem There is a unique optimal algorithm for every problem that can be solved using finite memory. Anil Nerode

Optimal Algorithms for Regular Languages Myhill-Nerode Theorem There is a unique optimal algorithm for every problem that can be solved using finite memory. algorithm here means a deterministic machine Anil Nerode

Optimal Algorithms for Regular Languages Anil Nerode Myhill-Nerode Theorem There is a unique optimal algorithm for every problem that can be solved using finite memory. algorithm here means a deterministic machine optimal means requires least memory, i.e., has fewest states

Optimal Algorithms for Regular Languages Anil Nerode Myhill-Nerode Theorem There is a unique optimal algorithm for every problem that can be solved using finite memory. algorithm here means a deterministic machine optimal means requires least memory, i.e., has fewest states unique means that any two DFAs with fewest states for a language are isomorphic

Roadmap DFA minimization: Minimize a given DFA M by merging indistinguishable states.

Roadmap DFA minimization: Minimize a given DFA M by merging indistinguishable states. In general, could be only minimal (locally optimal) In DFA minimization, a minimal (locally optimal) DFA is a minimum (globally optimal) DFA. Test if two given DFAs are equivalent. Revisit Myhill-Nerode Theorem.

Many DFAs for the same language

Minimization Problem Ultimate goal:

Minimization Problem Ultimate goal:

Minimization Problem Ultimate goal: Given a DFA M, construct the DFA with fewest states M such that L(M ) = L(M).

Minimization Problem Ultimate goal: Given a DFA M, construct the DFA with fewest states M such that L(M ) = L(M). Intermediate goal: Minimize a given DFA M by merging indistinguishable states.

Minimization Problem Ultimate goal: Given a DFA M, construct the DFA with fewest states M such that L(M ) = L(M). Intermediate goal: Minimize a given DFA M by merging indistinguishable states. Applications Algorithms using DFAs run in time directly related to the number of states of DFA. Implementation of the DFA itself takes memory proportional to log number of states. So constructing small DFAs is very critical.

Algorithm Step : Remove all unreachable states.

Algorithm Step : Remove all unreachable states. * Use DFS o BFS.

Algorithm Step : Remove all unreachable states. * Use DFS o BFS. Step 2: Merge similar states.

Some possible approaches Want to merge similar states.

Some possible approaches Want to merge similar states. Attempt : Focus on what each state remembers/encodes.

Some possible approaches Want to merge similar states. Attempt : Focus on what each state remembers/encodes. Seems hard when the DFA is large.

Some possible approaches Want to merge similar states. Attempt : Focus on what each state remembers/encodes. Seems hard when the DFA is large. Attempt 2: State Characterization? Two states are indistinguishable if ˆδ(p, w) = ˆδ(q, w) for all strings w.

Some possible approaches Want to merge similar states. Attempt : Focus on what each state remembers/encodes. Seems hard when the DFA is large. Attempt 2: State Characterization? Two states are indistinguishable if ˆδ(p, w) = ˆδ(q, w) for all strings w. Seems not strong enough.

Distinguishability When must two states p and q of M not be collapsed?

Distinguishability When must two states p and q of M not be collapsed? w. ˆδ(p, w) F and ˆδ(q, w) F ; or w. ˆδ(p, w) F and ˆδ(q, w) F

Distinguishability When must two states p and q of M not be collapsed? w. ˆδ(p, w) F and ˆδ(q, w) F ; or w. ˆδ(p, w) F and ˆδ(q, w) F We will say that p and q are distinguishable when this happens.

Indistinguishability We say that two states p and q of M are indistinguishable/equivalent if w. ˆδ(p, w) F iff ˆδ(q, w) F

Indistinguishability We say that two states p and q of M are indistinguishable/equivalent if w. ˆδ(p, w) F iff ˆδ(q, w) F

Indistinguishability We say that two states p and q of M are indistinguishable/equivalent if w. ˆδ(p, w) F iff ˆδ(q, w) F

Indistinguishability We say that two states p and q of M are indistinguishable/equivalent if w. ˆδ(p, w) F iff ˆδ(q, w) F Indistinguishability defines an equivalence class: A A (reflexivity), A B B A (symmetricity), A B and B C (transivity). So let s use p q to say that two states p and q are indistinguishable.

Gradually Refine Indistinguishability Recall p q : w. ˆδ(p, w) F iff ˆδ(q, w) F For each k, define p k q : w with w k. ˆδ(p, w) F iff ˆδ(q, w) F An equivalence class partitions states into disjoint groups. has two groups: Q \ F and F.

Gradually Refine Indistinguishability Suppose that we know for each pair of two states p, q if p k q or not. How can we examine if p k+ q or not? If p k q, then we have p k+ q. Each group of states can be only refined! If p k q, then we need to do more work:

Gradually Refine Indistinguishability Suppose that we know for each pair of two states p, q if p k q or not. How can we examine if p k+ q or not? If p k q, then we have p k+ q. Each group of states can be only refined! If p k q, then we need to do more work: p k+ q iff a Σ.δ(p, a) k δ(q, a)

Gradually Refine Indistinguishability Suppose that we know for each pair of two states p, q if p k q or not. How can we examine if p k+ q or not? If p k q, then we have p k+ q. Each group of states can be only refined! If p k q, then we need to do more work: Do you see why? p k+ q iff a Σ.δ(p, a) k δ(q, a)

Gradually Refine Indistinguishability Suppose that we know for each pair of two states p, q if p k q or not. How can we examine if p k+ q or not? If p k q, then we have p k+ q. Each group of states can be only refined! If p k q, then we need to do more work: Do you see why? p k+ q p k+ q iff a Σ.δ(p, a) k δ(q, a) u with u k a Σ.ˆδ(p, au) F iff ˆδ(q, au) F u with u k a Σ.ˆδ(δ(p, a), u) F iff ˆδ(δ(q, a), u) F a Σ u with u k.ˆδ(δ(p, a), u) F iff ˆδ(δ(q, a), u) F a Σ.δ(p, a) k δ(q, a)

Distinguishability Inductive Definition Distinguishability can be inductively defined as follows

Distinguishability Inductive Definition Distinguishability can be inductively defined as follows If p F and q F then p and q are distinuishable

Distinguishability Inductive Definition Distinguishability can be inductively defined as follows If p F and q F then p and q are distinuishable If for some a, δ(p, a) = p and δ(q, a) = q, and p and q are distinguishable, then p and q are distinguishable

Distinguishability An Algorithm Let distinct be a table with an entry for each pair of states. Initially all entries are. if p F and q F (or vice versa) then distinct(p, q) := repeat for each pair (p, q) and symbol a if distinct(δ(p, a), δ(q, a)) =, then distinct(p, q) := until no changes in table

Minimization Algorithm. Remove states that are not reachable from the initial state

Minimization Algorithm. Remove states that are not reachable from the initial state 2. Find all pairs of states that are distinguishable

Minimization Algorithm. Remove states that are not reachable from the initial state 2. Find all pairs of states that are distinguishable 3. Collapse pairs that are not distinguishable

Example A B C D E H G F

Example A B C D E H G F

Example B C E F G H A B C E F G A B C E H G F

Example B C E F G H A B C E F G A B C E H G F

Example B C E F G H A B C E F G A B C E H G F

Example B C E F G H A B C E F G A B C E H G F

Example : : 2 : 3 : {A, B, E, F, G, H}, {C} {A, E, G}, {B, H}, {F }, {C} {A, E}, {G}, {B, H}, {F }, {C} {A, E}, {G}, {B, H}, {F }, {C} No change from 2 to 3, so stop.

Example (2) Remove unreachable states. DFA M

Example (2) Remove unreachable states. DFA M

Example (2) :

Example (2) : {A, B, C}, {D, E}.

Example (2) : {A, B, C}, {D, E}. :

Example (2) : {A, B, C}, {D, E}. : {A}, {B, C}, {D, E}.

Example (2) : {A, B, C}, {D, E}. : {A}, {B, C}, {D, E}. 2 :

Example (2) : {A, B, C}, {D, E}. : {A}, {B, C}, {D, E}. 2 : {A}, {B, C}, {D, E}.

Optimal Algorithms for Regular Languages : {A, B, C}, {D, E}. : {A}, {B, C}, {D, E}. 2 : {A}, {B, C}, {D, E}.

Roadmap DFA minimization: Minimize a given DFA M by merging indistinguishable states (possibly locally optimal) done In DFA minimization, a minimal (locally optimal) DFA is a minimum (globally optimal) DFA. Test if the two given DFAs are equivalent. Revisit Myhill-Nerode Theorem.

Decide if two given DFAs accpet the same language We would like to test if two DFAs M = (Q M, Σ M, δ M, q M, F M ) and N = (Q N, Σ N, δ N, q N, F N ) accept the same language or not.

Decide if two given DFAs accpet the same language We would like to test if two DFAs M = (Q M, Σ M, δ M, q M, F M ) and N = (Q N, Σ N, δ N, q N, F N ) accept the same language or not.. Run the table-filling algorithm on both DFAs simultaneously.

Decide if two given DFAs accpet the same language We would like to test if two DFAs M = (Q M, Σ M, δ M, q M, F M ) and N = (Q N, Σ N, δ N, q N, F N ) accept the same language or not.. Run the table-filling algorithm on both DFAs simultaneously. 2. M and N accept the same language iff q M qn.

Table-filling Algorithm Gives a Globally Optimal DFA Very short proof sketch: M = (Q M, Σ M, δ M, q M, F M ): DFA output by the algorithm N = (Q N, Σ N, δ N, q N, F N ): a globally optimal DFA For the sake of contradiction suppose Q N < Q M. Then one can find q M i q M j such that q M i q N t q M j for some q N t Q N.

Isomorphism Definition Let M = (Q, Σ, δ, q, F ) and M 2 = (Q 2, Σ, δ 2, q 2, F 2 ) be two DFAs. A function f : Q Q 2 is said to be isomorphism iff f is bijective, i.e., one-to-one and onto f (q ) = q 2 For every p Q and a Σ, f (δ (p, a)) = δ 2 (f (p), a) q F iff f (q) F 2

Isomorphism Definition Let M = (Q, Σ, δ, q, F ) and M 2 = (Q 2, Σ, δ 2, q 2, F 2 ) be two DFAs. A function f : Q Q 2 is said to be isomorphism iff f is bijective, i.e., one-to-one and onto f (q ) = q 2 For every p Q and a Σ, f (δ (p, a)) = δ 2 (f (p), a) q F iff f (q) F 2 M and M 2 are said to be isomorphic if there is an isomorphism f from M to M 2.

Isomorphism Definition Let M = (Q, Σ, δ, q, F ) and M 2 = (Q 2, Σ, δ 2, q 2, F 2 ) be two DFAs. A function f : Q Q 2 is said to be isomorphism iff f is bijective, i.e., one-to-one and onto f (q ) = q 2 For every p Q and a Σ, f (δ (p, a)) = δ 2 (f (p), a) q F iff f (q) F 2 M and M 2 are said to be isomorphic if there is an isomorphism f from M to M 2. Thus, if M and M 2 are isomorphic then they are the same machine except for possibly renaming states.

Myhill-Nerode Theorem implies... Theorem For any regular language L, threre is a unique (upto isomorphism) DFA with fewest states that recognizes L.