{"issue":{"created_at":"2011-11-19T01:14:25Z","state":"open","updated_at":"2011-12-13T06:02:38Z","user":{"gravatar_id":"151165125673e24e8b5af6ae1ef9977d","id":586931,"url":"https://api.github.com/users/goodok","login":"goodok","avatar_url":"https://secure.gravatar.com/avatar/151165125673e24e8b5af6ae1ef9977d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":25,"body":"Main aims: remove dependence on platforms, when tests checked the order in the resulted expressions.\r\n\r\nThe code of the method 'flatten` of the class 'sympy.core.add.Add'\r\ncontain the following lines.\r\n\r\n        # order args canonically\r\n        # Currently we sort things using hashes, as it is quite fast. A\r\n        # better solution is not to sort things at all - but this needs\r\n        # some more fixing. NOTE: this is used in primitive, too, so if\r\n        # it changes here it should be changed there.\r\n\r\n        newseq.sort(key=hash)   <-- this line.\r\n\r\nIt 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).\r\n\r\nThis 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.\r\nThis change was made in the first commit.\r\n\r\nThe second commit contains changes of ordering (mainly relating to testing of the form '(x+y).args[0]==x') \r\n\r\nBut the third commit raise more complex questions, these are will be written at the discussion section of this pull request. UPDATE: questions with piecewise and test_solvers resolved.\r\n\r\n\r\nCommit 5 \"Remove random sorting of Add arguments, insert nested Add inplace.\"\r\n\r\nRemove hash depended sorting of arguments, and reordering of arguments for nested Add's:\r\n\r\nWhile cycling in Add.flatten the recursion is organized as\r\na cycle, which in particular two problems solves.\r\nBut with reordering.\r\n\r\n1. The task to collect similar terms\r\n\r\n    `2*x**2 + y + 5*x**2   --> 7*x**2 + y`\r\n\r\nwas solved originaly with the help of the dictionary\r\n(`{x**2:7,y:S.One}`) but further cycle by keys reorder them\r\nrandomly (or by hash).\r\n\r\nIn this commit The way of accumulation is changed, so do not break\r\noriginal order. Instead of cycle by keys of hash, the arguments iterated in order as they were originally.\r\n\r\n2. The task of nested Adds was solved with the help of the recursion\r\nwhich is organized as a cycle.\r\n\r\n    `Add(a, Add(b, c), d) --> Add(a, d, b, c)`\r\n\r\nIn this commit nested Add's are inserted in-place now:\r\n\r\n    `Add(a, Add(b, c), d) --> Add(a, b, c, d)`\r\n\r\n\r\nSee also:\r\n[issue 2855](http://code.google.com/p/sympy/issues/detail?id=2855)\r\n[Maillist](http://groups.google.com/group/sympy/browse_thread/thread/314b6f1841c00907)","assignee":null,"id":2286467,"pull_request":{"patch_url":"https://github.com/sympy/sympy/pull/722.patch","html_url":"https://github.com/sympy/sympy/pull/722","diff_url":"https://github.com/sympy/sympy/pull/722.diff"},"labels":[],"number":722,"title":"Issue 2855: Move any sorting of arguments from Add.flatten","closed_at":null,"html_url":"https://github.com/sympy/sympy/issues/722","url":"https://api.github.com/repos/sympy/sympy/issues/722","milestone":null},"action":"created","comment":{"created_at":"2011-12-13T06:02:38Z","updated_at":"2011-12-13T06:02:38Z","user":{"gravatar_id":"f65ea1dfe7ef7b9f889ed6877fcc69b8","id":20568,"url":"https://api.github.com/users/certik","login":"certik","avatar_url":"https://secure.gravatar.com/avatar/f65ea1dfe7ef7b9f889ed6877fcc69b8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"**SymPy Bot Summary:** All tests have passed.\n\nTest results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYstUIDA\n\n*Interpreter:*   /usr/bin/python  (3.2.0-final-0)\n*Architecture:* Linux (64-bit)\n*Cache:*        yes\n*Test command:* setup.py test\n*master hash*: 1ad15cb040f5c23a507604731c53ed2886ebc561\n*branch hash*: d815fc20db9c112b2b11f8d3fd0b65632bdda3ca\n\nAutomatic review by [SymPy Bot](https://github.com/sympy/sympy-bot).","id":3119313,"url":"https://api.github.com/repos/sympy/sympy/issues/comments/3119313"}}