Skip to content
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

Deprecate is_FiniteField etc., make sage.rings.finite_rings a namespace package #35119

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/.relint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
Hint: namespace package. Type import_statements("SOME_IDENTIFIER") to find a more specific import,
Hint: or use 'sage --fiximports' to fix automatically in the source file.
# Keep in sync with SAGE_ROOT/src/sage/misc/replace_dot_all.py
pattern: 'from\s+sage(|[.](arith|categories|combinat|ext|graphs(|[.]decompositions)|interfaces|libs|matrix|misc|numerical(|[.]backends)|rings|sets))[.]all\s+import'
pattern: 'from\s+sage(|[.](arith|categories|combinat|ext|graphs(|[.]decompositions)|interfaces|libs|matrix|misc|numerical(|[.]backends)|rings(|[.]finite_rings)|sets))[.]all\s+import'
filePattern: '.*[.](py|pyx|pxi)$'
error: false # Make this a warning instead of an error for now
11 changes: 7 additions & 4 deletions src/sage/crypto/boolean_function.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ from sage.rings.integer_ring import ZZ
from sage.rings.integer cimport Integer
from sage.rings.finite_rings.finite_field_constructor import GF
from sage.rings.polynomial.pbori.pbori import BooleanPolynomial
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.polynomial.polynomial_element import Polynomial

from sage.misc.superseded import deprecated_function_alias
Expand Down Expand Up @@ -329,11 +328,15 @@ cdef class BooleanFunction(SageObject):

elif isinstance(x, Polynomial):
K = x.base_ring()
if is_FiniteField(K) and K.characteristic() == 2:
if isinstance(K, FiniteField) and K.characteristic() == 2:
self._nvariables = K.degree()
bitset_init(self._truth_table, <mp_bitcnt_t> (1<<self._nvariables))
bitset_zero(self._truth_table)
if isinstance(K,FiniteField_givaro): #the ordering is not the same in this case
try:
from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro
except ImportError:
FiniteField_givaro = ()
if isinstance(K, FiniteField_givaro): # the ordering is not the same in this case
for u in K:
bitset_set_to(self._truth_table, ZZ(u._vector_().list(),2) , (x(u)).trace())
else:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/crypto/lfsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

from sage.structure.all import Sequence
from sage.rings.all import Integer, PolynomialRing
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField


def lfsr_sequence(key, fill, n):
Expand Down Expand Up @@ -179,7 +179,7 @@ def lfsr_sequence(key, fill, n):
raise TypeError("key must be a list")
key = Sequence(key)
F = key.universe()
if not is_FiniteField(F):
if not isinstance(F, FiniteField):
raise TypeError("universe of sequence must be a finite field")

s = fill
Expand Down
9 changes: 4 additions & 5 deletions src/sage/crypto/mq/rijndael_gf.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@

from sage.matrix.constructor import matrix
from sage.matrix.constructor import column_matrix
from sage.structure.element import Matrix
from sage.structure.element import Element, Matrix
from sage.rings.finite_rings.finite_field_base import FiniteField as FiniteField_base
from sage.rings.finite_rings.finite_field_constructor import FiniteField
from sage.structure.sage_object import SageObject
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
Expand Down Expand Up @@ -757,10 +758,9 @@ def _GF_to_hex(self, GF):
sage: rgf._GF_to_hex(output)
'e142cd5fcd9d6d94a3340793034391b5'
"""
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
if not isinstance(GF, Matrix) and \
not isinstance(GF, list) and \
not is_FiniteFieldElement(GF):
not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField_base)):
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
"elements from {0}, or a single element from {0}")
raise TypeError(msg.format(self._F))
Expand Down Expand Up @@ -883,10 +883,9 @@ def _GF_to_bin(self, GF):
sage: rgf._GF_to_bin(output)
'11011000000111111111100000011011110110000001111111111000000110111101100000011111111110000001101111011000000111111111100000011011'
"""
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
if not isinstance(GF, Matrix) and \
not isinstance(GF, list) and \
not is_FiniteFieldElement(GF):
not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField_base)):
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
"elements from {0}, or a single element from {0}")
raise TypeError(msg.format(self))
Expand Down
4 changes: 2 additions & 2 deletions src/sage/crypto/sbox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from sage.misc.functional import is_even
from sage.misc.misc_c import prod as mul
from sage.misc.superseded import deprecated_function_alias
from sage.modules.free_module_element import vector
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
from sage.rings.ideal import FieldIdeal, Ideal
from sage.rings.integer_ring import ZZ
Expand Down Expand Up @@ -195,7 +195,7 @@ cdef class SBox(SageObject):

