Exemple #1
0
 def __truediv__(self, other):
     if isinstance(other, Integral):
         other = abs(other)
         if other == 1:
             return self
         elif other == 2:
             return Parity(0)
         elif other == 4:
             return Parity(mat24.gcode_weight(self.value) & 1)
         else:
             raise ValueError(ERR_DIV4 % type(self))
     else:
         return NotImplemented
Exemple #2
0
 def __truediv__(self, other):
     if isinstance(other, PLoop):
         return PLoop(
             mat24.mul_ploop(self.value, mat24.pow_ploop(other.value, 3)))
     elif isinstance(other, Integral):
         if abs(other) == 1:
             return PLoop(self.value ^ ((other & 2) << 11))
         elif abs(other) == 2:
             return Parity(0)
         elif abs(other) == 4:
             return Parity(mat24.gcode_weight(self.value) & 1)
         else:
             raise TypeError(ERR_DIV4 % type(self))
     else:
         return NotImplemented
Exemple #3
0
 def __truediv__(self, other):
     if isinstance(other, Integral):
         other = abs(other)
         if other == 1:
             return self
         w = mat24.bw24(self.value)
         if other == 2 and w & 1 == 0:
             return Parity(w >> 1)
         elif other == 4 and w & 3 == 0:
             return Parity(w >> 2)
         elif other in (2, 4):
             err = "Don't know weight of Omega vector / %d"
             raise ValueError(err % other)
         else:
             raise TypeError(ERR_DIV4 % self.__class__)
     else:
         return NotImplemented
Exemple #4
0
 def __and__(self, other):
     if import_pending:
         complete_import()
     if isinstance(other, GCode):
         return PLoopIntersection(self, other)
     elif isinstance(other, Cocode):
         return Parity(mat24.scalar_prod(self.value, other.value))
     elif isinstance(value, GcVector):
         return GcVector(mat24.gcode_to_vect(self.value) & other.value)
     else:
         return NotImplemented
Exemple #5
0
 def __and__(self, other):
     if isinstance(other, XLeech2):
         ov = other
     elif isinstance(other, (GCode, PLoop)):
         d = other.value & 0xfff
         ov = (d << 12) ^ mat24.ploop_theta(d)
     elif isinstance(ploop, Cocode):
         ov = ploop.value & 0xfff
     else:
         return NotImplemented
     return Parity(gen_leech2_scalprod(self.value, ov))
Exemple #6
0
    def theta(self, g2=None):
        """Return cocycle of Golay code words.

        The cocycle ``theta`` maps a pair of Golay code words 
        to an integer modulo ``2``. 
        It is linear in its second argument, so it
        may also be considered as a mapping from the Golay code
        to the cocode of the Golay code.


        :param g2:  ``None`` (default) or another Golay code word of
                    type |GCode|.
        :returns:
            * If ``g2`` is a code word of type |GCode|, we return
              the value ``g1.theta(g2) = theta(g1, g2)`` 
              as a |Parity| object.
            * If ``g2`` is ``None`` (default), we return the value
              ``g1.theta() = theta(g1)``  as a |Cocode| object.
              Note that  ``g1.theta(g2) == g1.theta() & g2 .``

        The importance of the ``theta`` function comes from the
        fact that the multiplication of elements of the Parker loop
        is based on the cocycle. We embed the set of Golay code words  
        into  the set of positive Parker loop elements, which are 
        instances of class |PLoop|. 
 
        Let ``g1`` and ``g2`` be Golay code words of type |GCode|.
        Then  ``PLoop(g1)`` and ``PLoop(g2)`` are the corresponding
        positive Parker loop elements,  and  ``g1.theta(g2)`` is an 
        integer  modulo ``2`` of type |Parity|. We have:  
       
        ``PLoop(g1) * PLoop(g2) == (-1)**g1.theta(g2) * PLoop(g1 + g2) .``
        """
        th = mat24.ploop_theta(self.value)
        if g2 == None:
            complete_import()
            return Cocode(th)
        if isinstance(g2, GCode):
            return Parity(mat24.scalar_prod(g2.value, th))
        err = "Types %s is illegal for method theta()"
        raise TypeError(err % type(g2))
Exemple #7
0
 def __mod__(self, other):
     return Parity(self.parity) % other
Exemple #8
0
 def half_weight(self):
     return Parity(mat24.ploop_comm(self.v1, self.v2))
Exemple #9
0
 def __and__(self, other):
     if isinstance(other, GCode):
         return Parity(mat24.scalar_prod(self.value, other.value))
     else:
         return NotImplemented