0% found this document useful (0 votes)
134 views52 pages

Ch.4 Turing Machines

This document discusses Turing machines (TM), a model of computation that is more powerful than finite automata and pushdown automata. A TM has a finite control, tape divided into squares, and read/write head. At each step, the control reads the tape symbol and either writes a new symbol, moves the head, or halts. TMs can recognize languages that other models cannot. The document defines the formal components of a TM and how they operate. It also introduces graphical notation for representing TMs and combining simple machines to perform computations like language recognition. TMs are able to simulate any real-world computer, making them a universal model of computation.

Uploaded by

Rishab Jain
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)
134 views52 pages

Ch.4 Turing Machines

This document discusses Turing machines (TM), a model of computation that is more powerful than finite automata and pushdown automata. A TM has a finite control, tape divided into squares, and read/write head. At each step, the control reads the tape symbol and either writes a new symbol, moves the head, or halts. TMs can recognize languages that other models cannot. The document defines the formal components of a TM and how they operate. It also introduces graphical notation for representing TMs and combining simple machines to perform computations like language recognition. TMs are able to simulate any real-world computer, making them a universal model of computation.

Uploaded by

Rishab Jain
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/ 52

Theory of Computation

(CS C351 / CS F351)

BITS Pilani Dr.R.Gururaj


CS&IS Dept.
Hyderabad Campus
Turing Machines (Ch.4)

BITS Pilani, Hyderabad Campus


Introduction

• Neither FA nor PDA can be regarded as


truly general models for computers.
• Because they can not recognize some
languages.
• FA can not recognize L={anbn :n≥0}
• PDA can not recognize L={anbncn :n≥0}

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
• Here we study a new device which can
recognize these and many more complicated
languages.
• These machines are called Turing Machines,
named after the inventor
Allan Turing(1912-54).
• These are more general than automata we
studied earlier.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
The basic appearance is similar to that of
automata.

A Turing Machine consists of the following.


 Finite Control
 A Tape
 A R/W head

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
• The formal definition of a TM and their
operations are in the same mathematical
style as those used for FA and PDA.
• TM is not simply one more class of
automata to be replaced by a more
powerful type.
• We see that as primitive as TM seem to
be, attempts to strengthen them do not
have any effect.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Ex: Even we augment this TM model with
RA memory like what we have in any
computer will not increase the power of a
TM.
• So any fancier machine can be converted
into a TM with analogous functionality.
• Hence any computation carried out by a
fancier machine can be actually be carried
out by a TM.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Hence the TM seem to form a stable and maximal
class of computational devices, in terms of
computations they can perform.

The criteria to be satisfied by a TM:


• They should be automata: That is their
construction and functionality should be in the
same general spirit of the devices studied earlier.
• They should be as simple as possible to describe,
define and reason about.
• They should be as general as possible in terms of
the computations they carry out.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
• TM has : Finite control, Tape, and a R/W
head

• A Finite control operates in discrete steps.

• At each step it performs two functions in a


way that depends on its current state and
the tape symbol currently scanned by the
R/W head.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
1. Put the Finite Control in a new state.
2. Either
(a) Write a symbol in the tape square currently
scanned, i.e., replacing the one that is already
there.
Or
(b) Move the head one tape square to the left or right.

Note: The tape has a left end but no right end (extends
infinitely).
To prevent the machine moving its head off the left end,
we assume that the left most end/cell of the tape is
marked with a special symbol.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
• All the TMs are so designed that, when the head
reads ∆ it immediately moves to the right.
• We use distinct symbols  , and  to denote
head movements. We also assume that the two
symbols are not part of any alphabet.
• We give input to the TM by inscribing the string
on the tape.
• The rest of the tape is initially contains blanks
denoted by U.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
• The machine is free to alter its input in any
way as it needs.
• It can also write on the blank portion of the
tape to the right.
• The RW head can move by only one
square to the left or right at a time.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Formal definition

A Turing Machine is a quintuple- ( K, ∑ , δ, s, H )

K is a finite set of states


