Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Sort[] accuracy problem

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1130] Sort[] accuracy problem
  • From: "Wm. Martin McClain" <wmm at chem.wayne.edu>
  • Date: Wed, 17 May 1995 02:29:13 -0400
  • Organization: Wayne State University, College of Science

Dear mathgroupers:

I have a list of 3D points that I want to "alphabetize", but only up
to a certain accuracy.  I thought I could do this with 
                   Sort[points,logicFn[#1,#2]],    
where logicFn[#1,#2] replaces the default comparison function 
                   (#1<#2)&.
However, it seems that alphabetization, which happens automatically 
with the default comparison, is disabled when you supply your 
own comparison.  My question, in brief, is ?Can I restore it?

Here is what I mean by "alphabetize":

  In[298]:= Sort[{{5, 1}, {4, 3}, {1, 2}, {4, 1}}]
Out[298] =       {{1, 2}, {4, 1}, {4, 3}, {5, 1}}

The points {x,y} are sorted by ascending x, but when x does not 
decide, they are sorted by ascending y.  

Here is the kind of thing that is giving me trouble:

In[299]:= Sort[{{5.00, 1}, {4.00, 3}, {1.00, 2}, {4.01, 1}}]
Out[299] =     {{1.00, 2}, {4.00, 3}, {4.01, 1}, {5.00, 1}}

But I would like it to treat 4.00 and 4.01 as the same for the 
purposes of sorting, so that it returns the approximately 
alphebetized list

               {{1.00, 2}, {4.01, 1}, {4.00, 3}, {5.00, 1}}

where the difference between 1 and 3 is treated as more 
important than the difference between 4.00 and 4.01.I tried 

               Sort[list,(Round[#2*10]<Round[#1*10])&], 

but it seems to think that #n refers to the whole point {x,y}, 
rather than just to x (or on the second round, just to y), so the 
comparison becomes neither True nor False and no sorting is done.  

Any ideas?  (With this group there are always ideas...)

Thanks in advance- Martin McClain




  • Prev by Date: Re: Re: finding irregular areas
  • Next by Date: Re: Convert Products to Lists
  • Previous by thread: Re: Sort[] accuracy problem
  • Next by thread: Re: Convert Products to Lists