Ticket #2348: final_numberfields_gap.patch

File final_numberfields_gap.patch, 3.2 KB (added by SimonKing, 14 years ago)

The patch is relative to sage-2.10.3.rc0 and replaces the previous patches. I think it provides a solution of the problem

  • sage/matrix/matrix1.pyx

    # HG changeset patch
    # User Simon King <king@mathematik.uni-jena.de>
    # Date 1204414950 -3600
    # Node ID c18ec6a82eae11e2a605f6a3e566e8113a2fe0f3
    # Parent  5db8b4f0c24b27fee4b5287154af7a7b374d4d34
    Implementing the gap interface for number fields
    
    diff -r 5db8b4f0c24b -r c18ec6a82eae sage/matrix/matrix1.pyx
    a b cdef class Matrix(matrix0.Matrix): 
    6565            for j from 0 <= j < self._ncols:
    6666                tmp.append(self.get_unsafe(i,j)._gap_init_())
    6767            v.append( '[%s]'%(','.join(tmp)) )
    68         return '[%s]'%(','.join(v))
     68        # It is needed to multiply with 'One(...)', because
     69        # otherwise the result would not be a gap matrix
     70        return '[%s]*One(%s)'%(','.join(v),self.base_ring()._gap_init_())
    6971
    7072    def _maxima_init_(self):
    7173        """
  • sage/rings/number_field/number_field.py

    diff -r 5db8b4f0c24b -r c18ec6a82eae sage/rings/number_field/number_field.py
    a b class NumberField_generic(number_field_b 
    15811581        """
    15821582        return 0
    15831583
     1584    def _gap_init_(self):
     1585        """
     1586        Create a gap object representing self and return its name
     1587        """
     1588        if not self.is_absolute():
     1589            raise NotImplementedError, "Currently, only simple algebraic extensions are possible in gap"
     1590        if self.__dict__.has_key('_gap_name_'): # if it was constructed before
     1591            return self.__dict__['_gap_name_']
     1592        G = sage.interfaces.gap.gap
     1593        varname = G._next_var_name()
     1594        G.eval('%s := Indeterminate(%s,"x");;'%(varname,self.base_field()._gap_init_()))
     1595        mp = self.polynomial().__repr__().replace('x',varname)
     1596        OUTname = G._next_var_name()
     1597        G.eval('%s := AlgebraicExtension(%s,%s);;'%(OUTname,self.base_field()._gap_init_(),mp))
     1598        self.__dict__['_gap_name_'] = OUTname
     1599        return OUTname
     1600
    15841601    def class_group(self, proof=None, names='c'):
    15851602        r"""
    15861603        Return the class group of the ring of integers of this number field.
  • sage/rings/number_field/number_field_element.pyx

    diff -r 5db8b4f0c24b -r c18ec6a82eae sage/rings/number_field/number_field_element.pyx
    a b cdef class NumberFieldElement(FieldEleme 
    355355            \zeta_{12}^{2} - \zeta_{12} - 1
    356356        """
    357357        return self.polynomial()._latex_(name=self.number_field().latex_variable_name())
     358
     359    def _gap_init_(self):
     360        """
     361        Return gap string representation of self.
     362        """
     363        s = self.__repr__()
     364        if self.parent().__dict__.has_key('_gap_name_'):
     365            return s.replace(str(self.parent().gen()),'GeneratorsOfField(%s)[1]'%self.parent()._gap_init_())
     366        self.parent()._gap_init_()
     367        return s.replace(str(self.parent().gen()),'GeneratorsOfField(%s)[1]'%self.parent()._gap_init_())
    358368
    359369    def _pari_(self, var='x'):
    360370        raise NotImplementedError, "NumberFieldElement sub-classes must override _pari_"