Hi,

On 23 October 2010 09:52, smichr <[email protected]> wrote:

> > Does anyone have any idea how match() works in sympy?
> > And suggestions on implementing the function to pick up a non-
> > polynomial term from an expression is welcomed.
>
> Yes to both. I wrote up my notes when trying to understand what was
> going on here in Issue 1601:
>
> http://code.google.com/p/sympy/issues/detail?id=1601
>
> As far as the second goes, you can use the method .as_poly() to see if
> a given term of an Add can be made into a polynomial or not to answer
> the question. Is this what you want (to identify polynomial terms in
> x):
>
> h[3] >>> eq=x**2+(x+1)*(2+x)+exp(x)*(1+x)
> h[3] >>> [a for a in eq.as_Add() if a.as_poly(x)]
> [(1 + x)*(2 + x), x**2]
>

Hint: this code may be fragile (e.g. issues like zero equivalence of terms),
so better use:

[ a for a in eq.as_Add() if a.is_polynomial(x) ]

It should be also way faster.


> /chris
>
> --
> 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] <sympy%[email protected]>.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
>
Mateusz

-- 
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