RE: Strange behavior of Sort

*To*: mathgroup at smc.vnet.net*Subject*: [mg12968] RE: [mg12941] Strange behavior of Sort*From*: Ersek_Ted%PAX1A at mr.nawcad.navy.mil*Date*: Sun, 28 Jun 1998 02:51:56 -0400*Sender*: owner-wri-mathgroup at wolfram.com

Edward Neuman wrote: | | |In Mathematica 3.0: | |In[5]:= |li={1/Sqrt[2], 1, -Sqrt[2]}; | |In[7]:= |Sort[li]//InputForm | |Out[7]//InputForm= |{1, 1/Sqrt[2], -Sqrt[2]} | |Sort doesn't work properly on this list. | | Lets look at that some more. In[1]:= lst={-1,0,1,-2,2,Sqrt[2],-Sqrt[2],1/Sqrt[2],-1/Sqrt[2]}; As you pointed out simple application of Sort will not sort them in increasing order. In[2]:= Sort[lst]//N Out[2]= {-2., -1., 0, 1., 2., -0.707107, 0.707107, -1.41421, 1.41421} If you want them sorted numerically you can specify an appropriate ordering function. In[3]:= Sort[lst, Less]//N Out[3]= {-2., -1.41421, -1., -0.707107, 0, 0.707107, 1., 1.41421, 2.} Now what is the default ordering function? Dave Withoff posted it once, but I didn't understand what he was saying. Ted Ersek