[Python-Dev] RE: (Don't Read If You're Busy With 2.1b2) "Rich" Comparisons?

Tim Peters tim.one@home.com
Sat, 24 Mar 2001 05:19:15 -0500


[Martin v. Loewis]
> The missing bit linking the two (sup and max) is
>
> "The supremum of S is equal to its maximum if S possesses a greatest
> member."
> [http://www.cenius.fsnet.co.uk/refer/maths/articles/s/supremum.html]
>
> So given a subset of a lattice, it may not have a maximum, but it will
> always have a supremum. It appears that the Python max function
> differs from the mathematical maximum in that respect: max will return
> a value, even if that is not the "largest value"; the mathematical
> maximum might give no value.

Note that the definition of supremum given on that page can't be satisfied in
general for lattices.  For example "x divides y" induces a lattice, where gcd
is the glb and lcm (least common multiple) the lub.  The set {6, 15} then has
lub 30, but is not a supremum under the 2nd clause of that page because 10
divides 30 but neither of {6, 15} (so there's an element "less than" (== that
divides) 30 which no element in the set is "larger than").

So that defn. is suitable for real analysis, but the more general defn. of
sup(S) is simply that X = sup(S) iff X is an upper bound for S (same as the
1st clause on the referenced page), and that every upper bound Y of S is >=
X.  That works for lattices too.

Since Python's max works on sequences, and never terminates given an infinite
sequence, it only makes *sense* to ask what max(S) returns for finite
sequences S.  Under a total ordering, every finite set S has a maximal
element (an element X of S such that for all Y in S Y <= X), and Python's
max(S) does return one.  If there's only a partial ordering, Python's max()
is unpredictable (may or may not blow up, depending on the order the elements
are listed; e.g., [a, b, c] where a<b and c<b but a and c aren't comparable:
in that order, max returns b, but if given in order [a, c, b] max blows up).

Since this is all obvious to the most casual observer <0.9 wink>, it remains
unclear what the brouhaha is about.