Lecture 23 Recursive and Recursively Enumerable languages – cont’s Chomsky Hierarchy

advertisement
Lecture 23
Recursive and Recursively
Enumerable languages – cont’s
Chomsky Hierarchy
COT 4420
Theory of Computation
Section 11.4
Slides from Prof. Busch
Theorem:
If a language L is recursive then
there is an enumerator for it
Proof:
Let M be the Turing machine for L
Use M to build the enumerator for L
Enumerator for
Repeat:
L
~
1. M generates a string w
2.
M checks if w∈ L
YES: print
NO:
w to output
ignore
This part terminates,
Because L is recursive
w
Theorem:
If language L is Recursively enumerable then
there is an enumerator for it
Proof:
Let M be the Turing machine that accepts L
Use M to build the enumerator for L
Enumerator for
~
M
Enumerates all
strings of input alphabet
in proper order
L
M
Accepts L
NAIVE APPROACH
Enumerator for
Repeat:
L
~ generates a string w
M
M checks if w∈ L
YES: print
w to output
NO: ignore w
Problem:
If w∉ L
machine M may loop forever
BETTER APPROACH
~ Generates first string w
M
1
M executes first step on w1
~ Generates second string w
M
2
M executes first step on w2
second step on
w1
~ Generates third string w
M
3
M executes first step on w3
second step on
third step on
And so on............
w2
w1
String:
Step in
computation
of string
w1
w2
w3
w4
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4

If for any string wi machine M halts in an
accepting state then print wi to the output
Theorem:
If for language L there is an enumerator
then L is Recursively enumerable
Proof:
Using the enumerator for L
we will build a Turing machine
that accepts L
Input Tape
w
Turing Machine that accepts
Enumerator
for L
w
wi
Give me the
next string
in the
enumeration
sequence
L
Compare
If same,
Accept and Halt
Turing machine that accepts L
For any input string
w
Loop:
• Using the enumerator of L,
generate the next string of L
• Compare generated string with w,
if same, accept and exit loop
Conclusion:
• If a language is recursive then
there is an enumerator for it
• A language is Recursively Enumerable
if and only if
there is an enumerator for it
Chomsky Hierarchy
Linear-Bounded Automata:
Turing machine with space restriction
• Only the part of the tape containing the input
can be used
• We may use multiple tracks
• We enforce the restriction by enclosing the
input within ‘[‘ and ‘]’ markers
• These markers cannot be rewritten
• The head cannot go past these markers
Linear Bounded Automaton (LBA)
Input string
[ a b c d e ]
Left-end
marker
Working space
in tape
Right-end
marker
All computation is done between end markers
We define LBA’s as NonDeterministic
Open Problem:
Nondeterministic LBA’s have same power
as Deterministic LBA’s ?
Example languages accepted by LBAs:
L = {a b c }
n n n
L = {a }
n!
LBA’s have more power than PDA’s
(pushdown automata)
LBA’s have less power than Turing Machines
Context-Sensitive Languages
Context-sensitive Grammar
A grammar G = (V, T, S, P) is said to be contextsensitive if all productions are of the form
xy
Where x , y ∈ (V∪ T)+ and
|x| ≤ |y|
Context-sensitive Grammar
Why it is called context-sensitive?
All context-sensitive grammars can be rewritten
in a normal form in which all productions are of
the form
xAy  xvy
Context-sensitive Language
A language L is said to be context-sensitive if
there exists a context-sensitive grammar G such
that
L = L(G)
Context-sensitive Language - Example
L = { anbncn : n ≥ 1}
S  abc | aAbc
Ab  bA
Ac  Bbcc
bB  Bb
aB  aa | aaA
{ ww : w ∈ {0,1}*}
S  ABC
AB  0AD | 1AE
DC  B0C
EC  B1C
D0  0D
D1  1D
E0  0E
E1  1E
0B  B0
1B  B1
AB  λ
Cλ
“start”
“Add 0 or 1 left and use D,E to mark the second 0,1”
“Add 0 right”
“Add 1 right”
“Move D right”
“Move D right”
“Move E right”
“Move E right”
“Move B left”
“Move B left”
Example
ABC
0ADC
0AB0C
01AE0C
01A0EC
01A0B1C
01AB01C
01λ01λ
0101
Theorem:
A language L is context sensitive
if and only if
it is accepted by a Linear-Bounded automaton
There exists a recursive language that is not contextsensitive
Unrestricted Grammars:
Productions
u→v
String of variables
and terminals
String of variables
and terminals
Example unrestricted grammar:
S → aBc
aB → cA
Ac → d
Theorem:
A language L is recursively enumerable if and
only if L is generated by an unrestricted grammar
Chomsky
Hierarchy
Grammars
Languages
Automata
Type 0
Unrestricted
Recursively
Enumerable
Turing machine
(nondeterminisitc
or determinisitc)
Type 1
Context-sensitive Context-sensitive Nondeterministic
Linear bounded
automata
Type 2
Context-free
Context-free
Nondeterministic
pushdown
Type 3
Regular
Regular
NFA
DFA
The Chomsky Hierarchy
Non Recursively Enumerable
Recursively Enumerable
Recursive
Context-sensitive
Context-free
Deterministic
Context-free
Regular
Download