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

Similar documents
Nondeterminism and Epsilon Transitions

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Nondeterministic Finite Automata. Nondeterminism Subset Construction

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

Nondeterministic Finite Automata

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

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 )

Decision, Computation and Language

Chapter Five: Nondeterministic Finite Automata

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

Extended transition function of a DFA

Regular Expressions and Language Properties

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Chapter 5. Finite Automata

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

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

Uses of finite automata

Automata Theory, Computability and Complexity

CS 455/555: Finite automata

Lecture 4 Nondeterministic Finite Accepters

Nondeterministic 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

Inf2A: Converting from NFAs to DFAs and Closure Properties

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Computational Models #1

Computational Models - Lecture 1 1

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,

Computational Models Lecture 2 1

Finite Automata. Finite Automata

Computational Models Lecture 2 1

Theory of Computation (I) Yijia Chen Fudan University

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

Nondeterminism. September 7, Nondeterminism

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

Chap. 2 Finite Automata

Deterministic Finite Automaton (DFA)

Equivalence of DFAs and NFAs

Non-Deterministic Finite Automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Finite Automata Part Two

Lecture 3: Nondeterministic Finite Automata

September 7, Formal Definition of a Nondeterministic Finite Automaton

Regular Expressions. Definitions Equivalence to Finite Automata

CISC 4090 Theory of Computation

Theory of Computation

CSC236 Week 10. Larry Zhang

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Finite Automata and Regular Languages

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

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

Lecture 17: Language Recognition

CSE 105 Theory of Computation Professor Jeanne Ferrante

Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions

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

UNIT-III REGULAR LANGUAGES

Classes and conversions

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

Sri vidya college of engineering and technology

CS 208: Automata Theory and Logic

Finite Automata. Seungjin Choi

Lecture 1: Finite State Automaton

Intro to Theory of Computation

CMSC 330: Organization of Programming Languages

Finite Automata Part Two

Non-deterministic Finite Automata (NFAs)

Computer Sciences Department

Java II Finite Automata I

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

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

Course 4 Finite Automata/Finite State Machines

CS21 Decidability and Tractability

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

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

CS 322 D: Formal languages and automata theory

Homomorphisms and Efficient State Minimization

Nondeterministic finite automata

Automata and Languages

Lecture 2: Regular Expression

Chap. 2 Finite Automata

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

Critical CS Questions

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

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

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

Closure under the Regular Operations

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

CSC236 Week 11. Larry Zhang

Name: Student ID: Instructions:

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

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

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

Methods for the specification and verification of business processes MPB (6 cfu, 295AA)

Notes on State Minimization

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

Chap. 2 Finite Automata

Finite Automata and Regular Languages (part III)

Transcription:

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

Deterministic Finite Automata (DFA) A Deterministic Finite Automata (DFA) is a quintuple A = (Q,,, q 0, F) 1. Q is a finite set of states 2. is a finite set of symbols (alphabet) 3. Delta ( ) is a transition function (q,a) p 4. q 0 is the start state (q 0 Q ) 5. F is a set of final (accepting) states ( F Q ) Transition function takes two arguments: a state and an input symbol. (q, a) = the state that the DFA goes to when it is in state q and input a is received. BİL405 - Automata Theory and Formal Languages 2

Graph Representation of DFA s Nodes = states. Arcs represent transition function. Arc from state p to state q labeled by all those input symbols that have transitions from p to q. Arrow labeled Start to the start state. Final states indicated by double circles. 0 0,1 A 1 B 1 C Start 0 BİL405 - Automata Theory and Formal Languages 3

Alternative Representation: Transition Table Arrow for start state Final states starred * * 0 1 A A B B A C C C C Columns = input symbols Rows = states BİL405 - Automata Theory and Formal Languages 4

Strings Accepted By A DFA An DFA accepts a string w = a 1 a 2... a n if its path in the transition diagram that 1. Begins at the start state 2. Ends at an accepting state This DFA accepts input: 010001 This DFA rejects input: 011001 Start A 0 0,1 1 0 B 1 C BİL405 - Automata Theory and Formal Languages 5

Extended Delta Function Delta Hat The transition function can be extended to ^ that operates on states and strings (as opposed to states and symbols) ^ (q, ) = q ^ (q,xa) = ( ^ (q,x), a) BİL405 - Automata Theory and Formal Languages 6

Language Accepted by a DFA Formally, the language accepted by a DFA A is L(A) = { w ^ (q 0,w) F } Languages accepted by DFAs are called as regular languages. Every DFA accepts a regular language, and For every regular language there is a DFA accepts it BİL405 - Automata Theory and Formal Languages 7