∑ is an alphabet (containing blank symbol and
left end marker but not  and .
s€ K is the initial state
H subset of K is the set of halting states
δ is the transition function from (K-H) X ∑ 
KX(∑ U{, })
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
δ is the transition function from (K-H) X ∑  KX(∑ U{, })

Such that

(a) For all q€ K-H, if δ(q,∆)= (p,b) then b=

(b) For all q€ K-H, and a€∑, if δ(q,a)= (p,b) then b≠∆

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
If q € K-H, and a€∑, and δ(q,a)= (p,b) then then M when in
state q and scanning symbol a, will enter state p, and
(1) If b is symbol in ∑, M will rewrite currently scanned symbol a
with b.
or
(2) If b is  or , M will move its in the direction of b

The operations will stop only when it enters a halt state.

Notice that whenever it sees the left end marker it immediately


moves to the right.

Hence the left end marker is never erased.


CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Notation for TMs

• The TMs we have seen so far have been


extremely simple.
• Their tabular form is more complex and
hard to interpret. Hence we need some
graphical representation to manage the
complexity.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
• We shall adopt a notation similar to that of
the automata we have seen earlier (states
and arrows representing the transitions).
• Here in this case things that are joined are
TMs themselves.
• In other terms we use a hierarchical
notation, in which more complex machines
are built from simpler machines.
• We shall define a set of basic machines
and rules to combine them.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Symbol-writing machines:
Head-moving machines:
alphabet a € (∑ U{, } – {∆})
Ma= ({s,h}, ∑, δ, s, {h})
Where for each b € ∑– {∆} , δ(s,b)= (h,a)
δ(s,∆) is still (s,)
Only thing this machine does is to perform action a-
writing a if a € ∑ , moving in the direction indicated
by a if a € {,} and then to immediate halt.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
We abbreviate symbol-writing machine Ma with a

That is if a € ∑ , a-writing machine will be simply


denoted by a

We abbreviate head-moving machine M with L

We abbreviate head-moving machine M with R

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Rules for combining machines

Individual machines are like states of a finite


automaton.
And the machines may be connected to each other
in the way that the states of a automaton are
connected to each other.
The connection from one machine to the other is
not pursued until the first machine halts; the other
machine is then started from its initial state with
the tape and head positions as they are left by the
prev machine.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
That is if a € ∑ , a-writing machine will be simply
denoted by a

We abbreviate head-moving machine M with L

We abbreviate head-moving machine M with R

BITS Pilani, Hyderabad Campus


Computing Machines

So far we have seen only how a TM works, without


much indication about how it can be used for
performing computations

Ex: recognizing a language.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
We fix some conventions for the use of TMs:
1. The input string, with no blanks in it, is written
to the right of the leftmost symbol ∆, with a
blank to its left and a blank to its right.
2. The head is positioned at the tape square
containing the blank between ∆ and the input.
3. The machine starts operating in its initial state.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Ex: If M= ( K, ∑ , δ, s, H ) is a TM
and w€ (∑ - {U, , ∆})
Then initial configuration= (s, ∆Uw)

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Let M= ( K, ∑ , δ, s, H ) be a TM such that H={y, n}
consists of two distinguished halting states
(y for “yes”, and n for “no”)
Any configuration whose state component is y is
called as an accepting configuration.
A halting configuration whose state component n is
called a rejecting configuration.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
We say that M accepts string w€ (∑ - {U, , ∆})*
If (s, ∆Uw) yields an accepting configuration

We say that M rejects string w € (∑ - {U, , ∆})*


If (s, ∆Uw) yields a rejecting configuration

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
The Turing Machine M decides a language L
1. if it accepts or
2. Rejects it
That is a TM decides a language L if, when started
with input w, it always halts
No guarantees are given about wrong input.
A language L is recursive if there is a TM that
decides it.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
L={anbncn: n≥0}

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Let M= ( K, ∑ , δ, s, {h} ) be a TM,
∑0 subset of (∑ - {U, , ∆}) be an alphabet let w€ ∑0 *

Suppose M halts on input w,


and that (s, ∆Uw) → *M (h, ∆Uy); for some y € ∑0 *

Then y is called as output of M on w as input.


This is denoted by M(w)
M(w) is defined only if M halts on w
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
We say that M computes function f if, for all w€ ∑0 *
M(w) = f(w)
When machine halts it contains the string on the
tape ∆Uf(w)

A function f is called recursive if there is a TM M


that computes f.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Let M= ( K, ∑ , δ, s, {h} ) be a TM,
∑0 subset of (∑ - {U, , ∆}) be an alphabet
And let L is subset of ∑0 *
We say that M semidecisde L if for any w€ ∑0 *
if and only if M halts on input w.
A language L is recursively enumerable if and only if
there is a TM M that semidecides L.
If a L is recursive, then it is also recursively enumerable.
If a L is recursive, then it is complement is also.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Extensions of the Turing
Machine
It is clear that Turing machines can perform fairly
powerful computations.
We shall consider the effect of extending the TM
model in various directions.
We shall see that in each case the additional
features do not add to the classes of computable
functions or decidable languages : the “new,
improved model” of the TM in each instance be
simulated by the standard model.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Turing Machines with multiple
tapes
We can think of a TMs that have several tapes.
Each tape is connected to the finite control by
means of a R/W head( one on each tape).
The machine can in one step read the symbols
scanned by all its heads and then depending on
those symbols and its current state, write some of
those scanned squares and move some of heads to
the right or left, in addition to changing state.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
For any fixed integer k≥1, a k-tape Turing machine is
a Turing machine equipped as above with k tapes
and with corresponding heads.
Thus a standard TM with single tape can be seen as
a k-tape TM, where k=1.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Let M= ( K, ∑ , δ, s, H) be a k-tape TM, where k≥1
Where
K, ∑, s, and H have as in the definition of the
ordinary TM, and δ, transition function is a function
from
(K-H) X ∑k  KX(∑ U{, })k
Ex: δ(q, (a1,.., ak))= (p, (b1,.., bk))

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Ex: to transform ∆UwU into ∆UwUwU
1. Move the heads on both tapes to the right, copying
each symbol on the first tape onto the second tape,
until a blank is found on the first tape. The square of
the second tape should be left blank.
2. Move the head on the second tape to the left until a
blank is found.
3. Again move the heads on both tapes to the right, this
time copying symbols from the second tape onto the
first one.
4. Halt when a blank is found on the second tape.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Two-way infinite tapes

We can think of a TM that has a tape which is


infinite on both directions. All squares are initially
blank, except of those containing input.
The head is initially to the left of the input.
Hence the convention of left end marked is
meaningless here.
Still this fancy machine with multiple tapes do not
add substantial power to TMs. And can be
simulated by standard basic TM.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Multiple heads

What if we have one single tape with multiple


heads.
In one step, the heads all sense the scanned
symbols and move or write independently.
The issue is what if two heads scan and try to write
two different symbols on to a tape square. Some
convention need to used there to address this.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Two-dimensional tape

Another organization is that a TM has type as a


infinite 2D grid.
Such a device could be much more useful than the
standard one in solving puzzles.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
summary

Any language decided or


semidecided, and any function
computed by TM with several tapes,
heads, two-way infinite tapes, or
multi-dimensional tapes, can be
decided, semidecided, or computed,
respectively by a standard TM.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Random Access Turing
Machines
All the TMs which we have seen so far have quite
limiting common feature – their memory is
sequential.
In contrast real computers have random access
memories, each element of which can be accessed
in a single step, if appropriately addressed.
What could happen if we equip our TMs with
registers, capable of storing and manipulating the
addresses of tape squares.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
R3
k
Program counter
R2

R1

T[0] T[1] T[2] T[3]


R0

Registers

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Random Access Turing
Machines
1. A RATM has a fixed number of registers and one-
way infinite tape (memory).
2. Each register and each tape square is capable of
containing an arbitrary natural number.
3. The TM acts on its tape squares and registers as
dictated by a fixed program- the analog of the
transition function of ordinary TMs.
4. The program of a RATM is a sequence of
instructions.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
5. Initially the register values are 0, the program counter is
k =1, and the tape content encode the input string.
6. Then the machine executes the first instruction of its
program. This will change the contents of the registers
or of the tape squares, the value of program counter k,
an integer indicating the next instruction to be
executed.
7. Register R0 is an accumulator
8. This will continue until halt instruction is executed.
9. When halt is executed, then the k=0

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Kind of instructions allowed are

Instruction Operand Semantics


read j R0 :=T[Rj]
write j T[Rj] :=R0
store j Rj:= R0
load j R0:= Rj
load =c R0 = c
add j R0:= R0 + Rj
add =c R0:= R0 + c
sub j R0:= max{R0 - Rj , 0}
sub =c R0:= max{R0 - c , 0}
half R0:= floor[R0 / 2]
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
instructions cntd..

Instruction Operand Semantics


jump s k=:=s
jpos s If R0 > 0 then k:=s
jzero s If R0 = 0 then k:=s
halt j k=0

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Description
The description of a RA TM is a pair

M= (K, ∏), where k>0, is the number of registers and


∏ = (π1 , π2 , …, πp ), the program, is a finite sequence of
instructions. The last instruction πp

The configuration of RATM M= M= (K, ∏), is a K+2 tuple,

(k, R0, , R1 , … , RK-1, T)


For halted configuration, k=0.
CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Description
T is the tape contents, is a finite set of pairs of positive
integers – that is (i, m) € T means that the ith tape square,
currently contains the integer m>0. All other tape squares
not appearing as the first component of a pair in T are
assumed to contain 0.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Non-deterministic Turing
Machines
Another important feature of TM is non-determinism.
In case of FA, it is allowed to act non-deterministically,
without increase in it power.
But the non-deterministic PDA are more powerful than
deterministic ones.
We can also imagine Turing machines that act
non-deterministically.
Such machines might have, on certain combination of state
and scanned symbol, more than one possible choice of
behavior.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Non-deterministic Turing
Machines
A deterministic TM is ( K, ∑ , δ, s, H )
Where δ is a function from (K-H) X ∑ to KX(∑ U{, })
A non-deterministic Turing machine is a quintuple
M= ( K, ∑ , ∆, s, H ) where K, ∑ ,s, and H are as for
standard TM
∆ is subset of
((K-H) X ∑ ) X (KX(∑ U{, }))

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Grammars (Unrestricted
Grammars)
The class of language generated by Grammars is precisely
the class of recursively enumerable ones.
A language is generated by a Grammar if and only if it is
recursively enumerable.
The left-hand side of a rule may consist of more than one
NT with terminals; but at least with on NT
Final product is a string of terminals.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus
Grammars (Unrestricted
Grammars)
The class of language generated by Grammars is precisely
the class of recursively enumerable ones.
A language is generated by a Grammar if and only if it is
recursively enumerable.
The left-hand side of a rule may consist of more than one
NT with terminals; but at least with on NT
Final product is a string of terminals.

CSC / CSF 351 Theory of Computation Dr.R.Gururaj BITS Pilani, Hyderabad Campus

You might also like