Formal Languages and Automata

Similar documents
Minimal DFA. minimal DFA for L starting from any other

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

State Minimization for DFAs

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

Designing finite automata II

Myhill-Nerode Theorem

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

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

Chapter 2 Finite Automata

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

Convert the NFA into DFA

Theory of Computation Regular Languages

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

1 Nondeterministic Finite Automata

Lecture 08: Feb. 08, 2019

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

Non-deterministic Finite Automata

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

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

Lecture 09: Myhill-Nerode Theorem

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Java II Finite Automata I

Thoery of Automata CS402

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.

DFA minimisation using the Myhill-Nerode theorem

Nondeterminism and Nodeterministic Automata

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Finite Automata-cont d

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

CHAPTER 1 Regular Languages. Contents

Non-deterministic Finite Automata

Fundamentals of Computer Science

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

Worked out examples Finite Automata

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

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

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

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

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

CMSC 330: Organization of Programming Languages

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

Homework 3 Solutions

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

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

Finite-State Automata: Recap

Formal Language and Automata Theory (CS21004)

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

NFAs continued, Closure Properties of Regular Languages

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

Model Reduction of Finite State Machines by Contraction

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

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

Let's start with an example:

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

First Midterm Examination

GNFA GNFA GNFA GNFA GNFA

Deterministic Finite Automata

Formal languages, automata, and theory of computation

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.

Coalgebra, Lecture 15: Equations for Deterministic Automata

Non-Deterministic Finite Automata

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

Lexical Analysis Finite Automate

CISC 4090 Theory of Computation

3 Regular expressions

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Regular Languages and Applications

NFAs continued, Closure Properties of Regular Languages

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

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

Harvard University Computer Science 121 Midterm October 23, 2012

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1

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

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

Languages & Automata

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Revision Sheet. (a) Give a regular expression for each of the following languages:

Some Theory of Computation Exercises Week 1

input tape head moves current state

First Midterm Examination

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

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

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

Closure Properties of Regular Languages

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

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

Section: Other Models of Turing Machines. Definition: Two automata are equivalent if they accept the same language.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Context-Free Grammars and Languages

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

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

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

CS375: Logic and Theory of Computing

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Lecture 9: LTL and Büchi Automata

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

Transcription:

Moile Computing nd Softwre Engineering p. 1/5 Forml Lnguges nd Automt Chpter 2 Finite Automt Chun-Ming Liu cmliu@csie.ntut.edu.tw Deprtment of Computer Science nd Informtion Engineering Ntionl Tipei University of Technology Tipei, TAIWAN

Moile Computing nd Softwre Engineering p. 2/5 Finite Automt A finite utomton (or finite-stte mchine) is severely restricted model of n ctul computer. A finite utomton is chrcterized y hving no temporry storge.

Moile Computing nd Softwre Engineering p. 3/5 Contents Deterministic Finite Automt Nondeterministic Finite Automt Equivlence of Deterministic nd Nondeterministic Finite Automt Reduction of the Numer of Sttes in Finite Automt

Moile Computing nd Softwre Engineering p. 4/5 Deterministic Finite Automt A deterministic finite utomt (df) is defined y the quintuple where M = (Q, Σ,δ,q 0,F), Q is finite set of internl sttes, Σ is n lphet, δ : Q Σ Q is the trnsition function, q 0 Q is the initil stte, nd F Q is the set of finl sttes.

Moile Computing nd Softwre Engineering p. 5/5 Visuliztion of Finite Automt We cn use trnsition grphs to represent finite utomt: vertices sttes edges trnsitions lels on vertices re the nmes of the sttes lels on edges re the vlues of the input symols initil stte hs n incoming edge unleled finl sttes re drwn with doule cycle.

