Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Similar documents
Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Theory of Computation Regular Languages

Minimal DFA. minimal DFA for L starting from any other

Harvard University Computer Science 121 Midterm October 23, 2012

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Finite Automata-cont d

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Lecture 08: Feb. 08, 2019

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

Formal languages, automata, and theory of computation

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

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

1.3 Regular Expressions

1.4 Nonregular Languages

Finite-State Automata: Recap

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

Non-deterministic Finite Automata

GNFA GNFA GNFA GNFA GNFA

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

NFAs continued, Closure Properties of Regular Languages

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

State Minimization for DFAs

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

CMSC 330: Organization of Programming Languages

Non-deterministic Finite Automata

CS 330 Formal Methods and Models

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

Recursively Enumerable and Recursive. Languages

First Midterm Examination

Deterministic Finite Automata

Closure Properties of Regular Languages

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Regular expressions, Finite Automata, transition graphs are all the same!!

Java II Finite Automata I

Fundamentals of Computer Science

CS375: Logic and Theory of Computing

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Automata and Languages

First Midterm Examination

More on automata. Michael George. March 24 April 7, 2014

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

FABER Formal Languages, Automata and Models of Computation

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

Homework Solution - Set 5 Due: Friday 10/03/08

CS 330 Formal Methods and Models

Lexical Analysis Finite Automate

Myhill-Nerode Theorem

Nondeterminism and Nodeterministic Automata

Homework 3 Solutions

CS 275 Automata and Formal Language Theory

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CSC 473 Automata, Grammars & Languages 11/9/10

Coalgebra, Lecture 15: Equations for Deterministic Automata

Formal Language and Automata Theory (CS21004)

Formal Languages and Automata

CS 275 Automata and Formal Language Theory

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Chapter 2 Finite Automata

Convert the NFA into DFA

Closure Properties of Regular Languages

CHAPTER 1 Regular Languages. Contents

Handout: Natural deduction for first order logic

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

DFA minimisation using the Myhill-Nerode theorem

1 Structural induction, finite automata, regular expressions

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir

1 From NFA to regular expression

Let's start with an example:

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

NFAs continued, Closure Properties of Regular Languages

Lecture 6 Regular Grammars

CISC 4090 Theory of Computation

Probabilistic Model Checking Michaelmas Term Dr. Dave Parker. Department of Computer Science University of Oxford

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS375: Logic and Theory of Computing

(e) if x = y + z and a divides any two of the integers x, y, or z, then a divides the remaining integer

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

CSCI FOUNDATIONS OF COMPUTER SCIENCE

CS 330 Formal Methods and Models

DFA Minimization and Applications

1 Structural induction

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

UNIFORM CONVERGENCE. Contents 1. Uniform Convergence 1 2. Properties of uniform convergence 3

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Transcription:

Finite Automt Theory nd Forml Lnguges TMV027/DIT321 LP4 2018 Lecture 10 An Bove April 23rd 2018 Recp: Regulr Lnguges We cn convert between FA nd RE; Hence both FA nd RE ccept/generte regulr lnguges; More on lgebric lws for RE nd how to prove them; We use the Pumping lemm to show tht lnguge is NOT regulr; RL re closed under: Union, complement, intersection, difference, conctention, closure; Prefix, reversl; Closure properties cn be used both to prove tht lnguge IS regulr or tht lnguge is NOT regulr. April 23rd 2018, Lecture 10 TMV027/DIT321 1/25

Overview of Tody s Lecture Decision properties for RL; Equivlence of RL; Minimistion of utomt. Contributes to the following lerning outcome: Explin nd mnipulte the diff. concepts in utomt theory nd forml lng; Understnd the power nd the limittions of regulr lng nd context-free lng; Prove properties of lnguges, grmmrs nd utomt with rigorously forml mthemticl methods; Design utomt, regulr expressions nd context-free grmmrs ccepting or generting certin lnguge; Describe the lnguge ccepted by n utomt or generted by regulr expression or context-free grmmr; Simplify utomt nd context-free grmmrs; Determine if certin word belongs to lnguge; Differentite nd mnipulte forml descriptions of lng, utomt nd grmmrs. April 23rd 2018, Lecture 10 TMV027/DIT321 2/25 Decision Properties of Regulr Lnguges We wnt to be ble to nswer YES/NO to questions such s Is string w in the lnguge L? Is this lnguge empty? Are these 2 lnguges equivlent? In generl lnguges re infinite so we cnnot do mnul checking. Insted we work with the finite description of the lnguges (DFA, NFA. ǫ-nfa, RE). Which description is most convenient depends on the property nd on the lnguge. April 23rd 2018, Lecture 10 TMV027/DIT321 3/25

