       Mathematica Sorting Anti-Stable?

• To: mathgroup at smc.vnet.net
• Subject: [mg105262] Mathematica Sorting Anti-Stable?
• From: beckman <bc.beckman at gmail.com>
• Date: Wed, 25 Nov 2009 22:59:30 -0500 (EST)

```Consider:

In:= sortTestPoints = {{1, 1}, {1, 2}, {2, 1}, {2, 2}}

Out= (1	1
1	2
2	1
2	2

)

To produce a lexical sort, first sort by the second element. Notice it
reverses the order of the first element (first clue that "Sort" might
be antistable)

In:= Sort[sortTestPoints, #1[] < #2[] &]

Out= (2	1
1	1
2	2
1	2

)

Now, sort by the first element

In:= Sort[Sort[sortTestPoints, #1[] < #2[] &], #1[] < #2
[] &]

Out= (1	2
1	1
2	2
2	1

)

But, by itself, without a value for the the optional ordering
function, Sort effects a correct lexical sort.

In:= Sort@sortTestPoints

Out= (1	1
1	2
2	1
2	2

)

```

• Prev by Date: Replacing Values Close to One
• Next by Date: Re: part assigned sequence behavior puzzling
• Previous by thread: Re: Replacing Values Close to One
• Next by thread: Re: Mathematica Sorting Anti-Stable?