Skip to content

Commit 829da8c

Browse files
author
Release Manager
committed
gh-36917: `sage.rings`: Modularization fixes <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> Standard modularization changes: - Using more lazy imports, more specific imports and similar - Some try... except for imports of element implementations - `# needs` - incidental doctest cosmetics <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> This is: - Cherry-picked from #35095 <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36917 Reported by: Matthias Köppe Reviewer(s): David Coudert
2 parents 9f286eb + 9dc050d commit 829da8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+573
-368
lines changed

src/sage/calculus/test_sympy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
<class 'sage.symbolic.expression.Expression'>
157157
sage: t1, t2
158158
(omega + x, omega + x)
159-
sage: e = sympy.sin(var("y"))+sage.all.cos(sympy.Symbol("x"))
159+
sage: e = sympy.sin(var("y")) + sage.functions.trig.cos(sympy.Symbol("x"))
160160
sage: type(e)
161161
<class 'sympy.core.add.Add'>
162162
sage: e
@@ -166,7 +166,7 @@
166166
<class 'sage.symbolic.expression.Expression'>
167167
sage: e
168168
cos(x) + sin(y)
169-
sage: e = sage.all.cos(var("y")**3)**4+var("x")**2
169+
sage: e = sage.functions.trig.cos(var("y")**3)**4+var("x")**2
170170
sage: e = e._sympy_()
171171
sage: e
172172
x**2 + cos(y**3)**4

src/sage/ext/fast_callable.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ def function_name(fn):
576576
Given a function, return a string giving a name for the function.
577577
578578
For functions we recognize, we use our standard opcode name for the
579-
function (so operator.add becomes 'add', and sage.all.sin becomes 'sin').
579+
function (so :func:`operator.add` becomes ``'add'``, and :func:`sage.functions.trig.sin`
580+
becomes ``'sin'``).
580581
581582
For functions we don't recognize, we try to come up with a name,
582583
but the name will be wrapped in braces; this is a signal that

src/sage/groups/generic.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@
117117

118118
from copy import copy
119119

120+
from sage.arith.misc import integer_ceil, integer_floor, xlcm
121+
from sage.arith.srange import xsrange
122+
from sage.misc.functional import log
120123
from sage.misc.misc_c import prod
121124
import sage.rings.integer_ring as integer_ring
122125
import sage.rings.integer
123-
from sage.arith.srange import xsrange
124126

125127
#
126128
# Lists of names (as strings) which the user may use to identify one
@@ -1396,8 +1398,7 @@ def order_from_bounds(P, bounds, d=None, operation='+',
13961398
if d > 1:
13971399
Q = multiple(P, d, operation=operation)
13981400
lb, ub = bounds
1399-
bounds = (sage.arith.all.integer_ceil(lb / d),
1400-
sage.arith.all.integer_floor(ub / d))
1401+
bounds = (integer_ceil(lb / d), integer_floor(ub / d))
14011402

14021403
# Use generic bsgs to find n=d*m with lb<=n<=ub and n*P=0
14031404

@@ -1486,7 +1487,7 @@ def merge_points(P1, P2, operation='+',
14861487
if n2.divides(n1):
14871488
return (g1, n1)
14881489

1489-
m, k1, k2 = sage.arith.all.xlcm(n1, n2)
1490+
m, k1, k2 = xlcm(n1, n2)
14901491
m1 = n1 // k1
14911492
m2 = n2 // k2
14921493
g1 = multiple(g1, m1, operation=operation)

src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def __init__(self, parent, M, check=True, **kwargs):
117117
118118
EXAMPLES::
119119
120-
sage:
121120
sage: from sage.modular.modform_hecketriangle.hecke_triangle_groups import HeckeTriangleGroup, HeckeTriangleGroupElement
122121
sage: lam = PolynomialRing(ZZ, 'lam').gen()
123122
sage: M = matrix([[-1, 0], [-lam^4 + 5*lam^2 + lam - 5, -1]])

src/sage/rings/bernoulli_mod_p.pyx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ AUTHOR:
2323
# https://www.gnu.org/licenses/
2424
# ****************************************************************************
2525

26+
from sage.arith.misc import is_prime, primitive_root
27+
2628
cimport sage.rings.fast_arith
2729
import sage.rings.fast_arith
2830
cdef sage.rings.fast_arith.arith_int arith_int
@@ -135,12 +137,12 @@ def bernoulli_mod_p(int p):
135137
if p <= 2:
136138
raise ValueError("p (=%s) must be a prime >= 3" % p)
137139

138-
if not sage.arith.all.is_prime(p):
140+
if not is_prime(p):
139141
raise ValueError("p (=%s) must be a prime" % p)
140142

141143
cdef int g, gSqr, gInv, gInvSqr, isOdd
142144

143-
g = sage.arith.all.primitive_root(p)
145+
g = primitive_root(p)
144146
gInv = arith_int.c_inverse_mod_int(g, p)
145147
gSqr = ((<llong> g) * g) % p
146148
gInvSqr = ((<llong> gInv) * gInv) % p
@@ -303,7 +305,7 @@ def bernoulli_mod_p_single(long p, long k):
303305
if p <= 2:
304306
raise ValueError("p (=%s) must be a prime >= 3" % p)
305307

306-
if not sage.arith.all.is_prime(p):
308+
if not is_prime(p):
307309
raise ValueError("p (=%s) must be a prime" % p)
308310

309311
cdef long x = bernmm_bern_modp(p, k)

src/sage/rings/complex_interval.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ cdef class ComplexIntervalFieldElement(FieldElement):
290290
291291
Exact and nearly exact points are still visible::
292292
293-
sage: # needs sage.plot
293+
sage: # needs sage.plot sage.symbolic
294294
sage: plot(CIF(pi, 1), color='red') + plot(CIF(1, e), color='purple') + plot(CIF(-1, -1))
295295
Graphics object consisting of 6 graphics primitives
296296

src/sage/rings/continued_fraction.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,20 @@
208208
import numbers
209209

210210
import sage.rings.abc
211+
212+
from sage.misc.lazy_import import lazy_import
211213
from sage.rings.infinity import Infinity
212214
from sage.rings.integer import Integer
213215
from sage.rings.integer_ring import ZZ
214216
from sage.structure.richcmp import rich_to_bool, richcmp_method
215217
from sage.structure.sage_object import SageObject
216218

219+
lazy_import('sage.combinat.words.abstract_word', 'Word_class')
220+
lazy_import('sage.combinat.words.finite_word', 'FiniteWord_class')
221+
lazy_import('sage.combinat.words.infinite_word', 'InfiniteWord_class')
222+
lazy_import('sage.combinat.words.word', 'Word')
223+
224+
217225
ZZ_0 = Integer(0)
218226
ZZ_1 = Integer(1)
219227
ZZ_m1 = Integer(-1)
@@ -2490,7 +2498,10 @@ def continued_fraction_list(x, type="std", partial_convergents=False,
24902498

24912499
cf = None
24922500

2493-
from sage.rings.real_mpfr import RealLiteral
2501+
try:
2502+
from sage.rings.real_mpfr import RealLiteral
2503+
except ImportError:
2504+
RealLiteral = ()
24942505
if isinstance(x, RealLiteral):
24952506
from sage.rings.real_mpfi import RealIntervalField
24962507
x = RealIntervalField(x.prec())(x)
@@ -2661,7 +2672,6 @@ def continued_fraction(x, value=None):
26612672
pass
26622673

26632674
# input for finite or ultimately periodic partial quotient expansion
2664-
from sage.combinat.words.finite_word import FiniteWord_class
26652675
if isinstance(x, FiniteWord_class):
26662676
x = list(x)
26672677

@@ -2675,12 +2685,10 @@ def continued_fraction(x, value=None):
26752685
return ContinuedFraction_periodic(x1, x2)
26762686

26772687
# input for infinite partial quotient expansion
2678-
from sage.combinat.words.infinite_word import InfiniteWord_class
26792688
from sage.misc.lazy_list import lazy_list_generic
26802689
if isinstance(x, (lazy_list_generic, InfiniteWord_class)):
26812690
return ContinuedFraction_infinite(x, value)
26822691

2683-
from sage.combinat.words.abstract_word import Word_class
26842692
if isinstance(x, Word_class):
26852693
raise ValueError("word with unknown length cannot be converted "
26862694
"to continued fractions")

src/sage/rings/finite_rings/element_base.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ cdef class FinitePolyExtElement(FiniteRingElement):
586586
Finite Field in a of size 19^2
587587
sage: b = a**20
588588
sage: p = FinitePolyExtElement.charpoly(b, "x", algorithm="pari")
589-
sage: q = FinitePolyExtElement.charpoly(b, "x", algorithm="matrix") # needs sage.modules
590-
sage: q == p # needs sage.modules
589+
sage: q = FinitePolyExtElement.charpoly(b, "x", algorithm="matrix") # needs sage.modules
590+
sage: q == p # needs sage.modules
591591
True
592592
sage: p
593593
x^2 + 15*x + 4

src/sage/rings/finite_rings/element_givaro.pyx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ from cysignals.signals cimport sig_on, sig_off
5656

5757
from cypari2.paridecl cimport *
5858

59+
import sage.arith.misc
60+
5961
from sage.misc.randstate cimport current_randstate
6062
from sage.rings.finite_rings.element_pari_ffelt cimport FiniteFieldElement_pari_ffelt
6163
from sage.structure.richcmp cimport richcmp
62-
import sage.arith.all
6364

6465
from cypari2.gen cimport Gen
6566
from cypari2.stack cimport clear_stack
@@ -414,9 +415,6 @@ cdef class Cache_givaro(Cache_base):
414415
# Reduce to pari
415416
e = e.__pari__()
416417

417-
elif isinstance(e, sage.libs.gap.element.GapElement_FiniteField):
418-
return e.sage(ring=self.parent)
419-
420418
elif isinstance(e, GapElement):
421419
from sage.libs.gap.libgap import libgap
422420
return libgap(e).sage(ring=self.parent)
@@ -434,6 +432,13 @@ cdef class Cache_givaro(Cache_base):
434432
return ret
435433

436434
else:
435+
try:
436+
from sage.libs.gap.element import GapElement_FiniteField
437+
except ImportError:
438+
pass
439+
else:
440+
if isinstance(e, GapElement_FiniteField):
441+
return e.sage(ring=self.parent)
437442
raise TypeError("unable to coerce %r" % type(e))
438443

439444
cdef GEN t
@@ -1568,7 +1573,7 @@ cdef class FiniteField_givaroElement(FinitePolyExtElement):
15681573
raise ArithmeticError("Multiplicative order of 0 not defined.")
15691574
n = (self._cache).order_c() - 1
15701575
order = Integer(1)
1571-
for p, e in sage.arith.all.factor(n):
1576+
for p, e in sage.arith.misc.factor(n):
15721577
# Determine the power of p that divides the order.
15731578
a = self**(n / (p**e))
15741579
while a != 1:

src/sage/rings/finite_rings/element_ntl_gf2e.pyx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ cdef class Cache_ntl_gf2e(Cache_base):
274274
cdef FiniteField_ntl_gf2eElement x
275275
cdef FiniteField_ntl_gf2eElement g
276276
cdef Py_ssize_t i
277-
from sage.libs.gap.element import GapElement_FiniteField
278277

279278
if is_IntegerMod(e):
280279
e = e.lift()
@@ -334,14 +333,18 @@ cdef class Cache_ntl_gf2e(Cache_base):
334333
# Reduce to pari
335334
e = e.__pari__()
336335

337-
elif isinstance(e, GapElement_FiniteField):
338-
return e.sage(ring=self._parent)
339-
340336
elif isinstance(e, GapElement):
341337
from sage.libs.gap.libgap import libgap
342338
return libgap(e).sage(ring=self._parent)
343339

344340
else:
341+
try:
342+
from sage.libs.gap.element import GapElement_FiniteField
343+
except ImportError:
344+
pass
345+
else:
346+
if isinstance(e, GapElement_FiniteField):
347+
return e.sage(ring=self._parent)
345348
raise TypeError("unable to coerce %r" % type(e))
346349

347350
cdef GEN t

0 commit comments

Comments
 (0)