0% found this document useful (0 votes)
65 views106 pages

Chapter 5 and 6 Turing Machines

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views106 pages

Chapter 5 and 6 Turing Machines

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 106

Chapter 5 and 6

Turing Machines and


Computability

1
Turing Machine
• A Turing machine is an automaton whose temporary
storage is a tape.
• It can be visualized as a single, one-dimensional array of
cells, each of which can hold a single symbol.
• This array extends indefinitely in both directions and is
therefore capable of holding an unlimited amount of
information.
• The information can be read and changed in any order.
• We will call such a storage device a tape because it is
analogous to the magnetic tapes used in older
computers.
• the tape is a read-write head that can travel right or left
on the tape and that can read and write a single symbol
on each move. 2
Turing Machine

 It is possible to design a formal model of a


computational device that capture the capabilities of
any algorithm. Alan Turing, 1940’s

TM:
• More powerful
• Essentially a finite automaton but with
unlimited memory
• Although theoretical, can do everything a
general purpose computer of today can do
•If a TM can’t solve it, neither can a computer
3
Turing Machines

• TM’s described
• Well before the days of modern computers but remains a
popular model for what is possible to compute on
today’s systems
• Advances in computing still fall under the TM model, so
even if they may run faster, they are still subject to the
same limitations
• A TM consists of a finite control (i.e. a finite state
automaton) that is connected to an infinite tape.

4
• Turing Machine use a “tape”, which is actually infinite in
both the directions.
• The tape consists of a series of “squares”, each of which can
hold a single symbol.
• The “tape-head”, or “read-write head”, can read a symbol
from the tape, write a symbol to the tape and move one
square in either direction.
Every computer algorithm can be implemented as a Turing
machine
• There are two kinds of Turing Machine available.
(a)Deterministic Turing Machine.
(b)Non-deterministic Turing Machine.

5
Actions of a Turing Machine

depending on current state


and
Change
current tape symbol
state

Write a new symbol


onto the current tape square

Move left/right one square

6
A Turing Machine
Tape
...... ......

Read-Write head
Control Unit

7
The Tape
No boundaries -- infinite length

...... ......

Read-Write head The head moves Left or Right

The head at each transition (time step):


1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
8
Example:
Time 0
...... a b a c ......

Time 1
...... a b k c ......

1. Reads a
2. Writes k
3. Moves Left
9
Turing Machine Defn:

Input Tape
alphabet alphabet
States

M  (Q, , ,  , q0 , , F )

Transition Accept
function states
Initial blank
state 10
Turing Machine Formal Description
7-tuple: (Q, , Γ, δ, q0, qaccept, qreject)
Q: finite set of states
: input alphabet (cannot include blank symbol, _)
Γ: tape alphabet, includes  and _
δ: transition function: Q  Γ  Q  Γ  {L, R}
q0: start state, q0  Q
qaccept: accepting state, qaccept  Q
qreject: rejecting state, qreject  Q

11
The Input String

Input string Blank symbol

......   a b a c    ......

head

Head starts at the leftmost position


of the input string
12
States and Transition Function

q1 a  b, R q2

 (q1, a)  (q2 , b, R)

13
States and Transition Function

q1 c  d, L q2

 (q1, c)  (q2 , d , L)

14
States and Transition Function

Read Write
Move Left

q1 a  b, L q2

Move Right

q1 a  b, R q2
15
Example:
Time 1
......   a b a c    ......

q1
current state

q1 a  b, R q2
16
Time 1
......   a b a c    ......

q1

Time 2
......   a b b c    ......

q2

q1 a  b, R q2
17
Example:
Time 1
......   a b a c    ......

q1

Time 2
......   a b b c g   ......

q2

q1   g, R q2
18
standard Turing machine
Since one can make several different definitions of a Turing
machine,
it is worthwhile to summarize the main features of our model,
which we will call a standard Turing machine:

1. The Turing machine has a tape that is unbounded in both


directions, allowing any number of left and right moves.
2. The Turing machine is deterministic in the sense that δ defines
at most one move for each configuration.
3. There is no special input file. We assume that at the initial time
the tape has some specified content. Some of this may be
considered input. Similarly, there is no special output device.
Whenever the machine halts, some or all of the contents of the
tape may be viewed as output.
19
Determinism
Turing Machines are deterministic
Allowed Not Allowed
a  b, R q2 a  b, R q2

