# Post-Correspondence Problem

```The Post Correspondence
Problem
Fall 2006
Costas Busch - RPI
1
Some undecidable problems for
context-free languages:
• Is
L(G1)  L(G2 )   ?
G1,G2 are context-free grammars
• Is context-free grammar
Fall 2006
Costas Busch - RPI
G ambiguous?
2
We need a tool to prove that the previous
problems for context-free languages
are undecidable:
The Post Correspondence Problem
Fall 2006
Costas Busch - RPI
3
The Post Correspondence Problem
Input:
Two sets of
n strings
A  w1, w2 , , wn
B  v1, v2 , , vn
Fall 2006
Costas Busch - RPI
4
There is a Post Correspondence Solution
if there is a sequence i, j ,, k such that:
PC-solution:
wi w j  wk  vi v j vk
Indices may be repeated or omitted
Fall 2006
Costas Busch - RPI
5
Example:
A:
w1
100
w2
11
w3
111
B:
v1
001
v2
111
v3
11
PC-solution: 2,1,3
w2 w1w3  v2v1v3
11100111
Fall 2006
Costas Busch - RPI
6
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
Fall 2006
Costas Busch - RPI
7
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
Fall 2006
Costas Busch - RPI
8
Example:
A:
w1
11
w2
111
w3
100
B:
v1
111
v2
11
v3
001
w1w3w2  v1v3v2
MPC-solution: 1,3,2
11100111
Fall 2006
Costas Busch - RPI
9
We will show:
1. The MPC problem is undecidable
(by reducing the membership to MPC)
2. The PC problem is undecidable
(by reducing MPC to PC)
Fall 2006
Costas Busch - RPI
10
Theorem: The MPC problem is undecidable
Proof: We will reduce the membership
problem to the MPC problem
Fall 2006
Costas Busch - RPI
11
Membership problem
Input: Turing machine M
string w
Question: w  L(M ) ?
Undecidable
Fall 2006
Costas Busch - RPI
12
Membership problem
Input: unrestricted grammar G
string w
Question: w L(G ) ?
Undecidable
Fall 2006
Costas Busch - RPI
13
Suppose we have a decider for
the MPC problem
String Sequences
A
MPC solution?
MPC problem
decider
NO
B
Fall 2006
YES
Costas Busch - RPI
14
We will build a decider for
the membership problem
w L(G) ?
G
w
Fall 2006
Membership
problem
decider
Costas Busch - RPI
YES
NO
15
The reduction of the membership problem
to the MPC problem:
Membership problem decider
G
A
w
B
Fall 2006
Costas Busch - RPI
yes yes
MPC problem
decider
no
no
16
We need to convert the input instance of
one problem to the other
Membership problem decider
G
w
Fall 2006
A
Reduction?
B
Costas Busch - RPI
yes yes
MPC problem
decider
no
no
17
Reduction:
Convert grammar G and string
to sets of strings
w
A and B
Such that:
There is an MPC
solution for A, B
G generates w
Fall 2006
Costas Busch - RPI
18
A
FS 
Fall 2006
Grammar G
B
F
S : start variable
F : special symbol
a
a
For every symbol a
V
V
For every variable V
Costas Busch - RPI
19
A
E
y

Fall 2006
Grammar G
B
string w
 wE
E : special symbol
x
For every production
x y

Costas Busch - RPI
20
Example:
Grammar G :
S  aABb | Bbb
Bb  C
AC  aac
String
Fall 2006
w  aaac
Costas Busch - RPI
21
A
B
w1 :
FS 
v1 :
w2 :
a
v2 :
w3 :

w8 :
Fall 2006
b
c
A
F
a
v3 :
b
c

A
B
B
C
S
C
S
v8 :
Costas Busch - RPI
22
A
w9 :

w14 :
Fall 2006
E
aABb
Bbb
C
aac

B
v9 :

v14 :
Costas Busch - RPI
 aaacE
S
S
Bb
AC

23
Grammar G :
S  aABb | Bbb
Bb  C
AC  aac
aaac  L(G ) :
S  aABb  aAC  aaac
Fall 2006
Costas Busch - RPI
24
S  aABb | Bbb
Derivation: S
A:
Bb  C
AC  aac
w1
F S
B:
Fall 2006
v1
Costas Busch - RPI
25
S  aABb | Bbb
Derivation:
Bb  C
AC  aac
S  aABb
A:
w1
w10
F S a A B b
B:
Fall 2006
v1 v10
Costas Busch - RPI
26
S  aABb | Bbb
Derivation:
S  aABb  aAC
A:
w1
Bb  C
AC  aac
w10 w14 w2 w5 w12
F S a A B ba A C
B : v1 v10 v14 v2 v5 v12
Fall 2006
Costas Busch - RPI
27
S  aABb | Bbb
Derivation:
S  aABb  aAC  aaac
A:
w1
Bb  C
AC  aac
w10 w14 w2 w5 w12w14 w2 w13
F S a A B ba A C a a a c E
B :v1 v10 v14 v2 v5 v12 v14 v2 v13
Fall 2006
Costas Busch - RPI
28
S  aABb | Bbb
Derivation:
S  aABb  aAC  aaac
A:
w1
Bb  C
AC  aac
w10 w14 w2 w5 w12w14 w2 w13 w9
F S a A B ba A C a a a c E
B :v1 v10 v14 v2 v5 v12 v14 v2 v13
Fall 2006
Costas Busch - RPI
v9
29
( A, B ) has an MPC-solution
if and
only if
w L(G)
Fall 2006
Costas Busch - RPI
30
Membership problem decider
G
w
Fall 2006
Construct
A, B
A
B
Costas Busch - RPI
yes yes
MPC problem
decider
no
no
31
Since the membership problem is undecidable,
The MPC problem is undecidable
END OF PROOF
Fall 2006
Costas Busch - RPI
32
Theorem: The PC problem is undecidable
Proof: We will reduce the MPC problem
to the PC problem
Fall 2006
Costas Busch - RPI
33
Suppose we have a decider for
the PC problem
String Sequences
C
PC solution?
PC problem
decider
NO
D
Fall 2006
YES
Costas Busch - RPI
34
We will build a decider for
the MPC problem
String Sequences
A
MPC solution?
MPC problem
decider
NO
B
Fall 2006
YES
Costas Busch - RPI
35
The reduction of the MPC problem
to the PC problem:
MPC problem decider
A
B
Fall 2006
C
D
Costas Busch - RPI
PC problem
decider
yes yes
no
no
36
We need to convert the input instance of
one problem to the other
MPC problem decider
C
A
Reduction?
B
Fall 2006
D
Costas Busch - RPI
PC problem
decider
yes yes
no
no
37
A, B : input to the MPC problem
A  w1, w2 ,, wn
B  v1, v2 ,, vn
Translated
to
C ,D : input to the PC problem
C  w1,,wn,wn1
D  v1,,vn,vn1
Fall 2006
Costas Busch - RPI
38
C
A
wi   1 2  k
For each
i
wi   1 *  2 *   k *
replace w1  * w1
wn1  
B
D
vi   1 2  k
vi  *1 *  2 *  *  k
For each i
vn1  *
Fall 2006
Costas Busch - RPI
39
C
PC-solution
D
w1wiwkwn1  v1v iwkvn1
These strings
Fall 2006
Costas Busch - RPI
40
C
PC-solution
D
w1wiwkwn1  v1v iwkvn1
A
B
w1wi wk  v1vi vk
MPC-solution
Fall 2006
Costas Busch - RPI
41
C, D
has a PC solution
if and
only if
A, B
Fall 2006
has an MPC solution
Costas Busch - RPI
42
MPC problem decider
A
B
Fall 2006
Construct
C
C, D
D
Costas Busch - RPI
PC problem
decider
yes yes
no
no
43
Since the MPC problem is undecidable,
The PC problem is undecidable
END OF PROOF
Fall 2006
Costas Busch - RPI
44
Some undecidable problems for
context-free languages:
• Is
L(G1)  L(G2 )   ?
G1,G2 are context-free grammars
• Is context-free grammar
ambiguous?
G
We reduce the PC problem to these problems
Fall 2006
Costas Busch - RPI
45
Theorem: Let G1,G2 be context-free
grammars. It is undecidable
to determine if
L(G1)  L(G2 )  
(intersection problem)
Proof: Reduce the PC problem to this
problem
Fall 2006
Costas Busch - RPI
46
Suppose we have a decider for the
intersection problem
Context-free
grammars
G1
G2
Fall 2006
L(G1)  L(G2 )   ?
Emptyinterection
problem
decider
Costas Busch - RPI
YES
NO
47
We will build a decider for
the PC problem
String Sequences
A
PC solution?
PC problem
decider
NO
B
Fall 2006
YES
Costas Busch - RPI
48
The reduction of the PC problem
to the empty-intersection problem:
PC problem decider
A
GA
B
GB
Fall 2006
Costas Busch - RPI
no
yes
Intersection
problem
yes no
decider
49
We need to convert the input instance of
one problem to the other
PC problem decider
GA
A
Reduction?
B
Fall 2006
GB
Costas Busch - RPI
no
yes
Intersection
problem
yes no
decider
50
Introduce new unique symbols:
a1, a2 ,, an
A  w1, w2 ,, wn
LA  {s : s  wi w j wk ak a j ai }
Context-free grammar GA : S A  wi S Aai | wi ai
B  v1, v2 ,, vn
LB  {s : s  vi v j vk ak a j ai }
Context-free grammar GB : S B  vi S B ai | vi ai
Fall 2006
Costas Busch - RPI
51
( A, B) has a PC solution
if and
only if
L(GA )  L(GB )  
Fall 2006
Costas Busch - RPI
52
L(G1)  L(G2 )  
s  wi w j wk ak a j ai
s  vi v j vk ak a j ai
Because
a1, a2 ,, an
are unique
There is a PC solution:
wi w j wk  viv j vk
Fall 2006
Costas Busch - RPI
53
PC problem decider
A
B
Fall 2006
GA
Construct
Context-Free
GB
Grammars
Costas Busch - RPI
no
yes
Intersection
problem
yes no
decider
54
Since PC is undecidable,
the Intersection problem is undecidable
END OF PROOF
Fall 2006
Costas Busch - RPI
55
Theorem: For a context-free grammar
G ,
it is undecidable to determine
if G is ambiguous
Proof:
Fall 2006
Reduce the PC problem
to this problem
Costas Busch - RPI
56
PC problem decider
A
B
Fall 2006
Construct
Context-Free
Grammar
no
G
Costas Busch - RPI
yes
Ambiguous
problem
yes no
decider
57
SA
start variable of GA
SB
start variable of GB
S
start variable of
G
S  S A | SB
Fall 2006
Costas Busch - RPI
58
( A, B) has a PC solution
if and
only if
L(GA )  L(GB )  
if and
only if
G
Fall 2006
is ambiguous
Costas Busch - RPI
59
```