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
(Integration) regressions? #21034
Comments
The problem is this leads to infinite recursion: In [2]: e = x*(-x**4/asin(5)**4 - x*sinh(x + log(asin(5))) + 5)
In [3]: e.is_zero That gets stuck in sinh(x + log(asin(5))).is_extended_positive It seems that this freezes: In [3]: e = -I*log((re(asin(5)) + I*im(asin(5)))/sqrt(re(asin(5))**2 + im(asin(5))**2))
In [4]: e % pi
^C That freezes because this does: In [7]: e2 = -I*log((re(asin(5)) + I*im(asin(5)))/sqrt(re(asin(5))**2 + im(asin(5))**2))/pi
In [8]: e2.round(2) There seems to be an infinite recursion on these lines: Lines 3770 to 3772 in 4c8422b
The problem is self==r . This expression seems to be real but fails the is_extended_real test.
The reason the if x.is_extended_real is False: That gives this diff: diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index 38c423a70f..1c7ef70b6a 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -3767,7 +3767,7 @@ def round(self, n=None):
'Expected a number but got %s:' % func_name(x))
elif x in (S.NaN, S.Infinity, S.NegativeInfinity, S.ComplexInfinity):
return x
- if not x.is_extended_real:
+ if x.is_extended_real is False:
r, i = x.as_real_imag()
return r.round(n) + S.ImaginaryUnit*i.round(n)
if not x: With that diff we get: In [1]: f1 = x*(-x**4/asin(5)**4 - x*sinh(x + log(asin(5))) + 5)
In [2]: integrate(f1, x)
Out[2]:
6 2
x 2 5⋅x
- ────────── - x ⋅cosh(x + log(asin(5))) + ──── + 2⋅x⋅sinh(x + log(asin(5))) - 2⋅cosh(x + log(asin(5)))
4 2
6⋅asin (5) I'm going to mark this as easy to fix although the issue with |
To fix this issue the diff above should be applied and also tests should be added for all of the issues that I highlighted (as well as the integral for For |
Hey, @oscarbenjamin, I have applied the diff you mentioned. Where should I add tests? I have added in |
You'll need to import the
I would add the test in |
Thank you |
Hi, I'd like to try to fix this issue |
Dear Prajwal, To sum up, as far as I understood, the current status is:
|
A first step would be to use |
The RecursionError for In [7]: Mod(4*x, I*pi)
---------------------------------------------------------------------------
RecursionError That gives a RecursionError in sympy 1.7.1 as well as master so the change between 1.7.1 and current master must be due to something else but the bug is there in both. The infinite recursion comes from here: Line 221 in b564d9b
The guard evaluate=(p, q) != (pwas, qwas) is intended to prevent infinite recursion but it doesn't work because in this example p = -pwas and q = -qwas :
|
Integration of sympy/sympy/solvers/solvers.py Lines 913 to 917 in 7053279
I tested the integral by introducing this flag and necessary code it works fine again. |
I'm interested in working on this issue. Is the problem with Edit: Nevermind, my apologies, I didn't see the most recent comment when I posted this. |
I think that the bug in |
I saw this behavior of the >>> from sympy import *
>>> x = Symbol('x', real=True, nonzero=True)
>>> f2 = (x + cosh(sin(4)))/(x*(x + 1/(12*x)))
>>> print(integrate(f2, x))
(1/2 - sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*log(x + (-exp(7*I*exp(-4*I)/2)*exp(I*exp(4*I)/2) + 2*(1/2 - sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*exp(7*I*exp(-4*I)/2)*exp(I*exp(4*I)/2) - 3*exp(5*I*exp(-4*I)/2)*exp(3*I*exp(4*I)/2) - 3*exp(3*I*exp(-4*I)/2)*exp(5*I*exp(4*I)/2) + 6*(1/2 - sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*exp(5*I*exp(-4*I)/2)*exp(3*I*exp(4*I)/2) - exp(I*exp(-4*I)/2)*exp(7*I*exp(4*I)/2) + 6*(1/2 - sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*exp(3*I*exp(-4*I)/2)*exp(5*I*exp(4*I)/2) + 2*(1/2 - sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*exp(I*exp(-4*I)/2)*exp(7*I*exp(4*I)/2))/(6*exp(4*I*exp(4*I)) + 24*exp(I*exp(-4*I))*exp(3*I*exp(4*I)) + 36*exp(2*I*exp(-4*I))*exp(2*I*exp(4*I)) + 24*exp(3*I*exp(-4*I))*exp(I*exp(4*I)) + 6*exp(4*I*exp(-4*I)))) + (1/2 + sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*log(x + (2*(1/2 + sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*exp(I*exp(-4*I)/2)*exp(7*I*exp(4*I)/2) + 6*(1/2 + sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*exp(3*I*exp(-4*I)/2)*exp(5*I*exp(4*I)/2) + 6*(1/2 + sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*exp(5*I*exp(-4*I)/2)*exp(3*I*exp(4*I)/2) + 2*(1/2 + sqrt(3)*sqrt(-exp(I*exp(-4*I))*exp(I*exp(4*I)))*(exp(I*exp(4*I)) + exp(I*exp(-4*I)))*exp(-I*exp(-4*I))*exp(-I*exp(4*I))/2)*exp(7*I*exp(-4*I)/2)*exp(I*exp(4*I)/2) - exp(7*I*exp(-4*I)/2)*exp(I*exp(4*I)/2) - 3*exp(5*I*exp(-4*I)/2)*exp(3*I*exp(4*I)/2) - 3*exp(3*I*exp(-4*I)/2)*exp(5*I*exp(4*I)/2) - exp(I*exp(-4*I)/2)*exp(7*I*exp(4*I)/2))/(6*exp(4*I*exp(4*I)) + 24*exp(I*exp(-4*I))*exp(3*I*exp(4*I)) + 36*exp(2*I*exp(-4*I))*exp(2*I*exp(4*I)) + 24*exp(3*I*exp(-4*I))*exp(I*exp(4*I)) + 6*exp(4*I*exp(-4*I)))) The actual result should have been,
So, in my opinion, the problem with |
It would be better to avoid/limit the rewrite than to simplify later on. The rewrite could be changed to something like:
|
Hello, I am trying to integrate the following expressions (
f
) which work under SymPy v1.4 but fail on both the master version and 1.7.1.Behavior in v1.4 is:
For
f1
: v1.7.1 and master raise the following error:RecursionError: maximum recursion depth exceeded
For
f2
: v1.7.1 raises CoercionFailed error (issue possibly related to #21024), while master fails withRecursionError: maximum recursion depth exceeded
The text was updated successfully, but these errors were encountered: