       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:=
|li={1/Sqrt, 1, -Sqrt};
|
|In:=
|Sort[li]//InputForm
|
|Out//InputForm=
|{1, 1/Sqrt, -Sqrt}
|
|Sort doesn't work properly on this list. |
|

Lets look at that some more.

In:=
lst={-1,0,1,-2,2,Sqrt,-Sqrt,1/Sqrt,-1/Sqrt};

As you pointed out simple application of Sort will not sort them in
increasing order.
In:=
Sort[lst]//N

Out=
{-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:=
Sort[lst,  Less]//N

Out=
{-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

```

• Prev by Date: Re: Find Max of "Concave" List
• Next by Date: Re: Fw: greek symbols in eps files
• Previous by thread: Re: Strange behavior of Sort
• Next by thread: Re: Strange behavior of Sort