Constructions on Finite Automata

Similar documents
Constructions on Finite Automata

Deterministic finite Automata

Regular expressions and Kleene s theorem

Regular expressions and Kleene s theorem

Closure under the Regular Operations

Lecture 3: Nondeterministic Finite Automata

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

Inf2A: Converting from NFAs to DFAs and Closure Properties

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

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,

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

Uses of finite automata

Equivalence of DFAs and NFAs

Decision, Computation and Language

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

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

Lecture 1: Finite State Automaton

NFA and regex. the Boolean algebra of languages. regular expressions. Informatics 1 School of Informatics, University of Edinburgh

3515ICT: Theory of Computation. Regular languages

Nondeterministic Finite Automata

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

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

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

Nondeterministic finite automata

CS 154, Lecture 3: DFA NFA, Regular Expressions

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

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

CS 455/555: Finite automata

Chapter 2: Finite Automata

Nondeterministic Finite Automata

Deterministic Finite Automaton (DFA)

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Lecture 4 Nondeterministic Finite Accepters

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Further discussion of Turing machines

Intro to Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

Computational Theory

Extended transition function of a DFA

Nondeterminism. September 7, Nondeterminism

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Regular expressions and Kleene s theorem

Finite Automata. Mahesh Viswanathan

Regular Languages. Problem Characterize those Languages recognized by Finite Automata.

Non-deterministic Finite Automata (NFAs)

CSE 105 Theory of Computation Professor Jeanne Ferrante

Finite Automata Part Two

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Homework 1 Due September 20 M1 M2

Finite Automata and Regular languages

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

Theory of Computation (I) Yijia Chen Fudan University

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

Chapter Five: Nondeterministic Finite Automata

Regular Expressions. Definitions Equivalence to Finite Automata

Finite Automata. Finite Automata

Chapter 6: NFA Applications

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

CPS 220 Theory of Computation REGULAR LANGUAGES

Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

September 7, Formal Definition of a Nondeterministic Finite Automaton

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

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

Computer Sciences Department

Finite Automata and Regular Languages

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

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

CSE 105 THEORY OF COMPUTATION

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

CSC236 Week 11. Larry Zhang

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

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

Optimizing Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 208: Automata Theory and Logic

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

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

Deterministic Finite Automata (DFAs)

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

Formal Models in NLP

CSE 105 THEORY OF COMPUTATION

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

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

Deterministic Finite Automata (DFAs)

Inf2A: The Pumping Lemma

Sri vidya college of engineering and technology

CSE 105 THEORY OF COMPUTATION

Finite Automata and Languages

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

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

Simplification of finite automata

CSE 105 THEORY OF COMPUTATION

Lecture 7 Properties of regular languages

CS 154 Formal Languages and Computability Assignment #2 Solutions

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Java II Finite Automata I

Transcription:

Constructions on Finite Automata Informatics 2A: Lecture 4 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 23rd September, 2014 1 / 29

1 Closure properties of regular languages Union Intersection Complement 2 2 / 29

Recap of Lecture 3 A language is a set of strings over an alphabet Σ. A language is called regular if it is recognised by some NFA. DFAs are an important subclass of NFAs. An NFA with n states can be determinized to an equivalent DFA with 2 n states, using the subset construction. Therefore the regular languages are exactly the languages recognised by DFAs. 3 / 29

Union of regular languages Union Intersection Complement Consider the following little theorem: If L 1 and L 2 are regular languages over Σ, so is L 1 L 2. This is dead easy to prove using NFAs. Suppose N 1 = (Q 1, 1, S 1, F 1 ) is an NFA for L 1, and N 2 = (Q 2, 2, S 2, F 2 ) is an NFA for L 2. We may assume Q 1 Q 2 = (just relabel states if not). Now consider the NFA (Q 1 Q 2, 1 2, S 1 S 2, F 1 F 2 ) This is just N 1 and N 2 side by side. Clearly, this NFA recognizes precisely L 1 L 2. Number of states = Q 1 + Q 2 no state explosion! 4 / 29

Intersection of regular languages Union Intersection Complement If L 1 and L 2 are regular languages over Σ, so is L 1 L 2. Suppose N 1 = (Q 1, 1, S 1, F 1 ) is an NFA for L 1, and N 2 = (Q 2, 2, S 2, F 2 ) is an NFA for L 2. We define a product NFA (Q,, S, F ) by: (q, r) a (q, r ) Q = Q 1 Q 2 q a q 1 and r S = S 1 S 2 F = F 1 F 2 a r 2 Number of states = Q 1 Q 2 a bit more costly than union! If N 1 and N 2 are DFAs then the product automaton is a DFA too. 5 / 29

Union Intersection Complement Complement of a regular language ( Recall the set-difference operation, where A, B are sets. ) A B = {x A x / B} If L is a regular language over Σ, then so is Σ L. Suppose N = (Q, δ, s, F ) is a DFA for L. Then (Q, δ, s, Q F ) is a DFA for Σ L. (We simply swap the accepting and rejecting states in N.) Number of states = Q no blow up at all, but we are required to start with a DFA. This in itself has size implications. The complement construction does not work if N is not determininstic! 6 / 29

Union Intersection Complement Closure properties of regular languages We ve seen that if both L 1 and L 2 are regular languages, then so are: L 1 L 2 (union) L 1 L 2 (intersection) Σ L 1 (complement) We sometimes express this by saying that regular languages are closed under the operations of union, intersection and complementation. ( Closed used here in the sense of self-contained.) Each closure property corresponds to an explicit construction on finite automata. Sometimes this uses NFAs (union), sometimes DFAs (complement), and sometimes the construction works equally well for both NFAs and DFAs (intersection). 7 / 29

