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

Commit

Permalink
Documentation done for lazy_laurent_series_ring.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasvicsr1 committed Aug 3, 2021
1 parent a8837ca commit 3594c69
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
46 changes: 30 additions & 16 deletions src/sage/rings/lazy_laurent_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,28 @@
sage: f.coefficient(100)
573147844013817084101
Coefficients are computed and cached only when necessary::
sage: f._coeff_stream._cache[100]
573147844013817084101
sage: f._coeff_stream._cache[101]
Traceback (most recent call last):
...
IndexError: list index out of range
Coefficients are computed depending on the type of implementation.
For example, for a dense implementation, all the coefficients upto
the required coefficient are calculated.::
sage: s = L(lambda n: n); s
z + 2*z^2 + 3*z^3 + 4*z^4 + 5*z^5 + 6*z^6 + ...
sage: s.coefficient(10)
10
sage: s._coeff_stream._cache
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
For a sparse implementation, only the coefficients that are needed are
calculated::
sage: L.<x> = LazyLaurentSeriesRing(ZZ, sparse=True)
sage: s = L(lambda n: n); s
x + 2*x^2 + 3*x^3 + 4*x^4 + 5*x^5 + 6*x^6 + ...
sage: s.coefficient(10)
10
sage: s._coeff_stream._cache
{0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 10: 10}
You can do arithmetic with lazy power series::
Expand Down Expand Up @@ -966,8 +980,8 @@ def __call__(self, g):
g_poly = R(sum([g._coeff_stream[i] * z**i for i in range(g._coeff_stream._approximate_valuation, g._coeff_stream._degree)]))
ret = poly(g_poly)
if ret.parent() is R:
p_list = [ret[i] for i in range(ret.valuation(), ret.degree() + 1)]
return P.element_class(P, CoefficientStream_exact(p_list, self._coeff_stream._is_sparse, valuation=ret.valuation()))
inital_coefficients = [ret[i] for i in range(ret.valuation(), ret.degree() + 1)]
return P.element_class(P, CoefficientStream_exact(inital_coefficients, self._coeff_stream._is_sparse, valuation=ret.valuation()))
except TypeError: # the result is not a Laurent polynomial
pass

Expand Down Expand Up @@ -1056,8 +1070,8 @@ def _mul_(self, other):
pr = R(sum([right[i] * z**i for i in range(right._approximate_valuation, right._degree)]))
p = pl * pr
c = left._constant
p_list = [p[i] for i in range(p.valuation(), p.degree() + 1)]
return P.element_class(P, CoefficientStream_exact(p_list, P._sparse, valuation=p.valuation(), constant=c))
inital_coefficients = [p[i] for i in range(p.valuation(), p.degree() + 1)]
return P.element_class(P, CoefficientStream_exact(inital_coefficients, P._sparse, valuation=p.valuation(), constant=c))
elif isinstance(right, CoefficientStream_exact):
if not right._constant:
pr = R(sum([right[i] * z**i for i in range(right._approximate_valuation, right._degree)]))
Expand Down Expand Up @@ -1126,8 +1140,8 @@ def _div_(self, other):
ret = pl / pr
try:
ret = P._laurent_poly_ring(ret)
p_list = [ret[i] for i in range(ret.valuation(), ret.degree() + 1)]
return P.element_class(P, CoefficientStream_exact(p_list, P._sparse, valuation=ret.valuation(), constant=left._constant))
inital_coefficients = [ret[i] for i in range(ret.valuation(), ret.degree() + 1)]
return P.element_class(P, CoefficientStream_exact(inital_coefficients, P._sparse, valuation=ret.valuation(), constant=left._constant))
except (TypeError, ValueError):
# We cannot divide the polynomials, so the result must be a series
pass
Expand Down Expand Up @@ -1163,8 +1177,8 @@ def __invert__(self):
poly = R(sum([self._coeff_stream[i] * z**i for i in range(self._coeff_stream._approximate_valuation, self._coeff_stream._degree)]))
if poly == R.gen():
ret = 1 / poly
p_list = [ret[i] for i in range(ret.valuation(), ret.degree() + 1)]
return P.element_class(P, CoefficientStream_exact(p_list, P._sparse, valuation=ret.valuation(), constant=self._coeff_stream._constant))
inital_coefficients = [ret[i] for i in range(ret.valuation(), ret.degree() + 1)]
return P.element_class(P, CoefficientStream_exact(inital_coefficients, P._sparse, valuation=ret.valuation(), constant=self._coeff_stream._constant))
# (f^-1)^-1 = f
if isinstance(self._coeff_stream, CoefficientStream_cauchy_inverse):
return P.element_class(P, self._coeff_stream._series)
Expand Down
30 changes: 22 additions & 8 deletions src/sage/rings/lazy_laurent_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
sage: s
1 + z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + 132*z^6 + ...
The implementation of the Ring can be either be a sparse or a dense one.
The default is a dense implementation.::
sage: L.<z> = LazyLaurentSeriesRing(ZZ, sparse=True)
sage: L._sparse
True
sage: L.<z> = LazyLaurentSeriesRing(ZZ)
sage: L._sparse
False
AUTHORS:
- Kwankyu Lee (2019-02-24): initial version
Expand Down Expand Up @@ -101,7 +111,7 @@ class LazyLaurentSeriesRing(UniqueRepresentation, Parent):
- ``base_ring`` -- base ring of this Laurent series ring
- ``names`` -- name of the generator of this Laurent series ring
- ``sparse`` -- (default: ``False``) whether this series is sparse or not
- ``sparse`` -- (default: ``False``) whether the implementation of the series is sparse or not
EXAMPLES::
Expand Down Expand Up @@ -216,8 +226,9 @@ def _coerce_map_from_(self, S):
R = self._laurent_poly_ring
if R.has_coerce_map_from(S):
def make_series_from(poly):
p_list = [poly[i] for i in range(poly.valuation(), poly.degree() + 1)]
return self.element_class(self, CoefficientStream_exact(p_list, self._sparse, valuation=poly.valuation()))
inital_coefficients = [poly[i] for i in range(poly.valuation(), poly.degree() + 1)]
coeff_stream = CoefficientStream_exact(inital_coefficients, self._sparse, valuation=poly.valuation())
return self.element_class(self, coeff_stream)
return SetMorphism(Hom(S, self, Sets()), make_series_from)

