Upload
ama2amal
View
243
Download
0
Embed Size (px)
Citation preview
8/2/2019 s30 Pumping Lemma
1/27
1
Formal Methods in Computer Science
CS1502
Pumping Lemma
Patchrawat Uthaisombut
University of Pittsburgh
8/2/2019 s30 Pumping Lemma
2/27
2
What do we know about NFAs and DFAs?
Describe the concept of closure.
What are closure properties of regular
languages that we know of?
Are all languages regular?
8/2/2019 s30 Pumping Lemma
3/27
3
Is language { 0n10n | n >= 0 } regular?Lets try to find an DFA or NFA
recognizing it.
What do we need to show to proof that
a language is NOT regular?
How?
8/2/2019 s30 Pumping Lemma
4/27
4
Using some other property
All regular languages share some property Q.
x (Reg(x) Q(x)) (All Ps are Qs)
Note, some non-regular languages may also have property Q.
If we can show that a language L doesnt have this property,then L cannot be regular.
~Q(L) ~Reg(L)
What property Q is a good choice to use? All regular languages must have property Q. If a language does not have property Q (and thus not regular), it
should be easy to prove this.
8/2/2019 s30 Pumping Lemma
5/27
5
Goals
Pumping lemma
Understanding the Pumping condition
Shared by all regular languages.
Proof of Pumping lemma
(Negation of Pumping condition)
(Using pumping lemma to show that alanguage is not regular.)
(Existence of non-regular languages)
8/2/2019 s30 Pumping Lemma
6/27
6
Pumping Condition
A language L satisfies thepumping condition if there exists an integer
p > 0 such that for all strings s in L of length atleast p
there exist strings x, y, z suchthat
s = xyzand
|xy| p and |y| > 0 and for all i0, xyiz is in L.
p(p>0 s((sL |s|p)
xyz(( s= xyz|xy| p |y| > 0
) i(i 0 xyizL)
))
)
Focus on the RED part first
8/2/2019 s30 Pumping Lemma
7/27
7
Let x = abcdefg be in L. Then there exists a substring y in s such that y
can be repeated (pumped) in place any number
of times and the resulting string is still in L. xyiz is in L for all i 0.
Example y = cde
xy0
z = xz =abfg is in L xy1z = xyz = abcdefgis in L xy2z = xyyz = abcdecdefgis in L xy3z = xyyyz = abcdecdecdefg is in L
1) s in L
2) s = xyz
3)for all i0, xyiz is in Ly can be pumped
8/2/2019 s30 Pumping Lemma
8/27
8
What the other parts mean
A language L satisfies the pumping condition if there exists an integer p > 0 such that
will discuss later
for all strings s in L of length at least p s must be in L and have sufficient length
there exist strings x, y, z such that s = xyz and |xy| n and
y occurs in the first p characters of s.
|y| > 0 and y is not the empty string.
for all i 0, xyiz is in L.
8/2/2019 s30 Pumping Lemma
9/27
9
Example
Let L be the set of even length strings over{a,b}.
Consider p = 2and s = abaa. What are the possibilities for y? abaa, abaa
abaa
Which one satisfies the pumping condition? abaa
Do all strings of L satisfy this?
8/2/2019 s30 Pumping Lemma
10/27
10
Example
Let L be the set of strings over {a,b} wherethe number of as mod 3 is 1.
Consider p = 3 and s = abbaaa. What are the possibilities for y?
abbaaa, abbaaa, abbaaa abbaaa, abbaaa abbaaa
Which ones satisfy the pumping condition? abbaaa, abbaaa, abbaaa
Do all strings of L satisfy this?
8/2/2019 s30 Pumping Lemma
11/27
11
Pumping Lemma
A language L satisfies the pumping condition if: there exists an integer p > 0 such that
for all strings s in L of length at least p
there exist strings x, y, z such that
s = xyzand
|xy| = 1 and
for all i >= 0, xyiz is in L
Pumping Lemma: All regular languages satisfy thepumping condition.
Now we proof the Pumping Lemma
8/2/2019 s30 Pumping Lemma
12/27
12
High Level Outline
Let L be an arbitrary regular language.
Let M be a DSA such that L(M) = L.
M exists by definition of L being regular.
Show that L satisfies the pumpingcondition
Use M in this part
Pumping Lemma follows.
8/2/2019 s30 Pumping Lemma
13/27
13
First step: n+1 prefixes of x
Let p be the number of states in M.
Let s be any string in L of length at least p.
Let si
denote the ith character of string s.
There are at least p+1 distinct prefixes of s
length 0:
length 1: s1
length 2: s1s2 ...
length i: s1s2 si ...
length n: s1s2 si sn
8/2/2019 s30 Pumping Lemma
14/27
14
Example
Let p = 8
Let s = abcdefgh
There are 9 distinct prefixes of s. length 0:
length 1: a
length 2: ab ...
length 8: abcdefgh
8/2/2019 s30 Pumping Lemma
15/27
15
Second step: Pigeon-hole Principle
As M processes string s, it processes each prefix of s
In particular, each prefix of s must end up in some state of M
Situation
There are p+1 distinct prefixes of s.
There are only p states in M.
Conclusion
At least two prefixes of s must end up in the same state of M
Pigeon-hole principle
If there are more birds than holes, then some hole has two or more birds.
Name these two prefixes w1 and w2.
8/2/2019 s30 Pumping Lemma
16/27
16
Third step: Forming x, y, z
Setting:
Prefix w1 has length i
Prefix w2 has lengthj > i
prefix w1
of length i: s1
s2
si
prefix w2 of length j: s1s2 si si+1 sj
Forming x, y, z
Set x = w1 = s1s2 si
Set y = si+1 sj Set z = sj+1 s|s|
xyz = s1s2 sisi+1 sjsj+1 s|s|x y z
8/2/2019 s30 Pumping Lemma
17/27
17
Example
Let M be a 5-state FSA that accepts all strings over{a,b,c,,z} whose length mod 5 = 3.
Consider x = abcdefghijklmnopqr, a string in L.
What are the two prefixes w1 and w2? w1 =
w2 = abcde
What are x, y, z?
x = y = abcde
z = fghijklmnopqr
xyz =abcdefghijklmnopqr
1 2 3 40
8/2/2019 s30 Pumping Lemma
18/27
18
Fourth step: Showing x, y, z
satisfy all the conditions |xy| p
xy = w2
w2 is one of the first p+1 prefixes of string s
|y| 1 y consists of the characters in w2 after w1 Since w2 and w1 are distinct prefixes of s, y is not
For all i 0, xyiz in L x=w1 and xy=w2 end up in the same state qof M
This is how we defined w1 and w2 Thus for all i 0, xyi ends up in state q
The string z causes M to go from state qto an acceptingstate.
8/2/2019 s30 Pumping Lemma
19/27
19
Example
Let M be a 5-state FSA that accepts all strings over{a,b,c,,z} whose length mod 5 = 3.
Consider x = abcdefghijklmnopqr, a string in L.
What are x, y, z? x =
y = abcde
z = fghijklmnopqr
|xy| = 5 p |y| = 5 1
For all i 0, xyiz = (abcde)ifghijklmnopqr is in L.
1 2 3 40
8/2/2019 s30 Pumping Lemma
20/27
20
Pumping Lemma
A language L satisfies the pumping condition if: there exists an integer p > 0 such that
for all strings s in L of length at least p
there exist strings x, y, z such that
s = xyzand
|xy| = 1 and
for all i >= 0, xyiz is in L
Pumping Lemma: All regular languages satisfy thepumping condition.
Now we proof the Pumping Lemma
8/2/2019 s30 Pumping Lemma
21/27
21
Rephrasing pumping lemma
Pumping Lemma: All regular languages satisfy thepumping condition. x ( Reg(L) Pump(L) )
A language is regular if and only if it satisfies thepumping condition. Equivalent? x ( ~Reg(L) ~Pump(L) ) Not Equivalent
All non-regular languages do not satisfy the pumpingcondition. Equivalent? x ( ~Reg(L) ~Pump(L) ) Not Equivalent
All languages that do not satisfy the pumpingcondition are not regular. Equivalent? x ( ~Pump(L) ~Reg(L) ) Equivalent
8/2/2019 s30 Pumping Lemma
22/27
22
How to use the pumping lemma
Contrapositive of Pumping Lemma:All languages that do not satisfy thepumping condition are not regular.
x ( ~Pump(L) ~Reg(L)
To prove that a language L is not regular1. Show that L does NOT satisfy the pumping
condition.2. Cite pumping lemma and conclude that L is not
regular.
Need to find negation of Pumping Condition
8/2/2019 s30 Pumping Lemma
23/27
23
Pumping Condition
A language L satisfies thepumping condition if there exists an integer
p > 0 such that for all strings s in L of length at
least p there exist strings x, y, z such
that s = xyzand
|xy|
p and |y| > 0 and for all i0, xyiz is in L.
p(p>0 s((sL |s|p)xyz(( s= xyz
|xy| p |y| > 0
) i(i 0 xyizL)
))
)
Need to find negation of Pumping Condition
8/2/2019 s30 Pumping Lemma
24/27
24
x ( P(x) Q(x) ) Not all Ps are Qs x ( P(x) Q(x) ) x (P(x) Q(x) )
x ( P(x) Q(x) ) Some Ps are not Qs
x ( P(x) Q(x) ) No Ps are Qs. x ( P(x) Q(x) )
x (
P(x)
Q(x) ) x ( P(x) Q(x) )All Ps are not Qs
8/2/2019 s30 Pumping Lemma
25/27
25
Negation of Pumping condition
p(p>0 s((sL |s|p)xyz(
( s= xyz
|xy| p |y| > 0
) i(i 0 xyizL)
))
)
p( p> 0 s( (sL |s| p) xyz(
( s= xyz
|xy| p|y| > 0
) i(i 0 xyizL)
))
)
8/2/2019 s30 Pumping Lemma
26/27
26
Negation of Pumping condition A language L does NOT
satisfy the pumping condition
if: for all integers p > 0
there exists a string s in L oflength at least p such that
for all strings x, y, z such that s = xyz,
|xy| p, and
|y| > 0, there exists an i 0 suchthat xyiz is not in L
p( p> 0 s( (sL |s| p) xyz(
( s= xyz
|xy|p
|y| > 0) i(i 0 xyizL)
)
))
8/2/2019 s30 Pumping Lemma
27/27
27
Pumping condition and its negation A language L satisfiesthe
pumping condition if:
there existsan integer p > 0such that
for allstrings s in L of length at
least p
there existstrings x, y, z suchthat
s = xyz,
|xy| p, and
|y| > 0, for alli 0, xyiz is inL
A language L does not satisfythe
pumping condition if: for allintegers p > 0
there existsa string s in L oflength at least p such that
for allstrings x, y, z such that
s = xyz,
|xy| p, and
|y| > 0,
there existsan i 0 such
that xyiz is not inL