The Minimization Problem Determinization involves an exponential blow-up in the automaton. Is it sometimes possible to reduce the size of the resulting DFA? Many different DFAs can give rise to the same language, e.g.: 1 1 0 1 0 1 q0 q1 0,1 q4 even odd 0 0 0 q3 q2 1 0 1 We shall see that there is always a unique smallest DFA for a given regular language. 8 / 29

1 0 1 q0 q1 0,1 q4 0 0 q3 q2 1 0 1 We perform the following steps to reduce M above: Throw away unreachable states (in this case, q4). Squish together equivalent states, i.e. states q, q such that: every string accepted starting from q is accepted starting from q, and vice versa. (In this case, q0 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. 9 / 29

Properties of minimization The minimization operation on DFAs enjoys the following properties which characterise the construction: L(Min(M)) = L(M). If L(M ) = L(M) and M Min(M) then M = Min(M). Here M is the number of states of the DFA M, and = means the two DFAs are isomorphic: that is, identical apart from a possible renaming of states. Two consequences of the above are: Min(M) = Min(M ) if and only if L(M) = L(M ). Min(Min(M)) = Min(M). For a formal treatment of minimization, see Kozen chapters 13 16. 10 / 29

Challenge question Consider the following DFA over {a, b}. q0 a q1 a a b b a q2 b q3 b How many states does the minimized DFA have? 11 / 29

Solution Closure properties of regular languages The minimized DFA has just 2 states: a q012 b b q3 a The minimized DFA has been obtained by squishing together states q0, q1 and q2. Clearly q3 must be kept distinct. Note that the corresponding language consists of all strings ending with b. 12 / 29

Minimization in practice Let s look again at our definition of equivalent states: states q, q such that: every string accepted starting from q is accepted starting from q, and vice versa. 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. 13 / 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. 14 / 29

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

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

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

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

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

Illustration of minimization algorithm So mark (q0,q1). q0 q1 q2 q3 q0 q1 q2 q3 20 / 29

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

Illustration of minimization algorithm So mark (q0,q2). q0 q1 q2 q3 q0 q1 q2 q3 22 / 29

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

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

Improving determinization Now we have a minimization algorithm, the following improved determinization procedure is possible. To determinize an NFA M with n states: 1 Perform the subset construction on M to produce an equivalent DFA N with 2 n states. 2 Perform the minimization algorithm on N to produce a DFA Min(N) with 2 n states. Using this method we are guaranteed to produce the smallest possible DFA equivalent to M. In many cases this avoids the exponential state-space blow-up. In some cases, however, an exponential blow-up is unavoidable. 25 / 29

End-of-last-lecture challenge question Consider last lecture s example NFA over {0, 1}: 0,1 1 0,1 0,1 0,1 0,1 q0 q1 q2 q3 q4 q5 What is the number of states of the smallest DFA that recognises the same language? 26 / 29

End-of-last-lecture challenge question Consider last lecture s example NFA over {0, 1}: 0,1 1 0,1 0,1 0,1 0,1 q0 q1 q2 q3 q4 q5 What is the number of states of the smallest DFA that recognises the same language? Answer: The smallest DFA has 32 states. 26 / 29

End-of-last-lecture challenge question Consider last lecture s example NFA over {0, 1}: 0,1 1 0,1 0,1 0,1 0,1 q0 q1 q2 q3 q4 q5 What is the number of states of the smallest DFA that recognises the same language? Answer: The smallest DFA has 32 states. More generally, the smallest DFA for the language: {x Σ the n-th symbol from the end of x is 1} has 2 n states. Whereas, there is an NFA with n + 1 states. 26 / 29

End-of-lecture questions 1 Show that the construction of a complement automaton (used to prove that regular languages are closed under complementation) does not work for nondeterministic finite automata. Specifically, find an example of an NFA M = (Q,, S, F ) for which the NFA (Q,, S, Q F ), obtained by swapping accepting and non-accepting states, does not recognize Σ L(M). Answer: For example, over the alphabet Σ = {a} consider ({q0, q1}, {(q0, a, q0), (q1, a, q1)}, {q0, q1}, {q 0 }) Here {q0, q1} is the set of start states, and {q0} is the set of accepting states. This recognises the full language Σ. If accepting and non-accepting states are swapped, the new set of accepting states is {q 1 }, and the language recognised is still Σ. 27 / 29

End-of-lecture questions 2 Suppose N 1 = (Q 1, 1, S 1, F 1 ) is an DFA for L 1, and N 2 = (Q 2, 2, S 2, F 2 ) is an DFA for L 2. Give a direct construction of a DFA N such that L(N) = L(N 1 ) L(N 2 ). Answer: Use the identity: L 1 L 2 = Σ ((Σ L 1 ) (Σ L 2 )) to reduce the construction to a composite of complementation and intersection constructions. More directly (but equivalently), simply modify the product automaton construction on slide 5 with (q, r) a (q, r ) q a q 1 or r a r 2 28 / 29

Reading Closure properties of regular languages Relevant reading: Closure properties of regular languages: Kozen chapter 4. Minimization: Kozen chapters 13 14. Next time: Regular expressions and Kleene s Theorem. (Kozen chapters 7 9.) 29 / 29