[Python-3000] sets in P3K?

Tim Peters tim.peters at gmail.com
Tue Apr 25 21:20:51 CEST 2006


[Guido]
>>> OTOH mathematicians (whether in high school or not) write things like
>>> {x | 2 < x < 10}, which is of course the origin of our list
>>> comprehensions and generator expressions [...]

[Boris Borcic]
>> Most of the time they use it as "filter" and write something like
>>
>> {x ∈ S st. P(x)}

[Jim Jewett]
> That is the formal form, because then you can specify (for example)
> whether x is limited to Real, Rational, or Integers.

Not that it matters to Python, but it's the formal form because
Guido's form isn't allowed at all in mainstream modern set theory:  it
directly yields Russell's Paradox (let R = {x | x not in x}; then is R
in R?; both "yes" and "no" lead to contradiction).  So in modern work,
"unrestricted comprehension" isn't allowed -- you can't just make up a
predicate and assert that there's a set consisting precisely of the
things satisfying the predicate.  For another example, {x | True} (the
set containing "everything") is also paradoxical.

Now you can only use a set if you can prove it exists, and one way to
prove a set exists is via what was once called the Axiom of
Comprehsion (but seems to be called the Axiom of Subsets more often
these days).  That says that if you have a set S, then for any
one-place predicate P, {x ∈ S | P(x)} exists.  So you can still make
up any predicate you like, but you can only use it to "separate out"
(why it's also sometimes, but I think rarely, called the Axiom of
Separation) the satisfiyng elements from another set.

> But what actually got used most of the time (in classes I took and texts and
> papers I read) was the shorter form Guido mentioned.

For example, in a text on number theory, it would be a major PITA to
keep repeating that the set from which predicates "separate out" is
the set of integers.  Nothing wrong with stating that that (or any
other known-to-exist) set is to be assumed in subsequent
comprehensions.  It would be a dubious thing for Python to, e.g., a
grow sys.universal_set global default though ;-)


More information about the Python-3000 mailing list