Post on 11-Jan-2016
description
INHERENT LIMITATIONS OF COMPUTER PROGAMS
CSci 4011
QUIZ 1A language is a:
If M is a DFA, L(M) is the set
Let M = (Q,,δ,q0,F). Q is the set of:
set of strings.
{ w | M accepts w }.
δ is the:
states
Transition function
q0 q1
a
b,a
DFA NFA
RegularLanguage
RegularExpression
DEF
REGULAR OR NOT?
Design a NFA for the language:
{0n1n | 0 < n ≤ k}
{0n1n | n > 0}?
{0n1n | 0 < n ≤ 2}
(For R a regexp, R2 means RR, and Rn means RR…R)
n
SOME LANGUAGES ARE NOT REGULAR!
B = {0n1n | n ≥ 0} is NOT regular!
Consider the path M takes on 0k1k:
There must be i < j ≤ k such that si = sj = q′ Q∈
Let M be a k-state DFA that recognizes B
M accepts 0k-(j-i)1k B!
So M does not recognize the language B.
0000…00..s0 s1s2… sisi+1
011111…11sk … s2k ∈ Fsj
0..
REGULAR OR NOT?
C = { w | w has equal number of 1s and 0s}
D = { w | w has equal number of occurrences of 01 and 10}
NOT REGULAR
(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
1. |y| > 0
2. |xy| ≤ P
3. xyiz L for any i ≥ 0
if w L and |w| ≥ Pthen there exist xyz = w where:
THE PUMPING LEMMA
1. |y| > 0
2. |xy| ≤ P
3. xyiz L for any i ≥ 0
if w L and |w| ≥ Pthen w = xyz, where:
Example:
Let L = 0*1* ; P = 1w = 011x =y =z =
ε011
Let L = (0 1)2*; P =∪w = 1x =y =z =
12ε
22
Let P be the number of states in M
Assume w L is such that |w| ≥ P
q0 qi qj q|w|
…
There must be j > i such that qi = qj
Let M be a DFA that recognizes L
1. |y| > 0
2. |xy| ≤ P
3. xyiz L for any i ≥ 0
We show w = xyz
xy
z
1 0
1
0 1
0,1
0a b c d
L(M) = *001*
0001 → 001 → abcd 00001 → abcccd
abccd
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
Find a string w ∈ L with |w| ≥ P
Show that no matter how you choosexyz, w cannot be pumped!
Conclude that L is not regular
Then there is a pumping length P
Let PALINDROMES = { wwR | w ∈ {0,1}* }
Assume … pumping length PFind a w ∈ PALINDROMES longer than P
0P1P1P0P
Show that … w cannot be pumped:
If w = xyz with |xy| ≤ P theny = 0J for some J>0.
Then xyyz = 0P+J12P0P PALINDROMES
00…0011…1100…00
P P2P
w=
yxyyz = 00…00011…1100…00
> P P2P
USING THE PUMPING LEMMA
THE ADVERSARY
For every P, w L with |w| ≥ P
1. |y| > 0
there exist xyz=w, where:
3. xyiz L for any i ≥ 0
2. |xy| ≤ P
WHAT THE PUMPING LEMMADOESN’T SAY - I
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 LEMMADOESN’T SAY - II
1. |y| > 0
For every xyz=w, where:
xyiz L for any i ≥ 0
2. |xy| ≤ P:
Example: Let L = 10*1*. Pickingw = 10P1P; x=ε; y=10P; z=1P
Does not contradict pumping lemma!
(you can pick x=1 y=0P z=1P.)
PUMPING DOWNC = { 0i1j | i > j ≥ 0}
Assume … pumping length P
Find a w ∈ C longer than P
Show that … w cannot be pumped:
If w = xyz with |xy| ≤ P theny = 0J for some J ≥ 1.
Then xy0z = xz = 0P+1-J1P C
0P+11P
00…0011…11
P+1 P
w=
y
xyyz = 00…00011…11
> P+1 P
xz = 0…0011…11
≤ P P
CHOOSING WISELYLet BALANCED = { w | w has an equal # of 1s and 0s }
Assume … there is a P
Find a w ∈ BALANCED longer than P
(01)P
Show that w cannot be pumped:
If w = xyz with |xy| ≤ P theny = 0J for some J>0.
Then xyyz = 0P+J1P BALANCED
0P1P
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
A C B∩ =
(Not regular)
Prove: A is not regular
or any of {¬, , ∩, ∪ ・ , R, *}
If A is regular, then A ∩ C (= B) is regular.
(regular)
But B is not regular so neither is A.
Prove A = {0i1j : i j} is not regular using B = {0n1n : n ≥ 0}
B { strings that mix 0s and 1s }∪
B = ¬A ∩ 0*1*
¬A =
PUMPINGNON-REGULAR LANGUAGES
Let F = {aibjck | i, j, k ≥ 0 and i=1 ⇒ j=k}
F has pumping length 2!
F ∩ ab*c* = {abncn | n ≥ 0}
i = 0i = 1i = 2
A non-regular language may still satisfy the pumping lemma.