_S_list = []
for e in S:
if is_FiniteFieldElement(e):
if isinstance(e, Element) and isinstance(e.parent(), FiniteField):
e = e.polynomial().change_ring(ZZ).subs(e.parent().characteristic())
_S_list.append(e)
S = _S_list
Expand Down
10 changes: 5 additions & 5 deletions src/sage/dynamics/arithmetic_dynamics/affine_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class initialization directly.
from sage.misc.cachefunc import cached_method
from sage.misc.classcall_metaclass import typecall
from sage.rings.integer import Integer
from sage.rings.finite_rings.finite_field_constructor import is_PrimeFiniteField
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.fraction_field import FractionField
from sage.rings.fraction_field import is_FractionField
from sage.rings.quotient_ring import is_QuotientRing
Expand Down Expand Up @@ -251,7 +250,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None):
raise ValueError('domain and codomain do not agree')
if R not in Fields():
return typecall(cls, polys, domain)
if is_FiniteField(R):
if isinstance(R, FiniteField):
return DynamicalSystem_affine_finite_field(polys, domain)
return DynamicalSystem_affine_field(polys, domain)
elif isinstance(morphism_or_polys,(list, tuple)):
Expand Down Expand Up @@ -299,7 +298,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None):

if R not in Fields():
return typecall(cls, polys, domain)
if is_FiniteField(R):
if isinstance(R, FiniteField):
return DynamicalSystem_affine_finite_field(polys, domain)
return DynamicalSystem_affine_field(polys, domain)

Expand All @@ -319,7 +318,8 @@ def __init__(self, polys_or_rat_fncts, domain):
"""
L = polys_or_rat_fncts
# Next attribute needed for _fast_eval and _fastpolys
self._is_prime_finite_field = is_PrimeFiniteField(L[0].base_ring())
R = L[0].base_ring()
self._is_prime_finite_field = isinstance(R, FiniteField) and R.is_prime_field()
DynamicalSystem.__init__(self, L, domain)

def __copy__(self):
Expand Down
8 changes: 4 additions & 4 deletions src/sage/dynamics/arithmetic_dynamics/generic_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class initialization directly.
from sage.schemes.affine.affine_space import is_AffineSpace
from sage.schemes.affine.affine_subscheme import AlgebraicScheme_subscheme_affine
from sage.rings.algebraic_closure_finite_field import AlgebraicClosureFiniteField_generic
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.qqbar import AlgebraicField_common
from sage.schemes.berkovich.berkovich_space import is_Berkovich_Cp
from sage.rings.rational_field import QQ
Expand Down Expand Up @@ -416,7 +416,7 @@ def field_of_definition_critical(self, return_embedding=False, simplify_all=Fals
CR = CR.ring()
x = CR.gen(0)
poly = (g*CR(f).derivative(x) - f*CR(g).derivative(x)).univariate_polynomial()
if is_FiniteField(ds.base_ring()):
if isinstance(ds.base_ring(), FiniteField):
return poly.splitting_field(names, map=return_embedding)
else:
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)
Expand Down Expand Up @@ -536,7 +536,7 @@ def field_of_definition_periodic(self, n, formal=False, return_embedding=False,
fn = ds.nth_iterate_map(n)
f,g = fn[0].numerator(), fn[0].denominator()
poly = (f - g*x).univariate_polynomial()
if is_FiniteField(ds.base_ring()):
if isinstance(ds.base_ring(), FiniteField):
return poly.splitting_field(names, map=return_embedding)
else:
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)
Expand Down Expand Up @@ -630,7 +630,7 @@ def field_of_definition_preimage(self, point, n, return_embedding=False, simplif
#want the polynomial ring not the fraction field
CR = CR.ring()
poly = (f*point[1] - g*CR(point[0])).univariate_polynomial()
if is_FiniteField(ds.base_ring()):
if isinstance(ds.base_ring(), FiniteField):
return poly.splitting_field(names, map=return_embedding)
else:
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)
Expand Down
15 changes: 8 additions & 7 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class initialization directly.
from sage.categories.finite_fields import FiniteFields
from sage.rings.algebraic_closure_finite_field import AlgebraicClosureFiniteField_generic
from sage.rings.complex_mpfr import ComplexField
from sage.rings.finite_rings.finite_field_constructor import (is_FiniteField, GF,
is_PrimeFiniteField)
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.finite_rings.finite_field_constructor import GF
from sage.rings.finite_rings.integer_mod_ring import Zmod
from sage.rings.fraction_field import (FractionField, is_FractionField, FractionField_1poly_field)
from sage.rings.fraction_field_element import is_FractionFieldElement, FractionFieldElement
Expand Down Expand Up @@ -373,7 +373,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None, names=None):
raise ValueError('"domain" must be a projective scheme')
if R not in Fields():
return typecall(cls, polys, domain)
if is_FiniteField(R):
if isinstance(R, FiniteField):
return DynamicalSystem_projective_finite_field(polys, domain)
return DynamicalSystem_projective_field(polys, domain)

Expand Down Expand Up @@ -432,7 +432,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None, names=None):
if not all(split_d == domain._degree(f) for f in split_poly):
msg = 'polys (={}) must be multi-homogeneous of the same degrees (by component)'
raise TypeError(msg.format(polys))
if is_FiniteField(R):
if isinstance(R, FiniteField):
from sage.dynamics.arithmetic_dynamics.product_projective_ds import DynamicalSystem_product_projective_finite_field
return DynamicalSystem_product_projective_finite_field(polys, domain)
return DynamicalSystem_product_projective(polys, domain)
Expand All @@ -450,7 +450,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None, names=None):
raise ValueError('"domain" must be a projective scheme')
if R not in Fields():
return typecall(cls, polys, domain)
if is_FiniteField(R):
if isinstance(R, FiniteField):
return DynamicalSystem_projective_finite_field(polys, domain)
return DynamicalSystem_projective_field(polys, domain)

Expand All @@ -469,8 +469,9 @@ def __init__(self, polys, domain):
(3/5*x^2 : y^2)
"""
# Next attribute needed for _fast_eval and _fastpolys
self._is_prime_finite_field = is_PrimeFiniteField(polys[0].base_ring())
DynamicalSystem.__init__(self,polys,domain)
R = polys[0].base_ring()
self._is_prime_finite_field = isinstance(R, FiniteField) and R.is_prime_field()
DynamicalSystem.__init__(self, polys, domain)

