def test_messy(): assert laplace_transform(Si(x), x, s) == ((-atan(s) + pi / 2) / s, 0, True) assert laplace_transform(Shi(x), x, s) == (acoth(s) / s, 1, True) # where should the logs be simplified? assert laplace_transform(Chi(x), x, s) == \ ((log(s**(-2)) - log((s**2 - 1)/s**2))/(2*s), 1, True) # TODO maybe simplify the inequalities? assert laplace_transform(besselj(a, x), x, s)[1:] == \ (0, And(Integer(0) < re(a/2) + Rational(1, 2), Integer(0) < re(a/2) + 1)) # NOTE s < 0 can be done, but argument reduction is not good enough yet assert fourier_transform(besselj(1, x)/x, x, s, noconds=False) == \ (Piecewise((0, 4*abs(pi**2*s**2) > 1), (2*sqrt(-4*pi**2*s**2 + 1), True)), s > 0) # TODO FT(besselj(0,x)) - conditions are messy (but for acceptable reasons) # - folding could be better assert integrate(E1(x)*besselj(0, x), (x, 0, oo), meijerg=True) == \ log(1 + sqrt(2)) assert integrate(E1(x)*besselj(1, x), (x, 0, oo), meijerg=True) == \ log(Rational(1, 2) + sqrt(2)/2) assert integrate(1/x/sqrt(1 - x**2), x, meijerg=True) == \ Piecewise((-acosh(1/x), 1 < abs(x**(-2))), (I*asin(1/x), True))
def test_messy(): assert laplace_transform(Si(x), x, s) == ((-atan(s) + pi/2)/s, 0, True) assert laplace_transform(Shi(x), x, s) == (acoth(s)/s, 1, True) # where should the logs be simplified? assert laplace_transform(Chi(x), x, s) == \ ((log(s**(-2)) - log((s**2 - 1)/s**2))/(2*s), 1, True) # TODO maybe simplify the inequalities? assert laplace_transform(besselj(a, x), x, s)[1:] == \ (0, And(Integer(0) < re(a/2) + Rational(1, 2), Integer(0) < re(a/2) + 1)) # NOTE s < 0 can be done, but argument reduction is not good enough yet assert fourier_transform(besselj(1, x)/x, x, s, noconds=False) == \ (Piecewise((0, 4*abs(pi**2*s**2) > 1), (2*sqrt(-4*pi**2*s**2 + 1), True)), s > 0) # TODO FT(besselj(0,x)) - conditions are messy (but for acceptable reasons) # - folding could be better assert integrate(E1(x)*besselj(0, x), (x, 0, oo), meijerg=True) == \ log(1 + sqrt(2)) assert integrate(E1(x)*besselj(1, x), (x, 0, oo), meijerg=True) == \ log(Rational(1, 2) + sqrt(2)/2) assert integrate(1/x/sqrt(1 - x**2), x, meijerg=True) == \ Piecewise((-acosh(1/x), 1 < abs(x**(-2))), (I*asin(1/x), True))
def test_sympyissue_21202(): res = (Piecewise( (s / (s**2 - 4), (4 * abs(s**-2) < 1) | (abs(s**2) / 4 < 1)), (pi * meijerg(((Rational(1, 2), ), (0, 0)), ((0, Rational(1, 2)), (0, )), s**2 / 4) / 2, True)), 2, Ne(s**2 / 4, 1)) assert laplace_transform(cosh(2 * x), x, s) == res
def test_sympyissue_7173(): assert laplace_transform(sinh(a*x)*cosh(a*x), x, s) == \ (a/(s**2 - 4*a**2), 0, And(Or(abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)) < pi/2, abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)) <= pi/2), Or(abs(periodic_argument(a, oo)) < pi/2, abs(periodic_argument(a, oo)) <= pi/2)))
def test_undefined_function(): f = Function('f') assert mellin_transform(f(x), x, s) == MellinTransform(f(x), x, s) assert mellin_transform(f(x) + exp(-x), x, s) == \ (MellinTransform(f(x), x, s) + gamma(s), (0, oo), True) assert laplace_transform(2 * f(x), x, s) == 2 * LaplaceTransform(f(x), x, s)
def test_expint(): aneg = Symbol('a', negative=True) u = Symbol('u', polar=True) assert mellin_transform(E1(x), x, s) == (gamma(s) / s, (0, oo), True) assert inverse_mellin_transform(gamma(s) / s, s, x, (0, oo)).rewrite(expint).expand() == E1(x) assert mellin_transform(expint(a, x), x, s) == \ (gamma(s)/(a + s - 1), (Max(1 - re(a), 0), oo), True) # XXX IMT has hickups with complicated strips ... assert simplify(unpolarify( inverse_mellin_transform(gamma(s)/(aneg + s - 1), s, x, (1 - aneg, oo)).rewrite(expint).expand(func=True))) == \ expint(aneg, x) assert mellin_transform(Si(x), x, s) == \ (-2**s*sqrt(pi)*gamma(s/2 + Rational(1, 2))/( 2*s*gamma(-s/2 + 1)), (-1, 0), True) assert inverse_mellin_transform(-2**s*sqrt(pi)*gamma((s + 1)/2) / (2*s*gamma(-s/2 + 1)), s, x, (-1, 0)) \ == Si(x) assert mellin_transform(Ci(sqrt(x)), x, s) == \ (-2**(2*s - 1)*sqrt(pi)*gamma(s)/(s*gamma(-s + Rational(1, 2))), (0, 1), True) assert inverse_mellin_transform( -4**s * sqrt(pi) * gamma(s) / (2 * s * gamma(-s + Rational(1, 2))), s, u, (0, 1)).expand() == Ci(sqrt(u)) # TODO LT of Si, Shi, Chi is a mess ... assert laplace_transform(Ci(x), x, s) == (-log(1 + s**2) / 2 / s, 0, True) assert laplace_transform(expint(a, x), x, s) == \ (lerchphi(s*polar_lift(-1), 1, a), 0, Integer(0) < re(a)) assert laplace_transform(expint(1, x), x, s) == (log(s + 1) / s, 0, True) assert laplace_transform(expint(2, x), x, s) == \ ((s - log(s + 1))/s**2, 0, True) assert inverse_laplace_transform(-log(1 + s**2)/2/s, s, u).expand() == \ Heaviside(u)*Ci(u) assert inverse_laplace_transform(log(s + 1)/s, s, x).rewrite(expint) == \ Heaviside(x)*E1(x) assert inverse_laplace_transform((s - log(s + 1))/s**2, s, x).rewrite(expint).expand() == \ (expint(2, x)*Heaviside(x)).rewrite(Ei).rewrite(expint).expand()
def test_as_integral(): f = Function('f') assert mellin_transform(f(x), x, s).rewrite('Integral') == \ Integral(x**(s - 1)*f(x), (x, 0, oo)) assert fourier_transform(f(x), x, s).rewrite('Integral') == \ Integral(f(x)*exp(-2*I*pi*s*x), (x, -oo, oo)) assert laplace_transform(f(x), x, s).rewrite('Integral') == \ Integral(f(x)*exp(-s*x), (x, 0, oo)) assert str(inverse_mellin_transform(f(s), s, x, (a, b)).rewrite('Integral')) \ == 'Integral(x**(-s)*f(s), (s, _c - oo*I, _c + oo*I))' assert str(inverse_laplace_transform(f(s), s, x).rewrite('Integral')) == \ 'Integral(E**(s*x)*f(s), (s, _c - oo*I, _c + oo*I))' assert inverse_fourier_transform(f(s), s, x).rewrite('Integral') == \ Integral(f(s)*exp(2*I*pi*s*x), (s, -oo, oo))
def test_laplace_transform(): LT = laplace_transform a, b, c, = symbols('a b c', positive=True) f = Function('f') # Test unevaluated form assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w) assert inverse_laplace_transform(f(w), w, t, plane=0) == InverseLaplaceTransform( f(w), w, t, 0) # test a bug spos = symbols('s', positive=True) assert LT(exp(t), t, spos)[:2] == (1 / (spos - 1), 1) # basic tests from wikipedia assert LT((t - a)**b*exp(-c*(t - a))*Heaviside(t - a), t, s) == \ ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True) assert LT(t**a, t, s) == (s**(-a - 1) * gamma(a + 1), 0, True) assert LT(Heaviside(t), t, s) == (1 / s, 0, True) assert LT(Heaviside(t - a), t, s) == (exp(-a * s) / s, 0, True) assert LT(1 - exp(-a * t), t, s) == (a / (s * (a + s)), 0, True) assert LT((exp(2*t) - 1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \ == exp(-b)/(s**2 - 1) assert LT(exp(t), t, s)[:2] == (1 / (s - 1), 1) assert LT(exp(2 * t), t, s)[:2] == (1 / (s - 2), 2) assert LT(exp(a * t), t, s)[:2] == (1 / (s - a), a) assert LT(log(t / a), t, s) == ((log(a * s) + EulerGamma) / s / -1, 0, True) assert LT(erf(t), t, s) == ((-erf(s / 2) + 1) * exp(s**2 / 4) / s, 0, True) assert LT(sin(a * t), t, s) == (a / (a**2 + s**2), 0, True) assert LT(cos(a * t), t, s) == (s / (a**2 + s**2), 0, True) # TODO would be nice to have these come out better assert LT(exp(-a * t) * sin(b * t), t, s) == (b / (b**2 + (a + s)**2), -a, True) assert LT(exp(-a*t)*cos(b*t), t, s) == \ ((a + s)/(b**2 + (a + s)**2), -a, True) assert LT(besselj(0, t), t, s) == (1 / sqrt(1 + s**2), 0, True) assert LT(besselj(1, t), t, s) == (1 - 1 / sqrt(1 + 1 / s**2), 0, True) # TODO general order works, but is a *mess* # TODO besseli also works, but is an even greater mess # test a bug in conditions processing # TODO the auxiliary condition should be recognised/simplified assert LT(exp(t) * cos(t), t, s)[:-1] in [ ((s - 1) / (s**2 - 2 * s + 2), -oo), ((s - 1) / ((s - 1)**2 + 1), -oo), ] # Fresnel functions assert laplace_transform(fresnels(t), t, s) == \ ((-sin(s**2/(2*pi))*fresnels(s/pi) + sin(s**2/(2*pi))/2 - cos(s**2/(2*pi))*fresnelc(s/pi) + cos(s**2/(2*pi))/2)/s, 0, True) assert laplace_transform( fresnelc(t), t, s) == ((sin(s**2 / (2 * pi)) * fresnelc(s / pi) / s - cos(s**2 / (2 * pi)) * fresnels(s / pi) / s + sqrt(2) * cos(s**2 / (2 * pi) + pi / 4) / (2 * s), 0, True)) assert LT(Matrix([[exp(t), t*exp(-t)], [t*exp(-t), exp(t)]]), t, s) ==\ Matrix([ [(1/(s - 1), 1, True), ((s + 1)**(-2), 0, True)], [((s + 1)**(-2), 0, True), (1/(s - 1), 1, True)] ])