Skip to content

Commit 5d7d2e3

Browse files
author
Release Manager
committed
gh-36882: fixing one bug in the use of valuation Trying to divide by an integer was failing here: ``` sage: L=PowerSeriesRing(QQ,'t') sage: t=L.gen() sage: F=algebras.Free(L,['A','B','C']) sage: A,B,C=F.gens() sage: f=t*A+t**2*B/2 # BUG HERE ``` and the same for Lazy power series. ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have created tests covering the changes. URL: #36882 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 368efce + c74f555 commit 5d7d2e3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/sage/categories/discrete_valuation.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,31 @@ def quo_rem(self, other):
147147
Return the quotient and remainder for Euclidean division
148148
of ``self`` by ``other``.
149149
150-
TESTS::
150+
EXAMPLES::
151151
152152
sage: R.<q> = GF(5)[[]]
153153
sage: (q^2 + q).quo_rem(q)
154154
(1 + q, 0)
155155
sage: (q + 1).quo_rem(q^2)
156156
(0, 1 + q)
157+
158+
TESTS::
159+
157160
sage: q.quo_rem(0)
158161
Traceback (most recent call last):
159162
...
160163
ZeroDivisionError: Euclidean division by the zero element not defined
161164
165+
sage: L = PowerSeriesRing(QQ, 't')
166+
sage: t = L.gen()
167+
sage: F = algebras.Free(L, ['A', 'B'])
168+
sage: A, B = F.gens()
169+
sage: f = t*A+t**2*B/2
162170
"""
163171
if not other:
164172
raise ZeroDivisionError("Euclidean division by the zero element not defined")
165173
P = self.parent()
174+
other = P(other)
166175
if self.valuation() >= other.valuation():
167176
return P(self / other), P.zero()
168177
else:

src/sage/modules/with_basis/indexed_element.pyx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ from sage.misc.superseded import deprecation
2727
from sage.typeset.ascii_art import AsciiArt, empty_ascii_art, ascii_art
2828
from sage.typeset.unicode_art import UnicodeArt, empty_unicode_art, unicode_art
2929
from sage.data_structures.blas_dict cimport add, negate, scal, axpy
30+
from sage.categories.modules import _Fields
3031

3132

3233
cdef class IndexedFreeModuleElement(ModuleElement):
@@ -958,6 +959,12 @@ cdef class IndexedFreeModuleElement(ModuleElement):
958959
Traceback (most recent call last):
959960
...
960961
TypeError: unsupported operand type(s) for /: 'str' and 'CombinatorialFreeModule_with_category.element_class'
962+
963+
sage: L = LazyPowerSeriesRing(QQ, 't')
964+
sage: t = L.gen()
965+
sage: F = algebras.Free(L, ['A', 'B'])
966+
sage: A, B = F.gens()
967+
sage: f = t*A + t**2*B/2
961968
"""
962969
if not isinstance(left, IndexedFreeModuleElement):
963970
return NotImplemented
@@ -966,7 +973,7 @@ cdef class IndexedFreeModuleElement(ModuleElement):
966973
F = self._parent
967974
B = self.base_ring()
968975
D = self._monomial_coefficients
969-
if not B.is_field():
976+
if B not in _Fields:
970977
return type(self)(F, {k: c._divide_if_possible(x)
971978
for k, c in D.items()})
972979

0 commit comments

Comments
 (0)