You are on page 1of 31

Theory of Computation (TOC)

GTU # 3160704

Unit – 5
Turing Machine

Prof. Dixita B. Kagathara


Computer Engineering Department
Darshan Institute of Engineering & Technology, Rajkot
dixita.kagathara@darshan.ac.in
+91 - 97277 47317 (CE Department)
Topics to be covered
 Looping
• What is Turing Machine?
• Formal Definition: Turing Machine
• Design of Turing Machine
• Universal Turing Machine
• Church Turing Thesis
Introduction to Turing
Machine
Introduction to Turing Machine
Finite Automata Pushdown Automata Turing Machine
 Input Strings  Input Strings  Input Strings
 Stack  Tape
a b a a
 Special symbol
I/p
Stack Accept |  Control portion
Control Reject
Δa b a a b Δ

TM Tape
Stack Head
PDA
Recursively enumerable
FA
Context language
free
language
Regular
language

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 4
Turing Machine
Δ b a ab b a Δ

Head

 The tape is capable of performing following three operations:


 Read a symbol above the tape head.
 Modify/Update a symbol above the tape head.
 Shifting either to previous square or next square.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 5
Turing Machine

2 3

1 4 Δ b a a b a Δ

Head
5 6

Tape

Control portion

Turing Machine = Control portion + Tape


Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 6
Turing Machine
 Operation to be performed by TM:
 Read a symbol above the tape head.
 Modify/Update a symbol above the tape head.
 Shifting either to previous square or next square.

Δ b a ab b a Δ

Head Some other Ex:


Update b | a, L
Read Shift (L or R or a | Δ, R
S)
a | b, R a | a, R
0 1
a | A, S

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 7
Definition: Turing Machine
 A Turing machine is a 5-tuple =( ,Σ,┌, 0,δ) where,

: is a finite set of states, assumed not to contain


ha (Acceptance State) and hr (Rejection State)
Σ : input Symbols

┌ : tape alphabets

0 : is initial state, is an element of Q

δ : is a transition function

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 8
Turing Machine Accepting ∗

L = {ab*a}
Tape
Strings accepting in given L are:
aa Δ a
A B
b a
A Δ
aba
abba
abbba
Δ aA B
b b
B aA Δ
Logic:
1. Read ‘a’, replace ‘a’ by ‘A’ (aA)
2. Read all ‘b’ one by one & replace it by ‘B’ (bB)
Δ Aa Aa Δ
if no ‘b’ found: SKIP step 2
3. Read ‘a’, replace ‘a’ by ‘A’ (aA)

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 9
Turing Machine Accepting ∗

Tape

Δ a
A B
b a
A Δ

b|B,R a|A,R
b|B,R b|B,R

Δ|Δ,R a|A,R a|A,R Δ|Δ,S


0 1 2 3 h

Control portion
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 10
Turing Machine Accepting { | ≥1 }
L = {anbn}
Strings accepting in given L are: Tape
ab
Δ a
A A
a B
b B
b Δ
aabb
aaabbb

Logic:
1. Read ‘a’, replace ‘a’ by ‘A’ (aA)
2. Move RIGHT to first ‘b’ Δ B b
aA aA Aa Bb b B Δ
if none : REJECT
3. Replace ‘b’ by ‘B’ (bB)
4. Move LEFT to leftmost ‘a’
5. Repeat the above steps until no more a’s
6. Make sure no more b’s remain.
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 11
Design a Turing machine for accepting { | ≥1 }

Δ A
a Aa bB B
b Δ

B/B,R B/B,L
a/a,R a/a,L

Δ/Δ,R a/A,R b/B,L


0 1 2 3

B/B,R
A/A,R
4

B/B,R
Δ/Δ,S

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 12
Turing Machine Accepting { | ≥0 }
a/a,R b/b,R C/C,L
B/B,R C/C,R a/a,L
b/B,R c/C,L b/b,L
Δ A a bB b
a A c C
B C c Δ 2 3 4
B/B,L

a/A,R A/A,R

Δ/Δ,R
0 1
Δ/Δ,S

h
B/B,R

5
C/C,R Δ/Δ,S

6
B/B,R
C/C,R
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 13
Turing Machine Accepting
Palindrome strings of E ven & O dd length
L = Palindrome string
Tape
Strings accepting in given L are:
aa Δ aΔ Δ
b Δ
b Δ
a Δ
bab Even Length
abba
babab
Δ bΔ Δ
a Δ
b Δ
a Δ
b Δ
Logic:
Odd Length
1. Read leftmost symbol , replace it with Δ
2. Keep moving to the right until the rightmost symbol,
If matched with leftmost symbol then replace it with Δ
Otherwise : REJECT the String
3. Repeat the above steps until no more symbol left in string.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 14
Turing Machine Accepting
Palindrome strings of E ven & O dd length
a/a,R
b/b,R Δ/Δ,R (odd pal)
Δ Δ
a Δ
b Δ
b Δ
a Δ
Δ/Δ,L
2 3

a/a,L
b/b,L
a/Δ,R a/Δ,L

Δ/Δ,R Δ/Δ,R
0 1 4 h

b/Δ,R b/Δ,L

Δ/Δ,L Δ/Δ,R
5 6
(odd pal)
a/a,R
b/b,R
Δ/Δ,R (even pal)

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 15
String Tracing
a/a,R
b/b,R Δ/Δ,R (odd pal)
├ (q0,△ a a)
├ (q1,△ a a) Δ/Δ,L
2 3

