1 introduction to turing machines 011011111101101100010
TRANSCRIPT
1
Introduction toTuring Machines
0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 0 010
Alan Turing -- 1912 – 1954 • Mathematician, a computer scientis
• Influantial • Development of computer sciences• provided an influential formalisation
• of the concept of the algorithm • and computation with the• Turing Machine • Turing Test contribute to the debate of AI
• Can machines think?
• One of the 100 more imp. People in 20th century• 21st on BBC nation wide poll of the 100 Greatest britons• http://www.turing.org.uk/turing/• http://en.wikipedia.org/wiki/Alan_Turing/
2
3
The Turing Machine
0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 0 0101
A TM consists of an infinite length tape, on which input is provided as a finite sequence of symbols.
A head reads the input tape. The TM starts at start state s0. On reading an input symbol it optionally replaces it with another symbol, changes its internal state and moves one cell to the right or left.
4
The Turing Machine
A TM is defined as: TM = <S, T, s0, , H> where,
S is a set of TM states T is a set of tape symbols s0 is the start state H S is a set of halting states : S x T S x T x {L,R}
is the transition function
5
A Turing Machine
............Tape
Read-Write head
Control Unit
6
The Tape
............
Read-Write head
No boundaries -- infinite length
The head moves Left or Right
7
............
Read-Write head
The head at each time step:
1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right
8
............
Example:Time 0
Time 1
1. Reads
2. Writes
a a cb
a
3. Moves Left
............ a b cd
d
9
............Time 1
a c
............Time 2
a c
1. Reads
2. Writes
3. Moves Right
b
s
s
b
f
f
10
The Input String
............
Blank symbol
head
a b ca
•Head starts at the leftmost position of the input string.•The input string is never empty
Input string
# # # # #
11
States & Transitions
1q 2qLba ,
Read Write Move Left
1q 2qRba ,
Move Right
12
............ a b cTime 1
1q 2q
............ a b cTime 2
1q
2q
Example:
current state
a
d
Rda ,
13
............ a b cTime 1
1q 2qLba ,
............ a b cTime 2
1q
2q
Example:
a
b
14
............ a b caTime 1
1q 2q
............ ga b cbTime 2
1q
2q
Example:
Lg,
# # # #
# # #
15
Determinism
1q
2qRba ,
Allowed Not Allowed
3qLdb ,
1q
2qRba ,
3qLda ,
No lambda transitions allowed
Turing Machines are deterministic
16
Partial Transition Function
1q
2qRba ,
3qLdb ,
Example:
No transitionfor input symbol c
Allowed:
# #
1q
............ a b ca # # #
17
Halting
The machine halts if there areno possible transitions to follow
# #
1q
............ a b c # # #
1q
2qRba ,
3qLdb ,
c
No possible transition
HALT!!!
18
Final States
1q 2q Allowed
1q 2q Not Allowed
• Final states have no outgoing transitions• In a final state the machine halts
19
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
20
Turing Machine Example
A Turing machine that accepts the language:
*aa
0q
Raa ,
L,1q
21
aaTime 0
0q
a
0q
Raa ,
L,1q
22
aaTime 1
0q
a
0q
Raa ,
L,1q
23
aaTime 2
0q
a
0q
Raa ,
L,1q
24
aaTime 3
0q
a
0q
Raa ,
L,1q
25
aaTime 4
1q
a
0q
Raa ,
L,1q
Halt & Accept
26
Rejection Example
0q
Raa ,
L,1q
baTime 0
0q
a
27
0q
Raa ,
L,1q
baTime 1
0q
a
No possible Transition
Halt & Reject
28
Infinite Loop Example
0q
Raa ,
L,1q
Lbb ,
A Turing machine for language *)(* babaa
29
baTime 0
0q
a
0q
Raa ,
L,1q
Lbb ,
30
baTime 1
0q
a
0q
Raa ,
L,1q
Lbb ,
31
baTime 2
0q
a
0q
Raa ,
L,1q
Lbb ,
32
baTime 2
0q
a
baTime 3
0q
a
baTime 4
0q
a
baTime 5
0q
a
Infinite
loop
33
Because of the infinite loop:
•The final state cannot be reached
•The machine never halts
•The input is not accepted
34
Another Turing Machine Example
Turing machine for the language }{ nnba
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
35
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
ba
0q
a bTime 0
36
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,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,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
4q
x y
Halt & Accept
Time 13
49
If we modify the machine for the language }{ nnba
we can easily construct a machine for the language }{ nnn cba
Observation:
50
Formal Definitionsfor
Turing Machines
51
Transition Function
1q 2qRba ,
),,(),( 21 Rbqaq
52
1q 2qLdc ,
),,(),( 21 Ldqcq
Transition Function
53
Turing Machine:
),,,,,,( 0 FqQM
States
Inputalphabet
Tapealphabet
Transitionfunction
Initialstate
blank
Finalstates
54
Configuration
ba
1q
a
Instantaneous description:
c
baqca 1
55
yx
2q
a b
Time 4
yx
0q
a b
Time 5
A Move: aybqxxaybq 02
56
yx
2q
a b
Time 4
yx
0q
a b
Time 5
bqxxyybqxxaybqxxaybq 1102
yx
1q
x b
Time 6
yx
1q
x b
Time 7
57
bqxxyybqxxaybqxxaybq 1102
bqxxyxaybq 12
Equivalent notation:
58
Initial configuration: wq0
ba
0q
a b
w
Input string
59
The Accepted Language
For any Turing Machine M
}:{)( 210 xqxwqwML f
Initial state Final state
60
Standard Turing Machine
• Deterministic
• Infinite tape in both directions
•Tape is the input/output file
The machine we described is the standard:
61
Computing Functionswith
Turing Machines
62
A function )(wf
Domain: Result Region:
has:
D
Dw
S
Swf )()(wf
63
A function may have many parameters:
yxyxf ),(
Example: Addition function
64
Integer Domain
Unary:
Binary:
Decimal:
11111
101
5
We prefer unary representation:
easier to manipulate with Turing machines
65
Definition:
A function is computable ifthere is a Turing Machine such that:
fM
Initial configuration Final configuration
Dw Domain
0q
w
fq
)(wf
final stateinitial state
For all
66
)(0 wfqwq f
Initial Configuration
FinalConfiguration
A function is computable ifthere is a Turing Machine such that:
fM
In other words:
Dw DomainFor all
67
Example
The function yxyxf ),( is computable
Turing Machine:
Input string: yx0 unary
Output string: 0xy unary
yx, are integers
68
0
0q
1 1 1 1
x y
1 Start
initial state
The 0 is the delimiter that separates the two numbers
69
0
0q
1 1 1 1
x y
1
0
fq
1 1
yx
11
Start
Finish
final state
initial state
70
0
fq
1 1
yx
11Finish
final state
The 0 helps when we usethe result for other operations
71
0q
Turing machine for function
1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
yxyxf ),(
72
Execution Example:
11x
11y 0
0q
1 1 1 1
Time 0
x y
Final Result
0
4q
1 1 1 1
yx
(2)
(2)
73
0
0q
1 1Time 0
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
1 1
74
0q
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
01 11 1Time 1
75
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
0
0q
1 1 1 1Time 2
76
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
1q
1 11 11Time 3
77
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
1q
1 1 1 11Time 4
78
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
1q
1 11 11Time 5
79
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
2q
1 1 1 11Time 6
80
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
3q
1 11 01Time 7
81
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
3q
1 1 1 01Time 8
82
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
3q
1 11 01Time 9
83
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
3q
1 1 1 01Time 10
84
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
3q
1 11 01Time 11
85
0q 1q 2q 3qL, L,01
L,11
R,
R,10
R,11
4q
R,11
4q
1 1 1 01
HALT & accept
Time 12
86
Another Example
The function xxf 2)( is computable
Turing Machine:
Input string: x unary
Output string: xx unary
x is integer
87
0q
1 1
x
1
1
fq
1 1
x2
11
Start
Finish
final state
initial state
88
Turing Machine Pseudocode for xxf 2)(
• Replace every 1 with $
• Repeat:
• Find rightmost $, replace it with 1
• Go to right end, insert 1
Until no more $ remain
89
0q 1q 2q
3q
R,1$
L,1
L,
R$,1 L,11 R,11
R,
Turing Machine for xxf 2)(
90
0q 1q 2q
3q
R,1$
L,1
L,
R$,1 L,11 R,11
R,
Example
0q
1 1
3q
1 11 1
Start Finish
91
Simple TM Examples
Turing Machine U+1:
Given a string of 1s on a tape (followed by an infinite number of 0s), add one more 1 at the end of the string.
#111100000000……. #1111100000000……….
92
Simple TM Examples
TM: U+1(s0, 1) |-- (s0, 1, R) (s0, 0) |-- (h, 1, STOP)
#s0111100000….. #1s011100000….. #11s01100000….. #111s0100000….. #1111s000000….. #11111h0000….. STOP
93
Another Example
The function ),( yxf
is computable0
1 yx
yx
if
if
94
Turing Machine for
Input: yx0
Output: 1 0or
),( yxf0
1 yx
yx
if
if
95
Turing Machine Pseudocode:
Match a 1 from with a 1 from x y
• Repeat
Until all of or is matchedx y
• If a 1 from is not matched erase tape, write 1 else erase tape, write 0
x)( yx
)( yx
96
Combining Turing Machines
97
Block Diagram
TuringMachine
input output
98
Example:
),( yxf0
yx yx
yx
if
if
Comparer
Adder
Eraser
yx,
yx,
yx
yx
yx
0
99
Turing’s Thesis
Any mathematical problem solving that can be described by a mechanical procedure (algorithm) can be modeled by a Turing machine.
All computers today perform only mechanical problem solving. They are no more expressive than a Turing machine.
100
Turing’s ThesisTuring’s thesis is not a “theorem” there is no
“proof” for the thesis.The theorem may be refuted by showing at
least one task that is performed by a digital computer which cannot be performed by a Turing machine.
Many contentions have been made to this end. However, till date there have not been any conclusive evidence to refute Turing’s thesis.
101
ConclusionsTMs are at a level that is much below the
assembly language of any typical microprocessor.
So in the practical world, TMs are more useful in what they cannot do rather than in what they can.
Lab2Write some simpleTuring machine
programs
QUESTIONS?
102