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

Similar documents
Finite Automata. Seungjin Choi

Finite Automata. Finite Automata

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

CS 154, Lecture 3: DFA NFA, Regular Expressions

Deterministic Finite Automaton (DFA)

Properties of Regular Languages. Wen-Guey Tzeng Department of Computer Science National Chiao Tung University

Automata and Languages

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

Chapter 2: 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

Chapter Five: Nondeterministic Finite Automata

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

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

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

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

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

Chapter 5. Finite Automata

Deterministic Finite Automata (DFAs)

Turing Machines. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Deterministic Finite Automata (DFAs)

Theory of Computation Lecture 1. Dr. Nahla Belal

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

Lecture 1: Finite State Automaton

Nondeterministic Finite Automata

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

Sri vidya college of engineering and technology

Deterministic Finite Automata (DFAs)

Java II Finite Automata I

Nondeterminism and Epsilon Transitions

CSC236 Week 11. Larry Zhang

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

Decision, Computation and Language

CS243, Logic and Computation Nondeterministic finite automata

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

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

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

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

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

Nondeterminism. September 7, Nondeterminism

CMSC 330: Organization of Programming Languages

Lecture 4 Nondeterministic Finite Accepters

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Course 4 Finite Automata/Finite State Machines

Languages. A language is a set of strings. String: A sequence of letters. Examples: cat, dog, house, Defined over an alphabet:

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

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,

Closure under the Regular Operations

Nondeterministic Finite Automata

Lecture 5: Minimizing DFAs

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

CHAPTER 1 Regular Languages. Contents

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

Equivalence of DFAs and NFAs

Theory of Computation

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

CS 455/555: Finite automata

CS 154 Formal Languages and Computability Assignment #2 Solutions

Chapter 2: Finite Automata

Extended transition function of a DFA

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Computer Sciences Department

Non-deterministic Finite Automata (NFAs)

Algorithms for NLP

Lecture 3: Finite Automata. Finite Automata. Deterministic Finite Automata. Summary. Dr Kieran T. Herley

CSE 135: Introduction to Theory of Computation Optimal DFA

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

Languages, regular languages, finite automata

Chapter 6: NFA Applications

Uses of finite automata

Computational Models #1

Deterministic Finite Automata (DFAs)

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

Regular Languages. Kleene Theorem I. Proving Kleene Theorem. Kleene Theorem. Proving Kleene Theorem. Proving Kleene Theorem

Hashing Techniques For Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

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

Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Lecture 3: Nondeterministic Finite Automata

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

CS 322 D: Formal languages and automata theory

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

Lecture 2: Regular Expression

Fooling Sets and. Lecture 5

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

Inf2A: Converting from NFAs to DFAs and Closure Properties

UNIT-III REGULAR LANGUAGES

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

Finite Automata Part Two

TWO-WAY FINITE AUTOMATA & PEBBLE AUTOMATA. Written by Liat Peterfreund

Chapter 3: The Church-Turing Thesis

FINITE STATE MACHINES (AUTOMATA)

Please give details of your answer. A direct answer without explanation is not counted.

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

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

Transcription:

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

Syllabus Deterministic finite acceptor Nondeterministic finite acceptor Equivalence of DFA and NFA Reduction of the number of states 2

Deterministic Finite Acceptor 3

A very low-level machine It has only states (control unit). It has no memory of any type. It has no output. Clock 4

A DFA M is defined by M=(Q,,, q 0, F) Q: a finite set of states : input alphabet (set of symbols) : Q x Q: a total function called transition function q 0 Q: the initial state F Q: set of final states A dfa is an acceptor for strings. 5

Example M=({q 0, q 1, q 2 }, {0,1},, q 0, {q 1 } ), where (q 0, 0)=q 0, (q 0, 1)=q 1, (q 1, 0)=q 0, (q 1, 1)=q 2, (q 2, 0)=q 2, (q 2, 1)=q 1 Transition table 0 1 q 0 q 0 q 1 q 1 q 0 q 2 q 2 q 2 q 1 6

Graph representation 7

How does it work? What does it represent? accept strings reject strings 8

From to * * : Qx * Q * (q,w) = the reached state after reading a string w by starting from state q. * (q, ) = q * (q, wa) = ( * (q, w), a)=p 9

