Ask Your Question

# manipulation of multivariate polynomial

Hello, I have an expression that comes from expanding a product of polynomials in one variable each. For demonstration purposes I'm using the Symbolic Ring but the question is not specific to it:

sage: var('a,b')
(a, b)
sage: ex=(1+a+a^2+a^3)*(1+b+b^2+b^3)
sage: ex.expand()
a^3*b^3 + a^3*b^2 + a^2*b^3 + a^3*b + a^2*b^2 + a*b^3 + a^3 + a^2*b + a*b^2 + b^3 + a^2 + a*b + b^2 + a + b + 1


Is there a nice way to get a new expression from that which has only exponents <=3 when a and b are seen as identical? The above product would then yield:

a^3 + a^2*b + a*b^2 + b^3 + a^2 + a*b + b^2 + a + b + 1


that is, for example a*b^3 is removed because it has combined exponent 4.

I'm looking for a way to achieve this without writing a loop that goes through all terms.

edit retag close merge delete

## 2 Answers

Sort by » oldest newest most voted

I meanwhile found that in the ring of multivariate power series the above product can be truncated using bigoh with two arguments:

sage: R.<a,b> = PowerSeriesRing(QQ); R
Multivariate Power Series Ring in a, b over Rational Field
sage: (1+a+a^2+a^3)*(1+b+b^2+b^3)+O(a,b)^4
1 + a + b + a^2 + a*b + b^2 + a^3 + a^2*b + a*b^2 + b^3 + O(a, b)^4

more

## Comments

I think (but am not sure) that both the big-O and .mod use a loop over terms internally, but it sounds like that's ok with you.

I have a loop but not through the terms

sage: R.<a,b> = ZZ[]
sage: f=(1+a+a^2+a^3)*(1+b+b^2+b^3)
sage: f.mod([a^i*b^(4-i) for i in xrange(5)])
a^3 + a^2*b + a*b^2 + b^3 + a^2 + a*b + b^2 + a + b + 1


Vincent

more

## Your Answer

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

Add Answer

## Stats

Asked: 2014-07-01 17:18:06 +0200

Seen: 317 times

Last updated: Jul 02 '14