return False
Expand Down Expand Up @@ -341,8 +352,8 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
if x == R.zero():
coeff_stream = CoefficientStream_exact([x], self._sparse, valuation=degree-1, constant=constant)
return self.element_class(self, coeff_stream)
p_list = [x[i] for i in range(x.valuation(), x.degree() + 1)]
coeff_stream = CoefficientStream_exact(p_list, self._sparse, valuation=x.valuation(), constant=constant, degree=degree)
inital_coefficients = [x[i] for i in range(x.valuation(), x.degree() + 1)]
coeff_stream = CoefficientStream_exact(inital_coefficients, self._sparse, 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 @@ -357,7 +368,8 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No
constant = ZZ.zero()
z = R.gen()
p = [x(i) for i in range(valuation, degree)]
return self.element_class(self, CoefficientStream_exact(p, self._sparse, valuation=valuation, constant=constant, degree=degree))
coeff_stream = CoefficientStream_exact(p, self._sparse, valuation=valuation, constant=constant, degree=degree)
return self.element_class(self, coeff_stream)
if len(signature(x).parameters) > 1:
return self.element_class(self, CoefficientStream_recursive(x, self.base_ring(), self._sparse, valuation))
return self.element_class(self, CoefficientStream_coefficient_function(x, self.base_ring(), self._sparse, valuation))
Expand All @@ -375,7 +387,8 @@ def _an_element_(self):
"""
c = self.base_ring()(1)
R = self._laurent_poly_ring
return self.element_class(self, CoefficientStream_exact([R.zero()], self._sparse, valuation=-11, constant=c))
coeff_stream = CoefficientStream_exact([R.zero()], self._sparse, valuation=-11, constant=c)
return self.element_class(self,coeff_stream)

@cached_method
def one(self):
Expand All @@ -389,7 +402,8 @@ def one(self):
1
"""
R = self._laurent_poly_ring
return self.element_class(self, CoefficientStream_exact([R.one()], self._sparse, constant=ZZ.zero(), degree=1))
coeff_stream = CoefficientStream_exact([R.one()], self._sparse, constant=ZZ.zero(), degree=1)
return self.element_class(self, coeff_stream)

@cached_method
def zero(self):
Expand Down

0 comments on commit 3594c69

Please sign in to comment.