├ (q2,△ △ a ) a/a,L
b/b,L
├ (q2,△ △ a △ a/Δ,L
a/Δ,R

) (q3,△ △ a )
Δ/Δ,R Δ/Δ,R
├ (q4,△ △ ) 0 1 4 h
├ (q1,△ △ △)
├ (ha, △ △ △ b/Δ,R b/Δ,L

Accept Δ/Δ,L Δ/Δ,R


△)
5 6
(odd pal)
a/a,R
Exercise b/b,R
1. aba Δ/Δ,R (even pal)
2. abab

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 16
TM Accepting same no of 0’s and 1’s
L = Same no. of 0’s and 1’s
Strings accepting in given L are:
Δ 1x 0x x0 1x Δ
01
10
0101 Δ 0x 1x 1x 0x 0x 1x Δ
1100
100011

Logic:
1. Move right, Read first leftmost 0, replace 0 with X (0X)
2. Keep moving to the left until you encounter Δ
3. Move right, Read first leftmost 1, replace 1 with X (1X)
4. Keep moving to the left until you encounter Δ
5. Repeat the above steps until no more 0’s and 1’s left in string.
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 17
TM Accepting same no of 0’s and 1’s
Δ 1X X
0 0X 1X Δ

1/1,R x/x,L x/x,R x/x,L


x/x,R 1/1,L 0/0,R 0/0,L

Δ/Δ,R
0/x,L Δ/Δ,R 1/x,L
0 1 2 3 4

Δ/Δ,L
Δ/Δ,R
Δ/Δ,S h
5

x/x,L

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 18
TM Accepting same no of a’s, b’s & c’s

X X
Δ b a cX cX Xa bX Δ

x/x,R x/x,L x/x,R x/x,L x/x,R x/x,L


b/b,R b/b,L a/a,R a/a,L b/b,R b/b,L
c/c,R c/c,L c/c,R c/c,L a/a,R a/a,L

Δ/Δ,R a/x,L Δ/Δ,R b/x,L Δ/Δ,R c/x,L


0 1 2 3 4 5 6

Δ/Δ,L Δ/Δ,R

Δ/Δ,S h
7

x/x,L

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 19
Turing machine to delete a symbol
ΔaabΔ

Δ a bΔ a b Δ

Logic:
1. Replace the symbol you want to delete by Δ.
2. Keep moving to the Right until you encounter Δ.
3. One by one Keep shifting every symbol one step to left until you encounter Δ.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 20
Turing machine to delete a symbol
a/a,L
Δ a Δ
a
b ab bΔ Δ

3
a/a,R
b/b,R
a/Δ,R a/Δ,L Δ/a,S
Δ/Δ,R
b/Δ,R
Δ/Δ,L b/a,L a/b,L h
0 1 2

b/Δ,L Δ/b,S

4
Δ/Δ,S
b/b,L

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 21
Turing machine to copy a string
String:
Δ Aaa bB Δ Δ
a Δ
b Δ
Δ ab Δ ab

Original Pasted

Δ bab Δ bab

Original Pasted Δ aA bB b
B A
aa Δ aΔ Δ
b Δ
b Δ
a Δ

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 22
Design a Turing machine to copy a string
a/a,R a/a,R
b/b,R b/b,R
Δ aa
A b
B Δ aΔ Δ
b Δ
Δ/Δ,R
2 3
a/a,L
Δ/a,L a/a,L b/b,L
b/b,L
a/A,R

Δ/Δ,R Δ/Δ,L
0 1 4 5

Δ/Δ,L b/B,R
Δ/b,L

Δ/Δ,S 6
Δ/Δ,R 7
h 8 a/a,R
a/a,R b/b,R
b/b,R A/A,R
A/a,L
B/b,L B/B,R

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 23
Design a TM for Accepting {SS | S ∈ {a,b}*}
Logic:
 Find middle point of the string and convert the string in to the uppercase.
 Convert first part of the string to lowercase.
 Compare first part and second part.
 ss.pptx (Click here)

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 24
Universal Turing machine
Universal Turing machine
The language
={< , >| & }

is Turing Recognizable

 Question : Given the description of a Turing Machine and some input string, can we decide the
machine accepts it?
 Answer: Just Run the TM on the input.
 Possible results:
1. M accepts w: will halt and accept
2. M rejects w: will halt and reject
3. M loops on w: will not halt

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 26
Input & Action on Universal Turing machine
Input:
1. M=description of TM
2. w=input string for M
Action:
3. Simulate M
4. Behave just like M (May accept, reject or loop)

The UTM is recognizer for


={< , >| }

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 27
Church Turing Thesis
Church Turing Thesis
 What does computable mean?
 Meaning of term Computable was given by:
1. Alonzo church (Lambda calculus)
2. Allen Turing (Turing Machine)

 Any algorithmic procedure that can be carried out at all, by a human computer or a team of
humans or an electronic computer, can be carried out by a TM. This statement usually referred to
as Church’s thesis, or the Church-Turing thesis.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 29
Church Turing Thesis
 Here is an informal summary of some of the evidence.
1. Humans normally work with a two-dimensional sheet of paper. A TM tape could be organized
so as to simulate two dimensions; one likely consequence would be that the TM would
require more moves to do what a human could do in one.
2. Various enhancements of the TM model have been suggested to make the operation more
like that of a human computer, or more convenient & efficient. The multitape TM is an
example.
3. Other theoretical models includes abstract machines with two stacks or with a queue.
4. Since the introduction of the Turing machine, no one has suggested any type of computation
that ought to be included in the category of “algorithmic procedure” and cannot be
implemented on a TM.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #3130006
#3160704
(PS)(TOC)
 Unit
 1Unit
– Basic
5 – Turing
Probability
Machine 30
Thank You

You might also like