review cs 301 - lecture 24 context sensitive … · cs 301 - lecture 24 context sensitive grammars...
TRANSCRIPT
1
CS 301 - Lecture 24 Context Sensitive Grammars and the Chomsky Hierarchy
Fall 2008
Review • Languages and Grammars
– Alphabets, strings, languages • Regular Languages
– Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA – Regular Expressions – Regular Grammars – Properties of Regular Languages – Languages that are not regular and the pumping lemma
• Context Free Languages – Context Free Grammars – Derivations: leftmost, rightmost and derivation trees – Parsing and ambiguity – Simplifications and Normal Forms – Nondeterministic Pushdown Automata – Pushdown Automata and Context Free Grammars – Deterministic Pushdown Automata – Pumping Lemma for context free grammars – Properties of Context Free Grammars
• Turing Machines – Definition, Accepting Languages, and Computing Functions – Combining Turing Machines and Turing’s Thesis – Turing Machine Variations – Universal Turing Machine and Linear Bounded Automata – Recursive and Recursively Enumerable Languages, Unrestricted Grammars – Today: Wrap-up Recursive languages, Context Sensitive Grammars and the Chomsky Hierarchy
Recursive
Recursively Enumerable
Non Recursively Enumerable
L
1a 2a 3a 4a
)( 1ML
0 1 10
)( 2ML
)( 3ML
01 0 1
0 1 11
)( 4ML 0 10 0
},,{ 43…aaL =
2
Consider the language
)}(:{ iii MLaaL ∈=
L consists of the 0’s in the diagonal
)}(:{ iii MLaaL ∉=
L
1a 2a 3a 4a
)( 1ML
0 1 10
)( 2ML
)( 3ML
01 0 1
0 1 11
)( 4ML 0 10 0
Question: ?1MMk =
1a 2a 3a 4a
)( 1ML
0 1 10
)( 2ML
)( 3ML
01 0 1
0 1 11
)( 4ML 0 10 0
Answer: 1MMk ≠)(
)(
11
1
MLa
MLa k
∉
∈
1a 2a 3a 4a
)( 1ML
0 1 10
)( 2ML
)( 3ML
01 0 1
0 1 11
)( 4ML 0 10 0
Question: ?2MMk =
3
1a 2a 3a 4a
)( 1ML
0 1 10
)( 2ML
)( 3ML
01 0 1
0 1 11
)( 4ML 0 10 0
Answer: 2MMk ≠)(
)(
22
2
MLa
MLa k
∉
∈
1a 2a 3a 4a
)( 1ML
0 1 10
)( 2ML
)( 3ML
01 0 1
0 1 11
)( 4ML 0 10 0
Question: ?3MMk =
1a 2a 3a 4a
)( 1ML
0 1 10
)( 2ML
)( 3ML
01 0 1
0 1 11
)( 4ML 0 10 0
Answer: 3MMk ≠)(
)(
33
3
MLa
MLa k
∈
∉
Similarly: ik MM ≠
)(
)(
ii
ki
MLa
MLa
∈
∉
)(
)(
ii
ki
MLa
MLa
∉
∈
for any i
Because either:
or
4
Therefore, the machine cannot exist kM
Therefore, the language is not recursively enumerable
L
End of Proof
Observation:
There is no algorithm that describes L
(otherwise would be accepted by some Turing Machine)
L
A Language which is Recursively Enumerable
and not Recursive
We want to find a language which
There is a Turing Machine that accepts the language
The machine doesn’t halt on some input
Is recursively enumerable
But not recursive
5
We will prove that the language
)}(:{ iii MLaaL ∈=
Is recursively enumerable but not recursive
1a 2a 3a 4a
)( 1ML
0 1 10
)( 2ML
)( 3ML
01 0 1
0 1 11
)( 4ML 0 10 0
},,{ 43…aaL =
The language
Theorem:
)}(:{ iii MLaaL ∈=
is recursively enumerable
Proof:
We will give a Turing Machine that accepts L
6
Turing Machine that accepts LFor any input string w
• Compute , for which iaw =• Find Turing machine iM
(using an enumeration procedure for Turing Machines)
• Simulate on input iMia
• If accepts, then accept iM w
i
End of Proof
Observation:
)}(:{ iii MLaaL ∈=
)}(:{ iii MLaaL ∉=
Recursively enumerable
Not recursively enumerable
(Thus, also not recursive)
Theorem:
The language )}(:{ iii MLaaL ∈=
is not recursive
Proof: Assume for contradiction that is recursive
Then is recursive:
L
LTake the Turing Machine that accepts M L halts on any input: M
If accepts then reject If rejects then accept
MM
7
Therefore:
L is recursive
But we know:
L is not recursively enumerable thus, not recursive
CONTRADICTION!!!!
Therefore, is not recursive L
End of Proof
L
Recursive
Recursively Enumerable
Non Recursively Enumerable
L
Machines and Grammars and Languages: Machine Grammar Language NFA = DFA Regular Regular
NPDA Context Free Context Free
Linear Bounded ?? ?? Automata
Turing Machine ?? Recursively Enumerable
8
Machines and Grammars and Languages: Machine Grammar Language NFA = DFA Regular Regular
NPDA Context Free Context Free
Linear Bounded Context Context Automata Sensitive Sensitive
Turing Machine Unrestricted Recursively Enumerable
Unrestricted Grammars:
Productions vu→
String of variables and terminals
String of variables and terminals
Example unrestricted grammar:
dAccAaBaBcS
→
→
→
Example unrestricted grammar derivation:
A language is recursively enumerable if and only if is generated by an unrestricted grammar
LL
Theorem:
Proof: omitted for this course, see Theorem 11.6 and 11.7 for details
9
Context-Sensitive Grammars:
and: |||| vu ≤
Productions vu→
String of variables and terminals
String of variables and terminals
The language }{ nnn cbais context-sensitive:
aaAaaaBBbbBBbccAcbAAbaAbcabcS
|
|
→
→
→
→
→
Derivation for:
aaAaaaBBbbBBbccAcbAAbaAbcabcS
|
|
→
→
→
→
→ A language is context sensistive if and only if is accepted by a Linear-Bounded automaton L
LTheorem:
Proof: see Theorem 11.8 and 11.9
10
Every context sensitive language is recursive
Theorem:
Derivation grows or stays the same at each step. Can only stay the same a finite number of times and only a finite number of derivations to try for string of length |w|
Intuition behind proof
There exist recursive languages that are not context-sensitive
Theorem:
The Chomsky Hierarchy
Not R.E. Recursively-enumerable
Recursive
Context-sensitive
Context-free
Regular
The Chomsky Hierarchy
Det. Context-free
Context Free
Linear Regular
Some Complications
Det. Context-free
11
Context-Sensitive (linear bounded automata)
Some Unknowns
Context-free (NPDA) Det. Context-free (DPDA)
Det. linear bounded automata goes where? Open question….
What’s Next • Read
– Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, 7.2, 7.3, (skip 7.4), 8, 9, 10, 11, 12.1, 12.2
– JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7, (skip 8), 9, (skip 10), 11 • Next Lecture Topics From 12.1 and 12.2
– Computability • Quiz 4 in Recitation on Wednesday 12/3
– Covers Linz 9, 10 and JFLAP 9, 11 – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you
like. – Quiz will take the full hour
• Homework – Homework Due Today – New Homework Available by Friday Morning – New Homework Due Next Thursday