Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.

Similar presentations


Presentation on theme: "1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012."— Presentation transcript:

1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012

2 2 Content - More Properties of Regular Languages (RL) - Standard Representations of RL - Elementary Questions about RL - Non-Regular Languages - The Pigeonhole Principle - The Pumping Lemma - Applications of the Pumping Lemma - NFA-DFA repetition

3 3 More Properties of Regular Languages Based on C Busch, RPI, Models of Computation

4 4 We have shown Regular languages are closed under Union Concatenation Star operation Reverse

5 5 Namely, for regular languages and : Union Concatenation Star operation Reverse Regular Languages

6 6 We will show that Regular languages are also closed under Complement Intersection

7 7 Namely, for regular languages and : Complement Intersection Regular Languages

8 8 Complement Theorem For regular language the complement is regular. Proof Take DFA that accepts and exchange: non-accepting states  accepting states Resulting DFA accepts

9 9 Example

10 10 Intersection TheoremFor regular languages and the intersection is regular. ProofApply DeMorgan’s Law:

11 11 regular

12 12 Standard Representations of Regular Languages

13 13 Regular Language Representations DFA NFA Regular Expression Regular Grammar Regular Language

14 14 Elementary Questions about Regular Languages

15 15 Membership Question Question: Given regular language and string how can we check if ? Answer: Take the DFA that accepts and check if is accepted.

16 16 DFA

17 17 Take the DFA that accepts. Check if there is a path from the initial state to a final state. Given regular language how can we check if is empty: ? Question: Answer: Empty Language Question

18 18 DFA

19 19 Given regular language how can we check if is finite? Take the DFA that accepts. Check if there is a walk with a cycle from the initial state to a final state. Question: Answer: Finiteness Question

20 20 DFA is infinite DFA is finite

21 21 Given regular languages and how can we check if ? Question: Find if Answer: Equality Question

22 22 and

23 23 or

24 24 Non-Regular Languages

25 25 Regular languages Non-regular languages

26 26 How can we prove that a language is not regular? Prove that there is no DFA that accepts Problem: this is not easy to prove. Solution: the Pumping Lemma !

27 27 The Pigeonhole Principle

28 28 The Pigeonhole Principle

29 29 pigeons pigeonholes

30 30 A pigeonhole must contain at least two pigeons

31 31........... pigeons pigeonholes

32 32 The Pigeonhole Principle........... pigeons pigeonholes There is a pigeonhole with at least 2 pigeons

33 33 The Pigeonhole Principle and DFAs

34 34 DFA with states

35 35 In walks of strings:no state is repeated

36 36 In walks of strings:a state is repeated

37 37 If the walk of string has length then a state is repeated

38 38 If in a walk of a string transitions states of DFA then a state is repeated Pigeonhole principle for any DFA:

39 39 In other words for a string transitions are pigeons states are pigeonholes

40 40 A string has length number of states A state must be repeated in the walk of In general...... walk of

41 41 The Pumping Lemma for Regular Languages see also http://www.math.uu.se/~salling/Movies/Nonregularity.mov

42 42 Take an infinite regular language DFA that accepts states

43 43 Take string with There is a walk with label......... walk

44 44 If string has length then, from the pigeonhole principle: a state is repeated in the walk...... walk ( number of states)

45 45 Write......

46 46 Lengths:...... (from pigeon principle, as q is the first repetition in sequence) (there is a walk in the graph)

47 47 The string is acceptedObservation:......

48 48 The string is accepted Observation:......

49 49 The string is accepted Observation:......

50 50 The string Generally:...... is accepted

51 51 The Pumping Lemma Given an infinite regular language there exists an integer such that for any string with length we can write with and such that:

52 52 Applications of the Pumping Lemma

53 53 Theorem The language is not regular. Proof Use the Pumping Lemma!

54 54 Assume to the contrary, that is a regular language. Since is infinite we can apply the Pumping Lemma.

55 55 Let be the integer in the Pumping Lemma Pick a string such that: with length e.g. pick

