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


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

Re: SortBy for multiple key sorts

From Christopher Young <cy56@comcast.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: SortBy for multiple key sorts
Date 2012-01-08 09:34 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jebnv9$1iv$1@smc.vnet.net> (permalink)
References <201201060916.EAA26845@smc.vnet.net> <CAEtRDScdXGAxq8bkV7zTBtBSi5CnK__M4CQr-V4fcZkvC7Kw-A@mail.gmail.com>

Show all headers | View raw


On Jan 6, 2012, at 12:21 PM, Bob Hanlon wrote:

> pts = {{0, 2}, {1, 2}, {2, 2}, {4, 1}, {3, 1}, {6, 1}, {5, 1}, {7, 0}, {-1,
>    0}};
>
> sortByYthenX = SortBy[pts, {Min[#[[2]]] &, Min[#[[1]]] &}]
>
> {{-1, 0}, {7, 0}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {0, 2}, {1, 2}, {2, 2}}
>
> The Min isn't doing anything useful
>
> sortByYthenX ==
> SortBy[pts, {#[[2]], #[[1]]} &] ==
> SortBy[pts, {Last, First}] ==
> Reverse /@ Sort[Reverse /@ pts]
>
> True


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.

In[83]:= SortBy[P, {#[[2]], #[[1]]} &]

Out[83]= {{-1, 0}, {0, 0}, {1, 0}, {-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}

To get the correcting sorting, rows across, going upwards from the bottom row, I have to take numerical evaluations:

In[84]:= SortBy[P, N@{#[[2]], #[[1]]} &]

Out[84]= {{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {-1,0}, {0,0}, {1, 0}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}

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


Thread

Re: SortBy for multiple key sorts Christopher Young <cy56@comcast.net> - 2012-01-08 09:34 +0000

csiph-web