Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derivative is incorrectly set to 0 for some summation expressions. #26561

Open
BodeTobias opened this issue May 3, 2024 · 2 comments
Open

Derivative is incorrectly set to 0 for some summation expressions. #26561

BodeTobias opened this issue May 3, 2024 · 2 comments

Comments

@BodeTobias
Copy link

While experimenting with symbolic derivation by matrices, I came across the following strange behavior. Do I need a special function to sum up two expressions or is it a bug?

Code

import sympy as sym
sym.init_printing()

E = sym.MatrixSymbol('E', 3, 3)

print((sym.Trace(E)**2 + 0).diff(E))
print((sym.Trace(E)**2 + 1).diff(E))

Output

(2*Trace(E))*I
0

@oscarbenjamin
Copy link
Contributor

More simply:

In [7]: E = MatrixSymbol('E', 3, 3)

In [8]: Trace(E).diff(E)
Out[8]: 𝕀

In [9]: (Trace(E) + 1).diff(E)
Out[9]: 𝟘

@sylee957
Copy link
Member

sylee957 commented May 6, 2024

I found some difference in results of Derivative(Trace(E) + 1, E).doit() and ArrayDerivative(Trace(E) + 1, E).doit(), so that may be able to point out some bug in the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants