Proofs, Recursion and Analysis of Algorithms

Download Report

Transcript Proofs, Recursion and Analysis of Algorithms

Modeling Arithmetic, Computation, and
Languages
Mathematical Structures
for Computer Science
Chapter 8
Copyright © 2006 W.H. Freeman & Co.
MSCS Slides
Turing Machines
Turing Machines

A Turing machine is essentially a finite-state machine with the
added ability to reread its input and also to erase and write over
its input with unlimited auxiliary memory.



Section 8.3
Unlimited auxiliary memory makes the Turing machine a
hypothetical “machine”  a model  and not a real device.
A Turing machine consists of a finite-state machine and an
unlimited tape divided into cells, each cell containing at most
one symbol from an allowable finite alphabet.
At any one instant, only a finite number of cells on the tape are
nonblank. The special symbol b is used to denote a blank cell.
The finite-state unit, through its readwrite head, reads one cell
of the tape at any given moment as shown in the figure below:
Turing Machines
1
Turing Machine

Depending on the present state of the unit and the symbol read,
the unit either does nothing (halts) or completes three actions:




Section 8.3
Print a symbol from the alphabet on the cell read (it might be the
same symbol that’s already there)
Go to the next state (it might be the same state as before)
Move the readwrite head one cell left or right
The actions of any particular Turing machine can be described
by a set of quintuples of the form (s, i, i, s, d), where s and i
indicate the present state and the tape symbol being read, i
denotes the symbol printed, s denotes the new state, and d
denotes the direction in which the readwrite head moves (R for
right, L for left).
Turing Machines
2
Example: Turning Machine


Section 8.3
Thus, a machine in the configuration illustrated by
Figure (a), if acting according to the instructions
contained in the quintuple (2, 1, 0, 1, R), would move
to the configuration illustrated in Figure (b).
The symbol 1 being read on the tape has been changed
to a 0, the state of the unit has been changed from 2 to
1, and the head has moved one cell to the right.
Turing Machines
3
Formal Definition: Turing machine



Section 8.3
DEFINITION: TURING MACHINE Let S be a
finite set of states and I a finite set of tape symbols (the
tape alphabet) including a special symbol b. A Turing
machine is a set of quintuples of the form (s, i, i, s, d)
where s, s  S; i, i  I; and d  {R, L} and no two
quintuples begin with the same s and i symbols.
The restriction that no two quintuples begin with the
same s and i symbols ensures that the action of the
Turing machine is deterministic and completely
specified by its present state and symbol read.
A Turing machine halts if it gets into a configuration
for which its present state and symbol read are not the
first two symbols of any quintuple.
Turing Machines
4
Turing Machine (TM) Example


Section 8.3
A Turing machine is defined by the set of quintuples (0, 0, 1, 0,
R), (0, 1, 0, 0, R), (0, b, 1, 1, L), (1, 0, 0, 1, R), (1, 1, 0, 1, R)
The action of this Turing machine when processing a particular
initial tape is shown by the sequence of configurations in figure
above, which also shows the quintuple that applies at each step.
Turing Machines
5
TMs as Set Recognizers



A final state in a Turing machine is one that is not the first
symbol in any quintuple. Thus, on entering a final state,
whatever the symbol read, the Turing machine halts.
DEFINITION: TURING MACHINE RECOGNITION
(ACCEPTANCE) A Turing machine T with tape alphabet I
recognizes (accepts) a subset S of I* if T, beginning in standard
initial configuration on a tape containing a string of tape
symbols, halts in a final state if and only if   S.
The definition of acceptance leaves open two possible behaviors
for T when applied to a string  of tape symbols not in S.



Section 8.3
T may halt in a non final state, or
T may fail to halt at all.
One can now build a Turing machine to recognize the set S =
{0n1n  n  0}. The machine is based on the second approach to
this recognition problem, sweeping back and forth across the
input and crossing out 01 pairs.
Turing Machines
6
TMs as Function Computer




Section 8.3
Given a particular Turing machine T and a string of  tape
symbols, we begin T in standard initial configuration on a tape
containing  .
If T eventually halts with a string  on the tape, we may
consider  as the value of a function evaluated at  . Using
function notation, T() = .
The domain of the function T consists of all strings for which T
eventually halts. We can also think of T as computing numbertheoretic functions, functions from a subset of Nk into N for
any k  1.
There is thus an infinite sequence T 1, T 2 ,... , T k ,... of numbertheoretic functions computed by T associated with each Turing
machine T. For each k, the function Tk is a partial function on k,
meaning that its domain may be a proper subset of Nk. A special
case of a partial function on Nk is a total function on Nk,
where the function is defined for all k-tuples of nonnegative
integers.
Turing Machines
7
TMs as Function Computers


