Ticket #1083: craigcitro-1083.patch

File craigcitro-1083.patch, 4.8 KB (added by craigcitro, 12 years ago)
  • sage/rings/number_field/maps.py

    # HG changeset patch
    # User Craig Citro <craigcitro@gmail.com>
    # Date 1201086621 28800
    # Node ID 7b1bceb5a2dc965618a229841cee928f13a1b213
    # Parent  d7036e297657c7ddcde57db96004afa29cc0585a
    Fix trac #1083, and b.matrix(QQ) for b a NumberFieldElement.
    
    diff -r d7036e297657 -r 7b1bceb5a2dc sage/rings/number_field/maps.py
    a b class MapRelativeNumberFieldToRelativeVe 
    119119        alpha = self.__K(alpha)
    120120        f = alpha.polynomial('x')
    121121        # f is the absolute polynomial that defines this number field element
    122         g = self.__rnf.rnfeltabstorel(pari(f))
     122        if self.__K.degree() == 1:
     123            g = -1*self.__rnf[0][0]*f[1] + f[0]
     124        else:
     125            g = self.__rnf.rnfeltabstorel(pari(f))
    123126        # Now g is a relative polynomial that defines this element.
    124127        # This g is a polynomial in a pari variable x with
    125128        # coefficients polynomials in a variable y.
  • sage/rings/number_field/number_field.py

    diff -r d7036e297657 -r 7b1bceb5a2dc sage/rings/number_field/number_field.py
    a b class NumberField_absolute(NumberField_g 
    29112911                     names[0] generators K and names[1] QQ(alpha).
    29122912           
    29132913        OUTPUT:
    2914             K   -- relative number field, map from K to self,
    2915                    map from self to K.
     2914            K   -- relative number field
    29162915
    29172916        Also, \code{K.structure()} returns from_K and to_K, where
    29182917        from_K is an isomorphism from K to self and to_K is an isomorphism
    class NumberField_relative(NumberField_g 
    33113310            2/3
    33123311            sage: k(m.0^4)
    33133312            9
     3313
     3314        TESTS:
     3315            sage: K.<a> = NumberField(ZZ['x'].0^2 + 2, 'a')
     3316            sage: L.<b> = K.extension(ZZ['x'].0 - a, 'b')
     3317            sage: L(a)
     3318            a
     3319            sage: L(b+a)
     3320            2*a
    33143321        """
    33153322        if isinstance(x, number_field_element.NumberFieldElement):
    33163323            P = x.parent()
    class NumberField_relative(NumberField_g 
    40064013            names -- name of generator for output field K.
    40074014           
    40084015        OUTPUT:
    4009             K, from_K, to_K -- relative number field, map from K to self,
    4010                                map from self to K.
     4016            K -- relative number field
     4017
     4018        Also, \code{K.structure()} returns from_K and to_K, where
     4019        from_K is an isomorphism from K to self and to_K is an isomorphism
     4020        from self to K.
    40114021
    40124022        EXAMPLES:
    40134023            sage: K.<a,b> = NumberField([x^4 + 3, x^2 + 2]); K
  • sage/rings/number_field/number_field_element.pyx

    diff -r d7036e297657 -r 7b1bceb5a2dc sage/rings/number_field/number_field_element.pyx
    a b cdef class NumberFieldElement(FieldEleme 
    15511551        return self.number_field()._pari_().elementval(self._pari_(), P._pari_prime)
    15521552
    15531553    def _matrix_over_base(self, L):
     1554        """
     1555        Return the matrix of self over the base field L.
     1556
     1557        EXAMPLES:
     1558            sage: K.<a> = NumberField(ZZ['x'].0^3-2, 'a')
     1559            sage: L.<b> = K.extension(ZZ['x'].0^2+3, 'b')
     1560            sage: L(a)._matrix_over_base(K) == L(a).matrix()
     1561            True
     1562        """
    15541563        K = self.number_field()
    15551564        E = L.embeddings(K)
    15561565        if len(E) == 0:
    cdef class NumberFieldElement(FieldEleme 
    15591568        return self._matrix_over_base_morphism(phi)
    15601569
    15611570    def _matrix_over_base_morphism(self, phi):
     1571        """
     1572        Return the matrix of self over a specified base,
     1573        where phi gives a map from the specified base to
     1574        self.parent().
     1575
     1576        EXAMPLES:
     1577            sage: F.<alpha> = NumberField(ZZ['x'].0^5-2)
     1578            sage: h = Hom(QQ,F)([1])
     1579            sage: alpha._matrix_over_base_morphism(h) == alpha.matrix()
     1580            True
     1581            sage: alpha._matrix_over_base_morphism(h) == alpha.matrix(QQ)
     1582            True
     1583        """
    15621584        L = phi.domain()
     1585
     1586        ## the code below doesn't work if the morphism is
     1587        ## over QQ, since QQ.primitive_element() doesn't
     1588        ## make sense
     1589        if L is QQ:
     1590            K = phi.codomain()
     1591            if K != self.number_field():
     1592                raise ValueError, "codomain of phi must be parent of self"
     1593            ## the variable name is irrelevant below, because the
     1594            ## matrix is over QQ
     1595            F = K.absolute_field('alpha')
     1596            from_f, to_F = F.structure()
     1597            return to_F(self).matrix()
     1598       
    15631599        alpha = L.primitive_element()
    15641600        beta = phi(alpha)
    15651601        K = phi.codomain()