Turingmachines 120327094202 Phpapp02
Turingmachines 120327094202 Phpapp02
nnn?
abc ww?
Context-Free Languages
nn R
ab ww
Regular Languages
a* a*b*
Languages accepted by
Turing Machines
nnn
abc ww
Context-Free Languages
nn R
ab ww NDPA
Regular Languages
Finite
a* a*b* Automata
A Turing Machine
Tape
...... ......
Read-Write head
Control Unit
The Tape
No boundaries -- infinite length
...... ......
Read-Write head
Read-Write head
1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
Example:
Time 0
...... a b a c ......
Time 1
...... a b k c ......
1. Reads a
2. Writes k
3. Moves Left
Time 1
...... a b k c ......
Time 2
...... a f k c ......
1. Reads b
2. Writes f
3. Moves Right
The Input String
Input string Blank symbol
...... a b a c ......
head
Head starts at the leftmost position
of the input string
Are treated as left and right brackets for the
input written on the tape.
States & Transitions
Read Write
Move Left
q1
a b
,L q
2
Move Right
q1
a b
,R q
2
Example:
Time 1
...... a b a c ......
q1
current state
q1
a b
,R q
2
Time 1
...... a b a c ......
q1
Time 2
...... a b b c ......
q2
q1
a b
,R q
2
Example:
Time 1
...... a b a c ......
q1
Time 2
...... a b b c ......
q2
q1
a b
,L q
2
Example:
Time 1
...... a b a c ......
q1
Time 2
...... a b b c g ......
q2
q1
g
,Rq
2
Determinism
Turing Machines are deterministic
q1 q1
q q
b ,L 3
d a ,L 3
d
...... a b a c ......
q1
a b
,R q2 Allowed:
q1 No transition
for input symbol c
b q
,L 3
d
Halting
...... a b a c ......
q1
a b
,R q2
No possible transition
q1
HALT!!!
b q
,L 3
d
Final States
q1 q2 Allowed
q1 q2 Not Allowed
If machine halts
in a non-final state
Reject Input or
If machine enters
an infinite loop
Turing Machine Example
A Turing machine that accepts the language:
aa
*
a a
,R
,L
q0 q1
Time 0 a a a
q0
a a
,R
,L
q0 q1
Time 1 a a a
q0
a a
,R
,L
q0 q1
Time 2 a a a
q0
a a
,R
,L
q0 q1
Time 3 a a a
q0
a a
,R
,L
q0 q1
Time 4 a a a
q1
a a
,R Halt & Accept
,L
q0 q1
Rejection Example
Time 0 a b a
q0
a a
,R
,L
q0 q1
Time 1 a b a
q0
No possible Transition
a ,R Halt & Reject
a
,L
q0 q1
Infinite Loop Example
b b
,L
a a
,R
,L
q0 q1
Time 0 a b a
q0
b b
,L
a a
,R
,L
q0 q1
Time 1 a b a
q0
b b
,L
a a
,R
,L
q0 q1
Time 2 a b a
q0
b b
,L
a a
,R
,L
q0 q1
Time 2 a b a
q0
Time 3 a b a
q0
Time 4 a b a
q0
Time 5 a b a
q0
... Infinite Loop
Because of the infinite loop:
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 0 a a b b
q0
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 1 x a b b
q1
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 2 x a b b
q1
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 3 x a y b
q2
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 4 x a y b
q2
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 5 x a y b
q0
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 6 x x y b
q1
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 7 x x y b
q1
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 8 x x y y
q2
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 9 x x y y
q2
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 10 x x y y
q0
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 11 x x y y
q3
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 12 x x y y
q3
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Time 13 x x y y
q4
Halt & Accept
q4
y y
,R y y
,L
y y
,R
a
,R a
a a
,L
,L
y y
,Ra
x,R b
y,L
q3 q0 q1 q2
x x
,R
Observation:
If we modify the
machine for the language nn
{
ab}
q1
c d
,L q
2
(
q,
c
)(
q,
d,
L)
1 2
Turing Machine:
Input Tape
alphabet alphabet
States
M
(
Q
,
,,
,q
0
,
,F
)
A partial Final
Transition states
function Initial Blank : a special symbol
state Of
Configuration
c a b a
q1
Instantaneous description: ca
q
1ba
Time 4 Time 5
x a y b x a y b
q2 q0
A Move: q
2
xayb
x
q
0ay
Time 4 Time 5
x a y b x a y b
q2 q0
Time 6 Time 7
x x y b x x y b
q1 q1
q
2
0
xay
x
q
ay
q
1
xx
y
xq
b
1
q
2
0
xay
x
q
ay
q
1
xx
y
xq
b
1
Equivalent notation: q
2
xayb
xxy
q
1b
Initial configuration: q0 w
Input string
a a b b
q0
The Accepted Language
For any Turing Machine M
L
(
M
){
w:q
w
0x
q
1fx
2}
Deterministic
1,1,R
1,1, R
DFA for the previous language
0
0 1 0
q0 q1 q2
1
1
0,1
Turing machine for odd no of 1s
1, 1 , R
1, b , R
1, b , R
Recursively Enumerable
and
Recursive
Languages
Definition:
A language is recursively enumerable
if some Turing machine accepts it
Let L be a recursively enumerable language
and M the Turing Machine that accepts it
For string w:
if
w L then M halts in a final state
if
w L then M halts in a non-final state
or loops forever
Definition:
A language is recursive
if some Turing machine accepts it
and halts on any input string
In other words:
A language is recursive if there is
a membership algorithm for it
Let L be a recursive language
and M the Turing Machine that accepts it
For string w:
if
w L then M halts in a final state
if
w L then M halts in a non-final state
We will prove:
Recursively Enumerable
Recursive
We will first prove:
Productions
uv
S aBc
aB cA
Ac d
Theorem:
Productions
uv
and: |
|u |v
|
The language {nnn
abc}
is context-sensitive:
S abc | aAbc
Ab bA
Ac Bbcc
bB Bb
aB aa | aaA
The language {nnn
abc}
is context-sensitive:
S abc | aAbc
Ab bA
Ac Bbcc
bB Bb
aB aa | aaA
Theorem:
Non-recursively enumerable
Recursively-enumerable
Recursive
Context-sensitive
Context-free
Regular