You are on page 1of 52

Turing Machines

Lecture 14-16
Ref. handout page 57 -65
an Turing
1912-1954
Great mathematician
The father of
the modern computer
Alan Turing`s Statue
at BIetchIey Park
Betchey Park
is near Miton Keynes
Haf hour from London
istorical Notes
For a ong time it was beieved that any
mathematica probem coud, at east in
principe, be proved from the basic axioms
1931, Kurt Gde proposed the theorem of
undecidabiity there exist theorems
which can neither be proved or disproved
Later, onso Church and an Turing
aso found other probems which had no
agorithmic soution
lan Turing was interested in
whether there was a way to define which
probems were/were not decidabe
(computabe)?
can we create a machine to simuate the
human brain so that those computabe
probems can be soved automaticay?
1935-36, Turing was working on a paper,
"computabe numbers. The Turing machine
in this paper turned out to be the simpest
prototype of a computers!
Turing`s Idea
thinks
State of mind changes
reads
The Turing Machines
nfiniteIy Iong) tape one symboI per square
control
unit
Current
state
Read/Write
head
...... ......
Turing Machine Conceptualization


start
reset

ctions oI a Turing Machine


ove Ieft/right one square
Change
state
Write a new symboI
onto the current tape square
depending on current state
and
current tape symboI
$tate Transitions
read write move
A B
X,Y / L
$tate Transitions
comparing with F and PD
read write move for TM
input vaue on stack/ op of stack for PD
A B
X,Y / L
$tate Transition Table
state read write move new
state
1 a b L 2
2 b b L 2
2 a b R 3
3 a b L 2
3 b c R 2
1
2
3
The InIinite Tape
a b a c a
nitiaI position of read/write
head the Ieft most)
nitiaI data finite)
BIank tape infinite)
Turing Machine Example
Test for a palindrome
aabbabbaaa


f 'a' then repace with space
go to right hand end
check for 'a'
if not found hat - error
ese go to eft hand end
do the
same
for 'b'
Cont. Transition Table Ior checking a`
state read write move New
state
start a

find
find a
find b
find

deete
deete a
deete b
deete

nswer (cont. TM Ior detecting palindromes)
start
return no
deB
yes
findB
de find
a,#
b,/R
a,a/R
b,b/R
a,a/R
b,b/R
a,a/L
b,b/L
#
b,
a,
b,b/L
a,a/L

Memo Ior In-class test 14 | /5|


questions my
answers
correct
answers
comments
1
2
3
4
5
Turing Machine Tricks
rite as many y' as there are x's
before

after
y y y y
nswer
&nary Numbers
0 x
1 x x
2 x x x
3 x x x x
4 x x x x x
5 x x x x x x
6 ......
x x x x + x x x = x x x x x x
? + ? = ?
The Limitations oI TMs
control
unit
ControI Unit
does one thing onIy
'hardware'
specific
...... ......
The 2-Tape Turing Machine
control
unit
data tape
...... ......
program tape
program tape stores the description
of a 1-tape TM's transition tabe
The 2-tape TM The &niversal TM
control
unit
ata tape
Program tape
...... ......
2-Tape Transitions
state read write move read write move new
state
tape 1 tape 2
ncudes 'no move'
The Emulator
control
unit
data tape
...... ......
program tape
etras e.g. the current state
n Example oI &TM (&niversal Turing Machine)
dding one to a binary number
e.g.
before
after
before
after
before
after
n Example oI &TM Cont.
How to go about writing a TM for adding
one (a singe-tape first)?
dea (agorithm):
1. Move the head to the right most position
2. f the right most is 0, repace it by 1,stop
3. move to eft one space
4. f the current vaue is '0' or a bank repace
it by 1, stop
1. Go to step 3
n Example oI &TM Cont.
start check
stop
carry
1,1/R
0,0/R
0,1,_
,1,
_
,/L
0,1,_
1,0,L
1,0,L
% which adds one in binary
state read write mov
new
state
start
start
1
0
1
0
R
R
start
start
start
check

L
_
check
stop
check
carry
1
1
0
0
L
L
carry
carry
carry
carry
0

1
1
_
_
stop
stop
Cont. change to 3-tape TM
S 1 1 R S S 0 0 R S S L C
Program tape
1 1 0 1
S
Data tape
Extra tape
hat`s so $pecial?
UTM
The ever
many ifting jobs
The whee
ots of uses
UTM
anything you can
'program'
Memo Ior In-class test 15 | /5|
questions my
answers
correct
answers
comments
1
2
3
4
5
Real Computer
Contro unit:
processor
Data tape:
user memory
Program tape:
program memory
Extra tape:
system memory
/O faciities added
TMs and Real` Computer - 2
Write a TM which
simuates a PC
nything a rea computer can do,a TM can do
TM
TMs and Real` Computer - 1
Write a Java program
which simuates a TM
nything a TM can do, a rea computer can do
TM
The Church-Turing Thesis
nything which can be computed can be
computed by a Turing Machine
nything which can't be done by a TM
can't be done by any computer
.orollary
$o ......
f there is anything a TM can't do
it probaby can't be done
s there anything which
TMs can't do???
But may be a TM can do anything
we can imagine (?)
Decision Problems
t is harder to say what we wi never be
abe to do rather than what we can do
(.omputable).
Consider ony simper probems decision
probems where the answer is 'yea' or 'no'.
Consider ony TMs with two hat states
'yes' and 'no'.
probem is de.idable if we can have a
TM for it which eventuay enters either the
'yes' or 'no' state depending on its input.
The alting Problem
...... n searching of an undecidabe probem.
The best-known such probem is caed the
halting problem.
Given an arbitrary program with an arbitrary
input, can we make a Turing Machine to test
whether the program stop or oop forever?
The Barber Paradox (by Bertrand Russell )
n.e upon a time, a
village barber put a
noti.e outside his shop
shave a and ony those
men in the viage who do
not shave themseves.
Q. Does the barber shave
himsef?
The Barber Paradox
U = { every man in the viage }
S = { men shave themseves }
U \ S = { men don't shave themseves}
Where does the barber beong to, S or U \ S ?
The Barber Paradox trouble in either ways
ssume: the barber does shave himsef
ny man in this viage who shaves himsef is
not shaved by barber.
Therefore, the barber does not shave himsef.
ssume: the barber doesn't shave himsef
ny man in this viage is shaved by the barber
if and ony if he is not shaved by himsef.
Therefore, the barber does shaves himsef.
hy is the Barber Paradox important?
paradox with importance to mathematica
ogic and set theory.
t was constructed to demonstrate the sef-
contradictory nature of the eementary set
theory
t underies the proof of an Turing's proof of
the undesirabiity of the hating probem.
Program Testing
(another way to look at the halting problem)
Java program is stored in a fie
The tite is caed 'abc.java'
have tested 'abc' with different data
t aways works
t's never got into an infinite oop
Can be sure it never wi for any input?
utomated Program Testing
fie containing
a program
fie of test data
Prog Test
MyTest
infinite oop /hat
The Java Prog Test Class
public class Prog Test

Public boolean halt(String 574


String /,9,)

if 574 halts when given /,9, as input


return true;
else
return false;

&sing Prog Test


import Prog Text
public class MyTest

static public void main(String` args)


String s = args`;
if(ProgTest.halt(ss))
loop forever
while(true) continue;

Running MyTest
java MyTest MyTest.java
command to
run java
MyTest
(program
To test)
with itsef
as data
$uppose It Loops
static public void main(String` args)
String s = args`; s = y%est.java
if(ProgTest.halt(ss))
loop forever
while(true) continue;

Prog%est.haIty%est.java y%est.java")
The Dilemma
f it hats it oops forever ...
f it oops forever it hats ...
The $olution
The resut is nonsense
MyTest must hat or oop
We got into this mess by assuming that
!rogTest.halts coud be written
So !rogTest.halts doesn't (can't) exist.
Conclusion
!rogTest.halts can't be written
No program exists which can te whether any
given program hats for any given data
There are some things computer can't do
Memo Ior In-class test 16 | /5|
questions my
answers
correct
answers
comments
1
2
3
4
5

You might also like