Here's a quick answer, not fully tested (as in, there might be edge cases where the generation of the monomial list fails, and perhaps the replacement rules, tool should be pretty robust, though). Let's first generate a random polynomial in the variables {a, b, c}
:
SeedRandom[10]
poly = RandomInteger[{-5, 5}, Length@#].# &[Times @@@ Map[Tuples[{a, b, c}, #] &, Range[3]]~Flatten~1 // DeleteDuplicates]
(* 5 a + 2 a^2 + 5 a^3 + 5 b + 3 a b + 3 a b^2 + 2 b^3 + 4 c + a c
+ 2 a^2 c + 5 b c + a b c - b^2 c - 5 c^2 + 3 a c^2 - 5 b c^2 + 2 c^3 *)
Then, make a list or replacement rules. Note that I am using MonomialList
with some post-processing to extract the monomials; this isn't necessary if you already have a list of the monomials.
rules = Thread[# -> Array[x, Length@#]] &@MonomialList@poly /. a_?NumericQ x_ :> x
(* {a^3 -> x[1], a^2 c -> x[2], a^2 -> x[3], a b^2 -> x[4],
a b c -> x[5], a b -> x[6], a c^2 -> x[7], a c -> x[8], a -> x[9],
b^3 -> x[10], b^2 c -> x[11], b c^2 -> x[12], b c -> x[13],
b -> x[14], c^3 -> x[15], c^2 -> x[16], c -> x[17]} *)
Finally, use the rules:
transformedpoly = poly /. rules
(* 5 x[1] + 2 x[2] + 2 x[3] + 3 x[4] + x[5] + 3 x[6] + 3 x[7] + x[8] +
5 x[9] + 2 x[10] - x[11] - 5 x[12] + 5 x[13] + 5 x[14] + 2 x[15] - 5 x[16] + 4 x[17] *)
We can go back to the original polynomial using Reverse /@ rules
:
transformedpoly /. Reverse /@ rules
(* 5 a + 2 a^2 + 5 a^3 + 5 b + 3 a b + 3 a b^2 + 2 b^3 + 4 c + a c
+ 2 a^2 c + 5 b c + a b c - b^2 c - 5 c^2 + 3 a c^2 - 5 b c^2 + 2 c^3 *)