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

Make limit work with binomial #10801

Closed
asmeurer opened this issue Mar 11, 2016 · 11 comments · Fixed by #10883
Closed

Make limit work with binomial #10801

asmeurer opened this issue Mar 11, 2016 · 11 comments · Fixed by #10883
Labels

Comments

@asmeurer
Copy link
Member

limit can work with binomial by converting to factorial first.

In [214]: limit(16**k/(k*binomial(2*k,k)**2), k, oo)
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/limits.py in doit(self, **hints)
    171         try:
--> 172             r = gruntz(e, z, z0, dir)
    173             if r is S.NaN:

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/gruntz.py in gruntz(e, z, z0, dir)
    640     if z0 == oo:
--> 641         r = limitinf(e, z)
    642     elif z0 == -oo:

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/gruntz.py in limitinf(e, x)
    423         x = p
--> 424     c0, e0 = mrv_leadterm(e, x)
    425     sig = sign(e0, x)

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/gruntz.py in mrv_leadterm(e, x)
    479     if Omega == SubsSet():
--> 480         Omega, exps = mrv(e, x)
    481     if not Omega:

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/gruntz.py in mrv(e, x)
    258         s1, e1 = mrv(a, x)
--> 259         s2, e2 = mrv(b, x)
    260         return mrv_max1(s1, s2, e.func(i, e1, e2), x)

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/gruntz.py in mrv(e, x)
    257         a, b = d.as_two_terms()
--> 258         s1, e1 = mrv(a, x)
    259         s2, e2 = mrv(b, x)

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/gruntz.py in mrv(e, x)
    265         else:
--> 266             s, expr = mrv(b, x)
    267             return s, expr**e

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/gruntz.py in mrv(e, x)
    294             # e.g. something like BesselJ(x, x)
--> 295             raise NotImplementedError("MRV set computation for functions in"
    296                                       " several variables not implemented.")

NotImplementedError: MRV set computation for functions in several variables not implemented.

