def test_branch_bug(): assert hyperexpand(hyper((-Rational(1, 3), Rational(1, 2)), (Rational(2, 3), Rational(3, 2)), -z)) == \ -cbrt(z)*lowergamma(exp_polar(I*pi)/3, z)/5 \ + sqrt(pi)*erf(sqrt(z))/(5*sqrt(z)) assert hyperexpand(meijerg([Rational(7, 6), 1], [], [Rational(2, 3)], [Rational(1, 6), 0], z)) == \ 2*z**Rational(2, 3)*(2*sqrt(pi)*erf(sqrt(z))/sqrt(z) - 2*lowergamma(Rational(2, 3), z)/z**Rational(2, 3))*gamma(Rational(2, 3))/gamma(Rational(5, 3))
def test_hyperexpand_special(): assert hyperexpand(hyper([a, b], [c], 1)) == \ gamma(c)*gamma(c - a - b)/gamma(c - a)/gamma(c - b) assert hyperexpand(hyper([a, b], [1 + a - b], -1)) == \ gamma(1 + a/2)*gamma(1 + a - b)/gamma(1 + a)/gamma(1 + a/2 - b) assert hyperexpand(hyper([a, b], [1 + b - a], -1)) == \ gamma(1 + b/2)*gamma(1 + b - a)/gamma(1 + b)/gamma(1 + b/2 - a) assert hyperexpand(meijerg([1 - z - a/2], [1 - z + a/2], [b/2], [-b/2], 1)) == \ gamma(1 - 2*z)*gamma(z + a/2 + b/2)/gamma(1 - z + a/2 - b/2) \ / gamma(1 - z - a/2 + b/2)/gamma(1 - z + a/2 + b/2) assert hyperexpand(hyper([a], [b], 0)) == 1 assert hyper([a], [b], 0) != 0
def test_partial_simp2(): # Now test that formulae are partially simplified. c, d, e = (randcplx() for _ in range(3)) assert hyperexpand(hyper([3, a], [1, b], z)) == \ (-a*b/2 + a*z/2 + 2*a)*hyper([a + 1], [b], z) \ + (a*b/2 - 2*a + 1)*hyper([a], [b], z) assert tn(hyperexpand(hyper([3, d], [1, e], z)), hyper([3, d], [1, e], z), z) assert hyperexpand(hyper([3], [1, a, b], z)) == \ hyper((), (a, b), z) \ + z*hyper((), (a + 1, b), z)/(2*a) \ - z*(b - 4)*hyper((), (a + 1, b + 1), z)/(2*a*b) assert tn(hyperexpand(hyper([3], [1, d, e], z)), hyper([3], [1, d, e], z), z)
def test_meijerg_lookup(): assert hyperexpand(meijerg([a], [], [b, a], [], z)) == \ z**b*exp(z)*gamma(-a + b + 1)*uppergamma(a - b, z) assert hyperexpand(meijerg([0], [], [0, 0], [], z)) == \ exp(z)*uppergamma(0, z) assert can_do_meijer([a], [], [b, a + 1], []) assert can_do_meijer([a], [], [b + 2, a], []) assert can_do_meijer([a], [], [b - 2, a], []) assert hyperexpand(meijerg([a], [], [a, a, a - Rational(1, 2)], [], z)) == \ -sqrt(pi)*z**(a - Rational(1, 2))*(2*cos(2*sqrt(z))*(Si(2*sqrt(z)) - pi/2) - 2*sin(2*sqrt(z))*Ci(2*sqrt(z))) == \ hyperexpand(meijerg([a], [], [a, a - Rational(1, 2), a], [], z)) == \ hyperexpand(meijerg([a], [], [a - Rational(1, 2), a, a], [], z)) assert can_do_meijer([a - 1], [], [a + 2, a - Rational(3, 2), a + 1], [])
def test_lookup_table(): table = defaultdict(list) _create_lookup_table(table) for _, l in sorted(table.items(), key=default_sort_key): for formula, terms, cond, hint in sorted(l, key=default_sort_key): subs = {} for a in list(formula.free_symbols) + [z_dummy]: if hasattr(a, 'properties') and a.properties: # these Wilds match positive integers subs[a] = randrange(1, 10) else: subs[a] = uniform(1.5, 2.0) if not isinstance(terms, list): terms = terms(subs) # First test that hyperexpand can do this. expanded = [hyperexpand(g) for (_, g) in terms] assert all(x.is_Piecewise or not x.has(meijerg) for x in expanded) # Now test that the meijer g-function is indeed as advertised. expanded = Add(*[f*x for (f, x) in terms]) a, b = formula.evalf(subs=subs, strict=False), expanded.evalf(subs=subs, strict=False) r = min(abs(a), abs(b)) if r < 1: assert abs(a - b).evalf(strict=False) <= 1e-10 else: assert (abs(a - b)/r).evalf(strict=False) <= 1e-10
def test_meijerg_with_Floats(): # see sympy/sympy#10681 f = meijerg(((3.0, 1), ()), ((Rational(3, 2), ), (0, )), z) a = -2.3632718012073 g = a * z**Rational(3, 2) * hyper( (-0.5, Rational(3, 2)), (Rational(5, 2), ), z * exp_polar(I * pi)) assert RR.almosteq((hyperexpand(f) / g).n(), 1.0, 1e-12)
def can_do_meijer(a1, a2, b1, b2, numeric=True): """ This helper function tries to hyperexpand() the meijer g-function corresponding to the parameters a1, a2, b1, b2. It returns False if this expansion still contains g-functions. If numeric is True, it also tests the so-obtained formula numerically (at random values) and returns False if the test fails. Else it returns True. """ r = hyperexpand(meijerg(a1, a2, b1, b2, z)) if r.has(meijerg): return False # NOTE hyperexpand() returns a truly branched function, whereas numerical # evaluation only works on the main branch. Since we are evaluating on # the main branch, this should not be a problem, but expressions like # exp_polar(I*pi/2*x)**a are evaluated incorrectly. We thus have to get # rid of them. The expand heuristically does this... r = unpolarify( expand(r, force=True, power_base=True, power_exp=False, mul=False, log=False, multinomial=False, basic=False)) if not numeric: return True repl = {} for n, a in enumerate(meijerg(a1, a2, b1, b2, z).free_symbols - {z}): repl[a] = randcplx(n) return tn(meijerg(a1, a2, b1, b2, z).subs(repl), r.subs(repl), z)
def _eval_expand_func(self, **hints): from diofant import gamma, hyperexpand if len(self.ap) == 2 and len(self.bq) == 1 and self.argument == 1: a, b = self.ap c = self.bq[0] return gamma(c) * gamma(c - a - b) / gamma(c - a) / gamma(c - b) return hyperexpand(self)
def test_lookup_table(): table = defaultdict(list) _create_lookup_table(table) for _, l in sorted(table.items(), key=default_sort_key): for formula, terms, cond, hint in sorted(l, key=default_sort_key): subs = {} for a in list(formula.free_symbols) + [z_dummy]: if hasattr(a, 'properties') and a.properties: # these Wilds match positive integers subs[a] = randrange(1, 10) else: subs[a] = uniform(1.5, 2.0) if not isinstance(terms, list): terms = terms(subs) # First test that hyperexpand can do this. expanded = [hyperexpand(g) for (_, g) in terms] assert all(x.is_Piecewise or not x.has(meijerg) for x in expanded) # Now test that the meijer g-function is indeed as advertised. expanded = Add(*[f * x for (f, x) in terms]) a, b = formula.evalf(subs=subs, strict=False), expanded.evalf(subs=subs, strict=False) r = min(abs(a), abs(b)) if r < 1: assert abs(a - b).evalf(strict=False) <= 1e-10 else: assert (abs(a - b) / r).evalf(strict=False) <= 1e-10
def test_hyperexpand(): # Luke, Y. L. (1969), The Special Functions and Their Approximations, # Volume 1, section 6.2 assert hyperexpand(hyper([], [], z)) == exp(z) assert hyperexpand(hyper([1, 1], [2], -z) * z) == log(1 + z) assert hyperexpand(hyper([], [Rational(1, 2)], -z**2 / 4)) == cos(z) assert hyperexpand(z * hyper([], [Rational(3, 2)], -z**2 / 4)) == sin(z) assert hyperexpand(hyper([Rational(1, 2), Rational(1, 2)], [Rational(3, 2)], z**2)*z) \ == asin(z) # Test place option f = meijerg(((0, 1), ()), ((Rational(1, 2), ), (0, )), z**2) assert hyperexpand(f) == sqrt(pi) / sqrt(1 + z**(-2)) assert hyperexpand(f, place=0) == sqrt(pi) * z / sqrt(z**2 + 1) assert hyperexpand(f, place=zoo) == sqrt(pi) / sqrt(1 + z**(-2))
def t(m, a, b): a, b = sympify([a, b]) m_ = m m = hyperexpand(m) if not m == Piecewise((a, abs(z) < 1), (b, abs(1 / z) < 1), (m_, True)): return False if not (m.args[0].args[0] == a and m.args[1].args[0] == b): return False z0 = randcplx() / 10 if abs(m.subs({z: z0}) - a.subs({z: z0})).evalf(strict=False) > 1e-10: return False if abs(m.subs({z: 1 / z0}) - b.subs({z: 1 / z0})).evalf(strict=False) > 1e-10: return False return True
def test_hyperexpand_bases(): assert hyperexpand(hyper([2], [a], z)) == \ a + z**(-a + 1)*(-a**2 + 3*a + z*(a - 1) - 2)*exp(z) * \ lowergamma(a - 1, z) - 1 # TODO [a+1, a+Rational(-1, 2)], [2*a] assert hyperexpand(hyper([1, 2], [3], z)) == -2 / z - 2 * log(-z + 1) / z**2 assert hyperexpand(hyper([Rational(1, 2), 2], [Rational(3, 2)], z)) == \ -1/(2*z - 2) + atanh(sqrt(z))/sqrt(z)/2 assert hyperexpand(hyper([Rational(1, 2), Rational(1, 2)], [Rational(5, 2)], z)) == \ (-3*z + 3)/4/(z*sqrt(-z + 1)) \ + (6*z - 3)*asin(sqrt(z))/(4*z**Rational(3, 2)) assert hyperexpand(hyper([1, 2], [Rational(3, 2)], z)) == -1/(2*z - 2) \ - asin(sqrt(z))/(sqrt(z)*(2*z - 2)*sqrt(-z + 1)) assert hyperexpand(hyper([Rational(-1, 2) - 1, 1, 2], [Rational(1, 2), 3], z)) == \ sqrt(z)*(6*z/7 - Rational(6, 5))*atanh(sqrt(z)) \ + (-30*z**2 + 32*z - 6)/35/z - 6*log(-z + 1)/(35*z**2) assert hyperexpand(hyper([1 + Rational(1, 2), 1, 1], [2, 2], z)) == \ -4*log(sqrt(-z + 1)/2 + Rational(1, 2))/z # TODO hyperexpand(hyper([a], [2*a + 1], z)) # TODO [Rational(1, 2), a], [Rational(3, 2), a+1] assert hyperexpand(hyper([2], [b, 1], z)) == \ z**(-b/2 + Rational(1, 2))*besseli(b - 1, 2*sqrt(z))*gamma(b) \ + z**(-b/2 + 1)*besseli(b, 2*sqrt(z))*gamma(b)
def can_do(ap, bq, numerical=True, div=1, lowerplane=False): r = hyperexpand(hyper(ap, bq, z)) if r.has(hyper): return False if not numerical: return True repl = {} randsyms = r.free_symbols - {z} while randsyms: # Only randomly generated parameters are checked. for n, a in enumerate(randsyms): repl[a] = randcplx(n) / div if not any(b.is_Integer and b <= 0 for b in Tuple(*bq).subs(repl)): break [a, b, c, d] = [2, -1, 3, 1] if lowerplane: [a, b, c, d] = [2, -2, 3, -1] return tn(hyper(ap, bq, z).subs(repl), r.replace(exp_polar, exp).subs(repl), z, a=a, b=b, c=c, d=d)
def _eval_expand_func(self, **hints): from diofant import hyperexpand return hyperexpand(self)
def test_diofantissue_241(): e = hyper((2, 3, 5, 9, 1), (1, 4, 6, 10), 1) assert hyperexpand(e) == Rational(108, 7)
def test_hyperexpand_parametric(): assert hyperexpand(hyper([a, Rational(1, 2) + a], [Rational(1, 2)], z)) \ == (1 + sqrt(z))**(-2*a)/2 + (1 - sqrt(z))**(-2*a)/2 assert hyperexpand(hyper([a, -Rational(1, 2) + a], [2*a], z)) \ == 2**(2*a - 1)*(sqrt(-z + 1) + 1)**(-2*a + 1)
def _eval_simplify(self, ratio, measure): from diofant.simplify.hyperexpand import hyperexpand return hyperexpand(self)
def test_bug(): h = hyper([-1, 1], [z], -1) assert hyperexpand(h) == (z + 1) / z
def test_Mod1_behavior(): n = Symbol('n', integer=True) # Note: this should not hang. assert simplify(hyperexpand(meijerg([1], [], [n + 1], [0], z))) == \ lowergamma(n + 1, z)
def test_lerchphi(): assert hyperexpand(hyper([1, a], [a + 1], z) / a) == lerchphi(z, 1, a) assert hyperexpand(hyper([1, a, a], [a + 1, a + 1], z) / a**2) == lerchphi( z, 2, a) assert hyperexpand(hyper([1, a, a, a], [a + 1, a + 1, a + 1], z)/a**3) == \ lerchphi(z, 3, a) assert hyperexpand(hyper([1] + [a]*10, [a + 1]*10, z)/a**10) == \ lerchphi(z, 10, a) assert combsimp( hyperexpand(meijerg([0, 1 - a], [], [0], [-a], exp_polar(-I * pi) * z))) == lerchphi(z, 1, a) assert combsimp( hyperexpand( meijerg([0, 1 - a, 1 - a], [], [0], [-a, -a], exp_polar(-I * pi) * z))) == lerchphi(z, 2, a) assert combsimp( hyperexpand( meijerg([0, 1 - a, 1 - a, 1 - a], [], [0], [-a, -a, -a], exp_polar(-I * pi) * z))) == lerchphi(z, 3, a) assert hyperexpand(z * hyper([1, 1], [2], z)) == -log(1 + -z) assert hyperexpand(z * hyper([1, 1, 1], [2, 2], z)) == polylog(2, z) assert hyperexpand(z * hyper([1, 1, 1, 1], [2, 2, 2], z)) == polylog(3, z) assert hyperexpand(hyper([1, a, 1 + Rational(1, 2)], [a + 1, Rational(1, 2)], z)) == \ -2*a/(z - 1) + (-2*a**2 + a)*lerchphi(z, 1, a) # Now numerical tests. These make sure reductions etc are carried out # correctly # a rational function (polylog at negative integer order) assert can_do([2, 2, 2], [1, 1]) # NOTE these contain log(1-x) etc ... better make sure we have |z| < 1 # reduction of order for polylog assert can_do([1, 1, 1, b + 5], [2, 2, b], div=10) # reduction of order for lerchphi # XXX lerchphi in mpmath is flaky assert can_do([1, a, a, a, b + 5], [a + 1, a + 1, a + 1, b], numerical=False) # test a bug assert hyperexpand(hyper([Rational(1, 2), Rational(1, 2), Rational(1, 2), 1], [Rational(3, 2), Rational(3, 2), Rational(3, 2)], Rational(1, 4))) == \ abs(-polylog(3, exp_polar(I*pi)/2) + polylog(3, Rational(1, 2)))
def test_diofantissue_203(): h = hyper((-5, -3, -4), (-6, -6), 1) assert hyperexpand(h) == Rational(1, 30) h = hyper((-6, -7, -5), (-6, -6), 1) assert hyperexpand(h) == -Rational(1, 6)
def test_shifted_sum(): assert simplify(hyperexpand(z**4*hyper([2], [3, Rational(3, 2)], -z**2))) \ == z*sin(2*z) + (-z**2 + Rational(1, 2))*cos(2*z) - Rational(1, 2)
def u(an, ap, bm, bq): m = meijerg(an, ap, bm, bq, z) m2 = hyperexpand(m, allow_hyper=True) if m2.has(meijerg) and not (m2.is_Piecewise and len(m2.args) == 3): return False return tn(m, m2, z)
def test_sympyissue_6052(): G0 = meijerg((), (), (1, ), (0, ), 0) assert hyperexpand(G0) == 0 assert hyperexpand(hyper((), (2, ), 0)) == 1
def test_polynomial(): assert hyperexpand(hyper([], [-1], z)) == oo assert hyperexpand(hyper([-2], [-1], z)) == oo assert hyperexpand(hyper([0, 0], [-1], z)) == 1 assert can_do([-5, -2, randcplx(), randcplx()], [-10, randcplx()]) assert hyperexpand(hyper((-1, 1), (-2, ), z)) == 1 + z / 2
def test_meijerg_expand(): # from mpmath docs assert hyperexpand(meijerg([[], []], [[0], []], -z)) == exp(z) assert hyperexpand(meijerg([[1, 1], []], [[1], [0]], z)) == \ log(z + 1) assert hyperexpand(meijerg([[1, 1], []], [[1], [1]], z)) == \ z/(z + 1) assert hyperexpand(meijerg([[], []], [[Rational(1, 2)], [0]], (z/2)**2)) \ == sin(z)/sqrt(pi) assert hyperexpand(meijerg([[], []], [[0], [Rational(1, 2)]], (z/2)**2)) \ == cos(z)/sqrt(pi) assert can_do_meijer([], [a], [a - 1, a - Rational(1, 2)], []) assert can_do_meijer([], [], [a / 2], [-a / 2], False) # branches... assert can_do_meijer([a], [b], [a], [b, a - 1]) # wikipedia assert hyperexpand(meijerg([1], [], [], [0], z)) == \ Piecewise((0, abs(z) < 1), (1, abs(1/z) < 1), (meijerg([1], [], [], [0], z), True)) assert hyperexpand(meijerg([], [1], [0], [], z)) == \ Piecewise((1, abs(z) < 1), (0, abs(1/z) < 1), (meijerg([], [1], [0], [], z), True)) # The Special Functions and their Approximations assert can_do_meijer([], [], [a + b / 2], [a, a - b / 2, a + Rational(1, 2)]) assert can_do_meijer([], [], [a], [b], False) # branches only agree for small z assert can_do_meijer([], [Rational(1, 2)], [a], [-a]) assert can_do_meijer([], [], [a, b], []) assert can_do_meijer([], [], [a, b], []) assert can_do_meijer([], [], [a, a + Rational(1, 2)], [b, b + Rational(1, 2)]) assert can_do_meijer([], [], [a, -a], [0, Rational(1, 2)], False) # dito assert can_do_meijer([], [], [a, a + Rational(1, 2), b, b + Rational(1, 2)], []) assert can_do_meijer([Rational(1, 2)], [], [0], [a, -a]) assert can_do_meijer([Rational(1, 2)], [], [a], [0, -a], False) # dito assert can_do_meijer([], [a - Rational(1, 2)], [a, b], [a - Rational(1, 2)], False) assert can_do_meijer([], [a + Rational(1, 2)], [a + b, a - b, a], [], False) assert can_do_meijer([a + Rational(1, 2)], [], [b, 2 * a - b, a], [], False) # This for example is actually zero. assert can_do_meijer([], [], [], [a, b]) # Testing a bug: assert hyperexpand(meijerg([0, 2], [], [], [-1, 1], z)) == \ Piecewise((0, abs(z) < 1), (z/2 - 1/(2*z), abs(1/z) < 1), (meijerg([0, 2], [], [], [-1, 1], z), True)) # Test that the simplest possible answer is returned: assert combsimp(simplify(hyperexpand( meijerg([1], [1 - a], [-a/2, -a/2 + Rational(1, 2)], [], 1/z)))) == \ -2*sqrt(pi)*(sqrt(z + 1) + 1)**a/a # Test that hyper is returned assert hyperexpand(meijerg([1], [], [a], [0, 0], z)) == hyper( (a, ), (a + 1, a + 1), z * exp_polar(I * pi)) * z**a * gamma(a) / gamma(a + 1)**2 assert can_do_meijer([], [], [a + Rational(1, 2)], [a, a - b / 2, a + b / 2]) assert can_do_meijer([], [], [3 * a - Rational(1, 2), a, -a - Rational(1, 2)], [a - Rational(1, 2)]) assert can_do_meijer([], [], [0, a - Rational(1, 2), -a - Rational(1, 2)], [Rational(1, 2)]) assert can_do_meijer([Rational(1, 2)], [], [-a, a], [0])
def test_mellin_transform(): from diofant import Max, Min MT = mellin_transform bpos = symbols('b', positive=True) # 8.4.2 assert MT(x**nu*Heaviside(x - 1), x, s) == \ (-1/(nu + s), (-oo, -re(nu)), True) assert MT(x**nu*Heaviside(1 - x), x, s) == \ (1/(nu + s), (-re(nu), oo), True) assert MT((1 - x)**(beta - 1)*Heaviside(1 - x), x, s) == \ (gamma(beta)*gamma(s)/gamma(beta + s), (0, oo), re(-beta) < 0) assert MT((x - 1)**(beta - 1)*Heaviside(x - 1), x, s) == \ (gamma(beta)*gamma(1 - beta - s)/gamma(1 - s), (-oo, -re(beta) + 1), re(-beta) < 0) assert MT((1 + x)**(-rho), x, s) == \ (gamma(s)*gamma(rho - s)/gamma(rho), (0, re(rho)), True) # TODO also the conditions should be simplified assert MT(abs(1 - x)**(-rho), x, s) == (cos(pi * (rho / 2 - s)) * gamma(s) * gamma(rho - s) / (cos(pi * rho / 2) * gamma(rho)), (0, re(rho)), And(re(rho) - 1 < 0, re(rho) < 1)) mt = MT((1 - x)**(beta - 1) * Heaviside(1 - x) + a * (x - 1)**(beta - 1) * Heaviside(x - 1), x, s) assert mt[1], mt[2] == ((0, -re(beta) + 1), True) assert MT((x**a - b**a)/(x - b), x, s)[0] == \ pi*b**(a + s - 1)*sin(pi*a)/(sin(pi*s)*sin(pi*(a + s))) assert MT((x**a - bpos**a)/(x - bpos), x, s) == \ (pi*bpos**(a + s - 1)*sin(pi*a)/(sin(pi*s)*sin(pi*(a + s))), (Max(-re(a), 0), Min(1 - re(a), 1)), True) expr = (sqrt(x + b**2) + b)**a assert MT(expr.subs(b, bpos), x, s) == \ (-a*(2*bpos)**(a + 2*s)*gamma(s)*gamma(-a - 2*s)/gamma(-a - s + 1), (0, -re(a)/2), True) expr = (sqrt(x + b**2) + b)**a / sqrt(x + b**2) assert MT(expr.subs(b, bpos), x, s) == \ (2**(a + 2*s)*bpos**(a + 2*s - 1)*gamma(s) * gamma(1 - a - 2*s)/gamma(1 - a - s), (0, -re(a)/2 + Rational(1, 2)), True) # 8.4.2 assert MT(exp(-x), x, s) == (gamma(s), (0, oo), True) assert MT(exp(-1 / x), x, s) == (gamma(-s), (-oo, 0), True) # 8.4.5 assert MT(log(x)**4 * Heaviside(1 - x), x, s) == (24 / s**5, (0, oo), True) assert MT(log(x)**3 * Heaviside(x - 1), x, s) == (6 / s**4, (-oo, 0), True) assert MT(log(x + 1), x, s) == (pi / (s * sin(pi * s)), (-1, 0), True) assert MT(log(1 / x + 1), x, s) == (pi / (s * sin(pi * s)), (0, 1), True) assert MT(log(abs(1 - x)), x, s) == (pi / (s * tan(pi * s)), (-1, 0), True) assert MT(log(abs(1 - 1 / x)), x, s) == (pi / (s * tan(pi * s)), (0, 1), True) # TODO we cannot currently do these (needs summation of 3F2(-1)) # this also implies that they cannot be written as a single g-function # (although this is possible) mt = MT(log(x) / (x + 1), x, s) assert mt[1:] == ((0, 1), True) assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg) mt = MT(log(x)**2 / (x + 1), x, s) assert mt[1:] == ((0, 1), True) assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg) mt = MT(log(x) / (x + 1)**2, x, s) assert mt[1:] == ((0, 2), True) assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg) # 8.4.14 assert MT(erf(sqrt(x)), x, s) == \ (-gamma(s + Rational(1, 2))/(sqrt(pi)*s), (-Rational(1, 2), 0), True)
def test_mellin_transform(): MT = mellin_transform bpos = symbols('b', positive=True) # 8.4.2 assert MT(x**nu*Heaviside(x - 1), x, s) == \ (-1/(nu + s), (-oo, -re(nu)), True) assert MT(x**nu*Heaviside(1 - x), x, s) == \ (1/(nu + s), (-re(nu), oo), True) assert MT((1 - x)**(beta - 1)*Heaviside(1 - x), x, s) == \ (gamma(beta)*gamma(s)/gamma(beta + s), (0, oo), re(-beta) < 0) assert MT((x - 1)**(beta - 1)*Heaviside(x - 1), x, s) == \ (gamma(beta)*gamma(1 - beta - s)/gamma(1 - s), (-oo, -re(beta) + 1), re(-beta) < 0) assert MT((1 + x)**(-rho), x, s) == \ (gamma(s)*gamma(rho - s)/gamma(rho), (0, re(rho)), True) # TODO also the conditions should be simplified assert MT(abs(1 - x)**(-rho), x, s) == ( 2*sin(pi*rho/2)*gamma(1 - rho)*cos(pi*(rho/2 - s))*gamma(s)*gamma(rho-s)/pi, (0, re(rho)), And(re(rho) - 1 < 0, re(rho) < 1)) mt = MT((1 - x)**(beta - 1)*Heaviside(1 - x) + a*(x - 1)**(beta - 1)*Heaviside(x - 1), x, s) assert mt[1], mt[2] == ((0, -re(beta) + 1), True) assert MT((x**a - b**a)/(x - b), x, s)[0] == \ pi*b**(a + s - 1)*sin(pi*a)/(sin(pi*s)*sin(pi*(a + s))) assert MT((x**a - bpos**a)/(x - bpos), x, s) == \ (pi*bpos**(a + s - 1)*sin(pi*a)/(sin(pi*s)*sin(pi*(a + s))), (Max(-re(a), 0), Min(1 - re(a), 1)), True) expr = (sqrt(x + b**2) + b)**a assert MT(expr.subs({b: bpos}), x, s) == \ (-a*(2*bpos)**(a + 2*s)*gamma(s)*gamma(-a - 2*s)/gamma(-a - s + 1), (0, -re(a)/2), True) expr = (sqrt(x + b**2) + b)**a/sqrt(x + b**2) assert MT(expr.subs({b: bpos}), x, s) == \ (2**(a + 2*s)*bpos**(a + 2*s - 1)*gamma(s) * gamma(1 - a - 2*s)/gamma(1 - a - s), (0, -re(a)/2 + Rational(1, 2)), True) # 8.4.2 assert MT(exp(-x), x, s) == (gamma(s), (0, oo), True) assert MT(exp(-1/x), x, s) == (gamma(-s), (-oo, 0), True) # 8.4.5 assert MT(log(x)**4*Heaviside(1 - x), x, s) == (24/s**5, (0, oo), True) assert MT(log(x)**3*Heaviside(x - 1), x, s) == (6/s**4, (-oo, 0), True) assert MT(log(x + 1), x, s) == (pi/(s*sin(pi*s)), (-1, 0), True) assert MT(log(1/x + 1), x, s) == (pi/(s*sin(pi*s)), (0, 1), True) assert MT(log(abs(1 - x)), x, s) == (pi/(s*tan(pi*s)), (-1, 0), True) assert MT(log(abs(1 - 1/x)), x, s) == (pi/(s*tan(pi*s)), (0, 1), True) # TODO we cannot currently do these (needs summation of 3F2(-1)) # this also implies that they cannot be written as a single g-function # (although this is possible) mt = MT(log(x)/(x + 1), x, s) assert mt[1:] == ((0, 1), True) assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg) mt = MT(log(x)**2/(x + 1), x, s) assert mt[1:] == ((0, 1), True) assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg) mt = MT(log(x)/(x + 1)**2, x, s) assert mt[1:] == ((0, 2), True) assert not hyperexpand(mt[0], allow_hyper=True).has(meijerg) # 8.4.14 assert MT(erf(sqrt(x)), x, s) == \ (-gamma(s + Rational(1, 2))/(sqrt(pi)*s), (-Rational(1, 2), 0), True)