Function is a bit confusing, because Function('f') creates a subclass
called f, but this property is not inherited when you inherit from
Function. So your object just works likeDouble(2) Also, your overriding of __new__ and __init__ is unnecessary, since they don't do anything (and in general, anything you'd want to do in those methods for subclasses of Function you should do in eval()). Aaron Meurer On Thu, Jul 28, 2016 at 7:37 AM, Felipe Vieira <[email protected]> wrote: > He all, > > I've read the posts. And the tutorial. And the code. > > Still I'm having trouble defining my own functions. > > Let's start with the very basics: I would like to define f(x) = 2 * x: > > from sympy import * > from sympy.abc import x, y > import sympy > > class Double(Function): > u"""A simple function that doubles the input.""" > > @classmethod > def eval(cls, arg): > return None > > def fdiff(self, argindex = 1): > return Integer(2) * self.args[0] > > def __new__(cls, *args, **kwargs): > return super(Double, cls).__new__(cls, *args, **kwargs) > > def __init__(self, *args, **kwargs): > super(Double, self).__init__() > > d = Double('d') > > d(2) > > When I run the code I get: > TypeError: 'Double' object is not callable > > > How can I pythonically/sympythonically define a Double inheriting from > function? Notice that this is just a first step in defining more 'complex' > functions (so don't tell me to use Lambda). > > Grea work with the project! Thank you! > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > 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/7cdffc27-8187-43af-a6be-68b15fbe9197%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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 [email protected]. To post to this group, send email to [email protected]. 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/CAKgW%3D6LDtvbT3pCAsPP_FvBeE8QSMwKH89FnrQB%2Be7k5XyQSMQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
