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
23
from sage.all import mwrank_EllipticCurve
24
from psage.lmfdb.auth import userpass
25
26
def selmer2(a_invariants, max_time=None):
27
if max_time is None:
28
E = mwrank_EllipticCurve(a_invariants)
29
return int(E.selmer_rank())
30
else:
31
try:
32
from sage.all import fork # not in official sage.
33
except ImportError:
34
raise ImportError, "You need to apply the patch from http://trac.sagemath.org/sage_trac/ticket/9631"
35
@fork(timeout=max_time)
36
def f():
37
E = mwrank_EllipticCurve(a_invariants)
38
return int(E.selmer_rank())
39
return f()
40
41
import sage.parallel.ncpus
42
43
def populate_db(address, level_min, level_max,
44
ncpus=sage.parallel.ncpus.ncpus(),
45
max_time=None):
46
"""
47
Compute and insert into the database the 2-selmer ranks of all the
48
curves in a give range of levels, for which 2-selmer ranks aren't
49
already known.
50
"""
51
user, password = userpass()
52
53
import math, random
54
from sage.all import prime_range, parallel, pari
55
56
level_min = int(level_min); level_max = int(level_max)
57
s = int(math.ceil((level_max - level_min)/float(ncpus)))
58
blocks = [(level_min+i*s, min(level_max,level_min+(i+1)*s)) for i in range(ncpus)]
59
60
@parallel(ncpus)
61
def f(l_min, l_max):
62
from pymongo import Connection
63
C = Connection(address).research
64
C.authenticate(user, password)
65
C = C.ellcurves
66
for v in C.find({'level':{'$gte':level_min, '$lt':level_max},
67
'sel2':{'$exists':False}}):
68
sel2 = selmer2(eval(v['weq']), max_time)
69
C.update({'_id':v['_id']}, {'$set':{'sel2':sel2}})
70
71
for ans in f(blocks):
72
print ans
73
74
"""
75
EXAMPLE QUERIES:
76
77
from pymongo import Connection
78
db = Connection(port=int(29000)).research
79
e = db.ellcurves
80
v = e.find({'level':{'$lt':100r}, 'sel2':{'$exists':True}})
81
sage: v.count()
82
7
83
"""
84
85