FORMAL LANUGAGE

Embed Size (px)

Citation preview

  • 7/28/2019 FORMAL LANUGAGE

    1/31

    CSCI 3130: Formal languages

    and automata theory

    Tutorial 7

    Chin

  • 7/28/2019 FORMAL LANUGAGE

    2/31

    Reminder

    Homework 4 is due at 23:59, today!

  • 7/28/2019 FORMAL LANUGAGE

    3/31

    Turing Machines

    a b a q1 q2

    a/b L

    Replace a with b, and move head left

    current state

    a b b q1 q2

    a/b L

    new state

  • 7/28/2019 FORMAL LANUGAGE

    4/31

    Turing Machines: Low-level Design

    Useful tools

    1. Move to left/right until pointing to x

    S = {a, b, x} G= {a, b, x, }

    q1

    a/a R

    b/b R

    a b a x b

    a b a x b

  • 7/28/2019 FORMAL LANUGAGE

    5/31

    Turing Machines: Low-level Design

    Useful tools

    2. Go to first symbol of the tape S = {a, b, x}

    G= {a, b, x, a, b, x, }

    At the beginning

    Now, use tool 1.

    q0

    a b a x b

    a b a x b

    q1b/b R

    a/a R

    x/x R

  • 7/28/2019 FORMAL LANUGAGE

    6/31

    Turing Machines: Low-level Design

    Useful tools

    3. Go to last symbol of the tape S = {a, b, x}

    Use component 1, then go 1 step to the left.

    G= {a, b, x, }

    q1

    a/a R

    b/b R

    a b a x b

    a b a x b

    x/x R

    / La b a x b

  • 7/28/2019 FORMAL LANUGAGE

    7/31

    Turing Machines

    Useful tips

    1. Check if the input is in the right form to

    reduce the possible inputs you have to deal with later

  • 7/28/2019 FORMAL LANUGAGE

    8/31

    Turing Machines

    Exercise

    1. L1 = {0n1n: n 0}

  • 7/28/2019 FORMAL LANUGAGE

    9/31

    Turing Machines

    L1 = {0n1n: n 0}

    High-level idea:

    If input is e, accept

    Check if the string is of the form 00*11*

    For each 0

    replace with x

    find the first 1 on the right and cross it

    Check if everything on the tape is x

  • 7/28/2019 FORMAL LANUGAGE

    10/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    If input is e, accept

    q0/ R qacc

  • 7/28/2019 FORMAL LANUGAGE

    11/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    Check if the string is of the form 00*11*

    q0 q10/0 R

    0/0 R

    q21/1 R

    1/1 R

    / L

  • 7/28/2019 FORMAL LANUGAGE

    12/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    Check if the string is of the form 00*11*

    (Go back to the first position)

    For each 0

    replace with x

    find the first 1 on the right and cross it

    Check if everything on the tape is x

  • 7/28/2019 FORMAL LANUGAGE

    13/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    Go back to the first position

    q0 q10/0 R

    q1

    0/0 L

    1/1 L

  • 7/28/2019 FORMAL LANUGAGE

    14/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    For each 0 (resp. 0)

    replace with x (resp. x)

    find the first 1 on the right and cross it

  • 7/28/2019 FORMAL LANUGAGE

    15/31

    Turing Machines

    L1 = {0n1n: n 0}

    Possible situations:

    x 0 0 1 1 1

    x 0 0 x 1 1

    x x 0 x x

    x x x x 1 1

  • 7/28/2019 FORMAL LANUGAGE

    16/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    For each 0 (resp. 0)

    replace with x (resp. x)

    find the first 1 on the right and cross it

    q1 q20/x R

    0/0 Rx/x R

    q31/x L

    x 0 0 x 1 1

    x x 0 x x 1

  • 7/28/2019 FORMAL LANUGAGE

    17/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    For each 0 (resp. 0)

    replace with x (resp. x)find the first 1 on the right and cross it

    How to go back to the left after each iteration?

    q1 q20/x R

    0/0 Rx/x R

    q31/x L

    x/x L

    x x 0 x x 1

    x x 0 x x 1

    0/0 L q4

    0/0 L

    x/x R

    x/x R

  • 7/28/2019 FORMAL LANUGAGE

    18/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    For each 0 (resp. 0)

    replace with x (resp. x)find the first 1 on the right and cross it

    What will happen after the last iteration?

    q1 q20/x R

    0/0 Rx/x R

    q31/x L

    x/x L

    x x x x x x

    x x x x x x

    0/0 L q4

    0/0 L

    x/x R

    x/x R

  • 7/28/2019 FORMAL LANUGAGE

    19/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    Check if everything on the tape is x

    q1 q20/x R

    0/0 Rx/x R

    q31/x L

    x/x L

    0/0 L q4

    0/0 L

    x/x R

    x/x R

    x x x x x x

    x/x R

    q2

    x/x R

    / R qacc

    x x x x x x

  • 7/28/2019 FORMAL LANUGAGE

    20/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    Putting everything together

    q1 q20/x R

    0/0 Rx/x R

    q31/x L

    x/x L

    0/0 L q4

    0/0 L

    x/x R

    x/x R

    x/x R

    q2

    x/x R

    / R qacc

    If input is e, acceptCheck if the string is of the form 00*11*

    (Go back to the first position)

    For each 0

    replace with x

    find the first 1 on the right and cross it

    Check if everything on the tape is x

    q0/ R qacc

    q0 q10/0 R

    0/0 R

    q21/1 R

    1/1 R

    /

    L

    q0 q10/0 R

    q1

    0/0 L

    1/1 L

  • 7/28/2019 FORMAL LANUGAGE

    21/31

    Turing Machines

    L1 = {0n1n: n 0}

    Implementation:

    Putting everything together

    q4 q50/x R

    0/0 Rx/x R

    q61/x L

    x/x L

    0/0 L q7

    0/0 L

    x/x Rx/x R

    x/x R

    q8

    x/x R

    /

    R qacc

    q1

    0/0 R

    q21/1 R

    1/1 R

    / Lq00/0 R

    q3

    0/0 L

    1/1 L

    If input is e, acceptCheck if the string is of the form 00*11*

    (Go back to the first position)

    For each 0

    replace with x

    find the first 1 on the right and cross it

    Check if everything on the tape is x

    0/x R

    / R

  • 7/28/2019 FORMAL LANUGAGE

    22/31

    Variants of Turing Machines

    Turning machine with left reset

    The machines head can move one symbol to the right, or

    jump to the leftest position of the tape

    It cannot move one symbol to the left

    Show that it is equivalent to a Turing Machine.

  • 7/28/2019 FORMAL LANUGAGE

    23/31

    Variants of Turing Machines

    Show that TM with left resetis equivalent to a TM

    Two steps

    1. Show how to simulate a TM with left reseton a TM

    2. Show how to simulate a TM on a TM with left reset

  • 7/28/2019 FORMAL LANUGAGE

    24/31

    Variants of Turing Machines

    1. Show how to simulate a TM with left reseton a TM

    How to go to first symbol of the tape? e.g. a/b reset

    S = {a, b, x} G= {a, b, x, a, b, x,}

    At the beginning

    To reset

    q0 q1b/b R

    a/a R

    x/x R

    q1

    a/a L

    b/b L

    x/x L

    a b a x b

    a b a x b

    a b a x b

    a b a x b

  • 7/28/2019 FORMAL LANUGAGE

    25/31

    Variants of Turing Machines

    1. Show how to simulate a TM with left reseton a TM

    Every time you change the symbol in the first position

    e.g. a / bR

    Add dots to the symbols e.g. a / bR

    a b a x b

    b b a x b

    a b a x b

    b b a x b

  • 7/28/2019 FORMAL LANUGAGE

    26/31

    Variants of Turing Machines

    2. Show how to simulate a TM on a TM with left resetIdea:

    First, mark the current position with a dot

    Then resetand mark the first position with a *

    Reset

    While (the dot is not one symbol to the right of the * position)

    Move the star to one position to the right

    Now the star is at the position you want to reach

    Remove the dot, reset, and go to the star position

    .

    * .

    * .

  • 7/28/2019 FORMAL LANUGAGE

    27/31

    Variants of Turing Machines

    While (the dot is not one symbol to the right of the * position)

    Move the star to one position to the right

    How?

    1. reset

    2. Go to the * position

    3. Move one position to the right

    4. If it is a dot, done

    Else mark it with a *

    5. reset

    6. Find the first * and remove it

    * .

    * .

    * .

    * * .

    * * .

    * * .

    * .

  • 7/28/2019 FORMAL LANUGAGE

    28/31

    Variants of Turing Machines

    2. Show how to simulate a TM on a TM with left reset

    e.g. a/x L

    a b a x b

    a b x b b

  • 7/28/2019 FORMAL LANUGAGE

    29/31

    Variants of Turing Machines

    2. Show how to simulate a TM on a TM with left reset

    e.g. a/x L

    1. a/x reset

    2. a/a reset3. a/a R

    4. b/b reset

    a b a x b

    a b x x b

    *

    a b x x b *

    *

    a b x x b *

    *

    a b x x b * *

  • 7/28/2019 FORMAL LANUGAGE

    30/31

    Variants of Turing Machines

    2. Show how to simulate a TM on a TM with left reset

    e.g. a/x L

    5. a/a R

    6. b/b R7. x/x reset

    8. a/aR

    Done.

    *

    *

    a b x x b *

    *

    a b x x b *

    a b x x b *

  • 7/28/2019 FORMAL LANUGAGE

    31/31

    End

    Questions?