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

`trace(2*A) != 2*Trace(A)` because LHS still has an MatMul #9052

Closed
cbm755 opened this Issue Feb 26, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@cbm755
Copy link
Contributor

cbm755 commented Feb 26, 2015

n = Symbol('n', integer=True)
A = MatrixSymbol('A', n, n)
trace(2*A) == 2*Trace(A)    # False
srepr(trace(2*A))   # note 2*Trace(MatMul(A))
@kevinventullo

This comment has been minimized.

Copy link
Contributor

kevinventullo commented Feb 26, 2015

I guess the problem is that 2*A is represented as a MatMul, and in general you can't simplify the trace of a product of two matrices.

Should we have trace check if its argument is a MatMul, and if the first argument of MatMul is a number, take that number times the trace of the rest? Then Trace would be returning a Mul instead of a Trace.

@cbm755

This comment has been minimized.

Copy link
Contributor

cbm755 commented Feb 26, 2015

Currently for , it does correctly pull the 2 out, it just leaves the MatMul behind :) #9031 has an XFAIL test for this. I think _eval_trace of matmul.py needs .doit()

(and yes, trace(MatMul(A, 2, B)) should go to 2*Trace(MatMul(A, B)) of course. #9031 has improves the test of that.)

cbm755 added a commit to cbm755/sympy that referenced this issue Jun 10, 2015

@cbm755 cbm755 closed this in #9061 Jun 11, 2015

skirpichev added a commit to diofant/diofant that referenced this issue Aug 5, 2015

Fixed some problems in matrices
1. added .doit() to _eval_trace
2. modified merge_explicit in MatMul to take scalars into account

Closes sympy/sympy#9052
Closes sympy/sympy#9053

// edited by skirpichev

skirpichev added a commit to diofant/diofant that referenced this issue Aug 13, 2015

Fixed some problems in matrices
1. added .doit() to _eval_trace
2. modified merge_explicit in MatMul to take scalars into account

Closes sympy/sympy#9052
Closes sympy/sympy#9053

// edited by skirpichev

skirpichev added a commit to diofant/diofant that referenced this issue Aug 23, 2015

Fixed some problems in matrices
1. added .doit() to _eval_trace
2. modified merge_explicit in MatMul to take scalars into account

Closes sympy/sympy#9052
Closes sympy/sympy#9053

// edited by skirpichev

skirpichev added a commit to diofant/diofant that referenced this issue Sep 13, 2015

Fixed some problems in matrices
1. added .doit() to _eval_trace
2. modified merge_explicit in MatMul to take scalars into account

Closes sympy/sympy#9052
Closes sympy/sympy#9053

// edited by skirpichev

skirpichev added a commit to diofant/diofant that referenced this issue Sep 28, 2015

Fixed some problems in matrices
1. added .doit() to _eval_trace
2. modified merge_explicit in MatMul to take scalars into account

Closes sympy/sympy#9052
Closes sympy/sympy#9053

// edited by skirpichev

skirpichev added a commit to diofant/diofant that referenced this issue Sep 28, 2015

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