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

Bug in integration solver #21721

Closed
stopslavery404 opened this issue Jul 8, 2021 · 9 comments · Fixed by #23592
Closed

Bug in integration solver #21721

stopslavery404 opened this issue Jul 8, 2021 · 9 comments · Fixed by #23592

Comments

@stopslavery404
Copy link

stopslavery404 commented Jul 8, 2021

For calculating the integration of pdf of cauchy distribution I tried sympy, but it produced wrong result.

integrate(1/(pi*(1+(x-a)**2)),(x,-oo,oo))
the expected output was 1 but it produced output 0 which is wrong.

image

image
image

@oscarbenjamin
Copy link
Contributor

If a is declared as real then the correct answer is given:

In [8]: a = Symbol('a', real=True)

In [9]: integrate(1/(pi*(1+(x-a)**2)),(x,-oo,oo))
Out[9]: 1

@stopslavery404
Copy link
Author

Thank you so much :)

@oscarbenjamin
Copy link
Contributor

Reopening because the answer should not be given as zero when a has not been declared as real

@oscarbenjamin
Copy link
Contributor

Seems to be a bug in the limit code:

In [1]: a = Symbol('a')

In [2]: I = integrate(1/(pi*(1+(x-a)**2)),x)

In [3]: I
Out[3]: 
  log(-a + x - )   log(-a + x + )
- ───────────────── + ─────────────────
          2                   2        
───────────────────────────────────────
                   π                   

In [4]: I.limit(x, oo)
Out[4]: 0

In [5]: I.limit(x, -oo)   # <-- should be -1
Out[5]: 0

Seems to be also a bug for this limit (even though the integral works in this case):

In [9]: a = Symbol('a', real=True)

In [10]: I = integrate(1/(pi*(1+(x-a)**2)),x)

In [11]: I
Out[11]: 
-atan(a - x) 
─────────────
      π      

In [12]: I.limit(x, oo)  # <-- should be +1/2
Out[12]: -1/2

In [13]: I.limit(x, -oo)
Out[13]: -1/2

@oscarbenjamin
Copy link
Contributor

In [12]: I.limit(x, oo)  # <-- should be +1/2
Out[12]: -1/2

Actually this is a regression on master since sympy 1.8. Bisected to 2b6b233 from #21589
CC @0sidharth @jksuom

@oscarbenjamin oscarbenjamin added this to the SymPy 1.9 milestone Jul 8, 2021
@jksuom
Copy link
Member

jksuom commented Jul 8, 2021

In [4]: I.limit(x, oo)
Out[4]: 0

In [5]: I.limit(x, -oo)   # <-- should be -1
Out[5]: 0

I get these results also on sympy-1.8. It looks like that would be correct if im(a) > 1 so that the arguments of the two log terms are on the same side of the real axis (on the same branch).

@oscarbenjamin
Copy link
Contributor

oscarbenjamin commented Jul 8, 2021

I get these results also on sympy-1.8.

I wonder if it depends on the Python version because I do not get the same in sympy 1.8 with Python 3.6 on Linux...

EDIT: I see that actually you were referring to the example without real=True.

skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 9, 2021
@0sidharth
Copy link
Member

The limit regression has been fixed in #21731, although the answer is still returned as 0 when a is not declared real.

@oscarbenjamin
Copy link
Contributor

Some of the problems mentioned above are fixed but some remain. The part that was identified as a regression has been fixed:

In [28]: a = Symbol('a', real=True)

In [29]: I = integrate(1/(pi*(1+(x-a)**2)),x)

In [30]: I.limit(x, oo)  # <-- should be +1/2
Out[30]: 1/2

I'm removing the 1.9 milestone.

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

Successfully merging a pull request may close this issue.

4 participants