In the top docstring of core/function, such behavior is proposed. I also found it mentioned in https://github.com/sympy/sympy/issues/5105, which was open 10 years ago... I know that using `rcall` on `Lambda(x,sin(x))+Lambda(x,cos(x))` will do it, but it seems a bit verbose.
I am currently developing modules for fluid mechanics, which are purely dependent on sympy. (Hopefully, I want to contribute it to sympy after I'm finished) In this module, what I plan to is to make 'Operator' class, which is a subclass of Expr. It will have callable sympy class (not instance) as argument. Also, classes such as 'OperAdd' and 'OperMul' will be introduced. For example, it will behave like this: ``` >>> Operator(sin)(x) sin(x) >>> Operator(sin)+Operator(cos) OperAdd(Operator(sin), Operator(cos)) >>> Operator(sin) + cos # This will convert cos to Operator(cos) OperAdd(Operator(sin), Operator(cos)) >>> OperAdd(Operator(sin), Operator(cos))(x) sin(x) + cos(x) >>> 2*Operator(sin) OperMul(2,Operator(sin)) >>> OperMul(2,Operator(sin))(x) 2*sin(x) >>> Operator(sin)(cos) OperComposite(sin, cos) >>> OperComposite(sin, cos)(x) sin(cos(x)) ``` Perhaps, it may also have not-callable Expr instance as argument. ``` >>> Operator(1+x)(y) y + x*y ``` Also, I am planning to make differential operator class, named DiffOp, which is a subclass of Operator. Instead of sympy class, it will have variables which will differentiate the expression. DiffOp(x) will represent d/dx. ``` >>> DiffOp(x)(sin(x)) cos(x) >>> DiffOp(x)(DiffOp(y)) DiffOp(x,y) >>> DiffOp(x) + Operator(sin) + x OperAdd(DiffOp(x), Operator(sin), Operator(x)) >>> (DiffOp(x) + Operator(sin) + x)(x) 1 + sin(x) + x**2 ``` How is it? Will it be OK? -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/sympy/b26e04b9-d137-48ca-b40a-a9b7fdec645d%40googlegroups.com.
