-
-
Save note35/87c2d5b9e88a4dbc09954a2bd76ccc75 to your computer and use it in GitHub Desktop.
russell's paradox in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
programing implementation russell's paradox python