Moile Computing nd Softwre Engineering p. 6/5 Exmple 1 Consider the df M = (Q, Σ,δ,q 0,F), where Q = {q 0,q 1,q 2 }, Σ = {0, 1}, F = {q 1 }, nd the trnsition function δ is tulted elow stte input δ(stte,input) q 0 0 q 0 q 0 1 q 1 q 1 0 q 0 q 1 1 q 2 q 2 0 q 2 q 2 1 q 1

Moile Computing nd Softwre Engineering p. 7/5 Exmple - Visuliztion of df Remrks: q 0 is n initil stte nd hs n incoming unleled edge. q 1 is finl stte nd with doule cycle.

Moile Computing nd Softwre Engineering p. 8/5 String Inputs Extending the df to the notion of computtion y n utomton on n input string consider the extended trnsition function δ : Q Σ Q. A configurtion is determined y the current stte nd the unred prt of the string eing processed.

Moile Computing nd Softwre Engineering p. 9/5 Exmple 2 M = ({q 0,q 1 }, {,},δ,q 0, {q 0 }), where the trnsition function δ is tulted elow stte input δ(stte,input) q 0 q 0 q 0 q 1 q 1 q 1 q 1 q 0

Moile Computing nd Softwre Engineering p. 10/5 Visuliztion of Exmple 2 Remrks: If the input string is, the initil configurtion is (q 0,).

Moile Computing nd Softwre Engineering p. 11/5 Reltions etween δ nd δ δ cn e derived from δ recursively s δ (q,λ) = q δ (q,w) = δ(δ (q,w),) (1) q Q,w Σ, nd Σ. Eqution (1) cn e written lterntively s δ (q,w) = δ (δ(q,),w).

Moile Computing nd Softwre Engineering p. 12/5 Configurtion Trnsitions If (q,w) nd (q,w ) re two configurtions of M, then (q,w) M (q,w ) if nd only if w = w for some Σ nd δ(q,) = q. (q,w) yields (q,w ) in one move using M for the reflexive nd trnsitive closure of M, for exmple, (q,w) M (q,w ) denotes tht (q,w) yields (q,w ) fter some numer, including zero, of steps.

Moile Computing nd Softwre Engineering p. 13/5 Exmple 3 Consider the df in Exmple 2, M = ({q 0,q 1 }, {,},δ,q 0, {q 0 }), with the input string is. Then, the initil configurtion is (q 0,) nd (q 0,) M (q 0,) M (q 0,) M (q 1,) M (q 0,) (q 0,λ) M Hence, (q 0,) M (q 0,λ).

Moile Computing nd Softwre Engineering p. 14/5 Lnguges nd Df s A string w Σ is sid to e ccepted y M if nd only if there is stte q f F s.t. (q 0,w) M (q f,λ). Exmple: is ccepted since q 0 F in the lst exmple. The lnguge ccepted y df M is the set of ll strings on Σ ccepted y M nd is denoted y L(M) nd L(M) = {w Σ : δ (q 0,w) F }. Note: L(M) = {w Σ : δ (q 0,w) F }

Moile Computing nd Softwre Engineering p. 15/5 Exmple 4 Remrks: q 2 is trp stte from which the df cn never escpe. L(M) = { n : n 0}

Moile Computing nd Softwre Engineering p. 16/5 Exercise Descrie the lnguge ccepted y the following df M = ({q 0,q 1,q 2,q 3 }, {,},δ,q 0, {q 0,q 1,q 2 }), where the trnsition function δ is tulted elow q σ δ(q,σ) q σ δ(q,σ) q 0 q 0 q 2 q 0 q 0 q 1 q 2 q 3 q 1 q 0 q 3 q 3 q 1 q 2 q 3 q 3

Moile Computing nd Softwre Engineering p. 17/5 Theorem Let M = (Q, Σ,δ,q 0,F) e df nd G M e the ssocited trnsition grph. Then, q i,q j Q nd w Σ +, δ (q i,w) = q j wlk in G M from q i to q j.

