inconsistent definition of "sort" (and what about stability?)
Subject: inconsistent definition of "sort" (and what about stability?)
From: Robert Dodier
Date: Sat, 19 Nov 2011 16:32:10 -0700
On 11/19/11, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> For those of us not running git, could you send out the plain text of the
> new version?
No problem. Here's the formatted text for the new version.
I've omitted the examples since I didn't change that part.
best
Robert
PS.
-- Function: sort (<L>, <P>)
-- Function: sort (<L>)
Sorts a list <L> according to a predicate `P' of two arguments,
such that `<P>(<L>[k + 1], <L>[k])' is `false' for any two
successive elements. The predicate may be specified as the name
of a function or binary infix operator, or as a `lambda'
expression. If specified as the name of an operator, the name is
enclosed in "double quotes".
The sorted list is returned as a new object; the argument <L> is
not modified. To construct the return value, `sort' makes a
shallow copy of the elements of <L>.
It is assumed the predicate <P> is a strict total order on the
elements of <L>. If not, `sort' might run to completion without
error, but the result is undefined. `sort' complains if the
predicate evaluates to something other than `true' or `false'.
`sort' is a stable sort: if two elements <x> and <y> are
equivalent in the sense that `<P>(<x>, <y>)' and `<P>(<y>, <x>)'
are both `false', then the relative order of <x> and <y> in <L> is
preserved by `sort'.
`sort (<L>)' is equivalent to `sort (<L>, orderlessp)'. That is,
the default sorting order is ascending, as determined by
`orderlessp'. All Maxima atoms and expressions are comparable
under `orderlessp'.
The predicate `ordergreatp' sorts a list in descending order. The
predicate `ordermagnitudep' sorts Maxima numbers, constant symbols
with a numerical value, or expressions which can be evaluated to a
constant by magnitude. All other elements of the list <L> are
sorted by `orderlessp'. The predicate `"<"' allows the ordering
by magnitude too, but does not order completely if elements in the
list <L> are not comparable under `"<"'.