automata and formal languages science/4888/crs...solution: use the pumping lemma !!! 9 take an...

30
Automata and Formal Languages Lecture 09 Dr. Ahmed Hassan Computer Science Department 1

Upload: others

Post on 07-Feb-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

  • Automata and Formal Languages

    Lecture 09

    Dr. Ahmed Hassan

    Computer Sc ience Department

    1

  • Books

    2

  • PowerPointhttp://www.bu.edu.eg/staff/ahmedaboalatah14-courses/14767

    3

  • Pumping lemmaPUMPING LEMMA

    4

  • AgendaPumping lemma1

    Example 1

    Pumping lemma2

    Example 2

    Example 3

    5

  • 6

    Non-regular languages

    (PUMPING LEMMA)

  • 7

    Regular languages

    ba*acb *

    ...etc

    *)( bacb

    Non-regular languagesL={π‘Žπ‘›π‘π‘›: n β‰₯ 0}

    L={𝑣𝑣𝑅: vΟ΅{π‘Ž, 𝑏}βˆ—}

  • 8

    How can we prove that a languageis not regular?

    L

    Prove that there is no DFA or NFA or REthat accepts L

    Difficulty: this is not easy to prove(since there is an infinite number of them)

    Solution: use the Pumping Lemma !!!

  • 9

    Take an infinite regular language L

    There exists a DFA that accepts L

    mstates

    (contains an infinite number of strings)

  • 10

    mw ||(number of states of DFA)

    then, at least one state is repeated in the walk of w

    q...... ......1 2 k

    Take string with Lw

    kw 21

    Walk in DFA of

    Repeated state in DFA

  • 11

    Take to be the first state repeatedq

    q....

    w

    There could be many states repeated

    q.... ....

    Second

    occurrence

    First

    occurrence

    Unique states

    One dimensional projection of walk :

    1 2 k

    i j

    1i 1j

  • 12

    q.... q.... ....

    Second

    occurrence

    First

    occurrence

    1 2 kij1i 1j

    wOne dimensional projection of walk :

    ix 1 jiy 1 kjz 1

    xyzw We can write

  • 13

    zyxw

    q... ...

    x

    y

    z

    In DFA:

    ...

    ...

    1 ki1ij

    1j

    contains only first occurrence of q

  • 14

    Observation: myx ||length numberof statesof DFA

    Since, in no state is repeated

    (except q)

    xy

    Unique States

    q...

    x

    y

    ...

    1 i1ij

  • 15

    Observation: 1|| ylength

    Since there is at least one transition in loop

    q

    y

    ...

    1ij

  • 16

    The string is accepted

    zxAdditional string:

    q... ...

    x z

    ...

    Do not follow loopy

    ...

    1 ki1ij

    1j

  • 17

    The string is accepted

    zyyx

    q... ... ...

    x z

    Follow loop2 times

    Additional string:

    y

    ...

    1 ki1ij

    1j

  • 18

    The string is accepted

    zyyyx

    q... ... ...

    x z

    Follow loop3 times

    Additional string:

    y

    ...

    1 ki1ij

    1j

  • 19

    The string is accepted

    zyx iIn General:

    ...,2,1,0i

    q... ... ...

    x z

    Follow looptimesi

    y

    ...

    1 ki1ij

    1j

  • 20

    Lzyx i Therefore: ...,2,1,0i

    Language accepted by the DFA

    q... ... ...

    x z

    y

    ...

    1 ki1ij

    1j

  • Pumping lemma(weak) Let L be an infinite regular language over A. then there exist strings

    x, y, z ∈ A*, where y β‰  Ɛ,

    such that

    x𝑦𝑖z ∈ L for all i β‰₯ 0. such that

    21

  • Example 1L={π‘Žπ‘›π‘π‘›: n β‰₯ 0}

    Let L be is regular and suppose L can be accepted by DFA (M) . Then there exist x , y, z ∈ π΄βˆ— , let i=1

    By pumping lemma 𝑀 = π‘₯𝑦𝑧 = π‘Žπ‘šπ‘π‘š

    1. y consists of a's. |xy|=k, y=π‘Žπ‘Ÿ . xy=π‘Žπ‘˜

    x𝑦2z = π‘Žπ‘šβˆ’π‘Ÿ .π‘Ž2π‘Ÿ . π‘Žπ‘šβˆ’π‘˜π‘π‘š=π‘Žπ‘š+π‘Ÿπ‘π‘š is not in L

    22

  • Example 12. y consists of b's.

    x𝑦2z = π‘Žπ‘š .𝑏2π‘Ÿ . π‘π‘šβˆ’π‘˜π‘π‘š=π‘Žπ‘šπ‘π‘š+π‘Ÿ not in L

    3. y consists of one or more a's followed by one or more b's.

    y=ab, x=π‘Žπ‘šβˆ’1, z= π‘π‘šβˆ’1

    xyz = π‘Žπ‘šβˆ’1 a𝑏 π‘π‘šβˆ’1

    x𝑦2z = π‘Žπ‘šβˆ’1 aπ‘π‘Žπ‘ π‘π‘šβˆ’1= π‘Žπ‘š π‘π‘Ž π‘π‘š not in L

    23

  • Pumping lemma (strong)Let L be an infinite regular language over A. and suppose L can be accepted by DFA (M) with m states. Then for any string w ∈ L such that |w| β‰₯ m there exist x , y, z ∈ π΄βˆ—such that

    1. w = xyz , yβ‰  Ɛ

    2. |xy| ≀ m,

    3. |y| β‰₯ 1,

    4. 𝑀𝑖 = x𝑦𝑖z Ο΅ L for all i β‰₯0

    24

  • Example 1L={π‘Žπ‘›π‘π‘›: n β‰₯ 0}

    Let L be is regular and suppose L can be accepted by DFA (M) with m states. Then for any string w ∈ L such that |w| β‰₯ m there exist x , y, z ∈ π΄βˆ—such that

    w=π‘Žπ‘šπ‘π‘š w = 2m > m

    By pumping lemma 𝑀 = π‘₯𝑦𝑧 = π‘Žπ‘šπ‘π‘š

    25

  • Example 1w=π‘Žπ‘šπ‘π‘š w = 2m > m

    By pumping lemma 𝑀 = π‘₯𝑦𝑧 = π‘Žπ‘šπ‘π‘š

    y=π‘Žπ‘Ÿ , r >0, y >0xy = k ≀ π‘š

    x= π‘Žπ‘˜βˆ’π‘Ÿ , y= π‘Žπ‘Ÿ, z= π‘Žπ‘šβˆ’π‘˜π‘π‘š

    x𝑦2z = π‘Žπ‘˜βˆ’π‘Ÿ .π‘Ž2π‘Ÿ . π‘Žπ‘šβˆ’π‘˜π‘π‘š=π‘Žπ‘š+π‘Ÿπ‘π‘š

    π‘›π‘œπ‘‘ 𝑖𝑛 L, Then L is not regular language

    26

  • Example 2L={π‘Žπ‘›: n is prime} is not regular language

    Let L be is regular and suppose L can be accepted by DFA (M) with m states. Then for any string w ∈ L such that |w| β‰₯ m there exist x , y, z ∈ π΄βˆ—such that

    w=π‘Žπ‘š , w = m β‰₯ m

    By pumping lemma w=π‘₯𝑦𝑧 = π‘Žπ‘š

    27

  • Example 2w=π‘Žπ‘š , w = m=m

    By pumping lemma 𝑀 = π‘₯𝑦𝑧 = π‘Žπ‘š, m is prime

    y=π‘Žπ‘Ÿ , r >0, y >0xy = k ≀ π‘š

    x= π‘Žπ‘˜βˆ’π‘Ÿ , y= π‘Žπ‘Ÿ, z= π‘Žπ‘šβˆ’π‘˜

    𝑀2=x𝑦2z = π‘Žπ‘˜βˆ’π‘Ÿ .π‘Ž2π‘Ÿ . π‘Žπ‘šβˆ’π‘˜=π‘Žπ‘šβˆ’π‘˜

    π‘€π‘š+1=xπ‘¦π‘š+1z = π‘Žπ‘˜βˆ’π‘Ÿπ‘Ž(π‘š+1)π‘Ÿ . π‘Žπ‘šβˆ’π‘˜

    28

  • Example 2π‘€π‘š+1=x𝑦

    π‘š+1z = π‘Žπ‘˜βˆ’π‘Ÿπ‘Ž(π‘š+1)π‘Ÿ . π‘Žπ‘šβˆ’π‘˜

    =π‘Žπ‘šπ‘Ÿ+π‘š=π‘Žπ‘š(π‘Ÿ+1)

    r>0 then (r+1)>1 and m is prime then m>1

    π‘›π‘œπ‘‘ 𝑖𝑛 L, because m(r+1) not prime

    Then L is not regular language

    29

  • 30

    ?