Ticket #9400: trac_9400.patch

File trac_9400.patch, 47.3 KB (added by was, 10 years ago)

apply only this patch (which also addresses the referees issue with hash)

  • sage/modular/cusps_nf.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1277963819 25200
    # Node ID d912407af0aee59b9612dfe4b53f288e716c5edd
    # Parent  5a26560c3ceded43f0115375e8a8b97de0a253b1
    trac 9400: modify the NumberField constructor to pass in optional integer B such that all the internal pari routines will replace the discriminant by its gcd with B, making some things massively faster; etc.
    
    diff --git a/sage/modular/cusps_nf.py b/sage/modular/cusps_nf.py
    a b  
    140140        sage: N = k.ideal(713, a + 208)
    141141        sage: L = list_of_representatives(N); L
    142142        (Fractional ideal (1),
    143         Fractional ideal (37, a + 12),
    144         Fractional ideal (47, a - 9))
     143        Fractional ideal (a + 12, 37),
     144        Fractional ideal (a - 9, 47))
    145145
    146146    The output of ``list_of_representatives`` has been cached:
    147147
     
    151151        [Fractional ideal (713, a + 208)]
    152152        sage: sage.modular.cusps_nf._list_reprs_cache[N]
    153153        (Fractional ideal (1),
    154         Fractional ideal (37, a + 12),
    155         Fractional ideal (47, a - 9))
     154        Fractional ideal (a + 12, 37),
     155        Fractional ideal (a - 9, 47))
    156156    """
    157157    if _list_reprs_cache.has_key(N):
    158158        lreps = _list_reprs_cache[N]
     
    12911291    from sage.misc.mrange import xmrange
    12921292    from sage.misc.misc import prod
    12931293
    1294     return [prod([u**e for u,e in zip(ulist,ei)],k(1)) for ei in xmrange(elist)]
    1295  No newline at end of file
     1294    return [prod([u**e for u,e in zip(ulist,ei)],k(1)) for ei in xmrange(elist)]
  • sage/rings/number_field/class_group.py

    diff --git a/sage/rings/number_field/class_group.py b/sage/rings/number_field/class_group.py
    a b  
    162162            sage: G
    163163            Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^4 + 23
    164164            sage: list(G)
    165             [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 + a - 1/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] # 32-bit
    166             [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 - a + 3/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] # 64-bit
     165            [Trivial principal fractional ideal class, Fractional ideal class (a + 1, 1/4*a^3 + 1/4*a^2 + 1/4*a + 1/4, 2, 1/2*a^2 + 1/2), Fractional ideal class (1/4*a^3 + 1/4*a^2 + 5/4*a + 5/4, 2, 2*a, 1/2*a^2 + 1/2)]           
    167166            sage: G.list()
    168             [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 + a - 1/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] # 32-bit
    169             [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 - a + 3/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] # 64-bit
     167            [Trivial principal fractional ideal class, Fractional ideal class (a + 1, 1/4*a^3 + 1/4*a^2 + 1/4*a + 1/4, 2, 1/2*a^2 + 1/2), Fractional ideal class (1/4*a^3 + 1/4*a^2 + 5/4*a + 5/4, 2, 2*a, 1/2*a^2 + 1/2)]
    170168
    171169        TESTS::
    172170
  • sage/rings/number_field/number_field.py

    diff --git a/sage/rings/number_field/number_field.py b/sage/rings/number_field/number_field.py
    a b  
    246246
    247247
    248248_nf_cache = {}
    249 def NumberField(polynomial, name=None, check=True, names=None, cache=True, embedding=None, latex_name=None):
     249def NumberField(polynomial, name=None, check=True, names=None, cache=True,
     250                embedding=None, latex_name=None,
     251                assume_disc_small=False,
     252                maximize_at_primes=None):
    250253    r"""
    251254    Return *the* number field defined by the given irreducible
    252255    polynomial and with variable with the given name. If check is True
     
    255258   
    256259    INPUT:
    257260   
    258     -  ``polynomial`` - a polynomial over `\QQ` or a number
    259        field, or a list of polynomials.
    260     -  ``name`` - a string (default: 'a'), the name of the
    261        generator
    262     -  ``check`` - bool (default: True); do type checking
    263        and irreducibility checking.
    264     -  ``embedding`` - image of the generator in an ambient
    265        field (default: None)
     261        - ``polynomial`` - a polynomial over `\QQ` or a number field,
     262          or a list of polynomials.
     263        - ``name`` - a string (default: 'a'), the name of the generator
     264        - ``check`` - bool (default: True); do type checking and
     265          irreducibility checking.
     266        - ``embedding`` - image of the generator in an ambient field
     267          (default: None)
     268        - ``assume_disc_small`` -- (default: False); if True, assume
     269          that no square of a prime greater than PARI's primelimit
     270          (which should be 500000); only applies for absolute fields
     271          at present.
     272        - ``maximize_at_primes`` -- (default: None) None or a list of
     273          primes; if not None, then the maximal order is computed by
     274          maximizing only at the primes in this list, which completely
     275          avoids having to factor the discriminant, but of course can
     276          lead to wrong results; only applies for absolute fields at
     277          present.
    266278   
    267279    EXAMPLES::
    268280   
     
    452464
    453465    if cache:
    454466        key = (polynomial, polynomial.base_ring(), name, latex_name,
    455                embedding, embedding.parent() if embedding is not None else None)
     467               embedding, embedding.parent() if embedding is not None else None,
     468               assume_disc_small, None if maximize_at_primes is None else tuple(maximize_at_primes))
    456469        if _nf_cache.has_key(key):
    457470            K = _nf_cache[key]()
    458471            if not K is None: return K
     
    464477        return S
    465478
    466479    if polynomial.degree() == 2:
    467         K = NumberField_quadratic(polynomial, name, latex_name, check, embedding)
     480        K = NumberField_quadratic(polynomial, name, latex_name, check, embedding,
     481             assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    468482    else:
    469         K = NumberField_absolute(polynomial, name, latex_name, check, embedding)
     483        K = NumberField_absolute(polynomial, name, latex_name, check, embedding,
     484             assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    470485
    471486    if cache:
    472487        _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)
     
    24142431            Traceback (most recent call last):
    24152432            ...
    24162433            TypeError: Unable to coerce number field defined by non-integral polynomial to PARI.
     2434
     2435        We illustrate the maximize_at_primes and assume_disc_small parameters::
     2436       
     2437            sage: p = next_prime(10^40); q = next_prime(p)
     2438            sage: K.<a> = NumberField(x^2 - p*q, maximize_at_primes=[p])
     2439
     2440        The following would take a very long time without the
     2441        maximize_at_primes option above::
     2442       
     2443            sage: K.pari_nf()
     2444            [x^2 - 100000000000000000000...]
     2445
     2446        I'm not sure this really illustrates anything::
     2447       
     2448            sage: K.<a> = NumberField(x^2 - 3*5*7*11*13, assume_disc_small=True)
     2449            sage: K.pari_nf()
     2450            [x^2 - 15015, [2, 0], 60060, 1, ...]
    24172451        """
    24182452        if self.absolute_polynomial().denominator() != 1:
    24192453            raise TypeError, "Unable to coerce number field defined by non-integral polynomial to PARI."
     
    24212455            return self.__pari_nf
    24222456        except AttributeError:
    24232457            f = self.pari_polynomial()
    2424             self.__pari_nf = f.nfinit()
     2458            if self._maximize_at_primes:
     2459                v = self._normalize_prime_list(self._maximize_at_primes)
     2460                m = self._pari_disc_factorization_matrix(v)
     2461                s = str(f)
     2462                # we use a string since the Sage wrapping of the pari
     2463                # c library nfinit doesn't support the third option.
     2464                k = pari('nfinit([%s,nfbasis(%s,0,%s)])'%(s,s,str(m)))
     2465            elif self._assume_disc_small:
     2466                k = f.nfinit(1)
     2467            else:
     2468                k = f.nfinit()
     2469            self.__pari_nf = k
    24252470            return self.__pari_nf
    24262471
    24272472    def _pari_init_(self):
     
    24402485            [x^2 + x + 1, [0, 1], -3, 1, ... [1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]]
    24412486            sage: pari(k)
    24422487            [x^2 + x + 1, [0, 1], -3, 1, ...[1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]]
    2443         """
     2488
     2489        We illustrate the maximize_at_primes parameter::
     2490       
     2491            sage: p = next_prime(10^40); q = next_prime(p)
     2492            sage: K.<a> = NumberField(x^2 - p*q, maximize_at_primes=[p,q])
     2493
     2494        Note that nfbasis is explicitly passed in::
     2495       
     2496            sage: K._pari_init_()
     2497            'nfinit(x^2 - 100000000000000000000000000000000000002600000000000000000000000000000000000016819,nfbasis(x^2 - 100000000000000000000000000000000000002600000000000000000000000000000000000016819,0,[10000000000000000000000000000000000000121, 1; 10000000000000000000000000000000000000139, 1]))'
     2498
     2499
     2500        We illustrate the assume_disc_small parameter (note the 1 option to nfinit)::
     2501       
     2502            sage: K.<a> = NumberField(x^2 - 3*5*7*11*13, assume_disc_small=True)
     2503            sage: K._pari_init_()
     2504            'nfinit(x^2 - 15015,1)'
     2505        """
     2506        f = str(self.pari_polynomial())
    24442507        if self.absolute_polynomial().denominator() != 1:
    24452508            raise TypeError, "Unable to coerce number field defined by non-integral polynomial to PARI."
    2446         return 'nfinit(%s)'%self.pari_polynomial()
    2447 
     2509        if self._maximize_at_primes:
     2510            v = self._normalize_prime_list(self._maximize_at_primes)
     2511            m = self._pari_disc_factorization_matrix(v)
     2512            return 'nfinit(%s,nfbasis(%s,0,%s))'%(f,f,str(m))
     2513        elif self._assume_disc_small:
     2514            return 'nfinit(%s,1)'%f
     2515        else:
     2516            return 'nfinit(%s)'%f
     2517           
    24482518    def pari_bnf(self, certify=False, units=True):
    24492519        """
    24502520        PARI big number field corresponding to this field.
     
    36683738       
    36693739        ALGORITHM: Uses the pari library.
    36703740        """
    3671         return self.maximal_order().basis()
     3741        return self.maximal_order(v=v).basis()
    36723742   
    36733743    def _compute_integral_basis(self, v=None):
    36743744        """
     
    37033773            sage: K.integral_basis()
    37043774            [1, 1/2*a^2 + 1/2*a, a^2]
    37053775        """
     3776        if (v is None or len(v) == 0) and self._maximize_at_primes:
     3777            v = self._maximize_at_primes
     3778               
    37063779        v = self._normalize_prime_list(v)
    37073780        try:
    37083781            return self._integral_basis_dict[v]
    37093782        except:
    37103783            f = self.pari_polynomial()
    3711 
    37123784            if len(v) == 0:
    3713                 B = f.nfbasis()
    3714             else:
    3715                 m = pari.matrix(len(v), 2)
    3716                 d = f.poldisc()
    3717                 for i in range(len(v)):
    3718                     p = pari(ZZ(v[i]))
    3719                     m[i,0] = p
    3720                     m[i,1] = d.valuation(p)
     3785                B = f.nfbasis(1 if self._assume_disc_small else 0)
     3786            else:
     3787                m = self._pari_disc_factorization_matrix(v)
    37213788                B = f.nfbasis(p = m)
    37223789
    37233790            basis = map(self, B)
    37243791            self._integral_basis_dict[v] = basis
    37253792            return basis
    37263793
     3794    def _pari_disc_factorization_matrix(self, v):
     3795        """
     3796        Returns a PARI matrix representation for the partial
     3797        factorization of the discriminant of the defining polynomial
     3798        of self, defined by the list of primes in the Python list v.
     3799        This function is used internally by the number fields code.
     3800       
     3801        EXAMPLES::
     3802
     3803            sage: x = polygen(QQ,'x')
     3804            sage: f = x^3 + 17*x + 393; f.discriminant().factor()
     3805            -1 * 5^2 * 29 * 5779
     3806            sage: K.<a> = NumberField(f)
     3807            sage: K._pari_disc_factorization_matrix([5,29])
     3808            [5, 2; 29, 1]
     3809        """
     3810        f = self.pari_polynomial()
     3811        m = pari.matrix(len(v), 2)
     3812        d = f.poldisc()
     3813        for i in range(len(v)):
     3814            p = pari(ZZ(v[i]))
     3815            m[i,0] = p
     3816            m[i,1] = d.valuation(p)
     3817        return m
     3818       
     3819
    37273820    def reduced_basis(self, prec=None):
    37283821        r"""
    37293822        This function returns an LLL-reduced basis for the
     
    42484341            sage: K.<a> = NumberField(x^4+3*x^2-17)
    42494342            sage: P = K.ideal(61).factor()[0][0]
    42504343            sage: K.residue_field(P)
    4251             Residue field in abar of Fractional ideal (-2*a^2 + 1)
     4344            Residue field in abar of Fractional ideal (a^2 + 30, 61)
    42524345       
    42534346        ::
    42544347       
     
    42624355            sage: L.residue_field(P)
    42634356            Traceback (most recent call last):
    42644357            ...
    4265             ValueError: Fractional ideal (-2*a^2 + 1) is not an ideal of Number Field in b with defining polynomial x^2 + 5
     4358            ValueError: Fractional ideal (a^2 + 30, 61) is not an ideal of Number Field in b with defining polynomial x^2 + 5
    42664359            sage: L.residue_field(2)
    42674360            Traceback (most recent call last):
    42684361            ...
     
    47464839
    47474840class NumberField_absolute(NumberField_generic):
    47484841
    4749     def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None):
     4842    def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None,
     4843                 assume_disc_small=False, maximize_at_primes=None):
    47504844        """
    47514845        Function to initialize an absolute number field.
    47524846
     
    47584852            <class 'sage.rings.number_field.number_field.NumberField_absolute_with_category'>
    47594853            sage: TestSuite(K).run()
    47604854        """
    4761         NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding)
     4855        NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding,
     4856                                     assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    47624857        self._element_class = number_field_element.NumberFieldElement_absolute
    47634858        self._zero_element = self(0)
    47644859        self._one_element =  self(1)
     
    63456440        sage: type(cf3(z1))
    63466441        <type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'>
    63476442    """
    6348     def __init__(self, n, names, embedding=None):
     6443    def __init__(self, n, names, embedding=None, assume_disc_small=False, maximize_at_primes=None):
    63496444        """
    63506445        A cyclotomic field, i.e., a field obtained by adjoining an n-th
    63516446        root of unity to the rational numbers.
     
    63766471                                      name= names,
    63776472                                      latex_name=latex_name,
    63786473                                      check=False,
    6379                                       embedding = embedding)
     6474                                      embedding = embedding,
     6475                                      assume_disc_small=assume_disc_small,
     6476                                      maximize_at_primes=maximize_at_primes)
    63806477        if n%2:
    63816478            self.__zeta_order = 2*n
    63826479        else:
     
    71637260            sage: CyclotomicField(17).integral_basis() == CyclotomicField(17)._compute_integral_basis()
    71647261            True
    71657262        """
    7166         return self.integral_basis()
     7263        return self.integral_basis(v=v)
    71677264       
    71687265               
    71697266    def zeta_order(self):
     
    73707467        sage: QuadraticField(-4, 'b')
    73717468        Number Field in b with defining polynomial x^2 + 4
    73727469    """
    7373     def __init__(self, polynomial, name=None, latex_name=None, check=True, embedding=None):
     7470    def __init__(self, polynomial, name=None, latex_name=None, check=True, embedding=None,
     7471                 assume_disc_small=False, maximize_at_primes=None):
    73747472        """
    73757473        Create a quadratic number field.
    73767474       
     
    73947492
    73957493            sage: TestSuite(k).run()
    73967494        """
    7397         NumberField_absolute.__init__(self, polynomial, name=name, check=check, embedding=embedding, latex_name=latex_name)
     7495        NumberField_absolute.__init__(self, polynomial, name=name, check=check,
     7496                                      embedding=embedding, latex_name=latex_name,
     7497                                      assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    73987498        self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic
    73997499        c, b, a = [rational.Rational(t) for t in self.defining_polynomial().list()]
    74007500        # set the generator
  • sage/rings/number_field/number_field_ideal.py

    diff --git a/sage/rings/number_field/number_field_ideal.py b/sage/rings/number_field/number_field_ideal.py
    a b  
    3636#                  http://www.gnu.org/licenses/
    3737#*****************************************************************************
    3838
     39SMALL_DISC = 1000000
     40
    3941import operator
    4042
    4143import sage.misc.latex as latex
     
    178180        if len(gens)==0:
    179181            raise ValueError, "gens must have length at least 1 (zero ideal is not a fractional ideal)"
    180182        Ideal_generic.__init__(self, field, gens, coerce)
     183
     184    def __hash__(self):
     185        """
     186        EXAMPLES::
     187
     188            sage: NumberField(x^2 + 1, 'a').ideal(7).__hash__()
     189            7225361069995395753                  # 64-bit
     190            -1895626071                          # 32-bit
     191        """
     192        try: return self._hash
     193        # At some point in the future (e.g., for relative extensions), we'll likely
     194        # have to consider other hashes, like the following.
     195        #except AttributeError: self._hash = hash(self.gens())
     196        except AttributeError: self._hash = self.pari_hnf().__hash__()
     197        return self._hash
    181198       
    182199    def _latex_(self):
    183200        """
     
    188205            '\\left(2, \\frac{1}{2} a - \\frac{1}{2}\\right)'
    189206            sage: latex(K.ideal([2, 1/2*a - 1/2]))
    190207            \left(2, \frac{1}{2} a - \frac{1}{2}\right)
     208
     209        The gens are reduced only if the norm of the discriminant of
     210        the defining polynomial is at most
     211        sage.rings.number_field.number_field_ideal.SMALL_DISC::
     212
     213            sage: K.<a> = NumberField(x^2 + 902384092834); K
     214            Number Field in a with defining polynomial x^2 + 902384092834
     215            sage: I = K.factor(19)[0][0]; I._latex_()
     216            '\\left(19\\right)'
     217
     218        We can make the generators reduced by increasing SMALL_DISC.
     219        We had better also set proof to False, or computing reduced
     220        gens could take too long::
     221       
     222            sage: proof.number_field(False)
     223            sage: sage.rings.number_field.number_field_ideal.SMALL_DISC = 10^20
     224            sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
     225            sage: K.ideal([17*a,17,17,17*a])._latex_()
     226            '\\left(17\\right)'
    191227        """
    192         return '\\left(%s\\right)'%(", ".join(map(latex.latex, self.gens_reduced())))
     228        return '\\left(%s\\right)'%(", ".join(map(latex.latex, self._gens_repr())))
    193229       
    194230    def __cmp__(self, other):
    195231        """
     
    363399
    364400    def _repr_short(self):
    365401        """
    366         Efficient string representation of this fraction ideal.
     402        Compact string representation of this fraction ideal.  When
     403        the norm of the discriminant of the defining polynomial of the
     404        number field is less than
     405
     406            sage.rings.number_field.number_field_ideal.SMALL_DISC
     407           
     408        then display reduced generators.  Otherwise just display generators.
    367409
    368410        EXAMPLES::
    369411
     
    372414            sage: I = K.factor(17)[0][0]; I
    373415            Fractional ideal (17, a^2 - 6)
    374416            sage: I._repr_short()
    375             '(17, a^2 - 6)'       
     417            '(17, a^2 - 6)'
     418
     419        We use reduced gens, because the discriminant is small::
     420       
     421            sage: K.<a> = NumberField(x^2 + 17); K
     422            Number Field in a with defining polynomial x^2 + 17
     423            sage: I = K.factor(17)[0][0]; I
     424            Fractional ideal (a)
     425
     426        Here the discriminant is 'large', so the gens aren't reduced::
     427
     428            sage: sage.rings.number_field.number_field_ideal.SMALL_DISC
     429            1000000
     430            sage: K.<a> = NumberField(x^2 + 902384094); K
     431            Number Field in a with defining polynomial x^2 + 902384094
     432            sage: I = K.factor(19)[0][0]; I
     433            Fractional ideal (19, a + 14)
     434            sage: I.gens_reduced()                 # long time
     435            (19, a - 5)
    376436        """
    377         #NOTE -- we will *have* to not reduce the gens soon, since this
    378         # makes things insanely slow in general.
    379         # When I fix this, I *have* to also change the _latex_ method.
    380         return '(%s)'%(', '.join(map(str, self.gens_reduced())))
    381 #         return '(%s)'%(', '.join(map(str, self.gens())))
     437        return '(%s)'%(', '.join(map(str, self._gens_repr())))
     438
     439    def _gens_repr(self):
     440        """
     441        Returns tuple of generators to be used for printing this
     442        number field idea.  The gens are reduced only if the absolute
     443        value of the norm of the discriminant of the defining
     444        polynomial is at most
     445        sage.rings.number_field.number_field_ideal.SMALL_DISC.
     446       
     447        EXAMPLES::
     448
     449            sage: sage.rings.number_field.number_field_ideal.SMALL_DISC
     450            1000000
     451           
     452           
     453            sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
     454            sage: K.discriminant()  # too big
     455            -1612688
     456            sage: I = K.ideal([17*a,17,17,17*a]); I._gens_repr()
     457            (17, 17*a)
     458            sage: I.gens_reduced()
     459            (17,)
     460        """
     461        # Small discriminant is easy to find nice gens -- otherwise it
     462        # is potentially very hard
     463        try:
     464            if abs(self.number_field().defining_polynomial().discriminant().norm()) <= SMALL_DISC:
     465                return self.gens_reduced()
     466        except TypeError:
     467            # In some cases with relative extensions, computing the
     468            # discriminant of the defining polynomial is not
     469            # supported.
     470            pass
     471        # Return unique sorted generators.  This eliminates the common case
     472        # where self.gens() is something like (17, 17), which looks silly.
     473        return tuple(sorted(set(self.gens())))
     474       
    382475
    383476    def _pari_(self):
    384477        """
     
    12941387            sage: K.<a> = CyclotomicField(11); K
    12951388            Cyclotomic Field of order 11 and degree 10
    12961389            sage: I = K.factor(31)[0][0]; I
    1297             Fractional ideal (-3*a^7 - 4*a^5 - 3*a^4 - 3*a^2 - 3*a - 3)
     1390            Fractional ideal (a^5 + 10*a^4 - a^3 + a^2 + 9*a - 1, 31)
    12981391            sage: I.divides(I)
    12991392            True
    13001393            sage: I.divides(31)
     
    13171410            sage: I = K.ideal(19); I
    13181411            Fractional ideal (19)
    13191412            sage: F = I.factor(); F
    1320             (Fractional ideal (a^2 + 2*a + 2)) * (Fractional ideal (a^2 - 2*a + 2))
     1413            (Fractional ideal (a^2 + 2*a + 2, 19)) * (Fractional ideal (19, a^2 - 2*a + 2))           
    13211414            sage: type(F)
    13221415            <class 'sage.structure.factorization.Factorization'>
    13231416            sage: list(F)
    1324             [(Fractional ideal (a^2 + 2*a + 2), 1), (Fractional ideal (a^2 - 2*a + 2), 1)]
     1417            [(Fractional ideal (a^2 + 2*a + 2, 19), 1), (Fractional ideal (19, a^2 - 2*a + 2), 1)]
    13251418            sage: F.prod()
    1326             Fractional ideal (19)
     1419            Fractional ideal (19*a^2 + 38*a + 38, 361, 19*a^2 - 38*a + 38, -19)
    13271420        """
    13281421        try:
    13291422            return self.__factorization
  • sage/rings/number_field/order.py

    diff --git a/sage/rings/number_field/order.py b/sage/rings/number_field/order.py
    a b  
    673673            sage: P = K.ideal(61).factor()[0][0]
    674674            sage: OK = K.maximal_order()
    675675            sage: OK.residue_field(P)
    676             Residue field in abar of Fractional ideal (-2*a^2 + 1)
     676            Residue field in abar of Fractional ideal (a^2 + 30, 61)
    677677        """
    678678        if self.is_maximal():
    679679            return self.number_field().residue_field(prime, name, check)
  • sage/rings/number_field/small_primes_of_degree_one.py

    diff --git a/sage/rings/number_field/small_primes_of_degree_one.py b/sage/rings/number_field/small_primes_of_degree_one.py
    a b  
    4646EXAMPLES::
    4747
    4848    sage: x = ZZ['x'].gen()
    49     sage: F.<a> = NumberField(x^2 - 2, 'a')
     49    sage: F.<a> = NumberField(x^2 - 2)
    5050    sage: Ps = F.primes_of_degree_one_list(3)
    5151    sage: Ps # random
    5252    [Fractional ideal (2*a + 1), Fractional ideal (-3*a + 1), Fractional ideal (-a + 5)]
     
    5959
    6060The next two examples are for relative number fields.::
    6161
    62     sage: L.<b> = F.extension(x^3 - a, 'b')
     62    sage: L.<b> = F.extension(x^3 - a)
    6363    sage: Ps = L.primes_of_degree_one_list(3)
    6464    sage: Ps # random
    6565    [Fractional ideal (17, b - 5), Fractional ideal (23, b - 4), Fractional ideal (31, b - 2)]
     
    6969    True
    7070    sage: all(P.residue_class_degree() == 1 for P in Ps)
    7171    True
    72     sage: M.<c> = NumberField(x^2 - x*b^2 + b, 'c')
     72    sage: M.<c> = NumberField(x^2 - x*b^2 + b)
    7373    sage: Ps = M.primes_of_degree_one_list(3)
    7474    sage: Ps # random
    7575    [Fractional ideal (17, c - 2), Fractional ideal (c - 1), Fractional ideal (41, c + 15)]
  • sage/rings/polynomial/polynomial_quotient_ring.py

    diff --git a/sage/rings/polynomial/polynomial_quotient_ring.py b/sage/rings/polynomial/polynomial_quotient_ring.py
    a b  
    888888             ((...1/3*a - 1)*b^2 + ...*b + ...*a + ..., +Infinity),
    889889             ((...1/3*a + 1)*b^2 ...*b ...*a ..., +Infinity)]
    890890            sage: L.S_units([K.ideal(1/2*a - 3/2)])
    891             [((...1/6*a - 1/2)*b^2 + (...1/3*a + 1)*b ... 2/3*a - 2, +Infinity),
    892              (-1/2*a + 1/2, 6),
    893              ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity),
    894              ((...1/3*a ... 1)*b^2 + (...2/3*a - 2)*b + ...*a + ..., +Infinity)]
     891            [(1/3*a*b^2 - 2/3*a*b + 4/3*a, +Infinity), (-1/2*a + 1/2, 6),
     892             ((-1/3*a - 1)*b^2 + (2/3*a - 2)*b + 13/6*a + 1/2, +Infinity),
     893             ((-1/3*a + 1)*b^2 - 4/3*a*b - 4/3*a - 3, +Infinity)]
    895894            sage: L.S_units([K.ideal(2)])
    896             [((...*a ... 1/2)*b^2 + (...a ... 1)*b + ...*a ... 3/2, +Infinity),
     895            [((-1/2*a - 1/2)*b^2 + (a + 1)*b - 3/2*a - 3/2, +Infinity),
    897896             ((1/6*a + 1/2)*b^2 + (-1/3*a - 1)*b + 1/6*a + 3/2, +Infinity),
    898              ((...*a + 1/2)*b^2 + (...a - 1)*b ...*a + ..., +Infinity),
    899              (-1/2*a + 1/2, 6),
    900              ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity),
    901              ((-1/3*a + 1)*b^2 - 4/3*a*b - 4/3*a - 3, +Infinity)]   
     897             ((1/6*a + 1/2)*b^2 + (-1/3*a - 1)*b + 2/3*a + 1, +Infinity),
     898              (-1/2*a + 1/2, 6), ((-1/3*a - 1)*b^2 + (2/3*a - 2)*b + 13/6*a + 1/2, +Infinity),
     899              ((-1/3*a + 1)*b^2 - 4/3*a*b - 4/3*a - 3, +Infinity)]
    902900
    903901        Note that all the returned values live where we expect them to::
    904902       
     
    948946            sage: L.<b> = K['y'].quotient(y^3 + 5); L
    949947            Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with modulus y^3 + 5
    950948            sage: L.units()
    951             [(-1/2*a + 1/2, 6),
    952              ((...1/3*a - 1)*b^2 + ...*b + ...*a + ..., +Infinity),
     949            [(-1/2*a + 1/2, 6), (2/3*a*b^2 + (2/3*a + 2)*b - 4/3*a + 3, +Infinity),
    953950             ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity)]
    954951            sage: L.<b> = K.extension(y^3 + 5)
    955952            sage: L.unit_group()
    956953            Unit group with structure C6 x Z x Z of Number Field in b with defining polynomial x^3 + 5 over its base field
    957954            sage: L.unit_group().gens()
    958             [-1/2*a + 1/2,
    959              (...1/3*a - 1)*b^2 + ...*b + ...*a + ...,
    960              (-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2]
     955            [-1/2*a + 1/2, (1/3*a + 1)*b^2 + (-2/3*a - 2)*b + 4/3*a + 3,
     956             (1/3*a + 1)*b^2 + (-2/3*a - 2)*b + 5/6*a + 7/2]
    961957
    962958        Note that all the returned values live where we expect them to::
    963959       
     
    11391135            sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1)], 3)
    11401136            [2, -a - 1]
    11411137            sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3)
    1142             [2, -a - 1, -a]
     1138            [2, -a - 1, a]
    11431139
    11441140        """
    11451141        units, clgp_gens = self._S_class_group_and_units(tuple(S), proof=proof)
  • sage/rings/residue_field.pyx

    diff --git a/sage/rings/residue_field.pyx b/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)
     
    6368    sage: R.<X, Y> = PolynomialRing(Rf)
    6469    sage: ubar = Rf(u)
    6570    sage: I = ideal([ubar*X + Y]); I
    66     Ideal ((ubar)*X + Y) of Multivariate Polynomial Ring in X, Y over Residue field in ubar of Fractional ideal (47, 517/55860*u^5 + 235/3724*u^4 + 9829/13965*u^3 + 54106/13965*u^2 + 64517/27930*u + 755696/13965)
     71    Ideal ((ubar)*X + Y) of Multivariate Polynomial Ring in X, Y over Residue field in ubar of Fractional ideal (u^3 - 22*u^2 - 9*u + 5, 47)
    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
    155         Residue field in abar of Fractional ideal (5, -2/25*a^2 - 1/5*a + 2)
     166        Residue field in abar of Fractional ideal (-2/25*a^2 - 1/5*a + 2, 5)
    156167        sage: k.polynomial()
    157168        abar^2 + 3*abar + 4
    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
    163         Residue field of Fractional ideal (-2/25*a^2 - 2/5*a - 3)
     175        Residue field of Fractional ideal (a + 55, 223)
    164176        sage: k(a)
    165177        168
    166178        sage: k(a)^3 - 875
    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
    449471            (Fractional ideal (37, a + 12)) * (Fractional ideal (-2*a + 5)) * (Fractional ideal (37, a + 9))
     
    463485        r"""
    464486        Return the hash of self.
    465487
    466         EXAMPLES:
     488        EXAMPLES::
     489       
    467490            sage: K.<a> = NumberField(x^3 + x + 1)
    468491            sage: hash(K.residue_field(K.prime_above(17))) # random
    469492            -6463132282686559142
     
    477500    A reduction map from a (subset) of a number field to this residue
    478501    class field.
    479502
    480     EXAMPLES:
     503    EXAMPLES::
     504       
    481505        sage: I = QQ[sqrt(17)].factor(5)[0][0]; I
    482506        Fractional ideal (5)
    483507        sage: k = I.residue_field(); k
     
    489513        """
    490514        Create a reduction map.
    491515
    492         EXAMPLES:
     516        EXAMPLES::
     517       
    493518            sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8)
    494519            sage: F = K.factor(2)[0][0].residue_field()
    495520            sage: F.reduction_map()
     
    504529        """
    505530        Return the domain of this reduction map.
    506531
    507         EXAMPLES:
     532        EXAMPLES::
     533       
    508534            sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 32)
    509535            sage: F = K.factor(2)[0][0].residue_field()
    510536            sage: F.reduction_map().domain()
     
    516542        """
    517543        Return the codomain of this reduction map.
    518544
    519         EXAMPLES:
     545        EXAMPLES::
     546       
    520547            sage: K.<a> = NumberField(x^3 + 128)
    521548            sage: F = K.factor(2)[0][0].residue_field()
    522549            sage: F.reduction_map().codomain()
     
    531558        If x doesn't map because it has negative valuation, then a
    532559        ZeroDivisionError exception is raised.
    533560
    534         EXAMPLES:
     561        EXAMPLES::
     562       
    535563            sage: K.<a> = NumberField(x^2 + 1)
    536564            sage: F = K.factor(2)[0][0].residue_field()
    537565            sage: r = F.reduction_map(); r
     
    544572            ZeroDivisionError: Cannot reduce field element 1/2*a modulo Fractional ideal (a + 1): it has negative valuation
    545573
    546574        An example to show that the issue raised in trac \#1951
    547         has been fixed.
     575        has been fixed::
     576       
    548577            sage: K.<i> = NumberField(x^2 + 1)
    549578            sage: P1, P2 = [g[0] for g in K.factor(5)]; (P1,P2)
    550579            (Fractional ideal (-i - 2), Fractional ideal (2*i + 1))
     
    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 (2*i + 1): 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]