Deterministic finite Automata

Similar documents
Constructions on Finite Automata

Constructions on Finite Automata

Regular expressions and Kleene s theorem

Regular expressions and Kleene s theorem

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

Lecture 3: Nondeterministic Finite Automata

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

Extended transition function of a DFA

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Nondeterminism. September 7, Nondeterminism

Nondeterministic Finite Automata

Deterministic Finite Automaton (DFA)

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

The Pumping Lemma: limitations of regular languages

3515ICT: Theory of Computation. Regular languages

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Nondeterministic finite automata

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

Computational Models - Lecture 1 1

Finite Automata. Finite Automata

September 7, Formal Definition of a Nondeterministic Finite Automaton

Theory of Computation

Computational Models #1

Finite Automata. Mahesh Viswanathan

Chapter Five: Nondeterministic Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSC236 Week 11. Larry Zhang

Closure under the Regular Operations

Chapter 2: Finite Automata

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

CS 121, Section 2. Week of September 16, 2013

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

Uses of finite automata

Deterministic Finite Automata (DFAs)

Equivalence of DFAs and NFAs

Deterministic Finite Automata (DFAs)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Non-deterministic Finite Automata (NFAs)

Decision, Computation and Language

Finite-State Machines (Automata) lecture 12

Nondeterministic Finite Automata

Lecture 3: Finite Automata

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

Regular expressions and Kleene s theorem

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

Chapter 2: Finite Automata

CSC236 Week 10. Larry Zhang

Automata: a short introduction

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

Theory of Computation Lecture 1. Dr. Nahla Belal

Formal Definition of Computation. August 28, 2013

Lecture 3: Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Nondeterministic Finite Automata

Computational Models - Lecture 4

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Homework 1 Due September 20 M1 M2

Lecture 1: Finite State Automaton

CS 154, Lecture 3: DFA NFA, Regular Expressions

Deterministic Finite Automata

Formal Language and Automata Theory (CS21004)

Computational Models Lecture 2 1

Languages, regular languages, finite automata

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

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Computer Sciences Department

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 )

Computational Models - Lecture 5 1

Turing Machines Part III

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

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

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

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

CSE 135: Introduction to Theory of Computation Optimal DFA

Fooling Sets and. Lecture 5

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

Announcements. Problem Set Four due Thursday at 7:00PM (right before the midterm).

Lecture 4: Finite Automata

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

Finite Automata (contd)

Course 4 Finite Automata/Finite State Machines

Java II Finite Automata I

Finite Automata Part One

CMP 309: Automata Theory, Computability and Formal Languages. Adapted from the work of Andrej Bogdanov

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

CSC173 Workshop: 13 Sept. Notes

UNIT-III REGULAR LANGUAGES

CS 322 D: Formal languages and automata theory

Chap. 1.2 NonDeterministic Finite Automata (NFA)

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

Introduction to the Theory of Computing

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.

Formal Definition of a Finite Automaton. August 26, 2013

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,

Turing machines and linear bounded automata

Theory of Computation

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

Transcription:

Deterministic finite Automata Informatics 2A: Lecture 3 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 21 September, 212 1 / 29

1 Languages and Finite State Machines What is a language? Regular languages and finite state machines: recap 2 Deterministic finite automata 3 2 / 29

Languages and alphabets What is a language? Regular languages and finite state machines: recap Throughout this course, languages will consist of finite sequences of symbols drawn from some given alphabet. An alphabet Σ is simply some finite set of letters or symbols which we treat as primitive. These might be... English letters: Σ = {a, b,..., z} Decimal digits: Σ = {, 1, 2, 3, 4, 5, 6, 7, 8, 9} ASCII characters: Σ = {, 1,..., a, b,...,?,!,...} Programming language tokens : Σ = {if, while, x, ==,...} Words in (some fragment of) a natural language. Primitive actions performable by a machine or system, e.g. Σ = {insert5p, pressbutton1,...} In toy examples, we ll use simple alphabets like {, 1} or {a, b, c}. 3 / 29

