sympy/sympy — pull request #722 by goodok (2011-11-19 01:14:25+00:00)
Title: Issue 2855: Move the sorting of arguments from Add.flatten to Add._hashable_content

The code of the method 'flatten` of the class 'sympy.core.add.Add'
contain the following lines.

# order args canonically
# Currently we sort things using hashes, as it is quite fast. A
# better solution is not to sort things at all - but this needs
# some more fixing. NOTE: this is used in primitive, too, so if
# it changes here it should be changed there.

newseq.sort(key=hash) <-- this line.

It is related with an Add class constructor (ordering of args before constructing), and therefore with basic hash functions (which is a hash of tuple of sorted arguments).

This kind of sorting moved to _hashable_content method of Add class. so ther orders of args of the Add class became as they are created from constructor.
This change was made in the first commit.

The second commit contains changes of ordering (mainly relating to testing of the form '(x+y).args[0]==x')

But the third commit raise more complex questions, these are will be written at the discussion section of this pull request.

See also:
[issue 2855](http://code.google.com/p/sympy/issues/detail?id=2855)
[Maillist](http://groups.google.com/group/sympy/browse_thread/thread/314b6f1841c00907)