Ask Your Question
1

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

asked 2016-06-02 17:25:07 +0100

petRUShka gravatar image

updated 2016-06-02 17:27:29 +0100

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-06-02 17:46:07 +0100

calc314 gravatar image

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)
edit flag offensive delete link more
2

answered 2016-06-02 17:51:13 +0100

tmonteil gravatar image

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-02 17:25:07 +0100

Seen: 645 times

Last updated: Jun 02 '16