class22

advertisement
Decidability
continued…
1
Theorem:
For a recursively enumerable language L
it is undecidable to determine whether
L is finite
Proof:
We will reduce the halting problem
to this problem
2
Let
M be the machine that accepts L
L( M )  L
Assume we have the finite language algorithm:
M
Algorithm for
finite language
problem
YES
L(M ) finite
NO
L(M ) not finite
3
We will design the halting problem algorithm:
M
w
Algorithm for
Halting problem
YES
M halts on w
NO
doesn’t
halt on
M
w
4
First construct machine
Initially, simulates
Mw :
M on input w
When M enters a halt state,
accept any input (inifinite language)
Otherwise accept nothing (finite language)
5
M halts on w
if and
only if
L( M w )
is not finite
6
Algorithm for halting problem:
Inputs: machine
1. Construct
M and string w
Mw
2. Determine if
L( M w )
is finite
YES: then
M doesn’t halt on w
NO: then
M halts on w
7
Machine for halting problem
M
w
construct
Mw
Check if
L( M w )
is finite
YES
NO
NO
YES
8
Theorem:
For a recursively enumerable language L
it is undecidable to determine whether
L contains two different strings of same length
Proof: We will reduce the halting problem
to this problem
9
Let
M be the machine that accepts L
L( M )  L
Assume we have the two-strings algorithm:
M
Algorithm for
two-strings
problem
YES
NO
L(M ) contains
L(M )
Doesn’t
contain
two equal length strings 10
We will design the halting problem algorithm:
M
w
Algorithm for
Halting problem
YES
M halts on w
NO
doesn’t
halt on
M
w
11
First construct machine
Initially, simulates
Mw :
M on input w
When M enters a halt state,
accept symbols a or b
(two equal length strings)
12
M halts on w
if and
only if
Mw
accepts
a and b
(two equal length strings)
13
Algorithm for halting problem:
Inputs: machine
1. Construct
M and string w
Mw
2. Determine if M w accepts
two strings of equal length
YES: then
M halts on w
NO: then
M doesn’t halt on w
14
Machine for halting problem
M
w
construct
Mw
Check if
L( M w )
has two
equal length
strings
YES
YES
NO
NO
15
The Post Correspondence
Problem
16
Some undecidable problems for
context-free languages:
• Is context-free grammar
• Is
G ambiguous?
L(G1)  L(G2 )   ?
17
We need a tool to prove that the previous
problems for context-free languages
are undecidable:
The Post Correspondence Problem
18
The Post Correspondence Problem
Input:
Two sequences of strings
A  w1, w2 , , wn
B  v1, v2 , , vn
19
There is a Post Correspondence Solution
if there is a sequence i, j ,, k such that:
wi w j  wk  vi v j vk
PC-solution
20
Example:
A:
w1
100
w2
11
w3
111
B:
v1
001
v2
111
v3
11
PC-solution: 2,1,3
w2 w1w3  v2v1v3
11100111
21
Example:
A:
w1
00
w2
001
w3
1000
B:
v1
0
v2
11
v3
011
There is no solution
Because total length of strings from B
is smaller than total length of strings from A
22
The Modified Post Correspondence Problem
Inputs:
A  w1, w2 , , wn
B  v1, v2 , , vn
MPC-solution:
1, i, j,, k
w1wi w j  wk  v1vi v j vk
23
Example:
A:
w1
11
w2
111
w3
100
B:
v1
111
v2
11
v3
001
MPC-solution: 1,3,2
w1w3w2  v1v2v3
11100111
24
1. We will prove that the
MPC problem is undecidable
2. We will prove that the
PC problem is undecidable
25
1. We will prove that the
MPC problem is undecidable
We will reduce the membership problem
to the MPC problem
26
Membership problem
Input: recursive language L
string w
Question:
w L ?
Undecidable
27
Membership problem
Input: unrestricted grammar G
string w
Question: w L(G ) ?
Undecidable
28
The reduction of the membership problem
to the MPC problem:
For unrestricted grammar G and string w
we construct a pair
A, B such that
A, B has an MPC-solution
if and only if w L(G )
29
A
FS 
B
F
Grammar G
S : start variable
F : special symbol
a
a
For every symbol a
V
V
For every variable V
30
A
E
y

B
 wE
Grammar G
string w
E : special symbol
x
For every production
x y

31
Example:
Grammar G :
S  aABb | Bbb
Bb  C
AC  aac
String
w  aaac
32
A
B
w1 :
FS 
v1 :
w2 :
a
v2 :

w8 :
F
a
b
c
b
c
A
A

B
B
C
S
C
S
v8 :
33
A
w9 :

w14 :
B
E
aABb
Bbb
C
aac

v9 :

v14 :
aaacE
S
S
Bb
AC

34
Grammar G :
S  aABb | Bbb
Bb  C
AC  aac
aaac  L(G )
S  aABb  aAC  aaac
35
S  aABb
A
w1
w10
F S a A B b
v1 v10
B
36
S  aABb  aAC
A
w1
w10 w14 w2 w5 w12
F S a A B ba A C
v1 v10 v14 v2 v5 v12
B
37
S  aABb  aAC  aaac
A
w1
w10 w14 w2 w5 w12w14 w2 w13 w9
F S a A B ba A C a a a c E
v1 v10 v14 v2 v5 v12 v14 v2 v13
v9
B
38
Theorem:
( A, B ) has an MPC-solution
if and only if w L(G )
39
Algorithm for membership problem:
Input: unrestricted grammar G
string w
Construct the pair A, B
If A, B has an MPC-solution then w L(G )
else w L(G )
40
Membership machine
solution
G
w
construct A, B
A, B
MPC
algorithm
w L(G)
w L(G)
No-solution
41
2. We will prove that the
PC problem is undecidable
We will reduce the MPC problem
to the PC problem
42
A, B : input to the MPC problem
A  w1, w2 ,, wn
B  v1, v2 ,, vn
43
We construct new sequences C, D
C  w0 , w1 ,, wn , wn 1
D  v0 , v1 ,, vn , vn 1
A  w1, w2 ,, wn
B  v1, v2 ,, vn
44
A
wi  abcad
C
wi  a * b * c * a * d *
We insert a special symbol between
any two symbols
45
B
vi  abcad
D
vi  * a * b * c * a * d
46
Special Cases
C
D
w0  * w1
v0  v1
wn 1  
vn 1  *
47
Observation:
There is a PC-solution for C, D
if and only if
there is a MPC-solution for A, B
48
PC-solution
w0  wk wn 1  v0  wk vn 1
MPC-solution
w1 wk  v1vk
49
MPC-algorithm
Input: sequences
A, B
Construct sequences C, D
Solve the PC problem for C, D
50
MPC algorithm
A, B
construct C, D
C, D
PC
algorithm
solution
No-solution
51
Download