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

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

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[1] μ[p]^j + (1 - w[1]) (η[p, 2] + μ[p])^j;
ss[1] (* gives s[1] *)
ss[2] (* gives s[2] *)

But how to simplify kappa, so that i get a term only contains s[1],s[2],\[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[2], #}], {s[1], 
 s[2]}, {w[1], \[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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.