23-1-11

Embed Size (px)

Citation preview

  • 8/3/2019 23-1-11

    1/9

  • 8/3/2019 23-1-11

    2/9

    A Turing machine is a kind ofstate machine. At any time the machine is in any one of a finite

    number of states. Instructions for a Turing machine consist in specified conditions under which

    the machine will transition between one state and another.

    The literature contains a number of different definitions of Turing machine. While differing in

    the specifics, they are equivalent in the sense that the same tasks turn out to be Turing-computable in every formulation. The definition here is just one of the common definitions, with

    some variants discussed in section 3 of this article.

    A Turing machine has an infinite one-dimensional tape divided into cells. Traditionally we think

    of the tape as being horizontal with the cells arranged in a left-right orientation. The tape has

    one end, at the left say, and stretches infinitely far to the right. Each cell is able to contain one

    symbol, either 0 or 1.

    The machine has a read-write headwhich is scanning a single cell on the tape. This read-write

    head can move left and right along the tape to scan successive cells.

    The action of a Turing machine is determined completely by (1) the current state of the

    machine (2) the symbol in the cell currently being scanned by the head and (3) a table of

    transition rules, which serve as the program for the machine.

    Each transition rule is a 4-tuple:

    Statecurrent, Symbol, Statenext, Action

    which can be read as saying if the machine is in state Statecurrent and the cell being scanned

    contains Symbol then move into state Statenext taking Action. As actions, a Turing machine

    may either to write a symbol on the tape in the current cell (which we will denote with the

    symbol in question), or to move the head one cell to the left or right, which we will denote by

    the symbols and respectively.

    If the machine reaches a situation in which there is no unique transition rule to be carried out,i.e., there is none or more than one, then the machine halts.

    In modern terms, the tape serves as the memory of the machine, while the read-write head is

    the memory bus through which data is accessed (and updated) by the machine. There are two

    important things to notice about the setup. The first concerns the definition of the machine

    itself, namely that the machine's tape is infinite in length. This corresponds to an assumption

    that the memory of the machine is infinite. The second concerns the definition of Turing-

    computable, namely that a function will be Turing-computable if there exists a set of

    2

  • 8/3/2019 23-1-11

    3/9

    instructions that will result in a Turing machine computing the function regardless of the

    amount of time it takes. One can think of this as assuming the availability of infinite time to

    complete the computation.

    These two assumptions are intended to ensure that the definition of computation that results is

    not too narrow. This is, it ensures that no computable function will fail to be Turing-computablesolely because there is insufficient time or memory to complete the computation. It follows that

    there may be some Turing-computable functions which may not be carried out by any existing

    computer, perhaps because no existing machine has sufficient memory to carry out the task.

    Some Turing-computable functions may not ever be computable in practice, since they may

    require more memory than can be built using all of the (finite number of) atoms in the

    universe. Conversely, a result that shows that a function is not Turing-computable is very

    strong, since it certainly implies that no computer that we could ever build could carry out the

    computation. Section 5 shows that some functions are not Turing-computable.

    Turing machine

    An abstract model of a computing device, used in mathematical studies of computability. A

    Turing machine takes a tape with a string of symbols on it as an input, and can respond to a

    given symbol by changing its internal state, writing a new symbol on the tape, shifting the tape

    right or left to the next symbol, or halting. The inner state of the Turing machine is described

    by a finite state machine. It has been shown that if the answer to a computational problem

    can be computed in a finite amount of time, then there exists an abstract Turing machine that

    can compute it.

    Example 1. As our _rst example, let's construct a Turing machine that takes a binary string and

    appends 0 to the left side of the string. The machine has four states: s; r0; r1; `. State s is the

    starting state, in state r0 and r1 it is moving right and preparing to write a 0 or 1, respectively,

    and in state ` it is moving left. The state s will be used only for getting started: thus, we only

    need to de_ne how the Turing machine behaves when reading . in state s. The states r0 and r1

    will be used, respectively, for writing 0 and writing 1 while remembering the overwritten

    symbol and moving to the right. Finally, state ` is used for returning to the left side of the tape

    without changing its contents. This plain-English description of the Turing machine implies the

    following transition function. For brevity, we have omitted from the table the lines

    corresponding to pairs (q; _) such that the Turing machine can't possibly be reading _ when it is

    in state q.

    3

    http://plato.stanford.edu/entries/turing-machine/#Uncomputabilityhttp://plato.stanford.edu/entries/turing-machine/#Uncomputability
  • 8/3/2019 23-1-11

    4/9

    Universal Turing Machines

    The most striking positive result concerning the capabilities of Turing machines is the existence

    ofUniversal Turing Machines (UTM). When started on a tape containing the encoding of another

    Turing machine, call it T, followed by the input to T, a UTM produces the same result as Twould

    when started on that input. Essentially a UTM can simulate the behavior of any Turing machine

    (including itself).

    One way to think of a UTM is as a programmable computer. When a UTM is given a program (a

    description of another machine), it makes itself behave as if it were that machine while

    processing the input.

    Note again, our identification of input-output equivalence with behaving identically. A

    machine Tworking on input tis likely to execute far fewer transitions that a UTM simulating T

    working on t, but for our purposes this fact is irrelevant.

    In order to design such a machine, it is first necessary to define a way of representing a Turing

    machine on the tape for the UTM to process. To do this we will recall that Turing machines are

    formally represented as a collection of 4-tuples. We will first design an encoding for individual

    tuples, and then for sequences of tuples.

    Universal Turing machines

    The key property of Turing machines, and all other equivalent models of computation, is

    universality: there is a single Turing machine U that is capable of simulating any other Turing

    machine | even those with vastly more states than U. In other words, one can think of U as a

    4

  • 8/3/2019 23-1-11

    5/9

    \Turing machine interpreter", written in the language of Turing machines. This capability for

    self-reference (the language of Turing machines is expressive enough to write an interpreter for

    itself) is the source of the surprising versatility of Turing machines and other models of compu-

    tation. It is also the Pandora's Box that allows us to come up with undecidable problems, as we

    shall see in the following section.

    DeFInition of a universal Turing machine

    A universal Turing machine is a Turing machine U with alphabet f0, 1, `(', `)', `,', `;'g. It takes

    an input of the form .M; xt, where M is a valid description of a Turing machine and x is a string

    in the alphabet of M, encoded using `-bit blocks as described earlier. (If its input fails to match

    this specification, the universal Turing machine U is allowed to behave arbitrarily.) The

    computation of U, given input .M; xt, has the same termination status | halting in state \halt",

    \yes", or \no", or never halting | as the computation of M on input x. Further- more, if M halts on

    input x (and, consequently, U halts on input .M; xt) then the string on U's tape at the time it

    halts is equal to the string on M's tape at the time it halts, again translated into binary using `-

    bit blocks as specified above. It is far from obvious that a universal Turing machine exists. In

    particular, such a machine must have a finite number of states, yet it must be able to simulate

    a computation performed by a Turing machine with a much greater number of states. In

    Section 3.4 we will describe how to construct a universal Turing machine. First, it is helpful to

    extend the definition of Turing machines to allow multiple tapes. After describing this extension

    we will indicate how a multi-tape Turing machine can be simulated by a single-tape machine

    (at the cost of a slower running time).

    Construction of a universal Turing machine

    We now proceed to describe the construction of a universal Turing machine U. Taking

    advantage

    of Section 3.3, we can describe U as a 5-tape Turing machine; the existence of a single-tape

    universal Turing machine then follows from the general simulation presented in that section.

    Our universal Turing machine has four tapes:

    _ the input tape: a read-only tape containing the input, which is never overwritten;

    _ the description tape: a tape containing the description of M, which is written once at

    initialization time and never overwritten afterwards;

    _ the working tape: a tape whose contents correspond to the contents of M's tape, translated

    into `-bit blocks of binary symbols separated by commas, as the computation proceeds.

    _ the state tape: a tape describing the current state of M, encoded as an `-bit block of binary

    symbols.

    _ the special tape: a tape containing the binary encodings of the special states fhalt,yes,nog

    and the \directional symbols" f ;!; g.

    5

  • 8/3/2019 23-1-11

    6/9

    The state tape solves the mystery of how a machine with a _nite number of states can

    simulate

    a machine with many more states: it encodes these states using a tape that has the capacity to

    hold an unbounded number of symbols.

    It would be too complicated to write down a diagram of the entire state transition function

    of a universal Turing machine, but we can describe it in plain English and pseudocode. Themachine begins with an initialization phase in which it performs the following tasks:

    _ copy the description of M onto the description tape,

    _ copy the input string x onto the working tape, inserting commas between each `-bit block;

    _ copy the starting state of M onto the state tape;

    _ write the identi_ers of the special states and directional symbols onto the special tape;

    _ move each cursor to the leftmost position on its respective tape.

    After this initialization, the universal Turing machine executes its main loop. Each iteration

    of the main loop corresponds to one step in the computation executed by M on input x. At

    the start of any iteration of U's main loop, the working tape and state tape contain the binary

    encodings of M's tape contents and its state at the start of the corresponding step in M's

    computation. Also, when U begins an iteration of its main loop, the cursor on each of its tapes

    except the working tape is at the leftmost position, and the cursor on the working tape is at the

    location corresponding to the position of M's cursor at the start of the corresponding step in its

    computation. (In other words, U's working tape cursor is pointing to the comma preceding the

    binary encoding of the symbol that M's cursor is pointing to.)

    The _rst step in an iteration of the main loop is to check whether it is time to halt. This is

    done by reading the contents of M's state tape and comparing it to the binary encoding of the

    states \halt", \yes", and \no", which are stored on the special tape. Assuming that M is not

    in one of the states \halt", \yes", \no", it is time to simulate one step in the execution of M.

    This is done by working through the segment of the description tape that contains the strings

    _1; _2; : : : ; _N describing M's transition function. The universal Turing machine moves through

    these strings in order from left to right. As it encounters each pair (q; _); it checks whether q is

    identical to the `-bit string on its state tape and _ is identical to the `-bit string on its working

    tape. These comparisons are performed one bit at a time, and if either of the comparisons fails,

    then U rewinds its state tape cursor back to the . and it rewinds its working tape cursor back to

    the comma that marked its location at the start of this iteration of the main loop. It then moves

    its description tape cursor forward to the description of the next rule in M's transition function.

    When it _nally encounters a pair (q; _) that matches its current state tape and working tape,

    then it moves forward to read the corresponding (p; _; d), and it copies p onto the state tape, _

    onto the working tape, and then moves its working tape cursor in the direction speci_ed by d.

    Finally, to end this iteration of the main loop, it rewinds the cursors on its description tape and

    6

  • 8/3/2019 23-1-11

    7/9

    state tape back to the leftmost position.

    It is worth mentioning that the use of _ve tapes in the universal Turing machine is overkill.

    In particular, there is no need to save the input .M; xt on a separate read-only input tape.

    As we have seen, the input tape is never used after the end of the initialization stage. Thus,

    for example, we can skip the initialization step of copying the description of M from the input

    tape to the description tape; instead, after the initialization _nishes, we can treat the input tapehenceforward as if it were the description tape.

    3. Varieties of Turing Machines

    We have presented here one of the most common formulations of Turing's basic idea. There

    are a number of variations to the formulation that turn out to be equivalent to this one, and

    different authors present Turing machines using any of these. Since they are all provably

    equivalent to one another we can consider any of the formulations as being the definition of

    Turing machine as we find convenient.

    Formulation F1 and formulation F2 are equivalent if for every machine described in formulation

    F1 there is machine a described in F2 which has the same input-output behavior, and vice versa,

    i.e., when started on the same tape at the same cell, will terminate with the same tape on the

    same cell.

    Two-way infinite tapes

    In our original formulation we specified that the tape had an end, at the left say, and stretched

    infinitely far to the right. Relaxing this stipulation to allow the tape to stretch infinitely far to

    right and left results in a new formulation of Turing machines. You might expect that the

    additional flexibility of having a two-way infinite tape would increase the number of functions

    that could be computed, but it does not. If there is a machine with a two-way infinite tape for

    computing some function, there there is machine with a one-way infinite tape that will compute

    that same function.

    Arbitrary numbers of read-write heads

    Modifying the definition of a Turing machine so that the machine has several read-write heads

    does not alter the notion of Turing-computability.

    Multiple tapes

    7

  • 8/3/2019 23-1-11

    8/9

    Instead of a single infinite tape, we could consider machines possessing many such tapes. The

    formulation of such a machine would have to allow the tuples to specify which tape is to be

    scanned, where the new symbol is to be written, and which tape head is to move. Again this

    formulation is equivalent to the original.

    Two-dimensional tapes

    Instead of a one-dimensional infinite tape, we could consider a two-dimensional tape, which

    stretches infinitely far up and down as well as left and right. We would add to the formulation

    that a machine transition can cause the read-write head to move up or down one cell in

    addition to being able to move left and right. Again this formulation is equivalent to the

    original.

    Arbitrary movement of the head

    Modifying the definition of a Turing machine so that the read-write head may move an arbitrary

    number of cells at any given transition does not alter the notion of Turing-computability.

    Arbitrary finite alphabet

    In our original formulation we allowed the use of only two symbols on the tape. In fact we do

    not increase the power of Turing machines by allowing the use of any finite alphabet of

    symbols.

    5-tuple formulation

    A common way to describe Turing machines is to allow the machine to both write and move its

    head in the same transition. This formulation requires the 4-tuples of the original formulation to

    be replaced by 5-tuples

    State0, Symbol, Statenew, Symbolnew, Move

    where Symbolnew is the symbol written, and Move is one of and .

    Again, this additional freedom does not result in a new definition of Turing-computable. For

    every one of the new machines there is one of the old machines with the same properties.

    Recursive & Primitive

    8

  • 8/3/2019 23-1-11

    9/9

    Computer language definition

    An example of a primitive recursive programming language is one that contains basic arithmetic operators

    (e.g. + and -, or ADD and SUBTRACT), conditionals and comparison (IF-THEN, EQUALS, LESS-THAN),

    and bounded loops, such as the basic for loop, where there is a known or calculable upper bound to all loops(FOR i FROM 1 to n), and no more general control structures such as while loops or IF-THEN plus GOTO.

    Douglas Hofstadter'sBloop in Gdel, Escher, Bach is one such. Adding unbounded loops (WHILE, GOTO)

    makes the language partially recursive, or Turing-complete; Floop is such, as are almost all real-worldcomputer languages.

    Arbitrary computer programs, or Turing machines, cannot in general be analyzed to see if they halt or not (the

    halting problem). However, all primitive recursive functions halt. This is not a contradiction; primitive

    recursive programs are a non-arbitrary subset of all possible programs, constructed specifically to beanalyzable.

    In the following we observe that primitive recursive functions can be of four types:

    1. functions for short: "number-theoretic functions" from { 0, 1, 2, ...} to { 0, 1, 2, ...},

    2. predicates: from { 0, 1, 2, ...} to truth values { t =true, f =false },3. propositional connectives: from truth values { t, f } to truth values { t, f },4. representing functions: from truth values { t, f } to { 0, 1, 2, ... }. Many times a predicate requires a

    representing function to convert the predicate's output { t, f } to { 0, 1 } (note the order "t" to "0" and

    "f" to "1" matches with ~(sig( )) defined below). By definition a function (x) is a "representingfunction" of the predicate P(x) if takes only values 0 and 1 and produces 0 when P is true".

    In the following the mark " ' ", e.g. a', is the primitive mark meaning "the successor of", usually thought of as

    " +1", e.g. a +1 =defa'. The functions 16-21 and #G are of particular interest with respect to converting

    primitive recursive predicates to, and extracting them from, their "arithmetical" form expressed as Gdelnumbers.

    9

    http://en.wikipedia.org/wiki/For_loophttp://en.wikipedia.org/wiki/For_loophttp://en.wikipedia.org/wiki/While_loophttp://en.wikipedia.org/wiki/GOTOhttp://en.wikipedia.org/wiki/Douglas_Hofstadterhttp://en.wikipedia.org/wiki/BlooP_and_FlooPhttp://en.wikipedia.org/wiki/BlooP_and_FlooPhttp://en.wikipedia.org/wiki/G%C3%B6del,_Escher,_Bachhttp://en.wikipedia.org/wiki/Halting_problemhttp://en.wikipedia.org/wiki/G%C3%B6del_numberhttp://en.wikipedia.org/wiki/G%C3%B6del_numberhttp://en.wikipedia.org/wiki/For_loophttp://en.wikipedia.org/wiki/While_loophttp://en.wikipedia.org/wiki/GOTOhttp://en.wikipedia.org/wiki/Douglas_Hofstadterhttp://en.wikipedia.org/wiki/BlooP_and_FlooPhttp://en.wikipedia.org/wiki/G%C3%B6del,_Escher,_Bachhttp://en.wikipedia.org/wiki/Halting_problemhttp://en.wikipedia.org/wiki/G%C3%B6del_numberhttp://en.wikipedia.org/wiki/G%C3%B6del_number