Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Updating doctests and making sure valuation() returns a Sage Integer …
Browse files Browse the repository at this point in the history
…or oo.
  • Loading branch information
tscrim committed Aug 11, 2022
1 parent 2e4ee87 commit 503ba26
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/sage/rings/lazy_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,9 +2076,10 @@ def valuation(self):
1
sage: (M - M).valuation()
+Infinity
"""
return self._coeff_stream.order()
if isinstance(self._coeff_stream, Stream_zero):
return self._coeff_stream.order()
return ZZ(self._coeff_stream.order())

def _mul_(self, other):
"""
Expand Down Expand Up @@ -3697,8 +3698,10 @@ def valuation(self):
sage: (g*g).valuation()
2*log(2)
"""
if isinstance(self._coeff_stream, Stream_zero):
return self._coeff_stream.order()
from sage.functions.log import log
return log(self._coeff_stream.order())
return log(ZZ(self._coeff_stream.order()))

def _mul_(self, other):
"""
Expand Down
25 changes: 15 additions & 10 deletions src/sage/rings/lazy_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No
sage: L(L(1), valuation=-4)
z^-4
sage: L(1/(1-z), valuation=-4)
z^-4 + z^-3 + z^-2 + z^-1 + 1 + z + z^2 + O(z^3)
z^-4 + z^-3 + z^-2 + O(z^-1)
sage: L(z^-3/(1-z), valuation=-4)
z^-4 + z^-3 + z^-2 + z^-1 + 1 + z + z^2 + O(z^3)
z^-4 + z^-3 + z^-2 + O(z^-1)
sage: L(z^3/(1-z), valuation=-4)
z^-4 + z^-3 + z^-2 + z^-1 + 1 + z + z^2 + O(z^3)
z^-4 + z^-3 + z^-2 + O(z^-1)
sage: L(z^3/(1-z), valuation=0)
1 + z + z^2 + z^3 + z^4 + z^5 + z^6 + O(z^7)
1 + z + z^2 + O(z^3)
sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L(lambda n: 1/(n+1), degree=3)
Expand Down Expand Up @@ -449,7 +449,7 @@ class LazyLaurentSeriesRing(LazySeriesRing):
sage: L.<z> = LazyLaurentSeriesRing(QQ)
sage: 1 / (1 - z)
1 + z + z^2 + z^3 + z^4 + z^5 + z^6 + O(z^7)
1 + z + z^2 + O(z^3)
sage: 1 / (1 - z) == 1 / (1 - z)
True
sage: L in Fields
Expand Down Expand Up @@ -732,7 +732,7 @@ def gens(self):
sage: L.gens()
(z,)
sage: 1/(1 - z)
1 + z + z^2 + z^3 + z^4 + z^5 + z^6 + O(z^7)
1 + z + z^2 + O(z^3)
"""
return tuple([self.gen(n) for n in range(self.ngens())])

Expand Down Expand Up @@ -816,7 +816,7 @@ def some_elements(self):
[0, 1, z,
z^-3 + z^-1 + 2 + z + z^2 + z^3,
z^2 + z^3 + z^4 + z^5 + O(z^6),
z^-3 + z^-2 + z^-1 + 2 + 2*z + 2*z^2 + 2*z^3 + O(z^4),
z^-3 + z^-2 + z^-1 + 2 + 2*z + 2*z^2 + O(z^3),
z^-2 + z^-1 + z + z^2 + z^4 + O(z^5)]
"""
z = self.gen()
Expand Down Expand Up @@ -870,18 +870,23 @@ class options(GlobalOptions):
sage: LLS.<z> = LazyLaurentSeriesRing(QQ)
sage: LLS.options.display_length
7
sage: f = 1/(1-z)
sage: f = 1 / (1 + z)
sage: f
1 + z + z^2 + z^3 + z^4 + z^5 + z^6 + O(z^7)
1 - z + z^2 - z^3 + z^4 - z^5 + z^6 + O(z^7)
sage: LLS.options.display_length = 10
sage: f
1 + z + z^2 + z^3 + z^4 + z^5 + z^6 + z^7 + z^8 + z^9 + O(z^10)
1 - z + z^2 - z^3 + z^4 - z^5 + z^6 - z^7 + z^8 - z^9 + O(z^10)
sage: g = LLS(lambda n: n^2, valuation=-2, degree=5, constant=42)
sage: g
4*z^-2 + z^-1 + z + 4*z^2 + 9*z^3 + 16*z^4 + 42*z^5 + 42*z^6 + 42*z^7 + O(z^8)
sage: h = 1 / (1 - z) # This is exact
sage: h
1 + z + z^2 + O(z^3)
sage: LLS.options.constant_length = 1
sage: g
4*z^-2 + z^-1 + z + 4*z^2 + 9*z^3 + 16*z^4 + 42*z^5 + O(z^6)
sage: h
1 + O(z)
sage: LazyLaurentSeriesRing.options._reset()
sage: LazyLaurentSeriesRing.options.display_length
7
Expand Down
14 changes: 11 additions & 3 deletions src/sage/rings/polynomial/laurent_polynomial.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial):

@coerce_binop
def quo_rem(self, right_r):
"""
r"""
Attempts to divide ``self`` by ``right`` and returns a quotient
``q`` and a remainder ``r`` such that ``self = q*other + r``.
Expand All @@ -1352,7 +1352,8 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial):
sage: (t^-2 + 3 + t).quo_rem(t^-4)
(t^2 + 3*t^4 + t^5, 0)
sage: num, den = t^-2 + t, t^-2 + 1
sage: num = t^-2 + t
sage: den = t^-2 + 1
sage: q, r = num.quo_rem(den)
sage: num == q * den + r
True
Expand All @@ -1361,11 +1362,18 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial):
Check that :trac:`34330` is fixed::
sage: num, den = t^-2 + 3 + t, t^-4 + t
sage: num = t^-2 + 3 + t
sage: den = t^-4 + t
sage: q, r = num.quo_rem(den); q, r
(0, t^-2 + 3 + t)
sage: num == q * den + r
True
sage: num = 2*t^-4 + t^-3 + t^-2 + 2*t + 2*t^2
sage: q, r = num.quo_rem(den); q, r
(2 + 2*t, -t^-3 + t^-2)
sage: num == q * den + r
True
"""
cdef LaurentPolynomial_univariate right = <LaurentPolynomial_univariate> right_r
q, r = self.__u.quo_rem(right.__u)
Expand Down

0 comments on commit 503ba26

Please sign in to comment.