0% found this document useful (0 votes)
33 views33 pages

Unit - 4 Notes

Uploaded by

vasu32483
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)
33 views33 pages

Unit - 4 Notes

Uploaded by

vasu32483
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/ 33

Turing Machine

Turing machine was invented in 1936 by Alan Turing. It is an accepting device


which accepts Recursive Enumerable Language generated by type 0 grammar.

There are various features of the Turing machine:

1. It has an external memory which remembers arbitrary long sequence of input.


2. It has unlimited memory capability.
3. The model has a facility by which the input at left or right on the tape can be read
easily.
4. The machine can produce a certain output based on its input. Sometimes it may
be required that the same input has to be used to generate the output. So in this
machine, the distinction between input and output has been removed. Thus a
common set of alphabets can be used for the Turing machine.

Formal definition of Turing machine


A Turing machine can be defined as a collection of 7 components:

Q: the finite set of states


∑: the finite set of input symbols
T: the tape symbol
q0: the initial state
F: a set of final states
B: a blank symbol used as a end marker for input
δ: a transition or mapping function.

The mapping function shows the mapping from states of finite automata and
input symbol on the tape to the next states, external symbols and the direction
for moving the tape head. This is known as a triple or a program for turing
machine.

​ (q0, a) → (q1, A, R)
That means in q0 state, if we read symbol 'a' then it will go to state q1, replaced a
by X and move ahead right(R stands for right).

Example:
Construct TM for the language L ={0n1n} where n>=1.

Solution:
We have already solved this problem by PDA. In PDA, we have a stack to
remember the previous symbol. The main advantage of the Turing machine is
we have a tape head which can be moved forward or backward, and the input
tape can be scanned.

The simple logic which we will apply is read out each '0' mark it by A and then
move ahead along with the input tape and find out 1 convert it to B. Now, repeat
this process for all a's and b's.

Now we will see how this turing machine work for 0011.

The simulation for 0011 can be shown as below:

Now, we will see how this turing machine will works for 0011. Initially, state is q0
and head points to 0 as:

The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0
by A and head will move to the right as:

The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol,
remain in the same state and move to the right as:

The move will be δ(q1, 1) = δ(q2, B, L) which means it will go to state q2, replaced 1
by B and head will move to left as:
Advertisement

Now move will be δ(q2, 0) = δ(q2, 0, L) which means it will not change any symbol,
remain in the same state and move to left as:

The move will be δ(q2, A) = δ(q0, A, R), it means will go to state q0, replaced A by A
and head will move to the right as:

The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0
by A, and head will move to right as:

The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol,
remain in the same state and move to right as:

The move will be δ(q1, 1) = δ(q2, B, L) which means it will go to state q2, replaced 1
by B and head will move to left as:
The move δ(q2, B) = (q2, B, L) which means it will not change any symbol, remain
in the same state and move to left as:

Now immediately before B is A that means all the 0?s are market by A. So we will
move right to ensure that no 1 is present. The move will be δ(q2, A) = (q0, A, R)
which means it will go to state q0, will not change any symbol, and move to right
as:

The move δ(q0, B) = (q3, B, R) which means it will go to state q3, will not change
any symbol, and move to right as:

The move δ(q3, B) = (q3, B, R) which means it will not change any symbol, remain
in the same state and move to right as:

The move δ(q3, Δ) = (q4, Δ, R) which means it will go to state q4 which is the HALT
state and HALT state is always an accept state for any TM.
The same TM can be represented by Transition Diagram:

Basic Model of Turing machine


The turning machine can be modelled with the help of the following
representation.

1. The input tape is having an infinite number of cells, each cell containing one
input symbol and thus the input string can be placed on tape. The empty tape is
filled by blank characters.

2. The finite control and the tape head which is responsible for reading the
current input symbol. The tape head can move to left to right.

3. A finite set of states through which machine has to undergo.

4. Finite set of symbols called external symbols which are used in building the
logic of turing machine.

Language accepted by Turing machine


The turing machine accepts all the language even though they are recursively
enumerable. Recursive means repeating the same set of rules for any number of
times and enumerable means a list of elements. The TM also accepts the
computable functions, such as addition, multiplication, subtraction, division,
power function, and many more.

Example:
Construct a turing machine which accepts the language of aba over ∑ = {a, b}.

Solution:

We will assume that on input tape the string 'aba' is placed like this:

The tape head will read out the sequence up to the Δ characters. If the tape head
is readout 'aba' string then TM will halt after reading Δ.

Now, we will see how this turing machine will work for aba. Initially, state is q0
and head points to a as:

The move will be δ(q0, a) = δ(q1, A, R) which means it will go to state q1, replaced a
by A and head will move to right as:

