1 chapter 4 properties of regular languages pasbag, turkey

49
1 Chapter 4 Chapter 4 Properties of Properties of Regular Languages Regular Languages Pasbag, Turke y

Upload: wesley-jackson

Post on 18-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

1

Chapter 4 Chapter 4 Properties of Regular Properties of Regular

LanguagesLanguages

Pasbag, Turkey

Page 2: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

2

OutlineOutline

• 4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

• 4.2 Closure Properties of Regular 4.2 Closure Properties of Regular LanguagesLanguages

• 4.3 Decision Properties of Regular 4.3 Decision Properties of Regular LanguagesLanguages

• 4.4 Equivalence and Minimization of 4.4 Equivalence and Minimization of AutomataAutomata

Page 3: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

3

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

• 4.1.1 Pumping Lemma for Regular 4.1.1 Pumping Lemma for Regular LanguagesLanguages– NotNot every language is regular. every language is regular.

• E.g., E.g., LL0101 = {0 = {0nn11nn | | nn 1} 1} is not a regular language. is not a regular language.

– How to prove? Answer: use the pumping How to prove? Answer: use the pumping lemma.lemma.

– In the sequel, we abbreviate “regular language” In the sequel, we abbreviate “regular language” as “RL.”as “RL.”

Page 4: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

4

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

• Theorem 4.1 Theorem 4.1 Pumping lemma for RL’sPumping lemma for RL’s

Let Let LL be an RL. Then, there exists an integer c be an RL. Then, there exists an integer constant onstant nn (depending on (depending on LL) such that for every ) such that for every string string ww in in LL with | with |ww| | nn, we can break , we can break ww into into three substrings, three substrings, ww = = xyzxyz, such that:, such that:1.1. yy (i.e., (i.e., yy has at least one symbol); has at least one symbol);

2.2. ||xyxy| | nn; and; and

3.3. for all for all kk 0, the “pumped” string 0, the “pumped” string xyxykkzz is also in is also in LL..

ProofProof.. See the textbook.See the textbook.

Page 5: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

5

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

• (Supplemental)(Supplemental)– The pumping lemma may be rewritten more The pumping lemma may be rewritten more

precisely by mathematical notations as precisely by mathematical notations as

((LL)()(nn)()(ww))((ww LL, |, |ww| | nn

((xx, , yy, , zz))((ww = = xyzxyz, |, |xyxy| | nn, |, |yy| | 1, ( 1, (kk)()(xxyykkzz LL))))))..

Page 6: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

6

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

• 4.1.2 Applications of Pumping Lemma4.1.2 Applications of Pumping Lemma

– The pumping lemma may be used for proving The pumping lemma may be used for proving

“a given language is“a given language is notnot an RL,” instead of an RL,” instead of

proving “proving “isis an RL.” an RL.”

Page 7: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

7

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

• 4.1.2 Applications of Pumping Lemma4.1.2 Applications of Pumping Lemma

– Example 4.2Example 4.2 Prove the language Prove the language

LLeqeq = { = {ww | | ww has equal numbers of 0’s and 1’s} has equal numbers of 0’s and 1’s}

is is notnot an RL. an RL.

Page 8: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

8

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

• 4.1.2 Applications of Pumping Lemma4.1.2 Applications of Pumping Lemma

ProofProof (by contradiction): (by contradiction):

– Assume that Assume that LLeqeq is an RL. Then is an RL. Then the pumping lthe pumping l

emmaemma says that there exists an integer says that there exists an integer nn such t such t

hat hat for every string for every string ww in in LL with length | with length |ww| | nn, ,

ww can be broken into 3 pieces, can be broken into 3 pieces, ww = = xyzxyz, such t, such t

hat the three conditions 1~3 hold.hat the three conditions 1~3 hold.

Page 9: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

9

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

– In particular, pick the string In particular, pick the string ww = 0 = 0nn11nn whose le whose le

ngth is 2ngth is 2n. n. We know that We know that ww is in is in LLeqeq..

– BecauseBecause ||w| = w| = 22nn > > nn, by Theorem 4.1, string , by Theorem 4.1, string

