Skip to content

Commit 53ede8c

Browse files
author
Matthias Koeppe
committed
sage.rings.finite_rings: Deprecate is_FiniteField, is_PrimeFiniteField
1 parent bb7ee85 commit 53ede8c

38 files changed

+136
-122
lines changed

src/sage/crypto/boolean_function.pyx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ from sage.rings.integer_ring import ZZ
3838
from sage.rings.integer cimport Integer
3939
from sage.rings.finite_rings.finite_field_constructor import GF
4040
from sage.rings.polynomial.pbori.pbori import BooleanPolynomial
41-
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
42-
from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro
41+
from sage.rings.finite_rings.finite_field_base import FiniteField
4342
from sage.rings.polynomial.polynomial_element import is_Polynomial
4443

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

330329
elif is_Polynomial(x):
331330
K = x.base_ring()
332-
if is_FiniteField(K) and K.characteristic() == 2:
331+
if isinstance(K, FiniteField) and K.characteristic() == 2:
333332
self._nvariables = K.degree()
334333
bitset_init(self._truth_table, <mp_bitcnt_t> (1<<self._nvariables))
335334
bitset_zero(self._truth_table)
336-
if isinstance(K,FiniteField_givaro): #the ordering is not the same in this case
335+
try:
336+
from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro
337+
except ImportError:
338+
FiniteField_givaro = ()
339+
if isinstance(K, FiniteField_givaro): # the ordering is not the same in this case
337340
for u in K:
338341
bitset_set_to(self._truth_table, ZZ(u._vector_().list(),2) , (x(u)).trace())
339342
else:

src/sage/crypto/lfsr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129

130130
from sage.structure.all import Sequence
131131
from sage.rings.all import Integer, PolynomialRing
132-
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
132+
from sage.rings.finite_rings.finite_field_base import FiniteField
133133

134134

135135
def lfsr_sequence(key, fill, n):
@@ -179,7 +179,7 @@ def lfsr_sequence(key, fill, n):
179179
raise TypeError("key must be a list")
180180
key = Sequence(key)
181181
F = key.universe()
182-
if not is_FiniteField(F):
182+
if not isinstance(F, FiniteField):
183183
raise TypeError("universe of sequence must be a finite field")
184184

185185
s = fill

src/sage/dynamics/arithmetic_dynamics/affine_ds.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class initialization directly.
4343
from sage.misc.cachefunc import cached_method
4444
from sage.misc.classcall_metaclass import typecall
4545
from sage.rings.integer import Integer
46-
from sage.rings.finite_rings.finite_field_constructor import is_PrimeFiniteField
47-
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
46+
from sage.rings.finite_rings.finite_field_base import FiniteField
4847
from sage.rings.fraction_field import FractionField
4948
from sage.rings.fraction_field import is_FractionField
5049
from sage.rings.quotient_ring import is_QuotientRing
@@ -251,7 +250,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None):
251250
raise ValueError('domain and codomain do not agree')
252251
if R not in Fields():
253252
return typecall(cls, polys, domain)
254-
if is_FiniteField(R):
253+
if isinstance(R, FiniteField):
255254
return DynamicalSystem_affine_finite_field(polys, domain)
256255
return DynamicalSystem_affine_field(polys, domain)
257256
elif isinstance(morphism_or_polys,(list, tuple)):
@@ -299,7 +298,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None):
299298

300299
if R not in Fields():
301300
return typecall(cls, polys, domain)
302-
if is_FiniteField(R):
301+
if isinstance(R, FiniteField):
303302
return DynamicalSystem_affine_finite_field(polys, domain)
304303
return DynamicalSystem_affine_field(polys, domain)
305304

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

325325
def __copy__(self):

