# Redefine monomials as independent variables

I am doing work with variables $x_1$, $x_2$, $x_3$, etc. In the process I generate polynomials which are of the form $$p = x_1 x_2 x_3 + x_2^2 x_3 + x_1^2 x_2 + \ldots$$ I would like to be able to do operations on each of these monomials as if they were independent variables.

So suppose one has a list of monomials, $$\{x_1^2 x_2, x_3 x_2 x_1, x_1^2 x_3, \ldots\}$$ Is there a way of changing the attributes of the elements in this list so that one can treat these monomials as single variables? For example, this would allow one to differentiate with respect to a specific monomial, as opposed to a single $x_i$.

I realize this may not be possible in Mathematica but it would greatly simplify my work if this could be done. Thanks for any advice.

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
poly = RandomInteger[{-5, 5}, Length@#].# &[Times @@@ Map[Tuples[{a, b, c}, #] &, Range]~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, a^2 c -> x, a^2 -> x, a b^2 -> x,
a b c -> x, a b -> x, a c^2 -> x, a c -> x, a -> x,
b^3 -> x, b^2 c -> x, b c^2 -> x, b c -> x,
b -> x, c^3 -> x, c^2 -> x, c -> x} *)


Finally, use the rules:

transformedpoly = poly /. rules
(* 5 x + 2 x + 2 x + 3 x + x + 3 x + 3 x + x +
5 x + 2 x - x - 5 x + 5 x + 5 x + 2 x - 5 x + 4 x *)


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

• I think this is a good strategy -- I used it and it worked well enough. Thanks very much. Sep 25 '17 at 23:57