Skip to content

Commit

Permalink
Trac #34191: Remove imports from sage.rings.all in sage.modular
Browse files Browse the repository at this point in the history
Part of Meta-ticket #34201: Replace imports from sage.*.all for
namespace packages

Also clean up some other outdated importing practices.

URL: https://trac.sagemath.org/34191
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): David Ayotte
  • Loading branch information
Release Manager committed Aug 30, 2022
2 parents c21365e + f76fe41 commit 9cafd35
Show file tree
Hide file tree
Showing 63 changed files with 627 additions and 509 deletions.
64 changes: 35 additions & 29 deletions src/sage/modular/abvar/abvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,53 @@
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************

from copy import copy
from random import randrange

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
from sage.matrix.constructor import matrix
from sage.matrix.special import block_diagonal_matrix, identity_matrix
from sage.misc.lazy_import import lazy_import

from sage.categories.all import ModularAbelianVarieties
from sage.structure.sequence import Sequence, Sequence_generic
from sage.structure.richcmp import (richcmp_method, richcmp_not_equal,
rich_to_bool)
from sage.structure.parent import Parent
from .morphism import HeckeOperator, Morphism, DegeneracyMap
from .torsion_subgroup import RationalTorsionSubgroup, QQbarTorsionSubgroup
from .finite_subgroup import (FiniteSubgroup_lattice, FiniteSubgroup,
TorsionPoint)
from .cuspidal_subgroup import (CuspidalSubgroup, RationalCuspidalSubgroup,
RationalCuspSubgroup)
from sage.rings.all import ZZ, QQ, QQbar, Integer
from sage.arith.all import LCM, divisors, prime_range, next_prime
from sage.rings.ring import is_Ring
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.infinity import infinity
from sage.modules.free_module import is_FreeModule
from sage.modular.arithgroup.all import (is_CongruenceSubgroup, is_Gamma0,
is_Gamma1, is_GammaH)
from sage.modular.modsym.all import ModularSymbols
from sage.modular.modsym.space import ModularSymbolsSpace
from sage.misc.misc_c import prod
from sage.modular.arithgroup.congroup_gamma0 import is_Gamma0
from sage.modular.arithgroup.congroup_gamma1 import is_Gamma1
from sage.modular.arithgroup.congroup_gammaH import is_GammaH
from sage.modular.arithgroup.congroup_generic import is_CongruenceSubgroup
from sage.modular.modform.constructor import Newform
from sage.matrix.all import matrix, block_diagonal_matrix, identity_matrix
from sage.modular.modsym.modsym import ModularSymbols
from sage.modular.modsym.space import ModularSymbolsSpace
from sage.modular.quatalg.brandt import BrandtModule
from sage.modules.free_module import is_FreeModule
from sage.modules.free_module_element import vector
from sage.misc.misc_c import prod
from sage.arith.misc import is_prime
from sage.rings.fast_arith import prime_range
from sage.rings.infinity import infinity
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
from sage.sets.primes import Primes

from . import homspace
from . import lseries
from sage.structure.parent import Parent
from sage.structure.richcmp import richcmp_method, richcmp_not_equal, rich_to_bool
from sage.structure.sequence import Sequence, Sequence_generic

lazy_import('sage.databases.cremona',
['cremona_letter_code', 'CremonaDatabase'])

from . import homspace
from . import lseries
from .morphism import HeckeOperator, Morphism, DegeneracyMap
from .torsion_subgroup import RationalTorsionSubgroup, QQbarTorsionSubgroup
from .finite_subgroup import (FiniteSubgroup_lattice, FiniteSubgroup,
TorsionPoint)
from .cuspidal_subgroup import (CuspidalSubgroup, RationalCuspidalSubgroup,
RationalCuspSubgroup)


def is_ModularAbelianVariety(x) -> bool:
"""
Expand Down Expand Up @@ -4929,7 +4936,6 @@ def brandt_module(self, p):
if self.level().valuation(p) != 1:
raise ValueError("p must exactly divide the level")
M = self.level() / p
from sage.modular.all import BrandtModule
V = BrandtModule(p, M)
# now cut out version of self in B
S = self.modular_symbols(sign=1)
Expand Down
9 changes: 6 additions & 3 deletions src/sage/modular/abvar/cuspidal_subgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from .finite_subgroup import FiniteSubgroup
from sage.rings.all import infinity, QQ, ZZ
from sage.matrix.all import matrix
from sage.matrix.constructor import matrix
from sage.modular.arithgroup.all import is_Gamma0
from sage.modular.cusps import Cusp
from sage.rings.infinity import infinity
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ

from .finite_subgroup import FiniteSubgroup


class CuspidalSubgroup_generic(FiniteSubgroup):
Expand Down
7 changes: 5 additions & 2 deletions src/sage/modular/abvar/finite_subgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@
from sage.structure.gens_py import abelian_iterator
from sage.structure.sequence import Sequence
from sage.structure.richcmp import richcmp_method, richcmp
from sage.rings.all import QQ, ZZ, QQbar, Integer
from sage.arith.all import lcm
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

Expand Down
7 changes: 5 additions & 2 deletions src/sage/modular/abvar/homology.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.modular.hecke.module import HeckeModule_free_module
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.ring import CommutativeRing
from sage.structure.richcmp import richcmp_method, richcmp, richcmp_not_equal
from sage.modular.hecke.all import HeckeModule_free_module
from sage.rings.all import Integer, ZZ, QQ, CommutativeRing

# TODO: we will probably also need homology that is *not* a Hecke module.

Expand Down
21 changes: 12 additions & 9 deletions src/sage/modular/abvar/torsion_subgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,19 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from sage.structure.richcmp import richcmp_method, richcmp
from sage.arith.misc import divisors, gcd
from sage.misc.misc_c import prod
from sage.modular.abvar.torsion_point import TorsionPoint
from sage.modules.module import Module
from .finite_subgroup import FiniteSubgroup
from sage.rings.all import ZZ, QQ
from sage.sets.primes import Primes
from sage.modular.arithgroup.all import is_Gamma0, is_Gamma1
from sage.all import divisors, gcd, prime_range
from sage.modular.dirichlet import DirichletGroup
from sage.misc.misc_c import prod
from sage.modular.arithgroup.all import is_Gamma0, is_Gamma1
from sage.modular.dirichlet import DirichletGroup
from sage.modules.module import Module
from sage.rings.fast_arith import prime_range
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.sets.primes import Primes
from sage.structure.richcmp import richcmp_method, richcmp

from .finite_subgroup import FiniteSubgroup


@richcmp_method
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/arithgroup/arithgroup_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sage.groups.old import Group
from sage.categories.groups import Groups
from sage.rings.integer_ring import ZZ
from sage.arith.all import lcm
from sage.arith.functions import lcm
from sage.misc.cachefunc import cached_method
from copy import copy # for making copies of lists of cusps
from sage.modular.modsym.p1list import lift_to_sl2z
Expand Down
25 changes: 12 additions & 13 deletions src/sage/modular/arithgroup/arithgroup_perm.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,18 @@
#
################################################################################

from sage.arith.functions import lcm
from sage.arith.misc import CRT_basis
from sage.groups.perm_gps.constructor import PermutationGroupElement as PermutationConstructor
from sage.groups.perm_gps.permgroup import PermutationGroup
from sage.groups.perm_gps.permgroup_element import PermutationGroupElement
from sage.misc.cachefunc import cached_method
from sage.misc.misc_c import prod
from sage.rings.integer_ring import ZZ

from .all import SL2Z
from .arithgroup_generic import ArithmeticSubgroup
from sage.rings.integer_ring import ZZ
from sage.misc.cachefunc import cached_method
import sage.arith.all as arith

from sage.groups.perm_gps.permgroup_element import PermutationGroupElement
from sage.groups.perm_gps.constructor import PermutationGroupElement as PermutationConstructor

Idm = SL2Z([1,0,0,1]) # identity

Expand Down Expand Up @@ -206,8 +210,7 @@ def eval_sl2z_word(w):
[ 66 -59]
[ 47 -42]
"""
from sage.all import prod
mat = [Lm,Rm]
mat = [Lm, Rm]
w0 = Idm
w1 = w
return w0 * prod((mat[a[0]]**a[1] for a in w1), Idm)
Expand Down Expand Up @@ -243,7 +246,6 @@ def word_of_perms(w, p1, p2):
G = G2
p1 = G(p1)
else:
from sage.groups.perm_gps.all import PermutationGroup
G = PermutationGroup([p1,p2])
p1 = G(p1)
p2 = G(p2)
Expand Down Expand Up @@ -431,8 +433,6 @@ def ArithmeticSubgroup_Permutation(

# Check transitivity. This is the most expensive check, so we do it
# last.
from sage.groups.perm_gps.all import PermutationGroup

G = PermutationGroup(gens)
if not G.is_transitive():
raise ValueError("Permutations do not generate a transitive group")
Expand Down Expand Up @@ -676,7 +676,6 @@ def perm_group(self):
sage: ap.HsuExample10().perm_group()
Permutation Group with generators [(1,2)(3,4)(5,6)(7,8)(9,10), (1,8,3)(2,4,6)(5,7,10), (1,4)(2,5,9,10,8)(3,7,6), (1,7,9,10,6)(2,3)(4,5,8)]
"""
from sage.groups.perm_gps.all import PermutationGroup
# we set canonicalize to False as otherwise PermutationGroup changes the
# order of the generators.
return PermutationGroup([self.S2(), self.S3(), self.L(), self.R()], canonicalize=False)
Expand Down Expand Up @@ -1288,7 +1287,7 @@ def generalised_level(self):
sage: G.generalised_level()
3
"""
return arith.lcm(self.cusp_widths())
return lcm(self.cusp_widths())

def congruence_closure(self):
r"""
Expand Down Expand Up @@ -1477,7 +1476,7 @@ def is_congruence(self):
# e>1, m>1
onehalf = ZZ(2).inverse_mod(m) # i.e. 2^(-1) mod m
onefifth = ZZ(5).inverse_mod(e) # i.e. 5^(-1) mod e
c,d = arith.CRT_basis([m, e])
c, d = CRT_basis([m, e])
# c=0 mod e, c=1 mod m; d=1 mod e, d=0 mod m
a = L**c
b = R**c
Expand Down
13 changes: 8 additions & 5 deletions src/sage/modular/arithgroup/congroup_gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from .congroup_generic import CongruenceSubgroup
from sage.misc.misc_c import prod
from sage.rings.all import ZZ, Zmod, QQ
from sage.rings.integer import GCD_list
from sage.arith.misc import gcd
from sage.groups.matrix_gps.finitely_generated import MatrixGroup
from sage.matrix.constructor import matrix
from sage.misc.misc_c import prod
from sage.modular.cusps import Cusp
from sage.arith.all import gcd
from sage.rings.finite_rings.integer_mod_ring import Zmod
from sage.rings.integer import GCD_list
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.structure.richcmp import richcmp_method, richcmp

from .congroup_generic import CongruenceSubgroup
from .congroup_sl2z import SL2Z


_gamma_cache = {}
def Gamma_constructor(N):
r"""
Expand Down
33 changes: 15 additions & 18 deletions src/sage/modular/arithgroup/congroup_gamma0.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from .congroup_gammaH import GammaH_class
from .congroup_gamma1 import is_Gamma1
from sage.modular.modsym.p1list import lift_to_sl2z
from .congroup_generic import CongruenceSubgroup

from sage.modular.cusps import Cusp
from sage.arith.misc import kronecker_symbol, divisors, euler_phi, gcd, moebius
from sage.misc.cachefunc import cached_method
from sage.rings.all import IntegerModRing, ZZ
from sage.arith.all import kronecker_symbol
from sage.misc.misc_c import prod
import sage.modular.modsym.p1list
import sage.arith.all as arith
from sage.modular.cusps import Cusp
from sage.modular.modsym.p1list import lift_to_sl2z, P1List
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
from sage.rings.integer_ring import ZZ

from .congroup_gamma1 import is_Gamma1
from .congroup_gammaH import GammaH_class
from .congroup_generic import CongruenceSubgroup


def is_Gamma0(x):
Expand Down Expand Up @@ -211,7 +210,6 @@ def _list_of_elements_in_H(self):
"""
N = self.level()
if N != 1:
gcd = arith.gcd
H = [x for x in range(1, N) if gcd(x, N) == 1]
else:
H = [1]
Expand Down Expand Up @@ -321,7 +319,7 @@ def coset_reps(self):
if N == 1: # P1List isn't very happy working modulo 1
yield SL2Z([1,0,0,1])
else:
for z in sage.modular.modsym.p1list.P1List(N):
for z in P1List(N):
yield SL2Z(lift_to_sl2z(z[0], z[1], N))

@cached_method
Expand Down Expand Up @@ -455,8 +453,8 @@ def _find_cusps(self):
N = self.level()
s = []

for d in arith.divisors(N):
w = arith.gcd(d, N//d)
for d in divisors(N):
w = gcd(d, N//d)
if w == 1:
if d == 1:
s.append(Cusp(1,0))
Expand All @@ -466,8 +464,8 @@ def _find_cusps(self):
s.append(Cusp(1,d))
else:
for a in range(1, w):
if arith.gcd(a, w) == 1:
while arith.gcd(a, d//w) != 1:
if gcd(a, w) == 1:
while gcd(a, d//w) != 1:
a += w
s.append(Cusp(a,d))
return sorted(s)
Expand All @@ -484,7 +482,7 @@ def ncusps(self):
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
"""
n = self.level()
return sum([arith.euler_phi(arith.gcd(d,n//d)) for d in n.divisors()])
return sum([euler_phi(gcd(d,n//d)) for d in n.divisors()])


def nu2(self):
Expand Down Expand Up @@ -595,7 +593,6 @@ def dimension_new_cusp_forms(self, k=2, p=0):
sage: all(Gamma0(N).dimension_new_cusp_forms(2)==100 for N in L)
True
"""
from sage.arith.all import moebius
from sage.functions.other import floor

N = self.level()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/arithgroup/congroup_gamma1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sage.misc.misc_c import prod
from .congroup_gammaH import GammaH_class, is_GammaH, GammaH_constructor
from sage.rings.integer_ring import ZZ
from sage.arith.all import euler_phi as phi, moebius, divisors
from sage.arith.misc import euler_phi as phi, moebius, divisors
from sage.modular.dirichlet import DirichletGroup


Expand Down
3 changes: 2 additions & 1 deletion src/sage/modular/arithgroup/congroup_gammaH.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#
################################################################################

from sage.arith.all import euler_phi, lcm, gcd, divisors, get_inverse_mod, get_gcd, factor, xgcd
from sage.arith.functions import lcm
from sage.arith.misc import euler_phi, gcd, divisors, get_inverse_mod, get_gcd, factor, xgcd
from sage.modular.modsym.p1list import lift_to_sl2z
from .congroup_generic import CongruenceSubgroup
from sage.modular.cusps import Cusp
Expand Down
Loading

0 comments on commit 9cafd35

Please sign in to comment.