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

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

Lecture 1: Finite State Automaton

Pushdown Automata (Pre Lecture)

Deterministic Finite Automaton (DFA)

Extended transition function of a DFA

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Automata and Languages

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

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

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

Nondeterministic Finite Automata

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

CS 208: Automata Theory and Logic

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

Chapter 5. Finite Automata

CMSC 330: Organization of Programming Languages

Finite Automata. Seungjin Choi

CSCE 551 Final Exam, April 28, 2016 Answer Key

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

Chapter Five: Nondeterministic Finite Automata

Nondeterminism. September 7, Nondeterminism

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,

Theory of Computation (I) Yijia Chen Fudan University

Regular Expressions (Pre Lecture)

CS21 Decidability and Tractability

Nondeterministic Finite Automata

Decision, Computation and Language

Java II Finite Automata I

Finite Automata. Finite Automata

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

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Lecture 4 Nondeterministic Finite Accepters

Nondeterministic finite automata

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

Deterministic Finite Automata (DFAs)

Deterministic Finite Automata (DFAs)

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

Nondeterminism and Epsilon Transitions

Closure under the Regular Operations

CS 154 Formal Languages and Computability Assignment #2 Solutions

Formal Models in NLP

Course 4 Finite Automata/Finite State Machines

Context-Free Languages (Pre Lecture)

Sri vidya college of engineering and technology

Equivalence of DFAs and NFAs

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CS 455/555: Finite automata

Deterministic Finite Automata (DFAs)

Intro to Theory of Computation

Takeaway Notes: Finite State Automata

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

Chapter 6: NFA Applications

Computer Sciences Department

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Finite Automata and Languages

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

Finite Automata and Regular Languages

Finite Automata and Regular languages

CS 154, Lecture 3: DFA NFA, Regular Expressions

CS243, Logic and Computation Nondeterministic finite automata

Introduction to Finite-State Automata

Lecture 3: Nondeterministic Finite Automata

Lecture 4: Nondeterministic Finite Automata

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

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

Finite Automata and Regular Languages (part III)

Nondeterministic Finite Automata. Nondeterminism Subset Construction

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

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

Inf2A: Converting from NFAs to DFAs and Closure Properties

Classes and conversions

Computational Models - Lecture 1 1

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

Non-deterministic Finite Automata (NFAs)

CSE 105 Theory of Computation Professor Jeanne Ferrante

Theory of Computation

Chap. 1.2 NonDeterministic Finite Automata (NFA)

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

Finite Automata. Mahesh Viswanathan

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

Closure under the Regular Operations

Automata: a short introduction

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

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

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

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

CISC 4090 Theory of Computation

CSC173 Workshop: 13 Sept. Notes

Computability Theory

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

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

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 )

CS21 Decidability and Tractability

Nondeterministic Finite Automata

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

Theory of Computation

Transcription:

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

Outline Dantam (Mines CSCI-561) Finite Automata Fall 2017 2 / 35

Languages Review Outline Dantam (Mines CSCI-561) Finite Automata Fall 2017 3 / 35

Languages Review Alphabets Symbol: An abstract, primitive, atomic thing Examples: a, x, 4, θ, ℵ,!, Set: An unordered collection, without repetition Alphabet: A non-empty, finite set of symbols Σ B = {0, 1} Σ E = {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z} Σ C = {,,, } Dantam (Mines CSCI-561) Finite Automata Fall 2017 4 / 35

Languages Review String Sequence: An ordered list of objects Example: (1, 2, 3, 5, 8,...) Abbreviated Notation: 12358... Empty (zero-length) sequence: ɛ String: A sequence over some alphabet Γ B = 101010 Γ E = hello Γ C = Dantam (Mines CSCI-561) Finite Automata Fall 2017 5 / 35

Languages Review Languages Language: A set of strings Examples: Alternations of 0 and 1: {ɛ, 01, 10, 0101, 1010, 010101, 101010,...} 0s and 1s with no consecutive 1s: {ɛ, 0, 1, 00, 01, 10, 000, 001, 010, 100, 101, 0000, 0001, 0010, 0100, 0101,...} Dantam (Mines CSCI-561) Finite Automata Fall 2017 6 / 35

Traffic Light Example Outline Dantam (Mines CSCI-561) Finite Automata Fall 2017 7 / 35

Traffic Light Example Traffic Light Example State: NS = {red, yellow, green} EW = {red, yellow, green} timeout = {0, 1} Sensors: Q = {timeout, ns-car, ew-car} gr timeout grt ew-car yr timeout timeout rg timeout rgt ns-car ry Dantam (Mines CSCI-561) Finite Automata Fall 2017 8 / 35

Traffic Light Example Traffic Light w/ Pedestrian Example State: NS = {red, yellow, green}, EW = {red, yellow, green}, timeout = {0, 1}, pedestrian = {0, 1} Sensors: Q = {timeout, ns-car, ew-car, pedestrian} timeout ry ns-car ew-car gr timeout grt ew-car pedestrian yr timeout yrp rg timeout rgt timeout pedestrian ryp timeout rrp timeout rrpt ns-car More: Left-turn arrows Railroad crossings Synchronize with other lights Dantam (Mines CSCI-561) Finite Automata Fall 2017 9 / 35

Traffic Light Example Transition Table gr timeout grt ew-car yr timeout timeout rg timeout rgt ns-car state timeout ns-car ew-car gr grt grt yr yr rg rg rgt rgt ry ry gr ry / SWITCH CASE / e v e n t = n e x t e v e n t ( ) ; switch ( s t a t e ) { case GR: switch ( e v e n t ) { case TIMEOUT: s t a t e = GRT; break ; d e f a u l t : s t a t e = DEAD; } /... / } / LOOKUP TABLE / e v e n t = n e x t e v e n t ( ) ; s t a t e = t a b l e [ s t a t e ] [ e v e n t ] ; Dantam (Mines CSCI-561) Finite Automata Fall 2017 10 / 35

Deterministic Finite Automata Outline Dantam (Mines CSCI-561) Finite Automata Fall 2017 11 / 35

Deterministic Finite Automata Deterministic Finite Automata (DFA) A deterministic finite automaton is a 5-tuple: M = (Q, Σ, δ, q 0, F ), where Q is a finite set call the states Σ is a finite set call the alphabet δ : Q Σ Q is the transition function q0 Q is the start state F Q is the set of accept states Dantam (Mines CSCI-561) Finite Automata Fall 2017 12 / 35

