bfe1emodule4turing machine

Upload: samarth-saxena

Post on 07-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 Bfe1emodule4turing Machine

    1/47

    1

    Turing Machines

    Zeph Grunschlag

  • 8/4/2019 Bfe1emodule4turing Machine

    2/47

    2

    A

    gendaTuring Machines Alan Turing

    Motivation

    Church-Turing Thesis

    Definitions

    Computation

    TM Configuration

    Recognizers vs. Deciders

  • 8/4/2019 Bfe1emodule4turing Machine

    3/47

    3

    A

    lan TuringAlan Turing was one of the founding fathers of

    CS.

    His computer model the Turing Machinewas inspiration/premonition of the electroniccomputer that came two decades later

    Was instrumental in cracking the Nazi

    Enigma cryptosystem in WWIIInvented the Turing Test used in AI

    Legacy: The Turing Award. Pre-eminentaward in Theoretical CS

  • 8/4/2019 Bfe1emodule4turing Machine

    4/47

    4

    A

    Thinking MachineFirst Goal of Turings Machine: A model that

    can compute anything that a human can

    compute. Before invention of electroniccomputers the term computer actuallyreferred to a person whos line of work is tocalculate numerical quantities!

    As this is a philosophical endeavor, it cantreally be proved.

    Turings Thesis: Any algorithm can be carriedout by one of his machines

  • 8/4/2019 Bfe1emodule4turing Machine

    5/47

    5

    A

    Thinking MachineSecond Goal of Turings Machine: A model

    thats so simple, that can actually prove

    interesting epistemological results. EyedHilberts 10th problem, as well as acomputational analog of GdelsIncompleteness Theorem in Logic.

    Philosophy notwithstanding, Turings programsfor cracking the Enigma cryptosystem provethat he really was a true hacker! Turingsmachine is actually easily programmable, ifyou really get into it. Not practically useful,

    though

  • 8/4/2019 Bfe1emodule4turing Machine

    6/47

    6

    A

    Thinking MachineImagine a super-organized, obsessive-

    compulsive human computer. The computer

    wants to avoid mistakes so everything writtendown is completely specified oneletter/number at a time. The computerfollows a finite set of rules which are referredto every time another symbol is written

    down. Rules are such that at any given time,only one rule is active so no ambiguity canarise. Each rule activates another ruledepending on what letter/number is currently

    read, EG:

  • 8/4/2019 Bfe1emodule4turing Machine

    7/47

    7

    A Thinking MachineEG Successor Program

    Sample Rules:

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    Lets see how they are carried out on apiece of paper that contains thereverse binary representation of47:

  • 8/4/2019 Bfe1emodule4turing Machine

    8/47

    8

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    1 1 1 1 0 1

  • 8/4/2019 Bfe1emodule4turing Machine

    9/47

    9

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 1 1 1 0 1

  • 8/4/2019 Bfe1emodule4turing Machine

    10/47

    10

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 1 1 0 1

  • 8/4/2019 Bfe1emodule4turing Machine

    11/47

    11

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 1 0 1

  • 8/4/2019 Bfe1emodule4turing Machine

    12/47

    12

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 0 0 1

  • 8/4/2019 Bfe1emodule4turing Machine

    13/47

    13

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 0 1 1

  • 8/4/2019 Bfe1emodule4turing Machine

    14/47

    14

    A Thinking MachineEG Successor Program

    So the successors output on 111101 was000011 which is the reverse binaryrepresentation of48.

    Similarly, the successor of 127 should be128:

  • 8/4/2019 Bfe1emodule4turing Machine

    15/47

    15

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    1 1 1 1 1 1 1

  • 8/4/2019 Bfe1emodule4turing Machine

    16/47

    16

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 1 1 1 1 1 1

  • 8/4/2019 Bfe1emodule4turing Machine

    17/47

    17

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 1 1 1 1 1

  • 8/4/2019 Bfe1emodule4turing Machine

    18/47

    18

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 1 1 1 1

  • 8/4/2019 Bfe1emodule4turing Machine

    19/47

    19

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 0 1 1 1

  • 8/4/2019 Bfe1emodule4turing Machine

    20/47

    20

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 0 0 1 1

  • 8/4/2019 Bfe1emodule4turing Machine

    21/47

    21

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 0 0 0 1

  • 8/4/2019 Bfe1emodule4turing Machine

    22/47

    22

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 0 0 0 0

  • 8/4/2019 Bfe1emodule4turing Machine

    23/47

    23

    A Thinking MachineEG Successor Program

    If read 1, write 0, go right, repeat.

    If read 0, write 1, HALT!

    If read , write 1, HALT!

    0 0 0 0 0 0 0 1

  • 8/4/2019 Bfe1emodule4turing Machine

    24/47

    24

    A Thinking Machine

    It was hard for the ancients to believe that anyalgorithm could be carried out on such a

    device. For us, its much easier to believe,especially if youve programmed in assembly!

    However, ancients did finally believe Turingwhen Churchs lambda-calculus paradigm (on

    which lisp programming is based) provedequivalent!

  • 8/4/2019 Bfe1emodule4turing Machine

    25/47

    25

    Turing Machines

    A Turing Machine (TM) is a device with a finiteamount of read-only hard memory (states),and an unbounded1 amount of read/writetape-memory. There is no separate input.Rather, the input is assumed to reside on thetape at the time when the TM starts running.

    Just as with Automata, TMs can either beinput/output machines (compare with FiniteState Transducers), or yes/no decisionmachines. Start with yes/no machines.

  • 8/4/2019 Bfe1emodule4turing Machine

    26/47

    26

    Comparison with PreviousModels

    DeviceSeparateInput?

    Read/Write DataStructure

    Deterministicby default?

    FA

    PDA

    TM

  • 8/4/2019 Bfe1emodule4turing Machine

    27/47

    27

    Comparison with PreviousModels

    DeviceSeparateInput?

    Read/Write DataStructure

    Deterministicby default?

    FA Yes None Yes

    PDA

    TM

  • 8/4/2019 Bfe1emodule4turing Machine

    28/47

    28

    Comparison with PreviousModels

    DeviceSeparateInput?

    Read/Write DataStructure

    Deterministicby default?

    FA Yes None Yes

    PDA Yes LIFO Stack No

    TM

  • 8/4/2019 Bfe1emodule4turing Machine

    29/47

    29

    Comparison with PreviousModels

    DeviceSeparateInput?

    Read/Write DataStructure

    Deterministicby default?

    FA Yes None Yes

    PDA Yes LIFO Stack No

    TM No1-way infinitetape. 1 cell

    access per step.

    Yes

    (but will alsoallow crashes)

  • 8/4/2019 Bfe1emodule4turing Machine

    30/47

    30

    Turing MachineDecision Machine Example

    First example (adding 1 bit to reverse binarystring) was basically something that a Finite

    Transducer could have achieved (exceptwhen theres overflow). Lets give anexample from next step up in languagehierarchy.

    {bit-strings with same number of 0s as 1s}a context free language:

  • 8/4/2019 Bfe1emodule4turing Machine

    31/47

    31

    Turing MachineDecision Machine Example

    This is a true Turing machine as:

    Tape is semi-infinite (indicated by torn cell):

    Input is prepared at beginning of tape

    No intrinsic way to detect left tape end similar to empty stack detection problem for PDAs

    similar trick used introduce $ as the end symbolAll rules must include a move direction (R/L)

    Situations that cant happen arent dealt with(technically under-deterministic)

  • 8/4/2019 Bfe1emodule4turing Machine

    32/47

    32

    Turing MachineDecision Machine Example

    {bit-strings with same number of 0s as 1s}:

    Pseudocode:

    while (there is a 0 and a 1)

    cross these out

    if (everything crossed out)

    accept

    else

    reject

  • 8/4/2019 Bfe1emodule4turing Machine

    33/47

    33

    TM ExampleInstructions Set

    0. if read , go right (dummy move), ACCEPT

    if read 0, write $, go right, goto 1 // $ detects start of tape

    if read 1, write $, go right, goto 2

    1. if read , go right, REJECT

    if read 0 or X, go right, repeat (= goto 1) // look for a 1if read 1, write X, go left, goto 3

    2. if read , go right, REJECT

    if read 1 or X, go right, repeat // look for a 0

    if read 0, write X, go left, goto 3

    3. if read $, go right, goto 4 // look for start of tapeelse, go left, repeat

    4. if read 0, write X, go right, goto 1 // similar to step 0

    if read 1, write X, go right, goto 2

    if read X, go right, repeat

    if read , go right, ACCEPT

  • 8/4/2019 Bfe1emodule4turing Machine

    34/47

    34

    TM ExampleState Diagram

    These instructions can be expressed by a familiarlooking flow diagram:

    0

    1

    rej

    0$,R

    acc

    R

    21$,R

    0|XR

    1|XR

    3

    R

    0X,L

    1X,L 0|1|XL

    4

    $R

    XR

    0X,R

    1X,R

    R

  • 8/4/2019 Bfe1emodule4turing Machine

    35/47

    35

    TM Transition NotationAn edge from the state p to the state q labeled

    by

    ab,D means if in state p and tape head

    reading a, replace a by b and move in thedirection D, and into state q

    aD means if in state p and tape headreading a, dont change a and move in the

    direction D, and into state qa|b||z means that given that thetape head is reading any of the pipeseparated symbols, take same action onany of the symbols

  • 8/4/2019 Bfe1emodule4turing Machine

    36/47

    36

    TM Configuration NotationA TMs next action is completely determined by

    current state and symbol read, so canpredict all of future actions if know:

    1. current state2. current tape contents3. current position of TMs reading headHandy notation lists all of these in a single

    string. A symbol representing current state,is sandwiched between content of tape toleft of head, and content of tape to right(including tape head). The part of tape

    which is blank ad-infinitum is ignored.

  • 8/4/2019 Bfe1emodule4turing Machine

    37/47

    37

    TM Configuration NotationFor example

    Is denoted by:$xxx1q3010

    Reading rule 3

  • 8/4/2019 Bfe1emodule4turing Machine

    38/47

    38

    TM ExampleCrazy Web-Page

    The following link shows how theexample machine accepts 01101010

    and how the tape configuration notationchanges step by step.

  • 8/4/2019 Bfe1emodule4turing Machine

    39/47

    39

    TM Formal DefinitionStatic Picture

    DEF: ATuring machine (TM) consists ofa 7-tuple M = (Q, 7, +, H, q0, qacc, qrej). Q, 7,and q0, are the same as for an FA. +is the

    tape alphabet which necessarily containsthe blank symbol , as well as the inputalphabet7. H is as follows:

    Therefore given a non-halt state p, and a tapesymbol x, Hp,x= (q,y,D) means that TM goesinto state q, replaces x by y, and the tapehead moves in direction D.

    }RL,{}),{-(: rejacc v+vp+v QQ qq

  • 8/4/2019 Bfe1emodule4turing Machine

    40/47

    40

    TM Dynamic Picture

    A string x is acceptedby M if after beingput on the tape with the Turing

    machine head set to the left-mostposition, and letting M run, Meventually enters the accept state. In

    this case w is an element of L(M) thelanguage accepted by M.We can formalize this notion as follows:

  • 8/4/2019 Bfe1emodule4turing Machine

    41/47

    41

    TM Formal DefinitionDynamic Picture

    Suppose TMs configuration at time t is given by uapxvwhere p is the current state, ua is whats to the left ofthe head, x is whats being read, and v is whats to theright of the head.

    IfHp,x= (q,y,R) then write:uapxv uaypv

    With resulting configuration uaypv at time t+1. If,Hp,x= (q,y,L) instead, then write:

    uapxv upayvThere are also two special cases: head is forging new ground pad with the blank symbol

    head is stuck at left end by def. head stays put (only case)

    is read as yields

  • 8/4/2019 Bfe1emodule4turing Machine

    42/47

    42

    TM Formal DefinitionDynamic Picture

    As with context free grammars, one can consider thereflexive, transitive closure * of . I.e. this isthe relation between strings recursively defined by:

    if u = v then u * v

    if u v then u * vif u *v and v * w, then u *w

    * is read as computesto

    A string x is said to be accepted by M if the start

    configuration q0 x computes to some acceptingconfiguration y i.e., a configuration containing qacc.

    The language accepted byM is the set of all acceptedstrings. I.e:

    L(M) = { x 7* | accepting config. y, q0 x * y}

  • 8/4/2019 Bfe1emodule4turing Machine

    43/47

    43

    TM Acceptors vs. DecidersThree possibilities occur on a given input w :1. The TM M eventually enters qacc and

    therefore halts and accepts. (w L(M) )2. The TM M eventually enters q

    rej

    or crashessomewhere. M rejectsw . (w L(M) )

    3. Neither occurs! I.e., M never halts itscomputation and is caught up in an infiniteloop, never reaching qacc or qrej. In this case

    w is neither accepted nor rejected. However,any string not explicitly accepted isconsidered to be outside the acceptedlanguage. (w L(M) )

  • 8/4/2019 Bfe1emodule4turing Machine

    44/47

    44

    TM Acceptors vs. DecidersAny Turing Machines is said to be a recognizerand

    recognizesL(M); if in addition, M never enters aninfinite loop, M is called a deciderand is said todecide L(M).

    Q: Is the above M an recognizer? A decider? What isL(M)?

    0

    1

    rej acc

    2

    R

    1R

    0R

    1R 0R

    0R1L

  • 8/4/2019 Bfe1emodule4turing Machine

    45/47

    45

    TM Acceptors vs. DecidersA: M is an recognizer but not a decider because 101

    causes an infinite loop.L(M) = 1+0+

    Q: Is L(M ) decidable ?

    0

    1

    rej acc

    2

    R

    1R

    0R

    1R 0R

    0R1L

  • 8/4/2019 Bfe1emodule4turing Machine

    46/47

    46

    TM Acceptors vs. DecidersA: Yes. All regular languages are decidable

    because can always convert a DFA into aTM without infinite loops.

  • 8/4/2019 Bfe1emodule4turing Machine

    47/47

    47

    Constructive Example

    Heres a document showing how modulardesign can help you write down a TM

    decider for {anbncn}. The example isnon-context free.