q1 q1
q3 a  d, L q3
b  d, L

No lambda transitions allowed


20
21
22
Outcome of Nondeterministic computation

• Accept
• If any branch of the computation accepts, then the
nondeterministic TM will accept
• Reject
• If all branches of the computation Halts and
Rejects(i.e., no branches accept, but all computation
halts), then the nondeterministic TM rejects.
• Loop
• Computation continues, but “accept” is never
encountered.
• Some branches in the computation history are
infinite. 23
Halting
• One way for a TM to accept input is to end in a final state.
• Another way is acceptance by halting.
• We say that a TM halts if it enters a state q, scanning a tape symbol X, and
there is no move in this situation; i.e. δ(q,X) is undefined.
• When a string is given as input, the TM always halts:
• The TM will accept if it is in L. The TM will Reject if it is not in L.
• Note that this definition of halting was not used in the transition diagram
for the TM we described earlier; instead that TM died on unspecified
input!
• It is possible to modify the prior example so that there is no unspecified
input except for our accepting state. An equivalent TM that halts exists
for a TM that accepts input via final state.
• In general, 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 if it does not
accept the input. Turing machines that always halt, regardless of
accepting or not accepting, are good models of algorithms for decidable
problems. Such languages are called recursive.

24
Halting Example 1:

......   a b a c    ......

q1

q1 No transition from q1
HALT!!!

25
Halting Example 2:

......   a b a c    ......

q1

a  b, R q2
No possible transition
q1 from q1 and symbol c
b  d, L q3 HALT!!!
26
Accepting States

q1 q2 Allowed

q1 q2 Not Allowed

•Accepting states have no outgoing transitions


•The machine halts and accepts
27
Acceptance
If machine halts
Accept Input in an accept state
string
If machine halts
Reject Input in a non-accept state
string or
If machine enters
an infinite loop
In order to accept an input string, it is not
necessary to scan all the symbols in the
string 28
Turing Machine Example

Input alphabet   {a , b }

Accepts the language: a*


a  a, R

  , L
q0 q1

29
Time 0   a a a  

q0

a  a, R

  , L
q0 q1

30
Time 1   a a a  

q0

a  a, R

  , L
q0 q1

31
Time 2   a a a  

q0

a  a, R

  , L
q0 q1

32
Time 3   a a a  

q0

a  a, R

  , L
q0 q1

33
Time 4   a a a  

q1

a  a, R Halt & Accept

  , L
q0 q1

34
Rejection Example

Time 0   a b a  

q0

a  a, R

  , L
q0 q1
35
Time 1   a b a  

q0
No possible Transition
a  a, R Halt & Reject

  , L
q0 q1
36
A simpler machine for same language
but for input alphabet   {a }

Accepts the language: a*

q0

37
Time 0   a a a  

q0

Halt & Accept

q0

Not necessary to scan input


38
Infinite Loop Example
A Turing machine
for language a * b ( a  b ) *
b  b, L
a  a, R

  , L
q0 q1

39
Time 0   a b a  

q0

b  b, L
a  a, R

  , L
q0 q1

40
Time 1   a b a  

q0

b  b, L
a  a, R

  , L
q0 q1

41
Time 2   a b a  

q0

b  b, L
a  a, R

  , L
q0 q1

42
Time 2   a b a  
q0
Time 3   a b a  

Infinite loop
q0
Time 4   a b a  
q0

Time 5   a b a  
q0 43
Because of the infinite loop:

•The accepting state cannot be reached

•The machine never halts

•The input string is rejected

44
45
46
Cont..

47
Another Turing Machine Example
n n
{a b }
Turing machine for the language n 1

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 48
Basic Idea:
Match a’s with b’s:
Repeat:
replace leftmost a with x
find leftmost b and replace it with y
Until there are no more a’s or b’s

If there is a remaining a or b reject

49
Time 0  a a b b  

q0

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 50
Time 1  x a b b  

q1

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 51
Time 2  x a b b  

q1

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 52
Time 3  x a y b  

q2

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 53
Time 4  x a y b  

q2

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 54
Time 5  x a y b  

q0

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 55
Time 6  x x y b  

q1

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 56
Time 7  x x y b  

q1

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 57
Time 8  x x y y  

q2

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 58
Time 9  x x y y  