Testing Membership in Regulr Lnguges Given RL L nd word w over the lphbet of L, is w L? When L is given by FA we cn simply run the FA with the input w nd see if the word is ccepted by the FA. We hve seen n lgorithm simulting the running of DFA (nd you hve implemented lgorithms simulting the running of NFA nd ǫ-nfa, right? :-). Using derivtives (see exercises 4.2.3 nd 4.2.5) there is nice lgorithm checking membership on RE. Let M = L(R) nd w = 1... n. Let \R = D R = {x x M} (in the book dm d ). D w R = D n (... (D 1 R)...). It cn then be shown tht w M iff ǫ D w R. April 23rd 2018, Lecture 10 TMV027/DIT321 4/25 Testing Emptiness of Regulr Lnguges given FA Given FA for lnguge, testing whether the lnguge is empty or not mounts to checking if there is pth from the strt stte to finl stte. Let D = (Q, Σ, δ, q 0, F ) be DFA. Recll the notion of ccessible sttes: Acc = {ˆδ(q 0, x) x Σ }. Proposition: Given D s bove, then D = (Q Acc, Σ, δ Q Acc, q 0, F Acc) is DFA such tht L(D) = L(D ). In prticulr, L(D) = if F Acc =. (Actully, L(D) = iff F Acc = since if ˆδ(q 0, x) F then ˆδ(q 0, x) F Acc.) April 23rd 2018, Lecture 10 TMV027/DIT321 5/25

Testing Emptiness of Regulr Lnguges given FA A recursive lgorithm to test whether stte is ccessible/rechble is s follows: Bse cse: The strt stte q 0 is rechble from q 0. Recursive step: If q is rechble from q 0 nd there is n rc from q to p (with ny lbel, including ǫ) then p is lso rechble from q 0. (This step is repeted until no new rechble stte is found.) (This lgorithm is n instnce of grph-rechbility.) If the set of rechble sttes contins t lest one finl stte then the RL is NOT empty. Exercise: Progrm this! April 23rd 2018, Lecture 10 TMV027/DIT321 6/25 Testing Emptiness of Regulr Lnguges given RE Given RE for the lnguge we cn insted define the function: isempty : RE Bool isempty( ) = True isempty(ǫ) = Flse isempty() = Flse isempty(r 1 + R 2 ) = isempty(r 1 ) isempty(r 2 ) isempty(r 1 R 2 ) = isempty(r 1 ) isempty(r 2 ) isempty(r ) = Flse April 23rd 2018, Lecture 10 TMV027/DIT321 7/25

Functionl Representtion of Testing Emptiness for RE dt RExp = Empty Epsilon Atom Plus (RExp ) (RExp ) Conct (RExp ) (RExp ) Str (RExp ) isempty :: RExp -> Bool isempty Empty = True isempty (Plus e1 e2) = isempty e1 && isempty e2 isempty (Conct e1 e2) = isempty e1 isempty e2 isempty _ = Flse April 23rd 2018, Lecture 10 TMV027/DIT321 8/25 Other Testing Algorithms on Regulr Expressions Tests if RE genertes ǫ. hsepsilon : RE Bool hsepsilon( ) = Flse hsepsilon(ǫ) = True hsepsilon() = Flse hsepsilon(r 1 + R 2 ) = hsepsilon(r 1 ) hsepsilon(r 2 ) hsepsilon(r 1 R 2 ) = hsepsilon(r 1 ) hsepsilon(r 2 ) hsepsilon(r ) = True April 23rd 2018, Lecture 10 TMV027/DIT321 9/25