During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-214-830bdb8908f4> in <module>()
----> 1 limit(16**k/(k*binomial(2*k,k)**2), k, oo)

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/limits.py in limit(e, z, z0, dir)
     43     """
     44
---> 45     return Limit(e, z, z0, dir).doit(deep=False)
     46
     47

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/series/limits.py in doit(self, **hints)
    183                 r = limit_seq(e, z, trials)
    184                 if r is None:
--> 185                     raise NotImplementedError()
    186             else:
    187                 raise NotImplementedError()

NotImplementedError:

In [215]: limit(16**k/(k*binomial(2*k,k)**2).rewrite(factorial), k, oo)
Out[215]: π

skirpichev added a commit to diofant/diofant that referenced this issue Mar 12, 2016
@wrat
Copy link
Contributor

wrat commented Mar 13, 2016

Means we have to convert binomial to factorial in limit.py ??but how it can recognize that given expression is binomial??

@asmeurer
Copy link
Member Author

You can use expr.has(binomial).

@wrat
Copy link
Contributor

wrat commented Mar 13, 2016

ohkkk , I am looking into this .

@wrat
Copy link
Contributor

wrat commented Mar 13, 2016

gruntz fails on factorials but works with the gamma function .so
e= e.rewrite(factorial) or e = e.rewrite(factorial,gamma) ??
I have tried from e=e.rewrite(factorial) then it is showing 'pi' as output (which is right)."
But why it shows not implemented error using e=e.rewrite(factorial,gamma) .

@wrat
Copy link
Contributor

wrat commented Mar 13, 2016

@asmeurer
def test_limit_seq(): assert (limit(binomial(2*x, x) / Sum(binomial(2*y, y), (y, 1, x)), x, oo) == S(3) / 4)
can we discuss about this test case??

@leosartaj
Copy link
Member

@wrat This limit is found using a different algorithm, implemented here. It is currently called as last resort, in-case no other algorithm can find the limit. Reason being, it is still new, and capable of solving only a small subset.

@wrat
Copy link
Contributor

wrat commented Mar 14, 2016

See PR #10825

@asmeurer
Copy link
Member Author

I think we can also fix this by implementing binomial._rewrite_as_tractable.

@wrat
Copy link
Contributor

wrat commented Mar 14, 2016

Yeah of course we can fix it like that but while implementing it , may be we will get some issue according to me actually .so should I implement like binomial._rewrite_as_tractable to get merge.

@wrat
Copy link
Contributor

wrat commented Mar 15, 2016

@asmeurer ping

@asmeurer
Copy link
Member Author

I think the as_tractable way is the best way to fix this.

wrat added a commit to wrat/sympy that referenced this issue Mar 19, 2016
…ial form.

 for calculating the limit of funtion we are using gruntz algorithm. gruntz algorithm is not works with binomial limits so we have to convert its factorial form.
 for example:
 while calculating limit(16**k/(k*binomial(2*k,k)**2), k, oo)
 we are getting NotImplemented Exception but after some changes we are now able to get the result as PI.
 Refer to sympy#10801 issue
"
wrat added a commit to wrat/sympy that referenced this issue Mar 19, 2016
          if not e.has(z):
              return e
-
+        #limit is not working with binomial,gruntz raise an exception

     and   e = e.rewrite(factorial)

   issue  sympy#10801
"
wrat added a commit to wrat/sympy that referenced this issue Mar 19, 2016
" space after # and space around = below in limits.py
  issue sympy#10801
"
Conflicts:
	sympy/series/limits.py
	sympy/series/tests/test_limits.py
wrat added a commit to wrat/sympy that referenced this issue Mar 21, 2016
…ial form.for calculating the limit of funtion we are using gruntz algorithm. gruntz algorithm is not works with binomial limits so we have to convert its factorial form.

for example:
while calculating limit(16**k/(k*binomial(2*k,k)**2), k, oo)
we are getting NotImplemented Exception but after some changes we are now able to get the result as PI.
Refer to sympy#10801 issue"
skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016
    close sympy/sympy#3112 (MrvAsympt was added in diofant#6)
    close sympy/sympy#9173 (test was added in 5a510ac)
    close sympy/sympy#9808 (fixed in 09e539b)
    close sympy/sympy#9341 (fixed in af98a00)
    close sympy/sympy#9908 (fixed in cc3fa8d)
    close sympy/sympy#6171 (test added in d278031)
    close sympy/sympy#9276 (diagnose_imports.py removed in ab8c535)
    close sympy/sympy#10201 (fixed in 0d0fc5f)
    close sympy/sympy#9057 (test was added in 8290a0c)
    close sympy/sympy#11159 (test was added in ffb76cb)
    close sympy/sympy#2839 (new AST transformers are used, see diofant#278 and diofant#167)
    close sympy/sympy#11081 (see ed01e16 and bb92329)
    close sympy/sympy#10974 (see 73fc425)
    close sympy/sympy#10806 (test in 539929a)
    close sympy/sympy#10801 (test in 2fe3da5)
    close sympy/sympy#9549 (test in 88bdefa)
    close sympy/sympy#4231 (test was added in fb411d5)
    close sympy/sympy#8634 (see 2fcbb58)
    close sympy/sympy#8481 (see 1ef20d3)
    close sympy/sympy#9956 (fixed in a34735f)
    close sympy/sympy#9747 (see e117c60)
    close sympy/sympy#7853 (see 3e4fbed)
    close sympy/sympy#9634 (see 2be03f5)
    close sympy/sympy#8500 (fixed in diofant#104 and finally in diofant#316)
    close sympy/sympy#9192 (see 9bf622f)
    close sympy/sympy#7130 (see e068fa3)
    close sympy/sympy#8514 (see b2d543b)
    close sympy/sympy#9334 (see 90de625)
    close sympy/sympy#8229 (see 9755b89)
    close sympy/sympy#8061 (see 7054f06)
    close sympy/sympy#7872 (tested in diofant#6)
    close sympy/sympy#3496 (tested in test_log_symbolic)
    close sympy/sympy#2929 (see da7db7a)
    close sympy/sympy#8203 (oo is not a real, see diofant#36)
    close sympy/sympy#7649 (0 is imaginary since diofant#8)
    close sympy/sympy#7256 (fixed in c0a4549)
    close sympy/sympy#6783 (see cb28d63)
    close sympy/sympy#5662 (is_integer issue fixed in 6bfa9f8, there is no is_bounded anymore)
    close sympy/sympy#5295 (fixed with diofant#354)
    close sympy/sympy#4856 (we now have flake/pep tests)
    close sympy/sympy#4555 (flake8 enabled after diofant#214)
    close sympy/sympy#5773 (cmp_to_key removed after diofant#164 and c9acbf0)
    close sympy/sympy#5484 (see above)

    Added regression tests:
    from https://groups.google.com/forum/#!topic/sympy/LkTMQKC_BOw
    fixes sympy/sympy#8825 (probably via diofant#209)
    fixes sympy/sympy#8635
    fixes sympy/sympy#8157
    fixes sympy/sympy#7872
    fixes sympy/sympy#7599
    fixes sympy/sympy#6179
    fixes sympy/sympy#5415
    fixes sympy/sympy#2865
    fixes sympy/sympy#5907
    fixes sympy/sympy#11722

    Closes diofant#347
skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016
    close sympy/sympy#3112 (MrvAsympt was added in diofant#6)
    close sympy/sympy#9173 (test was added in 5a510ac)
    close sympy/sympy#9808 (fixed in 09e539b)
    close sympy/sympy#9341 (fixed in af98a00)
    close sympy/sympy#9908 (fixed in cc3fa8d)
    close sympy/sympy#6171 (test added in d278031)
    close sympy/sympy#9276 (diagnose_imports.py removed in ab8c535)
    close sympy/sympy#10201 (fixed in 0d0fc5f)
    close sympy/sympy#9057 (test was added in 8290a0c)
    close sympy/sympy#11159 (test was added in ffb76cb)
    close sympy/sympy#2839 (new AST transformers are used, see diofant#278 and diofant#167)
    close sympy/sympy#11081 (see ed01e16 and bb92329)
    close sympy/sympy#10974 (see 73fc425)
    close sympy/sympy#10806 (test in 539929a)
    close sympy/sympy#10801 (test in 2fe3da5)
    close sympy/sympy#9549 (test in 88bdefa)
    close sympy/sympy#4231 (test was added in fb411d5)
    close sympy/sympy#8634 (see 2fcbb58)
    close sympy/sympy#8481 (see 1ef20d3)
    close sympy/sympy#9956 (fixed in a34735f)
    close sympy/sympy#9747 (see e117c60)
    close sympy/sympy#7853 (see 3e4fbed)
    close sympy/sympy#9634 (see 2be03f5)
    close sympy/sympy#8500 (fixed in diofant#104 and finally in diofant#316)
    close sympy/sympy#9192 (see 9bf622f)
    close sympy/sympy#7130 (see e068fa3)
    close sympy/sympy#8514 (see b2d543b)
    close sympy/sympy#9334 (see 90de625)
    close sympy/sympy#8229 (see 9755b89)
    close sympy/sympy#8061 (see 7054f06)
    close sympy/sympy#7872 (tested in diofant#6)
    close sympy/sympy#3496 (tested in test_log_symbolic)
    close sympy/sympy#2929 (see da7db7a)
    close sympy/sympy#8203 (oo is not a real, see diofant#36)
    close sympy/sympy#7649 (0 is imaginary since diofant#8)
    close sympy/sympy#7256 (fixed in c0a4549)
    close sympy/sympy#6783 (see cb28d63)
    close sympy/sympy#5662 (is_integer issue fixed in 6bfa9f8, there is no is_bounded anymore)
    close sympy/sympy#5295 (fixed with diofant#354)
    close sympy/sympy#4856 (we now have flake/pep tests)
    close sympy/sympy#4555 (flake8 enabled after diofant#214)
    close sympy/sympy#5773 (cmp_to_key removed after diofant#164 and c9acbf0)
    close sympy/sympy#5484 (see above)

    Added regression tests:
    from https://groups.google.com/forum/#!topic/sympy/LkTMQKC_BOw
    fixes sympy/sympy#8825 (probably via diofant#209)
    fixes sympy/sympy#8635
    fixes sympy/sympy#8157
    fixes sympy/sympy#7872
    fixes sympy/sympy#7599
    fixes sympy/sympy#6179
    fixes sympy/sympy#5415
    fixes sympy/sympy#2865
    fixes sympy/sympy#5907
    fixes sympy/sympy#11722

    Closes diofant#347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants