def cmp_label(lab1, lab2): from sage.databases.cremona import parse_cremona_label, class_to_int a, b, c = parse_cremona_label(lab1) id1 = int(a), class_to_int(b), int(c) a, b, c = parse_cremona_label(lab2) id2 = int(a), class_to_int(b), int(c) return cmp(id1, id2)
def curve_cmp(E1, E2): r""" Comparison function for elliptic curves over `Q`. Order by label if in the database, else first by conductor, then by c_invariants. """ t = cmp(E1.conductor(), E2.conductor()) if t: return t # Now they have the same conductor try: from sage.databases.cremona import parse_cremona_label, class_to_int k1 = parse_cremona_label(E1.label()) k2 = parse_cremona_label(E2.label()) t = cmp(class_to_int(k1[1]), class_to_int(k2[1])) if t: return t return cmp(k1[2], k2[2]) except RuntimeError: # if not in database, label() will fail pass return cmp(E1.ainvs(), E2.ainvs())
def test_conductor_pair(p, N1, N2): import sage.databases.cremona as c for E1 in cremona_optimal_curves([N1]): if N1 == N2: cl1 = c.class_to_int(c.parse_cremona_label(E1.label())[1]) else: cl1 = 0 for E2 in cremona_optimal_curves([N2]): if N1 == N2: cl2 = c.class_to_int(c.parse_cremona_label(E2.label())[1]) else: cl2 = 0 if N1 != N2 or cl2 < cl1: res, info = test_cong(p, E1, E2) if res: report(res, info, p, E1.label(), E2.label())
def curve_key(E1): r""" Comparison key for elliptic curves over `\QQ`. The key is a tuple: - if the curve is in the database: (conductor, 0, label, number) - otherwise: (conductor, 1, a_invariants) EXAMPLES:: sage: from sage.schemes.elliptic_curves.ell_egros import curve_key sage: E = EllipticCurve_from_j(1728) sage: curve_key(E) (32, 0, 0, 2) sage: E = EllipticCurve_from_j(1729) sage: curve_key(E) (2989441, 1, (1, 0, 0, -36, -1)) """ try: from sage.databases.cremona import parse_cremona_label, class_to_int N, l, k = parse_cremona_label(E1.label()) return (N, 0, class_to_int(l), k) except LookupError: return (E1.conductor(), 1, E1.ainvs())
def sorting_label(d1): """ Provide a sorting key. """ from sage.databases.cremona import parse_cremona_label, class_to_int a, b, c = parse_cremona_label(d1["label"]) return (int(a), class_to_int(b), int(c))
def curve_key(E1): r""" Comparison key for elliptic curves over `\QQ`. The key is a tuple: - if the curve is in the database: (conductor, 0, label, number) - otherwise: (conductor, 1, a_invariants) EXAMPLES:: sage: from sage.schemes.elliptic_curves.ell_egros import curve_key sage: E = EllipticCurve_from_j(1728) sage: curve_key(E) (32, 0, 0, 2) sage: E = EllipticCurve_from_j(1729) sage: curve_key(E) (2989441, 1, (1, 0, 0, -36, -1)) """ try: from sage.databases.cremona import parse_cremona_label, class_to_int N, l, k = parse_cremona_label(E1.label()) return (N, 0, class_to_int(l), k) except RuntimeError: return (E1.conductor(), 1, E1.ainvs())
def cmp_label(lab1, lab2): """ EXAMPLES:: cmp_label('24a5', '33a1') -1 cmp_label('11a1', '11a1') 0 """ from sage.databases.cremona import parse_cremona_label, class_to_int a, b, c = parse_cremona_label(lab1) id1 = int(a), class_to_int(b), int(c) a, b, c = parse_cremona_label(lab2) id2 = int(a), class_to_int(b), int(c) if id1 == id2: return 0 return -1 if id1 < id2 else 1
def __scale_by_periods_only__(self): r""" If we fail to scale with ``_find_scaling_L_ratio``, we drop here to try and find the scaling by the quotient of the periods to the `X_0`-optimal curve. The resulting ``_scaling`` is not guaranteed to be correct, but could well be. EXAMPLES:: sage: E = EllipticCurve('19a1') sage: m = E.modular_symbol(sign=+1) sage: m.__scale_by_periods_only__() Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by -1, 2 or -2. sage: m._scaling 1 sage: E = EllipticCurve('19a2') sage: m = E.modular_symbol(sign=+1) sage: m._scaling 3/2 sage: m.__scale_by_periods_only__() Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by -1, 2 or -2. sage: m._scaling 3 """ # we only do this inside the cremona-tables. try: crla = parse_cremona_label(self._E.label()) except RuntimeError: # raised when curve is outside of the table print( "Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by a rational number." ) self._scaling = 1 else: print( "Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by -1, 2 or -2." ) cr0 = Integer(crla[0]).str() + crla[1] + '1' E0 = EllipticCurve(cr0) if self._sign == 1: q = E0.period_lattice().basis()[0] / self._E.period_lattice( ).basis()[0] else: q = E0.period_lattice().basis()[1].imag( ) / self._E.period_lattice().basis()[1].imag() if E0.real_components() == 1: q *= 2 if self._E.real_components() == 1: q /= 2 q = ZZ(int(round(q * 200))) / 200 verbose('scale modular symbols by %s' % q) self._scaling = q
def curve_cmp(E1, E2): r""" Comparison function for elliptic curves over `\QQ`. Order by label if in the database, else first by conductor, then by c_invariants. Deprecated, please use instead `curve_key`. EXAMPLES:: sage: from sage.schemes.elliptic_curves.ell_egros import curve_cmp sage: E1 = EllipticCurve_from_j(1728) sage: E2 = EllipticCurve_from_j(1729) sage: curve_cmp(E1,E2) doctest:...: DeprecationWarning: Please use 'curve_key' instead. See http://trac.sagemath.org/21142 for details. -1 """ from sage.misc.superseded import deprecation deprecation(21142, "Please use 'curve_key' instead.") t = cmp(E1.conductor(), E2.conductor()) if t: return t # Now they have the same conductor try: from sage.databases.cremona import parse_cremona_label, class_to_int k1 = parse_cremona_label(E1.label()) k2 = parse_cremona_label(E2.label()) t = cmp(class_to_int(k1[1]), class_to_int(k2[1])) if t: return t return cmp(k1[2], k2[2]) except RuntimeError: # if not in database, label() will fail pass return cmp(E1.ainvs(), E2.ainvs())
def curve_cmp(E1, E2): r""" Comparison function for elliptic curves over `\QQ`. Order by label if in the database, else first by conductor, then by c_invariants. Deprecated, please use instead `curve_key`. EXAMPLES:: sage: from sage.schemes.elliptic_curves.ell_egros import curve_cmp sage: E1 = EllipticCurve_from_j(1728) sage: E2 = EllipticCurve_from_j(1729) sage: curve_cmp(E1,E2) doctest:...: DeprecationWarning: Please use 'curve_key' instead. See http://trac.sagemath.org/21142 for details. -1 """ from sage.misc.superseded import deprecation deprecation(21142, "Please use 'curve_key' instead.") t = cmp(E1.conductor(), E2.conductor()) if t: return t # Now they have the same conductor try: from sage.databases.cremona import parse_cremona_label, class_to_int k1 = parse_cremona_label(E1.label()) k2 = parse_cremona_label(E2.label()) t = cmp(class_to_int(k1[1]),class_to_int(k2[1])) if t: return t return cmp(k1[2], k2[2]) except RuntimeError: # if not in database, label() will fail pass return cmp(E1.ainvs(),E2.ainvs())
def _find_scaling_period(self): r""" Uses the integral period map of the modular symbol implementation in sage in order to determine the scaling. The resulting modular symbol is correct only for the `X_0`-optimal curve, at least up to a possible factor +-1 or +-2. EXAMPLES:: sage: E = EllipticCurve('11a1') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (1/5, 1) sage: E = EllipticCurve('11a2') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (1, 5) sage: E = EllipticCurve('121b2') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (0, 11/2, 0, 11/2, 11/2, 0, 0, -3, 2, 1/2, -1, 3/2) """ P = self._modsym.integral_period_mapping() self._e = P.matrix().transpose().row(0) self._e /= 2 E = self._E try: crla = parse_cremona_label(E.label()) except RuntimeError: # raised when curve is outside of the table self._scaling = 1 else: cr0 = Integer(crla[0]).str() + crla[1] + '1' E0 = EllipticCurve(cr0) if self._sign == 1: q = E0.period_lattice().basis()[0] / E.period_lattice().basis( )[0] else: q = E0.period_lattice().basis()[1].imag() / E.period_lattice( ).basis()[1].imag() if E0.real_components() == 1: q *= 2 if E.real_components() == 1: q /= 2 q = QQ(int(round(q * 200))) / 200 verbose('scale modular symbols by %s' % q) self._scaling = q self._e *= self._scaling
def __scale_by_periods_only__(self): r""" If we fail to scale with ``_find_scaling_L_ratio``, we drop here to try and find the scaling by the quotient of the periods to the `X_0`-optimal curve. The resulting ``_scaling`` is not guaranteed to be correct, but could well be. EXAMPLES:: sage: E = EllipticCurve('19a1') sage: m = E.modular_symbol(sign=+1) sage: m.__scale_by_periods_only__() Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by -1, 2 or -2. sage: m._scaling 1 sage: E = EllipticCurve('19a2') sage: m = E.modular_symbol(sign=+1) sage: m._scaling 3/2 sage: m.__scale_by_periods_only__() Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by -1, 2 or -2. sage: m._scaling 3 """ # we only do this inside the cremona-tables. try : crla = parse_cremona_label(self._E.label()) except RuntimeError: # raised when curve is outside of the table print("Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by a rational number.") self._scaling = 1 else : print("Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by -1, 2 or -2.") cr0 = Integer(crla[0]).str() + crla[1] + '1' E0 = EllipticCurve(cr0) if self._sign == 1: q = E0.period_lattice().basis()[0]/self._E.period_lattice().basis()[0] else: q = E0.period_lattice().basis()[1].imag()/self._E.period_lattice().basis()[1].imag() if E0.real_components() == 1: q *= 2 if self._E.real_components() == 1: q /= 2 q = ZZ(int(round(q*200)))/200 verbose('scale modular symbols by %s'%q) self._scaling = q
def _find_scaling_period(self): r""" Uses the integral period map of the modular symbol implementation in sage in order to determine the scaling. The resulting modular symbol is correct only for the `X_0`-optimal curve, at least up to a possible factor +-1 or +-2. EXAMPLES:: sage: E = EllipticCurve('11a1') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (1/5, 1) sage: E = EllipticCurve('11a2') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (1, 5) sage: E = EllipticCurve('121b2') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (0, 11/2, 0, 11/2, 11/2, 0, 0, -3, 2, 1/2, -1, 3/2) """ P = self._modsym.integral_period_mapping() self._e = P.matrix().transpose().row(0) self._e /= 2 E = self._E try : crla = parse_cremona_label(E.label()) except RuntimeError: # raised when curve is outside of the table self._scaling = 1 else : cr0 = Integer(crla[0]).str() + crla[1] + '1' E0 = EllipticCurve(cr0) if self._sign == 1: q = E0.period_lattice().basis()[0]/E.period_lattice().basis()[0] else: q = E0.period_lattice().basis()[1].imag()/E.period_lattice().basis()[1].imag() if E0.real_components() == 1: q *= 2 if E.real_components() == 1: q /= 2 q = QQ(int(round(q*200)))/200 verbose('scale modular symbols by %s'%q) self._scaling = q self._e *= self._scaling
def cmp_label(lab1, lab2): a, b, c = parse_cremona_label(lab1) id1 = int(a), class_to_int(b), int(c) a, b, c = parse_cremona_label(lab2) id2 = int(a), class_to_int(b), int(c) return cmp(id1, id2)
def _find_scaling_period(self): r""" Uses the integral period map of the modular symbol implementation in sage in order to determine the scaling. The resulting modular symbol is correct only for the `X_0`-optimal curve, at least up to a possible factor +- a power of 2. EXAMPLES:: sage: E = EllipticCurve('11a1') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (1/5, 1/2) sage: E = EllipticCurve('11a2') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (1, 5/2) sage: E = EllipticCurve('121b2') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (0, 0, 0, 11/2, 11/2, 11/2, 11/2, -3, 3/2, 1/2, -1, 2) TESTS:: sage: E = EllipticCurve('19a1') sage: m = E.modular_symbol(sign=+1, implementation='sage', normalize='none') sage: m._find_scaling_period() sage: m._scaling 1 sage: E = EllipticCurve('19a2') sage: m = E.modular_symbol(sign=+1, implementation='sage', normalize='none') sage: m._scaling 1 sage: m._find_scaling_period() sage: m._scaling 3 """ P = self._modsym.integral_period_mapping() self._e = P.matrix().transpose().row(0) self._e /= 2 E = self._E try: crla = parse_cremona_label(E.label()) except RuntimeError: # raised when curve is outside of the table print( "Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by a rational number." ) self._scaling = 1 else: cr0 = Integer(crla[0]).str() + crla[1] + '1' E0 = EllipticCurve(cr0) if self._sign == 1: q = E0.period_lattice().basis()[0] / E.period_lattice().basis( )[0] else: q = E0.period_lattice().basis()[1].imag() / E.period_lattice( ).basis()[1].imag() if E0.real_components() == 1: q *= 2 if E.real_components() == 1: q /= 2 q = QQ((q * 200).round()) / 200 verbose('scale modular symbols by %s' % q) self._scaling = q c = self(0) # required, to change base point from oo to 0 if c < 0: c *= -1 self._scaling *= -1 self._at_zero = c self._e *= self._scaling
def sorting_label(lab1): """ Provide a sorting key. """ a, b, c = parse_cremona_label(lab1) return (int(a), class_to_int(b), int(c))
def _find_scaling_period(self): r""" Uses the integral period map of the modular symbol implementation in sage in order to determine the scaling. The resulting modular symbol is correct only for the `X_0`-optimal curve, at least up to a possible factor +- a power of 2. EXAMPLES:: sage: E = EllipticCurve('11a1') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (1/5, 1) sage: E = EllipticCurve('11a2') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (1, 5) sage: E = EllipticCurve('121b2') sage: m = sage.schemes.elliptic_curves.ell_modular_symbols.ModularSymbolSage(E,+1,normalize='period') sage: m._e (0, 11/2, 0, 11/2, 11/2, 0, 0, -3, 2, 1/2, -1, 3/2) TESTS:: sage: E = EllipticCurve('19a1') sage: m = E.modular_symbol(sign=+1, implementation='sage', normalize='none') sage: m._find_scaling_period() sage: m._scaling 1 sage: E = EllipticCurve('19a2') sage: m = E.modular_symbol(sign=+1, implementation='sage', normalize='none') sage: m._scaling 1 sage: m._find_scaling_period() sage: m._scaling 3 """ P = self._modsym.integral_period_mapping() self._e = P.matrix().transpose().row(0) self._e /= 2 E = self._E try : crla = parse_cremona_label(E.label()) except RuntimeError: # raised when curve is outside of the table print("Warning : Could not normalize the modular symbols, maybe all further results will be multiplied by a rational number.") self._scaling = 1 else : cr0 = Integer(crla[0]).str() + crla[1] + '1' E0 = EllipticCurve(cr0) if self._sign == 1: q = E0.period_lattice().basis()[0]/E.period_lattice().basis()[0] else: q = E0.period_lattice().basis()[1].imag()/E.period_lattice().basis()[1].imag() if E0.real_components() == 1: q *= 2 if E.real_components() == 1: q /= 2 q = QQ(int(round(q*200)))/200 verbose('scale modular symbols by %s'%q) self._scaling = q c = self(0) # required, to change base point from oo to 0 if c<0: c *= -1 self._scaling *= -1 self._at_zero = c self._e *= self._scaling
def make_allcurves_lines(outfile, code, ainvs, r, t): E = EllipticCurve(ainvs) N, cl, n = parse_cremona_label(code) for i, F in enumerate(E.isogeny_class().curves): put_allcurves_line(outfile,N,cl,str(i+1),list(F.ainvs()),r,F.torsion_order()) outfile.flush()