예제 #1
0
def p_adic_l_invariant_additive(logA,logB, alpha, beta, Tmatrix):
    K = logA.parent()
    logA, logB = K(logA), K(logB)
    x,y,z,t = Tmatrix.change_ring(K).list()
    M = Matrix(K,2,2,[alpha,x*alpha+z*beta,beta, y*alpha+t*beta])
    n  = Matrix(K,2,1,[logA, logB])
    return M.solve_right(n).list()
예제 #2
0
 def matrix_rep(self,B=None):
     r"""
     Returns a matrix representation of ``self``.
     """
     #Express the element in terms of the basis B
     if B is None:
         B = self._parent.basis()
     A=Matrix(self._parent._R,self._parent.dimension(),self._parent.dimension(),[[b._val[ii,0] for b in B] for ii in range(self._depth)])
     tmp=A.solve_right(self._val)
     return tmp
예제 #3
0
    def matrix_rep(self,B=None):
        r"""
        Returns a matrix representation of ``self``.
        """
        #Express the element in terms of the basis B
        if B is None:
            B = self._parent.basis()

        A = Matrix(self._parent._R,self._parent.dimension(),self._parent.dimension(),[[b._moments[ii,0] for b in B] for ii in range(self._dimension)])
        tmp = A.solve_right(self._moments)
        return tmp
    class _FiniteBasisConverter:
        def __init__(self, P, comb_mod, basis):
            r"""
            Basis should be a finite set of polynomials
            """
            self._poly_ring = P
            self._module = comb_mod
            self._basis = basis

            max_deg = max([self._poly_ring(b).degree() for b in self._basis])
            monoms = []
            for b in self._basis:
                poly = self._poly_ring(b)
                monoms += poly.monomials()
            monoms_list = tuple(Set(monoms))

            # check if the basis represented in terms of Monomials is efficient
            degs = [self._poly_ring(m).degree() for m in monoms]
            min_deg, max_deg = min(degs), max(degs)
            monoms_obj = Monomials(self._poly_ring, (min_deg, max_deg + 1))

            if monoms_obj.cardinality() < 2 * len(monoms_list):
                computational_basis = monoms_obj
            else:
                computational_basis = monoms_list
            self._monomial_module = PolynomialFreeModule(
                P=self._poly_ring, basis=computational_basis)
            cols = [self._monomial_module(b).to_vector() for b in self._basis]
            self._basis_mat = Matrix(cols).transpose()
            if self._basis_mat.ncols() > self._basis_mat.rank():
                raise ValueError(
                    "Basis polynomials are not linearly independent")

        def convert(self, p):
            r"""
            Algorithm is to convert all polynomials into monomials and use
            linear algebra to solve for the appropriate coefficients in this
            common basis.
            """
            try:
                p_vect = self._monomial_module(p).to_vector()
                decomp = self._basis_mat.solve_right(p_vect)
            except ValueError:
                raise ValueError(
                    "Value %s is not spanned by the basis polynomials" % p)
            polys = [v[1] * self._module.monomial(v[0])
                     for v in zip(self._basis, decomp)]
            module_p = sum(polys, self._module.zero())
            return module_p
예제 #5
0
    def matrix_rep(self,B=None):
        r"""

        EXAMPLES:

        This example illustrates ...

        ::

        """
        #Express the element in terms of the basis B
        if(B is None):
            B=self._parent.basis()
        A=Matrix(self._parent._R,self._parent.dimension(),self._parent.dimension(),[[b._val[ii,0] for b in B] for ii in range(self._depth)])
        tmp=A.solve_right(self._val)
        return tmp
예제 #6
0
    def matrix_rep(self, B=None):
        r"""

        EXAMPLES:

        This example illustrates ...

        ::

        """
        #Express the element in terms of the basis B
        if (B is None):
            B = self._parent.basis()
        A = Matrix(self._parent._R, self._parent.dimension(),
                   self._parent.dimension(),
                   [[b._val[ii, 0] for b in B] for ii in range(self._depth)])
        tmp = A.solve_right(self._val)
        return tmp
예제 #7
0
 def linear_relation(self, List, Psi, verbose=True, prec=None):
     for Phi in List:
         assert Phi.valuation() >= 0, "Symbols must be integral"
     assert Psi.valuation() >= 0
     R = self.base()
     Rbase = R.base()
     w = R.gen()
     d = len(List)
     if d == 0:
         if Psi.is_zero():
             return [None, R(1)]
         else:
             return [None, 0]
     if prec is None:
         M, var_prec = Psi.precision_absolute()
     else:
         M, var_prec = prec
     p = self.prime()
     V = R**d
     RSR = LaurentSeriesRing(Rbase, R.variable_name())
     VSR = RSR**self.source().ngens()
     List_TMs = [VSR(Phi.list_of_total_measures()) for Phi in List]
     Psi_TMs = VSR(Psi.list_of_total_measures())
     A = Matrix(RSR, List_TMs).transpose()
     try:
         sol = V([vv.power_series() for vv in A.solve_right(Psi_TMs)])
     except ValueError:
         #try "least squares"
         if verbose:
             print "Trying least squares."
         sol = (A.transpose() * A).solve_right(A.transpose() * Psi_TMs)
         #check precision (could make this better, checking each power of w)
         p_prec = M
         diff = Psi_TMs - sum([sol[i] * List_TMs[i] for i in range(len(List_TMs))])
         for i in diff:
             for j in i.list():
                 if p_prec > j.valuation():
                     p_prec = j.valuation()
         if verbose:
             print "p-adic precision is now", p_prec
         #Is this right?
         sol = V([R([j.add_bigoh(p_prec) for j in i.list()]) for i in sol])
     return [sol, R(-1)]
예제 #8
0
def solve_coefficient_system(Q, equations, vars):
    # NOTE: to make things easier (and uniform) in the univariate case a dummy
    # variable is added to the polynomial ring. See compute_bd()
    a = Q.gens()[:-1]
    B = Q.base_ring()

    # construct the coefficient system and right-hand side
    system = [[e.coefficient({ai:1}) for ai in a] for e in equations]
    rhs = [-e.constant_coefficient() for e in equations]
    system = Matrix(B, system)
    rhs = Matrix(B, rhs).transpose()

    # we only allow unique solutions. return None if there are infinitely many
    # solutions or if no solution exists. Sage will raise a ValueError in both
    # circumstances
    try:
        sol = system.solve_right(rhs)
    except ValueError:
        return None
    return sol
예제 #9
0
def solve_coefficient_system(Q, equations, vars):
    # NOTE: to make things easier (and uniform) in the univariate case a dummy
    # variable is added to the polynomial ring. See compute_bd()
    a = Q.gens()[:-1]
    B = Q.base_ring()

    # construct the coefficient system and right-hand side
    system = [[e.coefficient({ai: 1}) for ai in a] for e in equations]
    rhs = [-e.constant_coefficient() for e in equations]
    system = Matrix(B, system)
    rhs = Matrix(B, rhs).transpose()

    # we only allow unique solutions. return None if there are infinitely many
    # solutions or if no solution exists. Sage will raise a ValueError in both
    # circumstances
    try:
        sol = system.solve_right(rhs)
    except ValueError:
        return None
    return sol