Language L(M) w is accepted by M if *(q 0, w) F w is not accepted by M if *(q 0, w) F The language accepted by M is L(M)= {w * : * (q 0, w) F } 10

What language is accepted by M 11

What language is accepted by M L(M) = {a n b : n 0} 12

DFA design Find a dfa that accepts strings starting with prefix ab, where ={a, b} 13

Find a dfa that accepts strings ending with suffix ab. Problem: we don t know when the input ends until the machine stops Technique: each state records the characteristic of the input string up to the current position 14

Design a dfa for L={w {0,1}* : w contains substring 001} Consider 100001 15

Design a dfa accepting all strings over {0, 1} except those containing substring 001 16

Design a dfa for L = {w {a,b}* : n a (w) is even and n b (w) is odd} 17

Can we design a dfa for L={a n b n : n 1}? 18

Regular languages Definition: a language L is regular if and only if some dfa M accepts L, that is, L=L(M). Show that L={awa : w {a,b}*} is regular. 19

Every finite language L is regular. 20

Questions? What languages are regular? How to determine whether a language L is regular or not? Yes design a DFA for L No show every DFA cannot accept it. Feasible? Find other ways. 21

Nondeterministic Finite Acceptor 22

An imaginary computing model As intermediate object to establish the relation between regular expressions and dfa Find important use in classifying complexity classes 23

An NFA M is defined by M=(Q,,, q 0, F) Q: finite set of states : input alphabet (set of symbols) : Qx( { }) 2 Q : nondeterministic transition function q 0 Q: the initial state F Q: set of final states Note (q 1, a)={q 0, q 2 } -transition: (q 1, )={q 1, q 2 } Unspecified transition: (q 1, b): not defined 24

Example: NFA with -transitions 0 1 q 0 {q 2 } - {q 1 } q 1 - {q 0, q 2 } {q 2 } F={q 0 } q 2 - - - 25

-transition (q 0, )={q 2 } Unspecified (undefined) transition (q 0, 0), Going into a dead state 26

Transition function * *(q i, w)=s : the states reachable from q i with input w q j S if and only if there is a walk, labeled with w, from q i to q j We can insert as many s as we want into w. Example *(q 0, a) = {q 1, q 2 } *(q 1, b) = {q 0 } *(q 0, aa)={q 1, q 2 } *(q 0, ab)= {q 0 } *(q 0, wa)= ڂ p δ (q 0,w) δ (p, a) 27

How to compute * Compute *(q, ) The states are reachable from q by a sequence of - transitions. Note q *(q, ) Note the difference between (q, ) and *(q, ) (q, ) = {p, r}, *(q, ) = {q, p, r, t, s, u} q p t r s u 28

*(q 0, ) = {q 0 }, *(q 1, ) = {q 1, q 2 }, *(q 2, ) = {q 2 }, Compute *(q 0, a) = Compute *(q 1, b) = Compute *(q 0, ab) = ڂ p δ (q,a) δ (p, b) 29

Language accepted by nfa A string w is accepted by nfa M if there is a walk w from q 0 to a final state q f, that is, *(q 0, w) F A string w is not accepted by M if there is not any walk w from q 0 to any final state q f The language L(M) accepted by nfa M is L(M)={ w * : *(q 0, w) F } Note: if *(q 0, w) is undefined (dead), then w is not accepted. 30

Example, For the following nfa, L(M)={ (10) n : n 0} *(q 0, 10111) cannot reach a final state no matter what paths it takes. Thus, 10111 is not accepted by M 31

Design nfa s Design an nfa for L={w {a,b}* : w contains substring abb } 32

Design an nfa for L={w {a,b}* : w does not contain substring abb } Cannot exchange final and non-final states 33

Design an nfa for L={a n b : n 0} {b n a : n 1} 34

Equivalence of nfa and dfa Two finite acceptors M 1 and M 2 are equivalent if and only if L(M 1 )=L(M 2 ) 35

C dfa : the class of dfa s C nfa : the class of nfa s Is the class C nfa more powerful than C dfa? Is there a language accepted by an nfa, but not accepted by any dfa? 36

