Ticket #9400: 9400_combined.patch

File 9400_combined.patch, 47.3 KB (added by jdemeyer, 10 years ago)

All 3 patches combined (apply only this patch)

  • sage/libs/pari/gen.pyx

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1283704081 25200
    # Node ID 9b1e50c3b3909d629e4b2ea0ec4e868d26f5dbd1
    # Parent  f282b3777b8412d5f6b4571860ed40c27a66aba3
    #9400: Allow the NumberField constructor to compute an order maximal at only a certain set of primes.
    #9400: ReSTify residue class fields.
    #9400: Optimize reduction modulo a prime.
    #9400: PARI functions nfbasis() and nfinit(): document and fix implementation.
    #9400: Change pari_nf() to always use integral_basis() (this means that all the maximize_at_primes code can be moved out of pari_nf()).
    #9400: Rename _compute_integral_basis to _pari_integral_basis and don't convert from PARI to Sage.
    #9400: Make CyclotomicField more analogous to NumberField_generic, such that only _pari_integral_basis() needs to be specialized, not integral_basis(). 
    
    diff -r f282b3777b84 -r 9b1e50c3b390 sage/libs/pari/gen.pyx
    a b  
    64386438        _sig_on
    64396439        return self.new_gen(modreverse(self.g))
    64406440
    6441     def nfbasis(self, long flag=0, p=0):
    6442         cdef gen _p
    6443         cdef GEN g
    6444         if p != 0:
    6445             _p = self.pari(p)
    6446             g = _p.g
    6447         else:
    6448             g = <GEN>NULL
    6449         _sig_on
    6450         return self.new_gen(nfbasis0(self.g, flag, g))
    6451 
    6452     def nfbasis_d(self, long flag=0, p=0):
     6441    def nfbasis(self, long flag=0, fa=0):
     6442        """
     6443        nfbasis(x, flag, fa): integral basis of the field QQ[a], where ``a`` is
     6444        a root of the polynomial x.
     6445       
     6446        Binary digits of ``flag`` mean:
     6447         - 1: assume that no square of a prime>primelimit divides the
     6448              discriminant of ``x``.
     6449         - 2: use round 2 algorithm instead of round 4.
     6450       
     6451        If present, ``fa`` provides the matrix of a partial factorization of
     6452        the discriminant of ``x``, useful if one wants only an order maximal at
     6453        certain primes only.
     6454       
     6455        EXAMPLES::
     6456       
     6457            sage: pari('x^3 - 17').nfbasis()
     6458            [1, x, 1/3*x^2 - 1/3*x + 1/3]
     6459       
     6460        We test ``flag`` = 1, noting it gives a wrong result when the
     6461        discriminant (-4 * `p`^2 * `q` in the example below) has a big square
     6462        factor::
     6463       
     6464            sage: p = next_prime(10^10); q = next_prime(p)
     6465            sage: x = polygen(QQ); f = x^2 + p^2*q
     6466            sage: pari(f).nfbasis(1)   # Wrong result
     6467            [1, x]
     6468            sage: pari(f).nfbasis()    # Correct result
     6469            [1, 1/10000000019*x]
     6470            sage: pari(f).nfbasis(fa = "[2,2; %s,2]"%p)    # Correct result and faster
     6471            [1, 1/10000000019*x]
     6472       
     6473        TESTS:
     6474       
     6475        ``flag`` = 2 should give the same result::
     6476           
     6477            sage: pari('x^3 - 17').nfbasis(flag = 2)
     6478            [1, x, 1/3*x^2 - 1/3*x + 1/3]
     6479        """
     6480        global t0
     6481        t0GEN(fa)
     6482        if typ(t0) != t_MAT:
     6483            t0 = <GEN>0
     6484        _sig_on
     6485        return self.new_gen(nfbasis0(self.g, flag, t0))
     6486
     6487    def nfbasis_d(self, long flag=0, fa=0):
    64536488        """
    64546489        nfbasis_d(x): Return a basis of the number field defined over QQ
    64556490        by x and its discriminant.
     
    64716506            sage: pari([-2,0,0,1]).Polrev().nfbasis_d()
    64726507            ([1, x, x^2], -108)
    64736508        """
    6474         cdef gen d
    6475         cdef GEN g
    6476        
    6477         if p:
    6478             g = (<gen>self.pari(p)).g
    6479         else:
    6480             g = <GEN>NULL
    6481            
    6482         _sig_on
    6483         nfb = self.new_gen(nfbasis(self.g, &t0, flag, g))
    6484         d = self.new_gen(t0)
    6485         return nfb, d
     6509        global t0
     6510        cdef GEN disc
     6511        t0GEN(fa)
     6512        if typ(t0) != t_MAT:
     6513            t0 = <GEN>0
     6514        _sig_on
     6515        B = self.new_gen_noclear(nfbasis(self.g, &disc, flag, t0))
     6516        D = self.new_gen(disc);
     6517        return B,D
    64866518
    64876519    def nfdisc(self, long flag=0, p=0):
    64886520        """
     
    65496581        x = f.variable()
    65506582        return x.Mod(f)
    65516583
    6552     def nfinit(self, long flag=0):
    6553         _sig_on
    6554         return P.new_gen(nfinit0(self.g, flag, prec))
     6584    def nfinit(self, long flag=0, long precision=0):
     6585        """
     6586        nfinit(pol, {flag=0}): ``pol`` being a nonconstant irreducible
     6587        polynomial, gives a vector containing all the data necessary for PARI
     6588        to compute in this number field.
     6589       
     6590        ``flag`` is optional and can be set to:
     6591         - 0: default
     6592         - 1: do not compute different
     6593         - 2: first use polred to find a simpler polynomial
     6594         - 3: outputs a two-element vector [nf,Mod(a,P)], where nf is as in 2
     6595              and Mod(a,P) is a polmod equal to Mod(x,pol) and P=nf.pol
     6596       
     6597        EXAMPLES::
     6598           
     6599            sage: pari('x^3 - 17').nfinit()
     6600            [x^3 - 17, [1, 1], -867, 3, [[1, 1.68006..., 2.57128...; 1, -0.340034... + 2.65083...*I, -1.28564... - 2.22679...*I], [1, 1.68006..., 2.57128...; 1, 2.31080..., -3.51243...; 1, -2.99087..., 0.941154...], [1, 2, 3; 1, 2, -4; 1, -3, 1], [3, 1, 0; 1, -11, 17; 0, 17, 0], [51, 0, 16; 0, 17, 3; 0, 0, 1], [17, 0, -1; 0, 0, 3; -1, 3, 2], [51, [-17, 6, -1; 0, -18, 3; 1, 0, -16]]], [2.57128..., -1.28564... - 2.22679...*I], [1, 1/3*x^2 - 1/3*x + 1/3, x], [1, 0, -1; 0, 0, 3; 0, 1, 1], [1, 0, 0, 0, -4, 6, 0, 6, -1; 0, 1, 0, 1, 1, -1, 0, -1, 3; 0, 0, 1, 0, 2, 0, 1, 0, 1]]
     6601           
     6602        TESTS:
     6603       
     6604        This example only works after increasing precision::
     6605       
     6606            sage: pari('x^2 + 10^100 + 1').nfinit(precision=64)
     6607            Traceback (most recent call last):
     6608            ...
     6609            PariError: precision too low (10)
     6610            sage: pari('x^2 + 10^100 + 1').nfinit()
     6611            [...]
     6612
     6613        Throw a PARI error which is not precer::
     6614       
     6615            sage: pari('1.0').nfinit()
     6616            Traceback (most recent call last):
     6617            ...
     6618            PariError: incorrect type (11)
     6619        """
     6620       
     6621        # If explicit precision is given, use only that
     6622        if precision:
     6623            return self._nfinit_with_prec(flag, precision)
     6624       
     6625        # Otherwise, start with 64 bits of precision and increase as needed:
     6626        precision = 64
     6627        while True:
     6628            try:
     6629                return self._nfinit_with_prec(flag, precision)
     6630            except PariError, err:
     6631                if err.errnum() == precer:
     6632                    precision *= 2
     6633                else:
     6634                    raise err
     6635
     6636    # NOTE: because of the way _sig_on and Cython exceptions work, this
     6637    # function MUST NOT be folded into nfinit() above. It has to be a
     6638    # seperate function.
     6639    def _nfinit_with_prec(self, long flag, long precision):
     6640        """
     6641        See ``self.nfinit()``.
     6642        """
     6643        _sig_on
     6644        return P.new_gen(nfinit0(self.g, flag, pbw(precision)))
    65556645
    65566646    def nfisisom(self, gen other):
    65576647        """
     
    68756965        _sig_on
    68766966        return self.new_gen(polgalois(self.g, prec))
    68776967
    6878     def nfgaloisconj(self, long flag=0, denom=None, long prec=0):
     6968    def nfgaloisconj(self, long flag=0, denom=None, long precision=0):
    68796969        r"""
    68806970        Edited from the pari documentation:
    68816971
     
    69026992        else:
    69036993            t0 = NULL
    69046994        _sig_on
    6905         return self.new_gen(galoisconj0(self.g, flag, t0, pbw(prec)))
     6995        return self.new_gen(galoisconj0(self.g, flag, t0, pbw(precision)))
    69066996
    69076997    def nfroots(self, poly):
    69086998        r"""
     
    92759365
    92769366cdef extern from "pari/pari.h":
    92779367    char *errmessage[]
    9278     int user
    9279     int errpile
    9280     int noer
     9368    int talker2, bugparier, alarmer, openfiler, talker, flagerr, impl, \
     9369        archer, notfuncer, precer, typeer, consister, user, errpile, \
     9370        overflower, matinv1, mattype1, arither1, primer1, invmoder, \
     9371        constpoler, notpoler, redpoler, zeropoler, operi, operf, gdiver, \
     9372        memer, negexper, sqrter5, noer
     9373    int warner, warnprec, warnfile, warnmem
    92819374
    92829375cdef extern from "misc.h":
    92839376    int     factorint_withproof_sage(GEN* ans, GEN x, GEN cutoff)
     
    93009393
    93019394    errmessage = staticmethod(__errmessage)
    93029395
     9396    def errnum(self):
     9397        r"""
     9398        Return the PARI error number corresponding to this exception.
     9399       
     9400        EXAMPLES::
     9401           
     9402            sage: try:
     9403            ...     pari('1/0')
     9404            ... except PariError, err:
     9405            ...     print err.errnum()
     9406            27
     9407        """
     9408        return self.args[0]
     9409
    93039410    def __repr__(self):
    9304         return "PariError(%d)"%self.args[0]
     9411        r"""
     9412        TESTS::
     9413           
     9414            sage: PariError(11)
     9415            PariError(11)
     9416        """
     9417        return "PariError(%d)"%self.errnum()
    93059418
    93069419    def __str__(self):
    9307         return "%s (%d)"%(self.errmessage(self.args[0]),self.args[0])
     9420        r"""
     9421        EXAMPLES::
     9422           
     9423            sage: try:
     9424            ...     pari('1/0')
     9425            ... except PariError, err:
     9426            ...     print err
     9427            division by zero (27)
     9428        """
     9429        return "%s (%d)"%(self.errmessage(self.errnum()), self.errnum())
     9430
    93089431
    93099432# We expose a trap function to C.
    93109433# If this function returns without raising an exception,
  • sage/rings/number_field/number_field.py

    diff -r f282b3777b84 -r 9b1e50c3b390 sage/rings/number_field/number_field.py
    a b  
    248248
    249249
    250250_nf_cache = {}
    251 def NumberField(polynomial, name=None, check=True, names=None, cache=True, embedding=None, latex_name=None):
     251def NumberField(polynomial, name=None, check=True, names=None, cache=True,
     252                embedding=None, latex_name=None,
     253                assume_disc_small=False,
     254                maximize_at_primes=None):
    252255    r"""
    253256    Return *the* number field defined by the given irreducible
    254257    polynomial and with variable with the given name. If check is True
     
    257260   
    258261    INPUT:
    259262   
    260     -  ``polynomial`` - a polynomial over `\QQ` or a number
    261        field, or a list of polynomials.
    262     -  ``name`` - a string (default: 'a'), the name of the
    263        generator
    264     -  ``check`` - bool (default: True); do type checking
    265        and irreducibility checking.
    266     -  ``embedding`` - image of the generator in an ambient
    267        field (default: None)
     263        - ``polynomial`` - a polynomial over `\QQ` or a number field,
     264          or a list of polynomials.
     265        - ``name`` - a string (default: 'a'), the name of the generator
     266        - ``check`` - bool (default: True); do type checking and
     267          irreducibility checking.
     268        - ``embedding`` - image of the generator in an ambient field
     269          (default: None)
     270        - ``assume_disc_small`` -- (default: False); if True, assume
     271          that no square of a prime greater than PARI's primelimit
     272          (which should be 500000); only applies for absolute fields
     273          at present.
     274        - ``maximize_at_primes`` -- (default: None) None or a list of
     275          primes; if not None, then the maximal order is computed by
     276          maximizing only at the primes in this list, which completely
     277          avoids having to factor the discriminant, but of course can
     278          lead to wrong results; only applies for absolute fields at
     279          present.
    268280   
    269281    EXAMPLES::
    270282   
     
    454466
    455467    if cache:
    456468        key = (polynomial, polynomial.base_ring(), name, latex_name,
    457                embedding, embedding.parent() if embedding is not None else None)
     469               embedding, embedding.parent() if embedding is not None else None,
     470               assume_disc_small, None if maximize_at_primes is None else tuple(maximize_at_primes))
    458471        if _nf_cache.has_key(key):
    459472            K = _nf_cache[key]()
    460473            if not K is None: return K
     
    466479        return S
    467480
    468481    if polynomial.degree() == 2:
    469         K = NumberField_quadratic(polynomial, name, latex_name, check, embedding)
     482        K = NumberField_quadratic(polynomial, name, latex_name, check, embedding,
     483             assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    470484    else:
    471         K = NumberField_absolute(polynomial, name, latex_name, check, embedding)
     485        K = NumberField_absolute(polynomial, name, latex_name, check, embedding,
     486             assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    472487
    473488    if cache:
    474489        _nf_cache[key] = weakref.ref(K)
     
    926941    """
    927942    def __init__(self, polynomial, name,
    928943                 latex_name=None, check=True, embedding=None,
    929                  category = None):
     944                 category = None,
     945                 assume_disc_small=False, maximize_at_primes=None):
    930946        """
    931947        Create a number field.
    932948       
     
    978994            ...
    979995            TypeError: polynomial must be defined over rational field
    980996        """
    981 
     997        self._assume_disc_small = assume_disc_small
     998        self._maximize_at_primes = maximize_at_primes
    982999        from sage.categories.number_fields import NumberFields
    9831000        default_category = NumberFields()
    9841001        if category is None:
     
    21652182       
    21662183            sage: x = ZZ['x'].gen()
    21672184            sage: F.<t> = NumberField(x^3 - 2)
    2168        
     2185           
    21692186        ::
    21702187       
    21712188            sage: P2 = F.prime_above(2)
     
    23872404        """
    23882405        PARI number field corresponding to this field.
    23892406       
    2390         This is the number field constructed using nfinit. This is the same
     2407        This is the number field constructed using nfinit(). This is the same
    23912408        as the number field got by doing pari(self) or gp(self).
    23922409       
    23932410        EXAMPLES::
     
    23972414            sage: k.pari_nf()[:4]
    23982415            [x^4 - 3*x + 7, [0, 2], 85621, 1]
    23992416            sage: pari(k)[:4]
    2400             [x^4 - 3*x + 7, [0, 2], 85621, 1]       
     2417            [x^4 - 3*x + 7, [0, 2], 85621, 1]
    24012418       
    24022419        ::
    24032420       
     
    24152432            Traceback (most recent call last):
    24162433            ...
    24172434            TypeError: Unable to coerce number field defined by non-integral polynomial to PARI.
     2435
     2436        We illustrate the maximize_at_primes and assume_disc_small parameters::
     2437       
     2438            sage: p = next_prime(10^40); q = next_prime(p)
     2439
     2440        The following would take a very long time without the
     2441        maximize_at_primes option above::
     2442       
     2443            sage: K.<a> = NumberField(x^2 - p*q, maximize_at_primes=[p])
     2444            sage: K.pari_nf()
     2445            [x^2 - 100000000000000000000...]
     2446
     2447        Since the discriminant is square-free, this also works::
     2448       
     2449            sage: K.<a> = NumberField(x^2 - p*q, assume_disc_small=True)
     2450            sage: K.pari_nf()
     2451            [x^2 - 100000000000000000000...]
    24182452        """
    24192453        if self.absolute_polynomial().denominator() != 1:
    24202454            raise TypeError, "Unable to coerce number field defined by non-integral polynomial to PARI."
     
    24222456            return self.__pari_nf
    24232457        except AttributeError:
    24242458            f = self.pari_polynomial()
    2425             self.__pari_nf = f.nfinit()
     2459            self.__pari_nf = pari([f, self._pari_integral_basis()]).nfinit()
    24262460            return self.__pari_nf
    24272461
    2428     def _pari_init_(self):
    2429         """
    2430         Needed for conversion of number field to PARI.
     2462    def _pari_(self):
     2463        """
     2464        Converts this number field to PARI.
    24312465       
    24322466        This only works if the defining polynomial of this number field is
    24332467        integral and monic.
     
    24352469        EXAMPLES::
    24362470       
    24372471            sage: k = NumberField(x^2 + x + 1, 'a')
    2438             sage: k._pari_init_()
    2439             'nfinit(x^2 + x + 1)'
    24402472            sage: k._pari_()
    24412473            [x^2 + x + 1, [0, 1], -3, 1, ... [1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]]
    24422474            sage: pari(k)
    24432475            [x^2 + x + 1, [0, 1], -3, 1, ...[1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]]
    24442476        """
    2445         if self.absolute_polynomial().denominator() != 1:
    2446             raise TypeError, "Unable to coerce number field defined by non-integral polynomial to PARI."
    2447         return 'nfinit(%s)'%self.pari_polynomial()
     2477        return self.pari_nf()
     2478       
     2479    def _pari_init_(self):
     2480        """
     2481        Converts this number field to PARI.
     2482       
     2483        This only works if the defining polynomial of this number field is
     2484        integral and monic.
     2485       
     2486        EXAMPLES::
     2487       
     2488            sage: k = NumberField(x^2 + x + 1, 'a')
     2489            sage: k._pari_init_()
     2490            '[x^2 + x + 1, [0, 1], -3, 1, ... [1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]]'
     2491            sage: gp(k)
     2492            [x^2 + x + 1, [0, 1], -3, 1, ...[1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]]
     2493        """
     2494        return str(self.pari_nf())
    24482495
    24492496    def pari_bnf(self, certify=False, units=True):
    24502497        """
     
    28242871            sage: K.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1)], 3)
    28252872            [2, a + 1]
    28262873            sage: K.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3)
    2827             [2, a + 1, a]
     2874            [2, a + 1, a]    # 32-bit
     2875            [2, a + 1, -a]   # 64-bit
    28282876            sage: K.<a> = NumberField(polygen(QQ))
    28292877            sage: K.selmer_group([],5)
    28302878            []
     
    36523700            sage: K.integral_basis()
    36533701            [1, 1/2*a^2 + 1/2*a, a^2]
    36543702       
    3655         ALGORITHM: Uses the pari library.
    3656         """
    3657         return self.maximal_order().basis()
    3658    
    3659     def _compute_integral_basis(self, v=None):
    3660         """
    3661         Internal function returning an integral basis of this number field;
    3662         used in the maximal_order() function.
    3663        
    3664         Note that this is *not* necessarily the same basis returned by
    3665         self.integral_basis().
     3703        ALGORITHM: Uses the pari library (via _pari_integral_basis).
     3704        """
     3705        return self.maximal_order(v=v).basis()
     3706   
     3707    def _pari_integral_basis(self, v=None):
     3708        """
     3709        Internal function returning an integral basis of this number field in
     3710        PARI format.
    36663711       
    36673712        INPUT:
    36683713       
     
    36743719        EXAMPLES::
    36753720       
    36763721            sage: K.<a> = NumberField(x^5 + 10*x + 1)
    3677             sage: K._compute_integral_basis()
    3678             [1, a, a^2, a^3, a^4]
     3722            sage: K._pari_integral_basis()
     3723            [1, x, x^2, x^3, x^4]
    36793724       
    36803725        Next we compute the ring of integers of a cubic field in which 2 is
    36813726        an "essential discriminant divisor", so the ring of integers is not
     
    36843729        ::
    36853730       
    36863731            sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8)
    3687             sage: K._compute_integral_basis()
    3688             [1, a, 1/2*a^2 - 1/2*a]
     3732            sage: K._pari_integral_basis()
     3733            [1, x, 1/2*x^2 - 1/2*x]
    36893734            sage: K.integral_basis()
    36903735            [1, 1/2*a^2 + 1/2*a, a^2]
    36913736        """
     3737        if (v is None or len(v) == 0) and self._maximize_at_primes:
     3738            v = self._maximize_at_primes
     3739               
    36923740        v = self._normalize_prime_list(v)
    36933741        try:
    36943742            return self._integral_basis_dict[v]
    36953743        except:
    36963744            f = self.pari_polynomial()
    3697 
    36983745            if len(v) == 0:
    3699                 B = f.nfbasis()
    3700             else:
    3701                 m = pari.matrix(len(v), 2)
    3702                 d = f.poldisc()
    3703                 for i in range(len(v)):
    3704                     p = pari(ZZ(v[i]))
    3705                     m[i,0] = p
    3706                     m[i,1] = d.valuation(p)
    3707                 B = f.nfbasis(p = m)
    3708 
    3709             basis = map(self, B)
    3710             self._integral_basis_dict[v] = basis
    3711             return basis
     3746                B = f.nfbasis(1 if self._assume_disc_small else 0)
     3747            else:
     3748                m = self._pari_disc_factorization_matrix(v)
     3749                B = f.nfbasis(fa = m)
     3750
     3751            self._integral_basis_dict[v] = B
     3752            return B
     3753
     3754    def _pari_disc_factorization_matrix(self, v):
     3755        """
     3756        Returns a PARI matrix representation for the partial
     3757        factorization of the discriminant of the defining polynomial
     3758        of self, defined by the list of primes in the Python list v.
     3759        This function is used internally by the number fields code.
     3760       
     3761        EXAMPLES::
     3762
     3763            sage: x = polygen(QQ,'x')
     3764            sage: f = x^3 + 17*x + 393; f.discriminant().factor()
     3765            -1 * 5^2 * 29 * 5779
     3766            sage: K.<a> = NumberField(f)
     3767            sage: fa = K._pari_disc_factorization_matrix([5,29]); fa
     3768            [5, 2; 29, 1]
     3769            sage: fa.type()
     3770            't_MAT'
     3771        """
     3772        f = self.pari_polynomial()
     3773        m = pari.matrix(len(v), 2)
     3774        d = f.poldisc()
     3775        for i in range(len(v)):
     3776            p = pari(ZZ(v[i]))
     3777            m[i,0] = p
     3778            m[i,1] = d.valuation(p)
     3779        return m
     3780       
    37123781
    37133782    def reduced_basis(self, prec=None):
    37143783        r"""
     
    46804749
    46814750class NumberField_absolute(NumberField_generic):
    46824751
    4683     def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None):
     4752    def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None,
     4753                 assume_disc_small=False, maximize_at_primes=None):
    46844754        """
    46854755        Function to initialize an absolute number field.
    46864756
     
    46924762            <class 'sage.rings.number_field.number_field.NumberField_absolute_with_category'>
    46934763            sage: TestSuite(K).run()
    46944764        """
    4695         NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding)
     4765        NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding,
     4766                                     assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    46964767        self._element_class = number_field_element.NumberFieldElement_absolute
    46974768        self._zero_element = self(0)
    46984769        self._one_element =  self(1)
     
    52565327        except KeyError:
    52575328            pass
    52585329
    5259         B = self._compute_integral_basis(v = v)
     5330        B = map(self, self._pari_integral_basis(v = v))
    52605331
    52615332        if len(v) == 0 or v is None:
    52625333            is_maximal = True
     
    62816352        sage: type(cf3(z1))
    62826353        <type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'>
    62836354    """
    6284     def __init__(self, n, names, embedding=None):
     6355    def __init__(self, n, names, embedding=None, assume_disc_small=False, maximize_at_primes=None):
    62856356        """
    62866357        A cyclotomic field, i.e., a field obtained by adjoining an n-th
    62876358        root of unity to the rational numbers.
     
    63126383                                      name= names,
    63136384                                      latex_name=latex_name,
    63146385                                      check=False,
    6315                                       embedding = embedding)
     6386                                      embedding = embedding,
     6387                                      assume_disc_small=assume_disc_small,
     6388                                      maximize_at_primes=maximize_at_primes)
    63166389        if n%2:
    63176390            self.__zeta_order = 2*n
    63186391        else:
     
    70607133            p = sage.rings.arith.next_prime(p)
    70617134            if p % n == 1:
    70627135                return p
    7063 
    7064     def integral_basis(self, v=None):
    7065         """
    7066         Return a list of elements of this number field that are a basis for
    7067         the full ring of integers.
     7136   
     7137    def _pari_integral_basis(self, v=None):
     7138        """
     7139        Internal function returning an integral basis of this number field in
     7140        PARI format.
    70687141       
    70697142        This field is cyclomotic, so this is a trivial computation, since
    70707143        the power basis on the generator is an integral basis. Thus the v
     
    70727145       
    70737146        EXAMPLES::
    70747147       
    7075             sage: CyclotomicField(5).integral_basis()
    7076             [1, zeta5, zeta5^2, zeta5^3]
     7148            sage: CyclotomicField(5)._pari_integral_basis()
     7149            [1, x, x^2, x^3]
     7150            sage: len(CyclotomicField(137)._pari_integral_basis())
     7151            136
    70777152        """
    70787153        try:
    70797154            return self._integral_basis_dict[tuple()]
    70807155        except KeyError:
    7081             v = tuple()
    7082             z = self.gen()
    7083             a = self(1)
     7156            z = pari(self.gen())
     7157            a = pari(1)
    70847158            B = []
    70857159            for n in xrange(self.degree()):
    7086                 B.append(a)
     7160                B.append(a.lift())
    70877161                a *= z
    7088             self._integral_basis_dict[tuple()] = B
     7162            self._integral_basis_dict[tuple()] = pari(B)
    70897163            return B
    7090 
    7091     def _compute_integral_basis(self, v=None):
    7092         """
    7093         Alias for self.integral_basis().
    7094        
    7095         EXAMPLES::
    7096        
    7097             sage: len(CyclotomicField(137)._compute_integral_basis())
    7098             136
    7099             sage: CyclotomicField(17).integral_basis() == CyclotomicField(17)._compute_integral_basis()
    7100             True
    7101         """
    7102         return self.integral_basis()
    71037164       
    71047165               
    71057166    def zeta_order(self):
     
    73067367        sage: QuadraticField(-4, 'b')
    73077368        Number Field in b with defining polynomial x^2 + 4
    73087369    """
    7309     def __init__(self, polynomial, name=None, latex_name=None, check=True, embedding=None):
     7370    def __init__(self, polynomial, name=None, latex_name=None, check=True, embedding=None,
     7371                 assume_disc_small=False, maximize_at_primes=None):
    73107372        """
    73117373        Create a quadratic number field.
    73127374       
     
    73307392
    73317393            sage: TestSuite(k).run()
    73327394        """
    7333         NumberField_absolute.__init__(self, polynomial, name=name, check=check, embedding=embedding, latex_name=latex_name)
     7395        NumberField_absolute.__init__(self, polynomial, name=name, check=check,
     7396                                      embedding=embedding, latex_name=latex_name,
     7397                                      assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    73347398        self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic
    73357399        c, b, a = [rational.Rational(t) for t in self.defining_polynomial().list()]
    73367400        # set the generator
  • sage/rings/number_field/number_field_ideal_rel.py

    diff -r f282b3777b84 -r 9b1e50c3b390 sage/rings/number_field/number_field_ideal_rel.py
    a b  
    414414            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
    415415            sage: I = K.ideal(3, c)
    416416            sage: J = I.ideal_below(); J
    417             Fractional ideal (-b)
     417            Fractional ideal (b)   # 32-bit
     418            Fractional ideal (-b)  # 64-bit
    418419            sage: J.number_field() == F
    419420            True
    420421        """
     
    592593            sage: I.relative_ramification_index()
    593594            2
    594595            sage: I.ideal_below()
    595             Fractional ideal (b)
     596            Fractional ideal (b)   # 32-bit
     597            Fractional ideal (-b)  # 64-bit
    596598            sage: K.ideal(b) == I^2
    597599            True
    598600        """
  • sage/rings/polynomial/polynomial_quotient_ring.py

    diff -r f282b3777b84 -r 9b1e50c3b390 sage/rings/polynomial/polynomial_quotient_ring.py
    a b  
    689689        `x^2 + 31` from 12 to 2, i.e. we lose a generator of order 6::
    690690       
    691691            sage: S.S_class_group([K.ideal(a)])
    692             [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), 6, 1/16*xbar^3 - 5/16*xbar^2 + 31/16*xbar - 139/16), ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 2, -1/8*xbar^2 - 15/8)]
     692            [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), 6, 1/16*xbar^3 - 5/16*xbar^2 + 31/16*xbar - 139/16), ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 2, -1/8*xbar^2 - 15/8)]  # 32-bit
     693            [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), 6, -1/16*xbar^3 + 1/16*xbar^2 - 31/16*xbar + 47/16), ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 2, -1/8*xbar^2 - 15/8)]  # 64-bit
    693694
    694695        Note that all the returned values live where we expect them to::
    695696       
     
    10691070            sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1)], 3)
    10701071            [2, -a - 1]
    10711072            sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3)
    1072             [2, -a - 1, a]   # 32-bit
    1073             [2, -a - 1, -a]  # 64-bit
     1073            [2, -a - 1, -a]  # 32-bit
     1074            [2, -a - 1, a]   # 64-bit
    10741075
    10751076        """
    10761077        units, clgp_gens = self._S_class_group_and_units(tuple(S), proof=proof)
  • sage/rings/residue_field.pyx

    diff -r f282b3777b84 -r 9b1e50c3b390 sage/rings/residue_field.pyx
    a b  
    1414    841
    1515
    1616We reduce mod a prime for which the ring of integers is not
    17 monogenic (i.e., 2 is an essential discriminant divisor):
     17monogenic (i.e., 2 is an essential discriminant divisor)::
     18
    1819    sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8)
    1920    sage: F = K.factor(2); F
    2021    (Fractional ideal (1/2*a^2 - 1/2*a + 1)) * (Fractional ideal (a^2 - 2*a + 3)) * (Fractional ideal (3/2*a^2 - 5/2*a + 4))
     
    2526    sage: F[2][0].residue_field()
    2627    Residue field of Fractional ideal (3/2*a^2 - 5/2*a + 4)
    2728
    28 We can also form residue fields from ZZ:
     29We can also form residue fields from ZZ::
     30
    2931    sage: ZZ.residue_field(17)
    3032    Residue field of Integers modulo 17
    3133
     
    3537    -- John Cremona (2008-9): extend reduction maps to the whole valuation ring
    3638                              add support for residue fields of ZZ
    3739
    38 TESTS:
     40TESTS::
     41
    3942    sage: K.<z> = CyclotomicField(7)
    4043    sage: P = K.factor(17)[0][0]
    4144    sage: ff = K.residue_field(P)
     
    4346    sage: parent(a*a)
    4447    Residue field in zbar of Fractional ideal (17)
    4548
    46 Reducing a curve modulo a prime:
     49Reducing a curve modulo a prime::
     50
    4751    sage: K.<s> = NumberField(x^2+23)
    4852    sage: OK = K.ring_of_integers()
    4953    sage: E = EllipticCurve([0,0,0,K(1),K(5)])
     
    5256    sage: E.base_extend(Fpp)
    5357    Elliptic Curve defined by y^2  = x^3 + x + 5 over Residue field of Fractional ideal (13, s - 4)
    5458
    55 Calculating Groebner bases over various residue fields.  First over a small non-prime field:
     59Calculating Groebner bases over various residue fields.  First over a small non-prime field::
     60
    5661    sage: F1.<u> = NumberField(x^6 + 6*x^5 + 124*x^4 + 452*x^3 + 4336*x^2 + 8200*x + 42316)
    5762    sage: reduct_id = F1.factor(47)[0][0]
    5863    sage: Rf = F1.residue_field(reduct_id)
     
    6772    sage: I.groebner_basis()
    6873    [X + (-19*ubar^2 - 5*ubar - 17)*Y]
    6974
    70 And now over a large prime field:
     75And now over a large prime field::
     76
    7177    sage: x = ZZ['x'].0
    7278    sage: F1.<u> = NumberField(x^2 + 6*x + 324)
    7379    sage: reduct_id = F1.prime_above(next_prime(2^42))
     
    125131    of the ring of integers of a number field.
    126132
    127133    INPUT:
    128         p -- a prime ideal of an order in a number field.
    129         names -- the variable name for the finite field created.
    130                  Defaults to the name of the number field variable but
    131                  with bar placed after it.
    132         check -- whether or not to check if p is prime.
     134   
     135        - ``p`` -- a prime ideal of an order in a number field.
     136        - ``names`` -- the variable name for the finite field created.
     137          Defaults to the name of the number field variable but with
     138          bar placed after it.
     139        - ``check`` -- whether or not to check if p is prime.
    133140
    134141    OUTPUT:
    135          -- The residue field at the prime p.
     142   
     143         - The residue field at the prime p.
    136144
    137     EXAMPLES:
     145    EXAMPLES::
     146   
    138147        sage: K.<a> = NumberField(x^3-7)
    139148        sage: P = K.ideal(29).factor()[0][0]
    140149        sage: ResidueField(P)
    141150        Residue field in abar of Fractional ideal (2*a^2 + 3*a - 10)
    142151
    143     The result is cached:
     152    The result is cached::
     153   
    144154        sage: ResidueField(P) is ResidueField(P)
    145155        True
    146156        sage: k = K.residue_field(P); k
     
    149159        841
    150160
    151161    An example where the generator of the number field doesn't
    152     generate the residue class field.
     162    generate the residue class field::
     163   
    153164        sage: K.<a> = NumberField(x^3-875)
    154165        sage: P = K.ideal(5).factor()[0][0]; k = K.residue_field(P); k
    155166        Residue field in abar of Fractional ideal (5, -2/25*a^2 - 1/5*a + 2)
     
    158169        sage: k.0^3 - 875
    159170        2
    160171
    161     An example where the residue class field is large but of degree 1:
     172    An example where the residue class field is large but of degree 1::
     173   
    162174        sage: K.<a> = NumberField(x^3-875); P = K.ideal(2007).factor()[0][0]; k = K.residue_field(P); k
    163175        Residue field of Fractional ideal (-2/25*a^2 - 2/5*a - 3)
    164176        sage: k(a)
     
    167179        0
    168180
    169181    In this example, 2 is an inessential discriminant divisor, so divides
    170     the index of ZZ[a] in the maximal order for all a.
     182    the index of ZZ[a] in the maximal order for all a::
     183   
    171184        sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8); P = K.ideal(2).factor()[0][0]; P
    172185        Fractional ideal (1/2*a^2 - 1/2*a + 1)
    173186        sage: F = K.residue_field(P); F
     
    288301    """
    289302    The class representing a generic residue field.
    290303
    291     EXAMPLES:
     304    EXAMPLES::
     305   
    292306        sage: I = QQ[i].factor(2)[0][0]; I
    293307        Fractional ideal (I + 1)
    294308        sage: k = I.residue_field(); k
     
    299313    def __init__(self, p, f, intp):
    300314        """
    301315        INPUT:
    302            p -- the prime (ideal) defining this residue field
    303            f -- the morphism from the order to self.
    304            intp -- the rational prime that p lives over.
     316       
     317           - ``p`` -- the prime (ideal) defining this residue field
     318           - ``f`` -- the morphism from the order to self.
     319           - ``intp`` -- the rational prime that p lives over.
    305320
    306321        EXAMPLES::
    307322
     
    330345        r"""
    331346        Return the maximal ideal that this residue field is the quotient by.
    332347
    333         EXAMPLES:
     348        EXAMPLES::
     349       
    334350            sage: K.<a> = NumberField(x^3 + x + 1)
    335351            sage: P = K.ideal(29).factor()[0][0]
    336352            sage: k = K.residue_field(P) # indirect doctest
     
    346362
    347363    def coerce_map_from_impl(self, R):
    348364        """
    349         EXAMPLES:
     365        EXAMPLES::
     366       
    350367            sage: K.<i> = NumberField(x^2+1)
    351368            sage: P = K.ideal(-3*i-2)
    352369            sage: OK = K.maximal_order()
     
    365382        """
    366383        Returns a string describing this residue field.
    367384
    368         EXAMPLES:
     385        EXAMPLES::
     386       
    369387            sage: K.<a> = NumberField(x^3-7)
    370388            sage: P = K.ideal(29).factor()[0][0]
    371389            sage: k = K.residue_field(P)
     
    384402        Returns a lift of x to the Order, returning a "polynomial" in the
    385403        generator with coefficients between 0 and $p-1$.
    386404
    387         EXAMPLES:
     405        EXAMPLES::
     406       
    388407            sage: K.<a> = NumberField(x^3-7)
    389408            sage: P = K.ideal(29).factor()[0][0]
    390409            sage: k =K.residue_field(P)
     
    406425        Return the partially defined reduction map from the number
    407426        field to this residue class field.
    408427
    409         EXAMPLES:
     428        EXAMPLES::
     429       
    410430            sage: I = QQ[2^(1/3)].factor(2)[0][0]; I
    411431            Fractional ideal (a)
    412432            sage: k = I.residue_field(); k
     
    422442
    423443    def lift_map(self):
    424444        """
    425         EXAMPLES:
     445        EXAMPLES::
     446       
    426447            sage: I = QQ[3^(1/3)].factor(5)[1][0]; I
    427448            Fractional ideal (a - 2)
    428449            sage: k = I.residue_field(); k
     
    443464        Compares two residue fields: they are equal iff the primes
    444465        defining them are equal.
    445466       
    446         EXAMPLES:
     467        EXAMPLES::
     468       
    447469            sage: K.<a> = NumberField(x^3-11)
    448470            sage: F = K.ideal(37).factor(); F
    449             (Fractional ideal (37, a + 12)) * (Fractional ideal (-2*a + 5)) * (Fractional ideal (37, a + 9))  # 32-bit
    450             (Fractional ideal (37, a + 12)) * (Fractional ideal  (2*a - 5)) * (Fractional ideal (37, a + 9))  # 64-bit
     471            (Fractional ideal (37, a + 12)) * (Fractional ideal (2*a - 5)) * (Fractional ideal (37, a + 9))   # 32-bit
     472            (Fractional ideal (37, a + 12)) * (Fractional ideal (-2*a + 5)) * (Fractional ideal (37, a + 9))  # 64-bit
    451473            sage: k = K.residue_field(F[0][0])
    452474            sage: l = K.residue_field(F[1][0])
    453475            sage: k == l
     
    464486        r"""
    465487        Return the hash of self.
    466488
    467         EXAMPLES:
     489        EXAMPLES::
     490       
    468491            sage: K.<a> = NumberField(x^3 + x + 1)
    469492            sage: hash(K.residue_field(K.prime_above(17))) # random
    470493            -6463132282686559142
     
    478501    A reduction map from a (subset) of a number field to this residue
    479502    class field.
    480503
    481     EXAMPLES:
     504    EXAMPLES::
     505       
    482506        sage: I = QQ[sqrt(17)].factor(5)[0][0]; I
    483507        Fractional ideal (5)
    484508        sage: k = I.residue_field(); k
     
    490514        """
    491515        Create a reduction map.
    492516
    493         EXAMPLES:
     517        EXAMPLES::
     518       
    494519            sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8)
    495520            sage: F = K.factor(2)[0][0].residue_field()
    496521            sage: F.reduction_map()
     
    505530        """
    506531        Return the domain of this reduction map.
    507532
    508         EXAMPLES:
     533        EXAMPLES::
     534       
    509535            sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 32)
    510536            sage: F = K.factor(2)[0][0].residue_field()
    511537            sage: F.reduction_map().domain()
     
    517543        """
    518544        Return the codomain of this reduction map.
    519545
    520         EXAMPLES:
     546        EXAMPLES::
     547       
    521548            sage: K.<a> = NumberField(x^3 + 128)
    522549            sage: F = K.factor(2)[0][0].residue_field()
    523550            sage: F.reduction_map().codomain()
     
    532559        If x doesn't map because it has negative valuation, then a
    533560        ZeroDivisionError exception is raised.
    534561
    535         EXAMPLES:
     562        EXAMPLES::
     563       
    536564            sage: K.<a> = NumberField(x^2 + 1)
    537565            sage: F = K.factor(2)[0][0].residue_field()
    538566            sage: r = F.reduction_map(); r
     
    545573            ZeroDivisionError: Cannot reduce field element 1/2*a modulo Fractional ideal (a + 1): it has negative valuation
    546574
    547575        An example to show that the issue raised in trac \#1951
    548         has been fixed.
     576        has been fixed::
     577       
    549578            sage: K.<i> = NumberField(x^2 + 1)
    550579            sage: P1, P2 = [g[0] for g in K.factor(5)]; (P1,P2)
    551580            (Fractional ideal (i + 2), Fractional ideal (-i + 2))
     
    562591            -1
    563592            sage: F2(a)
    564593            Traceback (most recent call last):
     594            ...
    565595            ZeroDivisionError: Cannot reduce field element -2/5*i + 1/5 modulo Fractional ideal (-i + 2): it has negative valuation
    566 
    567596        """
    568597        # The reduction map is just x |--> F(to_vs(x) * (PB**(-1))) if
    569598        # either x is integral or the denominator of x is coprime to
     
    578607            except ZeroDivisionError:
    579608                raise ZeroDivisionError, "Cannot reduce rational %s modulo %s: it has negative valuation"%(x,p)
    580609
    581         dx = x.denominator()
    582         if x.is_integral() or dx.gcd(ZZ(p.absolute_norm())) == 1:
     610        try:
    583611            return self.__F(self.__to_vs(x) * self.__PBinv)
     612        except: pass
    584613
    585614        # Now we do have to work harder...below this point we handle
    586615        # cases which failed before trac 1951 was fixed.
    587616        R = self.__K.ring_of_integers()
    588         dx = R(dx)
     617        dx = R(x.denominator())
    589618        nx = R(dx*x)
    590619        vnx = nx.valuation(p)
    591620        vdx = dx.valuation(p)
     
    593622            return self(0)
    594623        if vnx < vdx:
    595624            raise ZeroDivisionError, "Cannot reduce field element %s modulo %s: it has negative valuation"%(x,p)
     625       
    596626        a = self.__K.uniformizer(p,'negative') ** vnx
    597627        nx /= a
    598628        dx /= a
     
    609639
    610640    def __repr__(self):
    611641        """
    612         EXAMPLES:
     642        EXAMPLES::
     643       
    613644            sage: K.<theta_5> = CyclotomicField(5)
    614645            sage: F = K.factor(7)[0][0].residue_field()
    615646            sage: F.reduction_map().__repr__()
     
    621652    """
    622653    Lifting map from residue class field to number field.
    623654
    624     EXAMPLES:
     655    EXAMPLES::
     656   
    625657        sage: K.<a> = NumberField(x^3 + 2)
    626658        sage: F = K.factor(5)[0][0].residue_field()
    627659        sage: F.degree()
     
    637669        """
    638670        Create a lifting map.
    639671
    640         EXAMPLES:
     672        EXAMPLES::
     673       
    641674            sage: K.<theta_5> = CyclotomicField(5)
    642675            sage: F = K.factor(7)[0][0].residue_field()
    643676            sage: F.lift_map()
     
    666699        """
    667700        Return the codomain of this lifting map.
    668701
    669         EXAMPLES:
     702        EXAMPLES::
     703       
    670704            sage: K.<a> = CyclotomicField(7)
    671705            sage: F = K.factor(5)[0][0].residue_field()
    672706            sage: L = F.lift_map(); L
     
    680714        """
    681715        Lift from this residue class field to the number field.
    682716
    683         EXAMPLES:
     717        EXAMPLES::
     718       
    684719            sage: K.<a> = CyclotomicField(7)
    685720            sage: F = K.factor(5)[0][0].residue_field()
    686721            sage: L = F.lift_map(); L
     
    700735
    701736    def __repr__(self):
    702737        """
    703         EXAMPLES:
     738        EXAMPLES::
     739       
    704740            sage: K.<theta_12> = CyclotomicField(12)
    705741            sage: F.<tmod> = K.factor(7)[0][0].residue_field()
    706742            sage: F.lift_map().__repr__()
     
    716752    The class representing a homomorphism from the order of a number
    717753    field to the residue field at a given prime.
    718754
    719     EXAMPLES:
     755    EXAMPLES::
     756   
    720757        sage: K.<a> = NumberField(x^3-7)
    721758        sage: P  = K.ideal(29).factor()[0][0]
    722759        sage: k  = K.residue_field(P)
     
    738775           im_gen -- The image of the generator of the number field.
    739776
    740777        EXAMPLES:
    741         We create a residue field homomorphism:
     778       
     779        We create a residue field homomorphism::
     780       
    742781            sage: K.<theta> = CyclotomicField(5)
    743782            sage: P = K.factor(7)[0][0]
    744783            sage: P.residue_class_degree()
     
    759798
    760799    cpdef Element _call_(self, x):
    761800        """
    762         Applies this morphism to an element
     801        Applies this morphism to an element.
    763802
    764         EXAMPLES:
     803        EXAMPLES::
     804       
    765805            sage: K.<a> = NumberField(x^3-x+8)
    766806            sage: P = K.ideal(29).factor()[0][0]
    767807            sage: k =K.residue_field(P)
     
    779819        Returns a lift of x to the Order, returning a "polynomial" in
    780820        the generator with coefficients between 0 and p-1.
    781821
    782         EXAMPLES:
     822        EXAMPLES::
     823       
    783824            sage: K.<a> = NumberField(x^3-7)
    784825            sage: P = K.ideal(29).factor()[0][0]
    785826            sage: k = K.residue_field(P)
     
    804845    """
    805846    The class representing residue fields of number fields that have prime order.
    806847
    807     EXAMPLES:
     848    EXAMPLES::
     849   
    808850        sage: R.<x> = QQ[]
    809851        sage: K.<a> = NumberField(x^3-7)
    810852        sage: P = K.ideal(29).factor()[1][0]
     
    828870    def __init__(self, p, name, im_gen = None, intp = None):
    829871        """
    830872        INPUT:
    831            p -- A prime ideal of a number field.
    832            name -- the name of the generator of this extension
    833            im_gen -- the image of the generator of the number field in this finite field.
    834            intp -- the rational prime that p lies over.
     873       
     874           - ``p`` -- A prime ideal of a number field.
     875           - ``name`` -- the name of the generator of this extension
     876           - ``im_gen`` -- the image of the generator of the number field in this finite field.
     877           - ``intp`` -- the rational prime that p lies over.
    835878
    836         EXAMPLES:
     879        EXAMPLES::
     880       
    837881            sage: K.<i> = QuadraticField(-1)
    838882            sage: kk = ResidueField(K.factor(5)[0][0])
    839883            sage: type(kk)
     
    851895    def __call__(self, x):
    852896        """
    853897        INPUT:
    854            x -- something to cast in to self.
     898       
     899           - ``x`` -- something to cast in to self.
    855900
    856         EXAMPLES:
     901        EXAMPLES::
     902       
    857903            sage: R.<x> = QQ[]
    858904            sage: K.<a> = NumberField(x^3-7)
    859905            sage: P = K.ideal(29).factor()[1][0]
     
    881927    """
    882928    The class representing residue fields of number fields that have non-prime order >= 2^16.
    883929
    884     EXAMPLES:
     930    EXAMPLES::
     931   
    885932        sage: K.<a> = NumberField(x^3-7)
    886933        sage: P = K.ideal(923478923).factor()[0][0]
    887934        sage: k = K.residue_field(P)
     
    897944    """
    898945    def __init__(self, p, q, name, g, intp):
    899946        """
    900         EXAMPLES:
    901         We create an ext_pari residue field:
     947        EXAMPLES::
     948       
     949        We create an ext_pari residue field::
     950       
    902951            sage: K.<a> = NumberField(x^3-7)
    903952            sage: P = K.ideal(923478923).factor()[0][0]
    904953            sage: type(P.residue_field())
     
    913962        """
    914963        Coerce x into self.
    915964       
    916         EXAMPLES:
     965        EXAMPLES::
     966       
    917967            sage: K.<aa> = NumberField(x^3 - 2)
    918968            sage: P = K.factor(10007)[0][0]
    919969            sage: P.residue_class_degree()
     
    940990    """
    941991    The class representing residue fields of number fields that have non-prime order < 2**16.
    942992
    943     EXAMPLES:
     993    EXAMPLES::
     994   
    944995        sage: R.<x> = QQ[]
    945996        sage: K.<a> = NumberField(x^3-7)
    946997        sage: P = K.ideal(29).factor()[0][0]
     
    9581009    def __init__(self, p, q, name, g, intp):
    9591010        """
    9601011        INPUT:
    961            p -- the prime ideal defining this residue field
    962            q -- the order of this residue field (a power of intp)
    963            name -- the name of the generator of this extension
    964            g -- the polynomial modulus for this extension
    965            intp -- the rational prime that p lies over.
     1012       
     1013           - ``p`` -- the prime ideal defining this residue field
     1014           - ``q`` -- the order of this residue field (a power of intp)
     1015           - ``name`` -- the name of the generator of this extension
     1016           - ``g`` -- the polynomial modulus for this extension
     1017           - ``intp`` -- the rational prime that p lies over.
    9661018
    967         EXAMPLES:
     1019        EXAMPLES::
     1020       
    9681021            sage: R.<x> = QQ[]
    9691022            sage: K.<a> = NumberField(x^4+3*x^2-17)
    9701023            sage: P = K.ideal(61).factor()[0][0]
     
    9781031    def __call__(self, x):
    9791032        """
    9801033        INPUT:
    981           x -- Something to cast into self.
     1034       
     1035            - x -- Something to cast into self.
    9821036
    983         EXAMPLES:
     1037        EXAMPLES::
     1038       
    9841039            sage: R.<x> = QQ[]
    9851040            sage: K.<a> = NumberField(x^4+3*x^2-17)
    9861041            sage: P = K.ideal(61).factor()[0][0]