0% found this document useful (0 votes)
8 views62 pages

Variats of TM

The document discusses Turing Machines (TMs), their components, and their significance in computer science and complexity theory. It explains the structure of TMs, including their alphabet, tape, tape head, states, and programs, as well as variants like k-Track TMs. Additionally, it covers practical applications of TMs, such as addition and multiplication of binary numbers, and defines a computer in the context of TMs.

Uploaded by

Mohsin Khan
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)
8 views62 pages

Variats of TM

The document discusses Turing Machines (TMs), their components, and their significance in computer science and complexity theory. It explains the structure of TMs, including their alphabet, tape, tape head, states, and programs, as well as variants like k-Track TMs. Additionally, it covers practical applications of TMs, such as addition and multiplication of binary numbers, and defines a computer in the context of TMs.

Uploaded by

Mohsin Khan
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/ 62

CS-352 TAFL

Variants of TM

Instructor: Yusra Arshad

Book: Prof. Sipser-MIT

1
Turing Machines
 Turing machines are extremely basic symbol manipulating devices which
despite their simplicity can be adapted to simulate the logic of any computer
that could possibly be constructed.
 Never physically constructed as it was basically a thought experiment about
the limits of mechanical computation.
 Studying their abstract properties yields many insights into computer science
and complexity theory

2
Turing Machines
 A Turing machine is a collection of six things
1. An alphabet ∑ of input letters, which for clarity's sake does not contain
the blank symbol Δ.
2. A TAPE divided into a sequence of numbered cells each containing one
character or a blank.
 The input word is presented to the machine one letter
per cell beginning in the left-most cell, called cell i.
 The rest of the TAPE is initially filled with blanks, Δ's.

3
Turing Machines
 A Turing machine is a collection of six things
3. TAPE HEAD that can in one step read the contents of a cell on the
TAPE, replace it with some other character, and reposition itself to the
next cell to the right or to the left of the one it has just read.
• At the start of the processing, the TAPE HEAD always
begins by reading the input in cell i.
• The TAPE HEAD can never move left from cell i. If it
is given orders to do so, the machine crashes.
4. An alphabet, Г, of characters that can be printed on the TAPE by the
TAPE HEAD.
• This can include ∑.
• Even though we allow the TAPE HEAD to print a Δ we
call this erasing and do not include the blank as a letter in the
alphabet Г.

4
Turing Machines
 A Turing machine is a collection of six things
5. Finite set of states including exactly one START state from which we
begin execution (and which we may reenter during execution) and some
(maybe none) HALT states that cause execution to terminate when we
enter them.
• The other states have no functions, only names like
q1,q2,q3 or 1,2,3….

5
Turing Machines
6. A program, which is a set of rules that tell us, on the
basis of the letter the TAPE HEAD has just read, how
to change states, what to print and where to move the
TAPE HEAD.
 We depict the program as a collection of directed edges
connecting the states.
 Each edge is labeled with a triplet of information:
(letter, letter, direction)
• The first letter (either Δ or from ∑) is the character the
TAPE HEAD reads from the cell to which it is pointing.
• The second letter (also Δ or from Г) is what the TAPE
HEAD prints in the cell before it leaves.
• The third component, the direction, tells the TAPE
HEAD whether to move one cell to the right, R, or one
cell to the left, L.

6
Turing Machines
 If we are in a state and read a letter that offers no
choice of path to another state, we crash; that means
we terminate execution unsuccessfully.
 To terminate execution of a certain input successfully,
we must be led to a HALT state. The word on the input
TAPE is then said to be accepted by the TM.
 A crash also occurs when we are in the first cell on the
TAPE and try to move the TAPE HEAD left.
 By definition, all Turing machines are deterministic.
This means that there is no state q that has two or more
edges leaving it labeled with the same first letter.

7
Example: A Turing machine

What is it doing?

8
A Turing machine for every FA
 Do some more examples

9
Example
 What is this machine doing?

10
Example
 Same machine but more simpler

11
Example
 How would you change this machine so that it accepts
anb2n.

12
Example
 What about an+1bn.

13
Example
 What about anbn+1.

14
Example
 Can you now make machines for
 a2nb3n
 a2n+2bn

15
Example
 Lets Build One Machine for Even Palindrome

 If Done, now lets convert it so that it also accepts Odd


Palindromes

16
Example

17
Variants of Turing
Machines
TM with multiple Tapes
 Also called k-TRACK TM, have multiple TAPES.
 The picture below has four TAPES stacked one on top
