Beispiel #1
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
Beispiel #2
0
    def vector_mul_exp(self, v1, g, e, break_g=False):
        """Compute product v1 * g**e of vector v1 and group word g.

        Here v1 is a vector in this space, e is an integer, g is a 
        group element, and  v1 is replaced by v1 * g**e.

        This method should be  called for elements v1 of the space
        'self' and for elements g of the group 'self.group' only.

        If break_g is True, each factor g is multiplied with v1
        separately. Otherwise, the expression  g**e  may be
        optimized. This option is mainly for benchmarking.

        After applying this function to vecter v1, the vector
        v1 has an attribute v1.last_timing containing the run
        time of the C part of this operation in seconds.
        """
        work = mm_vector(v1.p)
        assert v1.space == self
        assert -1 << 31 < e < 1 << 31
        assert isinstance(g, MM0)
        length = g.length
        if break_g:
            g._extend(length + 1)
            g._data[length] = 0x70000000
            length += 1
        t_start = time.perf_counter()
        #t_start = default_timer()
        v1.ops.op_word(v1.data, g._data, length, e, work)
        v1.last_timing = time.perf_counter() - t_start
        #v1.last_timing = default_timer() - t_start
        return v1
Beispiel #3
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")
Beispiel #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])
Beispiel #5
0
def reduce_v_axis_C(v, std_axis):
    va = mm_vector(15, 2)
    vc, work = va[0].data, va[1].data
    mm_op15_copy(v.data, vc)
    r = np.zeros(200, dtype=np.uint32)
    res = mm_reduce_vector_vp(vc, std_axis, r, work)
    if not 0 < res <= 200:
        raise ValueError(ERR_REDUCE_V_AXIS, res)
    g = MM0('a', r[:res])
    axis_found = r[res - 1]
    assert axis_found & 0xfe000000 == 0x84000000
    axis_found &= 0x1ffffff
    return g, axis_found
Beispiel #6
0
    def imul_group_word(self, v1, g):
        """Return product v1 * g of vector v1 and group word g.

        v1 may be destroyed.

        This method is called for elements v1 of the space
        'self' and for elements g of the group 'self.group' only.
        """
        work = mm_vector(v1.p)
        if isinstance(g, AbstractMMGroupWord):
            a = g.mmdata
            v1.ops.op_word(v1.data, a, len(a), 1, work)
            return v1
        err = "Multiplicator for MM vector must be int or in MM group"
        raise TypeError(err)
Beispiel #7
0
def mm_reduce_v_baby_axis_C(v, axis=V_START, mode=0):
    va = mm_vector(15, 2)
    vc, work = va[0].data, va[1].data
    mm_op15_copy(v.data, vc)
    r = np.zeros(200, dtype=np.uint32)
    res = mm_reduce_vector_shortcut(1, mode, axis, r)
    if res < 0:
        raise ValueError(ERR_REDUCE_MM_V_BABY_AXIS % res)
    res = mm_reduce_vector_vm(vc, r, work)
    if res < 0:
        raise ValueError(ERR_REDUCE_MM_V_BABY_AXIS % res)
    g = MM0('a', r[:res])
    axis_found = r[res - 1]
    assert axis_found & 0xfe000000 == 0x86000000
    axis_found &= 0x1ffffff
    return g, axis_found
Beispiel #8
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])
Beispiel #9
0
 def __init__(self, p, tag=0, i0=None, i1=None):
     self.ops = get_mm_ops(p)
     self.p = p
     self.data = mm_vector(p)
     add_vector(self, tag, i0, i1)