The move will be δ(q1, b) = δ(q2, B, R) which means it will go to state q2, replaced
b by B and head will move to right as:
The move will be δ(q2, a) = δ(q3, A, R) which means it will go to state q3, replaced
a by A and head will move to right as:

The move δ(q3, Δ) = (q4, Δ, S) which means it will go to state q4 which is the HALT
state and HALT state is always an accept state for any TM.

The same TM can be represented by Transition Table:

States a b Δ

q0 (q1, A, R) – –

q1 – (q2, B, R) –

q2 (q3, A, R) – –

q3 – – (q4, Δ, S)

q4 – – –

The same TM can be represented by Transition Diagram:


Examples of TM
Example 1:
Construct a TM for the language L = {0n1n2n} where n≥1

Solution:

L = {0n1n2n | n≥1} represents language where we use only 3 character, i.e., 0, 1 and
2. In this, some number of 0's followed by an equal number of 1's and then
followed by an equal number of 2's. Any type of string which falls in this category
will be accepted by this language.

The simulation for 001122 can be shown as below:

Now, we will see how this Turing machine will work for 001122. Initially, state is q0
and head points to 0 as:

The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0
by A and head will move to the right as:
The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol,
remain in the same state and move to the right as:

The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1
by B and head will move to right as:

The move will be δ(q2, 1) = δ(q2, 1, R) which means it will not change any symbol,
remain in the same state and move to right as:

The move will be δ(q2, 2) = δ(q3, C, R) which means it will go to state q3, replaced
2 by C and head will move to right as:

Advertisement

Now move δ(q3, 2) = δ(q3, 2, L) and δ(q3, C) = δ(q3, C, L) and δ(q3, 1) = δ(q3, 1, L) and
δ(q3, B) = δ(q3, B, L) and δ(q3, 0) = δ(q3, 0, L), and then move δ(q3, A) = δ(q0, A, R), it
means will go to state q0, replaced A by A and head will move to right as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0
by A, and head will move to right as:

The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol,
remain in the same state and move to right as:

The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1
by B and head will move to right as:

The move will be δ(q2, C) = δ(q2, C, R) which means it will not change any symbol,
remain in the same state and move to right as:

The move will be δ(q2, 2) = δ(q3, C, L) which means it will go to state q3, replaced 2
by C and head will move to left until we reached A as:
immediately before B is A that means all the 0's are market by A. So we will move
right to ensure that no 1 or 2 is present. The move will be δ(q2, B) = (q4, B, R)
which means it will go to state q4, will not change any symbol, and move to right
as:

The move will be (q4, B) = δ(q4, B, R) and (q4, C) = δ(q4, C, R) which means it will
not change any symbol, remain in the same state and move to right as:

The move δ(q4, X) = (q5, X, R) which means it will go to state q5 which is the HALT
state and HALT state is always an accept state for any TM.

The same TM can be represented by Transition Diagram:


Example 2:
Construct a TM machine for checking the palindrome of the string of even
length.

Solution:

Firstly we read the first symbol from the left and then we compare it with the first
symbol from right to check whether it is the same.

Again we compare the second symbol from left with the second symbol from
right. We repeat this process for all the symbols. If we found any symbol not
matching, we cannot lead the machine to HALT state.

Suppose the string is ababbabaΔ. The simulation for ababbabaΔ can be shown
as follows:

Now, we will see how this Turing machine will work for ababbabaΔ. Initially, state
is q0 and head points to a as:
We will mark it by * and move to right end in search of a as:

We will move right up to Δ as:

We will move left and check if it is a:

It is 'a' so replace it by Δ and move left as:

Now move to left up to * as:

Move right and read it


Now convert b by * and move right as:

Move right up to Δ in search of b as:

Move left, if the symbol is b then convert it into Δ as:

Now move left until * as:

Replace a by * and move right up to Δ as:

We will move left and check if it is a, then replace it by Δ as:


It is 'a' so replace it by Δ as:

Now move left until *

Now move right as:

Replace b by * and move right up to Δ as:

Move left, if the left symbol is b, replace it by Δ as:

Move left till *


Move right and check whether it is Δ

Go to HALT state

The same TM can be represented by Transition Diagram:

Example 3:
Construct a TM machine for checking the palindrome of the string of odd length.
Solution:

Firstly we read the first symbol from left and then we compare it with the first
symbol from right to check whether it is the same.

Again we compare the second symbol from left with the second symbol from
right. We repeat this process for all the symbols. If we found any symbol not
matching, we lead the machine to HALT state.

Suppose the string is 00100Δ. The simulation for 00100Δ can be shown as follows:

Now, we will see how this Turing machine will work for 00100Δ. Initially, state is
q0 and head points to 0 as:

Now replace 0 by * and move right as:

Move right up to Δ as:

Move left and replace 0 by Δ and move left:

Now move left up to * as:


Move right, convert 0 by * and then move right as:

Moved right up to Δ

Move left and replace 0 by Δ as:

Move left till * as:

Move right and convert 1 to * as:

Move left
Since it is *, goto HALT state.

The same TM can be represented by Transition Diagram:

Example 4:
Construct TM for the addition function for the unary number system.

Solution:

The unary number is made up of only one character, i.e. The number 5 can be
written in unary number system as 11111. In this TM, we are going to perform the
addition of two unary numbers.

For example

2+3
i.e. 11 + 111 = 11111

If you observe this process of addition, you will find the resemblance with string
concatenation function.
In this case, we simply replace + by 1 and move ahead right for searching end of
the string we will convert last 1 to Δ.

Input: 3+2

The simulation for 111+11Δ can be shown as below:

Move right up to + sign as:

Convert + to 1 and move right as:

Now, move right

Again move right

Now Δ has encountered, so just move left as:


Convert 1 to Δ

Thus the tape now consists of the addition of two unary numbers.

The TM will look like as follows:

Here, we are implementing the function of f(a + b) = c. We assume a and b both


are non zero elements.

Example 5:
Construct a TM for subtraction of two unary numbers f(a-b) = c where a is always
greater than b.

Solution: Here we have certain assumptions as the first number is greater than
the second one. Let us assume that a = 3, b = 2, so the input tape will be:
We will move right to - symbol as perform reduction of a number of 1's from the
first number. Let us look at the simulation for understanding the logic:

Move right up to - as:

Move right and convert 1 to * as:

Now move left

Again move left

Convert 1 to * and move right-hand


Now move right till 1

Convert 1 to * and move left

Convert 1 to * and move

Move right till Δ as:

Now we are in the HALT state.

Thus we get 1 on the input tape as the answer for f(3-2).

The Turing machine will look like this:


Church’s Thesis for Turing Machine
In 1936, A method named as lambda-calculus was created by Alonzo
Church in which the Church numerals are well defined, i.e. the
encoding of natural numbers. Also in 1936, Turing machines (earlier
called theoretical model for machines) was created by Alan Turing,
that is used for manipulating the symbols of string with the help of
tape.

Church Turing Thesis :

Turing machine is defined as an abstract representation of a


computing device such as hardware in computers. Alan Turing
proposed Logical Computing Machines (LCMs), i.e. Turing’s
expressions for Turing Machines. This was done to define algorithms
properly. So, Church made a mechanical method named as ‘M’ for
manipulation of strings by using logic and mathematics. This
method M must pass the following statements:

● Number of instructions in M must be finite.


● Output should be produced after performing finite number
of steps.
● It should not be imaginary, i.e. can be made in real life.
● It should not require any complex understanding.

Using these statements Church proposed a hypothesis called

Church’s Turing thesis

that can be stated as: “The assumption that the intuitive notion of
computable functions can be identified with partial recursive
functions.”

Or in simple words we can say that “Every computation that can be


carried out in the real world can be effectively performed by a Turing
Machine.”

In 1930, this statement was first formulated by Alonzo Church and is


usually referred to as Church’s thesis, or the Church-Turing thesis.
However, this hypothesis cannot be proved. The recursive functions
can be computable after taking following assumptions:

1. Each and every function must be computable.


2. Let ‘F’ be the computable function and after performing
some elementary operations to ‘F’, it will transform a new
function ‘G’ then this function ‘G’ automatically becomes the
computable function.
3. If any functions that follow above two assumptions must be
states as computable function.
Universal Turing Machine
The UTM was associated with Alan Turing back in 1936. Being a
theoretical device, it is able to run any Turing machine on its tape, an
idea that represents general computation. The idea created an
awakening of what could be done computationally, algorithmically,
and by machines. Because a single machine can execute any
algorithm, the UTM truly models the heart of modern computing
systems and at the same time explores the boundaries of what can
be computed.

What is a Universal Turing Machine (UTM)?

A Universal Turing Machine can be defined as a theoretical


construction that can simulate the behavior of other machines. This
is done specifically by reading, apart from the input tape it simulates,
a description of how this very machine it is simulating would work,
and transition rules showing how it would respond to the input. This
gives the UTM the character of a general-purpose computational
device that can execute any arbitrary computable function. Universal
Turing machines have hence been taken to provide the means for
the Church-Turing thesis: anything computable can be computed by
a Turing machine. In this sense, the UTM is more properly considered
to be a universal interpreter that can run any algorithm specified by
another machine.
A Universal Turing Machine is a Turing Machine which when
supplied with an appropriate description of a Turing Machine M and
an input string w, can simulate the computation of w.

