Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/schemes/elliptic_curves/gp_simon.py
4108 views
1
"""
2
Denis Simon's PARI scripts
3
"""
4
5
#*****************************************************************************
6
# Copyright (C) 2005 William Stein <[email protected]>
7
#
8
# Distributed under the terms of the GNU General Public License (GPL)
9
#
10
# This code is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# General Public License for more details.
14
#
15
# The full text of the GPL is available at:
16
#
17
# http://www.gnu.org/licenses/
18
#*****************************************************************************
19
20
from __future__ import with_statement
21
22
23
from sage.structure.parent_gens import localvars
24
25
from sage.interfaces.gp import Gp
26
from sage.misc.sage_eval import sage_eval
27
from sage.misc.randstate import current_randstate
28
from sage.rings.all import QQ
29
from constructor import EllipticCurve
30
31
gp = None
32
def init():
33
"""
34
Function to initialize the gp process
35
"""
36
global gp
37
if gp is None:
38
gp = Gp(script_subdirectory='simon')
39
gp.read("ell.gp")
40
gp.read("ellQ.gp")
41
gp.read("qfsolve.gp")
42
gp.read("resultant3.gp")
43
44
45
def simon_two_descent(E, verbose=0, lim1=5, lim3=50, limtriv=10, maxprob=20, limbigprime=30):
46
"""
47
Interface to Simon's gp script for two-descent.
48
49
.. NOTE::
50
51
Users should instead run E.simon_two_descent()
52
53
EXAMPLES::
54
55
sage: import sage.schemes.elliptic_curves.gp_simon
56
sage: E=EllipticCurve('389a1')
57
sage: sage.schemes.elliptic_curves.gp_simon.simon_two_descent(E)
58
[2, 2, [(1 : 0 : 1), (-11/9 : -55/27 : 1)]]
59
sage: E.simon_two_descent()
60
(2, 2, [(1 : 0 : 1), (-11/9 : -55/27 : 1)])
61
62
TESTS::
63
64
sage: E = EllipticCurve('37a1').change_ring(QuadraticField(-11,'x'))
65
sage: E.simon_two_descent()
66
(1, 1, [(-1 : 0 : 1)])
67
68
"""
69
init()
70
71
current_randstate().set_seed_gp(gp)
72
73
K = E.base_ring()
74
K_orig = K
75
# The following is to correct the bug at \#5204: the gp script
76
# fails when K is a number field whose generator is called 'x'.
77
if not K is QQ:
78
K = K.change_names('a')
79
E_orig = E
80
E = EllipticCurve(K,[K(list(a)) for a in E.ainvs()])
81
F = E.integral_model()
82
83
if K != QQ:
84
# Simon's program requires that this name be y.
85
with localvars(K.polynomial().parent(), 'y'):
86
gp.eval("K = bnfinit(%s);" % K.polynomial())
87
if verbose >= 2:
88
print "K = bnfinit(%s);" % K.polynomial()
89
gp.eval("%s = Mod(y,K.pol);" % K.gen())
90
if verbose >= 2:
91
print "%s = Mod(y,K.pol);" % K.gen()
92
93
if K == QQ:
94
cmd = 'ellrank([%s,%s,%s,%s,%s]);' % F.ainvs()
95
else:
96
cmd = 'bnfellrank(K, [%s,%s,%s,%s,%s]);' % F.ainvs()
97
98
gp('DEBUGLEVEL_ell=%s; LIM1=%s; LIM3=%s; LIMTRIV=%s; MAXPROB=%s; LIMBIGPRIME=%s;'%(
99
verbose, lim1, lim3, limtriv, maxprob, limbigprime))
100
101
if verbose >= 2:
102
print cmd
103
s = gp.eval('ans=%s;'%cmd)
104
if s.find("###") != -1:
105
raise RuntimeError, "%s\nAn error occurred while running Simon's 2-descent program"%s
106
if verbose > 0:
107
print s
108
v = gp.eval('ans')
109
if v=='ans': # then the call to ellrank() or bnfellrank() failed
110
return 'fail'
111
if verbose >= 2:
112
print "v = ", v
113
# pari represents field elements as Mod(poly, defining-poly)
114
# so this function will return the respective elements of K
115
def _gp_mod(*args):
116
return args[0]
117
ans = sage_eval(v, {'Mod': _gp_mod, 'y': K.gen(0)})
118
inv_transform = F.isomorphism_to(E)
119
ans[2] = [inv_transform(F(P)) for P in ans[2]]
120
ans[2] = [E_orig([K_orig(list(c)) for c in list(P)]) for P in ans[2]]
121
return ans
122
123
124