Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not evaluate unnecessarily #35291

Merged
merged 2 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/sage/data_structures/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -1853,16 +1853,19 @@ def get_coefficient(self, n):
fv = self._left._approximate_order
gv = self._right._approximate_order
if n < 0:
return sum(self._left[i] * self._neg_powers[-i][n]
for i in range(fv, n // gv + 1))
return sum(f_coeff_i * self._neg_powers[-i][n]
for i in range(fv, n // gv + 1)
if (f_coeff_i := self._left[i]))
# n > 0
while len(self._pos_powers) <= n // gv:
# TODO: possibly we always want a dense cache here?
self._pos_powers.append(Stream_cauchy_mul(self._pos_powers[-1], self._right, self._is_sparse))
ret = sum(self._left[i] * self._neg_powers[-i][n] for i in range(fv, 0))
ret = sum(f_coeff_i * self._neg_powers[-i][n] for i in range(fv, 0)
if (f_coeff_i := self._left[i]))
if n == 0:
ret += self._left[0]
return ret + sum(self._left[i] * self._pos_powers[i][n] for i in range(1, n // gv+1))
return ret + sum(f_coeff_i * self._pos_powers[i][n] for i in range(1, n // gv + 1)
if (f_coeff_i := self._left[i]))


class Stream_plethysm(Stream_binary):
Expand Down
25 changes: 25 additions & 0 deletions src/sage/rings/lazy_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,21 @@ def __call__(self, *g, check=True):
sage: T(1-x-2*y + x*y^2)(1/(1-a), 3)
3 + 8*a + 8*a^2 + 8*a^3 + 8*a^4 + 8*a^5 + 8*a^6 + O(a,b)^7

Check that issue :trac:`35261` is fixed::

sage: L.<z> = LazyPowerSeriesRing(QQ)
sage: fun = lambda n: 1 if ZZ(n).is_power_of(2) else 0
sage: f = L(fun)
sage: g = L.undefined(valuation=1)
sage: g.define((~f.shift(-1)(g)).shift(1))
sage: g
z - z^2 + 2*z^3 - 6*z^4 + 20*z^5 - 70*z^6 + 256*z^7 + O(z^8)

sage: f = L(fun)
sage: g = L.undefined(valuation=1)
sage: g.define((z - (f - z)(g)))
sage: g
z - z^2 + 2*z^3 - 6*z^4 + 20*z^5 - 70*z^6 + 256*z^7 + O(z^8)
"""
fP = parent(self)
if len(g) != fP._arity:
Expand Down Expand Up @@ -4712,6 +4727,16 @@ def revert(self):
sage: f = L([-1], valuation=1, degree=3, constant=-1)
sage: f.revert()
(-z) + z^3 + (-z^4) + (-2*z^5) + 6*z^6 + z^7 + O(z^8)

Check that issue :trac:`35261` is fixed::

sage: L.<z> = LazyPowerSeriesRing(QQ)
sage: f = L(lambda n: 1 if ZZ(n).is_power_of(2) else 0)
sage: f
z + z^2 + z^4 + O(z^7)
sage: f.revert()
z - z^2 + 2*z^3 - 6*z^4 + 20*z^5 - 70*z^6 + 256*z^7 + O(z^8)

"""
P = self.parent()
if P._arity != 1:
Expand Down