Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It can be simplified to sum( c*ddfor dd, c in P.dict().items() if sum(dd) <= N ).

It can be simplified to sum( c*ddfor c*dd for dd, c in P.dict().items() if sum(dd) <= N ).

It can be simplified to sum( c*dd for dd, c in P.dict().items() P if sum(dd) <= N ).

It can be simplified to sum( c*dd for dd, c c,t in P if sum(dd) <= t.degree().<= N ).

It can be simplified to sum( c*dd c*t for c,t in P if t.degree().<= N ).

It can be simplified to sum( c*t for c,t in P if t.degree().<= t.degree() <= N ).

It Here is a condensed version of @slelievre's answer.

We can be simplified to iterate over the dictionary items for sum( c*t P in a simpler way.

For example:

 sage: sum((c*t for c,t c, t in P if t.degree() <= N )N), P.parent().zero())
.

Note how we start the sum at the zero polynomial.

With this, the zero polynomial is truncated to itself rather than to the integer zero.

Here is a condensed version of @slelievre's answer.

We can iterate over the dictionary items for P in a simpler way.

For example:

 sage: sum((c*t for c, t in P if t.degree() <= N), P.parent().zero())

Note how we start the sum at the zero polynomial.

With this, polynomials without terms of degree <= N give the zero polynomial is truncated to itself rather than to polynomial, not the integer zero.