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

MatrixElement has None for is_commutative #9391

Closed
cbm755 opened this issue May 9, 2015 · 4 comments
Closed

MatrixElement has None for is_commutative #9391

cbm755 opened this issue May 9, 2015 · 4 comments

Comments

@cbm755
Copy link
Contributor

cbm755 commented May 9, 2015

Is this ok? Symbol's are forbidden from having unknown commutativity. But I'm not sure whether this is ok for other objects/exprs.

This comes out of a discussion in #9364.

@kshitij10496
Copy link
Member

Doesn't #9364 close this ?

@cbm755
Copy link
Contributor Author

cbm755 commented Jan 18, 2016

@kshitij10496 I don't think so. I filed this issue so we didn't lose the discussion from #9364.

To refresh my memory, I tried:

In [31]: M = MatrixSymbol('M', 3, 3)

In [32]: A = M[0,0]

In [33]: srepr(A)
Out[33]: "MatrixElement(MatrixSymbol('M', Integer(3), Integer(3)), Integer(0), Integer(0))"

In [34]: A.is_commutative

Note the element of the Matrix has unknown commutativity. IIRC, this issue just asks if this is ok or not.

Whereas:

In [35]: x = Symbol("x", commutative=None)

--------- 8< --------------------------------------------------------

ValueError: Symbol commutativity must be True or False.

Thanks for the nudge to clarify this a bit!

@asmeurer
Copy link
Member

asmeurer commented May 9, 2016

commutative is a weird assumption. In my opinion, it shouldn't be part of the assumptions system.

For most assumptions, None, basically means, "don't simplify this expression, using facts that would require knowledge of this assumption." For instance, if x.is_positive is None, then sqrt(x**2) doesn't get simplified. If x.is_positive is True or False, it does get simplified (to x or -x, respectively).

For commutative, though, False acts like None, because it avoids simplification. x*y - y*x doesn't simplify to 0 if x and y have is_commutative = False. There's no simplification that is made for is_commutative=False and not is_commutative=None. You might expect this to say something stronger, namely, that x*y - y*x is not 0 if is_commutative=False, and it could be 0 if is_commutative=None, but no current code is written this way, and it would be very difficult to do that, because the commutative assumption doesn't reference any other variables or expressions. Saying that a non-commutative expression doesn't commute with any other non-commutative expression is mathematically wrong, but OK for the purposes of just avoiding incorrect simplifications. This is why it doesn't belong in the assumptions system. It works in a fundamentally different way from every other assumption, and the lack of rigor around it makes it difficult to use with deduction systems.

As a result, is_commutative=None should really not be used anywhere. To further complicate things, commutative is the only assumption that defaults to True for Symbol (all other assumptions default to None). A lot of the core implicitly assumes that it is either True or False (and explicit checks against None would be pointless anyway, since commutative=None would effectively be the same as commutative=False, preventing simplification).

For matrices, it is possible to have matrices of non-commutative symbols. I don't know if our current matrix algorithms do the right thing here, but it is possible. Even so, the default for MatrixElement ought to be True, just like with Symbol. If you really want noncommutative matrix elements (which, again, I don't even know if they would give the right answers), you should have to set some flag when creating the MatrixSymbol, like MatrixSymbol(commutative_elements=False) or something.

@asmeurer
Copy link
Member

Fixed by #11084

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

3 participants