Moile Computing nd Softwre Engineering p. 18/5 Exmple 5 Find df tht recognizes the set of ll strings on Σ = {,} strting with the prefix., q 0 q 1 q 2 q 3,

Moile Computing nd Softwre Engineering p. 19/5 Exmple 6 Find df tht ccepts ll the strings on {0, 1}, except those contining the sustring 001. 1 0 0, 1 0 q 0 q 1 q 3 1 0 1 q 2

Moile Computing nd Softwre Engineering p. 20/5 Regulr Lnguges A lnguge L is clled regulr if nd only if there exists some deterministic finite utomton M such tht L = L(M). Exmple 7: Show tht the lnguge is regulr. L = {w : w {,} } Note tht, to show lnguge is regulr, we need to find df which ccepts it.

Moile Computing nd Softwre Engineering p. 21/5 Exmple 7 q 0 q 1 q 2, q 3 Remrks:

Moile Computing nd Softwre Engineering p. 22/5 Contents Deterministic Finite Automt Nondeterministic Finite Automt Equivlence of Deterministic nd Nondeterministic Finite Automt Reduction of the Numer of Sttes in Finite Automt

Moile Computing nd Softwre Engineering p. 23/5 Nondeterministic Finite Automt A nondeterministic finite utomt (nf) is defined y the quintuple where M = (Q, Σ,δ,q 0,F), Q is finite set of internl sttes, Σ is n lphet, δ : Q (Σ {λ}) 2 Q is the trnsition function (2 Q = the set of ll susets of Q), q 0 Q is the initil stte, nd F Q is the set of finl sttes.

Moile Computing nd Softwre Engineering p. 24/5 Aout Nf s λ is llowed to e the second rgument of δ it is possile tht δ(q i,) = λ (i.e. no trnsition) An nf cn lso e presented y stte digrm (grph) A string is ccepted y n nf if there exist some possile moves tht rech to finl stte.

Moile Computing nd Softwre Engineering p. 25/5 Exmple 8 q 2 q 1 q 3 q 0 q 4 q 5

Moile Computing nd Softwre Engineering p. 26/5 Exmple 9 An nf tht ccepts the set of ll strings contining either two consecutive 0 s or two consecutive 1 s. 0, 1 0, 1 0 0 q 0 q 3 q 4 1 q 3 q 4 1 0, 1

Moile Computing nd Softwre Engineering p. 27/5 String Inputs The trnsition cn e extended to the notion of computtion on n input string consider the extended trnsition function δ : Q Σ 2 Q. A recursive definition of δ is lso nlogous to the one for df. δ (q i,w) contins q j if nd only if there exists wlk in the stte grph from q i to q j.

Moile Computing nd Softwre Engineering p. 28/5 Acceptnce The lnguge ccepted y n nf M is the set of ll strings on Σ ccepted y M nd is defined s L(M) = {w Σ : δ (q 0,w) F }. Exmple 10: In the ove nf, L(M) = {(10) n : n 0}. A configurtion is ded configurtion if the trnsition on it is undefined.

Moile Computing nd Softwre Engineering p. 29/5 Resons for Nondeterminism voiding cktrcking helpful in solving prolems esily effective mechnism for descriing some complicted lnguges concisely certin theoreticl results re more esily estlished for nf s

Moile Computing nd Softwre Engineering p. 30/5 Contents Deterministic Finite Automt Nondeterministic Finite Automt Equivlence of Deterministic nd Nondeterministic Finite Automt Reduction of the Numer of Sttes in Finite Automt

Moile Computing nd Softwre Engineering p. 31/5 Nf s v.s. Df s Intuitively, the fmily of ll nf s includes the fmily of ll df s. We re therefore thinking if for ech nf, there exists corresponding df tht ccepts the sme lnguge.

Moile Computing nd Softwre Engineering p. 32/5 Equivlence Two finite utomt M 1 nd M 2 re sid to e equivlent if L(M 1 ) = L(M 2 ). Exmple 11:

