Skip to content

Commit

Permalink
sagemathgh-36882: fixing one bug in the use of valuation
Browse files Browse the repository at this point in the history
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: sagemath#36882
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Dec 25, 2023
2 parents 854e573 + c74f555 commit be5cfaa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=2389d2b093493c568deda190ffc326ff2b835169
md5=545e80b50deb4efa46f14d0a543ba98f
cksum=169905223
sha1=49a633dd8ed1ed4dcff9804c91e655ddf747660f
md5=804aaaded8e8427776cb2fa900a45404
cksum=1214543131
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
73e52a419812253c3c3ce72bab7f1a5ddf4c0461
7cddb2e5880160a2d84c815ffa62eb5bf328bd39
11 changes: 10 additions & 1 deletion src/sage/categories/discrete_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.<q> = 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:
Expand Down
9 changes: 8 additions & 1 deletion src/sage/modules/with_basis/indexed_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +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.modules import _Fields


cdef class IndexedFreeModuleElement(ModuleElement):
Expand Down Expand Up @@ -958,6 +959,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
Expand All @@ -966,7 +973,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()})

Expand Down

0 comments on commit be5cfaa

Please sign in to comment.