def __copy__(self):
r"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/cubic_braid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,10 +1543,10 @@ def as_matrix_group(self, root_bur=None, domain=None, characteristic=None, var='
self._classical_invariant_form = herm_form

if unitary:
from sage.rings.finite_rings.finite_field_base import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.groups.matrix_gps.unitary import GU
d, d = herm_form.dimensions()
if is_FiniteField(domain):
if isinstance(domain, FiniteField):
base_group = GU(d, domain, var=domain.gen(), invariant_form=herm_form)
else:
base_group = GU(d, domain, invariant_form=herm_form)
Expand Down
8 changes: 4 additions & 4 deletions src/sage/groups/matrix_gps/orthogonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
# ****************************************************************************

from sage.rings.integer_ring import ZZ
from sage.rings.finite_rings.finite_field_base import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.misc.latex import latex
from sage.misc.cachefunc import cached_method
from sage.groups.matrix_gps.named_group import (
Expand Down Expand Up @@ -127,7 +127,7 @@ def normalize_args_e(degree, ring, e):
...
ValueError: must have e=-1 or e=1 for even degree
"""
if is_FiniteField(ring) and degree%2 == 0:
if isinstance(ring, FiniteField) and degree%2 == 0:
if e not in (-1, +1):
raise ValueError('must have e=-1 or e=1 for even degree')
else:
Expand Down Expand Up @@ -171,7 +171,7 @@ def _OG(n, R, special, e=0, var='a', invariant_form=None):
e = normalize_args_e(degree, ring, e)

if invariant_form is not None:
if is_FiniteField(ring):
if isinstance(ring, FiniteField):
raise NotImplementedError("invariant_form for finite groups is fixed by GAP")

if e == 0:
Expand Down Expand Up @@ -202,7 +202,7 @@ def _OG(n, R, special, e=0, var='a', invariant_form=None):
latex(ring),
'+' if e == 1 else '-')

if is_FiniteField(ring):
if isinstance(ring, FiniteField):
cmd = '{0}O({1}, {2}, {3})'.format(ltx_prefix, e, degree, ring.order())
return OrthogonalMatrixGroup_gap(degree, ring, False, name, ltx, cmd)
else:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/groups/matrix_gps/symplectic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

from sage.misc.latex import latex
from sage.misc.cachefunc import cached_method
from sage.rings.finite_rings.finite_field_base import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.groups.matrix_gps.named_group import (
normalize_args_vectorspace, normalize_args_invariant_form,
NamedMatrixGroup_generic, NamedMatrixGroup_gap)
Expand Down Expand Up @@ -145,7 +145,7 @@ def Sp(n, R, var='a', invariant_form=None):
raise ValueError('the degree must be even')

if invariant_form is not None:
if is_FiniteField(ring):
if isinstance(ring, FiniteField):
raise NotImplementedError("invariant_form for finite groups is fixed by GAP")

invariant_form = normalize_args_invariant_form(ring, degree, invariant_form)
Expand Down
8 changes: 4 additions & 4 deletions src/sage/groups/matrix_gps/unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# ****************************************************************************

from sage.rings.finite_rings.finite_field_constructor import GF
from sage.rings.finite_rings.finite_field_base import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.misc.latex import latex
from sage.misc.cachefunc import cached_method
from sage.groups.matrix_gps.named_group import (
Expand All @@ -77,7 +77,7 @@ def finite_field_sqrt(ring):
sage: finite_field_sqrt(GF(4, 'a'))
2
"""
if not is_FiniteField(ring):
if not isinstance(ring, FiniteField):
raise ValueError('not a finite field')
q, rem = ring.cardinality().sqrtrem()
if rem:
Expand Down Expand Up @@ -107,7 +107,7 @@ def _UG(n, R, special, var='a', invariant_form=None):
latex_prefix ='S'

degree, ring = normalize_args_vectorspace(n, R, var=var)
if is_FiniteField(ring):
if isinstance(ring, FiniteField):
q = ring.cardinality()
ring = GF(q**2, name=var)
if invariant_form is not None:
Expand All @@ -134,7 +134,7 @@ def _UG(n, R, special, var='a', invariant_form=None):
name = '{0} Unitary Group of degree {1} over {2}'.format(prefix, degree, ring)
ltx = r'\text{{{0}U}}_{{{1}}}({2})'.format(latex_prefix, degree, latex(ring))

if is_FiniteField(ring):
if isinstance(ring, FiniteField):
cmd = '{0}U({1}, {2})'.format(latex_prefix, degree, q)
return UnitaryMatrixGroup_gap(degree, ring, special, name, ltx, cmd)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/interfaces/gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ def intmod_gap_to_sage(x):
sage: b.parent()
Ring of integers modulo 65537
"""
from sage.rings.finite_rings.all import FiniteField
from sage.rings.finite_rings.finite_field_constructor import FiniteField
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this should be finite_field_base?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, line 1762 uses the constructor function, not the class

from sage.rings.finite_rings.integer_mod import Mod
from sage.rings.integer import Integer
s = str(x)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
import sage.rings.integer as integer
import sage.rings.finite_rings.finite_field_constructor
from sage.rings.finite_rings.finite_field_base import FiniteField
import sage.misc.latex as latex
import sage.modules.free_module

Expand Down Expand Up @@ -223,7 +223,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
else:
return matrix_complex_double_dense.Matrix_complex_double_dense

elif sage.rings.finite_rings.finite_field_constructor.is_FiniteField(R):
elif isinstance(R, FiniteField):
if R.order() == 2:
try:
from . import matrix_mod2_dense
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@
import sage.misc.latex as latex

from sage.modules.module import Module
import sage.rings.finite_rings.finite_field_constructor as finite_field
import sage.rings.ring as ring
import sage.rings.abc
import sage.rings.integer_ring
Expand All @@ -195,6 +194,7 @@
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
from sage.misc.lazy_attribute import lazy_attribute
from sage.misc.randstate import current_randstate
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.structure.factory import UniqueFactory
from sage.structure.sequence import Sequence
from sage.structure.richcmp import (richcmp_method, rich_to_bool, richcmp,
Expand Down Expand Up @@ -6348,7 +6348,7 @@ def _element_constructor_(self, e, *args, **kwds):
"""
try:
k = e.parent()
if finite_field.is_FiniteField(k) and k.base_ring() == self.base_ring() and k.degree() == self.degree():
if isinstance(k, FiniteField) and k.base_ring() == self.base_ring() and k.degree() == self.degree():
return self(e._vector_())
except AttributeError:
pass
Expand Down
Loading