Download - Unit 10fi
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 339
Unit 10 Models for Executing
Algorithms III: TM
Structure
10.1 Introduction
Objectives
10.2 Prelude to Formal Definition
10.3 Turing Machine: Formal Definition and Examples
10.4 Instantaneous Description and Transition Diagrams
10.5 Some Formal Definitions
10.6 Observations
10.7 Turing Machine as a Computer of Functions
10.8 Summary
10.9 Terminal Questions
10.10 Answers
10.1 Introduction
In the previous units we discussed two of the major approaches to modeling
of computation viz. the automata / machine approach and linguistic /
grammatical approach. Under grammatical approach, we discussed two
models viz., Regular Languages and Context-free Languages.
Under automata approach, we discussed two models viz., Finite Automata
and Pushdown Automata. Next, we discuss still more powerful automata for
computation.
Turing machine TM is the next more powerful model of automata approach
which recognizes more languages than Pushdown automata models do.
Also Phrase-structure model is the corresponding grammatical model that
matches Turing machines in computational power.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 340
Notations: Turing Machine (TM), Deterministic Turing Machine, Non-
Deterministic Turing Machine, Turing Thesis, Computation, Computational
Equivalence, Configuration of TM, Turing-Acceptable Language, Turing
Decidable Language, Recursively Enumerable Language, Turing
Computable Function.
TM : Turing Machine
: Set of tape symbols, includes , the blank symbol
: Set of input/machine symbols, does not include #
Q : the finite set of states of TM
F : Set of final states
a, b, c.. : Members of
: Variable for members of
x or x : Any symbol of other than x
# : The blank symbol
, , : Variables for String over
L : Move the Head to the Left
R : Move the Head to the Right
q : A state of TM, i.e., q Q
s or q0 : The start / initial state
Halt or h : The halt state. The same symbol h is used for the purpose of
denoting halt state for all halt state versions of TM. And then h
is not used for other purposes.
e or : The empty string
C1 M C2 : Configuration C2 is obtained from configuration C1 in one move
of the machine M
C1 *C2 : Configuration C2 is obtained from configuration C1 in finite
number of moves.
w1 a w2 : The symbol a is the symbol currently being scanned by the head
Or
w1
a w2 : The symbol a is the symbol currently being scanned by the head.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 341
Objectives
At the end of this unit the student should be able to:
Construct TMs for simple computational tasks;
Realize some simple mathematical functions as TMs; and
Apply modular techniques for the construction of TMs for more complex
functions and computational tasks from TMs already constructed for
simple functions and tasks.
10.2 Prelude to Formal Definition
In the next section, we will notice through a formal definition of TM that a TM
is an abstract entity constituted of mathematical objects like sets and a
(partial) function. However, in order to help our understanding of the subject-
matter of TMs, we can visualize a TM as a physical computing device that
can be represented as a figure.
Infinite Tape
d a b # c b . . . .
Read / Write Head
Finite Control
Figure 10.2.1: Turing Machine
Such a view, in addition to being more comprehensible to human beings,
can be a quite useful aid in the design of TMs accomplishing some
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 342
computable tasks, by allowing informal explanation of the various steps
involved in arriving at a particular design. Without physical view and informal
explanations, whole design process would be just a sequence of derivations
of new formal symbolic expressions from earlier known or derived symbolic
expressions not natural for human understanding.
According to this view of TM, it consists of
(i) a tape, with an end on the left but infinite on the right side. The tape is
divided into squares or cells, with each cell capable of holding one of
the tape symbols including the blank symbol #. At any time, there can
be only finitely many cells of the tape that can contain non-blank
symbols. The set of tape symbols is denoted by .
As the very first step in the sequence of operations of a TM, the input,
as a finite sequence of the input symbols is placed in the left-most
cells of the tape. The set of input symbols denoted by , does not
contain the blank symbol #. However, during operations of a TM, a cell
may contain a tape symbol which is not necessarily an input symbol.
There are versions of TM, to be discussed later, in which the tape may be
infinite in both left and right sides having neither left end nor right end.
(ii) a finite control, which can be in any one of the finite number of states.
The states in TM can be divided in three categories viz.,
(a) the Initial state, the state of the control just at the time when TM
starts its operations. The initial state of a TM is generally denoted
by q0 or s. the Halt state, which is the state in which TM stops all
further operations.
(b) The halt state is generally denoted by h. The halt state is distinct
from the initial state. Thus, a TM HAS AT LEAST TWO STATES.
(c) Other states
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 343
(iii) a tape head (or simply Head), is always stationed at one of the tape
cells and provides communication for interaction between the tape and
the finite control. The head can read or scan the symbol in the cell
under it. The symbol is communicated to the finite control. The control
taking into consideration the symbol and its current state decides for
further course of action including
the change of the symbol in the cell being scanned and / or
change of its state and / or
moving the head to the Left or to the Right. The control may decide
not to move the head.
The course of action is called a move of the Turing Machine. In other words,
the move is a function of current state of the control and the tape symbol
being scanned.
In case the control decides for change of the symbol in the cell being
scanned, then the change is carried out by the head. This change of symbol
in the cell being scanned is called writing of the cell by the head.
Initially, the head scans the left-most cell of the tape.
10.3 Turing Machine: Formal Definition and Examples
There are a number of versions of a TM. We consider below Halt State
version of formal definition a TM.
Definition: Turing Machine (Halt State Version)
A Turing Machine is a sixtuple of the form (Q, , , , q0, h), where
(i) Q is the finite set of states,
(ii) is the finite set of non-blank information symbols,
(iii) is the set of tape symbols, including the blank symbol #
(iv) is the next-move partial function from Q x to Q x x {L, R, N},
where L denoted the tape Head moves to the left adjacent cell, R
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 344
denotes tape Head moves to the Right adjacent cell and N denotes
Head does not move, i.e., continues scanning the same cell.
In other words, for qi Q and ak , there exists (not necessarily
always, because is a partial function) some q j Q and some a1
such that (qi ak) = (q j, a1, x), where x may assume any one of the
values L, R and N.
The meaning of (qi ak) = (q j, al, x) is that if qi is the current state of the
TM, and ak is cell currently under the Head, then TM writes a1 in the
cell currently under the Head, enters the state q j and the Head moves
to the right adjacent cell, if the value of x is R, Head moves to the left
adjacent cell, if the value of x is L and continues scanning the same
cell, if the value of x is N.
(v) q0Q, is the initial / start state.
(vi) h Q is the Halt State, in which the machine stops any further activity.
Remark 10.3.1
Again, there are a number of variations in literature of even the above
version of TM. For example, some authors allow at one time only one of the
two actions viz., (i) writing of the current cell and (ii) movement of the Head
to the left or to the right. However, this restricted version of TM can easily be
seen to be computationally equivalent to the definition of TM given above,
because one move of the TM given by the definition can be replaced by at
most two moves of the TM introduced in the Remark.
In the next unit, we will discuss different versions of TM and issues relating
to equivalences of these versions.
In order to illustrate the ideas involved, let us consider the following
simple examples.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 345
Example 10.3.2
Consider the Turing Machine (Q, , , , q0, h) defined below that erases all
the non-blank symbols on the tape, where the sequence of non-blank
symbols does not contain any blank symbol # in-between:
Q = {q0, h} = {a, b}, = {a, b, #}
and the next-move function is defined by the following table:
q: State : Input Symbol (q, )
q0 A {q0, #, R}
q0 B {q0, #, R}
q0 # {h, #, N}
H # ACCEPT
Next, we consider how to design a Turing Machine to accomplish some
computational task through the following example. For this purpose, we
need the definition.
A string Accepted by a TM
A string over is said to be accepted by a TM, M = (Q, , , , q0, h) if
when the string is placed in the left-most cells on the tape of M and TM is
started in the initial state q0 then after a finite number of moves of the TM as
determined by , Turing Machine is in state h (and hence stops further
operations). The concepts will be treated in more details later on. Further, a
string is said to be rejected if under the conditions mentioned above, the TM
enters a state q h and scans some symbol x, then (q, x) is not defined.
Example 10.3.3
Design a TM which accepts all strings of the form bn dn for n 1and rejects
all other strings.
Let the TM, M to be designed be given by M = (Q, , , , q0, h) with
= {b, d}. The values of Q, , , shall be determined by the design process
explained below. However to begin with we take = [b, d, #}.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 346
We illustrate the design process by considering various types of strings
which are to be accepted or rejected by the TM.
As input, we consider only those strings which are over {b, d}. Also, it is
assumed that, when moving from left, occurrence of first # indicates
termination of strings over .
Case I: When the given string is of the form bn dm (bd)* for n 1, m 1 as
shown below for n = 2 m = 1
We are considering this particular type of strings, because, by taking simpler
cases of the type, we can determine some initial moves of the required TM
both for strings to be accepted and strings to be rejected.
B b d - - - -
Where denotes one of b, d or #
Initially, TM should mark left-most b. The term mark is used here in this
sense that the symbol is scanned matching with corresponding b or d as the
case may be. To begin with, the TM should attempt to match, from the left,
the first b to the d which is the first d after all bs have exhausted. For this
purpose, TM should move right skipping over all bs. And after scanning the
corresponding d, it should move left, until we reach the b, which is the last b
that was marked.
Next, TM should mark the b, if it exists, which is immediately on the right of
the previously marked b, i.e., should mark the b which is the left-most b
which is yet to be marked.
But, in order to recognize the yet-to-be-marked left-most b, we must change
each of the bs, immediately on marking, to some other symbol say B. Also,
for each b, we attempt to find the left-most yet-to-be-marked d. In order to
identify the left-most yet-to-be-marked d, we should change each of the ds
immediately on marking it, by some other symbol say D.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 347
Thus we require two additional Tape symbols B and D, i.e., =
{b, d, B, D #}.
After one iteration of replacing one b by B and one d by D the tape would be
of the form
B b D - - - -
and the tape Head would be scanning left-most b.
In respect of the states of the machine, we observe that in the beginning,
in the initial state q0, the cell under the Head is a b, and then this b is
replaced by a B; and at this stage, if we do not change the state then TM
would attempt to change next b also to B without matching the previous b to
the corresponding d. But in order to recognize the form bn dn of the string we
do not want, in this round, other bs to be changed to Bs before we have
marked the corresponding d. Therefore,
(q0, b) = (q1, B, R).
Therefore, the state must be changed to some new state say q1. Also in
order to locate corresponding d, the movement of the tape Head must be to
the right. Also, in state q1, the TM Head should skip over all bs to move to
the right to find out the first d from left. Therefore, even on encountering b,
we may still continue in state q1. Therefore, we should have
(q1, b) = (q1, b, R).
However, on encountering a d, the behaviour of the machine would be
different, i.e., now TM would change the first d from left to D and start
leftward journey. Therefore, after a d is changed to D, the state should be
changed to say q2. In state q2 we start leftward journey jumping over Ds and
bs. Therefore
(q1, d) = (q2, D, L) and
(q2, D) = (q2, D, L) and
(q2, b) = (q2, b, L).
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 348
In q2, when we meet the first B, we know that none of the cells to the left of
the current cell contains b and, if there is some b still left on the tape, then it
is in the cell just to the right of the current cell. Therefore, we should move to
the right and then if it is a b, it is the left-most b on the tape and therefore
the whole process should be repeated, starting in state q0 again.
Therefore, before entering b from the left side, TM should enter the initial
state q0. Therefore,
(q2, B) = (q0, B, R).
For to-be-accepted type string, when all the bs are converted to Bs and
when the last d is converted to D in q2, we move towards left to first B and
then move to right in q0 then we get the following transition:
From configuration
B B D D # #
q2
To configuration
B B D D # #
q0
Now we consider a special subcase of bn dm (bd)*, in which initially we
have the following input.
B D b .
Which after some moves changes to
B D b
q0
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 349
The above string is to be rejected. But if we take (q0, D) as q0 then whole
process of matching bs and ds will be again repeated and then even the
(initial) input of the form
B d b # #
will be incorrectly accepted. In general, in state q0, we encounter D, if all bs
have already been converted to Bs and corresponding ds to Ds. Therefore,
the next state of (q0, D) cannot be q0.
Let
(q0, D) = (q3, D, R).
As explained just above, for a string of the to-be-accepted type, i.e., of the
form bn dn, in q3 we do not expect symbols b, B or even another d because
then there will be more ds than bs in the string, which should be rejected.
In all these cases, strings are to be rejected. One of the ways of rejecting a
string say s by a TM is first giving the string as (initial) input to the TM and
then by not providing a value of in some state q h, while making some
move of the TM.
Thus the TM, not finding next move, stops in a state q h. Therefore, the
string is rejected by the TM.
Thus, each of (q3, b), (q3, B) and (q3, D) is undefined
Further, in q3, we skip over Ds, therefore
(q3, D) = (q3, D, R)
Finally when in q3, if we meet #, this should lead to accepting of the string of
the form bn dn, i.e., we should enter the state h. Thus,
(q3, #) = (h, #, N)
Next, we consider the cases not covered by bn dm (bd)* with n = 1, m = 1
are. Such
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 350
Case II when n =0 but m 0, i.e., when input string is of the form dm(bd)*
for m 0.
Case III when the input is of the form bn #, n 0
Case IV when the input is of the form # ..
Now we consider the cases in detail.
Case II
d
q0 The above string is to be rejected, therefore, we take (q0, d) as undefined
Case III: When the input is of the form bn # # .. #...., say
B #
q0
After one round we have
B #
q1
As the string is to be rejected, therefore,
(q1, #) is undefined
Case IV : When # is the left-most symbol in the input
# .. # .. #
q0
As the string is to be rejected, therefore, we take (q0, #) as undefined
We have considered all possible cases of input strings over = {b, d} and in
which, while scanning from left, occurrence of the first # indicates
termination of strings over .
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 351
After the above discussion, the design of the TM that accepts strings of the
form bndn and rejects all other strings over {b, d}, may be summarized as
follows:
The TM is given by (Q, , , , q0, h) where
Q = {q0, q1, q2, q3, h}
= {b, d}
= {b, d, B, D, #}
The next-move partial function is given by
b d B D #
q0 {q1, B, R) * * (q3, D, R) *
q1 {q1, b, R) {q2, D, L) * {q1, D, R) *
q2 {q2, b, L) * (q0, B, R) {q2, D, L) *
q3 * * * (q3, D, R) (h, #, N)
H * * * * Accept
* Indicates the move is not defined.
Remark
In general, such lengthy textual explanation as provided in the above case
of design of a TM, is not given. We have included such lengthy explanation,
as the purpose is to explain the very process of design. In general, table of
the type given above along with some supporting textual statements are
sufficient as solutions to such problems. In stead of tables, we may give
Transition Diagrams (to be defined).
10.4 Instantaneous Description and Transition Diagrams
The following differences in the roles of tape and tape Head of Finite
Automaton (FA) and Pushdown Automaton (PDA) on one hand and in the roles
of tape and tape head of Turing Machine on other hand need to be noticed:
(i) The cells of the tape of an FA or a PDA are only read / scanned but are
never changed / written into, whereas the cells of the tape of a TM may
be written also.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 352
(ii) The tape head of an FA or a PDA always moves from left to right.
However, the tape head of a TM can move in both directions.
As a consequence of facts mentioned in (i) and (ii) above, we conclude
that in the case of FA and PDA the information in the tape cells
already scanned do not play any role in deciding future moves of the
automaton, but in the case of a TM, the information contents of all the
cells, including the ones earlier scanned also play a role in deciding
future moves. This leads to the slightly different definitions of
configuration or Instantaneous Description (ID) in the case of a TM.
10.4.1 Instantaneous Description
The total configuration or, for short just, configuration of a Turing Machine is
the information in respect of:
(i) Contents of all the cells of the tape, starting from the left-most cell up to
at least the last cell containing a non-blank symbol and containing all
cells upto the cell being scanned.
(ii) The cell currently being scanned by the machine and
(iii) The state of the machine.
Some authors use the term Instantaneous Description instead of Total
Configuration.
Initial Configuration: The total configuration at the start of the (Turing)
Machine is called the initial configuration.
Halted Configuration: is a configuration whose state component is the Halt
state.
There are various notations used for denoting the total configuration
of a Turing Machine.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 353
Notation 1: We use the notations, illustrated below through an example:
Let the TM be in state q3 scanning the symbol g with the symbols on the
tape as follows:
# # b d a f # g H k # # # #
Then one of the notations is
# # b d a f # g h k # # # #
q3
Notation 2: However, the above being a two-dimensional notation, is
sometimes inconvenient. Therefore the following linear notations are
frequently used:
(q3,##bdaf#,g,hk), in which third component of the above 4-component vector,
contains the symbol being scanned by the tape head.
Alternatively, the configuration is also denoted by (q3,##bdaf#ghk), where the
symbol under the tape head is underscored but two last commas are dropped.
It may be noted that the sequence of blanks after the last non-blank symbol,
is not shown in the configuration. The notation may be alternatively written
(q3, w, g, u) where w is the string to the left and u the string to the right
respectively of the symbol that is currently being scanned.
In case g is the left-most symbol then we use the empty string e instead of
w. Similarly, if g is being currently scanned and there is no non-blank
character to the right of g then we use e, the empty string instead of u.
Notation 3: The next notation neither uses parentheses nor commas. Here
the state is written just to the left of the symbol currently being scanned by
the tape Head. Thus the configuration (q3, ##bdaf#, g, h, k) is denoted as
# # bdaf#q3ghk
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 354
Thus if the tape is like
g W # .
q5
then we may denote the corresponding configuration as (q5, e, g, u). And , if
the tape is like
a b c g # #
q6
Then the configuration is (q6, abc, g, e) or (q6, abc g ) or alternatively as
abcq6g by the following notation.
10.4.2 Transition Diagrams
In some situations, graphical representation of the next-move (partial)
function of a Turing Machine may give better idea of the behaviour of a TM
in comparison to the tabular representation of .
A Transition Diagram of the next-move functions of a TM is a graphical
representation consisting of a finite number of nodes and (directed) labelled
arcs between the nodes. Each node represents a state of the TM and a
label on an arc from one state (say p) to a state (say q) represents the
information about the required input symbol say x for the transition from p to
q to take place and the action on the part of the control of TM. The action
part consists of (i) the symbol say y to be written in the current cell and (ii)
the movement of the tape Head.
Then the label of an arc is generally written as x/(y, M) where M is L, R or N.
Example 10.4.2.1
Let M = {Q, , , , q0, h}
Where Q = {q0, q1, q2, h3}
= {0, 1}
= {0, 1, #}
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 355
and be given by the following table.
0 1 #
q0 - - (q2, #, R)
q1 (q2, 0, R) (q1, #, R) (h, #, N)
q2 (q2, 0, L) (q1, 1, R) (h, #, N)
h3 - - -
Then, the above Turing Machine may be denoted by the Transition Diagram
shown below, where we assume that q0 is the initial state and h is the final
state.
Figure 10.4.2.1
I / #, R
I / 1#, R
q0
q1
q2
h
# / #, R
# / #, N
# / #, R
0 / 0, R
0 / 0, L
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 356
10.5 Some Formal Definitions
In the previous units, we have used, without formally defining some of the
concepts like move, acceptance and rejection of strings by a TM. In this
section, we define these concepts formally
In the rest of the unit we assume the TM under consideration is
M = (Q, , , , q0, h)
Definition: Move of a Turing Machine. We give formal definition of the
concept by considering three possible different types of moves, viz.,
move to the left,
move to the right, and
Do not Move.
For the definition and notation for Move, assume the TM is in the configuration
(q, a1, a2 .. a i1, a i, a i +1, .. an)
Case (i) (a i, q) = (b, p, L), for motion to left
Consider the following three subcases:
Case i(a) if i > 1, then the move is the activity of TM of going from the
configuration
(q, a1, a2 .. a i1, a i, a i +1, .. an) to the configuration
(p, a1, .. a i2, a i1, a i, a i +1, .. an) and is denoted as
(q, a1, a2 .. a i1, a i, a i +1, .. an) m (p, a1, .. a i2, a i1, b, a i +1, .. an).
The suffix M, denoting the TM under consideration, may be dropped, if the
machine under consideration is known from the context.
Case i(b) if i = 1, the move leads to hanging configuration, as TM is already
scanning left-most symbol and attempts to move to the left, which is not
possible. Hence move is not defined.
Case i(c) when i = n and b is the blank symbol #, then the move is denoted
as (q, a1, a2 .. a n1, an, e) (q, a1, a2 .. a n2, a n 1, , e).
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 357
Case (ii) (a i, q) = (b, p, R), for motion to the right
Consider the following two subcases:
Case ii(a) if i < n then the move is denoted as
(q, a1, ... a i1, a i, a i +1, an) (p, a1, ... a i1, b, a i +1, a i +2.. an)
Case ii(b) if i = n the move is denoted as
(q, a1, .. a n1, an, e) (p, a1 , #, e).
Case iii (a i, q) = (b, p, No Move) when Head does not move.
Then the move is denoted as
(q, a1, a i1, a i, a i +1, an) (p, a1, .. a i1, b, a i +1, an)
Definition: A configuration results (or is derived) from another configuration.
We illustrate the concept through an example based on say Case (iii) above
of the definition of move. In this case, we say the configuration
(p, a1, .. a i1, b, a i +1, .. an) results in a single move or is derived in a
single move from the configuration (q, a1, .. a i1, a i, a i +1, .. an). Also,
we may say that the move yields the configuration (p, a1, .. a i1, b, a i +1,
.. an) or the configuration (q, a1, .. a i1, a i, a i +1, .. an) yields the
configuration (p, a1, .. a i1, b, a i +1, .. an) in a single move.
Definition: Configuration results in n Moves or finite number of moves.
If, for some positive integer n, the configurations c1, c2, . . . cn are such that
ci results from ci 1 in a single move, i.e.,
c i1 c i for i = 2, . . . n
then, we may say that cn results from c1 in n moves or a finite number of
moves. The fact is generally denoted as
c1 n c n or c1
c n
The latter notation is the preferred one, because generally n does not play
significant role in most of the relevant discussions.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 358
The notation c1 c n also equivalently stands for the statement that c1 yields
cn in finite number of steps.
Definition: Computation
If c0 is an initial configuration and for some n, the configurations c1, c2, . . . ,
cn are such that c0, c1 . . . cn, then, the sequence of configurations
c0, c1, . . . cn constitutes a computation .
Definition: A string acceptable by a TM
is said to be acceptable by TMM if (q0, )* (h, r) for r *
Informally, is acceptable by M, if when the machine M is started in the
initial state q0 after writing on the leftmost part of the tape, then, if after
finite number of moves, the machine M halts (i.e., reaches state h and of
course, does not hang and does not continue moving for ever) with some
string of tape symbols, the original string is said to be accepted by the
machine M.
Definition: Length of Computation
If C0 is initial configuration of a TM M and C0, C1 . . . . , Cn is a computation,
then n is called the length of the computation C0, C1 . . . . , Cn.
Definition: Input to a Computation
In the initial configuration, the string, which is on that portion of the tape
beginning with the first non-blank square and ending with the last non-blank
square, is called input to the computation.
Definition: Language accepted by a TM
M = (, , , , q0, h), denoted by L(M), and is defined as
L(M) = { * and if = a1 . . . . an then
(q0, e, a1, a, . . . an) *
(h, b1 . . . b j1, b j, . . . b j+1 . . . bn)
for some b1 b2 . . . . bn *
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 359
L(M), the language accepted by the TM M is the set of all finite strings
over which are accepted by M.
Definition: Turing Acceptable Language
A language L over some alphabet is said to be Turing Acceptable
Language, if there exists a Turing Machine M such that L = L(M).
Definition: Turing Decidable Language
There are at least two alternate, but of course, equivalent ways of defining a
Turing Decidable Language as given below:
Definition: A language L over , i.e., L * is said to be Turing Decidable,
if both the languages L and its complement * ~ L are Turing acceptable.
Definition: A language L over , i.e., L * is said to be Turing Decidable,
if there is a function
fL : * NY ,
such that for each *
LifN
LifYfL
Remark 10.5.1
A very important fact in respect of Turing acceptability of a string (or a
language) needs our attention. The fact has been discussed in details in a
later unit about undecidability. However, we briefly mention it below.
For a TM M and an input string *, even after a large number of moves
we may not reach the halt state. However, from this we can neither
conclude that Halt state will be reached in a finite number of moves nor can
we conclude that Halt state will not be reached in a finite number moves.
This raises the question of how to decide that an input string w is not
accepted by a TM M.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 360
An input string w is said to be not accepted by a TM M = (Q, , , , q0, h) if
any of the following three cases arise:
(i) There is a configuration of M for which there is no next move i.e., there
may be a state and a symbol under the tape head, for which does not
have a value.
(ii) The tape Head is scanning the left-most cell containing the symbol x
and the state of M is say q and (x, q) suggests a move to the left of
the current cell. However, there is no cell to the left of the left-most cell.
Therefore, move is not possible. The potentially resulting situation
(cant say exactly configuration) is called Hanging configuration.
(iii) The TM on the given input w enters an infinite loop. For example, if
configuration is as
X y
q0
and we are given
(q0, x) = (q1, x, R)
and (q1, y) = (q0, y, L)
Then we are in an infinite loop.
10.6 Observations
The concept of TM is one of the most important concepts in the theory of
Computation. In view of its significance, we discuss a number of issues in
respect of TMs through the following note.
Note 10.6.1
Turing Machine is not just another computational model, which may be
further extended by another still more powerful computational model. It is
not only the most powerful computational model known so far but also is
conjectured to be the ultimate computational model.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 361
Turing Thesis: The power of any computational process is captured within
the class of Turing Machines.
It may be noted that Turing thesis is just a conjecture and not a theorem,
hence, Turing Thesis can not be logically deduced from more elementary
facts. However, the conjecture can be shown to be false, if a more powerful
computational model is proposed that can recognize all the languages which
are recognized by the TM model and also recognizes at least one more
language that is not recognized by any TM.
In view of the unsuccessful efforts made in this direction since 1936, when
Turing suggested his model, at least at present, it seems to be unlikely to
have a more powerful computational model than TM Model.
Note 10.6.2
The Finite Automata and Push-Down Automata models were used only as
accepting devices for languages in the sense that the automata, when given
an input string from a language, tells whether the string is acceptable or not.
The Turing Machines are designed to play at least the following three
different roles:
(i) As accepting devices for languages, similar to the role played by FAs
and PDAs.
(ii) As a computer of functions. In this role, a TM represents a particular
function (say the SQUARE function which gives as output the square of
the integer given as input). Initial input is treated as representing an
argument of the function. And the (final) string on the tape when the TM
enters the Halt State is treated as representative of the value obtained
by an application of the function to the argument represented by the
initial string.
(iii) As an enumerator of strings of a language that outputs the strings of a
language, one at a time, in some systematic order, i.e., as a list.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 362
Note 10.6.3
Halt State of TM vs. set of Final States of FA/PDA
We have already briefly discussed the differences in the behaviour of TM on
entering the Halt State and the behaviour of Finite Automata or Push Down
Automata on entering a Final State.
A TM on entering the Halt State stops making moves and whatever string is
there on the tape, is taken as output irrespective of whether the position of
Head is at the end or in the middle of the string on the tape. However, an
FA/PDA, while scanning a symbol of the input tape, if enters a final state,
can still go ahead (as it can do on entering a non-final state) with the
repeated activities of moving to the right, of scanning the symbol under the
head and of entering a new state etc. In the case of FA / PDA, the portion of
string from left to the symbol under tape Head is accepted if the state is a
final state and is not accepted if the state is not a final state of the machine.
To be more clear we repeat: the only difference in the two situations when
an FA / PDA enters a final state and when it enters a non-final state is that
in the case of the first situation, the part of the input scanned so far is said to
be accepted / recognized whereas in the second situation the input scanned
so far is said to be unaccepted.
However, in the Final State version of TM, the Head is allowed movements
even after entering a Final State. Some definite statement like Accepted /
Recognized can be made if, in this version, the TM is in Final State.
Note 10.6.4
Final State Version of Turing Machine
Instead of the version discussed above, in which a particular state is
designated as Halt State, some authors define TM in which a subset of the
set of states Q is designated as Set of Final States, which may be denoted
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 363
by F. This version is extension of Finite automata with the following
changes, which are minimum required changes to get a Turing Machine
from an FA.
(i) The Head can move in both Left and Right directions whereas in PDA /
FA the head moves only to the Right.
(ii) The TM, while scanning a cell, can both read the cell and also, if
required, change the value of the cell, i.e., can write in the cell. In Finite
Automata, the Head only can read the cell. It can be shown that the
Halt State version of TM is equivalent to the Final State version of
Turing Machine.
(iii) In this version, the TM machine halts only in a given state and a given
symbol under the head, no next move is possible. Then the (initial)
input on the tape of TM, is unacceptable.
Definition: Acceptability of * in Final State Version
Let M1 = (Q, , , , q0, F)
be a TM in final state version. Then w is said to be acceptable if C0 is the
initial configuration with w as input string to M1 and
C0 * Cn
is such that
Cn = (p, , a, )
with p in F, set of final states, and a , the set of tape symbols, and , *
Equivalence of the Two Versions
We discuss the equivalence only informally. If in the Halt state version of a
TM instead of the halt state h, we take F = {h} then it is the Final state
version of the TM. Conversely, if F = {f1, f2, . . . . fr} is the set of final states
then we should note the fact that in the case of acceptance of a string, a TM
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 364
in final state version enters a final state only once and then halts with
acceptance. Therefore, if we rename each of the final state as h, it will not
make any difference to the computation of an acceptable or unacceptable
string over . Thus F may be treated as {h}, which further may be treated as
just h.
10.7 Turing Machine as a Computer of Functions
In the previous section of this unit, we mentioned that a Turing Machine may
be used as-
(i) A language Recognizer/acceptor
(ii) A computer of Functions
(iii) An Enumerator of Strings of a language.
We have already discussed the Turing Machine in the role of language
accepting device. Next, we discuss how a TM can be used as a computer of
functions.
Note 10.7.1
For the purpose of discussing TMs as computers of functions, we make the
following assumptions:
A string over some alphabet say will be written on the tape as ##,
# is the blank symbol.
Also initially, the TM will be scanning the right-most # of the string ##.
Thus, the initial configuration, (q0, ## ) represents the starting point for the
computation of the function with as input.
The assumption facilitates computation of composition of functions
Though, most of the time, we require functions of one or more arguments
having only integer values with values of arguments under the functions
again as integers, yet, we consider functions with domain and codomain
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 365
over arbitrary alphabet sets say 0 and 1 respectively, neither of which
contains the blank symbol #.
Next we define what is meant by computation, using Turing Machine, of a
function
f : 0* 1*
Definition: A function f : 0* 1* is said to be Turing-Computable, or
simply computable, if there is a Turing Machine M = (Q, , , , q0, h), where
contains the following holds:
(q0,## ,) *m (h, ## ,)
whenever 0* and 1* satisfying f() = .
Note 10.7.2
It may be noted that, if the string contains some symbols from the set
0, i.e., symbols not belonging to the domain of f, then the TM may
hang or may not halt at all.
Note 10.7.3
Next, we discuss the case of functions which require k arguments, where k
may be any finite integer, greater than or equal to zero. For example,
the operation PLUS takes two arguments m and n and returns m + n.
The function f with the rule f(x, y, z) = (2x + y) * z takes three arguments.
The function C with rule C ( ) = 17 takes zero number of arguments
Let us now discuss how to represent k distinct arguments of a function f on
the tape. Suppose k = 3 and x1, x2, y1 y2 y3 and z1 z2 are the three strings as
three arguments of function f. If these three arguments are written on the
tape as
# X1 x2 y1 y2 y3 z1 z2 #
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 366
Then the above tape contents may even be interpreted as a single
argument viz., x1, x2, y1 y2 y3 z1 z2. Therefore, in order, to avoid such an
incorrect interpretation, the arguments are separated by #. Thus, the above
three arguments will be written on the tape as
# x1 x2 # y1 y2 y3 # z z2 #
In general, if a function f takes k 1 arguments say 1, 2, . . ., k where
each of these arguments is a string over 0 (i.e., each i belongs to 0*)
and if f (1, 2, . . ., k) = for some 1*; then we say f is Turing
Computable if there is a Turing Machine M such that
(q0, e, #1#2 . . . # k#, e) *M (h, e, ##, e)
Also, when f takes zero number of arguments and f ( ) = then, we say f is
computable, if there is a Turing Machine M such that
(q0, e, ## , e) *M (h, e, ## , e)
Note 10.7.4
In stead of functions with countable, but otherwise arbitrary sets as domains
and ranges, we consider only those functions, for each of which the domain
and range is the set of natural numbers. This is not a serious restriction in
the sense that any countable set can, through proper encoding, be
considered as a set of natural numbers.
For natural numbers, there are various representations; some of the
well-known representations are Roman Numerals (e.g., VI for six), Decimal
Numerals (6 for six), Binary Numerals (110 for six). Decimal number system
uses 10 symbols viz., 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. Binary number system
uses two symbols denoted by 0 and 1. In the discussion of Turing
Computable Functions, the unary representation described below is
found useful. The unary number system uses one symbol only: Let the
symbol be denoted by I then the number with name six is represented as
IIIIII. In this notation, zero is represented by empty / null string. Any other
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 367
number say twenty is represented in unary systems by writing the symbol I,
twenty times. In order to facilitate the discussion, the number n, in unary
notation will be denoted by In in stead of writing the symbol I, n times.
The advantage of the unary representation is that, in view of the fact that
most of the symbols on the tape are input symbols and if the input symbol is
just one, then the next state will generally be determined by only the
current state, because the other determinant of the next state viz., tape
symbol is most of the time the unary symbol.
We recall that for the set X, the notation X* represents the set of all finite
strings of symbols from the set X. Thus, any function f from the set of natural
number to the set of natural numbers, in the unary notation, is a function of
the form f : {} * {} *
Definition: The function f : N N with f(n) = m for each n N and
considered as f : {} * {} *, with {} a unary number system, will be called
Turing Computable function, if a TM M can be designed such that M
starting in initial tape configuration
# I I . . . . . . I#
with n consecutive Is between the two #s of the above string, halts in the
following configuration.
# I I . . . . . . I #
containing f(n) = m Is between the two #s
The above idea may be further generalized to the functions of more
than one integer arguments. For example, SUM of two natural numbers n
and m takes two integer arguments and returns the integer (n + m). The
initial configuration with the tape containing the representation of the two
arguments say n and m respectively, is of the form
# I I . . . . I # I I . . . . I#
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 368
where the string contains respectively n and m s between respective pairs
of #s and Head scans the last #. The function SUM will be Turing
computable if we can design a TM which when started with the initial tape
configuration as given above, halts in the Tape configuration as given
below:
# I I . . . . I I . . . . I#
where the above string contains n + m consecutive s between pair of #s.
Example
Show that the SUM function is Turing Computable.
The problem under the above-mentioned example may also be stated as:
Construct a TM that finds the sum of two natural numbers.
The following design of the required TM, is not efficient yet explains a
number of issues about which a student should be aware while
designing a TM for computing a function.
Legal and Illegal Configurations for SUM function:
In order to understand the design process of any TM for a (computable)
function in general and that of SUM in particular, let us consider the possible
legal as well as illegal initial configuration types as follows:
Note: in the following, the sequence denotes any sequence of Is
possibly empty and the sequences *** denotes any sequence of Tape
symbols possibly empty and possibly including #. Underscore denotes the
cell being scanned.
Legal initial configuration types:
Configuration (i)
q0
# # # ***
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 369
Representing n = 0, m = 0
Configuration (ii)
q0
n = 0, m 0
Configuration (iii)
q0
n 0, m = 0
Configuration (iv)
q0
n 0, m 0
We treat the following configuration
q0
containing two or more than two #s to the left of # being scanned in initial
configuration, as valid, where denotes sequence of s only.
Some illegal initial configurations:
Configuration (v)
# # # ***
# # # ***
# # # ***
# # # #
*** I ***
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 370
Where at least one of *** does not contain # and initially the Head is
scanning an or any symbol other than #. The configuration is invalid as it
does not contain required number of #s.
Configuration (vi), though is a special case of the above-mentioned
configuration, yet it needs to be mentioned separately.
Left most symbol is or any other non-# symbol
Where *** does not contain any #,
Configuration (vii)
Where *** does not contain # then the configuration represents only one of
the natural numbers.
Also, in case of legal initial configurations, the final configuration that
represents the results m + n should be of the form.
Halt
with representing exactly m + n s.
Also in case of illegal initial configurations, the TM to be designed, should be
in one of the following three situations indicating non-computability of the
function with an illegal initial input, as explained before:
(i) the TM has an infinite loop of moves;
(ii) the TM head attempts to fall off the left edge (i.e., the TM has Hanging
configuration); or
(iii) the TM does not have a move in a non-Halt state.
*** # ***
# ... # ***
# ..... #
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 371
We use the above-mentioned description of initial configurations and the
corresponding final configurations, in helping us to decide about the various
components of the TM to be designed.
At this stage, we plan how to reach from an initial configuration to a
final configuration. In the case of this problem of designing TM for SUM
function, it is easily seen that for a legal initial configuration, we need to
remove the middle # to get a final configuration.
(a) Summing up initially the machine is supposed to be in the initial state
(say) q0
(b) In this case of legal moves for TM for SUM function, first move of the
Head should be to the Left only
(c) In this case, initially there are at least two more #s on the left of the #
being scanned. Therefore, to keep count of the #s, we must change
state after scanning each #. Let q1, q2 and q3 be the states in which the
required TM enters after scanning the three #s
(d) In this case the movement of the Head, after scanning the initial # and
also after scanning one more # on the left, should continue to move to
the Left only, so as to be able to ensure the presence of third # also.
Also, in states q1 and q2, the TM need not change state on scanning .
Thus we have,
(q0, #) = (q1, #, L),
(q1, #) = (q2, #, L)
and
(q1, ) = (q1, , L), (q2, ) = (q2, , L).
However, from this point onward, the Head should start moving to the
Right.
(q2, #) = (q3, #, R)
Thus, at this stage we are in a configuration of the form
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 372
# #
q3
For further guidance in the matter of the design of the required TM, we
again look back on the legal configurations.
(e) In the configuration just shown above in q3, if the symbol being
scanned is # (as in case of configuration (i) and configuration (ii)), then
the only action required is to skip over s, if any, and halt at the next #
on the right.
However, if the symbol being scanned in q3 of the above configuration,
happens to be an (as in case of configuration (iii) and configuration
(iv)) then the actions to be taken, that are to be discussed after a
while, have to be different.
But in both cases, movement of the Head has to be to the Right.
Therefore, we need two new states say q4 and q5 such that
(q3, #) = (q4, #, R)
(the processing / scanning argument on the left, is completed).
(q3, ) = (q5, , R)
(the scanning of the argument on the left, is initiated).
Taking into consideration the cases of the initial configuration (i) and
configuration (ii) we can further say that
(q4, ) = (q4, , R)
(q4, #) = (halt, #, N)
Next, taking into consideration the cases of initial configuration (iii) and
configuration (iv) cases, we decide about next moves including the states
etc., in the current state q5.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 373
We are in the following general configuration
(that subsumes the initial configuration (iii) and configuration (iv) cases)
# I # #
q5
Where the blank spaces between #s may be empty or non-empty sequence
of Is. Next landmark symbol is the next # on the right. Therefore, we may
skip over the s without changing the state i.e.,
(q5, ) = (q5, , R)
But we must change the state when # is encountered in q5, otherwise, the
next sequence of s will again be skipped over and we will not be able to
distinguish between configuration (iii) and configuration (iv) for further
necessary action.
Therefore,
(q5, #) = (q6, #, R)
(notice that, though at this stage, scanning of the argument on the left is
completed, yet we can not enter in state q4, as was done earlier, because in
this case, the sequence of subsequent actions have to be different. In this
case, the # in the middle has to be deleted, which is not done in state q4).
Thus, at this stage we have the general configuration as
# # #
q6
Next, in q6, if the current symbol is a #, as is the case in configuration (iii),
then we must halt after moving to the left i.e.,
(q6, #) = (halt, #, L)
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 374
We reach the final configuration.
0# # #
Halt
However, if we are in configuration (iv) then we have
# # #
q6
Then the following sequence of actions is required for deleting the middle #.
Action (i): To remove the # in the middle so that we get a continuous
sequence of s to represent the final result. For this purposes, we move to
the left and replace the # by . But then it will give one more than number
of s required in the final result.
Therefore,
Action (ii): We must find out the rightmost and replace the rightmost by #
and stop, i.e., enter halt state. In order to accomplish Action (ii) we reach the
next # on the right, skipping over all s and then on reaching the desired #,
and then move left to an over there. Next, we replace that by # and halt.
Translating the above actions in terms of formal moves, we get
For Action (i)
(q6, ) = (q7, , L)
(q7, #) = (q8, , R)
(at this stage we have replaced the # in the middle of two sequences of s
by an )
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 375
For Action (ii)
(q8, ) = (q8, , R)
(q8, #) = (q9, #, L)
(q9, ) = (halt, #, N)
It can be verified that through above-mentioned moves, the designed TM
does not have a next-move at some stage in the case of each of the illegal
configurations.
Formally, the SUM TM can be defined as:
SUM = (Q, , , , q0, h)
Where Q = {q0, q1, .. q10, halt}
= { }
= { , # }
and
The next-move (partial) function is given by the Table
I #
q0 (q1, #, L)
q1 (q1, I, L) (q2, #, L)
q2 (q2, I, L) (q3, #, R)
q3 (q5, I, R) (q4, #, R)
q4 (q4, I, R) (halt, #, N)
q5 (q5, I, R) (q6, #, R)
q6 (q7, I, L) (halt, #, L)
q7 (q8, I, R)
q8 (q8, I, R) (q9, #, L)
q9 (halt, #, N)
halt
indicates that is not defined.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 376
Note 10.7.6
As mentioned earlier also in the case of design of TM for recognizing the
language of strings of the form bndn, the design given above contains too
detailed explanation of the various steps. The purpose is to explain the
involved design process in fine details for better understanding of the
students. However, the students need not supply such details while
solving a problem of designing TM for computing a function. While giving the
values of Q, , explicitly and representing either by a table or a transition
diagram, we need to give only some supporting statements to help
understanding of the ideas involved in the definitions of Q, , and .
Example
Construct a TM that multiplies two integers, each integer greater than or
equal to zero (Problem may also be given as: show that multiplication of two
natural numbers is Turing Computable).
Informal Description of the solution:
The legal and illegal configurations for this problem are the same as those
of the problem of designing TM for SUM function. Also, the moves required
to check the validity of input given for SUM function are the same and are
repeated below:
(q0, #) = (q1, #, L)
(q1, #) = (q2, #, L)
(q1, ) = (q1, , L)
(q2, #) = (q3, #, R)
(q2, ) = (q2, , L)
Next, we determine the rest of the behaviour of the proposed TM.
Case I
When n = 0 covering configuration (i) and configuration (ii) The general
configuration is of the form
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 377
# # #
q3
To get representation of zero, as one of the multiplier and multiplic and is
zero, the result must be zero. We should enter state say q4 which skips all
s and meets the next # on the right.
Once the Head meets the required #, Head should move to the left replacing
all s by #s and halt on the # it encounters so that we have the
configuration
# # #
Halt
The moves suggested by the above explanation covering configuration
(i) and configuration (ii) are:
(q3, #) = (q4, #, R)
(q4, ) = (q4, , R)
(q4, #) = (q5, #, L)
(q5, ) = (q5, #, L)
(q5, #) = (Halt, #, R)
Case II
Covering configuration (iii), we have at one stage
# # #
q3
If we take (q3, I) = (q4, #, R), then we get the following desired
configuration in finite number of moves:
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 378
# # # # # #
Halt
Case III
While covering the configuration (iv), At one stage, we are in the
configuration
n s m s # I # #
q3
In this case, the final configuration is of the form
m n s # # # #
Halt
The strategy to get the representation for n m s consists of the
following steps:
(i) Replace the left-most in the representation of n by # and then copy
the m s in the cells which are on the right of the # which was being
scanned in the initial configuration. In the subsequent moves, copying
of s is initiated in the cells which are in the left-most cells on the right
hand of last s on the tape, containing continuous infinite sequence of
#s.
Repeat the process till all s of the initial representation of n, are
replaced by #. At this stage, as shown in the following figure, the tape
contains m s of the initial representation of the integer m and
additionally n.m s. Thus the tape contains m extra #s than are
required in the representation of final result. Hence, we replace all s
of m by #s and finally skipping over all s of the representation of
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 379
(n m) we reach the # which is on the right of all the (n m) s on the
tape as required.
Alternatively: In stead of copying n times of the m s, we copy only (n 1)
times to get the configuration
# # # # . #
m s ((n1) m) s
Then we replace the # between two sequences of s by and replace the
right-most by # and halt.
The case of illegal initial configurations may be handled on similar lines as
were handed for SUM Turing machine.
Self Assessment Questions
1. Briefly describe a turing machine
2. What do you mean by instantaneous description and transition
diagrams.
10.8 Summary
In this unit, after giving informal idea of what a Turing machine is, the
concept is formally defined and illustrated through a number of examples.
Further, it is explained how TM can be used to compute mathematical
functions. Finally, a technique is explained for designing more and more
complex TMs out of already designed TMs, starting with some very simple
TMs.
10.9 Terminal Questions
1. Show that the sum functions is turing computable.
-
Analysis and Design of Algorithms Unit 10
Sikkim Manipal University Page No.: 380
10.10 Answers
Self Assessment Questions
1. Refer Section 10.3.
2. Refer Section 10.4
Terminal Questions
1. Refer Section 10.7