Пример #1
0
def integrate_H0_moments(G, divisor, hc, depth, gamma, prec, counter,
                         total_counter, progress_bar, parallelize):
    # verbose('Integral %s/%s...'%(counter,total_counter))
    p = G.p
    HOC = hc.parent()
    if prec is None:
        prec = HOC.coefficient_module().precision_cap()
    try:
        coeff_depth = HOC.coefficient_module().precision_cap()
    except AttributeError:
        coeff_depth = HOC.coefficient_module().coefficient_module(
        ).precision_cap()
    K = divisor.parent().base_ring()
    QQp = Qp(p, prec)
    R = PolynomialRing(K, 'r')
    divisor_list = [(P, n) for P, n in divisor]
    resadd = ZZ(0)
    resval = ZZ(0)
    resmul = ZZ(1)
    edgelist = [(1, o, QQ(1) / QQ(p + 1)) for o in G.get_covering(depth)]
    while len(edgelist) > 0:
        newedgelist = []
        ii = 0
        for parity, edge, wt in edgelist:
            ii += 1
            rev, h = edge
            a, b, c, d = [K(o) for o in G.embed(h, prec).list()]
            try:
                c0unit = K.one()
                c0val = 0
                pol = R.zero()
                for P, n in divisor_list:
                    if P == Infinity:
                        continue
                    else:
                        hp0 = K(b + a * P)
                        hp1 = K(d + c * P)
                        if hp1.valuation() <= hp0.valuation():
                            raise ValueError
                    x = hp1 / hp0
                    v = [K.zero(), K(x)]
                    xpow = K(x)
                    for m in xrange(2, coeff_depth + 1):
                        xpow *= x
                        v.append(xpow / QQ(m))
                    pol -= QQ(n) * R(v)
                    c0unit *= (-hp0).unit_part()**n
                    c0val += n * hp0.valuation()
                pol += c0unit.log(p_branch=0)
                newgamma = G.reduce_in_amalgam(h * gamma.quaternion_rep,
                                               return_word=False)
                if rev:
                    newgamma = newgamma.conjugate_by(G.wp())
                if G.use_shapiro():
                    mu_e = hc.evaluate_and_identity(newgamma, parallelize)
                else:
                    mu_e = hc.evaluate(newgamma, parallelize)
            except (ValueError):
                verbose('Subdividing...')
                newedgelist.extend([(parity, o, wt / QQ(p**2))
                                    for o in G.subdivide([edge], parity, 2)])
                continue
            if HOC._use_ps_dists:
                resadd += sum(
                    a * mu_e.moment(i)
                    for a, i in izip(pol.coefficients(), pol.exponents())
                    if i < len(mu_e._moments))
            else:
                resadd += mu_e.evaluate_at_poly(pol, K, coeff_depth)
            try:
                if G.use_shapiro():
                    tmp = hc.get_liftee().evaluate_and_identity(newgamma)
                else:
                    tmp = hc.get_liftee().evaluate(newgamma)
                resval += c0val * ZZ(tmp[0])
                resmul *= c0unit**ZZ(tmp[0])
            except IndexError:
                pass
            if progress_bar:
                update_progress(float(QQ(ii) / QQ(len(edgelist))),
                                'Integration %s/%s' % (counter, total_counter))

        edgelist = newedgelist
    return resadd, resmul, resval
Пример #2
0
    def _sage_(self):
        """
        EXAMPLES::

            sage: m = lie('[[1,0,3,3],[12,4,-4,7],[-1,9,8,0],[3,-5,-2,9]]') # optional - lie
            sage: m.sage()  # optional - lie
            [ 1  0  3  3]
            [12  4 -4  7]
            [-1  9  8  0]
            [ 3 -5 -2  9]

        """
        t = self.type()
        if t == 'grp':
            raise ValueError(
                "cannot convert Lie groups to native Sage objects")
        elif t == 'mat':
            import sage.matrix.constructor
            data = sage_eval(str(self).replace('\n', '').strip())
            return sage.matrix.constructor.matrix(data)
        elif t == 'pol':
            from sage.rings.all import PolynomialRing, QQ

            # Figure out the number of variables
            s = str(self)
            open_bracket = s.find('[')
            close_bracket = s.find(']')
            nvars = len(s[open_bracket:close_bracket].split(','))

            # create the polynomial ring
            R = PolynomialRing(QQ, nvars, 'x')
            x = R.gens()
            pol = R.zero()

            # Split up the polynomials into terms
            terms = []
            for termgrp in s.split(' - '):
                # The first entry in termgrp has
                # a negative coefficient
                termgrp = "-" + termgrp.strip()
                terms += termgrp.split('+')
            # Make sure we don't accidentally add a negative
            # sign to the first monomial
            if s[0] != "-":
                terms[0] = terms[0][1:]

            # go through all the terms in s
            for term in terms:
                xpos = term.find('X')
                coef = eval(term[:xpos].strip())
                exps = eval(term[xpos + 1:].strip())
                monomial = prod([x[i]**exps[i] for i in range(nvars)])
                pol += coef * monomial

            return pol
        elif t == 'tex':
            return repr(self)
        elif t == 'vid':
            return None
        else:
            return ExpectElement._sage_(self)
