Skip to content

Commit 3b8ae11

Browse files
committed
Combined with change_ring() in multi_polynomial_element.py
1 parent 3688c18 commit 3b8ae11

File tree

2 files changed

+21
-39
lines changed

2 files changed

+21
-39
lines changed

src/sage/rings/polynomial/multi_polynomial.pyx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,23 +841,29 @@ cdef class MPolynomial(CommutativePolynomial):
841841

842842
def change_ring(self, R):
843843
r"""
844-
Return a copy of this polynomial but with coefficients in ``R``,
845-
if at all possible.
844+
Return this polynomial with coefficients converted to ``R``.
846845
847846
INPUT:
848847
849-
- ``R`` -- a ring or morphism.
848+
- ``R`` -- a ring or morphism; if a morphism, the coefficients
849+
are mapped to the codomain of ``R``
850+
851+
OUTPUT: a new polynomial with the base ring changed to ``R``.
850852
851853
EXAMPLES::
852854
853855
sage: R.<x,y> = QQ[]
854856
sage: f = x^3 + 3/5*y + 1
855857
sage: f.change_ring(GF(7))
856858
x^3 + 2*y + 1
859+
sage: g = x^2 + 5*y
860+
sage: g.change_ring(GF(5))
861+
x^2
857862
858863
::
859864
860-
sage: R.<x,y> = GF(9,'a')[] # needs sage.rings.finite_rings
865+
sage: # needs sage.rings.finite_rings
866+
sage: R.<x,y> = GF(9,'a')[]
861867
sage: (x+2*y).change_ring(GF(3))
862868
x - y
863869
@@ -870,12 +876,22 @@ cdef class MPolynomial(CommutativePolynomial):
870876
sage: f.change_ring(K.embeddings(CC)[1])
871877
x^2 + (-0.500000000000000 - 0.866025403784438*I)*y
872878
879+
::
880+
881+
sage: # needs sage.rings.number_field
882+
sage: K.<w> = CyclotomicField(5)
883+
sage: R.<x,y> = K[]
884+
sage: f = x^2 + w*y
885+
sage: f.change_ring(K.embeddings(QQbar)[1])
886+
x^2 + (-0.8090169943749474? + 0.5877852522924731?*I)*y
887+
873888
TESTS:
874889
875890
Check that :issue:`25022` is fixed::
876891
892+
sage: # needs sage.rings.number_field sage.symbolic
877893
sage: K.<x,y> = ZZ[]
878-
sage: (x*y).change_ring(SR).monomials() # needs sage.rings.number_field sage.symbolic
894+
sage: (x*y).change_ring(SR).monomials()
879895
[x*y]
880896
881897
Check that :issue:`36832` is fixed::

src/sage/rings/polynomial/multi_polynomial_element.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -412,40 +412,6 @@ def __rpow__(self, n):
412412
def element(self):
413413
return self.__element
414414

415-
def change_ring(self, R):
416-
r"""
417-
Change the base ring of this polynomial to ``R``.
418-
419-
INPUT:
420-
421-
- ``R`` -- ring or morphism.
422-
423-
OUTPUT: a new polynomial converted to ``R``.
424-
425-
EXAMPLES::
426-
427-
sage: R.<x,y> = QQ[]
428-
sage: f = x^2 + 5*y
429-
sage: f.change_ring(GF(5))
430-
x^2
431-
432-
::
433-
434-
sage: # needs sage.rings.number_field
435-
sage: K.<w> = CyclotomicField(5)
436-
sage: R.<x,y> = K[]
437-
sage: f = x^2 + w*y
438-
sage: f.change_ring(K.embeddings(QQbar)[1])
439-
x^2 + (-0.8090169943749474? + 0.5877852522924731?*I)*y
440-
"""
441-
if isinstance(R, Morphism):
442-
#if we're given a hom of the base ring extend to a poly hom
443-
if R.domain() == self.base_ring():
444-
R = self.parent().hom(R, self.parent().change_ring(R.codomain()))
445-
return R(self)
446-
else:
447-
return self.parent().change_ring(R)(self)
448-
449415

450416
class MPolynomial_polydict(Polynomial_singular_repr, MPolynomial_element):
451417
r"""

0 commit comments

Comments
 (0)