2-ProgrammingTM
2-ProgrammingTM
3/23/2025
LEARNING OBJECTIVE
• To Design Turing machines for any Languages (K3)
–To Understand the concept of Turing Machine
3/23/2025
TURING-COMPUTABLE FUNCTIONS
• A total function f: Σ* → Σ* is Turing-computable if there exists a DTM M
such that for every x in Σ*,
(s, BxB) ├* (h, Bf(x)B).
3/23/2025
TURING-COMPUTABLE FUNCTIONS
Construct a TM for successive function ?
f : N → N, f(x) = x+1.
Assume that the input is encoded in UNARY form.
Let M = (Q, Σ, Γ, δ, q0, B, F)
Q = {q0,q1} q0=start state q1=final state
Σ = {0}
Γ = {0,B}
F = {q1}
3/23/2025
TURING-COMPUTABLE FUNCTIONS
Construct a TM for successive function ?
f : N → N, f(x) = x+1.
Assume that the input is encoded in UNARY form.
Let M = (Q, Σ, Γ, δ, q0, B, F)
Q = {q0,q1} q0=start state q1=final state
Σ = {0}
Γ = {0,B}
F = {q1}
3/23/2025
TURING-COMPUTABLE FUNCTIONS
3/23/2025
ADDITION
• We can represent numbers on a TM by using the unary representation, which
just uses n 0’s to represent the number n.
Example: 00000 = 5
• We can construct a TM to concatenate two strings together.
• If we represent two numbers in unary form, then a TM which concatenates
these two strings is actually performing addition!
3/23/2025
ADDITION
• Addition of two numbers as simple as concatenation of two strings.
• Assume two integers are represented in unary form on the tape of a Turing
machine.
• Assume the two integers are separated by a 1 between them.
• Design a Turing machine that will add these two numbers.
3/23/2025
ADDITION
• f(m,n)=m+n
3/23/2025
ADDITION
• 3+2
3/23/2025
SUBTRACTION M - N
• For example, proper subtraction m – n is defined to be
m – n for m >= n, and
zero for m < n.
3/23/2025
SUBTRACTION M - N
3/23/2025
PROGRAMMING TECHNIQUES OF TURING MACHINES
• Storage in the Finite Control
• Multiple Tracks
• Checking off Symbols
• Subroutines
3/23/2025
STORAGE IN THE FINITE CONTROL
• The finite control can be used to hold the finite amount of
information.
• It is considered as a pair of elements, like (q0,a), where one exercising
control and second component stores a symbol in the finite control.
• Consider a turing machine M which accepts the language 01* +
10*
• Let M = (Q, {0,1}, {0,1,B}, δ, {q0,B},B,F)
• Q = {q0,q1} x {0,1,B}
= ([q0,0], [q0,1], [q0,B], [q1,0], [q1,1], [q1,B])
• F = {[q1,B]}
3/23/2025
δ([q0,B],0) = ([q1,0], 0,R)
δ([q0,B],1) = ([q1,1], 1, R)
δ([q1,0],1) = ([q1,0], 1, R)
δ([q1,1],0) = ([q1,1], 0, R)
δ([q1,0],B) = ([q1,B],0,L)
δ([q1,1], B) = ([q1,B], 1, L)
3/23/2025
MULTIPLE TRACKS
3/23/2025
CHECKING OFF SYMBOLS
{wcwR|w in Σ*}
{aibi : i≥1}
3/23/2025
Consider a turing machine M = (Q, Σ, Γ, δ, q0, B, F) for the language
L = {wcw|w∈{a, b}+}
a) Q = {[q,d] | q = q1 q2.... q9 and d = a, b or B}
b) Σ = {[B, d] | d = a, b or c}
c) Γ = {[x, d] | x = B or and d = a, b, c or B}
d) q0 = [q1, B]
e) F = {[q9, B]}
f) B = [B, B]
g) δ is defined for d = a or b and e = a or b.
3/23/2025
CHECKING OFF SYMBOLS
Forward
δ([q1, B], [B, d]) = ([q2, d], [✓, d], R)
δ([q2, d], [B, e]) = ([q2, d], [B, e], R)
δ([q2,d], [B, c]} = ([q3, d], [B, c], R)
δ([q3,d], [✓, e]) = ([q3,d], [✓, e], R)
δ([q3,d], [B, d]) = ([q4,B], [✓, d], L)
3/23/2025
CHECKING OFF SYMBOLS
Backward
δ([q4,B], [✓, d]) = ([q4,B], [✓, d], L)
δ([q4,B], [B, c]) = ([q5,B], [B, c], L)
δ([q5,B], [B, d]) = ([q6,B], [B, d], L)
δ([q6,B], [B, d]) = ([q6,B], [B, d], L)
δ([q6,B], [✓, d]) = ([q1,B], [✓, d], R)
3/23/2025
CHECKING OFF SYMBOLS
Terminate
δ([q5,B], [✓, d]) = ([q7,B], [✓, d], R)
δ([q7,B], [B, c]) = ([q8,B], [B, c], R)
δ([q8,B], [✓, d]) = ([q8,B], [✓, d], R)
δ([q8,B], [B, B]) = ([q9,B], [, B], L)
3/23/2025
SUBROUTINES
δ(q0,0) = (q6, B, R)
δ(q6, 0) = (q6, 0, R)
δ(q6, 1) = (q1, 1, R)
3/23/2025
3/23/2025
3/23/2025
3/23/2025
δ(q0, 001001) |– Bq601001B |– Bq80100100
|– B0q61001B |– q9B0100100 (
|– B01q1001B |– Bq00100100
|– BBq6100100
|– B01Xq201B |– BB1q100100
|– B01X0q21B |– BB1Xq20100
|– B01X01q2B |– BB1X0q2100
|– BB1X0q2100
|– B01X0q310 |– BB1X01q200
|– B01Xq3010 |– BB1X010q20
|– B01q3X010 |– BB1X0100q2B
|– BB1X010q300
|– B01Xq1010 |– BB1X01q3000
|– B01XXq210 |– BB1X0q31000
|– B01XX1q20 |– BB1Xq301000
|– BB1q3X01000
|– B01XX10q2B |– BB1Xq101000
|– B01XX1q300 |– BB1XXq21000
|– B01XXq3100 |– BB1XX1q2000
|– BB1XX10q200
|– B01Xq3X100 |– BB1XX100q20
|– B01XXq1100 |– BB1XX1000q2B
|– B01Xq4X100 |– BB1XX100q300
|– BB1XX10q3000
|– B01q4X0100 |– BB1XX1q30000
|– B0q4100100 |– BB1XXq310000
|– B01q500100 |– BB1Xq3X10000
|– BB1XXq110000
|– B0q7100100
3/23/2025
|– BB1Xq4X10000
|– BB1q4X010000
|– BBq410010000
|– BB1q50010000
|– BBq710010000
|– Bq8B10010000
|– BBq1010010000
|– BBBq110010000
|– BBBBq11010000
|– BBBBBq1110000
|– BBBBBBq120000
3/23/2025
SUMMARY
• Definition of Total and partial function
• Computing a numerical function using Turing Machine
• Programming techniques of Turing Machine
3/23/2025
TEST YOUR KNOWLEDGE
• Which of the following statements is/are FALSE?
1. For every non-deterministic Turing machine, there exists an equivalent
deterministic Turing machine.
2. Turing recognizable languages are closed under union and complementation.
3. Turing decidable languages are closed under intersection and
complementation.
4. Turing recognizable languages are closed under union and intersection.
A. 1 and 4 only
B. 1 and 3 only
C. 2 only
D. 3 only
3/23/2025
TEST YOUR KNOWLEDGE
3/23/2025
REFERENCE
3/23/2025