56 56 Write: it must be that length From the Pumping Lemma Therefore:

57 57 From the Pumping Lemma: We can choose We have: CONTRADICTION!

58 58 Therefore: Our assumption that is a regular language is not true. Conclusion is not a regular language. END OF PROOF

59 59 Regular languages Non-regular languages

60 60 TheoremThe language Proof Use the Pumping Lemma! is not regular.

61 61 Assume to the contrary, that is a regular language. Since is infinite we can apply the Pumping Lemma.

62 62 pick Pick a string such that: length Let be the integer in the Pumping Lemma.

63 63 Write it must be that length From the Pumping Lemma

64 64 We can choose CONTRADICTION! So we get a’s on the left, while is on the right:

65 65 Conclusion is not a regular language. Our assumption that is a regular language is not true. Therefore: END OF PROOF

66 66 Regular languages Non-regular languages

67 67 Theorem The language is not regular. Proof Use the Pumping Lemma.

68 68 Assume to the contrary that is a regular language. Since is infinite we can apply the Pumping Lemma.

69 69 Pick Let be the integer in the Pumping Lemma. Pick a string such that: length

70 70 Write it must be that length From the Pumping Lemma

71 71 From the Pumping Lemma Thus: We have:

72 72 Therefore: BUT: CONTRADICTION!

73 73 Conclusion is not a regular language. Therefore: Our assumption that is a regular language is not true. END OF PROOF

74 74 Regular languages Non-regular languages

75 75 Theorem The language is not regular. Proof Use the Pumping Lemma. Factorial of n, (n!) is the product of all positive integers less than or equal to n. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120 The value of 0! is 1.

76 76 Assume to the contrary that is a regular language. Since is infinite we can apply the Pumping Lemma.

77 77 Pick Pick a string such that: length Let be the integer in the Pumping Lemma.

78 78 Write From the Pumping Lemma it must be that length

79 79 From the Pumping Lemma: Thus: We have:

80 80 Therefore: Since: There is

