Issue 2696 in sympy: Assumptions fail for non-commutative symbols

2 views
Skip to first unread message

sy...@googlecode.com

unread,
Sep 20, 2011, 1:12:39 PM9/20/11
to sympy-...@googlegroups.com
Status: Accepted
Owner: MRock...@gmail.com
Labels: Type-Defect Priority-Medium WrongResult

New issue 2696 by MRock...@gmail.com: Assumptions fail for non-commutative
symbols
http://code.google.com/p/sympy/issues/detail?id=2696

In [1]: x = Symbol('x', commutative=False)

In [2]: x.is_irrational

In [3]: (-x).is_irrational
Out[3]: False

The Mul._eval_is_irrational method has correct behavior. I suspect this is
an issue with the new assumptions

sy...@googlecode.com

unread,
Sep 20, 2011, 7:04:18 PM9/20/11
to sympy-...@googlegroups.com
Updates:
Labels: Assumptions

Comment #1 on issue 2696 by asmeurer: Assumptions fail for non-commutative
symbols
http://code.google.com/p/sympy/issues/detail?id=2696

The new assumptions seem to handle it correctly:

In [1]: x = Symbol('x', commutative=False)

In [2]: print ask(Q.irrational(-x))
None


sy...@googlecode.com

unread,
Sep 23, 2011, 12:39:53 AM9/23/11
to sympy-...@googlegroups.com

Comment #2 on issue 2696 by smi...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

in facts.py it says


rules: {} of a -> [b, c, ...]
return: {} of c <- [a, b, ...]

Note however, that this prerequisites may be *not* enough to prove a
fact. An example is 'a -> b' rule, where prereq(a) is b, and
prereq(b)
is a. That's because a=T -> b=T, and b=F -> a=F, but a=F -> b=?

The prereqs traversed for is_irrational (after obtianing a correct None
from Mul.is_irrational) are integer, even, odd, all of which are False. The
conclusion returned is False. So perhaps the above applies?

sy...@googlecode.com

unread,
Sep 23, 2011, 1:06:34 PM9/23/11
to sympy-...@googlegroups.com

Comment #3 on issue 2696 by asmeurer: Assumptions fail for non-commutative
symbols
http://code.google.com/p/sympy/issues/detail?id=2696

The result should be None then. To put it in the perspective of the
comment from facts.py, ? should equal None.

sy...@googlecode.com

unread,
Sep 23, 2011, 8:00:27 PM9/23/11
to sympy-...@googlegroups.com

Comment #4 on issue 2696 by Ronan.L...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

irrational implies real, which implies complex, which implies commutative,
so x.is_irrational should return False.

The new assumptions aren't involved here.

sy...@googlecode.com

unread,
Sep 23, 2011, 11:13:33 PM9/23/11
to sympy-...@googlegroups.com

Comment #5 on issue 2696 by Ronan.L...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

The problem is that 'commutative' is special-cased in Symbol, which
prevents it from being handled correctly by the assumption system (this was
briefly discussed in issue 2446). I think that the solution is to remove
this special-casing.

sy...@googlecode.com

unread,
Sep 24, 2011, 1:22:03 PM9/24/11
to sympy-...@googlegroups.com

Comment #6 on issue 2696 by asmeurer: Assumptions fail for non-commutative
symbols
http://code.google.com/p/sympy/issues/detail?id=2696

Ah, I see. noncommutative implies not complex. So this is correct.
Should this be closed then?

By the way, I seem to remember discussing this before, but is it a good
idea to make irrational imply real? This way, irrational != not rational,
which is somewhat confusing. I suppose it might seem strange to say that a
number like I is irrational, but I think it technically fits with the
definition (cannot be written as the quotient of integers).

sy...@googlecode.com

unread,
Sep 24, 2011, 1:58:16 PM9/24/11
to sympy-...@googlegroups.com

Comment #7 on issue 2696 by Ronan.L...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

There's still the issue of x.is_irrational returning None instead of False,
and also the fact that inconsistent assumptions are allowed, like
Symbol('x', real=True, commutative=False).