Section 8.3
DEFINITION: TURING-COMPUTABLE
FUNCTION A Turing-computable function is a
number-theoretic function computed by some Turing
machine.
A Turing-computable function f can in fact be
computed by an infinite number of Turing machines.
Once a machine T is found to compute f, we can
always include extraneous quintuples in T, producing
other machines that also compute f.
Turing Machines
8
Church-Turing Thesis




Section 8.3
CHURCH-TURING THESIS A number-theoretic function is
computable by an algorithm if and only if it is Turing
computable.
The Church-Turing thesis equates an intuitive idea with a
mathematical idea, it can never be formally proved and must
remain a thesis, not a theorem.
The Church-Turing thesis is now widely accepted as a working
tool by researchers dealing with computational procedures.
If, in a research paper, a method is set forth for computing a
function and the method intuitively seems to be an algorithm,
then the Church-Turing thesis is invoked and the function is
declared to be Turing-computable (or one of the names
associated with one of the equivalent formulations of Turing
computability).
Turing Machines
9
Church-Turing Thesis


The Church-Turing thesis is stated in terms of number-theoretic functions,
but it can be interpreted more broadly.
Any algorithm in which a finite set of symbols is manipulated can be
translated into a number-theoretic function by a suitable encoding of the
symbols as nonnegative integers, much as input to a real computer is
encoded and stored in binary form.


Hence, using the Church-Turing thesis, one can say that if there is an
algorithm to do a symbol manipulation task, there is a Turing machine to do it.
By accepting the Church-Turing thesis, we have accepted the Turing
machine as the ultimate model of a computational procedure. Turing
machine capabilities exceed those of any actual computer, which, after all,
does not have the unlimited tape storage of a Turing machine
Section 8.3
Turing Machines
10
Decision Problems and Uncomputability


DEFINITION: DECISION PROBLEM A decision problem
asks if an algorithm exists to decide whether individual
statements from some large class of statements are true.
The solution to a decision problem answers the question of
whether an algorithm exists.


A positive solution consists of proving that an algorithm exists,
and it is generally given by actually producing an algorithm that
works.
A negative solution consists of proving that no algorithm exists.
• It must be shown that it is impossible for anyone ever to come up with
an algorithm.
• When a negative solution to a decision problem is found, the problem
is said to be unsolvable, uncomputable, or undecidable.

Section 8.3
This terminology can be confusing because the decision
problem itself  the question of whether an algorithm exists to
do a task  has been solved; what must forever be unsolvable is
the task itself.
Turing Machines
11
Halting Problem



DEFINITION: HALTING PROBLEM The halting
problem asks: Does an algorithm exist to decide,
given any Turing machine T and string , whether T
begun on a tape containing  will eventually halt?
THEOREM ON THE HALTING PROBLEM The
halting problem is unsolvable.
The proof of the unsolvability of the halting problem
depends on two ideas:


Section 8.3
Encoding a Turing machine into a string description
Having a machine look at and act on its own
description
Turing Machines
12
Computational Complexity


DEFINITION: P
P is the collection of all sets recognizable by Turing machines in
polynomial time.
Instead of determining the complexity of the Turing machine
algorithm (i.e., (n) or (n2)), simply note whether it is a
polynomial-time algorithm.




Section 8.3
Only quite trivial algorithms can be better than polynomial time
because it takes a Turing machine n steps just to examine its tape.
Problems for which no polynomial-time algorithms exist are
called intractable. Such problems may be solvable, but only by
inefficient algorithms.
Ordinary Turing machines act deterministically, due to our
restriction that no two quintuples begin with the same present
state/present symbol pair. A relaxation of this requirement
results in a nondeterministic Turing machine, which may have a
choice of actions at any step.
A nondeterministic Turing machine recognizes a string on its
tape if some sequence of actions leads to halting in a final state.
Turing Machines
13
NP



DEFINITION: NP
NP is the collection of all sets recognizable by nondeterministic
Turing machines in polynomial time. (NP comes from
nondeterministic polynomial time.)
While a set in P requires that a deterministic Turing machine be
able to make a decision (in polynomial time) about whether
some string on its tape does or does not belong to the set, a set in
NP requires only that a nondeterministic Turing machine be able
to verify (in polynomial time) by a fortuitous choice of actions
that an input string is in the set.
NP-complete problems: Those that not only are they in NP, but
if a polynomial-time decision algorithm were ever found for any
one of them, that is, if any of them were ever found to be in P,
then indeed we would have P = NP.

Section 8.3
The Hamiltonian circuit problem belongs to this class of problems.
Turing Machines
14