Skip to content

Instantly share code, notes, and snippets.

@startling
Created April 3, 2012 05:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save startling/2289437 to your computer and use it in GitHub Desktop.
Save startling/2289437 to your computer and use it in GitHub Desktop.
russell's paradox in python
class Set(object):
"""Sets can contain anything, including themselves. This leads to
paradoxical behavior: given R, the set of all sets that don't contain
themselves, does R contain R? Here this becomes an infinite recursion.
"""
def __init__(self, predicate):
self.predicate = predicate
def __contains__(self, obj):
return self.predicate(obj)
# We hit the recursion limit with this:
R = Set(lambda s: s not in s)
print R in R
class Set(object):
"""If we add another stipulation -- no sets contain themselves -- we
exorcise this particular paradox.
"""
def __init__(self, predicate):
self.predicate = predicate
def __contains__(self, obj):
return obj is not self and self.predicate(obj)
# no sets contain themselves, so this is always False.
R = Set(lambda s: s not in s)
print R in R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment