[Python-Dev] (Don't Read If You're Busy With 2.1b2) "Rich" Comparisons?
Guido van Rossum
guido@digicool.com
Fri, 23 Mar 2001 16:41:14 -0500
> > > >>> a = set([1,2])
> > > >>> b = set([1,3])
> > > >>> a>b
> > > 0
> > > >>> a<b
> > > 0
> >
> > I'd expect both of these to raise an exception.
>
> I wouldn't. a>b means "does a contain b". It doesn't.
> There *is* a partial order on sets: partial means a<b, a>b, a==b can all
> be false, but that there is a meaning for all of them.
Agreed, you can define < and > any way you want on your sets. (Why
not <= and >=? Don't a<b suggest that b has at least one element not
in a?)
> FWIW, I'd be for a partial order on complex numbers too
> (a<b iff a.real<b.real and a.imag<b.imag)
Where is that useful? Are there mathematicians who define it this way?
> > > >>> max(a,b) == a
> > > 1
> > >
> > > While I'd like
> > >
> > > >>> max(a,b) == set([1,2,3])
> > > >>> min(a,b) == set([1])
> >
> > You shouldn't call that max() or min().
>
> I didn't. Mathematicians do.
> The mathematical definition for max() I learned in Calculus 101 was
> "the smallest element which is > then all arguments" (hence, properly speaking,
> max should also specify the set in which it takes place. Doesn't seem to
> matter in real life)
Sorry, mathematicians can overload stuff that you can't in Python.
Write your own operator, function or method to calculate this, just
don't call it max. And as someone else remarked, a|b and a&b might
already fit this bill.
> > These functions are supposed
> > to return one of their arguments
>
> Why?
>From the docs for max:
"""
With a single argument \var{s}, return the largest item of a
non-empty sequence (e.g., a string, tuple or list). With more than
one argument, return the largest of the arguments.
"""
It's quite clear to me from this that it returns always one of the
elements of a collection.
--Guido van Rossum (home page: http://www.python.org/~guido/)