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

Slides:



Advertisements
Similar presentations
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Advertisements

Fall 2006Costas Busch - RPI1 Non-regular languages (Pumping Lemma)
3.2 Pumping Lemma for Regular Languages Given a language L, how do we know whether it is regular or not? If we can construct an FA to accept the language.
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
CS21 Decidability and Tractability
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
Courtesy Costas Busch - RPI1 More Applications of the Pumping Lemma.
Fall 2006Costas Busch - RPI1 Regular Expressions.
Fall 2003Costas Busch - RPI1 Decidability. Fall 2003Costas Busch - RPI2 Recall: A language is decidable (recursive), if there is a Turing machine (decider)
1 More Properties of Regular Languages. 2 We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Costas Busch - RPI1 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
Costas Busch - RPI1 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
1 More Applications of the Pumping Lemma. 2 The Pumping Lemma: Given a infinite regular language there exists an integer for any string with length we.
Courtesy Costas Busch - RPI1 Non-regular languages.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
Homework 4 Solutions.
Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Fall 2006Costas Busch - RPI1 More Applications of the Pumping Lemma.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Non-Deterministic Automata Regular Expressions.
Lecture 7UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7.
Prof. Busch - LSU1 Non-regular languages (Pumping Lemma)
Prof. Busch - LSU1 More Applications of the Pumping Lemma.
1 Non-regular languages. 2 Regular languages Non-regular languages.
Costas Busch - RPI1 More Applications of the Pumping Lemma.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 15-1 Mälardalen University 2012.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
TK PrasadPumping Lemma1 Nonregularity Proofs. TK PrasadPumping Lemma2 Grand Unification Regular Languages: Grand Unification (Parallel Simulation) (Rabin.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
Class Discussion Can you draw a DFA that accepts the language {a k b k | k = 0,1,2,…} over the alphabet  ={a,b}?
Properties of Regular Languages
CSCI 2670 Introduction to Theory of Computing September 13.
CS 203: Introduction to Formal Languages and Automata
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
1 Find as many examples as you can of w, x, y, z so that w is accepted by this DFA, w = x y z, y ≠ ε, | x y | ≤ 7, and x y n z is in L for all n ≥ 0.
Nonregular Languages How do you prove a language to be regular? How do you prove a language to be nonregular? A Pumping Lemma.
Equivalence with FA * Any Regex can be converted to FA and vice versa, because: * Regex and FA are equivalent in their descriptive power ** Regular language.
Formal Language & Automata Theory
Non-regular languages
Standard Representations of Regular Languages
CSE322 PUMPING LEMMA FOR REGULAR SETS AND ITS APPLICATIONS
Properties of Regular Languages
PROPERTIES OF REGULAR LANGUAGES
Formal Language & Automata Theory
CSE 3813 Introduction to Formal Languages and Automata
PDAs Accept Context-Free Languages
Single Final State for NFA
Infiniteness Test The Pumping Lemma Nonregular Languages
CSE322 PROPERTIES OF REGULAR LANGUAGES
4. Properties of Regular Languages
Deterministic PDAs - DPDAs
Elementary Questions about Regular Languages
Non-regular languages
Chapter 4 Properties of Regular Languages
Formal Languages, Automata and Models of Computation
More Applications of the Pumping Lemma
Instructor: Aaron Roth
Applications of Regular Closure
NFAs accept the Regular Languages
Presentation transcript:

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

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 More Properties of Regular Languages Based on C Busch, RPI, Models of Computation

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

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

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

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

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 Example

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

11 regular

12 Standard Representations of Regular Languages

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

14 Elementary Questions about Regular Languages

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 DFA

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 DFA

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 DFA is infinite DFA is finite

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

22 and

23 or

24 Non-Regular Languages

25 Regular languages Non-regular languages

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 The Pigeonhole Principle

28 The Pigeonhole Principle

29 pigeons pigeonholes

30 A pigeonhole must contain at least two pigeons

pigeons pigeonholes

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

33 The Pigeonhole Principle and DFAs

34 DFA with states

35 In walks of strings:no state is repeated

36 In walks of strings:a state is repeated

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

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

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

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

41 The Pumping Lemma for Regular Languages see also

42 Take an infinite regular language DFA that accepts states

43 Take string with There is a walk with label walk

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

45 Write......

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

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

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

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

50 The string Generally: is accepted

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 Applications of the Pumping Lemma

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

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

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

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

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

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

59 Regular languages Non-regular languages

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

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

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

63 Write it must be that length From the Pumping Lemma

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

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

66 Regular languages Non-regular languages

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

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

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

70 Write it must be that length From the Pumping Lemma

71 From the Pumping Lemma Thus: We have:

72 Therefore: BUT: CONTRADICTION!

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

74 Regular languages Non-regular languages

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 Assume to the contrary that is a regular language. Since is infinite we can apply the Pumping Lemma.

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

78 Write From the Pumping Lemma it must be that length

79 From the Pumping Lemma: Thus: We have:

80 Therefore: Since: There is

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

82 Therefore: BUT: CONTRADICTION! and

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

84 Regular languages Non-regular languages

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

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

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

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

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

90 Regular languages Non-regular languages

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

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

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

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

95 From the Pumping Lemma: Thus: We have:

96 Therefore: BUT: CONTRADICTION

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

98 Pumping Lemma, in short

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 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 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 Note: It suffices to show that only one string gives a contradiction You don’t need to obtain contradiction for every

103 Extra Examples on Regular Languages

104 FA  RE

105 FA  RE or

106 NFA  DFA Subset Construction Delmängdkonstruktion

107 Convert an NFA to DFA using the subset construction

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 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 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 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 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 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 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 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 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 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 NFA  DFA RESULT

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*

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

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

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