Chapter 2: Finite Automata

Similar documents
cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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,

Uses of finite automata

Chapter Five: Nondeterministic Finite Automata

Decision, Computation and Language

Lecture 3: Nondeterministic Finite Automata

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

Theory of Computation

Chapter 5. 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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Finite Automata. Mahesh Viswanathan

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

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

Nondeterministic Finite Automata

Introduction to Turing Machines. Reading: Chapters 8 & 9

Turing machines Finite automaton no storage Pushdown automaton storage is a stack What if we give the automaton a more flexible storage?

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

1 Showing Recognizability

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

Closure under the Regular Operations

Constructions on Finite Automata

CS243, Logic and Computation Nondeterministic finite automata

Formal Language and Automata Theory (CS21004)

Automata Theory (2A) Young Won Lim 5/31/18

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Computation Histories

Constructions on Finite Automata

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

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

Nondeterministic Finite Automata. Nondeterminism Subset Construction

3515ICT: Theory of Computation. Regular languages

Closure under the Regular Operations

Part I: Definitions and Properties

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

Lecture 1: Finite State Automaton

Theory of Computation (IV) Yijia Chen Fudan University

Further discussion of Turing machines

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

Theory of Languages and Automata

arxiv: v2 [cs.fl] 29 Nov 2013

Finite Automata. Seungjin Choi

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

Nondeterministic finite automata

Finite Automata. Finite Automata

Theory of Computation (IX) Yijia Chen Fudan University

CS 154. Finite Automata, Nondeterminism, Regular Expressions

The Church-Turing Thesis

Languages, regular languages, finite automata

Finite Automata and Regular languages

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Homework 8. a b b a b a b. two-way, read/write

CPSC 421: Tutorial #1

Deterministic Finite Automaton (DFA)

Theory of Computation (I) Yijia Chen Fudan University

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Chapter 6: NFA Applications

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

(Refer Slide Time: 0:21)

Computability Theory

Java II Finite Automata I

CSCE 551: Chin-Tser Huang. University of South Carolina

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

DM17. Beregnelighed. Jacob Aae Mikkelsen

Equivalence of DFAs and NFAs

Non-emptiness Testing for TMs

CSE 135: Introduction to Theory of Computation Optimal DFA

Lecture 17: Language Recognition

Lecture 4 Nondeterministic Finite Accepters

The Turing machine model of computation

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

Computability and Complexity

Chapter 6: Turing Machines

Computability and Complexity

CPS 220 Theory of Computation REGULAR LANGUAGES

Finite Automata and Regular Languages (part III)

Variants of Turing Machine (intro)

Theory of computation: initial remarks (Chapter 11)

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

Automata and Languages

Most General computer?

Chap. 1.2 NonDeterministic Finite Automata (NFA)

CS21 Decidability and Tractability

Nondeterminism. September 7, Nondeterminism

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

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

CS 455/555: Finite automata

Blackhole Pushdown Automata

Intro to Theory of Computation

Computational Models - Lecture 5 1

Pushdown Automata. Reading: Chapter 6


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

Computational Theory

Decidability (intro.)

Student#: CISC-462 Exam, December XY, 2017 Page 1 of 12

Transcription:

Chapter 2: Finite Automata 2.1 States, State Diagrams, and Transitions Finite automaton is the simplest acceptor or recognizer for language specification. It is also the simplest model of a computer. A state is the condition with respect to structure, form, constitution, and phase. 1

2.2 Deterministic Finite Automata Definition A deterministic finite automaton (DFA) M is specified by a quintuple M = (Q, Σ, δ, s, F ) where Q is an alphabet of state symbols; Σ is an alphabet of input symbols; δ : Q Σ Q is a transition function; s in Q is the start state; and F Q is a set of final states. 2

DFAs are intended to read input words and accept or reject them, that is they are recognizers. To see how DFAs do this we treat them from a machine-oriented viewpoint. Input tape Read head Cells Finite control 3

Let M = (Q, Σ, δ, s, F ) be a DFA, then we view it as a machine (a primitive computer) which has an input tape (or file) of cells, a reading head, and a finite control: The finite control knows the transition function and the current state. The transition function and current state are analogous to a program and the current statement being executed (instruction counter). The input tape contains the input word, one symbol to each cell of the tape. 4

