Updates:
        Summary: Remove automatic distribution 2*(x + y) => 2*x + 2*y

Comment #9 on issue 1497 by asmeurer: Remove automatic distribution 2*(x +  
y) => 2*x + 2*y
http://code.google.com/p/sympy/issues/detail?id=1497

I have changed the issue to removing automatic distribution of numbers.   
See also the list thread I linked to
above.  Ideally, we would only have distribution of numbers whenever there  
are exactly two arguments in a Mul,
a number and an Add (as in 2*(x + y) to 2*x + 2*y), but because of the  
iterative nature of Mul. For example, with
2*(x + y)*z, Mul first sees 2*(x + y), which is combined, then it  
multiplies that with the z term, giving (2*x +
2*y)*z.  Currently there is no way to tell if there is more remaining to be  
iteratively combined, as far as I know.
This also creates contradictory automatic simplification.  For example, if  
you force Mul to evaluate (x + y)*z first,
either with parentheses or order, the 2 will not distribute.

In [5]: 2*(x + y)*z
Out[5]: z⋅(2⋅x + 2⋅y)

In [6]: 2*((x + y)*z)
Out[6]: 2⋅z⋅(x + y)

In [7]: (x + y)*z*2
Out[7]: 2⋅z⋅(x + y)

Another benefit noted from not doing this automatically is that you can  
have factor(2*x + 2*y) return 2*(x + y),
something which is currently impossible.

Basically to do this, you need to remove (from line 304 in core/mul.py):
         # we are done
         if len(c_part)==2 and c_part[0].is_Number and c_part[1].is_Add:
             # 2*(1+a) -> 2 + 2 * a
             coeff = c_part[0]
             c_part = [Add(*[coeff*f for f in c_part[1].args])]

and fix any tests that fail (which unfortunately is quite a few).

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-issues" 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-issues?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to