def _easy_prime_decomp(p, polynomial):
    """
    prime decomposition by factoring polynomial
    """
    f = algfield.fppoly(polynomial, p)
    d = f.degree()
    factor = f.factor()
    p_alg = algfield.BasicAlgNumber([[p] + [0] * (d - 1), 1], polynomial)
    if len(factor) == 1 and factor[0][1] == 1:
        return [(module.Ideal_with_generator([p_alg]), 1,
                 factor[0][0].degree())]
    else:
        dlist = []
        for i in range(len(factor)):
            basis_list = []
            for j in range(d):
                if factor[i][0][j] == 0:
                    basis_list.append(0)
                else:
                    basis_list.append(factor[i][0][j].toInteger())
            prime_ideal = module.Ideal_with_generator(
                [p_alg,
                 algfield.BasicAlgNumber([basis_list, 1], polynomial)])
            dlist.append((prime_ideal, factor[i][1], factor[i][0].degree()))
        return dlist
def _check_H(p, H, field, gamma_mul):
    """
    If H express the prime ideal, return (H, f),
    where f: residual degree.
    Else return some column of M_1 (not (1,0,..,0)^t).
    """
    F_p = finitefield.FinitePrimeField(p)
    if H == None:
        f = field.degree
    else:
        f = H.row - H.column # rank(A), A.column
    # CCANT Algo 6.2.9 step 10-11
    # step 10
    B = matrix.unitMatrix(f, F_p)
    M_basis = []
    for j in range(1, f + 1):
        alpha_pow = _pow_by_base_mul(B[j], p, gamma_mul, f)
        alpha_pow -= B[j]
        M_basis.append(alpha_pow)
    M_1 = matrix.FieldMatrix(f, f, M_basis).kernel()
    # step 11
    if M_1.column > 1: # dim(M_1) > 1
        return M_1[M_1.column]
    else:
        H_simple = _two_element_repr_prime_ideal(
                   p, H.map(lambda x: x.getResidue()), field, f)
        p_alg = algfield.BasicAlgNumber([[p] + [0] * (field.degree - 1), 1], 
                field.polynomial)
        sol = module.Ideal_with_generator([p_alg, H_simple])
        return (sol, f)
def _vector_to_algnumber(vector_repr, field):
    """
    vector (w.r.t. theta) -> omega
    """
    int_vector, denom = module._toIntegerMatrix(vector_repr)
    int_vector = int_vector[1].compo  # Submodule -> list
    omega = algfield.BasicAlgNumber([int_vector, denom], field.polynomial)
    return omega
def _matrix_to_algnumber_list(matrix_repr, field):
    """
    matrix (w.r.t. theta) -> [omega_i]
    """
    int_matrix, denom = module._toIntegerMatrix(matrix_repr)
    omega = []
    for i in range(1, int_matrix.column + 1):
        omega_i = algfield.BasicAlgNumber(
            [int_matrix[i], denom], field.polynomial)
        omega.append(omega_i)
    return omega
Beispiel #5
0
 def setUp(self):
     self.a = algfield.BasicAlgNumber([[1, 1], 1], [-2, 0, 1])
     self.b = algfield.BasicAlgNumber([[-1, 2], 1], [-2, 0, 1])