From 442deb7bf7e48a2514bb7943d7e54895b7159f2f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 12:14:55 -0700 Subject: [PATCH 01/20] sage.modular: Modularization fixes for imports --- src/sage/modular/abvar/homspace.py | 6 ++-- src/sage/modular/btquotients/btquotient.py | 8 ++--- src/sage/modular/cusps.py | 6 +++- src/sage/modular/dirichlet.py | 7 ++-- src/sage/modular/hecke/ambient_module.py | 13 ++++--- src/sage/modular/hecke/submodule.py | 8 ++--- src/sage/modular/modform/ambient_eps.py | 6 ++-- src/sage/modular/modform/ambient_g0.py | 4 +-- src/sage/modular/modform/ambient_g1.py | 6 ++-- src/sage/modular/modform/constructor.py | 34 ++++++++++--------- .../hecke_triangle_group_element.py | 27 ++++++++------- src/sage/modular/modsym/boundary.py | 7 ++-- src/sage/modular/modsym/modsym.py | 15 ++++---- src/sage/modular/multiple_zeta.py | 5 ++- src/sage/modular/quatalg/brandt.py | 6 ++-- src/sage/modular/ssmod/ssmod.py | 4 ++- 16 files changed, 89 insertions(+), 73 deletions(-) diff --git a/src/sage/modular/abvar/homspace.py b/src/sage/modular/abvar/homspace.py index 1b29df45c1b..6d96cc0fabe 100644 --- a/src/sage/modular/abvar/homspace.py +++ b/src/sage/modular/abvar/homspace.py @@ -186,14 +186,14 @@ from . import morphism import sage.rings.integer_ring -import sage.rings.all +from sage.rings.infinity import Infinity from sage.rings.ring import Ring from sage.matrix.matrix_space import MatrixSpace from sage.matrix.constructor import Matrix, identity_matrix from sage.structure.element import is_Matrix -ZZ = sage.rings.integer_ring.ZZ +from sage.rings.integer_ring import ZZ class Homspace(HomsetWithBase): @@ -882,7 +882,7 @@ def index_in(self, other, check=True): M = self.free_module() N = other.free_module() if M.rank() < N.rank(): - return sage.rings.all.Infinity + return Infinity return M.index_in(N) def index_in_saturation(self): diff --git a/src/sage/modular/btquotients/btquotient.py b/src/sage/modular/btquotients/btquotient.py index ff9701f3d33..6ced79751c3 100644 --- a/src/sage/modular/btquotients/btquotient.py +++ b/src/sage/modular/btquotients/btquotient.py @@ -41,10 +41,7 @@ from copy import copy from collections import deque -from sage.algebras.quatalg.quaternion_algebra import QuaternionAlgebra from sage.arith.misc import gcd, xgcd, kronecker_symbol, fundamental_discriminant -from sage.graphs.graph import Graph -from sage.interfaces.magma import magma from sage.libs.pari.all import pari from sage.matrix.constructor import Matrix from sage.matrix.matrix_space import MatrixSpace @@ -57,7 +54,6 @@ from sage.modular.arithgroup.all import Gamma0 from sage.modular.arithgroup.congroup_gammaH import GammaH_constructor from sage.modular.dirichlet import DirichletGroup -lazy_import("sage.plot.colors", "rainbow") from sage.quadratic_forms.quadratic_form import QuadraticForm from sage.rings.finite_rings.finite_field_constructor import GF from sage.rings.finite_rings.integer_mod_ring import Zmod @@ -70,6 +66,10 @@ from sage.structure.sage_object import SageObject from sage.structure.unique_representation import UniqueRepresentation +lazy_import('sage.algebras.quatalg.quaternion_algebra', 'QuaternionAlgebra') +lazy_import('sage.graphs.graph', 'Graph') +lazy_import('sage.plot.colors', 'rainbow') + class DoubleCosetReduction(SageObject): r""" diff --git a/src/sage/modular/cusps.py b/src/sage/modular/cusps.py index 27147942a6a..05c0deda58e 100644 --- a/src/sage/modular/cusps.py +++ b/src/sage/modular/cusps.py @@ -28,7 +28,6 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.libs.pari.all import pari, pari_gen from sage.misc.fast_methods import Singleton from sage.modular.modsym.p1list import lift_to_sl2z_llong from sage.rings.infinity import Infinity, InfinityRing @@ -41,6 +40,11 @@ from sage.structure.parent import Parent from sage.structure.richcmp import richcmp +try: + from sage.libs.pari.all import pari, pari_gen +except ImportError: + pari_gen = () + class Cusp(Element): """ diff --git a/src/sage/modular/dirichlet.py b/src/sage/modular/dirichlet.py index 68b4eaaa4f1..f20345cfb2d 100644 --- a/src/sage/modular/dirichlet.py +++ b/src/sage/modular/dirichlet.py @@ -65,18 +65,16 @@ from sage.arith.misc import bernoulli, kronecker, factor, gcd, fundamental_discriminant, euler_phi, valuation from sage.categories.map import Map from sage.categories.objects import Objects -from sage.functions.other import binomial, factorial -from sage.libs.pari import pari from sage.misc.cachefunc import cached_method from sage.misc.fast_methods import WithEqualityById from sage.misc.functional import round +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.modules.free_module import FreeModule from sage.rings.finite_rings.integer_mod import Mod from sage.rings.finite_rings.integer_mod_ring import IntegerModRing from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ -from sage.rings.number_field.number_field import CyclotomicField, NumberField, NumberField_generic from sage.rings.power_series_ring import PowerSeriesRing from sage.rings.rational_field import RationalField, QQ, is_RationalField from sage.rings.ring import is_Ring @@ -87,6 +85,9 @@ from sage.structure.richcmp import richcmp from sage.structure.sequence import Sequence +lazy_import('sage.libs.pari', 'pari') +lazy_import('sage.rings.number_field.number_field', ['CyclotomicField', 'NumberField', 'NumberField_generic']) + def trivial_character(N, base_ring=RationalField()): r""" diff --git a/src/sage/modular/hecke/ambient_module.py b/src/sage/modular/hecke/ambient_module.py index 3e4ae52f00f..6b03862d6dd 100644 --- a/src/sage/modular/hecke/ambient_module.py +++ b/src/sage/modular/hecke/ambient_module.py @@ -21,9 +21,8 @@ from . import module from . import submodule -import sage.modules.all - -import sage.rings.all +from sage.modules.free_module import FreeModule, is_FreeModule +from sage.rings.integer import Integer import sage.arith.all as arith @@ -70,7 +69,7 @@ def __init__(self, base_ring, rank, level, weight, category=None): sage: sage.modular.hecke.ambient_module.AmbientHeckeModule(QQ, 3, 2, 4) Generic ambient Hecke module of rank 3, level 2 and weight 4 over Rational Field """ - rank = sage.rings.all.Integer(rank) + rank = Integer(rank) if rank < 0: raise ValueError("rank (=%s) must be nonnegative" % rank) self.__rank = rank @@ -491,7 +490,7 @@ def free_module(self): try: return self.__free_module except AttributeError: - M = sage.modules.all.FreeModule(self.base_ring(), self.rank()) + M = FreeModule(self.base_ring(), self.rank()) self.__free_module = M return M @@ -917,7 +916,7 @@ def old_submodule(self, p=None): def submodule(self, M, Mdual=None, check=True): """ - Return the Hecke submodule of self generated by M, which may be a + Return the Hecke submodule of ``self`` generated by `M`, which may be a submodule of the free module of self, or a list of elements of self. EXAMPLES:: @@ -927,7 +926,7 @@ def submodule(self, M, Mdual=None, check=True): Modular Forms subspace of dimension 2 of Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(37) of weight 2 over Rational Field """ if check: - if not sage.modules.free_module.is_FreeModule(M): + if not is_FreeModule(M): V = self.free_module() if isinstance(M, (list, tuple)): M = V.span([V(x.element()) for x in M]) diff --git a/src/sage/modular/hecke/submodule.py b/src/sage/modular/hecke/submodule.py index efcd8c9c848..e50b9d723e8 100644 --- a/src/sage/modular/hecke/submodule.py +++ b/src/sage/modular/hecke/submodule.py @@ -21,8 +21,8 @@ import sage.arith.all as arith from sage.misc.verbose import verbose from sage.misc.cachefunc import cached_method +from sage.modules.free_module import is_FreeModule from sage.structure.richcmp import richcmp_method, richcmp_not_equal -import sage.modules.all from . import module @@ -80,7 +80,7 @@ def __init__(self, ambient, submodule, dual_free_module=None, check=True): from . import ambient_module if not isinstance(ambient, ambient_module.AmbientHeckeModule): raise TypeError("ambient must be an ambient Hecke module") - if not sage.modules.free_module.is_FreeModule(submodule): + if not is_FreeModule(submodule): raise TypeError("submodule must be a free module") if not submodule.is_submodule(ambient.free_module()): raise ValueError("submodule must be a submodule of the ambient free module") @@ -94,7 +94,7 @@ def __init__(self, ambient, submodule, dual_free_module=None, check=True): module.HeckeModule_free_module.__init__(self, ambient.base_ring(), ambient.level(), ambient.weight()) if not (dual_free_module is None): - if not sage.modules.free_module.is_FreeModule(dual_free_module): + if not is_FreeModule(dual_free_module): raise TypeError("dual_free_module must be a free module") if dual_free_module.rank() != submodule.rank(): raise ArithmeticError("dual_free_module must have the same rank as submodule") @@ -908,7 +908,7 @@ def submodule(self, M, Mdual=None, check=True): sage: S.submodule(S[0].free_module()) Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 18 for Gamma_0(18) of weight 4 with sign 0 over Rational Field """ - if not sage.modules.free_module.is_FreeModule(M): + if not is_FreeModule(M): V = self.ambient_module().free_module() if isinstance(M, (list, tuple)): M = V.span([V(x.element()) for x in M]) diff --git a/src/sage/modular/modform/ambient_eps.py b/src/sage/modular/modform/ambient_eps.py index b5c3c543d67..8f14e22ce20 100644 --- a/src/sage/modular/modform/ambient_eps.py +++ b/src/sage/modular/modform/ambient_eps.py @@ -75,7 +75,7 @@ # http://www.gnu.org/licenses/ ######################################################################### -import sage.rings.all as rings +from sage.rings.integer import Integer import sage.modular.arithgroup.all as arithgroup import sage.modular.dirichlet as dirichlet @@ -200,7 +200,7 @@ def change_ring(self, base_ring): return self return ambient_R.ModularFormsAmbient_R(self, base_ring=base_ring) - @cached_method(key=lambda self, sign: rings.Integer(sign)) # convert sign to an Integer before looking this up in the cache + @cached_method(key=lambda self, sign: Integer(sign)) # convert sign to an Integer before looking this up in the cache def modular_symbols(self, sign=0): """ Return corresponding space of modular symbols with given sign. @@ -220,7 +220,7 @@ def modular_symbols(self, sign=0): ... ValueError: sign must be -1, 0, or 1 """ - sign = rings.Integer(sign) + sign = Integer(sign) return modsym.ModularSymbols(self.character(), weight=self.weight(), sign=sign, diff --git a/src/sage/modular/modform/ambient_g0.py b/src/sage/modular/modform/ambient_g0.py index a409a062984..114718b68b9 100644 --- a/src/sage/modular/modform/ambient_g0.py +++ b/src/sage/modular/modform/ambient_g0.py @@ -16,7 +16,7 @@ # http://www.gnu.org/licenses/ ######################################################################### -import sage.rings.all as rings +from sage.rings.rational_field import Q as QQ import sage.modular.arithgroup.all as arithgroup @@ -43,7 +43,7 @@ def __init__(self, level, weight): sage: type(m) """ - ambient.ModularFormsAmbient.__init__(self, arithgroup.Gamma0(level), weight, rings.QQ) + ambient.ModularFormsAmbient.__init__(self, arithgroup.Gamma0(level), weight, QQ) def _pari_init_(self): """ diff --git a/src/sage/modular/modform/ambient_g1.py b/src/sage/modular/modform/ambient_g1.py index 75f0de39e15..8c10c861cc0 100644 --- a/src/sage/modular/modform/ambient_g1.py +++ b/src/sage/modular/modform/ambient_g1.py @@ -50,7 +50,7 @@ # http://www.gnu.org/licenses/ ######################################################################### -import sage.rings.all as rings +from sage.rings.rational_field import Q as QQ import sage.modular.arithgroup.all as arithgroup @@ -77,7 +77,7 @@ def __init__(self, group, weight, eis_only): sage: type(m) """ - ambient.ModularFormsAmbient.__init__(self, group, weight, rings.QQ, eis_only=eis_only) + ambient.ModularFormsAmbient.__init__(self, group, weight, QQ, eis_only=eis_only) #################################################################### # Computation of Special Submodules @@ -170,7 +170,7 @@ def __init__(self, level, weight, eis_only): sage: type(m) """ - ambient.ModularFormsAmbient.__init__(self, arithgroup.Gamma1(level), weight, rings.QQ, eis_only=eis_only) + ambient.ModularFormsAmbient.__init__(self, arithgroup.Gamma1(level), weight, QQ, eis_only=eis_only) #################################################################### # Computation of Special Submodules diff --git a/src/sage/modular/modform/constructor.py b/src/sage/modular/modform/constructor.py index 6e9acf74e36..c30a28354ca 100644 --- a/src/sage/modular/modform/constructor.py +++ b/src/sage/modular/modform/constructor.py @@ -34,7 +34,9 @@ import sage.modular.arithgroup.all as arithgroup import sage.modular.dirichlet as dirichlet -import sage.rings.all as rings +from sage.rings.integer import Integer +from sage.rings.rational_field import Q as QQ +from sage.rings.ring import CommutativeRing from .ambient_eps import ModularFormsAmbient_eps from .ambient_g0 import ModularFormsAmbient_g0_Q @@ -92,38 +94,38 @@ def canonical_parameters(group, level, weight, base_ring): ... ValueError: group and level do not match. """ - weight = rings.Integer(weight) + weight = Integer(weight) if weight <= 0: raise NotImplementedError("weight must be at least 1") if isinstance(group, dirichlet.DirichletCharacter): - if ( group.level() != rings.Integer(level) ): + if ( group.level() != Integer(level) ): raise ValueError("group.level() and level do not match.") group = group.minimize_base_ring() - level = rings.Integer(level) + level = Integer(level) elif arithgroup.is_CongruenceSubgroup(group): - if ( rings.Integer(level) != group.level() ): + if ( Integer(level) != group.level() ): raise ValueError("group.level() and level do not match.") # normalize the case of SL2Z if arithgroup.is_SL2Z(group) or \ - arithgroup.is_Gamma1(group) and group.level() == rings.Integer(1): - group = arithgroup.Gamma0(rings.Integer(1)) + arithgroup.is_Gamma1(group) and group.level() == Integer(1): + group = arithgroup.Gamma0(Integer(1)) elif group is None: pass else: try: - m = rings.Integer(group) + m = Integer(group) except TypeError: raise TypeError("group of unknown type.") - level = rings.Integer(level) + level = Integer(level) if ( m != level ): raise ValueError("group and level do not match.") group = arithgroup.Gamma0(m) - if not isinstance(base_ring, rings.CommutativeRing): + if not isinstance(base_ring, CommutativeRing): raise TypeError("base_ring (=%s) must be a commutative ring"%base_ring) # it is *very* important to include the level as part of the data @@ -299,7 +301,7 @@ def ModularForms(group=1, if base_ring is None: base_ring = group.minimize_base_ring().base_ring() if base_ring is None: - base_ring = rings.QQ + base_ring = QQ if isinstance(group, dirichlet.DirichletCharacter) \ or arithgroup.is_CongruenceSubgroup(group): @@ -324,17 +326,17 @@ def ModularForms(group=1, M = None if arithgroup.is_Gamma0(group): M = ModularFormsAmbient_g0_Q(group.level(), weight) - if base_ring != rings.QQ: + if base_ring != QQ: M = ambient_R.ModularFormsAmbient_R(M, base_ring) elif arithgroup.is_Gamma1(group): M = ModularFormsAmbient_g1_Q(group.level(), weight, eis_only) - if base_ring != rings.QQ: + if base_ring != QQ: M = ambient_R.ModularFormsAmbient_R(M, base_ring) elif arithgroup.is_GammaH(group): M = ModularFormsAmbient_gH_Q(group, weight, eis_only) - if base_ring != rings.QQ: + if base_ring != QQ: M = ambient_R.ModularFormsAmbient_R(M, base_ring) elif isinstance(group, dirichlet.DirichletCharacter): @@ -466,7 +468,7 @@ def Newforms(group, weight=2, base_ring=None, names=None): return CuspForms(group, weight, base_ring).newforms(names) -def Newform(identifier, group=None, weight=2, base_ring=rings.QQ, names=None): +def Newform(identifier, group=None, weight=2, base_ring=QQ, names=None): """ INPUT: @@ -497,7 +499,7 @@ def Newform(identifier, group=None, weight=2, base_ring=rings.QQ, names=None): group, identifier = parse_label(identifier) if weight != 2: raise ValueError("Canonical label not implemented for higher weight forms.") - elif base_ring != rings.QQ: + elif base_ring != QQ: raise ValueError("Canonical label not implemented except for over Q.") elif group is None: raise ValueError("Must specify a group or a label.") diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py index af1c6c89a3a..0f9354d901e 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py @@ -3223,26 +3223,26 @@ def slash(self, f, tau=None, k=None): INPUT: - ``f`` -- A function in ``tau`` (or an object for which - evaluation at ``self.acton(tau)`` makes sense. + evaluation at ``self.acton(tau)`` makes sense. - ``tau`` -- Where to evaluate the result. - This should be a valid argument for :meth:`acton`. + This should be a valid argument for :meth:`acton`. - If ``tau`` is a point of ``HyperbolicPlane()`` then - its coordinates in the upper half plane model are used. + If ``tau`` is a point of ``HyperbolicPlane()`` then + its coordinates in the upper half plane model are used. - Default: ``None`` in which case ``f`` has to be - a rational function / polynomial in one variable and - the generator of the polynomial ring is used for ``tau``. - That way ``slash`` acts on rational functions / polynomials. + Default: ``None`` in which case ``f`` has to be + a rational function / polynomial in one variable and + the generator of the polynomial ring is used for ``tau``. + That way ``slash`` acts on rational functions / polynomials. - ``k`` -- An even integer. - Default: ``None`` in which case ``f`` either - has to be a rational function / polynomial in one - variable (then -degree is used). - Or ``f`` needs to have a ``weight`` attribute which - is then used. + Default: ``None`` in which case ``f`` either + has to be a rational function / polynomial in one + variable (then -degree is used). + Or ``f`` needs to have a ``weight`` attribute which + is then used. EXAMPLES:: @@ -3321,4 +3321,5 @@ def as_hyperbolic_plane_isometry(self, model="UHP"): sage: el.as_hyperbolic_plane_isometry("KM").parent() Set of Morphisms from Hyperbolic plane in the Klein Disk Model to Hyperbolic plane in the Klein Disk Model in Category of hyperbolic models of Hyperbolic plane """ + from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane return HyperbolicPlane().UHP().get_isometry(self._matrix).to_model(model) diff --git a/src/sage/modular/modsym/boundary.py b/src/sage/modular/modsym/boundary.py index f29c363cf8b..277f55cca33 100644 --- a/src/sage/modular/modsym/boundary.py +++ b/src/sage/modular/modsym/boundary.py @@ -101,7 +101,8 @@ import sage.modular.hecke.all as hecke from sage.modular.modsym.manin_symbol import ManinSymbol -import sage.rings.all as rings +from sage.rings.rational_field import Q as QQ +from sage.rings.ring import Ring from . import element @@ -283,7 +284,7 @@ def __init__(self, group=arithgroup.Gamma0(1), weight=2, sign=0, - base_ring=rings.QQ, + base_ring=QQ, character=None): """ Space of boundary symbols for a congruence subgroup of SL_2(Z). @@ -319,7 +320,7 @@ def __init__(self, if not arithgroup.is_CongruenceSubgroup(group): raise TypeError("group must be a congruence subgroup") sign = int(sign) - if not isinstance(base_ring, rings.Ring) and rings.is_CommutativeRing(base_ring): + if not isinstance(base_ring, Ring): raise TypeError("base_ring must be a commutative ring") if character is None and arithgroup.is_Gamma0(group): character = dirichlet.TrivialCharacter(group.level(), base_ring) diff --git a/src/sage/modular/modsym/modsym.py b/src/sage/modular/modsym/modsym.py index 0a87eece1d7..27a8def4a29 100644 --- a/src/sage/modular/modsym/modsym.py +++ b/src/sage/modular/modsym/modsym.py @@ -92,8 +92,9 @@ import sage.modular.arithgroup.all as arithgroup import sage.modular.dirichlet as dirichlet -import sage.rings.rational_field as rational_field -import sage.rings.all as rings +from sage.rings.integer import Integer +from sage.rings.ring import CommutativeRing +from sage.rings.rational_field import RationalField def canonical_parameters(group, weight, sign, base_ring): @@ -114,15 +115,15 @@ def canonical_parameters(group, weight, sign, base_ring): sage: type(p1[1]) """ - sign = rings.Integer(sign) + sign = Integer(sign) if not (sign in [-1,0,1]): raise ValueError("sign must be -1, 0, or 1") - weight = rings.Integer(weight) + weight = Integer(weight) if weight <= 1: raise ValueError("the weight must be at least 2") - if isinstance(group, (int, rings.Integer)): + if isinstance(group, (int, Integer)): group = arithgroup.Gamma0(group) elif isinstance(group, dirichlet.DirichletCharacter): if group.is_trivial(): @@ -134,9 +135,9 @@ def canonical_parameters(group, weight, sign, base_ring): base_ring = eps.base_ring() if base_ring is None: - base_ring = rational_field.RationalField() + base_ring = RationalField() - if not isinstance(base_ring, rings.CommutativeRing): + if not isinstance(base_ring, CommutativeRing): raise TypeError("base_ring (=%s) must be a commutative ring"%base_ring) if not base_ring.is_field(): diff --git a/src/sage/modular/multiple_zeta.py b/src/sage/modular/multiple_zeta.py index 032a592ef36..471b39325c3 100644 --- a/src/sage/modular/multiple_zeta.py +++ b/src/sage/modular/multiple_zeta.py @@ -184,10 +184,10 @@ from sage.combinat.words.word import Word from sage.combinat.words.words import Words from sage.combinat.words.shuffle_product import ShuffleProduct_w1w2 as shuffle -from sage.libs.pari.all import pari from sage.matrix.constructor import matrix from sage.misc.cachefunc import cached_function, cached_method from sage.misc.lazy_attribute import lazy_attribute +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.modular.multiple_zeta_F_algebra import F_algebra from sage.modules.free_module import VectorSpace @@ -195,6 +195,9 @@ from sage.rings.rational_field import QQ from sage.sets.positive_integers import PositiveIntegers +lazy_import('sage.libs.pari.all', 'pari') + + # multiplicative generators for weight <= 17 # using the following convention # (3, 5) <---> (sign) * [1,0,0,1,0,0,0,0] diff --git a/src/sage/modular/quatalg/brandt.py b/src/sage/modular/quatalg/brandt.py index 81381adef3d..1c74d953f6d 100644 --- a/src/sage/modular/quatalg/brandt.py +++ b/src/sage/modular/quatalg/brandt.py @@ -202,12 +202,11 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.algebras.quatalg.quaternion_algebra import QuaternionAlgebra, basis_for_quaternion_lattice -from sage.algebras.quatalg.quaternion_algebra_cython import rational_matrix_from_rational_quaternions from sage.arith.misc import gcd, factor, prime_divisors, kronecker, next_prime from sage.matrix.constructor import matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.misc.verbose import verbose from sage.modular.dirichlet import TrivialCharacter @@ -223,6 +222,9 @@ from sage.rings.ring import CommutativeRing from sage.structure.richcmp import richcmp, richcmp_method +lazy_import('sage.algebras.quatalg.quaternion_algebra', ['QuaternionAlgebra', 'basis_for_quaternion_lattice']) +lazy_import('sage.algebras.quatalg.quaternion_algebra_cython', 'rational_matrix_from_rational_quaternions') + cache = {} diff --git a/src/sage/modular/ssmod/ssmod.py b/src/sage/modular/ssmod/ssmod.py index 78fe82dc1f1..a23320cecb0 100644 --- a/src/sage/modular/ssmod/ssmod.py +++ b/src/sage/modular/ssmod/ssmod.py @@ -68,8 +68,8 @@ # **************************************************************************** from sage.arith.misc import kronecker, next_prime -from sage.libs.pari.all import pari from sage.matrix.matrix_space import MatrixSpace +from sage.misc.lazy_import import lazy_import from sage.modular.arithgroup.all import Gamma0 from sage.modular.hecke.module import HeckeModule_free_module from sage.rings.finite_rings.finite_field_constructor import FiniteField @@ -78,6 +78,8 @@ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.structure.richcmp import richcmp_method, richcmp +lazy_import('sage.libs.pari.all', 'pari') + ZZy = PolynomialRing(ZZ, 'y') From 3313b79caa71563212248374f2381af91d6f0738 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 12:26:41 -0700 Subject: [PATCH 02/20] src/.relint.yml: Flag another type of .all import --- src/.relint.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/.relint.yml b/src/.relint.yml index d0eafb0d8fc..ab460661f1e 100644 --- a/src/.relint.yml +++ b/src/.relint.yml @@ -53,6 +53,17 @@ # imports from .all are allowed in all.py; also allow in some modules that need sage.all filePattern: '(.*/|)(?!(all|benchmark|dev_tools|parsing|sage_eval))[^/.]*[.](py|pyx|pxi)$' +- name: 'namespace_pkg_all_import_2: Module-level import of .all of a namespace package' + hint: | + Sage library code should not import sage.PAC.KAGE.all when sage.PAC.KAGE is an implicit + namespace package. Type import_statements("SOME_IDENTIFIER") to find a more specific import, + and rewrite the import statement as "from sage.PAC.KAGE.MODULE import ..." + or "lazy_import('sage.PAC.KAGE.MODULE', '...')". + # Keep in sync with above; but for now we ignore sage.{arith,categories} + pattern: '^import\s+sage(|[.](combinat|crypto|databases|data_structures|dynamics|ext|game_theory|games|geometry|graphs|groups|interfaces|manifolds|matrix|matroids|misc|modules|monoids|numerical|probability|quadratic_forms|quivers|rings|sat|schemes|sets|stats|symbolic|tensor)[a-z0-9_.]*|[.]libs)[.]all' + # imports from .all are allowed in all.py; also allow in some modules that need sage.all + filePattern: '(.*/|)(?!(all|benchmark|dev_tools|parsing|sage_eval|.*_test))[^/.]*[.](py|pyx|pxi)$' + # Magic doctest comments - name: 'multiline_doctest_comment: magic comment on a continuation line' From 98073c7a493a9f5565e1c7bd3d9c6b380c651a6b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 12:27:14 -0700 Subject: [PATCH 03/20] sage -fiximports: Exclude an autogenerated file --- src/sage/misc/replace_dot_all.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sage/misc/replace_dot_all.py b/src/sage/misc/replace_dot_all.py index ebb9a83dfff..46462ca7c2c 100644 --- a/src/sage/misc/replace_dot_all.py +++ b/src/sage/misc/replace_dot_all.py @@ -385,7 +385,11 @@ def make_replacements_in_file(location, package_regex=None, verbose=False, outpu write_file.write(replaced_content) # overwriting the old file contents with the new/replaced content -def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex=None, verbose=False): +excluded_file_regex = 'auto-methods|replace_dot_all' + + +def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex=None, verbose=False, *, + excluded_file_regex=r'auto-methods|replace_dot_all'): r""" Replace ``import`` statements in the files in directory ``dir`` matching the regex pattern ``file_regex``. @@ -396,6 +400,7 @@ def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex - ``package_regex`` -- (default: :obj:`default_package_regex`) a regular expression matching the ``sage.PAC.KAGE.all`` package names from which we do not want to import. - ``verbose`` -- if True, print statements when interesting examples are found + - ``excluded_file_regex`` -- a regular expression matching the file names to exclude EXAMPLES:: @@ -404,14 +409,14 @@ def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex """ global numberFiles, numberFilesMatchingRegex file_regex = re.compile(file_regex) + excluded_file_regex = re.compile(excluded_file_regex) for root, dirs, files in os.walk(dir, topdown=False): for name in files: numberFiles += 1 - if file_regex.search(name): + if file_regex.search(name) and not excluded_file_regex.search(name): numberFilesMatchingRegex += 1 location = os.path.join(root, name) - if location.find('replace_dot_all') == -1: # to avoid changing anything in this file itself - make_replacements_in_file(location, package_regex, verbose) + make_replacements_in_file(location, package_regex, verbose) # ******************************************************** EXECUTES MAIN FUNCTION ********************************************************************** From 62cdde87850e86ef348aff2d79a74e3dcfa0e934 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 12:39:13 -0700 Subject: [PATCH 04/20] sage.schemes: Modularization fixes for imports --- src/sage/lfunctions/sympow.py | 6 +- src/sage/modules/vector_space_homspace.py | 6 +- .../schemes/elliptic_curves/constructor.py | 16 +++-- src/sage/schemes/elliptic_curves/ell_field.py | 35 +++++----- .../schemes/elliptic_curves/ell_generic.py | 36 +++++----- .../elliptic_curves/ell_rational_field.py | 66 ++++++++++--------- .../schemes/elliptic_curves/ell_tate_curve.py | 4 +- .../schemes/elliptic_curves/formal_group.py | 13 ++-- src/sage/schemes/elliptic_curves/gal_reps.py | 16 +++-- src/sage/schemes/elliptic_curves/heegner.py | 50 +++++++------- .../schemes/elliptic_curves/padic_lseries.py | 12 ++-- src/sage/schemes/elliptic_curves/padics.py | 63 +++++++++--------- 12 files changed, 174 insertions(+), 149 deletions(-) diff --git a/src/sage/lfunctions/sympow.py b/src/sage/lfunctions/sympow.py index 4cf14233aa2..796e2672d82 100644 --- a/src/sage/lfunctions/sympow.py +++ b/src/sage/lfunctions/sympow.py @@ -51,7 +51,7 @@ from sage.structure.sage_object import SageObject from sage.misc.pager import pager from sage.misc.verbose import verbose -import sage.rings.all +from sage.rings.integer import Integer class Sympow(SageObject): @@ -237,7 +237,7 @@ def modular_degree(self, E): if i == -1: print(self._fix_err(v)) raise RuntimeError("failed to compute modular degree") - return sage.rings.all.Integer(v[i + len(s):]) + return Integer(v[i + len(s):]) def analytic_rank(self, E): r""" @@ -296,7 +296,7 @@ def analytic_rank(self, E): print(self._fix_err(v)) raise RuntimeError("failed to compute analytic rank") j = v.rfind(':') - r = sage.rings.all.Integer(v[i + len(s):j]) + r = Integer(v[i + len(s):j]) i = v.rfind(' ') L = v[i + 1:] return r, L diff --git a/src/sage/modules/vector_space_homspace.py b/src/sage/modules/vector_space_homspace.py index 13004ea14ce..48d195a7608 100644 --- a/src/sage/modules/vector_space_homspace.py +++ b/src/sage/modules/vector_space_homspace.py @@ -191,7 +191,7 @@ # http://www.gnu.org/licenses/ #################################################################################### -import sage.matrix.all as matrix +from sage.matrix.constructor import Matrix as matrix import sage.modules.free_module_homspace # This module initially overrides just the minimum functionality necessary @@ -384,7 +384,7 @@ def __call__(self, A, check=True, **kwds): msg = 'function cannot be applied properly to some basis element because\n' + e.args[0] raise ValueError(msg) try: - A = matrix.matrix(D.dimension(), C.dimension(), [C.coordinates(C(a)) for a in images]) + A = matrix(D.dimension(), C.dimension(), [C.coordinates(C(a)) for a in images]) except (ArithmeticError, TypeError) as e: msg = 'some image of the function is not in the codomain, because\n' + e.args[0] raise ArithmeticError(msg) @@ -396,7 +396,7 @@ def __call__(self, A, check=True, **kwds): raise ValueError(msg.format(len(D.basis()), len(A))) try: v = [C(a) for a in A] - A = matrix.matrix(D.dimension(), C.dimension(), [C.coordinates(a) for a in v]) + A = matrix(D.dimension(), C.dimension(), [C.coordinates(a) for a in v]) except (ArithmeticError, TypeError) as e: msg = 'some proposed image is not in the codomain, because\n' + e.args[0] raise ArithmeticError(msg) diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index 770295962dd..b9e9999418a 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -23,7 +23,9 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -import sage.rings.all as rings +from sage.rings.integer_ring import ZZ +from sage.rings.rational_field import QQ +from sage.rings.rational_field import RationalField import sage.rings.abc from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing @@ -448,8 +450,8 @@ def create_key_and_extra_args(self, x=None, y=None, j=None, minimal_twist=True, if R is None: R = Sequence(x).universe() - if R in (rings.ZZ, int): - R = rings.QQ + if R in (ZZ, int): + R = QQ return (R, tuple(R(a) for a in x)), kwds @@ -471,7 +473,7 @@ def create_object(self, version, key, **kwds): """ R, x = key - if R is rings.QQ: + if R is QQ: from .ell_rational_field import EllipticCurve_rational_field return EllipticCurve_rational_field(x, **kwds) elif isinstance(R, NumberField): @@ -597,7 +599,7 @@ def EllipticCurve_from_c4c6(c4, c6): try: K = c4.parent() except AttributeError: - K = rings.RationalField() + K = RationalField() if K not in _Fields: K = K.fraction_field() return EllipticCurve([-K(c4)/K(48), -K(c6)/K(864)]) @@ -692,7 +694,7 @@ def coefficients_from_j(j, minimal_twist=True): try: K = j.parent() except AttributeError: - K = rings.RationalField() + K = RationalField() if K not in _Fields: K = K.fraction_field() @@ -708,7 +710,7 @@ def coefficients_from_j(j, minimal_twist=True): else: return Sequence([0, j, 0, 0, -j**2], universe=K) - if K is rings.RationalField(): + if K is RationalField(): # we construct the minimal twist, i.e. the curve with minimal # conductor with this j_invariant: if j == 0: diff --git a/src/sage/schemes/elliptic_curves/ell_field.py b/src/sage/schemes/elliptic_curves/ell_field.py index 5a5fdf1fcb6..3c359e3de03 100644 --- a/src/sage/schemes/elliptic_curves/ell_field.py +++ b/src/sage/schemes/elliptic_curves/ell_field.py @@ -12,11 +12,13 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -import sage.rings.all as rings import sage.rings.abc from sage.categories.number_fields import NumberFields from sage.categories.finite_fields import FiniteFields - +from sage.rings.integer import Integer +from sage.rings.integer_ring import ZZ +from sage.rings.polynomial.polynomial_ring import polygen +from sage.rings.rational_field import QQ from sage.schemes.elliptic_curves.ell_point import EllipticCurvePoint_field from sage.schemes.curves.projective_curve import ProjectivePlaneCurve_field @@ -55,7 +57,7 @@ def genus(self): sage: E.genus() 1 """ - return rings.ZZ.one() + return ZZ.one() r""" Twists: rewritten by John Cremona as follows: @@ -149,7 +151,7 @@ def quadratic_twist(self, D=None): if D is None: if K.is_finite(): - x = rings.polygen(K) + x = polygen(K) if char == 2: # We find D such that x^2+x+D is irreducible. If the # degree is odd we can take D=1; otherwise it suffices to @@ -229,9 +231,9 @@ def two_torsion_rank(self): sage: EllipticCurve('15a1').two_torsion_rank() 2 """ - f = self.division_polynomial(rings.Integer(2)) + f = self.division_polynomial(Integer(2)) n = len(f.roots())+1 - return rings.Integer(n).ord(rings.Integer(2)) + return Integer(n).ord(Integer(2)) def quartic_twist(self, D): r""" @@ -425,8 +427,8 @@ def is_quadratic_twist(self, other): return zero if E.is_isomorphic(F): - if K is rings.QQ: - return rings.ZZ(1) + if K is QQ: + return ZZ(1) return K.one() char = K.characteristic() @@ -445,7 +447,7 @@ def is_quadratic_twist(self, other): if j == 0: um = c6E/c6F - x = rings.polygen(K) + x = polygen(K) ulist = (x**3-um).roots(multiplicities=False) if not ulist: D = zero @@ -453,7 +455,7 @@ def is_quadratic_twist(self, other): D = ulist[0] elif j == 1728: um = c4E/c4F - x = rings.polygen(K) + x = polygen(K) ulist = (x**2-um).roots(multiplicities=False) if not ulist: D = zero @@ -467,7 +469,7 @@ def is_quadratic_twist(self, other): if D.is_zero(): return D - if K is rings.QQ: + if K is QQ: D = D.squarefree_part() assert E.quadratic_twist(D).is_isomorphic(F) @@ -708,7 +710,6 @@ def descend_to(self, K, f=None): # j-invariant is in the image, otherwise return an empty list: j = self.j_invariant() - from sage.rings.rational_field import QQ if K == QQ: try: jK = QQ(j) @@ -996,7 +997,7 @@ def division_field(self, l, names='t', map=False, **kwds): - Lorenz Panny (2022): extend to finite fields """ from sage.misc.verbose import verbose - l = rings.Integer(l) + l = Integer(l) if not l.is_prime(): raise ValueError("l must be a prime number") @@ -1052,7 +1053,7 @@ def division_field(self, l, names='t', map=False, **kwds): # Polynomial defining the corresponding Y-coordinate curve = self.defining_polynomial().map_coefficients(F_to_K) - ypol = curve(X, rings.polygen(K), 1) + ypol = curve(X, polygen(K), 1) L = ypol.splitting_field(names, map=map, **kwds) if map: L, K_to_L = L @@ -1571,7 +1572,7 @@ def isogenies_prime_degree(self, l=None, max_l=31): raise NotImplementedError("This code could be implemented for general real fields, but has not been yet.") if isinstance(F, sage.rings.abc.ComplexField): raise NotImplementedError("This code could be implemented for general complex fields, but has not been yet.") - if F is rings.QQbar: + if isinstance(F, sage.rings.abc.AlgebraicField): raise NotImplementedError("This code could be implemented for QQbar, but has not been yet.") if l is None: @@ -1581,9 +1582,9 @@ def isogenies_prime_degree(self, l=None, max_l=31): try: l = list(l) except TypeError: - L = [rings.ZZ(l)] + L = [ZZ(l)] else: - L = [rings.ZZ(d) for d in l] + L = [ZZ(d) for d in l] from .isogeny_small_degree import isogenies_prime_degree return sum([isogenies_prime_degree(self, d) for d in L], []) diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 406450f0831..c7a4bb94e73 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -55,6 +55,7 @@ import math import sage.rings.abc +from sage.rings.finite_rings.integer_mod import mod from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.polynomial.polynomial_ring import polygen, polygens from sage.rings.polynomial.polynomial_element import polynomial_is_variable @@ -64,7 +65,13 @@ import sage.groups.generic as generic from sage.arith.functions import lcm -import sage.rings.all as rings +from sage.rings.integer import Integer +from sage.rings.big_oh import O +from sage.rings.infinity import Infinity as oo +from sage.rings.rational import Rational +from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF +from sage.rings.rational_field import RationalField +from sage.rings.real_mpfr import RealField from sage.misc.cachefunc import cached_method from sage.misc.fast_methods import WithEqualityById @@ -82,9 +89,6 @@ sqrt = math.sqrt exp = math.exp -oo = rings.infinity # infinity -O = rings.O # big oh - def is_EllipticCurve(x): r""" @@ -575,8 +579,8 @@ def __call__(self, *args, **kwds): # characteristic of the base ring. if so, coerce the point to # infinity. characteristic = self.base_ring().characteristic() - if characteristic != 0 and isinstance(args[0][0], rings.Rational) and isinstance(args[0][1], rings.Rational): - if rings.mod(args[0][0].denominator(),characteristic) == 0 or rings.mod(args[0][1].denominator(),characteristic) == 0: + if characteristic != 0 and isinstance(args[0][0], Rational) and isinstance(args[0][1], Rational): + if mod(args[0][0].denominator(),characteristic) == 0 or mod(args[0][1].denominator(),characteristic) == 0: return self._reduce_point(args[0], characteristic) args = tuple(args[0]) @@ -632,10 +636,10 @@ def _reduce_point(self, R, p): \code{EllipticCurve._reduce_point} """ if R.is_zero(): - return R.curve().change_ring(rings.GF(p))(0) + return R.curve().change_ring(GF(p))(0) x, y = R.xy() d = lcm(x.denominator(), y.denominator()) - return R.curve().change_ring(rings.GF(p))([x*d, y*d, d]) + return R.curve().change_ring(GF(p))([x*d, y*d, d]) def is_x_coord(self, x): r""" @@ -1018,7 +1022,7 @@ def __is_over_RationalField(self): sage: E._EllipticCurve_generic__is_over_RationalField() # optional - sage.rings.finite_rings False """ - return isinstance(self.base_ring(), rings.RationalField) + return isinstance(self.base_ring(), RationalField) def is_on_curve(self, x, y): r""" @@ -1936,7 +1940,7 @@ def division_polynomial(self, m, x=None, two_torsion_multiplicity=2, force_evalu if not (isinstance(x, tuple) and len(x) == 2): raise ValueError("x should be a tuple of length 2 (or None) when two_torsion_multiplicity is 1") - m = rings.Integer(m) + m = Integer(m) if x is None: try: @@ -2099,7 +2103,7 @@ def _multiple_x_numerator(self, n, x=None): sage: E._multiple_x_numerator(5) # optional - sage.rings.finite_rings x^25 + 65037*x^23 + 55137*x^22 + ... + 813*x^2 + 10220*x + 42539 """ - n = rings.Integer(n).abs() + n = Integer(n).abs() if not n: raise ValueError("n must be nonzero") @@ -2195,7 +2199,7 @@ def _multiple_x_denominator(self, n, x=None): sage: E._multiple_x_denominator(5) # optional - sage.rings.finite_rings 25*x^24 + 3100*x^22 + 19000*x^21 + ... + 24111*x^2 + 52039*x + 56726 """ - n = rings.Integer(n).abs() + n = Integer(n).abs() if not n: raise ValueError("n must be nonzero") @@ -2321,7 +2325,7 @@ def multiplication_by_m(self, m, x_only=False): sage: assert(E(eval(f,P)) == 2*P) # optional - sage.rings.finite_rings """ # Coerce the input m to be an integer - m = rings.Integer(m) + m = Integer(m) if m == 0: raise ValueError("m must be a non-zero integer") @@ -3168,7 +3172,7 @@ def plot(self, xmin=None, xmax=None, components='both', **args): NotImplementedError: plotting of curves over Complex Field with 53 bits of precision is not implemented yet """ - RR = rings.RealField() + RR = RealField() K = self.base_ring() if not RR.has_coerce_map_from(K): raise NotImplementedError("plotting of curves over %s is not implemented yet" % K) @@ -3372,7 +3376,7 @@ def _p_primary_torsion_basis(self, p, m=None): sage: [t[1] for t in E._p_primary_torsion_basis(2)] # long time (3s on sage.math, 2011) # optional - sage.rings.finite_rings [16, 1] """ - p = rings.Integer(p) + p = Integer(p) if not p.is_prime(): raise ValueError("p (=%s) should be prime" % p) @@ -3385,7 +3389,7 @@ def _p_primary_torsion_basis(self, p, m=None): # First find the p-torsion: Ep = self(0).division_points(p) - p_rank = rings.Integer(len(Ep)).exact_log(p) + p_rank = Integer(len(Ep)).exact_log(p) assert p_rank in [0, 1, 2] if p_rank == 0: diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index d4cd35d8092..633fc0e9a47 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -73,26 +73,32 @@ import sage.databases.cremona import sage.arith.all as arith -import sage.rings.all as rings +from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF +from sage.rings.fast_arith import prime_range +from sage.rings.real_mpfr import RR +from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing +from sage.structure.element import RingElement from sage.rings.power_series_ring import PowerSeriesRing from sage.rings.infinity import Infinity as oo from sage.rings.integer_ring import ZZ, IntegerRing from sage.rings.rational_field import QQ from sage.rings.integer import Integer +from sage.rings.real_mpfi import RealIntervalField from sage.rings.real_mpfr import RealField from sage.rings.complex_mpfr import ComplexField from sage.rings.rational_field import RationalField from sage.structure.coerce import py_scalar_to_element from sage.structure.element import Element -import sage.misc.all as misc +from sage.misc.misc_c import prod as mul +from sage.misc.misc_c import prod from sage.misc.verbose import verbose as verbose_verbose from sage.functions.log import log -import sage.matrix.all as matrix -from sage.libs.pari.all import pari -from sage.functions.gamma import gamma_inc +from sage.matrix.matrix_space import MatrixSpace +lazy_import('sage.libs.pari.all', 'pari') +lazy_import("sage.functions.gamma", "gamma_inc") from math import sqrt from sage.interfaces.gp import gp from sage.misc.cachefunc import cached_method @@ -102,7 +108,7 @@ C = ComplexField() R = RealField() Z = IntegerRing() -IR = rings.RealIntervalField(20) +IR = RealIntervalField(20) _MAX_HEIGHT = 21 @@ -379,7 +385,7 @@ def is_p_integral(self, p): raise ArithmeticError("p must be prime") if self.is_integral(): return True - return bool(misc.mul([x.valuation(p) >= 0 for x in self.ainvs()])) + return bool(mul([x.valuation(p) >= 0 for x in self.ainvs()])) def is_integral(self): r""" @@ -400,7 +406,7 @@ def is_integral(self): try: return self.__is_integral except AttributeError: - self.__is_integral = bool(misc.mul([x.denominator() == 1 for x in self.ainvs()])) + self.__is_integral = bool(mul([x.denominator() == 1 for x in self.ainvs()])) return self.__is_integral def mwrank(self, options=''): @@ -1525,9 +1531,9 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False): if algorithm == 'pari': rank_lead = self.pari_curve().ellanalyticrank() if leading_coefficient: - return (rings.Integer(rank_lead[0]), rank_lead[1].sage()) + return (Integer(rank_lead[0]), rank_lead[1].sage()) else: - return rings.Integer(self.pari_curve().ellanalyticrank()[0]) + return Integer(self.pari_curve().ellanalyticrank()[0]) elif algorithm == 'rubinstein': if leading_coefficient: raise NotImplementedError("Cannot compute leading coefficient using rubinstein algorithm") @@ -1545,7 +1551,7 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False): if leading_coefficient: raise NotImplementedError("Cannot compute leading coefficient using magma") from sage.interfaces.magma import magma - return rings.Integer(magma(self).AnalyticRank()) + return Integer(magma(self).AnalyticRank()) elif algorithm == 'zero_sum': if leading_coefficient: s = "Cannot compute leading coefficient using the zero sum method" @@ -2631,7 +2637,7 @@ def regulator(self, proof=None, precision=53, **kwds): sage: EllipticCurve([0, 0, 1, -79, 342]).regulator(proof=False) # long time (6s on sage.math, 2011) 14.790527570131... """ - R = rings.RealField(precision) + R = RealField(precision) if proof is None: from sage.structure.proof.proof import get_flag @@ -3941,7 +3947,7 @@ def modular_degree(self, algorithm='sympow', M=1): m = sympow.modular_degree(self) elif algorithm == 'magma': from sage.interfaces.magma import magma - m = rings.Integer(magma(self).ModularDegree()) + m = Integer(magma(self).ModularDegree()) else: raise ValueError("unknown algorithm %s" % algorithm) self.__modular_degree = m @@ -4171,16 +4177,16 @@ def reduction(self,p): sage: E.reduction(5) # optional - sage.rings.finite_rings Elliptic Curve defined by y^2 = x^3 + x + 1 over Finite Field of size 5 """ - p = rings.Integer(p) + p = Integer(p) if not p.is_prime(): raise AttributeError("p must be prime.") disc = self.discriminant() if not disc.valuation(p) == 0: local_data = self.local_data(p) if local_data.has_good_reduction(): - return local_data.minimal_model().change_ring(rings.GF(p)) + return local_data.minimal_model().change_ring(GF(p)) raise AttributeError("The curve must have good reduction at p.") - return self.change_ring(rings.GF(p)) + return self.change_ring(GF(p)) def torsion_order(self): r""" @@ -4990,8 +4996,8 @@ def is_isogenous(self, other, proof=True, maxp=200): D1 = E1.discriminant() D2 = E2.discriminant() - if any(E1.change_ring(rings.GF(p)).cardinality() != E2.change_ring(rings.GF(p)).cardinality() - for p in rings.prime_range(2, maxp) + if any(E1.change_ring(GF(p)).cardinality() != E2.change_ring(GF(p)).cardinality() + for p in prime_range(2, maxp) if D1.valuation(p) == 0 and D2.valuation(p) == 0): return False @@ -5334,7 +5340,7 @@ def _shortest_paths(self): """ from sage.graphs.graph import Graph isocls = self.isogeny_class() - M = isocls.matrix(fill=True).change_ring(rings.RR) + M = isocls.matrix(fill=True).change_ring(RR) # see trac #4889 for nebulous M.list() --> M.entries() change... # Take logs here since shortest path minimizes the *sum* of the weights -- not the product. M = M.parent()([a.log() if a else 0 for a in M.list()]) @@ -5553,7 +5559,7 @@ def supersingular_primes(self, B): [] """ v = self.aplist(max(B, 3)) - P = rings.prime_range(max(B,3)+1) + P = prime_range(max(B,3)+1) N = self.conductor() return [P[i] for i in [0,1] if P[i] <= B and v[i] % P[i] == 0 and N % P[i] != 0] + \ [P[i] for i in range(2,len(v)) if v[i] == 0 and N % P[i] != 0] @@ -5585,7 +5591,7 @@ def ordinary_primes(self, B): [] """ v = self.aplist(max(B, 3)) - P = rings.prime_range(max(B, 3) + 1) + P = prime_range(max(B, 3) + 1) result = [P[i] for i in [0, 1] if P[i] <= B and v[i] % P[i]] result += [P[i] for i in range(2, len(v)) if v[i] != 0] return result @@ -6213,7 +6219,7 @@ def point_preprocessing(free,tor): j = self.j_invariant() b2 = self.b2() - Qx = rings.PolynomialRing(RationalField(),'x') + Qx = PolynomialRing(RationalField(),'x') pol = Qx([-self.c6()/216,-self.c4()/12,0,4]) if disc > 0: # two real component -> 3 roots in RR #on curve 897e4, only one root is found with default precision! @@ -6282,7 +6288,7 @@ def point_preprocessing(free,tor): c9_help_list.append((mod_h_list[i]).sqrt()/mw_base_log[i]) c9 = e/c7.sqrt() * min(c9_help_list) n = r+1 - c10 = R(2 * 10**(8+7*n) * R((2/e)**(2 * n**2)) * (n+1)**(4 * n**2 + 10 * n) * log(c9)**(-2*n - 1) * misc.prod(mod_h_list)) + c10 = R(2 * 10**(8+7*n) * R((2/e)**(2 * n**2)) * (n+1)**(4 * n**2 + 10 * n) * log(c9)**(-2*n - 1) * prod(mod_h_list)) top = Z(128) # arbitrary first upper bound bottom = Z(0) @@ -6305,7 +6311,7 @@ def point_preprocessing(free,tor): H_q = R(10)**bound break_cond = 0 #at least one reduction step #reduction via LLL - M = matrix.MatrixSpace(Z,n) + M = MatrixSpace(Z,n) while break_cond < 0.9: #as long as the improvement of the new bound in comparison to the old is greater than 10% c = R((H_q**n)*10) #c has to be greater than H_q^n m = copy(M.identity_matrix()) @@ -6807,9 +6813,9 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): # denom_maxpa is a list of pairs (d,q) where d runs # through possible denominators, and q=p^a is the # maximum prime power divisor of d: - denom_maxpa = [(misc.prod(tmp),max(tmp)) for tmp in cartesian_product_iterator(p_pow_alpha)] + denom_maxpa = [(prod(tmp),max(tmp)) for tmp in cartesian_product_iterator(p_pow_alpha)] # The maximum denominator is this (not used): -# denom = [misc.prod([pp[-1] for pp in p_pow_alpha],1)] +# denom = [prod([pp[-1] for pp in p_pow_alpha],1)] for de,maxpa in denom_maxpa: n_max = (abs_bound*de).ceil() n_min = maxpa*de @@ -6865,7 +6871,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): w1, w2 = E.period_lattice().basis() - Qx = rings.PolynomialRing(RationalField(),'x') + Qx = PolynomialRing(RationalField(),'x') pol = Qx([-54*c6,-27*c4,0,1]) if disc > 0: # two real component -> 3 roots in RR # it is possible that only one root is found with default precision! (see integral_points()) @@ -6974,7 +6980,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): sys.stdout.flush() break_cond = 0 - M = matrix.MatrixSpace(Z,n) + M = MatrixSpace(Z,n) #Reduction of initial bound if verbose: print('initial bound', H_q) @@ -7122,7 +7128,7 @@ def cremona_curves(conductors): ('39a3', 0), ('39a4', 0)] """ - if isinstance(conductors, (rings.RingElement, int)): + if isinstance(conductors, (RingElement, int)): conductors = [conductors] return sage.databases.cremona.CremonaDatabase().iter(conductors) @@ -7148,7 +7154,7 @@ def cremona_optimal_curves(conductors): ['990a1', '990b1', '990c1', '990d1', '990e1', '990f1', '990g1', '990h3', '990i1', '990j1', '990k1', '990l1'] """ - if isinstance(conductors, (rings.RingElement, int)): + if isinstance(conductors, (RingElement, int)): conductors = [conductors] return sage.databases.cremona.CremonaDatabase().iter_optimal(conductors) diff --git a/src/sage/schemes/elliptic_curves/ell_tate_curve.py b/src/sage/schemes/elliptic_curves/ell_tate_curve.py index 0b7cd52a146..631f1ba97ac 100644 --- a/src/sage/schemes/elliptic_curves/ell_tate_curve.py +++ b/src/sage/schemes/elliptic_curves/ell_tate_curve.py @@ -50,7 +50,7 @@ from sage.functions.log import log from sage.misc.functional import denominator from sage.misc.misc_c import prod -import sage.matrix.all as matrix +from sage.matrix.constructor import Matrix as matrix @richcmp_method @@ -659,7 +659,7 @@ def padic_regulator(self, prec=20): "for non-split multiplicative reduction.") basis = self._E.gens() - M = matrix.matrix(K, rank, rank, 0) + M = matrix(K, rank, rank, 0) height = self.padic_height(prec=prec) point_height = [height(P) for P in basis] diff --git a/src/sage/schemes/elliptic_curves/formal_group.py b/src/sage/schemes/elliptic_curves/formal_group.py index 7949eb94bcf..63ce58c74c6 100644 --- a/src/sage/schemes/elliptic_curves/formal_group.py +++ b/src/sage/schemes/elliptic_curves/formal_group.py @@ -15,7 +15,8 @@ from sage.structure.sage_object import SageObject import sage.misc.misc as misc -import sage.rings.all as rings +from sage.rings.power_series_ring import PowerSeriesRing +from sage.rings.laurent_series_ring import LaurentSeriesRing from sage.rings.big_oh import O @@ -159,7 +160,7 @@ def w(self, prec=20): R = w.parent() except AttributeError: # No cached version available - R = rings.PowerSeriesRing(k, "t") + R = PowerSeriesRing(k, "t") w = R([k(0), k(0), k(0), k(1)], 4) cached_prec = 4 self.__w = w @@ -526,7 +527,7 @@ def group_law(self, prec=10): if prec <= 0: raise ValueError("The precision must be positive.") - R = rings.PowerSeriesRing(self.curve().base_ring(), 2, 't1,t2') + R = PowerSeriesRing(self.curve().base_ring(), 2, 't1,t2') t1, t2 = R.gens() if prec == 1: @@ -666,7 +667,7 @@ def mult_by_n(self, n, prec=10): # Now the general case, not necessarily over a field. - R = rings.PowerSeriesRing(self.curve().base_ring(), "t") + R = PowerSeriesRing(self.curve().base_ring(), "t") t = R.gen() if n == 1: @@ -744,7 +745,7 @@ def sigma(self, prec=10): fl = self.log(prec) F = fl.reverse() - S = rings.LaurentSeriesRing(k,'z') + S = LaurentSeriesRing(k,'z') z = S.gen() F = F(z + O(z**prec)) wp = self.x()(F) + (a1**2 + 4*a2)/12 @@ -752,7 +753,7 @@ def sigma(self, prec=10): h = g.integral().integral() sigma_of_z = z.power_series() * h.exp() - T = rings.PowerSeriesRing(k,'t') + T = PowerSeriesRing(k,'t') fl = fl(T.gen()+O(T.gen()**prec)) sigma_of_t = sigma_of_z(fl) return sigma_of_t diff --git a/src/sage/schemes/elliptic_curves/gal_reps.py b/src/sage/schemes/elliptic_curves/gal_reps.py index 1b8d2ad64fd..c28b4f76d2c 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps.py +++ b/src/sage/schemes/elliptic_curves/gal_reps.py @@ -115,17 +115,19 @@ # http://www.gnu.org/licenses/ ###################################################################### +from math import sqrt + from sage.structure.sage_object import SageObject import sage.arith.all as arith from sage.rings.fast_arith import prime_range -import sage.misc.all as misc +from sage.misc.lazy_import import lazy_import +from sage.misc.misc_c import prod as mul from sage.misc.verbose import verbose -import sage.rings.all as rings +from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.real_mpfr import RealField from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF -from math import sqrt -from sage.libs.pari.all import pari +lazy_import('sage.libs.pari.all', 'pari') def _ex_set(p): @@ -467,7 +469,7 @@ def _is_surjective(self, p, A): self.__image_type[p] = "The image is meta-cyclic inside a Borel subgroup as there is a %s-torsion point on the curve." % p return False - R = rings.PolynomialRing(self._E.base_ring(), 'x') + R = PolynomialRing(self._E.base_ring(), 'x') x = R.gen() if p == 2: @@ -676,12 +678,12 @@ def non_surjective(self, A=1000): C2 = (sqrt(p0)+1)**8 C = max(C1,C2) verbose("j is not integral -- Serre's bound is %s" % C) - C3 = 1 + 4*sqrt(6)*int(N)/3 * sqrt(misc.mul([1+1.0/int(p) for p,_ in arith.factor(N)])) + C3 = 1 + 4*sqrt(6)*int(N)/3 * sqrt(mul([1+1.0/int(p) for p,_ in arith.factor(N)])) C = min(C,C3) verbose("conductor = %s, and bound is %s" % (N,C)) else: # Cojocaru's bound (depends on the conductor) - C = 1 + 4*sqrt(6)*int(N)/3 * sqrt(misc.mul([1+1.0/int(p) for p,_ in arith.factor(N)])) + C = 1 + 4*sqrt(6)*int(N)/3 * sqrt(mul([1+1.0/int(p) for p,_ in arith.factor(N)])) verbose("conductor = %s, and bound is %s" % (N,C)) B = [] p = 2 diff --git a/src/sage/schemes/elliptic_curves/heegner.py b/src/sage/schemes/elliptic_curves/heegner.py index 71e620c643a..3f916aed997 100644 --- a/src/sage/schemes/elliptic_curves/heegner.py +++ b/src/sage/schemes/elliptic_curves/heegner.py @@ -98,7 +98,13 @@ import sage.rings.abc import sage.rings.number_field.number_field_element import sage.rings.number_field.number_field as number_field -import sage.rings.all as rings +from sage.rings.number_field.number_field import NumberField +from sage.rings.number_field.number_field import QuadraticField +from sage.rings.real_mpfr import RealField +from sage.rings.complex_mpfr import ComplexField +from sage.rings.real_mpfi import RealIntervalField +from sage.rings.infinity import Infinity as infinity +from sage.rings.fast_arith import prime_range from sage.arith.functions import lcm from sage.arith.misc import (binomial, factorial, prime_divisors, @@ -3565,14 +3571,14 @@ def point_exact(self, prec=53, algorithm='lll', var='a', optimize=False): return v[0] g, d = make_monic(f) - K = rings.NumberField(g, var) + K = NumberField(g, var) x = K.gen() / d if optimize: KO, from_KO, to_KO = K.optimized_representation() K = KO x = to_KO(x) if K.degree() < 2 * self.ring_class_field().degree_over_K(): - M = rings.QuadraticField(self.discriminant(),'b') + M = QuadraticField(self.discriminant(),'b') KD = K.composite_fields(M, names='a')[0] phi = K.embeddings(KD)[0] x = phi(x) @@ -3807,7 +3813,7 @@ def _trace_numerical_conductor_1(self, prec=53): R, U = self._good_tau_representatives() E = self.__E phi = E.modular_parametrization() - C = rings.ComplexField(prec) + C = ComplexField(prec) F = E.change_ring(C) s = 0 for u, weight in U: @@ -4323,7 +4329,7 @@ def trace_to_real_numerical(self, prec=53): R = 2*P else: R = P + E.point([x.conjugate() for x in P],check=False) - F = self.curve().change_ring(rings.RealField(prec)) + F = self.curve().change_ring(RealField(prec)) return F.point([x.real() for x in R], check=False) @cached_method @@ -6590,12 +6596,12 @@ def heegner_point_height(self, D, prec=2, check_rank=True): eps = self.root_number() L1_vanishes = self.lseries().L1_vanishes() - IR = rings.RealIntervalField(20) # TODO: why 20 bits here? + IR = RealIntervalField(20) # TODO: why 20 bits here? if eps == 1 and L1_vanishes: return IR(0) # rank even hence >= 2, so Heegner point is torsion. - RR = rings.RealField() + RR = RealField() from math import sqrt alpha = RR(sqrt(abs(D)))/(2*self.period_lattice().complex_area()) @@ -6739,13 +6745,13 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." % D) if check_rank and self.rank() >= 2: - return rings.infinity + return infinity # First compute upper bound on height of Heegner point. tm = verbose("computing heegner point height...") h0 = self.heegner_point_height(D, prec=prec, check_rank=check_rank) if h0 == 0: - return rings.infinity + return infinity # We divide by 2 to get the height **over Q** of the # Heegner point on the twist. @@ -6767,7 +6773,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, from .ell_rational_field import _MAX_HEIGHT - IR = rings.RealIntervalField(20) # todo: 20? + IR = RealIntervalField(20) # todo: 20? a = 1 if c > _MAX_HEIGHT or F is self: @@ -6794,7 +6800,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, verbose("doing point search") P = F.point_search(c) verbose("done with point search") - P = [x for x in P if x.order() == rings.infinity] + P = [x for x in P if x.order() == infinity] a = 1 if len(P) == 0: return IR(1) @@ -6832,7 +6838,7 @@ def _adjust_heegner_index(self, a): 1.?e-8 """ if a.lower() < 0: - IR = rings.RealIntervalField(20) # todo: 20? + IR = RealIntervalField(20) # todo: 20? a = IR((0, a.upper())) return a.sqrt() @@ -6939,7 +6945,7 @@ def _bound(P): S, I, reg = F.saturation(P) - IR = rings.RealIntervalField(20) # todo: 20? + IR = RealIntervalField(20) # todo: 20? h = IR(reg-eps,reg+eps) ind2 = ht/(h/2) verbose("index squared = %s" % ind2) @@ -6955,17 +6961,17 @@ def _bound(P): # First try a quick search, in case we get lucky and find # a generator. P = F.point_search(13, rank_bound=1) - P = [x for x in P if x.order() == rings.infinity] + P = [x for x in P if x.order() == infinity] if len(P) > 0: return _bound(P) # Do search to eliminate possibility that Heegner point is # divisible by primes up to p, without finding Heegner point. P = F.point_search(c, rank_bound=1) - P = [x for x in P if x.order() == rings.infinity] + P = [x for x in P if x.order() == infinity] if len(P) == 0: # We've eliminated the possibility of a divisor up to p. - return rings.prime_range(3, p), D, False + return prime_range(3, p), D, False else: return _bound(P) @@ -7035,7 +7041,7 @@ def _heegner_index_in_EK(self, D): E = self # nice shortcut F = E.quadratic_twist(D).minimal_model() - K = rings.QuadraticField(D, 'a') + K = QuadraticField(D, 'a') # Define a map phi that we'll use to put the points of E^D(QQ) # into E(K): @@ -7050,11 +7056,11 @@ def _heegner_index_in_EK(self, D): ((z.order() % 2 == 0 and len(z.order().factor()) == 1))] r = len(basis) # rank - V = rings.QQ**r + V = QQ**r B = [] # Iterate through reps for A/(2*A) creating vectors in (1/2)*ZZ^r - for v in rings.GF(2)**r: + for v in GF(2)**r: if not v: continue P = sum([basis[i] for i in range(r) if v[i]]) @@ -7062,9 +7068,9 @@ def _heegner_index_in_EK(self, D): if (P+t).is_divisible_by(2): B.append(V(v)/2) - A = rings.ZZ**r + A = ZZ**r # Take span of our vectors in (1/2)*ZZ^r, along with ZZ^r. This is E(K)/tor. - W = V.span(B, rings.ZZ) + A + W = V.span(B, ZZ) + A # Compute the index in E(K)/tor of A = E(Q)/tor + E^D(Q)/tor, cache, and return. index = A.index_in(W) @@ -7163,7 +7169,7 @@ def heegner_sha_an(self, D, prec=53): # see page 311 of [GZ1986]_ for the formula. E = self # notational convenience F = E.quadratic_twist(D).minimal_model() - K = rings.QuadraticField(D, 'a') + K = QuadraticField(D, 'a') # Compute each of the quantities in BSD # - The torsion subgroup over K. diff --git a/src/sage/schemes/elliptic_curves/padic_lseries.py b/src/sage/schemes/elliptic_curves/padic_lseries.py index 7f32eb10a21..b4221da5823 100644 --- a/src/sage/schemes/elliptic_curves/padic_lseries.py +++ b/src/sage/schemes/elliptic_curves/padic_lseries.py @@ -61,7 +61,7 @@ # https://www.gnu.org/licenses/ ###################################################################### -import sage.matrix.all as matrix +from sage.matrix.constructor import Matrix as matrix import sage.schemes.hyperelliptic_curves.monsky_washnitzer from sage.arith.functions import lcm as LCM @@ -1449,7 +1449,7 @@ def Dp_valued_series(self, n=3, quadratic_twist=+1, prec=5): H = QpT(Hli, prec) # now compute phi - phi = matrix.matrix([[0, -1 / p], [1, E.ap(p) / p]]) + phi = matrix([[0, -1 / p], [1, E.ap(p) / p]]) lpv = vector([G + (E.ap(p)) * H, - R(p) * H]) # this is L_p eps = (1 - phi)**(-2) resu = lpv * eps.transpose() @@ -1498,7 +1498,7 @@ def frobenius(self, prec=20, algorithm="mw"): Q = x**3 + modprecring(Ew.a4()) * x + modprecring(Ew.a6()) trace = Ew.ap(p) fr = sage.schemes.hyperelliptic_curves.monsky_washnitzer.matrix_of_frobenius(Q, p, adjusted_prec, trace) - fr = matrix.matrix(output_ring,2,2,fr) + fr = matrix(output_ring,2,2,fr) # return a vector for PARI's ellchangecurve to pass from e1 to e2 def isom(e1, e2): @@ -1516,7 +1516,7 @@ def isom(e1, e2): r = v[1] # change basis - A = matrix.matrix([[u, -r/u], [0, 1/u]]) + A = matrix([[u, -r/u], [0, 1/u]]) frn = A * fr * A**(-1) return 1 / p*frn @@ -1610,7 +1610,7 @@ def __phi_bpr(self, prec=0): c = -gamma d = E.ap(p) - a b = (-1/p+a*d)/c - phi = matrix.matrix([[a,b],[c,d]]) + phi = matrix([[a,b],[c,d]]) return phi def bernardi_sigma_function(self, prec=20): @@ -1748,7 +1748,7 @@ def hv(vec, P): basis = E.gens() def regv(vec): - M = matrix.matrix(K, rk, rk, 0) + M = matrix(K, rk, rk, 0) point_height = [hv(vec, P) for P in basis] for i in range(rk): for j in range(i+1, rk): diff --git a/src/sage/schemes/elliptic_curves/padics.py b/src/sage/schemes/elliptic_curves/padics.py index f59e4b823fc..b9bb640e0ad 100644 --- a/src/sage/schemes/elliptic_curves/padics.py +++ b/src/sage/schemes/elliptic_curves/padics.py @@ -23,10 +23,13 @@ import math -import sage.arith.all as arith -import sage.matrix.all as matrix -import sage.misc.misc as misc -import sage.rings.all as rings +from sage.arith.functions import lcm as LCM +from sage.arith.misc import valuation +from sage.matrix.constructor import Matrix as matrix +from sage.misc.misc import newton_method_sizes +from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF +from sage.rings.padics.factory import Qp as pAdicField +from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing import sage.schemes.hyperelliptic_curves.hypellfrob import sage.schemes.hyperelliptic_curves.monsky_washnitzer @@ -61,7 +64,7 @@ def __check_padic_hypotheses(self, p): ArithmeticError: p must be a good ordinary prime """ - p = rings.Integer(p) + p = Integer(p) if not p.is_prime(): raise ValueError("p = (%s) must be prime" % p) if p == 2: @@ -399,7 +402,7 @@ def padic_height_pairing_matrix(self, p, prec=20, height=None, check_hypotheses= K = Qp(p, prec=prec) rank = self.rank() - M = matrix.matrix(K, rank, rank, 0) + M = matrix(K, rank, rank, 0) if rank == 0: return M @@ -630,7 +633,7 @@ def _multiple_to_make_good_reduction(E): "Please change the model first.") raise NotImplementedError(st) if E.is_minimal(): - n2 = arith.LCM(E.tamagawa_numbers()) + n2 = LCM(E.tamagawa_numbers()) else: # generalising to number fields one can get the u from local_data Emin = E.global_minimal_model() @@ -651,7 +654,7 @@ def _multiple_to_make_good_reduction(E): otherbad = Integer(Emin.discriminant()).prime_divisors() otherbad = [p for p in otherbad if u%p != 0 ] li += [E.tamagawa_number(p) for p in otherbad] - n2 = arith.LCM(li) + n2 = LCM(li) return n2 def padic_height(self, p, prec=20, sigma=None, check_hypotheses=True): @@ -805,13 +808,13 @@ def padic_height(self, p, prec=20, sigma=None, check_hypotheses=True): # For notation and definitions, see [Har2009]_. - n1 = self.change_ring(rings.GF(p)).cardinality() + n1 = self.change_ring(GF(p)).cardinality() n2 = _multiple_to_make_good_reduction(self) - n = arith.LCM(n1, n2) + n = LCM(n1, n2) m = int(n / n2) - adjusted_prec = prec + 2 * arith.valuation(n, p) # this is M' - R = rings.Integers(p ** adjusted_prec) + adjusted_prec = prec + 2 * valuation(n, p) # this is M' + R = Integers(p ** adjusted_prec) if sigma is None: sigma = self.padic_sigma(p, adjusted_prec, check_hypotheses=False) @@ -948,15 +951,15 @@ def padic_height_via_multiply(self, p, prec=20, E2=None, check_hypotheses=True): # For notation and definitions, [Har2009]_ - n1 = self.change_ring(rings.GF(p)).cardinality() + n1 = self.change_ring(GF(p)).cardinality() n2 = _multiple_to_make_good_reduction(self) - n = arith.LCM(n1, n2) + n = LCM(n1, n2) m = int(n / n2) lamb = int(math.floor(math.sqrt(prec))) - adjusted_prec = prec + 2 * arith.valuation(n, p) # this is M' - R = rings.Integers(p ** (adjusted_prec + 2*lamb)) + adjusted_prec = prec + 2 * valuation(n, p) # this is M' + R = Integers(p ** (adjusted_prec + 2*lamb)) sigma = self.padic_sigma_truncated(p, N=adjusted_prec, E2=E2, lamb=lamb) @@ -1150,7 +1153,7 @@ def padic_sigma(self, p, N=20, E2=None, check=False, check_hypotheses=True): QQt = LaurentSeriesRing(RationalField(), "x") - R = rings.Integers(p**(N-2)) + R = Integers(p**(N-2)) X = self.change_ring(R) c = (X.a1()**2 + 4*X.a2() - R(E2)) / 12 @@ -1171,7 +1174,7 @@ def padic_sigma(self, p, N=20, E2=None, check=False, check_hypotheses=True): assert A.valuation() == -1 and A[-1] == 1 A = A - A.parent().gen() ** (-1) A = A.power_series().list() - R = rings.Integers(p**(N-1)) + R = Integers(p**(N-1)) A = [R(u) for u in A] A[0] = self.change_ring(R).a1()/2 # fix constant term A = PowerSeriesRing(R, "x")(A, len(A)) @@ -1184,7 +1187,7 @@ def padic_sigma(self, p, N=20, E2=None, check=False, check_hypotheses=True): # [Note: there are actually more digits available, but it's a bit # tricky to figure out exactly how many, and we only need p^(N-k+1) # for p-adic height purposes anyway] - K = rings.pAdicField(p, N + 1) + K = pAdicField(p, N + 1) sigma = sigma.padded_list(N+1) @@ -1193,13 +1196,13 @@ def padic_sigma(self, p, N=20, E2=None, check=False, check_hypotheses=True): for n in range(2, N+1): sigma[n] = K(sigma[n].lift(), N - n + 1) - S = rings.PowerSeriesRing(K, "t", N+1) + S = PowerSeriesRing(K, "t", N+1) sigma = S(sigma, N+1) # if requested, check that sigma satisfies the appropriate # differential equation if check: - R = rings.Integers(p**N) + R = Integers(p**N) X = self.change_ring(R) x = X.formal_group().x(N+5) # few extra terms for safety f = X.formal_group().differential(N+5) @@ -1337,7 +1340,7 @@ def padic_sigma_truncated(self, p, N=20, lamb=0, E2=None, check_hypotheses=True) QQt = LaurentSeriesRing(RationalField(), "x") - R = rings.Integers(p**(N-2)) + R = Integers(p**(N-2)) X = self.change_ring(R) c = (X.a1()**2 + 4*X.a2() - R(E2)) / 12 @@ -1358,7 +1361,7 @@ def padic_sigma_truncated(self, p, N=20, lamb=0, E2=None, check_hypotheses=True) assert A.valuation() == -1 and A[-1] == 1 A = A - A.parent().gen() ** (-1) A = A.power_series().list() - R = rings.Integers(p**(N-1+lamb)) + R = Integers(p**(N-1+lamb)) A = [R(u) for u in A] A[0] = self.change_ring(R).a1()/2 # fix constant term A = PowerSeriesRing(R, "x")(A, len(A)) @@ -1368,7 +1371,7 @@ def padic_sigma_truncated(self, p, N=20, lamb=0, E2=None, check_hypotheses=True) # Convert the answer to power series over p-adics; drop the precision # of the t^j coefficient to p^{N - 2 + (3 - j)(lamb + 1)}). - K = rings.pAdicField(p, N - 2 + 3*(lamb+1)) + K = pAdicField(p, N - 2 + 3*(lamb+1)) sigma = sigma.padded_list(trunc+1) @@ -1377,7 +1380,7 @@ def padic_sigma_truncated(self, p, N=20, lamb=0, E2=None, check_hypotheses=True) for j in range(2, trunc+1): sigma[j] = K(sigma[j].lift(), N - 2 + (3 - j)*(lamb+1)) - S = rings.PowerSeriesRing(K, "t", trunc + 1) + S = PowerSeriesRing(K, "t", trunc + 1) sigma = S(sigma, trunc+1) return sigma @@ -1551,7 +1554,7 @@ def padic_E2(self, p, prec=20, check=False, check_hypotheses=True, algorithm="au frob_p_n = frob_p**prec # todo: think about the sign of this. Is it correct? - output_ring = rings.pAdicField(p, prec) + output_ring = pAdicField(p, prec) E2_of_X = output_ring( (-12 * frob_p_n[0,1] / frob_p_n[1,1]).lift() ) \ + O(p**prec) @@ -1686,16 +1689,16 @@ def matrix_of_frobenius(self, p, prec=20, check=False, check_hypotheses=True, al else: trace = self.ap(p) - base_ring = rings.Integers(p**adjusted_prec) + base_ring = Integers(p**adjusted_prec) - R, x = rings.PolynomialRing(base_ring, 'x').objgen() + R, x = PolynomialRing(base_ring, 'x').objgen() Q = x**3 + base_ring(X.a4()) * x + base_ring(X.a6()) frob_p = sage.schemes.hyperelliptic_curves.monsky_washnitzer.matrix_of_frobenius( Q, p, adjusted_prec, trace) else: # algorithm == "sqrtp" p_to_prec = p**prec - R = rings.PolynomialRing(Integers(), "x") + R = PolynomialRing(Integers(), "x") Q = R([X.a6() % p_to_prec, X.a4() % p_to_prec, 0, 1]) frob_p = sage.schemes.hyperelliptic_curves.hypellfrob.hypellfrob(p, prec, Q) @@ -1776,7 +1779,7 @@ def _brent(F, p, N): G = Rx.one() # loop over an appropriate increasing sequence of lengths s - for s in misc.newton_method_sizes(N): + for s in newton_method_sizes(N): # zero-extend to s terms # todo: there has to be a better way in Sage to do this... G = Rx(G.list(), s) From 785ba39f28134d8c78cc697eade35af0b6ebd6c9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 12:48:25 -0700 Subject: [PATCH 05/20] src/sage/schemes/elliptic_curves/ell_point.py: Modularization fix for imports --- src/sage/schemes/elliptic_curves/ell_point.py | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/ell_point.py b/src/sage/schemes/elliptic_curves/ell_point.py index 391897f6103..410a5f93640 100644 --- a/src/sage/schemes/elliptic_curves/ell_point.py +++ b/src/sage/schemes/elliptic_curves/ell_point.py @@ -122,13 +122,15 @@ from sage.rings.padics.factory import Qp from sage.rings.padics.precision_error import PrecisionError -import sage.rings.all as rings import sage.rings.abc + +from sage.rings.infinity import Infinity as oo from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ +from sage.rings.rational_field import QQ +from sage.rings.real_mpfr import RealField +from sage.rings.real_mpfr import RR import sage.groups.generic as generic -from sage.libs.pari.all import pari, PariError -from cypari2.pari_instance import prec_words_to_bits from sage.structure.sequence import Sequence from sage.structure.richcmp import richcmp @@ -141,7 +143,11 @@ from .constructor import EllipticCurve -oo = rings.infinity # infinity +try: + from sage.libs.pari.all import pari, PariError + from cypari2.pari_instance import prec_words_to_bits +except ImportError: + PariError = () class EllipticCurvePoint(SchemeMorphism_point_projective_ring): @@ -2293,9 +2299,9 @@ def is_on_identity_component(self, embedding=None): K = E.base_field() if e is None: try: - e = K.embeddings(rings.RealField())[0] + e = K.embeddings(RealField())[0] except IndexError: - e = K.embeddings(rings.ComplexField())[0] + e = K.embeddings(ComplexField())[0] # If there is only one component, the result is True: if not isinstance(e.codomain(), sage.rings.abc.RealField): # complex embedding @@ -2405,7 +2411,7 @@ def has_good_reduction(self, P=None): xyz = list(Q) e = min([c.valuation(P) for c in xyz]) if e != 0: - if K is rings.QQ: + if K is QQ: pi = P else: pi = K.uniformizer(P) @@ -2711,30 +2717,30 @@ def height(self, precision=None, normalised=True, algorithm='pari'): 1.06248137652528 """ if self.has_finite_order(): - return rings.QQ(0) + return QQ(0) E = self.curve() K = E.base_ring() if precision is None: - precision = rings.RealField().precision() + precision = RealField().precision() known_prec = -1 try: height = self.__height known_prec = height.prec() if known_prec > precision: - height = rings.RealField(precision)(height) + height = RealField(precision)(height) except AttributeError: pass if known_prec < precision: - if algorithm == 'pari' and K is rings.QQ: + if algorithm == 'pari' and K is QQ: Emin = E.minimal_model() iso = E.isomorphism_to(Emin) P = iso(self) h = Emin.pari_curve().ellheight(P, precision=precision) - height = rings.RealField(precision)(h) + height = RealField(precision)(h) else: height = (self.non_archimedean_local_height(prec=precision) + self.archimedean_local_height(prec=precision)) @@ -2868,8 +2874,8 @@ def archimedean_local_height(self, v=None, prec=None, weighted=False): if prec is None: prec = 53 - if K is rings.QQ: - v = K.embeddings(rings.RR)[0] + if K is QQ: + v = K.embeddings(RR)[0] h = self.archimedean_local_height(v, prec+10) else: r1, r2 = K.signature() @@ -2885,7 +2891,7 @@ def archimedean_local_height(self, v=None, prec=None, weighted=False): prec_v = v.codomain().prec() if prec is None: prec = prec_v - if K is rings.QQ: + if K is QQ: v = K.embeddings(RealField())[0] v_inf = refine_embedding(v, Infinity) v_is_real = v_inf(K.gen()).imag().is_zero() @@ -2943,7 +2949,7 @@ def archimedean_local_height(self, v=None, prec=None, weighted=False): beta = False lam = -t.abs().log() mu = 0 - four_to_n = rings.QQ(1) + four_to_n = QQ(1) for n in range(nterms): if beta: @@ -3079,14 +3085,14 @@ def non_archimedean_local_height(self, v=None, prec=None, -2/3*log(2) """ if prec: - log = lambda x: rings.RealField(prec)(x).log() + log = lambda x: RealField(prec)(x).log() else: from sage.functions.log import log if v is None: D = self.curve().discriminant() K = self.curve().base_ring() - if K is rings.QQ: + if K is QQ: factorD = D.factor() if self[0] == 0: c = 1 @@ -3149,9 +3155,9 @@ def non_archimedean_local_height(self, v=None, prec=None, r = -C/4 r -= offset/6 if not r: - return rings.QQ.zero() + return QQ.zero() else: - if E.base_ring() is rings.QQ: + if E.base_ring() is QQ: Nv = Integer(v) else: Nv = v.norm() From e2778a787cc2114b5a0be6a743a1a527782d5dc8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 13:02:22 -0700 Subject: [PATCH 06/20] src/.relint.yml (namespace_pkg_all_import_2): Exclude explain_pickle --- src/.relint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.relint.yml b/src/.relint.yml index ab460661f1e..9ed75b17b14 100644 --- a/src/.relint.yml +++ b/src/.relint.yml @@ -62,7 +62,7 @@ # Keep in sync with above; but for now we ignore sage.{arith,categories} pattern: '^import\s+sage(|[.](combinat|crypto|databases|data_structures|dynamics|ext|game_theory|games|geometry|graphs|groups|interfaces|manifolds|matrix|matroids|misc|modules|monoids|numerical|probability|quadratic_forms|quivers|rings|sat|schemes|sets|stats|symbolic|tensor)[a-z0-9_.]*|[.]libs)[.]all' # imports from .all are allowed in all.py; also allow in some modules that need sage.all - filePattern: '(.*/|)(?!(all|benchmark|dev_tools|parsing|sage_eval|.*_test))[^/.]*[.](py|pyx|pxi)$' + filePattern: '(.*/|)(?!(all|benchmark|dev_tools|parsing|sage_eval|explain_pickle|.*_test))[^/.]*[.](py|pyx|pxi)$' # Magic doctest comments From 4b42cca1cfb202a23b25a3208f1789229f81c298 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 4 Jun 2023 09:03:10 -0700 Subject: [PATCH 07/20] src/sage/lfunctions/lcalc.py: Modularization fixes --- src/sage/lfunctions/lcalc.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/sage/lfunctions/lcalc.py b/src/sage/lfunctions/lcalc.py index d791460039b..2f6ddc2db48 100644 --- a/src/sage/lfunctions/lcalc.py +++ b/src/sage/lfunctions/lcalc.py @@ -30,9 +30,14 @@ import os from sage.structure.sage_object import SageObject +from sage.misc.lazy_import import lazy_import from sage.misc.pager import pager -import sage.rings.all -import sage.schemes.elliptic_curves.ell_generic +from sage.rings.integer_ring import ZZ +from sage.rings.rational_field import QQ + +lazy_import('sage.rings.complex_mpfr', 'ComplexField') +lazy_import('sage.rings.real_mpfr', 'RealField') +lazy_import('sage.schemes.elliptic_curves.ell_generic', 'EllipticCurve') prec = 32 @@ -75,9 +80,8 @@ def _compute_L(self, L): if L == 'tau': return '--tau' return L - import sage.schemes.all - if sage.schemes.elliptic_curves.ell_generic.is_EllipticCurve(L): - if L.base_ring() == sage.rings.all.RationalField(): + if isinstance(L, EllipticCurve): + if L.base_ring() == QQ: L = L.minimal_model() return '-e --a1 %s --a2 %s --a3 %s --a4 %s --a6 %s' % tuple(L.a_invariants()) raise TypeError("$L$-function of %s not known" % L) @@ -127,7 +131,7 @@ def zeros(self, n, L=''): [0.000000000, 5.00317001, 6.87039122] """ L = self._compute_L(L) - RR = sage.rings.all.RealField(prec) + RR = RealField(prec) X = self('-z %s %s' % (int(n), L)) return [RR(z) for z in X.split()] @@ -162,7 +166,7 @@ def zeros_in_interval(self, x, y, stepsize, L=''): [(14.1347251, 0.184672916), (21.0220396, -0.0677893290), (25.0108576, -0.0555872781)] """ L = self._compute_L(L) - RR = sage.rings.all.RealField(prec) + RR = RealField(prec) X = self('--zeros-interval -x %s -y %s --stepsize=%s %s' % ( float(x), float(y), float(stepsize), L)) return [tuple([RR(z) for z in t.split()]) for t in X.split('\n')] @@ -193,7 +197,7 @@ def value(self, s, L=''): 2.69261988568132 - 0.0203860296025982*I """ L = self._compute_L(L) - CC = sage.rings.all.ComplexField(prec) + CC = ComplexField(prec) s = CC(s) x, y = self('-v -x %s -y %s %s' % (s.real(), s.imag(), L)).split() return CC((float(x), float(y))) @@ -275,7 +279,7 @@ def values_along_line(self, s0, s1, number_samples, L=''): """ L = self._compute_L(L) - CC = sage.rings.all.ComplexField(prec) + CC = ComplexField(prec) s0 = CC(s0) s1 = CC(s1) v = self('--value-line-segment -x %s -y %s -X %s -Y %s --number-samples %s %s' % ( @@ -343,8 +347,7 @@ def twist_values(self, s, dmin, dmax, L=''): 0.373691713 + 0.0*I """ L = self._compute_L(L) - CC = sage.rings.all.ComplexField(prec) - Z = sage.rings.all.Integer + CC = ComplexField(prec) s = CC(s) typ = '--twist-quadratic' dmin = int(dmin) @@ -358,7 +361,7 @@ def twist_values(self, s, dmin, dmax, L=''): return w for a in v.split('\n'): d, x, y = a.split() - w.append((Z(d), CC(x, y))) + w.append((ZZ(d), CC(x, y))) return w def twist_zeros(self, n, dmin, dmax, L=''): @@ -393,8 +396,7 @@ def twist_zeros(self, n, dmin, dmax, L=''): {-3: [8.03973716, 11.2492062, 15.7046192], 5: [6.64845335, 9.83144443, 11.9588456]} """ L = self._compute_L(L) - RR = sage.rings.all.RealField(prec) - Z = sage.rings.all.Integer + RR = RealField(prec) typ = '--twist-quadratic' n = int(n) v = self('-z %s %s --start %s --finish %s %s' % ( @@ -405,7 +407,7 @@ def twist_zeros(self, n, dmin, dmax, L=''): for a in v.split('\n'): d, x = a.split() x = RR(x) - d = Z(d) + d = ZZ(d) if d in w: w[d].append(x) else: @@ -439,10 +441,9 @@ def analytic_rank(self, L=''): 1 """ L = self._compute_L(L) - Z = sage.rings.all.Integer s = self('--rank-compute %s' % L) i = s.find('equals') - return Z(s[i + 6:]) + return ZZ(s[i + 6:]) # An instance From 711376ff71d82384039ca36e81494491287fdb16 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 14:14:59 -0700 Subject: [PATCH 08/20] src/sage/schemes/elliptic_curves/ell_rational_field.py: Fix more imports --- src/sage/schemes/elliptic_curves/ell_rational_field.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index 633fc0e9a47..765485f0374 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -66,8 +66,6 @@ from sage.modular.modsym.modsym import ModularSymbols from sage.modular.pollack_stevens.space import ps_modsym_from_elliptic_curve -from sage.lfunctions.zero_sums import LFunctionZeroSum_EllipticCurve - import sage.modular.modform.constructor import sage.modular.modform.element import sage.databases.cremona @@ -92,6 +90,7 @@ from sage.structure.element import Element from sage.misc.misc_c import prod as mul from sage.misc.misc_c import prod +from sage.misc.lazy_import import lazy_import from sage.misc.verbose import verbose as verbose_verbose from sage.functions.log import log @@ -1769,6 +1768,8 @@ def analytic_rank_upper_bound(self, ....: bad_primes=bad_primes, ncpus=2) 32 """ + from sage.lfunctions.zero_sums import LFunctionZeroSum_EllipticCurve + Z = LFunctionZeroSum_EllipticCurve(self, N) bound = Z.analytic_rank_upper_bound(max_Delta=max_Delta, adaptive=adaptive, From 0645cb2a944e553fa96eea8352dd766a82740d6e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 17:30:34 -0700 Subject: [PATCH 09/20] Fix up import --- src/sage/lfunctions/lcalc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/lfunctions/lcalc.py b/src/sage/lfunctions/lcalc.py index 2f6ddc2db48..73246cdd81e 100644 --- a/src/sage/lfunctions/lcalc.py +++ b/src/sage/lfunctions/lcalc.py @@ -37,7 +37,7 @@ lazy_import('sage.rings.complex_mpfr', 'ComplexField') lazy_import('sage.rings.real_mpfr', 'RealField') -lazy_import('sage.schemes.elliptic_curves.ell_generic', 'EllipticCurve') +lazy_import('sage.schemes.elliptic_curves.ell_generic', 'EllipticCurve_generic', as_='EllipticCurve') prec = 32 From 0ccf1952f8f0f3a89db14af220edf4498e44a216 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 20:49:32 -0700 Subject: [PATCH 10/20] src/sage/schemes/elliptic_curves/constructor.py: Fix up --- src/sage/schemes/elliptic_curves/constructor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index b9e9999418a..ca210ca6e2b 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -423,7 +423,7 @@ def create_key_and_extra_args(self, x=None, y=None, j=None, minimal_twist=True, x = x.lhs() - x.rhs() if isinstance(parent(x), sage.rings.abc.SymbolicRing): - x = x._polynomial_(rings.QQ['x', 'y']) + x = x._polynomial_(QQ['x', 'y']) if isinstance(x, MPolynomial): if y is None: From 04e515b092717ec78f5d540ba88742d08d7a8686 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 19:24:06 -0700 Subject: [PATCH 11/20] sage.modular: Modularization fixes for imports --- src/sage/modular/abvar/abvar.py | 7 +- src/sage/modular/abvar/finite_subgroup.py | 10 ++- src/sage/modular/arithgroup/all.py | 3 +- src/sage/modular/btquotients/btquotient.py | 6 +- .../modular/btquotients/pautomorphicform.py | 5 +- src/sage/modular/local_comp/local_comp.py | 4 +- src/sage/modular/local_comp/smoothchar.py | 6 +- src/sage/modular/modform/all.py | 5 +- .../modular/modform/cuspidal_submodule.py | 7 +- src/sage/modular/modform/eis_series.py | 5 +- .../modular/modform/eisenstein_submodule.py | 72 ++++++++++++------- src/sage/modular/modform/element.py | 6 +- .../modular/modform/hecke_operator_on_qexp.py | 4 +- .../modform_hecketriangle/abstract_space.py | 7 +- .../graded_ring_element.py | 6 +- .../hecke_triangle_group_element.py | 4 +- .../hecke_triangle_groups.py | 12 ++-- src/sage/modular/modsym/all.py | 3 +- src/sage/modular/modsym/space.py | 3 +- src/sage/modular/overconvergent/genus0.py | 6 +- .../modular/overconvergent/weightspace.py | 6 +- .../modular/pollack_stevens/distributions.py | 8 ++- src/sage/modular/pollack_stevens/modsym.py | 6 +- .../modular/pollack_stevens/padic_lseries.py | 4 +- 24 files changed, 135 insertions(+), 70 deletions(-) diff --git a/src/sage/modular/abvar/abvar.py b/src/sage/modular/abvar/abvar.py index 05a9c16b9a1..818268b72fe 100644 --- a/src/sage/modular/abvar/abvar.py +++ b/src/sage/modular/abvar/abvar.py @@ -33,6 +33,8 @@ from copy import copy from random import randrange +import sage.rings.abc + from sage.arith.functions import lcm as LCM from sage.arith.misc import divisors, next_prime, is_prime from sage.categories.modular_abelian_varieties import ModularAbelianVarieties @@ -55,7 +57,6 @@ from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.rings.qqbar import QQbar from sage.rings.rational_field import QQ from sage.rings.ring import is_Ring from sage.schemes.elliptic_curves.constructor import EllipticCurve @@ -66,6 +67,8 @@ lazy_import('sage.databases.cremona', ['cremona_letter_code', 'CremonaDatabase']) +lazy_import('sage.rings.qqbar', 'QQbar') + from . import homspace from . import lseries @@ -798,7 +801,7 @@ def _Hom_(self, B, cat=None): L = B.base_field() if K == L: F = K - elif K == QQbar or L == QQbar: + elif isinstance(K, sage.rings.abc.AlgebraicField) or isinstance(L, sage.rings.abc.AlgebraicField): F = QQbar else: # TODO -- improve this diff --git a/src/sage/modular/abvar/finite_subgroup.py b/src/sage/modular/abvar/finite_subgroup.py index 3f4f0ffbd8f..3d459ab124c 100644 --- a/src/sage/modular/abvar/finite_subgroup.py +++ b/src/sage/modular/abvar/finite_subgroup.py @@ -97,6 +97,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** +from sage.misc.lazy_import import lazy_import from sage.modular.abvar.torsion_point import TorsionPoint from sage.modules.module import Module from sage.modules.free_module import is_FreeModule @@ -105,12 +106,13 @@ from sage.structure.richcmp import richcmp_method, richcmp from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ -from sage.rings.qqbar import QQbar from sage.rings.rational_field import QQ from sage.arith.functions import lcm from sage.misc.misc_c import prod from sage.structure.element import coercion_model +lazy_import('sage.rings.qqbar', 'QQbar') + @richcmp_method class FiniteSubgroup(Module): @@ -521,7 +523,7 @@ def _repr_(self): 'Finite subgroup with invariants [3, 3, 3, 3, 3, 3, 3, 3, 3, 3] over QQ of Abelian variety J0(42) of dimension 5' """ K = self.__field_of_definition - if K == QQbar: + if isinstance(K, sage.rings.abc.AlgebraicField): field = "QQbar" elif K == QQ: field = "QQ" @@ -815,7 +817,7 @@ def invariants(self): class FiniteSubgroup_lattice(FiniteSubgroup): - def __init__(self, abvar, lattice, field_of_definition=QQbar, check=True): + def __init__(self, abvar, lattice, field_of_definition=None, check=True): """ A finite subgroup of a modular abelian variety that is defined by a given lattice. @@ -841,6 +843,8 @@ def __init__(self, abvar, lattice, field_of_definition=QQbar, check=True): sage: G = J.finite_subgroup([[1/3,0], [0,1/5]]); G Finite subgroup with invariants [15] over QQbar of Abelian variety J0(11) of dimension 1 """ + if field_of_definition is None: + field_of_definition = QQbar if check: from .abvar import is_ModularAbelianVariety if not is_FreeModule(lattice) or lattice.base_ring() != ZZ: diff --git a/src/sage/modular/arithgroup/all.py b/src/sage/modular/arithgroup/all.py index 9f312be37d0..d4fb241d1f9 100644 --- a/src/sage/modular/arithgroup/all.py +++ b/src/sage/modular/arithgroup/all.py @@ -9,7 +9,8 @@ from .congroup_gamma import Gamma_constructor as Gamma, is_Gamma from .congroup_sl2z import SL2Z, is_SL2Z -from .arithgroup_perm import ArithmeticSubgroup_Permutation +from sage.misc.lazy_import import lazy_import +lazy_import('sage.modular.arithgroup.arithgroup_perm', 'ArithmeticSubgroup_Permutation') from .congroup import (degeneracy_coset_representatives_gamma0, degeneracy_coset_representatives_gamma1) diff --git a/src/sage/modular/btquotients/btquotient.py b/src/sage/modular/btquotients/btquotient.py index 6ced79751c3..0049ed02f7a 100644 --- a/src/sage/modular/btquotients/btquotient.py +++ b/src/sage/modular/btquotients/btquotient.py @@ -42,7 +42,6 @@ from collections import deque from sage.arith.misc import gcd, xgcd, kronecker_symbol, fundamental_discriminant -from sage.libs.pari.all import pari from sage.matrix.constructor import Matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.cachefunc import cached_method @@ -59,8 +58,6 @@ from sage.rings.finite_rings.integer_mod_ring import Zmod from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ -from sage.rings.number_field.number_field import NumberField -from sage.rings.padics.factory import Qp, Zp from sage.rings.padics.precision_error import PrecisionError from sage.rings.rational_field import QQ from sage.structure.sage_object import SageObject @@ -68,7 +65,10 @@ lazy_import('sage.algebras.quatalg.quaternion_algebra', 'QuaternionAlgebra') lazy_import('sage.graphs.graph', 'Graph') +lazy_import('sage.libs.pari.all', 'pari') lazy_import('sage.plot.colors', 'rainbow') +lazy_import('sage.rings.number_field.number_field', 'NumberField') +lazy_import('sage.rings.padics.factory', ['Qp', 'Zp']) class DoubleCosetReduction(SageObject): diff --git a/src/sage/modular/btquotients/pautomorphicform.py b/src/sage/modular/btquotients/pautomorphicform.py index a0d7e1294f9..3ed9fc34711 100644 --- a/src/sage/modular/btquotients/pautomorphicform.py +++ b/src/sage/modular/btquotients/pautomorphicform.py @@ -46,6 +46,7 @@ from sage.matrix.constructor import Matrix, zero_matrix from sage.matrix.matrix_space import MatrixSpace +from sage.misc.lazy_import import lazy_import from sage.misc.verbose import verbose from sage.modular.btquotients.btquotient import DoubleCosetReduction from sage.modular.hecke.all import AmbientHeckeModule, HeckeModuleElement @@ -56,7 +57,6 @@ from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.rings.laurent_series_ring import LaurentSeriesRing -from sage.rings.padics.factory import Qp from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational_field import QQ from sage.rings.real_mpfr import RR @@ -64,6 +64,9 @@ from sage.structure.richcmp import op_EQ, op_NE from sage.structure.unique_representation import UniqueRepresentation +lazy_import('sage.rings.padics.factory', 'Qp') + + # Need this to be pickleable diff --git a/src/sage/modular/local_comp/local_comp.py b/src/sage/modular/local_comp/local_comp.py index 4a8ec0195f5..765ce805ed9 100644 --- a/src/sage/modular/local_comp/local_comp.py +++ b/src/sage/modular/local_comp/local_comp.py @@ -23,14 +23,16 @@ from sage.rings.integer_ring import ZZ from sage.rings.polynomial.polynomial_ring import polygen from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.rings.qqbar import QQbar from sage.misc.abstract_method import abstract_method from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.verbose import verbose from sage.misc.flatten import flatten from sage.modular.modform.element import Newform from sage.structure.sequence import Sequence +lazy_import('sage.rings.qqbar', 'QQbar') + from .type_space import TypeSpace from .smoothchar import SmoothCharacterGroupQp, SmoothCharacterGroupUnramifiedQuadratic, SmoothCharacterGroupRamifiedQuadratic diff --git a/src/sage/modular/local_comp/smoothchar.py b/src/sage/modular/local_comp/smoothchar.py index 0e878b99277..b56befe27cb 100644 --- a/src/sage/modular/local_comp/smoothchar.py +++ b/src/sage/modular/local_comp/smoothchar.py @@ -49,15 +49,14 @@ from sage.categories.rings import Rings from sage.misc.abstract_method import abstract_method from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.misc.mrange import xmrange from sage.misc.verbose import verbose from sage.modular.dirichlet import DirichletGroup -from sage.rings.finite_rings.conway_polynomials import conway_polynomial from sage.rings.finite_rings.integer_mod_ring import Zmod from sage.rings.infinity import Infinity from sage.rings.integer_ring import ZZ -from sage.rings.number_field.number_field import NumberField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational_field import QQ from sage.structure.element import MultiplicativeGroupElement, parent @@ -65,6 +64,9 @@ from sage.structure.richcmp import richcmp_not_equal, richcmp from sage.structure.sequence import Sequence +lazy_import('sage.rings.finite_rings.conway_polynomials', 'conway_polynomial') +lazy_import('sage.rings.number_field.number_field', 'NumberField') + class SmoothCharacterGeneric(MultiplicativeGroupElement): r""" diff --git a/src/sage/modular/modform/all.py b/src/sage/modular/modform/all.py index eefb8c3609f..feb1521d3ca 100644 --- a/src/sage/modular/modform/all.py +++ b/src/sage/modular/modform/all.py @@ -14,9 +14,10 @@ from .theta import theta_qexp, theta2_qexp -from .j_invariant import j_invariant_qexp +from sage.misc.lazy_import import lazy_import -from .vm_basis import victor_miller_basis, delta_qexp +lazy_import('sage.modular.modform.j_invariant', 'j_invariant_qexp') +lazy_import('sage.modular.modform.vm_basis', ['victor_miller_basis', 'delta_qexp']) from .hecke_operator_on_qexp import hecke_operator_on_qexp, hecke_operator_on_basis diff --git a/src/sage/modular/modform/cuspidal_submodule.py b/src/sage/modular/modform/cuspidal_submodule.py index fe9d35d55dd..19a0b5661c0 100644 --- a/src/sage/modular/modform/cuspidal_submodule.py +++ b/src/sage/modular/modform/cuspidal_submodule.py @@ -41,12 +41,14 @@ from sage.matrix.constructor import Matrix from sage.matrix.special import identity_matrix from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.verbose import verbose from sage.rings.integer import Integer from sage.rings.rational_field import QQ +lazy_import('sage.modular.modform.vm_basis', 'victor_miller_basis') + from .submodule import ModularFormsSubmodule -from . import vm_basis from . import weight1 class CuspidalSubmodule(ModularFormsSubmodule): @@ -316,8 +318,7 @@ def _compute_q_expansion_basis(self, prec=None): prec = self.prec() else: prec = Integer(prec) - return vm_basis.victor_miller_basis(self.weight(), prec, - cusp_only=True, var='q') + return victor_miller_basis(self.weight(), prec, cusp_only=True, var='q') def _pari_init_(self): """ diff --git a/src/sage/modular/modform/eis_series.py b/src/sage/modular/modform/eis_series.py index fbdee194cfa..be0f2557c73 100644 --- a/src/sage/modular/modform/eis_series.py +++ b/src/sage/modular/modform/eis_series.py @@ -14,16 +14,17 @@ from sage.arith.functions import lcm from sage.arith.misc import bernoulli, divisors, is_squarefree +from sage.misc.lazy_import import lazy_import from sage.misc.timing import cputime from sage.modular.arithgroup.congroup_gammaH import GammaH_class from sage.modular.dirichlet import DirichletGroup from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ -from sage.rings.number_field.number_field import CyclotomicField from sage.rings.power_series_ring import PowerSeriesRing from sage.rings.rational_field import QQ -from .eis_series_cython import eisenstein_series_poly, Ek_ZZ +lazy_import('sage.modular.modform.eis_series_cython', ['eisenstein_series_poly', 'Ek_ZZ']) +lazy_import('sage.rings.number_field.number_field', 'CyclotomicField') def eisenstein_series_qexp(k, prec=10, K=QQ, var='q', normalization='linear'): diff --git a/src/sage/modular/modform/eisenstein_submodule.py b/src/sage/modular/modform/eisenstein_submodule.py index aced6a69aca..fd1731574fa 100644 --- a/src/sage/modular/modform/eisenstein_submodule.py +++ b/src/sage/modular/modform/eisenstein_submodule.py @@ -8,10 +8,12 @@ from sage.categories.objects import Objects from sage.matrix.constructor import Matrix from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.rings.integer import Integer -from sage.rings.number_field.number_field import CyclotomicField from sage.structure.sequence import Sequence +lazy_import('sage.rings.number_field.number_field', 'CyclotomicField') + from . import eis_series from . import element from . import submodule @@ -29,7 +31,8 @@ def __init__(self, ambient_space): sage: E = ModularForms(23,4).eisenstein_subspace() # indirect doctest sage: E - Eisenstein subspace of dimension 2 of Modular Forms space of dimension 7 for Congruence Subgroup Gamma0(23) of weight 4 over Rational Field + Eisenstein subspace of dimension 2 of Modular Forms space of dimension 7 + for Congruence Subgroup Gamma0(23) of weight 4 over Rational Field sage: E == loads(dumps(E)) True """ @@ -101,10 +104,13 @@ def modular_symbols(self, sign=0): sage: eps = DirichletGroup(13).0 sage: E = EisensteinForms(eps^2, 2) sage: E.modular_symbols() - Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2 + Modular Symbols subspace of dimension 2 of Modular Symbols space of + dimension 4 and level 13, weight 2, character [zeta6], sign 0, + over Cyclotomic Field of order 6 and degree 2 sage: E = EisensteinForms(eps, 1); E - Eisenstein subspace of dimension 1 of Modular Forms space of character [zeta12] and weight 1 over Cyclotomic Field of order 12 and degree 4 + Eisenstein subspace of dimension 1 of Modular Forms space of character + [zeta12] and weight 1 over Cyclotomic Field of order 12 and degree 4 sage: E.modular_symbols() Traceback (most recent call last): ... @@ -127,11 +133,13 @@ def parameters(self): EXAMPLES:: sage: ModularForms(24,2).eisenstein_submodule().parameters() - [(Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, 2), - ... - Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, 24)] + [(Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, + Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, 2), + ... + Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, 24)] sage: EisensteinForms(12,6).parameters()[-1] - (Dirichlet character modulo 12 of conductor 1 mapping 7 |--> 1, 5 |--> 1, Dirichlet character modulo 12 of conductor 1 mapping 7 |--> 1, 5 |--> 1, 12) + (Dirichlet character modulo 12 of conductor 1 mapping 7 |--> 1, 5 |--> 1, + Dirichlet character modulo 12 of conductor 1 mapping 7 |--> 1, 5 |--> 1, 12) sage: pars = ModularForms(DirichletGroup(24).0,3).eisenstein_submodule().parameters() sage: [(x[0].values_on_gens(),x[1].values_on_gens(),x[2]) for x in pars] @@ -144,7 +152,14 @@ def parameters(self): ((-1, 1, 1), (1, 1, 1), 3), ((-1, 1, 1), (1, 1, 1), 6)] sage: EisensteinForms(DirichletGroup(24).0,1).parameters() - [(Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, Dirichlet character modulo 24 of conductor 4 mapping 7 |--> -1, 13 |--> 1, 17 |--> 1, 1), (Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, Dirichlet character modulo 24 of conductor 4 mapping 7 |--> -1, 13 |--> 1, 17 |--> 1, 2), (Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, Dirichlet character modulo 24 of conductor 4 mapping 7 |--> -1, 13 |--> 1, 17 |--> 1, 3), (Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, Dirichlet character modulo 24 of conductor 4 mapping 7 |--> -1, 13 |--> 1, 17 |--> 1, 6)] + [(Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, + Dirichlet character modulo 24 of conductor 4 mapping 7 |--> -1, 13 |--> 1, 17 |--> 1, 1), + (Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, + Dirichlet character modulo 24 of conductor 4 mapping 7 |--> -1, 13 |--> 1, 17 |--> 1, 2), + (Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, + Dirichlet character modulo 24 of conductor 4 mapping 7 |--> -1, 13 |--> 1, 17 |--> 1, 3), + (Dirichlet character modulo 24 of conductor 1 mapping 7 |--> 1, 13 |--> 1, 17 |--> 1, + Dirichlet character modulo 24 of conductor 4 mapping 7 |--> -1, 13 |--> 1, 17 |--> 1, 6)] """ char = self._parameters_character() if char is None: @@ -159,7 +174,8 @@ def new_submodule(self, p=None): EXAMPLES:: sage: e = EisensteinForms(Gamma0(225), 2).new_submodule(); e - Modular Forms subspace of dimension 3 of Modular Forms space of dimension 42 for Congruence Subgroup Gamma0(225) of weight 2 over Rational Field + Modular Forms subspace of dimension 3 of Modular Forms space of dimension 42 + for Congruence Subgroup Gamma0(225) of weight 2 over Rational Field sage: e.basis() [ q + O(q^6), @@ -190,7 +206,8 @@ def change_ring(self, base_ring): EXAMPLES:: sage: E = EisensteinForms(12,2) ; E - Eisenstein subspace of dimension 5 of Modular Forms space of dimension 5 for Congruence Subgroup Gamma0(12) of weight 2 over Rational Field + Eisenstein subspace of dimension 5 of Modular Forms space of dimension 5 + for Congruence Subgroup Gamma0(12) of weight 2 over Rational Field sage: E.basis() [ 1 + O(q^6), @@ -200,7 +217,8 @@ def change_ring(self, base_ring): q^4 + O(q^6) ] sage: E.change_ring(GF(5)) - Eisenstein subspace of dimension 5 of Modular Forms space of dimension 5 for Congruence Subgroup Gamma0(12) of weight 2 over Finite Field of size 5 + Eisenstein subspace of dimension 5 of Modular Forms space of dimension 5 + for Congruence Subgroup Gamma0(12) of weight 2 over Finite Field of size 5 sage: E.change_ring(GF(5)).basis() [ 1 + O(q^6), @@ -233,7 +251,8 @@ def eisenstein_series(self): ] sage: EisensteinForms(1,24).eisenstein_series() [ - 236364091/131040 + q + 8388609*q^2 + 94143178828*q^3 + 70368752566273*q^4 + 11920928955078126*q^5 + O(q^6) + 236364091/131040 + q + 8388609*q^2 + 94143178828*q^3 + + 70368752566273*q^4 + 11920928955078126*q^5 + O(q^6) ] sage: EisensteinForms(5,4).eisenstein_series() [ @@ -259,7 +278,8 @@ def eisenstein_series(self): sage: eps = DirichletGroup(13).0^2 sage: ModularForms(eps,2).eisenstein_series() [ - -7/13*zeta6 - 11/13 + q + (2*zeta6 + 1)*q^2 + (-3*zeta6 + 1)*q^3 + (6*zeta6 - 3)*q^4 - 4*q^5 + O(q^6), + -7/13*zeta6 - 11/13 + q + (2*zeta6 + 1)*q^2 + (-3*zeta6 + 1)*q^3 + + (6*zeta6 - 3)*q^4 - 4*q^5 + O(q^6), q + (zeta6 + 2)*q^2 + (-zeta6 + 3)*q^3 + (3*zeta6 + 3)*q^4 + 4*q^5 + O(q^6) ] @@ -271,7 +291,8 @@ def eisenstein_series(self): sage: M = ModularForms(DirichletGroup(13).0, 1) sage: M.eisenstein_series() [ - -1/13*zeta12^3 + 6/13*zeta12^2 + 4/13*zeta12 + 2/13 + q + (zeta12 + 1)*q^2 + zeta12^2*q^3 + (zeta12^2 + zeta12 + 1)*q^4 + (-zeta12^3 + 1)*q^5 + O(q^6) + -1/13*zeta12^3 + 6/13*zeta12^2 + 4/13*zeta12 + 2/13 + q + (zeta12 + 1)*q^2 + + zeta12^2*q^3 + (zeta12^2 + zeta12 + 1)*q^4 + (-zeta12^3 + 1)*q^5 + O(q^6) ] sage: M = ModularForms(GammaH(15, [4]), 4) @@ -322,9 +343,9 @@ def _compute_q_expansion_basis(self, prec=None, new=False): O(q^6)] sage: EisensteinForms(22,4)._compute_q_expansion_basis(15) [1 + O(q^15), - q + 28*q^3 - 8*q^4 + 126*q^5 + 344*q^7 - 72*q^8 + 757*q^9 - 224*q^12 + 2198*q^13 + O(q^15), - q^2 + 9*q^4 + 28*q^6 + 73*q^8 + 126*q^10 + 252*q^12 + 344*q^14 + O(q^15), - q^11 + O(q^15)] + q + 28*q^3 - 8*q^4 + 126*q^5 + 344*q^7 - 72*q^8 + 757*q^9 - 224*q^12 + 2198*q^13 + O(q^15), + q^2 + 9*q^4 + 28*q^6 + 73*q^8 + 126*q^10 + 252*q^12 + 344*q^14 + O(q^15), + q^11 + O(q^15)] """ if prec is None: prec = self.prec() @@ -543,7 +564,8 @@ class EisensteinSubmodule_eps(EisensteinSubmodule_params): sage: M.eisenstein_series() [ - -1/3*zeta6 - 1/3 + q + (2*zeta6 - 1)*q^2 + q^3 + (-2*zeta6 - 1)*q^4 + (-5*zeta6 + 1)*q^5 + O(q^6), + -1/3*zeta6 - 1/3 + q + (2*zeta6 - 1)*q^2 + q^3 + + (-2*zeta6 - 1)*q^4 + (-5*zeta6 + 1)*q^5 + O(q^6), -1/3*zeta6 - 1/3 + q^3 + O(q^6), q + (-2*zeta6 + 1)*q^2 + (-2*zeta6 - 1)*q^4 + (5*zeta6 - 1)*q^5 + O(q^6), q + (zeta6 + 1)*q^2 + 3*q^3 + (zeta6 + 2)*q^4 + (-zeta6 + 5)*q^5 + O(q^6), @@ -590,8 +612,8 @@ def cyclotomic_restriction(L,K): EXAMPLES:: - sage: L = CyclotomicField(12) ; N = CyclotomicField(33) ; M = CyclotomicField(132) - sage: z, n = sage.modular.modform.eisenstein_submodule.cyclotomic_restriction(L,N) + sage: L = CyclotomicField(12); N = CyclotomicField(33); M = CyclotomicField(132) + sage: z, n = sage.modular.modform.eisenstein_submodule.cyclotomic_restriction(L, N) sage: n 2 @@ -600,11 +622,11 @@ def cyclotomic_restriction(L,K): sage: z(L.0)(M.0) zeta132^11 - sage: z(L.0^3-L.0+1) + sage: z(L.0^3 - L.0 + 1) (zeta33^19 + zeta33^8)*x + 1 - sage: z(L.0^3-L.0+1)(M.0) + sage: z(L.0^3 - L.0 + 1)(M.0) zeta132^33 - zeta132^11 + 1 - sage: z(L.0^3-L.0+1)(M.0) - M(L.0^3-L.0+1) + sage: z(L.0^3 - L.0 + 1)(M.0) - M(L.0^3 - L.0 + 1) 0 """ if not L.has_coerce_map_from(K): @@ -687,7 +709,7 @@ def z(a): EXAMPLES:: - sage: L = CyclotomicField(121) ; K = CyclotomicField(11) + sage: L = CyclotomicField(121); K = CyclotomicField(11) sage: z = sage.modular.modform.eisenstein_submodule.cyclotomic_restriction_tower(L,K) sage: z(L.0) x diff --git a/src/sage/modular/modform/element.py b/src/sage/modular/modform/element.py index 4d2123abab1..fba61a0fdd8 100644 --- a/src/sage/modular/modform/element.py +++ b/src/sage/modular/modform/element.py @@ -35,10 +35,10 @@ from sage.arith.functions import lcm from sage.arith.misc import divisors, moebius, sigma, factor, crt from sage.arith.srange import xsrange -from sage.combinat.integer_vector_weighted import WeightedIntegerVectors from sage.matrix.constructor import Matrix from sage.matrix.constructor import matrix from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.misc.verbose import verbose from sage.modular.dirichlet import DirichletGroup @@ -51,13 +51,15 @@ from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.rings.morphism import RingHomomorphism -from sage.rings.number_field.number_field_morphisms import NumberFieldEmbedding from sage.rings.power_series_ring import PowerSeriesRing from sage.rings.rational_field import QQ from sage.rings.real_mpfr import RealField from sage.structure.element import coercion_model, ModuleElement, Element from sage.structure.richcmp import richcmp, op_NE, op_EQ +lazy_import('sage.combinat.integer_vector_weighted', 'WeightedIntegerVectors') +lazy_import('sage.rings.number_field.number_field_morphisms', 'NumberFieldEmbedding') + import sage.modular.hecke.element as element from . import defaults diff --git a/src/sage/modular/modform/hecke_operator_on_qexp.py b/src/sage/modular/modform/hecke_operator_on_qexp.py index 8601c9fd51e..36e092d8200 100644 --- a/src/sage/modular/modform/hecke_operator_on_qexp.py +++ b/src/sage/modular/modform/hecke_operator_on_qexp.py @@ -14,12 +14,14 @@ from sage.arith.misc import divisors, gcd from sage.matrix.constructor import matrix from sage.matrix.matrix_space import MatrixSpace +from sage.misc.lazy_import import lazy_import from sage.rings.infinity import Infinity from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ -from sage.rings.number_field.number_field import CyclotomicField from sage.rings.power_series_ring_element import is_PowerSeries +lazy_import('sage.rings.number_field.number_field', 'CyclotomicField') + from sage.modular.dirichlet import DirichletGroup, is_DirichletCharacter from .element import is_ModularFormElement diff --git a/src/sage/modular/modform_hecketriangle/abstract_space.py b/src/sage/modular/modform_hecketriangle/abstract_space.py index fcff2fdedae..7df851946dc 100644 --- a/src/sage/modular/modform_hecketriangle/abstract_space.py +++ b/src/sage/modular/modform_hecketriangle/abstract_space.py @@ -18,19 +18,20 @@ from sage.misc.cachefunc import cached_method from sage.modules.free_module_element import is_FreeModuleElement from sage.modules.free_module_element import vector -from sage.rings.imaginary_unit import I from sage.rings.infinity import infinity from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.rings.laurent_series_ring import is_LaurentSeriesRing from sage.rings.polynomial.polynomial_ring import is_PolynomialRing from sage.rings.power_series_ring import is_PowerSeriesRing -from sage.rings.qqbar import AlgebraicField from sage.rings.rational_field import QQ from sage.structure.element import parent from .abstract_ring import FormsRing_abstract +lazy_import('sage.rings.imaginary_unit', 'I') +lazy_import('sage.rings.qqbar', 'QQbar') + class FormsSpace_abstract(FormsRing_abstract): r""" @@ -756,7 +757,7 @@ def aut_factor(self, gamma, t): if (gamma.is_translation()): return ZZ(1) elif (gamma.is_reflection()): - return self._ep * (t/AlgebraicField()(I))**self._weight + return self._ep * (t/QQbar(I))**self._weight else: L = [v for v in gamma.word_S_T()[0]] aut_f = ZZ(1) diff --git a/src/sage/modular/modform_hecketriangle/graded_ring_element.py b/src/sage/modular/modform_hecketriangle/graded_ring_element.py index 92981f2f52e..3d57a5e41b6 100644 --- a/src/sage/modular/modform_hecketriangle/graded_ring_element.py +++ b/src/sage/modular/modform_hecketriangle/graded_ring_element.py @@ -24,12 +24,14 @@ from sage.rings.infinity import infinity from sage.rings.integer_ring import ZZ from sage.rings.laurent_series_ring_element import LaurentSeries -from sage.rings.number_field.number_field import QuadraticField from sage.structure.element import CommutativeAlgebraElement from sage.structure.parent_gens import localvars from sage.structure.richcmp import op_NE, op_EQ from sage.structure.unique_representation import UniqueRepresentation -from sage.symbolic.constants import pi + +lazy_import("sage.functions.log", "exp") +lazy_import("sage.rings.number_field.number_field", "QuadraticField") +lazy_import("sage.symbolic.constants", "pi") from .constructor import rational_type, FormsSpace, FormsRing from .series_constructor import MFSeriesConstructor diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py index 0f9354d901e..63a36fdae8b 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py @@ -17,13 +17,15 @@ # **************************************************************************** from sage.misc.latex import latex +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.misc.cachefunc import cached_method from sage.rings.integer_ring import ZZ from sage.rings.infinity import infinity from sage.rings.cc import CC -from sage.rings.qqbar import AA, QQbar + +lazy_import('sage.rings.qqbar', ['AA', 'QQbar']) from sage.groups.matrix_gps.group_element import MatrixGroupElement_generic from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py index cd51bda2b9d..bee7a47b0b9 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py @@ -27,13 +27,17 @@ from sage.misc.misc_c import prod from sage.rings.infinity import infinity from sage.rings.integer_ring import ZZ -from sage.rings.number_field.number_field import NumberField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.rings.qqbar import AA, AlgebraicField -from sage.rings.universal_cyclotomic_field import E from sage.rings.rational_field import QQ from sage.structure.unique_representation import UniqueRepresentation -from sage.symbolic.constants import pi + +lazy_import("sage.functions.log", "exp") +lazy_import("sage.functions.gamma", "psi1") +lazy_import("sage.functions.trig", "sec") +lazy_import("sage.rings.number_field.number_field", "NumberField") +lazy_import("sage.rings.qqbar", ["AA", "AlgebraicField"]) +lazy_import("sage.rings.universal_cyclotomic_field", "E") +lazy_import("sage.symbolic.constants", "pi") from .hecke_triangle_group_element import HeckeTriangleGroupElement, cyclic_representative, coerce_AA diff --git a/src/sage/modular/modsym/all.py b/src/sage/modular/modsym/all.py index e3bfa152ca7..798a4a7d55f 100644 --- a/src/sage/modular/modsym/all.py +++ b/src/sage/modular/modsym/all.py @@ -1,9 +1,10 @@ +from sage.misc.lazy_import import lazy_import from .element import set_modsym_print_mode from .modsym import ModularSymbols, ModularSymbols_clear_cache -from .heilbronn import HeilbronnCremona, HeilbronnMerel +lazy_import('sage.modular.modsym.heilbronn', ['HeilbronnCremona', 'HeilbronnMerel']) from .p1list import P1List, lift_to_sl2z diff --git a/src/sage/modular/modsym/space.py b/src/sage/modular/modsym/space.py index 9297b4d4313..9cf4bf0796f 100644 --- a/src/sage/modular/modsym/space.py +++ b/src/sage/modular/modsym/space.py @@ -27,6 +27,7 @@ from sage.categories.fields import Fields from sage.matrix.matrix_space import MatrixSpace from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.modules.free_module import EchelonMatrixKey, FreeModule, VectorSpace from sage.modules.free_module_element import FreeModuleElement @@ -46,7 +47,7 @@ from sage.modular.hecke.module import HeckeModule_free_module from sage.modular.modsym.element import ModularSymbolsElement -from . import hecke_operator +lazy_import('sage.modular.modsym', 'hecke_operator') def is_ModularSymbolsSpace(x): diff --git a/src/sage/modular/overconvergent/genus0.py b/src/sage/modular/overconvergent/genus0.py index dc74311e7f4..30e52f242e6 100644 --- a/src/sage/modular/overconvergent/genus0.py +++ b/src/sage/modular/overconvergent/genus0.py @@ -177,25 +177,27 @@ from sage.matrix.matrix_space import MatrixSpace from sage.matrix.special import diagonal_matrix from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.verbose import verbose from sage.modular.arithgroup.all import is_Gamma0, is_Gamma1 from sage.modular.dirichlet import trivial_character from sage.modular.etaproducts import EtaProduct from sage.modular.modform.element import ModularFormElement from sage.modular.modform.hecke_operator_on_qexp import hecke_operator_on_qexp -from sage.modular.modform.j_invariant import j_invariant_qexp from sage.modules.free_module_element import vector from sage.modules.module import Module from sage.rings.big_oh import O from sage.rings.infinity import Infinity from sage.rings.integer_ring import ZZ -from sage.rings.padics.factory import Qp as pAdicField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.power_series_ring import PowerSeriesRing from sage.rings.rational_field import QQ from sage.structure.element import Vector, ModuleElement from sage.structure.richcmp import richcmp +lazy_import('sage.modular.modform.j_invariant', 'j_invariant_qexp') +lazy_import('sage.rings.padics.factory', 'Qp', as_='pAdicField') + from .weightspace import WeightSpace_constructor as WeightSpace, WeightCharacter diff --git a/src/sage/modular/overconvergent/weightspace.py b/src/sage/modular/overconvergent/weightspace.py index e7716b173a6..8f0ecc8b8c0 100644 --- a/src/sage/modular/overconvergent/weightspace.py +++ b/src/sage/modular/overconvergent/weightspace.py @@ -68,18 +68,20 @@ from sage.arith.misc import divisors from sage.categories.sets_cat import Sets from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.modular.dirichlet import DirichletGroup, trivial_character from sage.rings.finite_rings.integer_mod_ring import IntegerModRing from sage.rings.infinity import Infinity from sage.rings.integer_ring import ZZ -from sage.rings.padics.factory import Qp -from sage.rings.padics.padic_generic_element import pAdicGenericElement from sage.rings.padics.precision_error import PrecisionError from sage.rings.rational_field import QQ from sage.structure.element import Element from sage.structure.parent import Parent from sage.structure.richcmp import richcmp +lazy_import('sage.rings.padics.factory', 'Qp') +lazy_import('sage.rings.padics.padic_generic_element', 'pAdicGenericElement') + _wscache = {} def WeightSpace_constructor(p, base_ring=None): diff --git a/src/sage/modular/pollack_stevens/distributions.py b/src/sage/modular/pollack_stevens/distributions.py index 1bb73ceacc9..55a5ec72663 100644 --- a/src/sage/modular/pollack_stevens/distributions.py +++ b/src/sage/modular/pollack_stevens/distributions.py @@ -40,19 +40,21 @@ # http://www.gnu.org/licenses/ #***************************************************************************** +from sage.misc.lazy_import import lazy_import from sage.modules.module import Module from sage.structure.parent import Parent -from sage.rings.padics.factory import ZpCA, QpCR -from sage.rings.padics.padic_generic import pAdicGeneric from sage.rings.rational_field import QQ from sage.rings.integer_ring import ZZ from sage.misc.cachefunc import cached_method from sage.categories.modules import Modules -from sage.modular.pollack_stevens.dist import get_dist_classes # , Dist_long from sage.structure.factory import UniqueFactory import sage.rings.ring as ring +lazy_import('sage.modular.pollack_stevens.dist', 'get_dist_classes') +lazy_import('sage.rings.padics.factory', ['ZpCA', 'QpCR']) +lazy_import('sage.rings.padics.padic_generic', 'pAdicGeneric') + from .sigma0 import _default_adjuster diff --git a/src/sage/modular/pollack_stevens/modsym.py b/src/sage/modular/pollack_stevens/modsym.py index a9ff459a590..78e601189a8 100644 --- a/src/sage/modular/pollack_stevens/modsym.py +++ b/src/sage/modular/pollack_stevens/modsym.py @@ -42,16 +42,18 @@ from sage.arith.misc import next_prime, gcd, kronecker from sage.categories.action import Action from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.verbose import verbose from sage.rings.integer_ring import ZZ -from sage.rings.padics.factory import Qp -from sage.rings.padics.padic_generic import pAdicGeneric from sage.rings.padics.precision_error import PrecisionError from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational_field import QQ from sage.structure.element import ModuleElement from sage.structure.richcmp import op_EQ, op_NE +lazy_import('sage.rings.padics.factory', 'Qp') +lazy_import('sage.rings.padics.padic_generic', 'pAdicGeneric') + from .manin_map import ManinMap from .sigma0 import Sigma0 from .fund_domain import M2Z diff --git a/src/sage/modular/pollack_stevens/padic_lseries.py b/src/sage/modular/pollack_stevens/padic_lseries.py index 0692e81aef3..396a96af90e 100644 --- a/src/sage/modular/pollack_stevens/padic_lseries.py +++ b/src/sage/modular/pollack_stevens/padic_lseries.py @@ -21,13 +21,15 @@ # **************************************************************************** from sage.arith.misc import kronecker, binomial +from sage.misc.lazy_import import lazy_import from sage.rings.integer_ring import ZZ -from sage.rings.padics.factory import Qp as pAdicField from sage.rings.padics.precision_error import PrecisionError from sage.rings.power_series_ring import PowerSeriesRing from sage.rings.rational_field import QQ from sage.structure.sage_object import SageObject +lazy_import('sage.rings.padics.factory', 'Qp', as_='pAdicField') + class pAdicLseries(SageObject): r""" From 555b2fdd8b54b53ca7281e248ad02cd95c9edd01 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 30 Jan 2023 23:58:02 -0800 Subject: [PATCH 12/20] src/sage/modular/dirichlet.py: Fix import --- src/sage/modular/dirichlet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/modular/dirichlet.py b/src/sage/modular/dirichlet.py index f20345cfb2d..2bfa8e8a7fb 100644 --- a/src/sage/modular/dirichlet.py +++ b/src/sage/modular/dirichlet.py @@ -62,7 +62,7 @@ import sage.rings.abc from sage.arith.functions import lcm -from sage.arith.misc import bernoulli, kronecker, factor, gcd, fundamental_discriminant, euler_phi, valuation +from sage.arith.misc import bernoulli, binomial, factorial, kronecker, factor, gcd, fundamental_discriminant, euler_phi, valuation from sage.categories.map import Map from sage.categories.objects import Objects from sage.misc.cachefunc import cached_method From b980bc0a27e30b98412c02e25fc15e29a7e910b6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 3 Jul 2023 17:11:28 -0700 Subject: [PATCH 13/20] src/sage/modular/modform_hecketriangle/abstract_space.py: Fix up import --- src/sage/modular/modform_hecketriangle/abstract_space.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/modular/modform_hecketriangle/abstract_space.py b/src/sage/modular/modform_hecketriangle/abstract_space.py index 7df851946dc..110b0fe3be7 100644 --- a/src/sage/modular/modform_hecketriangle/abstract_space.py +++ b/src/sage/modular/modform_hecketriangle/abstract_space.py @@ -16,6 +16,7 @@ # **************************************************************************** from sage.matrix.constructor import matrix from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.modules.free_module_element import is_FreeModuleElement from sage.modules.free_module_element import vector from sage.rings.infinity import infinity From 3dcafb7ac844236c6eecb163076e866a37d4af7b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 3 Jul 2023 19:22:48 -0700 Subject: [PATCH 14/20] src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py: Fix up imports --- .../modular/modform_hecketriangle/hecke_triangle_groups.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py index bee7a47b0b9..a5e72e0eaa0 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py @@ -17,13 +17,11 @@ # **************************************************************************** from sage.arith.misc import divisors -from sage.functions.gamma import psi1 -from sage.functions.log import exp -from sage.functions.trig import sec from sage.groups.matrix_gps.finitely_generated import FinitelyGeneratedMatrixGroup_generic from sage.matrix.constructor import matrix from sage.misc.cachefunc import cached_method from sage.misc.latex import latex +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.rings.infinity import infinity from sage.rings.integer_ring import ZZ From d5508dfec919bf9e77835109b10f129d879b3a54 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 3 Jul 2023 22:22:06 -0700 Subject: [PATCH 15/20] src/sage/modular/modform_hecketriangle/graded_ring_element.py: Fix up --- src/sage/modular/modform_hecketriangle/graded_ring_element.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/modular/modform_hecketriangle/graded_ring_element.py b/src/sage/modular/modform_hecketriangle/graded_ring_element.py index 3d57a5e41b6..a2ef2a03b04 100644 --- a/src/sage/modular/modform_hecketriangle/graded_ring_element.py +++ b/src/sage/modular/modform_hecketriangle/graded_ring_element.py @@ -19,6 +19,7 @@ from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane from sage.misc.cachefunc import cached_method from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass +from sage.misc.lazy_import import lazy_import from sage.modules.free_module_element import vector from sage.rings.big_oh import O from sage.rings.infinity import infinity From fdb6c66d89b3d2bbf5fd1252abf423d4007430b1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 7 Jul 2023 05:46:51 -0700 Subject: [PATCH 16/20] src/sage/modular/abvar/finite_subgroup.py: Add missing import --- src/sage/modular/abvar/finite_subgroup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sage/modular/abvar/finite_subgroup.py b/src/sage/modular/abvar/finite_subgroup.py index 3d459ab124c..f3381145d86 100644 --- a/src/sage/modular/abvar/finite_subgroup.py +++ b/src/sage/modular/abvar/finite_subgroup.py @@ -97,6 +97,8 @@ # http://www.gnu.org/licenses/ #***************************************************************************** +import sage.rings.abc + from sage.misc.lazy_import import lazy_import from sage.modular.abvar.torsion_point import TorsionPoint from sage.modules.module import Module From 999d1062b61859059f677030fe26dbd022b54ac2 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 7 Jul 2023 06:12:15 -0700 Subject: [PATCH 17/20] sage.modular: Work around lazy_import limitations --- src/sage/modular/abvar/abvar.py | 7 +++---- src/sage/modular/abvar/finite_subgroup.py | 6 +++--- src/sage/modular/arithgroup/arithgroup_generic.py | 11 ++++++----- .../hecke_triangle_group_element.py | 4 +++- src/sage/modular/modsym/heilbronn.pyx | 5 ++++- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/sage/modular/abvar/abvar.py b/src/sage/modular/abvar/abvar.py index 818268b72fe..7f59627139a 100644 --- a/src/sage/modular/abvar/abvar.py +++ b/src/sage/modular/abvar/abvar.py @@ -67,7 +67,6 @@ lazy_import('sage.databases.cremona', ['cremona_letter_code', 'CremonaDatabase']) -lazy_import('sage.rings.qqbar', 'QQbar') from . import homspace @@ -802,7 +801,7 @@ def _Hom_(self, B, cat=None): if K == L: F = K elif isinstance(K, sage.rings.abc.AlgebraicField) or isinstance(L, sage.rings.abc.AlgebraicField): - F = QQbar + from sage.rings.qqbar import QQbar as F else: # TODO -- improve this raise ValueError("please specify a category") @@ -1000,7 +999,7 @@ def intersection(self, other): for v in V.coordinate_module(S).basis()] if A.dimension() > 0: - finitegroup_base_field = QQbar + from sage.rings.qqbar import QQbar as finitegroup_base_field else: finitegroup_base_field = self.base_field() G = self.finite_subgroup(gens, field_of_definition=finitegroup_base_field) @@ -3129,7 +3128,7 @@ def finite_subgroup(self, X, field_of_definition=None, check=True): raise ValueError("X must be a subgroup of self.") if field_of_definition is None: - field_of_definition = QQbar + from sage.rings.qqbar import QQbar as field_of_definition return FiniteSubgroup_lattice( self, X, field_of_definition=field_of_definition, check=check) diff --git a/src/sage/modular/abvar/finite_subgroup.py b/src/sage/modular/abvar/finite_subgroup.py index f3381145d86..ec76a0f5e26 100644 --- a/src/sage/modular/abvar/finite_subgroup.py +++ b/src/sage/modular/abvar/finite_subgroup.py @@ -113,8 +113,6 @@ from sage.misc.misc_c import prod from sage.structure.element import coercion_model -lazy_import('sage.rings.qqbar', 'QQbar') - @richcmp_method class FiniteSubgroup(Module): @@ -754,6 +752,8 @@ def subgroup(self, gens): sage: H == G.subgroup([[1/11,0,0,0]]) True """ + from sage.rings.qqbar import QQbar + if not isinstance(gens, (tuple, list)): raise TypeError("gens must be a list or tuple") A = self.abelian_variety() @@ -846,7 +846,7 @@ def __init__(self, abvar, lattice, field_of_definition=None, check=True): Finite subgroup with invariants [15] over QQbar of Abelian variety J0(11) of dimension 1 """ if field_of_definition is None: - field_of_definition = QQbar + from sage.rings.qqbar import QQbar as field_of_definition if check: from .abvar import is_ModularAbelianVariety if not is_FreeModule(lattice) or lattice.base_ring() != ZZ: diff --git a/src/sage/modular/arithgroup/arithgroup_generic.py b/src/sage/modular/arithgroup/arithgroup_generic.py index 892c8de62d2..844d8db7165 100644 --- a/src/sage/modular/arithgroup/arithgroup_generic.py +++ b/src/sage/modular/arithgroup/arithgroup_generic.py @@ -885,12 +885,12 @@ def index(self): def generalised_level(self): r""" - Return the generalised level of self, i.e. the least common multiple of + Return the generalised level of ``self``, i.e., the least common multiple of the widths of all cusps. - If self is *even*, Wohlfart's theorem tells us that this is equal to - the (conventional) level of self when self is a congruence subgroup. - This can fail if self is odd, but the actual level is at most twice the + If ``self`` is *even*, Wohlfart's theorem tells us that this is equal to + the (conventional) level of ``self`` when ``self`` is a congruence subgroup. + This can fail if ``self`` is odd, but the actual level is at most twice the generalised level. See the paper by Kiming, Schuett and Verrill for more examples. @@ -898,7 +898,8 @@ def generalised_level(self): sage: Gamma0(18).generalised_level() 18 - sage: sage.modular.arithgroup.arithgroup_perm.HsuExample18().generalised_level() + sage: from sage.modular.arithgroup.arithgroup_perm import HsuExample18 + sage: HsuExample18().generalised_level() 24 In the following example, the actual level is twice the generalised diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py index 63a36fdae8b..7c3867923c9 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py @@ -25,7 +25,7 @@ from sage.rings.infinity import infinity from sage.rings.cc import CC -lazy_import('sage.rings.qqbar', ['AA', 'QQbar']) +lazy_import('sage.rings.qqbar', 'AA') from sage.groups.matrix_gps.group_element import MatrixGroupElement_generic from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane @@ -774,6 +774,8 @@ def _primitive_block_decomposition_data(self): if self.parent().n() == infinity: raise NotImplementedError + from sage.rings.qqbar import QQbar + emb = self.root_extension_embedding(QQbar) p = self.fixed_points()[0] embp = emb(p) diff --git a/src/sage/modular/modsym/heilbronn.pyx b/src/sage/modular/modsym/heilbronn.pyx index e6e63f1bbcb..45f0921034d 100644 --- a/src/sage/modular/modsym/heilbronn.pyx +++ b/src/sage/modular/modsym/heilbronn.pyx @@ -111,7 +111,8 @@ cdef class Heilbronn: EXAMPLES:: - sage: H = sage.modular.modsym.heilbronn.Heilbronn() + sage: from sage.modular.modsym.heilbronn import Heilbronn + sage: H = Heilbronn() sage: H._initialize_list() Traceback (most recent call last): ... @@ -343,6 +344,7 @@ cdef class HeilbronnCremona(Heilbronn): EXAMPLES:: + sage: from sage.modular.modsym.heilbronn import HeilbronnCremona sage: H = HeilbronnCremona.__new__(HeilbronnCremona) sage: H.p = 5 sage: H @@ -457,6 +459,7 @@ cdef class HeilbronnMerel(Heilbronn): EXAMPLES:: + sage: from sage.modular.modsym.heilbronn import HeilbronnMerel sage: H = HeilbronnMerel.__new__(HeilbronnMerel) sage: H.n = 5 sage: H From 1fe5d3807cecd88b866628ca43f51bd0c38b893d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 21 Jul 2023 14:42:09 -0700 Subject: [PATCH 18/20] git grep -l 'from sage.matrix.constructor import Matrix as matrix' | xargs sed -i.bak 's/from sage.matrix.constructor import Matrix as matrix/from sage.matrix.constructor import matrix/' --- src/sage/modules/vector_space_homspace.py | 2 +- src/sage/numerical/interactive_simplex_method.py | 2 +- src/sage/rings/number_field/number_field_ideal.py | 2 +- src/sage/schemes/elliptic_curves/ell_tate_curve.py | 2 +- src/sage/schemes/elliptic_curves/heegner.py | 2 +- src/sage/schemes/elliptic_curves/padic_lseries.py | 2 +- src/sage/schemes/elliptic_curves/padics.py | 2 +- src/sage/schemes/toric/library.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sage/modules/vector_space_homspace.py b/src/sage/modules/vector_space_homspace.py index 48d195a7608..c15f0f59285 100644 --- a/src/sage/modules/vector_space_homspace.py +++ b/src/sage/modules/vector_space_homspace.py @@ -191,7 +191,7 @@ # http://www.gnu.org/licenses/ #################################################################################### -from sage.matrix.constructor import Matrix as matrix +from sage.matrix.constructor import matrix import sage.modules.free_module_homspace # This module initially overrides just the minimum functionality necessary diff --git a/src/sage/numerical/interactive_simplex_method.py b/src/sage/numerical/interactive_simplex_method.py index ba0adb60481..ae9e43383e4 100644 --- a/src/sage/numerical/interactive_simplex_method.py +++ b/src/sage/numerical/interactive_simplex_method.py @@ -185,7 +185,7 @@ from sage.geometry.polyhedron.constructor import Polyhedron from sage.matrix.special import column_matrix from sage.matrix.special import identity_matrix -from sage.matrix.constructor import Matrix as matrix +from sage.matrix.constructor import matrix from sage.matrix.special import random_matrix from sage.misc.latex import LatexExpr, latex from sage.misc.cachefunc import cached_function, cached_method diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py index 7a4b3b2debc..92f6a16ca48 100644 --- a/src/sage/rings/number_field/number_field_ideal.py +++ b/src/sage/rings/number_field/number_field_ideal.py @@ -2757,7 +2757,7 @@ def ideallog(self, x, gens=None, check=True): G = self.idealstar(2) invs = G.invariants() - from sage.matrix.constructor import Matrix as matrix + from sage.matrix.constructor import matrix from sage.matrix.special import identity_matrix from sage.matrix.special import zero_matrix from sage.matrix.special import diagonal_matrix diff --git a/src/sage/schemes/elliptic_curves/ell_tate_curve.py b/src/sage/schemes/elliptic_curves/ell_tate_curve.py index 631f1ba97ac..c69acf6c155 100644 --- a/src/sage/schemes/elliptic_curves/ell_tate_curve.py +++ b/src/sage/schemes/elliptic_curves/ell_tate_curve.py @@ -50,7 +50,7 @@ from sage.functions.log import log from sage.misc.functional import denominator from sage.misc.misc_c import prod -from sage.matrix.constructor import Matrix as matrix +from sage.matrix.constructor import matrix @richcmp_method diff --git a/src/sage/schemes/elliptic_curves/heegner.py b/src/sage/schemes/elliptic_curves/heegner.py index 3f916aed997..8811fa2f228 100644 --- a/src/sage/schemes/elliptic_curves/heegner.py +++ b/src/sage/schemes/elliptic_curves/heegner.py @@ -109,7 +109,7 @@ from sage.arith.functions import lcm from sage.arith.misc import (binomial, factorial, prime_divisors, GCD as gcd, XGCD as xgcd) -from sage.matrix.constructor import Matrix as matrix +from sage.matrix.constructor import matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.cachefunc import cached_method from sage.misc.misc_c import prod diff --git a/src/sage/schemes/elliptic_curves/padic_lseries.py b/src/sage/schemes/elliptic_curves/padic_lseries.py index b4221da5823..23c7519ca0b 100644 --- a/src/sage/schemes/elliptic_curves/padic_lseries.py +++ b/src/sage/schemes/elliptic_curves/padic_lseries.py @@ -61,7 +61,7 @@ # https://www.gnu.org/licenses/ ###################################################################### -from sage.matrix.constructor import Matrix as matrix +from sage.matrix.constructor import matrix import sage.schemes.hyperelliptic_curves.monsky_washnitzer from sage.arith.functions import lcm as LCM diff --git a/src/sage/schemes/elliptic_curves/padics.py b/src/sage/schemes/elliptic_curves/padics.py index b9bb640e0ad..51f7cc3db90 100644 --- a/src/sage/schemes/elliptic_curves/padics.py +++ b/src/sage/schemes/elliptic_curves/padics.py @@ -25,7 +25,7 @@ from sage.arith.functions import lcm as LCM from sage.arith.misc import valuation -from sage.matrix.constructor import Matrix as matrix +from sage.matrix.constructor import matrix from sage.misc.misc import newton_method_sizes from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF from sage.rings.padics.factory import Qp as pAdicField diff --git a/src/sage/schemes/toric/library.py b/src/sage/schemes/toric/library.py index e4344334d81..309b62e05c1 100644 --- a/src/sage/schemes/toric/library.py +++ b/src/sage/schemes/toric/library.py @@ -40,7 +40,7 @@ from sage.structure.sage_object import SageObject -from sage.matrix.constructor import Matrix as matrix +from sage.matrix.constructor import matrix from sage.matrix.special import identity_matrix from sage.geometry.fan import Fan from sage.geometry.lattice_polytope import LatticePolytope From 5a6d6bd2a06b705a804c36a9bbbf369f2319d254 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 22 Jul 2023 10:43:23 -0700 Subject: [PATCH 19/20] src/.relint.yml: Use the same filePattern for namespace_pkg_all_import* --- src/.relint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.relint.yml b/src/.relint.yml index 9ed75b17b14..97bf2ac1dbc 100644 --- a/src/.relint.yml +++ b/src/.relint.yml @@ -51,7 +51,7 @@ # Keep in sync with SAGE_ROOT/src/sage/misc/replace_dot_all.py pattern: 'from\s+sage(|[.](arith|categories|combinat|crypto|databases|data_structures|dynamics|ext|game_theory|games|geometry|graphs|groups|interfaces|manifolds|matrix|matroids|misc|modules|monoids|numerical|probability|quadratic_forms|quivers|rings|sat|schemes|sets|stats|symbolic|tensor)[a-z0-9_.]*|[.]libs)[.]all\s+import' # imports from .all are allowed in all.py; also allow in some modules that need sage.all - filePattern: '(.*/|)(?!(all|benchmark|dev_tools|parsing|sage_eval))[^/.]*[.](py|pyx|pxi)$' + filePattern: '(.*/|)(?!(all|benchmark|dev_tools|parsing|sage_eval|explain_pickle|.*_test))[^/.]*[.](py|pyx|pxi)$' - name: 'namespace_pkg_all_import_2: Module-level import of .all of a namespace package' hint: | From 299ae874a6df76b577dca6e62ac4266c089ec743 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 22 Jul 2023 10:48:08 -0700 Subject: [PATCH 20/20] src/sage/misc/replace_dot_all.py: Remove redundant definition of excluded_file_regex --- src/sage/misc/replace_dot_all.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sage/misc/replace_dot_all.py b/src/sage/misc/replace_dot_all.py index 46462ca7c2c..8272ec5af6c 100644 --- a/src/sage/misc/replace_dot_all.py +++ b/src/sage/misc/replace_dot_all.py @@ -385,9 +385,6 @@ def make_replacements_in_file(location, package_regex=None, verbose=False, outpu write_file.write(replaced_content) # overwriting the old file contents with the new/replaced content -excluded_file_regex = 'auto-methods|replace_dot_all' - - def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex=None, verbose=False, *, excluded_file_regex=r'auto-methods|replace_dot_all'): r"""