# Several variables, consider polynomail as polynomial only of $X$, group coefficients

Suppose I have variables d, e and x and I somehow using symbolic calculation get polynomial like this:

$$9d^2e^2x^2 - 36d^2ex^3 + 18de^2x^2$$

I want sage to group coefficients at x and consider my polynomial as polynomial only of x, I want other variables to be no more than just parameters. In short I want to see something like this:

$$9de^2(d + 2)x^2 - 36d^2ex^3$$

Is it possible to exploit such an approach in Sage?

P.S. I shortened my example. In real life example it is not so easy to see such a grouping by hands.

edit retag close merge delete

Sort by » oldest newest most voted

You can try:

var('d e x')
f = 9*d^2*e^2*x^2-36*d^2*e*x^3+18*d*e^2*x^2
f.collect(x)


If your example is very complicated, you might wish to use

f.coefficients(x)


to obtain a list of the coefficients with respect to $x$.

Depending on what you are doing, it might also be useful to define the ring you are working in:

R.<x> = PolynomialRing(QQ)

more

If i understand correctly, you are looking for a polynomial in the indeterminate x whose coefficients belong to the polynomial ring with indeterminates d and e. You can define this as follows (assuming the numeral coefficients are rational numbers):

sage: R.<d,e> = PolynomialRing(QQ)
sage: R
Multivariate Polynomial Ring in d, e over Rational Field

sage: S.<x> = PolynomialRing(R)
sage: S
Univariate Polynomial Ring in x over Multivariate Polynomial Ring in d, e over Rational Field

sage: P = 9*d^2*e^2*x^2-36*d^2*e*x^3+18*d*e^2*x^2
sage: P
-36*d^2*e*x^3 + (9*d^2*e^2 + 18*d*e^2)*x^2

more