{"action":"created","issue":{"url":"https://api.github.com/repos/sympy/sympy/issues/8928","labels_url":"https://api.github.com/repos/sympy/sympy/issues/8928/labels{/name}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/8928/comments","events_url":"https://api.github.com/repos/sympy/sympy/issues/8928/events","html_url":"https://github.com/sympy/sympy/issues/8928","id":56171136,"number":8928,"title":"default_sort_key puts x before sqrt(x)","user":{"login":"smichr","id":90703,"avatar_url":"https://avatars.githubusercontent.com/u/90703?v=3","gravatar_id":"","url":"https://api.github.com/users/smichr","html_url":"https://github.com/smichr","followers_url":"https://api.github.com/users/smichr/followers","following_url":"https://api.github.com/users/smichr/following{/other_user}","gists_url":"https://api.github.com/users/smichr/gists{/gist_id}","starred_url":"https://api.github.com/users/smichr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smichr/subscriptions","organizations_url":"https://api.github.com/users/smichr/orgs","repos_url":"https://api.github.com/users/smichr/repos","events_url":"https://api.github.com/users/smichr/events{/privacy}","received_events_url":"https://api.github.com/users/smichr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-01T17:49:43Z","updated_at":"2015-02-03T01:48:19Z","closed_at":null,"body":"If default_sort_key is being used to sort expressions according to complexity, it fails in this case:\r\n\r\n```python\r\n>>> default_sort_key\r\n<function default_sort_key at 0x01942CF0>\r\n>>> f=_\r\n>>> f(x)\r\n((2, 0, 'Symbol'), (1, ('x',)), ((1, 0, 'Number'), (0, ()), (), 1), 1)\r\n>>> f(sqrt(x))\r\n((2, 0, 'Symbol'), (1, ('x',)), ((1, 0, 'Number'), (0, ()), (), 1/2), 1)\r\n```\r\n\r\nordered works, however:\r\n\r\n```\r\n>>> list(ordered((sqrt(x),x)))\r\n[x, sqrt(x)]\r\n```\r\n\r\ndefault_sort_key should be fixed or ordered should be used"},"comment":{"url":"https://api.github.com/repos/sympy/sympy/issues/comments/72577067","html_url":"https://github.com/sympy/sympy/issues/8928#issuecomment-72577067","issue_url":"https://api.github.com/repos/sympy/sympy/issues/8928","id":72577067,"user":{"login":"smichr","id":90703,"avatar_url":"https://avatars.githubusercontent.com/u/90703?v=3","gravatar_id":"","url":"https://api.github.com/users/smichr","html_url":"https://github.com/smichr","followers_url":"https://api.github.com/users/smichr/followers","following_url":"https://api.github.com/users/smichr/following{/other_user}","gists_url":"https://api.github.com/users/smichr/gists{/gist_id}","starred_url":"https://api.github.com/users/smichr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smichr/subscriptions","organizations_url":"https://api.github.com/users/smichr/orgs","repos_url":"https://api.github.com/users/smichr/repos","events_url":"https://api.github.com/users/smichr/events{/privacy}","received_events_url":"https://api.github.com/users/smichr/received_events","type":"User","site_admin":false},"created_at":"2015-02-03T01:48:19Z","updated_at":"2015-02-03T01:48:19Z","body":"> If the ordered output is assumed correct, what is it based on ?\r\n\r\nYou can look at the code to see how it works. I believe it uses total arg length or count_ops value to sort on.\r\n\r\nI'm not sure there is something to be fixed except to \r\n\r\n* check the code where default_sort_key is being used to see if it is being used to put short expressions first. That's how I became aware of the problem. In heurisch or meijerint (I forget now) this was being done and it was assumed this ordering. But it didn't work out that way.\r\n* add a note to the default_sort_key function (if necessary) that gives examples to show that it cannot be used for this sort of ordering"}}