of the other.
 The TAPE head reads the corresponding cells all at once

 Here, the TAPE HEAD is reading cell iii of TAPE 1, cell iii
of TAPE 2, cell iii of TAPE 3, and cell iii of TAPE 4 at
once.
 The TAPE HEAD can write something new in each of these
cells and then move to the left to read the four cell ii's or to
the right to read the four cell iv's.
19
k-Track TM
 The input strings are taken from ∑, while the TAPE
HEAD can write any character from Г.

 p,q,r,s are from ∑, while t,u,v,w are from Г, and M is


either R or L.
 If what is read from TAPE 1 is p, from TAPE 2 is q,
from TAPE 3 is r, from TAPE 4 is s, and so on, then
what will be written on TAPE 1 is t, on TAPE 2 is u, on
TAPE 3 is v, and on TAPE 4 is w, and so on.
 The TAPE HEAD will be moved in the direction
indicated by M.

20
k-Track TM
 To operate a kTM we start with an input string from
∑* on TAPE 1 starting in cell i, and if we reach
ACCEPT we say that the string is in the language of
the kTM.
 We also say that the contents of all the TAPES is the
output produced by this input string.
 It is a very useful modification, it allows a natural
correspondence between the machine algorithm and
traditional hand calculation, as we will see from the
examples.
 The words track and TAPE are used interchangeably
for a kTM.
 A k-Track TM can be very easily converted to a
TM.
21
k-Track TM: Example
 How Do we add numbers by hand?
 Line them up in two rows, find the right-hand column,
perform the addition column by column moving left,
remembering whether there are carries and stopping when
the last column has been added.
 The following 3TM performs this algorithm exactly as we
were taught in Third Grade except that it uses a column of
$'s to mark the left edge.
 Here = means that leave as it is
 We need to insert $ in the very first column for two reasons
 To mark the end of computation
 Helps in inserting the extra carry after whole
computation

22
k-Track TM: Example

23
Computers
Computers
 The finite automata, are only language acceptors.
When we gave them output capabilities, as with Mealy
and Moore machines these are called transducers.
 The pushdown automata similarly do not produce
output but are only language acceptors. However, we
recognized their potential for doing parsing.
 On the other hand, TMs always have a natural output.
 When the processing of any given TM terminates,
whatever is left on its TAPE can be considered to be
the intended, meaningful output.
 Sometimes the TAPE is only a scratch pad where the
machine has performed some calculations needed to
determine whether the input string should be accepted.
 In this case, what is left on the TAPE is meaningless.
25
Computers
 Like we did for TMs accepting anbnan and
PALINDROME.
 However, we may start by loading the TAPE with some
data that we want to process.
 Then we run the machine until it reaches the HALT
state.
 At that time the contents of the TAPE will have been
converted into the desired output, which we can
interpret as the result of a calculation.
 We begin with the encoding of the natural numbers as
strings of a's alone (Unary encoding)

26
Computers
 Every word in (a + b)* can then be interpreted as a
