It depends if you want op(u) to also be usable in expressions. If you
do, the simplest way is to make op be a Function, and define __call__
on it so that it returns an object representing op(u)(x).
Defining that other object is the tricky part. I think something like
class AppliedOp(Expr):
def __new__(cls, op, x):
obj = Expr.__new__(cls, op, x)
return obj
@property
def func(self):
return self._args[0]
@property
def args(self):
return self._args[1:]
and op is
class op(Function):
def __call__(self, x):
return AppliedOp(self, x)
You'll also want to define some printing methods on AppliedOp so that
it prints as op(u)(x).
Aaron Meurer
On Tue, Apr 5, 2016 at 7:04 AM, Nico <[email protected]> wrote:
> So far, I've always defined functions as
> ```
> class f(sympy.Function):
> pass
> ```
> which I could then conveniently use as
> ```
> x = sympy.Symbol('x')
> y = f(x)
> ```
> Nice.
>
> Now, I would like to define a function that itself returns a function, aka,
> an operator. It should be used as
> ```
> y = op(u)(x)
> ```
> With the naïve definition above, I'm getting
> ```
> TypeError: 'op' object is not callable
> ```
> Any hints?
>
> Cheers,
> Nico
>
> --
> 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/aed8dedf-9b6c-468e-838a-ad56a659ddfe%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%3D6JnwPFnDC0d%2BTLv9%3DhjOSv4aMQhPC6wSeew_%3DfhAXn37Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.