A better way to simplify with rules than this?

kappa = {1, (1 - ϕ)*(1 - w) + (1 - ϕ)*w +
ϕ*w*(1 - μ[p]) + ϕ*(1 - w)*(1 - η[p, 2] -
μ[p]), ϕ*w*μ[p] + ϕ*(1 - w)*
(η[p, 2] + μ[p]), (1 - ϕ)*(1 - w) +
(1 - ϕ)*w + (1 - ϕ)*ϕ*w*(1 - μ[p]) +
ϕ^2*w*(1 - μ[p])^2 + (1 - ϕ)*ϕ*(1 - w)*
(1 - η[p, 2] - μ[p]) + ϕ^2*(1 - w)*
(1 - η[p, 2] - μ[p])^2, ϕ^2*w*(1 - μ[p])*
μ[p] + ϕ^2*(1 - w)*(1 - η[p, 2] - μ[p])*
(η[p, 2] + μ[p]), (1 - ϕ)*ϕ*w*μ[p] +
ϕ^2*w*(1 - μ[p])*μ[p] + (1 - ϕ)*ϕ*(1 - w)*
(η[p, 2] + μ[p]) + ϕ^2*(1 - w)*
(1 - η[p, 2] - μ[p])*(η[p, 2] + μ[p]),
ϕ^2*w*μ[p]^2 + ϕ^2*(1 - w)*(η[p, 2] + μ[p])^
2}

rules = {w*μ[p] + (1 - w)*(η[p, 2] + μ[p]) -> s,
w*μ[p]^2 + (1 - w)*(η[p, 2] + μ[p])^2 -> s}

There is a very simple expression kappa I am trying to simplify, using rules. I know that a direct replacement /. is not going to work as the terms do not match exactly.

So I have looked up some other ways, like TransformationFunctions. But I dont understand the examples. How to write out the functions.

The relationships in the rules are simple, I can express them like this

ss[j_] := w μ[p]^j + (1 - w) (η[p, 2] + μ[p])^j;
ss (* gives s *)
ss (* gives s *)

But how to simplify kappa, so that i get a term only contains s,s,\[Phi]?

Basically, I am looking for the equivalent command to simplify/siderels in Maple, here. At background, it computes a Gröbner Basis, see here and here. and then some magic replacement rules applies, it gives me what I want. I don't know much about it, but as long as it can simplify the expression, I am happy.

Updated (with an answer):

Flatten[GroebnerBasis[Flatten[{Thread[ss[#] - s[#]] & /@ Range, #}], {s,
s}, {w, \[Eta][p, 2], \[Mu][p]}] & /@ kappa]

After some trial and error, I came up with the above solution. I am not sure how efficient it will be when I have more terms in kappa to simplify with more rules.

Is there a better way? Perhaps shorter code?

• vars = Variables[kappa]; PolynomialReduce[kappa, GroebnerBasis[Subtract @@@ rules, vars], vars][[All, 2]] will give such a result. – Daniel Lichtblau Dec 28 '14 at 23:09
• @DanielLichtblau It does seem much faster and can be extended to a larger dimension of my problem! – Chen Stats Yu Dec 28 '14 at 23:19