09StdTuring Part1
09StdTuring Part1
DTM, NTM
LBA
PDA
DPDA
DFA,
NFA
The Turing Machine
Alan Mathison Turing, b. 1912, d. 1954. Contributed
much to the foundations of computing theory.
Published the Turing machine model in 1937.
Church-Turing Thesis - “Any algorithmic procedure that
can be carried out by a human, a team of humans, or a
machine can be carried out by some Turing machine.”
Unproveable, because we don’t have a precise definition
of what “algorithmic procedure” means, but generally
accepted as true.
Puts a limit on what can be computed.
Alan Turing
• One of the first to conceive a machine
that can run computation
mechanically without human
intervention. We call “algorithmic
computation” now.
• The first to conceive a universal
machine – that can run programs
• Break German Enigma Machine 1912-1954
(encryption) in WWII
• Turing Award: the most prestigious
award in CS
• Bio movie: The Imitation Game, 2015
Turing machine's storage is actually quite simple. It
can be visualized as a single, one-dimensional
array of cells, each of which can hold a single
symbol.
– This array extends indefinitely in both directions
and is therefore capable of holding an unlimited
amount of information.
– The information can be read and changed in any
order.
– We will call such a storage device a tape because
it is analogous to the magnetic tapes used in older
computers.
The Standard Turing Machine
Definition: Turing Machine
The tape on a Turing machine can be thought of as a
linear structure marked off into squares or cells. It is
usually defined as infinite in both directions, but may
be thought of as bounded on the left side, but infinite
on the right. Each cell on the tape on a Turing
machine can hold a symbol from the input alphabet, a
symbol from the tape alphabet (which may include
some symbols which are not in the input alphabet), or
a blank symbol which is distinct from the input
alphabet.
The TM tape head
/ , R
q0 q1
a b a
Consider a Turing machine with a move defined as follows:
δ(q 0 , a) = (q 1 , d, R)
Figure shows the situation (a) before the move and (b) after
the move.
Consider the Turing machine defined by
Q = {q 0 , q 1 },
Σ = {a, b},
Γ = {a, b, },
F = {q 1 }
where δ is defined as follows:
1. δ(q 0 , a) = (q 0 , b, R),
2. δ(q 0 , b) = (q 0 , b, R),
3. δ(q 0 , ) = (q 1 , , L).
Linz Figure 9 .3 shows a sequence of moves for this Turing machine:
• It begins in state q 0 with the input positioned over an a.
• When an a is read, transition rule 1 fires, replaces a by b on the tape,
moves right, and stays in state q 0 .
• When a b is read, transition rule 2 fires, leaves b on the tape, moves right,
and stays in state q 0 .
• It continues moving right, replacing each a by a b and leaving each b
unchanged.
• When a blank ( ) is read, transition rule 3 fires, leaves the blank on the
tape, moves left, and enters final state q 1 .
Transition Graph for Turing Machine
we can use transition graphs to represent Turing machines.
We label the edges of the graph with a triple giving (1) the
current tape symbol, (2) the symbol that replaces it, and (3)
the direction in which the read-write head moves.
q3 q3,y,R q4, ,R
q4
{anbn | n 1}
Replace leftmost a with an x and find the first b and
replace with a y:
(q0,a)=(q1,x,R) (q1,y)=(q1,y,R)
(q1,a)=(q1,a,R) (q1,b)=(q2,y,L)
Come back to the next left-most a:
(q2,y)=(q2,y,L) (q2,x)=(q0,x,R)
(q2,a)=(q2,a,L)
Finally, check to see if all input has been processed and the
a’s and b’s balance (and a’s precede the b’s):
(q0,y)= (q3,y,R) (q3, Δ) = (q4, Δ,R)
(q3,y) = (q3,y,R)
Another Turing Machine
Example
Turing machine for the language
n n
{a b }
q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L
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
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
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
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
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
x → x,R
Time 5 ⋄ x a y b ⋄ ⋄
q0
q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L
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
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
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
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
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
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
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
x → x,R
Time 13 ⋄ x x y y ⋄ ⋄
q4
q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L
x → x,R
Observation:
If we modify the
machine for the language n n
{a b }
a b c x y z Δ
q0
q1,x,R q4,y,R
A function f is computable if
there is a Turing Machine M such that:
qf f (w )
Initial Final
Configuration Configuration
Initial Final
Configuration Configuration
w ∈ D
For all Domain
Example
The function f ( x,y ) =x+y is computable
where 0 separates the two numbers at initiation and after the result at
termination
x y
Start ⋄ 1 1 ⋯ 1 0 1 ⋯ 1 ⋄
q0
initial state
Start ⋄ 1 1 ⋯ 1 0 1 ⋯ 1 ⋄
q0 initial state
x+ y
Finish ⋄ 1 1 ⋯ 1 1 0 ⋄
qf final state
The 0 helps when we use
the result for other operations
x+ y
Finish ⋄ 1 1 ⋯ 1 1 0 ⋄
qf final state
Turing machine for function f ( x,y ) =x+y
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Execution Example: Time 0
x y
x= 11 (2)
⋄ 1 1 0 1 1 ⋄
y= 11 (2)
q0
Final Result
x+ y
⋄ 1 1 1 1 0 ⋄
q4
Time 0 ⋄ 1 1 0 1 1 ⋄
q0
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 1 ⋄ 1 1 0 1 1 ⋄
q0
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 2 ⋄ 1 1 0 1 1 ⋄
q0
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 3 ⋄ 1 1 1 1 1 ⋄
q1
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 4 ⋄ 1 1 1 1 1 ⋄
q1
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 5 ⋄ 1 1 1 1 1 ⋄
q1
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 6 ⋄ 1 1 1 1 1 ⋄
q2
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 7 ⋄ 1 1 1 1 0 ⋄
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 8 ⋄ 1 1 1 1 0 ⋄
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 9 ⋄ 1 1 1 1 0 ⋄
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 10 ⋄ 1 1 1 1 0 ⋄
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 11 ⋄ 1 1 1 1 0 ⋄
q3
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
q4
Time 12 ⋄ 1 1 1 1 0 ⋄
q4
1 → 1, R 1 → 1, R 1 → 1, L
q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3
⋄ → ⋄ ,R
HALT & accept q4
Combining Turing Machines
Block Diagram
Turing
input Machine output
You can combine several smaller TMs in order to make a
larger, more complicated TM.
The composite of two different TMs, T1 and T2, is written as
T1T2. It would be represented as:
T1 T2
What happens is that T1T2 begins by executing the moves of
T1, up to the point where T1 would halt. Instead of halting,
T1T2 moves to the initial state of T2, where it begins
executing the moves of T2.
If T2 halts, then T1T2 halts. If T1 or T2 crashes, then T1T2
crashes.
You can also make the transition to T2
conditional.
a
T1 T2
Here, T1 would execute its moves up to the
point where it would normally halt. If
the symbol on the tape at that point is an
a, then T1T2 will begin executing the
moves of T2. Otherwise T1T2 will crash
we can compose simpler operations on Turing machines to form
more complex operations
f ( x,y )=
0 if x≤ y
x,y
Adder x+ y
x,y x> y
Comparer
x≤ y Eraser 0
Turing’s Thesis
The Turing thesis is an hypothesis that any computation that can
be carried out by mechanical means can be performed by some
Turing machine.
This is a broad assertion. It is not something we can prove!
The Turing thesis is actually a definition of mechanical
computation: a computation is mechanical if and only if it can be
performed by some Turing machine.
Some arguments for accepting the Turing thesis as the definition of
mechanical computation include:
1. Anything that can be computed by any existing digital computer
can also be computed by a Turing machine.
2. There are no known problems that are solvable by what we
intuitively consider an algorithm for which a Turing machine
program cannot be written.
3. No alternative model for mechanical computation is more
powerful than the Turing machine model.
Definition 9.5 (Algorithm):
An algorithm for a function f : D → R isa Turing machine M ,
which given as input any d ∈ D on its tape, eventually halts with the
correct answer f (d) ∈ R on its tape. Specifically, we can require
that
for all d ∈ D.
To prove that “there exists an algorithm”, we can construct a Turing
machine that computes the result