If this is a bug it runs far deeper than SortBy
. Since no one has yet been able to provide a reference for the intended ordering of Sort
a reference for the intended ordering of Sort
etc. it is hard to say with certainty. I can demonstrate that Sort
, Ordering
and Order
all agree, even if I can't justify that result.
x = {6/13 (4 - Sqrt[3]), 6/13 (4 + Sqrt[3])};
Outer[#@#2 &, {Order @@ # &, Ordering, Sort}, {x, -x}, 1] // Transpose // MatrixForm
Observe that both the original and negated (-x
) forms are handed the same by each of the three functions. We can deduce that these expressions while not SameQ
are considered "order irrelevant." Whether or not that is intended behavior I think only the designers can say.
What is clearly stated is that numeric comparision is not used by default, e.g.:
Sort[{∞, Sqrt[2], 1, 2, -∞, 1/Sqrt[2]}]
{1, 2, 1/Sqrt[2], Sqrt[2], -∞, ∞}
Therefore you should use N
if you desire a numeric ranking.