Ticket #8334: 7585_12_1_fixes.2.patch

File 7585_12_1_fixes.2.patch, 61.5 KB (added by David Roe, 12 years ago)

Fixed merge error; apply against 4.6.alpha1

  • sage/algebras/iwahori_hecke_algebra.py

    # HG changeset patch
    # User David Roe <roed@math.harvard.edu>
    # Date 1260893171 18000
    # Node ID ab51c0b8ddb1ebc555e940941197bca5a7997fc7
    # Parent  cc21ebc4d35885abb1b04faae3a849efab2a9a95
    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 cc21ebc4d358 -r ab51c0b8ddb1 sage/algebras/iwahori_hecke_algebra.py
    a b  
    5555        sage: w0
    5656        s1*s2*s3*s1*s2*s1
    5757        sage: H.an_element()
    58         3*s1*s2 + 3*s1 + 1
     58        3*s1*s2 + 2*s1 + 2
    5959
    6060    Iwahori Hecke algebras have proved to be fundamental. See for example:
    6161
  • sage/categories/coxeter_groups.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/categories/coxeter_groups.py
    a b  
    158158                [0 1 0 0]
    159159                [0 0 1 0]
    160160                [0 0 0 1],
    161                  [0 1 0 0]
     161                 [0 0 0 1]
    162162                [1 0 0 0]
    163                 [0 0 1 0]
    164                 [0 0 0 1]]
     163                [0 1 0 0]
     164                [0 0 1 0]]
    165165                sage: W.order()   
    166166                24
    167167            """
    168             return list(self.simple_reflections()) + [ self.one(), self.an_element() ]
     168            return list(self.simple_reflections()) + [ self.one(), self.an_element_force() ]
    169169
    170170        def from_reduced_word(self, word):
    171171            r"""
  • sage/categories/finite_fields.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/categories/finite_fields.py
    a b  
    1313
    1414from sage.misc.cachefunc import cached_method
    1515from sage.categories.category import Category
    16 from sage.categories.all import Fields
    1716from sage.rings.field import is_Field
     17from sage.misc.lazy_attribute import lazy_attribute
    1818
    1919class FiniteFields(Category):
    2020    """
     
    4545        EXAMPLES::
    4646
    4747            sage: FiniteFields().super_categories()
    48             [Category of fields]
     48            [Category of fields, Category of finite enumerated sets]
    4949        """
    50         return [Fields()]
     50        from sage.categories.all import Fields, FiniteEnumeratedSets
     51        return [Fields(), FiniteEnumeratedSets()]
    5152
    5253    def __contains__(self, x):
    5354        """
     
    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 cc21ebc4d358 -r ab51c0b8ddb1 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/singular/singular.pyx

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/libs/singular/singular.pyx
    a b  
    207207        sage: f.lc()
    208208        a^12 + a^11 + a^9 + a^8 + a^7 + 2*a^6 + a^5
    209209        sage: type(f.lc())
    210         <class 'sage.rings.finite_rings.element_ext_pari.FiniteField_ext_pariElement'>
     210        <class 'sage.rings.finite_rings.element_ext_pari.FiniteField_ext_pariElement_with_category'>
    211211    """
    212212    cdef napoly *z
    213213    cdef int c, e
  • sage/rings/finite_rings/constructor.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/finite_rings/constructor.py
    a b  
    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
     
    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 cc21ebc4d358 -r ab51c0b8ddb1 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
     42from sage.structure.dynamic_class import dynamic_class
     43from sage.categories.finite_fields import FiniteFields
    4144
    4245class FiniteField_ext_pariElement(FiniteFieldElement):
    4346    """
     
    9396            2*a + 1
    9497        """
    9598        field_element.FieldElement.__init__(self, parent)
     99        self.__class__ = dynamic_FiniteField_ext_pariElement
    96100        if isinstance(value, str):
    97101            raise TypeError, "value must not be a string"
    98102        if not check:
     
    687691        # TODO: This function is TERRIBLE!
    688692        return discrete_log(self, b)
    689693
     694dynamic_FiniteField_ext_pariElement = None
     695def _late_import():
     696    global dynamic_FiniteField_ext_pariElement
     697    dynamic_FiniteField_ext_pariElement = dynamic_class("%s_with_category"%FiniteField_ext_pariElement.__name__, (FiniteField_ext_pariElement, FiniteFields().element_class), doccls=FiniteField_ext_pariElement)
     698
    690699from sage.structure.sage_object import register_unpickle_override
    691700register_unpickle_override('sage.rings.finite_field_element', 'FiniteField_ext_pariElement', FiniteField_ext_pariElement)
  • sage/rings/finite_rings/element_givaro.pyx

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/finite_rings/element_givaro.pyx
    a b  
    1616    sage: k = GF(5); type(k)
    1717    <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)
     
    15311531            sage: b.charpoly('x')
    15321532            x^2 + 4*x + 2
    15331533            sage: P = S._finite_field_ext_pari_(); type(P)
    1534             <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari'>
     1534            <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari_with_category'>
    15351535            sage: c = b._finite_field_ext_pari_element(P); c
    15361536            b
    15371537            sage: type(c)
    1538             <class 'sage.rings.finite_rings.element_ext_pari.FiniteField_ext_pariElement'>           
     1538            <class 'sage.rings.finite_rings.element_ext_pari.FiniteField_ext_pariElement_with_category'>           
    15391539            sage: c.charpoly('x')
    15401540            x^2 + 4*x + 2
    15411541
     
    15431543            sage: d = b._finite_field_ext_pari_element(); d
    15441544            b
    15451545            sage: type(d)
    1546             <class 'sage.rings.finite_rings.element_ext_pari.FiniteField_ext_pariElement'>           
     1546            <class 'sage.rings.finite_rings.element_ext_pari.FiniteField_ext_pariElement_with_category'>           
    15471547        """
    15481548        if k is None:
    15491549            k = self.parent()._finite_field_ext_pari_()
  • sage/rings/finite_rings/element_ntl_gf2e.pyx

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 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
     
    518518        from sage.rings.integer_ring import ZZ
    519519        if R is int or R is long or R is ZZ:
    520520            return True
    521         from sage.rings.ring import is_FiniteField
     521        from sage.rings.finite_rings.finite_field_base import is_FiniteField
    522522        if is_FiniteField(R):
    523523            if R is <object>self:
    524524                return True
     
    669669            sage: kP
    670670            Finite Field in a of size 2^20
    671671            sage: type(kP)
    672             <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari'>
     672            <class 'sage.rings.finite_rings.finite_field_ext_pari.FiniteField_ext_pari_with_category'>
    673673        """
    674674        f = self.polynomial()
    675675        return FiniteField_ext_pari(self.order(), self.variable_name(), f)
  • sage/rings/finite_rings/finite_field_base.pyx

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/finite_rings/finite_field_base.pyx
    a b  
    5858        return self
    5959
    6060cdef class FiniteField(Field):
    61 #    def __init__(self):
    62 #        """
    63 #        EXAMPLES::
    64 #
    65 #            sage: K = GF(7); K
    66 #            Finite Field of size 7
    67 #            sage: loads(K.dumps()) == K
    68 #            True
    69 #            sage: GF(7^10, 'a')
    70 #            Finite Field in a of size 7^10
    71 #            sage: K = GF(7^10, 'a'); K
    72 #            Finite Field in a of size 7^10
    73 #            sage: loads(K.dumps()) == K
    74 #            True
    75 #        """
    76 #        raise NotImplementedError
     61    def __init__(self, base, names, normalize):
     62        """
     63        EXAMPLES::
     64
     65            sage: K = GF(7); K
     66            Finite Field of size 7
     67            sage: loads(K.dumps()) == K
     68            True
     69            sage: GF(7^10, 'a')
     70            Finite Field in a of size 7^10
     71            sage: K = GF(7^10, 'a'); K
     72            Finite Field in a of size 7^10
     73            sage: loads(K.dumps()) == K
     74            True
     75        """
     76        from sage.categories.finite_fields import FiniteFields
     77        Field.__init__(self, base, names, normalize, category=FiniteFields())
    7778
    7879    def __repr__(self):
    7980        """
     
    594595        v = self.vector_space().random_element()
    595596        return self(v)
    596597
     598    def some_elements(self):
     599        """
     600        Returns a collection of elements of this finite field for use in unit testing.
     601
     602        EXAMPLES::
     603
     604            sage: k = GF(2^8,'a')
     605            sage: k.some_elements() # random output
     606            [a^4 + a^3 + 1, a^6 + a^4 + a^3, a^5 + a^4 + a, a^2 + a]
     607        """
     608        return [self.random_element() for i in range(4)]
     609
    597610    def polynomial(self):
    598611        """
    599612        Return the defining polynomial of this finite field.
  • sage/rings/finite_rings/finite_field_ext_pari.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/finite_rings/finite_field_ext_pari.py
    a b  
    173173            sage: GF(19^2, 'a')
    174174            Finite Field in a of size 19^2
    175175        """
     176        if element_ext_pari.dynamic_FiniteField_ext_pariElement is None: element_ext_pari._late_import()
    176177        from constructor import FiniteField as GF
    177178        q = integer.Integer(q)
    178179        if q < 2:
     
    193194            raise ValueError, "The size of the finite field must not be prime."
    194195            #base_ring = self
    195196           
    196         ParentWithGens.__init__(self, base_ring, name, normalize=True)
     197        FiniteField_generic.__init__(self, base_ring, name, normalize=True)
    197198
    198199        self._kwargs = {}
    199200        self.__char = F[0][0]
     
    570571            sage: FiniteField_ext_pari(4,'a')._coerce_(2/3)
    571572            Traceback (most recent call last):
    572573            ...
    573             TypeError: no canonical coercion of element into self
     574            TypeError: no canonical coercion from Rational Field to Finite Field in a of size 2^2
    574575            sage: FiniteField_ext_pari(8,'a')._coerce_(FiniteField_ext_pari(4,'a').0)
    575576            Traceback (most recent call last):
    576577            ...
    577             TypeError: no canonical coercion of element into self
     578            TypeError: no canonical coercion from Finite Field in a of size 2^2 to Finite Field in a of size 2^3
    578579            sage: FiniteField_ext_pari(16,'a')._coerce_(FiniteField_ext_pari(4,'a').0)
    579580            Traceback (most recent call last):
    580581            ...
    581             TypeError: no canonical coercion of element into self
     582            TypeError: no canonical coercion from Finite Field in a of size 2^2 to Finite Field in a of size 2^4
    582583            sage: k = FiniteField_ext_pari(8,'a')
    583584            sage: k._coerce_(FiniteField(7,'a')(2))
    584585            Traceback (most recent call last):
    585586            ...
    586             TypeError: no canonical coercion of element into self
     587            TypeError: no canonical coercion from Finite Field of size 7 to Finite Field in a of size 2^3
    587588        """
    588589        from sage.rings.integer_ring import ZZ
    589590        from sage.rings.finite_rings.integer_mod_ring import IntegerModRing_generic
     
    595596            if R.characteristic() == self.characteristic():
    596597                if R.degree() == 1:
    597598                    return True
    598                 elif self.degree() % K.degree() == 0:
     599                elif self.degree() % R.degree() == 0:
    599600                    # TODO: This is where we *would* do coercion from one nontrivial finite field to another...
    600601                    return False               
    601602        from sage.rings.residue_field import ResidueField_generic
  • sage/rings/finite_rings/finite_field_givaro.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 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
     
    321321            sage: F81(F9.gen())
    322322            Traceback (most recent call last):
    323323            ...
    324             TypeError: unable to coerce from a finite field other than the prime subfield
     324            NotImplementedError
    325325        """
    326326        return self._cache.element_from_data(e)
    327327
  • sage/rings/finite_rings/finite_field_prime_modn.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/finite_rings/finite_field_prime_modn.py
    a b  
    5757        p = integer.Integer(p)
    5858        if not arith.is_prime(p):
    5959            raise ArithmeticError, "p must be prime"
    60         from sage.categories.fields import Fields
     60        from sage.categories.finite_fields import FiniteFields
    6161        self.__char = p
    6262        import sage.structure.factorization as factorization
    6363        self._IntegerModRing_generic__factored_order = factorization.Factorization([(p,1)], integer.Integer(1))
    6464        self._kwargs = {}
    65         integer_mod_ring.IntegerModRing_generic.__init__(self, p, category = Fields())
    66         ParentWithGens.__init__(self, self, ('x',), normalize=False)
     65        integer_mod_ring.IntegerModRing_generic.__init__(self, p, category = FiniteFields())
     66        FiniteField_generic.__init__(self, self, ('x',), normalize=False)
    6767
    6868    def __reduce__(self):
    6969        """
     
    138138            5
    139139        """
    140140        from sage.rings.integer_ring import ZZ
    141         from sage.rings.integer_mod_ring import IntegerModRing_generic
     141        from sage.rings.finite_rings.integer_mod_ring import IntegerModRing_generic
    142142        if S is int:
    143143            return integer_mod.Int_to_IntegerMod(self)
    144144        elif S is ZZ:
  • sage/rings/finite_rings/integer_mod_ring.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/finite_rings/integer_mod_ring.py
    a b  
    270270        self.__unit_group_exponent = None
    271271        self.__factored_order = None
    272272        quotient_ring.QuotientRing_generic.__init__(self, ZZ, ZZ.ideal(order), names=None)
    273         from sage.categories.commutative_rings import CommutativeRings
    274         #from sage.categories.fields import Fields
    275         from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
    276273        if category is None:
    277             #category = Fields()  if order.is_prime() else CommutativeRings()
    278             category = CommutativeRings()
    279         category = category.join([category, FiniteEnumeratedSets()])
     274            from sage.categories.commutative_rings import CommutativeRings
     275            from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
     276            from sage.categories.category import Category
     277            category = Category.join([CommutativeRings(), FiniteEnumeratedSets()])
    280278        ParentWithGens.__init__(self, self, category = category)
    281279        if cache is None:
    282280            cache = order < 500
  • sage/rings/fraction_field_FpT.pyx

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/fraction_field_FpT.pyx
    a b  
    15051505                      From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5
    15061506                      To:   Finite Field of size 5
    15071507                    then
    1508                       Conversion via _integer_ method map:
     1508                      Lifting map:
    15091509                      From: Finite Field of size 5
    15101510                      To:   Integer Ring
    15111511            sage: t = K.gen()
  • sage/rings/ideal_monoid.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/ideal_monoid.py
    a b  
    8888            sage: M([a-4, 13])
    8989            Fractional ideal (13, a - 4)
    9090        """
     91        #print x, type(x)
    9192        if isinstance(x, ideal.Ideal_generic):
    9293            x = x.gens()
    9394        y = self.__R.ideal(x)
  • sage/rings/polynomial/ideal.py

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 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 cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/polynomial/polynomial_element.pyx
    a b  
    48634863                    return ZZ(k)
    48644864        if isinstance(p, Polynomial):
    48654865            p = self.parent().coerce(p)
    4866         elif is_Ideal(p) and p.ring() is self.parent():
     4866        elif is_Ideal(p) and p.ring() is self.parent(): # eventually need to handle fractional ideals in the fraction field
    48674867            if self.parent().base_ring().is_field(): # common case
    48684868                p = p.gen()
    48694869            else:
    48704870                raise NotImplementedError
    48714871        else:
    4872             raise TypeError, "The polynomial, p, must have the same parent as self."
     4872            from sage.rings.fraction_field import is_FractionField
     4873            if is_FractionField(p.parent()) and self.parent().has_coerce_map_from(p.parent().ring()):
     4874                p = self.parent().coerce(p.parent().ring()(p)) # here we require that p be integral.
     4875            else:
     4876                raise TypeError, "The polynomial, p, must have the same parent as self."
    48734877
    48744878        if p.degree() == 0:
    48754879            raise ArithmeticError, "The polynomial, p, must have positive degree."
  • sage/rings/residue_field.pyx

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 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::
     
    269269                        p = p.parent().ideal(p)
    270270                elif is_Polynomial(p):
    271271                    p = p.parent().ideal(p)
    272                 elif isinstance(p.parent(), FractionField_1poly_field):
    273                     p = p.parent().ring_of_integers().ideal(p)
     272                #elif isinstance(p.parent(), FractionField_1poly_field):
     273                #    p = p.parent().ring_of_integers().ideal(p)
    274274                # will eventually support other function fields here.
    275275                else:
    276276                    raise ValueError, "p must be an ideal or element of a number field or function field."
     
    390390        sage: type(k)
    391391        <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn_with_category'>
    392392
    393         sage: R.<t> = GF(29)[]; P = R.ideal(t^2 + 2); k.<a> = ResidueField(P); k
    394         Residue field in a of Principal ideal (t^2 + 2) of Univariate Polynomial Ring in t over Finite Field of size 29
    395         sage: type(k)
    396         <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     393        #sage: R.<t> = GF(29)[]; P = R.ideal(t^2 + 2); k.<a> = ResidueField(P); k
     394        #Residue field in a of Principal ideal (t^2 + 2) of Univariate Polynomial Ring in t over Finite Field of size 29
     395        #sage: type(k)
     396        #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    397397    """
    398398    def __init__(self, p):
    399399        """
     
    412412            sage: k = K.residue_field(P) # indirect doctest
    413413            sage: F = ZZ.residue_field(17)  # indirect doctest
    414414
    415             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    416             sage: k.<a> = P.residue_field() # indirect doctest
     415            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     416            #sage: k.<a> = P.residue_field() # indirect doctest
    417417
    418418            sage: k.category()
    419             Category of fields
     419            Category of finite fields
    420420            sage: F.category()
    421             Category of fields
     421            Category of finite fields
    422422
    423423        TESTS::
    424424
     
    444444            sage: k = K.residue_field(K.prime_above(p))
    445445            sage: k.ideal().norm() == p
    446446            True
    447             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    448             sage: k.<a> = R.residue_field(P)
    449             sage: k.ideal()
    450             Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
     447
     448            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     449            #sage: k.<a> = R.residue_field(P)
     450            #sage: k.ideal()
     451            #Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
    451452        """
    452453        return self.p
    453454
     
    469470            sage: ResidueField_generic._element_constructor_(F, GF(13)(8))
    470471            Traceback (most recent call last):
    471472            ...
    472             TypeError: cannot coerce <type 'sage.rings.integer_mod.IntegerMod_int'>
     473            TypeError: cannot coerce <type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
    473474
    474             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    475             sage: k.<a> = P.residue_field()
    476             sage: ResidueField_generic._element_constructor_(k, t)
    477             a
    478             sage: ResidueField_generic._element_constructor_(k, GF(17)(4))
    479             4
     475            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     476            #sage: k.<a> = P.residue_field()
     477            #sage: ResidueField_generic._element_constructor_(k, t)
     478            #a
     479            #sage: ResidueField_generic._element_constructor_(k, GF(17)(4))
     480            #4
    480481        """
    481482        K = OK = self.p.ring()
    482483        if OK.is_field():
     
    510511            sage: GF(13).has_coerce_map_from(F)
    511512            False
    512513           
    513             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    514             sage: k.<a> = P.residue_field()
    515             sage: k.has_coerce_map_from(Qp(17)) # indirect doctest
    516             False
     514            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     515            #sage: k.<a> = P.residue_field()
     516            #sage: k.has_coerce_map_from(Qp(17)) # indirect doctest
     517            #False
    517518        """
    518519        OK = self.p.ring()
    519520        if OK.is_field():
     
    535536            sage: F = ZZ.residue_field(17); F
    536537            Residue field of Integers modulo 17
    537538
    538             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    539             sage: k.<a> = P.residue_field(); k # indirect doctest
    540             Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
     539            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     540            #sage: k.<a> = P.residue_field(); k # indirect doctest
     541            #Residue field in a of Principal ideal (t^3 + t^2 + 7) of Univariate Polynomial Ring in t over Finite Field of size 17
    541542        """
    542543        if self.p.ring() is ZZ:
    543544            return "Residue field of Integers modulo %s"%self.p.gen()
     
    561562            sage: k.lift(12821*b+918)
    562563            3*a + 19
    563564
    564             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    565             sage: k.<a> = P.residue_field()
    566             sage: k.lift(a^2 + 5)
    567             t^2 + 5
     565            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     566            #sage: k.<a> = P.residue_field()
     567            #sage: k.lift(a^2 + 5)
     568            #t^2 + 5
    568569        """
    569570        if hasattr(self.p, "ring"):
    570571            R = self.p.ring()
     
    603604            sage: F.reduction_map().codomain()
    604605            Residue field of Fractional ideal (-1/4*a)       
    605606
    606             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    607             sage: k.<a> = P.residue_field(); f = k.reduction_map(); f
    608             Partially defined reduction map:
    609               From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 17
    610               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
    611             sage: f(1/t)
    612             12*a^2 + 12*a
     607            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     608            #sage: k.<a> = P.residue_field(); f = k.reduction_map(); f
     609            #Partially defined reduction map:
     610            #  From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 17
     611            #  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
     612            #sage: f(1/t)
     613            #12*a^2 + 12*a
    613614        """
    614615        return self.convert_map_from(self.p.ring().fraction_field())
    615616
     
    634635            sage: f(k.0)
    635636            1
    636637
    637             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    638             sage: k.<a> = P.residue_field(); f = k.lift_map(); f
    639             Lifting map:
    640               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
    641               To:   Univariate Polynomial Ring in t over Finite Field of size 17
    642             sage: f(a^2 + 5)
    643             t^2 + 5
     638            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     639            #sage: k.<a> = P.residue_field(); f = k.lift_map(); f
     640            #Lifting map:
     641            #  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
     642            #  To:   Univariate Polynomial Ring in t over Finite Field of size 17
     643            #sage: f(a^2 + 5)
     644            #t^2 + 5
    644645        """
    645646        OK = self.p.ring()
    646647        if OK.is_field():
     
    663664            sage: k == l
    664665            False
    665666
    666             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    667             sage: k.<a> = P.residue_field()
    668             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 11)
    669             sage: l.<b> = P.residue_field()
    670             sage: k == l
    671             False
    672             sage: ll.<c> = P.residue_field()
    673             sage: ll == l
    674             False
     667            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     668            #sage: k.<a> = P.residue_field()
     669            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 11)
     670            #sage: l.<b> = P.residue_field()
     671            #sage: k == l
     672            #False
     673            #sage: ll.<c> = P.residue_field()
     674            #sage: ll == l
     675            #False
    675676        """
    676677        c = cmp(type(self), type(x))
    677678        if c: return c
     
    691692            -6463132282686559142
    692693            sage: hash(K.residue_field(K.prime_above(2^60))) # random
    693694            -6939519969600666586
    694             sage: K = GF(13)['t'].fraction_field()
    695             sage: hash(K.residue_field(GF(13)['t'].gen() + 2)) # random
    696             743237312
     695            #sage: K = GF(13)['t'].fraction_field()
     696            #sage: hash(K.residue_field(GF(13)['t'].gen() + 2)) # random
     697            #743237312
    697698        """
    698699        return 1 + hash(self.ideal())
    699700
     
    715716          From: Number Field in sqrt17 with defining polynomial x^2 - 17
    716717          To:   Residue field in sqrt17bar of Fractional ideal (5)
    717718
    718         sage: R.<t> = GF(next_prime(2^20))[]; P = R.ideal(t^2 + t + 1)
    719         sage: k = P.residue_field()
    720         sage: k.reduction_map()
    721         Partially defined reduction map:
    722           From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 1048583
    723           To:   Residue field in tbar of Principal ideal (t^2 + t + 1) of Univariate Polynomial Ring in t over Finite Field of size 1048583
     719        #sage: R.<t> = GF(next_prime(2^20))[]; P = R.ideal(t^2 + t + 1)
     720        #sage: k = P.residue_field()
     721        #sage: k.reduction_map()
     722        #Partially defined reduction map:
     723        #  From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 1048583
     724        #  To:   Residue field in tbar of Principal ideal (t^2 + t + 1) of Univariate Polynomial Ring in t over Finite Field of size 1048583
    724725    """
    725726    def __init__(self, K, F, to_vs, to_order, PB, PBinv):
    726727        """
     
    740741            sage: F.reduction_map().__repr__()
    741742            '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)'
    742743           
    743             sage: R.<t> = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1)
    744             sage: k = P.residue_field()
    745             sage: k.reduction_map()
    746             Partially defined reduction map:
    747               From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
    748               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)
    749             sage: type(k)
    750             <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     744            #sage: R.<t> = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1)
     745            #sage: k = P.residue_field()
     746            #sage: k.reduction_map()
     747            #Partially defined reduction map:
     748            #  From: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
     749            #  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)
     750            #sage: type(k)
     751            #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    751752        """
    752753        self._K = K
    753754        self._F = F   # finite field
     
    782783            ...
    783784            ZeroDivisionError: Cannot reduce field element 1/2*a modulo Fractional ideal (a + 1): it has negative valuation
    784785
    785             sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
    786             sage: k.<a> = R.residue_field(h); K = R.fraction_field()
    787             sage: f = k.convert_map_from(K)
    788             sage: type(f)
    789             <type 'sage.rings.residue_field.ReductionMap'>
    790             sage: f(1/t)
    791             a^4 + a
    792             sage: f(1/h)
    793             Traceback (most recent call last):
    794             ...
    795             ZeroDivisionError: division by zero in finite field.
     786            #sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
     787            #sage: k.<a> = R.residue_field(h); K = R.fraction_field()
     788            #sage: f = k.convert_map_from(K)
     789            #sage: type(f)
     790            #<type 'sage.rings.residue_field.ReductionMap'>
     791            #sage: f(1/t)
     792            #a^4 + a
     793            #sage: f(1/h)
     794            #Traceback (most recent call last):
     795            #...
     796            #ZeroDivisionError: division by zero in finite field.
    796797
    797798        An example to show that the issue raised in trac \#1951
    798799        has been fixed::
     
    891892            sage: s(l.gen()).parent()
    892893            Number Field in b with defining polynomial x^5 + 17*x + 1
    893894
    894             sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
    895             sage: k.<a> = R.residue_field(h); K = R.fraction_field()
    896             sage: f = k.convert_map_from(K)
    897             sage: f.section()
    898             Lifting map:
    899               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)
    900               To:   Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
     895            #sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
     896            #sage: k.<a> = R.residue_field(h); K = R.fraction_field()
     897            #sage: f = k.convert_map_from(K)
     898            #sage: f.section()
     899            #Lifting map:
     900            #  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)
     901            #  To:   Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
    901902        """
    902903        if self._section is None:
    903904            self._section = LiftingMap(self, self._to_order, self._PB)
     
    924925          From: Maximal Order in Number Field in a with defining polynomial x^3 - 7
    925926          To:   Residue field in abar of Fractional ideal (2*a^2 + 3*a - 10)
    926927
    927         sage: R.<t> = GF(19)[]; P = R.ideal(t^2 + 5)
    928         sage: k.<a> = R.residue_field(P)
    929         sage: f = k.coerce_map_from(R); f
    930         Ring morphism:
    931           From: Univariate Polynomial Ring in t over Finite Field of size 19
    932           To:   Residue field in a of Principal ideal (t^2 + 5) of Univariate Polynomial Ring in t over Finite Field of size 19
     928        #sage: R.<t> = GF(19)[]; P = R.ideal(t^2 + 5)
     929        #sage: k.<a> = R.residue_field(P)
     930        #sage: f = k.coerce_map_from(R); f
     931        #Ring morphism:
     932        #  From: Univariate Polynomial Ring in t over Finite Field of size 19
     933        #  To:   Residue field in a of Principal ideal (t^2 + 5) of Univariate Polynomial Ring in t over Finite Field of size 19
    933934    """
    934935    def __init__(self, K, F, to_vs, to_order, PB, PBinv):
    935936        """
     
    955956            sage: type(phi)
    956957            <type 'sage.rings.residue_field.NFResidueFieldHomomorphism'>
    957958
    958             sage: R.<t> = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1)
    959             sage: k = P.residue_field(); f = k.coerce_map_from(R)
    960             sage: f(t^10)
    961             tbar^6 + tbar^3 + tbar^2
     959            #sage: R.<t> = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1)
     960            #sage: k = P.residue_field(); f = k.coerce_map_from(R)
     961            #sage: f(t^10)
     962            #tbar^6 + tbar^3 + tbar^2
    962963           
    963964        """
    964965        self._K = K
     
    984985            sage: k.coerce_map_from(OK)(OK(a)^7) # indirect doctest
    985986            13*abar^2 + 7*abar + 21
    986987
    987             sage: R.<t> = GF(next_prime(2^18))[]; P = R.ideal(t - 71)
    988             sage: k = ResidueField(P); f = k.coerce_map_from(R); f
    989             Ring morphism:
    990               From: Univariate Polynomial Ring in t over Finite Field of size 262147
    991               To:   Residue field of Principal ideal (t + 262076) of Univariate Polynomial Ring in t over Finite Field of size 262147
    992             sage: f(t^2)
    993             5041
     988            #sage: R.<t> = GF(next_prime(2^18))[]; P = R.ideal(t - 71)
     989            #sage: k = ResidueField(P); f = k.coerce_map_from(R); f
     990            #Ring morphism:
     991            #  From: Univariate Polynomial Ring in t over Finite Field of size 262147
     992            #  To:   Residue field of Principal ideal (t + 262076) of Univariate Polynomial Ring in t over Finite Field of size 262147
     993            #sage: f(t^2)
     994            #5041
    994995        """
    995996        # The reduction map is just x |--> F(to_vs(x) * (PB**(-1))) if
    996997        # either x is integral or the denominator of x is coprime to
     
    10351036            sage: s(l.gen()).parent()
    10361037            Maximal Order in Number Field in b with defining polynomial x^5 + 17*x + 1
    10371038
    1038             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    1039             sage: k.<a> = P.residue_field(); f = k.coerce_map_from(R)
    1040             sage: f.section()
    1041             Lifting map:
    1042               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
    1043               To:   Univariate Polynomial Ring in t over Finite Field of size 17
     1039            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     1040            #sage: k.<a> = P.residue_field(); f = k.coerce_map_from(R)
     1041            #sage: f.section()
     1042            #Lifting map:
     1043            #  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
     1044            #  To:   Univariate Polynomial Ring in t over Finite Field of size 17
    10441045        """
    10451046        if self._section is None:
    10461047            self._section = LiftingMap(self, self._to_order, self._PB)
     
    10651066            sage: f.lift(12821*b+918)
    10661067            3*a + 19
    10671068
    1068             sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
    1069             sage: k.<a> = P.residue_field(); f = k.coerce_map_from(R)
    1070             sage: f.lift(a^2 + 5*a + 1)
    1071             t^2 + 5*t + 1
    1072             sage: f(f.lift(a^2 + 5*a + 1)) == a^2 + 5*a + 1
    1073             True
     1069            #sage: R.<t> = GF(17)[]; P = R.ideal(t^3 + t^2 + 7)
     1070            #sage: k.<a> = P.residue_field(); f = k.coerce_map_from(R)
     1071            #sage: f.lift(a^2 + 5*a + 1)
     1072            #t^2 + 5*t + 1
     1073            #sage: f(f.lift(a^2 + 5*a + 1)) == a^2 + 5*a + 1
     1074            #True
    10741075        """
    10751076        if self.domain() is ZZ:
    10761077            return x.lift()
     
    10961097        sage: L(3*a + 1) == F.0^2
    10971098        True
    10981099
    1099         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)
    1100         sage: k.<a> = P.residue_field(); k.lift_map()
    1101         Lifting map:
    1102           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
    1103           To:   Univariate Polynomial Ring in t over Finite Field of size 13
     1100        #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)
     1101        #sage: k.<a> = P.residue_field(); k.lift_map()
     1102        #Lifting map:
     1103        #  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
     1104        #  To:   Univariate Polynomial Ring in t over Finite Field of size 13
    11041105    """
    11051106    def __init__(self, reduction, to_order, PB):
    11061107        """
     
    11331134            sage: L.codomain()
    11341135            Maximal Order in Cyclotomic Field of order 7 and degree 6
    11351136
    1136             sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
    1137             sage: k.<a> = R.residue_field(h); K = R.fraction_field()
    1138             sage: L = k.lift_map(); L.codomain()
    1139             Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
     1137            #sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
     1138            #sage: k.<a> = R.residue_field(h); K = R.fraction_field()
     1139            #sage: L = k.lift_map(); L.codomain()
     1140            #Univariate Polynomial Ring in t over Finite Field of size 2 (using NTL)
    11401141        """
    11411142        self._K = reduction._K
    11421143        self._F = reduction._F   # finite field
     
    11611162            sage: F(a)
    11621163            abar
    11631164
    1164             sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
    1165             sage: k.<a> = R.residue_field(h); K = R.fraction_field()
    1166             sage: f = k.lift_map()
    1167             sage: f(a^2)
    1168             t^2
    1169             sage: f(a^6)
    1170             t^3 + t
     1165            #sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
     1166            #sage: k.<a> = R.residue_field(h); K = R.fraction_field()
     1167            #sage: f = k.lift_map()
     1168            #sage: f(a^2)
     1169            #t^2
     1170            #sage: f(a^6)
     1171            #t^3 + t
    11711172        """
    11721173        if self._K is QQ or self._K is ZZ:
    11731174            return self._K(x.lift())  # x.lift() is in ZZ
     
    12261227        sage: b + c
    12271228        3
    12281229
    1229         sage: R.<t> = GF(7)[]; P = R.ideal(2*t + 3)
    1230         sage: k = P.residue_field(); k
    1231         Residue field of Principal ideal (2*t + 3) of Univariate Polynomial Ring in t over Finite Field of size 7
    1232         sage: k(t^2)
    1233         4
    1234         sage: k.order()
    1235         7
     1230        #sage: R.<t> = GF(7)[]; P = R.ideal(2*t + 3)
     1231        #sage: k = P.residue_field(); k
     1232        #Residue field of Principal ideal (2*t + 3) of Univariate Polynomial Ring in t over Finite Field of size 7
     1233        #sage: k(t^2)
     1234        #4
     1235        #sage: k.order()
     1236        #7
    12361237    """
    12371238    def __init__(self, p, name, intp, to_vs, to_order, PB):
    12381239        """
     
    12491250            sage: type(kk)
    12501251            <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn_with_category'>
    12511252
    1252             sage: R.<t> = GF(7)[]; P = R.ideal(2*t + 3)
    1253             sage: k = P.residue_field(); type(k)
    1254             <class 'sage.rings.residue_field.ResidueFiniteField_prime_modn_with_category'>
     1253            #sage: R.<t> = GF(7)[]; P = R.ideal(2*t + 3)
     1254            #sage: k = P.residue_field(); type(k)
     1255            #<class 'sage.rings.residue_field.ResidueFiniteField_prime_modn_with_category'>
    12551256        """
    12561257        ResidueField_generic.__init__(self, p)
    12571258        FiniteField_prime_modn.__init__(self, intp, name)
     
    12751276                                                 convert_list=[ReductionMap(K, self, to_vs, to_order, PB, PBinv)])
    12761277 
    12771278    def _element_constructor_(self, x):
    1278             FiniteField_prime_modn.__init__(self, intp, name)
    1279             self.f = NFResidueFieldHomomorphism(self, p, im_gen)
    1280             ResidueField_generic.__init__(self, p, self.f, intp)
    1281 
    1282     def __call__(self, x):
    12831279        """
    12841280        INPUT:
    12851281       
     
    13051301            sage: k(v) # indirect doctest
    13061302            3
    13071303
    1308             sage: R.<t> = GF(2)[]; P = R.ideal(t+1); k.<a> = P.residue_field()
    1309             sage: V = k.vector_space(); v = V([1])
    1310             sage: k(v)
    1311             1
     1304            #sage: R.<t> = GF(2)[]; P = R.ideal(t+1); k.<a> = P.residue_field()
     1305            #sage: V = k.vector_space(); v = V([1])
     1306            #sage: k(v)
     1307            #1
    13121308        """
    13131309        if isinstance(x, FreeModuleElement) and len(x) == 1:
    13141310            x = x[0]
     
    13381334        sage: k.base_ring()
    13391335        Finite Field of size 923478923
    13401336
    1341         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)
    1342         sage: k.<a> = P.residue_field()
    1343         sage: type(k)
    1344         <class 'sage.rings.residue_field.ResidueFiniteField_ext_pari'>
    1345         sage: k(1/t)
    1346         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
     1337        #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)
     1338        #sage: k.<a> = P.residue_field()
     1339        #sage: type(k)
     1340        #<class 'sage.rings.residue_field.ResidueFiniteField_ext_pari'>
     1341        #sage: k(1/t)
     1342        #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
    13471343    """
    1348     def __init__(self, p, q, name, g, intp):
     1344    def __init__(self, p, q, name, modulus, to_vs, to_order, PB):
    13491345        """
    13501346        EXAMPLES::
    13511347       
     
    13561352            sage: type(P.residue_field())
    13571353            <class 'sage.rings.residue_field.ResidueFiniteField_ext_pari_with_category'>
    13581354        """
    1359         FiniteField_ext_pari.__init__(self, q, name, g)
    1360         self.p = p
    1361         self.f = NFResidueFieldHomomorphism(self, p, GF(q, name = name, modulus = g).gen(0))
    1362         ResidueField_generic.__init__(self, p, self.f, intp)
     1355        ResidueField_generic.__init__(self, p)
     1356        FiniteField_ext_pari.__init__(self, q, name, modulus)
     1357        K = OK = p.ring()
     1358        if OK.is_field():
     1359            OK = OK.ring_of_integers()
     1360        else:
     1361            K = K.fraction_field()
     1362        if PB is None:
     1363            PBinv = None
     1364        else:
     1365            PBinv = PB**(-1)
     1366        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)])
    13631367
    1364     def __call__(self, x):
     1368    def _element_constructor_(self, x):
    13651369        """
    13661370        Coerce x into self.
    13671371       
     
    13851389            sage: ff(v) # indirect doctest
    13861390            10005*alpha + 3
    13871391
    1388             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)
    1389             sage: k.<a> = P.residue_field()
    1390             sage: V = k.vector_space(); v = V([1,2,3,4,5,6,7,8,9,0,1,2]); k(v) # indirect doctest
    1391             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
     1392            #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)
     1393            #sage: k.<a> = P.residue_field()
     1394            #sage: V = k.vector_space(); v = V([1,2,3,4,5,6,7,8,9,0,1,2]); k(v) # indirect doctest
     1395            #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
    13921396        """
    13931397        try:
    13941398            return FiniteField_ext_pari._element_constructor_(self, x)
     
    14151419        sage: b*c
    14161420        13*abar + 5
    14171421
    1418         sage: R.<t> = GF(7)[]; P = R.ideal(t^2 + 4)
    1419         sage: k.<a> = R.residue_field(P); type(k)
    1420         <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    1421         sage: k(1/t)
    1422         5*a
     1422        #sage: R.<t> = GF(7)[]; P = R.ideal(t^2 + 4)
     1423        #sage: k.<a> = R.residue_field(P); type(k)
     1424        #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     1425        #sage: k(1/t)
     1426        #5*a
    14231427    """
    14241428    def __init__(self, p, q, name, modulus, to_vs, to_order, PB):
    14251429        """
     
    14401444            sage: P = K.ideal(61).factor()[0][0]
    14411445            sage: k = K.residue_field(P)
    14421446
    1443             sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field(); type(k)
    1444             <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    1445             sage: a^5
    1446             a^3 + 2*a^2 + a + 2
     1447            #sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field(); type(k)
     1448            #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     1449            #sage: a^5
     1450            #a^3 + 2*a^2 + a + 2
    14471451
    14481452        """
    14491453        ResidueField_generic.__init__(self, p)
     
    14791483            sage: k(v) # indirect doctest
    14801484            59*abar + 3
    14811485
    1482             sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field()
    1483             sage: V = k.vector_space(); v = V([0,1,2,3])
    1484             sage: k(v) # indirect doctest
    1485             2*a^2 + a
     1486            #sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field()
     1487            #sage: V = k.vector_space(); v = V([0,1,2,3])
     1488            #sage: k(v) # indirect doctest
     1489            #2*a^2 + a
    14861490        """
    14871491        try:
    14881492            return FiniteField_givaro._element_constructor_(self, x)
     
    15111515        sage: b*c
    15121516        13*abar + 5
    15131517
    1514         sage: R.<t> = GF(2)[]; P = R.ideal(t^19 + t^5 + t^2 + t + 1)
    1515         sage: k.<a> = R.residue_field(P); type(k)
    1516         <class 'sage.rings.residue_field.ResidueFiniteField_ntl_gf2e'>
    1517         sage: k(1/t)
    1518         a^18 + a^4 + a + 1
    1519         sage: k(1/t)*t
    1520         1
     1518        #sage: R.<t> = GF(2)[]; P = R.ideal(t^19 + t^5 + t^2 + t + 1)
     1519        #sage: k.<a> = R.residue_field(P); type(k)
     1520        #<class 'sage.rings.residue_field.ResidueFiniteField_ntl_gf2e'>
     1521        #sage: k(1/t)
     1522        #a^18 + a^4 + a + 1
     1523        #sage: k(1/t)*t
     1524        #1
    15211525    """
    15221526    # we change the order for consistency with FiniteField_ntl_gf2e's __cinit__
    15231527    def __init__(self, q, name, modulus, repr, p, to_vs, to_order, PB):
     
    15391543            sage: P = K.ideal(61).factor()[0][0]
    15401544            sage: k = K.residue_field(P)
    15411545
    1542             sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field(); type(k)
    1543             <class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
    1544             sage: a^5
    1545             a^3 + 2*a^2 + a + 2
     1546            #sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field(); type(k)
     1547            #<class 'sage.rings.residue_field.ResidueFiniteField_givaro'>
     1548            #sage: a^5
     1549            #a^3 + 2*a^2 + a + 2
    15461550        """
    15471551        ResidueField_generic.__init__(self, p)
    15481552        FiniteField_ntl_gf2e.__init__(self, q, name, modulus, repr)
     
    15771581            sage: k(v) # indirect doctest
    15781582            59*abar + 3
    15791583
    1580             sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field()
    1581             sage: V = k.vector_space(); v = V([0,1,2,3])
    1582             sage: k(v) # indirect doctest
    1583             2*a^2 + a
     1584            #sage: R.<t> = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k.<a> = P.residue_field()
     1585            #sage: V = k.vector_space(); v = V([0,1,2,3])
     1586            #sage: k(v) # indirect doctest
     1587            #2*a^2 + a
    15841588        """
    15851589        try:
    15861590            return FiniteField_ntl_gf2e._element_constructor_(self, x)
  • sage/rings/ring.pyx

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/rings/ring.pyx
    a b  
    326326        if len(args) == 0:
    327327            gens = [self(0)]
    328328        else:
    329             first = args[0]
    330             if isinstance(first, Ideal_generic) and len(args) == 1:
    331                 R = first.ring()
    332                 m = self.convert_map_from(R)
    333                 if m is not None:
    334                     gens = [m(g) for g in first.gens()]
    335                     coerce = False
     329            gens = args
     330            while isinstance(gens, (list, tuple, GeneratorType)) and len(gens) == 1:
     331                first = gens[0]
     332                if isinstance(first, Ideal_generic):
     333                    R = first.ring()
     334                    m = self.convert_map_from(R)
     335                    if m is not None:
     336                        gens = [m(g) for g in first.gens()]
     337                        coerce = False
     338                    else:
     339                        m = R.convert_map_from(self)
     340                        if m is not None:
     341                            raise NotImplementedError
     342                        else:
     343                            raise TypeError
     344                    break
     345                elif isinstance(first, (list, tuple, GeneratorType)):
     346                    gens = first
    336347                else:
    337                     m = R.convert_map_from(self)
    338                     if m is not None:
    339                         raise NotImplementedError
    340                     else:
    341                         raise TypeError
    342             else:
    343                 gens = args
    344                 if isinstance(first, (list, tuple, GeneratorType)) and len(gens) == 1:
    345                     gens = first
    346 
     348                    break
    347349        if coerce:
     350            #print [type(g) for g in gens]
    348351            gens = [self(g) for g in gens]
    349352        if isinstance(self, PrincipalIdealDomain):
    350353            # Use GCD algorithm to obtain a principal ideal
    351354            g = gens[0]
    352             for h in gens[1:]:
    353                 g = self.gcd(g, h)
     355            if len(gens) == 1:
     356                try:
     357                    g = g.gcd(g) # note: we set g = gcd(g, g) to "canonicalize" the generator: make polynomials monic, etc.
     358                except (AttributeError, NotImplementedError):
     359                    pass
     360            else:
     361                for h in gens[1:]:
     362                    g = g.gcd(h)
    354363            gens = [g]
    355364        if kwds.has_key('ideal_class'):
    356365            C = kwds['ideal_class']
     
    430439        C = self._ideal_class_(1)
    431440        if coerce:
    432441            gen = self(gen)
    433         return C([gen])
     442        return C(self, [gen])
    434443
    435444    def unit_ideal(self):
    436445        """
  • sage/structure/parent.pyx

    diff -r cc21ebc4d358 -r ab51c0b8ddb1 sage/structure/parent.pyx
    a b  
    530530        EXAMPLES::
    531531
    532532            sage: k = GF(5); k._element_constructor # indirect doctest
    533             <bound method FiniteField_prime_modn._element_constructor_ of Finite Field of size 5>
     533            <bound method FiniteField_prime_modn_with_category._element_constructor_ of Finite Field of size 5>
    534534        """
    535535        if hasattr(self, '_element_constructor_'):
    536536            assert callable(self._element_constructor_)