Skip to content

Commit d6c6f62

Browse files
author
Release Manager
committed
gh-36056: `sage.rings.finite_rings`: Modularization fixes, `# needs` <!-- ^^^^^ 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 --> <!-- Why is this change required? What problem does it solve? --> - Part of: #29705 - Cherry-picked from: #35095 <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- 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. - [x] 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: #36056 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee, Matthias Köppe
2 parents 03dec7d + 744ddf8 commit d6c6f62

17 files changed

+1012
-802
lines changed

src/sage/rings/finite_rings/conway_polynomials.py

+27-10
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
"""
1212

1313
from sage.misc.fast_methods import WithEqualityById
14+
from sage.misc.lazy_import import lazy_import
1415
from sage.structure.sage_object import SageObject
1516
from sage.rings.finite_rings.finite_field_constructor import FiniteField
1617
from sage.rings.integer import Integer
17-
import sage.databases.conway
18+
19+
lazy_import('sage.databases.conway', 'ConwayPolynomials')
20+
1821

1922
def conway_polynomial(p, n):
2023
"""
@@ -45,19 +48,19 @@ def conway_polynomial(p, n):
4548
4649
EXAMPLES::
4750
48-
sage: conway_polynomial(2,5)
51+
sage: conway_polynomial(2,5) # needs conway_polynomials
4952
x^5 + x^2 + 1
50-
sage: conway_polynomial(101,5)
53+
sage: conway_polynomial(101,5) # needs conway_polynomials
5154
x^5 + 2*x + 99
52-
sage: conway_polynomial(97,101)
55+
sage: conway_polynomial(97,101) # needs conway_polynomials
5356
Traceback (most recent call last):
5457
...
5558
RuntimeError: requested Conway polynomial not in database.
5659
"""
5760
(p, n) = (int(p), int(n))
5861
R = FiniteField(p)['x']
5962
try:
60-
return R(sage.databases.conway.ConwayPolynomials()[p][n])
63+
return R(ConwayPolynomials()[p][n])
6164
except KeyError:
6265
raise RuntimeError("requested Conway polynomial not in database.")
6366

@@ -82,7 +85,7 @@ def exists_conway_polynomial(p, n):
8285
8386
EXAMPLES::
8487
85-
sage: exists_conway_polynomial(2,3)
88+
sage: exists_conway_polynomial(2,3) # needs conway_polynomials
8689
True
8790
sage: exists_conway_polynomial(2,-1)
8891
False
@@ -91,7 +94,10 @@ def exists_conway_polynomial(p, n):
9194
sage: exists_conway_polynomial(6,6)
9295
False
9396
"""
94-
return sage.databases.conway.ConwayPolynomials().has_polynomial(p,n)
97+
try:
98+
return ConwayPolynomials().has_polynomial(p,n)
99+
except ImportError:
100+
return False
95101

96102
class PseudoConwayLattice(WithEqualityById, SageObject):
97103
r"""
@@ -127,6 +133,7 @@ class PseudoConwayLattice(WithEqualityById, SageObject):
127133
128134
EXAMPLES::
129135
136+
sage: # needs sage.rings.finite_rings
130137
sage: from sage.rings.finite_rings.conway_polynomials import PseudoConwayLattice
131138
sage: PCL = PseudoConwayLattice(2, use_database=False)
132139
sage: PCL.polynomial(3)
@@ -154,11 +161,13 @@ def __init__(self, p, use_database=True):
154161
"""
155162
TESTS::
156163
164+
sage: # needs sage.rings.finite_rings
157165
sage: from sage.rings.finite_rings.conway_polynomials import PseudoConwayLattice
158166
sage: PCL = PseudoConwayLattice(3)
159167
sage: PCL.polynomial(3)
160168
x^3 + 2*x + 1
161169
170+
sage: # needs sage.rings.finite_rings
162171
sage: PCL = PseudoConwayLattice(5, use_database=False)
163172
sage: PCL.polynomial(12)
164173
x^12 + 4*x^11 + 2*x^10 + 4*x^9 + 2*x^8 + 2*x^7 + 4*x^6 + x^5 + 2*x^4 + 2*x^2 + x + 2
@@ -171,9 +180,13 @@ def __init__(self, p, use_database=True):
171180
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
172181
self.ring = PolynomialRing(FiniteField(p), 'x')
173182
if use_database:
174-
C = sage.databases.conway.ConwayPolynomials()
175-
self.nodes = {n: self.ring(C.polynomial(p, n))
176-
for n in C.degrees(p)}
183+
try:
184+
C = ConwayPolynomials()
185+
except ImportError:
186+
self.nodes = {}
187+
else:
188+
self.nodes = {n: self.ring(C.polynomial(p, n))
189+
for n in C.degrees(p)}
177190
else:
178191
self.nodes = {}
179192

