On Tue, Jul 24, 2012 at 3:25 AM, Aaron Meurer <[email protected]> wrote:

> On Thu, Jun 21, 2012 at 3:17 PM, Chris Smith <[email protected]> wrote:
> > On Thu, Jun 21, 2012 at 3:34 PM, Aaron Meurer <[email protected]>
> wrote:
> >> I don't think there's an efficient function to do it, if that's what
> you're
> >> looking for (i.e., one that doesn't require full expansion). It's not
> too
> >> hard to come up with, though.
> >
> > (I gave up when I started chasing the recursion rabbit...I don't think
> > it's a trivial problem to handle it in a general way.)
>
> You don't have to do it recursively. You just want the terms such that
> k + m = N.  Poly.monoms() gives all the monomials, ordered
> lexicographically (i.e., by total degree).
>
> For example, if the monomials for your polys are [5, 4, 3, 2, 1, 0]
> and [4, 2, 1] (say you have x**5 + 2*x**4 - x**3 + x**2 - 2*x + 1 and
> x**4 - x**2 + x), and you want the term in the product of degree 5,
> then you just need to pair up (5, 0), (4, 1), (3, 2), (2, 3), (1, 4),
> and (0, 5).  In this case, only (4, 1), (3, 2), and (1, 4) are
> non-zero, so the result is -2*1 + -1*-1 + 1*1 = 1.  This can easily be
> generalized to multivariate polynomials and total degree.  You just
> sum each term from monoms(), and be sure to catch all terms of
> whatever degree you are looking for.
>
>
By general, I meant things like `(x + (x**2 + 2*x - 7)**3)**5`

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to