# 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 
119  119  alpha = self.__K(alpha) 
120  120  f = alpha.polynomial('x') 
121  121  # 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)) 
123  126  # Now g is a relative polynomial that defines this element. 
124  127  # This g is a polynomial in a pari variable x with 
125  128  # coefficients polynomials in a variable y. 
diff r d7036e297657 r 7b1bceb5a2dc sage/rings/number_field/number_field.py
a

b

class NumberField_absolute(NumberField_g 
2911  2911  names[0] generators K and names[1] QQ(alpha). 
2912  2912  
2913  2913  OUTPUT: 
2914   K  relative number field, map from K to self, 
2915   map from self to K. 
 2914  K  relative number field 
2916  2915  
2917  2916  Also, \code{K.structure()} returns from_K and to_K, where 
2918  2917  from_K is an isomorphism from K to self and to_K is an isomorphism 
… 
… 
class NumberField_relative(NumberField_g 
3311  3310  2/3 
3312  3311  sage: k(m.0^4) 
3313  3312  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 
3314  3321  """ 
3315  3322  if isinstance(x, number_field_element.NumberFieldElement): 
3316  3323  P = x.parent() 
… 
… 
class NumberField_relative(NumberField_g 
4006  4013  names  name of generator for output field K. 
4007  4014  
4008  4015  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. 
4011  4021  
4012  4022  EXAMPLES: 
4013  4023  sage: K.<a,b> = NumberField([x^4 + 3, x^2 + 2]); K 
diff r d7036e297657 r 7b1bceb5a2dc sage/rings/number_field/number_field_element.pyx
a

b

cdef class NumberFieldElement(FieldEleme 
1551  1551  return self.number_field()._pari_().elementval(self._pari_(), P._pari_prime) 
1552  1552  
1553  1553  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^32, '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  """ 
1554  1563  K = self.number_field() 
1555  1564  E = L.embeddings(K) 
1556  1565  if len(E) == 0: 
… 
… 
cdef class NumberFieldElement(FieldEleme 
1559  1568  return self._matrix_over_base_morphism(phi) 
1560  1569  
1561  1570  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^52) 
 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  """ 
1562  1584  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  
1563  1599  alpha = L.primitive_element() 
1564  1600  beta = phi(alpha) 
1565  1601  K = phi.codomain() 