Path: blob/master/src/sage/schemes/elliptic_curves/ell_local_data.py
8821 views
# -*- coding: utf-8 -*-1r"""2Local data for elliptic curves over number fields34Let `E` be an elliptic curve over a number field `K` (including `\QQ`).5There are several local invariants at a finite place `v` that6can be computed via Tate's algorithm (see [Sil2] IV.9.4 or [Ta]).78These include the type of reduction (good, additive, multiplicative),9a minimal equation of `E` over `K_v`,10the Tamagawa number `c_v`, defined to be the index `[E(K_v):E^0(K_v)]`11of the points with good reduction among the local points, and the12exponent of the conductor `f_v`.1314The functions in this file will typically be called by using ``local_data``.1516EXAMPLES::1718sage: K.<i> = NumberField(x^2+1)19sage: E = EllipticCurve([(2+i)^2,(2+i)^7])20sage: pp = K.fractional_ideal(2+i)21sage: da = E.local_data(pp)22sage: da.has_bad_reduction()23True24sage: da.has_multiplicative_reduction()25False26sage: da.kodaira_symbol()27I0*28sage: da.tamagawa_number()29430sage: da.minimal_model()31Elliptic Curve defined by y^2 = x^3 + (4*i+3)*x + (-29*i-278) over Number Field in i with defining polynomial x^2 + 13233An example to show how the Neron model can change as one extends the field::3435sage: E = EllipticCurve([0,-1])36sage: E.local_data(2)37Local data at Principal ideal (2) of Integer Ring:38Reduction type: bad additive39Local minimal model: Elliptic Curve defined by y^2 = x^3 - 1 over Rational Field40Minimal discriminant valuation: 441Conductor exponent: 442Kodaira Symbol: II43Tamagawa Number: 14445sage: EK = E.base_extend(K)46sage: EK.local_data(1+i)47Local data at Fractional ideal (i + 1):48Reduction type: bad additive49Local minimal model: Elliptic Curve defined by y^2 = x^3 + (-1) over Number Field in i with defining polynomial x^2 + 150Minimal discriminant valuation: 851Conductor exponent: 252Kodaira Symbol: IV*53Tamagawa Number: 35455Or how the minimal equation changes::5657sage: E = EllipticCurve([0,8])58sage: E.is_minimal()59True60sage: EK = E.base_extend(K)61sage: da = EK.local_data(1+i)62sage: da.minimal_model()63Elliptic Curve defined by y^2 = x^3 + (-i) over Number Field in i with defining polynomial x^2 + 16465REFERENCES:6667- [Sil2] Silverman, Joseph H., Advanced topics in the arithmetic of elliptic curves.68Graduate Texts in Mathematics, 151. Springer-Verlag, New York, 1994.6970- [Ta] Tate, John, Algorithm for determining the type of a singular fiber in an elliptic pencil.71Modular functions of one variable, IV, pp. 33--52. Lecture Notes in Math., Vol. 476,72Springer, Berlin, 1975.7374AUTHORS:7576- John Cremona: First version 2008-09-21 (refactoring code from77``ell_number_field.py`` and ``ell_rational_field.py``)7879- Chris Wuthrich: more documentation 2010-018081"""8283#*****************************************************************************84# Copyright (C) 2005 William Stein <[email protected]>85#86# Distributed under the terms of the GNU General Public License (GPL)87#88# This code is distributed in the hope that it will be useful,89# but WITHOUT ANY WARRANTY; without even the implied warranty of90# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU91# General Public License for more details.92#93# The full text of the GPL is available at:94#95# http://www.gnu.org/licenses/96#*****************************************************************************979899from sage.structure.sage_object import SageObject100from sage.misc.misc import verbose101102from sage.rings.all import PolynomialRing, QQ, ZZ, Integer, is_NumberFieldElement, is_NumberFieldFractionalIdeal103104from sage.rings.number_field.number_field import is_NumberField105from sage.rings.ideal import is_Ideal106107from constructor import EllipticCurve108from kodaira_symbol import KodairaSymbol109110class EllipticCurveLocalData(SageObject):111r"""112The class for the local reduction data of an elliptic curve.113114Currently supported are elliptic curves defined over `\QQ`, and115elliptic curves defined over a number field, at an arbitrary prime116or prime ideal.117118INPUT:119120- ``E`` -- an elliptic curve defined over a number field, or `\QQ`.121122- ``P`` -- a prime ideal of the field, or a prime integer if the field is `\QQ`.123124- ``proof`` (bool)-- if True, only use provably correct125methods (default controlled by global proof module). Note126that the proof module is number_field, not elliptic_curves,127since the functions that actually need the flag are in128number fields.129130- ``algorithm`` (string, default: "pari") -- Ignored unless the131base field is `\QQ`. If "pari", use the PARI C-library132``ellglobalred`` implementation of Tate's algorithm over133`\QQ`. If "generic", use the general number field134implementation.135136.. note::137138This function is not normally called directly by users, who139may access the data via methods of the EllipticCurve140classes.141142EXAMPLES::143144sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData145sage: E = EllipticCurve('14a1')146sage: EllipticCurveLocalData(E,2)147Local data at Principal ideal (2) of Integer Ring:148Reduction type: bad non-split multiplicative149Local minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field150Minimal discriminant valuation: 6151Conductor exponent: 1152Kodaira Symbol: I6153Tamagawa Number: 2154155"""156157def __init__(self, E, P, proof=None, algorithm="pari", globally=False):158r"""159Initializes the reduction data for the elliptic curve `E` at the prime `P`.160161INPUT:162163- ``E`` -- an elliptic curve defined over a number field, or `\QQ`.164165- ``P`` -- a prime ideal of the field, or a prime integer if the field is `\QQ`.166167- ``proof`` (bool)-- if True, only use provably correct168methods (default controlled by global proof module). Note169that the proof module is number_field, not elliptic_curves,170since the functions that actually need the flag are in171number fields.172173- ``algorithm`` (string, default: "pari") -- Ignored unless the174base field is `\QQ`. If "pari", use the PARI C-library175``ellglobalred`` implementation of Tate's algorithm over176`\QQ`. If "generic", use the general number field177implementation.178179- ``globally`` (bool, default: False) -- If True, the algorithm180uses the generators of principal ideals rather than an arbitrary181uniformizer.182183.. note::184185This function is not normally called directly by users, who186may access the data via methods of the EllipticCurve187classes.188189EXAMPLES::190191sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData192sage: E = EllipticCurve('14a1')193sage: EllipticCurveLocalData(E,2)194Local data at Principal ideal (2) of Integer Ring:195Reduction type: bad non-split multiplicative196Local minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field197Minimal discriminant valuation: 6198Conductor exponent: 1199Kodaira Symbol: I6200Tamagawa Number: 2201202::203204sage: EllipticCurveLocalData(E,2,algorithm="generic")205Local data at Principal ideal (2) of Integer Ring:206Reduction type: bad non-split multiplicative207Local minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field208Minimal discriminant valuation: 6209Conductor exponent: 1210Kodaira Symbol: I6211Tamagawa Number: 2212213::214215sage: EllipticCurveLocalData(E,2,algorithm="pari")216Local data at Principal ideal (2) of Integer Ring:217Reduction type: bad non-split multiplicative218Local minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field219Minimal discriminant valuation: 6220Conductor exponent: 1221Kodaira Symbol: I6222Tamagawa Number: 2223224::225226sage: EllipticCurveLocalData(E,2,algorithm="unknown")227Traceback (most recent call last):228...229ValueError: algorithm must be one of 'pari', 'generic'230231::232233sage: EllipticCurveLocalData(E,3)234Local data at Principal ideal (3) of Integer Ring:235Reduction type: good236Local minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field237Minimal discriminant valuation: 0238Conductor exponent: 0239Kodaira Symbol: I0240Tamagawa Number: 1241242::243244sage: EllipticCurveLocalData(E,7)245Local data at Principal ideal (7) of Integer Ring:246Reduction type: bad split multiplicative247Local minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field248Minimal discriminant valuation: 3249Conductor exponent: 1250Kodaira Symbol: I3251Tamagawa Number: 3252"""253self._curve = E254K = E.base_field()255p = check_prime(K,P) # error handling done in that function256if algorithm != "pari" and algorithm != "generic":257raise ValueError, "algorithm must be one of 'pari', 'generic'"258259self._reduction_type = None260if K is QQ:261self._prime = ZZ.ideal(p)262else:263self._prime = p264265if algorithm=="pari" and K is QQ:266Eint = E.integral_model()267data = Eint.pari_curve().elllocalred(p)268self._fp = data[0].python()269self._KS = KodairaSymbol(data[1].python())270self._cp = data[3].python()271# We use a global minimal model since we can:272self._Emin_reduced = Eint.minimal_model()273self._val_disc = self._Emin_reduced.discriminant().valuation(p)274if self._fp>0:275self._reduction_type = Eint.ap(p) # = 0,-1 or +1276else:277self._Emin, ch, self._val_disc, self._fp, self._KS, self._cp, self._split = self._tate(proof, globally)278if self._fp>0:279if self._Emin.c4().valuation(p)>0:280self._reduction_type = 0281elif self._split:282self._reduction_type = +1283else:284self._reduction_type = -1285286def __repr__(self):287r"""288Returns the string representation of this reduction data.289290EXAMPLES::291292sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData293sage: E = EllipticCurve('14a1')294sage: EllipticCurveLocalData(E,2).__repr__()295'Local data at Principal ideal (2) of Integer Ring:\nReduction type: bad non-split multiplicative\nLocal minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field\nMinimal discriminant valuation: 6\nConductor exponent: 1\nKodaira Symbol: I6\nTamagawa Number: 2'296sage: EllipticCurveLocalData(E,3).__repr__()297'Local data at Principal ideal (3) of Integer Ring:\nReduction type: good\nLocal minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field\nMinimal discriminant valuation: 0\nConductor exponent: 0\nKodaira Symbol: I0\nTamagawa Number: 1'298sage: EllipticCurveLocalData(E,7).__repr__()299'Local data at Principal ideal (7) of Integer Ring:\nReduction type: bad split multiplicative\nLocal minimal model: Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x - 6 over Rational Field\nMinimal discriminant valuation: 3\nConductor exponent: 1\nKodaira Symbol: I3\nTamagawa Number: 3'300"""301red_type = "good"302if not self._reduction_type is None:303red_type = ["bad non-split multiplicative","bad additive","bad split multiplicative"][1+self._reduction_type]304return "Local data at %s:\nReduction type: %s\nLocal minimal model: %s\nMinimal discriminant valuation: %s\nConductor exponent: %s\nKodaira Symbol: %s\nTamagawa Number: %s"%(self._prime,red_type,self.minimal_model(),self._val_disc,self._fp,self._KS,self._cp)305306def minimal_model(self, reduce=True):307"""308Return the (local) minimal model from this local reduction data.309310INPUT:311312- ``reduce`` -- (default: True) if set to True and if the initial313elliptic curve had globally integral coefficients, then the314elliptic curve returned by Tate's algorithm will be "reduced" as315specified in _reduce_model() for curves over number fields.316317EXAMPLES::318319sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData320sage: E = EllipticCurve([0,0,0,0,64]); E321Elliptic Curve defined by y^2 = x^3 + 64 over Rational Field322sage: data = EllipticCurveLocalData(E,2)323sage: data.minimal_model()324Elliptic Curve defined by y^2 = x^3 + 1 over Rational Field325sage: data.minimal_model() == E.local_minimal_model(2)326True327328To demonstrate the behaviour of the parameter ``reduce``::329330sage: K.<a> = NumberField(x^3+x+1)331sage: E = EllipticCurve(K, [0, 0, a, 0, 1])332sage: E.local_data(K.ideal(a-1)).minimal_model()333Elliptic Curve defined by y^2 + a*y = x^3 + 1 over Number Field in a with defining polynomial x^3 + x + 1334sage: E.local_data(K.ideal(a-1)).minimal_model(reduce=False)335Elliptic Curve defined by y^2 + (a+2)*y = x^3 + 3*x^2 + 3*x + (-a+1) over Number Field in a with defining polynomial x^3 + x + 1336337sage: E = EllipticCurve([2, 1, 0, -2, -1])338sage: E.local_data(ZZ.ideal(2), algorithm="generic").minimal_model(reduce=False)339Elliptic Curve defined by y^2 + 2*x*y + 2*y = x^3 + x^2 - 4*x - 2 over Rational Field340sage: E.local_data(ZZ.ideal(2), algorithm="pari").minimal_model(reduce=False)341Traceback (most recent call last):342...343ValueError: the argument reduce must not be False if algorithm=pari is used344sage: E.local_data(ZZ.ideal(2), algorithm="generic").minimal_model()345Elliptic Curve defined by y^2 = x^3 - x^2 - 3*x + 2 over Rational Field346sage: E.local_data(ZZ.ideal(2), algorithm="pari").minimal_model()347Elliptic Curve defined by y^2 = x^3 - x^2 - 3*x + 2 over Rational Field348349:trac:`14476`::350351sage: t = QQ['t'].0352sage: K.<g> = NumberField(t^4 - t^3-3*t^2 - t +1)353sage: E = EllipticCurve([-2*g^3 + 10/3*g^2 + 3*g - 2/3, -11/9*g^3 + 34/9*g^2 - 7/3*g + 4/9, -11/9*g^3 + 34/9*g^2 - 7/3*g + 4/9, 0, 0])354sage: vv = K.fractional_ideal(g^2 - g - 2)355sage: E.local_data(vv).minimal_model()356Elliptic Curve defined by y^2 + (-2*g^3+10/3*g^2+3*g-2/3)*x*y + (-11/9*g^3+34/9*g^2-7/3*g+4/9)*y = x^3 + (-11/9*g^3+34/9*g^2-7/3*g+4/9)*x^2 over Number Field in g with defining polynomial t^4 - t^3 - 3*t^2 - t + 1357358"""359if reduce:360try:361return self._Emin_reduced362except AttributeError:363pass364# trac 14476 we only reduce if the coefficients are globally integral365if all(a.is_integral() for a in self._Emin.a_invariants()):366self._Emin_reduced = self._Emin._reduce_model()367return self._Emin_reduced368else:369return self._Emin370else:371try:372return self._Emin373except AttributeError:374raise ValueError, "the argument reduce must not be False if algorithm=pari is used"375376def prime(self):377"""378Return the prime ideal associated with this local reduction data.379380EXAMPLES::381382sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData383sage: E = EllipticCurve([0,0,0,0,64]); E384Elliptic Curve defined by y^2 = x^3 + 64 over Rational Field385sage: data = EllipticCurveLocalData(E,2)386sage: data.prime()387Principal ideal (2) of Integer Ring388"""389return self._prime390391def conductor_valuation(self):392"""393Return the valuation of the conductor from this local reduction data.394395EXAMPLES::396397sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData398sage: E = EllipticCurve([0,0,0,0,64]); E399Elliptic Curve defined by y^2 = x^3 + 64 over Rational Field400sage: data = EllipticCurveLocalData(E,2)401sage: data.conductor_valuation()4022403"""404return self._fp405406def kodaira_symbol(self):407r"""408Return the Kodaira symbol from this local reduction data.409410EXAMPLES::411412sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData413sage: E = EllipticCurve([0,0,0,0,64]); E414Elliptic Curve defined by y^2 = x^3 + 64 over Rational Field415sage: data = EllipticCurveLocalData(E,2)416sage: data.kodaira_symbol()417IV418"""419return self._KS420421def tamagawa_number(self):422r"""423Return the Tamagawa number from this local reduction data.424425This is the index `[E(K_v):E^0(K_v)]`.426427EXAMPLES::428429sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData430sage: E = EllipticCurve([0,0,0,0,64]); E431Elliptic Curve defined by y^2 = x^3 + 64 over Rational Field432sage: data = EllipticCurveLocalData(E,2)433sage: data.tamagawa_number()4343435"""436return self._cp437438def tamagawa_exponent(self):439r"""440Return the Tamagawa index from this local reduction data.441442This is the exponent of `E(K_v)/E^0(K_v)`; in most cases it is443the same as the Tamagawa index.444445EXAMPLES::446447sage: from sage.schemes.elliptic_curves.ell_local_data import EllipticCurveLocalData448sage: E = EllipticCurve('816a1')449sage: data = EllipticCurveLocalData(E,2)450sage: data.kodaira_symbol()451I2*452sage: data.tamagawa_number()4534454sage: data.tamagawa_exponent()4552456457sage: E = EllipticCurve('200c4')458sage: data = EllipticCurveLocalData(E,5)459sage: data.kodaira_symbol()460I4*461sage: data.tamagawa_number()4624463sage: data.tamagawa_exponent()4642465"""466cp = self._cp467if cp!=4:468return cp469ks = self._KS470if ks._roman==1 and ks._n%2==0 and ks._starred:471return 2472return 4473474def bad_reduction_type(self):475r"""476Return the type of bad reduction of this reduction data.477478OUTPUT:479480(int or ``None``):481482- +1 for split multiplicative reduction483- -1 for non-split multiplicative reduction484- 0 for additive reduction485- ``None`` for good reduction486487EXAMPLES::488489sage: E=EllipticCurve('14a1')490sage: [(p,E.local_data(p).bad_reduction_type()) for p in prime_range(15)]491[(2, -1), (3, None), (5, None), (7, 1), (11, None), (13, None)]492493sage: K.<a>=NumberField(x^3-2)494sage: P17a, P17b = [P for P,e in K.factor(17)]495sage: E = EllipticCurve([0,0,0,0,2*a+1])496sage: [(p,E.local_data(p).bad_reduction_type()) for p in [P17a,P17b]]497[(Fractional ideal (4*a^2 - 2*a + 1), None), (Fractional ideal (2*a + 1), 0)]498"""499return self._reduction_type500501def has_good_reduction(self):502r"""503Return True if there is good reduction.504505EXAMPLES::506507sage: E = EllipticCurve('14a1')508sage: [(p,E.local_data(p).has_good_reduction()) for p in prime_range(15)]509[(2, False), (3, True), (5, True), (7, False), (11, True), (13, True)]510511sage: K.<a> = NumberField(x^3-2)512sage: P17a, P17b = [P for P,e in K.factor(17)]513sage: E = EllipticCurve([0,0,0,0,2*a+1])514sage: [(p,E.local_data(p).has_good_reduction()) for p in [P17a,P17b]]515[(Fractional ideal (4*a^2 - 2*a + 1), True),516(Fractional ideal (2*a + 1), False)]517"""518return self._reduction_type is None519520def has_bad_reduction(self):521r"""522Return True if there is bad reduction.523524EXAMPLES::525526sage: E = EllipticCurve('14a1')527sage: [(p,E.local_data(p).has_bad_reduction()) for p in prime_range(15)]528[(2, True), (3, False), (5, False), (7, True), (11, False), (13, False)]529530::531532sage: K.<a> = NumberField(x^3-2)533sage: P17a, P17b = [P for P,e in K.factor(17)]534sage: E = EllipticCurve([0,0,0,0,2*a+1])535sage: [(p,E.local_data(p).has_bad_reduction()) for p in [P17a,P17b]]536[(Fractional ideal (4*a^2 - 2*a + 1), False),537(Fractional ideal (2*a + 1), True)]538"""539return not self._reduction_type is None540541def has_multiplicative_reduction(self):542r"""543Return True if there is multiplicative reduction.544545.. note::546547See also ``has_split_multiplicative_reduction()`` and548``has_nonsplit_multiplicative_reduction()``.549550EXAMPLES::551552sage: E = EllipticCurve('14a1')553sage: [(p,E.local_data(p).has_multiplicative_reduction()) for p in prime_range(15)]554[(2, True), (3, False), (5, False), (7, True), (11, False), (13, False)]555556::557558sage: K.<a> = NumberField(x^3-2)559sage: P17a, P17b = [P for P,e in K.factor(17)]560sage: E = EllipticCurve([0,0,0,0,2*a+1])561sage: [(p,E.local_data(p).has_multiplicative_reduction()) for p in [P17a,P17b]]562[(Fractional ideal (4*a^2 - 2*a + 1), False), (Fractional ideal (2*a + 1), False)]563"""564return self._reduction_type in (-1,+1)565566def has_split_multiplicative_reduction(self):567r"""568Return True if there is split multiplicative reduction.569570EXAMPLES::571572sage: E = EllipticCurve('14a1')573sage: [(p,E.local_data(p).has_split_multiplicative_reduction()) for p in prime_range(15)]574[(2, False), (3, False), (5, False), (7, True), (11, False), (13, False)]575576::577578sage: K.<a> = NumberField(x^3-2)579sage: P17a, P17b = [P for P,e in K.factor(17)]580sage: E = EllipticCurve([0,0,0,0,2*a+1])581sage: [(p,E.local_data(p).has_split_multiplicative_reduction()) for p in [P17a,P17b]]582[(Fractional ideal (4*a^2 - 2*a + 1), False),583(Fractional ideal (2*a + 1), False)]584"""585return self._reduction_type == +1586587def has_nonsplit_multiplicative_reduction(self):588r"""589Return True if there is non-split multiplicative reduction.590591EXAMPLES::592593sage: E = EllipticCurve('14a1')594sage: [(p,E.local_data(p).has_nonsplit_multiplicative_reduction()) for p in prime_range(15)]595[(2, True), (3, False), (5, False), (7, False), (11, False), (13, False)]596597::598599sage: K.<a> = NumberField(x^3-2)600sage: P17a, P17b = [P for P,e in K.factor(17)]601sage: E = EllipticCurve([0,0,0,0,2*a+1])602sage: [(p,E.local_data(p).has_nonsplit_multiplicative_reduction()) for p in [P17a,P17b]]603[(Fractional ideal (4*a^2 - 2*a + 1), False), (Fractional ideal (2*a + 1), False)]604"""605return self._reduction_type == -1606607def has_additive_reduction(self):608r"""609Return True if there is additive reduction.610611EXAMPLES::612613sage: E = EllipticCurve('27a1')614sage: [(p,E.local_data(p).has_additive_reduction()) for p in prime_range(15)]615[(2, False), (3, True), (5, False), (7, False), (11, False), (13, False)]616617::618619sage: K.<a> = NumberField(x^3-2)620sage: P17a, P17b = [P for P,e in K.factor(17)]621sage: E = EllipticCurve([0,0,0,0,2*a+1])622sage: [(p,E.local_data(p).has_additive_reduction()) for p in [P17a,P17b]]623[(Fractional ideal (4*a^2 - 2*a + 1), False),624(Fractional ideal (2*a + 1), True)]625"""626return self._reduction_type == 0627628def _tate(self, proof = None, globally = False):629r"""630Tate's algorithm for an elliptic curve over a number field.631632Computes both local reduction data at a prime ideal and a633local minimal model.634635The model is not required to be integral on input. If `P` is636principal, uses a generator as uniformizer, so it will not637affect integrality or minimality at other primes. If `P` is not638principal, the minimal model returned will preserve639integrality at other primes, but not minimality.640641The optional argument globally, when set to True, tells the algorithm to use the generator of the prime ideal if it is principal. Otherwise just any uniformizer will be used.642643.. note::644645Called only by ``EllipticCurveLocalData.__init__()``.646647OUTPUT:648649(tuple) ``(Emin, p, val_disc, fp, KS, cp)`` where:650651- ``Emin`` (EllipticCurve) is a model (integral and) minimal at P652- ``p`` (int) is the residue characteristic653- ``val_disc`` (int) is the valuation of the local minimal discriminant654- ``fp`` (int) is the valuation of the conductor655- ``KS`` (string) is the Kodaira symbol656- ``cp`` (int) is the Tamagawa number657658659EXAMPLES (this raised a type error in sage prior to 4.4.4, see :trac:`7930`) ::660661sage: E = EllipticCurve('99d1')662663sage: R.<X> = QQ[]664sage: K.<t> = NumberField(X^3 + X^2 - 2*X - 1)665sage: L.<s> = NumberField(X^3 + X^2 - 36*X - 4)666667sage: EK = E.base_extend(K)668sage: toK = EK.torsion_order()669sage: da = EK.local_data() # indirect doctest670671sage: EL = E.base_extend(L)672sage: da = EL.local_data() # indirect doctest673674EXAMPLES:675676The following example shows that the bug at :trac:`9324` is fixed::677678sage: K.<a> = NumberField(x^2-x+6)679sage: E = EllipticCurve([0,0,0,-53160*a-43995,-5067640*a+19402006])680sage: E.conductor() # indirect doctest681Fractional ideal (18, 6*a)682683The following example shows that the bug at :trac:`9417` is fixed::684685sage: K.<a> = NumberField(x^2+18*x+1)686sage: E = EllipticCurve(K, [0, -36, 0, 320, 0])687sage: E.tamagawa_number(K.ideal(2))6884689690This is to show that the bug :trac: `11630` is fixed. (The computation of the class group would produce a warning)::691692sage: K.<t> = NumberField(x^7-2*x+177)693sage: E = EllipticCurve([0,1,0,t,t])694sage: P = K.ideal(2,t^3 + t + 1)695sage: E.local_data(P).kodaira_symbol()696II697698"""699E = self._curve700P = self._prime701K = E.base_ring()702OK = K.maximal_order()703t = verbose("Running Tate's algorithm with P = %s"%P, level=1)704F = OK.residue_field(P)705p = F.characteristic()706707# In case P is not principal we mostly use a uniformiser which708# is globally integral (with positive valuation at some other709# primes); for this to work, it is essential that we can710# reduce (mod P) elements of K which are not integral (but are711# P-integral). However, if the model is non-minimal and we712# end up dividing a_i by pi^i then at that point we use a713# uniformiser pi which has non-positive valuation at all other714# primes, so that we can divide by it without losing715# integrality at other primes.716717if globally:718principal_flag = P.is_principal()719else:720principal_flag = False721722if (K is QQ) or principal_flag :723pi = P.gens_reduced()[0]724verbose("P is principal, generator pi = %s"%pi, t, 1)725else:726pi = K.uniformizer(P, 'positive')727verbose("uniformizer pi = %s"%pi, t, 1)728pi2 = pi*pi; pi3 = pi*pi2; pi4 = pi*pi3729pi_neg = None730prime = pi if K is QQ else P731732pval = lambda x: x.valuation(prime)733pdiv = lambda x: x.is_zero() or pval(x) > 0734# Since ResidueField is cached in a way that735# does not care much about embeddings of number736# fields, it can happen that F.p.ring() is different737# from K. This is a problem: If F.p.ring() has no738# embedding but K has, then there is no coercion739# from F.p.ring().maximal_order() to K. But it is740# no problem to do an explicit conversion in that741# case (Simon King, trac ticket #8800).742743from sage.categories.pushout import pushout, CoercionException744try:745if hasattr(F.p.ring(), 'maximal_order'): # it is not ZZ746_tmp_ = pushout(F.p.ring().maximal_order(),K)747pinv = lambda x: F.lift(~F(x))748proot = lambda x,e: F.lift(F(x).nth_root(e, extend = False, all = True)[0])749preduce = lambda x: F.lift(F(x))750except CoercionException: # the pushout does not exist, we need conversion751pinv = lambda x: K(F.lift(~F(x)))752proot = lambda x,e: K(F.lift(F(x).nth_root(e, extend = False, all = True)[0]))753preduce = lambda x: K(F.lift(F(x)))754755def _pquadroots(a, b, c):756r"""757Local function returning True iff `ax^2 + bx + c` has roots modulo `P`758"""759(a, b, c) = (F(a), F(b), F(c))760if a == 0:761return (b != 0) or (c == 0)762elif p == 2:763return len(PolynomialRing(F, "x")([c,b,a]).roots()) > 0764else:765return (b**2 - 4*a*c).is_square()766def _pcubicroots(b, c, d):767r"""768Local function returning the number of roots of `x^3 +769b*x^2 + c*x + d` modulo `P`, counting multiplicities770"""771772return sum([rr[1] for rr in PolynomialRing(F, 'x')([F(d), F(c), F(b), F(1)]).roots()],0)773774if p == 2:775halfmodp = OK(Integer(0))776else:777halfmodp = pinv(Integer(2))778779A = E.a_invariants()780A = [0, A[0], A[1], A[2], A[3], 0, A[4]]781indices = [1,2,3,4,6]782if min([pval(a) for a in A if a != 0]) < 0:783verbose("Non-integral model at P: valuations are %s; making integral"%([pval(a) for a in A if a != 0]), t, 1)784e = 0785for i in range(7):786if A[i] != 0:787e = max(e, (-pval(A[i])/i).ceil())788pie = pi**e789for i in range(7):790if A[i] != 0:791A[i] *= pie**i792verbose("P-integral model is %s, with valuations %s"%([A[i] for i in indices], [pval(A[i]) for i in indices]), t, 1)793794split = None # only relevant for multiplicative reduction795796(a1, a2, a3, a4, a6) = (A[1], A[2], A[3], A[4], A[6])797while True:798C = EllipticCurve([a1, a2, a3, a4, a6]);799(b2, b4, b6, b8) = C.b_invariants()800(c4, c6) = C.c_invariants()801delta = C.discriminant()802val_disc = pval(delta)803804if val_disc == 0:805## Good reduction already806cp = 1807fp = 0808KS = KodairaSymbol("I0")809break #return810811# Otherwise, we change coordinates so that p | a3, a4, a6812if p == 2:813if pdiv(b2):814r = proot(a4, 2)815t = proot(((r + a2)*r + a4)*r + a6, 2)816else:817temp = pinv(a1)818r = temp * a3819t = temp * (a4 + r*r)820elif p == 3:821if pdiv(b2):822r = proot(-b6, 3)823else:824r = -pinv(b2) * b4825t = a1 * r + a3826else:827if pdiv(c4):828r = -pinv(12) * b2829else:830r = -pinv(12*c4) * (c6 + b2 * c4)831t = -halfmodp * (a1 * r + a3)832r = preduce(r)833t = preduce(t)834verbose("Before first transform C = %s"%C)835verbose("[a1,a2,a3,a4,a6] = %s"%([a1, a2, a3, a4, a6]))836C = C.rst_transform(r, 0, t)837(a1, a2, a3, a4, a6) = C.a_invariants()838(b2, b4, b6, b8) = C.b_invariants()839if min([pval(a) for a in (a1, a2, a3, a4, a6) if a != 0]) < 0:840raise RuntimeError, "Non-integral model after first transform!"841verbose("After first transform %s\n, [a1,a2,a3,a4,a6] = %s\n, valuations = %s"%([r, 0, t], [a1, a2, a3, a4, a6], [pval(a1), pval(a2), pval(a3), pval(a4), pval(a6)]), t, 2)842if pval(a3) == 0:843raise RuntimeError, "p does not divide a3 after first transform!"844if pval(a4) == 0:845raise RuntimeError, "p does not divide a4 after first transform!"846if pval(a6) == 0:847raise RuntimeError, "p does not divide a6 after first transform!"848849# Now we test for Types In, II, III, IV850# NB the c invariants never change.851852if not pdiv(c4):853# Multiplicative reduction: Type In (n = val_disc)854split = False855if _pquadroots(1, a1, -a2):856cp = val_disc857split = True858elif Integer(2).divides(val_disc):859cp = 2860else:861cp = 1862KS = KodairaSymbol("I%s"%val_disc)863fp = 1864break #return865866# Additive reduction867868if pval(a6) < 2:869## Type II870KS = KodairaSymbol("II")871fp = val_disc872cp = 1873break #return874if pval(b8) < 3:875## Type III876KS = KodairaSymbol("III")877fp = val_disc - 1878cp = 2879break #return880if pval(b6) < 3:881## Type IV882cp = 1883a3t = preduce(a3/pi)884a6t = preduce(a6/pi2)885if _pquadroots(1, a3t, -a6t): cp = 3886KS = KodairaSymbol("IV")887fp = val_disc - 2888break #return889890# If our curve is none of these types, we change coords so that891# p | a1, a2; p^2 | a3, a4; p^3 | a6892if p == 2:893s = proot(a2, 2) # so s^2=a2 (mod pi)894t = pi*proot(a6/pi2, 2) # so t^2=a6 (mod pi^3)895elif p == 3:896s = a1 # so a1'=2s+a1=3a1=0 (mod pi)897t = a3 # so a3'=2t+a3=3a3=0 (mod pi^2)898else:899s = -a1*halfmodp # so a1'=2s+a1=0 (mod pi)900t = -a3*halfmodp # so a3'=2t+a3=0 (mod pi^2)901C = C.rst_transform(0, s, t)902(a1, a2, a3, a4, a6) = C.a_invariants()903(b2, b4, b6, b8) = C.b_invariants()904verbose("After second transform %s\n[a1, a2, a3, a4, a6] = %s\nValuations: %s"%([0, s, t], [a1,a2,a3,a4,a6],[pval(a1),pval(a2),pval(a3),pval(a4),pval(a6)]), t, 2)905if pval(a1) == 0:906raise RuntimeError, "p does not divide a1 after second transform!"907if pval(a2) == 0:908raise RuntimeError, "p does not divide a2 after second transform!"909if pval(a3) < 2:910raise RuntimeError, "p^2 does not divide a3 after second transform!"911if pval(a4) < 2:912raise RuntimeError, "p^2 does not divide a4 after second transform!"913if pval(a6) < 3:914raise RuntimeError, "p^3 does not divide a6 after second transform!"915if min(pval(a1), pval(a2), pval(a3), pval(a4), pval(a6)) < 0:916raise RuntimeError, "Non-integral model after second transform!"917918# Analyze roots of the cubic T^3 + bT^2 + cT + d = 0 mod P, where919# b = a2/p, c = a4/p^2, d = a6/p^3920b = preduce(a2/pi)921c = preduce(a4/pi2)922d = preduce(a6/pi3)923bb = b*b924cc = c*c925bc = b*c926w = 27*d*d - bb*cc + 4*b*bb*d - 18*bc*d + 4*c*cc927x = 3*c - bb928if pdiv(w):929if pdiv(x):930sw = 3931else:932sw = 2933else:934sw = 1935verbose("Analyzing roots of cubic T^3 + %s*T^2 + %s*T + %s, case %s"%(b, c, d, sw), t, 1)936if sw == 1:937## Three distinct roots - Type I*0938verbose("Distinct roots", t, 1)939KS = KodairaSymbol("I0*")940cp = 1 + _pcubicroots(b, c, d)941fp = val_disc - 4942break #return943elif sw == 2:944## One double root - Type I*m for some m945verbose("One double root", t, 1)946## Change coords so that the double root is T = 0 mod p947if p == 2:948r = proot(c, 2)949elif p == 3:950r = c * pinv(b)951else:952r = (bc - 9*d)*pinv(2*x)953r = pi * preduce(r)954C = C.rst_transform(r, 0, 0)955(a1, a2, a3, a4, a6) = C.a_invariants()956(b2, b4, b6, b8) = C.b_invariants()957# The rest of this branch is just to compute cp, fp, KS.958# We use pi to keep transforms integral.959ix = 3; iy = 3; mx = pi2; my = mx960while True:961a2t = preduce(a2 / pi)962a3t = preduce(a3 / my)963a4t = preduce(a4 / (pi*mx))964a6t = preduce(a6 / (mx*my))965if pdiv(a3t*a3t + 4*a6t):966if p == 2:967t = my*proot(a6t, 2)968else:969t = my*preduce(-a3t*halfmodp)970C = C.rst_transform(0, 0, t)971(a1, a2, a3, a4, a6) = C.a_invariants()972(b2, b4, b6, b8) = C.b_invariants()973my *= pi974iy += 1975a2t = preduce(a2 / pi)976a3t = preduce(a3/my)977a4t = preduce(a4/(pi*mx))978a6t = preduce(a6/(mx*my))979if pdiv(a4t*a4t - 4*a6t*a2t):980if p == 2:981r = mx*proot(a6t*pinv(a2t), 2)982else:983r = mx*preduce(-a4t*pinv(2*a2t))984C = C.rst_transform(r, 0, 0)985(a1, a2, a3, a4, a6) = C.a_invariants()986(b2, b4, b6, b8) = C.b_invariants()987mx *= pi988ix += 1 # and stay in loop989else:990if _pquadroots(a2t, a4t, a6t):991cp = 4992else:993cp = 2994break # exit loop995else:996if _pquadroots(1, a3t, -a6t):997cp = 4998else:999cp = 21000break1001KS = KodairaSymbol("I%s*"%(ix+iy-5))1002fp = val_disc - ix - iy + 11003break #return1004else: # sw == 31005## The cubic has a triple root1006verbose("Triple root", t, 1)1007## First we change coordinates so that T = 0 mod p1008if p == 2:1009r = b1010elif p == 3:1011r = proot(-d, 3)1012else:1013r = -b * pinv(3)1014r = pi*preduce(r)1015C = C.rst_transform(r, 0, 0)1016(a1, a2, a3, a4, a6) = C.a_invariants()1017(b2, b4, b6, b8) = C.b_invariants()1018verbose("After third transform %s\n[a1,a2,a3,a4,a6] = %s\nValuations: %s"%([r,0,0],[a1,a2,a3,a4,a6],[pval(ai) for ai in [a1,a2,a3,a4,a6]]), t, 2)1019if min(pval(ai) for ai in [a1,a2,a3,a4,a6]) < 0:1020raise RuntimeError, "Non-integral model after third transform!"1021if pval(a2) < 2 or pval(a4) < 3 or pval(a6) < 4:1022raise RuntimeError, "Cubic after transform does not have a triple root at 0"1023a3t = preduce(a3/pi2)1024a6t = preduce(a6/pi4)1025# We test for Type IV*1026if not pdiv(a3t*a3t + 4*a6t):1027cp = 3 if _pquadroots(1, a3t, -a6t) else 11028KS = KodairaSymbol("IV*")1029fp = val_disc - 61030break #return1031# Now change coordinates so that p^3|a3, p^5|a61032if p==2:1033t = -pi2*proot(a6t, 2)1034else:1035t = pi2*preduce(-a3t*halfmodp)1036C = C.rst_transform(0, 0, t)1037(a1, a2, a3, a4, a6) = C.a_invariants()1038(b2, b4, b6, b8) = C.b_invariants()1039# We test for types III* and II*1040if pval(a4) < 4:1041## Type III*1042KS = KodairaSymbol("III*")1043fp = val_disc - 71044cp = 21045break #return1046if pval(a6) < 6:1047## Type II*1048KS = KodairaSymbol("II*")1049fp = val_disc - 81050cp = 11051break #return1052if pi_neg is None:1053if principal_flag:1054pi_neg = pi1055else:1056pi_neg = K.uniformizer(P, 'negative')1057pi_neg2 = pi_neg*pi_neg1058pi_neg3 = pi_neg*pi_neg21059pi_neg4 = pi_neg*pi_neg31060pi_neg6 = pi_neg4*pi_neg21061a1 /= pi_neg1062a2 /= pi_neg21063a3 /= pi_neg31064a4 /= pi_neg41065a6 /= pi_neg61066verbose("Non-minimal equation, dividing out...\nNew model is %s"%([a1, a2, a3, a4, a6]), t, 1)1067return (C, p, val_disc, fp, KS, cp, split)106810691070def check_prime(K,P):1071r"""1072Function to check that `P` determines a prime of `K`, and return that ideal.10731074INPUT:10751076- ``K`` -- a number field (including `\QQ`).10771078- ``P`` -- an element of ``K`` or a (fractional) ideal of ``K``.10791080OUTPUT:10811082- If ``K`` is `\QQ`: the prime integer equal to or which generates `P`.10831084- If ``K`` is not `\QQ`: the prime ideal equal to or generated by `P`.10851086.. note::10871088If `P` is not a prime and does not generate a prime, a TypeError is raised.10891090EXAMPLES::10911092sage: from sage.schemes.elliptic_curves.ell_local_data import check_prime1093sage: check_prime(QQ,3)109431095sage: check_prime(QQ,ZZ.ideal(31))1096311097sage: K.<a>=NumberField(x^2-5)1098sage: check_prime(K,a)1099Fractional ideal (a)1100sage: check_prime(K,a+1)1101Fractional ideal (a + 1)1102sage: [check_prime(K,P) for P in K.primes_above(31)]1103[Fractional ideal (5/2*a + 1/2), Fractional ideal (5/2*a - 1/2)]1104"""1105if K is QQ:1106if isinstance(P, (int,long,Integer)):1107P = Integer(P)1108if P.is_prime():1109return P1110else:1111raise TypeError, "%s is not prime"%P1112else:1113if is_Ideal(P) and P.base_ring() is ZZ and P.is_prime():1114return P.gen()1115raise TypeError, "%s is not a prime ideal of %s"%(P,ZZ)11161117if not is_NumberField(K):1118raise TypeError, "%s is not a number field"%K11191120if is_NumberFieldFractionalIdeal(P):1121if P.is_prime():1122return P1123else:1124raise TypeError, "%s is not a prime ideal of %s"%(P,K)11251126if is_NumberFieldElement(P):1127if P in K:1128P = K.ideal(P)1129else:1130raise TypeError, "%s is not an element of %s"%(P,K)1131if P.is_prime():1132return P1133else:1134raise TypeError, "%s is not a prime ideal of %s"%(P,K)11351136raise TypeError, "%s is not a valid prime of %s"%(P,K)113711381139