diff --git a/src/sage/schemes/generic/divisor.py b/src/sage/schemes/generic/divisor.py index c6d99b12204..fc2fb77a2a7 100644 --- a/src/sage/schemes/generic/divisor.py +++ b/src/sage/schemes/generic/divisor.py @@ -121,6 +121,29 @@ def is_Divisor(x): class Divisor_generic(FormalSum): r""" A Divisor. + + TESTS:: + + sage: E = EllipticCurve([1, 2]) + sage: P = E(-1, 0) + sage: Q = E(1, 2) + sage: Pd = E.divisor(P) + sage: Qd = E.divisor(Q) + sage: Pd + Qd == Qd + Pd + True + sage: Pd != Qd + True + sage: C = EllipticCurve([2, 1]) + sage: R = C(1, 2) + sage: Rd = C.divisor(R) + sage: Qd == Rd + False + sage: Rd == Qd + False + sage: Qd == (2 * (Qd * 1/2)) + True + sage: Qd == 1/2 * Qd + False """ def __init__(self, v, parent, check=True, reduce=True): @@ -363,14 +386,15 @@ def _repr_(self): """ return repr_lincomb([(tuple(I.gens()), c) for c, I in self]) - def support(self): + def support(self) -> list: """ Return the support of this divisor, which is the set of points that occur in this divisor with nonzero coefficients. EXAMPLES:: - sage: x,y = AffineSpace(2, GF(5), names='xy').gens() + sage: A = AffineSpace(2, GF(5), names='xy') + sage: x, y = A.gens() sage: C = Curve(y^2 - x^9 - x) sage: pts = C.rational_points(); pts [(0, 0), (2, 2), (2, 3), (3, 1), (3, 4)] diff --git a/src/sage/schemes/generic/divisor_group.py b/src/sage/schemes/generic/divisor_group.py index 5dfd66a1bb9..e0db3b54c6b 100644 --- a/src/sage/schemes/generic/divisor_group.py +++ b/src/sage/schemes/generic/divisor_group.py @@ -190,6 +190,36 @@ def _element_constructor_(self, x, check=True, reduce=True): else: return Divisor_generic([(self.base_ring()(1), x)], check=False, reduce=False, parent=self) + def _coerce_map_from_(self, other): + r""" + Return if there is a coercion map from ``other`` to ``self``. + + There is a coercion from another divisor group if there is + a coercion map from the schemes and there is a coercion map from + the base rings. + + TESTS:: + + sage: C = EllipticCurve([2, 1]) + sage: E = EllipticCurve([1, 2]) + sage: C.divisor_group()._coerce_map_from_(E.divisor_group()) + False + sage: E.divisor_group()._coerce_map_from_(C.divisor_group()) + False + sage: E.divisor_group()._coerce_map_from_(E.divisor_group()) + True + sage: C.divisor_group()._coerce_map_from_(C.divisor_group()) + True + sage: D = 1/2 * E.divisor(E(1, 2)) + sage: D.parent()._coerce_map_from_(E.divisor_group()) + True + sage: E.divisor_group()._coerce_map_from_(D.parent()) + False + """ + return (isinstance(other, DivisorGroup_generic) + and self.scheme().has_coerce_map_from(other.scheme()) + and super()._coerce_map_from_(other)) + def scheme(self): r""" Return the scheme supporting the divisors. diff --git a/src/sage/structure/formal_sum.py b/src/sage/structure/formal_sum.py index f8f9b4d16de..93f65c1f0e5 100644 --- a/src/sage/structure/formal_sum.py +++ b/src/sage/structure/formal_sum.py @@ -95,6 +95,12 @@ def __init__(self, x, parent=None, check=True, reduce=True): - ``reduce`` -- reduce (default: ``True``) if ``False``, do not combine common terms + .. WARNING:: + + Setting ``reduce`` to ``False`` can cause issues when comparing + equal sums where terms are not combined in the same way (e.g. + `2x + 3x` and `4x + 1x` will compare as not equal). + EXAMPLES:: sage: FormalSum([(1,2/3), (3,2/3), (-5, 7)]) @@ -230,8 +236,19 @@ def _richcmp_(self, other, op): True sage: a == 0 # 0 is coerced into a.parent()(0) False + + TESTS:: + + sage: a = FormalSum([(1, 3), (2, 5)]) + sage: b = FormalSum([(2, 5), (1, 3)]) + sage: a == b + True + sage: b == a + True """ - return richcmp(self._data, other._data, op) + self_data = [(c, x) for (x, c) in sorted(self._data, key=str)] + other_data = [(c, x) for (x, c) in sorted(other._data, key=str)] + return richcmp(self_data, other_data, op) def _neg_(self): """