ww can be broken into 3 pieces, can be broken into 3 pieces, ww = = xyz,xyz, so that so that

• yy

• |xy|xy| | nn; ;

• for all for all kk 0, 0, xyxykkzzLL. .

Page 10: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

10

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

– |xy|xy| | nn says that says that xyxy consists of consists of all 0’s all 0’s becausbecaus

e e ww = = 00nn11n n ..

– Furthermore, Furthermore, yy sayssays yy has at least one 0 has at least one 0. .

(A)(A)

– Now, Now, take take kk to be 0 to be 0 and the and the pumpingpumping in the 3r in the 3r

d condition says that d condition says that

xyxy00z = xz = xz = xz z = xz LL is true. is true.

(B)(B)

Page 11: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

11

4.1 Proving Languages Not to Be 4.1 Proving Languages Not to Be RegularRegular

– However, by However, by (A)(A) at least one 0 disappears w at least one 0 disappears w

hen hen yy was “pumped” out . was “pumped” out .

– This means that the resulting string This means that the resulting string xz xz cannocanno

t have equal numbers of 0’s and 1’st have equal numbers of 0’s and 1’s,, i.e., xz i.e., xz

LL. . Contradictive to Contradictive to (B)(B) above! above!

– So, the original assumption “So, the original assumption “LLeqeq is an RL” is is an RL” is

false false (according to principle of “proof by contradiction.”). (according to principle of “proof by contradiction.”). Done!Done!

Page 12: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

12

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s

• Closure means “being closed” in the Closure means “being closed” in the same type of language domain, such as same type of language domain, such as RL’s.RL’s.

• We will prove a set of We will prove a set of ““closureclosure”” theorems theorems of the form ---of the form ---““if certain languages are regular, and a if certain languages are regular, and a

language language LL is formed from them by certain is formed from them by certain operations, then operations, then LL is also regular.” is also regular.”

Page 13: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

13

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s

• Language operations for the above statement Language operations for the above statement to be true include:to be true include:– UnionUnion– ConcatenationConcatenation– Closure (star)Closure (star)

– IntersectionIntersection– ComplementationComplementation– DifferenceDifference– ReversalReversal

– HomomorphismHomomorphism– Inverse homomorphismInverse homomorphism

Page 14: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

14

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s

• 4.2.1~4.2.44.2.1~4.2.4 (for proofs, see the textbook) (for proofs, see the textbook)

– Let Let LL and and MM be two RL’s over alphabet be two RL’s over alphabet ..

– Theorem 4.4Theorem 4.4 - the union - the union LL∪∪MM is an RL. is an RL.

– Theorem 4.5Theorem 4.5 - the complement - the complement = = L L is an is an

RL (RL (** is the universal language) is the universal language)

L

Page 15: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

15

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s

• 4.2.1~4.2.44.2.1~4.2.4 (for proofs, see the textbook) (for proofs, see the textbook)

– Theorem 4.8Theorem 4.8 - the intersection - the intersection LL∩∩MM is an RL. is an RL.

– Theorem 4.10Theorem 4.10 - the difference - the difference LL MM is an RL. is an RL.

– TheoremsTheorems – the concatenation – the concatenation LMLM and the and the

closure closure LL** are RL’s are RL’s (no theorem numbers; mentioned in a frame (no theorem numbers; mentioned in a frame

on the top of p. 135).on the top of p. 135).

Page 16: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

16

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s

– The The reversalreversal of a string of a string ww = = aa11aa22, …, … a ann

is is wwRR = = aannaann--11……aa22aa11..

– The The reversalreversal LLRR of a language of a language LL is the l is the l

anguage consisting of the reversals of aanguage consisting of the reversals of a

ll its strings.ll its strings.

– Theorem 4.11Theorem 4.11 --- the reversal --- the reversal LLRR of an of an

RL RL LL is also an RL. is also an RL.

Page 17: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

17

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s

– AA (string) homomorphism(string) homomorphism is a function is a function hh which which substitutes a particular string for each substitutes a particular string for each symbol.symbol.

That is, That is, hh((aa) = ) = xx, where , where aa is a symbol and is a symbol and xx is is a string.a string.