Moile Computing nd Softwre Engineering p. 33/5 Theorem Let L e set ccepted y n nf. Then there exists df tht ccepts L. Notes: The proof is constructive nd shows wy to convert.

Deriving Df from Nf Let M = (Q, Σ,δ,q 0,F) e n nf ccepting L. We cn define df M = (Q, Σ,δ,q 0,F ) s follows: Q = 2 Q ; q 0 = [q 0 ]; F = set of ll sttes in Q contining stte of F ; For n element q = [q 1,q 2,,q i ] Q, δ (q,) is computed y pplying δ to ech stte of q 1,q 2,,q i, nd tking the union. The resulting union is the corresponding stte of δ (q,) in M. Note: Only the meningful sttes re kept. Tht is, we only reserve the stte hving pth from q 0 to itself in the trnsition grph. Moile Computing nd Softwre Engineering p. 34/5

Moile Computing nd Softwre Engineering p. 35/5 Exmple 12 δ [q 0 ] [q 1,q 2 ] [ ] [q 1,q 2 ] [q 1,q 2 ] [ ] [ ] [q 0 ] [ ]

Moile Computing nd Softwre Engineering p. 36/5 Exmple 13 δ [q 0 ] [q 1 ] [q 2 ] [q 0,q 1 ] [q 1,q 2 ] [q 0,q 1,q 2 ] 0 [q 0,q 1 ] [q 2 ] [ ] [q 0,q 1,q 2 ] [q 2 ] [q 0,q 1,q 2 ] 1 [q 1 ] [q 2 ] [q 2 ] [q 1,q 2 ] [q 2 ] [q 1,q 2 ]

Moile Computing nd Softwre Engineering p. 37/5 Contents Deterministic Finite Automt Nondeterministic Finite Automt Equivlence of Deterministic nd Nondeterministic Finite Automt Reduction of the Numer of Sttes in Finite Automt

Moile Computing nd Softwre Engineering p. 38/5 Stte Minimiztion Any df defines unique lnguge, ut the converse is not true. To minimize the numer of sttes of given df is to determine n equivlent df tht hs s few sttes s possile. For storge efficiency

Unrechle Sttes A stte is unrechle if there is no pth from the strt stte to it. Exmple 14: q 1 q 2 q 3 q 8 q 4 q 5 q 6 q 7, Sttes q 7 nd q 8 re unrechle. For stte minimiztion, sttes q 7 nd q 8 cn e removed. Moile Computing nd Softwre Engineering p. 39/5

Moile Computing nd Softwre Engineering p. 40/5 Removing Unrechle Sttes The set of rechle sttes cn e defined s the closure of {s} under the reltion {(p,q) : δ(p,) = q for some Σ}. computed y the following lgorithm: R := s; while there is stte p R nd Σ such tht δ(p,) R do dd δ(p,) to R.

Moile Computing nd Softwre Engineering p. 41/5 Exmple 15: Removing unrechle sttes in previous df q 1 q 2 q 3 q 4 q 5 q 6, Note: Sttes q 4 nd q 6 re equivlent.

Moile Computing nd Softwre Engineering p. 42/5 Right Congruence (Invrint) Definition: Let L Σ e lnguge, nd let x,y Σ. We sy tht x nd y re equivlent with respective to L, denoted x L y, if for ll z Σ, the following is true: xz L if nd only if yz L. Note: 1. L is n equivlence reltion. 2. x L y if either oth strings elong to L or neither is in L. 3. ppending ny string to oth strings results in two strings tht re either oth in L or oth not in L.

Moile Computing nd Softwre Engineering p. 43/5 Exmple 16: q 1 q 2 q 3 q 4 q 5 q 6, L = ( ) 1. If x is string, we denote y [x] the equivlent clss with respective to L to which x elongs. 2. L hs four equivlent clsses: (1) [e] = L, (2) [] = L, (3) [] = L, (4) [] = L( )Σ

