Transcript Chapter 9
CS 3240 – Chapter 9
Turing Machines
From Alan Turing, 1936
Turns out to be the LAST machine
The only machine you'll ever need
The Church-Turing Thesis
All algorithms have a Turing Machine equivalent
▪ Some TMs are not algorithms, however
4/8/2015
CS 3240 - Chapter 9
2
We have shown that anbncn is not context free
By the Pumping Lemma
What if we add an extra stack to a PDA?
4/8/2015
CS 3240 - Chapter 9
3
input, pop1/pop2, push1/push2
4/8/2015
CS 3240 - Chapter 9
4
an is accepted by an FA
anbn is accepted by a PDA
anbncn is accepted by a 2PDA
What about anbncndn?
4/8/2015
CS 3240 - Chapter 9
5
4/8/2015
CS 3240 - Chapter 9
6
An FA is a machine with no auxiliary memory
A PDA is like an FA but with unlimited, restricted
memory
LIFO access
A Turing Machine is like an FA but with unlimited,
unrestricted memory
We can move to any memory cell
We can both read and write there
4/8/2015
CS 3240 - Chapter 9
7
Language
Machine
Grammar
Regular
Finite Automaton
Regular Expression,
Regular Grammar
Context-Free
Pushdown Automaton
Context-Free
Grammar
Recursively
Enumerable
Turing Machine
Unrestricted PhraseStructure Grammar
CS 3240 - Introduction
8
4/8/2015
CS 3240 - Chapter 9
9
4/8/2015
CS 3240 - Chapter 9
10
Control Unit (Deterministic)
states (1 start state; 1 or more or halt states)
transitions: input,output,move (L or R)
I/O Tape (2-way, infinite)
pre-populated with (finite) input
output left on tape after processing
special blank symbol ☐
▪ not part of input alphabet
▪ used as a separator and/or a boundary
4/8/2015
CS 3240 - Chapter 9
11
Contents left on tape is ignored
Typically has only one accepting state
with no out-edges
Any string that causes the TM to halt in an
accepting state is in the TM’s language
otherwise it is not in the language
(an explicit reject state may also be used)
4/8/2015
CS 3240 - Chapter 9
12
Pseudocode:
Replace the first a with an X
Move right to first b, replace with Y
Move to right first c, replace with Z
Move left to right-most X
Repeat
When no more a’s, skip over all Y’s and Z’s
Halt and accept or reject
4/8/2015
CS 3240 - Chapter 9
13
4/8/2015
CS 3240 - Chapter 9
14
aabbcc
Xabbcc
Xabbcc
XaYbcc
XaYbcc
XaYbZc
XaYbZc
XaYbZc
XaYbZc
XaYbZc
XXYbZc
XXYbZc
4/8/2015
XXYYZc
XXYYZc
XXYYZZ
XXYYZZ
XXYYZZ
XXYYZZ
XXYYZZ
XXYYZZ
XXYYZZ
XXYYZZ
XXYYZZ☐
XXYYZZ☐☐ (accept)
CS 3240 - Chapter 9
15
q0aabbcc
Xq1abbcc
Xaq1bbcc
XaYq2bcc
XaYbq2cc
XaYq3bZc
Xaq3YbZc
Xq3aYbZc
q3XaYbZc
Xq0aYbZc
XXq1YbZc
XXYq1bZc
4/8/2015
XXYYq2Zc
XXYYZq2c
XXYYq3ZZ
XXYq3YZZ
XXq3YYZZ
Xq3XYYZZ
XXq0YYZZ
XXYq4YZZ
XXYYq4ZZ
XXYYZq4Z
XXYYZZq4☐
XXYYZZ☐q5☐ (accept)
CS 3240 - Chapter 9
16
A sequence of configurations in a TM leading
to a halt state
i.e., it doesn’t crash
If the TM is an acceptor, it explicitly accepts or
rejects
If the TM represents some function, f, it
leaves f(x) on the tape, for each valid input x
4/8/2015
CS 3240 - Chapter 9
17
4/8/2015
CS 3240 - Chapter 9
18
What would be a reasonable strategy?
4/8/2015
CS 3240 - Chapter 9
19
4/8/2015
CS 3240 - Chapter 9
20
The initial configuration of the tape is the
input
What’s left on the tape is the output
A model of a function
Exercising such a TM constitutes a
computation
4/8/2015
CS 3240 - Chapter 9
21
Suppose f: D→R is a function from domain D
to range R
If there is a TM that transforms every d in D to
f(d)
That is, it reads d from the tape and leaves f(d) on
the tape…
Then f is Turing-computable
This is the formal definition of an algorithm
4/8/2015
CS 3240 - Chapter 9
22
Must first decide how to encode numbers on a
TM tape
Then we must separate the numbers, so we
can distinguish between them
Plan:
represent the numbers in unary notation
then move the 1’s from one number to the other!
▪ i.e., just remove the separator and move the 1’s
together
4/8/2015
CS 3240 - Chapter 9
23
11101111
11101111
11101111
11101111
11111111
11111111
11111111
11111111
11111111_
1111111_
4/8/2015
CS 3240 - Chapter 9
24
4/8/2015
CS 3240 - Chapter 9
25
Using unary notation, as usual
4/8/2015
CS 3240 - Chapter 9
26
4/8/2015
CS 3240 - Chapter 9
27
Trace ababb
4/8/2015
CS 3240 - Chapter 9
28
TMs typically have one start and one or two
halt states (but can have many):
one if the TM is a function
two if the TM is an acceptor
You can “call” a TM as a routine by setting up
appropriate “linkage”
return to the desired state in the calling machine
make sure the tape workspace is in an acceptable
configuration
4/8/2015
CS 3240 - Chapter 9
29
Tape configuration:
start: [x]0[y]0
finish: [x]0[y]0[xy]
First, modify copy to accommodate a 0delimiters:
0[y]0… → 0[y]0…[y]
and finish by positioning at left of y
Then, mark a 1 in x with a, copy y to end, and
repeat; then restore x’s a’s to 1’s
4/8/2015
CS 3240 - Chapter 9
30
4/8/2015
CS 3240 - Chapter 9
31
4/8/2015
CS 3240 - Chapter 9
32
See Example 9.11 for an explanation of Comparer
4/8/2015
CS 3240 - Chapter 9
33
T = (Q, ∑, Γ, δ, q0, H)
Q = set of states
∑ = input alphabet
Γ = tape alphabet
includes ∑ and blank symbol (☐)
q0 = start state
H = one or more halt states
each typically represents a different meaning
4/8/2015
CS 3240 - Chapter 9
34
δ(q0,1) = (q0,1,R)
δ(q0,0) = (q1,1,R)
δ(q1,1) = (q1,1,R)
δ(q1,☐) = (q2,☐,L)
δ(q2,1) = (qh,☐,R)
4/8/2015
CS 3240 - Chapter 9
35
δ
q0
q1
q2
☐
0
1
(q1,1,R)
(q0,1,R)
(q1,1,R)
(q2,☐,L)
(qh,☐,R)
δ(q0,1) = (q0,1,R)
δ(q0,0) = (q1,1,R)
δ(q1,1) = (q1,1,R)
δ(q1,☐) = (q2,☐,L)
δ(q2,1) = (qh,☐,R)
4/8/2015
CS 3240 - Chapter 9
36
q0,1,q0,1,R
q0,0,q1,1,R
q1,1,q1,1,R
q1,B,q2,B,L
q2,1,qh,B,R
(B = ☐; Use in Program 4)
4/8/2015
CS 3240 - Chapter 9
37
Input:
A TM
▪ quintuple format: state1,input,state2,output,direction
An input string (initial tape contents)
Output:
A trace of the actions of the machine
▪ with the current state positioned as the read-write head
Final state and tape contents
4/8/2015
CS 3240 - Chapter 9
38
TMs can make multiple passes over the data
in multiple directions
And can process an arbitrary amount of
auxiliary data in addition to the original input
They can give more meaningful output
vs. just yes/no
Interesting fact:
TMs came first!
4/8/2015
CS 3240 - Chapter 9
39
TMs suffer from a vulnerability that FAs and
PDAs do not:
They are not guaranteed to halt
They may hang (loop forever)!
Depends on the nature of the computation
More on this later
4/8/2015
CS 3240 - Chapter 9
40
“Any computation that can be carried out by
mechanical means can be performed by some TM”
1. Anything that can be done on any digital computer
can be done by a TM
it’s the “lowest-level” programming language
2.
No one has yet found a solvable problem for which a
TM cannot be written
3.
No alternative computation model invented is more
powerful then a TM
4/8/2015
CS 3240 - Chapter 9
41
The Turing Machine is the model for most
programming as we know it
Imperative Programming
Defines a machine architecture
Characterized by reading and writing memory
Instructions and data share the same memory
There are other models of computation
Lambda Calculus (Functional paradigm; CS 4450)
Post Systems, Markov Systems, Structured Prog…
4/8/2015
CS 3240 - Chapter 9
42