Ask Your Question
0

Multivariate polynomials again: specifying variables

asked 11 years ago

Alasdair gravatar image

I'm back looking at multivariate polynomials, with which I was last experimenting about six months ago. Suppose I have a polynomial in four variables x,y,z,w. What I need to do is:

  1. Rewrite the polynomial in terms of two of the variables (say x, y), to obtain something like Ax^2y+Bxy+Cxy^3+Dx^2y^3, where each of the coefficients A, B, C and D is a polynomial in z and w.
  2. Obtain those polynomials in z and w as a list.

I don't know in advance what powers of x and y will be in the expression, nor do I know how many terms there will be.

I would have thought this would be fairly straightforward, but I can't find an easy way to do it. In Maxima number one can be done with "collectterms", but the Sage method "collect" seems only to work on one variable at a time.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 11 years ago

Luca gravatar image

Symbolics have a method .poly:

sage: var('x,y')
(x, y)
sage: p = x*y + x^2*y^2
sage: p.poly(x)
x^2*y^2 + x*y
sage: p.poly(x).coefficients()
[[y, 1], [y^2, 2]]

Multivariate polynomial rings have a method .polnomial()

sage: A.<x,y> = QQ[]
sage: p = x*y + x^2*y^2
sage: p.polynomial(x)
y^2*x^2 + y*x
sage: p.polynomial(x).list()
[0, y, y^2]

Both methods collect only with respect to one variable, so you may need to iterate.

Preview: (hide)
link

Comments

Thanks for that! I did in fact check out the polynomial method earlier; it seems however to only work on one variable; whereas I want something similar which works on multiple variables simultaneously.

Alasdair gravatar imageAlasdair ( 11 years ago )

I would have said that [c.polynomial(y) for c in p.polynomial(x)] is not too much typing to achieve want you want, but I just tried it and it looks buggy. I'll investigate further.

Luca gravatar imageLuca ( 11 years ago )

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 11 years ago

Seen: 1,273 times

Last updated: Jan 16 '14