sequence of numbers (strings of a's) separated
internally by b's.
 For example, abaa = (one a) b (two a's)
 the decoding of (abaa) = 1,2
 bbabbaa = (no a's) b (no a's) b (one a) b (no a's) b (two
a's)
 the decoding of (bbabbaa) = 0,0,1,0,2
 abaabb = (one a) b (two a's) b (no a's) b (no a's)
 decoded = 1,2,0,0

27
Computers
 What is the purpose of this TM now?

 It is an Adder
 For an input string to be accepted (lead to HALT), it has
to be of the form: a*ba*
 If we start with the input string anbam, we end up with:
an+m

28
Computers
 ADDER takes two numbers as input and leaves their
sum on the TAPE as output.
 This is our most primitive example of a TM
intentionally working as a calculator.
 If we used an input string not in the form a*ba*, the
machine would crash.
 This is analogous to our computer programs crashing if
the input data is not in the correct format.
 Our choice of unary notation is not essential; we could
build an "adding machine” for any other base as well.

29
Adder With Binary
 Let us build a TM that adds two numbers presented in
binary notation and leaves the answer on the TAPE in
binary notation.
 We shall construct this TM out of two parts. First we
consider the Turing machine T1 shown below:

 This TM presumes that the input is of the form: $(0 + 1)*


 This TM adds 1 to the binary number after the $.
 If the input was of the form $1*, the machine finds no 0 and crashes. This
adder does not work on numbers that are solid strings of l's:

30
Adder with Binary
 The machine on the next slide will accept a nonzero
number in binary and subtract I from it.
 The input is presumed to be of the form: $(0 + 1)*$ but
not: $0"$
 The subtraction The subtraction will be done in a three-
step process:
 Step 1: Reverse the O's and l's between the $'s. This is
called taking the l's complement.
 Step 2: Use T1 to add 1 to the number now between
the $'s. Notice that if the original number was not 0,
the l's complement is not a forbidden input to T, (i.e.,
not all l's).
 Step 3 Reverse the O's and l's again.

31
Adder with Binary

32
Adder with Binary
 The binary adder we shall now build works as follows:
 The input strings will be of the form $ (0 + 1)* $ (0 +
1)* which we call: $ x-part $ y-part
 We shall interpret the x-part and y-part as numbers in
binary that are to be added.
 We make the assumption that the total x + y has no
more bits than y itself.
 This is analogous to the addition of numbers in the
arithmetic registers of a computer where we presume that
there will be no overflow.
 If y is the larger number and starts with the bit 0, the
condition is guaranteed.
 If not, we can make use of the subroutine insert studies
previously to put enough O's in the front of y to make
the condition true.
33
Adder with Binary
 The algorithm to calculate x + y in binary will be this:
 Step 1: Check the x-part to see if it is 0. If yes, halt. If
no, proceed.
 Step 2: Subtract 1 from the x-part using the Turing
machine for subtractor on previous slide .
 Step 3 Add 1 to the y-part using the turing machine
described previoiusly.
 Step 4 Go to Step 1.
 The final result will be: $ 0* $ (x + y in binary)

34
Adder with Binary: Final Machine

35
Adder with Binary: Example
$4$7.
becomes $ 3 $ 8
becomes $ 2 $ 9
becomes $ 1 $ 10
becomes $ 0$ 11

36
Adder with Binary: Example
• $ 10 $ 0110 in an attempt to add two and six in binary.

37
Definition of Computers
 If a TM has the property that for every word it accepts,
at the time it halts, it leaves one solid string of a's and
b's on its TAPE starting in cell i, we call it a computer.
 The input string we call the input (or, string of input
numbers), and we identify it as a sequence of
nonnegative integers.
 The string left on the TAPE we call the output and
identify it also as a sequence of nonnegative integers.
 The machines we have are only approximations to the
real TMs.
 We will continue to deal with zero and positive
numbers.
 The negative number and fractions can be encoded into
positive numbers (as in regular computers)
38
Multiplication is Computable
 We shall assume that the two numbers of input are
preceded on the TAPE by an extra letter b.
 This machine, called MPY, takes strings of the form
bamban and leaves on the TAPE bamn.
 To make things easier on ourselves, we shall build a
machine that rejects the input if n or m is zero;
 However, if we wanted to we could build the machine
differently to allow multiplication by zero
 We could also do without the initial b too, but then we
would have to insert a cell i symbol to prevent back-up
crashes.

39
Multiplication
 The algorithm this machine will follow is to place the
symbol # after the input string.
 Then to the right of the # it will write one copy of the
string an for each a in the string am, one by one erasing
the a's in the first string.
 For example, the multiplication of 3 times 2 proceeds
in these stages: baaabaa#
bΔaabaa#aa
b Δ Δ abaa#aaaa
b Δ Δ Δ baa#aaaaaa
• The machine will then erase everything between and
including the first b and the #. The TAPE now looks like
this: b Δ Δ Δ Δ Δ Δ Δ aaaaaa.
40
Multiplication
 Then we will use the version of DELETE discussed
earlier to shifting the string of a‘s leftward to begin in
cell ii.
 Lets start building our machine; Till now we have

41
Multiplication
 Next, we go back and find the first a in am and convert
it into a A:

 Next, we find the beginning of the second factor an

42
Multiplication
 In state 9 we convert the first a into an A.
 In state 10 we move the TAPE HEAD to the right
going through a's and the # and perhaps other a's until
we find the Δ.
 To get to state 11, we change the first Δ to an a and
start the trip back down the TAPE leftward.
 In state 11, we skip over a's and the # and more a's
until we find the last copied A.
 In state 12 we look to the right of this A.
 If there is a #, then there are no more a's to copy and we go
to state 13.
 If there is another a, it must be copied so we change it to A
and go back to state 10.

43
Multiplication
 In state 13 we must change the A's back to a's so we
can repeat the process.
 Then we look for the next a in the first factor:

44
Multiplication
 After changing the A's back to a's, we move left,
through the middle b, into whatever is left of the first
factor am.
 If the cell to the immediate left of b is blank, then the
multiplication is finished and we move to state 15.
 If the cell to the left of b has an a in it, we go to state
16.
 Here we move leftward through the a's till we find the
first Δ A, then right one cell to the next a to be erased.
Changing this a to a Δ.
 We repeat the process of copying the second factor into
the Δ's after the # and a's by returning to state 8.
 When we get to state 15 we have the simple job left of
erasing the now useless second factor:
45
Multiplication

 Going to state 18 we change the # into an a so we must


later erase the end a.
 Using states 18 and 19, we find the end a and erase it.
 In state 20 we go back down the TAPE to the left to see
if there are more A's in front of the answer.
 If so, we make one an a and go back to state 18.
 If not, we encounter the b in cell i and we halt.
 This completes the machine MPY.
46
Recursively Enumerable
Languages
The TM Language
 The languages accepted by FAs are REGULAR.
 The languages accepted by PDAs are context free.
 The languages accepted by TMs are Recursively
Enumerable.
 A Turing machine is a little different from the previous
machines in that there are some words that are neither
accepted nor crash, namely, those that cause the
machine to loop around a circuit forever.
 These forever-looping words create a new kind of
problem.
 We can break the set of all finite strings over ∑ into
three disjoint sets:

48
Recursively Enumerable Language
 A language L over the alphabet Σ is called recursively
enumerable if there is a Turing machine T that accepts
every word in L and either rejects or loops for every
word in the language L', that is the complement of L
(every word in ∑* not in L).

 The TM on next slide accepts the language L =


{anbnan} and loops or rejects all words not in L.
Therefore {anbnan} is recursively enumerable.

49
Example

50
Recursive Language
 A language L over the alphabet ∑ is called recursive if
there is a Turing machine T that accepts every word in
L and rejects every word in L', that is,

 The following TM accepts the language of all words


over {a,b} that start with a and crashes on (rejects) all
words that do not. Therefore, this language is recursive

 It is obvious that every recursive language is also


recursively enumerable, because the TM for the
recursive language can be used to satisfy both
definitions.

51
Recursive Language
 However, there are some languages that are r.e. but not
recursive.
 This means that every TM that accepts these languages
must have some words on which it loops forever.

52
Encoding of Turing Machines
 Turing machines do seem to have immense power as
language acceptors or language recognizers, yet there
are some languages that are not accepted by any TM,
as we shall soon prove.
 First, we need to develop the idea of encoding TM.
 We can make a TM into a summary table and run
words on the table as we did with PDA's.
 We fix the halt state as state # 2 and starting state as 1.

53
Example of Summary Table

54
Encoding of Turing Machines
 We now introduce a coding whereby we can turn any
row of the TM into a string of a's and b's.
 Consider the general row

 Here X1, and X2 are numbers, X3 and X4 are characters


from {a,b,#} or Δ, and X5 is a direction (either L or R).
 We start by encoding the information X1 and X2 as:
aXlbaX2b which means a string of a's of length X1,
concatenated to a b concatenated to a string of a's X2
long concatenated to a b.
 This is a word in the language defined by a+ba+b.

55
Encoding of Turing Machines
 Next X3 and X4 are encoded by this table

 Next we encode X5 as follows.

56
Encoding of Turing Machines
 Finally, we assemble the pieces by concatenating them
into one string. For example, the row

becomes

57
Encoding of Turing Machines
 Every string of a's and b's that is a row is of the form
definable by the regular expression:

 It is also true that every word defined by this regular


expression can be interpreted as a row of a TM
summary table with one exception: We cannot leave a
HALT state. This means that defines
a forbidden sub-language.

58
Complete Example
 The summary table shown above can be made into a
string of a's and b‘s as follows:

 One one-word code for the whole machine is:


ababababbabaaabaaabbaaabaaabaaabaaaabaabbaaba
 This is not the only one-word code for this machine
since the order of the rows in the table is not rigid.
 Let us also not forget that there are many other
methods for encoding TM's, but ours is good enough.
59
Complete Example
 It is also important to observe that we can look at such
a long string and decode the TM from it provided that
the string is in the proper form
 That is, as long as the string is a word in the Code
Word Language (CWL, the coding scheme we have
defined).

 Right Now, we are not considering the Halt-leaving


states
 The algorithm for decoding is provided in next slide

60
 That is how we decode it

61
Complete Example
 Decoding

62

You might also like