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

Matrix power of identity matrix fails #9823

Open
Bonnevie opened this Issue Aug 13, 2015 · 5 comments

Comments

Projects
None yet
4 participants
@Bonnevie
Copy link

Bonnevie commented Aug 13, 2015

This seems very wrong to me: taking the identity matrix to the power of 2 yields the matrix of all zeros.

In [1]: import sympy as s

In [2]: M = s.Identity(3)

In [3]: A = (M**2)

In [4]: A.as_explicit()
Out[4]: 
Matrix([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])

calculating I*I explicitly yields the correct result.

@oliverlee

This comment has been minimized.

Copy link
Contributor

oliverlee commented Aug 13, 2015

Looks like __pow__ isn't defined for the Identity class.

@jksuom

This comment has been minimized.

Copy link
Member

jksuom commented Aug 13, 2015

__pow__ is defined for the Identity class, but it returns a MatPow object that is not explicitly evaluated. Matrix multiplication works fine.

>>> M = Identity(3)
>>> A = M*M
>>> A.as_explicit()
Matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
@oliverlee

This comment has been minimized.

Copy link
Contributor

oliverlee commented Aug 13, 2015

Are you looking at the right branch? It isn't defined for me.

@oliverlee

This comment has been minimized.

Copy link
Contributor

oliverlee commented Aug 17, 2015

This also happens for ZeroMatrix with MatPow as it only handles instances of MatrixBase.

In [1]: from sympy import MatPow, ZeroMatrix

In [2]: M = ZeroMatrix(3, 3)

In [3]: M**3 == M
Out[3]: True

In [4]: MatPow(M, 3) == M
Out[4]: False
@kevalds51

This comment has been minimized.

Copy link
Contributor

kevalds51 commented Aug 18, 2015

according to me it would be better to have separate conditions for ZeroMatrix and Identity matrix, this can be very easily evaluated using the predefined boolean variables such as isIdentity and is_ZeroMatrix. This would also reduce a lot of computation in case of large matrices.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Aug 19, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith ZeroMatrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Aug 20, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith ZeroMatrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Aug 20, 2015

@kevalds51
Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug with Zero Matrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Aug 20, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith Zero Matrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 7, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 7, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 7, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 7, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith ZeroMatrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 7, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith ZeroMatrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 7, 2015

@kevalds51
Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug with Zero Matrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 7, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith Zero Matrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 8, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 8, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 8, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 8, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith ZeroMatrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 8, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith ZeroMatrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 8, 2015

@kevalds51
Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug with Zero Matrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 8, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith Zero Matrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 9, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 9, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 9, 2015

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 9, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith ZeroMatrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 9, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith ZeroMatrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 9, 2015

@kevalds51
Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug with Zero Matrix too as requested, alongwith proper test cases.

kevalds51 added a commit to kevalds51/sympy that referenced this issue Oct 9, 2015

Re: Matrix power of identity matrix fails sympy#9823. Fixed the bug w…
…ith Zero Matrix too as requested, alongwith proper test cases.

asmeurer added a commit that referenced this issue Nov 4, 2015

Merge pull request #9978 from kevalds51/old_commit
Bug Fixed: Matrix power of identity matrix fails [Issue #9823]

skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 27, 2016

skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 16, 2016

Fix matrix power of identity/zero matrices
Closes sympy/sympy#9823

Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>

skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 17, 2016

Fix matrix power of identity/zero matrices
Closes sympy/sympy#9823

Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment