Exemple #1
0
def test_elem_to_word(ntests=50, verbose=0):
    print("Test function test_elem_to_word()")
    for i, w in enumerate(make_testwords(monomial=False, ntests=ntests)):
        m = MM0(w)
        if verbose:
            print("\nTest %d:" % (i + 1))
            print("Testing word\n%s" % m)
        elem = Xsp2_Co1(w)
        if i < 100:
            assert m == MM0(elem)
        if verbose:
            print("This is element\n%s" % elem)
        word = elem_to_word(elem, verbose > 1)
        if verbose:
            print("Reduced word\n%s" % MM0('a', word))
        elem_1 = Xsp2_Co1('a', word)
        if verbose:
            print("Recomputed element\n%s" % elem_1)
        ok = (elem == elem_1).all()
        if verbose or not ok:
            if not ok:
                print("Instead of to 1, the element reduces to:")
                print(elem * elem_1**(-1))
                err = "WTF"
                raise ValueError(err)
        word_C = elem_to_word_C(elem)
        assert (word_C == word).all(), (word_C, word)
        word1_C = reduce_word_C(m.mmdata)
        assert (word1_C == word).all(), (word1_C, word)
Exemple #2
0
def test_vector(verbose = 0):
    for ntest, (x4096, x24, g) in enumerate(create_test_vectors()):
        if verbose:
            print("\nTEST %s" % (ntest+1))
            print("vector =", x4096, x24)
        vm = x24[0] * Space_ZY.unit(x4096, x24[1:])
        vm_old = vm.copy()
        if verbose:
            print("vm =", vm.as_tuples())
            print("vm =", vm)
            vm.dump()
        v3 = vm.as_mmspace_vector() 
        if verbose:
            print("g =", g)
        g3 = MMGroup3(g)
        try:
            gm = Xsp2_Co1(g)
        except ValueError:
            print("\nError in constructing group element g")
            print("Debug data pool:\n", 
                    [hex(x) for x in get_error_pool(15)])
            raise
        gm_old = gm
        if verbose:
            print("gm = ", gm)
            print("g3 = ", g3)
        try:
            wm = vm * gm
            if verbose:
                print("w = vm * gm = ", wm)
        except ValueError:
            print("Debug data pool:\n", 
                    [hex(x) for x in get_error_pool(15)])
            map_v3(x24, gm, wm.short3, verbose = 1)
            raise
        w3_op =  wm.as_mmspace_vector()
        w3_mult =  v3 * g3
        if verbose:
            print("w3_op =", w3_op)
            print("w3_op data =")
            wm.dump()
            print("w3_mult =", w3_mult)
        ok =  w3_op == w3_mult 
        assert vm == vm_old
        assert gm == gm_old
        if not ok:
            print("\nError in TEST %s" % (ntest+1))
            print("vector =", x4096, x24)
            print("v =", hex(x4096), "(x)", x24)
            print("rep of v:", vm)
            print("v =", v3)
            print("g = ", g)
            print("rep of g:", gm)
            print("Output w = v * g\nexpected:", w3_mult)
            print("obtained:", w3_op)
            print("rep:", wm)
            map_v3(x24, gm, verbose = 1)
            if not ok:
               ERR = "Vector multiplication test in group G_{x0} failed"
               raise ValueError(ERR)
Exemple #3
0
def test_monomial_to_word(ntests=10, verbose=0):
    print("Test function test_monomial_to_word()")
    for i, w in enumerate(make_testwords()):
        if verbose:
            print("\nTest %d:" % (i + 1))
            m = MM0(w)
            print("Testing word\n%s" % m)
        elem = Xsp2_Co1(w)
        if verbose:
            print("This is element\n%s" % elem)
        data_i = monomial_to_word(elem, verbose > 1)
        elem_0 = elem.copy().mul_data(data_i)
        try:
            x = elem_0.as_xsp()
            ok = True
        except:
            raise
            ok = False
        if verbose or not ok:
            m_i = MM0("a", data_i)
            print("Reduced inverse word\n%s" % str(m_i))
            if not ok:
                print("Product with inverse\n%s" % elem_0)
                err = "WTF"
                raise ValueError(err)
            else:
                print("Result is:", hex(x))
            print("Test %d ok" % (i + 1))
        data_C = monomial_to_word_C(elem)
        assert (data_C == data_i).all(), (data_C, data_i)
