Status: Started
Owner: pr...@goodok.ru
Labels: Type-Enhancement Priority-Medium
New issue 2855 by pr...@goodok.ru: Move preordering of 'arg' from
Add.flatten to Add._hashable_content.
http://code.google.com/p/sympy/issues/detail?id=2855
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.
Thus the arguments of Add sorted by their hashes, while __new__ method
calling, that is in constructor.
Add(x, y)
x + y
Add(x, y).args
(y, x) <-- _args are sorted by hashes
Add(y, x)
x + y <-- printer system sort arguments independently
This sorting of arguments affects the calculation of the hash of the object
'Add' itself: by default the realization of the Basic.__hash__ is
calcullated as a hash of tuple of hashes of its arguments.
As it is related with the hashes therefore it is influent to compare
functions. So, when I tried to remove this line of sorting, I will get
x + y == y + x
False
It is also related with commutative topics (as a flatten function itself
too).
Probably we still need to remove this sorting of arguments from a 'flatten'
code and
reorganize other related things such as hash calculation or
commutativity in a right way.
For the last, as I understand, we need only to encapsulate this sorting
only where it is needed: at the hash function for commutative parts.
Summary the first stage for it:
- remove sorting from Add.flatten (that is while construct Add object)
- place it to the Add._hashable_content
See discussion in the mail list:
http://groups.google.com/group/sympy/browse_thread/thread/314b6f1841c00907
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.