Sorry if I'm in the wrong Stackexchange (but sage is a math program...)
I'm computing something on multivariate polynomials: I have a primary variable $x$ and several other variables $a, b, c, \dots$. When I do an operation, I would like the output grouped together as powers of $x$, not in the very expanded form. Does anyone know how to do this?
Code example:
S = PolynomialRing(GF(4,'x'),4,"abcd")
c1=(a*b*d + a*b + c + d + 1)*x + (a*b*c*d + b*c*d + c*d + a + d)
c2=(a*b*c*d + a*b*d + b*c*d + a*b + a*c + a*d + a)*x + (a*b*c + a*c + b*d + c)
cadd = c1 + c2
print(cadd)
Output:
x*a*b*c*d + x*b*c*d + a*b*c*d + x*a*c + a*b*c + x*a*d + b*c*d + x*a + x*c + a*c + x*d + b*d + c*d + x + a + c + d
Output I would like:
x*(a*b*c*d + b*c*d + a*c + a*d + a + c + d + 1) + (a*b*c*d + a*b*c + b*c*d + a*c + b*d + c*d + a + c + d)
Thanks!
Ok never mind, I found out - just in case anyone ever has a similar problem:
R. = PolynomialRing(GF(2), 4)
S. = PolynomialRing(R)