1
$\begingroup$

I have an expression which is a polynomial in Delta, xi and phi. The prefactors are huge expressions, but actually real constants. Therefore, I would like to replace them each by a single symbol e.g. c1, c2, .... Then I would perform some transformations that otherwise take forever, and finally I would like to resubstitue these expressions. Is there any way I can do this in an automated fashion?

Input: Expression and poly variables Output: Expression with "short" coeffficients and a list of replacement-rules to apply later to resubst. back the original prefactors.

Here is a small example of what I mean:

myExpr = (a^2+b^2-Sqrt[2*d-1/f]) + (a^2-b^2+r) * Delta 
         + (44r*t*f-a^(3/2)) * Delta * phi

should result in

myShortExpression = c1 + c2 * Delta + c3 * Delta * phi
replacementRules  = {c1->a^2+b^2-Sqrt[2*d-1/f],
                     c2->a^2-b^2+r,
                     c3->44r*t*f-a^(3/2)}
$\endgroup$
0

1 Answer 1

1
$\begingroup$
cr = CoefficientRules[myExpr, {Delta, phi}]
cr /. HoldPattern@(a_ -> b_) :> f @@ a -> b
FromCoefficientRules[cr /. HoldPattern@(a_ -> b_) :> a -> f @@ a, {Delta, phi}]
(* f[0, 0] + Delta f[1, 0] + Delta phi f[1, 1] *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.