0% found this document useful (0 votes)
24 views70 pages

Chapter 5 TuM

The document discusses Turing machines, a powerful model of computation invented by Alan Turing in 1936, which can simulate any modern computer and accept Recursive Enumerable Languages. It outlines the components, functions, and operations of Turing machines, including their infinite tape and ability to manipulate symbols, as well as comparing them to finite automata. Additionally, it provides examples of Turing machines designed to accept specific languages, illustrating their functionality and decision-making processes.

Uploaded by

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

Chapter 5 TuM

The document discusses Turing machines, a powerful model of computation invented by Alan Turing in 1936, which can simulate any modern computer and accept Recursive Enumerable Languages. It outlines the components, functions, and operations of Turing machines, including their infinite tape and ability to manipulate symbols, as well as comparing them to finite automata. Additionally, it provides examples of Turing machines designed to accept specific languages, illustrating their functionality and decision-making processes.

Uploaded by

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

Turing Machine

Chapter 5
Lecture 8
Contents
Models of computing
 DFA - regular languages
 Push down automata - Context-free
 Bounded Turing M’s - Context sensitive
 Turing machines - Phrase-structure
Introduction
 Turing machine was invented in 1936 by Alan Turing. It is an
accepting device which accepts Recursive Enumerable Language.
 There are various features of the Turing machine:
 It has an external memory which remembers arbitrary long sequence of
input.
 It has unlimited memory capability.
 The model has a facility by which the input at left or right on the tape can
be read easily.
 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.
Turing Machines
are…
 Very powerful (abstract) machines that could simulate any
modern day computer (although very, very slowly!)
 A TM is a mathematical model of computation describing an
abstract machine that manipulates symbols on a strip of tape
according to a table of rules. Despite the model's simplicity, it
is capable of implementing any computer algorithm.
 Why design such a machine?
 If a problem cannot be “solved” even using a TM, then it
implies that the problem is undecidable For every input,
answer YES or NO

 Computability vs. Decidability


A Turing machine
...... Tape ......
Control Unit Read-Write head
• Finite control, i.e., a program,
containing the position of the
read head, current symbol
being scanned, and the current
state.
• In one move, depending on the
current state and the current
symbol being scanned, the TM
1) changes state, 2) prints a
symbol over the cell being
scanned, and 3) moves its’ tape
head one cell left or right.
• Many modifications possible, but Church-Turing declares equivalence of all.
Cont…
No boundaries -- infinite length
...... ......

• Two-way, infinite tape, broken into cells,


Read-Write head each containing one symbol.
• Two-way, read/write tape head.
• An input string is placed on the tape,
The head at each time step: padded to the left and right infinitely with
1. Reads a symbol blanks, read/write head is positioned at the
left end of input string.
2. Writes a symbol
3. Moves Left or Right
TM Vs Finite Automata
1. A TM can both write on the tape and read from it; a FA can
only read its input
2. The read/write head of a TM can move both to the left and
to the right; a FA can move in one direction only
3. The tape of a TM is infinite; the input of a FA is finite
4. The special states of a TM for rejecting and accepting the
input take immediate effect; FA terminates when input is
entirely
Turing machine
Formal definition of TM

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. Q x Γ –> Q x Γ x {L,R}
M = (Q, Σ, Γ, δ, q0, B, F)
The Transition Function
 Takes two arguments:
1. A state, in Q.
2. A tape symbol in Γ.
 δ(q, Z) is either undefined or a triple of the form (p, Y, D).
 p is a state.
 Y is the new tape symbol.
 D is a direction, L or R.

 If δ(q, Z) = (p, Y, D) then, in state q, scanning Z under its


tape head, the TM:
1. Changes the state to p.
2. Replaces Z by Y on the tape.
3. Moves the head one square in direction D.
 D = L: move left; D = R; move right.
States & Transitions

Transition function
Write Move Left
Read

q1 a  b, L q2

q1 a  b, R q2
 (q1, a ) (q2 , b, R )
Turing machine ….General
Input alphabet Tape alphabet

States

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

Final states
Transition function

Initial state blank


Example

Turing machine for the language {a nb n }

q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L
y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R
Time 0  a a b b  

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

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

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

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

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

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

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

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

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

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

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

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

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

q4
Halt & Accept
q4 y  y, R y  y, L
y  y, R a  a, R a  a, L
  , L

y  y, R a  x, R b  y, L
q3 q0 q1 q2
x  x, R
ID of a TM
 Instantaneous Description or ID :
 X1X2…Xi-1qXiXi+1…Xn
means:
 q is the current state
 Tape head is pointing to Xi
 X1X2…Xi-1XiXi+1…Xn are the current tape symbols

 (q,Xi) = (p,Y,R) is same as:


X1…Xi-1qXi…Xn |---- X1…Xi-1YpXi+1…Xn
 (q,Xi) = (p,Y,L) is same as:
X1…Xi-1qXi…Xn |---- X1…pXi-1YXi+1…Xn
Cont…
 The particular input “aabb” gives the following
successive instantaneous descriptions for above
example.
 q0aabb├ Xq1abb ├ Xaq1bb ├ Xq2aYb ├Xq0aYb ├ XXq1Yb
├ XXYq1b ├ XXq2YY ├ Xq2XYY
 ├XXq0YY├XXYq3Y├XXYq3Y├XXYYq3B ├ XXYYBq4B
Language Accepted by TM
• 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 TM 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.
States a b Δ

q0 (q1, A, R) – –
q1 – (q2, B, R) –
q2 (q3, A, R) – –
q3 – – (q4, Δ, S)
q4 – – –
Examples
1. Construct a TM for the language L = {0n1n2n} where n≥1
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:

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:

• 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
TM can be represented by Transition Diagram:
Example 3
3. Construct a Turing Machine accepting a language of palindrome
over {a,b}* with each string of even length.
The TM scans the first symbol of input tape (a or b), erases , that is replaces it with
Blank symbol B and changes state (q1, or q2).
TM scans the remaining part without changing the tape symbol until it encounters
blank symbol B. Then the read write head moves to the left. If the rightmost symbol
tallies with the leftmost symbol (Which can be erased but remembered), the
rightmost symbol is erased otherwise TM halts. The read write head moves to the
left until blank B is encountered. The above steps are repeated after changing the
states suitably.
The Transition functions are as shown below:

δ(q0,a) = (q1,B, R),


δ(q5,B) = (q0,B,R),
δ(q0,b) = (q2,B, R),
δ(q4,b) = (q6,B,L),
δ(q1,a) = (q1,a,R),
δ(q6,a) = (q6,a,L),
δ(q1,b) = (q1,b,R),
δ(q6,b) = (q6,b,L),
δ(q1,B) = (q3,B,L),
δ(q6,B) = (q0,B,R),
δ(q2,a) = (q2,a,R),
δ(q0,B) = (q7,B,R),
δ(q2,b) = (q2,b,R),
δ(q2,B) = (q4,B,L),
δ(q3,a) = (q5,B,L),
δ(q5,a) = (q5,a,L),
δ(q5,b) = (q5,b,L),
L=wwr………….method 2
Example 4
Construct a Turing Machine for language L = {02n1n | n>=0}

The language L = {02n1n | n >= 0} represents a kind of language where we use


only 2 symbols, i.e., 0 and 1. In the beginning language has some number of
0’s followed by exactly half number of 1’s . Any such string which falls in
this category will be accepted by this language.

Idea:
The tape head reads the leftmost symbol of w, which is 0 and makes is blank
then the next left most 0 is made blank after this we traverse to the rightmost 1
of the string and make it blank. In nth is way we have reduced the string to 0 2n-
1 .If the string belongs to language L then at end empty string will be left and
2 n-1

hence gets accepted by the machine.


Meanings of symbols used:
R, L – direction of movement of one unit on either side.
B-Blank.
0, 1 – symbols whose combination string is to be tested.
Example 5

Turing Machine for L={ an b2n, input (a, b) *}


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

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


Acceptance
• When a Turing machine T operates on an input string S, there
are three outcomes, these are;
• It halts and accepts the string.
• It halts and rejects the string.
• Never halts, proceeds infinitely.
Accept Input If machine halts
in a final state
If machine halts
in a non-final state
Reject Input or
If machine enters
an infinite loop
Example
A Turing machine that accepts the language:
a*
a  a, R

  , L
q0 q1
Time 0   a a a  

q0
a  a, R

  , L
q0 q1

50
Time 1   a a a  

q0
a  a, R

  , L
q0 q1

51
Time 2   a a a  

q0
a  a, R

  , L
q0 q1

52
Time 3   a a a  

q0
a  a, R

  , L
q0 q1

