CSci 4011 INHERENT LIMITATIONS OF COMPUTER PROGAMS QUIZ 1 A language is a: set of strings. If M is a DFA, L(M) is the.

Download Report

Transcript CSci 4011 INHERENT LIMITATIONS OF COMPUTER PROGAMS QUIZ 1 A language is a: set of strings. If M is a DFA, L(M) is the.

CSci 4011
INHERENT LIMITATIONS
OF COMPUTER PROGAMS
QUIZ 1
A language is a: set of strings.
If M is a DFA, L(M) is the set { w | M accepts w }.
Let M = (Q,,δ,q0,F). Q is the set of: states
δ is the: Transition function
a
q0
b,a
q1
DFA
NFA
DEF
Regular
Language
Regular
Expression
REGULAR OR NOT?
Design a NFA for the language:
{0n1n | 0 < n ≤ 2}
{0n1n | 0 < n ≤ k}
{0n1n | n > 0}?
n
(For R a regexp, R2 means RR, and Rn means RR…R)
SOME LANGUAGES ARE
NOT REGULAR!
B = {0n1n | n ≥ 0} is NOT regular!
Let M be a k-state DFA that recognizes B
Consider the path M takes on 0k1k:
s0 s1s2…
sisi+1 sj sk
…
s2k ∈ F
0000…00.. 0..011111…11
There must be i < j ≤ k such that si = sj = q′ ∈ Q
M accepts 0k-(j-i)1k  B!
So M does not recognize the language B.
REGULAR OR NOT?
C = { w | w has equal number of 1s and 0s}
NOT REGULAR
D = { w | w has equal number of
occurrences of 01 and 10}
(0Σ*0)  (1Σ*1)  1  0  ε
THE PUMPING LEMMA
Let L be a regular language with |L| = 
Then there exists a length P such that
if w  L and |w| ≥ P
then there exist xyz = w where:
1. |y| > 0
2. |xy| ≤ P
3. xyiz  L for any i ≥ 0
THE PUMPING LEMMA
Example:
Let L = 0*1* ; P = 1
w = 011
x=ε
y=0
if w  L and |w| ≥ P
z = 11
then w = xyz, where:
Let L = (0∪1)2*; P = 2
1. |y| > 0
w = 12
2. |xy| ≤ P
x=1
y =i ≥2 0
3. xyiz  L for any
z=ε
Let M be a DFA that recognizes L
Let P be the number of states in M
Assume w  L is such that |w| ≥ P
We show w = xyz
y
x
1. |y| > 0
2. |xy| ≤ P
3. xyiz  L for any i ≥ 0
z
…
q0
qi
qj
There must be j > i such that qi = qj
q|w|
1
0,1
0
0
a
b
0
c
1
L(M) = *001*
0001
001
00001
→
→
→
abccd
abcd
abcccd
1
d
USING THE PUMPING LEMMA
Use the pumping lemma to prove that
B = {0n1n | n ≥ 0} is not regular
Hint: Assume B is regular, and try pumping s = 0P1P
If B is regular, s can be split into s = xyz,
where for any i ≥ 0, xyiz is also in B
For every choice of xy with |xy| ≤ P and |y|>0,
y must be a string of 0s.
In this case xyyz has more 0s than 1s
GENERAL STRATEGY
Proof by contradiction – assume L is regular
Then there is a pumping length P
Find a string w ∈ L with |w| ≥ P
Show that no matter how you choose
xyz, w cannot be pumped!
Conclude that L is not regular
Let PALINDROMES = { wwR | w ∈ {0,1}* }
Assume … pumping length P
Find a w ∈ PALINDROMES longer than P
0P1P1P0P
Show that … w cannot be pumped:
P
2P
P
w=
If w00…0011…1100…00
= xyz with |xy| ≤ P then
y =y 0J for some J>0.
Then
= 0P+J12P0P  PALINDROMES
xyyzxyyz
= 00…00011…1100…00
>P
2P
P
USING THE PUMPING LEMMA
THE ADVERSARY
WHAT THE PUMPING LEMMA
DOESN’T SAY - I
For every P, w  L with |w| ≥ P
there exist xyz=w, where:
1. |y| > 0
2. |xy| ≤ P
3. xyiz  L for any i ≥ 0
Let L = 1*. L is regular.
The string 10 cannot be pumped with P=1.
You need to show that no matter what P is chosen,
L has a string w, |w| ≥ P, that cannot be pumped.
WHAT THE PUMPING LEMMA
DOESN’T SAY - II
For every xyz=w, where:
1. |y| > 0
2. |xy| ≤ P:
xyiz  L for any i ≥ 0
Example: Let L = 10*1*. Picking
w = 10P1P; x=ε; y=10P; z=1P
Does not contradict pumping lemma!
(you can pick x=1 y=0P z=1P.)
PUMPING DOWN
C = { 0i1j | i > j ≥ 0}
Assume … pumping length P
Find a w ∈ C longer than P
0P+11P
Show that … w cannot be pumped:
P+1
P
w= 00…0011…11
If w = xyz with |xy| ≤ P then
y = 0J for
y some J ≥ 1.
0z = xz = 0P+1-J1P  C
Then
xy
xz = 0…0011…11
xyyz = 00…00011…11
> P+1
P
≤P
P
CHOOSING WISELY
Let BALANCED = { w | w has an equal # of 1s and 0s }
Assume … there is a P
Find a w ∈ BALANCED longer than P
(01)P
0P1P
Show that w cannot be pumped:
If w = xyz with |xy| ≤ P then
y = 0J for some J>0.
Then xyyz = 0P+J1P  BALANCED
REUSING A PROOF
Pumping a language can be lots of work…
Let’s try to reuse that work!
{0n1n : n ≥ 0} = BALANCED ∩ 0*1*
If BALANCED is regular then so is {0n1n: n ≥ 0}
USING CLOSURE
Prove: A is not regular
A
∩
C
=
(regular)
B
(Not regular)
or any of {¬, ∪, ∩, ・, R, *}
If A is regular, then A ∩ C (= B) is regular.
But B is not regular so neither is A.
Prove A = {0i1j : i  j} is not regular
using B = {0n1n : n ≥ 0}
¬A = B ∪{ strings that mix 0s and 1s }
B = ¬A ∩ 0*1*
PUMPING
NON-REGULAR LANGUAGES
Let F = {aibjck | i, j, k ≥ 0 and i=1 ⇒ j=k}
F has pumping length 2!
i=0
i=1
i=2
F ∩ ab*c* = {abncn | n ≥ 0}
A non-regular language may still satisfy the pumping lemma.