meljun cortes automata theory 5

Upload: meljun-cortes-mbampa

Post on 04-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    1/17

    CSC 3130: Automata theory and formal languages

    Limitations of finite automata

    MELJUN P. CORTES MBA MPA BSCS ACS

    MELJUN CORTES

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    2/17

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    3/17

    Which are regular?

    L1= {0n

    1m

    : n, m 0}L2= {0

    n1n: n 0}S= {0, 1}

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

    L4= {1n: n is prime}

    S= {1}

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

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

    S= {0, 1}

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    4/17

    Which are regular?

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

    How about:

    Lets try to design a DFA for it

    it appears that we need infinitely many states!

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

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    5/17

    A non-regular language

    Theorem

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

    L2

    We show something must be wrong with this DFA

    In particular, Mmust accept some strings not in L2

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

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    6/17

    A non-regular language

    What happens when we run Mon input x=

    0n+11n+1?

    Mbetter accept, because xL2

    M

    imaginary DFA for L2with nstates

    x

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    7/17

    A non-regular language

    What happens when we run Mon input x=

    0n+11n+1?

    Mbetter accept, because xL2 But since Mhas nstates, it must revisit at least one of

    its states while reading 0n+1

    Mx 0 0 0 0

    0

    0r1n+1

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    8/17

    Pigeonhole principle

    Here, balls are 0s, bins are states:

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

    If you have a DFA with nstates and it reads

    n+ 1consecutive 0s, then it must end up inthe same state twice.

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    9/17

    A non-regular language

    What happens when we run Mon input x=

    0n+11n+1?

    Mbetter accept, because xL2 But since Mhas nstates, it must revisitat least one of

    its states while reading 0n+1

    But then the DFA must contain a loopwith 0s

    Mx 0 0 0 0

    0

    0r1n+1

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    10/17

    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 theyare not in L2!

    M0 0 0 0

    0

    0r1n+1

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    11/17

    General method for showing non-

    regularity

    Every regularlanguage Lhas a property:

    For every sufficiently long input zin L, there is a

    middle part in zthat, even if repeated severaltimes, keeps the input inside L

    z a1 ak+1ak an-1

    an

    an+1am

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    12/17

    Pumping lemma for regular languages

    Theorem:For every regular language L

    There exists a number nsuch that for every

    string zin L, we can write z= u v wwhere

    |uv| n|v| 1

    For every i 0, the string u vi wis in L.

    z

    u

    v

    w

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    13/17

    Proving non-regularity

    If Lis regular, then:

    So to prove Lis notregular, it is enough to show:

    There exists nsuch that for every zin L, we

    can write z= u v wwhere |uv| n, |v| 1

    andFor every i 0, the string u vi wis in L.

    For every nthere exists zin L, such that for

    every way of writing z= u v wwhere

    |uv| nand|v| 1,the string u vi wis not

    in Lfor some i 0.

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    14/17

    Proving non regularity

    For every nthere exists zin L, such that forevery way of writing z= u v wwhere

    |uv| nand|v| 1,the string u vi wis not

    in Lfor some i 0.

    This is agame between you and an imagined

    adversary

    adversary

    choose n

    write z= uvw(|uv| n,|v| 1)

    you

    choose zLchoose i

    you winif uviwL

    1

    2

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    15/17

    Proving non-regularity

    You need to give a strategythat, regardless ofwhat the adversary does, always wins you the

    game

    adversary

    choose n

    write z= uvw(|uv| n,|v| 1)

    you

    choose zL

    choose i

    you winif uviwL

    1

    2

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    16/17

    Example

    L2= {0n1n: n 0} S= {0, 1}

    adversary

    choose n

    write z= uvw(|uv| n,|v| 1)

    you

    choose zL

    choose i

    you win if uviwL

    1

    2

    adversary

    choose n

    write z= uvw(|uv| n,|v| 1)

    you

    z= 0n+11n+1i= 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

  • 8/13/2019 MELJUN CORTES Automata Theory 5

    17/17

    More examples

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

    L4= {1n: n is prime}

    S= {1}

    L5= {x: xhas same number of 0s and 1s}L6= {x: xhas same number of patterns 01 and 10}

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

    L8

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

    S= {0, 1}