Skip to content

Commit 2e6b5ef

Browse files
author
Matthias Koeppe
committed
sage.rings.finite_rings: Deprecate is_FiniteFieldElent
1 parent 98a5484 commit 2e6b5ef

File tree

7 files changed

+20
-19
lines changed

7 files changed

+20
-19
lines changed

src/sage/crypto/mq/rijndael_gf.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424

425425
from sage.matrix.constructor import matrix
426426
from sage.matrix.constructor import column_matrix
427-
from sage.structure.element import Matrix
427+
from sage.structure.element import FieldElement, Matrix
428428
from sage.rings.finite_rings.finite_field_constructor import FiniteField
429429
from sage.structure.sage_object import SageObject
430430
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
@@ -757,10 +757,7 @@ def _GF_to_hex(self, GF):
757757
sage: rgf._GF_to_hex(output)
758758
'e142cd5fcd9d6d94a3340793034391b5'
759759
"""
760-
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
761-
if not isinstance(GF, Matrix) and \
762-
not isinstance(GF, list) and \
763-
not is_FiniteFieldElement(GF):
760+
if not isinstance(GF, (Matrix, list, FieldElement)):
764761
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
765762
"elements from {0}, or a single element from {0}")
766763
raise TypeError(msg.format(self._F))
@@ -883,10 +880,7 @@ def _GF_to_bin(self, GF):
883880
sage: rgf._GF_to_bin(output)
884881
'11011000000111111111100000011011110110000001111111111000000110111101100000011111111110000001101111011000000111111111100000011011'
885882
"""
886-
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
887-
if not isinstance(GF, Matrix) and \
888-
not isinstance(GF, list) and \
889-
not is_FiniteFieldElement(GF):
883+
if not isinstance(GF, (Matrix, list, FieldElement)):
890884
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
891885
"elements from {0}, or a single element from {0}")
892886
raise TypeError(msg.format(self))

src/sage/crypto/sbox.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cimport cython
55
from cysignals.memory cimport check_allocarray, sig_free
66

77
from sage.structure.sage_object cimport SageObject
8-
from sage.structure.element cimport Element
8+
from sage.structure.element cimport Element, FieldElement
99

1010
from sage.combinat.integer_vector import IntegerVectors
1111
from sage.crypto.boolean_function import BooleanFunction
@@ -17,7 +17,6 @@ from sage.misc.functional import is_even
1717
from sage.misc.misc_c import prod as mul
1818
from sage.misc.superseded import deprecated_function_alias
1919
from sage.modules.free_module_element import vector
20-
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
2120
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
2221
from sage.rings.ideal import FieldIdeal, Ideal
2322
from sage.rings.integer_ring import ZZ
@@ -195,7 +194,7 @@ cdef class SBox(SageObject):
195194

196195
_S_list = []
197196
for e in S:
198-
if is_FiniteFieldElement(e):
197+
if isinstance(e, FieldElement) and e.parent().is_finite():
199198
e = e.polynomial().change_ring(ZZ).subs(e.parent().characteristic())
200199
_S_list.append(e)
201200
S = _S_list

src/sage/dynamics/arithmetic_dynamics/projective_ds.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class initialization directly.
7373
from sage.categories.finite_fields import FiniteFields
7474
from sage.rings.algebraic_closure_finite_field import AlgebraicClosureFiniteField_generic
7575
from sage.rings.complex_mpfr import ComplexField
76+
from sage.rings.finite_rings.finite_field_base import FiniteField
7677
from sage.rings.finite_rings.finite_field_constructor import GF
7778
from sage.rings.finite_rings.integer_mod_ring import Zmod
7879
from sage.rings.fraction_field import (FractionField, is_FractionField, FractionField_1poly_field)

src/sage/rings/algebraic_closure_finite_field.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
from sage.misc.abstract_method import abstract_method
5858
from sage.misc.fast_methods import WithEqualityById
5959

