Ticket #14832: trac_14832-PolynomialRing_dense_finite_field.patch

File trac_14832-PolynomialRing_dense_finite_field.patch, 4.9 KB (added by pbruin, 10 years ago)

new class for polynomial rings over finite fields

  • sage/rings/polynomial/polynomial_ring.py

    # HG changeset patch
    # User Peter Bruin <peter.bruin@math.uzh.ch>
    # Date 1372186250 -7200
    # Node ID 641e5b0716af72a1bcb7e9d9338a3d88a998557c
    # Parent  739c6c4c4f751f2fe95f291c9b4e75cd7e51e4c2
    Trac 14832: new class PolynomialRing_dense_finite_field
    
    diff --git a/sage/rings/polynomial/polynomial_ring.py b/sage/rings/polynomial/polynomial_ring.py
    a b  
    14041404                           PolynomialRing_singular_repr,
    14051405                           principal_ideal_domain.PrincipalIdealDomain,
    14061406                           ):
    1407     def __init__(self, base_ring, name="x", sparse=False, element_class=None, implementation=None):
     1407    def __init__(self, base_ring, name="x", sparse=False, element_class=None):
    14081408        """
    14091409        TESTS:
    14101410            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_field as PRing
     
    14261426            sage: x^(10^20) # this should be fast
    14271427            x^100000000000000000000
    14281428        """
    1429         from sage.rings.finite_rings.finite_field_base import is_FiniteField
    1430         from sage.rings.rational_field import QQ
    14311429        from sage.rings.polynomial.polynomial_singular_interface import can_convert_to_singular
    1432         if implementation is None:
    1433             implementation = "NTL"
    1434 
    1435         if implementation == "NTL" and is_FiniteField(base_ring) and not(sparse):
    1436             from sage.libs.ntl.ntl_ZZ_pEContext import ntl_ZZ_pEContext
    1437             from sage.libs.ntl.ntl_ZZ_pX import ntl_ZZ_pX
    1438             from sage.rings.polynomial.polynomial_zz_pex import Polynomial_ZZ_pEX
    1439 
    1440             p=base_ring.characteristic()
    1441             self._modulus = ntl_ZZ_pEContext(ntl_ZZ_pX(list(base_ring.polynomial()), p))
    1442             element_class = Polynomial_ZZ_pEX
    14431430
    14441431        if not element_class:
    14451432            if sparse:
     
    17981785                self._fraction_field = FractionField_1poly_field(self)
    17991786            return self._fraction_field
    18001787
     1788class PolynomialRing_dense_finite_field(PolynomialRing_field):
     1789    """
     1790    Univariate polynomial ring over a finite field.
     1791
     1792    EXAMPLE::
     1793
     1794        sage: R = PolynomialRing(GF(27, 'a'), 'x')
     1795        sage: type(R)
     1796        <class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_finite_field_with_category'>
     1797    """
     1798    def __init__(self, base_ring, name="x", element_class=None, implementation=None):
     1799        if implementation is None:
     1800            implementation = "NTL"
     1801
     1802        if implementation == "NTL":
     1803            from sage.libs.ntl.ntl_ZZ_pEContext import ntl_ZZ_pEContext
     1804            from sage.libs.ntl.ntl_ZZ_pX import ntl_ZZ_pX
     1805            from sage.rings.polynomial.polynomial_zz_pex import Polynomial_ZZ_pEX
     1806
     1807            p=base_ring.characteristic()
     1808            self._modulus = ntl_ZZ_pEContext(ntl_ZZ_pX(list(base_ring.polynomial()), p))
     1809            element_class = Polynomial_ZZ_pEX
     1810
     1811        PolynomialRing_field.__init__(self, base_ring, sparse=False, name=name,
     1812                                      element_class=element_class)
     1813
    18011814class PolynomialRing_dense_padic_ring_generic(PolynomialRing_integral_domain):
    18021815    pass
    18031816
     
    19952008        return s + self._implementation_repr
    19962009
    19972010
    1998 class PolynomialRing_dense_mod_p(PolynomialRing_field,
     2011class PolynomialRing_dense_mod_p(PolynomialRing_dense_finite_field,
    19992012                                 PolynomialRing_dense_mod_n,
    20002013                                 PolynomialRing_singular_repr):
    20012014    def __init__(self, base_ring, name="x", implementation=None):
  • sage/rings/polynomial/polynomial_ring_constructor.py

    a b  
    4040import sage.rings.padics.padic_base_leaves as padic_base_leaves
    4141
    4242from sage.rings.integer import Integer
     43from sage.rings.finite_rings.constructor import is_FiniteField
    4344from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
    4445
    4546from sage.misc.cachefunc import weak_cached_function
     
    533534            else:  # n == 1!
    534535                R = m.PolynomialRing_integral_domain(base_ring, name)   # specialized code breaks in this case.
    535536
     537        elif is_FiniteField(base_ring) and not sparse:
     538            R = m.PolynomialRing_dense_finite_field(base_ring, name, implementation=implementation)
     539
    536540        elif isinstance(base_ring, padic_base_leaves.pAdicFieldCappedRelative):
    537541            R = m.PolynomialRing_dense_padic_field_capped_relative(base_ring, name)
    538542
     
    546550            R = m.PolynomialRing_dense_padic_ring_fixed_mod(base_ring, name)
    547551
    548552        elif base_ring.is_field(proof = False):
    549             R = m.PolynomialRing_field(base_ring, name, sparse, implementation=implementation)
     553            R = m.PolynomialRing_field(base_ring, name, sparse)
    550554
    551555        elif base_ring.is_integral_domain(proof = False):
    552556            R = m.PolynomialRing_integral_domain(base_ring, name, sparse, implementation)