Skip to content

Commit dcf6cc6

Browse files
committed
Fix finite_field_constructor
1 parent 290e36f commit dcf6cc6

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/sage/rings/finite_rings/finite_field_constructor.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193

194194

195195
from sage.structure.factory import UniqueFactory
196-
196+
from sage.misc.decorators import rename_keyword
197197

198198
class FiniteFieldFactory(UniqueFactory):
199199
"""
@@ -513,6 +513,7 @@ def __init__(self, *args, **kwds):
513513
self._modulus_cache = defaultdict(dict)
514514
super().__init__(*args, **kwds)
515515

516+
@rename_keyword(impl='implementation')
516517
def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
517518
implementation=None, proof=None,
518519
check_prime: bool = True, check_irreducible: bool = True,
@@ -564,15 +565,16 @@ def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
564565
sage: GF.create_key_and_extra_args(9, 'a', structure=None) # needs sage.libs.linbox
565566
((9, ('a',), x^2 + 2*x + 2, 'givaro', 3, 2, True, None, 'poly', True, True, True), {})
566567
567-
The ``implementation`` parameter is preferred, but ``impl`` is accepted
568-
for backwards compatibility::
568+
We do not allow giving both ``implementation`` and ``impl``::
569569
570570
sage: GF.create_key_and_extra_args(9, 'a', implementation='givaro') # needs sage.libs.linbox
571571
((9, ('a',), x^2 + 2*x + 2, 'givaro', 3, 2, True, None, 'poly', True, True, True), {})
572572
sage: GF.create_key_and_extra_args(9, 'a', impl='givaro') # needs sage.libs.linbox
573573
((9, ('a',), x^2 + 2*x + 2, 'givaro', 3, 2, True, None, 'poly', True, True, True), {})
574574
sage: GF.create_key_and_extra_args(9, 'a', implementation='givaro', impl='ntl') # needs sage.libs.linbox
575-
((9, ('a',), x^2 + 2*x + 2, 'givaro', 3, 2, True, None, 'poly', True, True, True), {})
575+
Traceback (most recent call last):
576+
...
577+
TypeError: create_key_and_extra_args() got an unexpected keyword argument 'impl'
576578
577579
TESTS::
578580
@@ -650,20 +652,11 @@ def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
650652
Finite Field in aa of size 7^2
651653
"""
652654
for key, val in kwds.items():
653-
if key not in ['structure', 'prec', 'embedding', 'latex_names', 'impl']:
655+
if key not in ['structure', 'prec', 'embedding', 'latex_names']:
654656
raise TypeError("create_key_and_extra_args() got an unexpected keyword argument '%s'" % key)
655657
if not (val is None or isinstance(val, list) and all(c is None for c in val)):
656658
raise NotImplementedError("ring extension with prescribed %s is not implemented" % key)
657659

658-
# Accept both 'implementation' (preferred) and 'impl' (for backwards compatibility)
659-
# Priority: 'implementation' takes precedence over 'impl' if both are provided
660-
impl = kwds.get('impl')
661-
if implementation is not None:
662-
impl = implementation
663-
elif impl is None:
664-
# Keep impl as None, will be set to default later
665-
pass
666-
667660
from sage.structure.proof.proof import WithProof
668661
from sage.structure.proof.all import arithmetic
669662
if proof is None:
@@ -690,8 +683,8 @@ def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
690683
# note that we haven't tested p for primality
691684

692685
if n == 1:
693-
if impl is None:
694-
impl = 'modn'
686+
if implementation is None:
687+
implementation = 'modn'
695688
if name is not None:
696689
certify_names((name,) if isinstance(name, str) else name)
697690
name = ('x',) # Ignore name
@@ -715,19 +708,19 @@ def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
715708
check_irreducible = False
716709
name = normalize_names(1, name)
717710

718-
if impl is None:
711+
if implementation is None:
719712
if order < zech_log_bound and FiniteField_givaro is not None:
720-
impl = 'givaro'
713+
implementation = 'givaro'
721714
elif p == 2 and FiniteField_ntl_gf2e is not None:
722-
impl = 'ntl'
715+
implementation = 'ntl'
723716
else:
724-
impl = 'pari_ffelt'
717+
implementation = 'pari_ffelt'
725718

726719
# Determine modulus.
727720
# For the 'modn' implementation, we use the following
728721
# optimization which we also need to avoid an infinite loop:
729722
# a modulus of None is a shorthand for x-1.
730-
if modulus is not None or impl != 'modn':
723+
if modulus is not None or implementation != 'modn':
731724
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
732725
R = PolynomialRing(FiniteField(p), 'x')
733726
if modulus is None:
@@ -745,15 +738,15 @@ def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
745738

746739
if modulus.degree() != n:
747740
raise ValueError("the degree of the modulus does not equal the degree of the field")
748-
# If modulus is x - 1 for impl="modn", set it to None
749-
if impl == 'modn' and modulus.list() == [-1,1]:
741+
# If modulus is x - 1 for implementation="modn", set it to None
742+
if implementation == 'modn' and modulus.list() == [-1,1]:
750743
modulus = None
751744
if modulus is None:
752745
check_irreducible = False
753746

754747
# Check extra arguments for givaro and setup their defaults
755748
# TODO: ntl takes a repr, but ignores it
756-
if impl == 'givaro':
749+
if implementation == 'givaro':
757750
if repr is None:
758751
repr = 'poly'
759752
if elem_cache is None:
@@ -763,7 +756,7 @@ def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
763756
repr = None
764757
elem_cache = None
765758

766-
return (order, name, modulus, impl, p, n, proof, prefix, repr, elem_cache, check_prime, check_irreducible), {}
759+
return (order, name, modulus, implementation, p, n, proof, prefix, repr, elem_cache, check_prime, check_irreducible), {}
767760

768761
def create_object(self, version, key, **kwds):
769762
"""

0 commit comments

Comments
 (0)