diff --git a/diofant/series/gruntz.py b/diofant/series/gruntz.py index f5d6b2782e..a02897516e 100644 --- a/diofant/series/gruntz.py +++ b/diofant/series/gruntz.py @@ -134,6 +134,16 @@ def mrv(e, x): return mrv(e.base, x) elif isinstance(e, log): return mrv(e.args[0], x) + elif e.is_Piecewise: + for a, c in e.args: + if not c.is_Atom: + c = c.func(c.lhs - c.rhs) + c = c.func(limitinf(c.lhs, x)) + if not c.is_Atom: + raise NotImplementedError("Parametric limits aren't supported yet.") + if c: + break + return mrv(a, x) elif e.is_Function and not isinstance(e.func, UndefinedFunction): return functools.reduce(lambda a, b: mrv_max(a, b, x), [mrv(a, x) for a in e.args]) diff --git a/diofant/tests/series/test_limits.py b/diofant/tests/series/test_limits.py index 03e89e2b7f..96f5e12d4c 100644 --- a/diofant/tests/series/test_limits.py +++ b/diofant/tests/series/test_limits.py @@ -99,6 +99,19 @@ def test_basic4(): e = ((n**(n + 1) + (n + 1)**n)/n**(n + 1))**n assert limit(e, n, oo) == E**E + # issue sympy/sympy#18492 + e1 = 2*sqrt(x)*Piecewise(((4*x - 2)/abs(sqrt(4 - 4*(2*x - 1)**2)), + 4*x - 2 >= 0), + ((2 - 4*x)/abs(sqrt(4 - 4*(2*x - 1)**2)), True)) + e2 = Piecewise((x**2/2, x <= Rational(1, 2)), (x/2 - Rational(1, 8), True)) + e3 = Piecewise(((x - 9)/5, x < -1), ((x - 9)/5, x > 4), + (sqrt(abs(x - 3)), True)) + assert limit(e1, x, 0) == 1 + assert limit(e2, x, 0) == 0 + assert limit(e2, x, oo) == oo + assert limit(e3, x, -1) == 2 + assert limit(e3, x, oo) == oo + def test_basic5(): class MyFunction(Function): diff --git a/docs/release/notes-0.14.rst b/docs/release/notes-0.14.rst index 6498d16d49..1a6a4b1839 100644 --- a/docs/release/notes-0.14.rst +++ b/docs/release/notes-0.14.rst @@ -7,6 +7,8 @@ Not Released Yet New features ============ +* Support calculating limits with :class:`~diofant.functions.elementary.piecewise.Piecewise` functions, see :pull:`1214`. + Major changes ============= @@ -67,3 +69,4 @@ These Sympy issues also were addressed: * :sympyissue:`14387`: Tutorial on limits creates impression that they are two-sided by default * :sympyissue:`8166`: Limit assumes function is continuous? * :sympyissue:`14502`: Problem with limit including factorial. +* :sympyissue:`18492`: Limit of Piecewise function - NotImplementedError: Don't know how to calculate the mrv