Skip to content

Commit

Permalink
Trac #30695: Padic slice method fails on exact zeros for certain inputs
Browse files Browse the repository at this point in the history
Using version 9.2.beta14 of Sage, the p-adic `slice` method fails on
exact zeros, for input of j=None or j=infinity (where j is the 'upper-
bound' of the slice). [[br]]
For example:
{{{
sage: F=Qp(3)
sage: a=F(0)
sage: a.slice(0,None)
------------------------------------------------------------------------
---
SignError                                 Traceback (most recent call
last)
<ipython-input-4-d78676a03c88> in <module>
----> 1 a.slice(Integer(0),None)

~/workspace/padic_project/sage/local/lib/python3.7/site-
packages/sage/rings/padics/local_generic_element.pyx in
sage.rings.padics.local_generic_element.LocalGenericElement.slice
(build/cythonized/sage/rings/padics/local_generic_element.c:3430)()
    329         if self.parent().is_field():
    330             start -= self.valuation()
--> 331             stop -= self.valuation()
    332
    333         # make sure that start and stop are non-negative

~/workspace/padic_project/sage/local/lib/python3.7/site-
packages/sage/structure/element.pyx in
sage.structure.element.Element.__sub__
(build/cythonized/sage/structure/element.c:11514)()
   1353         cdef int cl = classify_elements(left, right)
   1354         if HAVE_SAME_PARENT(cl):
-> 1355             return (<Element>left)._sub_(right)
   1356         if BOTH_ARE_ELEMENT(cl):
   1357             return coercion_model.bin_op(left, right, sub)

~/workspace/padic_project/sage/local/lib/python3.7/site-
packages/sage/structure/element.pyx in
sage.structure.element.ModuleElement._sub_
(build/cythonized/sage/structure/element.c:15803)()
   2386         return coercion_model.bin_op(self, n, add)
   2387
-> 2388     cpdef _sub_(self, other):
   2389         """
   2390         Default implementation of subtraction using addition and

~/workspace/padic_project/sage/local/lib/python3.7/site-
packages/sage/rings/infinity.py in _sub_(self, other)
    426                 raise SignError("cannot subtract unsigned
infinities")
    427             elif self._sign == other._sign:
--> 428                 raise SignError("cannot add infinity to minus
infinity")
    429         return self
    430

SignError: cannot add infinity to minus infinity

sage: a.slice(0,infinity)
------------------------------------------------------------------------
---
SignError                                 Traceback (most recent call
last)
<ipython-input-5-98f115011f22> in <module>
----> 1 a.slice(Integer(0),infinity)

~/workspace/padic_project/sage/local/lib/python3.7/site-
packages/sage/rings/padics/local_generic_element.pyx in
sage.rings.padics.local_generic_element.LocalGenericElement.slice
(build/cythonized/sage/rings/padics/local_generic_element.c:3430)()
    329         if self.parent().is_field():
    330             start -= self.valuation()
--> 331             stop -= self.valuation()
    332
    333         # make sure that start and stop are non-negative

~/workspace/padic_project/sage/local/lib/python3.7/site-
packages/sage/structure/element.pyx in
sage.structure.element.Element.__sub__
(build/cythonized/sage/structure/element.c:11514)()
   1353         cdef int cl = classify_elements(left, right)
   1354         if HAVE_SAME_PARENT(cl):
-> 1355             return (<Element>left)._sub_(right)
   1356         if BOTH_ARE_ELEMENT(cl):
   1357             return coercion_model.bin_op(left, right, sub)

~/workspace/padic_project/sage/local/lib/python3.7/site-
packages/sage/structure/element.pyx in
sage.structure.element.ModuleElement._sub_
(build/cythonized/sage/structure/element.c:15803)()
   2386         return coercion_model.bin_op(self, n, add)
   2387
-> 2388     cpdef _sub_(self, other):
   2389         """
   2390         Default implementation of subtraction using addition and

~/workspace/padic_project/sage/local/lib/python3.7/site-
packages/sage/rings/infinity.py in _sub_(self, other)
    426                 raise SignError("cannot subtract unsigned
infinities")
    427             elif self._sign == other._sign:
--> 428                 raise SignError("cannot add infinity to minus
infinity")
    429         return self
    430

SignError: cannot add infinity to minus infinity
}}}

URL: https://trac.sagemath.org/30695
Reported by: gh-n-vi
Ticket author(s): Noa Viner
Reviewer(s): Julian Rüth
  • Loading branch information
Release Manager committed Feb 16, 2022
2 parents ff40ba0 + 2dcddab commit 15f2fed
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/sage/rings/padics/local_generic_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,24 @@ cdef class LocalGenericElement(CommutativeRingElement):
sage: a.slice(None, 5, None)
2*5^2 + 2*5^3 + O(5^5)
Verify that :trac:`30695` has been fixed::
sage: F=Qp(3)
sage: a=F(0)
sage: a.slice(0,None)
0
"""

if k is None:
k = 1
if k <= 0:
raise ValueError("slice step must be positive")
if i is None:
i = self.valuation()
if j is None or j is infinity:
j = self.precision_absolute()
if k is None:
k = 1

if k<=0:
raise ValueError("slice step must be positive")
if j is infinity:
return self.parent()(0)

start = i
stop = j
Expand Down

0 comments on commit 15f2fed

Please sign in to comment.