Deterministic Finite Automata

Similar documents
Deterministic Finite Automata

Nondeterministic Finite Automata

Models of Computation I: Finite State Automata

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Theory of Computation

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

(pp ) PDAs and CFGs (Sec. 2.2)

Turing Machines Part II

Classes and conversions

CS 154, Lecture 3: DFA NFA, Regular Expressions

Sri vidya college of engineering and technology

Nondeterminism. September 7, Nondeterminism

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Advanced Automata Theory 2 Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

More on Regular Languages and Non-Regular Languages

Finite State Machines 2

3515ICT: Theory of Computation. Regular languages

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

Proving languages to be nonregular

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

CSC236 Week 10. Larry Zhang

Turing Machines. COMP2600 Formal Methods for Software Engineering. Katya Lebedeva. Australian National University Semester 2, 2014

Finite Automata (contd)

The Pumping Lemma. for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.

Computational Models Lecture 2 1

Finite Automata. Mahesh Viswanathan

Theory of Computation

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Decision, Computation and Language

Conflict Removal. Less Than, Equals ( <= ) Conflict

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Inf2A: The Pumping Lemma

UNIT-III REGULAR LANGUAGES

What we have done so far

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

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

(pp ) PDAs and CFGs (Sec. 2.2)

Chapter 5. Finite Automata

Deterministic finite Automata

Theory of Computation 3 Deterministic Finite Automata

Automata: a short introduction

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

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Constructions on Finite Automata

Finite-State Machines (Automata) lecture 12

Compilers. Lexical analysis. Yannis Smaragdakis, U. Athens (original slides by Sam

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

Computational Models #1

Inf2A: Converting from NFAs to DFAs and Closure Properties

Computational Models - Lecture 5 1

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

Context Free Grammars

Theory of Computation 4 Non-Deterministic Finite Automata

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

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

CSE 105 THEORY OF COMPUTATION

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove

Computational Models Lecture 2 1

CS 154 Introduction to Automata and Complexity Theory

Finite State Automata Design

COMP4141 Theory of Computation

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Computational Theory

CS375: Logic and Theory of Computing

Pushdown Automata. Reading: Chapter 6

Nondeterministic Finite Automata

Automata and Formal Languages - CM0081 Determinist Finite Automata

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Nondeterministic Finite Automata and Regular Expressions

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

CS 208: Automata Theory and Logic

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

Computational Models: Class 3

Alan Bundy. Automated Reasoning LTL Model Checking

CISC4090: Theory of Computation

Computational Models: Class 5

Turing Machines Part III

Regular Expressions and Language Properties

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Computational Models - Lecture 4

CSE 105 THEORY OF COMPUTATION

Büchi Automata and their closure properties. - Ajith S and Ankit Kumar

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

Theory of Computation Lecture 1. Dr. Nahla Belal

Computational Models - Lecture 1 1

Fooling Sets and. Lecture 5

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600/COMP6260 (Formal Methods for Software Engineering)

arxiv: v1 [cs.fl] 19 Mar 2015

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Transcription:

Deterministic Finite Automata COMP2600 Formal Methods for Software Engineering Katya Lebedeva Australian National University Semester 2, 2016 Slides by Ranald Clouston and Katya Lebedeva. COMP 2600 Deterministic Finite Automata 1

A Deterministic Finite State Automaton (DFA) is a quintuple (Σ,S,s 0,F,δ) where 1. Σ is a finite set of input symbols (the alphabet) 2. S is a finite state of states 3. s 0 is the start (or initial) state: s 0 S 4. F is a set of final (or accepting) states: F S 5. δ : S Σ S is a transition function COMP 2600 Deterministic Finite Automata 2

Example alphabet - {0,1} S0 1 S 0 1 1 2 0 S 1 0 states - {S 0,S 1,S 2 } initial state - S 0 final states - {S 2 } transition function 0 1 S 0 S 1 S 0 S 1 S 1 S 2 S 2 S 1 S 0 Note that the actual names of states are irrelevant. COMP 2600 Deterministic Finite Automata 3

Transition Function as a diagram S0 1 S 0 1 1 2 0 S 1 0 as a transition table 0 1 S 0 S 1 S 0 S 1 S 1 S 2 S 2 S 1 S 0 δ(s 0,0) = S 1 δ(s 0,1) = S 0 δ(s 1,0) = S 1 δ(s 1,1) = S 2 δ(s 2,0) = S 1 δ(s 2,1) = S 0 COMP 2600 Deterministic Finite Automata 4

Extended Transition Function We want to extend δ to multiple transitions: δ : S Σ S δ : S Σ S S0 1 S 0 1 1 2 0 S 1 0 Input 0101 takes the DFA from S 0 to S 2. Hence δ (S 0,0101) = S 2. Input 1011 takes the DFA from S 1 to S 0. Hence δ (S 1,1011) = S 0. COMP 2600 Deterministic Finite Automata 5

δ (s,w) = q automaton to state q. In other words: If and denotes that starting at state s, the input string w will take the w = a 1 a 2...a n δ(s,a 1 ) = p 1 δ(p 1,a 2 ) = p 2... δ(p n 1,a n ) = q then δ (s,a 1 a 2...a n ) = q COMP 2600 Deterministic Finite Automata 6

Definition by induction Basis: δ (s,ε) = s (1) Induction: δ (s,aα) = δ (δ(s,a),α) (2) Note that a Σ (i.e. a is a symbol) and α is a string. Thus δ is defined by breaking the input string into a single symbol followed by a string. We exploit the fact that strings are defined inductively! Since we informally thinking about δ as operating on a string, it should not matter how we break the input string for δ. Indeed, we can show that for any state s and strings α and β the following holds: δ (s,αβ) = δ (δ (s,α),β) COMP 2600 Deterministic Finite Automata 7

Append Theorem δ (s,αβ) = δ (δ (s,α),β) Proof: By induction on the length of α. Base case: α = ε LHS = δ (s,εβ) = δ (s,β) RHS = δ (δ (s,ε),β) = δ (s,β) = LHS (by (1)) COMP 2600 Deterministic Finite Automata 8

Inductive case: Suppose δ (s,αβ) = δ (δ (s,α),β) (IH) LHS = δ (s,(aα)β) = δ (s,a(αβ)) = δ (δ(s,a),αβ) (by (2)) = δ (δ (δ(s,a),α),β) (by IH) RHS = δ (δ (s,aα),β) = δ (δ (δ(s,a),α),β) (by (2)) Corollary: when β is a single symbol b δ (s,αb) = δ(δ (s,α),b) COMP 2600 Deterministic Finite Automata 9

Example: S0 1 S 0 1 1 2 0 S 1 0 δ (S 1,1011) = δ (δ(s 1,1),011) = δ (S 2,011) = δ (S 1,11) = δ (S 2,1) = δ (S 0,ε) = S 0 COMP 2600 Deterministic Finite Automata 10

Language accepted by a DFA We say a DFA accepts a string if, starting from the start state, it terminates in one of the final states. More precisely, let A = (S,Σ,δ,s 0,F) be a DFA and w be a string in Σ. We say w is accepted by A if δ (s 0,w) F The language accepted by A is the set of all strings accepted by A: L(A) = {w Σ δ (s 0,w) F} That is, w L(A) iff δ (s 0,w) F. COMP 2600 Deterministic Finite Automata 11

A 1 : S0 1 S 0 1 1 2 0 S 1 0 0011101 takes the machine from state S 0 through the sequence of states S 1, S 1, S 2, S 0, S 0, S 1 to the final state S 2 δ (S 0,0011101) = δ (S 1,011101) = δ (S 1,11101) =... = δ (S 1,1) = S 2 COMP 2600 Deterministic Finite Automata 12

A 1 : S0 1 S 0 1 1 2 0 S 1 0 Strings accepted by A 1 : 01, 001, 101, 0001, 0101, 00101101... Strings not accepted by A 1 : ε, 0, 1, 00, 10, 11, 100... What is the difference between strings that are accepted by A 1 and that are not? How do we justify our guess at this answer? COMP 2600 Deterministic Finite Automata 13

To prove that a machine M accepts the language that is characterised by a predicate P: 1. prove that any string satisfying P is accepted by M 2. prove that any string accepted by M satisfies P Our claim: A 1 accepts the language with only words finishing with 01. We need to prove the following: 1. If a string ends in 01, then it is accepted by A 1. I.e.: for all α Σ, δ (S 0,α01) F 2. If a string is accepted by A 1, then it ends in 01. I.e.: for all w Σ, if δ (S 0,w) F then exists α Σ. w = α01 COMP 2600 Deterministic Finite Automata 14

Part 1: for all α Σ, δ (S 0,α01) = S 2 By the append theorem, δ (S 0,α01) = δ (δ (S 0,α),01) A 1 : Observe that δ (s,01) = S 2 holds for all s S. S0 1 S 0 1 1 2 0 S 1 0 Indeed, there exist only three possible cases: δ (S 0,01) = δ (S 1,1) = S 2 δ (S 1,01) = δ (S 1,1) = S 2 δ (S 2,01) = δ (S 1,1) = S 2 Hence, δ (S 0,α01) = δ (δ (S 0,α),01) = S 2 COMP 2600 Deterministic Finite Automata 15

Part 2: for all w if δ (S 0,w) = S 2 then exists α Σ. w = α01 w = ε δ (S 0,ε) = S 0 and S 0 is not equal to S 2. Hence, the antecedent is false and the claim is true by the rules of propositional logic. w = 1 (w is a single symbol) The antecedent is false because there is no single step path from S 0 to S 2. Hence, the claim is true. w > 1. There are paths from S 0 to S 2 of two or more steps. Suppose δ (S 0,αxy) = S 2. S0 1 S By the corollary to the append theorem, 0 1 δ(δ 2 1 (S 0,αx),y) = S 2. 0 S 1 0 By the definition of δ, y must be 1 and δ (S 0,αx) must be S 1. Similarly, since δ(δ (S 0,α),x) = S 1, x is 0 by the definition of δ. COMP 2600 Deterministic Finite Automata 16

Limitations of DFAs What class of languages can be recognised by DFAs? A very important example: Consider this language: L = { a n b n n N} That is, L = {ε,ab,aabb,aaabbb,a 4 b 4,a 5 b 5,...} This language cannot be recognised by any finite state automaton! This is because DFA cannot remember how many a s it has seen. COMP 2600 Deterministic Finite Automata 17

Proof by contradiction: Suppose A is a DFA that accepts L. That is L = L(A). Each of the following expressions denotes a state of A δ (S 0,a), δ (S 0,aa), δ (S 0,a 3 )... Since this list is infinite and the number of states in A is finite, some of these expressions must denote the same state. Choose distinct i and j such that δ (S 0,a i ) = δ (S 0,a j ). What we have done here is pick two initial string fragments that the automaton will not be able to distinguish in terms of what is allowed for the rest of the string COMP 2600 Deterministic Finite Automata 18

Since a i b i is accepted, we know δ (S 0,a i b i ) F By the append theorem δ (S 0,a i b i ) = δ (δ (S 0,a i ),b i ) F Since δ (S 0,a i ) = δ (S 0,a j ) δ (δ (S 0,a j ),b i ) F δ (δ (S 0,a j ),b i ) = δ (S 0,a j b i ) F Thus a j b i is accepted by A. But a j b i is not in L, contradicting the initial assumption. COMP 2600 Deterministic Finite Automata 19

Pigeon-Hole Principle We used the pigeon-hole principle in the preceding proof: If we have more pigeons than pigeon-holes, then at least two pigeons must be sharing a hole. In our example we have infinitely many pigeons (words of the language) crammed into finitely many holes (states of the automaton). This is a useful technique to prove that a certain infinite language cannot be recognised by a finite state automata. But be careful: there are infinite languages that can be recognised by DFAs, as we have seen. COMP 2600 Deterministic Finite Automata 20

Equivalent Automata Two automata are said to be equivalent if they accept the same language. A 2 : a b b S a S 1 S 2 a b 0 A 3 : b S 3 S a 4 b a a S a S 1 b a,b 0 S 2 b S 3 a b Can we simplify a DFA? Is there an equivalent DFA with fewer states? COMP 2600 Deterministic Finite Automata 21

Equivalent States Two states S j and S k of a DFA are equivalent if, for all input strings w δ (S j,w) F if and only if δ (S k,w) F Note that δ (S j,w) and δ (S k,w) may be different states - we only care that both are in, or not in, F. In the following example, S 2 is equivalent to S 4. a b b A 2 : a S 1 S 2 S a b 0 b S 3 S a 4 b a COMP 2600 Deterministic Finite Automata 22

Algorithm for Finding Equivalent States There is an iterative algorithm to compute a list of equivalence classes of states. The working data structure for the algorithm is a list of groups of states Each group contains states that appear to be equivalent, given the tests we have done so far On each iteration, we test one of the groups with a symbol from the alphabet. If we notice different behaviour, we split the group. COMP 2600 Deterministic Finite Automata 23

Informal Description of the Algorithm Initialise: Divide the states into two groups: a group for non-final states and a group for final states. We assume that the states in the same group are equivalent, and we try to distinguish them. Loop: Pick a group, {s 1,...s j } and a symbol x. If states δ(s i,x) for i = 1, j are all in the same group, then the group {s 1,...s j } is not (yet) split. Otherwise split the group according to the result. Terminate when we cannot any more split any group by any letter of the alphabet. COMP 2600 Deterministic Finite Automata 24

A 2 : a b [[s 0,s 1,s 3 ],[s 2,s 4 ]] b a S 1 S 2 a [[s S a 0,s 1 ],[s 3 ],[s 2,s 4 ]] b 0 b b S 3 S a 4 [[s 0 ],[s 1 ],[s 3 ],[s 2,s 4 ]] a b a [[s 0 ],[s 1 ],[s 3 ],[s 2,s 4 ]] b [[s 0 ],[s 1 ],[s 3 ],[s 2,s 4 ]] COMP 2600 Deterministic Finite Automata 25

Elimination of States Suppose A = (Σ,S,s 0,F,δ) is a DFA with state S k equivalent to state S j. (and S k is not s 0.) We can eliminate S k from this automaton by defining a new automaton A = (Σ,S,s 0,F,δ ) as follows: S is S without S k F is F without S k δ S j (s,w) = δ(s, w) if δ(s,w) = S k otherwise. COMP 2600 Deterministic Finite Automata 26

Example A 2 : a b b a S 1 S 2 S a b 0 b S 3 S a 4 b a Since S 2 S 4 in A 2, we eliminate one of them: S 4. New set of states is {S 0,S 1,S 2,S 3 } New set of final states is {S 2 } New transition function is: a a S 1 b a,b S 0 S 2 b S 3 a b COMP 2600 Deterministic Finite Automata 27

Minimisation of a DFA Consider the DFA below: a a,b b S 1 S 2 a b S 3 None of S 1, S 2, S 3 are equivalent... But S 3 is inaccessible from the start state. That is why it can be deleted (along with the transitions emerging from it). Deleting equivalent and inaccessible states will give a minimal DFA. COMP 2600 Deterministic Finite Automata 28