@ for composition

40 views
Skip to first unread message

Christophe Bal

unread,
Oct 4, 2015, 1:23:56 PM10/4/15
to sympy-list

Hello.

The new operator @ could be usez to define composition of two functions : g@f(x) = g(f(x)).

Bad or good idea ?

Aaron Meurer

unread,
Oct 4, 2015, 1:30:43 PM10/4/15
to sy...@googlegroups.com
There's no precedence for it as far as I know. The operator was only
designed for matrix multiplication (which, by the way, we ought to
implement it for Matrix).

There is a technical challenge in that functions in SymPy are
typically classes, meaning the operator would have to be defined on
the metaclass. We've been trying to get rid of our metaclasses because
they can slow things down and they make the code more confusing. I
believe it is doable, though.

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/CAAb4jGknd6%3DbxKZuUGsTp4d6Howwe5dOzAX4p6p%3DBTX488D4CQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Christophe Bal

unread,
Oct 4, 2015, 1:55:01 PM10/4/15
to sympy-list

Francesco Bonazzi

unread,
Oct 4, 2015, 4:12:31 PM10/4/15
to sympy
On Sunday, 4 October 2015 19:30:43 UTC+2, Aaron Meurer wrote:
> There's no precedence for it as far as I know. The operator was only
> designed for matrix multiplication (which, by the way, we ought to
> implement it for Matrix).


Mathematica uses it for function composition.


> There is a technical challenge in that functions in SymPy are
> typically classes, meaning the operator would have to be defined on
> the metaclass. We've been trying to get rid of our metaclasses because
> they can slow things down and they make the code more confusing. I
> believe it is doable, though.
>

Maybe we need two classes: function (no arguments specified) and function with args.

Aaron Meurer

unread,
Oct 4, 2015, 4:26:44 PM10/4/15
to sy...@googlegroups.com
On Sun, Oct 4, 2015 at 3:12 PM, Francesco Bonazzi
<franz....@gmail.com> wrote:
> On Sunday, 4 October 2015 19:30:43 UTC+2, Aaron Meurer wrote:
>> There's no precedence for it as far as I know. The operator was only
>> designed for matrix multiplication (which, by the way, we ought to
>> implement it for Matrix).
>
>
> Mathematica uses it for function composition.

But we have to match the Python conventions, not the Mathematica ones.
For instance, @ has the same precedence as * and is left associative,
and this can't be changed.

>
>
>> There is a technical challenge in that functions in SymPy are
>> typically classes, meaning the operator would have to be defined on
>> the metaclass. We've been trying to get rid of our metaclasses because
>> they can slow things down and they make the code more confusing. I
>> believe it is doable, though.
>>
>
> Maybe we need two classes: function (no arguments specified) and function with args.

Having functions be objects has been a long standing issue
(https://github.com/sympy/sympy/issues/4787). I think it's doable, but
it would break any code that makes incorrect assumptions about the
relationship between an expression, its function, and its class (for
instance, using type(expr) or expr.__class__ instead of expr.func to
rebuild the expression).

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/00e21857-ff99-4a63-94f2-b8264a16abe1%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages