Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/ecnf/elliptic_curve_to_ecnf_format.py
1128 views
1
2
from sage.all import ZZ,QQ,PolynomialRing,EllipticCurve,pari
3
from lmfdb.WebNumberField import WebNumberField
4
from lmfdb.nfutils.psort import ideal_label
5
from scripts.ecnf.import_utils import make_curves_line
6
7
debug = False
8
9
10
def EllipticCurve_from_hoeij_data(line):
11
"""Given a line of the file "http://www.math.fsu.edu/~hoeij/files/X1N/LowDegreePlaces"
12
that is actually corresponding to an elliptic curve, this function returns the elliptic
13
curve corresponding to this
14
"""
15
Rx=PolynomialRing(QQ,'x')
16
x = Rx.gen(0)
17
Rxy = PolynomialRing(Rx,'y')
18
y = Rxy.gen(0)
19
20
N=ZZ(line.split(",")[0].split()[-1])
21
x_rel=Rx(line.split(',')[-2][2:-4])
22
assert x_rel.leading_coefficient()==1
23
y_rel=line.split(',')[-1][1:-5]
24
K = QQ.extension(x_rel,'x')
25
x = K.gen(0)
26
27
y_rel=Rxy(y_rel).change_ring(K)
28
y_rel=y_rel/y_rel.leading_coefficient()
29
if y_rel.degree()==1:
30
y = - y_rel[0]
31
else:
32
#print("needing an extension!!!!")
33
L = K.extension(y_rel,'y')
34
y = L.gen(0)
35
K = L
36
#B=L.absolute_field('s')
37
#f1,f2 = B.structure()
38
#x,y=f2(x),f2(y)
39
r = (x**2*y-x*y+y-1)/x/(x*y-1)
40
s = (x*y-y+1)/x/y
41
b = r*s*(r-1)
42
c = s*(r-1)
43
E=EllipticCurve([1-c,-b,-b,0,0])
44
return N,E,K
45
46
47
48
def to_polredabs(K):
49
"""
50
51
INPUT:
52
53
* "K" - a number field
54
55
OUTPUT:
56
57
* "phi" - an isomorphism K -> L, where L = QQ['x']/f and f a polynomial such that f = polredabs(f)
58
"""
59
R = PolynomialRing(QQ,'x')
60
x = R.gen(0)
61
if K == QQ:
62
L = QQ.extension(x,'w')
63
return QQ.hom(L)
64
L = K.absolute_field('a')
65
m1 = L.structure()[1]
66
f = L.absolute_polynomial()
67
g = pari(f).polredabs(1)
68
g,h = g[0].sage(locals={'x':x}),g[1].lift().sage(locals={'x':x})
69
if debug:
70
print('f', f)
71
print('g', g)
72
print('h', h)
73
M = QQ.extension(g,'w')
74
m2 = L.hom([h(M.gen(0))])
75
return m2*m1
76
77
78
def base_change(E, phi):
79
"""
80
INPUT:
81
82
- E -- an elliptic curve
83
- phi -- morphism whose domain is the base ring of E
84
85
OUTPUT:
86
87
the elliptic curve obtained by applying phi to the coefficients of E
88
"""
89
return EllipticCurve(phi.codomain(),map(phi,E.a_invariants()))
90
91
92
def EllipticCurve_polredabs_a_invariants(E,morphism=True):
93
"""
94
Input:
95
- E - an elliptic curve over a number field K
96
Output:
97
- [a1,a2,a3,a4,a6] - the a_invariants of E base changed along phi: K -> L
98
where phi is the morphism from K to its polredabs field
99
"""
100
K = E.base_field()
101
phi = to_polredabs(K)
102
ainvs = map(phi,E.a_invariants())
103
if morphism:
104
return ainvs,phi
105
return ainvs
106
#E_polred = base_change(E,phi)
107
#assert E.conductor().norm() == E_polred.conductor().norm()
108
#return E_polred
109
110
def EllipticCurve_polredabs(E):
111
"""
112
Input:
113
- E - an elliptic curve over a number field K
114
Output:
115
- E1 - the elliptic curve that is the base change of E along phi: K -> L
116
where phi is the morphism from K to its polredabs field
117
"""
118
return EllipticCurve(EllipticCurve_polredabs_a_invariants(E,False))
119
120
def EllipticCurve_to_ecnf_dict(E):
121
"""
122
Make the dict that should be fed to `make_curves_line` in `lmfdb/scripts/ecnf/import_utils.py`.
123
124
It sets `iso_label`, 'a' and `number` to '1' and `cm` and `base_change` to '?'
125
126
INPUT:
127
128
* E - A sage elliptic curve over a number field
129
"""
130
E = EllipticCurve_polredabs(E)
131
K = E.base_field()
132
WNF = WebNumberField.from_polredabs(K.polynomial())
133
ainvs = [map(str,ai) for ai in map(list,E.a_invariants())]
134
conductor = E.conductor()
135
conductor_str = "".join(str([conductor.norm()]+list(conductor.gens_two())).split())
136
ec = {'field_label':WNF.label,
137
'conductor_label':ideal_label(conductor),
138
'iso_label':'a',
139
'number':'1',
140
'conductor_ideal':conductor_str,
141
'conductor_norm':str(conductor.norm()),
142
'ainvs':ainvs,
143
'cm':'?',
144
'base_change':'?'}
145
return ec
146
147
def EllipticCurve_make_line(E):
148
"""
149
Just make_curves_line applied to EllipticCurve_to_ecnf_dict
150
151
INPUT:
152
153
* E - A sage elliptic curve over a number field
154
"""
155
return make_curves_line(EllipticCurve_to_ecnf_dict(E))
156
157
def hoeij_to_ecnf(url="http://www.math.fsu.edu/~hoeij/files/X1N/LowDegreePlaces",path="./curves.hoeij"):
158
import urllib2
159
file = urllib2.urlopen(url)
160
data = file.read()
161
file.close()
162
lines = [l for l in data.splitlines() if l[:3] == "N =" and "[" in l]
163
164
with open(path, 'w') as out_file:
165
for line in lines:
166
E = EllipticCurve_from_hoeij_data(line)
167
out_line = EllipticCurve_make_line(E[1])
168
out_file.write(out_line + "\n")
169
170