Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Decision Properties of Regular Languages General Discussion of “Properties” The Pumping Lemma Minimizing DFA.

Similar presentations


Presentation on theme: "1 Decision Properties of Regular Languages General Discussion of “Properties” The Pumping Lemma Minimizing DFA."— Presentation transcript:

1 1 Decision Properties of Regular Languages General Discussion of “Properties” The Pumping Lemma Minimizing DFA

2 2 Properties of Language Classes uA language class is a set of languages. wExample: the regular languages. uLanguage classes have two important kinds of properties: 1.Decision properties. 2.Closure properties.

3 3 Closure Properties uA closure property of a language class says that given languages in the class, an operation (e.g., union) produces another language in the same class. uExample: the regular languages are obviously closed under union, concatenation, and (Kleene) closure. wUse the RE representation of languages.

4 4 Representation of Languages uRepresentations can be formal or informal. uExample (formal): represent a language by a RE or FA defining it. uExample: (informal): a logical or prose statement about its strings: w{0 n 1 n | n is a nonnegative integer} w“The set of strings consisting of some number of 0’s followed by the same number of 1’s.”

5 5 Decision Properties uA decision property for a class of languages is an algorithm that takes a formal description of a language (e.g., a DFA) and tells whether or not some property holds. uExample: Is language L empty?

6 6 Why Decision Properties? uThink about DFA’s representing protocols. uExample: “Does the protocol terminate?” = “Is the language finite?” uExample: “Can the protocol fail?” = “Is the language nonempty?” wMake the final state be the “error” state.

7 7 Why Decision Properties – (2) uWe might want a “smallest” representation for a language, e.g., a minimum-state DFA or a shortest RE. uIf you can’t decide “Are these two languages the same?” wI.e., do two DFA’s define the same language? You can’t find a “smallest.”

8 8 The Membership Problem uOur first decision property for regular languages is the question: “is string w in regular language L?” uAssume L is represented by a DFA A. uSimulate the action of A on the sequence of input symbols forming w.

9 9 Example: Testing Membership Start 1 0 ACB 1 0 0,1 0 1 0 1 1 Next symbol Current state

10 10 Example: Testing Membership Start 1 0 ACB 1 0 0,1 0 1 0 1 1 Next symbol Current state

11 11 Example: Testing Membership Start 1 0 ACB 1 0 0,1 0 1 0 1 1 Next symbol Current state

12 12 Example: Testing Membership Start 1 0 ACB 1 0 0,1 0 1 0 1 1 Next symbol Current state

13 13 Example: Testing Membership Start 1 0 ACB 1 0 0,1 0 1 0 1 1 Next symbol Current state

14 14 Example: Testing Membership Start 1 0 ACB 1 0 0,1 0 1 0 1 1 Next symbol Current state

15 15 What if We Have the Wrong Representation? uThere is a circle of conversions from one form to another: RE DFA NFA ε -NFA

16 16 The Emptiness Problem uGiven a regular language, does the language contain any string at all? uAssume representation is DFA. uCompute the set of states reachable from the start state. uIf at least one final state is reachable, then yes, else no.

17 17 The Infiniteness Problem uIs a given regular language infinite? uStart with a DFA for the language. uKey idea: if the DFA has n states, and the language contains any string of length n or more, then the language is infinite. uOtherwise, the language is surely finite. wLimited to strings of length n or less.

18 18 Proof of Key Idea uIf an n-state DFA accepts a string w of length n or more, then there must be a state that appears twice on the path labeled w from the start state to a final state. uBecause there are at least n+1 states along the path.

19 19 Proof – (2) w = xyz q x y z Then xy i z is in the language for all i > 0. Since y is not ε, we see an infinite number of strings in L.

20 20 The Pumping Lemma uRegular languages wAccepted by DFA, NFA, ε-NFA, RE wSome languages are not regular upumping lemma for regular languages is used to show a language is NOT regular

21 21 Statement of the Pumping Lemma For every regular language L There is an integer n, such that For every string w in L of length > n We can write w = xyz such that: 1.|xy| < n. 2.|y| > 0. 3.For all i > 0, xy i z is in L. Number of states of DFA for L Labels along first cycle on path labeled w

22 Pumping lemma uWe can find a nonempty string y not far from the beginning and can be pumped (repeated) as many times as you like and the result should still be in the language L 1.|xy| < n. 2.|y| > 0. 3.For all i > 0, xy i z is in L 22 q x y z

23 Adversarial Game uProver (P) vs. Adversary (A) wProver wants to prove L is not regular 1.P picks language L to prove nonregular 2.A picks n but not reveal it 3.P picks w > n, usually w depends on n ww L 4.A divides w into w = xyz without showing how but |xy| 0 5.P wins by picking k s.t. xy k z is NOT in L 23

