Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
sage.rings.finite_rings: Deprecate is_FiniteFieldElent
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Dec 5, 2022
1 parent 473e9d4 commit b82fb1e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
12 changes: 3 additions & 9 deletions src/sage/crypto/mq/rijndael_gf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions src/sage/crypto/sbox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/sage/rings/algebraic_closure_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/sage/rings/finite_rings/element_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ from sage.rings.integer import Integer

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)

Expand Down
5 changes: 3 additions & 2 deletions src/sage/rings/padics/padic_template_element.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions src/sage/schemes/elliptic_curves/ell_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1532,7 +1533,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()
Expand Down

0 comments on commit b82fb1e

Please sign in to comment.