What is a language? What is a language? Regular languages and finite state machines: recap A language over an alphabet Σ will consist of finite sequences (strings) of elements of Σ. E.g. the following are strings over the alphabet Σ = {a, b, c}: a b ab cab bacca cccccccc There s also the empty string, which we usually write as ɛ. A language over Σ is simply a (finite or infinite) set of strings over Σ. A string s is legal in the language L if and only if s L. We write Σ for the set of all possible strings over Σ. So a language L is simply a subset of Σ. (L Σ ) (N.B. This is just a technical definition any real language is obviously much more than this!) 4 / 29

Ways to define a language What is a language? Regular languages and finite state machines: recap There are many ways in which we might formally define a language: Direct mathematical definition, e.g. L 1 = {a, aa, ab, abbc} L 2 = {axb x Σ } L 3 = {a n b n n } Regular expressions (see Lecture 5). Formal grammars (see Lecture 9 onwards). Specify some machine for testing whether a string is legal or not. The more complex the language, the more complex the machine might need to be. As we shall see, each level in the Chomsky hierarchy is correlated with a certain class of machines. 5 / 29

Finite state machines What is a language? Regular languages and finite state machines: recap 1 1 even odd This is an example of a finite state machine over Σ = {, 1}. At any moment, the machine is in one of 2 states. For any state, and any symbol in Σ, there s just one new state we can jump to. The state marked with the in-arrow is picked out as the starting state. So any string in Σ gives rise to a sequence of states. Certain states (with double circles) may be designated as accepting. We call a string legal if it takes us from the start state to some accepting state. In this way, the machine defines a language L Σ. 6 / 29

Finite state machines: Clicker question What is a language? Regular languages and finite state machines: recap 1 1 even odd For the finite state machine shown here, which of the following strings is not legal (i.e. not accepted)? 1 ɛ 2 11 3 11 4 11 7 / 29

Deterministic finite automata Deterministic finite automata (DFAs) Formally, a DFA with alphabet Σ consists of: Example: A finite set Q of states, A transition function δ : Q Σ Q, A designated starting state s Q, A set F Q of accepting states. Q = {even, odd} 1 δ : even odd even odd even odd s = even F = {even} 8 / 29

The language associated with a DFA Deterministic finite automata Suppose M = (Q, δ, s, F ) is a DFA with alphabet Σ. We can define a many-step transition function δ : Q Σ Q by δ(q, ɛ) = q δ(q, xu) = δ( δ(q, x), u) for q Q, x Σ, u Σ. Example: δ(odd, 11) = even. This enables us to define the language accepted by M: L(M) = {x Σ δ(s, x) F } We call a language L Σ regular if L = L(M) for some DFA M. Regular languages will occupy us for the next five lectures. 9 / 29

Example Languages and Finite State Machines Deterministic finite automata Let M be the DFA shown earlier: 1 1 even odd Then L(M) can be described directly as follows: L(M) = {x Σ x contains an even number of s} 1 / 29

More examples Languages and Finite State Machines Deterministic finite automata Which of these three languages do you think are regular? L 1 = {a, aa, ab, abbc} L 2 = {axb x Σ } L 3 = {a n b n n } If they are, can you design a DFA that shows this? If not, can you see why not? (We ll revisit this in Lecture 8.) Aside: DFAs are dead easy to implement and efficient to run. (We don t need much more than a two-dimensional array for the transition function δ.) So it s worth knowing when some task can be performed by a DFA. 11 / 29

The Minimization Problem Many different DFAs can give rise to the same language, e.g.: 1 1 1 1 q q1,1 q4 even odd q3 q2 1 1 This raises the question: Is there a best or smallest choice of DFA for a given regular language? 12 / 29

Suppose M = (Q, δ, s, F ) is the following DFA: 1 1 q q1,1 q4 q3 q2 1 1 Informally, we can perform the following steps to reduce M: Throw away unreachable states (in this case, q4). Squish together equivalent states, i.e. states q, q such that x Σ. δ(q, x) F δ(q, x) F In this case, q and q2 are equivalent, as are q1 and q3. Let s write Min(M) for the resulting reduced DFA. In this case, Min(M) is essentially the two-state machine on the previous slide. 13 / 29

