Re: Re: SortBy for multiple key sorts

*To*: mathgroup at smc.vnet.net*Subject*: [mg124113] Re: [mg124095] Re: SortBy for multiple key sorts*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Mon, 9 Jan 2012 03:19:56 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <201201060916.EAA26845@smc.vnet.net> <CAEtRDScdXGAxq8bkV7zTBtBSi5CnK__M4CQr-V4fcZkvC7Kw-A@mail.gmail.com> <201201080929.EAA01468@smc.vnet.net> <611D612A-B356-42E0-B75B-CE73BDD86BDE@mimuw.edu.pl>

On 8 Jan 2012, at 12:15, Andrzej Kozlowski wrote: >> >> >> Except that SortBy by default won't order irrationals except by the depth of their trees, or something like that. The normal expectation is that an irrational would be evaluated to machine precision, I would think. > > This has nothing at all to do with "irrationality" and everything with being a symbolic expression. Consider, for example, > > ls = {9, (1 + Sqrt[2])^2 + (1 - Sqrt[2])^2, 1} > > All the elements of ls are rational (in fact integers) but: > > Sort[ls] > > {1, 9, (1 - Sqrt[2])^2 + (1 + Sqrt[2])^2} > > Sort[ls, Less] > > {1, (1 - Sqrt[2])^2 + (1 + Sqrt[2])^2, 9} > > Sort[ls, Less] > > {1, (1 - Sqrt[2])^2 + (1 + Sqrt[2])^2, 9} > > I dare say, this is exactly as one would expect this to work, since in principle Mathematica does not replace exact quantities by approximate ones unless this is specifically requested by the user. Moreover, for complicated enough numeric quantities (which may result in numerical instability) machine arithmetic may not be reliable in determining the order and you could easily end up with wrong expressions. It would obviously be a very bad idea for Mathematica to use machine precision arithmetic for such a purpose by default. > > Andrzej Kozlowski That last line should have been: Simplify[ls] {9, 6, 1}

**References**:**SortBy for multiple key sorts***From:*Chris Young <cy56@comcast.net>

**Re: SortBy for multiple key sorts***From:*Christopher Young <cy56@comcast.net>