Languages and Finite Automata

The Chomsky Hierarchy
Fall 2004
COMP 335
1
The Chomsky Hierarchy
Non-recursively enumerable
Recursively-enumerable
Recursive
Context-sensitive
Context-free
Regular
Fall 2004
COMP 335
2
Decidability
Fall 2004
COMP 335
3
Consider problems with answer YES or NO
Examples:
• Does Machine
• Is string
• Does DFA
Fall 2004
M have three states ?
w a binary number?
M accept any input?
COMP 335
4
A problem is decidable if some Turing machine
decides (solves) the problem
Decidable problems:
• Does Machine
• Is string
• Does DFA
Fall 2004
M have three states ?
w a binary number?
M accept any input?
COMP 335
5
The Turing machine that decides (solves)
a problem answers YES or NO
for each instance of the problem
Input
problem
instance
Fall 2004
Turing Machine
YES
NO
COMP 335
6
The machine that decides (solves) a problem:
• If the answer is YES
then halts in a yes state
• If the answer is NO
then halts in a no state
These states may not be final states
Fall 2004
COMP 335
7
Turing Machine that decides a problem
YES states
NO states
YES and NO states are halting states
Fall 2004
COMP 335
8
Difference between
Recursive Languages and Decidable problems
For decidable problems:
The YES states may not be final states
Fall 2004
COMP 335
9
Some problems are undecidable:
which means:
there is no Turing Machine that
solves all instances of the problem
A simple undecidable problem:
The membership problem
Fall 2004
COMP 335
10
The Membership Problem
Input:
•Turing Machine
•String
Question:
M
w
Does M
accept w ?
w L(M ) ?
Fall 2004
COMP 335
11
Theorem:
The membership problem is undecidable
(there are M and w for which we cannot
decide whether w L(M ) )
Proof:
Fall 2004
Assume for contradiction that
the membership problem is decidable
COMP 335
12
Thus, there exists a Turing Machine
that solves the membership problem
M
H
YES
M accepts w
NO
M rejects w
H
w
Fall 2004
COMP 335
13
Let
L be a recursively enumerable language
Let
M be the Turing Machine that accepts L
We will prove that
L is also recursive:
we will describe a Turing machine that
accepts L and halts on any input
Fall 2004
COMP 335
14
Turing Machine that accepts
and halts on any input
M
H
M accepts w ?
w
Fall 2004
L
YES
accept w
NO
reject
COMP 335
w
15
Therefore,
L is recursive
Since L is chosen arbitrarily, every
recursively enumerable language is also
recursive
But there are recursively enumerable
languages which are not recursive
Contradiction!!!!
Fall 2004
COMP 335
16
Therefore, the membership problem
is undecidable
END OF PROOF
Fall 2004
COMP 335
17
Another famous undecidable problem:
The halting problem
Fall 2004
COMP 335
18
The Halting Problem
Input:
•Turing Machine
•String
Question:
Fall 2004
M
w
Does M
COMP 335
halt on input w ?
19
Theorem:
The halting problem is undecidable
(there are M and w for which we cannot
decide whether M halts on input w )
Proof:
Fall 2004
Assume for contradiction that
the halting problem is decidable
COMP 335
20
Thus, there exists Turing Machine
that solves the halting problem
M
H
YES
M halts on w
NO
doesn’t
halt on
H
w
Fall 2004
COMP 335
M
w
21
Construction of
H
H
Input:
initial tape contents
wM w
q y YES
q0
qn NO
Encoding
of M
Fall 2004
String
w
COMP 335
22
Construct machine
Fall 2004
H :
If
H returns YES then loop forever
If
H returns NO then halt
COMP 335
23
H
Loop forever
H
q y YES
wM w
qa
qb
q0
qn NO
Fall 2004
COMP 335
24
Construct machine
Input:
If
wM
Ĥ :
(machine
M )
M halts on input wM
Then loop forever
Else halt
Fall 2004
COMP 335
25
Ĥ
wM
Fall 2004
copy
wM wM
wM
COMP 335
H
26
Run machine
Ĥ with input itself:
Input:
(machine
If
wHˆ
Ĥ )
Ĥ halts on input wHˆ
Then loop forever
Else halt
Fall 2004
COMP 335
27
Ĥ on input wHˆ :
If
Ĥ halts then loops forever
If
Ĥ doesn’t halt then it halts
NONSENSE !!!!!
Fall 2004
COMP 335
28
Therefore, we have contradiction
The halting problem is undecidable
END OF PROOF
Fall 2004
COMP 335
29
Another proof of the same theorem:
If the halting problem was decidable then
every recursively enumerable language
would be recursive
Fall 2004
COMP 335
30
Theorem:
The halting problem is undecidable
Proof:
Fall 2004
Assume for contradiction that
the halting problem is decidable
COMP 335
31
There exists Turing Machine H
that solves the halting problem
M
YES
M halts on w
NO
doesn’t
halt on
H
w
Fall 2004
COMP 335
M
w
32
Let
L be a recursively enumerable language
Let
M be the Turing Machine that accepts L
We will prove that
L is also recursive:
we will describe a Turing machine that
accepts L and halts on any input
Fall 2004
COMP 335
33
Turing Machine that accepts
and halts on any input
M
H
NO
M halts on w ?
w
reject
L
w
YES
accept
Run M
with input w
w
Halts on final state
reject
w
Halts on non-final
state
Fall 2004
COMP 335
34
Therefore
L is recursive
Since L is chosen arbitrarily, every
recursively enumerable language
is also recursive
But there are recursively enumerable
languages which are not recursive
Contradiction!!!!
Fall 2004
COMP 335
35
Therefore, the halting problem is undecidable
END OF PROOF
Fall 2004
COMP 335
36