Properties of minimization The minimization operation on DFAs has the following pleasing properties: L(Min(M)) = L(M). Min(M) = Min(M ) if and only if L(M) = L(M ). (Consequence.) Min(Min(M)) = Min(M). Min(M) is the smallest DFA (in terms of number of states) with the same language as M. Here = means the two DFAs are isomorphic: that is, the same apart from a possible renaming of states. So up to isomorphism, minimization gives a best, or standard, choice of a DFA for a given regular language. For a formal treatment of minimization, see Kozen chapters 13 16. 14 / 29

Clicker question Languages and Finite State Machines Consider the following DFA over {a, b}. q a q1 a a b b a q2 b q3 b How many states does the minimized DFA have? 1, 2, 3 or 4? 15 / 29

Solution Languages and Finite State Machines The minimized DFA has just 2 states! q, q1 and q2 can all be identified, but clearly q3 must be kept distinct from these. a q12 b b q3 a Notice that the corresponding language consists of all strings ending with b. 16 / 29

Minimization in practice Let s look again at our definition of equivalence of states: q q iff x Σ. δ(q, x) F δ(q, x) F This is fine as an abstract mathematical definition of equivalence, but it doesn t seem to give us a way to compute which states are equivalent: we d have to check infinitely many strings x Σ. Fortunately, there s an actual algorithm for that works in reasonable time. This is useful in practice: we can specify our DFA in the most convenient way without worrying about its size, then minimize to a more compact DFA to be implemented e.g. in hardware. 17 / 29

First eliminate any unreachable states (easy). Then create a table of all possible pairs of states (p, q), initially unmarked. (E.g. a two-dimensional array of booleans, initially set to false.) We mark pairs (p, q) as and when we discover that p and q cannot be equivalent. 1 Start by marking all pairs (p, q) where p F and q F, or vice versa. 2 Look for unmarked pairs (p, q) such that for some u Σ, the pair (δ(p, u), δ(q, u)) is marked. Then mark (p, q). 3 Repeat step 2 until no such unmarked pairs remain. If (p, q) is still unmarked, can collapse p, q to a single state. 18 / 29

Illustration of minimization algorithm Consider the following DFA over {a, b}. 19 / 29

Illustration of minimization algorithm After eliminating unreachable states: 2 / 29

Illustration of minimization algorithm We mark states to be kept distinct using a half matrix: q q1 q2 q3 q q1 q2 q3 21 / 29

Illustration of minimization algorithm First mark accepting/non-accepting pairs: q q1 q2 q3 q q1 q2 q3 22 / 29

Illustration of minimization algorithm (q,q1) is unmarked, qo a q1, q1 a q3, and (q1,q3) is marked. q q1 q2 q3 q q1 q2 q3 23 / 29

Illustration of minimization algorithm So mark (q,q1). q q1 q2 q3 q q1 q2 q3 24 / 29

Illustration of minimization algorithm (q,q2) is unmarked, qo a q1, q2 a q3, and (q1,q3) is marked. q q1 q2 q3 q q1 q2 q3 25 / 29

Illustration of minimization algorithm So mark (q,q2). q q1 q2 q3 q q1 q2 q3 26 / 29

Illustration of minimization algorithm The only remaining unmarked pair (q1,q2) stays unmarked. q q1 q2 q3 q q1 q2 q3 27 / 29

Illustration of minimization algorithm So obtain mimized DFA by collapsing q1, q2 to a single state. 28 / 29

Reading Languages and Finite State Machines Relevant reading: DFAs and regular languages: Kozen chapter 3; J & M section 2.2. Minimization: Kozen chapters 13 16. Next time: Non-deterministic finite automata (NFAs), and relationship with DFAs. (See rest of Kozen chapters 5 and 6.) 29 / 29