q2

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 59
Time 10  x x y y  

q0

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 60
Time 11  x x y y  

q3

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 61
Time 12  x x y y  

q3

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 62
Time 13  x x y y  

q4
Halt & Accept

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R 63
Observation:

If we modify the
machine for the language n n
{a b }

we can easily construct


n n n
a machine for the language {a b c }

64
Instantaneous description (ID):

Configuration
  c a b a  

q1
An ID of a Turing machine M is a string aqy, where
• q1 is the present state of M,
• the entire input string is split as ay,
• the first symbol of y is the current symbol b under the R/W head
and
• y has all the subsequent symbols of the input string, and
• the string a is the substring of the input string formed by all the
symbols to the left of a.
Representation of ID ca q ba1
65
An “Instantaneous Description” or “Configuration” of a Turing
machine requires.
(a) the state the Turing machine is in
(b) the contents of the tape
(c) the position of the tape head on the tape.

This is written as a string of the form xi...xj qmxk… xl


where the x’s are the symbols on the tape, qm is the current state, and
the tape head is on the square containing xk (the symbol immediately
following qm).
The “Move” of a Turing machine can therefore be expressed as a pair
of instantaneous descriptions, separated by a symbol “|–”.
For example, if α(q5 , b)= (q8 , c, R)
then a possible move can be
abbabq5babb |– abbabcq8abb

66
Time 4 Time 5
 x a y b    x a y b  

q2 q0

A Move: q2 xayb  x q0 ayb


(yields in one mode)

67
Time 4 Time 5
 x a y b    x a y b  

q2 q0

Time 6 Time 7
 x x y b    x x y b  

q1 q1
A computation
q2 xayb  x q0 ayb  xx q1 yb  xxy q1 b
68
q2 xayb  x q0 ayb  xx q1 yb  xxy q1 b


Equivalent notation: q2 xayb  xxy q1 b

69
Initial configuration: q0 w

Input string

 a a b b  

q0

70
The Accepted Language
For any Turing Machine M


L( M )  {w : q0 w  x1 q f x2 }

Initial state Accept state

71
If a language L is accepted
by a Turing machine M
then we say that L is:

•Turing Recognizable

Other names used:


•Turing Acceptable
•Recursively Enumerable
72
Multitape Turing Machines
•A multitape Turing machine is like an ordinary TM
but it has several tapes instead of one tape.
•Initially the input starts on tape 1 and the other
tapes are blank.
•The transition function is changed to allow for
reading, writing, and moving the heads on all the
tapes simultaneously.
•This means we could read on multiples tape and move
in different directions on each tape as well as write a
different symbol on each tape, all in one move.

73
Multitape Turing Machine
Theorem: A multitape TM is equivalent in power to an
ordinary TM.
Recall that two TM’s are equivalent if they recognize the
same language. We can show how to convert a multitape
TM, M, to a single tape TM, S:
• Say that M has k tapes.
• Create the TM S to simulate having k tapes by interleaving the
information on each of the k tapes on its single tape
• Use a new symbol # as a delimiter to separate the contents of
each tape
• S must also keep track of the location on each of the simulated
heads
• Write a type symbol with a * to mark the place where the head on
the tape would be
• The * symbols are new tape symbols that don’t exist with M
• The finite control must have the proper logic to distinguish say, x* and x and
realize both refer to the same thing, but one is the current tape symbol.
74
Multitape Machine

… 0 1 0 1 0 B …

… a a a B …
M

… b a B …

Equivalent Single Tape Machine:

75
Single Tape Equivalent
•One final detail
•If at any point S moves one of the virtual
tape heads onto a #, then this action
signifies that M has moved the
corresponding head onto the previously
unread blank portion of that tape.
•To accommodate this situation, S writes a
blank symbol on this tape cell and shifts
the tape contents to the rightmost # by
one, adds a new #, and then continues
back where it left off
76
Nondeterministic TM
•Replace the “DFA” part of the TM with an
“NFA”
• Each time we make a nondeterministic move, you
can think of this as a branch or “fork” to two
simultaneously running machines. Each machine
gets a copy of the entire tape. If any one of these
machines ends up in an accepting state, then the
input is accepted.
•Although powerful, nondeterminism does
not affect the power of the TM model
•Theorem: Every nondeterministic TM has an
equivalent deterministic TM.
77
Equivalence of TM’s and Computers
•In one sense, a real computer has a finite amount
of memory, and thus is weaker than a TM.
•But, we can postulate an infinite supply of tapes,
disks, or some peripheral storage device to simulate
an infinite TM tape.
•Additionally, we can assume there is a human
operator to mount disks, keep them stacked neatly
on the sides of the computer, etc.
•Need to show both directions,
•a TM can simulate a computer and that
•a computer can simulate a TM

