0% found this document useful (0 votes)
101 views

Class 15

The document discusses Turing machines and their ability to compute functions. It defines a Turing machine as having a tape, read/write head, finite set of states, transition function, initial state, and final states. A function is computable by a Turing machine if the machine can take any input from the domain, move through its states according to the transition function, and halt in a final state with the output written on the tape. As an example, a Turing machine is described that can compute the addition function by taking two numbers in unary notation as input and writing their sum in unary notation as output. Human: Thank you for the summary. You captured the key points about Turing machines and their ability to

Uploaded by

annu khandelwal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Class 15

The document discusses Turing machines and their ability to compute functions. It defines a Turing machine as having a tape, read/write head, finite set of states, transition function, initial state, and final states. A function is computable by a Turing machine if the machine can take any input from the domain, move through its states according to the transition function, and halt in a final state with the output written on the tape. As an example, a Turing machine is described that can compute the addition function by taking two numbers in unary notation as input and writing their sum in unary notation as output. Human: Thank you for the summary. You captured the key points about Turing machines and their ability to

Uploaded by

annu khandelwal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 87

1

Turing Machines

2
The Language Hierarchy
* a
Regular Languages
Context-Free Languages
n n
b a
R
ww
n n n
c b a
ww
?
* *b a
?
3
* a
Regular Languages
Context-Free Languages
n n
b a
R
ww
n n n
c b a
ww
* *b a
Languages accepted by
Turing Machines
4
A Turing Machine
...... ......
Tape
Read-Write head
Control Unit
5
The Tape
...... ......
Read-Write head
No boundaries -- infinite length
The head moves Left or Right
6
...... ......
Read-Write head
The head at each time step:

1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
7
...... ......
Example:
Time 0
...... ......
Time 1
1. Reads
2. Writes
a a c
b
a
b
k
c
a
k
3. Moves Left
8
...... ......
Time 1
a
b
k
c
...... ......
Time 2
a
k
c f
1. Reads
2. Writes
b
f
3. Moves Right
9
The Input String
...... ......
^ ^ ^ ^
Blank symbol
head
^
a
b
c a
Head starts at the leftmost position
of the input string
Input string
10
...... ......
^ ^ ^ ^
Blank symbol
head
^
a
b
c a
Input string
Remark: the input string is never empty
11
States & Transitions
1
q
2
q
L b a ,
Read
Write
Move Left
1
q
2
q
R b a ,
Move Right
12
Example:
1
q
2
q
R b a ,
...... ......
^ ^ ^ ^ ^
a
b
c a
Time 1
1
q
current state
13
...... ......
^ ^ ^ ^ ^
a
b
c a
Time 1
1
q
2
q
R b a ,
...... ......
^ ^ ^ ^ ^
a
b
c
b
Time 2
1
q
2
q
14
...... ......
^ ^ ^ ^ ^
a
b
c a
Time 1
1
q
2
q
L b a ,
...... ......
^ ^ ^ ^ ^
a
b
c
b
Time 2
1
q
2
q
Example:
15
...... ......
^ ^ ^ ^ ^
a
b
c a
Time 1
1
q
2
q
R g, ^
...... ......
^ ^ ^ ^
g
a
b
c
b
Time 2
1
q
2
q
Example:
16
Determinism
1
q
2
q
R b a ,
Allowed
Not Allowed
3
q
L d b ,
1
q
2
q
R b a ,
3
q
L d a ,
No lambda transitions allowed
Turing Machines are deterministic
17
Partial Transition Function
1
q
2
q
R b a ,
3
q
L d b ,
...... ......
^ ^ ^ ^ ^
a
b
c a
1
q
Example:
No transition
for input symbol c
Allowed:
18
Halting
The machine halts if there are
no possible transitions to follow
19
Example:
...... ......
^ ^ ^ ^ ^
a
b
c a
1
q
1
q
2
q
R b a ,
3
q
L d b ,
No possible transition
HALT!!!
20
Final States
1
q
2
q
Allowed
1
q
2
q
Not Allowed
Final states have no outgoing transitions

In a final state the machine halts
21
Acceptance
Accept Input
If machine halts
in a final state
Reject Input
If machine halts
in a non-final state
or
If machine enters
an infinite loop
22
Turing Machine Example
A Turing machine that accepts the language:
* aa
0
q
R a a ,
L , ^ ^
1
q
23
^ ^ ^ ^
a a
Time 0
0
q
a
0
q
R a a ,
L , ^ ^
1
q
24
^ ^ ^ ^
a a
Time 1
0
q
a
0
q
R a a ,
L , ^ ^
1
q
25
^ ^ ^ ^
a a
Time 2
0
q
a
0
q
R a a ,
L , ^ ^
1
q
26
^ ^ ^ ^
a a
Time 3
0
q
a
0
q
R a a ,
L , ^ ^
1
q
27
^ ^ ^ ^
a a
Time 4
1
q
a
0
q
R a a ,
L , ^ ^
1
q
Halt & Accept
28
Rejection Example
0
q
R a a ,
L , ^ ^
1
q
^ ^ ^ ^
b
a
Time 0
0
q
a
29
0
q
R a a ,
L , ^ ^
1
q
^ ^ ^ ^
b
a
Time 1
0
q
a
No possible Transition
Halt & Reject
30
Infinite Loop Example
0
q
R a a ,
L , ^ ^
1
q
L b b ,
A Turing machine
for language
* ) ( * b a b aa + +
31
^ ^ ^ ^
b
a
Time 0
0
q
a
0
q
R a a ,
L , ^ ^
1
q
L b b ,
32
^ ^ ^ ^
b
a
Time 1
0
q
a
0
q
R a a ,
L , ^ ^
1
q
L b b ,
33
^ ^ ^ ^
b
a
Time 2
0
q
a
0
q
R a a ,
L , ^ ^
1
q
L b b ,
34
^ ^ ^ ^
b
a
Time 2
0
q
a
^ ^ ^ ^
b
a
Time 3
0
q
a
^ ^ ^ ^
b
a
Time 4
0
q
a
^ ^ ^ ^
b
a
Time 5
0
q
a
I
n
f
i
n
i
t
e

l
o
o
p

35
Because of the infinite loop:

The final state cannot be reached

The machine never halts

The input is not accepted
36
Formal Definitions
for
Turing Machines

37
Transition Function
1
q
2
q
R b a ,
) , , ( ) , (
2 1
R b q a q = o
38
1
q
2
q
L d c ,
) , , ( ) , (
2 1
L d q c q = o
Transition Function
39
Turing Machine:
) , , , , , , (
0
F q Q M ^ I E = o
States
Input
alphabet
Tape
alphabet
Transition
function
Initial
state
blank
Final
states
40
Configuration
^ ^ ^
b
a
1
q
a
Instantaneous description:
c
^
ba q ca
1
41
^ ^
y x
2
q
a
b
Time 4
^ ^
y x
0
q
a
b
Time 5
^ ^
A Move:
ayb q x xayb q
0 2

42
^ ^
y x
2
q
a
b
Time 4
^ ^
y x
0
q
a
b
Time 5
^ ^
b q xxy yb q xx ayb q x xayb q
1 1 0 2

^ ^
y x
1
q
x
b
Time 6
^ ^
y x
1
q
x
b
Time 7
^ ^
43
b q xxy yb q xx ayb q x xayb q
1 1 0 2

b q xxy xayb q
1 2
-

Equivalent notation:
44
Initial configuration:
w q
0
^ ^ b
a
0
q
a
b ^
w
Input string
45
The Accepted Language
For any Turing Machine
M
} : { ) (
2 1 0
x q x w q w M L
f
-
=
Initial state Final state
46
Standard Turing Machine
Deterministic

Infinite tape in both directions

Tape is the input/output file
The machine we described is the standard:
47
Computing Functions
with
Turing Machines

48
A function
) (w f
Domain:
Result Region:
has:
D
D we
S
S w f e ) (
) (w f
49
A function may have many parameters:
y x y x f + = ) , (
Example:
Addition function
50
Integer Domain
Unary:
Binary:
Decimal:
11111
101
5
We prefer unary representation:
easier to manipulate with Turing machines
51
Definition:
A function is computable if
there is a Turing Machine such that:
f
M
Initial configuration Final configuration
D we Domain
^
0
q
^
w
^
f
q
^
) (w f
final state initial state
For all
52
) (
0
w f q w q
f
-

Initial
Configuration
Final
Configuration
A function is computable if
there is a Turing Machine such that:
f
M
In other words:
D we Domain
For all
53
Example
The function
y x y x f + = ) , ( is computable
Turing Machine:
Input string:
y x0
unary
Output string: 0 xy
unary
y x,
are integers
54
^ 0
0
q
1 1 ^ 1 1
x y
1

Start
initial state
The 0 is the delimiter that
separates the two numbers
55
^ 0
0
q
1 1 ^ 1 1
x y
1

^ 0
f
q
1 ^ 1
y x +

1 1
Start
Finish
final state
initial state
56
^ 0
f
q
1 ^ 1
y x +

1 1
Finish
final state
The 0 helps when we use
the result for other operations
57
0
q
Turing machine for function
1
q
2
q
3
q
L , ^ ^ L , 0 1
L , 1 1
R , ^ ^
R , 1 0
R , 1 1
4
q
R , 1 1
y x y x f + = ) , (
58
Execution Example:
11 = x
11 = y
^ 0
0
q
1 1 ^ 1 1
Time 0
x y
Final Result
^ 0
4
q
1 1 ^ 1 1
y x +
(2)
(2)
59
^ 0
0
q
1 1 Time 0 ^
0
q
1
q
2
q
3
q
L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0 1 Time 10
70
0
q
1
q
2
q
3
q
L , ^ ^ L , 0 1
L , 1 1
R , ^ ^
R , 1 0
R , 1 1
4
q
R , 1 1
^
3
q
^ 1 1 1
0 1 Time 11
71
0
q
1
q
2
q
3
q
L , ^ ^ L , 0 1
L , 1 1
R , ^ ^
R , 1 0
R , 1 1
4
q
R , 1 1
^
4
q
1 1 ^ 1
0 1
HALT & accept
Time 12
72
Another Example
The function
x x f 2 ) ( = is computable
Turing Machine:
Input string: x
unary
Output string:
xx
unary
x
is integer
73
^
0
q
1 ^ 1
x
1

^ 1
f
q
1 ^ 1
x 2

1 1
Start
Finish
final state
initial state
74
Turing Machine Pseudocode for x x f 2 ) ( =
Replace every 1 with $
Repeat:
Find rightmost $, replace it with 1

Go to right end, insert 1
Until no more $ remain
75
0
q
1
q
2
q
3
q
R , 1 $
L , 1 ^
L , ^ ^
R $, 1
L , 1 1 R , 1 1
R , ^ ^
Turing Machine for
x x f 2 ) ( =
76
0
q
1
q
2
q
3
q
R , 1 $
L , 1 ^
L , ^ ^
R $, 1
L , 1 1 R , 1 1
R , ^ ^
Example
^
0
q
1 ^ 1
^
3
q
^ 1 1 1 1
Start
Finish
77
Another Example
The function
= ) , ( y x f
is computable
0
1
y x >
y x s
if
if
78
Turing Machine for
Input:
y x0
Output:
1 0 or
= ) , ( y x f
0
1
y x >
y x s
if
if
79
Turing Machine Pseudocode:
Match a 1 from with a 1 from
x y
Repeat
Until all of or is matched x y
If a 1 from is not matched
erase tape, write 1
else
erase tape, write 0
x
) ( y x >
) ( y x s
80
Combining Turing Machines

81
Block Diagram
Turing
Machine
input output
82
Example:
= ) , ( y x f
0
y x +
y x >
y x s
if
if
Comparer
Adder
Eraser
y x,
y x,
y x >
y x s
y x +
0
83
Turings Thesis

84
Turings thesis:
Any computation carried out
by mechanical means
can be performed by a Turing Machine
(1930)
85
Computer Science Law:
A computation is mechanical
if and only if
it can be performed by a Turing Machine
There is no known model of computation
more powerful than Turing Machines
86
Definition of Algorithm:
An algorithm for function
is a
Turing Machine which computes
) (w f
) (w f
87
When we say:
There exists an algorithm
Algorithms are Turing Machines
We mean:
There exists a Turing Machine
that executes the algorithm

You might also like