chapter 8 introduction to turing machines (part a) (1)

Upload: carlos-panameno

Post on 14-Apr-2018

236 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    1/40

    1

    Chapter 8 Introduction toTuring Machines (part a)

    Rothenberg, Germany

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    2/40

    2

    Outline

    Problems that Computers Cannot Solve

    The Turing Machine (TM)

    (in part b) Programming Techniques for TMs

    Extensions to the Basic TM

    Restricted TMs

    TMs and Computers

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    3/40

    3

    8.0 Introduction

    Concepts to be taught ---

    Studying questions about what languages can

    be defined be any computational device??There are specific problems that cannot be

    solved by computers! --- undecidable!

    Studying the Turing machine which seemssimple, but can be recognized as an accurate

    model for what any physical computing

    device is capable of doing.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    4/40

    4

    8.1 Problems That Computers

    Cannot Solve

    Purpose of this section ---

    to provide an informal proof , C-

    programming-based introduction to proof of aspecific problem that computers cannot solve.

    The problem:

    whether the first thing a C program prints ishello, world.

    We will give the intuition behind the formal

    proof.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    5/40

    5

    8.1 Problems That Computers

    Cannot Solve

    8.1.1 Programs that print Hello, World

    A C program that prints Hello, World :

    main(){

    print(hello, world\n);

    }

    Define hello, world problemto be:

    determine whether a given C program, with a given

    input, prints hello, worldas the first 12 characters

    that it prints.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    6/40

    6

    8.1 Problems That Computers

    Cannot Solve

    8.1.1 Programs that print Hello, World

    The problem described alternatively using symbols:

    Is there a programHthat could examine any

    program P and input I for P, and tell whether P,

    run with I as its input, would print hello, world?(A

    programHmeans an algorithmin concept here.)

    The answer is: undecidable! That is, there exists no

    suchprogram

    H. We will prove this by contradiction.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    7/407

    8.1 Problems That Computers

    Cannot Solve

    8.1.2 Hypothetical Hello, World Tester

    1ststep: assumeHexists in the following form:

    2ndstep: transformHto another formH2in simple

    ways which can be done by C programs

    3rdstep: proveH2 not existing. SoHalso not existing.

    Hello-world

    tester

    H

    I

    P

    yes if P, with input I , pr in tshello world

    no if not.Figure 8.3

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    8/408

    8.1 Problems That Computers

    Cannot Solve 8.1.2 Hypothetical Hello, World Tester

    2ndstep:

    (1) transformHtoH1in the following way -

    (2) transformH1toH

    2in the following way

    Use P both as input and program!

    Hello-world

    tester

    H1

    I

    P

    yes

    hel lo, wo rld

    Figure 8.4

    Hello-world

    tester

    H2

    P

    yes

    hel lo, wo rld

    Figure 8.5

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    9/409

    8.1 Problems That Computers

    Cannot Solve 8.1.2 Hypothetical Hello, World Tester

    2ndstep (contd):

    The function ofH2is:

    given any program P as input,if P prints hello world as first output, thenH2makes

    output yes;

    if P does not prints hello worldas first output, thenH2

    prints hello world.

    Hello-world

    tester

    H2

    P

    yes

    hel lo, wo rld

    Figure 8.5

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    10/40

    10

    8.1 Problems That Computers

    Cannot Solve

    8.1.2 Hypothetical Hello, World Tester3rdstep:

    ProveH2does not exist as follows

    LetPforH2in Fig. 8.5 (last figure) beH2itself, as

    follows:

    Hello-world

    tester

    H2

    H2

    yes

    hel lo, wo rld

    Figure 8.6

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    11/40

    11

    8.1 Problems That Computers

    Cannot Solve

    8.1.2 Hypothetical Hello, World Tester3rdstep (contd): ProveH2does not exist by contradiction as follows (contd)

    Now,

    (1) if the boxH2, given itself as input, makes outputyes, then it

    means thatthe inputH2, given itself as input, prints hello worldas first

    output.

    But this is contradictory because we just suppose thatH2, given

    itself as input, makes outputyes.

    Hello-world

    tester

    H2

    H2

    yes

    hel lo, wo rld

    Figure 8.6

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    12/40

    12

    8.1 Problems That Computers

    Cannot Solve

    8.1.2 Hypothetical Hello, World Tester3rdstep (contd): ProveH2does not exist as follows (contd)

    The above contradiction means the other alternative must betrue (since it must be one or the other), that is ---

    (2) the boxH2, given itself as input, printshello, world. Thisthen means that

    suchH2, when taken as input to the boxH2(itself), will makethe boxH2to make outputyes.

    Contradiction again because we just say that the boxH2,

    given itself as input, printshello, world.

    Hello-world

    testerH2

    H2

    yes

    Hel lo, world

    Figure 8.6

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    13/40

    13

    8.1 Problems That Computers

    Cannot Solve

    8.1.2 Hypothetical Hello, World Tester

    3rdstep (contd):

    ProveH2does not exist as follows (contd)

    Since both cases lead to contradiction, we conclude that the

    assumption thatH2exists is wrong by the principle of

    contradiction for proof.

    Hello-world

    tester

    H2

    H2

    yes

    Hel lo, world

    Figure 8.6

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    14/40

    14

    8.1 Problems That Computers

    Cannot Solve

    8.1.2 Hypothetical Hello, World Tester

    3rdstep (contd):

    H2does not exist

    H1does not exist (otherwise,H2must exist)

    Hdoes not exist (otherwise,H1must exist)

    The above self-contradictory technique, similar to the

    diagonalization technique (to be introduced later), was

    used by Alan Turing for proving undecidable problems.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    15/40

    15

    8.1 Problems That Computers

    Cannot Solve

    8.1.3 Reducing One Problem to Another

    Now we have an undecidable problem, which can be

    used to prove other undecidable problems by a

    technique of problem reduction.That is, if we knowP1is undecidable, then we may

    reduce P1to a new problem P2, so that we may prove

    P2

    undecidable by contradiction in the following way:

    If P2is decidable, then P1is decidable.

    But P1 is known undecidable. So, contradiction!

    Consequently, P2is undecidable.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    16/40

    16

    8.1 Problems That Computers

    Cannot Solve

    8.1.3 Reducing One Problem to Another

    Example 8.1

    We want to prove a new problemP2

    (called calls-foo

    problem):

    does program Q, given input y, ever call function foo?

    to be undecidable.

    Solution: regard Q in P1;

    reduceP1: the hello-world problem toP2: the calls-

    foo problem in the following way:

    (continued in the next page)

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    17/40

    17

    8.1 Problems That Computers

    Cannot Solve

    8.1.3 Reducing One Problem to AnotherExample 8.1 (contd)

    Solution: reduceP1toP2in the following way:

    If Qhas a function called foo, renameitand all calls to that

    function a new program Q1doing the same as Q. ()

    Add to Q1a function foo doing nothing & notcalled a new Q2

    Modify Q2to remember the first 12 characters that it prints,

    storing them in a global arrayAQ3 Modify Q3so that whenever it executes any output statement, it

    checksAto see if it has written 12 characters or more, and if so,

    whetherhello, world are the first characters. In that case, call the

    new function foo Rwith inputz=y.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    18/40

    18

    8.1 Problems That Computers

    Cannot Solve

    8.1.3 Reducing One Problem to Another

    Example 8.1 (contd)

    Solution (contd): Now,

    (1) if Qwith input y prints hello, worldas its first output, thenRwill call foo;

    (2) if Qwith input y does not print hello, world, thenRwill

    never call foo.

    (3) That is,R,with inputy,calls fooif and only if Q,with input

    y,prints hello, world.

    (4) So, if we can decide whetherR,with inputz,calls foo, then

    we can decide whether Q, with inputy, prints hello, world.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    19/40

    19

    8.1 Problems That Computers

    Cannot Solve

    8.1.3 Reducing One Problem to AnotherThe above example illustrates how to reduce a

    problem to another.

    An illustration of this idea is:

    ConstructP1

    instance

    P2

    instanceDecide yes

    no

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    20/40

    20

    8.2 The Turing Machine

    Concepts to be taught:

    The study of decidability provides guidance to programmers

    about what they might or might not be able to accomplish

    through programming. Previous problems are dealt with programs. But not all

    problems can be solved by programs.

    We need a simple model to deal with other decision problems

    (like grammar ambiguity problems) The Turing machine is one of such models, whose

    configuration is easy to describe, but whose function is the

    most versatile: all computations done by a modern computer

    can be done by a Turing machine.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    21/40

    21

    8.2 The Turing Machine

    8.2.1 The Quest to Decide All Mathematical

    Questions

    At the turn of 20thcentury, D, Hilbert asked:

    whether it was possible to find an algorithm for

    determining the truth or falsehood of any

    mathematical proposition.(in particular, he asked if there was a way to decide

    whether any formula in the 1st-order predicate

    calculus, applied to integer, was true)

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    22/40

    22

    8.2 The Turing Machine

    8.2.1 The Quest to Decide All MathematicalQuestions

    In 1931, K. Gdel published his incompleteness

    theorem:

    A certain formula in the predicate calculus applied

    to integers could not be neither proved nor

    disproved within the predicate calculus.

    The proof technique is diagonalization,resembling the self-contradictory technique

    used previously.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    23/40

    23

    8.2 The Turing Machine

    8.2.1 The Quest to Decide All MathematicalQuestions

    Natures of computational model

    Predicate calculus --- declarative

    Partial-recursive functions --- computational (a

    programming-language-like notion)

    Turing machine --- computational (computer-like)

    (invented by Alan Turing several years before true

    computers were invented)

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    24/40

    24

    8.2 The Turing Machine

    8.2.1 The Quest to Decide All Mathematical

    Questions

    Equivalence of maximalcomputational model

    They all compute the same functions or recognize

    the same languages, having the same power ofcomputation

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    25/40

    25

    8.2 The Turing Machine

    8.2.1 The Quest to Decide All MathematicalQuestions

    Unprovable Church-Turing hypothesis (or

    thesis)

    Any general way to compute will allow us to

    compute only the partial-recursive functions (orequivalently, what the Turing machine or modern-

    day computers can compute).

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    26/40

    26

    8.2 The Turing Machine

    8.2.2 Notion for the Turing Machine

    A model for Turing machine:

    BX2

    Finite

    control

    B B X1 Xi Xn B

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    27/40

    27

    8.2 The Turing Machine

    8.2.2 Notion for the Turing Machine

    A move of Turing machine includes:

    change state;

    write a tape symbol in the cell scanned; move the tape head left or right.

    Formal definition:

    A Turing machine (TM) is a 7-tupleM= (Q, S, G, d,q0,B,F) where

    Q: a finite set of states of the finite control;

    S: a finite set of input symbols;

    G: a set of tape symbols, with Sbeing a subset;

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    28/40

    28

    8.2 The Turing Machine

    8.2.2 Notion for the Turing Machine

    Formal definition (contd):

    d: a transition function d(q,X) = (p, Y,D) where

    q: the current state, in Q;

    X: a tape symbol being scanned;

    p: the next state, in Q;

    Y: the tape symbol written on the cell being scanned, used

    to replaceX;

    D: eitherL(left) orR (right) telling the move direction of

    the tape head;

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    29/40

    29

    8.2 The Turing Machine

    8.2.2 Notion for the Turing Machine

    Formal definition (contd):

    q0: the start state, in Q;

    B: the blank symbol in G,notin S (should not

    be an input symbol);

    F: the set of final or accepting states.

    A TM is a deterministicautomaton with a two-

    way infinitetape which can be read and writtenin

    either direction.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    30/40

    30

    8.2 The Turing Machine

    8.2.3 Instantaneous Descriptions for Turing

    Machine

    The instantaneous description(ID) of a TM isrepresented by

    X1X2Xi1qXiXi+1Xnin which

    qis the current state;The tape head is scanning the ith symbol from the left;

    X1X2Xnis the portion of the tape between the

    leftmost and the rightmost nonblank symbols.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    31/40

    31

    8.2 The Turing Machine

    8.2.3 Instantaneous Descriptions for Turing

    Machine

    Moves of a TM Mdenoted by or as follows:If d(q,Xi) = (p, Y,L) (a leftward move), then we

    write the following to describe the left move:

    X1X2Xi1qXiXi+1Xn X1X2Xi2pXi1YXi+1Xn

    Right moves are defined similarly.

    _

    |

    _

    |M

    _|M

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    32/40

    32

    8.2 The Turing Machine

    8.2.3 Instantaneous Descriptions for TuringMachine

    Example 8.2--- Design a TM to accept the languageL=

    {0n1n| n1} as follows.

    Starting at the left end of the input.

    Change 0 to anX.

    Move to the right over 0s and Ys until a 1.

    Change 1 to Y.

    Move left over Ys and 0s until anX.

    Look for a 0 immediately to the right.

    If a 0 is found, change it toXand repeat the above process.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    33/40

    33

    8.2 The Turing Machine

    8.2.3 Instantaneous Descriptions for TuringMachine

    Example 8.2--- Design a TM to accept the

    languageL= {0n1n| n1} (contd).

    M= ({q0~q4}, {0, 1}, {0, 1,X, Y,B}, d, q0,B, {q4})

    Transition table: in the next page.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    34/40

    34

    symbol

    state 0 1 X Y B

    q0

    (q1, X, R)1 - - (q3, Y, R)8 -q1

    (q1, 0, R)2 (q2, Y, L )4 - (q1, Y, R)3 -

    q2 (q2, 0, L )5 - (q0, X, R)7 (q2, Y, L )6 -q3 - - - (q

    3, Y, R)

    9 (q

    4, B, R)

    10

    q4

    - - - - -

    8.2 The Turing Machine 8.2.3 Instantaneous Descriptions for TM

    Example 8.2---

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    35/40

    35

    8.2 The Turing Machine

    8.2.3 Instantaneous Descriptions for TM

    Example 8.2(contd)

    To accept 0011 ---

    (use instead of )

    q0

    0011 Xq1

    011 X0q1

    11 Xq2

    0Y1 q2

    X0Y1

    Xq00Y1 XXq1Y1 XXYq11 XXq2YYXq2XYY

    XXq0YYXXYq3YXXYYq3BXXYYBq4B

    _|

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    36/40

    36

    8.2 The Turing Machine

    8.2.4 Transition Diagrams for TMs

    If d(q,X) = (p, Y,L), we use labelX/Yon the arc.

    If d(q,X) = (p, Y,R), we use labelX/Yon the arc.

    Example 8.3 --- Transition diagram for Example 8.2.

    See the textbook, p. 331.

    Example 8.4 --- TM as a function-computingmachine.No final state is needed. For details, see thetextbook and part b.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    37/40

    37

    8.2 The Turing Machine

    8.2.5 The Language of a TM

    LetM= (Q, S, G, d, q0,B,F) be a TM. The language

    accepted byMisL(M) = {w| wS*and q0w apbwithpF}

    The set of languages accepted by a TM is often

    called the recursively enumerable language or RElanguage.

    The term RE came from computational formalism

    that predate the TM.

    _*|M

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    38/40

    38

    8.2 The Turing Machine

    8.2.6 TMs and Halting

    Another notion for accepting strings by TMs

    --- acceptance by halting.

    We say a TM halts if it enters a state q

    scanning a tape symbolX, and there is no

    move in this situation, i.e., d(q,X) is

    undefined.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    39/40

    39

    8.2 The Turing Machine

    8.2.6 TMs and Halting

    Acceptance by halting may be used for a TMs

    functions other than accepting languages like Example8.4 and Example 8.5.

    We assume that a TM always halts when it is in an

    accepting state.It is not always possible to require that a TM halts even

    it does not accept.

  • 7/27/2019 Chapter 8 Introduction to Turing Machines (Part a) (1)

    40/40

    40

    8.2 The Turing Machine

    8.2.6 TMs and Halting

    Languages with TMs that do halt eventually,

    regardless whether or not they accept, are calledrecursive(considered in Sec. 9.2.1)

    TMs that always halt, regardless of whether or not

    they accept, are a good model of an algorithm. So TMs that always halt can be used for studies of

    decidability (see Chapter 9).