Ask Your Question
1

How to determine the coefficients of a polynomial when they depend on variables?

asked 2014-07-14 05:58:46 +0100

Zorgoth gravatar image

updated 2014-07-14 06:03:20 +0100

Suppose that EXP2 is a polynomial expression in the variables X_1,X_2,...,X_n with coefficients that depend on the variables B_1,B_2,...,B_m. Suppose EXP1 is an expression equal to EXP2, but scrambled.

Given EXP1, how can I automatically obtain EXP2?

For example, if I have

a=var('a')

b=var('b')

c=var('c')

d=var('d')

e=var('e')

eqn=a==bd^2+ce^2+e(b+2c*d),

how can I automatically rewrite a as a polynomial in b and c, so that I get an equation that looks like

a==b(d^2+e)+c(e^2+2ed)?

edit retag flag offensive close merge delete

Comments

I'm not sure how to display the asterisks as literal asterisks...

Zorgoth gravatar imageZorgoth ( 2014-07-14 06:02:42 +0100 )edit

To display code inline, put it in between backquotes. To display blocks of code, indent code by 4 spaces.

slelievre gravatar imageslelievre ( 2014-07-14 07:15:11 +0100 )edit

Thank you!

Zorgoth gravatar imageZorgoth ( 2014-07-15 18:22:54 +0100 )edit

Try it: you can edit your question and make it look nicer!

slelievre gravatar imageslelievre ( 2014-07-15 18:24:36 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-07-14 07:24:50 +0100

slelievre gravatar image

updated 2014-07-14 08:01:26 +0100

The best way to work with variables b_i and x_i as you want is to define multivariate polynomial rings Rb and Rx and inject variables. Then any polynomial expression in the b_i's and x_i's will be transformed as a polynomial in the x_i's with coefficients in polynomials in the b_i's.

sage: Rb = PolynomialRing(ZZ,10,name='b')
sage: Rx = PolynomialRing(Rb,10,name='x')

sage: Rb.inject_variables()
Defining b0, b1, b2, b3, b4, b5, b6, b7, b8, b9
sage: Rx.inject_variables()
Defining x0, x1, x2, x3, x4, x5, x6, x7, x8, x9

sage: b1 * (x2 + x3) + b2 * (x3 + x8)
b1*x2 + (b1 + b2)*x3 + b2*x8

For your baby example, you could work in the symbolic ring and just ask coefficients,

sage: var('b c d e')
(b, c, d, e)
sage: a = b*d^2+c*e^2+e*(b+2*c*d)
sage: a
b*d^2 + c*e^2 + (2*c*d + b)*e
sage: a.coefficient(b)
d^2 + e
sage: a.coefficient(c)
2*d*e + e^2

or you could mix the two in the following way.

sage: S.<d,e> = PolynomialRing(QQ)
sage: R.<b,c> = PolynomialRing(S)
sage: R
Multivariate Polynomial Ring in b, c over Multivariate Polynomial Ring in d, e over Rational Field
sage: var('b c d e')
(b, c, d, e)
sage: a = b*d^2+c*e^2+e*(b+2*c*d)
sage: a
b*d^2 + c*e^2 + (2*c*d + b)*e
sage: R(a)
(d^2 + e)*b + (2*d*e + e^2)*c

But as a rule, it is best to avoid the symbolic ring altogether, whenever possible. And the way your main question is formulated, the most sensible approach is the polynomial rings one.

edit flag offensive delete link more

Comments

Thank you very much! This answer provides a good solution both to my general question and a simple solution to my specific problem (since in my case I'm really just dealing with a scalar linear function of one set of variables with coefficients depending on another set of variables).

Zorgoth gravatar imageZorgoth ( 2014-07-15 18:25:12 +0100 )edit

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: 2014-07-14 05:58:46 +0100

Seen: 423 times

Last updated: Jul 14 '14