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

Deriving a sum of two matrix norms erroneously returns 0 #26585

Open
sdall opened this issue May 9, 2024 · 0 comments
Open

Deriving a sum of two matrix norms erroneously returns 0 #26585

sdall opened this issue May 9, 2024 · 0 comments

Comments

@sdall
Copy link

sdall commented May 9, 2024

SymPy 1.12 returns an unexpected matrix derivative.

from sympy.core.symbol import symbols
from sympy.matrices.expressions.matexpr import MatrixSymbol
from sympy.matrices.expressions.trace import Trace

m, n, k = symbols("m n k")

A = MatrixSymbol("A", n, m)
U = MatrixSymbol("U", n, k)
V = MatrixSymbol("V", k, m)

def nrm2(e): 
    return Trace(e.T * e)

# works 
(0.5*nrm2(A - U*V)).diff(U) 

# works
0.5*nrm2(A - U*V).diff(U) + 0.5*nrm2(A).diff(U)

# does not work (returns 0)
(0.5*nrm2(A - U*V) + 0.5*nrm2(A)).diff(U)  

# does not work (returns 0) 
(0.5*nrm2(A - U*V) + 0.5*nrm2(U)).diff(U)  
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

2 participants