24 24 Example: Use of Pumping Lemma uWe have claimed {0 k 1 k | k > 1} is not a regular language. 1.P picks L = {0 k 1 k | k > 1} 2.A picks n wWe don’t know what n is, some fixed value 3.P picks w = 0 n 1 n 4.A write w = xyz, |xy| < n, and y  ε. wxy must be all 0’s 5.xyyz NOT in L so proved L is not regular

25 Another Example uL pr consists of 1’s with length prime uP picks L pr and A picks n uP picks w = 1 p s.t. p > n+2  A picks w = xyz, |xy| < n, and y  ε wLet |y|=m and |xz|= p-m uP pumps y (p-m) times w|xy p-m z|=|xz|+(p-m)|y| = (p-m)(m+1) wThis is not prime so not in L 25

26 26 Efficient State Minimization uConstruct a table with all pairs of states. uIf you find a string that distinguishes two states (takes exactly one to an accepting state), mark that pair.

27 27 Love Start Love-15 15-Love s o Love-30 15-all 30-Love s s o o Love-40 15-30 30-15 40-Love s s s o o o Server Wins Opp’nt Wins s o 40-15 15-40 30-all s s s o o o 30-40 40-30 s s s o o o deuce s s o o Ad-out Ad-in s o s o s o

28 28 State Minimization – (2) uBasis: Mark pairs with exactly one final state.  Induction: mark [q, r] if for some input symbol a, [ δ (q,a), δ (r,a)] is marked. uAfter no more marks are possible, the unmarked pairs are equivalent and can be merged into one state.

29 29 Transitivity of “Indistinguishable” uIf state p is indistinguishable from q, and q is indistinguishable from r, then p is indistinguishable from r. uProof: The outcome (accept or don’t) of p and q on input w is the same, and the outcome of q and r on w is the same, then likewise the outcome of p and r.

30 30 Constructing the Minimum- State DFA uSuppose q 1,…,q k are indistinguishable states. uReplace them by one representative state q.  Then δ (q 1, a),…, δ (q k, a) are all indistinguishable states. wKey point: otherwise, we should have marked at least one more pair.  Let δ (q, a) = the representative state for that group.

31 31 Example: State Minimization r b {1} * {1,3,5,7,9}{2,4,6,8} {1,3,5,7,9} * {1,3,7,9}{2,4,6,8} {5} {2,4,6,8} {1,3,5,7,9}{2,4,6,8} {2,4,6,8} {1,3,7,9}{5} {2,4}{2,4,6,8} {1,3,5,7} {1,3,5,7} {2,4} {5} {2,4,6,8} {1,3,5,7,9} Remember this DFA? It was constructed for the chessboard NFA by the subset construction. r b A B C B D E C D F D D G E D G F D C G D G * * Here it is with more convenient state names

32 32 Example – Continued r b A B C B D E C D F D D G E D G F D C G D G * * G F E D C B A B C D E F x x x x x x x x x x Start with marks for the pairs with one of the final states F or G.

33 33 Example – Continued r b A B C B D E C D F D D G E D G F D C G D G * * G F E D C B A B C D E F x x x x x x x x x x Input r gives no help, because the pair [B, D] is not marked.

34 34 Example – Continued r b A B C B D E C D F D D G E D G F D C G D G * * G F E D C B A B C D E F x x x x x x x x x x But input b distinguishes {A,B,F} from {C,D,E,G}. For example, [A, C] gets marked because [C, F] is marked. x xx x x xx

35 35 Example – Continued r b A B C B D E C D F D D G E D G F D C G D G * * G F E D C B A B C D E F x x x x x x x x x x [C, D] and [C, E] are marked because of transitions on b to marked pair [F, G]. x xx x x xx xx

36 36 Example – Continued r b A B C B D E C D F D D G E D G F D C G D G * * G F E D C B A B C D E F x x x x x x x x x x [A, B] is marked because of transitions on r to marked pair [B, D]. x xx x x xx xx x [D, E] can never be marked, because on both inputs they go to the same state.

37 37 Example – Concluded r b A B C B D E C D F D D G E D G F D C G D G * * G F E D C B A B C D E F x x x x x x x x x x x xx x x xx xx x r b A B C B H H C H F H H G F H C G H G * * Replace D and E by H. Result is the minimum-state DFA.

38 38 Eliminating Unreachable States uUnfortunately, combining indistinguishable states could leave us with unreachable states in the “minimum-state” DFA. uThus, before or after, remove states that are not reachable from the start state.


Download ppt "1 Decision Properties of Regular Languages General Discussion of “Properties” The Pumping Lemma Minimizing DFA."

Similar presentations


Ads by Google