meljun cortes automata lecture turing machines 1

Upload: meljun-cortes-mbampa

Post on 07-Aug-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    1/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 1 of 26

    Turing Machines

    TURING MACHINES

    Turing Machines

      Introduction

    •   A finite automaton is a

    machine with a finite number 

    of states.

    It is used to model computers

    with a limited amount of 

    memory or programs that

    process only a small amountof data.

    The disadvantage of a DFA

    and an NFA is its limited

    number of states.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    2/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 2 of 26

    Turing Machines

    •   A pushdown automaton is

    similar to a finite automaton

    except that it has access to a

    stack.

    It is used to model machineswith unlimited memory.

    The problem with PDAs is that

    access to the data in the stack

    is limited on a last-in, first-outbasis.

    •   In general, finite automata and

    pushdown automata are

    limited to performing onlysimple tasks.

    •   Is there a model that can truly

    represent a general-purpose

    computer?

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    3/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 3 of 26

    Turing Machines

     Turing Machines

    •   A Turing m ach ine    (TM) is

    similar to a finite automaton

    and a pushdown automatonexcept that it has unlimited

    and unrestricted memory.

    •   It is similar to a PDA except

    that its storage device is called

    a tape .

    •   A tape can be viewed as an

    infinite, one-dimensional array

    of cells. Each cell can store

    one symbol.

    •   The Turing machine has a

    read/write head that can

    access any cell on the tape.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    4/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 4 of 26

    Turing Machines

    •   Representation of a TM:

    •   The read/write head can move

    left or right on the tape.

    •   It can read or write one symbol

    on each move.

    TM

    1 0

    Read/Write

    Head

    . . .0   o

    Tape

    o

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    5/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 5 of 26

    Turing Machines

    •   Initially, the first few cells

    contain the symbols of the

    input string while the rest are

    blank.

    •   During the computation

    process, the TM considers the

    current state it is in and the

    symbol on the tape beingpointed to by the read/write

    head.

    The TM can then replace the

    symbol on the tape, move to

    another state, and move the

    read/write head to the left or to

    the right.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    6/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 6 of 26

    Turing Machines

    • Case Study

    Consider the language

    L1 = {w #w w    {0, 1}*}.

    TM Operation:

    1. Read the first symbol of 

    the input string.Remember the symbol

    read and replace it with an

     x .

    2. Move the head to the firstsymbol to the right of #. If 

    no # is found, reject the

    string.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    7/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 7 of 26

    Turing Machines

    3. If the first symbol to the

    right of the # matches the

    symbol read earlier,

    replace this symbol with an x . If not, reject the string.

    4. Repeat the actions of steps

    1 to 3 for each symbol on

    the left side of #.

    5. When all symbols on the

    left side of # have been

    replaced with   x ’s,   check if 

    there are remaining

    symbols to the right of #. If there are, reject the string.

    Otherwise, accept the

    string.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    8/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 8 of 26

    Turing Machines

     Formal Definition of TuringMachines

    •   A Turing machine is a 7-tuple

    (Q, , , ,   q0,   qaccept,   qreject),

    where  Q, , and   are all finite

    sets, and

    1. Q is the set of states,

    2.   is the input alphabet,

    3.   is the tape alphabet,

    4.   is the transition function,

    5. q0   Q and is the start

    state,

    6. qaccept   Q and is the acceptstate, and

    7. qreject   Q and is the reject

    state, where qaccept   qreject.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    9/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 9 of 26

    Turing Machines

    •   Some points:

    1. The input alphabet does

    not include the blank

    symbol .

    2. The tape alphabet is

    composed of the input

    alphabet , the blank

    symbol  , and some other 

    symbols that may be

    stored on the tape.

    3. The read/write head starts

    at the leftmost cell. The

    head cannot go to the left

    of the leftmost cell.

    4. The first blank symbol

    encountered by the

    read/write indicates the

    end of the input string.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    10/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 10 of 26

    Turing Machines

    5. A TM has one accept stateand one reject state.

    If the TM goes in the

    accept state, it accepts the

    string being processed,and stops or halts the

    computation immediately.

    If the TM goes in the reject

    state, it rejects the stringbeing processed, and

    stops or halts the

    computation immediately.

    If the TM ends up in any

    other state, the TM is said

    to be in a loop. A loop

    simply states that the TM

    will go on forever, never 

    halting.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    11/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 11 of 26

    Turing Machines

    •   In a TM, transitions are

    represented by

    (qi , a) = (q j , b, R)

    This equation indicates that if 

    the current state is state  qi  and

    the symbol below the

    read/write head is   a, the TM

    goes to state   q j , writes thesymbol   b   on the tape, and

    moves the head to the right.

    Transitions can also be

    (qi , a) = (q j , b, L)

    where the head moves to the

    left instead of right.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    12/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 12 of 26

    Turing Machines

    • Configuration of a Turing

    Machine

    The conf igurat ion  of a TM is

    defined by the current state itis in, the contents of the tape,

    and the position of its

    read/write head.

    It is written as

     xqy 

    where   q is the current state of 

    the TM,   x   is the string on the

    left side of the current head

    position, and   y   is the string

    position on the right side of the

    head.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    13/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 13 of 26

    Turing Machines

    Example:

    Configuration = 101q30011

    q 3

    TM

    . . .

    Tape

    o1 0 1 0 0 1 1   o

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    14/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 14 of 26

    Turing Machines

    Configuration   C 1   is said to

    yield configuration  C 2 if the TM

    can reach   C 2   from   C 1   in one

    step. This is represented as

    C 1 C 2

    If the current configuration is

     x 0qi1y    and the transition

    function is (qi 

    , 1) = (q j 

    , 0, L),

    then

     x 0qi1y   xq j00y 

    If the current configuration is

     x 0qi1y    and the transitionfunction is (qi , 1) = (q j , 0, R),

    then:

     x 0qi1y   x 00q jy 

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    15/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 15 of 26

    Turing Machines

    •   Sample Transitions in TM

    State Diagrams

    The label 0 → x ,  R  means thatif the symbol under the

    read/write head is a 0, then the

    TM moves from state   qi    to

    state  q j , writes the symbol  x  on

    the tape, and moves the headto the right.

    q  j 

    0 → x, R

    q  i 

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    16/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 16 of 26

    Turing Machines

    The label 0  →  L means that if the symbol under the

    read/write head is a 0, then the

    TM moves from state   qi    tostate   q j , and moves the head

    to the left.

    The label 0   →   0,   L   willaccomplish the same thing.

    q  j 

    0 → L

    q  i 

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    17/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 17 of 26

    Turing Machines

    The label →  L means that if 

    the symbol under theread/write head is  , then the

    TM moves from state   qi    to

    state   q j , and moves the head

    to the left.

    The label 0, 1  →   x ,   L means

    that if the symbol under theread/write head is a 0 or 1,

    then the TM moves from state

    qi  to state  q j , writes the symbol

     x  on the tape, and moves the

    head to the left.

    q  j 

     

    → L

    q  i 

    q  j 

    0, 1 → x, L

    q  i 

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    18/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 18 of 26

    Turing Machines

    •   Language of a Turing Machine

    If a language is recognized by

    a Turing machine, then it is

    said to be Tur ing- recognizable .

     A TM recognizes a language if 

    it accepts all the strings of the

    language.

    If a TM accepts all the strings

    of a language and rejects all

    strings not in the language,

    then the language is said to be

    decided  by the TM.

    If a language is decided by a

    Turing machine, then it is said

    to be Turing-decidable .

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    19/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 19 of 26

    Turing Machines

    •   Continuation of the Case Study

    The TM   T 1   that can decide

    language   L1   = {w #w w    {0,

    1}*}:

    q 0

     #  → R

    q accept

    q 7

     

    → R

    x → R   q 2q 1

    q 3   q 4

    q 5

    q 6

    1   →  x   ,  R  

      0  →

       x ,   R

    0    → 

     x    ,  L      1 

      →    x ,     L

    0,1 → R

    x → R

    0,1 → R

    x → R

    # → R# → R

    0, 1, x → L

    # → L

    0, 1 → Lx → R

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    20/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 20 of 26

    Turing Machines

    Simulating how  M 1 accepts thestring 110#110, the following

    are the series of configurations

    M 1 enters:

    q0110#110 xxq60#xx0xq210#110 xq6x0#xx0

    x1q20#110 xxq00#xx0

    x10q2#110 xxxq1#xx0

    x10#q4110 xxx#q3xx0

    x10q5#x10 xxx#xq3x0x1q60#x10 xxx#xxq30

    xq610#x10 xxx#xq5xx

    q6x10#x10 xxx#q5xxx

    xq010#x10 xxxq5#xxx

    xxq20#x10 xxq6x#xxxxx0q2#x10 xxxq0#xxx

    xx0#q4x10 xxx#q7xxx

    xx0#xq410 xxx#xq7xx

    xx0#q5xx0 xxx#xxq7x

    xx0q5#xx0 xxx#xxxq

    7

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    21/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 21 of 26

    Turing Machines

    •   Example 2:

    Consider the language   L2   =

    {02n

    n ≥ 0}.

     Algorithm:

    1. Move the read/write from

    left to right across the tape.

     As this is done, replace

    every other 0 that is

    encountered with an x .

    2. If there is only one

    remaining 0 after step 1,

    accept.

    3. If the number of remaining

    0s is an odd number greater than 1, reject the

    string.

    4. If the number of remaining

    0s is an even number,

    repeat step 1.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    22/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 22 of 26

    Turing Machines

    The TM  M 2 that can decide the

    language L2 = {02n n ≥ 0} is:

     

    →    L     

    0, x → L

    0 → ,Rq 0

    q reject

    q 1   q 2

    q 4

    q 3q accept

     

       →       R

    0 → x, R

    x → Rx → R

      → R

      → R

    0 → R 0 → x, R

    x → R

    X, → R

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    23/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 23 of 26

    Turing Machines

    Simulating how   M 2 accepts thestring 00000000, the following

    are the series of configurations

    M 2 enters:

    q000000000   q1x0x0x0x

    q10000000   xq10x0x0x

    xq2000000   xxq2x0x0x

    x0q300000   xxxq20x0x

    x0xq20000   xxx0q3x0x

    x0x0q3000   xxx0xq30x

    x0x0xq200   xxx0xxq2xx0x0x0q30   xxx0xxxq2x0x0x0xq2   xxx0xxq4x

    x0x0x0q4x   xxx0xq4xx

    x0x0xq40x   xxx0q4xxx

    x0x0q4x0x   xxxq40xxxx0xq40x0x   xxq4x0xxx

    x0q4x0x0x   xq4xx0xxx

    xq40x0x0x   q4xxx0xxx

    q4x0x0x0x   q4xxx0xxx

    q4x0x0x0x   q1xxx0xxx

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    24/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 24 of 26

    Turing Machines

    xq1

    xx0xxx   xq4

    xxxxxx

    xxq1x0xxx   q4xxxxxxx

    xxxq10xxx   q4xxxxxxx

    xxxxq2xxx   q1xxxxxxx

    xxxxxq2xx   xq1xxxxxx

    xxxxxxq2x   xxq1xxxxx

    xxxxxxxq2   xxxq1xxxx

    xxxxxxq4x   xxxxq1xxx

    xxxxxq4xx   xxxxxq1xx

    xxxxq4xxx   xxxxxxq1x

    xxxq4xxxx   xxxxxxxq1xxq4xxxxx

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    25/26

    Theory of Computation (With Automata Theory)

    * Property of STI 

    Page 25 of 26

    Turing Machines

    •   Example 3:

    Consider the language   L3   =

    {ai b j c k  i j  = k  and i , j , k  ≥ 0}.

     Algorithm:

    1. Scan the tape from left to

    right to determine if the

    input string is composed of consecutives   a’s,   followed

    by consecutive   b’s,   and

    then followed by

    consecutive   c ’s. If not,

    reject the string.

    2. Move the read/write head

    back to the first cell (the

    leftmost cell) of the tape.

  • 8/21/2019 MELJUN CORTES Automata Lecture Turing Machines 1

    26/26

    Theory of Computation (With Automata Theory)

    3. Replace an   a   with a   y .Scan to the right (skipping

    a’s)   until a   b   is reached.

    Sweep between   b’s   and

    c ’s,   replacing each   c  with

    an   x   until all   b’s   (eachreplaced by   z   along the

    way) are processed. If 

    there are not enough   c’s,

    reject the string.

    4. Restore the   b’s (previously

    replaced by   z ’s). If there

    are   a’s   remaining, then

    repeat step 3.

    5. If all the   a’s   are replaced

    by   y ’s,   determine if all the

    c ’s are replaced by   x ’s. If 

    yes, then accept the string,

    else reject the string.