Ticket #11353: trac_11353_complement_of_frozenbitset.patch

File trac_11353_complement_of_frozenbitset.patch, 2.2 KB (added by dcoudert, 7 years ago)
  • sage/misc/bitset.pxd

    # HG changeset patch
    # User dcoudert <david.coudert@inria.fr>
    # Date 1344352627 -7200
    # Node ID e0fc3cc2480e4a1df27532dbc6f38e6eb997bd99
    # Parent  a3a5bdf1e8c8c9f17f141150bf07043c8115ec4b
    trac #11353 -- binds tilde for the complement of FrozenBitset
    
    diff --git a/sage/misc/bitset.pxd b/sage/misc/bitset.pxd
    a b  
    1313    cpdef intersection(self, FrozenBitset other)
    1414    cpdef difference(self, FrozenBitset other)
    1515    cpdef symmetric_difference(self, FrozenBitset other)
     16    cpdef complement(self)
    1617    cpdef __copy__(self)
    1718
    1819cdef class Bitset(FrozenBitset):
  • sage/misc/bitset.pyx

    diff --git a/sage/misc/bitset.pyx b/sage/misc/bitset.pyx
    a b  
    820820        """
    821821        return self.symmetric_difference(other)
    822822   
     823    cpdef complement(self):
     824        """
     825        Return the complement of self.
     826
     827        EXAMPLES::
     828
     829            sage: ~FrozenBitset('10101')
     830            01010
     831            sage: ~FrozenBitset('11111'*10)
     832            00000000000000000000000000000000000000000000000000
     833            sage: x = FrozenBitset('10'*40)
     834            sage: x == ~x
     835            False
     836            sage: x == ~~x
     837            True
     838            sage: x|(~x) == FrozenBitset('11'*40)
     839            True
     840            sage: ~x == FrozenBitset('01'*40)
     841            True
     842        """
     843        cdef FrozenBitset temp = self._new(self._bitset.size)
     844        bitset_complement(temp._bitset, self._bitset)
     845        return temp
     846
     847    def __invert__(self):
     848        """
     849        Return the complement of self.
     850
     851        EXAMPLES::
     852
     853            sage: ~FrozenBitset('10101')
     854            01010
     855            sage: ~FrozenBitset('11111'*10)
     856            00000000000000000000000000000000000000000000000000
     857            sage: x = FrozenBitset('10'*40)
     858            sage: x == ~x
     859            False
     860            sage: x == ~~x
     861            True
     862            sage: x|(~x) == FrozenBitset('11'*40)
     863            True
     864            sage: ~x == FrozenBitset('01'*40)
     865            True
     866        """
     867        return self.complement()
     868
    823869    cpdef  __copy__(self):
    824870        """
    825871        Return self (since self is immutable).