60-
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
6160
from sage.rings.finite_rings.finite_field_base import FiniteField
6261
from sage.rings.ring import Field
6362
from sage.structure.element import FieldElement
@@ -91,7 +90,7 @@ def __init__(self, parent, value):
9190
and ``loads(dumps(x))``.
9291
9392
"""
94-
if is_FiniteFieldElement(value):
93+
if isinstance(value, FieldElement) and value.parent().is_finite():
9594
n = value.parent().degree()
9695
else:
9796
from sage.rings.integer import Integer

src/sage/rings/finite_rings/element_base.pyx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,24 @@ from sage.misc.superseded import deprecated_function_alias
2525

2626
def is_FiniteFieldElement(x):
2727
"""
28-
Returns if x is a finite field element.
28+
Return True if ``x`` is a finite field element.
29+
30+
This function is deprecated.
2931
3032
EXAMPLES::
3133
3234
sage: from sage.rings.finite_rings.element_base import is_FiniteFieldElement
3335
sage: is_FiniteFieldElement(1)
36+
doctest:...: DeprecationWarning: the function is_FiniteFieldElement is deprecated; use isinstance(x, sage.structure.element.FieldElement) and x.parent().is_finite() instead
3437
False
3538
sage: is_FiniteFieldElement(IntegerRing())
3639
False
3740
sage: is_FiniteFieldElement(GF(5)(2))
3841
True
3942
"""
43+
from sage.misc.superseded import deprecation
44+
deprecation(32664, "the function is_FiniteFieldElement is deprecated; use isinstance(x, sage.structure.element.FieldElement) and x.parent().is_finite() instead")
45+
4046
from sage.rings.finite_rings.finite_field_base import FiniteField
4147
return isinstance(x, Element) and isinstance(x.parent(), FiniteField)
4248

src/sage/rings/padics/padic_template_element.pxi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ import sage.rings.finite_rings.integer_mod
3030
from cypari2.types cimport *
3131
from cypari2.gen cimport Gen as pari_gen
3232
from sage.libs.pari.convert_gmp cimport INT_to_mpz
33+
from sage.rings.finite_rings.finite_field_base import FiniteField
3334
from sage.rings.padics.common_conversion cimport get_ordp, get_preccap
3435
from sage.rings.integer cimport Integer
3536
from sage.rings.infinity import infinity
3637
from sage.rings.rational import Rational
3738
from sage.rings.padics.precision_error import PrecisionError
3839
from sage.rings.padics.misc import trim_zeros
39-
from sage.structure.element import canonical_coercion
40+
from sage.structure.element import canonical_coercion, FieldElement
4041
import itertools
4142

4243
cdef long maxordp = (1L << (sizeof(long) * 8 - 2)) - 1
@@ -145,7 +146,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement):
145146
elif sage.rings.finite_rings.integer_mod.is_IntegerMod(x):
146147
if not Integer(self.prime_pow.prime).divides(x.parent().order()):
147148
raise TypeError("p does not divide modulus %s"%x.parent().order())
148-
elif sage.rings.finite_rings.element_base.is_FiniteFieldElement(x):
149+
elif isinstance(x, FieldElement) and isinstance(x.parent(), FiniteField):
149150
k = self.parent().residue_field()
150151
if not k.has_coerce_map_from(x.parent()):
151152
raise NotImplementedError("conversion from finite fields which do not embed into the residue field not implemented")

src/sage/schemes/elliptic_curves/ell_finite_field.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
from .constructor import EllipticCurve
3030
from sage.schemes.hyperelliptic_curves.hyperelliptic_finite_field import HyperellipticCurve_finite_field
3131
from sage.rings.all import Integer, ZZ, PolynomialRing, GF, polygen
32-
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
32+
from sage.rings.finite_rings.finite_field_base import FiniteField
33+
from sage.structure.element import FieldElement
3334
import sage.groups.generic as generic
3435
from . import ell_point
3536
from sage.arith.all import gcd, lcm, binomial
@@ -1529,7 +1530,7 @@ def is_j_supersingular(j, proof=True):
15291530
sage: [p for p in prime_range(100) if is_j_supersingular(GF(p)(123456))]
15301531
[2, 3, 59, 89]
15311532
"""
1532-
if not is_FiniteFieldElement(j):
1533+
if not (isinstance(j, FieldElement) and isinstance(j.parent(), FiniteField)):
15331534
raise ValueError("%s must be an element of a finite field" % j)
15341535

15351536
F = j.parent()

0 commit comments

Comments
 (0)