The DFA is initialized with an input word x as follows: 1. x is placed on the input tape one symbol to a cell. 2. The reading head is positioned over the leftmost cell. 3. The current state is set to s. 4. The DFA is started. 5

The DFA, once started, begins its computation on the input word. As with any computer it has a basic execute cycle: 1. The symbol under the reading head is read, that is, the current symbol. If there is no symbol under the reading head the DFA terminates. This occurs when the whole input word has been read. 2. The next state is computed from the current state and symbol using the transition function, that is δ(current state, current symbol)=next state. If the current state is undefined the DFA aborts. 3. The reading head moves one cell to the right. 4. The next state becomes the current state and the execute cycle has been completed. 6

Definition Let M = (Q, Σ, δ, s, F ) be a DFA. We say that a word in QΣ is a configuration of M. It represents the current state of M and the remaining unread input of M. A configuration of a DFA, M, contains all the information necessary to continue M s computation. In programming parlance it is equivalent to a dump of the current value of all variables of a program and the current position in the program. 7

Definition Let M = (Q, Σ, δ, s, F ) be a DFA. If px and qy are two configurations of M, then we write px qy, if x = ay for some a in Σ, and δ(p, a) = q. We say px yields qy. Observe that is a binary relation over QΣ For k 1, we write px k qy if k = 1 and px qy, or k > 1 and there exists a configuration rz such that px rz and rz k 1 qy. 8

We write px + qy, where + is the trsnsitive closure of, if px k qy, for some k 1. We write px qy, where is the reflexive trsnsitive closure of, if either px = qy or px + qy. We say that the sequence of configurations given by px qy is a configuration sequence. 9

We can formally define acceptance by a DFA and the language of a DFA as follows. Definition Let M = (Q, Σ, δ, s, F ) be a DFA. We say that a word x in Σ is accepted by M if sx f, for some f in F. We say that sx f is an accepting configuration sequence. A word that is not accepted is said to be rejected. The set of words accepted by M, called the language accepted, defined, or recognized by M is denoted by L(M) and is defined as L(M) = {x : x is in Σ and sx f, for some f in F }. 10

The notion of acceptance has caused DFA to stand for deterministic finite acceptor in some circles. We say that L Σ is a DFA language if there is a DFA, M, with L = L(M). The collection of all DFA languages is denoted by L DF A and is called the family of DFA languages. 11

DFA MEMBERSHIP INSTANCE: A DFA, M = (Q, Σ, δ, s, F ), and a word x in Σ. QUESTION: Is x in L(M)? Definition If the transition function of a DFA is total we say that the DFA is complete and otherwise we say it is incomplete. Every incomplete DFA can be transformed into a complete one while preserving its language. 12

Example Let L i = {a i b i }, i 1. Construct DFAs, M i, accepting L i, for each i 1. Let K = j=1 L j K = {a i b i, : i 1}. Claim: K is not a DFA language. There is a language that is not a DFA language. The family of all DFA language over Σ is enumerable. 13

Definition Let M 1 and M 2 be two DFAs. If L(M 1 ) = L(M 2 ) we say that M 1 and M 2 are equivalent. Theorem 2.2.1 Let M = (Q, Σ, δ, s, F ) be an incomplete DFA, that is, there is a pair (q, a) in Q Σ such that δ(q, a) = undef. Then a DFA M can be constructed such that M is complete and L(M ) = L(M). Consider a computer implementation of DFAs. 14

2.3 Nondeterministic Finite Automata Definition A nondeterministic finite automaton (NFA) M is specified by a quintuple M = (Q, Σ, δ, s, F ) where Q is an alphabet of state symbols; Σ is an alphabet of input symbols; δ Q Σ Q is a transition relation; s in Q is the start state; and F Q is a set of final states. 15

For a triple (p, a, q) in δ, p corresponds to the current state, a to the current input symbol, and q to a next state. Clearly an NFA, (Q, Σ, δ, s, F ), is a DFA if for all p in Q and all a in Σ, there is at most one triple (p, a, q) in δ, for some q. When we are unconcerned about a finite automaton being deterministic or nondeterministic we refer to it simply as an FA. Remark: It is sometimes convenient to consider the transition relation δ as a function, which, in general, gives state sets, that is δ : Q Σ 2 Q is defined by For all p in Q and for all a in Σ: δ(p, a) = {q : (p, a, q) is in δ}. 16

Definition Let M = (Q, Σ, δ, s, F ) be an NFA. A configuration of M is a word in QΣ, as for DFAs. Given two configurations px and qy of M, we write px qy in M if x = ay for some a in Σ and (p, a, q) is in δ. Similarly, we write px k qy in M if either k = 1, when 1 is identical to or x = az, for some a in Σ and some z in Σ +, and there is an r such that px rz and rz k 1 qy. We write px + qy if px k qy for some k 1, and, finally, px qy if either px = qy or px + qy. 17

Definition Given M = (Q, Σ, δ, s, F ), an NFA, we say a word x in Σ is accepted if there is a configuration sequence sx q, for some q in F, and is rejected otherwise. The language of M, denoted by L(M) as before, is defined by L(M) = {x : x is in Σ and sx q, for some q in F }. A language L Σ is said to be an NFA language if there exists an NFA, M, with L = L(M) and we say two NFAs, M 1 and M 2, are equivalent if L(M 1 ) = L(M 2 ) and inequivalent otherwise. Finally, the family of NFA languages is denoted by L NF A. NFAs are simpler to define in many cases and, moreover, we can always construct a DFA from a given NFA which accepts exactly the same language. 18

Definition Let M = (Q, Σ, δ, s, F ) be an NFA. A super-configuration of M has the form Kx where K Q and x is in Σ. It means that K is the current set of states and x is the unread portion of the input word. The starting super-configuration for a word x in Σ is {s}x. We extend to super-configurations as follows. We say Kx Ny, for K, N Q and x, y in Σ, if x = ay, for some a in Σ, y in Σ, and N = {q : (p, a, q) is in δ, for some p in K}. We obtain + and as before and if Kx Ny we call it super-configuration sequence. Note that K K for all K Q and x, for all x in Σ. 19

Lemma 2.3.1 Let M = (Q, Σ, δ, s, F ) be an NFA. Then for all words x in Σ and for all K Q Kx N and Kx P implies P = N. Hence, M is deterministic with respect to super-configuration sequences. The above lemma tells us that there is a unique super-configuration sequence, begining with K, for each input word that is read completely. 20

Lemma 2.3.2 Let M = (Q, Σ, δ, s, F ) be an NFA. Then for all words x in Σ, and for all q in Q, qx p if and only if {q}x P, for some P with p in P. Definition Let M = (Q, Σ, δ, s, F ) be an NFA and x a word in Σ. We say x is accepted by M if {s}x P, for some P with P F, otherwise x is rejected. 21

Algorithm NFA to DFA - The Subset Construction. On entry: An NFA, M = (Q, Σ, δ, s, F ). On exit: A DFA, M = (Q, Σ, δ, s, F ) satisfying L(M) = L(M ). begin Let Q = 2 Q, s = {s}, and F = {K : K Q and K F }. We define δ : Q Σ Q by For all K Q and for all a in Σ, δ (K, a) = N if Ka N in M end of Algorithm. 22

Theorem 2.3.3 Given an NFA, M = (Q, Σ, δ, s, F ), then the DFA, M = (Q, Σ, δ, s, F ), obtained by either subset construction satisfies L(M) = L(M ). Theorem 2.3.4 L DF A = L NF A. Thus, NFAs have the some expressive power as DFAs. 23

2.4 Minimization and Simplification Definition Let M = (Q, Σ, δ, s, F ) be an NFA. A state q in Q is reachable or accessible if there exists a word x in Σ such that sx q. If no such word exists q is said to be unreachable or inaccessible. A state q in Q is useful if there exists a word x in Σ such that qx r, for some state r in F. Similarly q is useless if no such word exists. A symbol a in Σ is (symbol) reachable if there exists a reachable state q in Q for which δ(q, a). 24

Definition Let M = (Q, Σ, δ, s, F ) be a DFA. For two distinct states p and q in Q we say p and q are distinguishable if there exists an x in Σ such that px f, qx g and exactly one of f and g is in F. The word x distinguishes p from q. If no such word exists then p and q are indistingushable and we write p q, since ther are equivalent in their action as far as acceptance is concerned. Indeed, they can be merged without affecting the language accepted by M. This forms the basis of the minimization for which we need to refine the notion of indistingushable. Given an integer k 0, we say two distinct states p and q in Q are k-distindushable if there is a word x in Σ, x k, which distindushes p from q. If there is no such word, then we say that p and q are k-indistindushable and we write p k q. These notations are appropriate since both and k are equivalence relations over Q. 25

