MELJUN CORTES Automata Theory 16

Embed Size (px)

Citation preview

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    1/23

    CSC 3130: Automata theory and formal languages

    Variants of Turing Machines

    Fall 2008MELJUN P. CORTES MBA MPA BSCS ACS

    MELJUN CORTES

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    2/23

    Recognizing versus deciding

    Looping is an undesirable behavior so we

    say

    Such TM are called deciders

    The language recognized by a TM is theset ofall inputs that make it reach qacc

    A TM decides language Lif it recognizes L

    and

    does not loop on any input

    accept reject loop

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    3/23

    Turing Machines

    state control

    infinite tape

    0 1 0

    input

    Why is this a universal model of computation?

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    4/23

    The Church-Turing Thesis

    On Computable Numbers, with an

    Application to the Entscheidungsproblem

    1936:

    Section 9. The extent of the computable numbers

    All arguments [for the CT Thesis] which can be given arebound to be, fundamentally, appeals to intuition, and for this

    reason rather unsatisfactory mathematically.

    The arguments which I shall use are of three kinds:

    1. A direct appeal to intuition

    2. A proof of the equivalence of two definitions

    (In case the new definition has greater intuitive appeal)

    3. Giving examples of large classes of numbers which arecomputable.

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    5/23

    Variant 1: The multitape Turing

    Machine

    The transition may depend on the contents

    of

    all the cells

    Different tape heads can be moved

    independently

    state control tape 1 0 1 0

    tape 2 0 1

    tape 3 1 0 0

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    6/23

    Variant I: The multitape Turing

    Machine

    Multitape Turing Machines recognize thesame

    languages as single-tape Turing Machines

    M

    0 1 0

    0 1

    1 0 0

    G

    = {0, 1,

    }

    S 0 1 0 10 # # 0 #1 0

    G= {0, 1, , 0, 1, , #}

    #

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    7/23

    Variant I: The multitape Turing

    MachineFor every transition inM, do following in S:

    Until you find the last #,

    Find the next dotted symbolUpdate this symbol according to transition inM

    Move the dot according to transition inMIf there is no space to move the dot,

    Move everything to the right of the dot

    to make space firstMove head of Sto beginning of tape

    S 0 1 0 10 # # 0 #1 0

    G= {0, 1, , 0, 1, , #}

    #

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    8/23

    Variant 2: The random access

    machine

    It has registersthat can store arbitrary

    values, a

    program counter, and a random-accessmemor

    load -7 R0:= -7write R3 M[R3] := R0store R5 R5 := R0add R5 R0:= R0+ R5jpos 3 if R

    0> 0 thenPC := 3

    accept

    instruction meaning012345

    0PC

    0R0

    0R1

    0R2

    2M 1 2 2 0

    0 1 2 3 4

    program

    counter

    registers

    memory

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    9/23

    Variant 2: The random access

    machineload -7 R0:= -7write R2 M[R2] := R0save R1 R1 := R0add R1 R0:= R0+ R1jzero 3 if R

    0

    = 0 thenPC := 3accept

    instruction meaning012345

    0PC

    0R0

    0R1

    0R2

    0M 0 0 0 0

    0 1 2 3 4

    -7

    -7

    -7

    -14

    12345

    The instructions are indexed by the

    program counter

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    10/23

    Variant 2: The random access

    machine

    Simulating a Turing Machine on a RAM:

    Random assess machines recognize thesame

    languages as Turing Machines

    PC

    2R0

    1M 2 1 0 0

    M 2 11

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    11/23

    save R1 handle for state q00

    Simulating a TM on a RAM

    M

    q0

    q1

    qacc

    save R1 save head position

    read R1 read tape contents

    xadd -1

    jzero 6 if x= 1goto line 6

    load 2 new value of cell

    write R1 write in memory

    load R1 recall head position

    add 1 move head to right

    jump 30 go to state q1

    program0123

    6789

    10

    2 11 save R1 handle for state q1

    accept handle for state qacc

    30

    200

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    12/23

    Simulating a RAM on a Turing

    MachineThe configuration of a RAM consists of

    Program counter

    Contents of registers

    Indices and contents of all nonempty memory

    cells14PC

    3R0

    -7R1

    5R2

    2M 0 1 2 0

    1 2 3 4

    configuration =(14, 3, -7, 5, (0, 2), (2, 1), (3, 2))

    0

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    13/23

    Simulating a RAM on a Turing

    MachineThe TM has a simulation tape and a

    scratch tape

    The simulation tape stores RAM

    configuration

    The TM has a set of states corresponding

    to each

    (14,3,-7,5,(0,2),(2,1),(3,2))

    M

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    14/23

    Simulating a RAM on a Turing

    MachineExample: load R1

    (14,3,-7,5,(0,2),(2,1),(3,2))

    2. Write R1to conf tape

    c

    1. Copy R1to scratch tape -7s

    (14,-,-7,5,(0,2),(2,1),(3,2))

    -7

    c

    s

    (14,-,-7,5,(0,2),(2,1),(3,2))c

    (14,-,-7,5,(0,2),(2,1),(3,2) )c

    .

    (14,- ,-7,5,(0,2),(2,1),(3,2))c

    .

    .

    Make more space

    as needed

    (14,-7,-7,5,(0,2),(2,1),(3,2))c3. Erase scratch tape

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    15/23

    Variant 3: Nondeterministic

    Turing Machine

    The transition function is nondeterministic:

    The language recognized byNare those

    strings that

    can lead N to end in qacc

    N0 1 0

    d: (Q{qacc, qrej}) G subsets of (Q G {L, R})

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    16/23

    Equivalence of NTM and TM

    Let us look more deeply into NTMs

    Nondeterministic Turing Machinesrecognize

    the same languages as Turing Machines

    q3

    q5

    q6

    Nondeterministic choices can

    be numbered

    The first msteps of the computation

    are then fully specified by a sequenceof mnumbers

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    17/23

    Simulating a nondeterministic

    TMN

    1 00

    k= maximum number ofnondeterministic

    choices in any state

    M 1 00

    1 00

    3 21

    input tape

    2

    simulation tape

    address tape

    Address tape specifies nondeterministic choices ofN

    First, input is copied from input tape to simulation tapeThen,M simulatesNusing address tape data

    G = G{1,..., k}

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    18/23

    How to use the address tape

    SupposeNaccepts xwhen nondeterminism =11221321

    Then we want to make sure the address tape contains

    the string 11221321 at some pointin its execution

    N

    1 00

    M 1 00

    1 00

    3 21

    input tape

    2

    simulation tape

    address tape

    To ensure this we try all possibilities for the address tape

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    19/23

    Simulating a nondeterministic

    TM1 00

    1 00

    3 21

    input tape x

    2

    simulation tape z

    address tape a

    Initially:

    x= input ofN

    ais empty

    For all possible strings a:Copy xto z.

    SimulateNon input zusing a as the nondeterminism

    If aspecifies an invalid choice or

    simulation runs out of choices, abandon simulation.IfNenters its accept state, accept and halt.

    IfNenters its reject state, abandon simulation.

    Description ofM:

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    20/23

    Correctness of simulation

    IfNaccepts x:

    For all possible strings a:

    Copy xto z.SimulateNon input zusing a as the nondeterminism

    If aspecifies an invalid choice or

    simulation runs out of choices, abandon simulation.

    IfNenters its accept state, accept and halt.IfNenters its reject state, abandon simulation.

    Eventually,Mwill

    encounterthe correct a

    Description ofM:

    SoMwill

    accept

    Provided that all previoussimulations halt!

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    21/23

    Correctness of simulation

    Claim: Simulation step always halts (never

    loops)For all possible strings a:

    Copy xto z.SimulateNon input zusing a as the nondeterminism

    If aspecifies an invalid choice or

    simulation runs out of choices, abandon simulation.

    IfNenters its accept state, accept and halt.IfNenters its reject state, abandon simulation.

    Description ofM:

    Since ais finite, the simulation will

    eventually

    run out of choices

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    22/23

    Correctness of simulation

    IfNdoes not accept x, then for every a:

    For all possible strings a:

    Copy xto z.SimulateNon input zusing a as the nondeterminism

    If aspecifies an invalid choice or

    simulation runs out of choices, abandon simulation.

    IfNenters its accept state, accept and halt.IfNenters its reject state, abandon simulation.

    Description ofM:

    EitherNwill loop, so

    simulationruns out of choices

    OrNrejects, so simulation is

    abandoned anyway

    In either case, simulation fails, so M loops forever!

  • 8/13/2019 MELJUN CORTES Automata Theory 16

    23/23

    Context-free languages are

    recognizableCorollary

    In fact

    If Lis context-free, then it is recognizable by a TM

    If Lis context-free, then it is decidedby some TM