Path: blob/master/src/sage/schemes/hyperelliptic_curves/mestre.py
8820 views
r"""1Mestre's algorithm23This file contains functions that:45- create hyperelliptic curves from the Igusa-Clebsch invariants (over6`\QQ` and finite fields)7- create Mestre's conic from the Igusa-Clebsch invariants89AUTHORS:1011- Florian Bouyer12- Marco Streng1314"""15#*****************************************************************************16# Copyright (C) 2011, 2012, 201317# Florian Bouyer <[email protected]>18# Marco Streng <[email protected]>19#20# Distributed under the terms of the GNU General Public License (GPL)21# as published by the Free Software Foundation; either version 2 of22# the License, or (at your option) any later version.23# http://www.gnu.org/licenses/24#*****************************************************************************2526from sage.matrix.all import Matrix27from sage.schemes.plane_conics.constructor import Conic28from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing29from sage.schemes.hyperelliptic_curves.constructor import HyperellipticCurve303132def HyperellipticCurve_from_invariants(i, reduced=True, precision=None,33algorithm='default'):34r"""35Returns a hyperelliptic curve with the given Igusa-Clebsch invariants up to36scaling.3738The output is a curve over the field in which the Igusa-Clebsch invariants39are given. The output curve is unique up to isomorphism over the algebraic40closure. If no such curve exists over the given field, then raise a41ValueError.4243INPUT:4445- ``i`` - list or tuple of length 4 containing the four Igusa-Clebsch46invariants: I2,I4,I6,I10.47- ``reduced`` - Boolean (default = True) If True, tries to reduce the48polynomial defining the hyperelliptic curve using the function49:func:`reduce_polynomial` (see the :func:`reduce_polynomial`50documentation for more details).51- ``precision`` - integer (default = None) Which precision for real and52complex numbers should the reduction use. This only affects the53reduction, not the correctness. If None, the algorithm uses the default5453 bit precision.55- ``algorithm`` - ``'default'`` or ``'magma'``. If set to ``'magma'``, uses56Magma to parameterize Mestre's conic (needs Magma to be installed).5758OUTPUT:5960A hyperelliptic curve object.6162EXAMPLE:6364Examples over the rationals::6566sage: HyperellipticCurve_from_invariants([3840,414720,491028480,2437709561856])67Traceback (most recent call last):68...69NotImplementedError: Reduction of hyperelliptic curves not yet implemented. See trac #14755 and #14756.70sage: HyperellipticCurve_from_invariants([3840,414720,491028480,2437709561856],reduced = False)71Hyperelliptic Curve over Rational Field defined by y^2 = -x^6 + 4410*x^5 - 540*x^4 + 4320*x^3 - 19440*x^2 + 46656*x - 4665672sage: HyperellipticCurve_from_invariants([21, 225/64, 22941/512, 1])73Traceback (most recent call last):74...75NotImplementedError: Reduction of hyperelliptic curves not yet implemented. See trac #14755 and #14756.7677An example over a finite field::7879sage: HyperellipticCurve_from_invariants([GF(13)(1),3,7,5])80Hyperelliptic Curve over Finite Field of size 13 defined by y^2 = 8*x^5 + 5*x^4 + 5*x^2 + 9*x + 38182An example over a number field::8384sage: K = QuadraticField(353, 'a')85sage: H = HyperellipticCurve_from_invariants([21, 225/64, 22941/512, 1], reduced = false)86sage: f = K['x'](H.hyperelliptic_polynomials()[0])8788If the Mestre Conic defined by the Igusa-Clebsch invariants has no rational89points, then there exists no hyperelliptic curve over the base field with90the given invariants.::9192sage: HyperellipticCurve_from_invariants([1,2,3,4])93Traceback (most recent call last):94...95ValueError: No such curve exists over Rational Field as there are no rational points on Projective Conic Curve over Rational Field defined by -2572155000*u^2 - 317736000*u*v + 1250755459200*v^2 + 2501510918400*u*w + 39276887040*v*w + 2736219686912*w^29697Mestre's algorithm only works for generic curves of genus two, so another98algorithm is needed for those curves with extra automorphism. See also99:trac:`12199`::100101sage: P.<x> = QQ[]102sage: C = HyperellipticCurve(x^6+1)103sage: i = C.igusa_clebsch_invariants()104sage: HyperellipticCurve_from_invariants(i)105Traceback (most recent call last):106...107TypeError: F (=0) must have degree 2108109110Igusa-Clebsch invariants also only work over fields of charateristic111different from 2, 3, and 5, so another algorithm will be needed for fields112of those characteristics. See also :trac:`12200`::113114sage: P.<x> = GF(3)[]115sage: HyperellipticCurve(x^6+x+1).igusa_clebsch_invariants()116Traceback (most recent call last):117...118NotImplementedError: Invariants of binary sextics/genus 2 hyperelliptic curves not implemented in characteristics 2, 3, and 5119sage: HyperellipticCurve_from_invariants([GF(5)(1),1,0,1])120Traceback (most recent call last):121...122ZeroDivisionError: Inverse does not exist.123124ALGORITHM:125126This is Mestre's algorithm [M1991]_. Our implementation is based on the127formulae on page 957 of [LY2001]_, cross-referenced with [W1999]_ to128correct typos.129130First construct Mestre's conic using the :func:`Mestre_conic` function.131Parametrize the conic if possible.132Let `f_1, f_2, f_3` be the three coordinates of the parametrization of the133conic by the projective line, and change them into one variable by letting134`F_i = f_i(t, 1)`. Note that each `F_i` has degree at most 2.135136Then construct a sextic polynomial137`f = \sum_{0<=i,j,k<=3}{c_{ijk}*F_i*F_j*F_k}`,138where `c_{ijk}` are defined as rational functions in the invariants139(see the source code for detailed formulae for `c_{ijk}`).140The output is the hyperelliptic curve `y^2 = f`.141142REFERENCES:143144.. [LY2001] K. Lauter and T. Yang, "Computing genus 2 curves from145invariants on the Hilbert moduli space", Journal of Number Theory 131146(2011), pages 936 - 958147.. [M1991] J.-F. Mestre, "Construction de courbes de genre 2 a partir de148leurs modules", in Effective methods in algebraic geometry149(Castiglioncello, 1990), volume 94 of Progr. Math., pages 313 - 334150.. [W1999] P. van Wamelen, Pari-GP code, section "thecubic"151https://www.math.lsu.edu/~wamelen/Genus2/FindCurve/igusa2curve.gp152"""153from sage.structure.sequence import Sequence154i = Sequence(i)155k = i.universe()156try:157k = k.fraction_field()158except (TypeError, AttributeError, NotImplementedError):159pass160161MConic, x, y, z = Mestre_conic(i, xyz=True)162if k.is_finite():163reduced = False164165t = k['t'].gen()166167if algorithm == 'magma':168from sage.interfaces.all import magma169from sage.misc.sage_eval import sage_eval170if MConic.has_rational_point(algorithm='magma'):171parametrization = [l.replace('$.1', 't').replace('$.2', 'u') \172for l in str(magma(MConic).Parametrization()).splitlines()[4:7]]173[F1, F2, F3] = [sage_eval(p, locals={'t':t,'u':1,'a':k.gen()}) \174for p in parametrization]175else:176raise ValueError("No such curve exists over %s as there are no " \177"rational points on %s" % (k, MConic))178else:179if MConic.has_rational_point():180parametrization = MConic.parametrization(morphism=False)[0]181[F1, F2, F3] = [p(t, 1) for p in parametrization]182else:183raise ValueError("No such curve exists over %s as there are no " \184"rational points on %s" % (k, MConic))185186# setting the cijk from Mestre's algorithm187c111 = 12*x*y - 2*y/3 - 4*z188c112 = -18*x**3 - 12*x*y - 36*y**2 - 2*z189c113 = -9*x**3 - 36*x**2*y -4*x*y - 6*x*z - 18*y**2190c122 = c113191c123 = -54*x**4 - 36*x**2*y - 36*x*y**2 - 6*x*z - 4*y**2 - 24*y*z192c133 = -27*x**4/2 - 72*x**3*y - 6*x**2*y - 9*x**2*z - 39*x*y**2 - \19336*y**3 - 2*y*z194c222 = -27*x**4 - 18*x**2*y - 6*x*y**2 - 8*y**2/3 + 2*y*z195c223 = 9*x**3*y - 27*x**2*z + 6*x*y**2 + 18*y**3 - 8*y*z196c233 = -81*x**5/2 - 27*x**3*y - 9*x**2*y**2 - 4*x*y**2 + 3*x*y*z - 6*z**2197c333 = 27*x**4*y/2 - 27*x**3*z/2 + 9*x**2*y**2 + 3*x*y**3 - 6*x*y*z + \1984*y**3/3 - 10*y**2*z199200# writing out the hyperelliptic curve polynomial201f = c111*F1**3 + c112*F1**2*F2 + c113*F1**2*F3 + c122*F1*F2**2 + \202c123*F1*F2*F3 + c133*F1*F3**2 + c222*F2**3 + c223*F2**2*F3 + \203c233*F2*F3**2 + c333*F3**3204205try:206f = f*f.denominator() # clear the denominator207except (AttributeError, TypeError):208pass209210if reduced:211raise NotImplementedError("Reduction of hyperelliptic curves not " \212"yet implemented. " \213"See trac #14755 and #14756.")214215return HyperellipticCurve(f)216217218def Mestre_conic(i, xyz=False, names='u,v,w'):219r"""220Return the conic equation from Mestre's algorithm given the Igusa-Clebsch221invariants.222223It has a rational point if and only if a hyperelliptic curve224corresponding to the invariants exists.225226INPUT:227228- ``i`` - list or tuple of length 4 containing the four Igusa-Clebsch229invariants: I2, I4, I6, I10230- ``xyz`` - Boolean (default: False) if True, the algorithm also231returns three invariants x,y,z used in Mestre's algorithm232- ``names`` (default: 'u,v,w') - the variable names for the Conic233234OUTPUT:235236A Conic object237238EXAMPLES:239240A standard example::241242sage: Mestre_conic([1,2,3,4])243Projective Conic Curve over Rational Field defined by -2572155000*u^2 - 317736000*u*v + 1250755459200*v^2 + 2501510918400*u*w + 39276887040*v*w + 2736219686912*w^2244245Note that the algorithm works over number fields as well::246247sage: k = NumberField(x^2-41,'a')248sage: a = k.an_element()249sage: Mestre_conic([1,2+a,a,4+a])250Projective Conic Curve over Number Field in a with defining polynomial x^2 - 41 defined by (-801900000*a + 343845000)*u^2 + (855360000*a + 15795864000)*u*v + (312292800000*a + 1284808579200)*v^2 + (624585600000*a + 2569617158400)*u*w + (15799910400*a + 234573143040)*v*w + (2034199306240*a + 16429854656512)*w^2251252And over finite fields::253254sage: Mestre_conic([GF(7)(10),GF(7)(1),GF(7)(2),GF(7)(3)])255Projective Conic Curve over Finite Field of size 7 defined by -2*u*v - v^2 - 2*u*w + 2*v*w - 3*w^2256257An example with xyz::258259sage: Mestre_conic([5,6,7,8], xyz=True)260(Projective Conic Curve over Rational Field defined by -415125000*u^2 + 608040000*u*v + 33065136000*v^2 + 66130272000*u*w + 240829440*v*w + 10208835584*w^2, 232/1125, -1072/16875, 14695616/2109375)261262ALGORITHM:263264The formulas are taken from pages 956 - 957 of [LY2001]_ and based on pages265321 and 332 of [M1991]_.266267See the code or [LY2001]_ for the detailed formulae defining x, y, z and L.268269"""270from sage.structure.sequence import Sequence271k = Sequence(i).universe()272try:273k = k.fraction_field()274except (TypeError, AttributeError, NotImplementedError):275pass276277I2, I4, I6, I10 = i278279#Setting x,y,z as in Mestre's algorithm (Using Lauter and Yang's formulas)280x = 8*(1 + 20*I4/(I2**2))/225281y = 16*(1 + 80*I4/(I2**2) - 600*I6/(I2**3))/3375282z = -64*(-10800000*I10/(I2**5) - 9 - 700*I4/(I2**2) + 3600*I6/(I2**3) +28312400*I4**2/(I2**4) - 48000*I4*I6/(I2**5))/253125284285L = Matrix([[x+6*y , 6*x**2+2*y , 2*z ],286[6*x**2+2*y, 2*z , 9*x**3 + 4*x*y + 6*y**2 ],287[2*z , 9*x**3+4*x*y+6*y**2, 6*x**2*y + 2*y**2 + 3*x*z]])288289try:290L = L*L.denominator() # clears the denominator291except (AttributeError, TypeError):292pass293294u, v, w = PolynomialRing(k, names).gens()295MConic = Conic(k, L, names)296if xyz:297return MConic, x, y, z298return MConic299300301