fall 2004comp 3351 standard representations of regular languages regular languages dfas nfas regular...
Post on 21-Dec-2015
247 views
TRANSCRIPT
Fall 2004 COMP 335 1
Standard Representations of Regular Languages
Regular Languages
DFAs
NFAsRegularExpressions
RegularGrammars
Fall 2004 COMP 335 2
When we say: We are given a Regular Language
We mean:
L
Language is in a standard representation
L
Fall 2004 COMP 335 3
Elementary Questions
about
Regular Languages
Fall 2004 COMP 335 4
Membership Question
Question: Given regular languageand string how can we check if ?
L
Lw w
Answer: Take the DFA that acceptsand check if is accepted
Lw
Fall 2004 COMP 335 5
DFA
Lw
DFA
Lw
w
w
Fall 2004 COMP 335 6
Given regular languagehow can we checkif is empty: ?
L
L
Take the DFA that accepts
Check if there is any path from the initial state to a final state
L
)( L
Question:
Answer:
Fall 2004 COMP 335 7
DFA
L
DFA
L
Fall 2004 COMP 335 8
Given regular languagehow can we checkif is finite?
L
L
Take the DFA that accepts
Check if there is a walk with cyclefrom the initial state to a final state
L
Question:
Answer:
Fall 2004 COMP 335 9
DFA
L is infinite
DFA
L is finite
Fall 2004 COMP 335 10
Given regular languages and how can we check if ?
1L 2L
21 LL Question:
)()( 2121 LLLLFind ifAnswer:
Fall 2004 COMP 335 11
)()( 2121 LLLL
21 LL 21 LLand
21 LL
1L 2L 1L2L
21 LL 12 LL 2L 1L
Fall 2004 COMP 335 12
)()( 2121 LLLL
21 LL 21 LLor
1L 2L 1L2L
21 LL 12 LL
21 LL
Fall 2004 COMP 335 13
Non-regular languages
Fall 2004 COMP 335 14
Regular languages
ba* acb *
...etc
*)( bacb
Non-regular languages}0:{ nba nn
}*},{:{ bavvvR
Fall 2004 COMP 335 15
How can we prove that a languageis not regular?
L
Prove that there is no DFA that accepts L
Problem: this is not easy to prove
Solution: the Pumping Lemma !!!
Fall 2004 COMP 335 16
The Pigeonhole Principle
Fall 2004 COMP 335 17
pigeons
pigeonholes
4
3
Fall 2004 COMP 335 18
A pigeonhole mustcontain at least two pigeons
Fall 2004 COMP 335 19
...........
...........
pigeons
pigeonholes
n
m mn
Fall 2004 COMP 335 20
The Pigeonhole Principle
...........
pigeons
pigeonholes
n
m
mn There is a pigeonhole with at least 2 pigeons
Fall 2004 COMP 335 21
The Pigeonhole Principle
and
DFAs
Fall 2004 COMP 335 22
DFA with states 4
1q 2q 3qa
b
4q
b
a b
b
a a
Fall 2004 COMP 335 23
1q 2q 3qa
b
4q
b
b
b
a a
a
In walks of strings:
aab
aa
a no stateis repeated
Fall 2004 COMP 335 24
In walks of strings:
1q 2q 3qa
b
4q
b
b
b
a a
a
...abbbabbabb
abbabb
bbaa
aabb a stateis repeated
Fall 2004 COMP 335 25
If string has length :
1q 2q 3qa
b
4q
b
b
b
a a
a
w 4|| w
Thus, a state must be repeated
Then the transitions of string are more than the states of the DFA
w
Fall 2004 COMP 335 26
In general, for any DFA:
String has length number of states w
A state must be repeated in the walk of wq
q...... ......
walk of w
Repeated state
Fall 2004 COMP 335 27
In other words for a string : transitions are pigeons
states are pigeonholesq
a
w
q...... ......
walk of w
Repeated state
Fall 2004 COMP 335 28
The Pumping Lemma
Fall 2004 COMP 335 29
Take an infinite regular languageL
There exists a DFA that accepts L
mstates
Fall 2004 COMP 335 30
Take string with w Lw
There is a walk with label :w
.........
walk w
Fall 2004 COMP 335 31
If string has length w mw || (number of statesof DFA)
then, from the pigeonhole principle: a state is repeated in the walkw
q...... ......
walk w
Fall 2004 COMP 335 32
q
q...... ......
walk w
Let be the first state repeated in thewalk of w
Fall 2004 COMP 335 33
Write zyxw
q...... ......
x
y
z
Fall 2004 COMP 335 34
q...... ......
x
y
z
Observations: myx ||length numberof statesof DFA1|| ylength
Fall 2004 COMP 335 35
The string is accepted
zxObservation:
q...... ......
x
y
z
Fall 2004 COMP 335 36
The string is accepted
zyyxObservation:
q...... ......
x
y
z
Fall 2004 COMP 335 37
The string is accepted
zyyyxObservation:
q...... ......
x
y
z
Fall 2004 COMP 335 38
The string is accepted
zyx iIn General:
...,2,1,0i
q...... ......
x
y
z
Fall 2004 COMP 335 39
Lzyxw ii ∈In General: ...,2,1,0i
q...... ......
x
y
z
Language accepted by the DFA
Fall 2004 COMP 335 40
In other words, we described:
The Pumping Lemma !!!
Fall 2004 COMP 335 41
The Pumping Lemma:
• Given a infinite regular language L
• there exists an integer m
• for any string with length Lw mw ||
• we can write zyxw
• with andmyx || 1|| y
• such that: ,Lzyxw ii ...,2,1,0i
Fall 2004 COMP 335 42
Applications
of
the Pumping Lemma
Fall 2004 COMP 335 43
Theorem: The language }0:{ nbaL nn
is not regular.
Proof: Use the Pumping Lemma
Fall 2004 COMP 335 44
Assume that is a regular languageL
Since is an infinite language,we can apply the Pumping Lemma
L
}0:{ nbaL nn
Fall 2004 COMP 335 45
Let be the integer in the Pumping Lemma
Pick a string such that: (1) w Lw
mw ||
and
mmbawWe pick:
m
}0:{ nbaL nn
(2) length
Fall 2004 COMP 335 46
it must be that length
From the Pumping Lemma 1||,|| ymyx
babaaaaabaxyzw mm ............
1, kay k
x y z
m m
Write: zyxba mm
Thus:
Fall 2004 COMP 335 47
From the Pumping Lemma: Lzyxw ii
...,2,1,0i
Thus:
mmbazyx
Lzyxw 22
1, kay k
Fall 2004 COMP 335 48
From the Pumping Lemma:
Lbabaaaaaaazxy ...............2
x y z
km m
Thus:
Lzyx 2
mmbazyx 1, kay k
y
Lba mkm
Fall 2004 COMP 335 49
Lba mkm
}0:{ nbaL nnBut:
Lba mkm
CONTRADICTION!!!
1≥k
Fall 2004 COMP 335 50
Our assumption thatis a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
Fall 2004 COMP 335 51
Regular languages
Non-regular languages }0:{ nba nn
Fall 2004 COMP 335 52
More Applications
of
the Pumping Lemma
Fall 2004 COMP 335 53
The Pumping Lemma:
• Given a infinite regular language L
• there exists an integer m
• for any string with length Lw mw ||
• we can write zyxw
• with andmyx || 1|| y
• such that: Lzyx i ...,2,1,0i
Fall 2004 COMP 335 54
Regular languages
Non-regular languages *}:{ vvvL R
Fall 2004 COMP 335 55
Theorem:The language
is not regular
Proof: Use the Pumping Lemma
*}:{ vvvL R },{ ba
Fall 2004 COMP 335 56
Assume for contradictionthat is a regular languageL
Since is infinitewe can apply the Pumping Lemma
L
*}:{ vvvL R
Fall 2004 COMP 335 57
mmmm abbaw We pick
Let be the integer in the Pumping Lemma
Pick a string such that: w Lw
mw ||length
m
and
*}:{ vvvL R
Fall 2004 COMP 335 58
Write zyxabba mmmm
it must be that length
From the Pumping Lemma
ababbabaaaaxyz ..................
x y z
m m m m
1||,|| ymyx
1, kay kThus:
Fall 2004 COMP 335 59
From the Pumping Lemma: Lzyx i
...,2,1,0i
Thus: Lzyx 2
1, kay kmmmm abbazyx
Fall 2004 COMP 335 60
From the Pumping Lemma:
Lababbabaaaaaazxy ∈.....................=2
x y z
km + m m m
1, kay k
y
Lzyx 2
Thus:
mmmm abbazyx
Labba mmmkm
Fall 2004 COMP 335 61
Labba mmmkm
Labba mmmkm
BUT:
CONTRADICTION!!!
1k
*}:{ vvvL R
Fall 2004 COMP 335 62
Our assumption thatis a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
Fall 2004 COMP 335 63
Regular languages
Non-regular languages
}0,:{ lncbaL lnln
Fall 2004 COMP 335 64
Theorem:The language
is not regular
Proof: Use the Pumping Lemma
}0,:{ lncbaL lnln
Fall 2004 COMP 335 65
Assume for contradictionthat is a regular languageL
Since is infinitewe can apply the Pumping Lemma
L
}0,:{ lncbaL lnln
Fall 2004 COMP 335 66
mmm cbaw 2We pick
Let be the integer in the Pumping Lemma
Pick a string such that: w Lw
mw ||length
m
}0,:{ lncbaL lnln
and
Fall 2004 COMP 335 67
Write zyxcba mmm 2
it must be that length
From the Pumping Lemma
cccbcabaaaaaxyz ..................
x y z
m m m2
1||,|| ymyx
1, kay kThus:
Fall 2004 COMP 335 68
From the Pumping Lemma: Lzyx i
...,2,1,0i
Thus:
mmm cbazyx 2
Lxzzyx ∈=0
1, kay k
Fall 2004 COMP 335 69
From the Pumping Lemma:
Lcccbcabaaaxz ...............
x z
km m m2
mmm cbazyx 2 1, kay k
Lxz
Thus: Lcba mmkm 2
Fall 2004 COMP 335 70
Lcba mmkm 2
Lcba mmkm 2
BUT:
CONTRADICTION!!!
}0,:{ lncbaL lnln
1k
Fall 2004 COMP 335 71
Our assumption thatis a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
Fall 2004 COMP 335 72
Regular languages
Non-regular languages }0:{ ! naL n
Fall 2004 COMP 335 73
Theorem:The language
is not regular
Proof: Use the Pumping Lemma
}0:{ ! naL n
nnn )1(21!
Fall 2004 COMP 335 74
Assume for contradictionthat is a regular languageL
Since is infinitewe can apply the Pumping Lemma
L
}0:{ ! naL n
Fall 2004 COMP 335 75
!mawWe pick
Let be the integer in the Pumping Lemma
Pick a string such that: w Lw
mw ||length
m
}0:{ ! naL n
Fall 2004 COMP 335 76
Write zyxam !
it must be that length
From the Pumping Lemma
aaaaaaaaaaaxyz m ...............!
x y z
m mm !
1||,|| ymyx
mkay k 1,Thus:
Fall 2004 COMP 335 77
From the Pumping Lemma: Lzyx i
...,2,1,0i
Thus:
!mazyx
Lzyx 2
mkay k 1,
Fall 2004 COMP 335 78
From the Pumping Lemma:
Laaaaaaaaaaaazxy ..................2
x y z
km mm !
Thus:
!mazyx mkay k 1,
Lzyx 2
y
La km !
Fall 2004 COMP 335 79
La km !
!! pkm
}0:{ ! naL nSince:
mk 1
There must exist such that: p
Fall 2004 COMP 335 80
However:
)!1(
)1(!
!!
!!
!
m
mm
mmm
mm
mmkm ! for 1m
)!1(! mkm
!! pkm for any p
Fall 2004 COMP 335 81
La km !
La km !
BUT:
CONTRADICTION!!!
}0:{ ! naL n
mk 1
Fall 2004 COMP 335 82
Our assumption thatis a regular language is not true
L
Conclusion: L is not a regular language
Therefore: