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

limit of the derivative of (1-1/x)^x as x --> 1+ gives wrong answer #15323

Akuli opened this Issue Oct 2, 2018 · 6 comments


None yet
4 participants
Copy link

Akuli commented Oct 2, 2018

>>> from sympy import *
>>> var('x')
>>> wat = ((1 - 1/x)**x).diff(x)
>>> limit(wat, x, 1, dir='+')
>>> wat.subs(x, 1.0000000001)
>>> wat
(1 - 1/x)**x*(log(1 - 1/x) + 1/(x*(1 - 1/x)))

the answer should be 1, not 0

skirpichev added a commit to skirpichev/diofant that referenced this issue Oct 4, 2018


This comment has been minimized.

Copy link

ruchit2801 commented Oct 30, 2018

Where can I look for code of limit function?


This comment has been minimized.

Copy link

yashraj-code commented Nov 18, 2018

@jksuom i would like to solve this issue. Can you just guide me a bit where to look for possible error. ?
Thankyou !!


This comment has been minimized.

Copy link

jksuom commented Nov 18, 2018

I would look into the computation of mrv_leadterm() in limitinf() of sympy/series/


This comment has been minimized.

Copy link

yashraj-code commented Dec 1, 2018

@jksuom what is the logic behind the computation of mrv_leadterm() sympy/series/ .
I understood the purpose of e0,c0, but i am not able to understand how it is calculated ?


This comment has been minimized.

Copy link

jksuom commented Dec 1, 2018

The function is rewritten in terms of a single most rapidly varying component function denoted by w (imitating omega) and then expanded in a series of its powers. The exponents ei are real numbers, not necessarily integers, and the coefficients ci are functions lower comparability class than w, not necessarily constants in general. The series is computed in the same way as customary power series by traversing the expression tree of the function. Generally only the leading terms of the series need be retained to get c0 and e0.


This comment has been minimized.

Copy link

jksuom commented Jan 3, 2019

The algorithm computes the limit of e = (1 - 1/x)**x at 1+ by setting 1 + 1/x for x

>>> f = e.subs(x, 1 + 1/x); f
(1 - 1/(1 + 1/x))**(1 + 1/x)

and computing its limit limitinf(f, x) as x tends to oo. The algorithm first finds the set of most rapidly variable components of f:

>>> mrv(f, x)
({x: _Dummy_432, exp((1 + 1/x)*log(1 - 1/(1 + 1/x))): _Dummy_431}, {_Dummy_431: exp((1 + 1/_Dummy_432)*log(1 - 1/(1 + 1/_Dummy_432)))}, _Dummy_431)

It contains x and f rewritten in the form exp((1 + 1/x)*log(1 - 1/(1 + 1/x))) (which means that they are in the same comparability class). The algorithm then accelerates the convergence by substituting exp(x) for x. (It does not change the limit as exp(x) also tends to oo.)

>>> g = f.subs(x, exp(x)); g
(1 - 1/(1 + exp(-x)))**(1 + exp(-x))

The next task is to find the expansion of g as a series in w = exp(-x).

g = (1 - 1/(1 + w))**(1 + w) = (w/(1 + w)**(1 + w)
   = exp((1 + w)*log(w/(1 + w)))
   = exp((1 + w)*(log(w) - log(1 + w)) = exp(h)

As log(w) (= -x) is less rapidly moving than w (= exp(-x), h will have the following expansion

h = (1 + w)*(log(w) - w + <w**2>) = log(w) + (log(w) - 1)*w + <w**2>

It follows that

g = exp(h) = exp(log(w))*exp((log(w) - 1)*w + <w**2>)
   = w*(1 + (log(w) - 1)*w + <w**2>) = w + <w**2>

and therefore the most rapidly variable term of g is w = 1*w**1. In other words, mrv_leadterm(g, x) is (1, 1). However, SymPy will give us

>>> mrv_leadterm(g, x)
(exp(x), 2)

which is wrong. It means that the code will see g as tending quadratically to zero. If that were true, then the derivative would vanish linearly. This explains why the the algorithm gives 0 as the limit of the derivative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment