Sie sind auf Seite 1von 58

The Post Correspondence

Problem

Fall 2003 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 G ambiguous?

Fall 2003 Costas Busch - RPI 2


We need a tool to prove that the previous
problems for context-free languages
are undecidable:

The Post Correspondence Problem

Fall 2003 Costas Busch - RPI 3


The Post Correspondence Problem

Input: Two sequences of n strings

A  w1, w2 ,  , wn

B  v1, v2 ,  , vn

Fall 2003 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

Indeces may be repeated or ommited

Fall 2003 Costas Busch - RPI 5


Example: w1 w2 w3
A: 100 11 111

v1 v2 v3
B: 001 111 11

PC-solution: 2,1,3 w2 w1w3  v2v1v3

11100111
Fall 2003 Costas Busch - RPI 6
Example: w1 w2 w3
A: 00 001 1000

v1 v2 v3
B: 0 11 011

There is no solution

Because total length of strings from B


is smaller than total length of strings from A
Fall 2003 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 2003 Costas Busch - RPI 8
Example: w1 w2 w3
A: 11 111 100

v1 v2 v3
B: 111 11 001

MPC-solution: 1,3,2 w1w3w2  v1v3v2

11100111
Fall 2003 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 2003 Costas Busch - RPI 10


Theorem: The MPC problem is undecidable

Proof: We will reduce the membership


problem to the MPC problem

Fall 2003 Costas Busch - RPI 11


Membership problem

Input: recursive language L


string w

Question: w L ?

Undecidable

Fall 2003 Costas Busch - RPI 12


Membership problem

Input: unrestricted grammar G


string w

Question: w L(G ) ?

Undecidable

Fall 2003 Costas Busch - RPI 13


Suppose we have a decider for
the MPC problem

String Sequences MPC solution?

A YES
MPC problem
decider
B NO

Fall 2003 Costas Busch - RPI 14


We will build a decider for
the membership problem

w L(G ) ?
G Membership
YES
problem
w decider NO

Fall 2003 Costas Busch - RPI 15


The reduction of the membership problem
to the MPC problem:

Membership problem decider

A yes yes
G MPC problem
B decider no no
w

Fall 2003 Costas Busch - RPI 16


We need to convert the input instance of
one problem to the other

Membership problem decider

A yes yes
G convert MPC problem
inputs decider no no
w B
?

Fall 2003 Costas Busch - RPI 17


A B Grammar G

FS  F S : start variable
F : special symbol

a a For every symbol a

V V For every variable V

Fall 2003 Costas Busch - RPI 18


A B Grammar G

E  wE string w
E : special symbol

y x For every production


x y

 

Fall 2003 Costas Busch - RPI 19


Example:

Grammar G : S  aABb | Bbb


Bb  C
AC  aac

String w  aaac

Fall 2003 Costas Busch - RPI 20


A B

w1 : FS  v1 : F
w2 : a v2 : a
w3 : b v3 : b
c c
 A  A
B B
C C
w8 : S v8 : S
Fall 2003 Costas Busch - RPI 21
A B

w9 : E v9 :  aaacE
aABb S
Bbb S
 
C Bb
aac AC
w14 :  v14 : 

Fall 2003 Costas Busch - RPI 22


Grammar G : S  aABb | Bbb
Bb  C
AC  aac

aaac  L(G ) : S  aABb  aAC  aaac

Fall 2003 Costas Busch - RPI 23


S  aABb | Bbb
Derivation: S Bb  C
AC  aac

A: w1

F S 

B: v1

Fall 2003 Costas Busch - RPI 24


S  aABb | Bbb
Derivation:
Bb  C
S  aABb
AC  aac

A: w1 w10

F S a A B b

B: v1 v10

Fall 2003 Costas Busch - RPI 25


S  aABb | Bbb
Derivation:
Bb  C
S  aABb  aAC
AC  aac

A: w1 w10 w14 w2 w5 w12

F S a A B ba A C

B : v1 v10 v14 v2 v5 v12

Fall 2003 Costas Busch - RPI 26


S  aABb | Bbb
Derivation:
Bb  C
S  aABb  aAC  aaac AC  aac

A: w1 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 2003 Costas Busch - RPI 27


S  aABb | Bbb
Derivation:
Bb  C
S  aABb  aAC  aaac
AC  aac

A: w1 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 v9

Fall 2003 Costas Busch - RPI 28


( A, B ) has an MPC-solution

if and
only if

w L(G )

Fall 2003 Costas Busch - RPI 29


Membership problem decider

A yes yes
G Construct MPC problem
A, B B decider no no
w

Fall 2003 Costas Busch - RPI 30


