Skip to content

Commit a7f5913

Browse files
committed
refactor coercion maps
1 parent 95b8190 commit a7f5913

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/sage/rings/polynomial/integer_valued_polynomials.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ def __init__(self, R):
8383
cat = Algebras(R).Commutative().WithBasis()
8484
Parent.__init__(self, base=R, category=cat.WithRealizations())
8585

86-
S = self.S()
87-
B = self.B()
88-
B.module_morphism(S._from_binomial_basis, codomain=S).register_as_coercion()
89-
S.module_morphism(B._from_shifted_basis, codomain=B).register_as_coercion()
90-
9186
_shorthands = ["B", "S"]
9287

9388
def _repr_(self) -> str:
@@ -555,6 +550,11 @@ def _element_constructor_(self, x):
555550
if P is not self.base_ring():
556551
return self.element_class(self, x.monomial_coefficients())
557552

553+
if isinstance(P, IntegerValuedPolynomialRing.Binomial):
554+
phi = P.module_morphism(self._from_binomial_basis,
555+
codomain=self)
556+
return phi(x)
557+
558558
# ok, not a integer-valued polynomial ring element
559559
R = self.base_ring()
560560
# coercion via base ring
@@ -655,6 +655,8 @@ def _coerce_map_from_(self, R):
655655
# that coerces in:
656656
if isinstance(R, IntegerValuedPolynomialRing.Shifted):
657657
return self.base_ring().has_coerce_map_from(R.base_ring())
658+
if isinstance(R, IntegerValuedPolynomialRing.Binomial):
659+
return self.base_ring().has_coerce_map_from(R.base_ring())
658660
return self.base_ring().has_coerce_map_from(R)
659661

660662
def _poly(self, i):
@@ -991,6 +993,11 @@ def _element_constructor_(self, x):
991993
if P is not self.base_ring():
992994
return self.element_class(self, x.monomial_coefficients())
993995

996+
if isinstance(P, IntegerValuedPolynomialRing.Shifted):
997+
psi = P.module_morphism(self._from_shifted_basis,
998+
codomain=self)
999+
return psi(x)
1000+
9941001
# ok, not a integer-valued polynomial ring element
9951002
R = self.base_ring()
9961003
# coercion via base ring
@@ -1087,6 +1094,8 @@ def _coerce_map_from_(self, R):
10871094
# that coerces in:
10881095
if isinstance(R, IntegerValuedPolynomialRing.Binomial):
10891096
return self.base_ring().has_coerce_map_from(R.base_ring())
1097+
if isinstance(R, IntegerValuedPolynomialRing.Shifted):
1098+
return self.base_ring().has_coerce_map_from(R.base_ring())
10901099
return self.base_ring().has_coerce_map_from(R)
10911100

10921101
def _poly(self, i):

0 commit comments

Comments
 (0)