Deterministic Finite Automata Conceptual DFA Operation tape M : Σ {accept, reject} σ = σ 0 } σ 1... {{ σ k 1 } history σ k σ k+1 }... {{ σ n } future Finite Control Q {accept, reject} accept Reach end of tape (string) with control in accept state q F reject Reach end of tape (string) with control not in accept state q F language The language of M is the set of strings accepted by M, L (M) = {x M(x) = accept} Dantam (Mines CSCI-561) Finite Automata Fall 2017 13 / 35

Deterministic Finite Automata Graphical DFA L (M) = {x {0, 1} x ends in 1} states Q Graph Nodes alphabet Σ Graph Edge Labels transition function δ Graph Edges start state q 0 Designed graph node accept states F Double-circled graph nodes start start 0 1 1 q 0 q 1 0 state 0 1 F q 0 q 0 q 1 0 q 1 q 0 q 1 1 Dantam (Mines CSCI-561) Finite Automata Fall 2017 14 / 35

Deterministic Finite Automata Example: FA Design q even q odd L (M) = {w {0, 1} the number of 1s is odd} What state do we need to track? What are the state transitions? What are the start and accept states? 0 0 1 q even 1 q odd 0 0 start 1 q even 1 q odd Dantam (Mines CSCI-561) Finite Automata Fall 2017 15 / 35

Deterministic Finite Automata Example: FA Design continued q even q odd 0 0 q even 1 1 q odd state 0 1 F q even q even q odd 0 q odd q odd q even 1 0 0 start 1 q even 1 q odd Dantam (Mines CSCI-561) Finite Automata Fall 2017 16 / 35

Deterministic Finite Automata Symbolic DFA Semantics Transition Function δ : Q Σ Q Extended Transition Function ˆδ : Q Σ Q base ˆδ(q, ɛ) = q inductive For ω Σ and a Σ, ˆδ(q, ωa) = δ(ˆδ(q, ω), a) Accept ˆδ(q 0, ω) F M accepts ω Reject ˆδ(q 0, ω) F M rejects ω { } Language L (M) = ω Σ ˆδ(q 0, ω) F M recognizes L (M) Dantam (Mines CSCI-561) Finite Automata Fall 2017 17 / 35

Deterministic Finite Automata Example: DFA Simulation start 0 0 1 q even 1 q odd state 0 1 F q even q even q odd 0 q odd q odd q even 1 Simulate the DFA on the following strings: ɛ 01 010 0100 Dantam (Mines CSCI-561) Finite Automata Fall 2017 18 / 35

Deterministic Finite Automata DFA Simulation Algorithm 1: DFA-Simulate(M) Input: M = (Q, Σ, δ, q 0, F ) ; // states,alphabet,transition,start,accept Output: y {accept, reject} 1 q q 0 ; /* Read next symbol on input tape */ 2 σ next() ; 3 while σ EOF do /* Follow state transition */ 4 q δ(q, σ) ; /* Read next symbol on input tape */ 5 σ next() ; 6 if q F then 7 y accept; 8 else 9 y reject; Dantam (Mines CSCI-561) Finite Automata Fall 2017 19 / 35

Deterministic Finite Automata Regular Languages The regular set is the set of languages that can be recognized by DFAs R = {L (M) M is a DFA} A language is a regular language if some DFA accepts it (L R) M, (L = L (M)) What languages are not regular? Dantam (Mines CSCI-561) Finite Automata Fall 2017 20 / 35

Nondeterministic Finite Automata Outline Dantam (Mines CSCI-561) Finite Automata Fall 2017 21 / 35

Nondeterministic Finite Automata Determinism vs. Nondeterminism tape σ 0 σ 1 σ 2 σ 3... Deterministic Transition to single state δ dfa (q i, σ) = q j δ(q 0, σ 0 ) δ(d 1, σ 1 ) δ(d 2, σ 2 ) δ(d 3, σ 3 ) q 0 d 1 d 2 d 3... Nondeterministic Transition to a multiple states δ nfa (q i, σ) = {q j, q k, q l,...} q 0 n 10. n 20.. n 11. Dantam (Mines CSCI-561) Finite Automata Fall 2017 22 / 35

Nondeterministic Finite Automata Example: NFA and Transition Table start a start 0 1 2 q ɛ 0 q ɛ 1 q 2 0 s, followed by 1 s, followed by 2 s b q 0 q 1 q 2 a, b ɛ a state 0 1 2 ɛ F q 0 {q 0 } {q 1 } 0 q 1 {q 1 } {q 2 } 0 q 2 {q 2 } 1 state a b ɛ F q 0 {q 1 } {q 2 } 1 q 1 {q 1, q 2 } {q 2 } 0 q 2 {q 0 } 0 Dantam (Mines CSCI-561) Finite Automata Fall 2017 23 / 35

Nondeterministic Finite Automata Nondeterministic Finite Automata (NFA) A nondeterministic finite automaton is a 5-tuple: N = (Q, Σ, δ, q 0, F ), where Q is a finite set call the states Σ is a finite set call the alphabet δ : Q Σ P (Q) is the transition function q0 Q is the start state F Q is the set of accept states Dantam (Mines CSCI-561) Finite Automata Fall 2017 24 / 35

Nondeterministic Finite Automata NFA vs. DFA Given: NFA N = (Q N, Σ, δ N, q 0,N, F N ) Find: DFA M = (Q M, Σ, δ M, q 0,N, F M ), such that L (M) = L (N) Solution: DFA states are sets of NFA states NFA DFA states Q N Q M = P (Q N ) alphabet Σ Σ transition δ N : Q N Σ P (Q N ) δ M (Q, σ) {q Q N σ-reachable from q i Q} start q 0,N Q N q 0,M = {q Q N ɛ-reachable from q 0,N } accept F N Q N F M = {q m Q M q m F N } Dantam (Mines CSCI-561) Finite Automata Fall 2017 25 / 35

Nondeterministic Finite Automata Practical usage of DFAs vs. NFAs Today s physical computers are deterministic Options: 1. Simulate NFA by tracking all possible current states 2. Convert NFA to DFA by constructing the subsets of NFA state set Which option is better? Dantam (Mines CSCI-561) Finite Automata Fall 2017 26 / 35

Nondeterministic Finite Automata NFA subset construction outines ɛ closure(q) States reachable from q on ɛ transitions move-ɛ closure(q, σ) States reachable from state q after reading symbol σ Construct the reachable subsets of NFA states Dantam (Mines CSCI-561) Finite Automata Fall 2017 27 / 35

Nondeterministic Finite Automata ɛ-closure examples 0 1 2 start q 0 ɛ q 1 ɛ q 2 ɛ-closure(q 0 ) = {q 0, q 1, q 2 } ɛ-closure(q 1 ) = {q 1, q 2 } ɛ-closure(q 2 ) = {q 2 } a start q 0 b a ɛ q 1 a, b q 2 ɛ-closure(q 0 ) = {q 0, q 2 } ɛ-closure(q 1 ) = {q 1 } ɛ-closure(q 2 ) = {q 2 } States reachable from initial state on only ɛ transitions Dantam (Mines CSCI-561) Finite Automata Fall 2017 28 / 35

Nondeterministic Finite Automata ɛ closure Algorithm 2: ɛ-closure(nfa,s,c) Input: NFA, S, C ; // NFA, unvisited states, initial closure Output: C ; // final closure /* visit: P (Q) Q P (Q) 1 Function visit(c,q) is 2 if q c then // base case 3 return c; 4 else // Recursive case 5 return ɛ closure NFA, p, {q} c q p NFA ɛ }{{} ; add q to closure }{{} ɛ-neighbors of q 6 C fold-left(visit, C, S) ; */ Dantam (Mines CSCI-561) Finite Automata Fall 2017 29 / 35

Nondeterministic Finite Automata move-ɛ-closure examples 0 1 2 start q 0 ɛ q 1 ɛ q 2 move-ɛ-closure(q 0, 0) = {q 0, q 1, q 2 } move-ɛ-closure(q 0, 1) = {q 1, q 2 } move-ɛ-closure(q 0, 2) = {q 2 } a start q 0 b a ɛ q 1 a, b q 2 move-ɛ-closure(q 0, a) = {q 0, q 2 } move-ɛ-closure(q 1, a) = {q 1, q 2 } move-ɛ-closure(q 2, a) = {q 0, q 2 } States reachable from initial state after reading one symbol Dantam (Mines CSCI-561) Finite Automata Fall 2017 30 / 35

Nondeterministic Finite Automata move-ɛ closure Algorithm 3: move-ɛ-closure(nfa,q,σ) Input: NFA, Q, σ ; // NFA, initial states, token Output: C ; // reachable states 1 Function visit(c,q) is 2 return ɛ closure NFA, σ reachable from q { }} { p q σ p NFA, c ; }{{} ɛ-reachable after move 3 C fold-left visit,, ɛ closure(nfa, Q, ) ; }{{} ɛ-reachable from Q Dantam (Mines CSCI-561) Finite Automata Fall 2017 31 / 35

Nondeterministic Finite Automata NFA Simulation Algorithm 4: NFA-Simulate(N) Input: N = (Q, Σ, δ, q 0, F ) ; // states,alphabet,transition,start,accept Output: y {accept, reject} 1 c ɛ-closure(q 0 ); /* Read next symbol on input tape */ 2 σ next() ; 3 while σ EOF do /* Follow state transition */ 4 c move-ɛ-closure(n, c, σ)) ; /* Read next symbol on input tape */ 5 σ next() ; 6 if c F then 7 y accept; 8 else 9 y reject; Dantam (Mines CSCI-561) Finite Automata Fall 2017 32 / 35

Nondeterministic Finite Automata NFA to DFA Subset Construction Algorithm 5: NFA-to-DFA Input: N = (Q, Σ, E, q 0, F ) ; // NFA states, alphabet, edges, start, accept Output: M = (Q, Σ, E, q 0, F ) ; // DFA states, alphabet, edges, start, accept 1 q 0 ɛ-closure(q 0) ; 2 Q {q 0 }, E ; /* Construct Subsets */ 3 i 0 ; 4 while i < Q do /* Finding outgoing edges of i th DFA state */ 5 forall σ Σ do /* Check for transition from Q i on symbol σ */ 6 u = move ɛ closure(n, Q i, σ) ; 7 if u then 8 Q Q u ; // Add new subset { } 9 E E Q i σ u ; // Add new edge/transition 10 i i + 1; /* Accept States */ 11 F = {q Q q F } Dantam (Mines CSCI-561) Finite Automata Fall 2017 33 / 35

Nondeterministic Finite Automata NFA to DFA Example NFA 0 1 2 start q ɛ 0 q ɛ 1 q 2 DFA 0 1 2 start 1 2 q 0, q1, q2 q 1, q2 q 2 Dantam (Mines CSCI-561) Finite Automata Fall 2017 34 / 35 2

Nondeterministic Finite Automata NFA to DFA Examples (cont.) a NFA start q 0 b a ɛ q 1 a, b q 2 DFA a start q 0, q 2 b a q 1 b q 2 a b a q 1, q 2 q 0, q 2, q 2 b a Dantam (Mines CSCI-561) Finite Automata Fall 2017 35 / 35