+1 to as_ordered_args. I think for most places that use .args the order doesn't really matter. Those should use .args, and the slower .as_ordered_args should only be used in the cases where the order does matter.
It would be nice if there were a function that were just as fast as hash that wasn't platform dependent, though. Aaron Meurer On Sat, May 28, 2011 at 5:52 PM, Mateusz Paprocki <[email protected]> wrote: > Hi, > > On 28 May 2011 08:45, Mateusz Paprocki <[email protected]> wrote: >> >> Hi, >> >> On 27 May 2011 23:27, Chris Smith <[email protected]> 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. > > So I did the experiment (by replacing key=hash in Add with a cached version > of sorted_key) and SymPy is about 2x slower. There were 5 test failures and > 4 exceptions. We will have to stay with key=hash for now. > >> >> >>> >>> -- >>> 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. >> >> Mateusz > > Mateusz > > -- > 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. > -- 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.
