Skip to content

Instantly share code, notes, and snippets.

@note35
Forked from startling/naive_sets.py
Created July 2, 2018 12:39
Show Gist options
  • Save note35/87c2d5b9e88a4dbc09954a2bd76ccc75 to your computer and use it in GitHub Desktop.
Save note35/87c2d5b9e88a4dbc09954a2bd76ccc75 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
@note35
Copy link
Author

note35 commented Jul 2, 2018

programing implementation russell's paradox python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment