On 13.04.2012 12:57, vweber wrote:
> Dear All
> How is it possible to differentiate between defined(internal) and
> undefined functions?
> For example:
>
> x = symbols('x')
> f = Function('f')(x)
> eq=cos(x)+f
> s=eq.atoms(Function)
>>>> s
> set(f(x), cos(x))
>
> so I would like
>
> for i in s:
> IS_INTERNAL(i) or IS_DEFINED(i) or whatever
>
AppliedUndef may help:
In [1]: x = symbols('x')
In [2]: f = Function('f')(x)
In [3]: eq=cos(x)+f
In [4]: from sympy.core.function import AppliedUndef
In [5]: eq.atoms(AppliedUndef)
Out[5]: set(f(x))
In [6]: isinstance(cos(x), AppliedUndef)
Out[6]: False
In [7]: isinstance(f, AppliedUndef)
Out[7]: True
see also the identical question
https://mail.google.com/mail/u/0/#search/AppliedUndef/13697af357f5cfa3
```
> What is the best way to test if a sympy expression contains a function,
> either a named function such as sin(x) or a general function such as
> f(x,y,z). I would prefer not to differentiate with respect to all possible
> arguments and see if all the results are zero.
>>> eq=f(x)+sin(x)
>>> eq.has(Function) # best way to see if it's there
True
>>> eq.atoms(Function) # use this when you need to know what they are
set([f(x), sin(x)])
f(x) is an instance of AppliedUndef
f is an instance of UndefinedFunction
sin(x) is an instance of Function
sin is an instance of FunctionClass
In retrospect, more symmetry in naming would have been nice, e.g. f(x)
being UndefinedFunc and f being UndefinedFuncClass.
```
(If this is not in the FAQ, it should be.)
/c
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>