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

`MatMul(2, Matrix(...)).doit()` doesn't do it #9053

Open
cbm755 opened this Issue Feb 26, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@cbm755
Copy link
Contributor

cbm755 commented Feb 26, 2015

X = Matrix([[1, 2], [3, 4]])
assert MatMul(2, X).doit() == 2*X

needs fix to canonicalize bits?

@cbm755

This comment has been minimized.

Copy link
Contributor

cbm755 commented Feb 26, 2015

Bit more info:

X = ImmutableMatrix([[1, 2], [3, 4]])
w = MatMul(2, X)
w.doit()                                  # doesn't do it

Out[51]: 
2*Matrix([
[1, 2],
[3, 4]])

q = MatAdd(X, MatMul(2, X))
q.doit()                                   # does do it

Out[52]: 
Matrix([
[3,  6],
[9, 12]])

Looking at the steps taken by the code, it seems to be the canonicalize routine of MatAdd that does this latter result. Whereas MatMul's canonicalize apparently cannot.

@kevinventullo

This comment has been minimized.

Copy link
Contributor

kevinventullo commented Feb 26, 2015

MatAdd's canonicalize uses glom(matrix_of, factor_of, combine). The combine functions takes the object MatMul(2,X), pulls apart its arguments 2 and X, then combines them as 2*X. The difference being that 2*X returns [[2,4],[6,8]] rather than a MatMul.

Anyway, I think adding a similar glom to the rules in MatMul should fix this. I'll issue a PR in the morning if no one else has.

@cbm755

This comment has been minimized.

Copy link
Contributor

cbm755 commented Feb 26, 2015

Sounds good to me. There is an XFAIL test in #9031.

cbm755 added a commit to cbm755/sympy that referenced this issue Jun 10, 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