Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241818 views
1
#################################################################################
2
#
3
# (c) Copyright 2011 William Stein
4
#
5
# This file is part of PSAGE
6
#
7
# PSAGE is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# PSAGE is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#
20
#################################################################################
21
22
import sage.parallel.ncpus
23
from psage.lmfdb.auth import userpass
24
25
def populate_db(address, level_min, level_max, pmax=100,
26
ncpus=sage.parallel.ncpus.ncpus()):
27
"""
28
Compute and insert into the MongoDB database with the given
29
address the Fourier coefficients a_p for p up to pmax for the optimal
30
elliptic curves of the given range of levels (top level not
31
included), using the given number of threads.
32
33
Only curves with ap not yet set are affected by this function.
34
"""
35
user, password = userpass()
36
import math, random
37
from sage.all import prime_range, parallel, pari
38
39
level_min = int(level_min); level_max = int(level_max)
40
P = prime_range(pmax)
41
s = int(math.ceil((level_max - level_min)/float(ncpus)))
42
blocks = [(level_min+i*s, min(level_max,level_min+(i+1)*s)) for i in range(ncpus)]
43
44
@parallel(ncpus)
45
def f(l_min, l_max):
46
from pymongo import Connection
47
C = Connection(address).research
48
C.authenticate(user, password)
49
C = C.ellcurves
50
for v in C.find({'level':{'$gte':level_min, '$lt':level_max},
51
'number':1,
52
'ap':{'$exists':False}}):
53
E = pari('ellinit(%s,1)'%v['weq'])
54
ap = dict([(str(p),int(E.ellap(p))) for p in P])
55
C.update({'_id':v['_id']}, {'$set':{'ap':ap}})
56
57
for ans in f(blocks):
58
print ans
59
60
61
"""
62
EXAMPLE QUERIES:
63
64
from pymongo import Connection
65
db = Connection(port=int(29000)).research
66
e = db.ellcurves
67
v = e.find({'level':{'$lt':100r}, 'ap.2':-2r}, )
68
sage: v.count()
69
7
70
71
sage: v = e.find({'level':{'$lt':100r}, 'ap.2':-2r}, ['level', 'weq'])
72
sage: v.next()
73
{u'weq': u'[0,-1,1,-10,-20]', u'_id': ObjectId('4c9258841e8b55611895b170'), u'level': 11}
74
sage: v.next()
75
{u'weq': u'[0,0,1,-1,0]', u'_id': ObjectId('4c9258841e8b55611895b1bc'), u'level': 37}
76
77
sage: v = e.find({'level':{'$lt':100r}, 'ap.2':{'$mod':[int(2),int(0)]}}, ['level', 'weq', 'ap.2', 'ap.3'])
78
sage: v.next()
79
{u'ap': {u'3': -1, u'2': -2}, u'weq': u'[0,-1,1,-10,-20]', u'_id': ObjectId('4c9258841e8b55611895b170'), u'level': 11}
80
"""
81
82
83