deriving from sympy.Function: object not callable

191 views
Skip to first unread message

Nico

unread,
Jul 16, 2015, 3:53:17 AM7/16/15
to sy...@googlegroups.com
Following up on question [1], I'm wondering how one can derive from sympy.Function in a way that keeps all the original functionality in place. Something as naive as
```
import sympy

x = sympy.Symbol('x')

a = sympy.Function('a')
a(x)  # no problem

class MyTest(sympy.Function):
    pass
b = MyTest('b')
b(x)  # object is not callable
```
doesn't work: `b` is reported not to be callable here.

Any hints why this might be and how to fix it?

Cheers,
Nico


Nico

unread,
Jul 16, 2015, 5:31:15 AM7/16/15
to sy...@googlegroups.com
Got it:
As outlined in [1], what is mathematically perceived as a "function" is a class in terms of sympy, not an instance thereof.

--Nico


Aaron Meurer

unread,
Jul 16, 2015, 11:29:17 AM7/16/15
to sy...@googlegroups.com
Yes, unfortunately, Function acts differently when subclassed. 

What you want to do, I believe, is create a custom subclass of Function with the metaclass UndefinedFunction.  It's worth taking a look at the source code of Function to see how it works.

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 http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/57e9ce21-26d0-4bee-a505-7480ed4fd506%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages