Fall 2006 Costas Busch - RPI 1
Turing Machines
Fall 2006 Costas Busch - RPI 2
The Language Hierarchy
*a
Regular Languages
Context-Free Languages
nn
ba R
ww
nnn
cba ww?
**ba
?
Fall 2006 Costas Busch - RPI 3
*a
Regular Languages
Context-Free Languages
nn
ba R
ww
nnn
cba ww
**ba
Languages accepted by
Turing Machines
Fall 2006 Costas Busch - RPI 4
A Turing Machine
............
Tape
Read-Write head
Control Unit
Fall 2006 Costas Busch - RPI 5
The Tape
............
Read-Write head
No boundaries -- infinite length
The head moves Left or Right
Fall 2006 Costas Busch - RPI 6
............
Read-Write head
The head at each transition (time step):
1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
Fall 2006 Costas Busch - RPI 7
............
Example:
Time 0
............
Time 1
1. Reads
2. Writes
a a cb
a b k c
a
k
3. Moves Left
Fall 2006 Costas Busch - RPI 8
............
Time 1
a b k c
............
Time 2
a k cf
1. Reads
2. Writes
b
f
3. Moves Right
Fall 2006 Costas Busch - RPI 9
The Input String
............ ◊ ◊ ◊ ◊
Blank symbol
head
◊a b ca
Head starts at the leftmost position
of the input string
Input string
Fall 2006 Costas Busch - RPI 10
States & Transitions
1q 2qLba ,→
Read Write
Move Left
1q 2qRba ,→
Move Right
Fall 2006 Costas Busch - RPI 11
Example:
1q 2qRba ,→
............ ◊ ◊ ◊ ◊◊a b ca
Time 1
1q
current state
Fall 2006 Costas Busch - RPI 12
............ ◊ ◊ ◊ ◊◊a b ca
Time 1
1q 2qRba ,→
............ ◊ ◊ ◊ ◊◊a b cb
Time 2
1q
2q
Fall 2006 Costas Busch - RPI 13
............ ◊ ◊ ◊ ◊◊a b ca
Time 1
1q 2qLba ,→
............ ◊ ◊ ◊ ◊◊a b cb
Time 2
1q
2q
Example:
Fall 2006 Costas Busch - RPI 14
............ ◊ ◊ ◊ ◊◊a b ca
Time 1
1q 2qRg,→◊
............ ◊ ◊ ◊ ◊ga b cb
Time 2
1q
2q
Example:
Fall 2006 Costas Busch - RPI 15
Determinism
1q
2qRba ,→
Allowed Not Allowed
3qLdb ,→
1q
2qRba ,→
3qLda ,→
No lambda transitions allowed
Turing Machines are deterministic
Fall 2006 Costas Busch - RPI 16
Partial Transition Function
1q
2qRba ,→
3qLdb ,→
............ ◊ ◊ ◊ ◊◊a b ca
1q
Example:
No transition
for input symbol c
Allowed:
Fall 2006 Costas Busch - RPI 17
Halting
The machine halts in a state if there is
no transition to follow
Fall 2006 Costas Busch - RPI 18
Halting Example 1:
............ ◊ ◊ ◊ ◊◊a b ca
1q
1q No transition from
HALT!!!
1q
Fall 2006 Costas Busch - RPI 19
Halting Example 2:
............ ◊ ◊ ◊ ◊◊a b ca
1q
1q
2qRba ,→
3qLdb ,→
No possible transition
from and symbol
HALT!!!
1q c
Fall 2006 Costas Busch - RPI 20
Accepting States
1q 2q Allowed
1q 2q Not Allowed
•Accepting states have no outgoing transitions
•The machine halts and accepts
Fall 2006 Costas Busch - RPI 21
Acceptance
Accept Input
If machine halts
in an accept state
Reject Input
If machine halts
in a non-accept state
or
If machine enters
an infinite loop
string
string
Fall 2006 Costas Busch - RPI 22
Observation:
In order to accept an input string,
it is not necessary to scan all the
symbols in the string
Fall 2006 Costas Busch - RPI 23
Turing Machine Example
Accepts the language: *a
0q
Raa ,→
L,◊→◊
1q
Input alphabet },{ ba=Σ
Fall 2006 Costas Busch - RPI 24
◊ ◊ ◊ ◊aaTime 0
0q
a
0q
Raa ,→
L,◊→◊
1q
Fall 2006 Costas Busch - RPI 25
◊ ◊ ◊ ◊aaTime 1
0q
a
0q
Raa ,→
L,◊→◊
1q
Fall 2006 Costas Busch - RPI 26
◊ ◊ ◊ ◊aaTime 2
0q
a
0q
Raa ,→
L,◊→◊
1q
Fall 2006 Costas Busch - RPI 27
◊ ◊ ◊ ◊aaTime 3
0q
a
0q
Raa ,→
L,◊→◊
1q
Fall 2006 Costas Busch - RPI 28
◊ ◊ ◊ ◊aaTime 4
1q
a
0q
Raa ,→
L,◊→◊
1q
Halt & Accept
Fall 2006 Costas Busch - RPI 29
Rejection Example
0q
Raa ,→
L,◊→◊
1q
◊ ◊ ◊ ◊baTime 0
0q
a
Fall 2006 Costas Busch - RPI 30
0q
Raa ,→
L,◊→◊
1q
◊ ◊ ◊ ◊baTime 1
0q
a
No possible Transition
Halt & Reject
Fall 2006 Costas Busch - RPI 31
Accepts the language: *a
0q
but for input alphabet }{a=Σ
A simpler machine for same language
Fall 2006 Costas Busch - RPI 32
◊ ◊ ◊ ◊aaTime 0
0q
a
0q
Halt & Accept
Not necessary to scan input
Fall 2006 Costas Busch - RPI 33
Infinite Loop Example
0q
Raa ,→
L,◊→◊
1q
Lbb ,→
A Turing machine
for language *)(* baba ++
Fall 2006 Costas Busch - RPI 34
◊ ◊ ◊ ◊baTime 0
0q
a
0q
Raa ,→
L,◊→◊
1q
Lbb ,→
Fall 2006 Costas Busch - RPI 35
◊ ◊ ◊ ◊baTime 1
0q
a
0q
Raa ,→
L,◊→◊
1q
Lbb ,→
Fall 2006 Costas Busch - RPI 36
◊ ◊ ◊ ◊baTime 2
0q
a
0q
Raa ,→
L,◊→◊
1q
Lbb ,→
Fall 2006 Costas Busch - RPI 37
◊ ◊ ◊ ◊baTime 2
0q
a
◊ ◊ ◊ ◊baTime 3
0q
a
◊ ◊ ◊ ◊baTime 4
0q
a
◊ ◊ ◊ ◊baTime 5
0q
a
Infiniteloop
Fall 2006 Costas Busch - RPI 38
Because of the infinite loop:
•The accepting state cannot be reached
•The machine never halts
•The input string is rejected
Fall 2006 Costas Busch - RPI 39
Another Turing Machine Example
Turing machine for the language }{ nn
ba
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
1≥n
Fall 2006 Costas Busch - RPI 40
Match a’s with b’s:
Repeat:
replace leftmost a with x
find leftmost b and replace it with y
Until there are no more a’s or b’s
If there is a remaining a or b reject
Basic Idea:
Fall 2006 Costas Busch - RPI 41
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊ba
0q
a bTime 0 ◊
Fall 2006 Costas Busch - RPI 42
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊bx
1q
a b ◊Time 1
Fall 2006 Costas Busch - RPI 43
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊bx
1q
a b ◊Time 2
Fall 2006 Costas Busch - RPI 44
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
2q
a b ◊Time 3
Fall 2006 Costas Busch - RPI 45
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
2q
a b ◊Time 4
Fall 2006 Costas Busch - RPI 46
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
0q
a b ◊Time 5
Fall 2006 Costas Busch - RPI 47
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
1q
x b ◊Time 6
Fall 2006 Costas Busch - RPI 48
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
1q
x b ◊Time 7
Fall 2006 Costas Busch - RPI 49
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx x y
2q
◊Time 8
Fall 2006 Costas Busch - RPI 50
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx x y
2q
◊Time 9
Fall 2006 Costas Busch - RPI 51
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
0q
x y ◊Time 10
Fall 2006 Costas Busch - RPI 52
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
3q
x y ◊Time 11
Fall 2006 Costas Busch - RPI 53
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
3q
x y ◊Time 12
Fall 2006 Costas Busch - RPI 54
0q 1q 2q3q
Rxa ,→
Raa ,→
Ryy ,→
Lyb ,→
Laa ,→
Lyy ,→
Rxx ,→
Ryy ,→
Ryy ,→
4q
L,◊→◊
◊ ◊yx
4q
x y ◊
Halt & Accept
Time 13
Fall 2006 Costas Busch - RPI 55
If we modify the
machine for the language }{ nn
ba
we can easily construct
a machine for the language }{ nnn
cba
Observation:
Fall 2006 Costas Busch - RPI 56
Formal Definitions
for
Turing Machines
Fall 2006 Costas Busch - RPI 57
Transition Function
1q 2qRba ,→
),,(),( 21 Rbqaq =δ
Fall 2006 Costas Busch - RPI 58
1q 2qLdc ,→
),,(),( 21 Ldqcq =δ
Transition Function
Fall 2006 Costas Busch - RPI 59
Turing Machine:
),,,,,,( 0 FqQM ◊ΓΣ= δ
States
Input
alphabet
Tape
alphabet
Transition
function
Initial
state
blank
Accept
states
Fall 2006 Costas Busch - RPI 60
Configuration
◊ ◊ ◊ba
1q
a
Instantaneous description:
c◊
baqca 1
Fall 2006 Costas Busch - RPI 61
◊ ◊yx
2q
a b
Time 4
◊ ◊yx
0q
a b
Time 5
◊ ◊
A Move: aybqxxaybq 02 
(yields in one mode)
Fall 2006 Costas Busch - RPI 62
◊ ◊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
◊ ◊
A computation
Fall 2006 Costas Busch - RPI 63
bqxxyybqxxaybqxxaybq 1102 
bqxxyxaybq 12
∗
Equivalent notation:
Fall 2006 Costas Busch - RPI 64
Initial configuration: wq0
◊ ◊ba
0q
a b ◊
w
Input string
Fall 2006 Costas Busch - RPI 65
The Accepted Language
For any Turing Machine M
}:{)( 210 xqxwqwML f
∗
= 
Initial state Accept state
Fall 2006 Costas Busch - RPI 66
If a language is accepted
by a Turing machine
then we say that is:
•Turing Acceptable
•Recursively Enumerable
M
L
L
•Turing Recognizable
Other names used:
Fall 2006 Costas Busch - RPI 67
Computing Functions
with
Turing Machines
Fall 2006 Costas Busch - RPI 68
A function )(wf
Domain: Result Region:
has:
D
Dw∈
S
Swf ∈)(
)(wf
Fall 2006 Costas Busch - RPI 69
A function may have many parameters:
yxyxf +=),(
Example: Addition function
Fall 2006 Costas Busch - RPI 70
Integer Domain
Unary:
Binary:
Decimal:
11111
101
5
We prefer unary representation:
easier to manipulate with Turing machines
Fall 2006 Costas Busch - RPI 71
Definition:
A function is computable if
there is a Turing Machine such that:
f
M
Initial configuration Final configuration
Dw∈ Domain
◊
0q
◊w ◊
fq
◊)(wf
accept stateinitial state
For all
Fall 2006 Costas Busch - RPI 72
)(0 wfqwq f
∗

Initial
Configuration
Final
Configuration
A function is computable if
there is a Turing Machine such that:
f
M
In other words:
Dw∈ DomainFor all
Fall 2006 Costas Busch - RPI 73
Example
The function yxyxf +=),( is computable
Turing Machine:
Input string: yx0 unary
Output string: 0xy unary
yx, are integers
Fall 2006 Costas Busch - RPI 74
◊ 0
0q
1 1 ◊1 1
x y
1 Start
initial state
The 0 is the delimiter that
separates the two numbers
Fall 2006 Costas Busch - RPI 75
◊ 0
0q
1 1 ◊1 1
x y
1 
◊ 0
fq
1 ◊1
yx +
 11
Start
Finish
final state
initial state
Fall 2006 Costas Busch - RPI 76
◊ 0
fq
1 ◊1
yx +
 11Finish
final state
The 0 here helps when we use
the result for other operations
Fall 2006 Costas Busch - RPI 77
0q
Turing machine for function
1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
yxyxf +=),(
Fall 2006 Costas Busch - RPI 78
Execution Example:
11=x
11=y
◊ 0
0q
1 1 ◊1 1
Time 0
x y
Final Result
◊ 0
4q
1 1 ◊1 1
yx +
(=2)
(=2)
Fall 2006 Costas Busch - RPI 79
◊ 0
0q
1 1Time 0 ◊
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
1 1
Fall 2006 Costas Busch - RPI 80
◊
0q
◊
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
01 11 1Time 1
Fall 2006 Costas Busch - RPI 81
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊ 0
0q
1 1 ◊1 1Time 2
Fall 2006 Costas Busch - RPI 82
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
1q
◊1 11 11Time 3
Fall 2006 Costas Busch - RPI 83
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
1q
1 1 ◊1 11Time 4
Fall 2006 Costas Busch - RPI 84
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
1q
◊1 11 11Time 5
Fall 2006 Costas Busch - RPI 85
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
2q
1 1 ◊1 11Time 6
Fall 2006 Costas Busch - RPI 86
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
3q
◊1 11 01Time 7
Fall 2006 Costas Busch - RPI 87
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
3q
1 1 ◊1 01Time 8
Fall 2006 Costas Busch - RPI 88
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
3q
◊1 11 01Time 9
Fall 2006 Costas Busch - RPI 89
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
3q
1 1 ◊1 01Time 10
Fall 2006 Costas Busch - RPI 90
0q 1q 2q 3qL,◊→◊ L,01→
L,11→
R,◊→◊
R,10 →
R,11→
4q
R,11→
◊
3q
◊1 11 01Time 11
Fall 2006 Costas Busch - RPI 91
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
Fall 2006 Costas Busch - RPI 92
Another Example
The function xxf 2)( = is computable
Turing Machine:
Input string: x unary
Output string: xx unary
x is integer
Fall 2006 Costas Busch - RPI 93
◊
0q
1 ◊1
x
1
◊ 1
fq
1 ◊1
x2
 11
Start
Finish
accept state
initial state
Fall 2006 Costas Busch - RPI 94
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
Fall 2006 Costas Busch - RPI 95
0q 1q 2q
3q
R,1$ →
L,1→◊
L,◊→◊
R$,1→ L,11→ R,11→
R,◊→◊
Turing Machine for xxf 2)( =
Fall 2006 Costas Busch - RPI 96
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
Fall 2006 Costas Busch - RPI 97
Another Example
The function =),( yxf
is computable 0
1 yx >
yx ≤
if
if
Input: yx0
Output: 1 0or
Fall 2006 Costas Busch - RPI 98
Turing Machine Pseudocode:
Match a 1 from with a 1 fromx 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 ≤
Fall 2006 Costas Busch - RPI 99
Combining Turing Machines
Fall 2006 Costas Busch - RPI 100
Block Diagram
Turing
Machine
input output
Fall 2006 Costas Busch - RPI 101
Example:
=),( yxf
0
yx + yx >
yx ≤
if
if
Comparator
Adder
Eraser
yx,
yx,
yx >
yx ≤
yx +
0

Turing Machine

  • 1.
    Fall 2006 CostasBusch - RPI 1 Turing Machines
  • 2.
    Fall 2006 CostasBusch - RPI 2 The Language Hierarchy *a Regular Languages Context-Free Languages nn ba R ww nnn cba ww? **ba ?
  • 3.
    Fall 2006 CostasBusch - RPI 3 *a Regular Languages Context-Free Languages nn ba R ww nnn cba ww **ba Languages accepted by Turing Machines
  • 4.
    Fall 2006 CostasBusch - RPI 4 A Turing Machine ............ Tape Read-Write head Control Unit
  • 5.
    Fall 2006 CostasBusch - RPI 5 The Tape ............ Read-Write head No boundaries -- infinite length The head moves Left or Right
  • 6.
    Fall 2006 CostasBusch - RPI 6 ............ Read-Write head The head at each transition (time step): 1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right
  • 7.
    Fall 2006 CostasBusch - RPI 7 ............ Example: Time 0 ............ Time 1 1. Reads 2. Writes a a cb a b k c a k 3. Moves Left
  • 8.
    Fall 2006 CostasBusch - RPI 8 ............ Time 1 a b k c ............ Time 2 a k cf 1. Reads 2. Writes b f 3. Moves Right
  • 9.
    Fall 2006 CostasBusch - RPI 9 The Input String ............ ◊ ◊ ◊ ◊ Blank symbol head ◊a b ca Head starts at the leftmost position of the input string Input string
  • 10.
    Fall 2006 CostasBusch - RPI 10 States & Transitions 1q 2qLba ,→ Read Write Move Left 1q 2qRba ,→ Move Right
  • 11.
    Fall 2006 CostasBusch - RPI 11 Example: 1q 2qRba ,→ ............ ◊ ◊ ◊ ◊◊a b ca Time 1 1q current state
  • 12.
    Fall 2006 CostasBusch - RPI 12 ............ ◊ ◊ ◊ ◊◊a b ca Time 1 1q 2qRba ,→ ............ ◊ ◊ ◊ ◊◊a b cb Time 2 1q 2q
  • 13.
    Fall 2006 CostasBusch - RPI 13 ............ ◊ ◊ ◊ ◊◊a b ca Time 1 1q 2qLba ,→ ............ ◊ ◊ ◊ ◊◊a b cb Time 2 1q 2q Example:
  • 14.
    Fall 2006 CostasBusch - RPI 14 ............ ◊ ◊ ◊ ◊◊a b ca Time 1 1q 2qRg,→◊ ............ ◊ ◊ ◊ ◊ga b cb Time 2 1q 2q Example:
  • 15.
    Fall 2006 CostasBusch - RPI 15 Determinism 1q 2qRba ,→ Allowed Not Allowed 3qLdb ,→ 1q 2qRba ,→ 3qLda ,→ No lambda transitions allowed Turing Machines are deterministic
  • 16.
    Fall 2006 CostasBusch - RPI 16 Partial Transition Function 1q 2qRba ,→ 3qLdb ,→ ............ ◊ ◊ ◊ ◊◊a b ca 1q Example: No transition for input symbol c Allowed:
  • 17.
    Fall 2006 CostasBusch - RPI 17 Halting The machine halts in a state if there is no transition to follow
  • 18.
    Fall 2006 CostasBusch - RPI 18 Halting Example 1: ............ ◊ ◊ ◊ ◊◊a b ca 1q 1q No transition from HALT!!! 1q
  • 19.
    Fall 2006 CostasBusch - RPI 19 Halting Example 2: ............ ◊ ◊ ◊ ◊◊a b ca 1q 1q 2qRba ,→ 3qLdb ,→ No possible transition from and symbol HALT!!! 1q c
  • 20.
    Fall 2006 CostasBusch - RPI 20 Accepting States 1q 2q Allowed 1q 2q Not Allowed •Accepting states have no outgoing transitions •The machine halts and accepts
  • 21.
    Fall 2006 CostasBusch - RPI 21 Acceptance Accept Input If machine halts in an accept state Reject Input If machine halts in a non-accept state or If machine enters an infinite loop string string
  • 22.
    Fall 2006 CostasBusch - RPI 22 Observation: In order to accept an input string, it is not necessary to scan all the symbols in the string
  • 23.
    Fall 2006 CostasBusch - RPI 23 Turing Machine Example Accepts the language: *a 0q Raa ,→ L,◊→◊ 1q Input alphabet },{ ba=Σ
  • 24.
    Fall 2006 CostasBusch - RPI 24 ◊ ◊ ◊ ◊aaTime 0 0q a 0q Raa ,→ L,◊→◊ 1q
  • 25.
    Fall 2006 CostasBusch - RPI 25 ◊ ◊ ◊ ◊aaTime 1 0q a 0q Raa ,→ L,◊→◊ 1q
  • 26.
    Fall 2006 CostasBusch - RPI 26 ◊ ◊ ◊ ◊aaTime 2 0q a 0q Raa ,→ L,◊→◊ 1q
  • 27.
    Fall 2006 CostasBusch - RPI 27 ◊ ◊ ◊ ◊aaTime 3 0q a 0q Raa ,→ L,◊→◊ 1q
  • 28.
    Fall 2006 CostasBusch - RPI 28 ◊ ◊ ◊ ◊aaTime 4 1q a 0q Raa ,→ L,◊→◊ 1q Halt & Accept
  • 29.
    Fall 2006 CostasBusch - RPI 29 Rejection Example 0q Raa ,→ L,◊→◊ 1q ◊ ◊ ◊ ◊baTime 0 0q a
  • 30.
    Fall 2006 CostasBusch - RPI 30 0q Raa ,→ L,◊→◊ 1q ◊ ◊ ◊ ◊baTime 1 0q a No possible Transition Halt & Reject
  • 31.
    Fall 2006 CostasBusch - RPI 31 Accepts the language: *a 0q but for input alphabet }{a=Σ A simpler machine for same language
  • 32.
    Fall 2006 CostasBusch - RPI 32 ◊ ◊ ◊ ◊aaTime 0 0q a 0q Halt & Accept Not necessary to scan input
  • 33.
    Fall 2006 CostasBusch - RPI 33 Infinite Loop Example 0q Raa ,→ L,◊→◊ 1q Lbb ,→ A Turing machine for language *)(* baba ++
  • 34.
    Fall 2006 CostasBusch - RPI 34 ◊ ◊ ◊ ◊baTime 0 0q a 0q Raa ,→ L,◊→◊ 1q Lbb ,→
  • 35.
    Fall 2006 CostasBusch - RPI 35 ◊ ◊ ◊ ◊baTime 1 0q a 0q Raa ,→ L,◊→◊ 1q Lbb ,→
  • 36.
    Fall 2006 CostasBusch - RPI 36 ◊ ◊ ◊ ◊baTime 2 0q a 0q Raa ,→ L,◊→◊ 1q Lbb ,→
  • 37.
    Fall 2006 CostasBusch - RPI 37 ◊ ◊ ◊ ◊baTime 2 0q a ◊ ◊ ◊ ◊baTime 3 0q a ◊ ◊ ◊ ◊baTime 4 0q a ◊ ◊ ◊ ◊baTime 5 0q a Infiniteloop
  • 38.
    Fall 2006 CostasBusch - RPI 38 Because of the infinite loop: •The accepting state cannot be reached •The machine never halts •The input string is rejected
  • 39.
    Fall 2006 CostasBusch - RPI 39 Another Turing Machine Example Turing machine for the language }{ nn ba 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ 1≥n
  • 40.
    Fall 2006 CostasBusch - RPI 40 Match a’s with b’s: Repeat: replace leftmost a with x find leftmost b and replace it with y Until there are no more a’s or b’s If there is a remaining a or b reject Basic Idea:
  • 41.
    Fall 2006 CostasBusch - RPI 41 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊ba 0q a bTime 0 ◊
  • 42.
    Fall 2006 CostasBusch - RPI 42 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊bx 1q a b ◊Time 1
  • 43.
    Fall 2006 CostasBusch - RPI 43 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊bx 1q a b ◊Time 2
  • 44.
    Fall 2006 CostasBusch - RPI 44 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 2q a b ◊Time 3
  • 45.
    Fall 2006 CostasBusch - RPI 45 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 2q a b ◊Time 4
  • 46.
    Fall 2006 CostasBusch - RPI 46 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 0q a b ◊Time 5
  • 47.
    Fall 2006 CostasBusch - RPI 47 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 1q x b ◊Time 6
  • 48.
    Fall 2006 CostasBusch - RPI 48 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 1q x b ◊Time 7
  • 49.
    Fall 2006 CostasBusch - RPI 49 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx x y 2q ◊Time 8
  • 50.
    Fall 2006 CostasBusch - RPI 50 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx x y 2q ◊Time 9
  • 51.
    Fall 2006 CostasBusch - RPI 51 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 0q x y ◊Time 10
  • 52.
    Fall 2006 CostasBusch - RPI 52 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 3q x y ◊Time 11
  • 53.
    Fall 2006 CostasBusch - RPI 53 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 3q x y ◊Time 12
  • 54.
    Fall 2006 CostasBusch - RPI 54 0q 1q 2q3q Rxa ,→ Raa ,→ Ryy ,→ Lyb ,→ Laa ,→ Lyy ,→ Rxx ,→ Ryy ,→ Ryy ,→ 4q L,◊→◊ ◊ ◊yx 4q x y ◊ Halt & Accept Time 13
  • 55.
    Fall 2006 CostasBusch - RPI 55 If we modify the machine for the language }{ nn ba we can easily construct a machine for the language }{ nnn cba Observation:
  • 56.
    Fall 2006 CostasBusch - RPI 56 Formal Definitions for Turing Machines
  • 57.
    Fall 2006 CostasBusch - RPI 57 Transition Function 1q 2qRba ,→ ),,(),( 21 Rbqaq =δ
  • 58.
    Fall 2006 CostasBusch - RPI 58 1q 2qLdc ,→ ),,(),( 21 Ldqcq =δ Transition Function
  • 59.
    Fall 2006 CostasBusch - RPI 59 Turing Machine: ),,,,,,( 0 FqQM ◊ΓΣ= δ States Input alphabet Tape alphabet Transition function Initial state blank Accept states
  • 60.
    Fall 2006 CostasBusch - RPI 60 Configuration ◊ ◊ ◊ba 1q a Instantaneous description: c◊ baqca 1
  • 61.
    Fall 2006 CostasBusch - RPI 61 ◊ ◊yx 2q a b Time 4 ◊ ◊yx 0q a b Time 5 ◊ ◊ A Move: aybqxxaybq 02  (yields in one mode)
  • 62.
    Fall 2006 CostasBusch - RPI 62 ◊ ◊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 ◊ ◊ A computation
  • 63.
    Fall 2006 CostasBusch - RPI 63 bqxxyybqxxaybqxxaybq 1102  bqxxyxaybq 12 ∗ Equivalent notation:
  • 64.
    Fall 2006 CostasBusch - RPI 64 Initial configuration: wq0 ◊ ◊ba 0q a b ◊ w Input string
  • 65.
    Fall 2006 CostasBusch - RPI 65 The Accepted Language For any Turing Machine M }:{)( 210 xqxwqwML f ∗ =  Initial state Accept state
  • 66.
    Fall 2006 CostasBusch - RPI 66 If a language is accepted by a Turing machine then we say that is: •Turing Acceptable •Recursively Enumerable M L L •Turing Recognizable Other names used:
  • 67.
    Fall 2006 CostasBusch - RPI 67 Computing Functions with Turing Machines
  • 68.
    Fall 2006 CostasBusch - RPI 68 A function )(wf Domain: Result Region: has: D Dw∈ S Swf ∈)( )(wf
  • 69.
    Fall 2006 CostasBusch - RPI 69 A function may have many parameters: yxyxf +=),( Example: Addition function
  • 70.
    Fall 2006 CostasBusch - RPI 70 Integer Domain Unary: Binary: Decimal: 11111 101 5 We prefer unary representation: easier to manipulate with Turing machines
  • 71.
    Fall 2006 CostasBusch - RPI 71 Definition: A function is computable if there is a Turing Machine such that: f M Initial configuration Final configuration Dw∈ Domain ◊ 0q ◊w ◊ fq ◊)(wf accept stateinitial state For all
  • 72.
    Fall 2006 CostasBusch - RPI 72 )(0 wfqwq f ∗  Initial Configuration Final Configuration A function is computable if there is a Turing Machine such that: f M In other words: Dw∈ DomainFor all
  • 73.
    Fall 2006 CostasBusch - RPI 73 Example The function yxyxf +=),( is computable Turing Machine: Input string: yx0 unary Output string: 0xy unary yx, are integers
  • 74.
    Fall 2006 CostasBusch - RPI 74 ◊ 0 0q 1 1 ◊1 1 x y 1 Start initial state The 0 is the delimiter that separates the two numbers
  • 75.
    Fall 2006 CostasBusch - RPI 75 ◊ 0 0q 1 1 ◊1 1 x y 1  ◊ 0 fq 1 ◊1 yx +  11 Start Finish final state initial state
  • 76.
    Fall 2006 CostasBusch - RPI 76 ◊ 0 fq 1 ◊1 yx +  11Finish final state The 0 here helps when we use the result for other operations
  • 77.
    Fall 2006 CostasBusch - RPI 77 0q Turing machine for function 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ yxyxf +=),(
  • 78.
    Fall 2006 CostasBusch - RPI 78 Execution Example: 11=x 11=y ◊ 0 0q 1 1 ◊1 1 Time 0 x y Final Result ◊ 0 4q 1 1 ◊1 1 yx + (=2) (=2)
  • 79.
    Fall 2006 CostasBusch - RPI 79 ◊ 0 0q 1 1Time 0 ◊ 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ 1 1
  • 80.
    Fall 2006 CostasBusch - RPI 80 ◊ 0q ◊ 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ 01 11 1Time 1
  • 81.
    Fall 2006 CostasBusch - RPI 81 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 0 0q 1 1 ◊1 1Time 2
  • 82.
    Fall 2006 CostasBusch - RPI 82 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 1q ◊1 11 11Time 3
  • 83.
    Fall 2006 CostasBusch - RPI 83 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 1q 1 1 ◊1 11Time 4
  • 84.
    Fall 2006 CostasBusch - RPI 84 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 1q ◊1 11 11Time 5
  • 85.
    Fall 2006 CostasBusch - RPI 85 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 2q 1 1 ◊1 11Time 6
  • 86.
    Fall 2006 CostasBusch - RPI 86 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 3q ◊1 11 01Time 7
  • 87.
    Fall 2006 CostasBusch - RPI 87 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 3q 1 1 ◊1 01Time 8
  • 88.
    Fall 2006 CostasBusch - RPI 88 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 3q ◊1 11 01Time 9
  • 89.
    Fall 2006 CostasBusch - RPI 89 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 3q 1 1 ◊1 01Time 10
  • 90.
    Fall 2006 CostasBusch - RPI 90 0q 1q 2q 3qL,◊→◊ L,01→ L,11→ R,◊→◊ R,10 → R,11→ 4q R,11→ ◊ 3q ◊1 11 01Time 11
  • 91.
    Fall 2006 CostasBusch - RPI 91 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
  • 92.
    Fall 2006 CostasBusch - RPI 92 Another Example The function xxf 2)( = is computable Turing Machine: Input string: x unary Output string: xx unary x is integer
  • 93.
    Fall 2006 CostasBusch - RPI 93 ◊ 0q 1 ◊1 x 1 ◊ 1 fq 1 ◊1 x2  11 Start Finish accept state initial state
  • 94.
    Fall 2006 CostasBusch - RPI 94 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
  • 95.
    Fall 2006 CostasBusch - RPI 95 0q 1q 2q 3q R,1$ → L,1→◊ L,◊→◊ R$,1→ L,11→ R,11→ R,◊→◊ Turing Machine for xxf 2)( =
  • 96.
    Fall 2006 CostasBusch - RPI 96 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
  • 97.
    Fall 2006 CostasBusch - RPI 97 Another Example The function =),( yxf is computable 0 1 yx > yx ≤ if if Input: yx0 Output: 1 0or
  • 98.
    Fall 2006 CostasBusch - RPI 98 Turing Machine Pseudocode: Match a 1 from with a 1 fromx 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 ≤
  • 99.
    Fall 2006 CostasBusch - RPI 99 Combining Turing Machines
  • 100.
    Fall 2006 CostasBusch - RPI 100 Block Diagram Turing Machine input output
  • 101.
    Fall 2006 CostasBusch - RPI 101 Example: =),( yxf 0 yx + yx > yx ≤ if if Comparator Adder Eraser yx, yx, yx > yx ≤ yx + 0