On Jul 16, 6:48 pm, Toon Verstraelen <toon.verstrae...@ugent.be>
wrote:
> Christophe wrote:
> > Hello,
> > suppose that we have the following expression :
> >             (x**2+1)*(log(x+4)-7)
>
> > I would like to know that is a product and to have :
> >              (x**2+1) and (log(x+4)-7).
>

In terms of equations, there are 4 main types that I tend to think
about: those involving addition, multiplication or division,
functions, and powers. You have to ask sympy what you have, so if you
have something named eq and you don't know what it is (but in this
example you will see that it is your function) you use the is_*
methods.

###
>>> eq.is_Add
False
>>> eq.is_Mul
True
###


Now that you know it involves terms multiplied together, you can ask
for the terms with 'args':

###
>>> eq.args
(-1, 1 + x**2, 7 - log(4 + x))
###

So sympy sees eq as being a product of 3 terms. If you want, you could
look at the individual terms, looking for the function, but it is
easier to just ask for the Function-type atoms of the equation; the
atoms(Function) method will only scan at what you call "the first
level" (but atoms() with no argument will scan deeper for all numbers
and symbols that appear):

###
>>> eq.atoms(Function)
set([log(4 + x)])
>>> (log(sin(x)+2)).atoms()
set([2, x])
>>> (log(sin(x)+2)).atoms(Function)
set([log(2 + sin(x))]) #there is only 1 element in the set, a log
(with its arguments)
>>>

Hope that helps,
/chris

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

Reply via email to