I want to order lexicographically the monomials in a "parametrized polynomial", i.e. polynomials whose "symbolic bits" may be either "variables" or "parameters". For example:
In:= Expand[(x + a y + a^2 z)^3] /. a^n_ -> a^Mod[n, 3] Out= x^3 + y^3 + 6 x y z + z^3 + 3 x^2 y a + 3 y^2 z a + 3 x z^2 a + 3 x y^2 a^2 + 3 x^2 z a^2 + 3 y z^2 a^2
In the polynomial above
z are intended as "variables", whereas
a is intended as a "parameter".
The documentation for Mathematica states that monomials in a polynomial are ordered lexicographically by default, but if so, I don't understand why the two terms with
x^2 come after the
y^3 term in the polynomial above, for example.
So my question is: how can I force a lexicographic ordering of the monomials with respect to the "variables" (i.e.
z). (In particular, for the polynomial above, the symbol
a should be disregarded for the ordering.)
For example, the desired ordering for the polynomial above would be
x^3 + 3 x^2 y a + 3 x^2 z a^2 + 3 x y^2 a^2 + 3 x z^2 a + 6 x y z + y^3 + 3 y^2 z a + 3 y z^2 a^2 + z^3