Ticket #5508: sage-5508.3.patch

File sage-5508.3.patch, 64.1 KB (added by Francis Clarke, 14 years ago)

Replaces previous

  • doc/en/bordeaux_2008/nf_orders.rst

    # HG changeset patch
    # User Francis Clarke <F.Clarke@Swansea.ac.uk>
    # Date 1236943296 0
    # Node ID ed260fded06c7139ad01edca65fa64d77960563b
    # Parent  09a04286d37cf94dab260a3a3e3ea7b678312c41
    Improved relative number fields
    
    diff -r 09a04286d37c -r ed260fded06c doc/en/bordeaux_2008/nf_orders.rst
    a b  
    135135Sage, we do this by typing ``R.<X> = K[]``. Here ``R.<X>`` means
    136136"create the object :math:`R` with generator :math:`X`" and ``K[]``
    137137means a "polynomial ring over :math:`K`", where the generator is named
    138 based on the afformentioned :math:`X` (to create a polynomial ring in
     138based on the aformentioned :math:`X` (to create a polynomial ring in
    139139two variables :math:`X,Y` simply replace ``R.<X>`` by ``R.<X,Y>``).
    140140
    141141.. link
     
    180180-----------------------------------
    181181
    182182The relative number field :math:`L` also has numerous functions, many
    183 of which are by default relative. For example the ``degree`` function
    184 on :math:`L` returns the relative degree of :math:`L` over :math:`K`;
    185 for the degree of :math:`L` over :math:`\mathbb{Q}` use the
    186 ``absolute_degree`` function.
     183of which have both relative and absolute version. For example the
     184``relative_degree`` function on :math:`L` returns the relative degree
     185of :math:`L` over :math:`K`; the degree of :math:`L` over
     186:math:`\mathbb{Q}` is given by the ``absolute_degree`` function.  To
     187avoid possible ambiguity ``degree`` is not implemented for relative
     188number fields.
    187189
    188190.. link
    189191
    190192::
    191193
    192     sage: L.degree()
     194    sage: L.relative_degree()
    193195    3
    194196    sage: L.absolute_degree()
    195197    6
     
    260262defining polynomial, and in some cases this can be very slow (much
    261263slower than Magma). Perhaps this could be fixed by using Singular's
    262264multivariate polynomials modulo an appropriate ideal, since
    263 Singular polynomial arithmetic is extremely flast. Also, Sage has
     265Singular polynomial arithmetic is extremely fast. Also, Sage has
    264266very little direct support for constructive class field theory,
    265267which is a major motivation for explicit computation with relative
    266268orders; it would be good to expose more of Pari's functionality in
  • sage/rings/number_field/all.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/all.py
    a b  
    11from number_field_base import is_NumberField
    22
    3 from number_field import (NumberField, CyclotomicField, QuadraticField,
     3from number_field import (NumberField, NumberFieldTower, CyclotomicField, QuadraticField,
    44                          is_CyclotomicField, is_QuadraticField,
    55                          is_AbsoluteNumberField,
    66                          is_fundamental_discriminant)
  • sage/rings/number_field/class_group.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/class_group.py
    a b  
    301301        Return generators for a representative ideal in this
    302302        ideal class.
    303303
    304         EXAMPLE:
     304        EXAMPLES:
    305305        sage: K.<w>=QuadraticField(-23)
    306306        sage: OK=K.ring_of_integers()
    307307        sage: C=OK.class_group()
  • sage/rings/number_field/maps.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/maps.py
    a b  
    4545
    4646class NumberFieldIsomorphism(Map):
    4747    r"""
    48     A base class for various isomorphisms betweeen number fields and
     48    A base class for various isomorphisms between number fields and
    4949    vector spaces.
    5050    """
    5151    def _repr_type(self):
     
    145145        sage: L.<b> = NumberField(x^4 + 3*x^2 + 1)
    146146        sage: K = L.relativize(L.subfields(2)[0][1], 'a'); K
    147147        Number Field in a0 with defining polynomial x^2 - b0*x + 1 over its base field
    148         sage: V, fr, to = K.vector_space()
     148        sage: V, fr, to = K.relative_vector_space()
    149149        sage: V
    150150        Vector space of dimension 2 over Number Field in b0 with defining polynomial x^2 + 1
    151151        sage: fr
     
    206206        self.__K = K
    207207        self.__rnf = K.pari_rnf()
    208208        self.__zero = QQ(0)
    209         self.__n = K.degree()
     209        self.__n = K.relative_degree()
    210210        self.__x = pari('x')
    211211        self.__y = pari('y')
    212212        self.__B = K.absolute_base_field()
     
    218218        alpha = self.__K(alpha)
    219219        f = alpha.polynomial('x')
    220220        # f is the absolute polynomial that defines this number field element
    221         if self.__K.degree() == 1:
     221        if self.__K.relative_degree() == 1:
    222222            # Pari doesn't return a valid relative polynomial from an
    223223            # absolute one in the case of relative degree one. (Bug
    224224            # submitted to Pari, fixed in svn unstable as of 1/22/08
  • sage/rings/number_field/number_field.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/number_field.py
    a b  
    943943        elif isinstance(x, (tuple, list)) or \
    944944                (isinstance(x, sage.modules.free_module_element.FreeModuleElement) and
    945945                 self.base_ring().has_coerce_map_from(x.parent().base_ring())):
    946             if len(x) != self.degree():
     946            if len(x) != self.relative_degree():
    947947                raise ValueError, "Length must be equal to the degree of this number field"
    948             return sum([ x[i]*self.gen(0)**i for i in range(self.degree()) ])
     948            return sum([ x[i]*self.gen(0)**i for i in range(self.relative_degree()) ])
    949949        return self._coerce_non_number_field_element_in(x)
    950950
    951 
    952951    def _coerce_from_str(self, x):
    953952        """
    954953        Coerce a string representation of an element of this
     
    12121211            sage: to_K(L.0)
    12131212            2*i0 - 6
    12141213       
    1215         Note that he image is indeed a square root of -1.
     1214        Note that the image is indeed a square root of -1.
    12161215       
    12171216        ::
    12181217       
     
    18761875        OUTPUT: A list of prime ideals of self lying over x. If degree is
    18771876        specified and no such ideal exists, returns the empty list.
    18781877       
    1879         .. warning::
    1880 
    1881            At this time we factor the ideal x, which may not be
    1882            supported for relative number fields.
    1883        
    18841878        EXAMPLES::
    18851879       
    18861880            sage: x = ZZ['x'].gen()
     
    19331927            [Fractional ideal (t^2 - 2*t - 1)]
    19341928            sage: P5_2 = P5_2s[0]; P5_2.residue_class_degree()
    19351929            2
     1930
     1931        Works in relative extensions too::
     1932
     1933            sage: PQ.<X> = QQ[]
     1934            sage: F.<a, b> = NumberField([X^2 - 2, X^2 - 3])
     1935            sage: PF.<Y> = F[]
     1936            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
     1937            sage: I = F.ideal(a + 2*b)
     1938            sage: K.primes_above(I)
     1939            [Fractional ideal (2, ((-13*b - 45/2)*a - 37/2*b - 63/2)*c + 1),
     1940             Fractional ideal (5, (5/2*b + 7/2)*a + 2*b + 10)]
     1941            sage: K.primes_above(I, degree=1)
     1942            [Fractional ideal (2, ((-13*b - 45/2)*a - 37/2*b - 63/2)*c + 1)]
     1943            sage: K.primes_above(I, degree=4)
     1944            [Fractional ideal (5, (5/2*b + 7/2)*a + 2*b + 10)]
    19361945       
    19371946        TESTS:
    19381947
     
    19431952            ...
    19441953            AttributeError: 'NumberFieldIdeal' object has no attribute 'factor'
    19451954       
    1946         Sage can't factor ideals over extension fields yet::
    1947        
    1948             sage: G = F.extension(x^2 - 11, 'b')
    1949             sage: G.primes_above(13)
    1950             Traceback (most recent call last):
    1951             ...
    1952             NotImplementedError
    19531955        """
    19541956        if degree is not None:
    19551957            degree = ZZ(degree)
     
    20402042            sage: P5_2.residue_class_degree()
    20412043            2
    20422044       
     2045        Relative number fields are ok::
     2046
     2047            sage: G = F.extension(x^2 - 11, 'b')
     2048            sage: G.prime_above(7)
     2049            Fractional ideal (7, (3*t^2 + 2*t + 9)*b - t^2 - 31*t - 10)
     2050
    20432051        TESTS:
    20442052
    20452053        It doesn't make sense to factor the ideal (0)::
     
    20492057            ...
    20502058            AttributeError: 'NumberFieldIdeal' object has no attribute 'factor'
    20512059       
    2052         Sage can't factor ideals over extension fields yet::
    2053        
    2054             sage: G = F.extension(x^2 - 11, 'b')
    2055             sage: G.prime_above(13)
    2056             Traceback (most recent call last):
    2057             ...
    2058             NotImplementedError
    20592060        """
    20602061        ids = self.primes_above(x, degree)
    20612062        if not ids:
     
    22422243            ...
    22432244            TypeError: Unable to coerce number field defined by non-integral polynomial to PARI.
    22442245        """
    2245         if self.defining_polynomial().denominator() != 1:
     2246        if self.absolute_polynomial().denominator() != 1:
    22462247            raise TypeError, "Unable to coerce number field defined by non-integral polynomial to PARI."
    22472248        try:
    22482249            return self.__pari_nf
     
    27382739        r"""
    27392740        Compute the different fractional ideal of this number field.
    27402741       
    2741         The different is the set of all `x` in `K` such
    2742         that the trace of `xy` is an integer for all
    2743         `y \in O_K`.
     2742        The codifferent is the fractional ideal of all `x` in `K`
     2743        such that the the trace of `xy` is an integer for
     2744        all `y \in O_K`. 
     2745
     2746        The different is the integral ideal which is the inverse of
     2747        the codifferent.
    27442748       
    27452749        EXAMPLES::
    27462750       
     
    31483152            [1, zeta15, zeta15^2, zeta15^3, zeta15^4, zeta15^5, zeta15^6, zeta15^7]
    31493153        """
    31503154        g = self.gen()
    3151         return [ g**i for i in range(self.degree()) ]
     3155        return [ g**i for i in range(self.relative_degree()) ]
    31523156
    31533157    def integral_basis(self, v=None):
    31543158        """
     
    36703674            sage: M.polynomial_ring()
    36713675            Univariate Polynomial Ring in y over Number Field in a1 with defining polynomial y^2 + 1
    36723676        """
    3673         return self.polynomial().parent()
     3677        return self.relative_polynomial().parent()
    36743678
    36753679    def polynomial_quotient_ring(self):
    36763680        """
     
    36833687            sage: K.polynomial_quotient_ring()
    36843688            Univariate Quotient Polynomial Ring in alpha over Rational Field with modulus x^3 + 2*x - 5
    36853689        """
    3686         return self.polynomial_ring().quotient(self.polynomial(), self.variable_name())
     3690        return self.polynomial_ring().quotient(self.relative_polynomial(), self.variable_name())
    36873691       
    36883692    def regulator(self, proof=None):
    36893693        """
     
    53395343               
    53405344        assert False, "bug in relativize"
    53415345
     5346    # Synonyms so that terminology appropriate to relative number fields
     5347    # can be applied to an absolute number field:
     5348
     5349    def absolute_degree(self):
     5350        """
     5351        A synonym for degree.
     5352
     5353        EXAMPLES::
     5354
     5355            sage: K.<i> = NumberField(x^2 + 1)
     5356            sage: K.absolute_degree()
     5357            2
     5358        """
     5359        return self.degree()
     5360
     5361    def relative_degree(self):
     5362        """
     5363        A synonym for degree.
     5364
     5365        EXAMPLES::
     5366
     5367            sage: K.<i> = NumberField(x^2 + 1)
     5368            sage: K.relative_degree()
     5369            2
     5370        """
     5371        return self.degree()
     5372
     5373    def absolute_polynomial(self):
     5374        """
     5375        A synonym for polynomial.
     5376
     5377        EXAMPLES::
     5378
     5379            sage: K.<i> = NumberField(x^2 + 1)
     5380            sage: K.absolute_polynomial()
     5381            x^2 + 1
     5382        """
     5383        return self.polynomial()
     5384
     5385    def relative_polynomial(self):
     5386        """
     5387        A synonym for polynomial.
     5388
     5389        EXAMPLES::
     5390
     5391            sage: K.<i> = NumberField(x^2 + 1)
     5392            sage: K.relative_polynomial()
     5393            x^2 + 1
     5394        """
     5395        return self.polynomial()
     5396
     5397    def absolute_vector_space(self):
     5398        """
     5399        A synonym for vector_space.
     5400
     5401        EXAMPLES::
     5402
     5403            sage: K.<i> = NumberField(x^2 + 1)
     5404            sage: K.absolute_vector_space()
     5405            (Vector space of dimension 2 over Rational Field,
     5406             Isomorphism map:
     5407              From: Vector space of dimension 2 over Rational Field
     5408              To:   Number Field in i with defining polynomial x^2 + 1,
     5409             Isomorphism map:
     5410              From: Number Field in i with defining polynomial x^2 + 1
     5411              To:   Vector space of dimension 2 over Rational Field)
     5412        """
     5413        return self.vector_space()
     5414
     5415    def relative_vector_space(self):
     5416        """
     5417        A synonym for vector_space.
     5418
     5419        EXAMPLES::
     5420
     5421            sage: K.<i> = NumberField(x^2 + 1)
     5422            sage: K.relative_vector_space()
     5423            (Vector space of dimension 2 over Rational Field,
     5424             Isomorphism map:
     5425              From: Vector space of dimension 2 over Rational Field
     5426              To:   Number Field in i with defining polynomial x^2 + 1,
     5427             Isomorphism map:
     5428              From: Number Field in i with defining polynomial x^2 + 1
     5429              To:   Vector space of dimension 2 over Rational Field)
     5430        """
     5431        return self.vector_space()
     5432
     5433    def absolute_discriminant(self):
     5434        """
     5435        A synonym for discriminant.
     5436
     5437        EXAMPLES::
     5438
     5439            sage: K.<i> = NumberField(x^2 + 1)
     5440            sage: K.absolute_discriminant()
     5441            -4
     5442        """
     5443        return self.discriminant()
     5444
     5445    def relative_discriminant(self):
     5446        """
     5447        A synonym for discriminant.
     5448
     5449        EXAMPLES::
     5450
     5451            sage: K.<i> = NumberField(x^2 + 1)
     5452            sage: K.relative_discriminant()
     5453            -4
     5454        """
     5455        return self.discriminant()
     5456
     5457    def absolute_different(self):
     5458        """
     5459        A synonym for different.
     5460
     5461        EXAMPLES::
     5462
     5463            sage: K.<i> = NumberField(x^2 + 1)
     5464            sage: K.absolute_different()
     5465            Fractional ideal (2)
     5466        """
     5467        return self.different()
     5468
     5469    def relative_different(self):
     5470        """
     5471        A synonym for different.
     5472
     5473        EXAMPLES::
     5474
     5475            sage: K.<i> = NumberField(x^2 + 1)
     5476            sage: K.relative_different()
     5477            Fractional ideal (2)
     5478        """
     5479        return self.different()
     5480
     5481
    53425482class NumberField_cyclotomic(NumberField_absolute):
    53435483    """
    53445484    Create a cyclotomic extension of the rational field.
     
    60496189        else:
    60506190            return (ZZ(0), ZZ(m/2))
    60516191
     6192    def different(self):
     6193        """
     6194        Returns the different ideal of the cyclotomic field self.
     6195
     6196        EXAMPLES::
     6197
     6198            sage: C20 = CyclotomicField(20)
     6199            sage: C20.different()
     6200            Fractional ideal (-4*zeta20^7 + 8*zeta20^5 - 12*zeta20^3 + 6*zeta20)
     6201            sage: C18 = CyclotomicField(18)
     6202            sage: D = C18.different().norm()
     6203            sage: D == C18.discriminant().abs()
     6204            True
     6205        """
     6206        try:
     6207            return self.__different
     6208       
     6209        except AttributeError:
     6210           
     6211            z = self.gen()
     6212            n = self._n()
     6213            D = self.ideal(1)
     6214            factors = n.factor()
     6215            for f in factors:
     6216                p = f[0]
     6217                r = f[1]
     6218                e = (r*p - r - 1)*p**(r-1)
     6219                D *= self.ideal(z**(n/p**r) - 1)**e
     6220            self.__different = D
     6221            return self.__different
     6222
    60526223    def discriminant(self, v=None):
    60536224        """
    60546225        Returns the discriminant of the ring of integers of the cyclotomic
     
    63246495        if n%2:
    63256496            v += [-x for x in v]   
    63266497        return v
    6327    
     6498
     6499
    63286500class NumberField_quadratic(NumberField_absolute):
    63296501    """
    63306502    Create a quadratic extension of the rational field.
  • sage/rings/number_field/number_field_element.pyx

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/number_field_element.pyx
    a b  
    567567            ...
    568568            IndexError: index must be between 0 and degree minus 1.
    569569       
    570         The list method implicitly calls __getitem__::
     570        The list method implicitly calls ``__getitem__``::
    571571       
    572572            sage: list(c)
    573573            [8/27, -16/15, 32/25, -64/125]
     
    17911791            sage: (O.2).vector()
    17921792            (1, -b)
    17931793        """
    1794         return self.number_field().vector_space()[2](self)
     1794        return self.number_field().relative_vector_space()[2](self)
    17951795
    17961796    def charpoly(self, var='x'):
    17971797        raise NotImplementedError, "Subclasses of NumberFieldElement must override charpoly()"
     
    19511951            v = []
    19521952            x = K.gen()
    19531953            a = K(1)
    1954             d = K.degree()
     1954            d = K.relative_degree()
    19551955            for n in range(d):
    19561956                v += (a*self).list()
    19571957                a *= x
     
    24102410    def __init__(self, parent, f):
    24112411        NumberFieldElement.__init__(self, parent, f)
    24122412
     2413    def __getitem__(self, n):
     2414        """
     2415        Return the n-th coefficient of this relative number field element, written
     2416        as a polynomial in the generator.
     2417       
     2418        Note that `n` must be between 0 and `d-1`, where
     2419        `d` is the relative degree of the number field.
     2420       
     2421        EXAMPLES::
     2422       
     2423            sage: K.<a, b> = NumberField([x^3 - 5, x^2 + 3])
     2424            sage: c = (a + b)^3; c
     2425            3*b*a^2 - 9*a - 3*b + 5
     2426            sage: c[0]
     2427            -3*b + 5
     2428       
     2429        We illustrate bounds checking::
     2430       
     2431            sage: c[-1]
     2432            Traceback (most recent call last):
     2433            ...
     2434            IndexError: index must be between 0 and the relative degree minus 1.
     2435            sage: c[4]
     2436            Traceback (most recent call last):
     2437            ...
     2438            IndexError: index must be between 0 and the relative degree minus 1.
     2439       
     2440        The list method implicitly calls ``__getitem__``::
     2441       
     2442            sage: list(c)
     2443            [-3*b + 5, -9, 3*b]
     2444            sage: K(list(c)) == c
     2445            True
     2446        """
     2447        if n < 0 or n >= self.parent().relative_degree():
     2448            raise IndexError, "index must be between 0 and the relative degree minus 1."
     2449        return self.vector()[n]
     2450
    24132451    def list(self):
    24142452        """
    24152453        Return the list of coefficients of self written in terms of a power
  • sage/rings/number_field/number_field_ideal.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/number_field_ideal.py
    a b  
    224224            sage: I   # random sign in output
    225225            Fractional ideal (-2*a^2 - 1)
    226226        """
    227         # The first method does not work for ideals in relative extensions
    228         try:
    229             return self.coordinates(self.number_field()(x)).denominator() == 1
    230         except NotImplementedError:
    231             x_ideal = self.number_field().ideal(x)
    232             return self + x_ideal == self
     227        return self.coordinates(self.number_field()(x)).denominator() == 1
    233228
    234229    def __elements_from_hnf(self, hnf):
    235230        """
     
    508503        uses \code{bnfisprincipal}, so set \code{proof=True} if you
    509504        want to prove correctness (which \emph{is} the default).
    510505
    511         EXAMPLE:
     506        EXAMPLES:
    512507            sage: R.<x> = PolynomialRing(QQ)
    513508            sage: K.<i> = NumberField(x^2+1, 'i')
    514509            sage: J = K.ideal([i+1, 2])
     
    561556        r"""
    562557        Return a list of generators for this ideal as a $\mathbb{Z}$-module.
    563558
    564         EXAMPLE:
     559        EXAMPLES:
    565560            sage: R.<x> = PolynomialRing(QQ)       
    566561            sage: K.<i> = NumberField(x^2 + 1)
    567562            sage: J = K.ideal(i+1)
     
    576571        Return a tuple (I, d), where I is an integral ideal, and d is the
    577572        smallest positive integer such that this ideal is equal to I/d.
    578573
    579         EXAMPLE:
     574        EXAMPLES:
    580575            sage: R.<x> = PolynomialRing(QQ)
    581576            sage: K.<a> = NumberField(x^2-5)
    582577            sage: I = K.ideal(2/(5+a))
     
    747742        self._norm = QQ(self.number_field().pari_nf().idealnorm(self.pari_hnf()))
    748743        return self._norm
    749744
     745    # synonyms (using terminology of relative number fields)
     746
     747    def absolute_norm(self):
     748        """
     749        A synonym for norm.
     750
     751        EXAMPLES:
     752            sage: K.<i> = NumberField(x^2 + 1)
     753            sage: K.ideal(1 + 2*i).absolute_norm()
     754            5
     755        """
     756        return self.norm()
     757
     758    def relative_norm(self):
     759        """
     760        A synonym for norm.
     761
     762        EXAMPLES:
     763            sage: K.<i> = NumberField(x^2 + 1)
     764            sage: K.ideal(1 + 2*i).relative_norm()
     765            5
     766        """
     767        return self.norm()
     768
     769    def absolute_ramification_index(self):
     770        """
     771        A synonym for ramification_index.
     772
     773        EXAMPLES:
     774            sage: K.<i> = NumberField(x^2 + 1)
     775            sage: K.ideal(1 + i).absolute_ramification_index()
     776            2
     777        """
     778        return self.ramification_index()
     779
     780    def relative_ramification_index(self):
     781        """
     782        A synonym for ramification_index.
     783
     784        EXAMPLES:
     785            sage: K.<i> = NumberField(x^2 + 1)
     786            sage: K.ideal(1 + i).relative_ramification_index()
     787            2
     788        """
     789        return self.ramification_index()
     790
    750791    def number_field(self):
    751792        """
    752793        Return the number field that this is a fractional ideal in.
     
    763804
    764805    def smallest_integer(self):
    765806        r"""
    766         Return the smallest nonnegative integer in $I \cap \mathbb{Z}$,
     807        Return the smallest non-negative integer in $I \cap \mathbb{Z}$,
    767808        where $I$ is this ideal.  If $I = 0$, returns $0$.
    768809       
    769         EXAMPLE:
     810        EXAMPLES:
    770811            sage: R.<x> = PolynomialRing(QQ)
    771812            sage: K.<a> = NumberField(x^2+6)
    772813            sage: I = K.ideal([4,a])/7
     
    11101151        assuming it is prime.  Otherwise, raise a ValueError.
    11111152
    11121153        The ramification index is the power of this prime appearing in
    1113         the factorization of the prime in $\ZZ$ that this primes lies
     1154        the factorization of the prime in $\ZZ$ that this prime lies
    11141155        over.
    11151156
    11161157        EXAMPLES:
     
    13171358            False
    13181359            sage: (j/k).is_coprime(j/k)
    13191360            False
     1361
     1362            sage: F.<a, b> = NumberField([x^2 - 2, x^2 - 3])
     1363            sage: F.ideal(3 - a*b).is_coprime(F.ideal(3))
     1364            False
    13201365        """
    13211366        # Catch invalid inputs by making sure that we can make an ideal out of other.
    13221367        K = self.number_field()
    13231368        one = K.unit_ideal()
    13241369        other = K.ideal(other)
    13251370        if self.is_integral() and other.is_integral():           
    1326             if arith.gcd(ZZ(self.norm()), ZZ(other.norm())) == 1:
     1371            if arith.gcd(ZZ(self.absolute_norm()), ZZ(other.absolute_norm())) == 1:
    13271372                return True
    13281373            else:
    13291374                return self+other == one
    13301375        # This special case is necessary since the zero ideal is not a
    13311376        # fractional ideal!
    1332         if other.norm() == 0:
     1377        if other.absolute_norm() == 0:
    13331378            return self == one
    13341379        D1 = self.denominator()
    13351380        N1 = self.numerator()
     
    14041449            M_self = MatrixSpace(ZZ,n)([R.coordinates(y) for y in self_b])
    14051450            M_other = MatrixSpace(ZZ,n)([R.coordinates(y) for y in other_b])
    14061451        except TypeError:
    1407             raise TypeError, "element_1_mod only defined for integral ideals"
     1452            raise TypeError, "element_1_mod only defined for integral ideals"
    14081453 
    14091454        #hnf for matrix representing C = self+other:
    14101455        C = M_self.stack(M_other)
     
    14481493            True
    14491494            sage: I.euler_phi()*J.euler_phi() == (I*J).euler_phi()
    14501495            True
     1496            sage: L.<b> = K.extension(x^2 - 7)
     1497            sage: L.ideal(3).euler_phi()
     1498            64
    14511499        """
    14521500        if not self.is_integral():
    14531501            raise ValueError, "euler_phi only defined for integral ideals"
    14541502        return prod([(np-1)*np**(e-1) \
    1455                      for np,e in [(p.norm(),e) \
     1503                     for np,e in [(p.absolute_norm(),e) \
    14561504                                  for p,e in self.factor()]])
     1505
    14571506    def prime_to_idealM_part(self, M):
    14581507        """
    14591508        Version for integral ideals of the prime_to_m_part function over ZZ.
  • sage/rings/number_field/number_field_ideal_rel.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/number_field_ideal_rel.py
    a b  
    66   -- William Stein (2007-09-06)
    77   -- Nick Alexander (2009-01)
    88
    9 EXAMPLEES:
     9EXAMPLES:
    1010    sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 2])
    1111    sage: A = K.absolute_field('z')
    1212    sage: I = A.factor(3)[0][0]
     
    1515    [3, (-2*b - 1)*a + b - 1]
    1616    sage: K.fractional_ideal(G)
    1717    Fractional ideal ((-b + 1)*a - b - 2)
    18     sage: K.fractional_ideal(G).absolute_ideal().norm().factor()
     18    sage: K.fractional_ideal(G).absolute_norm().factor()
    1919    3^2
    2020"""
    2121
     
    3535#*****************************************************************************
    3636
    3737from number_field_ideal import NumberFieldFractionalIdeal, convert_from_zk_basis
     38from sage.structure.factorization import Factorization
    3839
    3940import sage.rings.rational_field as rational_field
     41import sage.rings.integer_ring as integer_ring
    4042QQ = rational_field.RationalField()
     43ZZ = integer_ring.IntegerRing()
    4144
    4245class NumberFieldFractionalIdeal_rel(NumberFieldFractionalIdeal):
    4346    """
     
    6164        sage: ((a0 + 1) / g).is_integral()
    6265        True
    6366    """
     67    def __cmp__(self, other):
     68        """
     69        Compare an ideal of a relative number field to something else.
     70
     71        EXAMPLES:
     72            sage: K.<a, b> = NumberField([x^2 + 23, x^2 - 7])
     73            sage: I = K.ideal(2, (a + 2*b + 3)/2)
     74            sage: J = K.ideal(2, a - b)
     75            sage: I == J
     76            False
     77        """
     78        if not isinstance(other, NumberFieldFractionalIdeal):
     79            return cmp(type(self), type(other))
     80        return cmp(self.pari_rhnf(), other.pari_rhnf())
     81
     82    def _contains_(self, x):
     83        """
     84        Return True if x is an element of this ideal.
     85
     86        This function is called (indirectly) when the \code{in}
     87        operator is used.
     88
     89        EXAMPLES:
     90            sage: K.<a, b> = NumberField([x^2 + 23, x^2 - 7])
     91            sage: I = K.ideal(2, (a + 2*b + 3)/2)
     92            sage: [z in I for z in [a, b, 2, a + b]]
     93            [False, False, True, True]
     94        """
     95        abs_ideal = self.absolute_ideal()
     96        to_abs = abs_ideal.number_field().structure()[1]
     97        return to_abs(x) in abs_ideal
     98
    6499    def pari_rhnf(self):
    65100        """
    66101        Return PARI's representation of this relative ideal in Hermite
     
    104139            Fractional ideal (b)
    105140            sage: J.absolute_ideal()
    106141            Fractional ideal (a^2)
    107             sage: J.norm()
     142            sage: J.relative_norm()
    108143            Fractional ideal (2)
    109             sage: J.norm().norm()
     144            sage: J.absolute_norm()
    110145            4
    111146            sage: J.absolute_ideal().norm()
    112147            4
     
    117152            Fractional ideal (c)
    118153            sage: J.absolute_ideal()
    119154            Fractional ideal (a)
    120             sage: J.absolute_ideal().norm()
     155            sage: J.absolute_norm()
    121156            2
    122157            sage: J.ideal_below()
    123158            Fractional ideal (b)
     
    148183            Fractional ideal (22584817, a - b - 120132)
    149184            sage: (2*a + b) in J
    150185            True
    151             sage: (- b - 120132).minpoly()
    152             x + b + 120132
    153             sage: J.norm().norm()
     186            sage: J.absolute_norm()
    154187            22584817
    155188            sage: J.absolute_ideal()
    156189            Fractional ideal (188/812911*a^5 - 1/812911*a^4 + 45120/812911*a^3 - 56/73901*a^2 + 3881638/812911*a + 50041/812911)
     
    162195        """
    163196        L = self.number_field()
    164197        K = L.absolute_field('a')
    165         K_to_L, L_to_K = K.structure()
    166         rnf = L.pari_rnf()
    167         nf_zk = id.number_field().pari_nf().getattr('zk')
    168         gens_in_K = [ QQ['x'](x) for x in nf_zk * id.pari_hnf()]
    169         # each gen is now a polynomial giving an element of the absolute number field
    170         gens_in_L = [ L(K(x)) for x in gens_in_K ]
    171         return L.ideal( gens_in_L )
     198        to_L = K.structure()[0]
     199        return L.ideal([to_L(g) for g in id.gens()])
    172200
    173201    def free_module(self):
    174202        return self.absolute_ideal().free_module()
     
    179207        except AttributeError:
    180208            L = self.number_field()
    181209            K = L.base_field()
    182             R = L.polynomial().parent()
     210            R = L.relative_polynomial().parent()
    183211            S = L['x']
    184212            gens = L.pari_rnf().rnfidealtwoelt(self.pari_rhnf())
    185213            gens = [ L(R(x.lift().lift())) for x in gens ]
     
    215243        zero = self.number_field().pari_rnf().rnfidealhnf(0)
    216244        return self.pari_rhnf() == zero
    217245
    218     def norm(self):
     246    def absolute_norm(self):
    219247        """
    220         Compute the relative norm of this extension L/K as an ideal of K.
     248        Compute the absolute norm of this fractional ideal in a relative number
     249        field, returning a positive integer.
    221250
    222         EXAMPLE:
     251        EXAMPLES:
     252            sage: L.<a, b, c> = QQ.extension([x^2 - 23, x^2 - 5, x^2 - 7])
     253            sage: I = L.ideal(a + b)
     254            sage: I.absolute_norm()
     255            104976
     256            sage: I.relative_norm().relative_norm().relative_norm()
     257            104976
     258        """
     259        return self.absolute_ideal().norm()
     260
     261    def relative_norm(self):
     262        """
     263        Compute the relative norm of this fractional ideal in a relative number
     264        field, returning an ideal in the base field.
     265
     266        EXAMPLES:
    223267            sage: R.<x> = QQ[]
    224268            sage: K.<a> = NumberField(x^2+6)
    225269            sage: L.<b> = K.extension(K['x'].gen()^4 + a)
    226             sage: N = L.ideal(b).norm(); N
     270            sage: N = L.ideal(b).relative_norm(); N
    227271            Fractional ideal (-a)
    228272            sage: N.parent()
    229273            Monoid of ideals of Number Field in a with defining polynomial x^2 + 6
    230274            sage: N.ring()
    231275            Number Field in a with defining polynomial x^2 + 6
     276            sage: PQ.<X> = QQ[]
     277            sage: F.<a, b> = NumberField([X^2 - 2, X^2 - 3])
     278            sage: PF.<Y> = F[]
     279            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
     280            sage: K.ideal(1).relative_norm()
     281            Fractional ideal (1)
     282            sage: K.ideal(13).relative_norm().relative_norm()
     283            Fractional ideal (28561)
     284            sage: K.ideal(13).relative_norm().relative_norm().relative_norm()
     285            815730721
     286            sage: K.ideal(13).absolute_norm()
     287            815730721
    232288        """
    233289        L = self.number_field()
    234290        K = L.base_field()
    235         R = K.polynomial().parent()
     291        K_abs = K.absolute_field('a')
     292        to_K = K_abs.structure()[0]
     293        R = K_abs.polynomial().parent()
    236294        hnf = L.pari_rnf().rnfidealnormrel(self.pari_rhnf())
    237         return K.ideal([ K(R(x)) for x in convert_from_zk_basis(K, hnf) ])
     295        return K.ideal([ to_K(K_abs(R(x))) for x in convert_from_zk_basis(K, hnf) ])
     296
     297    def norm(self):
     298        """
     299        The norm of a fractional ideal in a relative number field is deliberately
     300        unimplemented, so that a user cannot mistake the absolute norm
     301        for the relative norm, or vice versa.
     302        """
     303        raise NotImplementedError, "For a fractional ideal in a relative number field you must use relative_norm or absolute_norm as appropriate"
    238304
    239305    def ideal_below(self):
    240306        """
    241307        Compute the ideal of K below this ideal of L.
    242308
    243         EXAMPLE:
     309        EXAMPLES:
    244310            sage: R.<x> = QQ[]
    245311            sage: K.<a> = NumberField(x^2+6)
    246312            sage: L.<b> = K.extension(K['x'].gen()^4 + a)
     
    307373            True
    308374            sage: K0.ideal([-a0 + 1]) == K0.ideal([-a0 + 5])
    309375            False
     376
     377            It works when the base_field is itself a relative number field
     378            sage: PQ.<X> = QQ[]
     379            sage: F.<a, b> = NumberFieldTower([X^2 - 2, X^2 - 3])
     380            sage: PF.<Y> = F[]
     381            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
     382            sage: I = K.ideal(3, c)
     383            sage: J = I.ideal_below(); J
     384            Fractional ideal (-b*a + 3)
     385            sage: J.number_field() == F
     386            True
    310387        """
    311388        L = self.number_field()
    312389        K = L.base_field()
    313         R = K.polynomial().parent()
     390        K_abs = K.absolute_field('a')
     391        to_K = K_abs.structure()[0]
     392        R = K_abs.polynomial().parent()
    314393        hnf = L.pari_rnf().rnfidealdown(self.pari_rhnf())
    315         return K.ideal([ K(R(x)) for x in convert_from_zk_basis(K, hnf) ])
     394        return K.ideal([ to_K(K_abs(R(x))) for x in convert_from_zk_basis(K, hnf) ])
    316395
    317396    def factor(self):
    318         raise NotImplementedError
     397        """
     398        Factor the ideal by factoring the corresponding ideal
     399        in the absolute number field.
     400
     401        EXAMPLES:
     402            sage: K.<a, b> = QQ.extension([x^2 + 11, x^2 - 5])
     403            sage: K.factor(5)
     404            (Fractional ideal (5, 1/2*a - 1/2*b - 1))^2 * (Fractional ideal (5, 1/2*a - 1/2*b + 1))^2
     405            sage: K.ideal(5).factor()
     406            (Fractional ideal (5, 1/2*a - 1/2*b - 1))^2 * (Fractional ideal (5, 1/2*a - 1/2*b + 1))^2
     407            sage: K.ideal(5).prime_factors()
     408            [Fractional ideal (5, 1/2*a - 1/2*b - 1),
     409             Fractional ideal (5, 1/2*a - 1/2*b + 1)]
     410
     411            sage: PQ.<X> = QQ[]
     412            sage: F.<a, b> = NumberFieldTower([X^2 - 2, X^2 - 3])
     413            sage: PF.<Y> = F[]
     414            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
     415            sage: K.ideal(c)
     416            Fractional ideal (6, -2*c + (171/2*b + 291/2)*a + 117*b + 216)
     417            sage: K.ideal(c).factor()
     418            (Fractional ideal (2, ((-13*b - 45/2)*a - 37/2*b - 63/2)*c + 1))^2 * (Fractional ideal (3, c))
     419        """
     420        F = self.number_field()
     421        abs_ideal = self.absolute_ideal()
     422        to_F = abs_ideal.number_field().structure()[0]
     423        factor_list = [(F.ideal([to_F(g) for g in p.gens()]), e) for p, e in abs_ideal.factor()]
     424        # sorting and simplification will already have been done
     425        return Factorization(factor_list, sort=False, simplify=False)
     426
    319427    def integral_basis(self):
    320428        raise NotImplementedError
     429
    321430    def integral_split(self):
    322         raise NotImplementedError
    323     def is_maximal(self):
    324         raise NotImplementedError
     431        """
     432        Return a tuple (I, d), where I is an integral ideal, and d is the
     433        smallest positive integer such that this ideal is equal to I/d.
     434
     435        EXAMPLES:
     436            sage: K.<a, b> = NumberFieldTower([x^2 - 23, x^2 + 1])
     437            sage: I = K.ideal([a + b/3])
     438            sage: J, d = I.integral_split()
     439            sage: J.is_integral()
     440            True
     441            sage: J == d*I
     442            True
     443
     444        """
     445        d = self.absolute_ideal().integral_split()[1]
     446        return (d*self, d)
     447   
    325448    def is_prime(self):
    326         raise NotImplementedError
    327     def ramification(self):
    328         raise NotImplementedError
     449        """
     450        Return True if this ideal of a relative number field is prime.
     451
     452        EXAMPLES:
     453            sage: K.<a, b> = NumberField([x^2 - 17, x^3 - 2])
     454            sage: K.ideal(a + b).is_prime()
     455            True
     456            sage: K.ideal(13).is_prime()
     457            False
     458        """
     459        return self.absolute_ideal().is_prime()
     460
     461    def is_integral(self):
     462        """
     463        Return True if this ideal is integral.
     464
     465        EXAMPLES:
     466           sage: K.<a, b> = QQ.extension([x^2 + 11, x^2 - 5])
     467           sage: I = K.ideal(7).prime_factors()[0]
     468           sage: I.is_integral()
     469           True
     470           sage: (I/2).is_integral()
     471           False
     472        """
     473        return self.absolute_ideal().is_integral()
     474
     475    def absolute_ramification_index(self):
     476        """
     477        Return the absolute ramification index of this fractional ideal,
     478        assuming it is prime.  Otherwise, raise a ValueError.
     479
     480        The absolute ramification index is the power of this prime
     481        appearing in the factorization of the rational prime that
     482        this prime lies over.
     483
     484        Use relative_ramification_index to obtain the power of this
     485        prime occurring in the factorization of the prime ideal
     486        of the  base field that this prime lies over.
     487
     488        EXAMPLES:
     489            sage: PQ.<X> = QQ[]
     490            sage: F.<a, b> = NumberFieldTower([X^2 - 2, X^2 - 3])
     491            sage: PF.<Y> = F[]
     492            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
     493            sage: I = K.ideal(3, c)
     494            sage: I.absolute_ramification_index()
     495            4
     496            sage: I.smallest_integer()
     497            3
     498            sage: K.ideal(3) == I^4
     499            True
     500        """
     501        if self.is_prime():
     502            return self.absolute_ideal().ramification_index()
     503        raise ValueError, "the fractional ideal (= %s) is not prime"%self
     504
     505    def relative_ramification_index(self):
     506        """
     507        Return the relative ramification index of this fractional ideal,
     508        assuming it is prime.  Otherwise, raise a ValueError.
     509
     510        The relative ramification index is the power of this prime
     511        appearing in the factorization of the prime ideal of the 
     512        base field that this prime lies over.
     513
     514        Use absolute_ramification_index to obtain the power of this
     515        prime occurring in the factorization of the rational prime
     516        that this prime lies over.
     517
     518        EXAMPLES:
     519            sage: PQ.<X> = QQ[]
     520            sage: F.<a, b> = NumberFieldTower([X^2 - 2, X^2 - 3])
     521            sage: PF.<Y> = F[]
     522            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
     523            sage: I = K.ideal(3, c)
     524            sage: I.relative_ramification_index()
     525            2
     526            sage: I.ideal_below()
     527            Fractional ideal (-b*a + 3)
     528            sage: K.ideal(-b*a + 3) == I^2
     529            True
     530        """
     531        if self.is_prime():
     532            abs_index = self.absolute_ramification_index()
     533            base_ideal = self.ideal_below()
     534            return ZZ(abs_index/base_ideal.absolute_ramification_index())
     535        raise ValueError, "the fractional ideal (= %s) is not prime"%self
     536
     537    def ramification_index(self):
     538        """
     539        For ideals in relative number fields ramification_index is
     540        deliberately not implemented in order to avoid ambiguity.  Either
     541        relative_ramification_index or absolute_ramification_index should
     542        be used instead.
     543        """
     544        raise NotImplementedError, "For an ideal in a relative number field you must use relative_ramification_index or absolute_ramification_index as appropriate"
     545
    329546    def residue_class_degree(self):
    330         raise NotImplementedError
     547        """
     548        EXAMPLES:
     549            sage: PQ.<X> = QQ[]
     550            sage: F.<a, b> = NumberFieldTower([X^2 - 2, X^2 - 3])
     551            sage: PF.<Y> = F[]
     552            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
     553            sage: [I.residue_class_degree() for I in K.ideal(c).prime_factors()]
     554            [1, 2]
     555         """
     556        if self.is_prime():
     557            return self.absolute_ideal().residue_class_degree()
     558        raise ValueError, "the ideal (= %s) is not prime"%self
     559
     560    def residues(self):
     561        """
     562        Returns a iterator through a complete list of residues modulo this integral ideal.
     563
     564        An error is raised if this fractional ideal is not integral.
     565
     566        EXAMPLES:
     567            sage: K.<a, w> = NumberFieldTower([x^2 - 3, x^2 + x + 1])
     568            sage: I = K.ideal(6, -w*a - w + 4)
     569            sage: list(I.residues())[:5]
     570            [(-10/3*w - 8/3)*a,
     571             (-10/3*w - 8/3)*a + 1,
     572             (-10/3*w - 8/3)*a + 2,
     573             (-10/3*w - 8/3)*a + 3,
     574             (-10/3*w - 8/3)*a + 4]
     575        """
     576        abs_ideal = self.absolute_ideal()
     577        from_abs = abs_ideal.number_field().structure()[0]
     578        from sage.misc.mrange import xmrange_iter
     579        abs_residues = abs_ideal.residues()
     580        return xmrange_iter(abs_residues.iter_list, lambda c: from_abs(abs_residues.typ(c)))
     581
     582    def element_1_mod(self, other):
     583        """
     584        Returns an element r in this ideal such that 1-r is in other.
     585
     586        An error is raised if either ideal is not integral of if they
     587        are not coprime.
     588                     
     589        INPUT:
     590            other -- another ideal of the same field, or generators of an ideal.
     591        OUTPUT:
     592            r -- an element of the ideal self such that 1-r is in the ideal other.
     593
     594        EXAMPLES:
     595            sage: K.<a, b> = NumberFieldTower([x^2 - 23, x^2 + 1])
     596            sage: I = Ideal(2, (a - 3*b + 2)/2)
     597            sage: J = K.ideal(a)
     598            sage: z = I.element_1_mod(J); z
     599            -8*b*a + 24
     600            sage: z in I
     601            True
     602            sage: 1 - z in J
     603            True
     604        """
     605        # Catch invalid inputs by making sure that we can make an ideal out of other.
     606        K = self.number_field()
     607        if not self.is_integral():
     608            raise TypeError, "%s is not an integral ideal"%self
     609 
     610        other = K.ideal(other)
     611        if not other.is_integral():
     612            raise TypeError, "%s is not an integral ideal"%other
     613     
     614        if not self.is_coprime(other):
     615            raise TypeError, "%s and %s are not coprime ideals"%(self, other)
     616
     617        to_K = K.absolute_field('a').structure()[0]
     618        return to_K(self.absolute_ideal().element_1_mod(other.absolute_ideal()))
     619
    331620    def smallest_integer(self):
    332         raise NotImplementedError
    333     def valuation(self):
    334         raise NotImplementedError
     621        r"""
     622        Return the smallest non-negative integer in $I \cap \mathbb{Z}$,
     623        where $I$ is this ideal.  If $I = 0$, returns $0$.
     624       
     625        EXAMPLES:
     626            sage: K.<a, b> = NumberFieldTower([x^2 - 23, x^2 + 1])
     627            sage: I = K.ideal([a + b])
     628            sage: I.smallest_integer()
     629            12
     630            sage: [m for m in range(13) if m in I]
     631            [0, 12]
     632        """
     633        return self.absolute_ideal().smallest_integer()
     634
     635    def valuation(self, p):
     636        r"""
     637        Return the valuation of this fractional ideal at the prime
     638        $\mathfrak{p}$.  If $\mathfrak{p}$ is not prime, raise a
     639        ValueError.
     640
     641        INPUT:
     642            p -- a prime ideal of this relative number field.
     643
     644        OUTPUT:
     645            integer
     646
     647        EXAMPLES:
     648            sage: K.<a, b> = NumberField([x^2 - 17, x^3 - 2])
     649            sage: A = K.ideal(a + b)
     650            sage: A.is_prime()
     651            True
     652            sage: (A*K.ideal(3)).valuation(A)
     653            1
     654            sage: K.ideal(25).valuation(5)
     655            Traceback (most recent call last):
     656            ...
     657            ValueError: p (= Fractional ideal (5)) must be a prime
     658         """
     659        if p == 0:
     660            raise ValueError, "p (= %s) must be nonzero"%p
     661        if not isinstance(p, NumberFieldFractionalIdeal):
     662            p = self.number_field().ideal(p)
     663        if not p.is_prime():
     664            raise ValueError, "p (= %s) must be a prime"%p
     665        if p.ring() != self.number_field():
     666            raise ValueError, "p (= %s) must be an ideal in %s"%self.number_field()
     667        return self.absolute_ideal().valuation(p.absolute_ideal())
    335668
    336669def is_NumberFieldFractionalIdeal_rel(x):
    337670    """
     
    356689        Fractional ideal (b)
    357690        sage: is_NumberFieldFractionalIdeal_rel(I)
    358691        True
    359         sage: N = I.norm(); N
     692        sage: N = I.relative_norm(); N
    360693        Fractional ideal (-a)
    361694        sage: is_NumberFieldFractionalIdeal_rel(N)
    362695        False
  • sage/rings/number_field/number_field_rel.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/number_field_rel.py
    a b  
    119119import sage.rings.integer as integer
    120120import sage.rings.polynomial.polynomial_ring as polynomial_ring
    121121import sage.rings.polynomial.polynomial_element as polynomial_element
     122from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
    122123import sage.rings.ideal as ideal
    123124import sage.rings.complex_field
    124125import sage.groups.abelian_gps.abelian_group
     
    329330            Number Field in n with defining polynomial x^2 + x + 1 over its base field
    330331            sage: L.base_field().base_field()
    331332            Number Field in r with defining polynomial x^3 - 2
     333
     334        And a more complicated example:
     335            sage: PQ.<X> = QQ[]
     336            sage: F.<a, b> = NumberField([X^2 - 2, X^2 - 3])
     337            sage: PF.<Y> = F[]
     338            sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
     339            sage: L.<m, n, r> = K.change_names(); L
     340            Number Field in m with defining polynomial x^2 + (-2*r - 3)*n - 2*r - 6 over its base field
     341            sage: L.structure()
     342            (Isomorphism given by variable name change map:
     343              From: Number Field in m with defining polynomial x^2 + (-2*r - 3)*n - 2*r - 6 over its base field
     344              To:   Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field,
     345             Isomorphism given by variable name change map:
     346              From: Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field
     347              To:   Number Field in m with defining polynomial x^2 + (-2*r - 3)*n - 2*r - 6 over its base field)
    332348        """
    333349        if len(names) == 0:
    334350            names = self.variable_names()
    335351        elif isinstance(names, str):
    336352            names = names.split(',')
    337353        K = self.base_field().change_names(tuple(names[1:]))
    338         L = K.extension(self.defining_polynomial(), names=names[0])
     354        to_K = K.structure()[1]
     355        old_poly = self.relative_polynomial()
     356        new_poly = PolynomialRing(K, 'x')([to_K(c) for c in old_poly])
     357        L = K.extension(new_poly, names=names[0])
     358        L._set_structure(maps.NameChangeMap(L, self), maps.NameChangeMap(self, L))
    339359        return L
    340360
    341361    def is_absolute(self):
     
    407427
    408428    def absolute_degree(self):
    409429        """
     430        The degree of this relative number field over the rational field.
     431
    410432        EXAMPLES:
    411             sage: K.<a> = NumberField([x^2 + 3, x^2 + 2])
     433            sage: K.<a> = NumberFieldTower([x^2 - 17, x^3 - 2])
    412434            sage: K.absolute_degree()
    413             4
    414             sage: K.degree()
     435            6
     436        """
     437        return self.absolute_polynomial().degree()
     438
     439    def relative_degree(self):
     440        """
     441
     442        EXAMPLES:
     443            sage: K.<a> = NumberFieldTower([x^2 - 17, x^3 - 2])
     444            sage: K.relative_degree()
    415445            2
    416446        """
    417         return self.absolute_polynomial().degree()
     447        return self.relative_polynomial().degree()
     448
     449    def degree(self):
     450        """
     451        The degree, unqualified, of a relative number field is deliberately
     452        not implemented, so that a user cannot mistake the absolute degree
     453        for the relative degree, or vice versa.
     454        """
     455        raise NotImplementedError, "For a relative number field you must use relative_degree or absolute_degree as appropriate"
    418456
    419457    def maximal_order(self):
    420458        """
     
    458496            sage: print L == K
    459497            True       
    460498        """
    461         return NumberField_relative_v1, (self.__base_field, self.polynomial(), self.variable_name(),
     499        return NumberField_relative_v1, (self.__base_field, self.relative_polynomial(), self.variable_name(),
    462500                                          self.latex_variable_name(), self.gen_embedding())
    463501
    464502    def _repr_(self):
     
    476514            Number Field in b with defining polynomial x^7 + 3
    477515        """
    478516       
    479         return "Number Field in %s with defining polynomial %s over its base field"%(self.variable_name(), self.polynomial())
     517        return "Number Field in %s with defining polynomial %s over its base field"%(self.variable_name(), self.relative_polynomial())
    480518       
    481519        #return "Extension by %s of the Number Field in %s with defining polynomial %s"%(
    482520        #self.polynomial(), self.base_field().variable_name(),
     
    504542        r"""
    505543        Return a \LaTeX representation of the extension.
    506544
    507         EXAMPLE:
     545        EXAMPLES:
    508546            sage: x = QQ['x'].0
    509547            sage: K.<a> = NumberField(x^3 - 2)
    510548            sage: t = K['x'].gen()
     
    512550            '( \\mathbf{Q}[a]/(a^{3} - 2) )[b]/(b^{2} + b + a)'
    513551        """
    514552        return "( %s )[%s]/(%s)"%(latex(self.base_field()), self.latex_variable_name(),
    515                               self.polynomial()._latex_(self.latex_variable_name()))
     553                              self.relative_polynomial()._latex_(self.latex_variable_name()))
    516554
    517555    def _coerce_from_other_number_field(self, x):
    518556        """
     
    938976        """
    939977        return self.absolute_field('a').is_galois()
    940978
    941     def vector_space(self):
     979    def relative_vector_space(self):
    942980        """
    943981        Return vector space over the base field of self and isomorphisms
    944982        from the vector space to self and in the other direction.
     
    946984        EXAMPLES:
    947985            sage: K.<a,b,c> = NumberField([x^2 + 2, x^3 + 2, x^3 + 3]); K
    948986            Number Field in a with defining polynomial x^2 + 2 over its base field
    949             sage: V, from_V, to_V = K.vector_space()
     987            sage: V, from_V, to_V = K.relative_vector_space()
    950988            sage: from_V(V.0)
    951989            1
    952990            sage: to_V(K.0)
     
    959997            (0, 1)
    960998
    961999        The underlying vector space and maps is cached:
    962             sage: W, from_V, to_V = K.vector_space()
     1000            sage: W, from_V, to_V = K.relative_vector_space()
    9631001            sage: V is W
    9641002            True
    9651003        """
    9661004        try:
    967             return self.__vector_space
     1005            return self.__relative_vector_space
    9681006        except AttributeError:
    9691007            pass
    970         V = self.base_field()**self.degree()
     1008        V = self.base_field()**self.relative_degree()
    9711009        from_V = maps.MapRelativeVectorSpaceToRelativeNumberField(V, self)
    9721010        to_V   = maps.MapRelativeNumberFieldToRelativeVectorSpace(self, V)
    973         self.__vector_space = (V, from_V, to_V)
    974         return self.__vector_space
     1011        self.__relative_vector_space = (V, from_V, to_V)
     1012        return self.__relative_vector_space
    9751013
    9761014    def absolute_vector_space(self):
    9771015        """
     
    10091047        ans = (V, fr, to)
    10101048        self.__absolute_vector_space = ans
    10111049        return ans
     1050
     1051    def vector_space(self):
     1052        """
     1053        For a relative number field \code{L}, \code{L.vector_space()} is deliberately
     1054        not implemented, so that a user cannot confuse \code{L.relative_vector_space()}
     1055        with \code{L.absolute_vector_space()}.
     1056        """
     1057        raise NotImplementedError, "For a relative number field L you must use either L.relative_vector_space() or L.absolute_vector_space() as appropriate"
    10121058       
    10131059    def absolute_base_field(self):
    10141060        """
     
    10891135            sage: k.<a, c> = NumberField([x^2 + 3, x^2 + 1])
    10901136            sage: k.pari_polynomial()
    10911137            x^4 + 8*x^2 + 4
    1092             sage: k.defining_polynomial ()
     1138            sage: k.relative_polynomial ()
    10931139            x^2 + 3
    10941140        """
    10951141        try:
     
    11651211        """
    11661212        abs_base, _, _ = self.absolute_base_field()
    11671213        g = QQ['y'](abs_base.polynomial())
    1168         vals = [ QQ['y'](f.polynomial())._pari_().Mod(g) for f in self.polynomial().list() ]
     1214        vals = [ QQ['y'](f.polynomial())._pari_().Mod(g) for f in self.relative_polynomial().list() ]
    11691215        f = pari(vals).Polrev()
    11701216        return f
    11711217
     
    12151261            self.__abs_gen = self._element_class(self, QQ['x'].gen())
    12161262            return self.__abs_gen
    12171263       
    1218 
    12191264    def absolute_field(self, names):
    12201265        r"""
    12211266        Return an absolute number field K that is isomorphic to this
     
    13071352        """
    13081353        return QQ['x'](self._pari_rnfequation()[0])
    13091354
     1355    def relative_polynomial(self):
     1356        """
     1357        Return the defining polynomial of this relative number field over its base field.
     1358
     1359        EXAMPLES:
     1360            sage: K.<a> = NumberFieldTower([x^2 + x + 1, x^3 + x + 1])
     1361            sage: K.relative_polynomial()
     1362            x^2 + x + 1
     1363
     1364            Use absolute polynomial for a polynomial that defines the
     1365            absolute extension.
     1366
     1367            sage: K.absolute_polynomial()
     1368            x^6 + 3*x^5 + 8*x^4 + 9*x^3 + 7*x^2 + 6*x + 3
     1369        """
     1370        return self.__relative_polynomial
     1371
     1372    def defining_polynomial(self): 
     1373        """
     1374        Return the defining polynomial of this relative number field.
     1375
     1376        This is exactly the same as \code{self.relative_polynomal()}.
     1377
     1378        EXAMPLES:
     1379            sage: C.<z> = CyclotomicField(5)
     1380            sage: PC.<X> = C[]
     1381            sage: K.<a> = C.extension(X^2 + X + z); K
     1382            Number Field in a with defining polynomial X^2 + X + z over its base field
     1383            sage: K.defining_polynomial()
     1384            X^2 + X + z
     1385        """
     1386        return self.relative_polynomial()
     1387
     1388    def polynomial(self):
     1389        """
     1390        For a relative number field \code{L}, \code{L.polynomial()} is deliberately
     1391        not implemented.  Either \code{L.relative_polynomial()}
     1392        or \code{L.absolute_polynomial()} must be used.
     1393        """
     1394        raise NotImplementedError, "For a relative number field L you must use either L.relative_polynomial() or L.absolute_polynomial() as appropriate"
     1395
    13101396    def base_field(self):
    13111397        """
    13121398        Return the base field of this relative number field.
     
    13931479        self.__embeddings[K] = Sequence(v, cr=v!=[], immutable=True, check=False, universe=self.Hom(K))
    13941480        return self.__embeddings[K]
    13951481
     1482    def absolute_different(self):
     1483        r"""
     1484        Return the absolute different of this relative number field as
     1485        an ideal of $L$.  To get the relative different of $L/K$,
     1486        use \code{L.relative_different()}.
     1487
     1488        EXAMPLES:
     1489            sage: K.<i> = NumberField(x^2 + 1)
     1490            sage: t = K['t'].gen()
     1491            sage: L.<b> = K.extension(t^4 - i)
     1492            sage: L.absolute_different()
     1493            Fractional ideal (8)
     1494        """
     1495        abs = self.absolute_field('a')
     1496        from_abs = abs.structure()[0]
     1497        return self.ideal([from_abs(g) for g in abs.different().gens()])
     1498
     1499    def relative_different(self):
     1500        r"""
     1501        Return the relative different of this extension $L/K$ as
     1502        an ideal of $L$.  If you want the absolute different of
     1503        $L/Q$, use \code{L.different()}.
     1504
     1505        EXAMPLES:
     1506            sage: K.<i> = NumberField(x^2 + 1)
     1507            sage: PK.<t> = K[]
     1508            sage: L.<a> = K.extension(t^4  - i)
     1509            sage: L.relative_different()
     1510            Fractional ideal (4)
     1511        """
     1512        I = self.absolute_different()
     1513        J = self.ideal(self.base_field().absolute_different().gens())
     1514        return  I/J
     1515
     1516    def different(self):
     1517        """
     1518        The different, unqualified, of a relative number field is deliberately
     1519        not implemented, so that a user cannot mistake the absolute different
     1520        for the relative different, or vice versa.
     1521        """
     1522        raise NotImplementedError, "For a relative number field you must use relative_different or absolute_different as appropriate"
     1523
     1524    def absolute_discriminant(self, v=None):
     1525        r"""
     1526        Return the absolute discriminant of this relative number field
     1527        or if v is specified, the determinant of the trace pairing
     1528        on the elements of the list v. 
     1529
     1530        INPUT:
     1531            v (optional) -- list of element of this relative number field.
     1532        OUTPUT:
     1533            Integer if v is omitted, and Rational otherwise.
     1534
     1535        EXAMPLES:
     1536            sage: K.<i> = NumberField(x^2 + 1)
     1537            sage: t = K['t'].gen()
     1538            sage: L.<b> = K.extension(t^4 - i)
     1539            sage: L.absolute_discriminant()
     1540            16777216
     1541            sage: L.absolute_discriminant([(b + i)^j for j in range(8)])
     1542            61911970349056
     1543        """
     1544        abs = self.absolute_field('a')
     1545        if v != None:
     1546            to_abs = abs.structure()[1]
     1547            v = [to_abs(x) for x in v]
     1548        return abs.discriminant(v=v)
     1549
    13961550    def relative_discriminant(self, proof=None):
    13971551        r"""
    13981552        Return the relative discriminant of this extension $L/K$ as
     
    14081562        INPUT:
    14091563            proof -- (default: False)
    14101564
    1411         EXAMPLE:
     1565        EXAMPLES:
    14121566            sage: K.<i> = NumberField(x^2 + 1)
    14131567            sage: t = K['t'].gen()
    14141568            sage: L.<b> = K.extension(t^4 - i)
    14151569            sage: L.relative_discriminant()
    14161570            Fractional ideal (256)
    1417             sage: factor(L.discriminant())
    1418             2^24
    1419             sage: factor( L.relative_discriminant().norm() )
    1420             2^16
    1421         """
     1571         """
    14221572        proof = proof_flag(proof)
    14231573       
    14241574        bnf = self._pari_base_bnf(proof)
     
    14271577        D, d = bnf.rnfdisc(self.pari_relative_polynomial())
    14281578        return K.ideal([ K(R(x)) for x in convert_from_zk_basis(K, D) ])
    14291579
     1580    def discriminant(self):
     1581        """
     1582        The discriminant, unqualified, of a relative number field is deliberately
     1583        not implemented, so that a user cannot mistake the absolute discriminant
     1584        for the relative discriminant, or vice versa.
     1585        """
     1586        raise NotImplementedError, "For a relative number field you must use relative_discriminant or absolute_discriminant as appropriate"
     1587
     1588    def disc(self):
     1589        """
     1590        The discriminant, unqualified, of a relative number field is deliberately
     1591        not implemented, so that a user cannot mistake the absolute discriminant
     1592        for the relative discriminant, or vice versa.
     1593        """
     1594        raise NotImplementedError, "For a relative number field you must use relative_discriminant or absolute_discriminant as appropriate"
     1595
    14301596    def order(self, *gens, **kwds):
    14311597        """
    14321598        Return the order with given ring generators in the maximal
     
    14721638        gens = [self(x) for x in gens]
    14731639        return order.relative_order_from_ring_generators(gens, **kwds)
    14741640       
    1475 
    14761641    def galois_group(self, pari_group = True, algorithm='pari'):
    14771642        r"""
    14781643        Return the Galois group of the Galois closure of this number
     
    14901655        typing \code{K.polynomial().galois_group?}, where $K$
    14911656        is a number field.
    14921657
    1493         EXAMPLE:
     1658        EXAMPLES:
    14941659            sage: x = QQ['x'].0
    14951660            sage: K.<a> = NumberField(x^2 + 1)
    14961661            sage: R.<t> = PolynomialRing(K)
     
    15111676        self.__galois_group[pari_group, algorithm] = H
    15121677        return H
    15131678   
    1514 
    15151679    def is_free(self, proof=None):
    15161680        r"""
    15171681        Determine whether or not $L/K$ is free (i.e. if $\mathcal{O}_L$ is
     
    15611725        f = QQ['y'](str_poly)
    15621726        return self.base_field()(f.list())
    15631727
    1564     def polynomial(self):
    1565         """
    1566         Return the defining polynomial of this number field.
    1567 
    1568         EXAMPLES:
    1569             sage: y = polygen(QQ,'y')
    1570             sage: k.<a> = NumberField([y^2 + y + 1, x^3 + x + 1])
    1571             sage: k.polynomial()
    1572             y^2 + y + 1
    1573 
    1574         This is the same as defining_polynomial:
    1575             sage: k.defining_polynomial()
    1576             y^2 + y + 1
    1577 
    1578         Use absolute polynomial for a polynomial that defines the
    1579         absolute extension.
    1580             sage: k.absolute_polynomial()
    1581             x^6 + 3*x^5 + 8*x^4 + 9*x^3 + 7*x^2 + 6*x + 3
    1582         """
    1583         return self.__relative_polynomial
    1584 
    15851728    def relativize(self, alpha, names):
    15861729        r"""
    15871730        Given an element in self or an embedding of a subfield into self,
  • sage/rings/number_field/order.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/order.py
    a b  
    255255
    256256        """
    257257        if self._is_maximal is None:
    258             self._is_maximal = (self.absolute_discriminant() == self._K.discriminant())
     258            self._is_maximal = (self.absolute_discriminant() == self._K.absolute_discriminant())
    259259        return self._is_maximal
    260260
    261261    def is_field(self):
     
    11881188    def __call__(self, x):
    11891189        """
    11901190        Coerce an element into this relative order.
     1191
     1192        EXAMPLES::
     1193
     1194            sage: K.<a, b> = NumberField([x^2 + 2, x^2 + 1000*x + 1])
     1195            sage: OK = K.ring_of_integers()
     1196            sage: OK(a)
     1197            a
     1198            sage: OK([3, 4])
     1199            4*a + 3
     1200
     1201        The following used to fail; see trac #5276::
     1202
     1203            sage: S.<y> = OK[]; S
     1204            Univariate Polynomial Ring in y over Relative Order in Number Field in a with defining polynomial x^2 + 2 over its base field
     1205
    11911206        """
    1192         if x.parent() is not self._K:
    1193             x = self._K(x)
    1194         x = self._absolute_order(x) # will test membership
     1207
     1208        x = self._K(x)
     1209        abs_order = self._absolute_order
     1210        to_abs = abs_order._K.structure()[1]
     1211        x = abs_order(to_abs(x)) # will test membership
    11951212        return OrderElement_relative(self, x)
    11961213
    11971214    def _repr_(self):
  • sage/rings/number_field/small_primes_of_degree_one.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/small_primes_of_degree_one.py
    a b  
    4848    sage: all(P.residue_class_degree() == 1 for P in Ps)
    4949    True
    5050
    51     In the next two examples, relative residue class degrees are not yet
    52     implemented, but we can check that the absolute norms are in fact prime.
     51    The next two examples are for relative number fields.
    5352
    5453    sage: L.<b> = F.extension(x^3 - a, 'b')
    5554    sage: Ps = L.primes_of_degree_one_list(3)
    5655    sage: Ps # random
    5756    [Fractional ideal (17, b - 5), Fractional ideal (23, b - 4), Fractional ideal (31, b - 2)]
    58     sage: [ P.norm().norm() for P in Ps ] # random
     57    sage: [ P.absolute_norm() for P in Ps ] # random
    5958    [17, 23, 31]
    60     sage: all(ZZ(P.norm().norm()).is_prime() for P in Ps)
     59    sage: all(ZZ(P.absolute_norm()).is_prime() for P in Ps)
    6160    True
    6261    sage: all(P.residue_class_degree() == 1 for P in Ps)
    63     Traceback (most recent call last):
    64     ...
    65     NotImplementedError...
    66 
     62    True
    6763    sage: M.<c> = NumberField(x^2 - x*b^2 + b, 'c')
    6864    sage: Ps = M.primes_of_degree_one_list(3)
    6965    sage: Ps # random
    7066    [Fractional ideal (17, c - 2), Fractional ideal (c - 1), Fractional ideal (41, c + 15)]
    71     sage: [ P.norm().norm().norm() for P in Ps ] # random
     67    sage: [ P.absolute_norm() for P in Ps ] # random
    7268    [17, 31, 41]
    73     sage: all(ZZ(P.norm().norm().norm()).is_prime() for P in Ps)
     69    sage: all(ZZ(P.absolute_norm()).is_prime() for P in Ps)
    7470    True
    7571    sage: all(P.residue_class_degree() == 1 for P in Ps)
    76     Traceback (most recent call last):
    77     ...
    78     NotImplementedError...
     72    True
    7973
    8074AUTHOR:
    8175    -- Nick Alexander
  • sage/rings/number_field/totallyreal_rel.py

    diff -r 09a04286d37c -r ed260fded06c sage/rings/number_field/totallyreal_rel.py
    a b  
    750750            K = F.extension(Fx([-1,1,1]), 'tK')
    751751            Kabs = K.absolute_field('tKabs')
    752752            Kabs_pari = pari(Kabs.defining_polynomial())
    753             d = K.disc()
     753            d = K.absolute_discriminant()
    754754            if abs(d) <= B:
    755755                ng = Kabs_pari.polredabs()
    756756                ind = bisect.bisect_left(S, [d,ng])
     
    762762                K = F.extension(f, 'tK')
    763763                Kabs = K.absolute_field('tKabs')
    764764                Kabs_pari = pari(Kabs.defining_polynomial())
    765                 d = K.disc()
     765                d = K.absolute_discriminant()
    766766                if abs(d) <= B:
    767767                    ng = Kabs_pari.polredabs()
    768768                    ind = bisect.bisect_left(S, [d,ng])