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

Multivariable limit should be undefined, but gives unity. #24225

Closed
galenseilis opened this issue Nov 7, 2022 · 1 comment
Closed

Multivariable limit should be undefined, but gives unity. #24225

galenseilis opened this issue Nov 7, 2022 · 1 comment

Comments

@galenseilis
Copy link

galenseilis commented Nov 7, 2022

The following uses composition of single-variable limits, and gives unity.

from sympy import *

y = Symbol('y', complex=True)
x = Symbol('x', complex=True)

f = (log(1 + x) + log(1 + y)) / (x + y)

print(limit(limit(f, x, 0, dir='+-'), y, 0, dir='+-'), limit(limit(f, y, 0, dir='+-'), x, 0, dir='+-'))

But it seems that there exist directions in which (0,0) can be approached that are not equal, so the multivariable limit is undefined.

Is there a way to evaluate multivariable limits in SymPy?

@oscarbenjamin
Copy link
Contributor

Multivariable limits are only defined if you choose how to approach the limit which you can do in the way shown in the SO question:

In [1]: from sympy import *
   ...: 
   ...: y = Symbol('y', complex=True)
   ...: x = Symbol('x', complex=True)
   ...: 
   ...: f = (log(1 + x) + log(1 + y)) / (x + y)

In [2]: print(limit(limit(f, x, 0, dir='+-'), y, 0, dir='+-'), limit(limit(f, y, 0, dir='+-'), x, 0,
   ...: dir='+-'))
1 1

In [3]: alpha = symbols('alpha')

In [4]: f.subs(x, x+alpha*x**2).subs(y, -x+alpha*x**2)
Out[4]: 
   ⎛   2        ⎞      ⎛   2logαx  - x + 1+ logαx  + x + 1⎠
─────────────────────────────────────
                     2               
                2αx                

In [5]: f.subs(x, x+alpha*x**2).subs(y, -x+alpha*x**2).limit(x, 0)
Out[5]: 
2α - 1
───────
  2α

In [6]: f.subs(y, 1/(1+x)-1).limit(x, 0)
Out[6]: 0

Note that it isn't just the "direction" that matters but also how "fast" each variable approaches the limit e.g. if one variable goes like $x^2$ another like $x$ then that can change the value of the limit. The iterated limits that you asked for are defined and limit gives the correct result. If you want to approach along a different path then you will need to specify the path as I showed above.

skirpichev added a commit to diofant/diofant that referenced this issue Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants