From 53ede8c9bad73793c9431a51ac511eefa8c09eb2 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 14:21:20 -0800 Subject: [PATCH 01/10] sage.rings.finite_rings: Deprecate is_FiniteField, is_PrimeFiniteField --- src/sage/crypto/boolean_function.pyx | 11 +++++++---- src/sage/crypto/lfsr.py | 4 ++-- .../dynamics/arithmetic_dynamics/affine_ds.py | 10 +++++----- .../dynamics/arithmetic_dynamics/generic_ds.py | 8 ++++---- .../arithmetic_dynamics/projective_ds.py | 14 +++++++------- src/sage/groups/cubic_braid.py | 4 ++-- src/sage/groups/matrix_gps/orthogonal.py | 8 ++++---- src/sage/groups/matrix_gps/symplectic.py | 4 ++-- src/sage/groups/matrix_gps/unitary.py | 8 ++++---- src/sage/matrix/matrix_space.py | 4 ++-- src/sage/modules/free_module.py | 2 +- src/sage/rings/algebraic_closure_finite_field.py | 6 +++--- src/sage/rings/finite_rings/element_base.pyx | 4 ++-- .../rings/finite_rings/finite_field_base.pyx | 11 ++++++++--- .../finite_rings/finite_field_constructor.py | 16 +++++++++++----- src/sage/rings/finite_rings/hom_finite_field.pyx | 8 ++++---- .../finite_rings/hom_prime_finite_field.pyx | 4 ++-- src/sage/rings/finite_rings/homset.py | 4 ++-- src/sage/rings/morphism.pyx | 6 +++--- src/sage/rings/polynomial/polynomial_element.pyx | 8 ++++---- .../polynomial/polynomial_ring_constructor.py | 4 ++-- .../polynomial/polynomial_singular_interface.py | 14 +++++++------- src/sage/schemes/affine/affine_homset.py | 4 ++-- src/sage/schemes/affine/affine_morphism.py | 8 ++++---- src/sage/schemes/affine/affine_space.py | 16 ++++++++-------- src/sage/schemes/curves/constructor.py | 10 +++++----- src/sage/schemes/cyclic_covers/constructor.py | 4 ++-- src/sage/schemes/elliptic_curves/constructor.py | 4 ++-- src/sage/schemes/generic/algebraic_scheme.py | 4 ++-- .../schemes/hyperelliptic_curves/constructor.py | 2 +- src/sage/schemes/plane_conics/constructor.py | 4 ++-- src/sage/schemes/product_projective/homset.py | 4 ++-- src/sage/schemes/product_projective/space.py | 8 ++++---- src/sage/schemes/projective/projective_homset.py | 4 ++-- .../schemes/projective/projective_morphism.py | 10 +++++----- src/sage/schemes/projective/projective_space.py | 6 +++--- .../schemes/projective/projective_subscheme.py | 4 ++-- src/sage/symbolic/ring.pyx | 4 ++-- 38 files changed, 136 insertions(+), 122 deletions(-) diff --git a/src/sage/crypto/boolean_function.pyx b/src/sage/crypto/boolean_function.pyx index a9ea665475c..10693a17992 100644 --- a/src/sage/crypto/boolean_function.pyx +++ b/src/sage/crypto/boolean_function.pyx @@ -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 is_Polynomial from sage.misc.superseded import deprecated_function_alias @@ -329,11 +328,15 @@ cdef class BooleanFunction(SageObject): elif is_Polynomial(x): 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, (1< 1: # Specialized code breaks for n == 1 specialized = polynomial_ring.PolynomialRing_dense_mod_n - elif is_FiniteField(base_ring): + elif isinstance(base_ring, FiniteField): specialized = polynomial_ring.PolynomialRing_dense_finite_field elif isinstance(base_ring, padic_base_leaves.pAdicFieldCappedRelative): specialized = polynomial_ring.PolynomialRing_dense_padic_field_capped_relative diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 40b77534d19..5d309ceb85c 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -44,7 +44,7 @@ from sage.interfaces.singular import singular from sage.rings.rational_field import is_RationalField from sage.rings.function_field.function_field import RationalFunctionField -from sage.rings.finite_rings.finite_field_base import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.integer_ring import ZZ import sage.rings.finite_rings.finite_field_constructor @@ -103,13 +103,13 @@ def _do_singular_init_(singular, base_ring, char, _vars, order): elif isinstance(base_ring, sage.rings.abc.IntegerModRing): char = base_ring.characteristic() - if sage.rings.finite_rings.finite_field_constructor.is_FiniteField(base_ring) and char <= 2147483647: + if isinstance(base_ring, FiniteField) and char <= 2147483647: return make_ring(str(char)), None if char.is_power_of(2): return make_ring(f"(integer,2,{char.nbits()-1})"), None return make_ring(f"(integer,{char})"), None - elif sage.rings.finite_rings.finite_field_constructor.is_FiniteField(base_ring): + elif isinstance(base_ring, FiniteField): # not the prime field! gen = str(base_ring.gen()) R = make_ring(f"({char},{gen})") @@ -148,7 +148,7 @@ def _do_singular_init_(singular, base_ring, char, _vars, order): if B.is_prime_field() or B is ZZ: return make_ring(f"({base_char},{gens})"), None - if is_FiniteField(B) and B.characteristic() <= 2147483647: + if isinstance(B, FiniteField) and B.characteristic() <= 2147483647: ext_gen = str(B.gen()) _vars = '(' + ext_gen + ', ' + _vars[1:] @@ -333,7 +333,7 @@ def _singular_(self, singular=singular): R._check_valid() if self.base_ring() is ZZ or self.base_ring().is_prime_field(): return R - if sage.rings.finite_rings.finite_field_constructor.is_FiniteField(self.base_ring()) or \ + if isinstance(self.base_ring(), FiniteField) or \ (number_field.number_field_base.is_NumberField(self.base_ring()) and self.base_ring().is_absolute()): R.set_ring() # sorry for that, but needed for minpoly if singular.eval('minpoly') != f"({self.__minpoly})": @@ -427,14 +427,14 @@ def can_convert_to_singular(R): sage.rings.abc.RealField, sage.rings.abc.ComplexField, sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField))): return True - elif sage.rings.finite_rings.finite_field_constructor.is_FiniteField(base_ring): + elif isinstance(base_ring, FiniteField): return base_ring.characteristic() <= 2147483647 elif number_field.number_field_base.is_NumberField(base_ring): return base_ring.is_absolute() elif sage.rings.fraction_field.is_FractionField(base_ring): B = base_ring.base_ring() return (B.is_prime_field() or B is ZZ - or (is_FiniteField(B) and B.characteristic() <= 2147483647)) + or (isinstance(B, FiniteField) and B.characteristic() <= 2147483647)) elif isinstance(base_ring, RationalFunctionField): return base_ring.constant_field().is_prime_field() else: diff --git a/src/sage/schemes/affine/affine_homset.py b/src/sage/schemes/affine/affine_homset.py index 98b3b3a8994..914e54f7148 100644 --- a/src/sage/schemes/affine/affine_homset.py +++ b/src/sage/schemes/affine/affine_homset.py @@ -41,7 +41,7 @@ from sage.rings.rational_field import is_RationalField from sage.categories.fields import Fields from sage.categories.number_fields import NumberFields -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.schemes.generic.homset import SchemeHomset_points, SchemeHomset_generic @@ -354,7 +354,7 @@ def points(self, **kwds): raise TypeError("a positive bound B (= %s) must be specified"%B) from sage.schemes.affine.affine_rational_point import enum_affine_number_field return enum_affine_number_field(self, bound=B, tolerance=tol, precision=prec) - elif is_FiniteField(R): + elif isinstance(R, FiniteField): from sage.schemes.affine.affine_rational_point import enum_affine_finite_field return enum_affine_finite_field(self) else: diff --git a/src/sage/schemes/affine/affine_morphism.py b/src/sage/schemes/affine/affine_morphism.py index 1c4f2dff188..e6a8bad39bd 100644 --- a/src/sage/schemes/affine/affine_morphism.py +++ b/src/sage/schemes/affine/affine_morphism.py @@ -62,12 +62,11 @@ from sage.arith.all import gcd from sage.rings.integer import Integer -from sage.rings.finite_rings.finite_field_constructor import is_PrimeFiniteField from sage.rings.fraction_field import FractionField from sage.rings.fraction_field_element import FractionFieldElement from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.schemes.generic.morphism import SchemeMorphism_polynomial @@ -229,7 +228,8 @@ def __init__(self, parent, polys, check=True): SchemeMorphism_polynomial.__init__(self, parent, polys, check) # used in _fast_eval and _fastpolys - self._is_prime_finite_field = is_PrimeFiniteField(polys[0].base_ring()) + R = polys[0].base_ring() + self._is_prime_finite_field = isinstance(R, FiniteField) and R.is_prime_field() def __call__(self, x, check=True): """ @@ -683,7 +683,7 @@ def as_dynamical_system(self): R = self.base_ring() if R not in _Fields: return DynamicalSystem_affine(list(self), self.domain()) - if is_FiniteField(R): + if isinstance(R, FiniteField): return DynamicalSystem_affine_finite_field(list(self), self.domain()) return DynamicalSystem_affine_field(list(self), self.domain()) diff --git a/src/sage/schemes/affine/affine_space.py b/src/sage/schemes/affine/affine_space.py index ba56ef9fc8d..52c13b29068 100644 --- a/src/sage/schemes/affine/affine_space.py +++ b/src/sage/schemes/affine/affine_space.py @@ -17,7 +17,7 @@ from sage.rings.rational_field import is_RationalField from sage.rings.polynomial.polynomial_ring import is_PolynomialRing from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.categories.map import Map from sage.categories.fields import Fields from sage.categories.homset import Hom @@ -132,7 +132,7 @@ def AffineSpace(n, R=None, names=None, ambient_projective_space=None, from sage.schemes.projective.projective_space import ProjectiveSpace ambient_projective_space = ProjectiveSpace(n, R) if R in _Fields: - if is_FiniteField(R): + if isinstance(R, FiniteField): return AffineSpace_finite_field(n, R, names, ambient_projective_space, default_embedding_index) else: @@ -270,12 +270,12 @@ def rational_points(self, F=None): TypeError: second argument (= Integer Ring) must be a finite field """ if F is None: - if not is_FiniteField(self.base_ring()): - raise TypeError("base ring (= %s) must be a finite field"%self.base_ring()) - return [ P for P in self ] - elif not is_FiniteField(F): - raise TypeError("second argument (= %s) must be a finite field"%F) - return [ P for P in self.base_extend(F) ] + if not isinstance(self.base_ring(), FiniteField): + raise TypeError("base ring (= %s) must be a finite field" % self.base_ring()) + return [P for P in self] + elif not isinstance(F, FiniteField): + raise TypeError("second argument (= %s) must be a finite field" % F) + return [P for P in self.base_extend(F)] def __eq__(self, right): """ diff --git a/src/sage/schemes/curves/constructor.py b/src/sage/schemes/curves/constructor.py index 8a85dd9737c..9da795ac958 100644 --- a/src/sage/schemes/curves/constructor.py +++ b/src/sage/schemes/curves/constructor.py @@ -38,7 +38,7 @@ from sage.rings.polynomial.multi_polynomial_element import is_MPolynomial from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.rational_field import QQ @@ -294,7 +294,7 @@ def Curve(F, A=None): if is_AffineSpace(A): if n != 2: - if is_FiniteField(k): + if isinstance(k, FiniteField): if A.coordinate_ring().ideal(F).is_prime(): return IntegralAffineCurve_finite_field(A, F) if k in Fields(): @@ -307,7 +307,7 @@ def Curve(F, A=None): raise TypeError("need a single nonconstant polynomial to define a plane curve") F = F[0] - if is_FiniteField(k): + if isinstance(k, FiniteField): if _is_irreducible_and_reduced(F): return IntegralAffinePlaneCurve_finite_field(A, F) return AffinePlaneCurve_finite_field(A, F) @@ -321,7 +321,7 @@ def Curve(F, A=None): if n != 2: if not all(f.is_homogeneous() for f in F): raise TypeError("polynomials defining a curve in a projective space must be homogeneous") - if is_FiniteField(k): + if isinstance(k, FiniteField): if A.coordinate_ring().ideal(F).is_prime(): return IntegralProjectiveCurve_finite_field(A, F) if k in Fields(): @@ -339,7 +339,7 @@ def Curve(F, A=None): if not F.is_homogeneous(): raise TypeError("{} is not a homogeneous polynomial".format(F)) - if is_FiniteField(k): + if isinstance(k, FiniteField): if _is_irreducible_and_reduced(F): return IntegralProjectivePlaneCurve_finite_field(A, F) return ProjectivePlaneCurve_finite_field(A, F) diff --git a/src/sage/schemes/cyclic_covers/constructor.py b/src/sage/schemes/cyclic_covers/constructor.py index 0966b0793d5..aba10277b19 100644 --- a/src/sage/schemes/cyclic_covers/constructor.py +++ b/src/sage/schemes/cyclic_covers/constructor.py @@ -9,7 +9,7 @@ # ***************************************************************************** from sage.rings.polynomial.polynomial_element import is_Polynomial -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.schemes.affine.affine_space import AffineSpace from .cycliccover_generic import CyclicCover_generic from .cycliccover_finite_field import CyclicCover_finite_field @@ -127,7 +127,7 @@ def CyclicCover(r, f, names=None, check_smooth=True): names = ["x", "y"] A2 = AffineSpace(2, R, names=names) - if is_FiniteField(R): + if isinstance(R, FiniteField): return CyclicCover_finite_field(A2, r, f, names=names) else: return CyclicCover_generic(A2, r, f, names=names) diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index 1ecdc082cd5..931779c8c7a 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -27,7 +27,7 @@ import sage.rings.abc from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.number_field.number_field import is_NumberField from sage.rings.polynomial.multi_polynomial_element import is_MPolynomial from sage.rings.ring import is_Ring @@ -477,7 +477,7 @@ def create_object(self, version, key, **kwds): elif isinstance(R, sage.rings.abc.pAdicField): from .ell_padic_field import EllipticCurve_padic_field return EllipticCurve_padic_field(R, x) - elif is_FiniteField(R) or (isinstance(R, sage.rings.abc.IntegerModRing) and R.characteristic().is_prime()): + elif isinstance(R, FiniteField) or (isinstance(R, sage.rings.abc.IntegerModRing) and R.characteristic().is_prime()): from .ell_finite_field import EllipticCurve_finite_field return EllipticCurve_finite_field(R, x) elif R in _Fields: diff --git a/src/sage/schemes/generic/algebraic_scheme.py b/src/sage/schemes/generic/algebraic_scheme.py index 60d883905fe..aac33ed3042 100644 --- a/src/sage/schemes/generic/algebraic_scheme.py +++ b/src/sage/schemes/generic/algebraic_scheme.py @@ -132,7 +132,7 @@ from sage.rings.integer_ring import ZZ from sage.rings.qqbar import QQbar from sage.rings.rational_field import is_RationalField -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.number_field.order import is_NumberFieldOrder from sage.misc.latex import latex @@ -886,7 +886,7 @@ def rational_points(self, **kwds): if bound == 0: if is_RationalField(F): raise TypeError("A positive bound (= %s) must be specified."%bound) - if not is_FiniteField(F): + if not isinstance(F, FiniteField): raise TypeError("Argument F (= %s) must be a finite field."%F) pts = [] for P in self.ambient_space().rational_points(F): diff --git a/src/sage/schemes/hyperelliptic_curves/constructor.py b/src/sage/schemes/hyperelliptic_curves/constructor.py index 54556e08755..590677e21a9 100644 --- a/src/sage/schemes/hyperelliptic_curves/constructor.py +++ b/src/sage/schemes/hyperelliptic_curves/constructor.py @@ -24,7 +24,7 @@ import sage.rings.abc from sage.rings.rational_field import is_RationalField -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.polynomial.polynomial_element import is_Polynomial from sage.structure.dynamic_class import dynamic_class diff --git a/src/sage/schemes/plane_conics/constructor.py b/src/sage/schemes/plane_conics/constructor.py index a2a14190087..a962a392a63 100644 --- a/src/sage/schemes/plane_conics/constructor.py +++ b/src/sage/schemes/plane_conics/constructor.py @@ -31,7 +31,7 @@ from sage.rings.ring import IntegralDomain from sage.rings.rational_field import is_RationalField -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.polynomial.multi_polynomial_element import is_MPolynomial from sage.rings.polynomial.polynomial_ring import is_PolynomialRing from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing @@ -233,7 +233,7 @@ def Conic(base_field, F=None, names=None, unique=True): if F.parent().ngens() == 3: P2 = ProjectiveSpace(2, base_field, names) - if is_FiniteField(base_field): + if isinstance(base_field, FiniteField): return ProjectiveConic_finite_field(P2, F) if is_RationalField(base_field): return ProjectiveConic_rational_field(P2, F) diff --git a/src/sage/schemes/product_projective/homset.py b/src/sage/schemes/product_projective/homset.py index 7f4e1de0773..2b0119b1250 100644 --- a/src/sage/schemes/product_projective/homset.py +++ b/src/sage/schemes/product_projective/homset.py @@ -22,7 +22,7 @@ from sage.categories.number_fields import NumberFields from sage.misc.mrange import xmrange from sage.misc.misc_c import prod -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.rational_field import is_RationalField from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_subscheme from sage.schemes.generic.homset import SchemeHomset_points @@ -228,7 +228,7 @@ def points(self, **kwds): raise TypeError("a positive bound B (= %s) must be specified"%B) from sage.schemes.product_projective.rational_point import enum_product_projective_number_field return enum_product_projective_number_field(self, bound=B) - elif is_FiniteField(R): + elif isinstance(R, FiniteField): from sage.schemes.product_projective.rational_point import enum_product_projective_finite_field return enum_product_projective_finite_field(self) else: diff --git a/src/sage/schemes/product_projective/space.py b/src/sage/schemes/product_projective/space.py index 79bd69f671e..ac94e72cd0c 100644 --- a/src/sage/schemes/product_projective/space.py +++ b/src/sage/schemes/product_projective/space.py @@ -45,7 +45,7 @@ from sage.rings.integer import Integer from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational_field import QQ -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.categories.fields import Fields from sage.categories.commutative_rings import CommutativeRings from sage.rings.polynomial.polydict import ETuple @@ -137,7 +137,7 @@ def ProductProjectiveSpaces(n, R=None, names='x'): raise AttributeError("components must be over the same base ring") N.append(PS.dimension_relative()) names += PS.variable_names() - if is_FiniteField(R): + if isinstance(R, FiniteField): X = ProductProjectiveSpaces_finite_field(N, R, names) elif R in Fields(): X = ProductProjectiveSpaces_field(N, R, names) @@ -162,7 +162,7 @@ def ProductProjectiveSpaces(n, R=None, names='x'): else: n_vars = sum(1+d for d in n) names = normalize_names(n_vars, name_list) - if is_FiniteField(R): + if isinstance(R, FiniteField): X = ProductProjectiveSpaces_finite_field(n, R, names) elif R in Fields(): X = ProductProjectiveSpaces_field(n, R, names) @@ -1302,6 +1302,6 @@ def rational_points(self, F=None): """ if F is None: return list(self) - elif not is_FiniteField(F): + elif not isinstance(F, FiniteField): raise TypeError("second argument (= %s) must be a finite field"%F) return list(self.base_extend(F)) diff --git a/src/sage/schemes/projective/projective_homset.py b/src/sage/schemes/projective/projective_homset.py index 3ffd4a6b6e4..3ee0b78876e 100644 --- a/src/sage/schemes/projective/projective_homset.py +++ b/src/sage/schemes/projective/projective_homset.py @@ -47,7 +47,7 @@ from sage.rings.rational_field import is_RationalField from sage.categories.fields import Fields from sage.categories.number_fields import NumberFields -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_subscheme from copy import copy @@ -284,7 +284,7 @@ def points(self, **kwds): raise TypeError("a positive bound B (= %s) must be specified"%B) from sage.schemes.projective.projective_rational_point import enum_projective_number_field return enum_projective_number_field(self, bound=B, tolerance=tol, precision=prec) - elif is_FiniteField(R): + elif isinstance(R, FiniteField): from sage.schemes.projective.projective_rational_point import enum_projective_finite_field return enum_projective_finite_field(self.extended_codomain()) else: diff --git a/src/sage/schemes/projective/projective_morphism.py b/src/sage/schemes/projective/projective_morphism.py index 30afbb10ab1..45c1bb01b55 100644 --- a/src/sage/schemes/projective/projective_morphism.py +++ b/src/sage/schemes/projective/projective_morphism.py @@ -72,8 +72,7 @@ import sage.rings.abc from sage.rings.integer import Integer 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_constructor import 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.fraction_field import FractionField from sage.rings.integer_ring import ZZ @@ -274,7 +273,8 @@ def __init__(self, parent, polys, check=True): SchemeMorphism_polynomial.__init__(self, parent, polys, check) - self._is_prime_finite_field = is_PrimeFiniteField(polys[0].base_ring()) + R = polys[0].base_ring() + self._is_prime_finite_field = isinstance(R, FiniteField) and R.is_prime_field() def __call__(self, x, check=True): r""" @@ -727,7 +727,7 @@ def as_dynamical_system(self): R = self.base_ring() if R not in _Fields: return DynamicalSystem_projective(list(self), self.domain()) - if is_FiniteField(R): + if isinstance(R, FiniteField): return DynamicalSystem_projective_finite_field(list(self), self.domain()) return DynamicalSystem_projective_field(list(self), self.domain()) @@ -1006,7 +1006,7 @@ def normalize_coordinates(self, **kwds): # scales by 1/gcd of the coefficients. if R in _NumberFields: O = R.maximal_order() - elif is_FiniteField(R): + elif isinstance(R, FiniteField): O = R elif isinstance(R, QuotientRing_generic): O = R.ring() diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py index 670304af237..e215da942e1 100644 --- a/src/sage/schemes/projective/projective_space.py +++ b/src/sage/schemes/projective/projective_space.py @@ -81,7 +81,7 @@ from sage.arith.misc import gcd, binomial -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing @@ -256,7 +256,7 @@ def ProjectiveSpace(n, R=None, names=None): if R is None: R = ZZ # default is the integers if R in _Fields: - if is_FiniteField(R): + if isinstance(R, FiniteField): return ProjectiveSpace_finite_field(n, R, names) if is_RationalField(R): return ProjectiveSpace_rational_field(n, R, names) @@ -2253,7 +2253,7 @@ def rational_points(self, F=None): """ if F is None: return [P for P in self] - elif not is_FiniteField(F): + elif not isinstance(F, FiniteField): raise TypeError("second argument (= %s) must be a finite field" % F) return [P for P in self.base_extend(F)] diff --git a/src/sage/schemes/projective/projective_subscheme.py b/src/sage/schemes/projective/projective_subscheme.py index 3c0faa498a6..2d7bdf2974a 100644 --- a/src/sage/schemes/projective/projective_subscheme.py +++ b/src/sage/schemes/projective/projective_subscheme.py @@ -29,7 +29,7 @@ from sage.matrix.constructor import matrix from sage.rings.integer_ring import ZZ -from sage.rings.finite_rings.finite_field_constructor import is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational_field import is_RationalField @@ -982,7 +982,7 @@ def dual(self): from sage.libs.singular.function_factory import ff K = self.base_ring() - if not(is_RationalField(K) or is_FiniteField(K)): + if not(is_RationalField(K) or isinstance(K, FiniteField)): raise NotImplementedError("base ring must be QQ or a finite field") I = self.defining_ideal() m = I.ngens() diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index 2036a7331d4..9ecb93578d8 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -217,7 +217,7 @@ cdef class SymbolicRing(sage.rings.abc.SymbolicRing): from sage.rings.complex_mpfr import ComplexField from sage.rings.infinity import InfinityRing, UnsignedInfinityRing from sage.rings.real_lazy import RLF, CLF - from sage.rings.finite_rings.finite_field_base import is_FiniteField + from sage.rings.finite_rings.finite_field_base import FiniteField from sage.interfaces.maxima import Maxima @@ -235,7 +235,7 @@ cdef class SymbolicRing(sage.rings.abc.SymbolicRing): sage.rings.abc.RealBallField, sage.rings.abc.ComplexBallField, sage.rings.abc.IntegerModRing)) - or is_FiniteField(R)): + or isinstance(R, FiniteField)): return True elif isinstance(R, GenericSymbolicSubring): return True From 8d4d8e58683173fc9b452f9f3a8d764785ba1b36 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 14:46:10 -0800 Subject: [PATCH 02/10] sage.rings.finite_rings: Make it a namespace package --- src/.relint.yml | 2 +- src/sage/rings/finite_rings/__init__.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 src/sage/rings/finite_rings/__init__.py diff --git a/src/.relint.yml b/src/.relint.yml index abadae0de28..d1534abfdd2 100644 --- a/src/.relint.yml +++ b/src/.relint.yml @@ -47,6 +47,6 @@ hint: | Sage library code should not import from sage.PAC.KAGE.all when sage.PAC.KAGE is an implicit Hint: namespace package. Type import_statements("SOME_IDENTIFIER") to find a more specific import. - 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 diff --git a/src/sage/rings/finite_rings/__init__.py b/src/sage/rings/finite_rings/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 From 6ce26bc9f01f71faeb4a144a67b8487671cc45f5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 15:16:51 -0800 Subject: [PATCH 03/10] src/sage/rings/finite_rings/finite_field_constructor.py: Restore re-export of is_FiniteField --- src/sage/rings/finite_rings/finite_field_constructor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/finite_rings/finite_field_constructor.py b/src/sage/rings/finite_rings/finite_field_constructor.py index 544e8125880..a264e86ecd5 100644 --- a/src/sage/rings/finite_rings/finite_field_constructor.py +++ b/src/sage/rings/finite_rings/finite_field_constructor.py @@ -177,7 +177,7 @@ from sage.rings.integer import Integer # the import below is just a redirection -from sage.rings.finite_rings.finite_field_base import FiniteField +from sage.rings.finite_rings.finite_field_base import is_FiniteField assert is_FiniteField # just to silent pyflakes try: From 98a5484775ac1ec596baa9a3739499cf22cc61f0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 15:28:53 -0800 Subject: [PATCH 04/10] src/sage/rings/finite_rings/hom_finite_field.pyx: Import ABC as FiniteField_base --- src/sage/rings/finite_rings/hom_finite_field.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/finite_rings/hom_finite_field.pyx b/src/sage/rings/finite_rings/hom_finite_field.pyx index 55f2cac6a1d..44dc3450be8 100644 --- a/src/sage/rings/finite_rings/hom_finite_field.pyx +++ b/src/sage/rings/finite_rings/hom_finite_field.pyx @@ -106,7 +106,7 @@ from sage.rings.integer cimport Integer from sage.categories.homset import Hom from sage.structure.element cimport Element -from sage.rings.finite_rings.finite_field_base import FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField as FiniteField_base from sage.rings.morphism cimport RingHomomorphism, RingHomomorphism_im_gens, FrobeniusEndomorphism_generic from sage.rings.finite_rings.finite_field_constructor import FiniteField @@ -227,9 +227,9 @@ cdef class FiniteFieldHomomorphism_generic(RingHomomorphism_im_gens): """ domain = parent.domain() codomain = parent.codomain() - if not isinstance(domain, FiniteField): + if not isinstance(domain, FiniteField_base): raise TypeError("The domain is not a finite field or does not provide the required interface for finite fields") - if not isinstance(codomain, FiniteField): + if not isinstance(codomain, FiniteField_base): raise TypeError("The codomain is not a finite field or does not provide the required interface for finite fields") if domain.characteristic() != codomain.characteristic() or codomain.degree() % domain.degree() != 0: raise ValueError("No embedding of %s into %s" % (domain, codomain)) @@ -522,7 +522,7 @@ cdef class FrobeniusEndomorphism_finite_field(FrobeniusEndomorphism_generic): ... TypeError: The domain is not a finite field or does not provide the required interface for finite fields """ - if not isinstance(domain, FiniteField): + if not isinstance(domain, FiniteField_base): raise TypeError("The domain is not a finite field or does not provide the required interface for finite fields") try: n = Integer(n) From 2e6b5efe57a925b6bd5c2d9b8ad49f7718e05af7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 15:29:18 -0800 Subject: [PATCH 05/10] sage.rings.finite_rings: Deprecate is_FiniteFieldElent --- src/sage/crypto/mq/rijndael_gf.py | 12 +++--------- src/sage/crypto/sbox.pyx | 5 ++--- .../dynamics/arithmetic_dynamics/projective_ds.py | 1 + src/sage/rings/algebraic_closure_finite_field.py | 3 +-- src/sage/rings/finite_rings/element_base.pyx | 8 +++++++- src/sage/rings/padics/padic_template_element.pxi | 5 +++-- src/sage/schemes/elliptic_curves/ell_finite_field.py | 5 +++-- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/sage/crypto/mq/rijndael_gf.py b/src/sage/crypto/mq/rijndael_gf.py index 154c84d146c..1e08fb8e998 100644 --- a/src/sage/crypto/mq/rijndael_gf.py +++ b/src/sage/crypto/mq/rijndael_gf.py @@ -424,7 +424,7 @@ from sage.matrix.constructor import matrix from sage.matrix.constructor import column_matrix -from sage.structure.element import Matrix +from sage.structure.element import FieldElement, Matrix 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 @@ -757,10 +757,7 @@ 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): + if not isinstance(GF, (Matrix, list, FieldElement)): 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)) @@ -883,10 +880,7 @@ 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): + if not isinstance(GF, (Matrix, list, FieldElement)): 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)) diff --git a/src/sage/crypto/sbox.pyx b/src/sage/crypto/sbox.pyx index 77b7a904cc2..fb9a6f39da3 100644 --- a/src/sage/crypto/sbox.pyx +++ b/src/sage/crypto/sbox.pyx @@ -5,7 +5,7 @@ cimport cython from cysignals.memory cimport check_allocarray, sig_free from sage.structure.sage_object cimport SageObject -from sage.structure.element cimport Element +from sage.structure.element cimport Element, FieldElement from sage.combinat.integer_vector import IntegerVectors from sage.crypto.boolean_function import BooleanFunction @@ -17,7 +17,6 @@ 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_constructor import FiniteField as GF from sage.rings.ideal import FieldIdeal, Ideal from sage.rings.integer_ring import ZZ @@ -195,7 +194,7 @@ cdef class SBox(SageObject): _S_list = [] for e in S: - if is_FiniteFieldElement(e): + if isinstance(e, FieldElement) and e.parent().is_finite(): e = e.polynomial().change_ring(ZZ).subs(e.parent().characteristic()) _S_list.append(e) S = _S_list diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index 30b11ce4261..eb18d2fd0d3 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -73,6 +73,7 @@ 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_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) diff --git a/src/sage/rings/algebraic_closure_finite_field.py b/src/sage/rings/algebraic_closure_finite_field.py index 8577f1c613e..5d05d77a9c7 100644 --- a/src/sage/rings/algebraic_closure_finite_field.py +++ b/src/sage/rings/algebraic_closure_finite_field.py @@ -57,7 +57,6 @@ from sage.misc.abstract_method import abstract_method from sage.misc.fast_methods import WithEqualityById -from sage.rings.finite_rings.element_base import is_FiniteFieldElement from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.ring import Field from sage.structure.element import FieldElement @@ -91,7 +90,7 @@ def __init__(self, parent, value): and ``loads(dumps(x))``. """ - if is_FiniteFieldElement(value): + if isinstance(value, FieldElement) and value.parent().is_finite(): n = value.parent().degree() else: from sage.rings.integer import Integer diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index 02ca50d18d1..d92fbb792d2 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -25,18 +25,24 @@ from sage.misc.superseded import deprecated_function_alias def is_FiniteFieldElement(x): """ - Returns if x is a finite field element. + Return True if ``x`` is a finite field element. + + This function is deprecated. EXAMPLES:: sage: from sage.rings.finite_rings.element_base import is_FiniteFieldElement sage: is_FiniteFieldElement(1) + doctest:...: DeprecationWarning: the function is_FiniteFieldElement is deprecated; use isinstance(x, sage.structure.element.FieldElement) and x.parent().is_finite() instead False sage: is_FiniteFieldElement(IntegerRing()) False sage: is_FiniteFieldElement(GF(5)(2)) True """ + from sage.misc.superseded import deprecation + deprecation(32664, "the function is_FiniteFieldElement is deprecated; use isinstance(x, sage.structure.element.FieldElement) and x.parent().is_finite() instead") + from sage.rings.finite_rings.finite_field_base import FiniteField return isinstance(x, Element) and isinstance(x.parent(), FiniteField) diff --git a/src/sage/rings/padics/padic_template_element.pxi b/src/sage/rings/padics/padic_template_element.pxi index fed8ac89f81..2356fe9b2e6 100644 --- a/src/sage/rings/padics/padic_template_element.pxi +++ b/src/sage/rings/padics/padic_template_element.pxi @@ -30,13 +30,14 @@ import sage.rings.finite_rings.integer_mod from cypari2.types cimport * from cypari2.gen cimport Gen as pari_gen from sage.libs.pari.convert_gmp cimport INT_to_mpz +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.padics.common_conversion cimport get_ordp, get_preccap from sage.rings.integer cimport Integer from sage.rings.infinity import infinity from sage.rings.rational import Rational from sage.rings.padics.precision_error import PrecisionError from sage.rings.padics.misc import trim_zeros -from sage.structure.element import canonical_coercion +from sage.structure.element import canonical_coercion, FieldElement import itertools cdef long maxordp = (1L << (sizeof(long) * 8 - 2)) - 1 @@ -145,7 +146,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement): elif sage.rings.finite_rings.integer_mod.is_IntegerMod(x): if not Integer(self.prime_pow.prime).divides(x.parent().order()): raise TypeError("p does not divide modulus %s"%x.parent().order()) - elif sage.rings.finite_rings.element_base.is_FiniteFieldElement(x): + elif isinstance(x, FieldElement) and isinstance(x.parent(), FiniteField): k = self.parent().residue_field() if not k.has_coerce_map_from(x.parent()): raise NotImplementedError("conversion from finite fields which do not embed into the residue field not implemented") diff --git a/src/sage/schemes/elliptic_curves/ell_finite_field.py b/src/sage/schemes/elliptic_curves/ell_finite_field.py index 6676a1964c2..bd7aaf44c09 100644 --- a/src/sage/schemes/elliptic_curves/ell_finite_field.py +++ b/src/sage/schemes/elliptic_curves/ell_finite_field.py @@ -29,7 +29,8 @@ from .constructor import EllipticCurve from sage.schemes.hyperelliptic_curves.hyperelliptic_finite_field import HyperellipticCurve_finite_field from sage.rings.all import Integer, ZZ, PolynomialRing, GF, polygen -from sage.rings.finite_rings.element_base import is_FiniteFieldElement +from sage.rings.finite_rings.finite_field_base import FiniteField +from sage.structure.element import FieldElement import sage.groups.generic as generic from . import ell_point from sage.arith.all import gcd, lcm, binomial @@ -1529,7 +1530,7 @@ def is_j_supersingular(j, proof=True): sage: [p for p in prime_range(100) if is_j_supersingular(GF(p)(123456))] [2, 3, 59, 89] """ - if not is_FiniteFieldElement(j): + if not (isinstance(j, FieldElement) and isinstance(j.parent(), FiniteField)): raise ValueError("%s must be an element of a finite field" % j) F = j.parent() From 3be7c975fb00896aef21d721eda69d6d22759385 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 16:30:09 -0800 Subject: [PATCH 06/10] Fixups --- src/sage/modules/free_module.py | 4 ++-- src/sage/rings/finite_rings/element_base.pyx | 1 + src/sage/rings/finite_rings/finite_field_base.pyx | 1 + src/sage/rings/finite_rings/finite_field_constructor.py | 2 ++ src/sage/schemes/hyperelliptic_curves/constructor.py | 6 +++++- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index ff916cc4ad2..6b2f5b87b27 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -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 @@ -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, @@ -6348,7 +6348,7 @@ def _element_constructor_(self, e, *args, **kwds): """ try: k = e.parent() - if finite_field.isinstance(k, FiniteField) 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 diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index d92fbb792d2..17ca80e9028 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -34,6 +34,7 @@ def is_FiniteFieldElement(x): sage: from sage.rings.finite_rings.element_base import is_FiniteFieldElement sage: is_FiniteFieldElement(1) doctest:...: DeprecationWarning: the function is_FiniteFieldElement is deprecated; use isinstance(x, sage.structure.element.FieldElement) and x.parent().is_finite() instead + See https://trac.sagemath.org/32664 for details. False sage: is_FiniteFieldElement(IntegerRing()) False diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index d13c93f23be..09959aeae49 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -2122,6 +2122,7 @@ def is_FiniteField(R): sage: from sage.rings.finite_rings.finite_field_base import FiniteField sage: is_FiniteField(GF(9,'a')) doctest:...: DeprecationWarning: the function is_FiniteField is deprecated; use isinstance(x, sage.rings.finite_rings.finite_field_base.FiniteField) instead + See https://trac.sagemath.org/32664 for details. True sage: is_FiniteField(GF(next_prime(10^10))) True diff --git a/src/sage/rings/finite_rings/finite_field_constructor.py b/src/sage/rings/finite_rings/finite_field_constructor.py index a264e86ecd5..23ed63d8b30 100644 --- a/src/sage/rings/finite_rings/finite_field_constructor.py +++ b/src/sage/rings/finite_rings/finite_field_constructor.py @@ -797,8 +797,10 @@ def is_PrimeFiniteField(x): EXAMPLES:: + sage: from sage.rings.finite_rings.finite_field_constructor import is_PrimeFiniteField sage: is_PrimeFiniteField(QQ) doctest:...: DeprecationWarning: the function is_PrimeFiniteField is deprecated; use isinstance(x, sage.rings.finite_rings.finite_field_base.FiniteField) and x.is_prime_field() instead + See https://trac.sagemath.org/32664 for details. False sage: is_PrimeFiniteField(GF(7)) True diff --git a/src/sage/schemes/hyperelliptic_curves/constructor.py b/src/sage/schemes/hyperelliptic_curves/constructor.py index 590677e21a9..21afb10ef3a 100644 --- a/src/sage/schemes/hyperelliptic_curves/constructor.py +++ b/src/sage/schemes/hyperelliptic_curves/constructor.py @@ -249,7 +249,11 @@ def HyperellipticCurve(f, h=0, names=None, PP=None, check_squarefree=True): genus_classes = {2: HyperellipticCurve_g2} - is_pAdicField = lambda x: isinstance(x, sage.rings.abc.pAdicField) + def is_FiniteField(x): + return isinstance(x, FiniteField) + + def is_pAdicField(x): + return isinstance(x, sage.rings.abc.pAdicField) fields = [ ("FiniteField", is_FiniteField, HyperellipticCurve_finite_field), From 97a363e8cc60fc67718fad16d16ce583f24a7e0d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 17:58:06 -0800 Subject: [PATCH 07/10] Fixups --- src/sage/interfaces/gap.py | 2 +- src/sage/rings/finite_rings/finite_field_base.pyx | 2 +- src/sage/rings/finite_rings/finite_field_ntl_gf2e.py | 1 + src/sage/rings/finite_rings/hom_prime_finite_field.pyx | 2 +- src/sage/symbolic/ring.pyx | 4 ++-- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sage/interfaces/gap.py b/src/sage/interfaces/gap.py index c80a847d7e9..e105d5845ca 100644 --- a/src/sage/interfaces/gap.py +++ b/src/sage/interfaces/gap.py @@ -1743,7 +1743,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 from sage.rings.finite_rings.integer_mod import Mod from sage.rings.integer import Integer s = str(x) diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index 09959aeae49..470bbdf0502 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -2119,7 +2119,7 @@ def is_FiniteField(R): EXAMPLES:: - sage: from sage.rings.finite_rings.finite_field_base import FiniteField + sage: from sage.rings.finite_rings.finite_field_base import is_FiniteField sage: is_FiniteField(GF(9,'a')) doctest:...: DeprecationWarning: the function is_FiniteField is deprecated; use isinstance(x, sage.rings.finite_rings.finite_field_base.FiniteField) instead See https://trac.sagemath.org/32664 for details. diff --git a/src/sage/rings/finite_rings/finite_field_ntl_gf2e.py b/src/sage/rings/finite_rings/finite_field_ntl_gf2e.py index 82004502674..47723af64bd 100644 --- a/src/sage/rings/finite_rings/finite_field_ntl_gf2e.py +++ b/src/sage/rings/finite_rings/finite_field_ntl_gf2e.py @@ -52,6 +52,7 @@ def late_import(): import sage.rings.polynomial.polynomial_element is_Polynomial = sage.rings.polynomial.polynomial_element.is_Polynomial + class FiniteField_ntl_gf2e(FiniteField): """ Finite Field of characteristic 2 and order `2^n`. diff --git a/src/sage/rings/finite_rings/hom_prime_finite_field.pyx b/src/sage/rings/finite_rings/hom_prime_finite_field.pyx index 8120f5a4cd6..617595ea383 100644 --- a/src/sage/rings/finite_rings/hom_prime_finite_field.pyx +++ b/src/sage/rings/finite_rings/hom_prime_finite_field.pyx @@ -33,7 +33,7 @@ from .hom_finite_field cimport SectionFiniteFieldHomomorphism_generic from .hom_finite_field cimport FiniteFieldHomomorphism_generic from .hom_finite_field cimport FrobeniusEndomorphism_finite_field -from sage.rings.finite_rings.finite_field_base import FiniteField, is_FiniteField +from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.morphism cimport RingHomomorphism_im_gens diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index 9ecb93578d8..ce033910621 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -234,8 +234,8 @@ cdef class SymbolicRing(sage.rings.abc.SymbolicRing): sage.rings.abc.ComplexIntervalField, sage.rings.abc.RealBallField, sage.rings.abc.ComplexBallField, - sage.rings.abc.IntegerModRing)) - or isinstance(R, FiniteField)): + sage.rings.abc.IntegerModRing, + FiniteField))): return True elif isinstance(R, GenericSymbolicSubring): return True From 0c014033f33a907da6ba7c48224102e0ddd82af3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 18:53:12 -0800 Subject: [PATCH 08/10] Fixup: Elements of finite fields are not instances of FieldElement --- src/sage/crypto/mq/rijndael_gf.py | 10 +++++++--- src/sage/crypto/sbox.pyx | 5 +++-- src/sage/rings/algebraic_closure_finite_field.py | 4 ++-- src/sage/rings/padics/padic_template_element.pxi | 4 ++-- src/sage/schemes/elliptic_curves/ell_finite_field.py | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/sage/crypto/mq/rijndael_gf.py b/src/sage/crypto/mq/rijndael_gf.py index 1e08fb8e998..2dccf6b03b4 100644 --- a/src/sage/crypto/mq/rijndael_gf.py +++ b/src/sage/crypto/mq/rijndael_gf.py @@ -424,7 +424,7 @@ from sage.matrix.constructor import matrix from sage.matrix.constructor import column_matrix -from sage.structure.element import FieldElement, Matrix +from sage.structure.element import Element, Matrix 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 @@ -757,7 +757,9 @@ def _GF_to_hex(self, GF): sage: rgf._GF_to_hex(output) 'e142cd5fcd9d6d94a3340793034391b5' """ - if not isinstance(GF, (Matrix, list, FieldElement)): + if not isinstance(GF, Matrix) and \ + not isinstance(GF, list) and \ + not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField)): 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)) @@ -880,7 +882,9 @@ def _GF_to_bin(self, GF): sage: rgf._GF_to_bin(output) '11011000000111111111100000011011110110000001111111111000000110111101100000011111111110000001101111011000000111111111100000011011' """ - if not isinstance(GF, (Matrix, list, FieldElement)): + if not isinstance(GF, Matrix) and \ + not isinstance(GF, list) and \ + not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField)): 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)) diff --git a/src/sage/crypto/sbox.pyx b/src/sage/crypto/sbox.pyx index fb9a6f39da3..87683d79517 100644 --- a/src/sage/crypto/sbox.pyx +++ b/src/sage/crypto/sbox.pyx @@ -5,7 +5,7 @@ cimport cython from cysignals.memory cimport check_allocarray, sig_free from sage.structure.sage_object cimport SageObject -from sage.structure.element cimport Element, FieldElement +from sage.structure.element cimport Element from sage.combinat.integer_vector import IntegerVectors from sage.crypto.boolean_function import BooleanFunction @@ -17,6 +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.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 @@ -194,7 +195,7 @@ cdef class SBox(SageObject): _S_list = [] for e in S: - if isinstance(e, FieldElement) and e.parent().is_finite(): + 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 diff --git a/src/sage/rings/algebraic_closure_finite_field.py b/src/sage/rings/algebraic_closure_finite_field.py index 5d05d77a9c7..c527bcb6dc4 100644 --- a/src/sage/rings/algebraic_closure_finite_field.py +++ b/src/sage/rings/algebraic_closure_finite_field.py @@ -59,7 +59,7 @@ from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.ring import Field -from sage.structure.element import FieldElement +from sage.structure.element import Element, FieldElement from sage.structure.richcmp import richcmp @@ -90,7 +90,7 @@ def __init__(self, parent, value): and ``loads(dumps(x))``. """ - if isinstance(value, FieldElement) and value.parent().is_finite(): + if isinstance(value, Element) and isinstance(value.parent(), FiniteField): n = value.parent().degree() else: from sage.rings.integer import Integer diff --git a/src/sage/rings/padics/padic_template_element.pxi b/src/sage/rings/padics/padic_template_element.pxi index 2356fe9b2e6..72ff7784eb1 100644 --- a/src/sage/rings/padics/padic_template_element.pxi +++ b/src/sage/rings/padics/padic_template_element.pxi @@ -37,7 +37,7 @@ from sage.rings.infinity import infinity from sage.rings.rational import Rational from sage.rings.padics.precision_error import PrecisionError from sage.rings.padics.misc import trim_zeros -from sage.structure.element import canonical_coercion, FieldElement +from sage.structure.element import canonical_coercion, Element import itertools cdef long maxordp = (1L << (sizeof(long) * 8 - 2)) - 1 @@ -146,7 +146,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement): elif sage.rings.finite_rings.integer_mod.is_IntegerMod(x): if not Integer(self.prime_pow.prime).divides(x.parent().order()): raise TypeError("p does not divide modulus %s"%x.parent().order()) - elif isinstance(x, FieldElement) and isinstance(x.parent(), FiniteField): + elif isinstance(x, Element) and isinstance(x.parent(), FiniteField): k = self.parent().residue_field() if not k.has_coerce_map_from(x.parent()): raise NotImplementedError("conversion from finite fields which do not embed into the residue field not implemented") diff --git a/src/sage/schemes/elliptic_curves/ell_finite_field.py b/src/sage/schemes/elliptic_curves/ell_finite_field.py index bd7aaf44c09..863c56b22ea 100644 --- a/src/sage/schemes/elliptic_curves/ell_finite_field.py +++ b/src/sage/schemes/elliptic_curves/ell_finite_field.py @@ -30,7 +30,7 @@ from sage.schemes.hyperelliptic_curves.hyperelliptic_finite_field import HyperellipticCurve_finite_field from sage.rings.all import Integer, ZZ, PolynomialRing, GF, polygen from sage.rings.finite_rings.finite_field_base import FiniteField -from sage.structure.element import FieldElement +from sage.structure.element import Element import sage.groups.generic as generic from . import ell_point from sage.arith.all import gcd, lcm, binomial @@ -1530,7 +1530,7 @@ def is_j_supersingular(j, proof=True): sage: [p for p in prime_range(100) if is_j_supersingular(GF(p)(123456))] [2, 3, 59, 89] """ - if not (isinstance(j, FieldElement) and isinstance(j.parent(), FiniteField)): + if not (isinstance(j, Element) and isinstance(j.parent(), FiniteField)): raise ValueError("%s must be an element of a finite field" % j) F = j.parent() From 9f4d1c4bd227c145d964bff1a4f40305f780be2d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 5 Dec 2022 19:26:05 -0800 Subject: [PATCH 09/10] src/sage/crypto/mq/rijndael_gf.py: Fix imports --- src/sage/crypto/mq/rijndael_gf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sage/crypto/mq/rijndael_gf.py b/src/sage/crypto/mq/rijndael_gf.py index 2dccf6b03b4..6bcb86f4d21 100644 --- a/src/sage/crypto/mq/rijndael_gf.py +++ b/src/sage/crypto/mq/rijndael_gf.py @@ -425,6 +425,7 @@ from sage.matrix.constructor import matrix from sage.matrix.constructor import column_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 @@ -759,7 +760,7 @@ def _GF_to_hex(self, GF): """ if not isinstance(GF, Matrix) and \ not isinstance(GF, list) and \ - not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField)): + 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)) @@ -884,7 +885,7 @@ def _GF_to_bin(self, GF): """ if not isinstance(GF, Matrix) and \ not isinstance(GF, list) and \ - not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField)): + 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)) From 40a7d574bce11dcf62575c276a0aa8ac76c55e56 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 20 Feb 2023 18:37:07 -0800 Subject: [PATCH 10/10] src/sage/rings/finite_rings: Update doctest output (trac->github) --- src/sage/rings/finite_rings/element_base.pyx | 2 +- src/sage/rings/finite_rings/finite_field_base.pyx | 2 +- src/sage/rings/finite_rings/finite_field_constructor.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index 17ca80e9028..4f785ebf181 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -34,7 +34,7 @@ def is_FiniteFieldElement(x): sage: from sage.rings.finite_rings.element_base import is_FiniteFieldElement sage: is_FiniteFieldElement(1) doctest:...: DeprecationWarning: the function is_FiniteFieldElement is deprecated; use isinstance(x, sage.structure.element.FieldElement) and x.parent().is_finite() instead - See https://trac.sagemath.org/32664 for details. + See https://github.com/sagemath/sage/issues/32664 for details. False sage: is_FiniteFieldElement(IntegerRing()) False diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index 1ec0f276289..1bdb3f48bb1 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -2122,7 +2122,7 @@ def is_FiniteField(R): sage: from sage.rings.finite_rings.finite_field_base import is_FiniteField sage: is_FiniteField(GF(9,'a')) doctest:...: DeprecationWarning: the function is_FiniteField is deprecated; use isinstance(x, sage.rings.finite_rings.finite_field_base.FiniteField) instead - See https://trac.sagemath.org/32664 for details. + See https://github.com/sagemath/sage/issues/32664 for details. True sage: is_FiniteField(GF(next_prime(10^10))) True diff --git a/src/sage/rings/finite_rings/finite_field_constructor.py b/src/sage/rings/finite_rings/finite_field_constructor.py index 23ed63d8b30..9a3f55ab489 100644 --- a/src/sage/rings/finite_rings/finite_field_constructor.py +++ b/src/sage/rings/finite_rings/finite_field_constructor.py @@ -800,7 +800,7 @@ def is_PrimeFiniteField(x): sage: from sage.rings.finite_rings.finite_field_constructor import is_PrimeFiniteField sage: is_PrimeFiniteField(QQ) doctest:...: DeprecationWarning: the function is_PrimeFiniteField is deprecated; use isinstance(x, sage.rings.finite_rings.finite_field_base.FiniteField) and x.is_prime_field() instead - See https://trac.sagemath.org/32664 for details. + See https://github.com/sagemath/sage/issues/32664 for details. False sage: is_PrimeFiniteField(GF(7)) True