0% found this document useful (0 votes)
180 views53 pages

Unit 5 Turing Machine

Uploaded by

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

Unit 5 Turing Machine

Uploaded by

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

2160704

Theory of Computation

Turing Machine

1
Topics to be covered
• What is Turing Machine?
• Formal Definition: Turing Machine
• Design of Turing Machine
• Universal Turing Machine
• Church Turing Thesis

2
Introduction
Finite Automata Pushdown Automata Turing Machine
• Input Strings • Input Strings • Input Strings
• Stack • Tape
a b a a • Special symbol
Stack Accept
I/p
Control | Reject • Control portion

Δ a b a a b Δ

Tape
Stack Head

FA Recursively enumerable language


Context free language
Regular language

3
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.

4
Turing Machine

𝑞2 𝑞3

𝑞1 𝑞4 Δ b a a b a Δ

Head
𝑞5 𝑞6
Tape

Control portion

Turing Machine = Control portion + Tape

5
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) a | Δ, R
a | b, R
𝑞0 𝑞1 a | a, R

6
Definition: Turing Machine
• A Turing machine is a 7-tuple where,
is a finite set of states, assumed not to contain ha (Acceptance State) and hr (Rejection State).
: input Symbols, Є
tape alphabets
: is initial state, is an element of Q.
: is a transition function. ( : Q X  Q X X (L/R))
F: set of final states
B: blank symbol normally used as marker, B Є (or ∆ used for blank)

 Acceptor(language aceptor)
 Generator(generate output such as moore and mealy machine)
 Transducer(solve any mathematical function +, -, log, exp,…..)

7
Turing Machine Accepting

8
Design a 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)

9
Design a Turing Machine Accepting
Tape

Δ a
A b
B a
A Δ

h𝑟
b|B,R a|A,R
b|B,R b|B,R

𝑞0 Δ|Δ,R
𝑞1 a|A,R
𝑞2 a|A,R
𝑞3 Δ|Δ,R
h𝑎
Control portion
10
Turing Machine Accepting

11
Design a Turing Machine Accepting
L = {anbn}
Tape
Strings accepting in given L are:
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’ Δ aA aA Aa Bb B
b 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.
12
Design a Turing machine for accepting

Δ A
a Aa bB B
b Δ

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

a/A,R
𝑞0 Δ/Δ,R
𝑞1 𝑞2 b/B,L
𝑞3
B/B,R
A/A,R
𝑞4
B/B,R
Δ/Δ,R

h𝑎
13
Turing Machine Accepting

14
Design a Turing machine for accepting
a/a,R b/b,R C/C,L
B/B,R C/C,R a/a,L

Δ A a bB b
a A c C
B C c Δ
𝑞2 b/B,R
𝑞3 c/C,L
𝑞4 b/b,L
B/B,L

a/A,R A/A,R

𝑞0 Δ/Δ,R
𝑞1 Δ/Δ,R

B/B,R h𝑎
𝑞5 C/C,R Δ/Δ,S

B/B,R
𝑞6
C/C,R

15
Turing Machine Accepting

16
Design a TM for accepting Palindrome strings of even & odd length.
L = Palindrome string
Tape
Strings accepting in given L are:
aa Δ aΔ Δ
b b
Δ Δ
a Δ
bab Even Length
abba
babab
Δ Δ Δ
b a Δ
b Δ b
a Δ Δ

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.

17
Design a TM for accepting Palindrome strings of even & odd length.
a/a,R
b/b,R Δ/Δ,R (odd pal)
Δ a
Δ b
Δ b
Δ a
Δ Δ

𝑞2 Δ/Δ,L
𝑞3 a/a,L
b/b,L
a/Δ,R a/Δ,L

𝑞0 Δ/Δ,R
𝑞1 Δ/Δ,R
𝑞4 h𝑎
b/Δ,R b/Δ,L

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

18
String Tracing
├ (q0,△ a a)
├ (q1,△ a a)
├ (q2,△ △ a )
├ (q2,△ △ a △ )
├ (q3,△ △ a )
├ (q4,△ △ )
├ (q1,△ △ △)
├ (ha, △ △ △ △)
Accept

Exercise
1. aba
2. abab

19
TM Accepting same no of 0’s and 1’s

20
Design a TM for 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.
21
Design a TM for accepting same no of 0’s and 1’s

Δ 1X 0
X 0X 1
X Δ

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 𝑞1 0/x,L
𝑞2 Δ/Δ,R
𝑞3 1/x,L
𝑞4
Δ/Δ,L
Δ/Δ,R

𝑞5 Δ/Δ,R
h𝑎
x/x,L

22
TM Accepting same no of a’s, b’s & c’s

23
Design a TM for Accepting

X Xa cX cX Xa b
Δ b X Δ

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

𝑞0 Δ/Δ,R
𝑞1 a/x,L
𝑞2 Δ/Δ,R
𝑞3 b/x,L
𝑞4 Δ/Δ,R
𝑞5 c/x,L
𝑞6
Δ/Δ,L Δ/Δ,R

𝑞7 Δ/Δ,S
h𝑎
x/x,L

24
Turing machine to delete a symbol

25
Design a 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 Δ.

26
Design a Turing machine to delete a symbol
a/a,L
Δ a Δa
b ab bΔ Δ

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

Δ/Δ,S 𝑞4
b/b,L

27
Turing machine to copy a string

28
Design a Turing machine to copy a string
String:
Δ aa
A bB Δ a
Δ Δ
b Δ
Δ ab Δ ab

Original Pasted

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

29
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 Δ

𝑞2 Δ/Δ,R
𝑞3 a/a,L
Δ/a,L a/a,L b/b,L
b/b,L
a/A,R

𝑞0 Δ/Δ,R
𝑞1 𝑞4 Δ/Δ,L
𝑞5
Δ/Δ,L b/B,R
Δ/b,L

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

30
Design a Turing machine for L={WCW|WЄ(a,b)*}
b/b, R X/X, L
X/X, R b/b, L
a/a, R Y/Y, L
Y/Y, R a/a, L

𝑞0 Δ/Δ,R
𝑞1 a/X,R
𝑞2 C/C,R
𝑞3 a/X,L
𝑞4 C/C,L
𝑞5
X/X, R

b/Y,R b/b, R X/X, R X/X, L


C/C,R b/b, L
a/a, R Y/Y, R Y/Y, L
a/a, L

𝑞6 𝑞7 𝑞8 𝑞9
C/C,R b/X,L C/C,L
X/X, R
Y/Y, R 𝑞10
Y/Y, R

Δ/Δ,R 𝑞11
31
Design a Turing machine for L={WW|WЄ(0,1)*}
The logic for solving this problem can be divided into 2 parts:
 Finding the mid point of the string
 After we have found the mid point we match the symbols
Lets consider string 1 0 1 1 0 1, so w = 1 0 1 and string is of form (ww).
 The first thing that we do is to find the midpoint. For this, we convert 1 in the beginning
into Y and move right till the end of the string. Here we convert 1 into Y.
 Now move left till, find a X or Y. When we do so, convert the 0 or 1 right of it to X or Y
respectively and then do the same on the right end.
 Now our string would look like Y X 1 1 X Y. Thereafter, convert these 1’s also and finally it
would look like Y X Y Y X Y.
 At this point, you have achieved the first objective which was to find the midpoint.

32
 Now convert all X and Y on the left of midpoint into 0 and 1 respectively, so string becomes 1
0 1 Y X Y. Now, convert the 1 into Y and move right till, find Y in the beginning of the right part
of the string and convert this Y into a blank (denoted by B). Now string looks like Y 0 1 B X Y.
 Similarly, apply this on 0 and X followed by 1 and Y. After this string looks like Y X Y B B B. Now
that you have no 0 and 1 and all X and Y on the right part of the string are converted into
blanks so our string will be accepted.

 Input : 1 1 0 0 1 1 0 0
 Output : Accepted

 Input : 1 0 1 1 1 0 1
 Output : Not accepted
