sympy / sympy

A computer algebra system written in pure Python
https://sympy.org/
Other
12.79k stars 4.39k forks source link

[integrals] Wrong result for Integral((cos(x**2)-cos(x))/x**2, (x, -oo, oo)) #22487

Open sbondaryev opened 2 years ago

sbondaryev commented 2 years ago
Screenshot 2021-11-13 at 17 28 54

SymPy 1.9

Screenshot 2021-11-13 at 17 35 47
asmeurer commented 2 years ago

In the future, please paste the code into the issue instead of posting a screenshot. That way we can actually copy the code to execute it.

asmeurer commented 2 years ago

The definite integral gives the right answer, although it can't simplify it.

>>> integrate((cos(x**2) - cos(x))/x**2, x)
Si(x) + sqrt(2)*sqrt(pi)*fresnels(sqrt(2)*x/sqrt(pi))*gamma(-1/4)/(4*gamma(3/4)) + cos(x)/x + cos(x**2)*gamma(-1/4)/(4*x*gamma(3/4))
>>> limit(integrate((cos(x**2) - cos(x))/x**2, x), x, -oo)
-pi/2 - sqrt(2)*sqrt(pi)*gamma(-1/4)/(8*gamma(3/4))
>>> limit(integrate((cos(x**2) - cos(x))/x**2, x), x, oo)
sqrt(2)*sqrt(pi)*gamma(-1/4)/(8*gamma(3/4)) + pi/2
>>> simplify(limit(integrate((cos(x**2) - cos(x))/x**2, x), x, oo) - limit(integrate((cos(x**2) - cos(x))/x**2, x), x, -oo))
sqrt(2)*sqrt(pi)*gamma(-1/4)/(4*gamma(3/4)) + pi
>>> N(limit(integrate((cos(x**2) - cos(x))/x**2, x), x, oo) - limit(integrate((cos(x**2) - cos(x))/x**2, x), x, -oo))
0.634964378958793
oscargus commented 2 years ago

Even substituting with oo and -oo gives the correct result.

Edit: "correct" = the same as the limit.

sbondaryev commented 2 years ago

@asmeurer , @oscargus Still not working with when I use the Integral syntax

Step to reproduce

  1. go to https://www.sympy.org/en/shell.html
  2. enter
    from sympy.abc import x;I=Integral((cos(x**2)-cos(x))/x**2, (x, -oo, oo)); I.doit()
oscarbenjamin commented 2 years ago

The incorrect result comes from meijerg. The result changed from -oo to oo after 7ed5f670e5283e6355f4b786c900e628fd71c77e.