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
Incorrect limit involving elliptic functions #26250
Comments
The issues here come out of gruntz (which tells me there is something wrong with the series expansion of the numerator)
I think this is where the
|
Here is a smaller example where a similar phenomenon occurs. >>> x = symbols('x')
>>> t = 4*x/(x+1)
>>> e = ((x+1)*elliptic_e(t) + (x-1)*elliptic_k(t))/x**2
>>> print(e.limit(x, 0).evalf())
-4.71238898038469
>>> print(e.subs(x, 0.0001).evalf())
-1.57111057497161 We use >>> print(e.nseries().subs(x, 0).evalf())
-4.71238898038469 So how about the following example? >>> elliptic_e(t).nseries() This differs from the wolfram results. |
It's a bug in hyper.nseries: In [105]: f = hyper((-S(1)/2, S(1)/2), (1,), 4*x/(x + 1))
In [106]: f.nseries()
Out[106]:
2 3 4 5
x 3⋅x 5⋅x 175⋅x 441⋅x ⎛ 6⎞
1 - ───── - ────────── - ────────── - ─────────── - ─────────── + O⎝x ⎠
x + 1 2 3 4 5
4⋅(x + 1) 4⋅(x + 1) 64⋅(x + 1) 64⋅(x + 1) The method does not seem to do anything to handle the argument being anything other than a symbol. This change gives correct answers for all cases listed above: diff --git a/sympy/functions/special/hyper.py b/sympy/functions/special/hyper.py
index 277a1dda48..3ddb3cef19 100644
--- a/sympy/functions/special/hyper.py
+++ b/sympy/functions/special/hyper.py
@@ -282,7 +282,7 @@ def _eval_nseries(self, x, n, logx, cdir=0):
for i in range(n):
num = Mul(*[RisingFactorial(a, i) for a in ap])
den = Mul(*[RisingFactorial(b, i) for b in bq])
- terms.append(((num/den) * (arg**i)) / factorial(i))
+ terms.append(((num/den) * (arg**i).nseries()) / factorial(i))
return (Add(*terms) + Order(x**n,x)) I'm not sure what the proper way to write this code is. This also works: diff --git a/sympy/functions/special/hyper.py b/sympy/functions/special/hyper.py
index 277a1dda48..7b75611249 100644
--- a/sympy/functions/special/hyper.py
+++ b/sympy/functions/special/hyper.py
@@ -265,27 +265,6 @@ def _eval_as_leading_term(self, x, logx=None, cdir=0):
return S.One
return super()._eval_as_leading_term(x, logx=logx, cdir=cdir)
- def _eval_nseries(self, x, n, logx, cdir=0):
-
- from sympy.series.order import Order
-
- arg = self.args[2]
- x0 = arg.limit(x, 0)
- ap = self.args[0]
- bq = self.args[1]
-
- if x0 != 0:
- return super()._eval_nseries(x, n, logx)
-
- terms = []
-
- for i in range(n):
- num = Mul(*[RisingFactorial(a, i) for a in ap])
- den = Mul(*[RisingFactorial(b, i) for b in bq])
- terms.append(((num/den) * (arg**i)) / factorial(i))
-
- return (Add(*terms) + Order(x**n,x))
-
@property
def argument(self):
""" Argument of the hypergeometric function. """ Maybe |
from Wikipedia. However, it does not assume a case where the argument is not On the other hand, %%timeit
hyper((-S(1)/2, S(1)/2), (1,), x)._eval_nseries(x, n=50, logx=None, cdir=0)
880 µs ± 40.6 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each) %%timeit
hyperexpand(Function._eval_nseries(hyper((-S(1)/2, S(1)/2), (1,), x), x, n=50, logx=None, cdir=0))
6.41 ms ± 260 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) The safest way would be to evaluate with |
It would probably be best to compute In any case the bug that gives incorrect results should be fixed so if there is any doubt about what to do it would be better to begin by deleting the method that gives incorrect results. |
Yes, it is. I think we can delete it. |
This is from Sage:
https://groups.google.com/g/sage-support/c/dDe6JLMOgbM/m/mQLMehDFAAAJ?utm_medium=email&utm_source=footer
That gives:
The answer should be
-1/8
.The text was updated successfully, but these errors were encountered: