# Replace Coefficients of multivariate expressions by numbered constants

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)}


## 1 Answer

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] *)