src/sage/dynamics/arithmetic_dynamics/generic_ds.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class initialization directly.
3333
from sage.schemes.affine.affine_space import is_AffineSpace
3434
from sage.schemes.affine.affine_subscheme import AlgebraicScheme_subscheme_affine
3535
from sage.rings.algebraic_closure_finite_field import AlgebraicClosureFiniteField_generic
36-
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
36+
from sage.rings.finite_rings.finite_field_base import FiniteField
3737
from sage.rings.qqbar import AlgebraicField_common
3838
from sage.schemes.berkovich.berkovich_space import is_Berkovich_Cp
3939
from sage.rings.rational_field import QQ
@@ -416,7 +416,7 @@ def field_of_definition_critical(self, return_embedding=False, simplify_all=Fals
416416
CR = CR.ring()
417417
x = CR.gen(0)
418418
poly = (g*CR(f).derivative(x) - f*CR(g).derivative(x)).univariate_polynomial()
419-
if is_FiniteField(ds.base_ring()):
419+
if isinstance(ds.base_ring(), FiniteField):
420420
return poly.splitting_field(names, map=return_embedding)
421421
else:
422422
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)
@@ -536,7 +536,7 @@ def field_of_definition_periodic(self, n, formal=False, return_embedding=False,
536536
fn = ds.nth_iterate_map(n)
537537
f,g = fn[0].numerator(), fn[0].denominator()
538538
poly = (f - g*x).univariate_polynomial()
539-
if is_FiniteField(ds.base_ring()):
539+
if isinstance(ds.base_ring(), FiniteField):
540540
return poly.splitting_field(names, map=return_embedding)
541541
else:
542542
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)
@@ -630,7 +630,7 @@ def field_of_definition_preimage(self, point, n, return_embedding=False, simplif
630630
#want the polynomial ring not the fraction field
631631
CR = CR.ring()
632632
poly = (f*point[1] - g*CR(point[0])).univariate_polynomial()
633-
if is_FiniteField(ds.base_ring()):
633+
if isinstance(ds.base_ring(), FiniteField):
634634
return poly.splitting_field(names, map=return_embedding)
635635
else:
636636
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)

src/sage/dynamics/arithmetic_dynamics/projective_ds.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +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_constructor import (is_FiniteField, GF,
77-
is_PrimeFiniteField)
76+
from sage.rings.finite_rings.finite_field_constructor import GF
7877
from sage.rings.finite_rings.integer_mod_ring import Zmod
7978
from sage.rings.fraction_field import (FractionField, is_FractionField, FractionField_1poly_field)
8079
from sage.rings.fraction_field_element import is_FractionFieldElement, FractionFieldElement
@@ -374,7 +373,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None, names=None):
374373
raise ValueError('"domain" must be a projective scheme')
375374
if R not in Fields():
376375
return typecall(cls, polys, domain)
377-
if is_FiniteField(R):
376+
if isinstance(R, FiniteField):
378377
return DynamicalSystem_projective_finite_field(polys, domain)
379378
return DynamicalSystem_projective_field(polys, domain)
380379

@@ -433,7 +432,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None, names=None):
433432
if not all(split_d == domain._degree(f) for f in split_poly):
434433
msg = 'polys (={}) must be multi-homogeneous of the same degrees (by component)'
435434
raise TypeError(msg.format(polys))
436-
if is_FiniteField(R):
435+
if isinstance(R, FiniteField):
437436
from sage.dynamics.arithmetic_dynamics.product_projective_ds import DynamicalSystem_product_projective_finite_field
438437
return DynamicalSystem_product_projective_finite_field(polys, domain)
439438
return DynamicalSystem_product_projective(polys, domain)
@@ -451,7 +450,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None, names=None):
451450
raise ValueError('"domain" must be a projective scheme')
452451
if R not in Fields():
453452
return typecall(cls, polys, domain)
454-
if is_FiniteField(R):
453+
if isinstance(R, FiniteField):
455454
return DynamicalSystem_projective_finite_field(polys, domain)
456455
return DynamicalSystem_projective_field(polys, domain)
457456

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

