Пример #1
0
def check_add_qexp(dim, min_det=1, max_det=None, fix=False):
    count = 0
    query = {}
    query['dim'] = int(dim)
    query['det'] = {'$gte': int(min_det)}
    if max_det:
        query['det']['$lte'] = int(max_det)
    else:
        max_det = "infinity"
    lat_set = lat.find(query)
    print(
        "%s lattices to examine of dimension %s and determinant between %s and %s."
        % (lat_set.count(), dim, min_det, max_det))
    if lat_set.count() == 0:
        return None
    print("checking whether the q expansion is stored...")
    for l in lat_set:
        print("Testing lattice %s" % l['label'])
        if l['theta_series'] == "":
            print("q expansion NOT stored")
            if fix:
                M = l['gram']
                exp = [
                    int(i) for i in gp("Vec(1+2*'x*Ser(qfrep(" +
                                       str(gp(matrix(M))) + ",150,0)))")
                ]
                lat.update({'theta_series': l['theta_series']},
                           {"$set": {
                               'theta_series': exp
                           }},
                           upsert=True)
                print("Fixed lattice %s" % l['label'])
        else:
            print("q expansion stored")
Пример #2
0
def check_add_qexp(dim, min_det=1, max_det=None, fix=False):
    count = 0
    query = {}
    query['dim'] = int(dim)
    query['det'] = {'$gte' : int(min_det)}
    if max_det:
        query['det']['$lte'] = int(max_det)
    else:
        max_det = "infinity"
    lat_set = lat.find(query)
    print("%s lattices to examine of dimension %s and determinant between %s and %s."
          % (lat_set.count(), dim, min_det, max_det))
    if lat_set.count() == 0:
        return None
    print("checking whether the q expansion is stored...")
    for l in lat_set:
        print("Testing lattice %s" % l['label'])
        if l['theta_series'] == "":
            print("q expansion NOT stored")
            if fix:
                M=l['gram']
                exp=[int(i) for i in gp("Vec(1+2*'x*Ser(qfrep("+str(gp(matrix(M)))+",150,0)))")]
                lat.update({'theta_series': l['theta_series']}, {"$set": {'theta_series': exp}}, upsert=True)
                print("Fixed lattice %s" % l['label'])
        else:
            print("q expansion stored")
Пример #3
0
def AJ1(R, f, P, i=1):
    #if f.degree() == 5:
    #    return AJ1odd(R, f, P, i)
    assert f.degree() == 6
    J = gp("AJ1({},[{},{}],my_mesh,{})".format(str(f), str(P[0]), str(P[1]),
                                               str(i)))
    return vector(R, (J[1], J[2]))
Пример #4
0
 def gpK(self):
     if not self.haskey('gpK'):
         Qx = PolynomialRing(QQ,'x')
         # while [1] is a perfectly good basis for Z, gp seems to want []
         basis = [Qx(el.replace('a','x')) for el in self.zk()] if self.degree() > 1 else []
         k1 = gp( "nfinit([%s,%s])" % (str(self.poly()),str(basis)) )
         self._data['gpK'] = k1
     return self._data['gpK']
Пример #5
0
 def gpK(self):
     if not self.haskey('gpK'):
         Qx = PolynomialRing(QQ,'x')
         # while [1] is a perfectly good basis for Z, gp seems to want []
         basis = [Qx(el.replace('a','x')) for el in self.zk()] if self.degree() > 1 else []
         k1 = gp( "nfinit([%s,%s])" % (str(self.poly()),str(basis)) )
         self._data['gpK'] = k1
     return self._data['gpK']
Пример #6
0
    def __init__(self, number_field, mod_ideal=1, mod_archimedean=None):
        if mod_archimedean is None:
            mod_archimedean = [0] * len(number_field.real_places())
        mod_ideal = number_field.ideal(mod_ideal)

        bnf = gp(number_field.pari_bnf())
        # Use PARI to compute ray class group
        bnr = bnf.bnrinit([mod_ideal, mod_archimedean], 1)
        invariants = bnr[5][2]  # bnr.clgp.cyc
        invariants = tuple([Integer(x) for x in invariants])
        names = tuple(["I%i" % i for i in range(len(invariants))])
        generators = bnr[5][3]  # bnr.gen = bnr.clgp[3]
        generators = [number_field.ideal(pari(x)) for x in generators]

        AbelianGroup_class.__init__(self, invariants, names)
        self.__number_field = number_field
        self.__bnr = bnr
        self.__pari_mod = bnr[2][1]
        self.__mod_ideal = mod_ideal
        self.__mod_arch = mod_archimedean
        self.__generators = generators
Пример #7
0
    def __init__(self, number_field, mod_ideal = 1, mod_archimedean = None):
        if mod_archimedean == None:
            mod_archimedean = [0] * len(number_field.real_places())
        mod_ideal = number_field.ideal( mod_ideal )

        bnf = gp(number_field.pari_bnf())
        # Use PARI to compute ray class group
        bnr = bnf.bnrinit([mod_ideal, mod_archimedean],1)
        invariants = bnr[5][2]         # bnr.clgp.cyc
        invariants = tuple([ Integer(x) for x in invariants ])
        names = tuple([ "I%i"%i for i in range(len(invariants)) ])
        generators = bnr[5][3]         # bnr.gen = bnr.clgp[3]
        generators = [ number_field.ideal(pari(x)) for x in generators ]

        AbelianGroup_class.__init__(self, invariants, names)
        self.__number_field = number_field
        self.__bnr = bnr
        self.__pari_mod = bnr[2][1]
        self.__mod_ideal = mod_ideal
        self.__mod_arch = mod_archimedean
        self.__generators = generators
Пример #8
0
def myZZ(val):
    return int(ZZ(gp(val)))
Пример #9
0
def myZZ(val):
    return int(ZZ(gp(val)))
Пример #10
0
def load_gp():
    if not all([
            gp("RNEG") == 101,
            gp("RPOS") == 102,
            gp("INEG") == 103,
            gp("IPOS") == 104
    ]):
        #print "loading gp code"
        gp._reset_expect()
        # Branch values:
        gp("RNEG=101; RPOS=102; INEG=103; IPOS=104;")

        # Print branch label given a branch value.
        # The label corresponds to the branch cut.
        gp("""
            printbranch(branch)=
            {
                if( branch == RNEG, print("RNEG"));
                if( branch == RPOS, print("RPOS"));
                if( branch == INEG, print("INEG"));
                if( branch == IPOS, print("IPOS"));
                return();
                error("Unknown sqrt branch");
            }
            """.replace('\n', ''))

        # Square root determined by branch value, which should be thought of as a
        # continuation to a half-plane.
        gp("""
            rac2(z, branch)=
            {
                if( branch == RNEG, return( sqrt(z) ) );
                if( branch == RPOS, return( I * sqrt(-z) ) );
                if( branch == INEG, return( sqrt(I) * sqrt(-I*z) ) );
                if( branch == IPOS, return( sqrt(-I) * sqrt(I * z) ) );
                error("Unknown sqrt branch");
            }
            """.replace('\n', ''))

        # Best branch is the one that stays farthest away from the cut corresponding to
        # it.
        gp("""
            best_branch(z)=
            {
                my( x = real(z), y = imag(z) );
                if( abs(y) > abs(x),
                    if( y > 0, return(INEG), return(IPOS))
                    ,
                    if( x > 0, return(RNEG), return(RPOS))
                );
            }
            """.replace('\n', ''))

        # Evaluation:
        gp("EvPol(f, x) = subst(f, variable(f), x);")

        # Heuristic zero test:
        gp("IsApprox0(x) = abs(x) < 10^(-default(realprecision) / 2);")

        # Return real positive roots of a complex polynomial
        gp("""
        {
        polposroots( f ) = 
            if( poldegree( f ) <= 0, return( [] ) );

            my( Z = polroots( f ) );
            RZ = List();
            for(i = 1,#Z,
                if( IsApprox0( imag( Z[i] ) ) && real( Z[i] ) > 10^(-default(realprecision) / 2), listput( RZ, real(Z[i]) ))
            );
            Vec(RZ);
        }
        """.replace('\n', ''))

        # Return distinct roots in [0, 1] of a complex polynomial
        gp("""
            {
            pol01roots( f ) =
                if( poldegree( f ) <= 0, return([]));
                my( Z = polroots(f), i, z, eps = 10^(-default(realprecision) / 2));
                RZ = List();
                for(i = 1,#Z,
                    if( IsApprox0( imag(Z[i]) ),
                        z = real( Z[i] );
                        if( z > eps && z < 1-eps && (#RZ==0 || abs( z - RZ[#RZ]) > eps),
                            listput(RZ, z)
                        )
                    )
                );
                Vec(RZ);
            }
            """.replace('\n', ''))

        # Normalises a polynomial by removing the null leading terms (should fix the bug reported by Jeroen)
        gp("""
            {
            normalise_lc_pol(f) =
                my( d = poldegree(f), d2 = -1, var = variable(f), eps=10^(-default(realprecision)/2) );
                for(i=0,d,
                    if(abs(polcoeff(f,i))>eps,d2=i)
                );
                sum(i=0,d2,polcoeff(f,i)*var^i);
            }
            """.replace('\n', ''))

        # Returns values in [0, 1] where f crosses one of the branch cuts
        gp("""
            {
            polcrossaxes01(f) =
                my( u = real(f), v = imag(f), Z, Zf, eps = 10^(-default(realprecision)/2) );
                Z = pol01roots(f);
                u = normalise_lc_pol(u);
                v = normalise_lc_pol(v);
                if( u == 0 || v == 0, return(Z));
                Zf=prod(i=1,#Z,'t-Z[i]);
                Z=concat(Z,pol01roots(u\Zf)); Z=concat(Z,pol01roots(v\Zf));
                Z=vecsort(Z); /* TODO fix can be multiple roots there */
            }
            """.replace('\n', ''))

        # Integrates division by sqrt(f) from a to b (complexes), assuming no branch
        # cut and f square free. Detects zeros at ends and simplifies them out by changing
        # variable.
        gp("""{
        AJ_fin_nocut(f, a, b, branch, mesh)= 

         /*print("AJfin");*/
         my(t, g, h, S, z0, z1);

         g = EvPol(f, a + (b - a) * 't);

         z0 = IsApprox0( polcoeff(g, 0) );
         z1 = IsApprox0( EvPol(g, 1) );

         if(z0,

          if(z1,
           /*print("we have zeros at both ends");*/
           h = g\('t-'t^2);
           S = 6 * intnum( t = 0, 1, [1, a + (b - a) * t^2 * (3 - 2*t)] / rac2((3 - 2*t)*(2*t + 1) * EvPol(h, t^2 * (3 - 2*t)) ,branch),mesh)
          ,
           /*print("a is a zero, and b is not");*/
           h = g\ 't;
           S = 2 * intnum( t = 0, 1, [1 , a + (b - a) * t^2 ] / rac2( EvPol( h, t^2 ), branch), mesh)
          )
         ,
          if(z1,
           /*print("b is zero, and a is not");*/
           h = g\(1-'t);
           S = 2 * intnum(t = 0, 1, [1, b + (a - b) * t^2 ] / rac2( EvPol( h, 1 - t^2 ), branch), mesh)
          ,
           /*print("neither a or b are zeros");*/
           S = intnum(t = 0, 1, [1, a + (b - a) * t ] / rac2(EvPol(g, t), branch), mesh)
          )
         );
         (b - a) * S;
        }""".replace('\n', ''))

        # Abelian integral from x=a straight to x=b, starting at y=ya. Also returns yb.
        # Technique: Keep track of a branch switch throughout.
        # (The correct signed root is chosen by explicit continuation.)
        gp("""
        AJ_fin(f, a, b, ya, mesh) = 
        {
         my(g, stops, S = [0, 0], s, yprev, z, i, w, branch, ynew);

         /*print(["Int",a,b]);*/
         g = EvPol(f, a + (b - a) * 't);

         /* Checks for which 0<t<1 the image by f of the integration path crosses the axes */
         stops = polcrossaxes01( g ); 

         /*print(Str(#stops, "obstacles"));*/
         /* Turn these t into z */
         stops = apply( t-> a + t * (b-a), stops);
         /* Add endpoints */
         stops = concat([a], concat(stops,[b])); 
         /* print(stops); */
         
         /* Keep track of the sheet */
         s = 1;
         yprev = ya;
         z = a;

         for(i = 1,#stops - 1,

          w = EvPol(f,z);
          /* w is in the area we're starting from now. */
          if( IsApprox0(w), w = EvPol(deriv(f),z));
          branch = best_branch(w);

          /* Choose a sqrt accordingly */
          /* print(Str("New value ",w)); */
          /* printbranch(branch); */
          if( !IsApprox0( EvPol(f, z) ),
          /* adjust sign so that we stay in the same sheet */
           ynew = rac2( EvPol(f, z), branch);
           if( s * real(ynew/yprev) < 0, s = -s );
          );
          S += s * AJ_fin_nocut(f, stops[i], stops[i+1], branch, mesh);

          /* integrate 1 step */

          /* compute new start and new y */
          z = stops[i + 1];
          yprev = s * rac2(EvPol(f, z) , branch);
         );
         [S, yprev];
        }
        """.replace('\n', ''))

        # Image of P+Q-OO by Abel-Jacobi
        gp("""
        {
        AJ2(f, P, Q, mesh) =
         my();
         Z = polroots(f);
         /* Integrate P+Q-2(z,0) instead, it is the same up to a period */
         z = Z[1];
         AJ_fin(f, P[1], z, P[2], mesh)[1] + AJ_fin(f, Q[1], z, Q[2], mesh)[1];
        }
        """.replace('\n', ''))

        # Image of P-OO by Abel-Jacobi
        gp("""
        {
        AJ1(f,P,mesh)= 
            AJ1(f, P, mesh, 1);
        }
        """.replace('\n', ''))
        gp("""
        {
        AJ1(f,P,mesh,i)= 
         my();
         Z = polroots(f);
         z = Z[i]; /* Integrate P-(z,0) instead, it is the same up to a period */
         AJ_fin(f,P[1],z,P[2],mesh)[1];
        }
        """.replace('\n', ''))
        gp("""
        {
        whatZ(f)=
         Z = polroots(f);
         z = Z[1];
         z;
        }
        """.replace('\n', ''))
Пример #11
0
def Z(f):
    print gp("whatZ({})".format(str(f)))
Пример #12
0
def AJ2(f, P, Q):
    J = gp("AJ2({},[{},{}],[{},{}],my_mesh)".format(str(f), str(P[0]),
                                                    str(P[1]), str(Q[0]),
                                                    str(Q[1])))
    return (J[1], J[2])
Пример #13
0
def PariIntNumInit(n=1):
    gp("my_mesh = intnuminit(0,1,{})".format(str(n)))