Re: Sort[] accuracy problem, etc.

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg1168] Re: Sort[] accuracy problem, etc.
• From: Allan Hayes <hay at haystack.demon.co.uk>
• Date: Sat, 20 May 1995 03:13:27 -0400

```In [mg1130] Sort[] accuracy problem
"Wm. Martin McClain" <wmm at chem.wayne.edu> writes:

>I have a list of 3D points that I want to "alphabetize", but only up
>to a certain accuracy.
>           .............
>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}}

Here is one way that seems to do what you want and lends itself to
modification.

In[1]:=
ApproxSort[list_] :=

In[2]:=
ApproxSort[{{5.00, 1}, {4.00, 3}, {1.00, 2}, {4.01, 1}}]
Out[2]=
{{1., 2}, {4.01, 1}, {4., 3}, {5., 1}}

You just let the rounded version dominate the order and carry the
originals along.

Allan Hayes
hay at haystack.demon.co.uk

```

• Prev by Date: TeX-Mathematica printing
• Next by Date: Re: [mg 1129] Find the center!
• Previous by thread: TeX-Mathematica printing
• Next by thread: Re: [mg 1129] Find the center!