Chapter 2: Finite Automata

Similar documents
Chapter 5: Context-Free Languages

Lecture 5: Minimizing DFAs

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Java II Finite Automata I

Chapter 16: Non-Context-Free Languages

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. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Nondeterministic Finite Automata

CSE 135: Introduction to Theory of Computation Optimal DFA

CS154. Non-Regular Languages, Minimizing DFAs

Notes on State Minimization

3515ICT: Theory of Computation. Regular languages

What we have done so far

Chapter 5. Finite Automata

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

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

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

Lecture 1: Finite State Automaton

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

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

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

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

Nondeterministic Finite Automata

Lecture 4 Nondeterministic Finite Accepters

Lecture 3: Nondeterministic Finite Automata

Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions

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

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

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

CS 154 Formal Languages and Computability Assignment #2 Solutions

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

Constructions on Finite Automata

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

Lexical Analysis. DFA Minimization & Equivalence to Regular Expressions

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

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

Deterministic finite Automata

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

Lecture 2: Regular Expression

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

This lecture covers Chapter 6 of HMU: Pushdown Automata

Theory of Computation

Nondeterministic Finite Automata. Nondeterminism Subset Construction

CSC236 Week 11. Larry Zhang

More on Regular Languages and Non-Regular Languages

TDDD65 Introduction to the Theory of Computation

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

Nondeterministic finite automata

Uses of finite automata

Foundations of

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

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

Computational Theory

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

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

Lecture 7 Properties of regular languages

Constructions on Finite Automata

Deterministic Finite Automata (DFAs)

Extended transition function of a DFA

Deterministic Finite Automata (DFAs)

Formal Language and Automata Theory (CS21004)

Computational Models - Lecture 5 1

Minimization of DFAs

DFA to Regular Expressions

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

Sri vidya college of engineering and technology

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Computational Models - Lecture 3

Equivalence of DFAs and NFAs

CSci 311, Models of Computation Chapter 4 Properties of Regular Languages

0.1 Minimizing Finite State Machines

Deterministic Finite Automaton (DFA)

Homomorphisms and Efficient State Minimization

Chap. 1.2 NonDeterministic Finite Automata (NFA)

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

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

COMP4141 Theory of Computation

Johns Hopkins Math Tournament Proof Round: Automata

Deterministic Finite Automata (DFAs)

Chapter 2: Finite Automata

Non-deterministic Finite Automata (NFAs)

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

Proofs, Strings, and Finite Automata. CS154 Chris Pollett Feb 5, 2007.

Finite Automata and Regular languages

Harvard CS 121 and CSCI E-207 Lecture 6: Regular Languages and Countability

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

Finite Automata and Regular Languages (part II)

Nondeterministic Finite Automata

Further discussion of Turing machines

c 1998 Society for Industrial and Applied Mathematics Vol. 27, No. 4, pp , August

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CMSC 330: Organization of Programming Languages

CS21 Decidability and Tractability

Theory of Computation (I) Yijia Chen Fudan University

Languages, regular languages, finite automata

Equivalence. See section 4.4 of the text

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

Lecture 4: More on Regexps, Non-Regular Languages

1 Showing Recognizability

Transcription:

Chapter 2: Finite Automata Peter Cappello Department of Computer Science University of California, Santa Barbara Santa Barbara, CA 93106 cappello@cs.ucsb.edu Please read the corresponding chapter before attending this lecture. These notes are supplemented with figures, and material that arises during the lecture in response to questions. Please report any errors in these notes to cappello@cs.ucsb.edu. I ll fix them immediately. Based on An Introduction to Formal Languages and Automata, 3rd Ed., Peter Linz, Jones and Bartlett Publishers, Inc. 1

2.4 Reduction of the Number of States in Finite Automata Any DFA defines a unique language, but the converse is not true. Example: (Draw 2 distinct DFAs that accept the same language.) We present an algorithm that, given a DFA, produces an equivalent DFA with the minimum states possible. Defn. 2.8 2 states p and q of a DFA are indistinguishable if w Σ, δ (p, w) F δ (q, w) F. 2 states p and q of a DFA are distinguishable if they are not indistinguishable: If w Σ, δ (p, w) F and δ (q, w) / F. The binary relation q is indistinguishable from p, I(p, q) is an equivalence relation: 2

p Q, I(p, p), I(p, q) I(q, p), (I(p, q) I(q, r)) I(p, r). Thus, the indistinguishability relation partitions Q. (Informally indicate this on the example.) First, here is a procedure for marking pairs of states distinguishable. Imagine a table with a row for every state and a column for every state. Entry (p, q) is marked if p is distinguishable from q. 3