@@ -199,6 +212,7 @@ def polynomial(self, n):
199212
200213
EXAMPLES::
201214
215+
sage: # needs sage.rings.finite_rings
202216
sage: from sage.rings.finite_rings.conway_polynomials import PseudoConwayLattice
203217
sage: PCL = PseudoConwayLattice(2, use_database=False)
204218
sage: PCL.polynomial(3)
@@ -267,6 +281,7 @@ def check_consistency(self, n):
267281
268282
EXAMPLES::
269283
284+
sage: # needs sage.rings.finite_rings
270285
sage: from sage.rings.finite_rings.conway_polynomials import PseudoConwayLattice
271286
sage: PCL = PseudoConwayLattice(2, use_database=False)
272287
sage: PCL.check_consistency(6)
@@ -301,6 +316,7 @@ def _find_pow_of_frobenius(p, n, x, y):
301316
302317
EXAMPLES::
303318
319+
sage: # needs sage.rings.finite_rings
304320
sage: from sage.rings.finite_rings.conway_polynomials import _find_pow_of_frobenius
305321
sage: K.<a> = GF(3^14)
306322
sage: x = K.multiplicative_generator()
@@ -380,6 +396,7 @@ def _frobenius_shift(K, generators, check_only=False):
380396
381397
EXAMPLES::
382398
399+
sage: # needs sage.libs.ntl sage.rings.finite_rings
383400
sage: R.<x> = GF(2)[]
384401
sage: f30 = x^30 + x^28 + x^27 + x^25 + x^24 + x^20 + x^19 + x^18 + x^16 + x^15 + x^12 + x^10 + x^7 + x^2 + 1
385402
sage: f20 = x^20 + x^19 + x^15 + x^13 + x^12 + x^11 + x^9 + x^8 + x^7 + x^4 + x^2 + x + 1

src/sage/rings/finite_rings/element_base.pyx

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sage.doctest: optional - sage.rings.finite_rings
1+
# sage.doctest: needs sage.rings.finite_rings
22
"""
33
Base class for finite field elements
44
@@ -711,23 +711,23 @@ cdef class FinitePolyExtElement(FiniteRingElement):
711711
712712
EXAMPLES::
713713
714-
sage: k.<a> = FiniteField(9, impl='givaro', modulus='primitive')
715-
sage: a.is_square()
714+
sage: k.<a> = FiniteField(9, impl='givaro', modulus='primitive') # needs sage.libs.linbox
715+
sage: a.is_square() # needs sage.libs.linbox
716716
False
717-
sage: (a**2).is_square()
717+
sage: (a**2).is_square() # needs sage.libs.linbox
718718
True
719-
sage: k.<a> = FiniteField(4, impl='ntl', modulus='primitive')
720-
sage: (a**2).is_square()
719+
sage: k.<a> = FiniteField(4, impl='ntl', modulus='primitive') # needs sage.libs.ntl
720+
sage: (a**2).is_square() # needs sage.libs.ntl
721721
True
722-
sage: k.<a> = FiniteField(17^5, impl='pari_ffelt', modulus='primitive')
723-
sage: a.is_square()
722+
sage: k.<a> = FiniteField(17^5, impl='pari_ffelt', modulus='primitive') # needs sage.libs.pari
723+
sage: a.is_square() # needs sage.libs.pari
724724
False
725-
sage: (a**2).is_square()
725+
sage: (a**2).is_square() # needs sage.libs.pari
726726
True
727727
728728
::
729729
730-
sage: k(0).is_square()
730+
sage: k(0).is_square() # needs sage.libs.linbox
731731
True
732732
"""
733733
K = self.parent()
@@ -1049,6 +1049,7 @@ cdef class FinitePolyExtElement(FiniteRingElement):
10491049
10501050
TESTS::
10511051
1052+
sage: # needs sage.modules
10521053
sage: p = random_prime(2^99)
10531054
sage: k = randrange(2,10)
10541055
sage: F.<t> = GF((p, k))
@@ -1086,7 +1087,7 @@ cdef class Cache_base(SageObject):
10861087
EXAMPLES::
10871088
10881089
sage: k.<a> = GF(2^48)
1089-
sage: k._cache.fetch_int(2^33 + 2 + 1)
1090+
sage: k._cache.fetch_int(2^33 + 2 + 1) # needs sage.libs.ntl
10901091
a^33 + a + 1
10911092
"""
10921093
raise NotImplementedError("this must be implemented by subclasses")

src/sage/rings/finite_rings/element_pari_ffelt.pyx

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ from .element_base cimport FinitePolyExtElement
2828
from .integer_mod import IntegerMod_abstract
2929

3030
import sage.rings.integer
31-
from sage.modules.free_module_element import FreeModuleElement
3231
from sage.rings.integer cimport Integer
3332
from sage.rings.polynomial.polynomial_element import Polynomial
3433
from sage.rings.polynomial.multi_polynomial_element import MPolynomial
3534
from sage.rings.rational import Rational
3635
from sage.structure.richcmp cimport rich_to_bool
3736

37+
try:
38+
from sage.modules.free_module_element import FreeModuleElement
39+
except ImportError:
40+
FreeModuleElement = ()
3841

3942
from sage.interfaces.abc import GapElement
4043

@@ -1330,9 +1333,10 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement):
13301333
13311334
EXAMPLES::
13321335
1336+
sage: # needs sage.libs.gap
13331337
sage: F = FiniteField(2^3, 'aa', impl='pari_ffelt')
13341338
sage: aa = F.multiplicative_generator()
1335-
sage: gap(aa) # indirect doctest
1339+
sage: gap(aa) # indirect doctest
13361340
Z(2^3)
13371341
sage: b = F.multiplicative_generator()
13381342
sage: a = b^3
@@ -1347,6 +1351,7 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement):
13471351
13481352
You can specify the instance of the Gap interpreter that is used::
13491353
1354+
sage: # needs sage.libs.gap
13501355
sage: F = FiniteField(next_prime(200)^2, 'a', impl='pari_ffelt')
13511356
sage: a = F.multiplicative_generator()
13521357
sage: a._gap_ (gap)
@@ -1356,6 +1361,7 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement):
13561361
13571362
Gap only supports relatively small finite fields::
13581363
1364+
sage: # needs sage.libs.gap
13591365
sage: F = FiniteField(next_prime(1000)^2, 'a', impl='pari_ffelt')
13601366
sage: a = F.multiplicative_generator()
13611367
sage: a._gap_init_()

0 commit comments

Comments
 (0)