Skip to content

Commit b812c79

Browse files
committed
Use coercion instead of conversion
1 parent 4c3674d commit b812c79

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/sage/rings/polynomial/multi_polynomial_ideal.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
from sage.rings.integer_ring import ZZ
249249
from sage.rings.noncommutative_ideals import Ideal_nc
250250
from sage.rings.qqbar_decorators import handle_AA_and_QQbar
251+
from sage.structure.element import parent
251252
from sage.structure.richcmp import (op_EQ, op_GE, op_GT, op_LE, op_LT, op_NE,
252253
rich_to_bool, richcmp_method)
253254
from sage.structure.sequence import Sequence
@@ -4972,8 +4973,12 @@ def reduce(self, f):
49724973
49734974
sage: I.reduce(1)
49744975
1
4975-
sage: I.reduce(pi.n()) # unfortunate side effect
4976-
245850922/78256779
4976+
sage: I.reduce(1r)
4977+
1
4978+
sage: I.reduce(pi.n())
4979+
Traceback (most recent call last):
4980+
...
4981+
TypeError: element belong to Real Field with 53 bits of precision, cannot coerce to Multivariate Polynomial Ring in x, y over Rational Field
49774982
"""
49784983
try:
49794984
strat = self._groebner_strategy()
@@ -4982,7 +4987,10 @@ def reduce(self, f):
49824987
pass
49834988

49844989
gb = self.groebner_basis()
4985-
return self.ring()(f).reduce(gb)
4990+
R = self.ring()
4991+
if not R.has_coerce_map_from(parent(f)):
4992+
raise TypeError(f"element belong to {parent(f)}, cannot coerce to {R}")
4993+
return R(f).reduce(gb)
49864994

49874995
def _contains_(self, f):
49884996
r"""

0 commit comments

Comments
 (0)