Ticket #4981: polynomial_ring.patch

File polynomial_ring.patch, 33.2 KB (added by Burcin Erocal, 14 years ago)

clean up polynomial_ring.py (take 4)

  • sage/calculus/calculus.py

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1232525117 -3600
    # Node ID 8519f87e0ae6c948116403c7b75bb0994befebd0
    # Parent  ea9e3daf12fa969af7fa58ef69888694c3b8640a
    Cleanup sage.rings.polynomial.polynomial_ring.
    
    diff --git a/sage/calculus/calculus.py b/sage/calculus/calculus.py
    a b  
    19101910            sage: a
    19111911            y + x^3 + sqrt(2)
    19121912            sage: type(a)
    1913             <type 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>
     1913            <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field'>
    19141914            sage: a.degree()
    19151915            0
    19161916
  • sage/misc/classgraph.py

    diff --git a/sage/misc/classgraph.py b/sage/misc/classgraph.py
    a b  
    1616        classes -- optional dictionary to be filled in (it is also returned)
    1717
    1818    EXAMPLE:
     19        sage: from sage.rings.polynomial.padics import polynomial_padic_capped_relative_dense, polynomial_padic_flat
    1920        sage: C = class_graph(sage.rings.polynomial.padics, depth=2)
    2021        sage: C
    2122        {'Polynomial_padic_capped_relative_dense': ['Polynomial_generic_domain'],
  • sage/rings/polynomial/polynomial_quotient_ring.py

    diff --git a/sage/rings/polynomial/polynomial_quotient_ring.py b/sage/rings/polynomial/polynomial_quotient_ring.py
    a b  
    8282    $$
    8383
    8484        sage: A.<y> = PolynomialRing(GF(2)); A
    85         Univariate Polynomial Ring in y over Finite Field of size 2
     85        Univariate Polynomial Ring in y over Finite Field of size 2 (using NTL)
    8686        sage: B = A.quotient(y^2 + y + 1, 'y2'); print B
    8787        Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 with modulus y^2 + y + 1
    8888        sage: C = PolynomialRing(B, 'x'); x=C.gen(); print C
  • sage/rings/polynomial/polynomial_ring.py

    diff --git a/sage/rings/polynomial/polynomial_ring.py b/sage/rings/polynomial/polynomial_ring.py
    a b  
    5656    sage: V.<z> = K[]
    5757    sage: x+z
    5858    z + x
     59
     60These may change over time.
     61
     62    sage: type(ZZ['x'].0)
     63    <type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>
     64    sage: type(QQ['x'].0)
     65    <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_rational_dense'>
     66    sage: type(RR['x'].0)
     67    <type 'sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense'>
     68    sage: type(Integers(4)['x'].0)
     69    <type 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint'>
     70    sage: type(Integers(5*2^100)['x'].0)
     71    <type 'sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ'>
     72    sage: type(CC['x'].0)
     73    <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field'>
     74    sage: type(CC['t']['x'].0)
     75    <type 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>
    5976"""
    6077
    6178
     
    6784#                  http://www.gnu.org/licenses/
    6885#*****************************************************************************
    6986
    70 import sys # for maxint
    71 
    72 from sage.structure.element import is_Element
     87from sage.structure.element import Element
    7388import sage.algebras.algebra
    7489import sage.rings.commutative_ring as commutative_ring
    7590import sage.rings.commutative_algebra as commutative_algebra
     
    7893import sage.rings.field as field
    7994import sage.rings.integral_domain as integral_domain
    8095import sage.rings.principal_ideal_domain as principal_ideal_domain
     96from sage.rings.polynomial.polynomial_element import Polynomial
    8197import sage.rings.polynomial.polynomial_element_generic as polynomial_element_generic
    8298import sage.rings.rational_field as rational_field
    8399from sage.rings.integer_ring import is_IntegerRing, IntegerRing
     
    85101from sage.libs.pari.all import pari_gen
    86102import sage.misc.defaults
    87103import sage.misc.latex as latex
    88 import sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense as polynomial_padic_capped_relative_dense
    89 import sage.rings.polynomial.polynomial_integer_dense_ntl as polynomial_integer_dense_ntl
    90 import sage.rings.polynomial.polynomial_integer_dense_flint as polynomial_integer_dense_flint
    91 import sage.rings.polynomial.polynomial_modn_dense_ntl as polynomial_modn_dense_ntl
    92 import sage.rings.polynomial.padics.polynomial_padic_flat
    93104from sage.rings.real_mpfr import is_RealField
    94105from polynomial_real_mpfr_dense import PolynomialRealDense
    95106from sage.rings.polynomial.polynomial_singular_interface import PolynomialRing_singular_repr
     
    99110
    100111ZZ_sage = IntegerRing()
    101112
    102 from sage.interfaces.singular import is_SingularElement
     113from sage.interfaces.singular import SingularElement
    103114
    104115
    105116def is_PolynomialRing(x):
     
    144155    """
    145156    Univariate polynomial ring over a ring.
    146157    """
    147     def __init__(self, base_ring, name=None, sparse=False, implementation=None):
     158    def __init__(self, base_ring, name=None, sparse=False, element_class=None):
    148159        """
    149160        EXAMPLES:
    150161            sage: R.<x> = QQ['x']
     
    155166        """
    156167        sage.algebras.algebra.Algebra.__init__(self, base_ring, names=name, normalize=True)
    157168        self.__is_sparse = sparse
    158         self._implementation_names = (None,)
    159         self._implementation_repr = ''
    160         self.__set_polynomial_class(implementation)
    161         self.__generator = self([0,1], is_gen=True)
     169        if element_class:
     170            self._polynomial_class = element_class
     171        else:
     172            if sparse:
     173                self._polynomial_class = polynomial_element_generic.Polynomial_generic_sparse
     174            else:
     175                from sage.rings.polynomial import polynomial_element
     176                self._polynomial_class = polynomial_element.Polynomial_generic_dense
     177        self.__generator = self._polynomial_class(self, [0,1], is_gen=True)
    162178        self.__cyclopoly_cache = {}
    163179        self._has_singular = False
    164180
     
    214230        Coercing strings:
    215231            sage: QQ['y']('-y')
    216232            -y
     233
     234        TESTS:
     235        This shows that the issue at trac \#4106 is fixed:
     236            sage: x = var('x')
     237            sage: R = IntegerModRing(4)
     238            sage: S = PolynomialRing(R, x)
     239            sage: S(x)
     240            x
    217241        """
    218         if is_Element(x):
     242        C = self._polynomial_class
     243        if isinstance(x, Element):
    219244            P = x.parent()
    220245            if P is self:
    221246                return x
    222247            elif P == self.base_ring():
    223                 return self([x])
     248                return C(self, [x], check=True, is_gen=False,
     249                        construct=construct)
    224250            elif self.base_ring().has_coerce_map_from(P):
    225                 return self([P(x)])
     251                return C(self, [x], check=True, is_gen=False,
     252                        construct=construct)
    226253        if hasattr(x, '_polynomial_'):
    227254            return x._polynomial_(self)       
    228         if is_SingularElement(x) and self._has_singular:
     255        if isinstance(x, SingularElement) and self._has_singular:
    229256            self._singular_().set_ring()
    230257            try:
    231258                return x.sage_poly(self)
     
    249276            if x.type() != 't_POL':
    250277                x = x.Polrev()
    251278
    252         C = self.__polynomial_class
    253279        if absprec is None:
    254280            return C(self, x, check, is_gen, construct=construct)
    255281        else:
     
    463489        return cmp((left.base_ring(), left.variable_name()), (right.base_ring(), right.variable_name()))
    464490
    465491    def _repr_(self):
    466         s = "Univariate Polynomial Ring in %s over %s%s"%(
    467                 self.variable_name(), self.base_ring(),
    468                 self._implementation_repr)
     492        s = "Univariate Polynomial Ring in %s over %s"%(
     493                self.variable_name(), self.base_ring())
    469494        if self.is_sparse():
    470495            s = "Sparse " + s
    471496        return s
     
    478503            \mathbf{Z}[\alpha_{12}]
    479504        """
    480505        return "%s[%s]"%(latex.latex(self.base_ring()), self.latex_variable_names()[0])
    481 
    482     def __set_polynomial_class(self, implementation):
    483         """
    484         These may change over time, however we test them here to make sure *this* method is
    485         working as expected.
    486        
    487         TESTS:
    488             sage: type(ZZ['x'].0)
    489             <type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>
    490             sage: type(QQ['x'].0)
    491             <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_rational_dense'>
    492             sage: type(RR['x'].0)
    493             <type 'sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense'>
    494             sage: type(Integers(4)['x'].0)
    495             <type 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint'>
    496             sage: type(Integers(5*2^100)['x'].0)
    497             <type 'sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ'>
    498             sage: type(CC['x'].0)
    499             <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field'>
    500             sage: type(CC['t']['x'].0)
    501             <type 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>
    502         """
    503         from sage.rings.padics.padic_ring_capped_relative import pAdicRingCappedRelative
    504         from sage.rings.padics.padic_field_capped_relative import pAdicFieldCappedRelative
    505         from sage.rings.padics.padic_ring_lazy import pAdicRingLazy
    506         from sage.rings.padics.padic_field_lazy import pAdicFieldLazy
    507         from sage.rings.padics.padic_ring_capped_absolute import pAdicRingCappedAbsolute
    508         from sage.rings.padics.padic_ring_fixed_mod import pAdicRingFixedMod
    509         import sage.rings.polynomial.polynomial_element as polynomial_element
    510 
    511         R = self.base_ring()
    512         if isinstance(R, rational_field.RationalField) and not self.is_sparse():
    513             self.__polynomial_class = polynomial_element_generic.Polynomial_rational_dense
    514         elif is_IntegerRing(R) and not self.is_sparse():
    515             if implementation == 'NTL':
    516                 self.__polynomial_class = polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl
    517                 self._implementation_names = ('NTL',)
    518                 self._implementation_repr = ' (using NTL)'
    519             elif implementation == 'FLINT' or implementation is None:
    520                 self.__polynomial_class = polynomial_integer_dense_flint.Polynomial_integer_dense_flint
    521                 self._implementation_names = (None, 'FLINT')
    522             else:
    523                 raise ValueError, "Unknown implementation %s for ZZ[x]"
    524         elif isinstance(R, pAdicRingLazy):
    525             self.__polynomial_class = polynomial_element_generic.Polynomial_generic_dense # Fix
    526         elif isinstance(R, pAdicFieldLazy):
    527             self.__polynomial_class = polynomial_element_generic.Polynomial_generic_dense # Fix
    528         elif isinstance(R, pAdicRingCappedRelative):
    529             self.__polynomial_class = polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
    530         elif isinstance(R, pAdicFieldCappedRelative):
    531             self.__polynomial_class = polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
    532         elif isinstance(R, pAdicRingCappedAbsolute):
    533             self.__polynomial_class = sage.rings.polynomial.padics.polynomial_padic_flat.Polynomial_padic_flat # Fix
    534         elif isinstance(R, pAdicRingFixedMod):
    535             self.__polynomial_class = sage.rings.polynomial.padics.polynomial_padic_flat.Polynomial_padic_flat # Fix
    536         elif is_RealField(R):
    537             self.__polynomial_class = PolynomialRealDense
    538         elif isinstance(R, field.Field):
    539             if self.__is_sparse:
    540                 self.__polynomial_class = polynomial_element_generic.Polynomial_generic_sparse_field
    541             else:
    542                 self.__polynomial_class = polynomial_element_generic.Polynomial_generic_dense_field
    543         elif self.__is_sparse:
    544             self.__polynomial_class = polynomial_element_generic.Polynomial_generic_sparse
    545         else:
    546             self.__polynomial_class = polynomial_element.Polynomial_generic_dense
    547506
    548507    def base_extend(self, R):
    549508        """
     
    761720
    762721        EXAMPLES:
    763722            sage: R.<z> = Integers(2)[]; R
    764             Univariate Polynomial Ring in z over Ring of integers modulo 2
     723            Univariate Polynomial Ring in z over Ring of integers modulo 2 (using NTL)
    765724            sage: R.is_field()
    766725            False       
    767726        """
     
    1008967    """
    1009968    Univariate polynomial ring over a commutative ring.
    1010969    """
    1011     def __init__(self, base_ring, name=None, sparse=False, implementation=None):
     970    def __init__(self, base_ring, name=None, sparse=False, element_class=None):
    1012971        if not isinstance(base_ring, commutative_ring.CommutativeRing):
    1013972            raise TypeError, "Base ring must be a commutative ring."
    1014973        PolynomialRing_general.__init__(self, base_ring, name=name,
    1015                                         sparse=sparse, implementation=implementation)
     974                sparse=sparse, element_class=element_class)
    1016975
    1017976    def quotient_by_principal_ideal(self, f, names=None):
    1018977        """
     
    1023982        """
    1024983        import sage.rings.polynomial.polynomial_quotient_ring
    1025984        return sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing(self, f, names)
    1026 
    1027985   
    1028986
    1029987       
    1030988class PolynomialRing_integral_domain(PolynomialRing_commutative, integral_domain.IntegralDomain):
    1031     def __init__(self, base_ring, name="x", sparse=False, implementation=None):
    1032         PolynomialRing_commutative.__init__(self, base_ring, name,
    1033                                             sparse, implementation)
     989    def __init__(self, base_ring, name="x", sparse=False, implementation=None,
     990            element_class=None):
     991        """
     992        TESTS:
     993            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing
     994            sage: R = PRing(ZZ, 'x'); R
     995            Univariate Polynomial Ring in x over Integer Ring
     996            sage: type(R.gen())
     997            <type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>
     998
     999            sage: R = PRing(ZZ, 'x', implementation='NTL'); R
     1000            Univariate Polynomial Ring in x over Integer Ring (using NTL)
     1001            sage: type(R.gen())
     1002            <type 'sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl'>
     1003        """
     1004        self._implementation_repr = ''
     1005        if not element_class:
     1006            if is_IntegerRing(base_ring) and not sparse:
     1007                if implementation == 'NTL':
     1008                    from sage.rings.polynomial.polynomial_integer_dense_ntl \
     1009                            import Polynomial_integer_dense_ntl
     1010                    element_class = Polynomial_integer_dense_ntl
     1011                    self._implementation_names = ('NTL',)
     1012                    self._implementation_repr = ' (using NTL)'
     1013                elif implementation == 'FLINT' or implementation is None:
     1014                    from sage.rings.polynomial.polynomial_integer_dense_flint \
     1015                            import Polynomial_integer_dense_flint
     1016                    element_class = Polynomial_integer_dense_flint
     1017                    self._implementation_names = (None, 'FLINT')
     1018                else:
     1019                    raise ValueError, "Unknown implementation %s for ZZ[x]"
     1020        PolynomialRing_commutative.__init__(self, base_ring, name=name,
     1021                sparse=sparse, element_class=element_class)
     1022   
     1023    def _repr_(self):
     1024        """
     1025        TESTS:
     1026            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing
     1027            sage: R = PRing(ZZ, 'x', implementation='NTL'); R
     1028            Univariate Polynomial Ring in x over Integer Ring (using NTL)
     1029        """
     1030        s = PolynomialRing_commutative._repr_(self)
     1031        return s + self._implementation_repr
     1032
    10341033       
    10351034class PolynomialRing_field(PolynomialRing_integral_domain,
    10361035                           PolynomialRing_singular_repr,
    10371036                           principal_ideal_domain.PrincipalIdealDomain,
    10381037                           ):
    1039     def __init__(self, base_ring, name="x", sparse=False):
     1038    def __init__(self, base_ring, name="x", sparse=False, element_class=None):
     1039        """
     1040        TESTS:
     1041            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_field as PRing
     1042            sage: R = PRing(QQ, 'x'); R
     1043            Univariate Polynomial Ring in x over Rational Field
     1044            sage: type(R.gen())
     1045            <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_rational_dense'>
     1046            sage: R = PRing(QQ, 'x', sparse=True); R
     1047            Sparse Univariate Polynomial Ring in x over Rational Field
     1048            sage: type(R.gen())
     1049            <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse_field'>
     1050            sage: R = PRing(CC, 'x'); R
     1051            Univariate Polynomial Ring in x over Complex Field with 53 bits of precision
     1052            sage: type(R.gen())
     1053            <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field'>
     1054        """
     1055        if not element_class:
     1056            if sparse:
     1057                element_class = polynomial_element_generic.Polynomial_generic_sparse_field
     1058            elif isinstance(base_ring, rational_field.RationalField):
     1059                element_class = polynomial_element_generic.Polynomial_rational_dense
     1060            elif is_RealField(base_ring):
     1061                element_class = PolynomialRealDense
     1062            else:
     1063                element_class = polynomial_element_generic.Polynomial_generic_dense_field
     1064        PolynomialRing_integral_domain.__init__(self, base_ring, name=name, sparse=sparse, element_class=element_class)
     1065
    10401066        from sage.rings.polynomial.polynomial_singular_interface import can_convert_to_singular
    1041         PolynomialRing_commutative.__init__(self, base_ring, name, sparse)
    10421067        self._has_singular = can_convert_to_singular(self)
    10431068
    10441069    def lagrange_polynomial(self, points):
     
    10991124        return P
    11001125
    11011126class PolynomialRing_dense_padic_ring_generic(PolynomialRing_integral_domain):
    1102     def __init__(self, base_ring, name=None):
    1103         PolynomialRing_integral_domain.__init__(self, base_ring, name)
     1127    pass
    11041128
    11051129class PolynomialRing_dense_padic_field_generic(PolynomialRing_field):
    1106     def __init__(self, base_ring, name=None):
    1107         PolynomialRing_field.__init__(self, base_ring, name)
     1130    pass
    11081131
    11091132class PolynomialRing_dense_padic_ring_capped_relative(PolynomialRing_dense_padic_ring_generic):
    1110     pass
     1133    def __init__(self, base_ring, name=None, element_class=None):
     1134        """
     1135            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_capped_relative as PRing
     1136            sage: R = PRing(Zp(13), name='t'); R
     1137            Univariate Polynomial Ring in t over 13-adic Ring with capped relative precision 20
     1138            sage: type(R.gen())
     1139            <class 'sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense'>
     1140        """
     1141        if element_class is None:
     1142            from sage.rings.polynomial.padics.\
     1143                    polynomial_padic_capped_relative_dense import \
     1144                    Polynomial_padic_capped_relative_dense
     1145            element_class = Polynomial_padic_capped_relative_dense
     1146        PolynomialRing_dense_padic_ring_generic.__init__(self, base_ring,
     1147                name=name, element_class=element_class)
    11111148
    11121149class PolynomialRing_dense_padic_ring_capped_absolute(PolynomialRing_dense_padic_ring_generic):
    1113     pass
     1150    def __init__(self, base_ring, name=None, element_class=None):
     1151        """
     1152            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_capped_absolute as PRing
     1153            sage: R = PRing(Zp(13, type='capped-abs'), name='t'); R
     1154            Univariate Polynomial Ring in t over 13-adic Ring with capped absolute precision 20
     1155            sage: type(R.gen())
     1156            <class 'sage.rings.polynomial.padics.polynomial_padic_flat.Polynomial_padic_flat'>
     1157        """
     1158        if element_class is None:
     1159            from sage.rings.polynomial.padics.polynomial_padic_flat import \
     1160                    Polynomial_padic_flat
     1161            element_class = Polynomial_padic_flat
     1162        PolynomialRing_dense_padic_ring_generic.__init__(self, base_ring,
     1163                name=name, element_class=element_class)
    11141164
    11151165class PolynomialRing_dense_padic_ring_fixed_mod(PolynomialRing_dense_padic_ring_generic):
    1116     pass
     1166    def __init__(self, base_ring, name=None, element_class=None):
     1167        """
     1168            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_fixed_mod as PRing
     1169            sage: R = PRing(Zp(13, type='fixed-mod'), name='t'); R
     1170            Univariate Polynomial Ring in t over 13-adic Ring of fixed modulus 13^20
     1171
     1172            sage: type(R.gen())
     1173            <class 'sage.rings.polynomial.padics.polynomial_padic_flat.Polynomial_padic_flat'>
     1174        """
     1175        if element_class is None:
     1176            from sage.rings.polynomial.padics.polynomial_padic_flat import \
     1177                    Polynomial_padic_flat
     1178            element_class = Polynomial_padic_flat
     1179        PolynomialRing_dense_padic_ring_generic.__init__(self, base_ring,
     1180                name=name, element_class=element_class)
    11171181
    11181182class PolynomialRing_dense_padic_ring_lazy(PolynomialRing_dense_padic_ring_generic):
    1119     pass
     1183    def __init__(self, base_ring, name=None, element_class=None):
     1184        """
     1185            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_lazy as PRing
     1186            sage: R = PRing(Zp(13, type='lazy'), name='t')
     1187            Traceback (most recent call last):
     1188            ...
     1189            NotImplementedError: lazy p-adics need more work.  Sorry.
     1190
     1191            #sage: type(R.gen())
     1192
     1193        """
     1194        if element_class is None:
     1195            element_class = polynomial_element_generic.Polynomial_generic_dense
     1196        PolynomialRing_dense_padic_ring_generic.__init__(self, base_ring,
     1197                name=name, element_class=element_class)
    11201198
    11211199class PolynomialRing_dense_padic_field_capped_relative(PolynomialRing_dense_padic_field_generic):
    1122     pass
     1200    def __init__(self, base_ring, name=None, element_class=None):
     1201        """
     1202            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_field_capped_relative as PRing
     1203            sage: R = PRing(Qp(13), name='t'); R
     1204            Univariate Polynomial Ring in t over 13-adic Field with capped relative precision 20
     1205            sage: type(R.gen())
     1206            <class 'sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense'>
     1207        """
     1208        if element_class is None:
     1209            from sage.rings.polynomial.padics.\
     1210                    polynomial_padic_capped_relative_dense import \
     1211                    Polynomial_padic_capped_relative_dense
     1212            element_class = Polynomial_padic_capped_relative_dense
     1213        PolynomialRing_dense_padic_field_generic.__init__(self, base_ring,
     1214                name=name, element_class=element_class)
    11231215
    11241216class PolynomialRing_dense_padic_field_lazy(PolynomialRing_dense_padic_field_generic):
    1125     pass
     1217    def __init__(self, base_ring, name=None, element_class=None):
     1218        """
     1219            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_field_lazy as PRing
     1220            sage: R = PRing(Qp(13, type='lazy'), name='t')
     1221            Traceback (most recent call last):
     1222            ...
     1223            NotImplementedError: lazy p-adics need more work.  Sorry.
     1224
     1225            #sage: type(R.gen())
     1226        """
     1227        if element_class is None:
     1228            element_class = polynomial_element_generic.Polynomial_generic_dense
     1229        PolynomialRing_dense_padic_field_generic.__init__(self, base_ring,
     1230                name=name, element_class=element_class)
    11261231
    11271232class PolynomialRing_dense_mod_n(PolynomialRing_commutative):
    1128     def __init__(self, base_ring, name="x"):
     1233    def __init__(self, base_ring, name=None, element_class=None,
     1234            implementation=None):
     1235        """
     1236        TESTS:
     1237            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_n as PRing
     1238            sage: R = PRing(Zmod(15), 'x'); R
     1239            Univariate Polynomial Ring in x over Ring of integers modulo 15
     1240            sage: type(R.gen())
     1241            <type 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint'>
     1242
     1243            sage: R = PRing(Zmod(15), 'x', implementation='NTL'); R
     1244            Univariate Polynomial Ring in x over Ring of integers modulo 15 (using NTL)
     1245            sage: type(R.gen())
     1246            <type 'sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz'>
     1247
     1248            sage: R = PRing(Zmod(2**63*3), 'x', implementation='NTL'); R
     1249            Univariate Polynomial Ring in x over Ring of integers modulo 27670116110564327424 (using NTL)
     1250            sage: type(R.gen())
     1251            <type 'sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ'>
     1252
     1253            sage: R = PRing(Zmod(2**63*3), 'x', implementation='FLINT')
     1254            Traceback (most recent call last):
     1255            ...
     1256            ValueError: FLINT does not support modulus 27670116110564327424
     1257
     1258            sage: R = PRing(Zmod(2**63*3), 'x'); R
     1259            Univariate Polynomial Ring in x over Ring of integers modulo 27670116110564327424 (using NTL)
     1260            sage: type(R.gen())
     1261            <type 'sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ'>
     1262        """
     1263        from sage.rings.polynomial.polynomial_zmod_flint import \
     1264                Polynomial_zmod_flint
     1265        import sage.rings.polynomial.polynomial_modn_dense_ntl as \
     1266                modn_dense_ntl
    11291267        self.__modulus = base_ring.order()
    1130         PolynomialRing_commutative.__init__(self, base_ring, name)
     1268        if not element_class:
     1269            if implementation is None or implementation == 'FLINT':
     1270                import sys
     1271                if self.__modulus < sys.maxint:
     1272                    element_class = Polynomial_zmod_flint
     1273                    self._implementation_names = (None, 'FLINT')
     1274                    self._implementation_repr = ''
     1275                elif implementation == 'FLINT':
     1276                    raise ValueError, "FLINT does not support modulus %s"%(self.__modulus)
     1277            if not element_class:
     1278                self._implementation_names = ('NTL',)
     1279                self._implementation_repr = ' (using NTL)'
     1280                if self.__modulus < ZZ_sage(modn_dense_ntl.zz_p_max):
     1281                    element_class = modn_dense_ntl.Polynomial_dense_modn_ntl_zz
     1282                else:
     1283                    element_class = modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ
     1284        PolynomialRing_commutative.__init__(self, base_ring, name=name,
     1285                element_class=element_class)
    11311286
    11321287    def modulus(self):
     1288        """
     1289        EXAMPLES:
     1290            sage: R.<x> = Zmod(15)[]
     1291            sage: R.modulus()
     1292            15
     1293        """
    11331294        return self.__modulus
    11341295
    1135     def __call__(self, x=None, check=True, is_gen = False, construct=False):
     1296    def _repr_(self):
    11361297        """
    1137         EXAMPLES:
    1138         This shows that the issue at trac \#4106 is fixed:
    1139             sage: x = var('x')
    1140             sage: R = IntegerModRing(4)
    1141             sage: S = PolynomialRing(R, x)
    1142             sage: S(x)
    1143             x
     1298        TESTS:
     1299            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing
     1300            sage: R = PRing(ZZ, 'x', implementation='NTL'); R
     1301            Univariate Polynomial Ring in x over Integer Ring (using NTL)
    11441302        """
    1145         if hasattr(x, '_polynomial_'):
    1146             return x._polynomial_(self)
    1147         elif self.__modulus <= sys.maxint:
    1148             import sage.rings.polynomial.polynomial_zmod_flint as polynomial_zmod_flint
    1149             return polynomial_zmod_flint.Polynomial_zmod_flint(self, x, check, is_gen,construct=construct)
    1150         elif self.__modulus < ZZ_sage(polynomial_modn_dense_ntl.zz_p_max):
    1151             return polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz(self, x, check, is_gen, construct=construct)
    1152         else:
    1153             return polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ(self, x, check, is_gen, construct=construct)
     1303        s = PolynomialRing_commutative._repr_(self)
     1304        return s + self._implementation_repr
     1305
    11541306
    11551307class PolynomialRing_dense_mod_p(PolynomialRing_field,
    11561308                                 PolynomialRing_dense_mod_n,
    11571309                                 PolynomialRing_singular_repr):
    1158     def __init__(self, base_ring, name="x"):
     1310    def __init__(self, base_ring, name="x", implementation=None):
     1311        """
     1312
     1313        TESTS:
     1314            sage: P = GF(2)['x']; P
     1315            Univariate Polynomial Ring in x over Finite Field of size 2 (using NTL)
     1316            sage: type(P.gen())
     1317            <type 'sage.rings.polynomial.polynomial_gf2x.Polynomial_GF2X'>
     1318
     1319            sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_p
     1320            sage: P = PolynomialRing_dense_mod_p(GF(5), 'x'); P
     1321            Univariate Polynomial Ring in x over Finite Field of size 5
     1322            sage: type(P.gen())
     1323            <type 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint'>
     1324
     1325            sage: P = PolynomialRing_dense_mod_p(GF(5), 'x', implementation='NTL'); P
     1326            Univariate Polynomial Ring in x over Finite Field of size 5 (using NTL)
     1327            sage: type(P.gen())
     1328            <type 'sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_mod_p'>
     1329
     1330            sage: P = PolynomialRing_dense_mod_p(GF(9223372036854775837), 'x')
     1331            sage: P
     1332            Univariate Polynomial Ring in x over Finite Field of size 9223372036854775837 (using NTL)
     1333            sage: type(P.gen())
     1334            <type 'sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_mod_p'>
     1335
     1336
     1337        """
     1338        from sage.rings.polynomial.polynomial_zmod_flint import \
     1339                Polynomial_zmod_flint
     1340        self.__modulus = base_ring.characteristic()
     1341        element_class = None
     1342        if self.__modulus == 2:
     1343            import sage.rings.polynomial.polynomial_gf2x as polynomial_gf2x
     1344            element_class = polynomial_gf2x.Polynomial_GF2X
     1345            self._implementation_repr = ' (using NTL)'
     1346        elif implementation is None or implementation == 'FLINT':
     1347            import sys
     1348            if self.__modulus < sys.maxint:
     1349                self._implementation_names = (None, 'FLINT')
     1350                self._implementation_repr = ''
     1351                element_class = Polynomial_zmod_flint
     1352            elif implementation == 'FLINT':
     1353                raise ValueError, "FLINT does not support modulus %s"%(self.__modulus)
     1354        if not element_class:
     1355            from sage.rings.polynomial.polynomial_modn_dense_ntl import \
     1356                    Polynomial_dense_mod_p
     1357            element_class = Polynomial_dense_mod_p
     1358            self._implementation_names = ('NTL',)
     1359            self._implementation_repr = ' (using NTL)'
     1360        PolynomialRing_dense_mod_n.__init__(self, base_ring, name=name,
     1361                element_class=element_class)
     1362
    11591363        from sage.rings.polynomial.polynomial_singular_interface import can_convert_to_singular
    1160         self.__modulus = base_ring.order()
    1161         PolynomialRing_dense_mod_n.__init__(self, base_ring, name)
    11621364        self._has_singular = can_convert_to_singular(self)
    1163 
    1164     def __call__(self, x=None, check=True, is_gen = False, construct=False):
    1165         if is_SingularElement(x) and self._has_singular:
    1166             self._singular_().set_ring()
    1167             try:
    1168                 return x.sage_poly(self)
    1169             except:
    1170                 raise TypeError, "Unable to coerce singular object"
    1171         elif isinstance(x , str) and self._has_singular:
    1172             self._singular_().set_ring()
    1173             try:
    1174                 return self._singular_().parent(x).sage_poly(self)
    1175             except:
    1176                 raise TypeError,"Unable to coerce string"
    1177         elif hasattr(x, '_polynomial_'):
    1178             return x._polynomial_(self)
    1179         modulus = self.modulus()
    1180         if modulus == 2:
    1181             import sage.rings.polynomial.polynomial_gf2x as polynomial_gf2x
    1182             return polynomial_gf2x.Polynomial_GF2X(self, x, check, is_gen,construct=construct)
    1183         elif modulus <= sys.maxint:
    1184             import sage.rings.polynomial.polynomial_zmod_flint as polynomial_zmod_flint
    1185             return polynomial_zmod_flint.Polynomial_zmod_flint(self, x, check, is_gen,construct=construct)
    1186         else:
    1187             return polynomial_modn_dense_ntl.Polynomial_dense_mod_p(self, x, check, is_gen,construct=construct)
    11881365
    11891366
    11901367def polygen(ring_or_element, name="x"):
  • sage/rings/polynomial/polynomial_zmod_flint.pyx

    diff --git a/sage/rings/polynomial/polynomial_zmod_flint.pyx b/sage/rings/polynomial/polynomial_zmod_flint.pyx
    a b  
    1616
    1717cdef inline cparent get_cparent(parent):
    1818    if parent is None:
     19        return 0
     20    try:
     21        m = parent.modulus()
     22    except:
    1923        return 0
    2024    return <unsigned long>(parent.modulus())
    2125