Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7631
| From | "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: SortBy won't order irrationals |
| Date | 2012-01-07 10:24 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <je96hd$j42$1@smc.vnet.net> (permalink) |
| References | <je6e9b$q93$1@smc.vnet.net> |
This behavior is precisely as described in the documentation:
"Sort treats powers and products specially, ordering them to
correspond to terms in a polynomial."
FullForm[Sqrt[2]]
=> Power[2,Rational[1,2]]
Adding an N to your SortBy function isn't that much of a trouble is
it?
In case of Sort you could use Less as the ordering function.
Cheers -- Sjoerd
Check out Stackoverflow's Mathematica tag: http://stackoverflow.com/questions/tagged/mathematica
or better, help out with the new dedicated Mathematica Q&A site on
StackExchange.
It's almost in private beta, but needs just a few extra people to kick
off and participate. Go to:
http://area51.stackexchange.com/proposals/37304/mathematica?referrer=EJOMFcZOBpAIDM_
9uBjtlA2
On Jan 6, 10:18 am, Chris Young <c...@comcast.net> wrote:
> Have to use N[ ] on them first. Combined with Sort's refusal to accept
> multiple keys, this is extremely exasperating.
>
> In[1218]:= ptsIrr =
> {
> {0, 2}, {1, Sqrt[2]}, {2, 2},
> {4, 1}, {Sqrt[5], 1}, {6, 1}, {Sqrt[3], 1},
> {7, 0}, {-1, 0}
> }
>
> Out[1218]= {{0, 2}, {1, Sqrt[2]}, {2, 2}, {4, 1}, {Sqrt[5], 1}, {6,
> 1}, {Sqrt[3], 1}, {7, 0}, {-1, 0}}
>
> In[1219]:= sortIrrY = SortBy[ptsIrr, #[[2]] &]
>
> Out[1219]= {{-1, 0}, {7, 0}, {4, 1}, {6, 1}, {Sqrt[3], 1}, {Sqrt[5],
> 1}, {0, 2}, {2, 2}, {1, Sqrt[2]}}
>
> In[1220]:= sortIrrYN = SortBy[ptsIrr // N, #[[2]] &]
>
> Out[1220]= {{-1., 0.}, {7., 0.}, {1.73205, 1.}, {2.23607, 1.}, {4.,
> 1.}, {6., 1.}, {1., 1.41421}, {0., 2.}, {2., 2.}}
>
> In[1221]:= sortIrrYN2 = SortBy[ptsIrr, N[#[[2]]] &]
>
> Out[1221]= {{-1, 0}, {7, 0}, {4, 1}, {6, 1}, {Sqrt[3], 1}, {Sqrt[5],
> 1}, {1, Sqrt[2]}, {0, 2}, {2, 2}}
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
SortBy won't order irrationals Chris Young <cy56@comcast.net> - 2012-01-06 09:18 +0000 Re: SortBy won't order irrationals "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> - 2012-01-07 10:24 +0000
csiph-web