From 14e97111046dfc2500edfdb85b22908b801b766f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 14 Dec 2023 17:00:34 +0100 Subject: [PATCH 1/2] fixing one bug in the use of valuation --- src/sage/categories/discrete_valuation.py | 11 ++++++++++- src/sage/modules/with_basis/indexed_element.pyx | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/sage/categories/discrete_valuation.py b/src/sage/categories/discrete_valuation.py index 4bb61a5aa67..2be3e79e12b 100644 --- a/src/sage/categories/discrete_valuation.py +++ b/src/sage/categories/discrete_valuation.py @@ -147,22 +147,31 @@ def quo_rem(self, other): Return the quotient and remainder for Euclidean division of ``self`` by ``other``. - TESTS:: + EXAMPLES:: sage: R. = GF(5)[[]] sage: (q^2 + q).quo_rem(q) (1 + q, 0) sage: (q + 1).quo_rem(q^2) (0, 1 + q) + + TESTS:: + sage: q.quo_rem(0) Traceback (most recent call last): ... ZeroDivisionError: Euclidean division by the zero element not defined + sage: L = PowerSeriesRing(QQ, 't') + sage: t = L.gen() + sage: F = algebras.Free(L, ['A', 'B']) + sage: A, B = F.gens() + sage: f = t*A+t**2*B/2 """ if not other: raise ZeroDivisionError("Euclidean division by the zero element not defined") P = self.parent() + other = P(other) if self.valuation() >= other.valuation(): return P(self / other), P.zero() else: diff --git a/src/sage/modules/with_basis/indexed_element.pyx b/src/sage/modules/with_basis/indexed_element.pyx index db2ff9ee4a5..2d64322207b 100644 --- a/src/sage/modules/with_basis/indexed_element.pyx +++ b/src/sage/modules/with_basis/indexed_element.pyx @@ -27,6 +27,9 @@ from sage.misc.superseded import deprecation from sage.typeset.ascii_art import AsciiArt, empty_ascii_art, ascii_art from sage.typeset.unicode_art import UnicodeArt, empty_unicode_art, unicode_art from sage.data_structures.blas_dict cimport add, negate, scal, axpy +from sage.categories.fields import Fields + +_Fields = Fields() cdef class IndexedFreeModuleElement(ModuleElement): @@ -958,6 +961,12 @@ cdef class IndexedFreeModuleElement(ModuleElement): Traceback (most recent call last): ... TypeError: unsupported operand type(s) for /: 'str' and 'CombinatorialFreeModule_with_category.element_class' + + sage: L = LazyPowerSeriesRing(QQ, 't') + sage: t = L.gen() + sage: F = algebras.Free(L, ['A', 'B']) + sage: A, B = F.gens() + sage: f = t*A + t**2*B/2 """ if not isinstance(left, IndexedFreeModuleElement): return NotImplemented @@ -966,7 +975,7 @@ cdef class IndexedFreeModuleElement(ModuleElement): F = self._parent B = self.base_ring() D = self._monomial_coefficients - if not B.is_field(): + if B not in _Fields: return type(self)(F, {k: c._divide_if_possible(x) for k, c in D.items()}) From c74f555f77cb5be539e69489c0fae4adf47eff4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 19 Dec 2023 09:40:55 +0100 Subject: [PATCH 2/2] suggested detail --- src/sage/modules/with_basis/indexed_element.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sage/modules/with_basis/indexed_element.pyx b/src/sage/modules/with_basis/indexed_element.pyx index 2d64322207b..f366fe1bdf1 100644 --- a/src/sage/modules/with_basis/indexed_element.pyx +++ b/src/sage/modules/with_basis/indexed_element.pyx @@ -27,9 +27,7 @@ from sage.misc.superseded import deprecation from sage.typeset.ascii_art import AsciiArt, empty_ascii_art, ascii_art from sage.typeset.unicode_art import UnicodeArt, empty_unicode_art, unicode_art from sage.data_structures.blas_dict cimport add, negate, scal, axpy -from sage.categories.fields import Fields - -_Fields = Fields() +from sage.categories.modules import _Fields cdef class IndexedFreeModuleElement(ModuleElement):