This is a bug (I noted it at https://github.com/sympy/sympy/issues/6225).

The problem is that if someone writes an algorithm without explicitly
checking for noncommutatives, it is easy to get a wrong result. It's
difficult to guard against this in a universal way because often the
assumption is implicit. There are a dozen different ways this could happen.
For example, code might assume that (a*b)**n = a**n*b**n, or it might
assume that (a + b)**2 = a**2 + 2*a*b + b**2.

So in many cases there are some issues with noncommutatives, especially
since they are not used as often as normal commutative expressions. But as
we find more and more of them, we fix them and add tests for them, so they
can't be broken again.

Aaron Meurer

On Fri, Sep 8, 2017 at 10:11 AM, Valeriia Gladkova <
[email protected]> wrote:

> Yes, there are other problems with non-commutative things, like
> https://github.com/sympy/sympy/issues/12576#issuecomment-308384814 or
> https://github.com/sympy/sympy/issues/12258. It feels like
> non-commutative symbols weren't originally planned and when they were
> introduced, not all of the existing algorithms were changed to account for
> them. Or maybe the reason is that when those algorithms were being written,
> the authors forgot about non-commutativity. Hard to say, but something
> should be done about it. Could you open an issue if you haven't already
> done so?
>
>
> On Monday, 4 September 2017 18:25:10 UTC+3, ric wrote:
>>
>> Hello
>>
>> I'm playing with SympyLive and it seems to me that the commutative=False
>> assumption is not honored by some functions, resulting in wrong results.
>>
>> Example: When A and b are non-commuting symbols
>>
>> factor(A**2+B**2+2*A*B) gives (A+B)**2 but it should do nothing i.e.
>> A**2+B**2+2*A*B
>>
>> and itermonomials should give also the B*A monomial. Or at list they
>> should refuse to answer when some variables are not commuting.
>>
>> Hope this helps
>> ric
>>
>> #############################
>> Python console for SymPy 1.0 (Python 2.7.12)
>>
>> These commands were executed:
>> >>> from __future__ import division
>> >>> from sympy import *
>> >>> x, y, z, t = symbols('x y z t')
>> >>> k, m, n = symbols('k m n', integer=True)
>> >>> f, g, h = symbols('f g h', cls=Function)
>>
>> >>> from sympy.polys.orderings import *
>> >>> from sympy.polys.monomials import *
>> >>> A, B = symbols('A,B',commutative=False)
>> >>> A.is_commutative
>> False
>> >>> A*B-B*A   ## does nothing: OK
>> A*B - B*A
>> >>> factor(A**2+B**2+2*A*B) ## wrong result
>> (A + B)**2
>> >>> itermonomials([A,B], 2)) ## wrong result
>> set([1, A, A**2, B, B**2, A*B])
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/sympy/1d3c4817-ea9b-479f-b09f-263b4468d791%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/1d3c4817-ea9b-479f-b09f-263b4468d791%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6K7jLgzfv-3Yv0WKtcwZxpcUA7_WaAf%3DnukS-U_oLh9ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to