Ticket #8335: trac_8335-fixes-5.11.b3.patch

File trac_8335-fixes-5.11.b3.patch, 58.9 KB (added by jpflori, 8 years ago)
  • sage/categories/pushout.py

    # HG changeset patch
    # User Jean-Pierre Flori <jean-pierre.flori@ssi.gouv.fr>
    # Date 1372263982 -7200
    # Node ID f2a82303e5d309cb33b283e5c412aeca7d06c0c6
    # Parent  1b985f4cccbf68e5409bd862f03372b98be4bbef
    #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.::
    23532353
    23542354            sage: F = ZZ.quo([5]*ZZ).construction()[0]
    2355             sage: F(QQ) is Integers(1)
    2356             True
     2355            sage: F(QQ)
     2356            Ring of integers modulo 1
    23572357            sage: QQ.quo(5)
    23582358            Quotient of Rational Field by the ideal (1)
    2359 
    23602359        """
    23612360        I = self.I
    23622361        from sage.all import QQ
    23632362        if not I.is_zero():
    23642363            from sage.categories.fields import Fields
    23652364            if R in Fields():
     2365                #raise CoercionException, "Trivial quotient ring."
    23662366                from sage.all import Integers
    23672367                return Integers(1)
    23682368        if I.ring() != R:
     
    24932493    """
    24942494    rank = 3
    24952495   
    2496     def __init__(self, polys, names, embeddings, cyclotomic=None, prefix=None):
     2496    def __init__(self, polys, names, embeddings, cyclotomic=None, conway=None, prefix=None):
    24972497        """
    24982498        INPUT:
    24992499
     
    25082508        - ``cyclotomic``: optional integer. If it is provided,
    25092509          application of the functor to the rational field yields
    25102510          a cyclotomic field, rather than just a number field.
     2511        - ``conway``: optional integer. If it is provided,
     2512          application of the functor to finite fields yields
     2513          pseudo-Conway extensions of the given degree.
    25112514        - ``prefix``: optional string.  If it is provided, it will
    25122515          allow application of this functor to some finite fields to
    25132516          function without providing a variable name
     
    25752578        self.names = list(names)
    25762579        self.embeddings = list(embeddings)
    25772580        self.cyclotomic = int(cyclotomic) if cyclotomic is not None else None
     2581        from sage.rings.integer import Integer
     2582        self.conway = Integer(conway) if conway is not None else None
    25782583        self.prefix = prefix
    25792584
    25802585    def _apply_functor(self, R):
     
    25992604                return CyclotomicField(self.cyclotomic)
    26002605            if R==ZZ:
    26012606                return CyclotomicField(self.cyclotomic).maximal_order()
    2602         if len(self.polys) == 1:
     2607        if len(self.polys) == 1 or self.conway is not None:
    26032608            if is_FiniteField(R):
    2604                 return R.extension(self.polys[0], self.names[0], embedding=self.embeddings[0], prefix=self.prefix)
     2609                if self.conway is not None:
     2610                    return R.extension(self.conway, self.names[0], embedding=self.embeddings[0], prefix=self.prefix)
     2611                else:
     2612                    return R.extension(self.polys[0], self.names[0], embedding=self.embeddings[0], prefix=self.prefix)
    26052613            else:
    26062614                return R.extension(self.polys[0], self.names[0], embedding=self.embeddings[0])
    26072615        return R.extension(self.polys, self.names, embedding=self.embeddings)
     
    26432651          of the two embeddings is returned, provided that
    26442652          it is a number field.
    26452653        - If these two extensions are defined by Conway polynomials over finite fields
    2646           (indicated by the fact that their ``poly`` fields are just integers),
    2647           merges them into a single extension of degree the product of the two degrees.
     2654          (indicated by the fact that their ``conway`` fields are integers and not None),
     2655          merges them into a single extension of degree the lcm of the two degrees.
    26482656        - Otherwise, None is returned.
    2649          
     2657
    26502658        REMARK:
    26512659
    26522660        Algebraic extension with embeddings currently only
     
    26542662        why we use the admittedly strange rule above for
    26552663        merging.
    26562664
    2657         TESTS::
    2658 
    2659             sage: k = GF(3^3)
    2660             sage: l = GF(3^2)
    2661             sage: k.gen() + l.gen() # indirect doctest
     2665        EXAMPLES:
     2666
     2667        The following demonstrate coercions for finite fields using Conway or
     2668        pseudo-Conway polynomials::
     2669
     2670            sage: k = GF(3^2); a = k.gen()
     2671            sage: l = GF(3^3); b = l.gen()
     2672            sage: a + b # indirect doctest
    26622673            z6^5 + 2*z6^4 + 2*z6^3 + z6^2 + 2*z6 + 1
     2674
     2675        Note that embeddings are compatible in lattices of such finite fields::
     2676
     2677            sage: m = GF(3^5); c = m.gen()
     2678            sage: (a+b)+c == a+(b+c) # indirect doctest
     2679            True
     2680            sage: from sage.categories.pushout import pushout
     2681            sage: n = pushout(k, l)
     2682            sage: o = pushout(l, m)
     2683            sage: q = pushout(n, o)
     2684            sage: q(o(b)) == q(n(b)) # indirect doctest
     2685            True
     2686
     2687        Coercion is also available for number fields::
     2688
    26632689            sage: P.<x> = QQ[]
    26642690            sage: L.<b> = NumberField(x^8-x^4+1, embedding=CDF.0)
    26652691            sage: M1.<c1> = NumberField(x^2+x+1, embedding=b^4-1)
     
    26692695            sage: c1+c2; parent(c1+c2)    #indirect doctest
    26702696            -b^6 + b^4 - 1
    26712697            Number Field in b with defining polynomial x^8 - x^4 + 1
    2672             sage: from sage.categories.pushout import pushout
    26732698            sage: pushout(M1['x'],M2['x'])
    26742699            Univariate Polynomial Ring in x over Number Field in b with defining polynomial x^8 - x^4 + 1
    26752700
     
    27132738#                return other
    27142739        # ... or we may use the given embeddings
    27152740        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:
     2741        # finite fields use an Integer to encode the pseudo-Conway extension that allows pushouts
     2742        if isinstance(self.conway, Integer) and isinstance(other.conway, Integer) and self.prefix is not None and self.prefix == other.prefix:
    27182743            if self.embeddings != [None] or other.embeddings != [None]:
    27192744                raise NotImplementedError
    2720             return AlgebraicExtensionFunctor([self.polys[0]*other.polys[0]],[None],[None],prefix=self.prefix)
     2745            polys = self.polys+other.polys
     2746            return AlgebraicExtensionFunctor(polys,[None]*len(polys),[None]*len(polys),conway=self.conway.lcm(other.conway),prefix=self.prefix)
    27212747        if self.embeddings!=[None] and other.embeddings!=[None]:
    27222748            from sage.all import QQ
    27232749            KS = self(QQ)
     
    27892815        """
    27902816        if len(self.polys)==1:
    27912817            return [self]
    2792         return [AlgebraicExtensionFunctor([self.polys[i]], [self.names[i]], [self.embeddings[i]]) for i in range(len(self.polys))]
     2818        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))]
    27932819
    27942820class AlgebraicClosureFunctor(ConstructionFunctor):
    27952821    """
     
    31143140    S_tower = construction_tower(S)
    31153141    Rs = [c[1] for c in R_tower]
    31163142    Ss = [c[1] for c in S_tower]
    3117    
     3143
    31183144    if R in Ss:
    31193145        return S
    31203146    elif S in Rs:
    31213147        return R
    31223148   
    3123     if R_tower[-1][1] in Ss:
     3149    if Rs[-1] in Ss:
    31243150        Rs, Ss = Ss, Rs
    31253151        R_tower, S_tower = S_tower, R_tower
    31263152   
  • sage/interfaces/singular.py

    diff --git a/sage/interfaces/singular.py b/sage/interfaces/singular.py
    a b  
    14351435            sage: singular.eval('minpoly = 1+z+z2+z3+z4')
    14361436            'minpoly = 1+z+z2+z3+z4;'
    14371437            sage: singular('r3').sage_global_ring()
    1438             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
     1438            Multivariate Polynomial Ring in a, b, c over Finite Field in z of size 3^4
    14391439
    14401440        Real and complex fields in both Singular and Sage are defined with a precision.
    14411441        The precision in Singular is given in terms of digits, but in Sage it is given
     
    15221522                    singular.eval('short=%s'%is_short)
    15231523                else:
    15241524                    minpoly = ZZ[charstr[1]](minpoly)
    1525                 BR = br.extension(minpoly)
     1525                BR = br.extension(minpoly,name=charstr[1])
    15261526        else:
    15271527            BR = br
    15281528       
     
    15851585            'minpoly = 1+z+z2+z3+z4;'
    15861586            sage: p = singular('z^4*a^3+z^2*a*b*c')
    15871587            sage: p.sage_poly()
    1588             (2*z^3 + 2*z^2 + 2*z + 2)*a^3 + z^2*a*b*c
     1588            (-z^3 - z^2 - z - 1)*a^3 + (z^2)*a*b*c
    15891589            sage: singular('z^4')
    15901590            (-z3-z2-z-1)
    15911591
  • 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          If ``name`` is empty a pseudo-Conway polynomial is used.
     204          Otherwise a sparse polynomial is used for binary fields and a
     205          random polynomial is used for other characteristics.
     206        - Other options might be available depending on the implementation.
    215207
    216     - ``prefix`` (default: 'z') - a string used to generate names
     208    - ``elem_cache`` - cache all elements to avoid
     209      creation time (default: order < 500)
     210
     211    - ``check_irreducible`` - verify that the polynomial
     212      modulus is irreducible
     213
     214    - ``prefix`` (default: ``'z'``) - a string used to generate names
    217215      for subfields and pushouts of this field (mainly for use with
    218216      pseudo-Conway polynomials).
    219217
    220     - ``proof`` -- bool (default: True); if True use provable
     218    - ``proof`` -- bool (default: ``True``); if ``True`` use provable
    221219      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.
     220
     221    - ``args`` - additional parameters passed to finite
     222      field implementations
     223
     224    - ``kwds`` - additional keyword parameters passed to
     225      finite field implementations
     226
     227    ALIAS:
     228
     229    You can also use ``GF`` instead of ``FiniteField`` -- they are identical.
    232230
    233231    EXAMPLES::
    234    
     232
    235233        sage: k.<a> = FiniteField(9); k
    236234        Finite Field in a of size 3^2
    237235        sage: parent(a)
     
    240238        y^2 + 2*y + 2
    241239        sage: L = GF(27); L
    242240        Finite Field in z3 of size 3^3
    243    
     241
    244242    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.)::
     243    for a very long time if we didn't use ``proof=False``.
     244
     245    .. NOTE::
     246
     247        Magma only supports ``proof=False`` for making finite fields,
     248        so falsely appears to be faster than Sage -- see :trac:10975.
     249
     250    ::
    248251
    249252        sage: k = FiniteField(10^1000 + 453, proof=False)
    250253        sage: k = FiniteField((10^1000 + 453)^2, 'a', proof=False)      # long time -- about 5 seconds
    251254
    252255    ::
    253    
     256
    254257        sage: F.<x> = GF(5)[]
    255258        sage: K.<a> = GF(5**5, name='a', modulus=x^5 - x +1 )
    256259        sage: f = K.modulus(); f
    257260        x^5 + 4*x + 1
    258261        sage: type(f)
    259262         <type 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint'>
    260    
     263
    261264    The modulus must be irreducible::
    262    
     265
    263266        sage: K.<a> = GF(5**5, name='a', modulus=x^5 - x )
    264267        Traceback (most recent call last):
    265268        ...
    266269        ValueError: finite field modulus must be irreducible but it is not.
    267    
     270
    268271    You can't accidentally fool the constructor into thinking the modulus
    269272    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    
     273    irreducibility modulo p.  Also, the modulus has to be of the right degree::
     274
    274275        sage: F.<x> = QQ[]
    275276        sage: factor(x^5 + 2)
    276277        x^5 + 2
     
    283284        ...
    284285        ValueError: The degree of the modulus does not correspond to the
    285286        cardinality of the field.
    286    
     287
    287288    If you wish to live dangerously, you can tell the constructor not
    288289    to test irreducibility using check_irreducible=False, but this can
    289290    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    
     291    that the modulus really is irreducible and has the correct degree!::
     292
    294293        sage: F.<x> = GF(5)[]
    295294        sage: K.<a> = GF(5**2, name='a', modulus=x^2 + 2, check_irreducible=False)
    296295
     
    301300        [0, a, 1, 2, 1, 2, 1, 2, 1]
    302301
    303302    The order of a finite field must be a prime power::
    304    
     303
    305304        sage: GF(1)
    306305        Traceback (most recent call last):
    307306        ...
     
    310309        Traceback (most recent call last):
    311310        ...
    312311        ValueError: the order of a finite field must be a prime power.
    313    
     312
    314313    Finite fields with explicit random modulus are not cached::
    315    
     314
    316315        sage: k.<a> = GF(5**10, modulus='random')
    317316        sage: n.<a> = GF(5**10, modulus='random')
    318317        sage: n is k
    319318        False
    320319        sage: GF(5**10, 'a') is GF(5**10, 'a')
    321320        True
    322    
     321
    323322    We check that various ways of creating the same finite field yield
    324     the same object, which is cached.
    325    
    326     ::
    327    
     323    the same object, which is cached::
     324
    328325        sage: K = GF(7, 'a')
    329326        sage: L = GF(7, 'b')
    330327        sage: K is L
     
    337334        sage: M = GF(4,'a', K.modulus().change_variable_name('y'))
    338335        sage: K is M
    339336        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    
     337
     338    You may print finite field elements as integers. This currently only works
     339    if the order of field is `< 2^{16}`, though::
     340
    347341        sage: k.<a> = GF(2^8, repr='int')
    348342        sage: a
    349343        2
    350344
     345    The following demonstrate coercions for finite fields using Conway or
     346    pseudo-Conway polynomials::
     347
     348        sage: k = GF(5^2); a = k.gen()
     349        sage: l = GF(5^5); b = l.gen()
     350        sage: a + b
     351        3*z10^5 + z10^4 + z10^2 + 3*z10 + 1
     352
     353    Note that embeddings are compatible in lattices of such finite fields::
     354
     355        sage: m = GF(5^3); c = m.gen()
     356        sage: (a+b)+c == a+(b+c)
     357        True
     358        sage: (a*b)*c == a*(b*c)
     359        True
     360        sage: from sage.categories.pushout import pushout
     361        sage: n = pushout(k, l)
     362        sage: o = pushout(l, m)
     363        sage: q = pushout(n, o)
     364        sage: q(o(b)) == q(n(b))
     365        True
     366
     367    Another check that embeddings are defined properly::
     368
     369        sage: k = GF(3**10)
     370        sage: l = GF(3**20)
     371        sage: l(k.gen()**10) == l(k.gen())**10
     372        True
    351373    """
    352374    def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
    353375                                  impl=None, prefix='z', proof=None, **kwds):
    354376        """
    355377        EXAMPLES::
    356        
     378
    357379            sage: GF.create_key_and_extra_args(9, 'a')
    358380            ((9, ('a',), 'conwayz', None, '{}', 3, 2, True), {})
    359381            sage: GF.create_key_and_extra_args(9, 'a', foo='value')
     
    403425
    404426                if isinstance(modulus, (list, tuple)):
    405427                    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
    409428                elif sage.rings.polynomial.polynomial_element.is_Polynomial(modulus):
     429                    # some classes use 'random' as the modulus to
     430                    # generate a random modulus, but we don't want
     431                    # to cache it
    410432                    modulus = modulus.change_variable_name('x')
     433                    # We might need the following for compatibility with
     434                    # the extension method of CommutativeRing class
     435                    if name is None:
     436                        name = str(modulus.parent().gen(0))
    411437                elif not isinstance(modulus, str):
    412438                    raise ValueError("Modulus parameter not understood.")
    413439            else:  # Neither a prime, nor a prime power
     
    551577
    552578    return isinstance(x, FiniteField_prime_modn) or \
    553579           (isinstance(x, FiniteField_generic) and x.degree() == 1)
    554    
    555 ##################################################################
    556    
     580
     581
    557582def conway_polynomial(p, n):
    558583    r"""
    559     Return the Conway polynomial of degree n over GF(p), which is
     584    Return the Conway polynomial of degree ``n`` over `F_p`, which is
    560585    loaded from a table.
    561    
     586
    562587    If the requested polynomial is not known, this function raises a
    563     RuntimeError exception.
    564    
     588    ``RuntimeError`` exception.
     589
    565590    INPUT:
    566    
    567    
    568     -  ``p`` - int
    569    
    570     -  ``n`` - int
    571    
    572    
     591
     592    - ``p`` -- int
     593
     594    - ``n`` -- int
     595
    573596    OUTPUT:
    574    
    575    
    576     -  ``Polynomial`` - a polynomial over the prime finite
    577        field GF(p).
    578    
    579    
    580     .. note::
    581597
    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    
     598    - ``Polynomial`` -- a polynomial over the prime finite
     599      field GF(p).
     600
     601    .. NOTE::
     602
     603       The first time this function is called a table is read from disk,
     604       which takes a fraction of a second.
     605       Subsequent calls do not require reloading the table.
     606
    586607    See also the ``ConwayPolynomials()`` object, which is a
    587     table of Conway polynomials. For example, if
    588     ``c=ConwayPolynomials()``, then
     608    table of Conway polynomials.
     609    For example, if ``c=ConwayPolynomials()``, then
    589610    ``c.primes()`` is a list of all primes for which the
    590611    polynomials are known, and for a given prime `p`,
    591612    ``c.degree(p)`` is a list of all degrees for which the
    592613    Conway polynomials are known.
    593    
     614
    594615    EXAMPLES::
    595    
     616
    596617        sage: conway_polynomial(2,5)
    597618        x^5 + x^2 + 1
    598619        sage: conway_polynomial(101,5)
     
    600621        sage: conway_polynomial(97,101)
    601622        Traceback (most recent call last):
    602623        ...
    603         RuntimeError: requested conway polynomial not in database.
     624        RuntimeError: requested Conway polynomial not in database.
    604625    """
    605626    (p,n)=(int(p),int(n))
    606627    R = FiniteField(p)['x']
    607628    try:
    608629        return R(sage.databases.conway.ConwayPolynomials()[p][n])
    609630    except KeyError:
    610         raise RuntimeError("requested conway polynomial not in database.")
     631        raise RuntimeError("requested Conway polynomial not in database.")
    611632
    612633def exists_conway_polynomial(p, n):
    613634    r"""
    614635    Return True if the Conway polynomial over `F_p` of degree
    615636    `n` is in the database and False otherwise.
    616    
     637
    617638    If the Conway polynomial is in the database, to obtain it use the
    618639    command ``conway_polynomial(p,n)``.
    619    
     640
    620641    EXAMPLES::
    621    
     642
    622643        sage: exists_conway_polynomial(2,3)
    623644        True
    624645        sage: exists_conway_polynomial(2,-1)
     
    634655
    635656class PseudoConwayPolyTree(SageObject):
    636657    """
    637     An object holding references to pseudo-Conway polynomials for divisors of the given degree, so that they aren't garbage collected.
     658    An object holding references to pseudo-Conway polynomials for divisors
     659    of the given degree, so that they aren't garbage collected.
    638660    """
    639661    def __init__(self, p, n, nodes_dict, f):
    640662        """
    641         INPUT::
     663        INPUT:
    642664
    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.
     665        - ``p`` -- The prime for which this defines an extension of `F_p`.
     666
     667        - ``n`` -- The degree of the extension.
     668
     669        - ``nodes_dict`` -- dict or bool:
     670
     671          - Either a dictionary of ``PseudoConwayPolyTrees``, indexed by prime
     672            divisors of ``n``.
     673            The entry for `q` corresponds to the pseudo-Conway extension of
     674            degree `n/q`.
     675          - Or a boolean:
     676
     677            - If ``True``, then this polynomial is actually in the Conway
     678              polynomials database, and no references to other PCPTs are
     679              stored.
     680            - If ``False``, then `n == 1` and no references are stored
     681              (since there is no compatiblity condition).
     682
     683        - ``f`` -- The polynomial defining this extension.
    648684
    649685        EXAMPLES::
    650686
     
    657693        self.n = n
    658694        self.nodes_dict = nodes_dict
    659695        self.f = f
    660        
     696
    661697    def get_pseudo_conway_poly(self, m):
    662698        """
    663         Returns the pseudo-Conway polynomial associated to a divisor of the degree of this tree.
     699        Returns the pseudo-Conway polynomial associated to a divisor of the
     700        degree of this tree.
    664701
    665702        EXAMPLES::
    666        
     703
    667704            sage: from sage.rings.finite_rings.constructor import find_pseudo_conway_polynomial_tree
    668705            sage: PCPT = find_pseudo_conway_polynomial_tree(2, 6, False)
    669706            sage: PCPT.get_pseudo_conway_poly(3)
     
    681718            return pseudo_conway_poly[self.p][m]().f
    682719        except (KeyError, AttributeError):
    683720            return conway_polynomial(self.p, m)
    684            
     721
    685722    def check_consistency(self):
    686723        """
    687         Checks that the pseudo-Conway polynomials dividing the degree of this tree satisfy the required compatibility conditions.
     724        Checks that the pseudo-Conway polynomials dividing the degree of this
     725        tree satisfy the required compatibility conditions.
    688726
    689727        EXAMPLES::
    690728
     
    702740
    703741def find_pseudo_conway_polynomial_tree(p, n, use_database=True):
    704742    """
    705     Returns an object holding references to a set of consistent pseudo-Conway polynomials for degrees dividing n.
     743    Returns an object holding references to a set of consistent pseudo-Conway
     744    polynomials for degrees dividing ``n``.
    706745
    707     A Conway polynomial `f \in \Bold{F}_p` of degree `n` satisfies the following three conditions:
    708    
     746    A Conway polynomial `f \in \Bold{F}_p` of degree `n` satisfies the
     747    following three conditions:
     748
    709749    - `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.
     750    - In the quotient field `\Bold{F}_p[x]/(f)`, the indeterminant `x` is a
     751      multiplicative generator.
     752    - In this same quotient field, the minimal polynomial of
     753      `x^{\frac{p^n-1}{p^m-1}}` is the Conway polynomial of degree `m`
     754      for every divisor `m` of `n`.
     755    - `f` is lexicographically least among all such polynomials,
     756      under a certain ordering.
    713757
    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.
     758    The final condition is needed only in order to make the Conway polynomial
     759    unique.
     760    We define a pseudo-Conway polynomial to be one satisfying the first three
     761    conditions.
    715762
    716763    INPUT:
    717764
    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)
     765    - ``p`` -- a prime.
     766
     767    - ``n`` -- an integer greater than 1.
     768
     769    - ``use_database`` -- whether to use the Conway polynomials database if
     770      the Conway polynomial for `p, n` exists within it (versus computing a
     771      pseudo-Conway polynomial)
    721772
    722773    EXAMPLES::
    723774
    724775        sage: from sage.rings.finite_rings.constructor import find_pseudo_conway_polynomial_tree
    725776        sage: PCPT = find_pseudo_conway_polynomial_tree(2, 12, False)
    726777        sage: PCPT.f
    727         x^12 + x^10 + x^9 + x^8 + x^4 + x^2 + 1
     778        x^12 + x^11 + x^10 + x^4 + 1
     779        sage: PCPT = find_pseudo_conway_polynomial_tree(5, 6, False)
     780        sage: PCPT.f
     781        x^6 + x^4 + 4*x^3 + x^2 + 4*x + 2
     782        sage: PCPT = find_pseudo_conway_polynomial_tree(5, 11, False)
     783        sage: PCPT.f
     784        x^11 + 3*x + 3
    728785    """
    729786    if not pseudo_conway_poly.has_key(p):
    730787        pseudo_conway_poly[p] = {}
     
    736793            return pcp
    737794    if use_database and exists_conway_polynomial(p, n):
    738795        ans = PseudoConwayPolyTree(p, n, True, GF(p)['x'](conway_polynomial(p, n)))
    739         pdict[n] = weakref.ref(ans)
    740         return ans
    741     if n == 1 or n.is_prime():
     796    elif n == 1:
    742797        ans = PseudoConwayPolyTree(p, n, False, compute_pseudo_conway_polynomial(p, n, None))
    743     nodes = {}
    744     for q in n.prime_factors():
    745         nodes[q] = find_pseudo_conway_polynomial_tree(p, n//q, use_database)
    746     ans = PseudoConwayPolyTree(p, n, nodes, compute_pseudo_conway_polynomial(p, n, nodes))
     798    else:
     799        nodes = {}
     800        for q in n.prime_factors():
     801            nodes[q] = find_pseudo_conway_polynomial_tree(p, n//q, use_database)
     802        ans = PseudoConwayPolyTree(p, n, nodes, compute_pseudo_conway_polynomial(p, n, nodes))
    747803    pdict[n] = weakref.ref(ans)
    748804    return ans
    749805
     
    753809
    754810    INPUT:
    755811
    756     - `p` -- a prime.
     812    - ``p`` -- a prime.
     813
    757814    - ``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    
     815
     816    - ``x`` -- an element of a field `K` of characeristic p so that the
     817      multiplicative order of `x` is ``p^field_degree - 1``.
     818
     819    - ``y`` -- an element of `K` with the same minimal polynomial.
     820
    761821    OUTPUT:
    762    
     822
    763823    An element `i` of ``Integers(field_degree)`` so that `x = y^{p^i}`
    764824
    765825    EXAMPLES::
     
    771831        sage: _find_pow_of_frobenius(3, x, y, 14)
    772832        11
    773833    """
    774     assert x.minimal_polynomial() == y.minimal_polynomial()
    775     assert x.multiplicative_order() == p**field_degree - 1
    776     assert y.multiplicative_order() == p**field_degree - 1
     834    #assert x.minimal_polynomial() == y.minimal_polynomial()
     835    #assert x.multiplicative_order() == p**field_degree - 1
     836    #assert y.multiplicative_order() == p**field_degree - 1
    777837    from integer_mod import mod
    778     for i in range(field_degree):
     838    for i in xrange(field_degree):
    779839        if x == y: break
    780840        y = y**p
    781841    else:
     
    784844
    785845def _crt_non_coprime(running, a):
    786846    """
    787     Extends the ``crt`` method of IntegerMod to the case of non-relatively prime modulus.
     847    Extends the ``crt`` method of IntegerMod to the case of non-relatively
     848    prime modulus.
    788849
    789850    EXAMPLES::
    790851
     
    816877
    817878def _frobenius_shift(K, generators, check_only=False):
    818879    """
    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.
     880    Given a field `K` of degree `n` over `F_p` and a dictionary holding,
     881    for prime divisor `q` of `n`, an element with minimal polynomial a
     882    pseudo-Conway polynomial of degree `n/q`, modifies these generators into a
     883    compatible system.
    820884
    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
     885    Such a system of generators is said to be compatible if for each pair of
     886    prime divisors `q_1` and `q_2` and each common divisor `m` of `n/q_1` and
     887    `n/q_2`, the equality
    822888
    823889    ``generators[q1]^((p^(n/q1)-1)/(p^m-1)) == generators[q2]^((p^(n/q2)-1)/(p^m-1))``
    824890
     
    826892
    827893    INPUT:
    828894
    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.
     895    - ``K`` -- a finite field of degree n
     896
     897    - ``generators`` -- a dictionary, indexed by prime divisors `q` of `n`,
     898      whose entries are elements of `K` satisfying the `n/q` pseudo-Conway
     899      polynomial.
     900
     901    - ``check_only`` -- if ``True``, just asserts that the generators given
     902      form a compatible system.
    832903
    833904    EXAMPLES::
    834905
     
    885956    pairs = crt.keys()
    886957    for i, j in pairs:
    887958        L = crt[(i,j)]
    888         #print qlist[i], qlist[j]
    889         #print " ".join(["(%s, %s)"%(mm, mm.modulus()) for mm in L])
    890959        running = mod(0,1)
    891960        for a in L:
    892961            running = _crt_non_coprime(running, a)
    893         #print "(%s, %s)"%(running, running.modulus())
    894962        crt[(i,j)] = [(mod(running, q**(running.modulus().valuation(q))), running.modulus().valuation(q)) for q in qlist]
    895963        crt[(j,i)] = [(-a, level) for a, level in crt[(i,j)]]
    896964    # Let x_j be the power of Frobenius we apply to generators[qlist[j]], for 0 < j < len(qlist)
     
    9711039        for j in range(1,len(qlist)):
    9721040            frob_powers[j] = frob_powers[j].crt(x[j][0])
    9731041    for j in range(1, len(qlist)):
    974         #print "frob_power[%s] = mod(%s, %s)"%(qlist[j], frob_powers[j], frob_powers[j].modulus())
    9751042        generators[qlist[j]] = generators[qlist[j]]**(p**(-frob_powers[j]).lift())
    9761043    _frobenius_shift(K, generators, check_only=True)
    9771044
     
    9791046    """
    9801047    Computes a pseudo-Conway polynomial over the prime `p` of degree `n`.
    9811048
    982     A Conway polynomial `f \in \Bold{F}_p` of degree `n` satisfies the following three conditions:
    983    
     1049    A Conway polynomial `f \in \Bold{F}_p` of degree `n` satisfies the
     1050    following three conditions:
     1051
    9841052    - `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.
     1053    - In the quotient field `\Bold{F}_p[x]/(f)`, the indeterminant `x` is a
     1054      multiplicative generator.
     1055    - In this same quotient field, the minimal polynomial of
     1056      `x^{\frac{p^n-1}{p^m-1}}` is the Conway polynomial of degree `m`
     1057      for every divisor `m` of `n`.
     1058    - `f` is lexicographically least among all such polynomials,
     1059      under a certain ordering.
    9881060
    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.
     1061    The final condition is needed only in order to make the Conway polynomial
     1062    unique.  We define a pseudo-Conway polynomial to be one satisfying the
     1063    first three conditions.
    9901064
    9911065    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`.
     1066
     1067    - ``p`` -- a prime
     1068
     1069    - ``n`` -- a positive integer
     1070
     1071    - ``nodes`` -- None (in the case that `n == 1`) or a dictionary
     1072      of PseudoConwayPolyTree objects, indexed by prime divisors `q` of `n`
     1073      with entries corresponding to pseudo-Conway polynomials of degree `n/q`.
    9961074
    9971075    OUTPUT:
    9981076
    9991077    A pseudo-Conway polynomial over the prime `p` of degree `n`.
    10001078
    10011079    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.
     1080
     1081    Uses an algorithm described in [HL99]_, modified to find pseudo-Conway
     1082    polynomials rather than Conway polynomials.
     1083    Remove? The major modification was the addition of the function ``_frobenius_shift``.
     1084    The major difference is that we stop as soon as we find a primitive polynomial.
    10041085
    10051086    REFERENCE:
    10061087
    1007     .. [HL99] Heath L. and Loehr N. (1999). 
     1088    .. [HL99] Heath L. and Loehr N. (1999).
    10081089       New algorithms for generating Conway polynomials over finite fields.
    1009        Proceedings of the tenth annual ACM-SIAM symposium on Discrete algorithms, pp. 429-437.
     1090       Proceedings of the tenth annual ACM-SIAM symposium on Discrete
     1091       algorithms, pp. 429-437.
    10101092
    10111093    EXAMPLES::
    10121094
    10131095        sage: from sage.rings.finite_rings.constructor import compute_pseudo_conway_polynomial, find_pseudo_conway_polynomial_tree
    1014         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
     1096        sage: PCPT = find_pseudo_conway_polynomial_tree(next_prime(10000), 5, False) # long
     1097        sage: PCPT.f
     1098        x^5 + 3*x + 10002
    10161099        sage: PCPT30 = find_pseudo_conway_polynomial_tree(2, 30, False)
    10171100        sage: PCPT20 = find_pseudo_conway_polynomial_tree(2, 20, False)
    10181101        sage: PCPT12 = find_pseudo_conway_polynomial_tree(2, 12, False)
    10191102        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
     1103        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
    10211104    """
    10221105    k = GF(p)
    10231106    from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
    10241107    R = PolynomialRing(k, names='x')
    10251108    if n == 1:
    10261109        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
     1110    # Following not used
     1111    elif n.is_prime():
     1112        # n is prime.
     1113        # We require that the chosen generator (x) is a multiplicative
     1114        # generator for the units and compatible with the base field generator.
    10341115        x = R.gen()
     1116        g = nodes[n].f.any_root()
     1117        q = p**n - 1
     1118        F = [q//m for m in q.prime_factors()] # could be VERY expensive
    10351119        from sage.rings.arith import power_mod
     1120        # Now looking for a compatible primitive polynomial
     1121        # Don't use is_primitive which would keep on factoring `q`
    10361122        for f in R.polynomials(of_degree=n):
    10371123            # By using this iterator our chosen polynomial will be fairly sparse.
     1124            # However we have no guarantee to get a Conway polynomial as the ordering used will surely be different
    10381125            if f.is_irreducible():
    10391126                if not f.is_monic():
    10401127                    f = f.monic()
     1128                # Primitivity
    10411129                for m in F:
    10421130                    if power_mod(x, m, f) == 1:
    10431131                        break
     1132                # Compatibility with the base field generator
    10441133                else:
    1045                     return f
     1134                    if power_mod(x,(p**n-1)//(p-1),f) == g:
     1135                        return f
    10461136    # Our strategy is as follows:
    10471137    # Work in an arbitrary field K of order p**n.
    1048     # We're looking for a multiplicative generator of K whose 
     1138    # We're looking for a multiplicative generator of K whose
    10491139    K = GF(p**n, modulus="first_lexicographic", names='a')
    10501140    r = p**n - 1
    10511141    xi = {}
    10521142    for q in nodes.iterkeys():
    1053         #print nodes[q].f.degree(), n//q
    10541143        xi[q] = nodes[q].f.any_root(K, -n//q, True)
     1144    # The following is needed to ensure that in the concrete instantiation
     1145    # of the "new" extension all previous choices are compatible
    10551146    _frobenius_shift(K, xi)
    1056            
     1147
     1148    # Construct a compatible element having order the lcm of orders
    10571149    q, x = xi.popitem()
    10581150    v = p**(n//q) - 1
    10591151    for q, xitem in xi.iteritems():
     
    10611153        g, alpha, beta = v.xgcd(fi)
    10621154        x = x**beta * xitem**alpha
    10631155        v = v.lcm(fi)
     1156
     1157    # Get the missing part of the order to be primitive
    10641158    g = r // v
    1065     #print g, n, g.divides(p**n-1)
    1066     z = x.nth_root(g, cunningham=(p in [2,3,5,7,11]))
    1067     groot1 = K.multiplicative_generator()**v
     1159    # Iterate through g-th roots of x until a primitive one is found
     1160    z = x.nth_root(g)
     1161    root = K.multiplicative_generator()**v
    10681162    while z.multiplicative_order() != r:
    1069         z *= groot1
    1070     #print z
     1163        z *= root
     1164    # The following should work but tries to create a huge list
     1165    # whose length overflows Python's ints for large parameters
     1166    #Z = x.nth_root(g, all=True)
     1167    #for z in Z:
     1168    #    if z.multiplicative_order() == r:
     1169    #         break
     1170
    10711171    return z.minimal_polynomial()
    10721172
    10731173zech_log_bound = 2**16
  • 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  
    549549            [2^4 * 3]
    550550        """
    551551        if self.__factored_unit_order is None:
    552             if self.characteristic() in []: # want to be [2,3,5,7,11] once #7240 is finished.
    553                 from sage.rings.factorint import factor_cunningham
    554                 self.__factored_unit_order = [factor_cunningham(self.order()-1)]
    555             else:
    556                 self.__factored_unit_order = [(self.order()-1).factor()]
     552            self.__factored_unit_order = [(self.order()-1).factor()]
    557553        return self.__factored_unit_order
    558554
    559555    def cardinality(self):
     
    746742
    747743    def construction(self):
    748744        """
    749         Returns the construction of this finite field, as a ConstructionFunctor and the base field.
     745        Return the construction of this finite field, as a ``ConstructionFunctor``
     746        and the base field.
    750747
    751748        EXAMPLES::
    752        
     749
    753750            sage: v = GF(3^3).construction(); v
    754751            (AlgebraicExtensionFunctor, Finite Field of size 3)
    755752            sage: v[0].polys[0]
    756             3
     753            z3^3 + 2*z3 + 1
    757754            sage: v = GF(2^1000,'a').construction(); v[0].polys[0]
    758755            a^1000 + a^5 + a^4 + a^3 + 1
    759756        """
     
    761758        if self.degree() == 1:
    762759            # this is not of type FiniteField_prime_modn
    763760            from sage.rings.integer import Integer
    764             return AlgebraicExtensionFunctor([Integer(1)], [None],[None]), self.base_ring()
     761            return AlgebraicExtensionFunctor([self.polynomial()],[None],[None],conway=1), self.base_ring()
    765762        elif hasattr(self, '_PCPT') and self._PCPT is not None:
    766             return AlgebraicExtensionFunctor([self.degree()], [self.variable_name()],[None],prefix=self._prefix), self.base_ring()
     763            return AlgebraicExtensionFunctor([self.polynomial()],[self.variable_name()],[None],conway=self.degree(),prefix=self._prefix), self.base_ring()
    767764        else:
    768             return AlgebraicExtensionFunctor([self.polynomial()], [self.variable_name()],[None]), self.base_ring()
     765            return AlgebraicExtensionFunctor([self.polynomial()],[self.variable_name()],[None]), self.base_ring()
    769766
    770     def extension(self, modulus, name=None, names=None, embedding=None, prefix='z'):
     767    def extension(self, modulus, name=None, names=None, embedding=None, conway=None, prefix='z'):
    771768        """
    772         Returns an extension of this finite field.
     769        Return an extension of this finite field.
    773770
    774         INPUT::
     771        INPUT:
    775772
    776         - modulus -- either a polynomial with coefficients in this field or an integer. 
    777                      If an integer, returns the pseudo-Conway extension of this field of that degree.
    778         - name -- the name of the generator in the new extension
    779         - embedding -- currently not used; for compatibility with other AlgebraicExtensionFunctor calls.
    780         - prefix -- Passed on to the finite field constructor.  See the documentation of
    781                     ``GF`` in ``sage.rings.finite_rings.constructor``
     773        - ``modulus`` -- either a polynomial with coefficients in this field or
     774          an integer.
     775          If an Integer, returns the pseudo-Conway extension of this field of
     776          that degree.
    782777
    783         OUTPUT::
    784        
    785         An extension of the given modulus, or pseudo-Conway of the given degree if the modulus is just an integer.
    786        
     778        - ``name`` -- the name of the generator in the new extension
     779
     780        - ``embedding`` -- currently not used; for compatibility with other
     781          ``AlgebraicExtensionFunctor`` calls.
     782
     783        - ``conway`` -- currently not used; None or an ``Integer`` used to indicate
     784          that the extension is pseudo-Conway of the given degree.
     785
     786        - ``prefix`` -- Passed on to the finite field constructor.
     787          See the documentation of ``GF`` in ``sage.rings.finite_rings.constructor``
     788
     789        OUTPUT:
     790
     791        An extension of the given modulus, or pseudo-Conway of the given degree
     792        if ``conway`` is an integer.
     793
    787794        EXAMPLES::
    788795
     796            sage: k = GF(2)
     797            sage: R.<x> = k[]
     798            sage: k.extension(x^1000 + x^5 + x^4 + x^3 + 1, 'a')
     799            Finite Field in a of size 2^1000
    789800            sage: k = GF(3^4)
     801            sage: R.<x> = k[]
    790802            sage: k.extension(3)
    791803            Finite Field in z12 of size 3^12
    792             sage: R.<x> = GF(2)[]
    793             sage: GF(2).extension(x^1000 + x^5 + x^4 + x^3 + 1,'a')
    794             Finite Field in a of size 2^1000
    795             sage: R.<x> = GF(3)[]
    796804
    797         Extensions of non-prime finite fields by polynomials are not yet supported: we fall back to generic code.
     805        Extensions of non-prime finite fields by polynomials are not yet
     806        supported: we fall back to generic code::
    798807
    799808            sage: k.extension(x^5 + x^2 + x - 1)
    800809            Univariate Quotient Polynomial Ring in x over Finite Field in z4 of size 3^4 with modulus x^5 + x^2 + x + 2
    801810        """
    802811        from constructor import GF
     812        from sage.rings.polynomial.all import is_Polynomial
    803813        from sage.rings.integer import Integer
    804         from sage.rings.polynomial.all import is_Polynomial
    805814        if name is None and names is not None:
    806815            name = names
    807816        if self.degree() == 1:
    808817            if isinstance(modulus, Integer):
    809818                return GF(self.characteristic()**modulus, modulus='conway', name=name, prefix=prefix)
    810             if isinstance(modulus, (list, tuple)):
     819            elif isinstance(modulus, (list, tuple)):
    811820                return GF(self.characteristic()**(len(modulus) - 1), name=name, modulus=modulus, prefix=prefix)
    812821            elif is_Polynomial(modulus):
    813822                if modulus.change_ring(self).is_irreducible():
     
    821830
    822831    def subfields(self, degree=0, name=None):
    823832        """
    824         Return all proper subfields of self of the given degree,
    825         or of all possible degrees if degree is 0. 
     833        Return all proper subfields of ``self`` of the given ``degree``,
     834        or of all possible degrees if ``degree`` is `0`.
    826835
    827         The subfields are returned as
    828         absolute fields together with an embedding into self.
     836        The subfields are returned as absolute fields together with
     837        an embedding into ``self``.
    829838
    830         INPUT::
     839        INPUT:
    831840
    832         - degree -- (default 0) An integer.
    833         - name -- A string, a dictionary or None.
    834                   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.
    835                   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.
    836                   As a shortcut, you can provide a string and the degree of each subfield will be appended for the variable name of that subfield.
    837                   If None, uses the prefix of this field.
    838    
    839         OUTPUT::
     841        - ``degree`` -- (default: `0`) an integer
    840842
    841         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.
     843        - ``name`` -- a string, a dictionary or ``None``:
     844
     845          - If ``degree`` is nonzero, ``name`` must be a string
     846            (or ``None``, if this is a pseudo-Conway extension),
     847            and will be the variable name of the returned field.
     848          - If ``degree`` is zero, the dictionary should have keys the divisors
     849            of the degree of this field, with the desired variable name for the
     850            field of that degree as an entry.
     851          - As a shortcut, you can provide a string and the degree of each
     852            subfield will be appended for the variable name of that subfield.
     853          - If ``None``, uses the prefix of this field.
     854
     855        OUTPUT:
     856
     857        A list of pairs ``(K, e)``, where ``K`` ranges over the subfields of
     858        this field and ``e`` gives an embedding of ``K`` into this field.
    842859
    843860        EXAMPLES::
    844861
    845862            sage: k.<a> = GF(2^21)
    846863            sage: k.subfields()
    847             [(Finite Field of size 2, 
     864            [(Finite Field of size 2,
    848865              Conversion map:
    849866                  From: Finite Field of size 2
    850867                  To:   Finite Field in a of size 2^21),
     
    921938           This is not yet implemented for finite fields.
    922939
    923940        EXAMPLES::
    924        
     941
    925942            sage: GF(5).algebraic_closure()
    926943            Traceback (most recent call last):
    927944            ...
     
    945962    r"""
    946963    Used to unpickle finite prime fields. Now superseded (hence no doctest),
    947964    but kept around for backward compatibility.
    948    
     965
    949966    EXAMPLE::
    950967
    951968        sage: # not tested
     
    972989        False
    973990    """
    974991    return IS_INSTANCE(x, FiniteField)
    975 
  • 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  
    21522152        IntegerMod_abstract.__init__(self, parent)
    21532153        if empty:
    21542154            return
     2155        if self.__modulus.int32 == 1:
     2156            self.ivalue = 0
     2157            return
    21552158        cdef long x
    21562159        if PY_TYPE_CHECK(value, int):
    21572160            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  
    14111411        Returns a root of this polynomial in the given ring.
    14121412
    14131413        INPUT:
    1414        
    1415         - ``ring`` -- The ring in which a root is sought.  By default this is the coefficient ring.
    1416 
    1417         - ``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.
    1418 
    1419         - ``assume_squarefree`` (bool) -- Used for polynomials over finite fields.  If True, this polynomial is assumed to be squarefree.
    1420 
    1421         - ``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.
     1414
     1415        - ``ring`` -- The ring in which a root is sought.
     1416          By default this is the coefficient ring.
     1417
     1418        - ``degree`` (None or nonzero integer) -- Used for polynomials over
     1419          finite fields. Returns a root of degree ``abs(degree)`` over the
     1420          ground field. If negative, also assumes that all factors of this
     1421          polynomial are of degree ``abs(degree)``. If ``None``, returns a root
     1422          of minimal degree contained within the given ring.
     1423
     1424        - ``assume_squarefree`` (bool) -- Used for polynomials over
     1425          finite fields. If ``True``, this polynomial is assumed to be
     1426          squarefree.
     1427
     1428        - ``extend`` -- Used for polynomials over finite fields.
     1429          If ``ring`` is ``None`` and ``extend`` is ``True``, finds a root in
     1430          the smallest extension of the base ring over which this polynomial
     1431          has a root. If ``ring`` is ``None`` and ``extend`` is ``False``, only
     1432          looks for a root in the base ring. If ``ring`` is specified, then
     1433          ``extend=True`` allows a root to lie in an extension of the given
     1434          ring.
    14221435
    14231436        EXAMPLES::
    14241437
  • 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):