53
Time 4   a a a  

q1
a  a, R Halt & Accept

  , L
q0 q1
Rejection Example

Time 0   a b a  

q0
a  a, R

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

q0
No possible Transition

Halt & Reject


a  a, R

  , L
q0 q1
Infinite Loop Example
b  b, L
a  a, R

  , L
q0 q1
Time 0   a b a  

q0
b  b, L
a  a, R

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

q0
b  b, L
a  a, R

  , L
q0 q1

59
Time 2   a b a  

q0
b  b, L
a  a, R

  , L
q0 q1

60
Turing Decidable & Acceptable
• When we talk about Turing machines (TM) it could accept the
input, reject it or keep computing which is called loop.
• A Language is recognizable if and only if a TM accepts the
string, when the provided input lies in the language.
• Also, a language can be recognizable if the TM either terminates
and rejects the string or doesn't terminate at all. This means that
the TM continues with the computing when the provided input
doesn't lie in the language.(i.e. there is no requirement that the
TM should halt for strings not in the language.)
• The language is decidable if and only if there is a machine
which accepts the string when the provided input lies in that
language and rejects the string when provided input doesn't lie
in that language.
• Assume: TM has accepting state qacc
acc
and rejecting state qrej
rej
.

• Definition: TM M recognizes language L provided that


L = { w | M on w reaches qacc
acc
} = { w | M accepts w }.
Gen. Definition: TM M decides language L provided that both of
the following hold:
– On every w, M eventually reaches either qacc or qrej.
– L = { w | M on w reaches qacc }.
Thus, if M recognizes L, then: Whereas if M decides L,
– Words in L lead to qacc
acc
. then:
– Words not in L either lead to qrej or – Words in L lead to qacc
acc.
rej
never halt (“loop”). – Words not in L lead to
qrej
rej. Always halts
Undecidable problems
• The problems for which we can’t construct an algorithm that
can answer the problem correctly in the infinite time are
termed as Undecidable Problems in the theory of computation
(TOC)
• A problem is undecidable if there is no Turing machine that
will always halt an infinite amount of time to answer as ‘yes’
or ‘no’.
• Halting Problem: The Halting problem is the most famous of
the undecidable problems.
Consider the code
num=1;
while(num=0)
{ num=num+1;
}
Variations of Turing
Machines

64
Generic description
TMs with storage Will work for both a=0 and a=1

 E.g., TM for 01* + 10*


Current Tape Next
Current Storage symbol
symbol
state New
state
Storage
symbol
q Transition function :
storage
• ([q0,B],a) = ([q1,a], a, R)

Tape head • ([q1,a],a) = ([q1,a], a, R)

B B 0 1 1 1 1 1 B B … • ([q1,a],B) = ([q2,B], B, R)

Are the standard TMs Yes


[q,a]: where q is current state, equivalent to TMs with storage? 65

a is the symbol in storage


Multi-track Turing
Machines
 TM with multiple tracks, but just one unified tape
head
control
One tape head to read
k symbols from the k tracks
at one step.

Track 1 … …

… …
Track 2

Track k … …
Multi-Track TMs……Cont…
 TM with multiple “tracks” but just one head

E.g., TM for {wcw | w {0,1}* }


but w/o modifying original input string

BEFORE AFTER
control control

Tape head Tape head

… B B 0 1 0 c 0 1 0 B … Track 1 … B B 0 1 0 c 0 1 0 B …Track 1
… B B B B B B B B B B … Track 2 B B X X X c Y Y Y B …Track 2

Second track mainly used as a scratch space for marking


Multi-tape Turing
Machines
 TM with multiple tapes, each tape with a separate head
 Each head can move independently of the others

control

k separate heads

Tape 1 … …

… …
Tape 2

Tape k … …
Non-deterministic TMs
 A non-deterministic Turing machine has a single, one-way
infinite tape.
 For a given state and input symbol has at least one choice to
move (finite number of choices for the next move), each
choice has several choices of the path that it might follow for a
given input string.
 A non-deterministic Turing machine is equivalent to the
deterministic Turing machine.
Summary
 TMs == Recursively Enumerable languages
 TMs can be used as both:
 Language recognizers
 Calculators/computers
 Basic TM is equivalent to all the below:
1. TM + storage
2. Multi-track TM
3. Multi-tape TM
4. Non-deterministic TM
 TMs are like universal computing machines with
unbounded storage

You might also like