distinguishing own from intrinsic functions

27 views
Skip to first unread message

Nico

unread,
Apr 13, 2016, 8:35:08 AM4/13/16
to sympy
To get all function from an expression, one can do
```
from sympy import *

f = Function('f')
x = Symbol('x')
y = f(x) + 2 * sin(x)

for fun in y.atoms(Function):
    print(fun.func)
```
which in this case will print out `f` and `sin`.

I would now like to distinguish between function that I defined myself (`f`) the ones that come from elsewhere. I though about subclassing `sympy.Function`, but apparently it's not exactly meant to be used that way [1].

Any hints?

Cheers,
Nico


Nico Schlömer

unread,
Apr 13, 2016, 9:58:49 AM4/13/16
to sympy
I guess one thing I could do is taint the function class object as
```
f = Function('f')
f.my_custom_function = True
```

Aaron Meurer

unread,
Apr 13, 2016, 1:08:37 PM4/13/16
to sy...@googlegroups.com
sympy.Function is absolutely designed to be subclassed.

If f = Function('f'), then f is a subclass of UndefinedFunction, and
f(x) is an instance of AppliedUndef (both can be imported from
sympy.core.function). You can find custom functions with
y.atoms(AppliedUndef).

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/4c4c052e-7b95-4661-9356-b21fc0a271b0%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nico Schlömer

unread,
Apr 14, 2016, 2:52:55 AM4/14/16
to sympy
Thanks!
Reply all
Reply to author
Forward
0 new messages