Пример #3
0
    def __call__(self, P):
        r"""
        Return a rational point P in the abstract Homset J(K), given:

        0. A point P in J = Jac(C), returning P;

        1. A point P on the curve C such that J = Jac(C), where C is
          an odd degree model, returning [P - oo];

        2. A pair of points (P, Q) on the curve C such that J = Jac(C),
          returning [P-Q];

        3. A list of polynomials (a,b) such that `b^2 + h*b - f = 0 mod a`,
          returning [(a(x),y-b(x))].

        EXAMPLES::

            sage: P.<x> = PolynomialRing(QQ)
            sage: f = x^5 - x + 1; h = x
            sage: C = HyperellipticCurve(f,h,'u,v')
            sage: P = C(0,1,1)
            sage: J = C.jacobian()
            sage: Q = J(QQ)(P)
            sage: for i in range(6): i*Q
            (1)
            (u, v - 1)
            (u^2, v + u - 1)
            (u^2, v + 1)
            (u, v + 1)
            (1)

        ::

            sage: F.<a> = GF(3)
            sage: R.<x> = F[]
            sage: f = x^5-1
            sage: C = HyperellipticCurve(f)
            sage: J = C.jacobian()
            sage: X = J(F)
            sage: a = x^2-x+1
            sage: b = -x +1
            sage: c = x-1
            sage: d = 0
            sage: D1 = X([a,b])
            sage: D1
            (x^2 + 2*x + 1, y + x + 2)
            sage: D2 = X([c,d])
            sage: D2
            (x + 2, y)
            sage: D1+D2
            (x^2 + 2*x + 2, y + 2*x + 1)
        """
        if isinstance(P, (Integer, int)) and P == 0:
            R = PolynomialRing(self.value_ring(), 'x')
            return JacobianMorphism_divisor_class_field(
                self, (R.one(), R.zero()))
        elif isinstance(P, (list, tuple)):
            if len(P) == 1 and P[0] == 0:
                R = PolynomialRing(self.value_ring(), 'x')
                return JacobianMorphism_divisor_class_field(
                    self, (R.one(), R.zero()))
            elif len(P) == 2:
                P1 = P[0]
                P2 = P[1]
                if is_Integer(P1) and is_Integer(P2):
                    R = PolynomialRing(self.value_ring(), 'x')
                    P1 = R(P1)
                    P2 = R(P2)
                    return JacobianMorphism_divisor_class_field(self, (P1, P2))
                if is_Integer(P1) and is_Polynomial(P2):
                    R = PolynomialRing(self.value_ring(), 'x')
                    P1 = R(P1)
                    return JacobianMorphism_divisor_class_field(self, (P1, P2))
                if is_Integer(P2) and is_Polynomial(P1):
                    R = PolynomialRing(self.value_ring(), 'x')
                    P2 = R(P2)
                    return JacobianMorphism_divisor_class_field(self, (P1, P2))
                if is_Polynomial(P1) and is_Polynomial(P2):
                    return JacobianMorphism_divisor_class_field(self, tuple(P))
                if is_SchemeMorphism(P1) and is_SchemeMorphism(P2):
                    return self(P1) - self(P2)
            raise TypeError("argument P (= %s) must have length 2" % P)
        elif isinstance(
                P,
                JacobianMorphism_divisor_class_field) and self == P.parent():
            return P
        elif is_SchemeMorphism(P):
            x0 = P[0]
            y0 = P[1]
            R, x = PolynomialRing(self.value_ring(), 'x').objgen()
            return self((x - x0, R(y0)))
        raise TypeError(
            "argument P (= %s) does not determine a divisor class" % P)