Equivlence Reltion on Df s Definition: Let M = (Q, Σ,δ,s,F) e df. We sy tht two strings x,y Σ re equivlent with respective to M, denoted x M y, if, intuitively, they oth drive M from s to the sme stte. Formlly, x M y if there is stte q such tht (s,x) M (q,e) nd (s,y) M (q,e). Note: 1. M is n equivlence reltion. 2. Its equivlence clsses cn e identified y the sttes of M. 3. We denote the equivlence clss corresponding to stte q of M s E q. Moile Computing nd Softwre Engineering p. 44/5

Moile Computing nd Softwre Engineering p. 45/5 Exmple 17: q 1 q 2 q 3 q 4 q 5 q 6, L = ( ) The equivlence clsses of M re: (1) E q1 = (), (2) E q2 = L, (3) E q3 = L, (4) E q4 = (), (5) E q5 = L( )Σ, (6) E q6 = () L.

Moile Computing nd Softwre Engineering p. 46/5 Theorem Theorem: For ny df M = (Q, Σ,δ,s,F) nd ny strings x,y Σ, if x M y, then x L y. M is refinement of L. Exmple 18: Clsses E q5 nd [] coincide, while clsses E q1 nd E q3 re oth susets of [e]. Note: The numer of equivlence clsses of L under is nturl lower ound on the numer of sttes of ny df ccepting L.

Moile Computing nd Softwre Engineering p. 47/5 The Myhill-Nerode Theorem Theorem: Let L Σ e regulr lnguge. Then there is df with precisely s mny sttes s there re equivlence clsses in L tht ccepts L. Exmple 19: The stndrd utomton corresponding the L = ( ) is s follows nd hs four sttes. [e] [] {q 1, q 3 } {q 2 } {q 4, q 6 } {q 5 } [] [,],

Moile Computing nd Softwre Engineering p. 48/5 Corollry Corollry: A lnguge L is regulr if nd only if L hs finitely mny equivlence clsses. This corollry provides wy to for proving tht lnguge is not regulr. Exmple 20: L = { n n : n 1} is not regulr.

Moile Computing nd Softwre Engineering p. 49/5 Indistinguishle Sttes Let M = (Q, Σ,δ,s,F) e df. Definition: Define reltion A M Q Σ s (q,z) A M δ (q,z) F. We cll two sttes p,q Q equivlent (or, indistinguishle), denoted p q if for ll w Σ, (q,w) A M (p,w) A M. Two sttes which re not equivlent re distinguishle.

Moile Computing nd Softwre Engineering p. 50/5 Notes on Indistinguishle Sttes if two sttes re equivlent, then the corresponding equivlence clsses of M re susets of the sme equivlence clss of L. the equivlence clsses of re precisely those sets of stte of M tht must clumped together in order to otined the stndrd utomton of L(M).

Moile Computing nd Softwre Engineering p. 51/5 Sequence of Equivlence Reltions Definition: For two sttes p,q Q, p n q if the following is true: Note: (q,w) A M (p,w) A M, w with w n. n is corser equivlence reltion thn. Ech equivlence reltion in 0, 1, 2,... is refinement of the previous one. There re precisely two equivlence clsses of 0 : F nd Q F.

Moile Computing nd Softwre Engineering p. 52/5 Deriving n Lemm: For ny two sttes p,q Q nd ny integer n 1, p n q if nd only if () p n 1 q, nd () for ll Σ, δ(q,) n 1 δ(p,). Note: This lemm suggests wy to compute

Moile Computing nd Softwre Engineering p. 53/5 Constructing the Miniml df Algorithm: Initilly the equivlence clsses of 0 re F nd Q F ; repet for n = 1, 2,... Compute the equivlence clsses of n from those of n 1 until n is the sme s n 1.

Moile Computing nd Softwre Engineering p. 54/5 Exmple 21: Agin, we consider the following exmple q 1 q 2 q 3 q 4 q 5 q 6,