Language Accepted by a DFA 0 0,1 A 1 B 1 C Start 0 This DFA accepts all strings of 0 s and 1 s without two consecutive 1 s. Formally, L(A) = { w w is in {0,1}* and w does not have two consecutive 1 s } BİL405 - Automata Theory and Formal Languages 8

DFA Example A DFA accepting all and only strings with an even number of 0's and an even number of 1's Tabular representation of the DFA BİL405 - Automata Theory and Formal Languages 9

Proofs of Set Equivalence We need to prove that two descriptions of sets are in fact the same set. Here, one set is the language of this DFA, and the other is the set of strings of 0 s and 1 s with no consecutive 1 s. In general, to prove S=T, we need to prove two parts: S T and T S. That is: 1. If w is in S, then w is in T. 2. If w is in T, then w is in S. As an example, let S = the language of our running DFA, and T = no consecutive 1 s. 0 0,1 A 1 B 1 C Start BİL405 - Automata Theory and Formal Languages 10 0

Proof Part 1 : S T To prove: if w is accepted by our DFA then w has no consecutive 1 s. Proof is an induction on length of w. Important trick: Expand the inductive hypothesis to be more detailed than you need. BİL405 - Automata Theory and Formal Languages 11

The Inductive Hypothesis 1. If ^ (A, w) = A, then w has no consecutive 1 s and does not end in 1. 2. If ^ (A, w) = B, then w has no consecutive 1 s and ends in a single 1. Basis: w = 0; i.e., w = ε. (1) holds since ε has no 1 s at all. (2) holds vacuously, since ^ (A, ε) is not B. Important concept: If the if part of if..then is false, the statement is true. BİL405 - Automata Theory and Formal Languages 12

Inductive Step Need to prove (1) and (2) for w = xa. (1) for w is: If ^ (A, w) = A, then w has no consecutive 1 s and does not end in 1. Since ^ (A, w) = A, ^ (A, x) must be A or B, and a must be 0 (look at the DFA). By the IH, x has no 11 s. Thus, w has no 11 s and does not end in 1. BİL405 - Automata Theory and Formal Languages 13

Inductive Step Now, prove (2) for w = xa: If ^ (A, w) = B, then w has no 11 s and ends in 1. Since ^ (A, w) = B, ^ (A, x) must be A, and a must be 1 (look at the DFA). By the IH, x has no 11 s and does not end in 1. Thus, w has no 11 s and ends in 1. BİL405 - Automata Theory and Formal Languages 14

Proof Part 1 : T S Now, we must prove: if w has no 11 s, then w is accepted by our DFA Contrapositive : If w is not accepted by our DFA then w has 11. Key idea: contrapositive of if X then Y is the equivalent statement if not Y then not X. BİL405 - Automata Theory and Formal Languages 15

Using the Contrapositive Every w gets the DFA to exactly one state. Simple inductive proof based on: Every state has exactly one transition on 1, one transition on 0. The only way w is not accepted is if it gets to C. The only way to get to C [formally: ^ (A,w) = C] is if w = x1y, x gets to B, and y is the tail of w that follows what gets to C for the first time. If ^ (A,x) = B then surely x = z1 for some z. Thus, w = z11y and has 11. 0 0,1 A 1 B 1 C Start 0 BİL405 - Automata Theory and Formal Languages 16

Nondeterministic Finite Automata (NFA) A NFA can be in several states at once, or, it can "guess" which state to go to next. A NFA state can have more than one arc leaving from that state with a same symbol. Example: An automaton that accepts all and only strings ending in 01. State q 0 can go to q 0 or q 1 with the symbol 0. BİL405 - Automata Theory and Formal Languages 17

NFA Example What happens when the NFA processes the input 00101 In fact, all missing arcs go to a death state, the death state goes to itself for all symbols, and the death state is a non-accepting state. BİL405 - Automata Theory and Formal Languages 18

Definition of Nondeterministic Finite Automata Formally, a Nondeterministic Finite Automata (NFA) is a quintuple A = (Q,,, q 0, F) 1. Q is a finite set of states 2. is a finite set of symbols (alphabet) 3. Delta ( ) is a transition function from Qx to the powerset of Q. 4. q 0 is the start state (q 0 Q ) 5. F is a set of final (accepting) states ( F Q ) Transition function takes two arguments: a state and an input symbol. (q, a) = the set of the states that the DFA goes to when it is in state q and input a is received. BİL405 - Automata Theory and Formal Languages 19

NFA Table Representation The table representation of this NFA is as follows. NFA is its transition function is BİL405 - Automata Theory and Formal Languages 20

Extended Transition Function for NFA Delta Hat The transition function can be extended to ^ that operates on states and strings (as opposed to states and symbols) Basis: ^ (q, ) = q Induction: If ^ (q,x) = {p 1,p 2,...,p k } for a string x, then ^ (q,xa) = (p i, a) For the string w = xa, we compute ^ (q,x) first, then we follow any transition from any of the states with the symbol a. BİL405 - Automata Theory and Formal Languages 21

