Ticket #8334: 7585_12_1_fixes.patch

File 7585_12_1_fixes.patch, 52.7 KB (added by David Roe, 13 years ago)

Fixes various bugs and doctest failures introduced in earlier patches.

  • sage/categories/finite_fields.py

    # HG changeset patch
    # User David Roe <roed@math.harvard.edu>
    # Date 1260893171 18000
    # Node ID 349e0c4b8392d69f9530c1fa1924ef82b29ab4d3
    # Parent  a6362dfc5a2f05f3967a73d1a2ea009e29565c90
    8334: The part of 7585_12_fixes.patch that doesn't depend on the function
    field changes.  This no longer makes Tate's algorithm work for
    function fields, but it does fix some of the doctests broken by
    earlier patches.
    
    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/categories/finite_fields.py
    a b  
    1515from sage.categories.category import Category
    1616from sage.categories.all import Fields
    1717from sage.rings.field import is_Field
     18from sage.misc.lazy_attribute import lazy_attribute
    1819
    1920class FiniteFields(Category):
    2021    """
     
    7778        raise TypeError, "unable to canonically associate a finite field to %s"%x
    7879        # TODO: local dvr ring?
    7980
     81    @lazy_attribute
     82    def element_class(self):
     83        """
     84        A common super class for all elements of finite fields
     85
     86        EXAMPLES::
     87
     88            sage: C = FiniteFields().element_class; C
     89            <type 'sage.rings.finite_rings.element_base.FiniteFieldElement'>
     90            sage: type(C)
     91            <type 'type'>
     92        """
     93        from sage.rings.finite_rings.element_base import FiniteFieldElement
     94        return FiniteFieldElement
    8095
    8196    class ParentMethods:
    8297        pass
  • sage/interfaces/singular.py

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/interfaces/singular.py
    a b  
    669669            except TypeError:
    670670                return False
    671671            return True
     672        elif S is int or S is long:
     673            return True
    672674        raise NotImplementedError
    673675       
    674676
  • sage/libs/flint/zmod_poly_linkage.pxi

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/libs/flint/zmod_poly_linkage.pxi
    a b  
    456456        24998*x^2 + 29761*x + 2252
    457457
    458458        sage: f^-1
    459         18649/(x^2 + 16863*x + 9612)
     459        1/(24998*x^2 + 29761*x + 2252)
    460460
    461461        sage: f^-5
    462         24620/(x^10 + 20309*x^9 + 29185*x^8 + 11948*x^7 + 1965*x^6 + 7713*x^5 + 5810*x^4 + 20457*x^3 + 30732*x^2 + 9706*x + 4485)
     462        1/(20269*x^10 + 20535*x^9 + 7313*x^8 + 7311*x^7 + 16853*x^6 + 142*x^5 + 23853*x^4 + 12065*x^3 + 516*x^2 + 8473*x + 17945)
    463463
    464464     Testing the modulus:
    465465
     
    471471        15328*x + 6968
    472472
    473473        sage: pow(f, -2, g)
    474         16346/(x + 251)
     474        1/(15328*x + 6968)
    475475        sage: (f^2 % g)^-1
    476         16346/(x + 251)
     476        1/(15328*x + 6968)
    477477
    478478        sage: pow(f, 5, g)
    479479        7231*x + 17274
  • sage/rings/finite_rings/constructor.py

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/finite_rings/constructor.py
    a b  
    5353EXAMPLES::
    5454
    5555    sage: k = GF(5); type(k)
    56     <class 'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn'>
     56    <class 'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn_with_category'>
    5757
    5858::
    5959
    6060    sage: k = GF(5^2,'c'); type(k)
    61     <class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro'>
     61    <class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro_with_category'>
    6262
    6363::
    6464
     
    6868::
    6969
    7070    sage: k = GF(3^16,'c'); type(k)
    71     <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari'>
     71    <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari_with_category'>
    7272
    7373Finite Fields support iteration, starting with 0.
    7474
     
    9898::
    9999
    100100    sage: k = GF(3); type(k)
    101     <class 'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn'>
     101    <class 'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn_with_category'>
    102102    sage: k.base_ring()
    103103    Finite Field of size 3
    104104
    105105::
    106106
    107107    sage: k = GF(9,'alpha'); type(k)
    108     <class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro'>
     108    <class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro_with_category'>
    109109    sage: k.base_ring()
    110110    Finite Field of size 3
    111111
    112112::
    113113
    114114    sage: k = GF(3^40,'b'); type(k)
    115     <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari'>
     115    <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari_with_category'>
    116116    sage: k.base_ring()
    117117    Finite Field of size 3
    118118
  • sage/rings/finite_rings/element_ext_pari.py

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/finite_rings/element_ext_pari.py
    a b  
    3838import sage.rings.field_element as field_element
    3939import sage.rings.finite_rings.integer_mod as integer_mod
    4040from element_base import is_FiniteFieldElement
     41from sage.modules.free_module_element import FreeModuleElement
    4142
    4243class FiniteField_ext_pariElement(FiniteFieldElement):
    4344    """
  • sage/rings/finite_rings/element_givaro.pyx

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/finite_rings/element_givaro.pyx
    a b  
    1414
    1515EXAMPLES:
    1616    sage: k = GF(5); type(k)
    17     <class 'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn'>
     17    <class 'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn_with_category'>
    1818    sage: k = GF(5^2,'c'); type(k)
    19     <class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro'>
     19    <class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro_with_category'>
    2020    sage: k = GF(2^16,'c'); type(k)
    2121    <type 'sage.rings.finite_rings.element_ntl_gf2e.FiniteField_ntl_gf2e'>
    2222    sage: k = GF(3^16,'c'); type(k)
    23     <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari'>
     23    <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari_with_category'>
    2424
    2525    sage: n = previous_prime_power(2^16 - 1)
    2626    sage: while is_prime(n):
     
    2828    sage: factor(n)
    2929    251^2
    3030    sage: k = GF(n,'c'); type(k)
    31     <class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro'>
     31    <class 'sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro_with_category'>
    3232
    3333AUTHORS:
    3434     -- Martin Albrecht <malb@informatik.uni-bremen.de> (2006-06-05)
     
    15091509            sage: b.charpoly('x')
    15101510            x^2 + 4*x + 2
    15111511            sage: P = S._finite_field_ext_pari_(); type(P)
    1512             <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari'>
     1512            <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari_with_category'>
    15131513            sage: c = b._finite_field_ext_pari_element(P); c
    15141514            b
    15151515            sage: type(c)
  • sage/rings/finite_rings/element_ntl_gf2e.pyx

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/finite_rings/element_ntl_gf2e.pyx
    a b  
    219219        if p != 2:
    220220            raise ValueError("q must be a 2-power")
    221221
    222         ParentWithGens.__init__(self, GF(p), names, normalize=True)
     222        FiniteField.__init__(self, GF(p), names, normalize=True)
    223223
    224224        self._kwargs = {'repr':repr}
    225225        self._is_conway = False
     
    507507        from sage.rings.integer_ring import ZZ
    508508        if R is int or R is long or R is ZZ:
    509509            return True
    510         from sage.rings.ring import is_FiniteField
     510        from sage.rings.finite_rings.finite_field_base import is_FiniteField
    511511        if is_FiniteField(R):
    512512            if R is <object>self:
    513513                return True
     
    658658            sage: kP
    659659            Finite Field in a of size 2^20
    660660            sage: type(kP)
    661             <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari'>
     661            <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari_with_category'>
    662662        """
    663663        f = self.polynomial()
    664664        return FiniteField_ext_pari(self.order(), self.variable_name(), f)
  • sage/rings/finite_rings/finite_field_base.pyx

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/finite_rings/finite_field_base.pyx
    a b  
    5050        return self
    5151
    5252cdef class FiniteField(Field):
    53 #    def __init__(self):
    54 #        """
    55 #        EXAMPLES::
    56 #
    57 #            sage: K = GF(7); K
    58 #            Finite Field of size 7
    59 #            sage: loads(K.dumps()) == K
    60 #            True
    61 #            sage: GF(7^10, 'a')
    62 #            Finite Field in a of size 7^10
    63 #            sage: K = GF(7^10, 'a'); K
    64 #            Finite Field in a of size 7^10
    65 #            sage: loads(K.dumps()) == K
    66 #            True
    67 #        """
    68 #        raise NotImplementedError
     53    def __init__(self, base, names, normalize):
     54        """
     55        EXAMPLES::
     56
     57            sage: K = GF(7); K
     58            Finite Field of size 7
     59            sage: loads(K.dumps()) == K
     60            True
     61            sage: GF(7^10, 'a')
     62            Finite Field in a of size 7^10
     63            sage: K = GF(7^10, 'a'); K
     64            Finite Field in a of size 7^10
     65            sage: loads(K.dumps()) == K
     66            True
     67        """
     68        from sage.categories.finite_fields import FiniteFields
     69        Field.__init__(self, base, names, normalize, category=FiniteFields())
    6970
    7071    def __repr__(self):
    7172        """
  • sage/rings/finite_rings/finite_field_ext_pari.py

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/finite_rings/finite_field_ext_pari.py
    a b  
    187187            raise ValueError, "The size of the finite field must not be prime."
    188188            #base_ring = self
    189189           
    190         ParentWithGens.__init__(self, base_ring, name, normalize=True)
     190        FiniteField_generic.__init__(self, base_ring, name, normalize=True)
    191191
    192192        self._kwargs = {}
    193193        self.__char = F[0][0]
     
    552552            sage: FiniteField_ext_pari(4,'a')._coerce_(2/3)
    553553            Traceback (most recent call last):
    554554            ...
    555             TypeError: no canonical coercion of element into self
     555            TypeError: no canonical coercion from Rational Field to Finite Field in a of size 2^2
    556556            sage: FiniteField_ext_pari(8,'a')._coerce_(FiniteField_ext_pari(4,'a').0)
    557557            Traceback (most recent call last):
    558558            ...
    559             TypeError: no canonical coercion of element into self
     559            TypeError: no canonical coercion from Finite Field in a of size 2^2 to Finite Field in a of size 2^3
    560560            sage: FiniteField_ext_pari(16,'a')._coerce_(FiniteField_ext_pari(4,'a').0)
    561561            Traceback (most recent call last):
    562562            ...
    563             TypeError: no canonical coercion of element into self
     563            TypeError: no canonical coercion from Finite Field in a of size 2^2 to Finite Field in a of size 2^4
    564564            sage: k = FiniteField_ext_pari(8,'a')
    565565            sage: k._coerce_(FiniteField(7,'a')(2))
    566566            Traceback (most recent call last):
    567567            ...
    568             TypeError: no canonical coercion of element into self
     568            TypeError: no canonical coercion from Finite Field of size 7 to Finite Field in a of size 2^3
    569569        """
    570570        from sage.rings.integer_ring import ZZ
    571571        from sage.rings.finite_rings.integer_mod_ring import IntegerModRing_generic
     
    577577            if R.characteristic() == self.characteristic():
    578578                if R.degree() == 1:
    579579                    return True
    580                 elif self.degree() % K.degree() == 0:
     580                elif self.degree() % R.degree() == 0:
    581581                    # TODO: This is where we *would* do coercion from one nontrivial finite field to another...
    582582                    return False               
    583583        from sage.rings.residue_field import ResidueField_generic
  • sage/rings/finite_rings/finite_field_givaro.py

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/finite_rings/finite_field_givaro.py
    a b  
    9999            raise ValueError, "q must be < 2^16"
    100100
    101101        import constructor
    102         ParentWithGens.__init__(self, constructor.FiniteField(p), name, normalize=False)
     102        FiniteField.__init__(self, constructor.FiniteField(p), name, normalize=False)
    103103
    104104        self._kwargs['repr'] = repr
    105105        self._kwargs['cache'] = cache
     
    389389            sage: S.prime_subfield()
    390390            Finite Field of size 5
    391391            sage: type(S.prime_subfield())
    392             <class 'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn'>           
     392            <class 'sage.rings.finite_rings.finite_field_prime_modn.FiniteField_prime_modn_with_category'>           
    393393        """
    394394        try:
    395395            return self._prime_subfield
  • sage/rings/finite_rings/finite_field_prime_modn.py

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/finite_rings/finite_field_prime_modn.py
    a b  
    6363        self._IntegerModRing_generic__factored_order = factorization.Factorization([(p,1)], integer.Integer(1))
    6464        self._kwargs = {}
    6565        integer_mod_ring.IntegerModRing_generic.__init__(self, p)
    66         ParentWithGens.__init__(self, self, ('x',), normalize=False)
     66        FiniteField_generic.__init__(self, self, ('x',), normalize=False)
    6767
    6868    def __cmp__(self, other):
    6969        r"""
     
    127127            5
    128128        """
    129129        from sage.rings.integer_ring import ZZ
    130         from sage.rings.integer_mod_ring import IntegerModRing_generic
     130        from sage.rings.finite_rings.integer_mod_ring import IntegerModRing_generic
    131131        if S is int:
    132132            return integer_mod.Int_to_IntegerMod(self)
    133133        elif S is ZZ:
  • sage/rings/polynomial/ideal.py

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/polynomial/ideal.py
    a b  
     1"""
     2Ideals in Univariate Polynomial Rings.
    13
     4AUTHORS:
     5 
     6- David Roe (2009-12-14) -- initial version.
     7"""
    28
     9#*****************************************************************************
     10#
     11#   Sage: System for Algebra and Geometry Experimentation   
     12#
     13#       Copyright (C) 2009 DavidRoe <roed@math.harvard.edu>
     14#                          William Stein <wstein@gmail.com>
     15#
     16#  Distributed under the terms of the GNU General Public License (GPL)
     17#
     18#    This code is distributed in the hope that it will be useful,
     19#    but WITHOUT ANY WARRANTY; without even the implied warranty of
     20#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     21#    General Public License for more details.
     22#
     23#  The full text of the GPL is available at:
     24#
     25#                  http://www.gnu.org/licenses/
     26#*****************************************************************************
     27
     28from sage.structure.factorization import Factorization
    329from sage.rings.ideal import Ideal_pid
    430
    531class Ideal_1poly_field(Ideal_pid):
     
    4066        from sage.rings.residue_field import ResidueField
    4167        return ResidueField(self, names, check=False)
    4268   
     69    def factor(self):
     70        """
     71        Returns a factorization of this ideal into prime ideals.
     72
     73        EXAMPLES::
     74       
     75            sage: R.<t> = GF(5)[]
     76            sage: I = R.ideal(t^4 - 1)
     77            sage: F = I.factor(); F
     78            (Principal ideal (t + 1) of Univariate Polynomial Ring in t over Finite Field of size 5) * (Principal ideal (t + 2) of Univariate Polynomial Ring in t over Finite Field of size 5) * (Principal ideal (t + 3) of Univariate Polynomial Ring in t over Finite Field of size 5) * (Principal ideal (t + 4) of Univariate Polynomial Ring in t over Finite Field of size 5)
     79            sage: F.prod() == I
     80            True
     81        """
     82        R = self.ring()
     83        return Factorization([(R.ideal(p), e) for p, e in self.gen().factor()])
     84
     85    def valuation(self, p):
     86        """
     87        Returns the number of times p divides this ideal.
     88
     89        EXAMPLES::
     90
     91            sage: R.<t> = GF(5)[]
     92            sage: I = R.ideal((t+1)^3*t)
     93            sage: I.valuation(t+1)
     94            3
     95            sage: I.valuation(t)
     96            1
     97            sage: I.valuation(t-1)
     98            0
     99        """
     100        return self.gen().valuation(p)
  • sage/rings/polynomial/polynomial_element.pyx

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/polynomial/polynomial_element.pyx
    a b  
    47004700                    return ZZ(k)
    47014701        if isinstance(p, Polynomial):
    47024702            p = self.parent().coerce(p)
    4703         elif is_Ideal(p) and p.ring() is self.parent():
     4703        elif is_Ideal(p) and p.ring() is self.parent(): # eventually need to handle fractional ideals in the fraction field
    47044704            if self.parent().is_field(): # common case
    47054705                p = p.gen()
    47064706            else:
    47074707                raise NotImplementedError
    47084708        else:
    4709             raise TypeError, "The polynomial, p, must have the same parent as self."
     4709            from sage.rings.fraction_field import is_FractionField
     4710            if is_FractionField(p.parent()) and self.parent().has_coerce_map_from(p.parent().ring()):
     4711                p = self.parent().coerce(p.parent().ring()(p)) # here we require that p be integral.
     4712            else:
     4713                raise TypeError, "The polynomial, p, must have the same parent as self."
    47104714
    47114715        if p.degree() == 0:
    47124716            raise ArithmeticError, "The polynomial, p, must have positive degree."
  • sage/rings/residue_field.pyx

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/residue_field.pyx
    a b  
    3131    sage: ZZ.residue_field(17)
    3232    Residue field of Integers modulo 17
    3333
    34 And for polynomial rings over finite fields:
    35 
    36     sage: R.<t> = GF(5)[]
    37     sage: I = R.ideal(t^2 + 2)
    38     sage: k = ResidueField(I); k
    39     Residue field in tbar of Principal ideal (t^2 + 2) of Univariate Polynomial Ring in t over Finite Field of size 5
     34#And for polynomial rings over finite fields:
     35#
     36    #sage: R.<t> = GF(5)[]
     37    #sage: I = R.ideal(t^2 + 2)
     38    #sage: k = ResidueField(I); k
     39    #Residue field in tbar of Principal ideal (t^2 + 2) of Univariate Polynomial Ring in t over Finite Field of size 5
    4040
    4141AUTHORS:
    4242    -- David Roe (2007-10-3): initial version
     
    5555    Residue field in zbar of Fractional ideal (17)
    5656    sage: TestSuite(ff).run()
    5757
    58     sage: R.<t> = GF(11)[]; P = R.ideal(t^3 + t + 4)
    59     sage: ff.<a> = ResidueField(P)
    60     sage: a == ff(t)
    61     True
    62     sage: parent(a*a)
    63     Residue field in a of Principal ideal (t^3 + t + 4) of Univariate Polynomial Ring in t over Finite Field of size 11
     58    #sage: R.<t> = GF(11)[]; P = R.ideal(t^3 + t + 4)
     59    #sage: ff.<a> = ResidueField(P)
     60    #sage: a == ff(t)
     61    #True
     62    #sage: parent(a*a)
     63    #Residue field in a of Principal ideal (t^3 + t + 4) of Univariate Polynomial Ring in t over Finite Field of size 11
    6464
    6565Reducing a curve modulo a prime::
    6666
     
    7272    sage: E.base_extend(Fpp)
    7373    Elliptic Curve defined by y^2  = x^3 + x + 5 over Residue field of Fractional ideal (13, s - 4)
    7474
    75     sage: R.<t> = GF(11)[]; K = R.fraction_field(); P = R.ideal(t^3 + t + 4); ff.<a> = K.residue_field(P)
    76     sage: E = EllipticCurve([0,0,0,K(1),K(t)])
    77     sage: E.base_extend(ff)
    78     Elliptic Curve defined by y^2 = x^3 + x + a over Residue field in a of Principal ideal (t^3 + t + 4) of Univariate Polynomial Ring in t over Finite Field of size 11
     75    #sage: R.<t> = GF(11)[]; K = R.fraction_field(); P = R.ideal(t^3 + t + 4); ff.<a> = K.residue_field(P)
     76    #sage: E = EllipticCurve([0,0,0,K(1),K(t)])
     77    #sage: E.base_extend(ff)
     78    #Elliptic Curve defined by y^2 = x^3 + x + a over Residue field in a of Principal ideal (t^3 + t + 4) of Univariate Polynomial Ring in t over Finite Field of size 11
    7979
    8080Calculating Groebner bases over various residue fields.  First over a small non-prime field::
    8181
     
    190190        sage: k.order()
    191191        841
    192192
    193     It also works for polynomial rings::
    194 
    195         sage: R.<t> = GF(31)[]
    196         sage: P = R.ideal(t^5 + 2*t + 11)
    197         sage: ResidueField(P)
    198         Residue field in tbar of Principal ideal (t^5 + 2*t + 11) of Univariate Polynomial Ring in t over Finite Field of size 31
    199 
    200         sage: ResidueField(P) is ResidueField(P)
    201         True
    202         sage: k = ResidueField(P); k.order()
    203         28629151
     193#    It also works for polynomial rings::
     194#
     195        #sage: R.<t> = GF(31)[]
     196        #sage: P = R.ideal(t^5 + 2*t + 11)
     197        #sage: ResidueField(P)
     198        #Residue field in tbar of Principal ideal (t^5 + 2*t + 11) of Univariate Polynomial Ring in t over Finite Field of size 31
     199#
     200        #sage: ResidueField(P) is ResidueField(P)
     201        #True
     202        #sage: k = ResidueField(P); k.order()
     203        #28629151
    204204
    205205    An example where the generator of the number field doesn't
    206206    generate the residue class field::
     
    222222        sage: k(a)^3 - 875
    223223        0
    224224
    225     And for polynomial rings::
    226 
    227         sage: R.<t> = GF(next_prime(2^18))[]; P = R.ideal(t - 5)
    228         sage: k = ResidueField(P); k
    229         Residue field of Principal ideal (t + 262142) of Univariate Polynomial Ring in t over Finite Field of size 262147
    230         sage: k(t)
    231         5
     225#    And for polynomial rings::
     226#
     227        #sage: R.<t> = GF(next_prime(2^18))[]; P = R.ideal(t - 5)
     228        #sage: k = ResidueField(P); k
     229        #Residue field of Principal ideal (t + 262142) of Univariate Polynomial Ring in t over Finite Field of size 262147
     230        #sage: k(t)
     231        #5
    232232
    233233    In this example, 2 is an inessential discriminant divisor, so divides
    234234    the index of ZZ[a] in the maximal order for all a::
     
    262262                        p = p.parent().ideal(p)
    263263                elif is_Polynomial(p):
    264264                    p = p.parent().ideal(p)
    265                 elif isinstance(p.parent(), FractionField_1poly_field):
    266                     p = p.parent().ring_of_integers().ideal(p)
     265                #elif isinstance(p.parent(), FractionField_1poly_field):
     266                #    p = p.parent().ring_of_integers().ideal(p)
    267267                # will eventually support other function fields here.
    268268                else:
    269269                    raise ValueError, "p must be an ideal or element of a number field or function field."
     
    379379        sage: type(k)
    380380        <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn_with_category'>
    381381
    382         sage: R.<t> = GF(29)[]; P = R.ideal(t^2 + 2); k.<a> = ResidueField(P); k
    383         Residue field in a of Principal ideal (t^2 + 2) of Univariate Polynomial Ring in t over Finite Field of size 29
    384         sage: type(k)
    385         <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     382        #sage: R.<t> = GF(29)[]; P = R.ideal(t^2 + 2); k.<a> = ResidueField(P); k
     383        #Residue field in a of Principal ideal (t^2 + 2) of Univariate Polynomial Ring in t over Finite Field of size 29
     384        #sage: type(k)
     385        #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    386386    """
    387387    def __init__(self, p):
    388388        """
     
    401401            sage: k = K.residue_field(P) # indirect doctest
    402402            sage: F = ZZ.residue_field(17)  # indirect doctest
    403403
    404             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    405             sage: k.<a> = P.residue_field() # indirect doctest
     404            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     405            #sage: k.<a> = P.residue_field() # indirect doctest
    406406
    407407            sage: k.category()
    408             Category of fields
     408            Category of finite fields
    409409            sage: F.category()
    410             Category of fields
     410            Category of finite fields
    411411
    412412        TESTS::
    413413
     
    433433            sage: k = K.residue_field(K.prime_above(p))
    434434            sage: k.ideal().norm() == p
    435435            True
    436             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    437             sage: k.<a> = R.residue_field(P)
    438             sage: k.ideal()
    439             Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
     436
     437            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     438            #sage: k.<a> = R.residue_field(P)
     439            #sage: k.ideal()
     440            #Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
    440441        """
    441442        return self.p
    442443
     
    458459            sage: ResidueField_generic._element_constructor_(F, GF(13)(8))
    459460            Traceback (most recent call last):
    460461            ...
    461             TypeError: cannot coerce <type 'sage.rings.integer_mod.IntegerMod_int'>
     462            TypeError: cannot coerce <type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
    462463
    463             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    464             sage: k.<a> = P.residue_field()
    465             sage: ResidueField_generic._element_constructor_(k, t)
    466             a
    467             sage: ResidueField_generic._element_constructor_(k, GF(17)(4))
    468             4
     464            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     465            #sage: k.<a> = P.residue_field()
     466            #sage: ResidueField_generic._element_constructor_(k, t)
     467            #a
     468            #sage: ResidueField_generic._element_constructor_(k, GF(17)(4))
     469            #4
    469470        """
    470471        K = OK = self.p.ring()
    471472        if OK.is_field():
     
    499500            sage: GF(13).has_coerce_map_from(F)
    500501            False
    501502           
    502             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    503             sage: k.<a> = P.residue_field()
    504             sage: k.has_coerce_map_from(Qp(17)) # indirect doctest
    505             False
     503            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     504            #sage: k.<a> = P.residue_field()
     505            #sage: k.has_coerce_map_from(Qp(17)) # indirect doctest
     506            #False
    506507        """
    507508        OK = self.p.ring()
    508509        if OK.is_field():
     
    524525            sage: F = ZZ.residue_field(17); F
    525526            Residue field of Integers modulo 17
    526527
    527             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    528             sage: k.<a> = P.residue_field(); k # indirect doctest
    529             Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
     528            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     529            #sage: k.<a> = P.residue_field(); k # indirect doctest
     530            #Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
    530531        """
    531532        if self.p.ring() is ZZ:
    532533            return "Residue field of Integers modulo %s"%self.p.gen()
     
    550551            sage: k.lift(12821*b+918)
    551552            3*a + 19
    552553
    553             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    554             sage: k.<a> = P.residue_field()
    555             sage: k.lift(a^2 + 5)
    556             t^2 + 5
     554            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     555            #sage: k.<a> = P.residue_field()
     556            #sage: k.lift(a^2 + 5)
     557            #t^2 + 5
    557558        """
    558559        if hasattr(self.p, "ring"):
    559560            R = self.p.ring()
     
    592593            sage: F.reduction_map().codomain()
    593594            Residue field of Fractional ideal (-1/4*a)       
    594595
    595             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    596             sage: k.<a> = P.residue_field(); f = k.reduction_map(); f
    597             Partially defined reduction map:
    598               From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 17
    599               To:   Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
    600             sage: f(1/t)
    601             12*a^2 + 12*a
     596            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     597            #sage: k.<a> = P.residue_field(); f = k.reduction_map(); f
     598            #Partially defined reduction map:
     599            #  From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 17
     600            #  To:   Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
     601            #sage: f(1/t)
     602            #12*a^2 + 12*a
    602603        """
    603604        return self.convert_map_from(self.p.ring().fraction_field())
    604605
     
    623624            sage: f(k.0)
    624625            1
    625626
    626             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    627             sage: k.<a> = P.residue_field(); f = k.lift_map(); f
    628             Lifting map:
    629               From: Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
    630               To:   Univariate Polynomial Ring in t over Finite Field of size 17
    631             sage: f(a^2 + 5)
    632             t^2 + 5
     627            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     628            #sage: k.<a> = P.residue_field(); f = k.lift_map(); f
     629            #Lifting map:
     630            #  From: Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
     631            #  To:   Univariate Polynomial Ring in t over Finite Field of size 17
     632            #sage: f(a^2 + 5)
     633            #t^2 + 5
    633634        """
    634635        OK = self.p.ring()
    635636        if OK.is_field():
     
    651652            sage: k == l
    652653            False
    653654
    654             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    655             sage: k.<a> = P.residue_field()
    656             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 11)
    657             sage: l.<b> = P.residue_field()
    658             sage: k == l
    659             False
    660             sage: ll.<c> = P.residue_field()
    661             sage: ll == l
    662             False
     655            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     656            #sage: k.<a> = P.residue_field()
     657            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 11)
     658            #sage: l.<b> = P.residue_field()
     659            #sage: k == l
     660            #False
     661            #sage: ll.<c> = P.residue_field()
     662            #sage: ll == l
     663            #False
    663664        """
    664665        c = cmp(type(self), type(x))
    665666        if c: return c
     
    679680            -6463132282686559142
    680681            sage: hash(K.residue_field(K.prime_above(2^60))) # random
    681682            -6939519969600666586
    682             sage: K = GF(13)['t'].fraction_field()
    683             sage: hash(K.residue_field(GF(13)['t'].gen() + 2)) # random
    684             743237312
     683            #sage: K = GF(13)['t'].fraction_field()
     684            #sage: hash(K.residue_field(GF(13)['t'].gen() + 2)) # random
     685            #743237312
    685686        """
    686687        return 1 + hash(self.ideal())
    687688
     
    703704          From: Number Field in sqrt17 with defining polynomial x^2 - 17
    704705          To:   Residue field in sqrt17bar of Fractional ideal (5)
    705706
    706         sage: R.<t> = GF(next_prime(2^20))[]; P = R.ideal(t^2 + t + 1)
    707         sage: k = P.residue_field()
    708         sage: k.reduction_map()
    709         Partially defined reduction map:
    710           From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 1048583
    711           To:   Residue field in tbar of Principal ideal (t^2 + t + 1) of Univariate Polynomial Ring in t over Finite Field of size 1048583
     707        #sage: R.<t> = GF(next_prime(2^20))[]; P = R.ideal(t^2 + t + 1)
     708        #sage: k = P.residue_field()
     709        #sage: k.reduction_map()
     710        #Partially defined reduction map:
     711        #  From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 1048583
     712        #  To:   Residue field in tbar of Principal ideal (t^2 + t + 1) of Univariate Polynomial Ring in t over Finite Field of size 1048583
    712713    """
    713714    def __init__(self, K, F, to_vs, to_order, PB, PBinv):
    714715        """
     
    728729            sage: F.reduction_map().__repr__()
    729730            'Partially defined reduction map:\n  From: Cyclotomic Field of order 5 and degree 4\n  To:   Residue field in theta_5bar of Fractional ideal (7)'
    730731           
    731             sage: R.<t> = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1)
    732             sage: k = P.residue_field()
    733             sage: k.reduction_map()
    734             Partially defined reduction map:
    735               From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
    736               To:   Residue field in tbar of Principal ideal (t^7 + t^6 + t^5 + t^4 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
    737             sage: type(k)
    738             <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     732            #sage: R.<t> = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1)
     733            #sage: k = P.residue_field()
     734            #sage: k.reduction_map()
     735            #Partially defined reduction map:
     736            #  From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
     737            #  To:   Residue field in tbar of Principal ideal (t^7 + t^6 + t^5 + t^4 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
     738            #sage: type(k)
     739            #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    739740        """
    740741        self._K = K
    741742        self._F = F   # finite field
     
    770771            ...
    771772            ZeroDivisionError: Cannot reduce field element 1/2*a modulo Fractional ideal (a + 1): it has negative valuation
    772773
    773             sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
    774             sage: k.<a> = R.residue_field(h); K = R.fraction_field()
    775             sage: f = k.convert_map_from(K)
    776             sage: type(f)
    777             <type 'sage.rings.residue_field.ReductionMap'>
    778             sage: f(1/t)
    779             a^4 + a
    780             sage: f(1/h)
    781             Traceback (most recent call last):
    782             ...
    783             ZeroDivisionError: division by zero in finite field.
     774            #sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
     775            #sage: k.<a> = R.residue_field(h); K = R.fraction_field()
     776            #sage: f = k.convert_map_from(K)
     777            #sage: type(f)
     778            #<type 'sage.rings.residue_field.ReductionMap'>
     779            #sage: f(1/t)
     780            #a^4 + a
     781            #sage: f(1/h)
     782            #Traceback (most recent call last):
     783            #...
     784            #ZeroDivisionError: division by zero in finite field.
    784785
    785786        An example to show that the issue raised in trac \#1951
    786787        has been fixed::
     
    878879            sage: s(l.gen()).parent()
    879880            Number Field in b with defining polynomial x^5 + 17*x + 1
    880881
    881             sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
    882             sage: k.<a> = R.residue_field(h); K = R.fraction_field()
    883             sage: f = k.convert_map_from(K)
    884             sage: f.section()
    885             Lifting map:
    886               From: Residue field in a of Principal ideal (t^5 + t^2 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
    887               To:   Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
     882            #sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
     883            #sage: k.<a> = R.residue_field(h); K = R.fraction_field()
     884            #sage: f = k.convert_map_from(K)
     885            #sage: f.section()
     886            #Lifting map:
     887            #  From: Residue field in a of Principal ideal (t^5 + t^2 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
     888            #  To:   Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
    888889        """
    889890        if self._section is None:
    890891            self._section = LiftingMap(self, self._to_order, self._PB)
     
    910911          From: Maximal Order in Number Field in a with defining polynomial x^3 - 7
    911912          To:   Residue field in abar of Fractional ideal (2*a^2 + 3*a - 10)
    912913
    913         sage: R.<t> = GF(19)[]; P = R.ideal(t^2 + 5)
    914         sage: k.<a> = R.residue_field(P)
    915         sage: f = k.coerce_map_from(R); f
    916         Ring morphism:
    917           From: Univariate Polynomial Ring in t over Finite Field of size 19
    918           To:   Residue field in a of Principal ideal (t^2 + 5) of Univariate Polynomial Ring in t over Finite Field of size 19
     914        #sage: R.<t> = GF(19)[]; P = R.ideal(t^2 + 5)
     915        #sage: k.<a> = R.residue_field(P)
     916        #sage: f = k.coerce_map_from(R); f
     917        #Ring morphism:
     918        #  From: Univariate Polynomial Ring in t over Finite Field of size 19
     919        #  To:   Residue field in a of Principal ideal (t^2 + 5) of Univariate Polynomial Ring in t over Finite Field of size 19
    919920    """
    920921    def __init__(self, K, F, to_vs, to_order, PB, PBinv):
    921922        """
     
    930931            sage: k.coerce_map_from(OK)(OK(a)^7) # indirect doctest
    931932            13*abar^2 + 7*abar + 21
    932933
    933             sage: R.<t> = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1)
    934             sage: k = P.residue_field(); f = k.coerce_map_from(R)
    935             sage: f(t^10)
    936             tbar^6 + tbar^3 + tbar^2
     934            #sage: R.<t> = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1)
     935            #sage: k = P.residue_field(); f = k.coerce_map_from(R)
     936            #sage: f(t^10)
     937            #tbar^6 + tbar^3 + tbar^2
    937938        """
    938939        self._K = K
    939940        self._F = F   # finite field
     
    958959            sage: k.coerce_map_from(OK)(OK(a)^7) # indirect doctest
    959960            13*abar^2 + 7*abar + 21
    960961
    961             sage: R.<t> = GF(next_prime(2^18))[]; P = R.ideal(t - 71)
    962             sage: k = ResidueField(P); f = k.coerce_map_from(R); f
    963             Ring morphism:
    964               From: Univariate Polynomial Ring in t over Finite Field of size 262147
    965               To:   Residue field of Principal ideal (t + 262076) of Univariate Polynomial Ring in t over Finite Field of size 262147
    966             sage: f(t^2)
    967             5041
     962            #sage: R.<t> = GF(next_prime(2^18))[]; P = R.ideal(t - 71)
     963            #sage: k = ResidueField(P); f = k.coerce_map_from(R); f
     964            #Ring morphism:
     965            #  From: Univariate Polynomial Ring in t over Finite Field of size 262147
     966            #  To:   Residue field of Principal ideal (t + 262076) of Univariate Polynomial Ring in t over Finite Field of size 262147
     967            #sage: f(t^2)
     968            #5041
    968969        """
    969970        # The reduction map is just x |--> F(to_vs(x) * (PB**(-1))) if
    970971        # either x is integral or the denominator of x is coprime to
     
    10091010            sage: s(l.gen()).parent()
    10101011            Maximal Order in Number Field in b with defining polynomial x^5 + 17*x + 1
    10111012
    1012             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    1013             sage: k.<a> = P.residue_field(); f = k.coerce_map_from(R)
    1014             sage: f.section()
    1015             Lifting map:
    1016               From: Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
    1017               To:   Univariate Polynomial Ring in t over Finite Field of size 17
     1013            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     1014            #sage: k.<a> = P.residue_field(); f = k.coerce_map_from(R)
     1015            #sage: f.section()
     1016            #Lifting map:
     1017            #  From: Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
     1018            #  To:   Univariate Polynomial Ring in t over Finite Field of size 17
    10181019        """
    10191020        if self._section is None:
    10201021            self._section = LiftingMap(self, self._to_order, self._PB)
     
    10391040            sage: f.lift(12821*b+918)
    10401041            3*a + 19
    10411042
    1042             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    1043             sage: k.<a> = P.residue_field(); f = k.coerce_map_from(R)
    1044             sage: f.lift(a^2 + 5*a + 1)
    1045             t^2 + 5*t + 1
    1046             sage: f(f.lift(a^2 + 5*a + 1)) == a^2 + 5*a + 1
    1047             True
     1043            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     1044            #sage: k.<a> = P.residue_field(); f = k.coerce_map_from(R)
     1045            #sage: f.lift(a^2 + 5*a + 1)
     1046            #t^2 + 5*t + 1
     1047            #sage: f(f.lift(a^2 + 5*a + 1)) == a^2 + 5*a + 1
     1048            #True
    10481049        """
    10491050        if self.domain() is ZZ:
    10501051            return x.lift()
     
    10701071        sage: L(3*a + 1) == F.0^2
    10711072        True
    10721073
    1073         sage: R.<t> = GF(13)[]; P = R.ideal(8*t^12 + 9*t^11 + 11*t^10 + 2*t^9 + 11*t^8 + 3*t^7 + 12*t^6 + t^4 + 7*t^3 + 5*t^2 + 12*t + 1)
    1074         sage: k.<a> = P.residue_field(); k.lift_map()
    1075         Lifting map:
    1076           From: Residue field in a of Principal ideal (8*t^12 + 9*t^11 + 11*t^10 + 2*t^9 + 11*t^8 + 3*t^7 + 12*t^6 + t^4 + 7*t^3 + 5*t^2 + 12*t + 1) of Univariate Polynomial Ring in t over Finite Field of size 13
    1077           To:   Univariate Polynomial Ring in t over Finite Field of size 13
     1074        #sage: R.<t> = GF(13)[]; P = R.ideal(8*t^12 + 9*t^11 + 11*t^10 + 2*t^9 + 11*t^8 + 3*t^7 + 12*t^6 + t^4 + 7*t^3 + 5*t^2 + 12*t + 1)
     1075        #sage: k.<a> = P.residue_field(); k.lift_map()
     1076        #Lifting map:
     1077        #  From: Residue field in a of Principal ideal (8*t^12 + 9*t^11 + 11*t^10 + 2*t^9 + 11*t^8 + 3*t^7 + 12*t^6 + t^4 + 7*t^3 + 5*t^2 + 12*t + 1) of Univariate Polynomial Ring in t over Finite Field of size 13
     1078        #  To:   Univariate Polynomial Ring in t over Finite Field of size 13
    10781079    """
    10791080    def __init__(self, reduction, to_order, PB):
    10801081        """
     
    11071108            sage: L.codomain()
    11081109            Maximal Order in Cyclotomic Field of order 7 and degree 6
    11091110
    1110             sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
    1111             sage: k.<a> = R.residue_field(h); K = R.fraction_field()
    1112             sage: L = k.lift_map(); L.codomain()
    1113             Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
     1111            #sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
     1112            #sage: k.<a> = R.residue_field(h); K = R.fraction_field()
     1113            #sage: L = k.lift_map(); L.codomain()
     1114            #Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
    11141115        """
    11151116        self._K = reduction._K
    11161117        self._F = reduction._F   # finite field
     
    11351136            sage: F(a)
    11361137            abar
    11371138
    1138             sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
    1139             sage: k.<a> = R.residue_field(h); K = R.fraction_field()
    1140             sage: f = k.lift_map()
    1141             sage: f(a^2)
    1142             t^2
    1143             sage: f(a^6)
    1144             t^3 + t
     1139            #sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
     1140            #sage: k.<a> = R.residue_field(h); K = R.fraction_field()
     1141            #sage: f = k.lift_map()
     1142            #sage: f(a^2)
     1143            #t^2
     1144            #sage: f(a^6)
     1145            #t^3 + t
    11451146        """
    11461147        if self._K is QQ or self._K is ZZ:
    11471148            return self._K(x.lift())  # x.lift() is in ZZ
     
    12001201        sage: b + c
    12011202        3
    12021203
    1203         sage: R.<t> = GF(7)[]; P = R.ideal(2*t + 3)
    1204         sage: k = P.residue_field(); k
    1205         Residue field of Principal ideal (2*t + 3) of Univariate Polynomial Ring in t over Finite Field of size 7
    1206         sage: k(t^2)
    1207         4
    1208         sage: k.order()
    1209         7
     1204        #sage: R.<t> = GF(7)[]; P = R.ideal(2*t + 3)
     1205        #sage: k = P.residue_field(); k
     1206        #Residue field of Principal ideal (2*t + 3) of Univariate Polynomial Ring in t over Finite Field of size 7
     1207        #sage: k(t^2)
     1208        #4
     1209        #sage: k.order()
     1210        #7
    12101211    """
    12111212    def __init__(self, p, name, intp, to_vs, to_order, PB):
    12121213        """
     
    12241225            sage: type(kk)
    12251226            <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn_with_category'>
    12261227
    1227             sage: R.<t> = GF(7)[]; P = R.ideal(2*t + 3)
    1228             sage: k = P.residue_field(); type(k)
    1229             <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn_with_category'>
     1228            #sage: R.<t> = GF(7)[]; P = R.ideal(2*t + 3)
     1229            #sage: k = P.residue_field(); type(k)
     1230            #<class 'sage.rings.residue_field.ResidueFiniteField_prime_modn_with_category'>
    12301231        """
    12311232        ResidueField_generic.__init__(self, p)
    12321233        FiniteField_prime_modn.__init__(self, intp, name)
     
    12751276            sage: k(v) # indirect doctest
    12761277            3
    12771278
    1278             sage: R.<t> = GF(2)[]; P = R.ideal(t+1); k.<a> = P.residue_field()
    1279             sage: V = k.vector_space(); v = V([1])
    1280             sage: k(v)
    1281             1
     1279            #sage: R.<t> = GF(2)[]; P = R.ideal(t+1); k.<a> = P.residue_field()
     1280            #sage: V = k.vector_space(); v = V([1])
     1281            #sage: k(v)
     1282            #1
    12821283        """
    12831284        if isinstance(x, FreeModuleElement) and len(x) == 1:
    12841285            x = x[0]
     
    13081309        sage: k.base_ring()
    13091310        Finite Field of size 923478923
    13101311
    1311         sage: R.<t> = GF(5)[]; P = R.ideal(4*t^12 + 3*t^11 + 4*t^10 + t^9 + t^8 + 3*t^7 + 2*t^6 + 3*t^4 + t^3 + 3*t^2 + 2)
    1312         sage: k.<a> = P.residue_field()
    1313         sage: type(k)
    1314         <class 'sage.rings.residue_field.ResidueFiniteField_ext_pari'>
    1315         sage: k(1/t)
    1316         3*a^11 + a^10 + 3*a^9 + 2*a^8 + 2*a^7 + a^6 + 4*a^5 + a^3 + 2*a^2 + a
     1312        #sage: R.<t> = GF(5)[]; P = R.ideal(4*t^12 + 3*t^11 + 4*t^10 + t^9 + t^8 + 3*t^7 + 2*t^6 + 3*t^4 + t^3 + 3*t^2 + 2)
     1313        #sage: k.<a> = P.residue_field()
     1314        #sage: type(k)
     1315        #<class 'sage.rings.residue_field.ResidueFiniteField_ext_pari'>
     1316        #sage: k(1/t)
     1317        #3*a^11 + a^10 + 3*a^9 + 2*a^8 + 2*a^7 + a^6 + 4*a^5 + a^3 + 2*a^2 + a
    13171318    """
    1318     def __init__(self, p, q, name, g, intp):
     1319    def __init__(self, p, q, name, modulus, to_vs, to_order, PB):
    13191320        """
    13201321        EXAMPLES:
    13211322        We create an ext_pari residue field:
     
    13241325            sage: type(P.residue_field())
    13251326            <class 'sage.rings.residue_field.ResidueFiniteField_ext_pari_with_category'>
    13261327        """
    1327         FiniteField_ext_pari.__init__(self, q, name, g)
    1328         self.p = p
    1329         self.f = NFResidueFieldHomomorphism(self, p, GF(q, name = name, modulus = g).gen(0))
    1330         ResidueField_generic.__init__(self, p, self.f, intp)
     1328        ResidueField_generic.__init__(self, p)
     1329        FiniteField_ext_pari.__init__(self, q, name, modulus)
     1330        K = OK = p.ring()
     1331        if OK.is_field():
     1332            OK = OK.ring_of_integers()
     1333        else:
     1334            K = K.fraction_field()
     1335        if PB is None:
     1336            PBinv = None
     1337        else:
     1338            PBinv = PB**(-1)
     1339        self._populate_coercion_lists_(coerce_list=[self.base_ring(), ResidueFieldHomomorphism_global(OK, self, to_vs, to_order, PB, PBinv)], convert_list = [ReductionMap(K, self, to_vs, to_order, PB, PBinv)])
    13311340
    1332     def __call__(self, x):
     1341    def _element_constructor_(self, x):
    13331342        """
    13341343        Coerce x into self.
    13351344       
     
    13521361            sage: ff(v) # indirect doctest
    13531362            10005*alpha + 3
    13541363
    1355             sage: R.<t> = GF(5)[]; P = R.ideal(4*t^12 + 3*t^11 + 4*t^10 + t^9 + t^8 + 3*t^7 + 2*t^6 + 3*t^4 + t^3 + 3*t^2 + 2)
    1356             sage: k.<a> = P.residue_field()
    1357             sage: V = k.vector_space(); v = V([1,2,3,4,5,6,7,8,9,0,1,2]); k(v) # indirect doctest
    1358             2*a^11 + a^10 + 4*a^8 + 3*a^7 + 2*a^6 + a^5 + 4*a^3 + 3*a^2 + 2*a + 1
     1364            #sage: R.<t> = GF(5)[]; P = R.ideal(4*t^12 + 3*t^11 + 4*t^10 + t^9 + t^8 + 3*t^7 + 2*t^6 + 3*t^4 + t^3 + 3*t^2 + 2)
     1365            #sage: k.<a> = P.residue_field()
     1366            #sage: V = k.vector_space(); v = V([1,2,3,4,5,6,7,8,9,0,1,2]); k(v) # indirect doctest
     1367            #2*a^11 + a^10 + 4*a^8 + 3*a^7 + 2*a^6 + a^5 + 4*a^3 + 3*a^2 + 2*a + 1
    13591368        """
    13601369        try:
    13611370            return FiniteField_ext_pari._element_constructor_(self, x)
     
    13821391        sage: b*c
    13831392        13*abar + 5
    13841393
    1385         sage: R.<t> = GF(7)[]; P = R.ideal(t^2 + 4)
    1386         sage: k.<a> = R.residue_field(P); type(k)
    1387         <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    1388         sage: k(1/t)
    1389         5*a
     1394        #sage: R.<t> = GF(7)[]; P = R.ideal(t^2 + 4)
     1395        #sage: k.<a> = R.residue_field(P); type(k)
     1396        #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     1397        #sage: k(1/t)
     1398        #5*a
    13901399    """
    13911400    def __init__(self, p, q, name, modulus, to_vs, to_order, PB):
    13921401        """
     
    14071416            sage: P = K.ideal(61).factor()[0][0]
    14081417            sage: k = K.residue_field(P)
    14091418
    1410             sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field(); type(k)
    1411             <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    1412             sage: a^5
    1413             a^3 + 2*a^2 + a + 2
     1419            #sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field(); type(k)
     1420            #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     1421            #sage: a^5
     1422            #a^3 + 2*a^2 + a + 2
    14141423        """
    14151424        ResidueField_generic.__init__(self, p)
    14161425        FiniteField_givaro.__init__(self, q, name, modulus)
     
    14451454            sage: k(v) # indirect doctest
    14461455            59*abar + 3
    14471456
    1448             sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field()
    1449             sage: V = k.vector_space(); v = V([0,1,2,3])
    1450             sage: k(v) # indirect doctest
    1451             2*a^2 + a
     1457            #sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field()
     1458            #sage: V = k.vector_space(); v = V([0,1,2,3])
     1459            #sage: k(v) # indirect doctest
     1460            #2*a^2 + a
    14521461        """
    14531462        try:
    14541463            return FiniteField_givaro._element_constructor_(self, x)
     
    14771486        sage: b*c
    14781487        13*abar + 5
    14791488
    1480         sage: R.<t> = GF(2)[]; P = R.ideal(t^19 + t^5 + t^2 + t + 1)
    1481         sage: k.<a> = R.residue_field(P); type(k)
    1482         <class 'sage.rings.residue_field.ResidueFiniteField_ntl_gf2e'>
    1483         sage: k(1/t)
    1484         a^18 + a^4 + a + 1
    1485         sage: k(1/t)*t
    1486         1
     1489        #sage: R.<t> = GF(2)[]; P = R.ideal(t^19 + t^5 + t^2 + t + 1)
     1490        #sage: k.<a> = R.residue_field(P); type(k)
     1491        #<class 'sage.rings.residue_field.ResidueFiniteField_ntl_gf2e'>
     1492        #sage: k(1/t)
     1493        #a^18 + a^4 + a + 1
     1494        #sage: k(1/t)*t
     1495        #1
    14871496    """
    14881497    # we change the order for consistency with FiniteField_ntl_gf2e's __cinit__
    14891498    def __init__(self, q, name, modulus, repr, p, to_vs, to_order, PB):
     
    15051514            sage: P = K.ideal(61).factor()[0][0]
    15061515            sage: k = K.residue_field(P)
    15071516
    1508             sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field(); type(k)
    1509             <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    1510             sage: a^5
    1511             a^3 + 2*a^2 + a + 2
     1517            #sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field(); type(k)
     1518            #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     1519            #sage: a^5
     1520            #a^3 + 2*a^2 + a + 2
    15121521        """
    15131522        ResidueField_generic.__init__(self, p)
    15141523        FiniteField_ntl_gf2e.__init__(self, q, name, modulus, repr)
     
    15431552            sage: k(v) # indirect doctest
    15441553            59*abar + 3
    15451554
    1546             sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field()
    1547             sage: V = k.vector_space(); v = V([0,1,2,3])
    1548             sage: k(v) # indirect doctest
    1549             2*a^2 + a
     1555            #sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field()
     1556            #sage: V = k.vector_space(); v = V([0,1,2,3])
     1557            #sage: k(v) # indirect doctest
     1558            #2*a^2 + a
    15501559        """
    15511560        try:
    15521561            return FiniteField_ntl_gf2e._element_constructor_(self, x)
  • sage/rings/ring.pyx

    diff -r a6362dfc5a2f -r 349e0c4b8392 sage/rings/ring.pyx
    a b  
    346346        if isinstance(self, PrincipalIdealDomain):
    347347            # Use GCD algorithm to obtain a principal ideal
    348348            g = gens[0]
    349             for h in gens[1:]:
    350                 g = self.gcd(g, h)
     349            if len(gens) == 1:
     350                try:
     351                    g = g.gcd(g) # note: we set g = gcd(g, g) to "canonicalize" the generator: make polynomials monic, etc.
     352                except (AttributeError, NotImplementedError):
     353                    pass
     354            else:
     355                for h in gens[1:]:
     356                    g = g.gcd(h)
    351357            gens = [g]
    352358        C = self._ideal_class_(len(gens))
    353359        if len(gens) == 1 and isinstance(gens[0], (list, tuple)):