       Re: Re: SortBy for multiple key sorts

• To: mathgroup at smc.vnet.net
• Subject: [mg124103] Re: [mg124095] Re: SortBy for multiple key sorts
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Mon, 9 Jan 2012 03:16:28 -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>

```>
>
> 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 + (1 - Sqrt)^2, 1}

All the elements of ls are rational (in fact integers) but:

Sort[ls]

{1, 9, (1 - Sqrt)^2 + (1 + Sqrt)^2}

Sort[ls, Less]

{1, (1 - Sqrt)^2 + (1 + Sqrt)^2, 9}

Sort[ls, Less]

{1, (1 - Sqrt)^2 + (1 + Sqrt)^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

```

• Prev by Date: Re: more plotting peculiarities
• Next by Date: Re: more plotting peculiarities
• Previous by thread: Re: SortBy for multiple key sorts
• Next by thread: Re: Re: SortBy for multiple key sorts