コード例 #1
0
ファイル: ap.py プロジェクト: merbst/psage
def populate_db(address, level_min, level_max, pmax=100,
                ncpus=sage.parallel.ncpus.ncpus()):
    """
    Compute and insert into the MongoDB database with the given
    address the Fourier coefficients a_p for p up to pmax for the optimal
    elliptic curves of the given range of levels (top level not
    included), using the given number of threads.

    Only curves with ap not yet set are affected by this function.
    """
    user, password = userpass()
    import math, random
    from sage.all import prime_range, parallel, pari

    level_min = int(level_min); level_max = int(level_max)
    P = prime_range(pmax)
    s = int(math.ceil((level_max - level_min)/float(ncpus)))
    blocks = [(level_min+i*s, min(level_max,level_min+(i+1)*s)) for i in range(ncpus)]
    
    @parallel(ncpus)
    def f(l_min, l_max):
        from pymongo import Connection
        C = Connection(address).research
        C.authenticate(user, password)
        C = C.ellcurves
        for v in C.find({'level':{'$gte':level_min, '$lt':level_max},
                         'number':1,
                         'ap':{'$exists':False}}):
            E = pari('ellinit(%s,1)'%v['weq'])
            ap = dict([(str(p),int(E.ellap(p))) for p in P])
            C.update({'_id':v['_id']}, {'$set':{'ap':ap}})

    for ans in f(blocks):
        print ans
コード例 #2
0
def populate_db(address, level_min, level_max, 
                ncpus=sage.parallel.ncpus.ncpus(),
                max_time=None):
    """
    Compute and insert into the database the 2-selmer ranks of all the
    curves in a give range of levels, for which 2-selmer ranks aren't
    already known.
    """
    user, password = userpass()

    import math, random
    from sage.all import prime_range, parallel, pari

    level_min = int(level_min); level_max = int(level_max)
    s = int(math.ceil((level_max - level_min)/float(ncpus)))
    blocks = [(level_min+i*s, min(level_max,level_min+(i+1)*s)) for i in range(ncpus)]
    
    @parallel(ncpus)
    def f(l_min, l_max):
        from pymongo import Connection
        C = Connection(address).research
        C.authenticate(user, password)
        C = C.ellcurves
        for v in C.find({'level':{'$gte':level_min, '$lt':level_max},
                         'sel2':{'$exists':False}}):
            sel2 = selmer2(eval(v['weq']), max_time)
            C.update({'_id':v['_id']}, {'$set':{'sel2':sel2}})

    for ans in f(blocks):
        print ans
コード例 #3
0
def import_table(address, aplists_txt_filename, max_level=None):
    """
    Import a text table of eigenvalues, using upsert to avoid
    replication of data.
    """
    from psage.lmfdb.auth import userpass
    user, password = userpass()

    from sage.databases.cremona import cremona_letter_code
    from psage.modform.hilbert.sqrt5.sqrt5 import F
    labels, primes = labeled_primes_of_bounded_norm(F, 100)

    from pymongo import Connection
    C = Connection(address).research
    if not C.authenticate(user, password):
        raise RuntimeError, "failed to authenticate"
    e = C.ellcurves_sqrt5
    for X in open(aplists_txt_filename).read().splitlines():
        if X.startswith('#'):
            continue
        Nlevel, level, iso_class, ap = X.split('\t')
        ap = str_to_apdict(ap, labels)        
        Nlevel = int(Nlevel)
        iso_class = cremona_letter_code(int(iso_class))
        v = {'level':level, 'iso_class':iso_class,
             'number':1, 'Nlevel':Nlevel, 'ap':ap}
        if max_level and Nlevel > max_level: break
        print v
        spec = dict(v)
        del spec['ap']
        e.update(spec, v, upsert=True, safe=True)
    return e
コード例 #4
0
def counts_collection(address='localhost:29000'):
    from psage.lmfdb.auth import userpass
    user, password = userpass()
    from pymongo import Connection
    from pymongo.connection import DuplicateKeyError
    C = Connection(address).research
    C.authenticate(user, password)
    return C.ellcurves
コード例 #5
0
ファイル: queries.py プロジェクト: Alwnikrotikz/purplesage
def counts_collection(address='localhost:29000'):
    from psage.lmfdb.auth import userpass
    user, password = userpass()
    from pymongo import Connection
    from pymongo.connection import DuplicateKeyError
    C = Connection(address).research
    C.authenticate(user, password)
    return C.ellcurves
