Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
WHAT IS A COMPUTER?
program
input
computer
output
WHAT IS A COMPUTER?
void hello( String name)
{
print( Hello, , name);
}
world
deep blue
E2-E4
computer
Hello, world
?
3
TURING MACHINES
control
head
a b b
input
blanks
EXAMPLE
L1 = {w#w: w {a, b}*}
Strategy:
Read and remember the first symbol
abbaa#abbaa
xbbaa#abbaa
xbbaa#abbaa
xbbaa#xbbaa
EXAMPLE
L1 = {w#w: w {a, b}*}
Strategy:
Look for the first uncrossed symbol
xbbaa#xbbaa
xxbaa#xbbaa
xxbaa#xxbaa
xxxxx#xxxxx
At the end, there should be only xs and #s
If not, reject; otherwise, accept.
6
a/bL
q2
a b a
a/bL
q2
a b b
FORMAL DEFINITION
A Turing Machine is (Q, , , , q0, qacc, qrej):
CONFIGURATIONS
A configuration consists of the current state, the head
position, and tape contents
configuration
q1
q1
qacc
a/bR
abq1a
qacc
abbqacc
CONFIGURATIONS
We say configuration C yields C if the TM can go from C
to C in one step
abq1a yields abbqacc
The start configuration of the TM on input w is q0w
10
C0 is starting
11
LOOPING
Something strange can happen in a Turing Machine:
/R
qacc
q0
= {0, 1}
input: e
qrej
This machine
never halts
accept
qrej
reject
loop
12
HALTING
We say M halts on x if there exists a sequence of
configurations C0, C1, ..., Ck where
C0 is starting
Ci yields Ci+1
Ck is accepting
or rejecting
2
3
4
5
xbbaa#xbbaa
xxbaa#xbbaa
xxbaa#xbbaa
xxbaa#xxbaa
xxbaa#xxbaa
14
x/xR
#/#R
x/xR
a/aL
b/bL
x/xL
q0 #/#R
q1 /R qacc
1
8
q2
qa1
qa2
a/aL
b/bL
#/#L
q3
qrej
everything else
qb1
a/aR
b/bR
#/#R
qb2
x/xR
x/xR
15
a/aR
b/bR
x/xR
#/#R
x/xR
a/aL
b/bL
x/xL
q0 #/#R
q1 /R qacc
1
8
q2
qa1
qb1
a/aR
b/bR
#/#R
qa2
qb2
x/xR
x/xR
a/aL
b/bL
#/#L
q3
7
configurations:
q0aab#aab
xqa1ab#aab
xaqa1b#aab
xabqa1#aab
xab#qa2aab
xabq2#xab
xaq3b#xab
xq3ab#xab
q3xab#xab
xq0ab#xab
16
aabbcccc
For every a:
aabbcccc
aabbcccc
= {a, b, c}
= {a, b, c, a, b, c, }
aabbcccc
aabbcccc
aabbcccc
aabbcccc
aabbcccc
17
Implementation details:
aaqbbcccc
aabqbcccc
aabbqcccc
aabqbcccc
aabbqcccc
aabbcqccc
aabbqcccc
Replace b by b
Move right until you see a c
Replace c by c
Move left just past the last b
If any bs are left, repeat
= {a, b, c}
= {a, b, c, a, b, c, a, a, }
19
#01#0011#1
On input w,
For every pair of blocks xi and xj in w,
Compare the blocks xi and
xj they are the same,
If
reject. accept.
Otherwise,
20
Low-level description:
#01#0011#1
#01#0011#1
#
2. Place another mark on next unmarked#01#0011#1
(If there are no more #, accept)
21
#01#0011#1
current state:
3. Compare the two strings to the right
#01#0011#1
#01#0011#1
4. Move the right # to the right
5. Repeat Step 3
#01#0011#1
22
#01#0011#1
#01#0011#1
23
24
On input G,
0. Verify that G is the description of a graph
(no vertex repeats; edges only go between nodes)
1. Mark the first node of G
1
x
4
26
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
1
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
3
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
(1,2,3,4)((1,4)(2,3)(3,4)(4,2))
etc.27
28
(1862-1943)
Z3 (Germany, 1941)
PC (1980)
30
COMPUTATION IS UNIVERSAL
31
Turing Machine
32
Turing Machine
quantum computing
cosmic computing
DNA computing
33
ALAN TURING
Invented the Turing Test to tell
humans and computers apart
Broke German encryption machines
in World War II
The Turing Award is the Nobel
prize of Computer Science
Alan Turing
(1912-1954)
UNDECIDABILITY
What Hilbert meant to ask was:
35
40
control
tape 1 0 1 0
tape 2 0 1
tape 3 1 0 0
42
0 1 0
0 1
1 0 0
q3
0/1R
/1R
0/0L
q7
1 1 0
0 1 1
1 0 0
single tape
multiple tapes
44
# 0
= {0, 1, }
0 # 0
# 1
0 #
= {0, 1, , 0, 1, , #}
45
SIMULATING A MULTITAPE TM
We show how to simulate a multitape TM on an single
tape TM
y1
y2
z1
zc
xa xi
yb
yj
zk
Multitape TM
#x1x2...x a...xi#y1y2...yb...yj#z1z2...zc...zk#
Single-tape TM
46
SIMULATING A MULTITAPE TM
Single-tape TM: Initialization
w1w2...wn
#w 1w2...wn###
# 0
0 #
S: On input w1...wn:
SIMULATING A MULTITAPE TM
Single-tape TM: Simulating Multitape TM moves
Suppose Multitape TM wants to move like this:
q3
0/1R
/1R
0/0L
q7
# 0
# 0
0 # 0
0 # 0
# 1
# 1
0 #
0
0 #
48
SIMULATING A MULTITAPE TM
S: On input w1...wn:
#x1x2...x...x
i#y1y2...y...yj#z1z2...z...zk#
transitionqi
x/xA
y/yB
z/zC
qj
DOING SIMULATIONS
To simulate a model M by another model N:
1. Say how the state and storage of N is used
to represent the state and storage of M
2. Say what should be initially done to convert
the input of N (if anything)
50
0000
arithmetic
logical unit
registers
R0
R1
R2
R3
instruction
memory
data memory
0100
1010
0000
0000
51
CPU
PC
0000
0001
0010
0011
0100
0000
arithmetic
logical unit
registers
R0
R1
R2
R3
load 0001
write R3
store R5
add R5
jpos 0011
...
0100
1010
data memory
0000
0000
0001
0010
0011
0100
0000
0110
0110
0110
0110
0110
52
INSTRUCTION SET
load x
load Rk
store Rk
read Rk
write Rk
add Rk
jump n
Set PC to n
jzero n
Set PC to n, if R0 is zero
jpos n
Set PC to n, if R0 is positive
53
program
counter
R0
registers
R1
R2
2
0
1
1
2
2
0
1
2
3
4
5
instruction
meaning
load -7
write R2
store R1
add R1
jzero 3
accept
R0 := -7
M[R2] := R0
R1 := R0
R0 := R0 + R5
if R0 = 0 then PC := 3
2
3
0
4
memory
07
14
07
R2
0-7
0
0
1
2
3
4
5
0
1
0
2
instruction
meaning
load 7
write R2
store R1
add R1
jzero 3
accept
R0 := 7
M[R2] := R0
R1 := R0
R0 := R0 + R1
if R0 = 0 then PC := 3
0
3
0
4
PC
= {0, 1, 2, ..., k}
R0
blank
56
SIMULATING A TM ON A RAM
q0 1/2R q1
R1
0
1
2
3
store R1
read R1
x
add -1
jzero 6
handle
for state
q0
save
head
position
read tape contents
if x = 1 goto line 6
6
7
8
9
10
load 2
new value of cell
write R1
write in memory
load R1
recall head position
add 1 move head to right
30
jump
go to state q1
handle for state q1
30 store R1
PC 0
R0
program
200 accept
SIMULATING A TM ON A RAM
q0 1/2R q1
R0
23
2
0
21
R1
02
program
store R1
read R1
x
add -1
jzero 6
handle
for state
q0
save
head
position
read tape contents
load 2
write R1
load R1
add 1
30
jump
30 store R1
0
1
2
3
6
7
8
9
10
(head)
if x = 1 goto line 6
12 (tape)
58
PC 14
R0
R1
17
R2
2
0
configuration =
(14, 3, 17, 5, (0, 2), (2, 1), (3, 2))
0
1
1
2
2
3
0
4
59
(14,3,17,5,(0,2),(2,1),(3,2))
60
122
...
S: On input w1...wn:
1. Replace tape contents by
(0, 0, 0, ..., 0, (0, w1), (1, w2), ..., (n-1, wn))
61
(14,3,17,5,(0,2),(2,1),(3,2))
c
s
(14,1,17,5,(0,2),(2,1),(3,2))
17
.
(14,1,17,5,(0,2),(2,1),(3,2) )
.
(14,1 ,17,5,(0,2),(2,1),(3,2))
(14,17,17,5,(0,2),(2,1),(3,2))
4. Update PC
(15,17,17,5,(0,2),(2,1),(3,2))
62
63