Title: Formal Methods in Computer Science CS1502 Pumping Lemma
1Formal Methods in Computer ScienceCS1502Pumping
Lemma
- Patchrawat Uthaisombut
- University of Pittsburgh
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?
3- Is language 0n10n n gt 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?
4Using 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.
5Goals
- 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 a language is
not regular.) - (Existence of non-regular languages)
6Pumping Condition
- ?p (pgt0 ??s ((s?L ? s?p)? ?x ?y ?z (
( s xyz ? xy ? p ? y gt
0 ) ? ?i (i ? 0 ? xyiz ?L) )) - )
- A language L satisfies the pumping condition if
- there exists an integerp gt 0 such that
- for all strings s in L of length at least p
- there exist strings x, y, z such that
- s xyz and
- xy ? p and
- y gt 0 and
- for all i ? 0, xyiz is in L.
Focus on the RED part first
7y can be pumped
1) s in L 2) s xyz 3) for all i ? 0, xyiz is
in L
- 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
- xy0z xz abfg is in L
- xy1z xyz abcdefg is in L
- xy2z xyyz abcdecdefg is in L
- xy3z xyyyz abcdecdecdefg is in L
8What the other parts mean
- A language L satisfies the pumping condition if
- there exists an integer p gt 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 gt 0 and
- y is not the empty string.
- for all i ? 0, xyiz is in L.
9Example
- Let L be the set of even length strings over
a,b. - Consider p 2 and 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?
10Example
- Let L be the set of strings over a,b where the
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?
11Pumping Lemma
- A language L satisfies the pumping condition if
- there exists an integer p gt 0 such that
- for all strings s in L of length at least p
- there exist strings x, y, z such that
- s xyz and
- xy lt p and
- y gt 1 and
- for all i gt 0, xyiz is in L
- Pumping Lemma All regular languages satisfy the
pumping condition.
Now we proof the Pumping Lemma
12High 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 pumping condition
- Use M in this part
- Pumping Lemma follows.
13First step n1 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 p1 distinct prefixes of s
- length 0 ?
- length 1 s1
- length 2 s1s2
- ...
- length i s1s2 si
- ...
- length n s1s2 si sn
14Example
- Let p 8
- Let s abcdefgh
- There are 9 distinct prefixes of s.
- length 0 ?
- length 1 a
- length 2 ab
- ...
- length 8 abcdefgh
15Second 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 p1 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.
16Third step Forming x, y, z
- Setting
- Prefix w1 has length i
- Prefix w2 has length j gt i
- prefix w1 of length i s1s2 si
- prefix w2 of length j s1s2 si si1 sj
- Forming x, y, z
- Set x w1 s1s2 si
- Set y si1 sj
- Set z sj1 ss
- xyz s1s2 si si1 sj sj1 ss
- x y
z
17Example
3
1
2
4
0
- 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
18Fourth step Showing x, y, z satisfy all the
conditions
- xy ? p
- xy w2
- w2 is one of the first p1 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
- xw1 and xyw2 end up in the same state q of 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 q to an
accepting state.
19Example
3
1
2
4
0
- 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.
20Pumping Lemma
- A language L satisfies the pumping condition if
- there exists an integer p gt 0 such that
- for all strings s in L of length at least p
- there exist strings x, y, z such that
- s xyz and
- xy lt p and
- y gt 1 and
- for all i gt 0, xyiz is in L
- Pumping Lemma All regular languages satisfy the
pumping condition.
Now we proof the Pumping Lemma
21Rephrasing pumping lemma
- Pumping Lemma All regular languages satisfy the
pumping condition. - ?x ( Reg(L) ? Pump(L) )
- A language is regular if and only if it satisfies
the pumping condition. Equivalent? - ?x ( Reg(L) ? Pump(L) ) Not Equivalent
- All non-regular languages do not satisfy the
pumping condition. Equivalent? - ?x ( Reg(L) ? Pump(L) ) Not Equivalent
- All languages that do not satisfy the pumping
condition are not regular. Equivalent? - ?x ( Pump(L) ? Reg(L) ) Equivalent
22How to use the pumping lemma
- Contrapositive of Pumping LemmaAll languages
that do not satisfy the pumping condition are not
regular. - ?x ( Pump(L) ? Reg(L)
- To prove that a language L is not regular
- Show that L does NOT satisfy the pumping
condition. - Cite pumping lemma and conclude that L is not
regular.
Need to find negation of Pumping Condition
23Pumping Condition
Need to find negation of Pumping Condition
- ?p (pgt0 ??s ((s?L ? s?p)? ?x ?y ?z (
( s xyz ? xy ? p ? y gt
0 ) ? ?i (i ? 0 ? xyiz ?L) )) - )
- A language L satisfies the pumping condition if
- there exists an integerp gt 0 such that
- for all strings s in L of length at least p
- there exist strings x, y, z such that
- s xyz and
- xy ? p and
- y gt 0 and
- for all i ? 0, xyiz is in L.
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
25Negation of Pumping condition
- ??p (pgt0 ??s ((s?L ? s?p)? ?x ?y ?z (
( s xyz ? xy ? p ? y gt
0 ) ? ?i (i ? 0 ? xyiz ?L) )) - )
- ?p ( p gt 0 ? ?s ( (s?L ? s ? p) ?
?x ?y ?z ( ( s xyz ?
xy ? p ? y gt 0 ) ?
?i (i ? 0 ? xyiz ? L) ) ))
26Negation of Pumping condition
- A language L does NOT satisfy the pumping
condition if - for all integers p gt 0
- there exists a string s in L of length at least p
such that - for all strings x, y, z such that
- s xyz,
- xy ? p, and
- y gt 0,
- there exists an i ? 0 such that xyiz is not in L
- ?p ( p gt 0 ? ?s ( (s?L ? s ? p) ? ?x
?y ?z ( ( s xyz ? xy
? p ? y gt 0 ) ?
?i (i ? 0 ? xyiz ? L) ) ))
27Pumping condition and its negation
- A language L satisfies the pumping condition if
- there exists an integer p gt 0 such that
- for all strings s in L of length at least p
- there exist strings x, y, z such that
- s xyz,
- xy ? p, and
- y gt 0,
- for all i ? 0, xyiz is in L
- A language L does not satisfy the pumping
condition if - for all integers p gt 0
- there exists a string s in L of length at least p
such that - for all strings x, y, z such that
- s xyz,
- xy ? p, and
- y gt 0,
- there exists an i ? 0 such that xyiz is not in L