Concerning is_irrational, I think that this kind of negative assumption is
more confusing than helpful. Testing for not rational is easy: 'if not
x.is_rational: ...' so rather than making irrational == not rational, it
would be simpler to remove it altogether.

sy...@googlecode.com

unread,
Sep 24, 2011, 3:16:42 PM9/24/11
to sympy-...@googlegroups.com

Comment #8 on issue 2696 by Ronan.L...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

I sent a PR implementing the idea from comment 5.
https://github.com/sympy/sympy/pull/618

sy...@googlecode.com

unread,
Mar 5, 2012, 11:05:51 AM3/5/12
to sympy-...@googlegroups.com

Comment #10 on issue 2696 by julien.r...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

About Symbol('x', real=True, commutative=False): I though that would be a
symbol representing e.g. a real-valued matrix.

sy...@googlecode.com

unread,
Mar 5, 2012, 6:11:15 PM3/5/12
to sympy-...@googlegroups.com

Comment #11 on issue 2696 by asme...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

I would use MatrixSymbol for that. The way our assumptions deductions
work, real implies things that are only true for real numbers
(commutativity being one of them).

sy...@googlecode.com

unread,
Mar 6, 2012, 11:20:47 AM3/6/12
to sympy-...@googlegroups.com

Comment #12 on issue 2696 by julien.r...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

Well, that's one example. It could also represent a differential operator.
Anyway, I always took this real=True assumption to mean conjugate(x)==x and
nothing else. I would be interested to know, where in the code does real
imply commutative.

MatrixSymbol looks like a relatively recent addition. Maybe I ought to use
that, as you say, but up to now I never needed anything else then Symbol. I
can't seem to assume conjugate(x)==x when I use MatrixSymbol.

sy...@googlecode.com

unread,
Mar 6, 2012, 2:38:16 PM3/6/12
to sympy-...@googlegroups.com

Comment #13 on issue 2696 by asme...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

> I would be interested to know, where in the code does real imply
> commutative.

Well, where this bug manifests itself for one thing :)

This sort of thing is tricky, because a lot of it is just implicit
assumptions about how things work. That's why we should really fix issue
2196.

Another thing that is assumed by real=True is comparable=True. In other
words, it is assumed that you have a < b, a > b or a == b for any two real
a and b. This is only true if a and b are real numbers (not matrices or
operators or anything).

I suppose could consider Hermitian operators to be "real", since they act
very similarly to real numbers in most contexts. In many cases, you could
probably get sympy to do what you want for such an operator by using a
Symbol that is assumed to be real.

MatrixSymbol is still relatively new, so there are many things that aren't
implemented yet. Feel free to open issues as you see fit.

sy...@googlecode.com

unread,
Mar 15, 2012, 2:04:21 PM3/15/12
to sympy-...@googlegroups.com

Comment #14 on issue 2696 by julien.r...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

MatrixSymbol has many problems at first glance (issue 3150). Since I can no
longer have Symbols assumed real and noncommutative, I've opened issue 3151
to have an Hermitian assumption.

sy...@googlecode.com

unread,
Mar 20, 2012, 11:41:48 AM3/20/12
to sympy-...@googlegroups.com
Updates:
Status: Fixed

Comment #16 on issue 2696 by julien.r...@gmail.com: Assumptions fail for
non-commutative symbols
http://code.google.com/p/sympy/issues/detail?id=2696

The pull request has been committed but the issue tracker wasn't updated:

commit 09409374fb9d5e468a0dd771f145c884f86ba472
Merge: d26aadc 6a357cf
Author: Christopher Smith <smi...@gmail.com>
Date: Wed Mar 14 19:20:39 2012 -0700

Merge pull request #1116 from smichr/commut

Symbol commutativity patches


And indeed this is fixed:

In [1]: from sympy import *

In [2]: x=Symbol('x', commutative=False)

In [3]: x.is_irrational
Out[3]: False

In [4]: (-x).is_irrational
Out[4]: False


Reply all
Reply to author
Forward
0 new messages