Turing Machines Lecture 14-16 Ref. handout page 57 -65.
-
Upload
chandler-storer -
Category
Documents
-
view
228 -
download
2
Transcript of Turing Machines Lecture 14-16 Ref. handout page 57 -65.
![Page 1: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/1.jpg)
Turing Machines
Lecture 14-16
Ref. handout page 57 -65
![Page 2: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/2.jpg)
Alan Turing 1912-1954
Great mathematician The father of
the modern computer
![Page 3: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/3.jpg)
Alan Turing’s Statueat Bletchley Park
Bletchley Park is near Milton Keynes Half hour from London
![Page 4: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/4.jpg)
Historical Notes
For a long time it was believed that any mathematical problem could, at least in principle, be proved from the basic axioms
1931, Kurt Gödel proposed the theorem of undecidability – there exist theorems which can neither be proved or disproved
Later, Alonso Church and Alan Turing also found other problems which had no algorithmic solution
![Page 5: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/5.jpg)
Alan Turing was interested in whether there was a way to define which
problems were/were not decidable (computable)?
can we create a machine to simulate the human brain so that those computable problems can be solved automatically?
1935-36, Turing was working on a paper, “computable numbers”. The Turing machine in this paper turned out to be the simplest prototype of all computers!
![Page 6: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/6.jpg)
Turing’s Idea
a+b*x/y
thinks
State of mind changes
reads
makes notes
![Page 7: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/7.jpg)
The Turing Machines
(Infinitely long) tape, one symbol per square
control unit
Currentstate
Read/Writehead
...... ......
![Page 8: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/8.jpg)
A Turing Machine Conceptualization
0
00
-
-- 0
start
reset
-
-
![Page 9: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/9.jpg)
Actions of a Turing Machine
Move left/right one square
Change
state
Write a new symbol
onto the current tape square
depending on current state
and
current tape symbol
![Page 10: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/10.jpg)
State Transitions
read write move
A BX,Y / L
![Page 11: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/11.jpg)
State Transitions – comparing with FA and PDA
read write move for TM
input value on stack/ op of stack for PDA
A BX,Y / L
![Page 12: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/12.jpg)
A State 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
![Page 13: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/13.jpg)
The Infinite Tape
a b aca
Initial position of read/writehead (the left most)
Initial data (finite)
Blank tape (infinite)
![Page 14: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/14.jpg)
A Turing Machine Example
Test for a palindrome
aabbabbaaa □ □ □ □ □ □ □ □ □ □
If ‘a’ then replace with spacego to right hand endcheck for ‘a’if not found halt -> errorelse go to left hand end
do the samefor ‘b’
![Page 15: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/15.jpg)
Cont. Transition Table for checking ‘a’
state read write move New state
start a □ findA
findA a
findA b
findA □ deleteA
deleteA a
deleteA b
deleteA □
![Page 16: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/16.jpg)
Answer (cont. TM for detecting palindromes)
startreturn no
delB
yes
findB
delAfindAa,□/R
b,□/R
a,a/Rb,b/R
a,a/Rb,b/R
a,a/Lb,b/L
□,□/R
b,□/L
a,□/L
b,b/L
a,a/L
□,□/L
□,□/L
□,□/L
□,□/L
□,□/L
![Page 17: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/17.jpg)
Memo for In-class test 14 [ /5]
questions my answers
correct answers
comments
1
2
3
4
5
![Page 18: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/18.jpg)
Turing Machine Tricks
Write as many y’ as there are x’s
before
□ □ □ □ x x x x □ □ □ □
after
□ □ □ □ x x x x □ y y y y □ □ □ □
![Page 19: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/19.jpg)
Answer
![Page 20: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/20.jpg)
Unary Numbers
0 x1 x x2 x x x3 x x x x 4 x x x x x5 x x x x x x 6 ......
x x x x + x x x = x x x x x x ? + ? = ?
![Page 21: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/21.jpg)
The Limitations of TMs
control unit
Control Unitdoes one thing only
‘hardware’specific
...... ......
![Page 22: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/22.jpg)
The 2-Tape Turing Machine
control unit
data tape
...... ......
program tape
program tape stores the description of a 1-tape TM’s transition table
![Page 23: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/23.jpg)
The 2-tape TM – The Universal TM
control unit
Data tape
Program tape
...... ......
![Page 24: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/24.jpg)
2-Tape Transitions
state read write move read write move new
state
tape 1 tape 2
Includes ‘no move’
![Page 25: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/25.jpg)
The Emulator
control unit
data tape
...... ......
program tape
extras, e.g. the current state
![Page 26: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/26.jpg)
An Example of UTM (Universal Turing Machine)
Adding one to a binary numbere.g.before □ □ □ □ 1 0 1 0 □ □ □ □after □ □ □ □ 1 0 1 1 □ □ □ □
before □ □ □ □ 1 0 1 1 □ □ □ □after □ □ □ □ 1 1 0 0 □ □ □ □
before □ □ □ □ 1 1 1 1 □ □ □ □after □ □ □ 1 0 0 0 0 □ □ □ □
![Page 27: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/27.jpg)
An Example of UTM Cont.
How to go about writing a TM for adding one (a single-tape first)?
Idea (algorithm):
1. Move the head to the right most position
2. If the right most is 0, replace it by 1,stop
3. move to left one space
4. If the current value is ‘0’ or a blank replace
it by 1, stop
1. Go to step 3
![Page 28: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/28.jpg)
An Example of UTM Cont.
start check
stop carry
1,1/R0,0/R
0,1,_□,1, _
□,□ /L
0,1,_
1,0,L
1,0,L
A TM which adds one in binary
state read write mov
new
state
start
start
1
0
1
0
R
R
start
start
start
check
□
0
□
1
L
_
check
stop
check
carry
1
1
0
0
L
L
carry
carry
carry
carry
0
□
1
1
_
_
stop
stop
![Page 29: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/29.jpg)
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
![Page 30: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/30.jpg)
What’s so Special?
UTM
•The lever – many lifting jobs
•The wheel – lots of uses
•UTM –anything you can
‘program’
![Page 31: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/31.jpg)
Memo for In-class test 15 [ /5]
questions my answers
correct answers
comments
1
2
3
4
5
![Page 32: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/32.jpg)
A Real Computer
Control unit: processor
Data tape: user memory
Program tape:
program memory
Extra tape:
system memoryI/O facilities added
![Page 33: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/33.jpg)
TMs and ‘Real’ Computer - 2
Write a TM which simulates a PC
Anything a real computer can do,a TM can do
TM
![Page 34: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/34.jpg)
TMs and ‘Real’ Computer - 1
Write a Java program which simulates a TM
Anything a TM can do, a real computer can do
TM
![Page 35: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/35.jpg)
The Church-Turing Thesis
Anything which can be computed can be computed by a Turing Machine
Anything which can’t be done by a TM can’t be done by any computer
corollary
![Page 36: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/36.jpg)
So ......
If there is anything a TM can’t doit probably can’t be done
Is there anything which TMs can’t do???
But may be a TM can do anything we can imagine (?)
![Page 37: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/37.jpg)
Decision Problems
It is harder to say what we will never be able to do rather than what we can do (computable).
Consider only simpler problems – decision problems where the answer is ‘yea’ or ‘no’.
Consider only TMs with two halt states ‘yes’ and ‘no’.
A problem is decidable if we can have a TM for it which eventually enters either the ‘yes’ or ‘no’ state depending on its input.
![Page 38: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/38.jpg)
The Halting Problem
...... In searching of an undecidable problem.
The best-known such problem is called the halting problem.
Given an arbitrary program with an arbitrary input, can we make a Turing Machine to test whether the program stop or loop forever?
![Page 39: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/39.jpg)
The Barber Paradox (by Bertrand Russell )
Once upon a time, a village barber put a notice outside his shop
I shave all and only thosemen in the village who do not shave themselves.
Q. Does the barber shave himself?
![Page 40: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/40.jpg)
The Barber Paradox
U = { every man in the village }S = { men shave themselves }U \ S = { men don’t shave themselves}
Where does the barber belong to, S or U \ S ?
![Page 41: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/41.jpg)
The Barber Paradox – trouble in either ways
Assume: the barber does shave himselfAny man in this village who shaves himself is not shaved by barber.Therefore, the barber does not shave himself.
Assume: the barber doesn’t shave himselfAny man in this village is shaved by the barber if and only if he is not shaved by himself. Therefore, the barber does shaves himself.
![Page 42: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/42.jpg)
Why is the Barber Paradox important?
A paradox with importance to mathematical logic and set theory.
It was constructed to demonstrate the self-contradictory nature of the elementary set theory
It underlies the proof of Alan Turing’s proof of the undesirability of the halting problem.
![Page 43: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/43.jpg)
Program Testing – (another way to look at the halting problem)
A Java program is stored in a file
The title is called ‘abc.java’
• I have tested ‘abc’ with different data• It always works• It’s never got into an infinite loop• Can I be sure it never will for any input?
![Page 44: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/44.jpg)
Automated Program Testing
A file containing
a program
A file of test data
Prog Test
MyTest
infinite loop /halt
![Page 45: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/45.jpg)
The Java Prog Test Class
public class Prog Test
{
Public boolean halt(String prog, String data)
{
if prog halts when given data as input
return true;
else
return false;
}
}
![Page 46: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/46.jpg)
Using Prog Test
import Prog Textpublic class MyTest{
static public void main(String[] args){ String s = args[0];
if(ProgTest.halt(s,s)) // loop foreverwhile(true) continue;
}}
![Page 47: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/47.jpg)
Running MyTest
java MyTest MyTest.java
command to run java
MyTest(programTo test)
with itselfas data
![Page 48: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/48.jpg)
Suppose It Loops
static public void main(String[] args)
{ String s = args[0]; s = MyTest.java
if(ProgTest.halt(s,s))
// loop forever
while(true) continue;
}
ProgTest.halt(“MyTest.java, “MyTest.java”)
![Page 49: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/49.jpg)
The Dilemma
If it halts it loops forever ...
If it loops forever it halts ...
![Page 50: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/50.jpg)
The Solution
The result is nonsense –
MyTest must halt or loop
We got into this mess by assuming that
ProgTest.halts could be written
So ProgTest.halts doesn’t (can’t) exist.
![Page 51: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/51.jpg)
Conclusion
ProgTest.halts can’t be written
No program exists which can tell whether any given program halts for any given data
There are some things computer can’t do
![Page 52: Turing Machines Lecture 14-16 Ref. handout page 57 -65.](https://reader036.fdocuments.net/reader036/viewer/2022062307/5517fb7b550346c1568b4ffd/html5/thumbnails/52.jpg)
Memo for In-class test 16 [ /5]
questions my answers
correct answers
comments
1
2
3
4
5