Convert nfa to dfa: M N =(Q N,, N, q 0, F N ) M D =(Q D,, D, {q 0 }, F D ) Key point: dfa simulates transitions of nfa M N : q 0 {q i, q j,, q k } (state set) by * N M D : [q 0 ] [q i, q j,, q k ] (a state) by * D A set of states in M N is a state in M D q 0 w w w q i q j {q 0 } w {q i q j q k } q k 37

Recursion property M N : {q i, q j,, q k } {p r, p s,, p t } by N* in one step (on input symbol) M D : [q i, q j,, q k ] [p r, p s,, p t ] by D in one step q i a p r q i a p s {q i q j q k } a {p r p s p t } a q i a p t 38

Algorithm: nfa dfa 1. Compute N *(q, a) for all q Q N, a, 2. Start with {q 0 } in Q D 3. Expand to {q i, q j,, q k } from existent states For any unspecified {q i, q j,, q k } and a, compute D ({q i, q j,, q k }, a) = N *(q i, a) N *(q j, a) N *(q k, a) Repeat until all states are expanded. 4. For F D, a state {q i, q j,, q k } is in F D if any of q i, q j,, q k is in F N. {q 0 } is in F D if is accepted by M N 39

Example: Preparation *(q 0, 0) *(q 0, 1) *(q 1, 0) *(q 1, 1) *(q 2, 0) *(q 2, 1) 40

Expand from {q 0 } 41

42

Why correct? For any w +, D ({q 0 }, w) = {q i, q j,, q k } if and only if N *(q 0, w) = {q i, q j,, q k } Base: D ({q 0 }, a) = N *(q 0, a) for any a Hypothesis: true for w n D ({q 0 }, w) = N *(q 0, w) = {q i, q j,, q k } Induction step: true for wa =n+1 D *({q 0 }, wa) = D ({q i, q j,, q k }, a) = N *(q i, a) N *(q j, a) N *(q k, a) = N *(q 0, wa) 43

Some thoughts Every dfa accepts a unique language. For a given language, there are many dfa s that accept it. Questions How do we know two dfa s are equivalent? How do find a minimum-state dfa for a given L, if existing? For any regular language, is the minimum-state dfa s unique? 44

Reduction of States Ideas: Remove inaccessible states Find equivalent states Mark() Merge equivalent states Reduce() 45

Indistinguishable states Two states p and q are indistinguishable if for every w *, *(p, w) F *(q, w) F *(p, w) F *(q, w) F Merge indistinguishable states as a new state. How to find indistinguishable states? 46

Two states are distinguishable if there is w *, *(p, w) F and *(q, w) F, or *(p, w) F and *(q, w) F x p w q 0 y q w States p and q are distinguishable. They cannot be merged. 47

Observation (backward check) Start: Final and non-final states are distinguishable Recursion: if (p, a)=r, (q, a)=s, and (r, s) are distinguishable, then (p, q) are distinguishable. 48

Find distinguishable states: Procedure Mark(): 1. Remove all inaccessible states. 2. For all pairs of states (p, q), if p F and q F, or vice versa, then mark (p, q) as distinguishable. 3. Repeat the following until no un-marked pairs are marked For all pairs (p, q) and a, compute (p, a)=p a and (q, a)=q a. If (p a, q a ) is distinguishable, then mark (p, q) as distinguishable. 49

From equivalence classes to the dfa: Procedure: Reduce() 1. Use Mark() to find equivalence classes. 2. For each class {q i, q j,, q k }, create a state [ij k]. 3. ([ij k], a) = [lm n] if (q r, a)=q p, q r {q i, q j,,q k}, q p {q l, q m,, q n } 4. For each state [ij k], if some r [ij k] and q r F, then[ij k] F. 5. Output the reduced dfa, described above. 50

Example q 0 q 1 q 2 q 3 q 4 q0 q1 q2 q3 q4 51

52

Exercise p 3 p 0 b b b a a p 2 p 4 a b a a p 6 b p1 b a a p 5 53

Remarks For every regular language L, the minimum-state dfa is unique. The minimun-state dfa for L can be found from any dfa for L by the procedure mark() and reduce(). 54

Example Find a minimum-state dfa for L={a n b : n 0} {b n a : n 1} 55