Ejemplo n.º 1
0
def _pow_by_base_mul(self, other, base_mul, max_j=False):
    """
    return self * other with respect to basis (gamma_i),
    where self, other are matrix.
    (base_mul)_ij express gamma_i * gamma_j
    This function uses right-left binary method.
    """
    func = algorithm.powering_func(
        lambda x, y: _vect_mul_by_base_mul(x, y, base_mul, max_j))
    return func(self, other)
Ejemplo n.º 2
0
def _pow_by_base_mul(self, other, base_mul, max_j=False):
    """
    return self * other with respect to basis (gamma_i),
    where self, other are matrix.
    (base_mul)_ij express gamma_i * gamma_j
    This function uses right-left binary method.
    """
    func = algorithm.powering_func(
        lambda x,y:_vect_mul_by_base_mul(x, y, base_mul, max_j))
    return func(self, other)
Ejemplo n.º 3
0
def _substitution_by_base_mul(P, ele, base_mul, one_gamma, max_j=False):
    """
    return P(ele) with respect to basis (gamma_i),
    where P is a polynomial, ele is a vector w.r.t. gamma_i.
    (base_mul)_ij express gamma_i * gamma_j
    This function uses digital method (Horner method).
    """
    coeff = reversed(P.sorted)
    mul = lambda x, y: _vect_mul_by_base_mul(x, y, base_mul, max_j)
    return algorithm.digital_method(
        coeff, ele, lambda x, y: x + y, mul, lambda a, x: a * x,
        algorithm.powering_func(one_gamma, mul),
        vector.Vector([base_mul.coeff_ring.zero] * base_mul.row), one_gamma)
Ejemplo n.º 4
0
def _substitution_by_base_mul(P, ele, base_mul, one_gamma, max_j=False):
    """
    return P(ele) with respect to basis (gamma_i),
    where P is a polynomial, ele is a vector w.r.t. gamma_i.
    (base_mul)_ij express gamma_i * gamma_j
    This function uses digital method (Horner method).
    """
    coeff = reversed(P.sorted)
    mul = lambda x, y : _vect_mul_by_base_mul(x, y, base_mul, max_j)
    return algorithm.digital_method(
        coeff, ele, lambda x, y : x + y, mul,
        lambda a, x : a * x,
        algorithm.powering_func(one_gamma, mul),
        vector.Vector([base_mul.coeff_ring.zero] * base_mul.row),
        one_gamma
        )