Specific term order of polynomials
I'm studying the Lagrange resolvent method for solving n-degree equations. This is what I have so far:
# a,b,c,d represent the roots of a 4-degree polynomial
R.<a,b,c,d> = QQ[]
# w will be treated as a primitive 4th root of unity
K.<w> = R[]
F = a + b*w + c*w^2 + d*w^3
# Lagrange resolvent
W = F^4 % (w^4 - 1)
# list of coefficients of w^i in W
Ws = [W[i] for i in range(4)]
S4 = SymmetricGroup(R.gens())
# compute the orbit of W under the action of S4
WOrbit = set([tuple([ws(s(R.gens())) for ws in Ws]) for s in S4])
# pretty print the orbit
for indt, t in enumerate(WOrbit):
print(f"Res {indt + 1}:")
for ind, i in enumerate(t):
show(html(f"${latex(w^ind)}$: ${latex(i)}$"))
This works quite nicely except for the term ordering of the coefficients (polynomials in the roots a,b,c,d). For example, for two elements of the orbit, I have the following constant terms: $1: a^{4} + b^{4} + 12 a^{2} b c + 6 b^{2} c^{2} + c^{4} + 12 a b^{2} d + 12 a c^{2} d + 6 a^{2} d^{2} + 12 b c d^{2} + d^{4}$ $1: a^{4} + 6 a^{2} b^{2} + b^{4} + 12 a b c^{2} + c^{4} + 12 a^{2} c d + 12 b^{2} c d + 12 a b d^{2} + 6 c^{2} d^{2} + d^{4}$
I would like some consistent ordering of the terms. I guess the inconsistency is caused by permuting the variables. Is there any way to adapt the term ordering according to the used permutation?
Also, is it possible to achieve an ordering first by the "degree signature" and then lexicographically? E.g. the first example should be ordered as (I grouped the terms with the same degree signature): $1: (a^{4} + b^{4} + c^{4} + d^{4}) + (6 a^{2} d^{2} + 6 b^{2} c^{2}) + (12 a^{2} b c + 12 a b^{2} d + 12 a c^{2} d + 12 b c d^{2} )$
Last but not least, since I'm a beginner in Sage I would appreciate any comments on my solution. I'm sure there must be nicer or more efficient solutions for some of my steps.
A simple solution would be writing your own function for printing terms of a polynomial in desired order.