476476
def __copy__(self):
477477
r"""

src/sage/groups/cubic_braid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,10 +1543,10 @@ def as_matrix_group(self, root_bur=None, domain=None, characteristic=None, var='
15431543
self._classical_invariant_form = herm_form
15441544

15451545
if unitary:
1546-
from sage.rings.finite_rings.finite_field_base import is_FiniteField
1546+
from sage.rings.finite_rings.finite_field_base import FiniteField
15471547
from sage.groups.matrix_gps.unitary import GU
15481548
d, d = herm_form.dimensions()
1549-
if is_FiniteField(domain):
1549+
if isinstance(domain, FiniteField):
15501550
base_group = GU(d, domain, var=domain.gen(), invariant_form=herm_form)
15511551
else:
15521552
base_group = GU(d, domain, invariant_form=herm_form)

src/sage/groups/matrix_gps/orthogonal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
# ****************************************************************************
8686

8787
from sage.rings.integer_ring import ZZ
88-
from sage.rings.finite_rings.finite_field_base import is_FiniteField
88+
from sage.rings.finite_rings.finite_field_base import FiniteField
8989
from sage.misc.latex import latex
9090
from sage.misc.cachefunc import cached_method
9191
from sage.groups.matrix_gps.named_group import (
@@ -127,7 +127,7 @@ def normalize_args_e(degree, ring, e):
127127
...
128128
ValueError: must have e=-1 or e=1 for even degree
129129
"""
130-
if is_FiniteField(ring) and degree%2 == 0:
130+
if isinstance(ring, FiniteField) and degree%2 == 0:
131131
if e not in (-1, +1):
132132
raise ValueError('must have e=-1 or e=1 for even degree')
133133
else:
@@ -171,7 +171,7 @@ def _OG(n, R, special, e=0, var='a', invariant_form=None):
171171
e = normalize_args_e(degree, ring, e)
172172

173173
if invariant_form is not None:
174-
if is_FiniteField(ring):
174+
if isinstance(ring, FiniteField):
175175
raise NotImplementedError("invariant_form for finite groups is fixed by GAP")
176176

177177
if e == 0:
@@ -202,7 +202,7 @@ def _OG(n, R, special, e=0, var='a', invariant_form=None):
202202
latex(ring),
203203
'+' if e == 1 else '-')
204204

205-
if is_FiniteField(ring):
205+
if isinstance(ring, FiniteField):
206206
cmd = '{0}O({1}, {2}, {3})'.format(ltx_prefix, e, degree, ring.order())
207207
return OrthogonalMatrixGroup_gap(degree, ring, False, name, ltx, cmd)
208208
else:

src/sage/groups/matrix_gps/symplectic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

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

147147
if invariant_form is not None:
148-
if is_FiniteField(ring):
148+
if isinstance(ring, FiniteField):
149149
raise NotImplementedError("invariant_form for finite groups is fixed by GAP")
150150

151151
invariant_form = normalize_args_invariant_form(ring, degree, invariant_form)

src/sage/groups/matrix_gps/unitary.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# ****************************************************************************
5151

5252
from sage.rings.finite_rings.finite_field_constructor import GF
53-
from sage.rings.finite_rings.finite_field_base import is_FiniteField
53+
from sage.rings.finite_rings.finite_field_base import FiniteField
5454
from sage.misc.latex import latex
5555
from sage.misc.cachefunc import cached_method
5656
from sage.groups.matrix_gps.named_group import (
@@ -77,7 +77,7 @@ def finite_field_sqrt(ring):
7777
sage: finite_field_sqrt(GF(4, 'a'))
7878
2
7979
"""
80-
if not is_FiniteField(ring):
80+
if not isinstance(ring, FiniteField):
8181
raise ValueError('not a finite field')
8282
q, rem = ring.cardinality().sqrtrem()
8383
if rem:
@@ -107,7 +107,7 @@ def _UG(n, R, special, var='a', invariant_form=None):
107107
latex_prefix ='S'
108108

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

137-
if is_FiniteField(ring):
137+
if isinstance(ring, FiniteField):
138138
cmd = '{0}U({1}, {2})'.format(latex_prefix, degree, q)
139139
return UnitaryMatrixGroup_gap(degree, ring, special, name, ltx, cmd)
140140
else:

src/sage/matrix/matrix_space.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from sage.structure.parent import Parent
4444
from sage.structure.unique_representation import UniqueRepresentation
4545
import sage.rings.integer as integer
46-
import sage.rings.finite_rings.finite_field_constructor
46+
from sage.rings.finite_rings.finite_field_base import FiniteField
4747
import sage.misc.latex as latex
4848
import sage.modules.free_module
4949

@@ -223,7 +223,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
223223
else:
224224
return matrix_complex_double_dense.Matrix_complex_double_dense
225225

226-
elif sage.rings.finite_rings.finite_field_constructor.is_FiniteField(R):
226+
elif isinstance(R, FiniteField):
227227
if R.order() == 2:
228228
try:
229229
from . import matrix_mod2_dense

0 commit comments

Comments
 (0)