Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241852 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
def str_to_apdict(s, labels):
23
return dict([(labels[a], int(b)) for a,b in enumerate(s.split()) if b != '?'])
24
25
def labeled_primes_of_bounded_norm(F, B):
26
"""
27
Return a list [prime][letter code] of strings, corresponding to
28
the primes of F of bounded norm of F, ordered by residue
29
characteristic (not norm).
30
"""
31
from sage.databases.cremona import cremona_letter_code
32
from psage.modform.hilbert.sqrt5.sqrt5 import primes_of_bounded_norm
33
labels = []
34
last_c = 1
35
number = 0
36
primes = primes_of_bounded_norm(F, B)
37
for p in primes:
38
c = p.smallest_integer() # residue characteristic
39
if c != last_c:
40
last_c = c
41
number = 0
42
else:
43
number += 1
44
labels.append('%s%s'%(c,cremona_letter_code(number)))
45
return labels, primes
46
47
48
def import_table(address, aplists_txt_filename, max_level=None):
49
"""
50
Import a text table of eigenvalues, using upsert to avoid
51
replication of data.
52
"""
53
from psage.lmfdb.auth import userpass
54
user, password = userpass()
55
56
from sage.databases.cremona import cremona_letter_code
57
from psage.modform.hilbert.sqrt5.sqrt5 import F
58
labels, primes = labeled_primes_of_bounded_norm(F, 100)
59
60
from pymongo import Connection
61
C = Connection(address).research
62
if not C.authenticate(user, password):
63
raise RuntimeError, "failed to authenticate"
64
e = C.ellcurves_sqrt5
65
for X in open(aplists_txt_filename).read().splitlines():
66
if X.startswith('#'):
67
continue
68
Nlevel, level, iso_class, ap = X.split('\t')
69
ap = str_to_apdict(ap, labels)
70
Nlevel = int(Nlevel)
71
iso_class = cremona_letter_code(int(iso_class))
72
v = {'level':level, 'iso_class':iso_class,
73
'number':1, 'Nlevel':Nlevel, 'ap':ap}
74
if max_level and Nlevel > max_level: break
75
print v
76
spec = dict(v)
77
del spec['ap']
78
e.update(spec, v, upsert=True, safe=True)
79
return e
80
81
82
83
84
def aplist(E, B=100):
85
"""
86
Compute aplist for an elliptic curve E over Q(sqrt(5)), as a
87
string->number dictionary.
88
89
INPUT:
90
- E -- an elliptic curve
91
- B -- a positive integer (default: 100)
92
93
OUTPUT:
94
- dictionary mapping strings (labeled primes) to Python ints,
95
with keys the primes of P with norm up to B such that the
96
norm of the conductor is coprime to the characteristic of P.
97
"""
98
from psage.modform.hilbert.sqrt5.tables import canonical_gen
99
v = {}
100
from psage.modform.hilbert.sqrt5.sqrt5 import F
101
labels, primes = labeled_primes_of_bounded_norm(F, B)
102
103
from sage.all import ZZ
104
N = E.conductor()
105
try:
106
N = ZZ(N.norm())
107
except:
108
N = ZZ(N)
109
110
for i in range(len(primes)):
111
p = primes[i]
112
k = p.residue_field()
113
if N.gcd(k.cardinality()) == 1:
114
v[labels[i]] = int(k.cardinality() + 1 - E.change_ring(k).cardinality())
115
return v
116
117
118
119