Thanks, "make_list" works!

Now my code becomes

y = x0 * x1 * exp(40*x0)
non_poly_terms = [a for a in make_list(y, Add) if (not a.is_polynomial())]
print non_poly_terms     # [x0*x1*exp(40*x0)]
non_poly_terms = [a for a in make_list(non_poly_terms[0], Mul) if (not
a.is_polynomial())]
print non_poly_terms     # [exp(40*x0)]

The results seem to be correct.

Chenjie

On Sat, Oct 23, 2010 at 1:28 AM, Mateusz Paprocki <[email protected]> wrote:

> Hi,
>
> On 23 October 2010 10:22, Chenjie Gu <[email protected]> wrote:
>
>> Thanks a lot for the reply. I'll read the match algorithm later.
>>
>> But for the script you gave, it seems that in my version of sympy, there's
>> no function called "as_Add()".
>> I am using sympy 0.6.7. Are you using a higher version of sympy?
>>
>
> If there is no as_Add() (possibly it was added after last release), then
> use:
>
> In [1]: make_list(1 + x, Add)
> Out[1]: [1, x]
>
>
>>
>> Chenjie
>>
>>
>> On Sat, Oct 23, 2010 at 1:06 AM, smichr <[email protected]> wrote:
>>
>>> ...and if you only want terms that acutally have x then also use the
>>> method .has():
>>>
>>>
>>> h[1] >>> [a for a in (1+x).as_Add() if a.is_polynomial(x)]
>>> [1, x]
>>> h[2] >>> [a for a in (1+x).as_Add() if a.has(x) and
>>> a.is_polynomial(x)]
>>> [x]
>>> h[3] >>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> /c
>>>
>>> --
>>> 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.
>>>
>>>
>>  --
>> 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] <sympy%[email protected]>.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>

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