Ticket #8335: trac_8335-fixes-5.8.b0.2.patch

File trac_8335-fixes-5.8.b0.2.patch, 51.6 KB (added by jpflori, 9 years ago)
  • sage/categories/pushout.py

    # HG changeset patch
    # User Jean-Pierre Flori <jean-pierre.flor@ssi.gouv.fr>
    # Date 1360334827 -3600
    # Node ID 0aaa71dda8af2bb4d05df41fe6df0fe4aa2eef10
    # Parent  4cbd00666457bacdfc6afaec73bad96ad83d2e05
    #8335: Doc fixes
    
    diff --git a/sage/categories/pushout.py b/sage/categories/pushout.py
    a b  
    22912291        ...
    22922292        TypeError: Could not find a mapping of the passed element to this ring.
    22932293    """
    2294     rank = 7
     2294    rank = 4.5
    22952295   
    22962296    def __init__(self, I, names=None, as_field=False):
    22972297        """
     
    23482348
    23492349        Note that the ``quo()`` method of a field used to return the
    23502350        integer zero. That strange behaviour was removed in trac
    2351         ticket #9138. It now returns a trivial quotient ring when
    2352         applied to a field::
     2351        ticket :trac:`9138` to return a trivial quotient ring when
     2352        applied to a field. Note that since :trac:`8335` applying a
     2353        ``QuotientFunctor`` with arguments a field and a non-trivial ideal
     2354        will raise a ``CoercionException``::
    23532355
    23542356            sage: F = ZZ.quo([5]*ZZ).construction()[0]
    2355             sage: F(QQ) is Integers(1)
    2356             True
     2357            sage: F(QQ)
     2358            Traceback (most recent call last):
     2359            ...
     2360            CoercionException: Trivial quotient ring.
    23572361            sage: QQ.quo(5)
    23582362            Quotient of Rational Field by the ideal (1)
    2359 
    23602363        """
    23612364        I = self.I
    23622365        from sage.all import QQ
    23632366        if not I.is_zero():
    23642367            from sage.categories.fields import Fields
    23652368            if R in Fields():
    2366                 from sage.all import Integers
    2367                 return Integers(1)
     2369                raise CoercionException, "Trivial quotient ring."
     2370                #from sage.all import Integers
     2371                #return Integers(1)
    23682372        if I.ring() != R:
    23692373            if I.ring().has_coerce_map_from(R):
    23702374                R = I.ring()
     
    24932497    """
    24942498    rank = 3
    24952499   
    2496     def __init__(self, polys, names, embeddings, cyclotomic=None, prefix=None):
     2500    def __init__(self, polys, names, embeddings, cyclotomic=None, conway=None, prefix=None):
    24972501        """
    24982502        INPUT:
    24992503
     
    25082512        - ``cyclotomic``: optional integer. If it is provided,
    25092513          application of the functor to the rational field yields
    25102514          a cyclotomic field, rather than just a number field.
     2515        - ``conway``: optional integer. If it is provided,
     2516          application of the functor to finite fields yields
     2517          pseudo-Conway extensions of the given degree.
    25112518        - ``prefix``: optional string.  If it is provided, it will
    25122519          allow application of this functor to some finite fields to
    25132520          function without providing a variable name
     
    25752582        self.names = list(names)
    25762583        self.embeddings = list(embeddings)
    25772584        self.cyclotomic = int(cyclotomic) if cyclotomic is not None else None
     2585        from sage.rings.integer import Integer
     2586        self.conway = Integer(conway) if conway is not None else None
    25782587        self.prefix = prefix
    25792588
    25802589    def _apply_functor(self, R):
     
    25992608                return CyclotomicField(self.cyclotomic)
    26002609            if R==ZZ:
    26012610                return CyclotomicField(self.cyclotomic).maximal_order()
    2602         if len(self.polys) == 1:
     2611        if len(self.polys) == 1 or self.conway is not None:
    26032612            if is_FiniteField(R):
    2604                 return R.extension(self.polys[0], self.names[0], embedding=self.embeddings[0], prefix=self.prefix)
     2613                if self.conway is not None:
     2614                    return R.extension(self.conway, None, embedding=self.embeddings[0], prefix=self.prefix)
     2615                else:
     2616                    return R.extension(self.polys[0], self.names[0], embedding=self.embeddings[0], prefix=self.prefix)
    26052617            else:
    26062618                return R.extension(self.polys[0], self.names[0], embedding=self.embeddings[0])
    26072619        return R.extension(self.polys, self.names, embedding=self.embeddings)
     
    26432655          of the two embeddings is returned, provided that
    26442656          it is a number field.
    26452657        - If these two extensions are defined by Conway polynomials over finite fields
    2646           (indicated by the fact that their ``poly`` fields are just integers),
     2658          (indicated by the fact that their ``conway`` fields are integers and not None),
    26472659          merges them into a single extension of degree the product of the two degrees.
    26482660        - Otherwise, None is returned.
    26492661         
     
    27132725#                return other
    27142726        # ... or we may use the given embeddings
    27152727        from sage.rings.integer import Integer
    2716         # finite fields use an integer to encode the pseudo-Conway extension that allows pushouts
    2717         if isinstance(self.polys[0], Integer) and isinstance(other.polys[0], Integer) and self.prefix is not None and self.prefix == other.prefix:
     2728        # finite fields use an Integer to encode the pseudo-Conway extension that allows pushouts
     2729        if isinstance(self.conway, Integer) and isinstance(other.conway, Integer) and self.prefix is not None and self.prefix == other.prefix:
    27182730            if self.embeddings != [None] or other.embeddings != [None]:
    27192731                raise NotImplementedError
    2720             return AlgebraicExtensionFunctor([self.polys[0]*other.polys[0]],[None],[None],prefix=self.prefix)
     2732            return AlgebraicExtensionFunctor(self.polys+other.polys,self.names+other.names,self.embeddings+other.embeddings,conway=self.conway*other.conway,prefix=self.prefix)
    27212733        if self.embeddings!=[None] and other.embeddings!=[None]:
    27222734            from sage.all import QQ
    27232735            KS = self(QQ)
     
    27892801        """
    27902802        if len(self.polys)==1:
    27912803            return [self]
    2792         return [AlgebraicExtensionFunctor([self.polys[i]], [self.names[i]], [self.embeddings[i]]) for i in range(len(self.polys))]
     2804        return [AlgebraicExtensionFunctor([self.polys[i]], [self.names[i]], [self.embeddings[i]], conway=[self.polys[i].degree()] if self.conway is not None else None, prefix=self.prefix) for i in range(len(self.polys))]
    27932805
    27942806class AlgebraicClosureFunctor(ConstructionFunctor):
    27952807    """
     
    31143126    S_tower = construction_tower(S)
    31153127    Rs = [c[1] for c in R_tower]
    31163128    Ss = [c[1] for c in S_tower]
    3117    
     3129
    31183130    if R in Ss:
    31193131        return S
    31203132    elif S in Rs:
    31213133        return R
    31223134   
    3123     if R_tower[-1][1] in Ss:
     3135    if Rs[-1] in Ss:
    31243136        Rs, Ss = Ss, Rs
    31253137        R_tower, S_tower = S_tower, R_tower
    31263138   
  • sage/interfaces/singular.py

    diff --git a/sage/interfaces/singular.py b/sage/interfaces/singular.py
    a b  
    14301430            sage: singular.eval('minpoly = 1+z+z2+z3+z4')
    14311431            'minpoly = 1+z+z2+z3+z4;'
    14321432            sage: singular('r3').sage_global_ring()
    1433             Multivariate Polynomial Ring in a, b, c over Univariate Quotient Polynomial Ring in z over Finite Field of size 3 with modulus z^4 + z^3 + z^2 + z + 1
     1433            Multivariate Polynomial Ring in a, b, c over Finite Field in z of size 3^4
    14341434
    14351435        Real and complex fields in both Singular and Sage are defined with a precision.
    14361436        The precision in Singular is given in terms of digits, but in Sage it is given
     
    15171517                    singular.eval('short=%s'%is_short)
    15181518                else:
    15191519                    minpoly = ZZ[charstr[1]](minpoly)
    1520                 BR = br.extension(minpoly)
     1520                BR = br.extension(minpoly,name=charstr[1])
    15211521        else:
    15221522            BR = br
    15231523       
     
    15801580            'minpoly = 1+z+z2+z3+z4;'
    15811581            sage: p = singular('z^4*a^3+z^2*a*b*c')
    15821582            sage: p.sage_poly()
    1583             (2*z^3 + 2*z^2 + 2*z + 2)*a^3 + z^2*a*b*c
     1583            (-z^3 - z^2 - z - 1)*a^3 + (z^2)*a*b*c
    15841584            sage: singular('z^4')
    15851585            (-z3-z2-z-1)
    15861586
  • sage/matrix/action.pyx

    diff --git a/sage/matrix/action.pyx b/sage/matrix/action.pyx
    a b  
    55.. WARNING::
    66
    77    The class :class:`MatrixMulAction` and its descendants extends the class
    8     :class:`Action`. As a cosnequence objects from these classes only keep weak
     8    :class:`Action`. As a consequence objects from these classes only keep weak
    99    references to the underlying sets which are acted upon. This decision was
    1010    made in :trac:`715` in order to allow garbage collection within the coercion
    1111    framework, where actions are mainly used, and avoid memory leaks.
  • sage/rings/finite_rings/constructor.py

    diff --git a/sage/rings/finite_rings/constructor.py b/sage/rings/finite_rings/constructor.py
    a b  
    66Sage for several sizes of primes `p`. These implementations
    77are
    88
    9 
    109-  ``sage.rings.finite_rings.integer_mod.IntegerMod_int``,
    1110
    1211-  ``sage.rings.finite_rings.integer_mod.IntegerMod_int64``, and
     
    179178    Return the globally unique finite field of given order with
    180179    generator labeled by the given name and possibly with given
    181180    modulus.
    182    
     181
    183182    INPUT:
    184    
    185    
    186     -  ``order`` - int
    187    
    188     -  ``name`` - string; must be specified unless
    189        - ``order`` is prime
    190        - ``modulus`` is 'conway', in which case a name is generated
     183
     184    - ``order`` - int
     185
     186    - ``name`` - string; must be specified unless
     187
     188        - ``order`` is prime
     189        - ``modulus`` is 'conway', in which case a name is generated
    191190          from the degree and the ``prefix`` string.
    192    
    193     -  ``modulus`` - (optional) either a defining polynomial for the
    194        field, i.e., generator of the field will be a root of this
    195        polynomial; or a string:
    196191
    197            - 'conway': force the use of a pseudo-Conway polynomial.
    198             If a conway polynomial is found in the database, that is used.
    199             Otherwise, a polynomial is used with the same algebraic properties
    200             but without the lexicographic constraint implying uniqueness.
    201            - 'random': use a random irreducible polynomial;
    202            - 'default': a Conway polynomial is used if in the database. Otherwise
    203             a sparse polynomial is used for binary fields and a
    204             random polynomial is used for other characteristics.
    205            - 'first_lexicographic': uses the first irreducible polynomial.
     192    - ``modulus`` - (optional) either a defining polynomial for the
     193      field, i.e., generator of the field will be a root of this
     194      polynomial; or a string:
    206195
    207        Other options might be available depending on the
    208        implementation.
    209    
    210     -  ``elem_cache`` - cache all elements to avoid
    211        creation time (default: order < 500)
    212    
    213     -  ``check_irreducible`` - verify that the polynomial
    214        modulus is irreducible
     196        - ``'conway'``: force the use of a pseudo-Conway polynomial.
     197          If a conway polynomial is found in the database, that is used.
     198          Otherwise, a polynomial is used with the same algebraic properties
     199          but without the lexicographic constraint implying uniqueness.
     200        - ``'random'``: use a random irreducible polynomial.
     201        - ``'first_lexicographic'``: uses the first irreducible polynomial.
     202        - ``'default'``: a Conway polynomial is used if in the database.
     203          Otherwise a sparse polynomial is used for binary fields and a
     204          random polynomial is used for other characteristics.
     205        - Other options might be available depending on the implementation.
    215206
    216     - ``prefix`` (default: 'z') - a string used to generate names
     207    - ``elem_cache`` - cache all elements to avoid
     208      creation time (default: order < 500)
     209
     210    - ``check_irreducible`` - verify that the polynomial
     211      modulus is irreducible
     212
     213    - ``prefix`` (default: ``'z'``) - a string used to generate names
    217214      for subfields and pushouts of this field (mainly for use with
    218215      pseudo-Conway polynomials).
    219216
    220     - ``proof`` -- bool (default: True); if True use provable
     217    - ``proof`` -- bool (default: ``True``); if ``True`` use provable
    221218      primality test; otherwise only use pseudoprimality test.
    222    
    223     -  ``args`` - additional parameters passed to finite
    224        field implementations
    225    
    226     -  ``kwds`` - additional keyword parameters passed to
    227        finite field implementations
    228    
    229    
    230     ALIAS: You can also use GF instead of FiniteField - they are
    231     identical.
     219
     220    - ``args`` - additional parameters passed to finite
     221      field implementations
     222
     223    - ``kwds`` - additional keyword parameters passed to
     224      finite field implementations
     225
     226    ALIAS:
     227
     228    You can also use ``GF`` instead of ``FiniteField`` -- they are identical.
    232229
    233230    EXAMPLES::
    234    
     231
    235232        sage: k.<a> = FiniteField(9); k
    236233        Finite Field in a of size 3^2
    237234        sage: parent(a)
     
    240237        y^2 + 2*y + 2
    241238        sage: L = GF(27); L
    242239        Finite Field in z3 of size 3^3
    243    
     240
    244241    We illustrate the proof flag.  The following example would hang
    245     for a very long time if we didn't use proof=False.  (NOTE: Magma
    246     only supports proof=False for making finite fields, so falsely
    247     appears to be faster than Sage -- see Trac 10975.)::
     242    for a very long time if we didn't use ``proof=False``.
     243
     244    .. NOTE::
     245
     246        Magma only supports ``proof=False`` for making finite fields,
     247        so falsely appears to be faster than Sage -- see :trac:10975.
     248
     249    ::
    248250
    249251        sage: k = FiniteField(10^1000 + 453, proof=False)
    250252        sage: k = FiniteField((10^1000 + 453)^2, 'a', proof=False)      # long time -- about 5 seconds
    251253
    252254    ::
    253    
     255
    254256        sage: F.<x> = GF(5)[]
    255257        sage: K.<a> = GF(5**5, name='a', modulus=x^5 - x +1 )
    256258        sage: f = K.modulus(); f
    257259        x^5 + 4*x + 1
    258260        sage: type(f)
    259261         <type 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint'>
    260    
     262
    261263    The modulus must be irreducible::
    262    
     264
    263265        sage: K.<a> = GF(5**5, name='a', modulus=x^5 - x )
    264266        Traceback (most recent call last):
    265267        ...
    266268        ValueError: finite field modulus must be irreducible but it is not.
    267    
     269
    268270    You can't accidentally fool the constructor into thinking the modulus
    269271    is irreducible when it isn't mod p, since it actually tests
    270     irreducibility modulo p.  Also, the modulus has to be of the right degree.
    271    
    272     ::
    273    
     272    irreducibility modulo p.  Also, the modulus has to be of the right degree::
     273
    274274        sage: F.<x> = QQ[]
    275275        sage: factor(x^5 + 2)
    276276        x^5 + 2
     
    283283        ...
    284284        ValueError: The degree of the modulus does not correspond to the
    285285        cardinality of the field.
    286    
     286
    287287    If you wish to live dangerously, you can tell the constructor not
    288288    to test irreducibility using check_irreducible=False, but this can
    289289    easily lead to crashes and hangs - so do not do it unless you know
    290     that the modulus really is irreducible and has the correct degree!
    291    
    292     ::
    293    
     290    that the modulus really is irreducible and has the correct degree!::
     291
    294292        sage: F.<x> = GF(5)[]
    295293        sage: K.<a> = GF(5**2, name='a', modulus=x^2 + 2, check_irreducible=False)
    296294
     
    301299        [0, a, 1, 2, 1, 2, 1, 2, 1]
    302300
    303301    The order of a finite field must be a prime power::
    304    
     302
    305303        sage: GF(1)
    306304        Traceback (most recent call last):
    307305        ...
     
    310308        Traceback (most recent call last):
    311309        ...
    312310        ValueError: the order of a finite field must be a prime power.
    313    
     311
    314312    Finite fields with explicit random modulus are not cached::
    315    
     313
    316314        sage: k.<a> = GF(5**10, modulus='random')
    317315        sage: n.<a> = GF(5**10, modulus='random')
    318316        sage: n is k
    319317        False
    320318        sage: GF(5**10, 'a') is GF(5**10, 'a')
    321319        True
    322    
     320
    323321    We check that various ways of creating the same finite field yield
    324     the same object, which is cached.
    325    
    326     ::
    327    
     322    the same object, which is cached::
     323
    328324        sage: K = GF(7, 'a')
    329325        sage: L = GF(7, 'b')
    330326        sage: K is L
     
    337333        sage: M = GF(4,'a', K.modulus().change_variable_name('y'))
    338334        sage: K is M
    339335        True
    340    
    341     You may print finite field elements as integers. This
    342     currently only works if the order of field is `<2^{16}`,
    343     though.
    344    
    345     ::
    346    
     336
     337    You may print finite field elements as integers. This currently only works
     338    if the order of field is `< 2^{16}`, though::
     339
    347340        sage: k.<a> = GF(2^8, repr='int')
    348341        sage: a
    349342        2
    350 
    351343    """
    352344    def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
    353345                                  impl=None, prefix='z', proof=None, **kwds):
    354346        """
    355347        EXAMPLES::
    356        
     348
    357349            sage: GF.create_key_and_extra_args(9, 'a')
    358350            ((9, ('a',), 'conwayz', None, '{}', 3, 2, True), {})
    359351            sage: GF.create_key_and_extra_args(9, 'a', foo='value')
     
    403395
    404396                if isinstance(modulus, (list, tuple)):
    405397                    modulus = FiniteField(p)['x'](modulus)
    406                 # some classes use 'random' as the modulus to
    407                 # generate a random modulus, but we don't want
    408                 # to cache it
    409398                elif sage.rings.polynomial.polynomial_element.is_Polynomial(modulus):
     399                    # some classes use 'random' as the modulus to
     400                    # generate a random modulus, but we don't want
     401                    # to cache it
    410402                    modulus = modulus.change_variable_name('x')
     403                    # We might need the following for compatibility with
     404                    # the extension method of CommutativeRing class
     405                    if name is None:
     406                        name = str(modulus.parent().gen(0))
    411407                elif not isinstance(modulus, str):
    412408                    raise ValueError("Modulus parameter not understood.")
    413409            else:  # Neither a prime, nor a prime power
     
    551547
    552548    return isinstance(x, FiniteField_prime_modn) or \
    553549           (isinstance(x, FiniteField_generic) and x.degree() == 1)
    554    
    555 ##################################################################
    556    
     550
     551
    557552def conway_polynomial(p, n):
    558553    r"""
    559     Return the Conway polynomial of degree n over GF(p), which is
     554    Return the Conway polynomial of degree ``n`` over `F_p`, which is
    560555    loaded from a table.
    561    
     556
    562557    If the requested polynomial is not known, this function raises a
    563     RuntimeError exception.
    564    
     558    ``RuntimeError`` exception.
     559
    565560    INPUT:
    566    
    567    
    568     -  ``p`` - int
    569    
    570     -  ``n`` - int
    571    
    572    
     561
     562    - ``p`` -- int
     563
     564    - ``n`` -- int
     565
    573566    OUTPUT:
    574    
    575    
    576     -  ``Polynomial`` - a polynomial over the prime finite
    577        field GF(p).
    578    
    579    
    580     .. note::
    581567
    582        The first time this function is called a table is read from
    583        disk, which takes a fraction of a second. Subsequent calls do
    584        not require reloading the table.
    585    
     568    - ``Polynomial`` -- a polynomial over the prime finite
     569      field GF(p).
     570
     571    .. NOTE::
     572
     573       The first time this function is called a table is read from disk,
     574       which takes a fraction of a second.
     575       Subsequent calls do not require reloading the table.
     576
    586577    See also the ``ConwayPolynomials()`` object, which is a
    587     table of Conway polynomials. For example, if
    588     ``c=ConwayPolynomials()``, then
     578    table of Conway polynomials.
     579    For example, if ``c=ConwayPolynomials()``, then
    589580    ``c.primes()`` is a list of all primes for which the
    590581    polynomials are known, and for a given prime `p`,
    591582    ``c.degree(p)`` is a list of all degrees for which the
    592583    Conway polynomials are known.
    593    
     584
    594585    EXAMPLES::
    595    
     586
    596587        sage: conway_polynomial(2,5)
    597588        x^5 + x^2 + 1
    598589        sage: conway_polynomial(101,5)
     
    613604    r"""
    614605    Return True if the Conway polynomial over `F_p` of degree
    615606    `n` is in the database and False otherwise.
    616    
     607
    617608    If the Conway polynomial is in the database, to obtain it use the
    618609    command ``conway_polynomial(p,n)``.
    619    
     610
    620611    EXAMPLES::
    621    
     612
    622613        sage: exists_conway_polynomial(2,3)
    623614        True
    624615        sage: exists_conway_polynomial(2,-1)
     
    634625
    635626class PseudoConwayPolyTree(SageObject):
    636627    """
    637     An object holding references to pseudo-Conway polynomials for divisors of the given degree, so that they aren't garbage collected.
     628    An object holding references to pseudo-Conway polynomials for divisors
     629    of the given degree, so that they aren't garbage collected.
    638630    """
    639631    def __init__(self, p, n, nodes_dict, f):
    640632        """
    641         INPUT::
     633        INPUT:
    642634
    643         - p -- The prime for which this defines an extension of GF(p).
    644         - n -- The degree of the extension.
    645         - nodes_dict -- (dict or bool).  A dictionary of PseudoConwayPolyTrees, indexed by prime divisors of n.  The entry for q corresponds to the pseudo-Conway extension of degree n//q.
    646                         OR a boolean.  If True, then this polynomial is actually in the Conway polynomials database, and no references to other PCPTs are stored.  If False, then n is prime and no references are stored (since there is no compatiblity condition).
    647         - f -- The polynomial defining this extension.
     635        - ``p`` -- The prime for which this defines an extension of `F_p`.
     636
     637        - ``n`` -- The degree of the extension.
     638
     639        - ``nodes_dict`` -- dict or bool:
     640
     641          - Either a dictionary of ``PseudoConwayPolyTrees``, indexed by prime
     642            divisors of ``n``.
     643            The entry for `q` corresponds to the pseudo-Conway extension of
     644            degree `n/q`.
     645          - Or a boolean:
     646
     647            - If ``True``, then this polynomial is actually in the Conway
     648              polynomials database, and no references to other PCPTs are
     649              stored.
     650            - If ``False``, then ``n`` is prime and no references are stored
     651              (since there is no compatiblity condition).
     652
     653        - ``f`` -- The polynomial defining this extension.
    648654
    649655        EXAMPLES::
    650656
     
    657663        self.n = n
    658664        self.nodes_dict = nodes_dict
    659665        self.f = f
    660        
     666
    661667    def get_pseudo_conway_poly(self, m):
    662668        """
    663         Returns the pseudo-Conway polynomial associated to a divisor of the degree of this tree.
     669        Returns the pseudo-Conway polynomial associated to a divisor of the
     670        degree of this tree.
    664671
    665672        EXAMPLES::
    666        
     673
    667674            sage: from sage.rings.finite_rings.constructor import find_pseudo_conway_polynomial_tree
    668675            sage: PCPT = find_pseudo_conway_polynomial_tree(2, 6, False)
    669676            sage: PCPT.get_pseudo_conway_poly(3)
     
    681688            return pseudo_conway_poly[self.p][m]().f
    682689        except (KeyError, AttributeError):
    683690            return conway_polynomial(self.p, m)
    684            
     691
    685692    def check_consistency(self):
    686693        """
    687         Checks that the pseudo-Conway polynomials dividing the degree of this tree satisfy the required compatibility conditions.
     694        Checks that the pseudo-Conway polynomials dividing the degree of this
     695        tree satisfy the required compatibility conditions.
    688696
    689697        EXAMPLES::
    690698
     
    702710
    703711def find_pseudo_conway_polynomial_tree(p, n, use_database=True):
    704712    """
    705     Returns an object holding references to a set of consistent pseudo-Conway polynomials for degrees dividing n.
     713    Returns an object holding references to a set of consistent pseudo-Conway
     714    polynomials for degrees dividing ``n``.
    706715
    707     A Conway polynomial `f \in \Bold{F}_p` of degree `n` satisfies the following three conditions:
    708    
     716    A Conway polynomial `f \in \Bold{F}_p` of degree `n` satisfies the
     717    following three conditions:
     718
    709719    - `f` is irreducible.
    710     - In the quotient field `\Bold{F}_p[x]/(f)`, the indeterminant `x` is a multiplicative generator.
    711     - In this same quotient field, the minimal polynomial of `x^{\frac{p^n-1}{p^m-1}}` is the Conway polynomial of degree `m` for every divisor `m` of `n`.
    712     - `f` is lexicographically least among all such polynomials, under a certain ordering.
     720    - In the quotient field `\Bold{F}_p[x]/(f)`, the indeterminant `x` is a
     721      multiplicative generator.
     722    - In this same quotient field, the minimal polynomial of
     723      `x^{\frac{p^n-1}{p^m-1}}` is the Conway polynomial of degree `m`
     724      for every divisor `m` of `n`.
     725    - `f` is lexicographically least among all such polynomials,
     726      under a certain ordering.
    713727
    714     The final condition is needed only in order to make the Conway polynomial unique.  We define a pseudo-Conway polynomial to be one satisfying the first three conditions.
     728    The final condition is needed only in order to make the Conway polynomial
     729    unique.
     730    We define a pseudo-Conway polynomial to be one satisfying the first three
     731    conditions.
    715732
    716733    INPUT:
    717734
    718     - `p` -- a prime.
    719     - `n` -- an integer greater than 1.
    720     - `use_database` -- whether to use the Conway polynomials database if the Conway polynomial for `p, n` exists within it (versus computing a pseudo-Conway polynomial)
     735    - ``p`` -- a prime.
     736
     737    - ``n`` -- an integer greater than 1.
     738
     739    - ``use_database`` -- whether to use the Conway polynomials database if
     740      the Conway polynomial for `p, n` exists within it (versus computing a
     741      pseudo-Conway polynomial)
    721742
    722743    EXAMPLES::
    723744
    724745        sage: from sage.rings.finite_rings.constructor import find_pseudo_conway_polynomial_tree
    725746        sage: PCPT = find_pseudo_conway_polynomial_tree(2, 12, False)
    726747        sage: PCPT.f
    727         x^12 + x^10 + x^9 + x^8 + x^4 + x^2 + 1
     748        x^12 + x^11 + x^10 + x^4 + 1
    728749    """
    729750    if not pseudo_conway_poly.has_key(p):
    730751        pseudo_conway_poly[p] = {}
     
    753774
    754775    INPUT:
    755776
    756     - `p` -- a prime.
     777    - ``p`` -- a prime.
     778
    757779    - ``field_degree`` -- a positive integer
    758     - `x` -- an element of a field `K` of characeristic p so that the multiplicative order of `x` is ``p^field_degree``.
    759     - `y` -- an element of `K` with the same minimal polynomial.
    760    
     780
     781    - ``x`` -- an element of a field `K` of characeristic p so that the
     782      multiplicative order of `x` is ``p^field_degree``.
     783
     784    - ``y`` -- an element of `K` with the same minimal polynomial.
     785
    761786    OUTPUT:
    762    
     787
    763788    An element `i` of ``Integers(field_degree)`` so that `x = y^{p^i}`
    764789
    765790    EXAMPLES::
     
    784809
    785810def _crt_non_coprime(running, a):
    786811    """
    787     Extends the ``crt`` method of IntegerMod to the case of non-relatively prime modulus.
     812    Extends the ``crt`` method of IntegerMod to the case of non-relatively
     813    prime modulus.
    788814
    789815    EXAMPLES::
    790816
     
    816842
    817843def _frobenius_shift(K, generators, check_only=False):
    818844    """
    819     Given a field `K` of degree `n` over ``GF(p)`` and a dictionary holding, for each divisor `q` of `n`, an element with minimal polynomial a pseudo-Conway polynomial of degree `n/q`, modifies these generators into a compatibile system.
     845    Given a field `K` of degree `n` over `F_p` and a dictionary holding,
     846    for each divisor `q` of `n`, an element with minimal polynomial a
     847    pseudo-Conway polynomial of degree `n/q`, modifies these generators into a
     848    compatibile system.
    820849
    821     Such a system of generators is said to be compatible if for each pair of prime divisors `q_1` and `q_2` and each common divisor `m` of `n/q_1` and `n/q_2`, the equality
     850    Such a system of generators is said to be compatible if for each pair of
     851    prime divisors `q_1` and `q_2` and each common divisor `m` of `n/q_1` and
     852    `n/q_2`, the equality
    822853
    823854    ``generators[q1]^((p^(n/q1)-1)/(p^m-1)) == generators[q2]^((p^(n/q2)-1)/(p^m-1))``
    824855
     
    826857
    827858    INPUT:
    828859
    829     - K -- a finite field of degree n   
    830     - generators -- a dictionary, indexed by prime divisors `q` of `n`, whose entries are elements of `K` satisfying the `n/q` pseudo-Conway polynomial.
    831     - check_only -- if True, just asserts that the generators given form a compatible system.
     860    - ``K`` -- a finite field of degree n
     861
     862    - ``generators`` -- a dictionary, indexed by prime divisors `q` of `n`,
     863      whose entries are elements of `K` satisfying the `n/q` pseudo-Conway
     864      polynomial.
     865
     866    - ``check_only`` -- if ``True``, just asserts that the generators given
     867      form a compatible system.
    832868
    833869    EXAMPLES::
    834870
     
    9791015    """
    9801016    Computes a pseudo-Conway polynomial over the prime `p` of degree `n`.
    9811017
    982     A Conway polynomial `f \in \Bold{F}_p` of degree `n` satisfies the following three conditions:
    983    
     1018    A Conway polynomial `f \in \Bold{F}_p` of degree `n` satisfies the
     1019    following three conditions:
     1020
    9841021    - `f` is irreducible.
    985     - In the quotient field `\Bold{F}_p[x]/(f)`, the indeterminant `x` is a multiplicative generator.
    986     - In this same quotient field, the minimal polynomial of `x^{\frac{p^n-1}{p^m-1}}` is the Conway polynomial of degree `m` for every divisor `m` of `n`.
    987     - `f` is lexicographically least among all such polynomials, under a certain ordering.
     1022    - In the quotient field `\Bold{F}_p[x]/(f)`, the indeterminant `x` is a
     1023      multiplicative generator.
     1024    - In this same quotient field, the minimal polynomial of
     1025      `x^{\frac{p^n-1}{p^m-1}}` is the Conway polynomial of degree `m`
     1026      for every divisor `m` of `n`.
     1027    - `f` is lexicographically least among all such polynomials,
     1028      under a certain ordering.
    9881029
    989     The final condition is needed only in order to make the Conway polynomial unique.  We define a pseudo-Conway polynomial to be one satisfying the first three conditions.
     1030    The final condition is needed only in order to make the Conway polynomial
     1031    unique.  We define a pseudo-Conway polynomial to be one satisfying the
     1032    first three conditions.
    9901033
    9911034    INPUT:
    992    
    993     - `p` -- a prime
    994     - `n` -- a positive integer
    995     - ``nodes`` -- None (in the case that `n` is prime) or a dictionary of PseudoConwayPolyTree objects, indexed by prime divisors `q` of `n` with entries corresponding to pseudo-Conway polynomials of degree `n/q`.
     1035
     1036    - ``p`` -- a prime
     1037
     1038    - ``n`` -- a positive integer
     1039
     1040    - ``nodes`` -- None (in the case that `n` is prime) or a dictionary
     1041      of PseudoConwayPolyTree objects, indexed by prime divisors `q` of `n`
     1042      with entries corresponding to pseudo-Conway polynomials of degree `n/q`.
    9961043
    9971044    OUTPUT:
    9981045
    9991046    A pseudo-Conway polynomial over the prime `p` of degree `n`.
    10001047
    10011048    ALGORITHM:
    1002    
    1003     Uses an algorithm described in [HL99]_, modified to find pseudo-Conway polynomials rather than Conway polynomials.  The major modification was the addition of the function _frobenius_shift.
     1049
     1050    Uses an algorithm described in [HL99]_, modified to find pseudo-Conway
     1051    polynomials rather than Conway polynomials.
     1052    The major modification was the addition of the function ``_frobenius_shift``.
    10041053
    10051054    REFERENCE:
    10061055
    1007     .. [HL99] Heath L. and Loehr N. (1999). 
     1056    .. [HL99] Heath L. and Loehr N. (1999).
    10081057       New algorithms for generating Conway polynomials over finite fields.
    1009        Proceedings of the tenth annual ACM-SIAM symposium on Discrete algorithms, pp. 429-437.
     1058       Proceedings of the tenth annual ACM-SIAM symposium on Discrete
     1059       algorithms, pp. 429-437.
    10101060
    10111061    EXAMPLES::
    10121062
    10131063        sage: from sage.rings.finite_rings.constructor import compute_pseudo_conway_polynomial, find_pseudo_conway_polynomial_tree
    10141064        sage: compute_pseudo_conway_polynomial(next_prime(10000),11,None) # long because the arithmetic in FiniteField_ext_pari fields is slow.
    1015         x^11 + x + 7
     1065        x^11 + x + 24
    10161066        sage: PCPT30 = find_pseudo_conway_polynomial_tree(2, 30, False)
    10171067        sage: PCPT20 = find_pseudo_conway_polynomial_tree(2, 20, False)
    10181068        sage: PCPT12 = find_pseudo_conway_polynomial_tree(2, 12, False)
    10191069        sage: compute_pseudo_conway_polynomial(2, 60, {2:PCPT30,3:PCPT20,5:PCPT12})
    1020         x^60 + x^59 + x^56 + x^53 + x^49 + x^45 + x^43 + x^42 + x^41 + x^40 + x^39 + x^37 + x^36 + x^34 + x^31 + x^30 + x^27 + x^26 + x^25 + x^23 + x^21 + x^19 + x^17 + x^15 + x^14 + x^11 + x^9 + x^8 + x^7 + x^6 + x^5 + x^2 + 1
     1070        x^60 + x^58 + x^56 + x^55 + x^52 + x^51 + x^50 + x^47 + x^44 + x^39 + x^36 + x^33 + x^31 + x^28 + x^27 + x^25 + x^23 + x^21 + x^17 + x^15 + x^14 + x^13 + x^11 + x^10 + x^9 + x^8 + x^7 + x^4 + 1
    10211071    """
    10221072    k = GF(p)
    10231073    from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
    10241074    R = PolynomialRing(k, names='x')
    10251075    if n == 1:
    10261076        return R([-k.multiplicative_generator(), 1])
    1027     if nodes is None:
    1028         # n is prime.  We require only that the chosen generator (x) be a multiplicative generator for the units.
    1029         if p in [2,3,5,7,11]: # here we have Cunningham data
    1030             from sage.rings.factorint import factor_cunningham
    1031             F = [(p**n-1)//a for a, e in factor_cunningham(n)]
    1032         else:
    1033             F = (p**n-1).prime_factors() # could be VERY expensive
     1077    if nodes is None:
     1078        # n is prime.
     1079        # We only require that the chosen generator (x) is a multiplicative
     1080        # generator for the units.
     1081        q = p**n - 1
     1082        F = [q//m for m in q.prime_factors()] # could be VERY expensive
    10341083        x = R.gen()
    10351084        from sage.rings.arith import power_mod
    10361085        for f in R.polynomials(of_degree=n):
     
    10451094                    return f
    10461095    # Our strategy is as follows:
    10471096    # Work in an arbitrary field K of order p**n.
    1048     # We're looking for a multiplicative generator of K whose 
     1097    # We're looking for a multiplicative generator of K whose
    10491098    K = GF(p**n, modulus="first_lexicographic", names='a')
    10501099    r = p**n - 1
    10511100    xi = {}
     
    10531102        #print nodes[q].f.degree(), n//q
    10541103        xi[q] = nodes[q].f.any_root(K, -n//q, True)
    10551104    _frobenius_shift(K, xi)
    1056            
     1105
    10571106    q, x = xi.popitem()
    10581107    v = p**(n//q) - 1
    10591108    for q, xitem in xi.iteritems():
     
    10631112        v = v.lcm(fi)
    10641113    g = r // v
    10651114    #print g, n, g.divides(p**n-1)
    1066     z = x.nth_root(g, cunningham=(p in [2,3,5,7,11]))
     1115    # The following could be useful if #7240 is merged but #12125 is not.
     1116    #z = x.nth_root(g, cunningham=(p in [2,3,5,7,11]))
     1117    z = x.nth_root(g)
    10671118    groot1 = K.multiplicative_generator()**v
    10681119    while z.multiplicative_order() != r:
    10691120        z *= groot1
  • sage/rings/finite_rings/element_base.pyx

    diff --git a/sage/rings/finite_rings/element_base.pyx b/sage/rings/finite_rings/element_base.pyx
    a b  
    3232cdef class FiniteRingElement(CommutativeRingElement):
    3333    def _nth_root_common(self, n, all, algorithm, cunningham):
    3434        """
    35         This function exists to reduce code duplication between finite field nth roots and integer_mod nth roots.
    36        
     35        This function exists to reduce code duplication between finite field
     36        nth roots and integer_mod nth roots.
     37
    3738        The inputs are described there.
    38        
     39
    3940        TESTS::
    40        
     41
    4142            sage: a = Zmod(17)(13)
    4243            sage: a._nth_root_common(4, True, "Johnston", False)
    4344            [3, 5, 14, 12]
     
    545546        - ``all`` - bool (default: ``False``); if ``True``, return all `n`\th
    546547          roots of ``self``, instead of just one.
    547548
    548         - ``algorithm`` - string (default: ``None``); 'Johnston' is the only 
     549        - ``algorithm`` - string (default: ``None``); 'Johnston' is the only
    549550          currently supported option.  For IntegerMod elements, the problem
    550551          is reduced to the prime modulus case using CRT and `p`-adic logs,
    551552          and then this algorithm used.
     
    553554        OUTPUT:
    554555
    555556        If self has an `n`\th root, returns one (if ``all`` is ``False``) or a
    556         list of all of them (if ``all`` is ``True``).  Otherwise, raises a
    557         ValueError (if ``extend`` is ``False``) or a ``NotImplementedError`` (if
    558         ``extend`` is ``True``).
     557        list of all of them (if ``all`` is ``True``).
     558        Otherwise, raises a ``ValueError`` (if ``extend`` is ``False``)
     559        or a ``NotImplementedError`` (if ``extend`` is ``True``).
    559560
    560561        .. warning::
    561        
    562            The 'extend' option is not implemented (yet).
     562
     563           The ``extend`` option is not implemented (yet).
    563564
    564565        EXAMPLES::
    565566
  • sage/rings/finite_rings/finite_field_base.pyx

    diff --git a/sage/rings/finite_rings/finite_field_base.pyx b/sage/rings/finite_rings/finite_field_base.pyx
    a b  
    551551            [2^4 * 3]
    552552        """
    553553        if self.__factored_unit_order is None:
    554             if self.characteristic() in []: # want to be [2,3,5,7,11] once #7240 is finished.
    555                 from sage.rings.factorint import factor_cunningham
    556                 self.__factored_unit_order = [factor_cunningham(self.order()-1)]
    557             else:
    558                 self.__factored_unit_order = [(self.order()-1).factor()]
     554            self.__factored_unit_order = [(self.order()-1).factor()]
    559555        return self.__factored_unit_order
    560556
    561557    def cardinality(self):
     
    748744
    749745    def construction(self):
    750746        """
    751         Returns the construction of this finite field, as a ConstructionFunctor and the base field.
     747        Return the construction of this finite field, as a ``ConstructionFunctor``
     748        and the base field.
    752749
    753750        EXAMPLES::
    754        
     751
    755752            sage: v = GF(3^3).construction(); v
    756753            (AlgebraicExtensionFunctor, Finite Field of size 3)
    757754            sage: v[0].polys[0]
    758             3
     755            z3^3 + 2*z3 + 1
    759756            sage: v = GF(2^1000,'a').construction(); v[0].polys[0]
    760757            a^1000 + a^5 + a^4 + a^3 + 1
    761758        """
     
    763760        if self.degree() == 1:
    764761            # this is not of type FiniteField_prime_modn
    765762            from sage.rings.integer import Integer
    766             return AlgebraicExtensionFunctor([Integer(1)], [None],[None]), self.base_ring()
     763            return AlgebraicExtensionFunctor([self.polynomial()],[None],[None],conway=1), self.base_ring()
    767764        elif hasattr(self, '_PCPT') and self._PCPT is not None:
    768             return AlgebraicExtensionFunctor([self.degree()], [self.variable_name()],[None],prefix=self._prefix), self.base_ring()
     765            return AlgebraicExtensionFunctor([self.polynomial()],[self.variable_name()],[None],conway=self.degree(),prefix=self._prefix), self.base_ring()
    769766        else:
    770             return AlgebraicExtensionFunctor([self.polynomial()], [self.variable_name()],[None]), self.base_ring()
     767            return AlgebraicExtensionFunctor([self.polynomial()],[self.variable_name()],[None]), self.base_ring()
    771768
    772     def extension(self, modulus, name=None, names=None, embedding=None, prefix='z'):
     769    def extension(self, modulus, name=None, names=None, embedding=None, conway=None, prefix='z'):
    773770        """
    774         Returns an extension of this finite field.
     771        Return an extension of this finite field.
    775772
    776         INPUT::
     773        INPUT:
    777774
    778         - modulus -- either a polynomial with coefficients in this field or an integer. 
    779                      If an integer, returns the pseudo-Conway extension of this field of that degree.
    780         - name -- the name of the generator in the new extension
    781         - embedding -- currently not used; for compatibility with other AlgebraicExtensionFunctor calls.
    782         - prefix -- Passed on to the finite field constructor.  See the documentation of
    783                     ``GF`` in ``sage.rings.finite_rings.constructor``
     775        - ``modulus`` -- either a polynomial with coefficients in this field or
     776          an integer.
     777          If an Integer, returns the pseudo-Conway extension of this field of
     778          that degree.
    784779
    785         OUTPUT::
    786        
    787         An extension of the given modulus, or pseudo-Conway of the given degree if the modulus is just an integer.
    788        
     780        - ``name`` -- the name of the generator in the new extension
     781
     782        - ``embedding`` -- currently not used; for compatibility with other
     783          ``AlgebraicExtensionFunctor`` calls.
     784
     785        - ``conway`` -- currently not used; None or an ``Integer`` used to indicate
     786          that the extension is pseudo-Conway of the given degree.
     787
     788        - ``prefix`` -- Passed on to the finite field constructor.
     789          See the documentation of ``GF`` in ``sage.rings.finite_rings.constructor``
     790
     791        OUTPUT:
     792
     793        An extension of the given modulus, or pseudo-Conway of the given degree
     794        if ``conway`` is an integer.
     795
    789796        EXAMPLES::
    790797
     798            sage: k = GF(2)
     799            sage: R.<x> = k[]
     800            sage: k.extension(x^1000 + x^5 + x^4 + x^3 + 1, 'a')
     801            Finite Field in a of size 2^1000
    791802            sage: k = GF(3^4)
     803            sage: R.<x> = k[]
    792804            sage: k.extension(3)
    793805            Finite Field in z12 of size 3^12
    794             sage: R.<x> = GF(2)[]
    795             sage: GF(2).extension(x^1000 + x^5 + x^4 + x^3 + 1,'a')
    796             Finite Field in a of size 2^1000
    797             sage: R.<x> = GF(3)[]
    798806
    799         Extensions of non-prime finite fields by polynomials are not yet supported: we fall back to generic code.
     807        Extensions of non-prime finite fields by polynomials are not yet
     808        supported: we fall back to generic code::
    800809
    801810            sage: k.extension(x^5 + x^2 + x - 1)
    802811            Univariate Quotient Polynomial Ring in x over Finite Field in z4 of size 3^4 with modulus x^5 + x^2 + x + 2
    803812        """
    804813        from constructor import GF
     814        from sage.rings.polynomial.all import is_Polynomial
    805815        from sage.rings.integer import Integer
    806         from sage.rings.polynomial.all import is_Polynomial
    807816        if name is None and names is not None:
    808817            name = names
    809818        if self.degree() == 1:
    810819            if isinstance(modulus, Integer):
    811820                return GF(self.characteristic()**modulus, modulus='conway', name=name, prefix=prefix)
    812             if isinstance(modulus, (list, tuple)):
     821            elif isinstance(modulus, (list, tuple)):
    813822                return GF(self.characteristic()**(len(modulus) - 1), name=name, modulus=modulus, prefix=prefix)
    814823            elif is_Polynomial(modulus):
    815824                if modulus.change_ring(self).is_irreducible():
     
    823832
    824833    def subfields(self, degree=0, name=None):
    825834        """
    826         Return all proper subfields of self of the given degree,
    827         or of all possible degrees if degree is 0. 
     835        Return all proper subfields of ``self`` of the given ``degree``,
     836        or of all possible degrees if ``degree`` is `0`.
    828837
    829         The subfields are returned as
    830         absolute fields together with an embedding into self.
     838        The subfields are returned as absolute fields together with
     839        an embedding into ``self``.
    831840
    832         INPUT::
     841        INPUT:
    833842
    834         - degree -- (default 0) An integer.
    835         - name -- A string, a dictionary or None.
    836                   If degree is nonzero, name must be a string (or None, if this is a pseudo-Conway extension), and will be the variable name of the returned field.
    837                   If degree is zero, the dictionary should have keys the divisors of the degree of this field, with the desired variable name for the field of that degree as an entry.
    838                   As a shortcut, you can provide a string and the degree of each subfield will be appended for the variable name of that subfield.
    839                   If None, uses the prefix of this field.
    840    
    841         OUTPUT::
     843        - ``degree`` -- (default: `0`) an integer
    842844
    843         A list of pairs (K, e), where K ranges over the subfields of this field and e gives an embedding of K into this field.
     845        - ``name`` -- a string, a dictionary or ``None``:
     846
     847          - If ``degree`` is nonzero, ``name`` must be a string
     848            (or ``None``, if this is a pseudo-Conway extension),
     849            and will be the variable name of the returned field.
     850          - If ``degree`` is zero, the dictionary should have keys the divisors
     851            of the degree of this field, with the desired variable name for the
     852            field of that degree as an entry.
     853          - As a shortcut, you can provide a string and the degree of each
     854            subfield will be appended for the variable name of that subfield.
     855          - If ``None``, uses the prefix of this field.
     856
     857        OUTPUT:
     858
     859        A list of pairs ``(K, e)``, where ``K`` ranges over the subfields of
     860        this field and ``e`` gives an embedding of ``K`` into this field.
    844861
    845862        EXAMPLES::
    846863
    847864            sage: k.<a> = GF(2^21)
    848865            sage: k.subfields()
    849             [(Finite Field of size 2, 
     866            [(Finite Field of size 2,
    850867              Conversion map:
    851868                  From: Finite Field of size 2
    852869                  To:   Finite Field in a of size 2^21),
     
    923940           This is not yet implemented for finite fields.
    924941
    925942        EXAMPLES::
    926        
     943
    927944            sage: GF(5).algebraic_closure()
    928945            Traceback (most recent call last):
    929946            ...
     
    947964    r"""
    948965    Used to unpickle finite prime fields. Now superseded (hence no doctest),
    949966    but kept around for backward compatibility.
    950    
     967
    951968    EXAMPLE::
    952969
    953970        sage: # not tested
     
    974991        False
    975992    """
    976993    return IS_INSTANCE(x, FiniteField)
    977 
  • sage/rings/finite_rings/finite_field_givaro.py

    diff --git a/sage/rings/finite_rings/finite_field_givaro.py b/sage/rings/finite_rings/finite_field_givaro.py
    a b  
    2727    - ``name`` -- (default: ``'a'``) variable used for
    2828      :meth:`~sage.rings.finite_rings.element_givaro.FiniteField_givaroElement.poly_repr()`
    2929
    30     - ``modulus`` -- (default: ``conway``, a conway polynomial is used if in
     30    - ``modulus`` -- (default: ``'conway'``, a conway polynomial is used if in
    3131      the database, otherwise a pseudo-Conway polynomial is generated)
    3232      A minimal polynomial to use for reduction or ``'random'`` to force a
    3333      random irreducible polynomial.
  • sage/rings/finite_rings/integer_mod.pyx

    diff --git a/sage/rings/finite_rings/integer_mod.pyx b/sage/rings/finite_rings/integer_mod.pyx
    a b  
    20382038        IntegerMod_abstract.__init__(self, parent)
    20392039        if empty:
    20402040            return
     2041        if self.__modulus.int32 == 1:
     2042            self.ivalue = 0
     2043            return
    20412044        cdef long x
    20422045        if PY_TYPE_CHECK(value, int):
    20432046            x = value
  • sage/rings/finite_rings/integer_mod_ring.py

    diff --git a/sage/rings/finite_rings/integer_mod_ring.py b/sage/rings/finite_rings/integer_mod_ring.py
    a b  
    395395        """
    396396        return True
    397397
     398    def extension(self, poly, name=None, names=None, embedding=None):
     399        if self.modulus() == 1:
     400            return self
     401        else:
     402            from sage.rings.ring import CommutativeRing
     403            return CommutativeRing.extension(self, poly, name, names, embedding)
     404
    398405    @cached_method
    399406    def is_prime_field(self):
    400407        """
  • sage/rings/polynomial/polynomial_element.pyx

    diff --git a/sage/rings/polynomial/polynomial_element.pyx b/sage/rings/polynomial/polynomial_element.pyx
    a b  
    53675367        Returns a root of this polynomial in the given ring.
    53685368
    53695369        INPUT:
    5370        
    5371         - ``ring`` -- The ring in which a root is sought.  By default this is the coefficient ring.
    5372 
    5373         - ``degree`` (None or nonzero integer) -- Used for polynomials over finite fields.  Returns a root of degree ``abs(degree)`` over the ground field.  If negative, also assumes that all factors of this polynomial are of degree ``abs(degree)``.  If None, returns a root of minimal degree contained within the given ring.
    5374 
    5375         - ``assume_squarefree`` (bool) -- Used for polynomials over finite fields.  If True, this polynomial is assumed to be squarefree.
    5376 
    5377         - ``extend`` -- Used for polynomials over finite fields.  If ``ring is None`` and ``extend`` is true, finds a root in the smallest extension of the base ring over which this polynomial has a root.  If ``ring is None`` and ``extend`` is false, only looks for a root in the base ring.  If ``ring`` is specified, then extend=True allows a root to lie in an extension of the given ring.
     5370
     5371        - ``ring`` -- The ring in which a root is sought.
     5372          By default this is the coefficient ring.
     5373
     5374        - ``degree`` (None or nonzero integer) -- Used for polynomials over
     5375          finite fields. Returns a root of degree ``abs(degree)`` over the
     5376          ground field. If negative, also assumes that all factors of this
     5377          polynomial are of degree ``abs(degree)``. If ``None``, returns a root
     5378          of minimal degree contained within the given ring.
     5379
     5380        - ``assume_squarefree`` (bool) -- Used for polynomials over
     5381          finite fields. If ``True``, this polynomial is assumed to be
     5382          squarefree.
     5383
     5384        - ``extend`` -- Used for polynomials over finite fields.
     5385          If ``ring`` is ``None`` and ``extend`` is ``True``, finds a root in
     5386          the smallest extension of the base ring over which this polynomial
     5387          has a root. If ``ring`` is ``None`` and ``extend`` is ``False``, only
     5388          looks for a root in the base ring. If ``ring`` is specified, then
     5389          ``extend=True`` allows a root to lie in an extension of the given
     5390          ring.
    53785391
    53795392        EXAMPLES::
    53805393
  • 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  
    5353    -  ``ring`` - a univariate polynomial ring in one
    5454       variable.
    5555   
    56     -  ``polynomial`` - element
     56    -  ``polynomial`` - element with unit leading coefficient
    5757   
    5858    -  ``names`` - (optional) name for the variable
    5959   
  • sage/rings/polynomial/polynomial_quotient_ring_element.py

    diff --git a/sage/rings/polynomial/polynomial_quotient_ring_element.py b/sage/rings/polynomial/polynomial_quotient_ring_element.py
    a b  
    130130                raise TypeError, "polynomial must be in the polynomial ring of the parent"
    131131
    132132        f = parent.modulus()
    133         if polynomial.degree() >= f.degree():
     133        if polynomial.degree() >= f.degree() and polynomial.degree() >= 0:
    134134            try:
    135135                polynomial %= f
    136136            except AttributeError:
     
    143143                while R.degree() >= B.degree():
    144144                    S = P((R.leading_coefficient()/B.leading_coefficient())) * X**(R.degree()-B.degree())
    145145                    Q = Q + S
    146                     R = R - S*B           
     146                    R = R - S*B
    147147                polynomial = R
    148148        self._polynomial = polynomial
    149149
  • sage/rings/polynomial/polynomial_ring.py

    diff --git a/sage/rings/polynomial/polynomial_ring.py b/sage/rings/polynomial/polynomial_ring.py
    a b  
    181181from polynomial_real_mpfr_dense import PolynomialRealDense
    182182from sage.rings.polynomial.polynomial_singular_interface import PolynomialRing_singular_repr
    183183from sage.rings.fraction_field_element import FractionFieldElement
     184from sage.rings.finite_rings.element_base import FiniteRingElement
    184185
    185186from polynomial_element import PolynomialBaseringInjection
    186187
     
    417418                x = x.numerator() * x.denominator().inverse_of_unit()
    418419            else:
    419420                raise TypeError, "denominator must be a unit"
    420            
    421421        elif isinstance(x, pari_gen):
    422422            if x.type() == 't_RFRAC':
    423423                raise TypeError, "denominator must be a unit"
    424424            if x.type() != 't_POL':
    425425                x = x.Polrev()
     426        elif isinstance(x, FiniteRingElement):
     427            try:
     428                return self(x.polynomial())
     429            except AttributeError:
     430                pass
    426431        return C(self, x, check, is_gen, construct=construct, **kwds)
    427432
    428433    def is_integral_domain(self, proof = True):