Since the membership problem is undecidable,
The MPC problem is uncedecidable

END OF PROOF
Fall 2003 Costas Busch - RPI 31
Theorem: The PC problem is undecidable

Proof: We will reduce the MPC problem


to the PC problem

Fall 2003 Costas Busch - RPI 32


Suppose we have a decider for
the PC problem

String Sequences PC solution?

C YES
PC problem
decider
D NO

Fall 2003 Costas Busch - RPI 33


We will build a decider for
the MPC problem

String Sequences MPC solution?

A YES
MPC problem
decider
B NO

Fall 2003 Costas Busch - RPI 34


The reduction of the MPC problem
to the PC problem:

MPC problem decider

C yes yes
A PC problem
D decider no no
B

Fall 2003 Costas Busch - RPI 35


We need to convert the input instance of
one problem to the other

MPC problem decider

C yes yes
A convert PC problem
inputs D decider no no
B
?

Fall 2003 Costas Busch - RPI 36


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  w0 , w1 , , wn , wn 1
D  v0 , v1 , , vn , vn 1
Fall 2003 Costas Busch - RPI 37
A C
wi   1 2  k wi   1 *  2 *   k *
For each i replace w 1  * w 1

wn1  

D
B
vi   1 2  k vi  * 1 *  2 *  *  k

For each i vn1  *

Fall 2003 Costas Busch - RPI 38


PC-solution
C D
w 1wi w kwn1  v1v iw kvn1

Has to start with


These strings

Fall 2003 Costas Busch - RPI 39


C PC-solution D
w 1wi w kwn1  v1v i w kvn1

A B
w 1wi w k  v1vi v k
MPC-solution

Fall 2003 Costas Busch - RPI 40


C, D has a PC solution

if and
only if

A, B has an MPC solution

Fall 2003 Costas Busch - RPI 41


MPC problem decider

C yes yes
A Construct PC problem
C, D D decider no no
B

Fall 2003 Costas Busch - RPI 42


Since the MPC problem is undecidable,
The PC problem is undecidable

END OF PROOF

Fall 2003 Costas Busch - RPI 43


Some undecidable problems for
context-free languages:

• Is L(G1 )  L(G2 )   ?
G1,G2 are context-free grammars

• Is context-free grammar G
ambiguous?

We reduce the PC problem to these problems


Fall 2003 Costas Busch - RPI 44
Theorem: Let G1,G2 be context-free
grammars. It is undecidable
to determine if L(G1 )  L(G2 )  

Proof: Reduce the PC problem to this


problem

Fall 2003 Costas Busch - RPI 45


Suppose we have a decider for the
empty-intersection problem

Context-free L(G1 )  L(G2 )   ?


grammars
G1 Empty- YES
interection
problem
G2 NO
decider

Fall 2003 Costas Busch - RPI 46


We will build a decider for
the PC problem

String Sequences PC solution?

A YES
PC problem
decider
B NO

Fall 2003 Costas Busch - RPI 47


The reduction of the PC problem
to the empty-intersection problem:

PC problem decider

G A Empty- no yes
A
interection
GB problem
B yes no
decider

Fall 2003 Costas Busch - RPI 48


We need to convert the input instance of
one problem to the other

PC problem decider

G A Empty- no yes
A convert
inputs interection
GB problem
B ? yes no
decider

Fall 2003 Costas Busch - RPI 49


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 G A : 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 2003 Costas Busch - RPI 50


( A, B ) has a PC solution

if and
only if

L(G A )  L(GB )  

Fall 2003 Costas Busch - RPI 51


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:

s  wi w j  wk ak  a j ai
Fall 2003 Costas Busch - RPI 52
PC problem decider

G A Empty- no yes
A Construct
Context-Free interection
GB problem
B Grammars yes no
decider

Fall 2003 Costas Busch - RPI 53


Since PC is undecidable,
the empty-intersection problem is undecidable

END OF PROOF

Fall 2003 Costas Busch - RPI 54


Theorem: For a context-free grammar G,
it is undecidable to determine
if G is ambiguous

Proof: Reduce the PC problem


to this problem

Fall 2003 Costas Busch - RPI 55


PC problem decider

Ambiguous- no yes
A Construct
Context-Free
G grammar
Grammar problem
B yes no
decider

Fall 2003 Costas Busch - RPI 56


SA start variable of G A

SB start variable of GB

S start variable of G
S  S A | SB
Fall 2003 Costas Busch - RPI 57
( A, B ) has a PC solution

if and
only if

L(G A )  L(GB )  
if and
only if

G is ambiguous

Fall 2003 Costas Busch - RPI 58

Das könnte Ihnen auch gefallen