Ejemplo n.º 1
0
def mm_order(g):
    w, order = ORDER_VECTOR.copy(), 0
    work = mm_vector(15)
    while order < 120:
        mm_op15_word(w, g.mmdata, len(g.mmdata), 1, work)
        order +=1
        if mm_op15_compare(w, ORDER_VECTOR) == 0:
            return order
    raise ValueError("Order computation failed")
Ejemplo n.º 2
0
def py_check_mm_in_g_x0(g, mode = 0):
    """Check if ``g`` is in the subgroup ``G_x0`` of the monster
   
    If ``g`` is in the subgroup ``G_x0`` of the monster then the
    function changes the word representing ``g`` to a (uniquely 
    defined) word in the generators of the subgroup ``G_x0`` and
    returns ``g``.  
    
    Otherwise the function does not change ``g`` and returns ``None``.
    
    ``g`` must be an instance of class 
    ``mmgroup.mm_group.MMGroupWord``.
    """
    global err_in_g_x0_py
    err_in_g_x0_py = 0
    assert isinstance(g, (MM0, MM))
    v = ORDER_VECTOR
    w = mm_vector(15)
    work = mm_vector(15)
    mm_op15_copy(v, w)
    res = mm_op15_word(w, g.mmdata, len(g.mmdata), 1, work)
    assert res == 0

    g1i = find_in_G_x0(w)
    if g1i is None:
        return None
    res = mm_op15_word(w, g1i, len(g1i), 1, work)
    assert res == 0

    x = np.zeros(0, dtype = np.uint32) if mode & 4 else find_in_Q_x0(w)
    if x == None:
        return None

    g2i = np.array([0x90000000 + (x & 0xfff), 
        0xB0000000 + ((x >> 12) & 0x1fff)], dtype = np.uint32)
    res = mm_op15_word(w, g2i, 2, 1, work)  
    assert res == 0   
    g1i = np.append(g1i, g2i)
 
    assert res == 0   
    if mm_op15_compare(v, w):
        #print("vW", v, "\n",  w)
        err_in_g_x0_py = 9
        return None

    g._extend(11)
    g.length = length = len(g1i)
    g.reduced = 0
    if mode & 1 == 0:
        for i in range(length):
            g._data[i] = g1i[length - 1 - i] ^ 0x80000000
    else:
        for i in range(length):
            g._data[i] = g1i[i] 
    g.reduce()
    return g
Ejemplo n.º 3
0
def reduce_G_x0(g, mode=0):
    global reduce_time
    va = mm_vector(15, 2)
    v, work = va[0].data, va[1].data
    r = np.zeros(256, dtype=np.uint32)
    g1, n = g.mmdata, len(g.mmdata)

    t_start = time.perf_counter()
    mm_reduce_load_axis(v, 0)
    res = mm_op15_word(v, g1, n, 1, work)
    if res < 0: raise ValueError(ERR_GX0 % res)
    res = mm_reduce_vector_vp(v, mode, r, work)
    if res < 0: raise ValueError(ERR_GX0 % res)

    mm_reduce_load_axis(v, 1)
    res = mm_op15_word(v, g1, n, 1, work)
    if res < 0: raise ValueError(ERR_GX0 % res)
    res = mm_reduce_vector_vm(v, r, work)
    if res < 0: raise ValueError(ERR_GX0 % res)
    reduce_time = time.perf_counter() - t_start
    return MM0('a', r[:res])
Ejemplo n.º 4
0
def check_mm_in_g_x0(g, mode = 0):
    global err_in_g_x0_c
    assert isinstance(g, (MM0, MM))
    w = mm_vector(15)
    work = mm_vector(15, 2).ravel()
    mode = (mode | 8) & ~2
    v = ORDER_VECTOR
    mm_op15_copy(v, w)
    res = mm_op15_word(w, g.mmdata, len(g.mmdata), 1, work)
    assert res == 0
    h = np.zeros(11, dtype = np.uint32)
    res = mm_order_check_in_Gx0(w, h, mode, work)
    if res < 0:
        s = "mm_order_check_in_Gx0 failed with error %d"
        raise ValueError(s % res)
    if res >= 0x100:
         err_in_g_x0_c = res
         return None
    return MM0('a', h[:res])
Ejemplo n.º 5
0
def reduce_baby_axis(vector, axis=v_start, verbose=0):
    v = vector.data
    #V = vector.space
    work = V()
    vA = np.zeros(24 * 4, dtype=np.uint64)
    r = np.zeros(120, dtype=np.uint32)
    len_r = 0
    if verbose: print("Function reduce_baby_axis")
    for i in range(5):
        vt = mm_reduce_2A_axis_type(v)
        assert vt
        type = (vt >> 24) & 0xff
        vt &= 0xffffff
        if verbose:
            print("type =", hex(type), ", vt =", hex(vt), ", A(v0) =",
                  mm_op15_eval_A(v, axis), ", axis =", hex(axis))
        if type == 0xA1:  # case 10A
            v0 = short(v, 3)[0]
            v2all = short(v, 1)
            v2all = [w ^ v0 for w in v2all]
            v4 = find_ortho_short(v2all, axis)
            t_types = [0x61]
        elif type == 0x63:  # case 6C
            v2all = span(v, 3, verbose)
            v4 = find_ortho_short(v2all, axis)
            t_types = [0x41]
        elif type == 0x61:  # case 6A
            v2all = short(v, 5)
            v2all = [w ^ vt for w in v2all]  # if leech_type(w ^vt) == 4]
            v4 = find_ortho_short(v2all, axis)
            t_types = [0x41, 0x43]
        elif type == 0x43:  # case 4C
            v2all = radical(v, 1, verbose)
            v4 = find_ortho_short(v2all, axis)
            t_types = [0x22]
        elif type == 0x42:  # case 4B
            v2all = radical(v, 1, verbose)
            v4 = find_ortho_short(v2all, axis)
            t_types = [0x22]
        elif type == 0x41:  # case 4A
            v4 = vt
            assert leech_type(v4) == 4
            t_types = [0x21]
        elif type == 0x22:  # case 2B
            if mm_op15_eval_A(v, axis) in [0, 8]:
                v2all = span(v, 4, verbose)
                v4 = find_ortho_short(v2all, axis)
                t_types = [0x21]
            else:
                raise ValueError("WTF 2B")
        elif type == 0x21:  # case 2A
            if verbose:
                print("v has type 0x21, axis = %s, eval_A = %d" %
                      (hex(axis), mm_op15_eval_A(v, axis)))
            if mm_op15_eval_A(v, axis) == 0:
                vt ^= axis
                r1 = gen_leech2_reduce_type4(vt, r[len_r:])
                assert r1 >= 0
                mm_op15_word(v, r[len_r:], r1, 1, work.data)
                axis = op_axis(axis, r[len_r:len_r + r1])
                len_r += r1
                vt = mm_reduce_2A_axis_type(v) & 0xffffff
                vt = v_leech2_adjust_sign(v, vt)
                vt = gen_leech2_mul(vt, axis)
                assert vt & 0xffffff == 0x800000
                e = 1 + (vt >> 24)
                if verbose: print("e", e)
                r[len_r] = 0xD0000003 - e
                mm_op15_word(v, r[len_r:], 1, 1, work.data)
                axis = op_axis(axis, r[len_r:len_r + 1])
                len_r += 1
            else:
                assert mm_op15_eval_A(v, axis) == 4
            vt = mm_reduce_2A_axis_type(v) & 0xffffff
            vt = v_leech2_adjust_sign(v, vt)
            assert (vt ^ axis) & 0x1ffffff == 0x1000000, (hex(vt), hex(axis))
            if verbose:
                print("Function reduce_baby_axis terminated successfullly")
            return r[:len_r], axis
        else:
            raise ValueError("WTF1")

        r1 = gen_leech2_reduce_type4(v4, r[len_r:])
        assert r1 >= 0, (hex(v4), )
        mm_op15_word(v, r[len_r:], r1, 1, work.data)
        axis = op_axis(axis, r[len_r:len_r + r1])
        len_r += r1
        ok = False
        for e in (1, 2):
            mm_op15_t_A(v, e, vA)
            t = mm_reduce_2A_axis_type(vA) >> 24
            if verbose: print("e", e, hex(t))
            if t in t_types:
                r[len_r] = 0xD0000003 - e
                mm_op15_word(v, r[len_r:], 1, 1, work.data)
                axis = op_axis(axis, r[len_r:len_r + 1])
                len_r += 1
                ok = True
                break
        if not ok:
            raise ValueError("WTF2")

    raise ValueError("WTF3")
Ejemplo n.º 6
0
def reduce_axis(vector, std_axis=1, verbose=0):
    v = vector.data
    #V = vector.space
    work = V()
    vA = np.zeros(24 * 4, dtype=np.uint64)
    r = np.zeros(120, dtype=np.uint32)
    len_r = 0
    if verbose: print("Function reduce_axis")
    for i in range(5):
        vt = mm_reduce_2A_axis_type(v)
        assert vt
        type = (vt >> 24) & 0xff
        vt &= 0xffffff
        if verbose: print("type", hex(type))
        if type == 0xC3:  # case 12C
            v2all = radical(v, 7, verbose)
            v4 = find_type4(v2all)
            t_types = [0x42, 0x61]
        elif type == 0xA2:  # case 10B
            v2all = radical(v, 4, verbose)
            v4 = find_type4(v2all)
            t_types = [0x42, 0x43]
        elif type == 0xA1:  # case 10A
            v0 = short(v, 3)[0]
            v2all = short(v, 1)
            v2all = [w ^ v0 for w in v2all]
            v4 = find_type4(v2all)
            t_types = [0x61]
        elif type == 0x82:  # case 8B
            v2all = short(v, 1)
            v2_0 = v2all[0]
            v2all = [w ^ v2_0 for w in v2all]
            v4 = find_type4(v2all)
            t_types = [0x41]
        elif type == 0x66:  # case 6F
            v2all = radical(v, 7, verbose)
            v4 = find_type4(v2all)
            t_types = [0x43]
        elif type == 0x63:  # case 6C
            v2all = span(v, 3, verbose)
            v4 = find_type4(v2all)
            t_types = [0x41]
        elif type == 0x61:  # case 6A
            v2all = short(v, 5)
            v2all = [w ^ vt for w in v2all]
            v4 = find_type4(v2all)
            t_types = [0x41]
        elif type == 0x43:  # case 4C
            v2all = radical(v, 1, verbose)
            v4 = find_type4(v2all)
            t_types = [0x22]
        elif type == 0x42:  # case 4B
            v2all = radical(v, 1, verbose)
            v4 = find_type4(v2all)
            t_types = [0x22]
        elif type == 0x41:  # case 4A
            v4 = vt
            t_types = [0x21]
        elif type == 0x22:  # case 2B
            v2all = span(v, 4, verbose)
            v4 = find_type4(v2all)
            t_types = [0x21]
        elif type == 0x21:  # case 2A
            if not std_axis:
                vt = v_leech2_adjust_sign(v, vt)
                if verbose:
                    print("Function reduce_axis terminated successfullly")
                return r[:len_r], vt
            r1 = gen_leech2_reduce_type2(vt, r[len_r:])
            assert r1 >= 0
            mm_op15_word(v, r[len_r:], r1, 1, work.data)
            len_r += r1
            ind = mm_aux_get_mmv1(15, v, (24 + 3) * 32 + 2)
            if (ind != 15 - 2):
                r[len_r] = 0xB0000200
                mm_op15_word(v, r[len_r:], 1, 1, work.data)
                len_r += 1
            assert mm_op15_compare(v, V_START.data) == 0
            if verbose:
                print("Function reduce_axis terminated successfullly")
            return r[:len_r], 0x200
        else:
            raise ValueError("WTF1")

        r1 = gen_leech2_reduce_type4(v4, r[len_r:])
        assert r1 >= 0
        mm_op15_word(v, r[len_r:], r1, 1, work.data)
        len_r += r1
        ok = False
        for e in (1, 2):
            mm_op15_t_A(v, e, vA)
            t = mm_reduce_2A_axis_type(vA) >> 24
            if verbose: print("e", e, hex(t))
            if t in t_types:
                r[len_r] = 0xD0000003 - e
                mm_op15_word(v, r[len_r:], 1, 1, work.data)
                len_r += 1
                ok = True
                break
        if not ok:
            raise ValueError("WTF2")

    raise ValueError("WTF3")