78
Computer Simulate a TM
•This direction is fairly easy –
• Given a computer with a modern programming
language, certainly,
• we can write a computer program that emulates
the finite control of the TM.
•The only issue remains the infinite tape.
•Our program must map cells in the tape to
storage locations in a disk.
•When the disk becomes full, we must be able
to map to a different disk in the stack of disks
mounted by the human operator.
79
TM Simulate a Computer
• The simulation is performed at the level of stored
instructions and accessing words of main memory.
• TM has one tape that holds all the used memory locations and
their contents.
• Other TM tapes hold the instruction counter, memory address,
computer input file, and scratch data.
• The computer’s instruction cycle is simulated by:
1. Find the word indicated by the instruction counter on the
memory tape.
2. Examine the instruction code (a finite set of options), and get
the contents of any memory words mentioned in the
instruction, using the scratch tape.
3. Perform the instruction, changing any words' values as
needed, and adding new address-value pairs to the memory
tape, if needed.

80
TM/Computer Equivalence
•Anything a computer can do, a TM can do, and vice versa
•TM is much slower than the computer, though
•But the difference in speed is polynomial
•Each step done on the computer can be completed in
O(n2) steps on the TM.
•While slow, this is key information if we wish to make an
analogy to modern computers.
•Anything that we can prove using Turing machines
translates to modern computers with a polynomial time
transformation.
•Whenever we talk about defining algorithms to solve
problems, we can equivalently talk about how to
construct a TM to solve the problem.
• If a TM cannot be built to solve a particular problem, then it
means our modern computer cannot solve the problem
either. 81
Turing Languages
•We use the simplicity of the TM model to prove
formally that there are specific problems (i.e.
languages) that the TM cannot solve. Three classes
of languages:
• Turing-decidable or recursive: TM can accept the strings
in the language and tell if a string is not in the language.
Sometimes these are called decidable problems.
• Turing-recognizable or recursively enumerable : TM can
accept the strings in the language but cannot tell for
certain that a string is not in the language. Sometimes
these are called partially-decidable.
• Undecidable : no TM can even recognize ALL members of
the language.

82
Church-Turing Thesis
• As stated by Kleene:
Every effectively calculable function (effectively decidable
predicate) is general recursive.

“Since a precise mathematical definition


of the term effectively calculable
(effectively decidable) has been wanting,
we can take this thesis ... as a definition
of it...”

Yes, this is circular: everything calculable can be


computed by a TM, and we define what is calculable as
what can be computed by a TM.
83
In the year 1950, mathematician and computing
pioneer Alan Turing introduced a test to determine
whether a machine can think like a human or not,
which means it can demonstrate intelligence, known
as the Turing Test.
It was based on the "Imitation game" with some
modifications.
This technique is still a measure of various
successful AI projects, with some updates.

84
Church-Turing Thesis
• Any mechanical computation can be performed by a
Turing Machine
• There is a TM-n corresponding to every computable
problem
• We can model any mechanical computer with a TM
• The set of languages that can be decided by a TM is
identical to the set of languages that can be decided by
any mechanical computing machine
• If there is no TM that decides problem P, there is no
algorithm that solves problem P.

All of these statements are implied by the Church-Turing thesis


85
86
87
In decidable the TM halts, but in
REL(TR) it may or may not halt

88
Computability

89
INTRODUCTION

• A computable function:
A function f : that can be computed by a
Turing Machine
• The input X is on the tape.
• The TM runs and always halts
• The result f(x) is left on the tape.

90
INTRODUCTION
• A partial function f from X to Y is a rule which assigns to every element
of X at most one element of Y.
• A total function from X to Y is a rule which assigns to every element of X
a unique element of Y.

