Skip to content

Commit

Permalink
core: removed Expr.lseries()
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Jun 6, 2021
1 parent acca6cd commit 32ff9a2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 44 deletions.
26 changes: 1 addition & 25 deletions diofant/core/expr.py
Expand Up @@ -2483,29 +2483,6 @@ def taylor_term(self, n, x, *previous_terms):
_x = Dummy('x')
return self.subs({x: _x}).diff((_x, n)).subs({_x: x}).subs({x: 0}) * x**n / factorial(n)

def lseries(self, x=None, x0=0, dir='+', logx=None):
"""Wrapper for series yielding an iterator of the terms of the series.
Note: an infinite series will yield an infinite iterator. The following,
for exaxmple, will never terminate. It will just keep printing terms
of the sin(x) series::
for term in sin(x).lseries(x):
print term
The advantage of lseries() over nseries() is that many times you are
just interested in the next term in the series (i.e. the first term for
example), but you don't know how many you should ask for in nseries()
using the "n" parameter.
See Also
========
nseries
"""
return self.series(x, x0, n=None, dir=dir, logx=logx)

def _eval_lseries(self, x, logx=None):
# default implementation of lseries is using nseries(), and adaptively
# increasing the "n". As you can see, it is not very efficient, because
Expand Down Expand Up @@ -2564,7 +2541,6 @@ def nseries(self, x, n=6, logx=None):
========
series
lseries
Examples
========
Expand Down Expand Up @@ -2735,7 +2711,7 @@ def compute_leading_term(self, x, logx=None):

d = logx if logx else Dummy('logx')

for t in self.lseries(x, logx=d):
for t in self.series(x, n=None, logx=d):
t = t.cancel()

is_zero = t.equals(0)
Expand Down
2 changes: 1 addition & 1 deletion diofant/core/function.py
Expand Up @@ -1232,7 +1232,7 @@ def _subset(a, b):
return Derivative(*(x._subs(old, new) for x in self.args))

def _eval_lseries(self, x, logx):
for term in self.expr.lseries(x, logx=logx):
for term in self.expr.series(x, n=None, logx=logx):
yield self.func(term, *self.variables)

def _eval_nseries(self, x, n, logx):
Expand Down
2 changes: 1 addition & 1 deletion diofant/integrals/integrals.py
Expand Up @@ -916,7 +916,7 @@ def _eval_lseries(self, x, logx):
if x in l[1:]:
symb = l[0]
break
for term in expr.function.lseries(symb, logx):
for term in expr.function.series(symb, n=None, logx=logx):
yield integrate(term, *expr.limits)

def _eval_nseries(self, x, n, logx):
Expand Down
2 changes: 1 addition & 1 deletion diofant/tests/integrals/test_integrals.py
Expand Up @@ -865,7 +865,7 @@ def test_is_real():

def test_series():
i = Integral(cos(x), (x, x))
e = i.lseries(x)
e = i.series(x, n=None)
s1 = i.nseries(x, n=8).removeO().doit()
s2 = Add(*[next(e) for j in range(4)])
assert s1 == s2
Expand Down
28 changes: 14 additions & 14 deletions diofant/tests/series/test_lseries.py
Expand Up @@ -6,51 +6,51 @@


def test_sin():
e = sin(x).lseries(x)
e = sin(x).series(x, n=None)
assert next(e) == x
assert next(e) == -x**3/6
assert next(e) == x**5/120


def test_cos():
e = cos(x).lseries(x)
e = cos(x).series(x, n=None)
assert next(e) == 1
assert next(e) == -x**2/2
assert next(e) == x**4/24


def test_exp():
e = exp(x).lseries(x)
e = exp(x).series(x, n=None)
assert next(e) == 1
assert next(e) == x
assert next(e) == x**2/2
assert next(e) == x**3/6


def test_exp2():
e = exp(cos(x)).lseries(x)
e = exp(cos(x)).series(x, n=None)
assert next(e) == E
assert next(e) == -E*x**2/2
assert next(e) == E*x**4/6
assert next(e) == -31*E*x**6/720


def test_simple():
assert list(x.lseries()) == [x]
assert list(Integer(1).lseries(x)) == [1]
assert not next((x/(x + y)).lseries(y)).has(O)
assert [t.doit() for t in Derivative(1 + x, x).lseries(x)] == [0, 1]
assert list(x.series(n=None)) == [x]
assert list(Integer(1).series(x, n=None)) == [1]
assert not next((x/(x + y)).series(y, n=None)).has(O)
assert [t.doit() for t in Derivative(1 + x, x).series(x, n=None)] == [0, 1]

# issue sympy/sympy#5183
s = (x + 1/x).lseries()
s = (x + 1/x).series(n=None)
assert list(s) == [1/x, x]


def test_sympyissue_5183():
s = (x + 1/x).lseries()
assert next((x + x**2).lseries()) == x
assert next(((1 + x)**7).lseries(x)) == 1
assert next((sin(x + y)).series(x, n=3).lseries(y)) == x
s = (x + 1/x).series(n=None)
assert next((x + x**2).series(n=None)) == x
assert next(((1 + x)**7).series(x, n=None)) == 1
assert next((sin(x + y)).series(x, n=3).series(y, n=None)) == x
# it would be nice if all terms were grouped, but in the
# following case that would mean that all the terms would have
# to be known since, for example, every term has a constant in it.
Expand All @@ -60,7 +60,7 @@ def test_sympyissue_5183():

def test_tanh():
# issue sympy/sympy#6999
s = tanh(x).lseries(x, 1)
s = tanh(x).series(x, x0=1, n=None)
assert next(s) == tanh(1)
assert next(s) == x - (x - 1)*tanh(1)**2 - 1
assert next(s) == -(x - 1)**2*tanh(1) + (x - 1)**2*tanh(1)**3
Expand Down
4 changes: 2 additions & 2 deletions diofant/tests/series/test_series.py
Expand Up @@ -65,7 +65,7 @@ def test_simple():


def test_sympyissue_5223():
assert next(Integer(0).lseries(x)) == 0
assert next(Integer(0).series(x, n=None)) == 0
assert cos(x).series() == cos(x).series(x)

e = cos(x).series(x, 1, n=None)
Expand All @@ -78,7 +78,7 @@ def test_sympyissue_5223():
E - E*(-x + 1) + E*(-x + 1)**2/2

D = Derivative
assert next(D(cos(x), x).lseries()) == D(1, x)
assert next(D(cos(x), x).series(n=None)) == D(1, x)
assert D(exp(x), x).series(n=3) == (D(1, x) + D(x, x) + D(x**2/2, x) +
D(x**3/6, x) + O(x**3))

Expand Down
1 change: 1 addition & 0 deletions docs/release/notes-0.13.rst
Expand Up @@ -24,6 +24,7 @@ Compatibility breaks
* Removed ``igcd()``, ``ilcm()`` and ``prod()`` functions, see :pull:`1125`.
* Changed the :class:`~diofant.core.function.Derivative` (and similary :func:`~diofant.core.function.diff`) syntax to ``Derivative(foo, (x, 2))`` from ``Derivative(foo, x, 2)``, see :pull:`1131`.
* Removed ``prem()`` function, see :pull:`1140`.
* Removed ``lseries()`` method of :class:`~diofant.core.expr.Expr`, use :meth:`~diofant.core.expr.Expr.series` with ``n=None``, see :pull:`1146`.

Minor changes
=============
Expand Down

0 comments on commit 32ff9a2

Please sign in to comment.