コード例 #1
0
ファイル: set_partition.py プロジェクト: pombredanne/sage-1
    def __contains__(self, x):
        """
        TESTS::
        
            sage: S = SetPartitions(4, [2,2])
            sage: all([sp in S for sp in S])
            True
        """
        #x must be a set
        if not is_Set(x):
            return False

        #Make sure that the number of elements match up
        if sum(map(len, x)) != len(self.set):
            return False

        #Check to make sure each element of x
        #is a set
        u = Set([])
        for s in x:
            if not is_Set(s):
                return False
            u = u.union(s)

        #Make sure that the union of all the
        #sets is the original set
        if u != Set(self.set):
            return False

        return True
コード例 #2
0
    def __contains__(self, x):
        """
        TESTS::
        
            sage: S = SetPartitions(4, [2,2])
            sage: all([sp in S for sp in S])
            True
        """
        #x must be a set
        if not is_Set(x):
            return False

        #Make sure that the number of elements match up
        if sum(map(len, x)) != len(self.set):
            return False

        #Check to make sure each element of x
        #is a set
        u = Set([])
        for s in x:
            if not is_Set(s):
                return False
            u = u.union(s)

        #Make sure that the union of all the
        #sets is the original set
        if u != Set(self.set):
            return False

        return True
コード例 #3
0
ファイル: set_partition.py プロジェクト: biasse/sage
    def __contains__(self, x):
        """
        TESTS::

            sage: S = SetPartitions(4, [2,2])
            sage: all([sp in S for sp in S])
            True
        """
        #x must be a set, if it's not, make it into one
        if not (isinstance(x, (SetPartition, set, frozenset)) or is_Set(x)):
            return False

        #Make sure that the number of elements match up
        if sum(map(len, x)) != len(self._set):
            return False

        #Check to make sure each element of x is a set
        u = Set([])
        for s in x:
            if not (isinstance(s, (set, frozenset)) or is_Set(s)):
                return False
            u = u.union(Set(s))

        #Make sure that the union of all the
        #sets is the original set
        if u != Set(self._set):
            return False

        return True
コード例 #4
0
ファイル: set_partition.py プロジェクト: biasse/sage
    def __contains__(self, x):
        """
        TESTS::

            sage: S = SetPartitions(4, [2,2])
            sage: all([sp in S for sp in S])
            True
        """
        #x must be a set, if it's not, make it into one
        if not (isinstance(x, (SetPartition, set, frozenset)) or is_Set(x)):
            return False

        #Make sure that the number of elements match up
        if sum(map(len, x)) != len(self._set):
            return False

        #Check to make sure each element of x is a set
        u = Set([])
        for s in x:
            if not (isinstance(s, (set, frozenset)) or is_Set(s)):
                return False
            u = u.union(Set(s))

        #Make sure that the union of all the
        #sets is the original set
        if u != Set(self._set):
            return False

        return True
コード例 #5
0
    def __contains__(self, x):
        """
        TESTS::

            sage: OS = OrderedSetPartitions([1,2,3,4])
            sage: all([sp in OS for sp in OS])
            True
        """
        #x must be a list
        if not isinstance(x, (OrderedSetPartition, list, tuple)):
            return False

        #The total number of elements in the list
        #should be the same as the number is self._set
        if sum(map(len, x)) != len(self._set):
            return False

        #Check to make sure each element of the list
        #is a set
        u = Set([])
        for s in x:
            if not isinstance(s, (set, frozenset)) and not is_Set(s):
                return False
            u = u.union(s)

        #Make sure that the union of all the
        #sets is the original set
        if u != Set(self._set):
            return False

        return True
コード例 #6
0
    def __contains__(self, x):
        """
        TESTS::

            sage: OS = OrderedSetPartitions([1,2,3,4])
            sage: all([sp in OS for sp in OS])
            True
        """
        #x must be a list
        if not isinstance(x, (OrderedSetPartition, list, tuple)):
            return False

        #The total number of elements in the list
        #should be the same as the number is self._set
        if sum(map(len, x)) != len(self._set):
            return False

        #Check to make sure each element of the list
        #is a set
        u = Set([])
        for s in x:
            if not isinstance(s, (set, frozenset)) and not is_Set(s):
                return False
            u = u.union(s)

        #Make sure that the union of all the
        #sets is the original set
        if u != Set(self._set):
            return False

        return True