Пример #1
0
def test_reduce_n(ntests=100, verbose=0):
    """Test function ``gen_leech2_reduce_n`` """
    for n, v in enumerate(reduce_n_testdata(ntests)):
        ref_subtype = gen_leech2_subtype(v)
        if verbose:
            print(" \nTest %d, v = %s, subtype  = %s" %
                  (n + 1, hex(v), hex(ref_subtype)))
        subtype, op = ref_gen_leech2_reduce_n(v)
        ok = True
        err = "Unknown error"

        ok1 = ref_subtype == subtype
        if ok and not ok1:
            err = "Function gen_leech2_reduce_n returns wrong subtype"
        ok &= ok1

        v_mapped = gen_leech2_op_word(v, op, len(op))
        ok2 = v_mapped == map_vector(v)
        if ok and not ok2:
            err = "Wrong mapping in function gen_leech2_reduce_n"
        ok &= ok2

        ok3 = len(op) == 3
        tags = [x >> 28 for x in op]
        ok3 &= tags[:2] == [0xa, 0xc] and tags[2] in [9, 0xb]
        if ok and not ok3:
            err = "Error in computed operation on vector"
        ok &= ok3

        if (op[2] & 0xf0000000) == 0xB and v != 0x18000000:
            ok4 = op[2] & 0x800 == 0
        else:
            ok4 = True
        if ok and not ok4:
            err = "Computed operation on vector must be even"
        ok &= ok4

        op_c = np.zeros(3, dtype=np.uint32)
        subtype_c = gen_leech2_reduce_n(v, op_c)
        #op_c[1] &= ~2 # Produce an error for verifying the test
        ok_C_function = subtype_c == subtype
        ok_C_function &= (op_c == op).all()
        if ok and not ok_C_function:
            err = "Error in C function"
        ok &= ok_C_function

        if verbose or not ok:
            if not ok:
                print(" \nTest %d, v = %s, subtype  = %s" %
                      (n + 1, hex(v), hex(ref_subtype)))
            print("transformation", op)
            print("map expected:", hex(map_vector(v)), ", obtained",
                  hex(v_mapped))
            if not ok_C_function:
                print("Subtype from C function is %s, expected %s" %
                      (hex(subtype_c), hex(subtype)))
                print("Operation from C function:", op_c)
                print("Expected:                 ", op)
            if not ok:
                raise ValueError(err)
Пример #2
0
def test_reduce_type_4_std(ntests=500, verbose=0):
    """Test function ``reduce_type4_std`` """
    for n, v in enumerate(type4_testdata(ntests)):
        if verbose:
            print(" \nTest %d, v = %s, subtype  =%s" %
                  (n + 1, hex(v), hex(gen_leech2_subtype(v))))
        op = reduce_type4_std(v, verbose)
        w = gen_leech2_op_word(v, op, len(op))
        assert w & 0xffffff == 0x800000, hex(w)
Пример #3
0
def test_reduce_type_2_ortho(ntests=500, verbose=0):
    """Test function ``reduce_type2_ortho`` """
    for n, v in enumerate(type2_ortho_testdata(ntests)):
        if verbose:
            print(" \nTest %d, v = %s, subtype  =%s" %
                  (n + 1, hex(v), hex(gen_leech2_subtype(v))))
        op = reduce_type2_ortho(v, verbose)
        w = gen_leech2_op_word(v, op, len(op))
        assert w & 0xffffff == 0x800200, hex(w)
        b = gen_leech2_op_word(BETA, op, len(op))
        assert b == BETA
        a = np.zeros(6, dtype=np.uint32)
        l = gen_leech2_reduce_type2_ortho(v, a)
        if l < 0:
            err = "Error %s in function gen_leech2_reduce_type2_ortho"
            raise ValueError(err % hex(l & 0xffffffff))
        a = a[:l]
        assert list(a) == list(op), ((a), (op))
Пример #4
0
def mul_v2(v2, g):
    """Multiply vector in Leech lattice mod 2 by element of ``G_x0``

    Here parameter ``v2`` is an element of the Leech lattice mod 2 in
    Leech lattice encoding. Parameter ``g`` is an element of 
    the group ``G_x0`` endodes as an instance of class |MM| or |MM0|.

    The function returns the product ``v * g`` in  Leech lattice 
    encoding.
    """
    result = gen_leech2_op_word(v2, g._data, g.length)
    assert result & 0xfe000000 == 0, hex(result)
    return result
Пример #5
0
 def __mul__(self, other):
     if isinstance(other, XLeech2):
         return XLeech2(gen_leech2_mul(self.value, other.value))
     elif isinstance(other, AbstractMMGroupWord):
         data = other.mmdata
         v = gen_leech2_op_word(self.value, data, len(data))
         return XLeech2(v)
     elif isinstance(other, Integral):
         if abs(other) == 1:
             return XLeech2(self.value ^ ((other & 2) << 23))
         elif other == 0:
             return XLeech2(0)
         return NotImplemented
     else:
         return NotImplemented
Пример #6
0
def conj_x_by_word(x, g_mm):
    """Conugate x ith a word of elments in the Clifford group

    Here :math:`x` is an element of the normal subgroup :math:`Q_x0`
    of :math:`G_x0`, and :math:`g_{mm}` is an element of the 
    subgroup :math:`G_x0` of the monster.

    :math:`x` is given as an integer in **Leech lattice
    represention** and :math:`g_{mm}` is given as an element
    of the group  object ``mmgroup.MM``, which is the standard 
    instance of the monster group.

    The function returns :math:`g_{mm}^{-1} x g_{mm}` as an
    integer in **Leech lattice represention**.
    """
    w_g = g_mm.mmdata
    return gen_leech2_op_word(x, w_g, len(w_g))
Пример #7
0
def test_reduce_axis(verbose=0):
    for i, (v, std_axis) in enumerate(make_axis_testcases()):
        if verbose:
            print("\nTest case", i, ", std_axis =", bool(std_axis))
        r, axis = reduce_axis(v.copy(), std_axis, verbose)
        g = MM0('a', r)
        if std_axis:
            assert v * g == V_START
            assert axis == 0x200
        else:
            v1 = v * g
            assert mm_reduce_2A_axis_type(v1.data) >> 24 == 0x21
            a_g = np.zeros(20, dtype=np.uint32)
            r1 = gen_leech2_reduce_type2(axis, a_g)
            g2 = MM0('a', a_g[:r1])
            v2 = v1 * g2
            assert v2 in [V_START, V_OPP]
            axis2 = gen_leech2_op_word(axis, a_g, r1)
            assert axis2 & 0xffffff == 0x200
            assert v_leech2_adjust_sign(v2.data, axis2) == axis2

        g1, axis_found = reduce_v_axis_C(v, std_axis)
        assert g1 == g
        assert axis == axis_found
Пример #8
0
def conjugate_gen_xi(x, elem):
    data = [(TAGS[tag] << 28) + (d & 0xfffffff) for tag, d in elem]
    a = np.array(data, dtype = np.uint32)
    return gen_leech2_op_word(x, a, len(a))
Пример #9
0
def op_axis(axis, r):
    transformed_axis = gen_leech2_op_word(axis, r, len(r))
    if axis == v_start:
        assert transformed_axis == axis
    return transformed_axis