24
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011

INHERENT LIMITATIONS OF COMPUTER PROGAMS

  • Upload
    joshua

  • View
    38

  • Download
    3

Embed Size (px)

DESCRIPTION

CSci 4011. INHERENT LIMITATIONS OF COMPUTER PROGAMS. QUIZ 1. A language is a:. set of strings. { w | M accepts w }. If M is a DFA, L(M) is the set. states. Let M = (Q,  ,δ ,q 0 ,F). Q is the set of:. δ is the:. Transition function. a. b, a. q 0. q 1. NFA. DFA. DEF. - PowerPoint PPT Presentation

Citation preview

Page 1: INHERENT LIMITATIONS OF COMPUTER PROGAMS

INHERENT LIMITATIONS OF COMPUTER PROGAMS

CSci 4011

Page 2: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 3: INHERENT LIMITATIONS OF COMPUTER PROGAMS
Page 4: INHERENT LIMITATIONS OF COMPUTER PROGAMS

DFA NFA

RegularLanguage

RegularExpression

DEF

Page 5: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 6: INHERENT LIMITATIONS OF COMPUTER PROGAMS

SOME LANGUAGES ARE NOT REGULAR!

B = {0n1n | n ≥ 0} is NOT regular!

Page 7: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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..

Page 8: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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 ε

Page 9: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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:

Page 10: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 11: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 12: INHERENT LIMITATIONS OF COMPUTER PROGAMS

1 0

1

0 1

0,1

0a b c d

L(M) = *001*

0001 → 001 → abcd 00001 → abcccd

abccd

Page 13: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 14: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 15: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 16: INHERENT LIMITATIONS OF COMPUTER PROGAMS

USING THE PUMPING LEMMA

THE ADVERSARY

Page 17: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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.

Page 18: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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.)

Page 19: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 20: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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

Page 21: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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}

Page 22: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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.

Page 23: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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 =

Page 24: INHERENT LIMITATIONS OF COMPUTER PROGAMS

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.