Procedure mark 1. Remove all inaccessible states. (a) Do a DFS, starting at q 0, marking visited nodes reachable. (b) Remove all nodes that are not marked reachable. 2. p, q Q, if p F and q / F or vice versa, mark (p, q) distinguishable. 3. Repeat { p, q Q and a Σ, (a) compute δ(p, a) = p a and δ(q, a) = q a. (b) If (p a, q a ) distinguishable, mark (p, q) distinguishable. } until ( no previously unmarked pairs are marked ). 4

Thm. 2.3: Procedure mark, applied to any DFA M = (Q, Σ, δ, q 0, F ), terminates and determines all pairs of distinguishable states. Proof: 1. The procedure terminates, since the number of state pairs is finite. 2. It is clear that if a state pair is marked, then it is distinguishable. 3. We prove the converse: if a state pair is distinguishable, then it is marked. 4. First, we prove that after the n th iteration of the Repeat step, a state pair is marked if its component states are distinguishable by a string w, w n. (a) Basis n = 0: Step 2 marks all state pairs that are distinguishable by λ. 5

(b) Induction hypothesis: Assume for i = 0,..., n 1 that after i iterations of the Repeat step, a state pair is marked if its component states are distinguishable by a string w, w i. (c) Induction step: i. Consider state pair (p, q) that is distinguishable by a string of length n, but not of length n 1. ii. Let w = va be a string of length n that distinguishes them. iii. δ (p, v) = p v δ (q, v) = q v. Since (p, q) are not distinguishable by any string of length n 1, the pair (p, q) is not marked after the n 1 th iteration. iv. The nth character distinguishes them. 6

v. This is detected during the n th iteration of the Repeat step: δ(p v, a) = p a δ(q v, a) = q a, and either p a F and q a / F or vice versa. vi. (p, q) is marked after the n th iteration of the Repeat step. 5. Assume that the Repeat step terminates after n iterations. 6. Then, during the n th iteration, no new state pairs were marked. 7. If we add any character to the string and iterate again, we must get the same result. 8. Therefore, when the Repeat step terminates, all distinguishable states have been marked. 7

Procedure mark identifies each pair of distinguishable states. We then identify the equivalence classes, P, of indistinguishable states: Procedure partition 1. Let S = Q be a set of states not assigned to an equivalence class. Let P = be the set of equivalence classes. 2. While (S ) { (a) Insert new equivalence class C into P. (b) Let q S. Insert q into C. Delete q from S. (c) For all p S indistinguishable from q, Insert p into C. Delete p from S. } 8

Procedure reduce Given DFA M = (Q, Σ, δ, q 0, F ), construct DFA M = ( Q, Σ, δ, q 0, F ): 1. Invoke procedure mark to find all pairs of distinguishable states. 2. Invoke procedure partition to partition Q into equivalence classes. 3. For each equivalence class {q i, q j,..., q k }, create a state labelled ij k in Q. 4. For each transition rule of M of the form δ(r, a) = p, where r {q i, q j,..., q k } and p {q l, q m,..., q n }, Add to δ the transition: δ(ij k, a) = lm n. 5. q 0 is that state of M whose label includes q 0. 6. F is the set of states whose label includes i such that q i F. 9

Example: (Apply mark, partition, and reduce to a DFA.) Thm. 2.4: Given a DFA M, applying procedure reduce yields another DFA M such that L(M) = L( M) and there is no DFA with fewer states that accepts L(M). Proof: There are 2 things to prove: 1. L(M) = L( M). 2. There is no DFA with fewer states that accepts L(M). Part 1 can be done by induction on w, the input (in a manner similar to showing the equivalence of DFAs and NFAs). We now show part 2 by contradiction. 1. Let M have states {p 0, p 1,..., p m } with initial state p 0. 10

2. Assume there is an equivalent DFA M with transition function δ and initial state q 0 with fewer states. 3. Since M has no inaccessible states, there must be distinct strings w 1, w 2,..., w m such that δ (p 0, w i ) = p i, i = 1, 2,..., m. 4. Since M has fewer states than M, there must be at least 2 strings, w k and w l, such that δ (q 0, w k ) = δ (q 0, w l ). 5. Since p k is distinguishable from p l, there is a string x such that is a final state, and δ (p 0, w k x) = δ (p k, x) δ (p 0, w l x) = δ (p l, x) 11

is not a final state (or vice versa): w k x L( M) and w l x / L( M) or vice versa. 6. But, δ (q 0, w k x) = δ (δ (q 0, w k ), x) = δ (δ (q 0, w l ), x) = (δ (q 0, w l x). Thus, w k x L(M ) and w l x L(M ) or w k x / L(M ) and w l x / L(M ). 7. This contradicts the assumption that there is a DFA with fewer states than M that is equivalent to M. 12