Pumping Lemma For Regular Language
Pumping Lemma For Regular Language
Pumping Lemma For Regular Language
Languages
1
Some languages are not regular
When a language is regular?
if we are able to construct one of the following: DFA
or NFA or -NFA or regular expression
When is it not?
If we can show that no FA can be built for a language
2
How to prove languages are not regular?
3
Pigeonhole Principle
• If we put n objects into m boxes(pigeonholes),
and if n>m, then a least one box must having
more than one item in it .
Pumping Lemma
• A pumping lemma is a method which is used
to prove that a language is not regular by
contradiction.
Pumping Lemma for Regular Languages
Let L be an infinite regular language.Then there exists
some positive integer N such that for every string
w L s.t. |w|≥N, there exists and can be
decomposed w=xyz, such that:
1. y≠
2. |xy|≤N
3. For all k≥0, all strings of the form xykz L
6
Pumping Lemma: Proof
• L is regular => it should have a DFA.
– Set N := number of states in the DFA
• Any string wL, s.t. |w|≥N, should have the form:
w=a1a2…am, where m≥N
• Let the states traversed after reading the first N
symbols be: {p0,p1,… pN}
==> There are N+1 p-states, while there are only N DFA states
==> at least one state has to repeat
i.e, pi= pJwhere 0≤i<j≤N
7
Pumping Lemma: Proof…
8
Pumping Lemma: Proof…
• For part (1):
yk (for k loops)
– Since i<j, y ≠
x z
p0 pi pm
=pj
• For part (2):
– By PHP, the repetition of states has to occur
within the first N symbols in w
– ==> |xy|≤N
9
Example of using the Pumping Lemma to prove that
a language is not regular
11
Exercise 2
Prove L = {0n10n | n≥ 1} is not regular
12
Example 3: Pumping Lemma
Claim: L = { 0i | i is a perfect square} is not regular
• Proof:
By contradiction, let L be regular.
P/L should apply
Let N = P/L constant
Choose w=0N2
By pumping lemma, w=xyz satisfying all three rules
By rules (1) & (2), y has between 1 and N 0s
By rule (3), any string of the form xykz is also in L for all k≥0
Case k=0:
#zeros (xy0z) = #zeros (xyz) - #zeros (y)
N2 – N ≤ #zeros (xy0z) ≤ N2 - 1
(N-1)2 < N2 - N ≤ #zeros (xy0z) ≤ N2 - 1 < N2
xy0z L
But the above will complete the proof ONLY IF N>1.
… (proof contd.. Next slide)
13
Example 3: Pumping Lemma
(proof contd…)
If the adversary pick N=1, then (N-1)2 ≤ N2 – N, and therefore the #zeros(xy0z) could end up
being a perfect square!
This means that pumping down (i.e., setting k=0) is not giving us the proof!
So lets try pumping up next…
Case k=2:
#zeros (xy2z) = #zeros (xyz) + #zeros (y)
N2 + 1 ≤ #zeros (xy2z) ≤ N2 + N
N2 < N2 + 1 ≤ #zeros (xy2z) ≤ N2 + N < (N+1)2
xy2z L
(Notice that the above should hold for all possible N values of N>0. Therefore, this completes
the proof.)
14
Decision properties of regular
languages
Any “decision problem” looks like this:
Yes
Decision
Input problem
(generally solver
a question)
No
15
Membership question
• Decision Problem: Given L, is w in L?
• Possible answers: Yes or No
• Approach:
1. Build a DFA for L
2. Input w to the DFA
3. If the DFA ends in an accepting state, then yes;
otherwise no.
16
Emptiness test
• Decision Problem: Is L=Ø ?
• Approach:
On a DFA for L:
1. From the start state, run a reachability test, which
returns:
1. success: if there is at least one final state that is reachable from
the start state
2. failure: otherwise
2. L=Ø if and only if the reachability test fails
X FINITE
0
X q6 1
INFINITE
X
0
to this
due
1
19
Equivalence & Minimization of
DFAs
20
Applications of interest
• Comparing two DFAs:
– L(DFA1) == L(DFA2)?
21
When to call two states in a DFA
“equivalent”?
Two states p and q are said to be equivalent iff:
i) Any string w accepted by starting at p is also accepted by starting at
Past doesn’t matter - only future does!
q;
p
ii) Any string w rejected by starting at p is also
w rejected by starting at
AND q.
q
p
w
q
p≡q
22
Computing equivalent states in a DFA
Table Filling Algorithm
A =
0 1
B = =
0 1 0
A C E G C x x =
1 0 1
0 1 D x x x =
B 1
D 1
F 0
H E x x x x =
1 0 F x x x x x =
0
Pass #0 G x x x = x x =
1. Mark accepting states ≠ non-accepting states
H x x = x x x x =
Pass #1
2. Compare every pair of states A B C D E F G H
3. Distinguish by one symbol transition
4. Mark = or ≠ or blank(tbd)
Pass #2
5. Compare every pair of states
6. Distinguish by up to two symbol transitions (until different or same or tbd)
…. 23
(keep repeating until table complete)
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C =
1 0 1
0 1 D =
B 1
D 1
F 0
H E =
1 0 F =
0
G =
H =
A B C D E F G H
24
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C =
1 0 1
0 1 D =
B 1
D 1
F 0
H E X X X X =
1 0 F X =
0
G X =
1. Mark X between accepting vs. non-accepting state
H X =
A B C D E F G H
25
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C X =
1 0 1
0 1 D X =
B 1
D 1
F 0
H E X X X X =
1 0 F X =
0
G X X =
1. Mark X between accepting vs. non-accepting state
H X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
26
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X =
0
G X X X =
1. Mark X between accepting vs. non-accepting state
H X X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
27
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X =
0
G X X X X =
1. Mark X between accepting vs. non-accepting state
H X X = X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
28
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X =
0
G X X X = X =
1. Mark X between accepting vs. non-accepting state
H X X = X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
29
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X =
0
G X X X = X X =
1. Mark X between accepting vs. non-accepting state
H X X = X X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
30
Table Filling Algorithm - step by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X =
0
G X X X = X X =
1. Mark X between accepting vs. non-accepting state
H X X = X X X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
31
Table Filling Algorithm - step by step
A =
0 1
B = =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X X X =
0
G X X X = X X =
1. Mark X between accepting vs. non-accepting state
H X X = X X X X =
2. Pass 1: A B C D E F G H
Look 1- hop away for distinguishing states or strings
3. Pass 2:
Look 1-hop away again for distinguishing states or strings
continue….
32
Table Filling Algorithm - step by step
A =
0 1
B = =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
B 1
D 1
F 0
H E X X X X =
1 0 F X X X X X =
0
G X X X = X X =
1. Mark X between accepting vs. non-accepting state
H X X = X X X X =
2. Pass 1: A B C D E F G H
Look 1- hop away for distinguishing states or strings
3. Pass 2:
Look 1-hop away again for distinguishing states or strings Equivalences:
continue…. • A=B
• C=H
• D=G 33
Table Filling Algorithm - step by
step
0 1 0 1
0 1 0 0 1
A C E G A C E
1 0 1 1 0
0 1 0
1 1 0 1
B D F H D F
1 0 1 0
0
Equivalences:
• A=B
• C=H
• D=G 34
Table Filling Algorithm – special
case
A =
0 1
B =
0 1 0
A C E G C =
1 0 1
0 1 D =
1 1 0 E ? =
B D F H
1 F =
0
0 G =
H =
A B C D E F G H
Q) What happens if the input DFA
has more than one final state?
Can all final states initially be treated
as equivalent to one another?
35
Putting it all together …
How to minimize a DFA?
• Goal: Minimize the number of states in a DFA
• Algorithm:
1. Eliminate states unreachable fromfrom
Depth-first traversal thethestart state
start state
2. Identify and remove equivalent states
3. Output the resultant DFA
Table filling algorithm
36
Are Two DFAs Equivalent?
q0 …
Is q0 ≡ q0’?
: if yes, then DFA1≡DFA2
DFA2
: else, not equiv.
q0’ …
• Simplification of DFAs
– How to remove unreachable states?
– How to identify and collapse equivalent states?
– How to minimize a DFA?
– How to tell whether two DFAs are equivalent?
38