Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7680

Re: Re: SortBy for multiple key sorts

From Andrzej Kozlowski <akoz@mimuw.edu.pl>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Re: SortBy for multiple key sorts
Date 2012-01-09 08:19 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jee7v6$cso$1@smc.vnet.net> (permalink)
References <201201060916.EAA26845@smc.vnet.net> <CAEtRDScdXGAxq8bkV7zTBtBSi5CnK__M4CQr-V4fcZkvC7Kw-A@mail.gmail.com> <201201080929.EAA01468@smc.vnet.net>

Show all headers | View raw


>
>
> 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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re:  Re: SortBy for multiple key sorts Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2012-01-09 08:19 +0000

csiph-web