Universal Turing Machine

Construction of UTM

Without loss of generality, we assume the following for M:

● Q = {q1, q2, ….qn} where q1=initial state and q2=Final State


● τ = {σ1, σ2,,…σn} where σ represent blanks
● Select an encoding on which q1 is representable by 1, q2 by 11,
and so on.
● Similarly, σ1 is encoded as 1, σ2 as 11, etc.
● Finally, let us represent R/W head directions by 1 for L (Left)
and 11 for R(Right).
● The symbol 0 will be used as a separator between 1s.

With this scheme, any transition of M can be given as :


UTM Construction

Implementation of UTM

A UTM Mu then has an input alphabet = {0, 1} and the structure of a


multi-tape TM.

● Mu looks first at the contents of Tape 2 and Tape 3 to


determine the instantaneous description (ID) of M.
● It then consults Tape1 to see what M would do with this ID.
● Finally, Tape 2 and Tape 3 will be modified to reflect the
result of the move.
UTM Implementation

If no transition for a given ID is formed, Mu halts as M must:

● In either case, Mu behaves as M would.


● If M halts, when presented with string w then Mu will halt
when presented with the encoded M and the encoded string
on its tape.
● Moreover, the final string Mu .s tape will be the encoding of
the string.
● When M halts, Mu can tell if it is in the single accepting state
and so moves to an accepting state of its own ( or not).

Conclusion

The UTM in computer science was the conceptual basis, essentially a


theoretical framework upon which many conceptions about the
nature of computation were erected. This capability of the UTM to
simulate any computable process underlines a universality principle,
one that informs modern computer design and the study of
algorithms and complexity theory. As a matter of fact, even though
technology has advanced, UTM serves to this day as the basis for
modes of investigation into the limits of computation into areas such
as artificial intelligence and machine learning, among others. This
has remained relevant, shaping our understanding of current and
future computational systems.

Recursive and Recursive Enumerable Languages in TOC

Recursive Enumerable (RE) or Type -0 Language

RE languages or type-0 languages are generated by type-0


grammars. An RE language can be accepted or recognized by Turing
machine which means it will enter into final state for the strings of
language and may or may not enter into rejecting state for the
strings which are not part of the language. It means TM can loop
forever for the strings which are not a part of the language. RE
languages are also called as Turing recognizable languages.

Recursive Language (REC)

A recursive language (subset of RE) can be decided by Turing


machine which means it will enter into final state for the strings of
language and rejecting state for the strings which are not part of the
language. e.g.; L= {anbncn|n>=1} is recursive because we can
construct a turing machine which will move to final state if the string
is of the form anbncn else move to non-final state. So the TM will
always halt in this case. REC languages are also called as Turing
decidable languages. The relationship between RE and REC
languages can be shown in Figure 1.

Closure Properties of Recursive Languages


Union: If L1 and If L2 are two recursive languages, their union L1?L2
will also be recursive because if TM halts for L1 and halts for L2, it will
also halt for L1?L2.

Concatenation: If L1 and If L2 are two recursive languages, their


concatenation L1.L2 will also be recursive. For Example:

L1= {anbncn|n>=0}

L2= {dmemfm|m>=0}

L3= L1.L2

= {anbncndm emfm|m>=0 and n>=0} is also recursive.

L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s. L2


says m no. of d’s followed by m no. of e’s followed by m no. of f’s. Their
concatenation first matches no. of a’s, b’s and c’s and then matches
no. of d’s, e’s and f’s. So it can be decided by TM.

Kleene Closure: If L1is recursive, its kleene closure L1* will also be
recursive. For Example:

L1= {anbncn|n>=0}

L1*= { anbncn||n>=0}* is also recursive.

Intersection and complement: If L1 and If L2 are two recursive


languages, their intersection L1 ? L2 will also be recursive. For
Example:
L1= {anbncndm|n>=0 and m>=0}

L2= {anbncndn|n>=0 and m>=0}

L3=L1 ? L2

= { anbncndn |n>=0} will be recursive.

L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s and
then any no. of d’s. L2 says any no. of a’s followed by n no. of b’s
followed by n no. of c’s followed by n no. of d’s. Their intersection says
n no. of a’s followed by n no. of b’s followed by n no. of c’s followed by
n no. of d’s. So it can be decided by turing machine, hence recursive.

Similarly, complement of recursive language L1 which is ?*-L1, will


also be recursive.

Note: As opposed to REC languages, RE languages are not closed


under complementation which means complement of RE language
need not be RE.

You might also like