33
34
Design a Turing machine for Adder
Approach for Addition
 Numbers are given in Uniary form
 Example: 3 = 111, 2 = 11, 5 = 11111 etc.
 For addition of 3 and 4, numbers will be given in TAPE as "B B 1 1 1 0 1 1 1 1 B B".
 Convert '0' to '1' and reduce '1' from right
 Hence output will be "B B 1 1 1 1 1 1 1 B B B"
 Total number of '1' in output is = 7 which is addition of 3 and 4

35
Tap movement
• Input is given as "11011" (2 + 2)
• Scan string from left to right
• Pass all '1'SSS and convert '0' to '1'
• Reach BLANK in right
• Convert rightmost '1' to BLANK

Addition of 2 and 2 = 4 is written on TAPE


Input String : 11011
Output String : 1111

36
37
Design a Turing machine from unary to binary

X/X,R X/X,L
0/0 ,R 1/0,L
ΔΔΔΔΔΔCCCCCΔΔΔ
𝑞0 C/X,L
𝑞1
Δ/Δ,R
Δ/1,R
0/1,R

𝑞2

38
Design a Turing machine for 2’s complement

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


0/0 ,R 0/1 ,L

𝑞0 Δ/Δ,L
𝑞1 1/1,L
𝑞2 Δ/Δ,R
𝑞3

39
Problems
 Construct Turing machine for L = {an bm a(n+m) | n,m≥1}
 Construct a Turing Machine for language L = {02n1n | n>=0}
 Construct a Turing Machine for language L = {an bm cnm where n >=0 and m >= 0}

40
Universal Turing Machine

41
Universal Turing machine
The language

is Turing Recognizable
• 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

42
Finite Control

TM1 TM2 TM3………………………. 1 0 0 1 0 1 q1 q2 q2 q3……….


Description of TM’s I/O Tap Internal states

TM1: (q1,1)(q2,X,R)
(q2,0)(q2,X,R)
…….

43
Recursively enumerable languages
 Recursively enumerable languages are the universal set of all the languages, and the remaining
languages are their subsets.
 Recursively enumerable languages are those whose strings the Turing machine (TM) accepts.
These strings may do one of the following:
• Halt and accept
• Halt and reject
• Loop forever

 Turing machines for recursively enumerable languages may not always halt, and continue to run
endlessly for strings that are not a part of that language.
 Recursively enumerable languages are also called
44 Turing recognizing languages
Recursive languages
 Recursive languages are those whose strings are accepted by a total Turing machine that
does either of the following:
• Halt and accept
• Halt and reject

 Total turing machine: A turing machine that always gives some input, i.e., it does not go
into an infinite loop.
 A TM of a recursive language never goes into a loop and always halts in every case.
Recursive languages are hence also called Turing decidable languages.

45
Closure properties of recursive language
 Union: The union of two recursive languages L1​and L2​is also a recursive language. This
is, if the TM accepts any one of the languages, it also accepts L1​∪L2​.

46
 Intersection: The intersection of two recursive languages L1​and L2​is also a recursive
language. This is, if the TM accepts both languages, it also accepts L1​∩L2​.

47
 Complement: The complement of a recursive language L1​is also a recursive language.
This is, if the TM accepts L1​, it rejects it as a final output.

48
 Kleene's closure: The Kleene's closure of a recursive language L1​is also recursive. This
is, if L1​={0i1j} is recursive, then L1*​={0i1j}* is also recursive.
 Note: All recursively enumerable languages are recursive, but not vice versa.

49
Church Turing Thesis

51
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.

52
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.

53
Question 1
Consider the following types of languages: L1: Regular, L2: Context-
free, L3: Recursive, L4: Recursively enumerable. Which of the following is/are TRUE?

I. L3’∪L4 is recursively enumerable


II. L2’ ∪L3 is recursive
III. L1*∩L2 is context-free
IV. L1∪L2― is context-free
a. I only
b. I and III only
c. I and IV only
d. I, II and III only

54

You might also like