コード例 #6
0
def populate_db(address,
                level_min,
                level_max,
                num_zeros=100,
                ncpus=sage.parallel.ncpus.ncpus()):
    """
    Compute and insert into the MongoDB database with the given
    address the imaginary parts of the first num_zeros zeros of the
    L-series of each optimal elliptic curve in the given level range.

    Only curves with L0s not yet set are affected by this function.
    The key on the database is "L0s".
    """
    user, password = userpass()

    import math, random
    from sage.all import parallel, EllipticCurve

    from sage.libs.lcalc.lcalc_Lfunction import Lfunction_from_elliptic_curve

    level_min = int(level_min)
    level_max = int(level_max)
    s = int(math.ceil((level_max - level_min) / float(ncpus)))
    blocks = [(level_min + i * s, min(level_max, level_min + (i + 1) * s))
              for i in range(ncpus)]

    @parallel(ncpus)
    def f(l_min, l_max):
        from pymongo import Connection
        C = Connection(address).research
        C.authenticate(user, password)
        C = C.ellcurves
        for v in C.find({
                'level': {
                    '$gte': level_min,
                    '$lt': level_max
                },
                'number': 1,
                'L0s': {
                    '$exists': False
                }
        }):
            L = Lfunction_from_elliptic_curve(EllipticCurve(eval(v['weq'])),
                                              10**5)
            z = L.find_zeros_via_N(num_zeros)
            L0s = dict([(str(i), float(z[i])) for i in range(len(z))])
            C.update({'_id': v['_id']}, {'$set': {'L0s': L0s}})

    for ans in f(blocks):
        print(ans)
コード例 #7
0
def import_table(address, table_filename, max_level=None):
    """
    Import a text table of weq's, using upsert to avoid
    replication of data.  Format is like this:

    ::
    
      31      5*a-2       0   -3 2 -2 2 4 -4 4 -4 -2 -2 ? ? -6 -6 12 -4 6 -2 -8 0 0 16 10 -6              [1,a+1,a,a,0]
      31      5*a-3       0   -3 2 -2 2 -4 4 -4 4 -2 -2 ? ? -6 -6 -4 12 -2 6 0 -8 16 0 -6 10              [1,-a-1,a,0,0]
      36      6           0   ? ? -4 10 2 2 0 0 0 0 -8 -8 2 2 -10 -10 2 2 12 12 0 0 10 10                 [a,a-1,a,-1,-a+1]
    """
    from psage.modform.hilbert.sqrt5.sqrt5 import F
    from sage.databases.cremona import cremona_letter_code
    from aplists import labeled_primes_of_bounded_norm, str_to_apdict
    labels, primes = labeled_primes_of_bounded_norm(F, 100)

    from psage.lmfdb.auth import userpass
    user, password = userpass()

    from pymongo import Connection
    C = Connection(address).research
    if not C.authenticate(user, password):
        raise RuntimeError, "failed to authenticate"
    e = C.ellcurves_sqrt5

    for X in open(table_filename).read().splitlines():
        if X.startswith('#'):
            continue
        z = X.split()
        Nlevel = z[0]
        level = z[1]
        iso_class = z[2]
        weq = z[-1]
        ap = ' '.join(z[3:-1])
        ap = str_to_apdict(ap, labels)
        Nlevel = int(Nlevel)
        iso_class = cremona_letter_code(int(iso_class))
        v = {
            'level': level,
            'iso_class': iso_class,
            'number': 1,
            'Nlevel': Nlevel,
            'ap': ap,
            'weq': weq
        }
        if max_level and Nlevel > max_level: break
        print v
        spec = dict(v)
        del spec['weq']
        e.update(spec, v, upsert=True, safe=True)
コード例 #8
0
ファイル: util.py プロジェクト: Alwnikrotikz/purplesage
def ellcurves_sqrt5(address='localhost:29000', username=None, password=None):
    from sage.databases.cremona import cremona_letter_code
    from psage.modform.hilbert.sqrt5.sqrt5 import F
    from aplists import labeled_primes_of_bounded_norm
    labels, primes = labeled_primes_of_bounded_norm(F, 100)

    from pymongo import Connection
    C = Connection(address).research
    if username is None or password is None:
        from psage.lmfdb.auth import userpass
        username, password = userpass()
        
    if not C.authenticate(username, password):
        raise RuntimeError, "failed to authenticate"
    
    return C.ellcurves_sqrt5
コード例 #9
0
def ellcurves_sqrt5(address='localhost:29000', username=None, password=None):
    from sage.databases.cremona import cremona_letter_code
    from psage.modform.hilbert.sqrt5.sqrt5 import F
    from aplists import labeled_primes_of_bounded_norm
    labels, primes = labeled_primes_of_bounded_norm(F, 100)

    from pymongo import Connection
    C = Connection(address).research
    if username is None or password is None:
        from psage.lmfdb.auth import userpass
        username, password = userpass()

    if not C.authenticate(username, password):
        raise RuntimeError, "failed to authenticate"

    return C.ellcurves_sqrt5
コード例 #10
0
ファイル: weq.py プロジェクト: Alwnikrotikz/purplesage
def import_table(address, table_filename, max_level=None):
    """
    Import a text table of weq's, using upsert to avoid
    replication of data.  Format is like this:

    ::
    
      31      5*a-2       0   -3 2 -2 2 4 -4 4 -4 -2 -2 ? ? -6 -6 12 -4 6 -2 -8 0 0 16 10 -6              [1,a+1,a,a,0]
      31      5*a-3       0   -3 2 -2 2 -4 4 -4 4 -2 -2 ? ? -6 -6 -4 12 -2 6 0 -8 16 0 -6 10              [1,-a-1,a,0,0]
      36      6           0   ? ? -4 10 2 2 0 0 0 0 -8 -8 2 2 -10 -10 2 2 12 12 0 0 10 10                 [a,a-1,a,-1,-a+1]
    """
    from psage.modform.hilbert.sqrt5.sqrt5 import F
    from sage.databases.cremona import cremona_letter_code
    from aplists import labeled_primes_of_bounded_norm, str_to_apdict
    labels, primes = labeled_primes_of_bounded_norm(F, 100)

    from psage.lmfdb.auth import userpass
    user, password = userpass()

    from pymongo import Connection
    C = Connection(address).research
    if not C.authenticate(user, password):
        raise RuntimeError, "failed to authenticate"
    e = C.ellcurves_sqrt5


    for X in open(table_filename).read().splitlines():
        if X.startswith('#'):
            continue
        z = X.split()
        Nlevel = z[0]; level = z[1]; iso_class = z[2]; weq = z[-1]
        ap = ' '.join(z[3:-1])
        ap = str_to_apdict(ap, labels)
        Nlevel = int(Nlevel)
        iso_class = cremona_letter_code(int(iso_class))
        v = {'level':level, 'iso_class':iso_class,
             'number':1, 'Nlevel':Nlevel, 'ap':ap,
             'weq':weq}
        if max_level and Nlevel > max_level: break
        print v
        spec = dict(v)
        del spec['weq']
        e.update(spec, v, upsert=True, safe=True)
コード例 #11
0
ファイル: L0s.py プロジェクト: Alwnikrotikz/purplesage
def populate_db(address, level_min, level_max, num_zeros=100,
                ncpus=sage.parallel.ncpus.ncpus()):
    """
    Compute and insert into the MongoDB database with the given
    address the imaginary parts of the first num_zeros zeros of the
    L-series of each optimal elliptic curve in the given level range.

    Only curves with L0s not yet set are affected by this function.
    The key on the database is "L0s".
    """
    user, password = userpass()

    import math, random
    from sage.all import parallel, EllipticCurve

    from sage.libs.lcalc.lcalc_Lfunction import Lfunction_from_elliptic_curve
    
    level_min = int(level_min); level_max = int(level_max)
    s = int(math.ceil((level_max - level_min)/float(ncpus)))
    blocks = [(level_min+i*s, min(level_max,level_min+(i+1)*s)) for i in range(ncpus)]
    
    @parallel(ncpus)
    def f(l_min, l_max):
        from pymongo import Connection
        C = Connection(address).research
        C.authenticate(user, password)
        C = C.ellcurves
        for v in C.find({'level':{'$gte':level_min, '$lt':level_max},
                         'number':1,
                         'L0s':{'$exists':False}}):
            L = Lfunction_from_elliptic_curve(EllipticCurve(eval(v['weq'])), 10**5)
            z = L.find_zeros_via_N(num_zeros)
            L0s =  dict([(str(i),float(z[i])) for i in range(len(z))])
            C.update({'_id':v['_id']}, {'$set':{'L0s':L0s}})

    for ans in f(blocks):
        print ans