I was not very fond for defining sympy Add, Mul, Pow or Function application for equation object because I don't think that the algebra of equation looks well unifiable with other mathematical objects like Expr at the first glance, And I think that it's important to introduce Add, Mul, Pow, or function application for Expr or at least the mathematical objects that are conceptually unifiable with Expr. We automatically arrive to a conclusion that we need to define unevaluated sympy functions like `Add(eq1, eq2, evaluate=False)`, `sin(eq, evaluate=False)`, once we define how to define function application for them.
And we would also arrive in questions like: If equation brings its own algebra system, there should be an equation of equations? How should we solve them? On Sunday, February 7, 2021 at 8:29:58 PM UTC+9 Oscar wrote: > On Sun, 7 Feb 2021 at 00:07, David Bailey <da...@dbailey.co.uk> wrote: > > > > Dear Group, > > > > While thinking about Jonathon's question, I came across this oddity: > > > > x=symbols('x') > > > > f=symbols('f',cls=Function) > > > > diff(f,x) > > > > 1 > > > > Why 1? I think I would have expected it to generate a TypeError, just > like f+x does. > > The problem is that an undefined function like f is actually a class. > An object like f(x) is an instance of that class. When you do diff(f, > x) that calls through to f.diff(x). The f class has a diff method but > it is supposed to be called with an instance. Instead if you just call > f.diff(x) then the diff method is called with x as the instance so > what you get is equivalent to x.diff() which is treated as x.diff(x) > which gives 1. > > It's like this: > > In [10]: class MyExpr(Expr): > ...: def diff(self, *symbols): > ...: print('self =', self) > ...: print('symbols =', symbols) > ...: > > In [11]: diff(MyExpr, x) > self = x > symbols = () > > In [12]: diff(MyExpr(y), x) > self = MyExpr(y) > symbols = (x,) > > Ideally we should change it so that an undefined function like f is a > Basic instance rather than a Basic subclass. > > > Oscar > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/ded48de3-2f27-4698-928f-8841f39ac3a6n%40googlegroups.com.