Exemple #4
0
def xsp2co1_fast_half_order(wx):
    assert isinstance(wx, Xsp2_Co1)
    buf = np.zeros(10, dtype=np.uint32)
    m = MM0(wx)
    res = chk_qstate12(xsp2co1_half_order_word(m._data, m.length, buf))
    o, l = divmod(res, 256)
    assert 0 <= l <= 10
    out = Xsp2_Co1()
    chk_qstate12(xsp2co1_mul_elem_word(out._data, buf, l))
    return o, out
Exemple #5
0
def test_group(verbose = 0):
    unit = Xsp2_Co1()
    for ntest, (g1, g2) in enumerate(create_test_elements()):
        gm1 = Xsp2_Co1(g1)    
        gm2 = Xsp2_Co1(g2)    
        gm3_ref = Xsp2_Co1(g1 + g2)    
        gm3 = gm1 * gm2
        ok = gm3 == gm3_ref 
        if verbose or not ok:
            print("\nTEST %s" % (ntest+1))
            print("element g1 =", g1)
            print("element g2 =", g2)
            print("element g1 * g2")
            print("expected:", gm3_ref)
            print("obtained:", gm3)
            if not ok:
                ERR = "Multiplication in group G_{x1} failed"
                raise ValueError(ERR)
        gq1 = gm1.qs
        gq2 = gm2.qs
        gq3 = gm3.qs  
        gq3_ref = gq1 @ gq2
        sign_q  = int(gq3 == -gq3_ref)
        assert sign_q  or  gq3_ref == gq3       

        gleech1 = gm1.leech_op
        gleech2 = gm2.leech_op
        gleech3 = gm3.leech_op  
        gleech3_ref = gleech1 @ gleech2 / 8
        sign_leech  = int((gleech3 == -gleech3_ref).all())
        assert  (gleech3 @ gleech3.T == 64 * np.eye(24)).all()       
        assert sign_leech  or  (gleech3_ref == gleech3).all()

                
        gm1i =  gm1**(-1) 
        ok = gm1 * gm1i == unit
        if verbose or not ok:
            print("g1\n",  gm1) 
            print("g1 ** -1 obtained\n",  gm1**(-1)) 
            if not ok:            
                ERR = "Inversion in group G_{x1} failed"
                raise ValueError(ERR)
Exemple #6
0
def one_benchmark(ntests):
    tags = "dxyplplplplplp"
    samples = [Xsp2_Co1(*rand_G_x0_testword(tags)) for i in range(400)]
    a = np.zeros(10, dtype=np.uint32)
    t_start = time.process_time()
    for elem in samples:
        elem_data = elem._data
        for i in range(ntests):
            assert xsp2co1_elem_to_word(elem_data, a) >= 0
    t = time.process_time() - t_start
    return t / (ntests * len(samples))
Exemple #7
0
def xsp2co1_ref_power(wx, e):
    """Foolproof exponentiation in G_x0"""
    assert isinstance(wx, Xsp2_Co1)
    if e > 1:
        h = xsp2co1_ref_power(wx, e >> 1)
        return h * h * wx if e & 1 else h * h
    if e == 1:
        return wx
    if e == 0:
        return Xsp2_Co1()
    return (wx**(-1))**(-e)
Exemple #8
0
def test_elem_power(ntests=50, verbose=0):
    print("Test function computation a of power in G_x0")
    for i, w in enumerate(make_testwords(monomial=False, ntests=ntests)):
        e = randint(-2**35, 2**35)
        #print("Test ", i, "e", e)
        wx = Xsp2_Co1(w)
        power = xsp2co1_fast_power(wx, e)
        ref_power = xsp2co1_ref_power(wx, e)  # wx ** e
        assert power == ref_power, e
        if i < 10:
            e1 = i - 5
            power = xsp2co1_fast_power(wx, e1)
            assert power == xsp2co1_ref_power(wx, e1)
Exemple #9
0
def test_elem_order(ntests=50, verbose=0):
    neutral = Xsp2_Co1()
    print("Test function computation of order in G_x0")
    for i, w in enumerate(make_testwords(monomial=False, ntests=ntests)):
        wx = Xsp2_Co1(w)
        o_ref = xsp2co1_ref_order(wx)
        o = xsp2co1_fast_order(wx, via_word=i & 1)
        ok = o == o_ref
        if verbose or not ok:
            print("Test", i + 1)
            print("g = ", MM(*w))
            print("order =", o)
            if not ok:
                print("expected:", o_ref)
                raise ValueError("Computation or order has failed")

        o1, invol = xsp2co1_fast_half_order(wx)
        assert o1 == o
        if (o & 1):
            assert invol == neutral
        else:
            assert xsp2co1_fast_power(wx, o >> 1) == invol
            assert invol * invol == neutral
Exemple #10
0
def ref_conjugate(x, elem):
    elem_l = Xsp2_Co1(elem)
    mat_l = elem_l.qs.gate_h(0x800800)
    mat_x = qs_pauli_matrix(12, x)
    mat_res = mat_l.inv() @ mat_x @ mat_l
    return mat_res.pauli_vector()
Exemple #11
0
def mm_conjugate_involution(g, check=True, ntrials=20, verbose = 0):
    """Conjugte an involution in the monster to a standard element

    Given an involution :math:`g` in the monster group, the function 
    tries to find an element :math:`h` with :math:`h^{-1} g h = z`,
    where :math:`z` a standard representative of the involution class
    as in method ``conjugate_involution`` of class ``Xsp2_Co1``.
    """
    if not isinstance(g, (MM,MM0)):
        err = "Object must be element of the monster of type MM"
        raise TypeError(err)
    m = g.group
    m_1, z = m(), m('x', 0x1000)
    in_G_x = g.in_G_x0()
    if (verbose or check) and g*g != m_1:
        err = "Element is not an involution in the monster group"
        raise ValueError(err)
    if in_G_x:
        return Xsp2_Co1(g).conjugate_involution(m)
    if verbose:
        print("Function mm_conjugate_involution: conjugate g to the centre")
        print("g=", g)
    for i in range(ntrials):
        if verbose:
             print("\nmm_conjugate_involution trial", i)
        s = m('r', 1 + max(3, (i >> 2))) if i else m_1
        x = g**s
        o, y = (x * z).half_order(60)
        if verbose:
           print("x = g**s; s =", s)
           print("x * z has order o =", (x * z).order())
        if o == 0 or o & 1 or y is None:
            continue
        # Here o is even and y = (x * z)**(o/2) is an involution,
        # and y commutes with x and with z. Thus y is in G_x0.
        # Next we represent y as an element of G_x0.
        assert y.in_G_x0()
        if verbose:
            assert (x*z)**(o>>1) == y
            assert y**2 == m_1
            print("y = (x*z)**(o/2) = ", y)
            print("y has characters",  y.chi_G_x0())
        # Try to conjugate y to the central element z.
        # Continue the loop if this fails.
        try:
            itype = 3
            itype, h1 = Xsp2_Co1(y).conjugate_involution(m)
            assert itype == 2
        except (ValueError, AssertionError):
            if verbose:
                print("itype should be 2 but found %d" % itype) 
            continue
        # Now y**h1 = z.
        if verbose:
            print("itype=", itype)
            print("h1=", h1)
            y_conj = y**h1
            y_conj.in_G_x0()
            assert y_conj == z, y_conj
        x1 = x**h1
        # x1 commutes with y**h1 = z; so x1 is in G_x0.
        # Next we represent x1 as an element of G_x0
        x1.in_G_x0()
        if verbose:
            print("x1=", x1)
            print("x1 has characters",  x1.chi_G_x0())
        # Try to conjugate x1 to the central element z.
        # Raise ValueError the loop if this fails.
        itype, h2 = Xsp2_Co1(x1).conjugate_involution(m)
        # Now x1**h2 = x**(h1*h2) = g**(s*h1*h2) = z.
        # So we may return s*h1*h2
        t = (s*h1*h2).reduce()
        t.in_G_x0()
        t.reduce()
        if verbose:
            print("Result found (itype = %s):" % itype)
            print(t)
            print("Function mm_conjugate_involution terminated successfully.\n")
        return itype, t
    err = "Conjugation of element to central involution failed"
    raise ValueError(err)
Exemple #12
0
def xsp2co1_fast_power(wx, e):
    """The safe exponentiation in G_x0 to be tested"""
    assert isinstance(wx, Xsp2_Co1)
    power = Xsp2_Co1()
    chk_qstate12(xsp2co1_power_elem(wx._data, e, power._data))
    return power