Hi,

On 27 May 2011 23:27, Chris Smith <smi...@gmail.com> wrote:

> The reason for the apparent arbitrariness is that Add uses key=hash (for
> speed) while Mul uses Basic.compare.


It seems we just overlooked Basic.compare in Mul. I git blame
sympy/core/mul.py and the line with Basic.compare didn't change since the
first commit in git history (2007)). I did a small experiment and changed
Basic.compare to hash() in Mul, but SymPy failed miserably (13 test failures
and 49 exceptions (mostly series)). This shows that some parts of SymPy
expect commutative part of Muls to be in specific order.

We say all the time that hashing is fast and comparison methods aren't. But
hash() of an expression isn't very different from from as_tuple_tree(), just
hash is cached in _mhash. I will perform another experiment and replace
key=hash in Add with sorted_key (but with exactly the same caching approach
as Basic.__hash__ uses). Lets see how slow it will be and how many failures
it will cause.


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

Mateusz

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

Reply via email to