-
-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sage.rings.finite_rings
: Modularization fixes, # needs
#36056
Changes from all commits
bfc5cdf
4c437cb
97b5398
d1f5704
a1e4409
a44af4d
1f7e48a
173d3c3
c0118ba
19222fb
a04dbbc
e78d4ea
6042ff7
1bc26c2
1b54228
baca60e
1810daf
a3ef387
a18e1ab
e9630a6
8a823ff
98283ea
744ddf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,13 @@ | |
""" | ||
|
||
from sage.misc.fast_methods import WithEqualityById | ||
from sage.misc.lazy_import import lazy_import | ||
from sage.structure.sage_object import SageObject | ||
from sage.rings.finite_rings.finite_field_constructor import FiniteField | ||
from sage.rings.integer import Integer | ||
import sage.databases.conway | ||
|
||
lazy_import('sage.databases.conway', 'ConwayPolynomials') | ||
|
||
|
||
def conway_polynomial(p, n): | ||
""" | ||
|
@@ -45,19 +48,19 @@ def conway_polynomial(p, n): | |
|
||
EXAMPLES:: | ||
|
||
sage: conway_polynomial(2,5) | ||
sage: conway_polynomial(2,5) # needs conway_polynomials | ||
x^5 + x^2 + 1 | ||
sage: conway_polynomial(101,5) | ||
sage: conway_polynomial(101,5) # needs conway_polynomials | ||
x^5 + 2*x + 99 | ||
sage: conway_polynomial(97,101) | ||
sage: conway_polynomial(97,101) # needs conway_polynomials | ||
Traceback (most recent call last): | ||
... | ||
RuntimeError: requested Conway polynomial not in database. | ||
""" | ||
(p, n) = (int(p), int(n)) | ||
R = FiniteField(p)['x'] | ||
try: | ||
return R(sage.databases.conway.ConwayPolynomials()[p][n]) | ||
return R(ConwayPolynomials()[p][n]) | ||
except KeyError: | ||
raise RuntimeError("requested Conway polynomial not in database.") | ||
|
||
|
@@ -82,7 +85,7 @@ def exists_conway_polynomial(p, n): | |
|
||
EXAMPLES:: | ||
|
||
sage: exists_conway_polynomial(2,3) | ||
sage: exists_conway_polynomial(2,3) # needs conway_polynomials | ||
True | ||
sage: exists_conway_polynomial(2,-1) | ||
False | ||
|
@@ -91,7 +94,10 @@ def exists_conway_polynomial(p, n): | |
sage: exists_conway_polynomial(6,6) | ||
False | ||
""" | ||
return sage.databases.conway.ConwayPolynomials().has_polynomial(p,n) | ||
try: | ||
return ConwayPolynomials().has_polynomial(p,n) | ||
except ImportError: | ||
return False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it incorrect to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method is named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. That is reasonable. Thanks. |
||
|
||
class PseudoConwayLattice(WithEqualityById, SageObject): | ||
r""" | ||
|
@@ -127,6 +133,7 @@ class PseudoConwayLattice(WithEqualityById, SageObject): | |
|
||
EXAMPLES:: | ||
|
||
sage: # needs sage.rings.finite_rings | ||
sage: from sage.rings.finite_rings.conway_polynomials import PseudoConwayLattice | ||
mkoeppe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sage: PCL = PseudoConwayLattice(2, use_database=False) | ||
sage: PCL.polynomial(3) | ||
|
@@ -154,11 +161,13 @@ def __init__(self, p, use_database=True): | |
""" | ||
TESTS:: | ||
|
||
sage: # needs sage.rings.finite_rings | ||
sage: from sage.rings.finite_rings.conway_polynomials import PseudoConwayLattice | ||
sage: PCL = PseudoConwayLattice(3) | ||
mkoeppe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sage: PCL.polynomial(3) | ||
x^3 + 2*x + 1 | ||
|
||
sage: # needs sage.rings.finite_rings | ||
sage: PCL = PseudoConwayLattice(5, use_database=False) | ||
sage: PCL.polynomial(12) | ||
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): | |
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing | ||
self.ring = PolynomialRing(FiniteField(p), 'x') | ||
if use_database: | ||
C = sage.databases.conway.ConwayPolynomials() | ||
self.nodes = {n: self.ring(C.polynomial(p, n)) | ||
for n in C.degrees(p)} | ||
try: | ||
C = ConwayPolynomials() | ||
except ImportError: | ||
self.nodes = {} | ||
else: | ||
self.nodes = {n: self.ring(C.polynomial(p, n)) | ||
for n in C.degrees(p)} | ||
else: | ||
self.nodes = {} | ||
|
||
|
@@ -199,6 +212,7 @@ def polynomial(self, n): | |
|
||
EXAMPLES:: | ||
|
||
sage: # needs sage.rings.finite_rings | ||
sage: from sage.rings.finite_rings.conway_polynomials import PseudoConwayLattice | ||
sage: PCL = PseudoConwayLattice(2, use_database=False) | ||
sage: PCL.polynomial(3) | ||
|
@@ -267,6 +281,7 @@ def check_consistency(self, n): | |
|
||
EXAMPLES:: | ||
|
||
sage: # needs sage.rings.finite_rings | ||
sage: from sage.rings.finite_rings.conway_polynomials import PseudoConwayLattice | ||
sage: PCL = PseudoConwayLattice(2, use_database=False) | ||
sage: PCL.check_consistency(6) | ||
|
@@ -301,6 +316,7 @@ def _find_pow_of_frobenius(p, n, x, y): | |
|
||
EXAMPLES:: | ||
|
||
sage: # needs sage.rings.finite_rings | ||
sage: from sage.rings.finite_rings.conway_polynomials import _find_pow_of_frobenius | ||
sage: K.<a> = GF(3^14) | ||
sage: x = K.multiplicative_generator() | ||
|
@@ -380,6 +396,7 @@ def _frobenius_shift(K, generators, check_only=False): | |
|
||
EXAMPLES:: | ||
|
||
sage: # needs sage.libs.ntl sage.rings.finite_rings | ||
sage: R.<x> = GF(2)[] | ||
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 | ||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# sage.doctest: optional - sage.rings.finite_rings | ||
# sage.doctest: needs sage.rings.finite_rings | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't all files in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, sagemath-categories ships the basic modules of This makes the prime fields and the integer mod rings available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. I missed it. |
||
Base class for finite field elements | ||
|
||
|
@@ -711,23 +711,23 @@ cdef class FinitePolyExtElement(FiniteRingElement): | |
|
||
EXAMPLES:: | ||
|
||
sage: k.<a> = FiniteField(9, impl='givaro', modulus='primitive') | ||
sage: a.is_square() | ||
sage: k.<a> = FiniteField(9, impl='givaro', modulus='primitive') # needs sage.libs.linbox | ||
sage: a.is_square() # needs sage.libs.linbox | ||
False | ||
sage: (a**2).is_square() | ||
sage: (a**2).is_square() # needs sage.libs.linbox | ||
True | ||
sage: k.<a> = FiniteField(4, impl='ntl', modulus='primitive') | ||
sage: (a**2).is_square() | ||
sage: k.<a> = FiniteField(4, impl='ntl', modulus='primitive') # needs sage.libs.ntl | ||
sage: (a**2).is_square() # needs sage.libs.ntl | ||
True | ||
sage: k.<a> = FiniteField(17^5, impl='pari_ffelt', modulus='primitive') | ||
sage: a.is_square() | ||
sage: k.<a> = FiniteField(17^5, impl='pari_ffelt', modulus='primitive') # needs sage.libs.pari | ||
sage: a.is_square() # needs sage.libs.pari | ||
False | ||
sage: (a**2).is_square() | ||
sage: (a**2).is_square() # needs sage.libs.pari | ||
True | ||
|
||
:: | ||
|
||
sage: k(0).is_square() | ||
sage: k(0).is_square() # needs sage.libs.linbox | ||
True | ||
""" | ||
K = self.parent() | ||
|
@@ -1049,6 +1049,7 @@ cdef class FinitePolyExtElement(FiniteRingElement): | |
|
||
TESTS:: | ||
|
||
sage: # needs sage.modules | ||
sage: p = random_prime(2^99) | ||
sage: k = randrange(2,10) | ||
sage: F.<t> = GF((p, k)) | ||
|
@@ -1086,7 +1087,7 @@ cdef class Cache_base(SageObject): | |
EXAMPLES:: | ||
|
||
sage: k.<a> = GF(2^48) | ||
sage: k._cache.fetch_int(2^33 + 2 + 1) | ||
sage: k._cache.fetch_int(2^33 + 2 + 1) # needs sage.libs.ntl | ||
a^33 + a + 1 | ||
""" | ||
raise NotImplementedError("this must be implemented by subclasses") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the tag be file-scoped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module also contains code for computing pseudo-Conway polynomials, which has to be used when the database is not available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.