– Given Given ww = = aa11aa22……aann, define , define

hh((ww) = ) = hh((aa11))hh((aa22)…)…hh((aann).).

– Given a language, define Given a language, define

hh((LL) = {) = {hh((ww) | ) | wwLL}.}.

Page 18: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

18

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s– Example 4.13Example 4.13

• Let function Let function hh be defined as be defined as

hh(0)= (0)= abab and and hh(1) (1) ,,

then then hh is a string homomorphism. is a string homomorphism.

• For examples,For examples,

1. 1. hh(0011) = (0011) = hh(0)(0)hh(0)(0)hh(1)(1)hh(1)(1)

= = abababab = = abab abab..

2. If RE 2. If RE rr = = 1010**11, then , then hh((LL((rr)) = )) = LL((ab)((ab)**).).

Page 19: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

19

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s

– Theorem 4.14Theorem 4.14 - If - If LL is an RL, then is an RL, then hh((LL) is ) is also an RL where also an RL where hh is a homomorphism. is a homomorphism.

– Inverse homomorphismInverse homomorphism::

Let Let hh be a homomorphism from some alphabet be a homomorphism from some alphabet to strings in another alphabet to strings in another alphabet TT. Let . Let LL be an RL be an RL over over TT. Then . Then hh11((L L ) is the set of strings ) is the set of strings ww such such that that hh((ww) is in ) is in LL..

– hh11((L L ) is read “) is read “hh inverse of inverse of LL.”.”

Page 20: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

20

4.2 Closure Properties of RL’s4.2 Closure Properties of RL’s

– Example 4.15Example 4.15 --- ---• Let Let LL = = LL((((0000 + + 11))**))• Let (string) homomorphism Let (string) homomorphism hh be defined as be defined as

hh((aa) = 01, ) = 01, hh((bb) = 10.) = 10.• It can be proved that It can be proved that

hh11((LL) = ) = LL((((baba))**))

(see the textbook).(see the textbook).

– Theorem 4.16Theorem 4.16 - - If If hh is a homomorphism fro is a homomorphism from alphabet m alphabet to alphabet to alphabet TT, and , and LL is an RL, t is an RL, then hen hh11((LL) is also an RL.) is also an RL.

Page 21: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

21

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.1 Converting among Representations 4.3.1 Converting among Representations – Assume Assume

• #symbols = constant#symbols = constant

• #states = #states = n.n.

(for proofs, see the textbook)(for proofs, see the textbook)

– Conversion from an Conversion from an -NFA to a DFA-NFA to a DFA --- --- requiring O(requiring O(nn3322nn) time in the worse cases ) time in the worse cases

– Conversion from a DFA to an NFAConversion from a DFA to an NFA --- --- requiring O(requiring O(nn) time) time

Page 22: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

22

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.1 Converting among Representations 4.3.1 Converting among Representations

– From an automaton (DFA) to an REFrom an automaton (DFA) to an RE --- ---

requiring O(requiring O(nn3344nn) time) time

– From an RE to an automaton (From an RE to an automaton (-NFA)-NFA) --- ---

requiring requiring linearlinear time in the size of the RE time in the size of the RE

Page 23: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

23

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.2 Testing 4.3.2 Testing EmptinessEmptiness of RL’s of RL’s– Testing if a regular language generated by Testing if a regular language generated by

an automaton is an automaton is emptyempty::• Equivalent to testing if there exists Equivalent to testing if there exists nono path from path from

the start state to an accepting state.the start state to an accepting state.

• Requiring Requiring O(O(nn22)) time in the worse case. time in the worse case.

• Why? Time proportional to #arcs Why? Time proportional to #arcs

each state has at most each state has at most nn arcs (to the arcs (to the nn states) states) at most at most nn22 arcs arcs at most O( at most O(nn22) time ) time

Page 24: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

24

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.2 Testing Emptiness of RL’s4.3.2 Testing Emptiness of RL’s

– Testing if a language generated by an Testing if a language generated by an RREE is empty: is empty:• A 2-step method: see the next pageA 2-step method: see the next page

• A direct method: easy; see p. 154 of the teA direct method: easy; see p. 154 of the textbook.xtbook.

Page 25: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

25

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.2 Testing Emptiness of RL’s4.3.2 Testing Emptiness of RL’s– A 2-step method for testing if a language generA 2-step method for testing if a language gener

ated by an ated by an RERE is empty: is empty:• Convert the RE to an Convert the RE to an -NFA-NFA --- --- requiring O(requiring O(ss) time as said previously, where ) time as said previously, where

s = |RE| (length of RE).s = |RE| (length of RE).• Test if the language of the Test if the language of the -NFA is empty-NFA is empty --- --- requiring O(requiring O(nn22) time as said above.) time as said above.

– The overall time requirement is The overall time requirement is O(O(ss)) ++ O(O(nn22) )

Page 26: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

26

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.2 Testing Emptiness of RL’s4.3.2 Testing Emptiness of RL’s– Conclusion:Conclusion:

The problem of testing emptiness of RL’s is The problem of testing emptiness of RL’s is ddecidableecidable (i.e., there exists an algorithm to ans(i.e., there exists an algorithm to answer the problem)wer the problem)..

– Note: RL’s may be accepted by various autoNote: RL’s may be accepted by various automata (DFA’s, NFA’s, mata (DFA’s, NFA’s, -NFA’s) or generated -NFA’s) or generated by RE’s.by RE’s.

Page 27: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

27

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.3 Testing 4.3.3 Testing MembershipMembership in an RL in an RL– Membership ProblemMembership Problem::

given an RL given an RL LL and a string and a string ww, is , is wwLL??

