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

Open
opened this Issue Oct 2, 2018 · 6 comments

Projects
None yet
4 participants

### Akuli commented Oct 2, 2018

 ```>>> from sympy import * >>> var('x') x >>> wat = ((1 - 1/x)**x).diff(x) >>> limit(wat, x, 1, dir='+') 0 >>> wat.subs(x, 1.0000000001) 0.999999995294830 >>> 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

``` Add regression test ```
`Closes sympy/sympy#15323`
``` 78287f6 ```

### ruchit2801 commented Oct 30, 2018

 Where can I look for code of limit function?

### 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 !!
Member

### jksuom commented Nov 18, 2018

 I would look into the computation of `mrv_leadterm()` in `limitinf()` of `sympy/series/gruntz.py`.

### yashraj-code commented Dec 1, 2018

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

### 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.
Member

### 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 + ) = log(w) + (log(w) - 1)*w + `````` It follows that ``````g = exp(h) = exp(log(w))*exp((log(w) - 1)*w + ) = w*(1 + (log(w) - 1)*w + ) = w + `````` 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.