Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/schemes/elliptic_curves/gp_simon.py
8821 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 sage.structure.parent_gens import localvars
21
22
from sage.interfaces.gp import Gp
23
from sage.misc.sage_eval import sage_eval
24
from sage.misc.randstate import current_randstate
25
from sage.rings.all import QQ
26
from constructor import EllipticCurve
27
28
gp = None
29
def init():
30
"""
31
Function to initialize the gp process
32
"""
33
global gp
34
if gp is None:
35
gp = Gp(script_subdirectory='simon')
36
gp.read("ell.gp")
37
gp.read("ellQ.gp")
38
gp.read("qfsolve.gp")
39
gp.read("resultant3.gp")
40
41
42
def simon_two_descent(E, verbose=0, lim1=5, lim3=50, limtriv=10, maxprob=20, limbigprime=30):
43
"""
44
Interface to Simon's gp script for two-descent.
45
46
.. NOTE::
47
48
Users should instead run E.simon_two_descent()
49
50
EXAMPLES::
51
52
sage: import sage.schemes.elliptic_curves.gp_simon
53
sage: E=EllipticCurve('389a1')
54
sage: sage.schemes.elliptic_curves.gp_simon.simon_two_descent(E)
55
[2, 2, [(1 : 0 : 1), (-11/9 : -55/27 : 1)]]
56
sage: E.simon_two_descent()
57
(2, 2, [(1 : 0 : 1), (-11/9 : -55/27 : 1)])
58
59
TESTS::
60
61
sage: E = EllipticCurve('37a1').change_ring(QuadraticField(-11,'x'))
62
sage: E.simon_two_descent()
63
(1, 1, [(-1 : 0 : 1)])
64
65
"""
66
init()
67
68
current_randstate().set_seed_gp(gp)
69
70
K = E.base_ring()
71
K_orig = K
72
# The following is to correct the bug at \#5204: the gp script
73
# fails when K is a number field whose generator is called 'x'.
74
if not K is QQ:
75
K = K.change_names('a')
76
E_orig = E
77
E = EllipticCurve(K,[K(list(a)) for a in E.ainvs()])
78
F = E.integral_model()
79
80
if K != QQ:
81
# Simon's program requires that this name be y.
82
with localvars(K.polynomial().parent(), 'y'):
83
gp.eval("K = bnfinit(%s);" % K.polynomial())
84
if verbose >= 2:
85
print "K = bnfinit(%s);" % K.polynomial()
86
gp.eval("%s = Mod(y,K.pol);" % K.gen())
87
if verbose >= 2:
88
print "%s = Mod(y,K.pol);" % K.gen()
89
90
if K == QQ:
91
cmd = 'ellrank([%s,%s,%s,%s,%s]);' % F.ainvs()
92
else:
93
cmd = 'bnfellrank(K, [%s,%s,%s,%s,%s]);' % F.ainvs()
94
95
gp('DEBUGLEVEL_ell=%s; LIM1=%s; LIM3=%s; LIMTRIV=%s; MAXPROB=%s; LIMBIGPRIME=%s;'%(
96
verbose, lim1, lim3, limtriv, maxprob, limbigprime))
97
98
if verbose >= 2:
99
print cmd
100
s = gp.eval('ans=%s;'%cmd)
101
if s.find("***") != -1:
102
raise RuntimeError, "\n%s\nAn error occurred while running Simon's 2-descent program"%s
103
if verbose > 0:
104
print s
105
v = gp.eval('ans')
106
if v=='ans': # then the call to ellrank() or bnfellrank() failed
107
return 'fail'
108
if verbose >= 2:
109
print "v = ", v
110
# pari represents field elements as Mod(poly, defining-poly)
111
# so this function will return the respective elements of K
112
def _gp_mod(*args):
113
return args[0]
114
ans = sage_eval(v, {'Mod': _gp_mod, 'y': K.gen(0)})
115
inv_transform = F.isomorphism_to(E)
116
ans[2] = [inv_transform(F(P)) for P in ans[2]]
117
ans[2] = [E_orig([K_orig(list(c)) for c in list(P)]) for P in ans[2]]
118
return ans
119
120
121