This answer in which I wrote about the Operator Precedence Table was unexpectedly popular.
That got me thinking about similar things, and I am wondering:
Does an "ordering table" exist for the canonical order used by Sort
and similar functions?
(Ordering
, Order
, OrderedQ
)
It's easy enough to test the ordering of various expressions, but just as the precedence table contains some surprises even for experienced users I'm wondering if the canonical ordering does too? It seems odd if this isn't spelled out clearly somewhere, yet I don't recall seeing such a list.
The documentation for Order
tantalizingly says:
Order uses canonical order as described in the notes for Sort.
Yet the documentation for Sort
is quite basic, as far as I can find, saying only:
- Sort by default orders integers, rational, and approximate real numbers by their numerical values.
- Sort orders complex numbers by their real parts, and in the event of a tie, by the absolute values of their imaginary parts.
- Sort orders symbols by their names, and in the event of a tie, by their contexts.
- Sort usually orders expressions by putting shorter ones first, and then comparing parts in a depth-first manner.
- Sort treats powers and products specially, ordering them to correspond to terms in a polynomial.
- Sort orders strings as in a dictionary, with uppercase versions of letters coming after lowercase ones. Sort places ordinary letters first, followed in order by script, Gothic, double-struck, Greek, and Hebrew. Mathematical operators appear in order of decreasing precedence.
This describes how Sort
treats certain classes of expressions but it doesn't describe the relative ordering of these classes or attempt in any way to be exhaustive.
{a1, a10, a2, a9}
while intuitive sorting gives{a1, a2, a9, a10}
. This comes handy when sorting files for example. $\endgroup$Sort@{"a", "A", "á", "Á"}
yields{"a", "á", "A", "Á"}
, which seems to imply that Mathematica cannot really distinguish accented characters (as it was already discussed here). $\endgroup$