Ask Your Question

Multivariate polynomials again: specifying variables

asked 2014-01-16 18:13:53 +0200

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-01-16 20:35:56 +0200

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.

edit flag offensive delete link more


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 ( 2014-01-16 21:32:23 +0200 )edit

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 ( 2014-01-18 06:35:58 +0200 )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



Asked: 2014-01-16 18:13:53 +0200

Seen: 864 times

Last updated: Jan 16 '14