Exemple #1
0
def rand_xleech2_type(vtype):
    if vtype in [3, 4]:
        for i in range(1000):
            v = randint(0, 0x1ffffff)
            if gen_leech2_type(v) == vtype:
                return v
        raise ValueError(ERR_XL_RAND)
    if vtype == 0:
        return 0
    if vtype == 2:
        ve = randint(300, 98579)
        vs = mm_aux_index_extern_to_sparse(ve)
        sign = randint(0, 1)
        return mm_aux_index_sparse_to_leech2(vs) ^ (sign << 24)
    raise ValueError(ERR_XL_RAND)
Exemple #2
0
    def index_to_short_mod2(tag, i0=-1, i1=-1):
        r"""Convert index to a short Leech lattice vector modulo 2

        The tuple ``(tag, i0, i1)`` is interpreted as a basis vector
        as in method ``index_to_short``.
 
        Some but not all of these basis vectors correspond to short
        vector in the Leech lattice up to sign. If this is the
        case then the function returns a short vector of the Leech
        lattice modulo 2 as an integer. 

        The function raises ValueError if the basis vector in 
        :math:`\rho_p` does not correspond to a short vector.
        """
        i = MMSpace.index_to_sparse(tag, i0, i1)
        i2 = mm_aux_index_sparse_to_leech2(i)
        if i2 != 0:
            return i2
        err = "Vector does not map to short Leech lattice vector"
        raise ValueError(err)
Exemple #3
0
def type2_testvectors():
    """Yield short test vectors in the Leech lattice mod 2

    The function yields pairs ``(v2, vtype)``, where ``v2 ``is a short
    vector (of type 2) in the Leech lattice mod 2 in **Leech lattice
    encoding**, and ``vtype`` is the subtype of ``v``.

    This function uses function from file mm_aux.c for converting
    random indices of the rep 196884x to short vectors.
    """
    TEST_PARS = [
        (300, 2 * 276, 50, 0x20),
        (852, 759 * 64, 500, 0x22),
        (49428, 2048 * 24, 500, 0x21),
    ]
    for (start, nvectors, ntests, vtype) in TEST_PARS:
        for i in range(ntests):
            v_extern = randint(start, start + nvectors - 1)
            v_sparse = mm_aux_index_extern_to_sparse(v_extern)
            v2 = mm_aux_index_sparse_to_leech2(v_sparse)
            assert v2 != 0, (v_extern, hex(v_sparse), hex(v2))
            #print(v_extern, hex(v_sparse), hex(v2), hex(vtype))
            yield v2, vtype
Exemple #4
0
def value_from_ploop(ploop=0, cocode=None, *args):
    c = Cocode(cocode).ord if cocode else 0
    if isinstance(ploop, Integral):
        d = ploop & 0x1ffffff
    elif isinstance(ploop, PLoop):
        d = ploop.value & 0x1fff
        d = (d << 12) ^ mat24.ploop_theta(d)
    elif isinstance(ploop, XLeech2):
        d = ploop.value
    elif isinstance(ploop, Cocode):
        d = ploop.value & 0xfff
    elif isinstance(ploop, AbstractMMGroupWord):
        d = MM_to_Q_x0(ploop)
    elif isinstance(ploop, str):
        if len(ploop) == 1 and ploop in "BCTXES":
            d = 0
            a = tuple_to_sparse(0xff, ploop, cocode, *args)
            if len(a) == 1:
                a0 = a[0]
                d = mm_aux_index_sparse_to_leech2(a0)
                a0 &= 0xff
                if a0 == 0xfe:
                    d ^= 0x1000000
                elif a0 != 1:
                    d = 0
            if d:
                return d
        if ploop == "r":
            if cocode is None:
                return randint(0, 0x1ffffff)
            elif cocode in [0, 2, 3, 4]:
                return rand_xleech2_type(cocode)
        raise ValueError(ERR_XL_TUPLE)
    else:
        return TypeError(ERR_XL_TYPE % type(ploop))
    return d ^ c
Exemple #5
0
def rand_leech2():
    ext = 300 + randint(0, 98279)
    sp = mm_aux_index_extern_to_sparse(ext)
    return mm_aux_index_sparse_to_leech2(sp)
def map_x(x_index):
    v2 = mm_aux_index_sparse_to_leech2(x_index)
    return ((v2 & 0xfff) << 12) | ((v2 >> 12) & 0xfff)
from random import randint #, shuffle, sample

import numpy as np
import pytest

from mmgroup import MM0, MMSpace, MMV
from mmgroup.mm import mm_aux_index_extern_to_sparse
from mmgroup.mm import mm_aux_index_sparse_to_leech2
from mmgroup.mm import mm_aux_index_leech2_to_sparse
from mmgroup.mm15 import op_eval_X_find_abs as mm_op15_eval_X_find_abs

LEECH_SHORT = np.zeros(98280, dtype = np.int32)
for i in range(98280):
    sparse = mm_aux_index_extern_to_sparse(300 + i)
    l1 = LEECH_SHORT[i] = mm_aux_index_sparse_to_leech2(sparse)
    sparse1 = mm_aux_index_leech2_to_sparse(l1)
    assert sparse == sparse1, [hex(x) for x in (i, sparse, l1, sparse1)]

V = MMV(15)

v = V('R')




def from_v(v_abs, value, value1 = 0):
    if not value1:
        a = [LEECH_SHORT[i] for i in range(98280) if v_abs[i] == value]
        return np.array(a, dtype = np.uint32)
    else: