MELJUN CORTES Automata Theory (Automata5)

17
CSC 3130: Automata theory and formal languages Limitations of finite automata MELJUN P. CORTES, MBA,MPA,BSCS,ACS MELJUN P. CORTES, MBA,MPA,BSCS,ACS MELJUN CORTES MELJUN CORTES

description

MELJUN CORTES Automata Theory (Automata5)

Transcript of MELJUN CORTES Automata Theory (Automata5)

Page 1: MELJUN CORTES Automata Theory (Automata5)

CSC 3130: Automata theory and formal languages

Limitations of finite automata

MELJUN P. CORTES, MBA,MPA,BSCS,ACSMELJUN P. CORTES, MBA,MPA,BSCS,ACS

MELJUN CORTESMELJUN CORTES

Page 2: MELJUN CORTES Automata Theory (Automata5)

Many examples of regular languages

q0 q1

0 1

1

0

1 0 1

0, 1

q q q q

((0 + 1)0 + (0 + 1)(0 + 1)(0 + 1))*

all strings not containing pattern 010 followed by 101

Is every language regular?

Page 3: MELJUN CORTES Automata Theory (Automata5)

Which are regular?

L1 = {0n1m: n, m ≥ 0}

L2 = {0n1n: n ≥ 0}

= {0, 1}

L3 = {1n: n is divisible by 3}

L4 = {1n: n is prime}

= {1}

L5 = {x: x has same number of 0s and 1s}

L6 = {x: x has same number of patterns 01 and 10}

= {0, 1}

Page 4: MELJUN CORTES Automata Theory (Automata5)

Which are regular?

L1 = {0n1m: n, m ≥ 0}= 0*1*, so regular

• How about:

• Let’s try to design a DFA for it

… it appears that we need infinitely many states!

L2 = {0n1n: n ≥ 0} = {, 01, 0011, 000111, …}

Page 5: MELJUN CORTES Automata Theory (Automata5)

A non-regular language

• Theorem

• To prove this, we argue by contradiction:– Suppose we have managed to construct a DFA

M for L2

– We show something must be wrong with this DFA

– In particular, M must accept some strings not in L2

The language L2 = {0n1n: n ≥ 0} is not regular.

Page 6: MELJUN CORTES Automata Theory (Automata5)

A non-regular language

• What happens when we run M on input x = 0n+11n+1?– M better accept, because x L2

M

imaginary DFA for L2 with n states

x

Page 7: MELJUN CORTES Automata Theory (Automata5)

A non-regular language

• What happens when we run M on input x = 0n+11n+1?– M better accept, because x L2

– But since M has n states, it must revisit at least one of its states while reading 0n+1

Mx 0 0 0 0

0

0r1n+1

Page 8: MELJUN CORTES Automata Theory (Automata5)

Pigeonhole principle

• Here, balls are 0s, bins are states:

Suppose you are tossing n + 1 balls into n bins. Then two balls end up in the same bin.

If you have a DFA with n states and it reads n + 1 consecutive 0s, then it must end up in the same state twice.

Page 9: MELJUN CORTES Automata Theory (Automata5)

A non-regular language

• What happens when we run M on input x = 0n+11n+1?– M better accept, because x L2

– But since M has n states, it must revisit at least one of its states while reading 0n+1

– But then the DFA must contain a loop with 0s

Mx 0 0 0 0

0

0r1n+1

Page 10: MELJUN CORTES Automata Theory (Automata5)

A non-regular language

• The DFA will then also accept strings that go around the loop multiple times

• But such strings have more 0s than 1s, so they are not in L2!

M0 0 0 0

0

0r1n+1

Page 11: MELJUN CORTES Automata Theory (Automata5)

General method for showing non-regularity• Every regular language L has a property:

• For every sufficiently long input z in L, there is a “middle part” in z that, even if repeated several times, keeps the input inside L

z a1 ak+1ak …… an-1

an

an+1…am

Page 12: MELJUN CORTES Automata Theory (Automata5)

Pumping lemma for regular languages• Theorem: For every regular language L

There exists a number n such that for every string z in L, we can write z = u v w where |uv| ≤ n |v| ≥ 1 For every i ≥ 0, the string u vi w is in L.

z ……

u

v

w

Page 13: MELJUN CORTES Automata Theory (Automata5)

Proving non-regularity

• If L is regular, then:

• So to prove L is not regular, it is enough to show:

There exists n such that for every z in L, we can write z = u v w where |uv| ≤ n, |v| ≥ 1 and For every i ≥ 0, the string u vi w is in L.

For every n there exists z in L, such that for every way of writing z = u v w where|uv| ≤ n and |v| ≥ 1, the string u vi

w is not in L for some i ≥ 0.

Page 14: MELJUN CORTES Automata Theory (Automata5)

Proving non regularity

For every n there exists z in L, such that for every way of writing z = u v w where|uv| ≤ n and |v| ≥ 1, the string u vi

w is not in L for some i ≥ 0.• This is a game between you and an

imagined adversary

adversary

choose nwrite z = uvw (|uv| ≤ n,|v| ≥ 1)

you

choose z Lchoose iyou win if uviw L

1

2

Page 15: MELJUN CORTES Automata Theory (Automata5)

Proving non-regularity

• You need to give a strategy that, regardless of what the adversary does, always wins you the game

adversary

choose nwrite z = uvw (|uv| ≤ n,|v| ≥ 1)

you

choose z Lchoose iyou win if uviw L

1

2

Page 16: MELJUN CORTES Automata Theory (Automata5)

Example

• L2 = {0n1n: n ≥ 0} = {0, 1}

adversary

choose nwrite z = uvw (|uv| ≤ n,|v| ≥ 1)

you

choose z Lchoose iyou win if uviw L

1

2

adversary

choose nwrite z = uvw (|uv| ≤ n,|v| ≥ 1)

you

z = 0n+11n+1

i = 2

uviw = 0j+2k+l1n+1

= 0n+1+k1n+1

L

1

2

u = 0j, v = 0k, w = 0l1n+1

j + k + l = n + 1

Page 17: MELJUN CORTES Automata Theory (Automata5)

More examples

L3 = {1n: n is divisible by 3}

L4 = {1n: n is prime}

= {1}

L5 = {x: x has same number of 0s and 1s}

L6 = {x: x has same number of patterns 01 and 10}

L7 = {x: x has more 0s than 1s}

L8 = {x: x has different number of 0s and 1s}

= {0, 1}