Language of a NFA The language accepted by a NFA A is i.e. a string w is accepted by a NFA A iff the states that are reachable from the starting state by consuming w contain at least one final state. BİL405 - Automata Theory and Formal Languages 22

Language of a NFA - Example Let's prove formally that the NFA accepts the language {x01 : x * }. We'll do a mutual induction on the following three statements, BİL405 - Automata Theory and Formal Languages 23

Proof BİL405 - Automata Theory and Formal Languages 24

BİL405 - Automata Theory and Formal Languages 25

Equivalence of DFA and NFA NFA's are usually easier to construct. Surprisingly, for any NFA N there is a DFA D, such that L(D) = L(N), and vice versa. This involves the subset construction, an important example how an automaton B can be generically constructed from another automaton A. Given an NFA we will constract a DFA such that L(D) = L(N) BİL405 - Automata Theory and Formal Languages 26

Subset Construction BİL405 - Automata Theory and Formal Languages 27

Subset Construction - Example BİL405 - Automata Theory and Formal Languages 28

Subset Construction Accessible States We can often avoid the exponential blow-up by constructing the transition table for D only for accessible states S as follows: BİL405 - Automata Theory and Formal Languages 29

Subset Construction Accessible States (example) NFA DFA BİL405 - Automata Theory and Formal Languages 30

Equivalence of DFA and NFA - Theorem Theorem: Let D be the subset DFA of an NFA N. Then L(D) = L(N). Proof: We show on an induction on w that Basis: w =. The claim follows from definition. Induction: So, L(D) =L(N) BİL405 - Automata Theory and Formal Languages 31

Equivalence of DFA and NFA Theorem 2 Theorem: A language L is accepted by some DFA if and only if L is accepted by some NFA. Proof: The if-part is proved by the previous theorem. For the only-if-part, we note that any DFA can be converted to an equivalent NFA by modifying the D to N by the rule BİL405 - Automata Theory and Formal Languages 32

A Bad Case for Subset Construction - Exponential Blow-Up There is an NFA N with n+1 states that has no equivalent DFA with fewer than 2 n states BİL405 - Automata Theory and Formal Languages 33

A NFA for Text Search NFA accepting the set of keywords {ebay, web} BİL405 - Automata Theory and Formal Languages 34

Corresponding DFA for Text Search BİL405 - Automata Theory and Formal Languages 35

NFA with Epsilon Transitions - -NFA -NFA s allow transtions with label. Formally, -NFA is a quintuple A = (Q,,, q 0, F) 1. Q is a finite set of states 2. is a finite set of symbols (alphabet) 3. Delta ( ) is a transition function from Q x { } to the powerset of Q. 4. q 0 is the start state (q 0 Q ) 5. F is a set of final (accepting) states ( F Q ) BİL405 - Automata Theory and Formal Languages 36

-NFA Example An -NFA accepting decimal numbers consisting of: 1. An optional + or - sign 2. A string of digits 3. a decimal point 4. another string of digits One of the strings in (2) and.(4) are optional BİL405 - Automata Theory and Formal Languages 37

-NFA Example - Transition Table Transition Table BİL405 - Automata Theory and Formal Languages 38

Epsilon Closure We close a state by adding all states reachable by a sequence... Inductive denition of ECLOSE(q) Basis: q ECLOSE(q) Induction: p ECLOSE(q) and r (p, ) r ECLOSE(q) BİL405 - Automata Theory and Formal Languages 39

Epsilon Closure ECLOSE(1) = {1,2,3,4,6} ECLOSE(2) = {2,3,6} ECLOSE(3) = {3,6} ECLOSE(4) = {4} ECLOSE(5) = {5,7} ECLOSE(6) = {6} ECLOSE(7) = {7} BİL405 - Automata Theory and Formal Languages 40

Exdended Delta for -NFA Inductive definition ^ of for -NFA Basis: Induction: BİL405 - Automata Theory and Formal Languages 41

Given an -NFA Equivalence of DFA and -NFA we will construct a DFA such that L(D) = L(E) BİL405 - Automata Theory and Formal Languages 42

Equivalence of DFA and -NFA Subset Construction BİL405 - Automata Theory and Formal Languages 43

Equivalence of DFA and -NFA Subset Construction - Example BİL405 - Automata Theory and Formal Languages 44

Equivalence of DFA and -NFA - Theorem Theorem: A language L is accepted by some -NFA E if and only if L is accepted by some DFA D. Proof: We use D constructed using subset-construction and show by induction that Basis: Induction: BİL405 - Automata Theory and Formal Languages 45