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


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

Re: SortBy for multiple key sorts

Started byChristopher Young <cy56@comcast.net>
First post2012-01-08 09:34 +0000
Last post2012-01-08 09:34 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#7671 — Re: SortBy for multiple key sorts

FromChristopher Young <cy56@comcast.net>
Date2012-01-08 09:34 +0000
SubjectRe: SortBy for multiple key sorts
Message-ID<jebnv9$1iv$1@smc.vnet.net>
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}}

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web