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

Commit

Permalink
Merge branch 'u/mantepse/dense_lls-31897' of git://trac.sagemath.org/…
Browse files Browse the repository at this point in the history
…sage into t/32324/lazy_taylor_series
  • Loading branch information
mantepse committed Aug 9, 2021
2 parents 664e35a + 883a01e commit eb27019
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
22 changes: 15 additions & 7 deletions src/sage/rings/lazy_laurent_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,12 @@ def __call__(self, g):
sage: g^-3 + g^-2 + 1 / (1 + g^2)
z^-9 + 3*z^-8 + 3*z^-7 - z^-6 - 4*z^-5 - 2*z^-4 + z^-3 + O(z^-2)
sage: f = z^-3; g = z^-2 + z^-1;
sage: g^(-3)
z^6 - 3*z^7 + 6*z^8 - 10*z^9 + 15*z^10 - 21*z^11 + 28*z^12 + O(z^13)
sage: f(g)
z^6 - 3*z^7 + 6*z^8 - 10*z^9 + 15*z^10 - 21*z^11 + 28*z^12 + O(z^13)
sage: f = L(lambda n: n); f
z + 2*z^2 + 3*z^3 + 4*z^4 + 5*z^5 + 6*z^6 + O(z^7)
sage: f(z^2)
Expand Down Expand Up @@ -1946,15 +1952,17 @@ def __call__(self, g):
# We build this iteratively so each power can benefit from the caching
# Equivalent to P.sum(poly[i] * g**i for i in range(poly.valuation(), poly.degree()+1))
# We could just do "return poly(g)" if we don't care about speed
deg = poly.degree()
for i in range(deg):
ret += poly[i] * gp
gp *= g
ret += poly[deg] * gp
if poly.valuation() < 0:
d = poly.degree()
if d >= 0:
for i in range(d):
ret += poly[i] * gp
gp *= g
ret += poly[d] * gp
v = poly.valuation()
if v < 0:
gi = ~g
gp = P.one()
for i in range(-1, poly.valuation()-1, -1):
for i in range(-1, v-1, -1):
gp *= gi
ret += poly[i] * gp
return ret
Expand Down
34 changes: 30 additions & 4 deletions src/sage/rings/lazy_laurent_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,24 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
...
TypeError: no conversion of this rational to integer
This gives zero::
sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L(lambda n: 0, degree=3)
0
This does not::
sage: L(lambda n: 0, degree=3, constant=1)
z^3 + z^4 + z^5 + O(z^6)
This raises an error::
sage: L(lambda n: 0, valuation=3, constant=1)
Traceback (most recent call last):
...
ValueError: constant may only be specified if the degree is specified
.. TODO::
Add a method to change the sparse/dense implementation.
Expand Down Expand Up @@ -427,7 +445,7 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
return self.element_class(self, coeff_stream)
initial_coefficients = [x[i] for i in range(x.valuation(), x.degree() + 1)]
coeff_stream = CoefficientStream_exact(initial_coefficients, self._sparse,
valuation=x.valuation(), constant=constant, degree=degree)
valuation=x.valuation(), constant=constant, degree=degree)
return self.element_class(self, coeff_stream)
if isinstance(x, LazyLaurentSeries):
if x._coeff_stream._is_sparse is self._sparse:
Expand All @@ -437,14 +455,22 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
if callable(x):
if valuation is None:
valuation = 0
if degree is None:
if constant is not None:
raise ValueError("constant may only be specified if the degree is specified")
coeff_stream = CoefficientStream_coefficient_function(x, self.base_ring(), self._sparse, valuation)
return self.element_class(self, coeff_stream)
if degree is not None:
if constant is None:
constant = ZZ.zero()
p = [BR(x(i)) for i in range(valuation, degree)]
coeff_stream = CoefficientStream_exact(p, self._sparse, valuation=valuation,
constant=constant, degree=degree)
if not any(p) and not constant:
coeff_stream = CoefficientStream_zero(self._sparse)
else:
coeff_stream = CoefficientStream_exact(p, self._sparse, valuation=valuation,
constant=constant, degree=degree)
return self.element_class(self, coeff_stream)
return self.element_class(self, CoefficientStream_coefficient_function(x, self.base_ring(), self._sparse, valuation))

raise ValueError(f"unable to convert {x} into a lazy Laurent series")

def _an_element_(self):
Expand Down

0 comments on commit eb27019

Please sign in to comment.