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

Continuous limits involving division by x #21029

Open
peteroupc opened this issue Mar 3, 2021 · 1 comment · May be fixed by #22463
Open

Continuous limits involving division by x #21029

peteroupc opened this issue Mar 3, 2021 · 1 comment · May be fixed by #22463
Labels

Comments

@peteroupc
Copy link

peteroupc commented Mar 3, 2021

Take the function (sinh(x)+cosh(x)-1)/4. This function when divided by x, has a limit of 1/4 at 0:

In [77]: cc=(sinh(x)+cosh(x)-1)/4                                                                                                                  

In [78]: limit(cc/x,x,0)                                                                                                                           
Out[78]: 1/4

However, when the limit is taken as "x approaches a symbol" such as z, the result of limit doesn't take into account the fact that z could be 0:

In [79]: limit(cc/x,x,z)                                                                                                                           
Out[79]: 
 z    
ℯ  - 1
──────
 4⋅z  

In [80]: limit(cc/x,x,z).subs(z,0)                                                                                                                 
Out[80]: nan

In this case the correct solution to the limit would be a piecewise function:

  • 1/4 if z = 0.
  • (exp(z) - 1)/(4*z) otherwise.
@peteroupc peteroupc changed the title Limits involving division by x Continuous limits involving division by x Mar 3, 2021
skirpichev added a commit to skirpichev/diofant that referenced this issue Mar 28, 2021
Closes sympy/sympy#21029

BTW, "piecewise" answer will be horrible (in general) and
I doubt it's always possible (e.g. something like sin(1/z)).

Lets stick with old answer, like Mathematica does.
@anutosh491
Copy link
Member

anutosh491 commented Oct 22, 2021

well sinh(x) + cosh(x) is nothing but exp(x) and something like limit((exp(x) -1)/x, x, 0) = 1 is one of the most standard limits you'll find , so i'll try to address this as soon as I can .

>>> limit((exp(x)-1)/x, x, z) # Not the correct output 
(exp(z) - 1)/z
>>> limit((exp(x)-1)/x, x, z).subs(z, 0)
nan

f(x) = (exp(x) - 1)/x is not defined at 0 and hence returns nan here
Well this seems to be a general case rather than just something related to exp(x)

>>> limit(ln(1+x)/x, x, z)
log(z + 1)/z
>>> limit(ln(1+x)/x, x, z).subs(z, 0) 
nan
>>> limit(sin(x)/x, x, z)
sin(z)/z
>>> limit(sin(x)/x, x, z).subs(z, 0)
nan

EDIT: So throughout the gruntz.py , the workflow for these cases doesn't suggest any kind check for singularities! will have to go through that

EDIT 2: Heyy @oscarbenjamin , @jksuom would something like this work(in the sense that I'm not sure which cases would I be missing if any and what else should I be addressing)

diff --git a/sympy/series/gruntz.py b/sympy/series/gruntz.py
index 1154d40b17..fc35b0d9db 100644
--- a/sympy/series/gruntz.py
+++ b/sympy/series/gruntz.py
@@ -701,6 +701,14 @@ def gruntz(e, z, z0, dir="+"):
     except ValueError:
         r = limitinf(e0, z, leadsimp=True)

+    from sympy import singularities, Eq, Piecewise
+    if z0.is_symbol and not str(singularities(r, z0)) == 'EmptySet':
+        piecewise_list = []
+        for singularity in singularities(r, z0):
+            piecewise_list.append((gruntz(r, z0, singularity),Eq(z0, singularity)))
+        piecewise_list += [(r,True)]
+        r = Piecewise(*piecewise_list)
+
     # This is a bit of a heuristic for nice results... we always rewrite
     # tractable functions in terms of familiar intractable ones.
     # It might be nicer to rewrite the exactly to what they were initially,

This works correctly as per what I could see , as I said not at all sure what I could be missing !!! I know that some cases like limit(ln(1+x)/x ,x, z) won't be using gruntz.py and would use only limits.py so a similar fix there at the appropriate place might do it but other than that if you'll have something I would be glad to know .

>>> limit((sinh(x) + cosh(x) -1)/(4*x), x, z)
Piecewise((1/4, Eq(z, 0)), ((exp(z) - 1)/(4*z), True))

>>> limit(sin(x)/x, x, z)
Piecewise((1, Eq(z, 0)), (sin(z)/z, True))

>>> limit((1- cos(x))/x**2, x, z)
Piecewise((1/2, Eq(z, 0)), (-(cos(z) - 1)/z**2, True))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants