Automata Unit 5
Automata Unit 5
Automata Unit 5
Unit 5
Cosc 3101 1
Foundations
Cosc 3101 2
The Turing Machine
In order to argue for this claim, he (4) At any time, the machine is in one
needed a clear concept of “mechanical of a finite number of internal
procedure.” states.
His idea — which came to be called (5) The machine has instructions that
the Turing machine — was this: determine what it does given its
internal state and the symbol it
(1) A tape of infinite length
encounters on the tape. It can
(2) Finitely many squares of change its internal state;
the tape have a single
symbol from a finite change the symbol on the
language. square;
move forward;
(3) Someone (or something)
that can read the squares move backward;
and write in them. (Read-Write Head)
halt (i.e. stop).
Cosc 3101 3
Cosc 3101 4
Can Machines Think?
In “Computing machinery and intelligence,” written in
1950, Turing asks whether machines can think.
He claims that this question is too vague, and proposes,
instead, to replace it with a different one.
Cosc 3101 5
The Turing Test
The game runs as follows:
•You sit at a computer terminal and have an electronic
conversation.
•You don’t know who is on the other end; it could be a
person or a computer responding as it has been programmed
to do.
•If you can’t distinguish between a human being and a
computer from your interactions, then the computer is
intelligent.
Note that this is meant to be a sufficient condition of
intelligence only. There may be other ways to be intelligent.
Cosc 3101 6
Turing Test
• An art of creating machines that perform functions requiring
intelligence when performed by people.
• Turing (1950) "Computing machinery and intelligence":
"Can machines think?" "Can machines behave intelligently?"
• Operational test for intelligent behavior: the Imitation Game
Cosc 3101 7
The Language Hierarchy
n n n ?
a b c ww ?
Context-Free Languages
n n R
a b ww
Regular Languages
a* a *b *
Cosc 3101 8
Languages accepted by
Turing Machines
n n n
a b c ww
Context-Free Languages
n n R
a b ww
Regular Languages
a* a *b *
Cosc 3101 9
A Turing Machine
Tape
...... ......
Read-Write head
Control Unit
Cosc 3101 10
The Tape
Read-Write head
Cosc 3101 11
...... ......
Read-Write head
1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
Cosc 3101 12
Example: a k , L
Time 0
...... a b a c ......
Time 1
...... a b k c ......
1. Reads a
2. Writes k
3. Moves Left
Cosc 3101 13
Example: b f , R
Time 1
...... a b k c ......
Time 2
...... a f k c ......
1. Reads b
2. Writes f
3. Moves Right
Cosc 3101 14
The Input String
...... a b a c ......
head
...... a b a c ......
head
Cosc 3101 16
States & Transitions
Read Write
Move Left
q1 a b, L q2
Move Right
q1 a b, R q2
Cosc 3101 17
Example:
Time 1
...... a b a c ......
q1
Time 2
...... a b b c ......
q2
q1 a b, R q2
Cosc 3101 18
Example:
Time 1
...... a b a c ......
q1
Time 2
...... a b b c ......
q2
q1 a b, L q2
Cosc 3101 19
Example:
Time 1
...... a b a c ......
q1
Time 2
...... a b b c g ......
q2
q1 g, R q2
Cosc 3101 20
Determinism
Turing Machines are deterministic
q1 q1
q3 a d, L q3
b d, L
...... a b a c ......
q1
a b, R q2 Allowed:
q1 No transition
for input symbol c
b d, L q3
Cosc 3101 22
Halting
Cosc 3101 23
Example:
...... a b a c ......
q1
a b, R q2
No possible transition
q1
HALT!!!
b d, L q3
Cosc 3101 24
Final States
q1 q2 Allowed
q1 q2 Not Allowed
If machine halts
Accept Input
in a final state
If machine halts
in a non-final state
Reject Input or
If machine enters
an infinite loop
Cosc 3101 26
Turing Machine Example
a a, R
, L
q0 q1
Cosc 3101 27
Time 0 a a a
q0
a a, R
, L
q0 q1
Cosc 3101 28
Time 1 a a a
q0
a a, R
, L
q0 q1
Cosc 3101 29
Time 2 a a a
q0
a a, R
, L
q0 q1
Cosc 3101 30
Time 3 a a a
q0
a a, R
, L
q0 q1
Cosc 3101 31
Time 4 a a a
q1
, L
q0 q1
Cosc 3101 32
Rejection Example
Time 0 a b a
q0
a a, R
, L
q0 q1
Cosc 3101 33
Time 1 a b a
q0
No possible Transition
a a, R Halt & Reject
, L
q0 q1
Cosc 3101 34
Infinite Loop Example
A Turing machine
for language aa * b(a b) *
b b, L
a a, R
, L
q0 q1
Cosc 3101 35
Time 0 a b a
q0
b b, L
a a, R
, L
q0 q1
Cosc 3101 36
Time 1 a b a
q0
b b, L
a a, R
, L
q0 q1
Cosc 3101 37
Time 2 a b a
q0
b b, L
a a, R
, L
q0 q1
Cosc 3101 38
Time 2 a b a
q0
Time 3 a b a
Infinite loop
q0
Time 4 a b a
q0
Time 5 a b a
q0
Cosc 3101 39
Because of the infinite loop:
Cosc 3101 40
Formal Definitions
for
Turing Machines
Cosc 3101 41
Turing Machine: 7 Tuple
Input Tape
alphabet alphabet
States
M (Q, , , , q0 , , F )
Transition Final
function states
Initial blank
Cosc 3101
state 42
Standard Turing Machine
Cosc 3101 44
Example
x, y are integers
Turing Machine:
Cosc 3101 45
x y
Start 1 1 1 0 1 1
q0
initial state
Cosc 3101 46
x y
Start 1 1 1 0 1 1
q0 initial state
x y
Finish 1 1 1 1 0
q f final state
Cosc 3101 47
Turing machine for function f ( x, y ) x y
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 48
Execution Example: Time 0
x y
x 11 (2)
1 1 0 1 1
y 11 (2)
q0
Final Result
x y
1 1 1 1 0
q4
Cosc 3101 49
Time 0 1 1 0 1 1
q0
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 50
Time 1 1 1 0 1 1
q0
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 51
Time 2 1 1 0 1 1
q0
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 52
Time 3 1 1 1 1 1
q1
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 53
Time 4 1 1 1 1 1
q1
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 54
Time 5 1 1 1 1 1
q1
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 55
Time 6 1 1 1 1 1
q2
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 56
Time 7 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 57
Time 8 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 58
Time 9 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 59
Time 10 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 60
Time 11 1 1 1 1 0
q3
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
q4
Cosc 3101 61
Time 12 1 1 1 1 0
q4
1 1, R 1 1, R 1 1, L
q0 0 1, R q1 , L q2
1 0, L q3
, R
HALT & accept q4
Cosc 3101 62
A limitation of Turing Machines:
they execute
only one program
Real Computers are re-programmable
Solution: Universal Turing Machine
Attributes:
• Reprogrammable machine
Cosc 3101
• Simulates any other Turing Machine 63
Universal Turing Machine
•In the 1936 paper Turing proved that there are “general-
purpose” Turing machines that can compute whatever any
other Turing machine.
•This is done by coding the function of the special-purpose
machine as instructions of the other machine — that is by
“programming” it. This is called Turing’s theorem.
•In computer science, a universal Turing
machine (UTM) is a Turing machine that can
simulate an arbitrary Turing machine on arbitrary
input.
•The concept of the universal Turing machine is just the
concept of the computer as we know it.
Cosc 3101 64