If we cannot distingush p and q with words of length at most k + 1, for some k 0, then we cannot distingush them with the words of at most k. In other words, p k+1 q implies p k q, for all k 0, that is k+1. k We say k+1 is a refinement of k. Similarly, we obtain k, for all k 0.... k... 1 0 There are at most two equivalence classes formed by 0, F and Q F. We can construct by refining 0 to give 1, 1 to give 2, and so on. To refine i to give i+1 we use the observation For two distinct states p and q with p i q, p i+1 q if and only if, for all a in Σ, δ(p, a) i δ(q, a) 26

Lemma 2.4.1 Let M = (Q, Σ, δ, s, F ) be a DFA with #Q = m. Then two distinct states p and q are indistingushable if and only if they are (m 2)-indistingushable. Let M = (Q, Σ, δ, s, F ), be k and construct a DFA, M = (Q, Σ, δ, s, F ) from k as follows: Let Q = [p] p is in Q and [p] is the equivalence class of p in, s = [s], F = {[p] : p is in F }, and define δ by For all [p] in Q, for all a in Σ, δ ([p], a) = [δ(p, a)] 27

Theorem 2.4.2 Let M = (Q, Σ, δ, s, F ) be a complete DFA having only reachable states and M = (Q, Σ, δ, s, F ) be the corresponding DFA constructed from for M. Then M is a minimal complete DFA equivalent to M. Corollary 2.4.3 Let M = (Q, Σ, δ, s, F ) be a complete DFA and M and M be two minimal complete DFAs equivalent to M. Then M and M are equal apart from a renaming states, that is, there is an isomorphism between M and M. This corollary implies that the following question is decidable: DFA EQUIVALENCE INSTANCE: Two DFAs M 1 and M 2. QUESTION: Is L(M 1 ) = L(M 2 )? 28

2.5 DFAs and Tries Although the definition of DFA cannot be further restricted without restricting the languages accepted by them, there are two restrictions that are of interest. We say a DFA, M = (Q, Σ, δ, s, F ), has a loop if there is a state q in Q and a nonempty word x in Σ + such that qx q; q is said to be a looping state. M is said to be loop-free if it has no looping states, in other words, the state diagram has no cycles. 29

Furthermore, we say M is a tree if it is loop-free and for all states q in Q, q s, there is one and only one state p with δ(p, a) = q, for some a in Σ. Loop-free DFAs accept only finite languages, and this raises the question: Is every finite language accepted by some loop-free DFA? Even if a DFA has loops it may still accept a finite language; therefore, we have the decision problem DFA FINITENESS INSTANCE: A DFA, M = (Q, Σ, δ, s, F ). QUESTION: Is L(M) finite? 30

2.6 λ-fas and Lazy FAs 2.6.1 λ-fas and λ-transitions In the FAs we have discussed so far we require that the reading head move at each step. We now relax the condition by allowing the reading head to remain at a cell during a transition. We call such a transition a λ-transition; the input symbol is ignored. 31

Definition M = (Q, Σ, δ, s, F ) is a λ-nfa, or λ-transition NFA, if δ Q (Σ {λ}) Q. We require, on a λ-transition, that the reading head doesn t move and the input symbol is ignored. Given a configuration px in QΣ we write px qy if x = Ay, for some A in Σ {λ}, and (p, A, q) is in δ; is extended to + and as before. Thus, at each configuration there is not only the choice of transition usual in NFAs, but also the additional possibility of taking λ-transitions. 32

There are two situation in which λ-transitions are useful: The Plus of an NFA The Union of Two NFAs Clearly, every NFA is a λ-nfa, but surprisingly the expressive power of λ-nfas is no more than that of NFAs. Theorem 2.6.1 Let M = (Q, Σ, δ, s, F ) be a λ-nfa; then an equivalent NFA, M, can be constructed from M. 33

2.6.2 Lazy Finite Automata Definition A lazy finite automaton, M, is a quintuple (Q, Σ, δ, s, F ) where Q,, Σ, s, and F are as for FAs, but δ Q Σ Q, a finite transition relation. In other words, transitions are allowed with words rather than just symbols and the empty word. A single move is defined by px qy if x = wy, for some w in Σ, and (p, w, q) is in δ Theorem 2.6.2 Let M be a lazy FA. Then there is a λ-nfa, M, with L(M ) = L(M). 34