91
PRIMITIVE RECURSIVE FUNCTIONS\ INITIAL FUNCTIONS
• Given the Initial Functions Over N
• Zero function Z defined by Z(x) = 0,
• Successor function S defined by S(x) = x + 1
• Projection function 𝑈𝑖𝑛 defined by 𝑈𝑖𝑛 (x1, x2,…, xn) = xi
• In particular
. Z(7) = 0, S(7) = 8

𝑈13 (2, 4, 7) = 2, 𝑈23 (2, 4, 7)=4 𝑈34 (1,2,3,4)=3

92
93
• Definition: If f1, f2, ..., fk are partial functions of n variables and g is a partial
function of k variables, then the composition of g with f1, f2, .. .fk is a partial
function of n variables defined by g(f1(X1, X2 .. , xn), f2(x1, X2, ..., Xn), ... , fk(X1,
X2, ..., Xn))
• If, for example, f1, f2 and f3, are partial functions of two variables and g is a
partial function of three variables, then the composition of g with f1, f2, f3, is
given by g(f1(X1, X2), f2(x1, X2), f3(X1, X2)).

94
RECURSIVE FUNCTION THEORY
• It is seen that a sufficiently powerful formal system cannot be both:
• consistent(not be possible to both prove and disprove a proposition in the
system.) and
• Complete (be possible either to prove or disprove any proposition that can be
expressed in the system.).
• Simple arithmetic on integers is an example of a system that is “sufficiently
powerful”. It is always preferred to give up completeness rather than
consistency, because in a consistent system any proposition can be proven.
• Ideally, we wanted to have an algorithmic theorem proving procedure to
distinguish between
• the provable propositions and
• unprovable ones.
• Alan Turing invented Turing machines in an attempt to solve this problem.
With the halting problem,
• Alan Turing had shown that it is not possible to distinguish between solvable
and insolvable problems.

95
PRIMITIVE RECURSIVE FUNCTIONS

• This section describes the basic ideas behind recursive function


theory.
• The Recursive functions are described over the natural numbers I =
{0, 1, 2, 3, ......}. Recursive functions are looked at as “Pure Symbol
Systems”.
• Numbers are not used in the system, rather,
• we use the system to construct both numbers and arithmetical functions on
numbers.
• It’s a different numbering system, in the same way as Roman
numerals are different.
• partial functions: functions that are not defined for every input
argument.

96
cont.…
• The correspondence is as given below.

• These projector functions are a way of extracting one of the parameters


and discarding the rest. We define only P1 and P2 as only functions of no
more than two arguments are only discussed.
97
98
Definition : A function is called primitive recursive if and only if it can be constructed
from the basic function Z, S and P by successive composition and primitive recursion.

99
Example 3: Find out the values of
(a) Z(80)
(b) P24 (2,3, 7,6)
(c) P34 (2,3,6, 7)
(d) S (78)
With Z as the zero function, S as the successor function and P as the
projection function.
Solution

100
Eg. Addition of integers x and y can be implemented with
the function add(x,y), defined by

101
we can define multiplication by

102
Recursively Enumerable Languages
• Recursively enumerable languages are the ones that can be
accepted by Turing machines.
• Only if a language is recursive is there an algorithm guaranteed to
determine whether an arbitrary string is an element.
• As a result, there must be some languages that are not recursively
enumerable and others that are recursively enumerable but not
recursive.

103
RECURSIVELY ENUMERABLE AND RECURSIVE
• Recursively enumerable languages are sometimes referred to as Turing
acceptable, and
• recursive languages are sometimes called Turing-decidable, or simply
decidable.
• A language L is recursively enumerable if there is a TM that accepts L, and L is
recursive if there is a TM that decides L.
• Every recursive language is recursively enumerable.
• If L and L are both recursively enumerable languages over , then L ∪ L and L ∩
1 2 1 2 1

L are also recursively enumerable.


2

• If L and L are both recursive languages over , then L ∪ L and L ∩ L are


1 2 1 2 1 2

also recursive.
• If L is a recursively (enumerable) language, and its complement L is
also recursively enumerable, then L is recursive

104
ENUMERATING A LANGUAGE
• To enumerate a set means to list the elements, and we
begin by saying precisely how a Turing machine
enumerates a language L (or, informally, lists the
elements of L).

• The easiest way to formulate the definition is to use a


multi tape TM with one tape that operates exclusively as
the output tape.

105
Defn: A TM Enumerating a language

106

You might also like