Other Testing Algorithms on Regulr Expressions Tests if R genertes t most ǫ: L(R) {ǫ}. tmosteps : RE Bool tmosteps( ) = True tmosteps(ǫ) = True tmosteps() = Flse tmosteps(r 1 + R 2 ) = tmosteps(r 1 ) tmosteps(r 2 ) tmosteps(r 1 R 2 ) = isempty(r 1 ) isempty(r 2 ) (tmosteps(r 1 ) tmosteps(r 2 )) tmosteps(r ) = tmosteps(r) April 23rd 2018, Lecture 10 TMV027/DIT321 10/25 Other Testing Algorithms on Regulr Expressions Tests if regulr expression genertes n infinite lnguge. infinite : RE Bool infinite( ) = Flse infinite(ǫ) = Flse infimote() = Flse infinite(r 1 + R 2 ) = infinite(r 1 ) infinite(r 2 ) infinite(r 1 R 2 ) = (infinite(r 1 ) (isempty(r 2 )) ( (isempty(r 1 )) infinite(r 2 )) infinite(r ) = (tmosteps(r)) April 23rd 2018, Lecture 10 TMV027/DIT321 11/25

Testing Equivlence of Regulr Lnguges We hve seen how one cn prove tht 2 RE re equl, hence the lnguges they represent re equivlent (but this is not n esy process). We will see now how to test when 2 DFA describe the sme lnguge. April 23rd 2018, Lecture 10 TMV027/DIT321 12/25 Testing Equivlence of Sttes in DFA How to nswer the question do sttes p nd q behve in the sme wy? Definition: We sy tht sttes p nd q re equivlent if for ll w, ˆδ(p, w) is n ccepting stte iff ˆδ(q, w) is n ccepting stte. Note: We do not require tht ˆδ(p, w) = ˆδ(q, w)! Definition: If p nd q re not equivlent, then they re distinguishble. Tht is, there exists t lest one w such tht one of ˆδ(p, w) nd ˆδ(q, w) is n ccepting stte nd the other is not. April 23rd 2018, Lecture 10 TMV027/DIT321 13/25

Exmple: Identifying Distinguishble Pirs Let us find the distinguishble pirs in the following DFA. q 0 b q 1 q 2 b b q 3 q 4, b, b q 5, b q 0 q 1 q 2 q 3 q 4 q 5 X X X X X q 4 X X X q 3 X X X q 2 X X q 1 If p is ccepting nd q is not, then the word ǫ distinguish them. δ(q 1, ) = q 3 nd δ(q 5, ) = q 5. Since (q 3, q 5 ) is distinguishble so must be (q 1, q 5 ). Wht bout δ(q 2, ) nd δ(q 5, )? Wht bout the pirs (q 0, q 3 ) nd (q 0, q 4 ) with the input? Finlly, let us consider the pirs (q 3, q 4 ) nd (q 1, q 2 ). April 23rd 2018, Lecture 10 TMV027/DIT321 14/25 Tble-Filling Algorithm This lgorithm finds pirs of sttes tht re distinguishble. Any 2 sttes tht we do not find distinguishble re equivlent (see slide 17). Let D = (Q, Σ, δ, q 0, F ) be DFA. The tble-filling lgorithm is s follows: Bse cse: If p is n ccepting stte nd q is not, then (p, q) re distinguishble. Recursive step: Let p nd q be such tht for some, δ(p, ) = r nd δ(q, ) = s with (r, s) known to be distinguishble. Then (p, q) re lso distinguishble. (This step is repeted until no new distinguishble pir is found.) (If w distinguishes r nd s then w must distinguish p nd q since ˆδ(p, w) = ˆδ(r, w) nd ˆδ(q, w) = ˆδ(s, w).) April 23rd 2018, Lecture 10 TMV027/DIT321 15/25

Exmple: Tble-Filling Algorithm Let us fill the tble of distinguishble pirs in the following DFA. q 0 q 1 q 2 q 3 q 4 q 5 q 0 q 1 q 2 q 3 q 4 q 5 X X X X q 4 X X X q 3 X X q 2 X X q 1 X Let us consider the bse cse of the lgorithm. Let us consider the pir (q 0, q 5 ). Let us consider the pir (q 0, q 2 ). Let us consider (q 2, q 3 ) nd (q 3, q 5 ). Finlly, let us consider the remining pirs. April 23rd 2018, Lecture 10 TMV027/DIT321 16/25 Equivlent Sttes Theorem: Let D = (Q, Σ, δ, q 0, F ) be DFA. If 2 sttes re not distinguishble by the tble-filling lgorithm then the sttes re equivlent. Proof: Let us ssume there is bd pir (p, q) such tht p nd q re distinguishble but the tble-filling lgorithm doesn t find them so. If there re bd pirs, let (p, q ) be bd pir with the shortest string w = 1 2... n tht distinguishes 2 sttes. Note w is not ǫ otherwise (p, q ) is found distinguishble in the bse step. Let δ(p, 1 ) = r nd δ(q, 1 ) = s. Sttes r nd s re distinguished by 2... n since this string tkes r to ˆδ(p, w) nd s to ˆδ(q, w). Now string 2... n distinguishes 2 sttes nd is shorter thn w which is the shortest string tht distinguishes bd pir. Then (r, s) cnnot be bd pir nd hence it must be found distinguishble by the lgorithm. Then the recursive step should hve found (p, q ) distinguishble. This contrdicts the ssumption tht bd pirs exist. April 23rd 2018, Lecture 10 TMV027/DIT321 17/25

Testing Equivlence of Regulr Lnguges We cn use the tble-filling lgorithm to test equivlence of regulr lnguges. Let M nd N be 2 regulr lnguges. Let D M = (Q M, Σ, δ M, q M, F M ) nd D N = (Q N, Σ, δ N, q N, F N ) be their corresponding DFA. Let us ssume Q M Q N = (esy to obtin by renming). Construct D = (Q M Q N, Σ, δ,, F M F N ) (initil stte irrelevnt). δ is the union of δ M nd δ N s function (we need to mke δ totl!). One should now check if the pir (q M, q N ) is equivlent. If so, string is ccepted by D M iff it is ccepted by D N. Hence M nd N re equivlent lnguges. April 23rd 2018, Lecture 10 TMV027/DIT321 18/25 Equivlence of Sttes: An Equivlence Reltion The reltion stte p is equivlent to stte q, denoted p q, is n equivlence reltion. Reflexive: p. p p; Symmetric: p q. p q q p; Trnsitive: p q r. p q q r p r. (See Theorem 4.23 for proof of the trnsitivity prt.) Exercise: Prove these properties! April 23rd 2018, Lecture 10 TMV027/DIT321 19/25

Prtition of Sttes Let D = (Q, Σ, δ, q 0, F ) be DFA. The tble-filling lgo. defines the equivlence of sttes reltion over Q. This is n equivlence reltion so we cn define the quotient Q/. This quotient gives us prtition into clsses of mutully equivlent sttes. Exmple: The prtition for the exmple in slide 14 is the following (note the singleton clsses!) {q 0 } {q 1, q 2 } {q 3, q 4 } {q 5 } Exmple: The prtition for the exmple in slide 16 is the following {q 0, q 3 } {q 1, q 4 } {q 2, q 5 } Note: Clsses might lso hve more thn 2 elements. April 23rd 2018, Lecture 10 TMV027/DIT321 20/25 Exmple: Minimistion of DFA How to use the prtition into clsses of equivlent sttes to minimise DFA? Exmple: The miniml DFA corresponding to the DFA in slide 14 is, b, b, b, b q 0 q 1 q 2 q 3 q 4 q 5 Exmple: The miniml DFA corresponding to the DFA in slide 16 is q 0 q 3 q 1 q 4 q 2 q 5 Exercise: Progrm the minimistion lgorithm! April 23rd 2018, Lecture 10 TMV027/DIT321 21/25

Minimistion of DFA: The Algorithm Let D = (Q, Σ, δ, q 0, F ) be DFA. Q/ llows to build n equivlent DFA with the minimum nr. of sttes. This minimum DFA is unique (modulo the nme of the sttes). The lgorithm for building the minimum DFA D = (Q, Σ, δ, q 0, F ) is: 1 Eliminte ny non ccessible stte; 2 Prtition the remining sttes using the tble-filling lgorithm; 3 Use ech clss s single stte in the new DFA; 4 The strt stte is the clss contining q 0 ; 5 The finl sttes re ll those clsses contining elements in F ; 6 δ (S, ) = T if given ny q S, δ(q, ) = p for some p T. (Actully, the prtition gurntees tht q S. p T. δ(q, ) = p.) April 23rd 2018, Lecture 10 TMV027/DIT321 22/25 Does the Minimistion Algorithm Give Miniml DFA? Given DFA D, the minimistion lgorithm gives us DFA D with the miniml number of sttes with respect to those of D. But, could there exist DFA A completely unrelted to D, lso ccepting the sme lnguge nd with less sttes thn those in D? Section 4.4.4 in the book shows by contrdiction tht A cnnot exist. Theorem: If D is DFA nd D the DFA constructed from D with the minimistion lgorithm described before, then D hs s few sttes s ny DFA equivlent to D. April 23rd 2018, Lecture 10 TMV027/DIT321 23/25

Cn we Minimise NFA? One could find smller NFA, but not with this lgorithm. 0, 1 Exmple: Consider the following NFA q 0 0 q 1 1 0 q 2 The tble-filling lgorithm does not find equivlent sttes in this cse. However, the following is smller nd equivlent NFA for the lnguge. 0, 1 q 0 0 q 1 April 23rd 2018, Lecture 10 TMV027/DIT321 24/25 Overview of Next Lecture Sections 5 5.2.2, nd notes on Inductive sets nd induction: Context-free grmmrs; Derivtions; Prse trees; Proofs in grmmrs. April 23rd 2018, Lecture 10 TMV027/DIT321 25/25