I'm not sure what the point of a comparison function is if we don't
implement a total ordering. The main place cmp methods get used is in
sorting. If you have a large list of objects, and, for example, you
want to know whether X is in the list, you might find this out by
looping over the whole list. Or, if the list is sorted, you can use
cmp to do a binary search. Thus testing for containment goes from n to
log(n). Python's own sort function uses cmp, which suggests to me that
it is a silly decision to abandon total orderings. Sage's uniq
function only works if the objects input have a total ordering defined
by their cmp method. I think that __cmp__ isn't something for which
"canonical" in the mathematical sense should be applied. This is a
computer scientific operation, for doing computer scientific things,
such as smart searches through lists and giving unique output.

I think that __cmp__ should give a total ordering whenever possible,
because it makes developing Sage easier. We can guarantee unique
reproducible output in more cases, find elements in lists faster, and
sort lists with completely unknown entries. In an environment where we
are programming for an unknown user where the inputs are simply not
predictable ahead of time (and checking what types they all are
massively slows everything down), it would be handy to be able to
count on something as simple as sorted(L) returning the same thing for
any permutation of L. I really don't think that is too much to ask of
a computer algebra system.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to