More Properties of Regular anguages 1
We have proven Regular languages are closed under: Union Concatenation Star operation Reverse 2
Namely, for regular languages 1 and 2 : Union 1 2 Concatenation Star operation Reverse 1 2 1 R 1 Regular anguages 3
We will prove Regular languages are closed under: Complement Intersection 4
Namely, for regular languages 1 and 2 : Complement Intersection 1 1 2 Regular anguages 5
Complement Theorem: For regular language the complement is regular Proof: Take DFA that accepts and make nonfinal states final final states nonfinal Resulting DFA accepts 6
Example: a ( a* b) a,b b a, b q0 q1 q2 ( a * a * b( a b)( a b)*) a a,b b a, b q0 q1 q2 7
Intersection Theorem: For regular languages the intersection 1 1 2 and 2 is regular Proof: Apply DeMorgan s aw: 1 2 1 2 8
1, 2 regular 1, 2 regular 1 2 regular 1 2 regular 1 2 regular 9
Standard Representations of Regular anguages 10
Standard Representations of Regular anguages Regular anguages DFAs Regular Grammars NFAs Regular Expressions 11
When we say: We are given a Regular anguage We mean: anguage representation is in a standard We may assume a regular language can be represented as a DFA, an NFA, a regular expression, or a regular grammar, whatever we find convenient. 12
Elementary Questions about Regular anguages 13
Membership Question Question: Given regular language and string w how can we check if? w Answer: Take the DFA that accepts and check if w is accepted 14
DFA w w DFA w w 15
Question: Given regular language how can we check if is empty:? ( ) Answer: Take the DFA that accepts Check if there is a path from the initial state to a final state 16
DFA DFA 17
Question: Given regular language how can we check if is finite? Answer: Take the DFA that accepts Check if there is a walk with cycle from the initial state to a final state 18
DFA is infinite DFA is finite 19
Question: Given regular languages 1 and 2 how can we check if 1 2? Answer: Find if ( 2 1 2 ) ( 1 ) 20
( 2 1 2 ) ( 1 ) 1 2 and 1 2 1 2 2 2 1 1 1 2 2 1 1 2 21
( 2 1 2 ) ( 1 ) 1 2 or 1 2 1 2 2 1 1 2 2 1 1 2 22
Non-regular languages 23
Non-regular languages { a n b n : n 0} { ww R : w { a, b}*} Regular languages a *b b* c a b c( a b)* etc... 24
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 emma!!! 25
The Pigeonhole Principle 26
4 pigeons 3 pigeonholes 27
A pigeonhole must contain at least two pigeons 28
n pigeons... m pigeonholes n m... 29
The Pigeonhole Principle n m pigeons pigeonholes n m There is a pigeonhole with at least 2 pigeons... 30
The Pigeonhole Principle and DFAs 31
DFA with 4 states b b b a q1 q b 2 q3 a b a q 4 32
In walks of strings: a aa aab no state is repeated b b b a a q1 q2 q3 b q 4 a a 33
In walks of strings: aabb bbaa abbabb a state is repeated abbbabbabb... b b b a a q1 q2 q3 b q 4 a a 34
In walks of strings: aabb bbaa abbabb a state is repeated abbbabbabb... b b b a a q1 q2 q3 b q 4 a a 35
w w 4 If string has length : Then the transitions of string Thus, a state must be repeated w are more than the states of the DFA b b b a a q1 q2 q3 b q 4 a a 36
In general, for any DFA: String has length number of states w A state q must be repeated in the walk of w walk of w... q... Repeated state 37
w In other words for a string : a transitions are pigeons q states are pigeonholes walk of w... q... Repeated state 38
The Pumping emma 39
Take an infinite regular language DFA that accepts m states 40
Take string w with w There is a walk with label w :... walk w 41
If string w has length w m number of states of DFA then, from the pigeonhole principle: a state q is repeated in the walk w... q... walk w 42
et q be the first state repeated... q... walk w 43
Write w x y z y... q... x z 44
Observations: length x y m number of states length y 1 of DFA y... q... x z 45
Observation: The string x z is accepted y... q... x z 46
Observation: The string x y y z is accepted y... q... x z 47
Observation: The string x y y y z is accepted y... q... x z 48
In General: The string x y i z is accepted i 0,1, 2,... y... q... x z 49
In General: x y i z i 0,1, 2,... The original language y... q... x z 50
In other words, we described: The Pumping emma!!! 51
The Pumping emma: Given a infinite regular language there exists an integer m for any string w with length w m we can write w x y z with x y m y 1 and such that: x y i z i 0,1, 2,... 52
Applications of the Pumping emma 53
Theorem: The language { a b : n 0} n n is not regular Proof: Use the Pumping emma 54
n n { a b : n 0} Assume for contradiction that is a regular language Since is infinite we can apply the Pumping emma 55
n n { a b : n 0} et m be the integer in the Pumping emma Pick a string w such that: w length w m We pick m b m w a 56
Write: a m b m x y z From the Pumping emma it must be that length x y m, y 1 m m xyz a m b m a... aa... aa... ab... b x y z Thus: y a k, k 1 57
x y z m b m a y a k, k 1 From the Pumping emma: x y i z i 0,1, 2,... Thus: x y 2 z 58
m m x y z a b y a, k 1 k From the Pumping emma: x y 2 z m k m xy 2 z a... aa... aa... aa... ab... b x y y z Thus: a m k b m 59
a m k b m k 1 BUT: n n { a b : n 0} a m k b m CONTRADICTION!!! 60
Therefore: Our assumption that is a regular language is not true Conclusion: is not a regular language 61
Non-regular language { a b : n 0} n n Regular languages 62