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

Commit

Permalink
fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Aug 2, 2021
1 parent ca73f84 commit 5b62ddb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
20 changes: 9 additions & 11 deletions src/sage/rings/lazy_laurent_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2106,25 +2106,23 @@ def _repr_(self):

if not isinstance(self._coeff_stream, CoefficientStream_exact):
m = v + 7 # long enough
elif not self._coeff_stream._constant:
# Just a polynonial, so let that print itself
R = self.parent()._poly_ring
if len(self.parent().variable_names()) == 1:
z = R.gen()
return repr(R.sum(self._coeff_stream[i] * z**i for i in range(v, self._coeff_stream._degree)))
else:
return repr(R.sum(self._coeff_stream[i] for i in range(v, self._coeff_stream._degree)))
else:
m = self._coeff_stream._degree + 3

# Use the polynomial printing
R = self.parent()._poly_ring
if len(self.parent().variable_names()) == 1:
z = R.gen()
ret = repr(R.sum(self._coeff_stream[i] * z**i for i in range(v, m)))
ret = " + ".join([repr(R(self._coeff_stream[i] * z**i)) for i in range(v, m)
if self._coeff_stream[i]])
else:
ret = repr(R.sum(self._coeff_stream[i] for i in range(v, m)))
ret = " + ".join([repr(R(self._coeff_stream[i])) for i in range(v, m)
if self._coeff_stream[i]])

if not ret:
return "0"
# TODO: Better handling when ret == 0 but we have not checked up to the constant term
if isinstance(self._coeff_stream, CoefficientStream_exact) and not self._coeff_stream._constant:
return ret
return ret + ' + ...'


Expand Down
49 changes: 21 additions & 28 deletions src/sage/rings/lazy_laurent_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,41 +578,31 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
sage: X.valuation()
2
sage: def g(i):
....: if i < 0:
....: return 1
....: else:
....: return 1 + sum(k for k in range(i+1))
sage: e = L(g, -5); e
z^-5 + z^-4 + z^-3 + z^-2 + z^-1 + 1 + 2*z + ...
sage: e = L(lambda n: n+1); e
1 + 2*z + 3*z^2 + 4*z^3 + 5*z^4 + 6*z^5 + 7*z^6 + ...
sage: f = e^-1; f
z^5 - z^6 - z^11 + ...
1 + -2*z + z^2 + ...
sage: f.coefficient(10)
0
sage: f[20]
9
sage: f[30]
-219
0
sage: L(valuation=2, constant=1)
z^2 + z^3 + z^4 + ...
sage: L(constant=1)
Traceback (most recent call last):
...
ValueError: you must specify the degree for the polynomial 0
1 + z + z^2 + ...
Alternatively, ``x`` can be a list of elements of the base ring.
Then these elements are read as coefficients of the terms of
degrees starting from the ``valuation``. In this case, ``constant``
may be just an element of the base ring instead of a tuple or can be
simply omitted if it is zero::
sage: f = L([1,2,3,4], -5)
sage: f
z^-5 + 2*z^-4 + 3*z^-3 + 4*z^-2
sage: g = L([1,3,5,7,9], 5, -1)
sage: g
z^5 + 3*z^6 + 5*z^7 + 7*z^8 + 9*z^9 - z^10 - z^11 - z^12 + ...
sage: f = L([1,2,3,4], 1); f
z + 2*z^2 + 3*z^3 + 4*z^4
sage: g = L([1,3,5,7,9], 5, -1); g
z^5 + 3*z^6 + 5*z^7 + 7*z^8 + 9*z^9 + -z^10 + -z^11 + -z^12 + ...
.. TODO::
Expand All @@ -621,9 +611,10 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
if valuation is None:
valuation = 0
assert valuation >= 0, "the valuation of a Taylor series must be positive"

R = self._poly_ring
if x is None:
assert degree is None
coeff_stream = CoefficientStream_uninitialized(self._sparse, valuation)
return self.element_class(self, coeff_stream)

Expand All @@ -640,13 +631,13 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
if not x and not constant:
coeff_stream = CoefficientStream_zero(self._sparse)
else:
if x and valuation:
valuation = valuation - v
if degree is None and not x:
degree = valuation
if x == R.zero():
coeff_stream = CoefficientStream_exact([x], self._sparse, valuation=degree-1, constant=constant)
if not x:
coeff_stream = CoefficientStream_exact([], self._sparse,
valuation=valuation,
degree=degree,
constant=constant)
return self.element_class(self, coeff_stream)

if len(self.variable_names()) == 1:
v = x.valuation()
d = x.degree()
Expand All @@ -656,11 +647,13 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
v = min(p_dict.keys())
d = max(p_dict.keys())
p_list = [p_dict.get(i, 0) for i in range(v, d + 1)]

coeff_stream = CoefficientStream_exact(p_list, self._sparse,
valuation=valuation,
constant=constant,
degree=degree)
return self.element_class(self, coeff_stream)

if isinstance(x, LazyTaylorSeries):
if x._coeff_stream._is_sparse is self._sparse:
return self.element_class(self, x._coeff_stream)
Expand Down Expand Up @@ -689,7 +682,7 @@ def _an_element_(self):
sage: L = LazyTaylorSeriesRing(ZZ, 'z')
sage: L.an_element()
z^-10 + z^-9 + z^-8 + ...
z + z^2 + z^3 + z^4 + ...
"""
c = self.base_ring()(1)
R = self._poly_ring
Expand Down

0 comments on commit 5b62ddb

Please sign in to comment.