[New-bugs-announce] [issue4090] Documenting set comparisons and operations

Terry J. Reedy report at bugs.python.org
Thu Oct 9 18:17:27 CEST 2008


New submission from Terry J. Reedy <tjreedy at udel.edu>:

RefMan Expressions Comparisons has a subsection headed
"Comparison of objects of the same type depends on the type"
with entries for numbers, bytes, strings, tuples, lists, mappings, and
most_other (compared by id).  Sets (and dict views) are missing.  While
sets are similar to dicts, they are different because they also have
order comparisons.

A problem in defining comparisons for sets is that the usual definitions
depend on equality comparisons of the members involved being, as usual,
reflexive, symmetric, and transitive.  But float('nan') is irreflexive.
 For integral value i, int(i), float(i) or Fraction(i), and Decimal(i)
are (currently) jointly intransitive.  See
http://bugs.python.org/issue4087 
Even without these issues, users are free to write __eq__ methods
however they want.

So I suggest something like the following:
"If equality among the set members involved is reflexive, symmetric, and
transitive as defined in mathematics, set comparisons have the usual
definitions in terms of set inclusion.  Otherwise, they are undefined."

If dict equality had been defined in terms of equality of the set of
(key,value) pairs, it would have the same problem.  The algorithmic
definition in terms of ordered lists works fine, however.

I also suggest a warning be added at the top of the set section in the
Lib. Ref.  Something like:
"The usual definitions of set operations, given below, depend on
equality testing between the members involved being reflexive,
symmetric, and transitive.  If this is not true, results are undefined."

----------
assignee: georg.brandl
components: Documentation
messages: 74585
nosy: georg.brandl, tjreedy
severity: normal
status: open
title: Documenting set comparisons and operations
versions: Python 2.6, Python 2.7, Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4090>
_______________________________________


More information about the New-bugs-announce mailing list