I want to combine or merge diffuse passes with glossy passes to get a set of new color, direct and indirect passes.
What you normally do when you combine passes is to add indirect pass with direct pass and then multiply with the color, then do the same with the other type of passes and add them together, so:
Composite = Xcolor * (Xind + XDir) + Ycolor * (Yind + YDir)
now you want to separate Composite in Zcolor * (Zind + ZDir), then:
Zcolor * (Zind + ZDir) = Xcolor * (Xind + XDir) + Ycolor * (Yind + YDir)
There are 3 unknowns for one equation, therefore you have to assume more relationships for the unknowns, I chose these because they give good results:
Zind = Xind + Yind
ZDir = XDir + YDir
with these relationships Zcolor can be solved to
Zcolor = Composite/(Zind + ZDir)
This is the node setup.