Skip to content

Instantly share code, notes, and snippets.

@note35
Created July 2, 2018 12:39
Show Gist options
  • Select an option

  • Save note35/87c2d5b9e88a4dbc09954a2bd76ccc75 to your computer and use it in GitHub Desktop.

Select an option

Save note35/87c2d5b9e88a4dbc09954a2bd76ccc75 to your computer and use it in GitHub Desktop.

Revisions

  1. @startling startling revised this gist Apr 3, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions sets.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,6 @@ def __init__(self, predicate):
    def __contains__(self, obj):
    return obj is not self and self.predicate(obj)

    # we can do this just fine, though -- it's always False because no sets contain
    # themselves.
    # no sets contain themselves, so this is always False.
    R = Set(lambda s: s not in s)
    print R in R
  2. @startling startling created this gist Apr 3, 2012.
    14 changes: 14 additions & 0 deletions naive_sets.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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
    14 changes: 14 additions & 0 deletions sets.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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)

    # we can do this just fine, though -- it's always False because no sets contain
    # themselves.
    R = Set(lambda s: s not in s)
    print R in R