test_failing_integrals.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. # A collection of failing integrals from the issues.
  2. from sympy.core.numbers import (I, Rational, oo, pi)
  3. from sympy.core.singleton import S
  4. from sympy.core.symbol import symbols
  5. from sympy.functions.elementary.complexes import sign
  6. from sympy.functions.elementary.exponential import (exp, log)
  7. from sympy.functions.elementary.hyperbolic import (sech, sinh)
  8. from sympy.functions.elementary.miscellaneous import sqrt
  9. from sympy.functions.elementary.piecewise import Piecewise
  10. from sympy.functions.elementary.trigonometric import (acos, atan, cos, sin, tan)
  11. from sympy.functions.special.delta_functions import DiracDelta
  12. from sympy.functions.special.gamma_functions import gamma
  13. from sympy.integrals.integrals import (Integral, integrate)
  14. from sympy.simplify.fu import fu
  15. from sympy.testing.pytest import XFAIL, slow, tooslow
  16. from sympy.abc import x, k, c, y, b, h, a, m, z, n, t
  17. @tooslow
  18. @XFAIL
  19. def test_issue_3880():
  20. # integrate_hyperexponential(Poly(t*2*(1 - t0**2)*t0*(x**3 + x**2), t), Poly((1 + t0**2)**2*2*(x**2 + x + 1), t), [Poly(1, x), Poly(1 + t0**2, t0), Poly(t, t)], [x, t0, t], [exp, tan])
  21. assert not integrate(exp(x)*cos(2*x)*sin(2*x) * (x**3 + x**2)/(2*(x**2 + x + 1)), x).has(Integral)
  22. def test_issue_4212_real():
  23. xr = symbols('xr', real=True)
  24. negabsx = Piecewise((-xr, xr < 0), (xr, True))
  25. assert integrate(sign(xr), xr) == negabsx
  26. @XFAIL
  27. def test_issue_4212():
  28. # XXX: Maybe this should be expected to fail without real assumptions on x.
  29. # As a complex function sign(x) is not analytic and so there is no complex
  30. # function whose complex derivative is sign(x). With real assumptions this
  31. # works (see test_issue_4212_real above).
  32. assert not integrate(sign(x), x).has(Integral)
  33. def test_issue_4511():
  34. # This works, but gives a slightly over-complicated answer.
  35. f = integrate(cos(x)**2 / (1 - sin(x)), x)
  36. assert fu(f) == x - cos(x) - 1
  37. assert f == ((x*tan(x/2)**2 + x - 2)/(tan(x/2)**2 + 1)).expand()
  38. def test_integrate_DiracDelta_no_meijerg():
  39. assert integrate(integrate(integrate(
  40. DiracDelta(x - y - z), (z, 0, oo)), (y, 0, 1), meijerg=False), (x, 0, 1)) == S.Half
  41. @XFAIL
  42. def test_integrate_DiracDelta_fails():
  43. # issue 6427
  44. # works without meijerg. See test_integrate_DiracDelta_no_meijerg above.
  45. assert integrate(integrate(integrate(
  46. DiracDelta(x - y - z), (z, 0, oo)), (y, 0, 1)), (x, 0, 1)) == S.Half
  47. @XFAIL
  48. @slow
  49. def test_issue_4525():
  50. # Warning: takes a long time
  51. assert not integrate((x**m * (1 - x)**n * (a + b*x + c*x**2))/(1 + x**2), (x, 0, 1)).has(Integral)
  52. @XFAIL
  53. @tooslow
  54. def test_issue_4540():
  55. # Note, this integral is probably nonelementary
  56. assert not integrate(
  57. (sin(1/x) - x*exp(x)) /
  58. ((-sin(1/x) + x*exp(x))*x + x*sin(1/x)), x).has(Integral)
  59. @XFAIL
  60. @slow
  61. def test_issue_4891():
  62. # Requires the hypergeometric function.
  63. assert not integrate(cos(x)**y, x).has(Integral)
  64. @XFAIL
  65. @slow
  66. def test_issue_1796a():
  67. assert not integrate(exp(2*b*x)*exp(-a*x**2), x).has(Integral)
  68. @XFAIL
  69. def test_issue_4895b():
  70. assert not integrate(exp(2*b*x)*exp(-a*x**2), (x, -oo, 0)).has(Integral)
  71. @XFAIL
  72. def test_issue_4895c():
  73. assert not integrate(exp(2*b*x)*exp(-a*x**2), (x, -oo, oo)).has(Integral)
  74. @XFAIL
  75. def test_issue_4895d():
  76. assert not integrate(exp(2*b*x)*exp(-a*x**2), (x, 0, oo)).has(Integral)
  77. @XFAIL
  78. @slow
  79. def test_issue_4941():
  80. assert not integrate(sqrt(1 + sinh(x/20)**2), (x, -25, 25)).has(Integral)
  81. @XFAIL
  82. def test_issue_4992():
  83. # Nonelementary integral. Requires hypergeometric/Meijer-G handling.
  84. assert not integrate(log(x) * x**(k - 1) * exp(-x) / gamma(k), (x, 0, oo)).has(Integral)
  85. @XFAIL
  86. def test_issue_16396a():
  87. i = integrate(1/(1+sqrt(tan(x))), (x, pi/3, pi/6))
  88. assert not i.has(Integral)
  89. @XFAIL
  90. def test_issue_16396b():
  91. i = integrate(x*sin(x)/(1+cos(x)**2), (x, 0, pi))
  92. assert not i.has(Integral)
  93. @XFAIL
  94. def test_issue_16046():
  95. assert integrate(exp(exp(I*x)), [x, 0, 2*pi]) == 2*pi
  96. @XFAIL
  97. def test_issue_15925a():
  98. assert not integrate(sqrt((1+sin(x))**2+(cos(x))**2), (x, -pi/2, pi/2)).has(Integral)
  99. def test_issue_15925b():
  100. f = sqrt((-12*cos(x)**2*sin(x))**2+(12*cos(x)*sin(x)**2)**2)
  101. assert integrate(f, (x, 0, pi/6)) == Rational(3, 2)
  102. @XFAIL
  103. def test_issue_15925b_manual():
  104. assert not integrate(sqrt((-12*cos(x)**2*sin(x))**2+(12*cos(x)*sin(x)**2)**2),
  105. (x, 0, pi/6), manual=True).has(Integral)
  106. @XFAIL
  107. @tooslow
  108. def test_issue_15227():
  109. i = integrate(log(1-x)*log((1+x)**2)/x, (x, 0, 1))
  110. assert not i.has(Integral)
  111. # assert i == -5*zeta(3)/4
  112. @XFAIL
  113. @slow
  114. def test_issue_14716():
  115. i = integrate(log(x + 5)*cos(pi*x),(x, S.Half, 1))
  116. assert not i.has(Integral)
  117. # Mathematica can not solve it either, but
  118. # integrate(log(x + 5)*cos(pi*x),(x, S.Half, 1)).transform(x, y - 5).doit()
  119. # works
  120. # assert i == -log(Rational(11, 2))/pi - Si(pi*Rational(11, 2))/pi + Si(6*pi)/pi
  121. @XFAIL
  122. def test_issue_14709a():
  123. i = integrate(x*acos(1 - 2*x/h), (x, 0, h))
  124. assert not i.has(Integral)
  125. # assert i == 5*h**2*pi/16
  126. @slow
  127. @XFAIL
  128. def test_issue_14398():
  129. assert not integrate(exp(x**2)*cos(x), x).has(Integral)
  130. @XFAIL
  131. def test_issue_14074():
  132. i = integrate(log(sin(x)), (x, 0, pi/2))
  133. assert not i.has(Integral)
  134. # assert i == -pi*log(2)/2
  135. @XFAIL
  136. @slow
  137. def test_issue_14078b():
  138. i = integrate((atan(4*x)-atan(2*x))/x, (x, 0, oo))
  139. assert not i.has(Integral)
  140. # assert i == pi*log(2)/2
  141. @XFAIL
  142. def test_issue_13792():
  143. i = integrate(log(1/x) / (1 - x), (x, 0, 1))
  144. assert not i.has(Integral)
  145. # assert i in [polylog(2, -exp_polar(I*pi)), pi**2/6]
  146. @XFAIL
  147. def test_issue_11845a():
  148. assert not integrate(exp(y - x**3), (x, 0, 1)).has(Integral)
  149. @XFAIL
  150. def test_issue_11845b():
  151. assert not integrate(exp(-y - x**3), (x, 0, 1)).has(Integral)
  152. @XFAIL
  153. def test_issue_11813():
  154. assert not integrate((a - x)**Rational(-1, 2)*x, (x, 0, a)).has(Integral)
  155. @XFAIL
  156. def test_issue_11254c():
  157. assert not integrate(sech(x)**2, (x, 0, 1)).has(Integral)
  158. @XFAIL
  159. def test_issue_10584():
  160. assert not integrate(sqrt(x**2 + 1/x**2), x).has(Integral)
  161. @XFAIL
  162. def test_issue_9101():
  163. assert not integrate(log(x + sqrt(x**2 + y**2 + z**2)), z).has(Integral)
  164. @XFAIL
  165. def test_issue_7147():
  166. assert not integrate(x/sqrt(a*x**2 + b*x + c)**3, x).has(Integral)
  167. @XFAIL
  168. def test_issue_7109():
  169. assert not integrate(sqrt(a**2/(a**2 - x**2)), x).has(Integral)
  170. @XFAIL
  171. def test_integrate_Piecewise_rational_over_reals():
  172. f = Piecewise(
  173. (0, t - 478.515625*pi < 0),
  174. (13.2075145209219*pi/(0.000871222*t + 0.995)**2, t - 478.515625*pi >= 0))
  175. assert abs((integrate(f, (t, 0, oo)) - 15235.9375*pi).evalf()) <= 1e-7
  176. @XFAIL
  177. def test_issue_4311_slow():
  178. # Not slow when bypassing heurish
  179. assert not integrate(x*abs(9-x**2), x).has(Integral)
  180. @XFAIL
  181. def test_issue_20370():
  182. a = symbols('a', positive=True)
  183. assert integrate((1 + a * cos(x))**-1, (x, 0, 2 * pi)) == (2 * pi / sqrt(1 - a**2))
  184. @XFAIL
  185. def test_polylog():
  186. # log(1/x)*log(x+1)-polylog(2, -x)
  187. assert not integrate(log(1/x)/(x + 1), x).has(Integral)
  188. @XFAIL
  189. def test_polylog_manual():
  190. # Make sure _parts_rule does not go into an infinite loop here
  191. assert not integrate(log(1/x)/(x + 1), x, manual=True).has(Integral)