– If If LL is represented by a is represented by a DFADFA, the algorithm , the algorithm to answer the problem requires O(to answer the problem requires O(nn) time, ) time, where where nn | |ww| (# symbols in the string | (# symbols in the string instead of #states of the automaton).instead of #states of the automaton).

– Why?Why? Just processing input symbols one by Just processing input symbols one by one to see if an accepting state is reached.one to see if an accepting state is reached.

Page 28: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

28

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.3 Testing Membership in an RL4.3.3 Testing Membership in an RL– If If LL is represented by an is represented by an NFANFA without without --

transitions, the algorithm requires O(transitions, the algorithm requires O(nsns22) ) time, where time, where • nn | |ww| (# symbols in string | (# symbols in string ww instead of instead of

#states#states))• ss = #states = #states

– Why?Why? Just processing input symbols one by Just processing input symbols one by one to see if an accepting state is reached, one to see if an accepting state is reached, and at each state there are at most and at each state there are at most ss22 choices choices of next statesof next states..

Page 29: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

29

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.3 Testing Membership in an RL4.3.3 Testing Membership in an RL– If If LL is represented by an is represented by an -NFA-NFA, the , the

algorithm has to compute the algorithm has to compute the -closures at -closures at first before processing the symbols.first before processing the symbols.• Computing Computing -closures requires O(-closures requires O(ss22)+O()+O(ss22)= )=

O(O(ss22) time ) time (see the textbook).(see the textbook).• Processing the input string of symbols needs Processing the input string of symbols needs

nnO(O(ss22)=O()=O(nsns22) time.) time.• Overall required time is O(Overall required time is O(nsns22))

Page 30: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

30

4.3 Decision Properties of RL’s4.3 Decision Properties of RL’s

• 4.3.3 Testing Membership in an RL4.3.3 Testing Membership in an RL– If If LL is represented by an RE is represented by an REof size of size ss, the al, the al

gorithm first transforms it to an gorithm first transforms it to an -NFA with -NFA with at most at most 22ss states states in O(in O(ss) time) time, and then do as , and then do as before (said in the last page).before (said in the last page).

– Conclusion:Conclusion:

The problem of testing the membership of aThe problem of testing the membership of an RL is n RL is decidabledecidable..

Page 31: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

31

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• What we want to show in this section:What we want to show in this section:

– Testing whether two descriptions of RL’s Testing whether two descriptions of RL’s

define the same languages.define the same languages.

– Minimization of DFA’s ---Minimization of DFA’s ---

• Good for implementations of DFA’s with less Good for implementations of DFA’s with less

resources (like space, time, IC areas, …)resources (like space, time, IC areas, …)

Page 32: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

32

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.1 Testing Equivalence of States4.4.1 Testing Equivalence of States– GoalGoal: :

want to understand when two distinct want to understand when two distinct states states pp and and qq can be replaced by a can be replaced by a single state that behaves like both single state that behaves like both pp and and qq..

Page 33: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

33

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.1 Testing Equivalence of States4.4.1 Testing Equivalence of States– Two states are said Two states are said equivalentequivalent if if

for all strings for all strings ww, , ((pp, , ww) is an ) is an acceptingaccepting state if and only if state if and only if ((qq, , ww) is an ) is an acceptingaccepting state.state.

– Note:Note:• It is It is notnot necessary to enter necessary to enter the samethe same accepting accepting

state for the above definition to be met.state for the above definition to be met.• We only require that We only require that eithereither both states are both states are

acceptingaccepting oror both states are non-acceptingboth states are non-accepting. .

Page 34: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

34

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.1 Testing Equivalence of States4.4.1 Testing Equivalence of States– Non-equivalent states are said to be Non-equivalent states are said to be

distinguishabledistinguishable.. That is, state That is, state pp is said to be distinguishable is said to be distinguishable

from from qq if there is at least a string if there is at least a string ww such such that one of (that one of (pp, , ww) and () and (qq, , ww) is accepting, ) is accepting, and the other is and the other is notnot accepting. accepting.

– A systematic way to find distinguishable A systematic way to find distinguishable states --- use a states --- use a table-filling algorithmtable-filling algorithm (see (see the next page).the next page).

Page 35: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

35

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.1 Testing Equivalence of States4.4.1 Testing Equivalence of States– Table-filling algorithmTable-filling algorithmBasisBasis..

If If pp is an accepting state and is an accepting state and qq is not, then the pair { is not, then the pair {pp, , qq} is distinguishable.} is distinguishable.

InductionInduction. .

– Let Let pp and and qq be states such that for some input symbol be states such that for some input symbol aa, the next states , the next states rr ((pp, , aa) and ) and ss ((qq, , aa) are know) are known to be distinguishable.n to be distinguishable. Then {Then {pp, , qq} are distinguishabl} are distinguishable. e. (dist. pair (dist. pair rr, , ss 的的前行者前行者 p, qp, q也是也是 dist. pair)dist. pair)

– Why?Why? See the next page. (dist. = distinguishable)See the next page. (dist. = distinguishable)

Page 36: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

36

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.1 Testing Equivalence of States4.4.1 Testing Equivalence of States

rr ((pp, , aa), ), ss ((qq, , aa) are distinguishable) are distinguishable

There exists a string There exists a string ww such that such that onlyonly one of one of ((rr, , ww) and ) and ((ss, , ww) is accepting.) is accepting.

But (But (pp, , awaw) = () = (rr, , ww), (), (qq, , awaw) = () = (ss, , ww))

There exists a string There exists a string awaw such that such that onlyonly one of one of ((pp, , awaw) and ) and ((qq, , awaw) is accepting.) is accepting.

pp and and qq are distinguishable. are distinguishable.

Page 37: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

37

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.1 Testing Equivalence of States4.4.1 Testing Equivalence of States– Example 4.19Example 4.19 --- apply the algorithm to the --- apply the algorithm to the

DFA shown in Fig. 4.18 (below).DFA shown in Fig. 4.18 (below).

1

C B

0

D 0 A start

1 E 1

F G H

0

0

0

0

1

1 1

1

0

0 1

Page 38: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

38

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

– Basis: Since Basis: Since CC is the only accepting state, is the only accepting state, we put an “we put an “xx” into the pairs of {” into the pairs of {AA, , CC}, {}, {BB, , CC}, {}, {CC, , DD}, {}, {CC, , EE}, {}, {CC, , FF}, {}, {CC, , GG}, {}, {CC, , HH}, with }, with xx meaning “distinguishable”. meaning “distinguishable”.

B

C x x

D x

E x

F x

G x

H x

A B C D E F G

Page 39: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

39

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

– Induction: For the pair {Induction: For the pair {CC, , HH}, input 0 }, input 0 brings pair {brings pair {EE, , FF} to pair {} to pair {CC, , HH}, so {}, so {EE, , FF} are distinguishable and the pair is } are distinguishable and the pair is marked.marked. B

C x x

D x

E x

F x x

G x

H x

A B C D E F G

Page 40: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

40

4.4 Equivalence & Minimization of Automata4.4 Equivalence & Minimization of Automata

– Find other pairs by using Find other pairs by using existingexisting pairs pairs (colored pairs are found from the bold red (colored pairs are found from the bold red pair as “triggers” & subscripts are inputs).pair as “triggers” & subscripts are inputs).

– Do this for all pairs Do this for all pairs in orderin order recursivelyrecursively until no more pair can be marked.until no more pair can be marked.

B

C x x

D x0 x

E x x

F x0, 1 x

G x x0 x0

H x x0 x0, 1

A B C D E F G

1

C B

0

D 0 A start

1 E 1

F G H

0

0

0

0

1

1 1

1

0

0 1

Page 41: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

41

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

– Final results are as follows.Final results are as follows.

– The above method described in the textbook “wastes” some The above method described in the textbook “wastes” some intermediate results. A better way is given next.intermediate results. A better way is given next.

B xC x x

D x x x

E x x x

F x x x x

G x x x x x xH x x x x x x

A B C D E F G

1

C B

0

D 0 A start

1 E 1

F G H

0

0

0

0

1

1 1

1

0

0 1

Page 42: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

42

4.4 Equivalence & Minimization of Automata4.4 Equivalence & Minimization of Automata

– A better way ---A better way --- ( see 3 ( see 3rdrd paragraph, p. 160 in textbook) paragraph, p. 160 in textbook) after finding after finding distinguishable pairs by final states and mark them by distinguishable pairs by final states and mark them by ““xx” in the table, perform:” in the table, perform:• Set up a Set up a listlist for each pair in the table for each pair in the table, initially empty, initially empty..• For each For each unmarkedunmarked pair { pair {pp, , qq}, do:}, do:

– For each symbol For each symbol aa, compute , compute rr((pp, , aa), ), ss((qq, , aa).).– IfIf any pair { any pair {rr, , ss} is marked} is marked, then, then also mark the pair also mark the pair

{{pp, , qq} } as well as all the pairs in the listas well as all the pairs in the list of the pair of the pair {{pp, , qq}, and }, and also recursivelyalso recursively all the pairs in the lists all the pairs in the lists of just-marked pairsof just-marked pairs;;

elseelse put the pair {put the pair {pp, , qq} into the list of each pair of } into the list of each pair of {{rr, , ss}.}.

• Repeat the last step until no more pair in the table can Repeat the last step until no more pair in the table can be marked.be marked.

Page 43: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

43

Bv x

C x x

D x

E x

F x

G x x

H x

A B C D E F G

B x

C x x

D x

E x

F x

G x x x

H x

A B C D E F G

1

C B

0

D 0 A start

1 E 1

F G H

0

0

0

0

1

1 1

1

0

0 1

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

Bv x

C x x

D x

E x

F x

G x

H x

A B C D E F G

B x

C x x

D x

E x

F x

G x x x

H x

A B C D E F G

{{rr, , ss} = {} = {BB, , GG}, {}, {FF, , CC} with {} with {FF, , CC} } already marked, so mark {already marked, so mark {pp, , qq} = } = {{AA, , BB}}

{{rr, , ss} = {} = {BB, , GG}, {}, {EE, , FF} with both } with both unmarked, so put {unmarked, so put {AA, , GG} into lists of } into lists of {{BB, , GG} and {} and {EE, , FF}}

List = List = {{AA, , GG}}

{{rr, , ss} = {C, } = {C, EE} } which is marked which is marked already, so mark already, so mark {{BB, , GG} and } and also also {{AA, , GG} in the list} in the list

List = {List = {AA, , GG}}

Page 44: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

44

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

– Final results are as follows.Final results are as follows.

– Then, Then, what???what???

B xC x x

D x x x

E x x x

F x x x x

G x x x x x xH x x x x x x

A B C D E F G

1

C B

0

D 0 A start

1 E 1

F G H

0

0

0

0

1

1 1

1

0

0 1

Page 45: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

45

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.1 Testing Equivalence of States4.4.1 Testing Equivalence of States– Theorem 4.20Theorem 4.20 If two states are not If two states are not

distinguishable by the table-filling algorithm, then distinguishable by the table-filling algorithm, then they are equivalent.they are equivalent.

• 4.4.2 Taught later4.4.2 Taught later

• 4.4.3 Minimization of DFA’s4.4.3 Minimization of DFA’s– Group equivalent states into a block and regard Group equivalent states into a block and regard

each block as a new state in the minimized DFA.each block as a new state in the minimized DFA.– Take the block containing the old start state as the Take the block containing the old start state as the

new start state.new start state.– Take the new accepting states as those blocks Take the new accepting states as those blocks

which contain old accepting states.which contain old accepting states.

Page 46: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

46

4.4 Equivalence & Minimization of Automata4.4 Equivalence & Minimization of Automata

• 4.4.3 Minimization of DFA’s4.4.3 Minimization of DFA’s– Example 4.25Example 4.25 (cont’d from Example 4.19) (cont’d from Example 4.19)

• The final result below says (The final result below says (AA, , EE), (), (BB, , HH), (), (DD, , FF) ) are equivalent states and can be put into 3 are equivalent states and can be put into 3 blocks as states of the new DFA. The final new blocks as states of the new DFA. The final new DFA is as follows (right).DFA is as follows (right).

B x

C x x

D x x x

E x x x

F x x x x

G x x x x x x

H x x x x x x

A B C D E F G

1

C B, H

0

D, F 0 A, E 開始

G

0

0

1

0 1

1

1

start

Fig. 4.12 (identical to that in textbook except drawing style)

Page 47: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

47

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.2 Testing Equivalence of RL’s4.4.2 Testing Equivalence of RL’s– Use the table filling algorithmUse the table filling algorithm– Given two DFA’s Given two DFA’s AALL and and AAMM with with startstart states states qqLL and and qqMM, ,

respectively, for two RL’s respectively, for two RL’s LL and and MM, we can test if their , we can test if their languages are equivalent by:languages are equivalent by:

• Imagine a third DFA Imagine a third DFA AA33 whose states are whose states are unionunion of those of of those of AALL and and AAMM..

• Test if Test if qqLL and and qqMM are equivalent; if so,are equivalent; if so, L L andand M M areare equivalent.equivalent.• Why? Because accepting the same set of strings, i.e., the samWhy? Because accepting the same set of strings, i.e., the sam

e set of languages.e set of languages.

– See Example 4.21 for an example.See Example 4.21 for an example.

Page 48: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

48

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.2 Testing Equivalence of RL’s4.4.2 Testing Equivalence of RL’s

– The table filling algorithm requires O(The table filling algorithm requires O(nn22) time ) time

where where nn = #states. = #states.

– ConclusionConclusion::

The problem of testing the equivalence of two The problem of testing the equivalence of two

RL’s is decidable.RL’s is decidable.

Page 49: 1 Chapter 4 Properties of Regular Languages Pasbag, Turkey

49

4.4 Equivalence & Minimization 4.4 Equivalence & Minimization of Automataof Automata

• 4.4.4 Why the Minimized DFA’s Can’t 4.4.4 Why the Minimized DFA’s Can’t be Beatenbe Beaten– The minimized DFA by the table filling algorithm The minimized DFA by the table filling algorithm

is really the “minimal,” having the is really the “minimal,” having the fewestfewest states in states in all DFA’s which accept the same language, as all DFA’s which accept the same language, as guaranteed by the following theorem.guaranteed by the following theorem.

– Theorem 4.26Theorem 4.26 If If AA is a DFA, and is a DFA, and MM the DFA the DFA constructed from constructed from AA by the table filling algorithm, by the table filling algorithm, then then MM has as few states as any DFA equivalent to has as few states as any DFA equivalent to AA..