m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1077 lines
49 KiB

6 months ago
  1. from sympy.integrals.transforms import (mellin_transform,
  2. inverse_mellin_transform, laplace_transform,
  3. inverse_laplace_transform, fourier_transform, inverse_fourier_transform,
  4. sine_transform, inverse_sine_transform,
  5. cosine_transform, inverse_cosine_transform,
  6. hankel_transform, inverse_hankel_transform,
  7. LaplaceTransform, FourierTransform, SineTransform, CosineTransform,
  8. InverseLaplaceTransform, InverseFourierTransform,
  9. InverseSineTransform, InverseCosineTransform, IntegralTransformError)
  10. from sympy.core.function import (Function, expand_mul)
  11. from sympy.core import EulerGamma, Subs, Derivative, diff
  12. from sympy.core.numbers import (I, Rational, oo, pi)
  13. from sympy.core.relational import Eq
  14. from sympy.core.singleton import S
  15. from sympy.core.symbol import (Symbol, symbols)
  16. from sympy.functions.combinatorial.factorials import factorial
  17. from sympy.functions.elementary.complexes import (Abs, re, unpolarify)
  18. from sympy.functions.elementary.exponential import (exp, exp_polar, log)
  19. from sympy.functions.elementary.hyperbolic import (cosh, sinh, coth, asinh)
  20. from sympy.functions.elementary.miscellaneous import sqrt
  21. from sympy.functions.elementary.trigonometric import (atan, atan2, cos, sin, tan)
  22. from sympy.functions.special.bessel import (besseli, besselj, besselk, bessely)
  23. from sympy.functions.special.delta_functions import Heaviside
  24. from sympy.functions.special.error_functions import (erf, erfc, expint, Ei)
  25. from sympy.functions.special.gamma_functions import gamma
  26. from sympy.functions.special.hyper import meijerg
  27. from sympy.simplify.gammasimp import gammasimp
  28. from sympy.simplify.hyperexpand import hyperexpand
  29. from sympy.simplify.trigsimp import trigsimp
  30. from sympy.testing.pytest import XFAIL, slow, skip, raises, warns_deprecated_sympy
  31. from sympy.matrices import Matrix, eye
  32. from sympy.abc import x, s, a, b, c, d
  33. nu, beta, rho = symbols('nu beta rho')
  34. def test_undefined_function():
  35. from sympy.integrals.transforms import MellinTransform
  36. f = Function('f')
  37. assert mellin_transform(f(x), x, s) == MellinTransform(f(x), x, s)
  38. assert mellin_transform(f(x) + exp(-x), x, s) == \
  39. (MellinTransform(f(x), x, s) + gamma(s + 1)/s, (0, oo), True)
  40. def test_free_symbols():
  41. f = Function('f')
  42. assert mellin_transform(f(x), x, s).free_symbols == {s}
  43. assert mellin_transform(f(x)*a, x, s).free_symbols == {s, a}
  44. def test_as_integral():
  45. from sympy.integrals.integrals import Integral
  46. f = Function('f')
  47. assert mellin_transform(f(x), x, s).rewrite('Integral') == \
  48. Integral(x**(s - 1)*f(x), (x, 0, oo))
  49. assert fourier_transform(f(x), x, s).rewrite('Integral') == \
  50. Integral(f(x)*exp(-2*I*pi*s*x), (x, -oo, oo))
  51. assert laplace_transform(f(x), x, s).rewrite('Integral') == \
  52. Integral(f(x)*exp(-s*x), (x, 0, oo))
  53. assert str(2*pi*I*inverse_mellin_transform(f(s), s, x, (a, b)).rewrite('Integral')) \
  54. == "Integral(f(s)/x**s, (s, _c - oo*I, _c + oo*I))"
  55. assert str(2*pi*I*inverse_laplace_transform(f(s), s, x).rewrite('Integral')) == \
  56. "Integral(f(s)*exp(s*x), (s, _c - oo*I, _c + oo*I))"
  57. assert inverse_fourier_transform(f(s), s, x).rewrite('Integral') == \
  58. Integral(f(s)*exp(2*I*pi*s*x), (s, -oo, oo))
  59. # NOTE this is stuck in risch because meijerint cannot handle it
  60. @slow
  61. @XFAIL
  62. def test_mellin_transform_fail():
  63. skip("Risch takes forever.")
  64. MT = mellin_transform
  65. bpos = symbols('b', positive=True)
  66. # bneg = symbols('b', negative=True)
  67. expr = (sqrt(x + b**2) + b)**a/sqrt(x + b**2)
  68. # TODO does not work with bneg, argument wrong. Needs changes to matching.
  69. assert MT(expr.subs(b, -bpos), x, s) == \
  70. ((-1)**(a + 1)*2**(a + 2*s)*bpos**(a + 2*s - 1)*gamma(a + s)
  71. *gamma(1 - a - 2*s)/gamma(1 - s),
  72. (-re(a), -re(a)/2 + S.Half), True)
  73. expr = (sqrt(x + b**2) + b)**a
  74. assert MT(expr.subs(b, -bpos), x, s) == \
  75. (
  76. 2**(a + 2*s)*a*bpos**(a + 2*s)*gamma(-a - 2*
  77. s)*gamma(a + s)/gamma(-s + 1),
  78. (-re(a), -re(a)/2), True)
  79. # Test exponent 1:
  80. assert MT(expr.subs({b: -bpos, a: 1}), x, s) == \
  81. (-bpos**(2*s + 1)*gamma(s)*gamma(-s - S.Half)/(2*sqrt(pi)),
  82. (-1, Rational(-1, 2)), True)
  83. def test_mellin_transform():
  84. from sympy.functions.elementary.miscellaneous import (Max, Min)
  85. MT = mellin_transform
  86. bpos = symbols('b', positive=True)
  87. # 8.4.2
  88. assert MT(x**nu*Heaviside(x - 1), x, s) == \
  89. (-1/(nu + s), (-oo, -re(nu)), True)
  90. assert MT(x**nu*Heaviside(1 - x), x, s) == \
  91. (1/(nu + s), (-re(nu), oo), True)
  92. assert MT((1 - x)**(beta - 1)*Heaviside(1 - x), x, s) == \
  93. (gamma(beta)*gamma(s)/gamma(beta + s), (0, oo), re(beta) > 0)
  94. assert MT((x - 1)**(beta - 1)*Heaviside(x - 1), x, s) == \
  95. (gamma(beta)*gamma(1 - beta - s)/gamma(1 - s),
  96. (-oo, 1 - re(beta)), re(beta) > 0)
  97. assert MT((1 + x)**(-rho), x, s) == \
  98. (gamma(s)*gamma(rho - s)/gamma(rho), (0, re(rho)), True)
  99. assert MT(abs(1 - x)**(-rho), x, s) == (
  100. 2*sin(pi*rho/2)*gamma(1 - rho)*
  101. cos(pi*(s - rho/2))*gamma(s)*gamma(rho-s)/pi,
  102. (0, re(rho)), re(rho) < 1)
  103. mt = MT((1 - x)**(beta - 1)*Heaviside(1 - x)
  104. + a*(x - 1)**(beta - 1)*Heaviside(x - 1), x, s)
  105. assert mt[1], mt[2] == ((0, -re(beta) + 1), re(beta) > 0)
  106. assert MT((x**a - b**a)/(x - b), x, s)[0] == \
  107. pi*b**(a + s - 1)*sin(pi*a)/(sin(pi*s)*sin(pi*(a + s)))
  108. assert MT((x**a - bpos**a)/(x - bpos), x, s) == \
  109. (pi*bpos**(a + s - 1)*sin(pi*a)/(sin(pi*s)*sin(pi*(a + s))),
  110. (Max(0, -re(a)), Min(1, 1 - re(a))), True)
  111. expr = (sqrt(x + b**2) + b)**a
  112. assert MT(expr.subs(b, bpos), x, s) == \
  113. (-a*(2*bpos)**(a + 2*s)*gamma(s)*gamma(-a - 2*s)/gamma(-a - s + 1),
  114. (0, -re(a)/2), True)
  115. expr = (sqrt(x + b**2) + b)**a/sqrt(x + b**2)
  116. assert MT(expr.subs(b, bpos), x, s) == \
  117. (2**(a + 2*s)*bpos**(a + 2*s - 1)*gamma(s)
  118. *gamma(1 - a - 2*s)/gamma(1 - a - s),
  119. (0, -re(a)/2 + S.Half), True)
  120. # 8.4.2
  121. assert MT(exp(-x), x, s) == (gamma(s), (0, oo), True)
  122. assert MT(exp(-1/x), x, s) == (gamma(-s), (-oo, 0), True)
  123. # 8.4.5
  124. assert MT(log(x)**4*Heaviside(1 - x), x, s) == (24/s**5, (0, oo), True)
  125. assert MT(log(x)**3*Heaviside(x - 1), x, s) == (6/s**4, (-oo, 0), True)
  126. assert MT(log(x + 1), x, s) == (pi/(s*sin(pi*s)), (-1, 0), True)
  127. assert MT(log(1/x + 1), x, s) == (pi/(s*sin(pi*s)), (0, 1), True)
  128. assert MT(log(abs(1 - x)), x, s) == (pi/(s*tan(pi*s)), (-1, 0), True)
  129. assert MT(log(abs(1 - 1/x)), x, s) == (pi/(s*tan(pi*s)), (0, 1), True)
  130. # 8.4.14
  131. assert MT(erf(sqrt(x)), x, s) == \
  132. (-gamma(s + S.Half)/(sqrt(pi)*s), (Rational(-1, 2), 0), True)
  133. def test_mellin_transform2():
  134. MT = mellin_transform
  135. # TODO we cannot currently do these (needs summation of 3F2(-1))
  136. # this also implies that they cannot be written as a single g-function
  137. # (although this is possible)
  138. mt = MT(log(x)/(x + 1), x, s)
  139. assert mt[1:] == ((0, 1), True)
  140. assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg)
  141. mt = MT(log(x)**2/(x + 1), x, s)
  142. assert mt[1:] == ((0, 1), True)
  143. assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg)
  144. mt = MT(log(x)/(x + 1)**2, x, s)
  145. assert mt[1:] == ((0, 2), True)
  146. assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg)
  147. @slow
  148. def test_mellin_transform_bessel():
  149. from sympy.functions.elementary.miscellaneous import Max
  150. MT = mellin_transform
  151. # 8.4.19
  152. assert MT(besselj(a, 2*sqrt(x)), x, s) == \
  153. (gamma(a/2 + s)/gamma(a/2 - s + 1), (-re(a)/2, Rational(3, 4)), True)
  154. assert MT(sin(sqrt(x))*besselj(a, sqrt(x)), x, s) == \
  155. (2**a*gamma(-2*s + S.Half)*gamma(a/2 + s + S.Half)/(
  156. gamma(-a/2 - s + 1)*gamma(a - 2*s + 1)), (
  157. -re(a)/2 - S.Half, Rational(1, 4)), True)
  158. assert MT(cos(sqrt(x))*besselj(a, sqrt(x)), x, s) == \
  159. (2**a*gamma(a/2 + s)*gamma(-2*s + S.Half)/(
  160. gamma(-a/2 - s + S.Half)*gamma(a - 2*s + 1)), (
  161. -re(a)/2, Rational(1, 4)), True)
  162. assert MT(besselj(a, sqrt(x))**2, x, s) == \
  163. (gamma(a + s)*gamma(S.Half - s)
  164. / (sqrt(pi)*gamma(1 - s)*gamma(1 + a - s)),
  165. (-re(a), S.Half), True)
  166. assert MT(besselj(a, sqrt(x))*besselj(-a, sqrt(x)), x, s) == \
  167. (gamma(s)*gamma(S.Half - s)
  168. / (sqrt(pi)*gamma(1 - a - s)*gamma(1 + a - s)),
  169. (0, S.Half), True)
  170. # NOTE: prudnikov gives the strip below as (1/2 - re(a), 1). As far as
  171. # I can see this is wrong (since besselj(z) ~ 1/sqrt(z) for z large)
  172. assert MT(besselj(a - 1, sqrt(x))*besselj(a, sqrt(x)), x, s) == \
  173. (gamma(1 - s)*gamma(a + s - S.Half)
  174. / (sqrt(pi)*gamma(Rational(3, 2) - s)*gamma(a - s + S.Half)),
  175. (S.Half - re(a), S.Half), True)
  176. assert MT(besselj(a, sqrt(x))*besselj(b, sqrt(x)), x, s) == \
  177. (4**s*gamma(1 - 2*s)*gamma((a + b)/2 + s)
  178. / (gamma(1 - s + (b - a)/2)*gamma(1 - s + (a - b)/2)
  179. *gamma( 1 - s + (a + b)/2)),
  180. (-(re(a) + re(b))/2, S.Half), True)
  181. assert MT(besselj(a, sqrt(x))**2 + besselj(-a, sqrt(x))**2, x, s)[1:] == \
  182. ((Max(re(a), -re(a)), S.Half), True)
  183. # Section 8.4.20
  184. assert MT(bessely(a, 2*sqrt(x)), x, s) == \
  185. (-cos(pi*(a/2 - s))*gamma(s - a/2)*gamma(s + a/2)/pi,
  186. (Max(-re(a)/2, re(a)/2), Rational(3, 4)), True)
  187. assert MT(sin(sqrt(x))*bessely(a, sqrt(x)), x, s) == \
  188. (-4**s*sin(pi*(a/2 - s))*gamma(S.Half - 2*s)
  189. * gamma((1 - a)/2 + s)*gamma((1 + a)/2 + s)
  190. / (sqrt(pi)*gamma(1 - s - a/2)*gamma(1 - s + a/2)),
  191. (Max(-(re(a) + 1)/2, (re(a) - 1)/2), Rational(1, 4)), True)
  192. assert MT(cos(sqrt(x))*bessely(a, sqrt(x)), x, s) == \
  193. (-4**s*cos(pi*(a/2 - s))*gamma(s - a/2)*gamma(s + a/2)*gamma(S.Half - 2*s)
  194. / (sqrt(pi)*gamma(S.Half - s - a/2)*gamma(S.Half - s + a/2)),
  195. (Max(-re(a)/2, re(a)/2), Rational(1, 4)), True)
  196. assert MT(besselj(a, sqrt(x))*bessely(a, sqrt(x)), x, s) == \
  197. (-cos(pi*s)*gamma(s)*gamma(a + s)*gamma(S.Half - s)
  198. / (pi**S('3/2')*gamma(1 + a - s)),
  199. (Max(-re(a), 0), S.Half), True)
  200. assert MT(besselj(a, sqrt(x))*bessely(b, sqrt(x)), x, s) == \
  201. (-4**s*cos(pi*(a/2 - b/2 + s))*gamma(1 - 2*s)
  202. * gamma(a/2 - b/2 + s)*gamma(a/2 + b/2 + s)
  203. / (pi*gamma(a/2 - b/2 - s + 1)*gamma(a/2 + b/2 - s + 1)),
  204. (Max((-re(a) + re(b))/2, (-re(a) - re(b))/2), S.Half), True)
  205. # NOTE bessely(a, sqrt(x))**2 and bessely(a, sqrt(x))*bessely(b, sqrt(x))
  206. # are a mess (no matter what way you look at it ...)
  207. assert MT(bessely(a, sqrt(x))**2, x, s)[1:] == \
  208. ((Max(-re(a), 0, re(a)), S.Half), True)
  209. # Section 8.4.22
  210. # TODO we can't do any of these (delicate cancellation)
  211. # Section 8.4.23
  212. assert MT(besselk(a, 2*sqrt(x)), x, s) == \
  213. (gamma(
  214. s - a/2)*gamma(s + a/2)/2, (Max(-re(a)/2, re(a)/2), oo), True)
  215. assert MT(besselj(a, 2*sqrt(2*sqrt(x)))*besselk(
  216. a, 2*sqrt(2*sqrt(x))), x, s) == (4**(-s)*gamma(2*s)*
  217. gamma(a/2 + s)/(2*gamma(a/2 - s + 1)), (Max(0, -re(a)/2), oo), True)
  218. # TODO bessely(a, x)*besselk(a, x) is a mess
  219. assert MT(besseli(a, sqrt(x))*besselk(a, sqrt(x)), x, s) == \
  220. (gamma(s)*gamma(
  221. a + s)*gamma(-s + S.Half)/(2*sqrt(pi)*gamma(a - s + 1)),
  222. (Max(-re(a), 0), S.Half), True)
  223. assert MT(besseli(b, sqrt(x))*besselk(a, sqrt(x)), x, s) == \
  224. (2**(2*s - 1)*gamma(-2*s + 1)*gamma(-a/2 + b/2 + s)* \
  225. gamma(a/2 + b/2 + s)/(gamma(-a/2 + b/2 - s + 1)* \
  226. gamma(a/2 + b/2 - s + 1)), (Max(-re(a)/2 - re(b)/2, \
  227. re(a)/2 - re(b)/2), S.Half), True)
  228. # TODO products of besselk are a mess
  229. mt = MT(exp(-x/2)*besselk(a, x/2), x, s)
  230. mt0 = gammasimp(trigsimp(gammasimp(mt[0].expand(func=True))))
  231. assert mt0 == 2*pi**Rational(3, 2)*cos(pi*s)*gamma(S.Half - s)/(
  232. (cos(2*pi*a) - cos(2*pi*s))*gamma(-a - s + 1)*gamma(a - s + 1))
  233. assert mt[1:] == ((Max(-re(a), re(a)), oo), True)
  234. # TODO exp(x/2)*besselk(a, x/2) [etc] cannot currently be done
  235. # TODO various strange products of special orders
  236. @slow
  237. def test_expint():
  238. from sympy.functions.elementary.miscellaneous import Max
  239. from sympy.functions.special.error_functions import (Ci, E1, Ei, Si)
  240. from sympy.functions.special.zeta_functions import lerchphi
  241. from sympy.simplify.simplify import simplify
  242. aneg = Symbol('a', negative=True)
  243. u = Symbol('u', polar=True)
  244. assert mellin_transform(E1(x), x, s) == (gamma(s)/s, (0, oo), True)
  245. assert inverse_mellin_transform(gamma(s)/s, s, x,
  246. (0, oo)).rewrite(expint).expand() == E1(x)
  247. assert mellin_transform(expint(a, x), x, s) == \
  248. (gamma(s)/(a + s - 1), (Max(1 - re(a), 0), oo), True)
  249. # XXX IMT has hickups with complicated strips ...
  250. assert simplify(unpolarify(
  251. inverse_mellin_transform(gamma(s)/(aneg + s - 1), s, x,
  252. (1 - aneg, oo)).rewrite(expint).expand(func=True))) == \
  253. expint(aneg, x)
  254. assert mellin_transform(Si(x), x, s) == \
  255. (-2**s*sqrt(pi)*gamma(s/2 + S.Half)/(
  256. 2*s*gamma(-s/2 + 1)), (-1, 0), True)
  257. assert inverse_mellin_transform(-2**s*sqrt(pi)*gamma((s + 1)/2)
  258. /(2*s*gamma(-s/2 + 1)), s, x, (-1, 0)) \
  259. == Si(x)
  260. assert mellin_transform(Ci(sqrt(x)), x, s) == \
  261. (-2**(2*s - 1)*sqrt(pi)*gamma(s)/(s*gamma(-s + S.Half)), (0, 1), True)
  262. assert inverse_mellin_transform(
  263. -4**s*sqrt(pi)*gamma(s)/(2*s*gamma(-s + S.Half)),
  264. s, u, (0, 1)).expand() == Ci(sqrt(u))
  265. # TODO LT of Si, Shi, Chi is a mess ...
  266. assert laplace_transform(Ci(x), x, s) == (-log(1 + s**2)/2/s, 0, True)
  267. assert laplace_transform(expint(a, x), x, s) == \
  268. (lerchphi(s*exp_polar(I*pi), 1, a), 0, re(a) > S.Zero)
  269. assert laplace_transform(expint(1, x), x, s) == (log(s + 1)/s, 0, True)
  270. assert laplace_transform(expint(2, x), x, s) == \
  271. ((s - log(s + 1))/s**2, 0, True)
  272. assert inverse_laplace_transform(-log(1 + s**2)/2/s, s, u).expand() == \
  273. Heaviside(u)*Ci(u)
  274. assert inverse_laplace_transform(log(s + 1)/s, s, x).rewrite(expint) == \
  275. Heaviside(x)*E1(x)
  276. assert inverse_laplace_transform((s - log(s + 1))/s**2, s,
  277. x).rewrite(expint).expand() == \
  278. (expint(2, x)*Heaviside(x)).rewrite(Ei).rewrite(expint).expand()
  279. @slow
  280. def test_inverse_mellin_transform():
  281. from sympy.core.function import expand
  282. from sympy.functions.elementary.miscellaneous import (Max, Min)
  283. from sympy.functions.elementary.trigonometric import cot
  284. from sympy.simplify.powsimp import powsimp
  285. from sympy.simplify.simplify import simplify
  286. IMT = inverse_mellin_transform
  287. assert IMT(gamma(s), s, x, (0, oo)) == exp(-x)
  288. assert IMT(gamma(-s), s, x, (-oo, 0)) == exp(-1/x)
  289. assert simplify(IMT(s/(2*s**2 - 2), s, x, (2, oo))) == \
  290. (x**2 + 1)*Heaviside(1 - x)/(4*x)
  291. # test passing "None"
  292. assert IMT(1/(s**2 - 1), s, x, (-1, None)) == \
  293. -x*Heaviside(-x + 1)/2 - Heaviside(x - 1)/(2*x)
  294. assert IMT(1/(s**2 - 1), s, x, (None, 1)) == \
  295. -x*Heaviside(-x + 1)/2 - Heaviside(x - 1)/(2*x)
  296. # test expansion of sums
  297. assert IMT(gamma(s) + gamma(s - 1), s, x, (1, oo)) == (x + 1)*exp(-x)/x
  298. # test factorisation of polys
  299. r = symbols('r', real=True)
  300. assert IMT(1/(s**2 + 1), s, exp(-x), (None, oo)
  301. ).subs(x, r).rewrite(sin).simplify() \
  302. == sin(r)*Heaviside(1 - exp(-r))
  303. # test multiplicative substitution
  304. _a, _b = symbols('a b', positive=True)
  305. assert IMT(_b**(-s/_a)*factorial(s/_a)/s, s, x, (0, oo)) == exp(-_b*x**_a)
  306. assert IMT(factorial(_a/_b + s/_b)/(_a + s), s, x, (-_a, oo)) == x**_a*exp(-x**_b)
  307. def simp_pows(expr):
  308. return simplify(powsimp(expand_mul(expr, deep=False), force=True)).replace(exp_polar, exp)
  309. # Now test the inverses of all direct transforms tested above
  310. # Section 8.4.2
  311. nu = symbols('nu', real=True)
  312. assert IMT(-1/(nu + s), s, x, (-oo, None)) == x**nu*Heaviside(x - 1)
  313. assert IMT(1/(nu + s), s, x, (None, oo)) == x**nu*Heaviside(1 - x)
  314. assert simp_pows(IMT(gamma(beta)*gamma(s)/gamma(s + beta), s, x, (0, oo))) \
  315. == (1 - x)**(beta - 1)*Heaviside(1 - x)
  316. assert simp_pows(IMT(gamma(beta)*gamma(1 - beta - s)/gamma(1 - s),
  317. s, x, (-oo, None))) \
  318. == (x - 1)**(beta - 1)*Heaviside(x - 1)
  319. assert simp_pows(IMT(gamma(s)*gamma(rho - s)/gamma(rho), s, x, (0, None))) \
  320. == (1/(x + 1))**rho
  321. assert simp_pows(IMT(d**c*d**(s - 1)*sin(pi*c)
  322. *gamma(s)*gamma(s + c)*gamma(1 - s)*gamma(1 - s - c)/pi,
  323. s, x, (Max(-re(c), 0), Min(1 - re(c), 1)))) \
  324. == (x**c - d**c)/(x - d)
  325. assert simplify(IMT(1/sqrt(pi)*(-c/2)*gamma(s)*gamma((1 - c)/2 - s)
  326. *gamma(-c/2 - s)/gamma(1 - c - s),
  327. s, x, (0, -re(c)/2))) == \
  328. (1 + sqrt(x + 1))**c
  329. assert simplify(IMT(2**(a + 2*s)*b**(a + 2*s - 1)*gamma(s)*gamma(1 - a - 2*s)
  330. /gamma(1 - a - s), s, x, (0, (-re(a) + 1)/2))) == \
  331. b**(a - 1)*(sqrt(1 + x/b**2) + 1)**(a - 1)*(b**2*sqrt(1 + x/b**2) +
  332. b**2 + x)/(b**2 + x)
  333. assert simplify(IMT(-2**(c + 2*s)*c*b**(c + 2*s)*gamma(s)*gamma(-c - 2*s)
  334. / gamma(-c - s + 1), s, x, (0, -re(c)/2))) == \
  335. b**c*(sqrt(1 + x/b**2) + 1)**c
  336. # Section 8.4.5
  337. assert IMT(24/s**5, s, x, (0, oo)) == log(x)**4*Heaviside(1 - x)
  338. assert expand(IMT(6/s**4, s, x, (-oo, 0)), force=True) == \
  339. log(x)**3*Heaviside(x - 1)
  340. assert IMT(pi/(s*sin(pi*s)), s, x, (-1, 0)) == log(x + 1)
  341. assert IMT(pi/(s*sin(pi*s/2)), s, x, (-2, 0)) == log(x**2 + 1)
  342. assert IMT(pi/(s*sin(2*pi*s)), s, x, (Rational(-1, 2), 0)) == log(sqrt(x) + 1)
  343. assert IMT(pi/(s*sin(pi*s)), s, x, (0, 1)) == log(1 + 1/x)
  344. # TODO
  345. def mysimp(expr):
  346. from sympy.core.function import expand
  347. from sympy.simplify.powsimp import powsimp
  348. from sympy.simplify.simplify import logcombine
  349. return expand(
  350. powsimp(logcombine(expr, force=True), force=True, deep=True),
  351. force=True).replace(exp_polar, exp)
  352. assert mysimp(mysimp(IMT(pi/(s*tan(pi*s)), s, x, (-1, 0)))) in [
  353. log(1 - x)*Heaviside(1 - x) + log(x - 1)*Heaviside(x - 1),
  354. log(x)*Heaviside(x - 1) + log(1 - 1/x)*Heaviside(x - 1) + log(-x +
  355. 1)*Heaviside(-x + 1)]
  356. # test passing cot
  357. assert mysimp(IMT(pi*cot(pi*s)/s, s, x, (0, 1))) in [
  358. log(1/x - 1)*Heaviside(1 - x) + log(1 - 1/x)*Heaviside(x - 1),
  359. -log(x)*Heaviside(-x + 1) + log(1 - 1/x)*Heaviside(x - 1) + log(-x +
  360. 1)*Heaviside(-x + 1), ]
  361. # 8.4.14
  362. assert IMT(-gamma(s + S.Half)/(sqrt(pi)*s), s, x, (Rational(-1, 2), 0)) == \
  363. erf(sqrt(x))
  364. # 8.4.19
  365. assert simplify(IMT(gamma(a/2 + s)/gamma(a/2 - s + 1), s, x, (-re(a)/2, Rational(3, 4)))) \
  366. == besselj(a, 2*sqrt(x))
  367. assert simplify(IMT(2**a*gamma(S.Half - 2*s)*gamma(s + (a + 1)/2)
  368. / (gamma(1 - s - a/2)*gamma(1 - 2*s + a)),
  369. s, x, (-(re(a) + 1)/2, Rational(1, 4)))) == \
  370. sin(sqrt(x))*besselj(a, sqrt(x))
  371. assert simplify(IMT(2**a*gamma(a/2 + s)*gamma(S.Half - 2*s)
  372. / (gamma(S.Half - s - a/2)*gamma(1 - 2*s + a)),
  373. s, x, (-re(a)/2, Rational(1, 4)))) == \
  374. cos(sqrt(x))*besselj(a, sqrt(x))
  375. # TODO this comes out as an amazing mess, but simplifies nicely
  376. assert simplify(IMT(gamma(a + s)*gamma(S.Half - s)
  377. / (sqrt(pi)*gamma(1 - s)*gamma(1 + a - s)),
  378. s, x, (-re(a), S.Half))) == \
  379. besselj(a, sqrt(x))**2
  380. assert simplify(IMT(gamma(s)*gamma(S.Half - s)
  381. / (sqrt(pi)*gamma(1 - s - a)*gamma(1 + a - s)),
  382. s, x, (0, S.Half))) == \
  383. besselj(-a, sqrt(x))*besselj(a, sqrt(x))
  384. assert simplify(IMT(4**s*gamma(-2*s + 1)*gamma(a/2 + b/2 + s)
  385. / (gamma(-a/2 + b/2 - s + 1)*gamma(a/2 - b/2 - s + 1)
  386. *gamma(a/2 + b/2 - s + 1)),
  387. s, x, (-(re(a) + re(b))/2, S.Half))) == \
  388. besselj(a, sqrt(x))*besselj(b, sqrt(x))
  389. # Section 8.4.20
  390. # TODO this can be further simplified!
  391. assert simplify(IMT(-2**(2*s)*cos(pi*a/2 - pi*b/2 + pi*s)*gamma(-2*s + 1) *
  392. gamma(a/2 - b/2 + s)*gamma(a/2 + b/2 + s) /
  393. (pi*gamma(a/2 - b/2 - s + 1)*gamma(a/2 + b/2 - s + 1)),
  394. s, x,
  395. (Max(-re(a)/2 - re(b)/2, -re(a)/2 + re(b)/2), S.Half))) == \
  396. besselj(a, sqrt(x))*-(besselj(-b, sqrt(x)) -
  397. besselj(b, sqrt(x))*cos(pi*b))/sin(pi*b)
  398. # TODO more
  399. # for coverage
  400. assert IMT(pi/cos(pi*s), s, x, (0, S.Half)) == sqrt(x)/(x + 1)
  401. @slow
  402. def test_laplace_transform():
  403. from sympy import lowergamma
  404. from sympy.functions.special.delta_functions import DiracDelta
  405. from sympy.functions.special.error_functions import (fresnelc, fresnels)
  406. LT = laplace_transform
  407. a, b, c, = symbols('a, b, c', positive=True)
  408. t, w, x = symbols('t, w, x')
  409. f = Function("f")
  410. g = Function("g")
  411. # Test rule-base evaluation according to
  412. # http://eqworld.ipmnet.ru/en/auxiliary/inttrans/
  413. # Power-law functions (laplace2.pdf)
  414. assert LT(a*t+t**2+t**(S(5)/2), t, s) ==\
  415. (a/s**2 + 2/s**3 + 15*sqrt(pi)/(8*s**(S(7)/2)), 0, True)
  416. assert LT(b/(t+a), t, s) == (-b*exp(-a*s)*Ei(-a*s), 0, True)
  417. assert LT(1/sqrt(t+a), t, s) ==\
  418. (sqrt(pi)*sqrt(1/s)*exp(a*s)*erfc(sqrt(a)*sqrt(s)), 0, True)
  419. assert LT(sqrt(t)/(t+a), t, s) ==\
  420. (-pi*sqrt(a)*exp(a*s)*erfc(sqrt(a)*sqrt(s)) + sqrt(pi)*sqrt(1/s),
  421. 0, True)
  422. assert LT((t+a)**(-S(3)/2), t, s) ==\
  423. (-2*sqrt(pi)*sqrt(s)*exp(a*s)*erfc(sqrt(a)*sqrt(s)) + 2/sqrt(a),
  424. 0, True)
  425. assert LT(t**(S(1)/2)*(t+a)**(-1), t, s) ==\
  426. (-pi*sqrt(a)*exp(a*s)*erfc(sqrt(a)*sqrt(s)) + sqrt(pi)*sqrt(1/s),
  427. 0, True)
  428. assert LT(1/(a*sqrt(t) + t**(3/2)), t, s) ==\
  429. (pi*sqrt(a)*exp(a*s)*erfc(sqrt(a)*sqrt(s)), 0, True)
  430. assert LT((t+a)**b, t, s) ==\
  431. (s**(-b - 1)*exp(-a*s)*lowergamma(b + 1, a*s), 0, True)
  432. assert LT(t**5/(t+a), t, s) == (120*a**5*lowergamma(-5, a*s), 0, True)
  433. # Exponential functions (laplace3.pdf)
  434. assert LT(exp(t), t, s) == (1/(s - 1), 1, True)
  435. assert LT(exp(2*t), t, s) == (1/(s - 2), 2, True)
  436. assert LT(exp(a*t), t, s) == (1/(s - a), a, True)
  437. assert LT(exp(a*(t-b)), t, s) == (exp(-a*b)/(-a + s), a, True)
  438. assert LT(t*exp(-a*(t)), t, s) == ((a + s)**(-2), -a, True)
  439. assert LT(t*exp(-a*(t-b)), t, s) == (exp(a*b)/(a + s)**2, -a, True)
  440. assert LT(b*t*exp(-a*t), t, s) == (b/(a + s)**2, -a, True)
  441. assert LT(t**(S(7)/4)*exp(-8*t)/gamma(S(11)/4), t, s) ==\
  442. ((s + 8)**(-S(11)/4), -8, True)
  443. assert LT(t**(S(3)/2)*exp(-8*t), t, s) ==\
  444. (3*sqrt(pi)/(4*(s + 8)**(S(5)/2)), -8, True)
  445. assert LT(t**a*exp(-a*t), t, s) == ((a+s)**(-a-1)*gamma(a+1), -a, True)
  446. assert LT(b*exp(-a*t**2), t, s) ==\
  447. (sqrt(pi)*b*exp(s**2/(4*a))*erfc(s/(2*sqrt(a)))/(2*sqrt(a)), 0, True)
  448. assert LT(exp(-2*t**2), t, s) ==\
  449. (sqrt(2)*sqrt(pi)*exp(s**2/8)*erfc(sqrt(2)*s/4)/4, 0, True)
  450. assert LT(b*exp(2*t**2), t, s) == b*LaplaceTransform(exp(2*t**2), t, s)
  451. assert LT(t*exp(-a*t**2), t, s) ==\
  452. (1/(2*a) - s*erfc(s/(2*sqrt(a)))/(4*sqrt(pi)*a**(S(3)/2)), 0, True)
  453. assert LT(exp(-a/t), t, s) ==\
  454. (2*sqrt(a)*sqrt(1/s)*besselk(1, 2*sqrt(a)*sqrt(s)), 0, True)
  455. assert LT(sqrt(t)*exp(-a/t), t, s) ==\
  456. (sqrt(pi)*(2*sqrt(a)*sqrt(s) + 1)*sqrt(s**(-3))*exp(-2*sqrt(a)*\
  457. sqrt(s))/2, 0, True)
  458. assert LT(exp(-a/t)/sqrt(t), t, s) ==\
  459. (sqrt(pi)*sqrt(1/s)*exp(-2*sqrt(a)*sqrt(s)), 0, True)
  460. assert LT( exp(-a/t)/(t*sqrt(t)), t, s) ==\
  461. (sqrt(pi)*sqrt(1/a)*exp(-2*sqrt(a)*sqrt(s)), 0, True)
  462. assert LT(exp(-2*sqrt(a*t)), t, s) ==\
  463. ( 1/s -sqrt(pi)*sqrt(a) * exp(a/s)*erfc(sqrt(a)*sqrt(1/s))/\
  464. s**(S(3)/2), 0, True)
  465. assert LT(exp(-2*sqrt(a*t))/sqrt(t), t, s) == (exp(a/s)*erfc(sqrt(a)*\
  466. sqrt(1/s))*(sqrt(pi)*sqrt(1/s)), 0, True)
  467. assert LT(t**4*exp(-2/t), t, s) ==\
  468. (8*sqrt(2)*(1/s)**(S(5)/2)*besselk(5, 2*sqrt(2)*sqrt(s)), 0, True)
  469. # Hyperbolic functions (laplace4.pdf)
  470. assert LT(sinh(a*t), t, s) == (a/(-a**2 + s**2), a, True)
  471. assert LT(b*sinh(a*t)**2, t, s) == (2*a**2*b/(-4*a**2*s**2 + s**3),
  472. 2*a, True)
  473. # The following line confirms that issue #21202 is solved
  474. assert LT(cosh(2*t), t, s) == (s/(-4 + s**2), 2, True)
  475. assert LT(cosh(a*t), t, s) == (s/(-a**2 + s**2), a, True)
  476. assert LT(cosh(a*t)**2, t, s) == ((-2*a**2 + s**2)/(-4*a**2*s**2 + s**3),
  477. 2*a, True)
  478. assert LT(sinh(x + 3), x, s) == (
  479. (-s + (s + 1)*exp(6) + 1)*exp(-3)/(s - 1)/(s + 1)/2, 0, Abs(s) > 1)
  480. # The following line replaces the old test test_issue_7173()
  481. assert LT(sinh(a*t)*cosh(a*t), t, s) == (a/(-4*a**2 + s**2), 2*a, True)
  482. assert LT(sinh(a*t)/t, t, s) == (log((a + s)/(-a + s))/2, a, True)
  483. assert LT(t**(-S(3)/2)*sinh(a*t), t, s) ==\
  484. (-sqrt(pi)*(sqrt(-a + s) - sqrt(a + s)), a, True)
  485. assert LT(sinh(2*sqrt(a*t)), t, s) ==\
  486. (sqrt(pi)*sqrt(a)*exp(a/s)/s**(S(3)/2), 0, True)
  487. assert LT(sqrt(t)*sinh(2*sqrt(a*t)), t, s) ==\
  488. (-sqrt(a)/s**2 + sqrt(pi)*(a + s/2)*exp(a/s)*erf(sqrt(a)*\
  489. sqrt(1/s))/s**(S(5)/2), 0, True)
  490. assert LT(sinh(2*sqrt(a*t))/sqrt(t), t, s) ==\
  491. (sqrt(pi)*exp(a/s)*erf(sqrt(a)*sqrt(1/s))/sqrt(s), 0, True)
  492. assert LT(sinh(sqrt(a*t))**2/sqrt(t), t, s) ==\
  493. (sqrt(pi)*(exp(a/s) - 1)/(2*sqrt(s)), 0, True)
  494. assert LT(t**(S(3)/7)*cosh(a*t), t, s) ==\
  495. (((a + s)**(-S(10)/7) + (-a+s)**(-S(10)/7))*gamma(S(10)/7)/2, a, True)
  496. assert LT(cosh(2*sqrt(a*t)), t, s) ==\
  497. (sqrt(pi)*sqrt(a)*exp(a/s)*erf(sqrt(a)*sqrt(1/s))/s**(S(3)/2) + 1/s,
  498. 0, True)
  499. assert LT(sqrt(t)*cosh(2*sqrt(a*t)), t, s) ==\
  500. (sqrt(pi)*(a + s/2)*exp(a/s)/s**(S(5)/2), 0, True)
  501. assert LT(cosh(2*sqrt(a*t))/sqrt(t), t, s) ==\
  502. (sqrt(pi)*exp(a/s)/sqrt(s), 0, True)
  503. assert LT(cosh(sqrt(a*t))**2/sqrt(t), t, s) ==\
  504. (sqrt(pi)*(exp(a/s) + 1)/(2*sqrt(s)), 0, True)
  505. # logarithmic functions (laplace5.pdf)
  506. assert LT(log(t), t, s) == (-log(s+S.EulerGamma)/s, 0, True)
  507. assert LT(log(t/a), t, s) == (-log(a*s + S.EulerGamma)/s, 0, True)
  508. assert LT(log(1+a*t), t, s) == (-exp(s/a)*Ei(-s/a)/s, 0, True)
  509. assert LT(log(t+a), t, s) == ((log(a) - exp(s/a)*Ei(-s/a)/s)/s, 0, True)
  510. assert LT(log(t)/sqrt(t), t, s) ==\
  511. (sqrt(pi)*(-log(s) - 2*log(2) - S.EulerGamma)/sqrt(s), 0, True)
  512. assert LT(t**(S(5)/2)*log(t), t, s) ==\
  513. (15*sqrt(pi)*(-log(s)-2*log(2)-S.EulerGamma+S(46)/15)/(8*s**(S(7)/2)),
  514. 0, True)
  515. assert (LT(t**3*log(t), t, s, noconds=True)-6*(-log(s) - S.EulerGamma\
  516. + S(11)/6)/s**4).simplify() == S.Zero
  517. assert LT(log(t)**2, t, s) ==\
  518. (((log(s) + EulerGamma)**2 + pi**2/6)/s, 0, True)
  519. assert LT(exp(-a*t)*log(t), t, s) ==\
  520. ((-log(a + s) - S.EulerGamma)/(a + s), -a, True)
  521. # Trigonometric functions (laplace6.pdf)
  522. assert LT(sin(a*t), t, s) == (a/(a**2 + s**2), 0, True)
  523. assert LT(Abs(sin(a*t)), t, s) ==\
  524. (a*coth(pi*s/(2*a))/(a**2 + s**2), 0, True)
  525. assert LT(sin(a*t)/t, t, s) == (atan(a/s), 0, True)
  526. assert LT(sin(a*t)**2/t, t, s) == (log(4*a**2/s**2 + 1)/4, 0, True)
  527. assert LT(sin(a*t)**2/t**2, t, s) ==\
  528. (a*atan(2*a/s) - s*log(4*a**2/s**2 + 1)/4, 0, True)
  529. assert LT(sin(2*sqrt(a*t)), t, s) ==\
  530. (sqrt(pi)*sqrt(a)*exp(-a/s)/s**(S(3)/2), 0, True)
  531. assert LT(sin(2*sqrt(a*t))/t, t, s) == (pi*erf(sqrt(a)*sqrt(1/s)), 0, True)
  532. assert LT(cos(a*t), t, s) == (s/(a**2 + s**2), 0, True)
  533. assert LT(cos(a*t)**2, t, s) ==\
  534. ((2*a**2 + s**2)/(s*(4*a**2 + s**2)), 0, True)
  535. assert LT(sqrt(t)*cos(2*sqrt(a*t)), t, s) ==\
  536. (sqrt(pi)*(-2*a + s)*exp(-a/s)/(2*s**(S(5)/2)), 0, True)
  537. assert LT(cos(2*sqrt(a*t))/sqrt(t), t, s) ==\
  538. (sqrt(pi)*sqrt(1/s)*exp(-a/s), 0, True)
  539. assert LT(sin(a*t)*sin(b*t), t, s) ==\
  540. (2*a*b*s/((s**2 + (a - b)**2)*(s**2 + (a + b)**2)), 0, True)
  541. assert LT(cos(a*t)*sin(b*t), t, s) ==\
  542. (b*(-a**2 + b**2 + s**2)/((s**2 + (a - b)**2)*(s**2 + (a + b)**2)),
  543. 0, True)
  544. assert LT(cos(a*t)*cos(b*t), t, s) ==\
  545. (s*(a**2 + b**2 + s**2)/((s**2 + (a - b)**2)*(s**2 + (a + b)**2)),
  546. 0, True)
  547. assert LT(c*exp(-b*t)*sin(a*t), t, s) == (a*c/(a**2 + (b + s)**2),
  548. -b, True)
  549. assert LT(c*exp(-b*t)*cos(a*t), t, s) == ((b + s)*c/(a**2 + (b + s)**2),
  550. -b, True)
  551. assert LT(cos(x + 3), x, s) == ((s*cos(3) - sin(3))/(s**2 + 1), 0, True)
  552. # Error functions (laplace7.pdf)
  553. assert LT(erf(a*t), t, s) == (exp(s**2/(4*a**2))*erfc(s/(2*a))/s, 0, True)
  554. assert LT(erf(sqrt(a*t)), t, s) == (sqrt(a)/(s*sqrt(a + s)), 0, True)
  555. assert LT(exp(a*t)*erf(sqrt(a*t)), t, s) ==\
  556. (sqrt(a)/(sqrt(s)*(-a + s)), a, True)
  557. assert LT(erf(sqrt(a/t)/2), t, s) == ((1-exp(-sqrt(a)*sqrt(s)))/s, 0, True)
  558. assert LT(erfc(sqrt(a*t)), t, s) ==\
  559. ((-sqrt(a) + sqrt(a + s))/(s*sqrt(a + s)), 0, True)
  560. assert LT(exp(a*t)*erfc(sqrt(a*t)), t, s) ==\
  561. (1/(sqrt(a)*sqrt(s) + s), 0, True)
  562. assert LT(erfc(sqrt(a/t)/2), t, s) == (exp(-sqrt(a)*sqrt(s))/s, 0, True)
  563. # Bessel functions (laplace8.pdf)
  564. assert LT(besselj(0, a*t), t, s) == (1/sqrt(a**2 + s**2), 0, True)
  565. assert LT(besselj(1, a*t), t, s) ==\
  566. (a/(sqrt(a**2 + s**2)*(s + sqrt(a**2 + s**2))), 0, True)
  567. assert LT(besselj(2, a*t), t, s) ==\
  568. (a**2/(sqrt(a**2 + s**2)*(s + sqrt(a**2 + s**2))**2), 0, True)
  569. assert LT(t*besselj(0, a*t), t, s) ==\
  570. (s/(a**2 + s**2)**(S(3)/2), 0, True)
  571. assert LT(t*besselj(1, a*t), t, s) ==\
  572. (a/(a**2 + s**2)**(S(3)/2), 0, True)
  573. assert LT(t**2*besselj(2, a*t), t, s) ==\
  574. (3*a**2/(a**2 + s**2)**(S(5)/2), 0, True)
  575. assert LT(besselj(0, 2*sqrt(a*t)), t, s) == (exp(-a/s)/s, 0, True)
  576. assert LT(t**(S(3)/2)*besselj(3, 2*sqrt(a*t)), t, s) ==\
  577. (a**(S(3)/2)*exp(-a/s)/s**4, 0, True)
  578. assert LT(besselj(0, a*sqrt(t**2+b*t)), t, s) ==\
  579. (exp(b*s - b*sqrt(a**2 + s**2))/sqrt(a**2 + s**2), 0, True)
  580. assert LT(besseli(0, a*t), t, s) == (1/sqrt(-a**2 + s**2), a, True)
  581. assert LT(besseli(1, a*t), t, s) ==\
  582. (a/(sqrt(-a**2 + s**2)*(s + sqrt(-a**2 + s**2))), a, True)
  583. assert LT(besseli(2, a*t), t, s) ==\
  584. (a**2/(sqrt(-a**2 + s**2)*(s + sqrt(-a**2 + s**2))**2), a, True)
  585. assert LT(t*besseli(0, a*t), t, s) == (s/(-a**2 + s**2)**(S(3)/2), a, True)
  586. assert LT(t*besseli(1, a*t), t, s) == (a/(-a**2 + s**2)**(S(3)/2), a, True)
  587. assert LT(t**2*besseli(2, a*t), t, s) ==\
  588. (3*a**2/(-a**2 + s**2)**(S(5)/2), a, True)
  589. assert LT(t**(S(3)/2)*besseli(3, 2*sqrt(a*t)), t, s) ==\
  590. (a**(S(3)/2)*exp(a/s)/s**4, 0, True)
  591. assert LT(bessely(0, a*t), t, s) ==\
  592. (-2*asinh(s/a)/(pi*sqrt(a**2 + s**2)), 0, True)
  593. assert LT(besselk(0, a*t), t, s) ==\
  594. (log(s + sqrt(-a**2 + s**2))/sqrt(-a**2 + s**2), a, True)
  595. assert LT(sin(a*t)**8, t, s) ==\
  596. (40320*a**8/(s*(147456*a**8 + 52480*a**6*s**2 + 4368*a**4*s**4 +\
  597. 120*a**2*s**6 + s**8)), 0, True)
  598. # Test general rules and unevaluated forms
  599. # These all also test whether issue #7219 is solved.
  600. assert LT(Heaviside(t-1)*cos(t-1), t, s) == (s*exp(-s)/(s**2 + 1), 0, True)
  601. assert LT(a*f(t), t, w) == a*LaplaceTransform(f(t), t, w)
  602. assert LT(a*Heaviside(t+1)*f(t+1), t, s) ==\
  603. a*LaplaceTransform(f(t + 1)*Heaviside(t + 1), t, s)
  604. assert LT(a*Heaviside(t-1)*f(t-1), t, s) ==\
  605. a*LaplaceTransform(f(t), t, s)*exp(-s)
  606. assert LT(b*f(t/a), t, s) == a*b*LaplaceTransform(f(t), t, a*s)
  607. assert LT(exp(-f(x)*t), t, s) == (1/(s + f(x)), -f(x), True)
  608. assert LT(exp(-a*t)*f(t), t, s) == LaplaceTransform(f(t), t, a + s)
  609. assert LT(exp(-a*t)*erfc(sqrt(b/t)/2), t, s) ==\
  610. (exp(-sqrt(b)*sqrt(a + s))/(a + s), -a, True)
  611. assert LT(sinh(a*t)*f(t), t, s) ==\
  612. LaplaceTransform(f(t), t, -a+s)/2 - LaplaceTransform(f(t), t, a+s)/2
  613. assert LT(sinh(a*t)*t, t, s) ==\
  614. (-1/(2*(a + s)**2) + 1/(2*(-a + s)**2), a, True)
  615. assert LT(cosh(a*t)*f(t), t, s) ==\
  616. LaplaceTransform(f(t), t, -a+s)/2 + LaplaceTransform(f(t), t, a+s)/2
  617. assert LT(cosh(a*t)*t, t, s) ==\
  618. (1/(2*(a + s)**2) + 1/(2*(-a + s)**2), a, True)
  619. assert LT(sin(a*t)*f(t), t, s) ==\
  620. I*(-LaplaceTransform(f(t), t, -I*a + s) +\
  621. LaplaceTransform(f(t), t, I*a + s))/2
  622. assert LT(sin(a*t)*t, t, s) ==\
  623. (2*a*s/(a**4 + 2*a**2*s**2 + s**4), 0, True)
  624. assert LT(cos(a*t)*f(t), t, s) ==\
  625. LaplaceTransform(f(t), t, -I*a + s)/2 +\
  626. LaplaceTransform(f(t), t, I*a + s)/2
  627. assert LT(cos(a*t)*t, t, s) ==\
  628. ((-a**2 + s**2)/(a**4 + 2*a**2*s**2 + s**4), 0, True)
  629. # The following two lines test whether issues #5813 and #7176 are solved.
  630. assert LT(diff(f(t), (t, 1)), t, s) == s*LaplaceTransform(f(t), t, s)\
  631. - f(0)
  632. assert LT(diff(f(t), (t, 3)), t, s) == s**3*LaplaceTransform(f(t), t, s)\
  633. - s**2*f(0) - s*Subs(Derivative(f(t), t), t, 0)\
  634. - Subs(Derivative(f(t), (t, 2)), t, 0)
  635. assert LT(a*f(b*t)+g(c*t), t, s) == a*LaplaceTransform(f(t), t, s/b)/b +\
  636. LaplaceTransform(g(t), t, s/c)/c
  637. assert inverse_laplace_transform(
  638. f(w), w, t, plane=0) == InverseLaplaceTransform(f(w), w, t, 0)
  639. assert LT(f(t)*g(t), t, s) == LaplaceTransform(f(t)*g(t), t, s)
  640. # additional basic tests from wikipedia
  641. assert LT((t - a)**b*exp(-c*(t - a))*Heaviside(t - a), t, s) == \
  642. ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True)
  643. assert LT((exp(2*t) - 1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \
  644. == exp(-b)/(s**2 - 1)
  645. # DiracDelta function: standard cases
  646. assert LT(DiracDelta(t), t, s) == (1, 0, True)
  647. assert LT(DiracDelta(a*t), t, s) == (1/a, 0, True)
  648. assert LT(DiracDelta(t/42), t, s) == (42, 0, True)
  649. assert LT(DiracDelta(t+42), t, s) == (0, 0, True)
  650. assert LT(DiracDelta(t)+DiracDelta(t-42), t, s) == \
  651. (1 + exp(-42*s), 0, True)
  652. assert LT(DiracDelta(t)-a*exp(-a*t), t, s) == (s/(a + s), 0, True)
  653. assert LT(exp(-t)*(DiracDelta(t)+DiracDelta(t-42)), t, s) == \
  654. (exp(-42*s - 42) + 1, -oo, True)
  655. # Collection of cases that cannot be fully evaluated and/or would catch
  656. # some common implementation errors
  657. assert LT(DiracDelta(t**2), t, s) == LaplaceTransform(DiracDelta(t**2), t, s)
  658. assert LT(DiracDelta(t**2 - 1), t, s) == (exp(-s)/2, -oo, True)
  659. assert LT(DiracDelta(t*(1 - t)), t, s) == \
  660. LaplaceTransform(DiracDelta(-t**2 + t), t, s)
  661. assert LT((DiracDelta(t) + 1)*(DiracDelta(t - 1) + 1), t, s) == \
  662. (LaplaceTransform(DiracDelta(t)*DiracDelta(t - 1), t, s) + \
  663. 1 + exp(-s) + 1/s, 0, True)
  664. assert LT(DiracDelta(2*t-2*exp(a)), t, s) == (exp(-s*exp(a))/2, 0, True)
  665. assert LT(DiracDelta(-2*t+2*exp(a)), t, s) == (exp(-s*exp(a))/2, 0, True)
  666. # Heaviside tests
  667. assert LT(Heaviside(t), t, s) == (1/s, 0, True)
  668. assert LT(Heaviside(t - a), t, s) == (exp(-a*s)/s, 0, True)
  669. assert LT(Heaviside(t-1), t, s) == (exp(-s)/s, 0, True)
  670. assert LT(Heaviside(2*t-4), t, s) == (exp(-2*s)/s, 0, True)
  671. assert LT(Heaviside(-2*t+4), t, s) == ((1 - exp(-2*s))/s, 0, True)
  672. assert LT(Heaviside(2*t+4), t, s) == (1/s, 0, True)
  673. assert LT(Heaviside(-2*t+4), t, s) == ((1 - exp(-2*s))/s, 0, True)
  674. # Fresnel functions
  675. assert laplace_transform(fresnels(t), t, s) == \
  676. ((-sin(s**2/(2*pi))*fresnels(s/pi) + sin(s**2/(2*pi))/2 -
  677. cos(s**2/(2*pi))*fresnelc(s/pi) + cos(s**2/(2*pi))/2)/s, 0, True)
  678. assert laplace_transform(fresnelc(t), t, s) == (
  679. ((2*sin(s**2/(2*pi))*fresnelc(s/pi) - 2*cos(s**2/(2*pi))*fresnels(s/pi)
  680. + sqrt(2)*cos(s**2/(2*pi) + pi/4))/(2*s), 0, True))
  681. # Matrix tests
  682. Mt = Matrix([[exp(t), t*exp(-t)], [t*exp(-t), exp(t)]])
  683. Ms = Matrix([[ 1/(s - 1), (s + 1)**(-2)],
  684. [(s + 1)**(-2), 1/(s - 1)]])
  685. # The default behaviour for Laplace tranform of a Matrix returns a Matrix
  686. # of Tuples and is deprecated:
  687. with warns_deprecated_sympy():
  688. Ms_conds = Matrix([[(1/(s - 1), 1, True), ((s + 1)**(-2),
  689. -1, True)], [((s + 1)**(-2), -1, True), (1/(s - 1), 1, True)]])
  690. with warns_deprecated_sympy():
  691. assert LT(Mt, t, s) == Ms_conds
  692. # The new behavior is to return a tuple of a Matrix and the convergence
  693. # conditions for the matrix as a whole:
  694. assert LT(Mt, t, s, legacy_matrix=False) == (Ms, 1, True)
  695. # With noconds=True the transformed matrix is returned without conditions
  696. # either way:
  697. assert LT(Mt, t, s, noconds=True) == Ms
  698. assert LT(Mt, t, s, legacy_matrix=False, noconds=True) == Ms
  699. @slow
  700. def test_inverse_laplace_transform():
  701. from sympy.core.exprtools import factor_terms
  702. from sympy.functions.special.delta_functions import DiracDelta
  703. from sympy.simplify.simplify import simplify
  704. ILT = inverse_laplace_transform
  705. a, b, c, = symbols('a b c', positive=True)
  706. t = symbols('t')
  707. def simp_hyp(expr):
  708. return factor_terms(expand_mul(expr)).rewrite(sin)
  709. assert ILT(1, s, t) == DiracDelta(t)
  710. assert ILT(1/s, s, t) == Heaviside(t)
  711. assert ILT(a/(a + s), s, t) == a*exp(-a*t)*Heaviside(t)
  712. assert ILT(s/(a + s), s, t) == -a*exp(-a*t)*Heaviside(t) + DiracDelta(t)
  713. assert ILT((a + s)**(-2), s, t) == t*exp(-a*t)*Heaviside(t)
  714. assert ILT((a + s)**(-5), s, t) == t**4*exp(-a*t)*Heaviside(t)/24
  715. assert ILT(a/(a**2 + s**2), s, t) == sin(a*t)*Heaviside(t)
  716. assert ILT(s/(s**2 + a**2), s, t) == cos(a*t)*Heaviside(t)
  717. assert ILT(b/(b**2 + (a + s)**2), s, t) == exp(-a*t)*sin(b*t)*Heaviside(t)
  718. assert ILT(b*s/(b**2 + (a + s)**2), s, t) +\
  719. (a*sin(b*t) - b*cos(b*t))*exp(-a*t)*Heaviside(t) == 0
  720. assert ILT(exp(-a*s)/s, s, t) == Heaviside(-a + t)
  721. assert ILT(exp(-a*s)/(b + s), s, t) == exp(b*(a - t))*Heaviside(-a + t)
  722. assert ILT((b + s)/(a**2 + (b + s)**2), s, t) == \
  723. exp(-b*t)*cos(a*t)*Heaviside(t)
  724. assert ILT(exp(-a*s)/s**b, s, t) == \
  725. (-a + t)**(b - 1)*Heaviside(-a + t)/gamma(b)
  726. assert ILT(exp(-a*s)/sqrt(s**2 + 1), s, t) == \
  727. Heaviside(-a + t)*besselj(0, a - t)
  728. assert ILT(1/(s*sqrt(s + 1)), s, t) == Heaviside(t)*erf(sqrt(t))
  729. assert ILT(1/(s**2*(s**2 + 1)), s, t) == (t - sin(t))*Heaviside(t)
  730. assert ILT(s**2/(s**2 + 1), s, t) == -sin(t)*Heaviside(t) + DiracDelta(t)
  731. assert ILT(1 - 1/(s**2 + 1), s, t) == -sin(t)*Heaviside(t) + DiracDelta(t)
  732. assert ILT(1/s**2, s, t) == t*Heaviside(t)
  733. assert ILT(1/s**5, s, t) == t**4*Heaviside(t)/24
  734. assert simp_hyp(ILT(a/(s**2 - a**2), s, t)) == sinh(a*t)*Heaviside(t)
  735. assert simp_hyp(ILT(s/(s**2 - a**2), s, t)) == cosh(a*t)*Heaviside(t)
  736. # TODO sinh/cosh shifted come out a mess. also delayed trig is a mess
  737. # TODO should this simplify further?
  738. assert ILT(exp(-a*s)/s**b, s, t) == \
  739. (t - a)**(b - 1)*Heaviside(t - a)/gamma(b)
  740. assert ILT(exp(-a*s)/sqrt(1 + s**2), s, t) == \
  741. Heaviside(t - a)*besselj(0, a - t) # note: besselj(0, x) is even
  742. # XXX ILT turns these branch factor into trig functions ...
  743. assert simplify(ILT(a**b*(s + sqrt(s**2 - a**2))**(-b)/sqrt(s**2 - a**2),
  744. s, t).rewrite(exp)) == \
  745. Heaviside(t)*besseli(b, a*t)
  746. assert ILT(a**b*(s + sqrt(s**2 + a**2))**(-b)/sqrt(s**2 + a**2),
  747. s, t).rewrite(exp) == \
  748. Heaviside(t)*besselj(b, a*t)
  749. assert ILT(1/(s*sqrt(s + 1)), s, t) == Heaviside(t)*erf(sqrt(t))
  750. # TODO can we make erf(t) work?
  751. assert ILT(1/(s**2*(s**2 + 1)),s,t) == (t - sin(t))*Heaviside(t)
  752. assert ILT( (s * eye(2) - Matrix([[1, 0], [0, 2]])).inv(), s, t) ==\
  753. Matrix([[exp(t)*Heaviside(t), 0], [0, exp(2*t)*Heaviside(t)]])
  754. def test_inverse_laplace_transform_delta():
  755. from sympy.functions.special.delta_functions import DiracDelta
  756. ILT = inverse_laplace_transform
  757. t = symbols('t')
  758. assert ILT(2, s, t) == 2*DiracDelta(t)
  759. assert ILT(2*exp(3*s) - 5*exp(-7*s), s, t) == \
  760. 2*DiracDelta(t + 3) - 5*DiracDelta(t - 7)
  761. a = cos(sin(7)/2)
  762. assert ILT(a*exp(-3*s), s, t) == a*DiracDelta(t - 3)
  763. assert ILT(exp(2*s), s, t) == DiracDelta(t + 2)
  764. r = Symbol('r', real=True)
  765. assert ILT(exp(r*s), s, t) == DiracDelta(t + r)
  766. def test_inverse_laplace_transform_delta_cond():
  767. from sympy.functions.elementary.complexes import im
  768. from sympy.functions.special.delta_functions import DiracDelta
  769. ILT = inverse_laplace_transform
  770. t = symbols('t')
  771. r = Symbol('r', real=True)
  772. assert ILT(exp(r*s), s, t, noconds=False) == (DiracDelta(t + r), True)
  773. z = Symbol('z')
  774. assert ILT(exp(z*s), s, t, noconds=False) == \
  775. (DiracDelta(t + z), Eq(im(z), 0))
  776. # inversion does not exist: verify it doesn't evaluate to DiracDelta
  777. for z in (Symbol('z', extended_real=False),
  778. Symbol('z', imaginary=True, zero=False)):
  779. f = ILT(exp(z*s), s, t, noconds=False)
  780. f = f[0] if isinstance(f, tuple) else f
  781. assert f.func != DiracDelta
  782. # issue 15043
  783. assert ILT(1/s + exp(r*s)/s, s, t, noconds=False) == (
  784. Heaviside(t) + Heaviside(r + t), True)
  785. def test_fourier_transform():
  786. from sympy.core.function import (expand, expand_complex, expand_trig)
  787. from sympy.polys.polytools import factor
  788. from sympy.simplify.simplify import simplify
  789. FT = fourier_transform
  790. IFT = inverse_fourier_transform
  791. def simp(x):
  792. return simplify(expand_trig(expand_complex(expand(x))))
  793. def sinc(x):
  794. return sin(pi*x)/(pi*x)
  795. k = symbols('k', real=True)
  796. f = Function("f")
  797. # TODO for this to work with real a, need to expand abs(a*x) to abs(a)*abs(x)
  798. a = symbols('a', positive=True)
  799. b = symbols('b', positive=True)
  800. posk = symbols('posk', positive=True)
  801. # Test unevaluated form
  802. assert fourier_transform(f(x), x, k) == FourierTransform(f(x), x, k)
  803. assert inverse_fourier_transform(
  804. f(k), k, x) == InverseFourierTransform(f(k), k, x)
  805. # basic examples from wikipedia
  806. assert simp(FT(Heaviside(1 - abs(2*a*x)), x, k)) == sinc(k/a)/a
  807. # TODO IFT is a *mess*
  808. assert simp(FT(Heaviside(1 - abs(a*x))*(1 - abs(a*x)), x, k)) == sinc(k/a)**2/a
  809. # TODO IFT
  810. assert factor(FT(exp(-a*x)*Heaviside(x), x, k), extension=I) == \
  811. 1/(a + 2*pi*I*k)
  812. # NOTE: the ift comes out in pieces
  813. assert IFT(1/(a + 2*pi*I*x), x, posk,
  814. noconds=False) == (exp(-a*posk), True)
  815. assert IFT(1/(a + 2*pi*I*x), x, -posk,
  816. noconds=False) == (0, True)
  817. assert IFT(1/(a + 2*pi*I*x), x, symbols('k', negative=True),
  818. noconds=False) == (0, True)
  819. # TODO IFT without factoring comes out as meijer g
  820. assert factor(FT(x*exp(-a*x)*Heaviside(x), x, k), extension=I) == \
  821. 1/(a + 2*pi*I*k)**2
  822. assert FT(exp(-a*x)*sin(b*x)*Heaviside(x), x, k) == \
  823. b/(b**2 + (a + 2*I*pi*k)**2)
  824. assert FT(exp(-a*x**2), x, k) == sqrt(pi)*exp(-pi**2*k**2/a)/sqrt(a)
  825. assert IFT(sqrt(pi/a)*exp(-(pi*k)**2/a), k, x) == exp(-a*x**2)
  826. assert FT(exp(-a*abs(x)), x, k) == 2*a/(a**2 + 4*pi**2*k**2)
  827. # TODO IFT (comes out as meijer G)
  828. # TODO besselj(n, x), n an integer > 0 actually can be done...
  829. # TODO are there other common transforms (no distributions!)?
  830. def test_sine_transform():
  831. t = symbols("t")
  832. w = symbols("w")
  833. a = symbols("a")
  834. f = Function("f")
  835. # Test unevaluated form
  836. assert sine_transform(f(t), t, w) == SineTransform(f(t), t, w)
  837. assert inverse_sine_transform(
  838. f(w), w, t) == InverseSineTransform(f(w), w, t)
  839. assert sine_transform(1/sqrt(t), t, w) == 1/sqrt(w)
  840. assert inverse_sine_transform(1/sqrt(w), w, t) == 1/sqrt(t)
  841. assert sine_transform((1/sqrt(t))**3, t, w) == 2*sqrt(w)
  842. assert sine_transform(t**(-a), t, w) == 2**(
  843. -a + S.Half)*w**(a - 1)*gamma(-a/2 + 1)/gamma((a + 1)/2)
  844. assert inverse_sine_transform(2**(-a + S(
  845. 1)/2)*w**(a - 1)*gamma(-a/2 + 1)/gamma(a/2 + S.Half), w, t) == t**(-a)
  846. assert sine_transform(
  847. exp(-a*t), t, w) == sqrt(2)*w/(sqrt(pi)*(a**2 + w**2))
  848. assert inverse_sine_transform(
  849. sqrt(2)*w/(sqrt(pi)*(a**2 + w**2)), w, t) == exp(-a*t)
  850. assert sine_transform(
  851. log(t)/t, t, w) == sqrt(2)*sqrt(pi)*-(log(w**2) + 2*EulerGamma)/4
  852. assert sine_transform(
  853. t*exp(-a*t**2), t, w) == sqrt(2)*w*exp(-w**2/(4*a))/(4*a**Rational(3, 2))
  854. assert inverse_sine_transform(
  855. sqrt(2)*w*exp(-w**2/(4*a))/(4*a**Rational(3, 2)), w, t) == t*exp(-a*t**2)
  856. def test_cosine_transform():
  857. from sympy.functions.special.error_functions import (Ci, Si)
  858. t = symbols("t")
  859. w = symbols("w")
  860. a = symbols("a")
  861. f = Function("f")
  862. # Test unevaluated form
  863. assert cosine_transform(f(t), t, w) == CosineTransform(f(t), t, w)
  864. assert inverse_cosine_transform(
  865. f(w), w, t) == InverseCosineTransform(f(w), w, t)
  866. assert cosine_transform(1/sqrt(t), t, w) == 1/sqrt(w)
  867. assert inverse_cosine_transform(1/sqrt(w), w, t) == 1/sqrt(t)
  868. assert cosine_transform(1/(
  869. a**2 + t**2), t, w) == sqrt(2)*sqrt(pi)*exp(-a*w)/(2*a)
  870. assert cosine_transform(t**(
  871. -a), t, w) == 2**(-a + S.Half)*w**(a - 1)*gamma((-a + 1)/2)/gamma(a/2)
  872. assert inverse_cosine_transform(2**(-a + S(
  873. 1)/2)*w**(a - 1)*gamma(-a/2 + S.Half)/gamma(a/2), w, t) == t**(-a)
  874. assert cosine_transform(
  875. exp(-a*t), t, w) == sqrt(2)*a/(sqrt(pi)*(a**2 + w**2))
  876. assert inverse_cosine_transform(
  877. sqrt(2)*a/(sqrt(pi)*(a**2 + w**2)), w, t) == exp(-a*t)
  878. assert cosine_transform(exp(-a*sqrt(t))*cos(a*sqrt(
  879. t)), t, w) == a*exp(-a**2/(2*w))/(2*w**Rational(3, 2))
  880. assert cosine_transform(1/(a + t), t, w) == sqrt(2)*(
  881. (-2*Si(a*w) + pi)*sin(a*w)/2 - cos(a*w)*Ci(a*w))/sqrt(pi)
  882. assert inverse_cosine_transform(sqrt(2)*meijerg(((S.Half, 0), ()), (
  883. (S.Half, 0, 0), (S.Half,)), a**2*w**2/4)/(2*pi), w, t) == 1/(a + t)
  884. assert cosine_transform(1/sqrt(a**2 + t**2), t, w) == sqrt(2)*meijerg(
  885. ((S.Half,), ()), ((0, 0), (S.Half,)), a**2*w**2/4)/(2*sqrt(pi))
  886. assert inverse_cosine_transform(sqrt(2)*meijerg(((S.Half,), ()), ((0, 0), (S.Half,)), a**2*w**2/4)/(2*sqrt(pi)), w, t) == 1/(t*sqrt(a**2/t**2 + 1))
  887. def test_hankel_transform():
  888. r = Symbol("r")
  889. k = Symbol("k")
  890. nu = Symbol("nu")
  891. m = Symbol("m")
  892. a = symbols("a")
  893. assert hankel_transform(1/r, r, k, 0) == 1/k
  894. assert inverse_hankel_transform(1/k, k, r, 0) == 1/r
  895. assert hankel_transform(
  896. 1/r**m, r, k, 0) == 2**(-m + 1)*k**(m - 2)*gamma(-m/2 + 1)/gamma(m/2)
  897. assert inverse_hankel_transform(
  898. 2**(-m + 1)*k**(m - 2)*gamma(-m/2 + 1)/gamma(m/2), k, r, 0) == r**(-m)
  899. assert hankel_transform(1/r**m, r, k, nu) == (
  900. 2*2**(-m)*k**(m - 2)*gamma(-m/2 + nu/2 + 1)/gamma(m/2 + nu/2))
  901. assert inverse_hankel_transform(2**(-m + 1)*k**(
  902. m - 2)*gamma(-m/2 + nu/2 + 1)/gamma(m/2 + nu/2), k, r, nu) == r**(-m)
  903. assert hankel_transform(r**nu*exp(-a*r), r, k, nu) == \
  904. 2**(nu + 1)*a*k**(-nu - 3)*(a**2/k**2 + 1)**(-nu - S(
  905. 3)/2)*gamma(nu + Rational(3, 2))/sqrt(pi)
  906. assert inverse_hankel_transform(
  907. 2**(nu + 1)*a*k**(-nu - 3)*(a**2/k**2 + 1)**(-nu - Rational(3, 2))*gamma(
  908. nu + Rational(3, 2))/sqrt(pi), k, r, nu) == r**nu*exp(-a*r)
  909. def test_issue_7181():
  910. assert mellin_transform(1/(1 - x), x, s) != None
  911. def test_issue_8882():
  912. # This is the original test.
  913. # from sympy import diff, Integral, integrate
  914. # r = Symbol('r')
  915. # psi = 1/r*sin(r)*exp(-(a0*r))
  916. # h = -1/2*diff(psi, r, r) - 1/r*psi
  917. # f = 4*pi*psi*h*r**2
  918. # assert integrate(f, (r, -oo, 3), meijerg=True).has(Integral) == True
  919. # To save time, only the critical part is included.
  920. F = -a**(-s + 1)*(4 + 1/a**2)**(-s/2)*sqrt(1/a**2)*exp(-s*I*pi)* \
  921. sin(s*atan(sqrt(1/a**2)/2))*gamma(s)
  922. raises(IntegralTransformError, lambda:
  923. inverse_mellin_transform(F, s, x, (-1, oo),
  924. **{'as_meijerg': True, 'needeval': True}))
  925. def test_issue_8514():
  926. from sympy.simplify.simplify import simplify
  927. a, b, c, = symbols('a b c', positive=True)
  928. t = symbols('t', positive=True)
  929. ft = simplify(inverse_laplace_transform(1/(a*s**2+b*s+c),s, t))
  930. assert ft == (I*exp(t*cos(atan2(0, -4*a*c + b**2)/2)*sqrt(Abs(4*a*c -
  931. b**2))/a)*sin(t*sin(atan2(0, -4*a*c + b**2)/2)*sqrt(Abs(
  932. 4*a*c - b**2))/(2*a)) + exp(t*cos(atan2(0, -4*a*c + b**2)
  933. /2)*sqrt(Abs(4*a*c - b**2))/a)*cos(t*sin(atan2(0, -4*a*c
  934. + b**2)/2)*sqrt(Abs(4*a*c - b**2))/(2*a)) + I*sin(t*sin(
  935. atan2(0, -4*a*c + b**2)/2)*sqrt(Abs(4*a*c - b**2))/(2*a))
  936. - cos(t*sin(atan2(0, -4*a*c + b**2)/2)*sqrt(Abs(4*a*c -
  937. b**2))/(2*a)))*exp(-t*(b + cos(atan2(0, -4*a*c + b**2)/2)
  938. *sqrt(Abs(4*a*c - b**2)))/(2*a))/sqrt(-4*a*c + b**2)
  939. def test_issue_12591():
  940. x, y = symbols("x y", real=True)
  941. assert fourier_transform(exp(x), x, y) == FourierTransform(exp(x), x, y)
  942. def test_issue_14692():
  943. b = Symbol('b', negative=True)
  944. assert laplace_transform(1/(I*x - b), x, s) == \
  945. (-I*exp(I*b*s)*expint(1, b*s*exp_polar(I*pi/2)), 0, True)