On Mar 1, 2:00 pm, Addison Cugini <[email protected]> wrote:
> I have run into a problem when multiplying several square-roots together
> with a non-commutative object.
>
> In [19]: str(Symbol('x', commutative=False)*sqrt(2)/sqrt(6))
> Out[19]: 3**(1/2)/3
>
> It looks like some function that is called in Mul's constructor is dropping
> the non-commutative object somewhere. I don't know the code well enough to
> find the particular location where this is happening, but it looks like a
> bug.
>
> Cheers,
> Addison Cugini

You're right there's a bug there. When things like sqrt(2)/sqrt(6) can
be simplified there is a second run through "flatten" but it does not
carry the non-commutative part. Here's a patch fixing it:

diff --git a/sympy/core/mul.py b/sympy/core/mul.py
index 4ca70b1..0ba2ffa 100644
--- a/sympy/core/mul.py
+++ b/sympy/core/mul.py
@@ -304,7 +304,7 @@ def flatten(cls, seq):
             c_part = [Add(*[coeff*f for f in c_part[1].args])]

         if reeval:
-            return Mul.flatten(c_part)
+            return Mul.flatten(c_part+nc_part)
         return c_part, nc_part, order_symbols


-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to