81 81 However )!1(  m)1(!  mm!!  mmm !!  mm!  mm for for any

82 82 Therefore: BUT: CONTRADICTION! and

83 83 Conclusion is not a regular language. Our assumption that is a regular language is not true. Therefore: END OF PROOF

84 84 Regular languages Non-regular languages

85 85 Theorem The language is not regular. Proof Use the Pumping Lemma.

86 86 Assume to the contrary, that is a regular language. Since is infinite we can apply the Pumping Lemma.

87 87 it must be that length length From the Pumping Lemma: The length of must be prime for each string of.

88 88 Thus: But, choosing which is not prime! CONTRADICTION!

89 89 Conclusion is not a regular language. Our assumption that is a regular language is not true. Therefore: END OF PROOF

90 90 Regular languages Non-regular languages

91 91 Theorem The language is not regular. Proof Use the Pumping Lemma! For your exercise: An alternative variant of proof from slide 53.

92 92 Assume to the contrary that is a regular language. Since is infinite we can apply the Pumping Lemma.

93 93 Pick a string such that: length Pick Let be the integer in the Pumping Lemma.

94 94 Write: it must be that: length From the Pumping Lemma Therefore:

95 95 From the Pumping Lemma: Thus: We have:

96 96 Therefore: BUT: CONTRADICTION

97 97 Our assumption that is a regular language is not true. Conclusion: is not a regular language. Therefore: END OF PROOF

98 98 Pumping Lemma, in short

99 99 Observation: Every language of finite size has to be regular. (We can easily construct an NFA that accepts every string in the language, or a union of regular expressions) Therefore, every non-regular language has to be of infinite size. (contains an infinite number of strings)

100 100 Suppose you want to prove that An infinite language is not regular 1. Assume the opposite: is regular 2. The pumping lemma should hold for 3. Use the pumping lemma to obtain a contradiction 4. Therefore, is not regular

101 101 Explanation of Step 3: How to get a contradiction with pumping lemma i. Find a particular string which satisfies the conditions of the pumping lemma ii. Write iii. Show thatfor some iv. This gives a contradiction, since from pumping lemma

102 102 Note: It suffices to show that only one string gives a contradiction You don’t need to obtain contradiction for every

103 103 Extra Examples on Regular Languages

104 104 FA  RE

105 105 FA  RE or

106 106 NFA  DFA Subset Construction Delmängdkonstruktion

107 107 Convert an NFA to DFA using the subset construction

108 108 Each state of the DFA is a set of states of the NFA. Start by the initial state of the DFA which is the  -closure of the initial state of the NFA (all the states you reach by  - transitions from the initial state). CLOSE{0}={0, 1, 3}=S 0

109 109 Determine the transition function of the DFA on all inputs. Begin with the initial state S 0, and determine the transition on input a. CLOSE{0} = {0, 1, 3} = S 0  (S 0, a) = CLOSE{1, 2}

110 110 The  -closure of the set {1, 2} is {1, 2, 3} This is a new state in the DFA, call it S 1. CLOSE{0} = {0, 1, 3} = S 0  (S 0, a) = CLOSE{1, 2} = {1, 2, 3} = S 1

111 111 With the initial state S 0, determine the transition on input b. CLOSE{0} = {0, 1, 3} = S 0  (S 0, a) = CLOSE{1, 2} = {1, 2, 3} = S 1  (S0, b) = CLOSE{3}

112 112 The  - closure of the set {3} is {1, 3}. This is a new state in the DFA, call it S 2. CLOSE{0} = {0, 1, 3} = S 0  (S 0, a) = CLOSE{1, 2} = {1, 2, 3} = S 1  (S0, b) = CLOSE{3} = {1, 3} = S 2

113 113 Determine the transition function of the DFA from state S 1 on inputs a and b. On a there is no where to go in the NFA, so we create a “sink“(“trap”) state for DFA.  (S 0, a) = CLOSE{1, 2} = {1, 2, 3} = S 1  (S 0, b) = CLOSE{3} = {1, 3} = S 2  (S 1, a) = CLOSE{} =  = S 3

114 114 Determine the transition function of the DFA from state S 1 on inputs a and b. On b there is a transition to an existing state S 2.  (S 0, a) = CLOSE{1, 2} = {1, 2, 3} = S 1  (S 0, b) = CLOSE{3} = {1, 3} = S 2  (S 1, a) = CLOSE{} =  = S 3  (S 1, b) = CLOSE{3} = {1, 3} = S2

115 115 Determine the transition from state S 2 on inputs a and b.  (S 0, a) = CLOSE{1, 2} = {1, 2, 3} = S 1  (S 0, b) = CLOSE{3} = {1, 3} = S 2  (S 1, a) = CLOSE{} =  = S 3  (S 1, b) = CLOSE{3} = {1, 3} = S 2  (S 2, a) = CLOSE{} =  = S 3  (S 2, b) = CLOSE{3} = {1, 3} = S 2

116 116 Determining the transition from state S 2 on inputs a and b is easy ; from the empty set of states there are no transitions in the NFA. In the DFA this is represented by a transition from the empty set back to itself.

117 117 The final states of the DFA are determined from the final states of the NFA. State 3 was the only final state in the NFA. (Any set of NFA states containing a final state is a final state in the DFA.)

118 118 NFA  DFA RESULT

119 State elimination +10* 0*11 0*1 qq qq qq 01 qq qq  +10*)(0*1)*0*11 qq qq  +10*)(0*1)*0*11 + 01

120 Example 7 Convert the following NFA to DFA. s p 0 ε 0 ε 0 1 1 ε 0 r s r p 0 qrqr p 1 s q, r, p 0 1 0 1 q

121 s p 0 0 0 1 1 0 r q 0 q 1 q r p 0 1 0 1 Converting the NFA to DFA p r s

122 122 Application: Lex - lexical analyzer Lex RE NFADFA Minimal DFA The final states of the DFA are associated with actions.


Download ppt "1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012."

Similar presentations


Ads by Google