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

Closed
opened this Issue Feb 26, 2015 · 2 comments

Projects
None yet
2 participants
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))
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.
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.)

Merged

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

Fixed some problems in matrices
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
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
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
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