Path: blob/master/src/sage/schemes/elliptic_curves/gp_simon.py
8821 views
"""1Denis Simon's PARI scripts2"""34#*****************************************************************************5# Copyright (C) 2005 William Stein <[email protected]>6#7# Distributed under the terms of the GNU General Public License (GPL)8#9# This code is distributed in the hope that it will be useful,10# but WITHOUT ANY WARRANTY; without even the implied warranty of11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12# General Public License for more details.13#14# The full text of the GPL is available at:15#16# http://www.gnu.org/licenses/17#*****************************************************************************1819from sage.structure.parent_gens import localvars2021from sage.interfaces.gp import Gp22from sage.misc.sage_eval import sage_eval23from sage.misc.randstate import current_randstate24from sage.rings.all import QQ25from constructor import EllipticCurve2627gp = None28def init():29"""30Function to initialize the gp process31"""32global gp33if gp is None:34gp = Gp(script_subdirectory='simon')35gp.read("ell.gp")36gp.read("ellQ.gp")37gp.read("qfsolve.gp")38gp.read("resultant3.gp")394041def simon_two_descent(E, verbose=0, lim1=5, lim3=50, limtriv=10, maxprob=20, limbigprime=30):42"""43Interface to Simon's gp script for two-descent.4445.. NOTE::4647Users should instead run E.simon_two_descent()4849EXAMPLES::5051sage: import sage.schemes.elliptic_curves.gp_simon52sage: E=EllipticCurve('389a1')53sage: sage.schemes.elliptic_curves.gp_simon.simon_two_descent(E)54[2, 2, [(1 : 0 : 1), (-11/9 : -55/27 : 1)]]55sage: E.simon_two_descent()56(2, 2, [(1 : 0 : 1), (-11/9 : -55/27 : 1)])5758TESTS::5960sage: E = EllipticCurve('37a1').change_ring(QuadraticField(-11,'x'))61sage: E.simon_two_descent()62(1, 1, [(-1 : 0 : 1)])6364"""65init()6667current_randstate().set_seed_gp(gp)6869K = E.base_ring()70K_orig = K71# The following is to correct the bug at \#5204: the gp script72# fails when K is a number field whose generator is called 'x'.73if not K is QQ:74K = K.change_names('a')75E_orig = E76E = EllipticCurve(K,[K(list(a)) for a in E.ainvs()])77F = E.integral_model()7879if K != QQ:80# Simon's program requires that this name be y.81with localvars(K.polynomial().parent(), 'y'):82gp.eval("K = bnfinit(%s);" % K.polynomial())83if verbose >= 2:84print "K = bnfinit(%s);" % K.polynomial()85gp.eval("%s = Mod(y,K.pol);" % K.gen())86if verbose >= 2:87print "%s = Mod(y,K.pol);" % K.gen()8889if K == QQ:90cmd = 'ellrank([%s,%s,%s,%s,%s]);' % F.ainvs()91else:92cmd = 'bnfellrank(K, [%s,%s,%s,%s,%s]);' % F.ainvs()9394gp('DEBUGLEVEL_ell=%s; LIM1=%s; LIM3=%s; LIMTRIV=%s; MAXPROB=%s; LIMBIGPRIME=%s;'%(95verbose, lim1, lim3, limtriv, maxprob, limbigprime))9697if verbose >= 2:98print cmd99s = gp.eval('ans=%s;'%cmd)100if s.find("***") != -1:101raise RuntimeError, "\n%s\nAn error occurred while running Simon's 2-descent program"%s102if verbose > 0:103print s104v = gp.eval('ans')105if v=='ans': # then the call to ellrank() or bnfellrank() failed106return 'fail'107if verbose >= 2:108print "v = ", v109# pari represents field elements as Mod(poly, defining-poly)110# so this function will return the respective elements of K111def _gp_mod(*args):112return args[0]113ans = sage_eval(v, {'Mod': _gp_mod, 'y': K.gen(0)})114inv_transform = F.isomorphism_to(E)115ans[2] = [inv_transform(F(P)) for P in ans[2]]116ans[2] = [E_orig([K_orig(list(c)) for c in list(P)]) for P in ans[2]]117return ans118119120121