Ticket #1863: 1863.patch

File 1863.patch, 1.3 KB (added by mhansen, 11 years ago)
  • sage/rings/polynomial/multi_polynomial.pyx

    # HG changeset patch
    # User Martin Albrecht <malb@informatik.uni-bremen.de>
    # Date 1206974420 25200
    # Node ID f3da27e25c165489232bf7644ba012c9f4f2d98e
    # Parent  b473c2b22af9aea4061d9c1b5a6d6a513c58d607
    implement f.change_ring for f \in multivariate polynomial ring (fixes #1863)
    
    diff -r b473c2b22af9 -r f3da27e25c16 sage/rings/polynomial/multi_polynomial.pyx
    a b cdef class MPolynomial(CommutativeRingEl 
    524524                raise TypeError, "Variable index %d must be < parent(self).ngens()."%var
    525525        else:
    526526            raise TypeError, "Parameter var must be either a variable, a string or an integer."
     527
     528    def change_ring(self, R):
     529        """
     530        Return a copy of this polynomial but with coefficients in R,
     531        if at all possible.
    527532           
     533        INPUT:
     534            R -- a ring
     535   
     536        EXAMPLES:
     537            sage: R.<x,y> = QQ[]
     538            sage: f = x^3 + 3/5*y + 1
     539            sage: f.change_ring(GF(7))
     540            x^3 + 2*y + 1
     541        """
     542        P = self._parent
     543        P = P.change_ring(R)
     544        return P(self)
     545           
    528546cdef remove_from_tuple(e, int ind):
    529547    w = list(e)
    530548    del w[ind]