コード例 #1
0
 def __init__(self, dim, M_max):
         self.dim = dim
         self.m_order = list(range(M_max+1))
         Delta, Delta_12, Xi = symbols('Delta Delta_12 Xi')
         Bulk_expr = -1*(Xi**(Delta/2))*hyper([(Delta + Delta_12)/2 , (Delta - Delta_12)/2], [Delta + 1 - (dim/2)],-Xi)
         Bdy_expr = (Xi**(-Delta + (delta_1 + delta_2)/2))*hyper([Delta, Delta + 1 - (dim/2)], [2*Delta + 2 - (dim)], -Xi**(-1))
         # if dim == 3:
         #         Bdy_expr = (0.5/(Xi**0.5))*((4/(1 + Xi))**(Delta - 0.5))*(1 + (Xi/(1+Xi))**(0.5))**(-2*(Delta - 1))
         Bulk_array = [Bulk_expr]
         Bdy_array = [Bdy_expr]
         for n in range(1, M_max + 1):
                 Bulk_array.append(diff(Bulk_expr, Xi, n))
                 Bdy_array.append(diff(Bdy_expr, Xi, n))
         self.table = np.array([Bulk_array, Bdy_array])      
コード例 #2
0
def test_catalan():
    n = Symbol('n', integer=True)
    m = Symbol('n', integer=True, positive=True)

    catalans = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786]
    for i, c in enumerate(catalans):
        assert catalan(i) == c
        assert catalan(n).rewrite(factorial).subs(n, i) == c
        assert catalan(n).rewrite(Product).subs(n, i).doit() == c

    assert catalan(x) == catalan(x)
    assert catalan(2*x).rewrite(binomial) == binomial(4*x, 2*x)/(2*x + 1)
    assert catalan(Rational(1, 2)).rewrite(gamma) == 8/(3*pi)
    assert catalan(Rational(1, 2)).rewrite(factorial).rewrite(gamma) ==\
        8 / (3 * pi)
    assert catalan(3*x).rewrite(gamma) == 4**(
        3*x)*gamma(3*x + Rational(1, 2))/(sqrt(pi)*gamma(3*x + 2))
    assert catalan(x).rewrite(hyper) == hyper((-x + 1, -x), (2,), 1)

    assert catalan(n).rewrite(factorial) == factorial(2*n) / (factorial(n + 1)
                                                              * factorial(n))
    assert isinstance(catalan(n).rewrite(Product), catalan)
    assert isinstance(catalan(m).rewrite(Product), Product)

    assert diff(catalan(x), x) == (polygamma(
        0, x + Rational(1, 2)) - polygamma(0, x + 2) + log(4))*catalan(x)

    assert catalan(x).evalf() == catalan(x)
    c = catalan(S.Half).evalf()
    assert str(c) == '0.848826363156775'
    c = catalan(I).evalf(3)
    assert str((re(c), im(c))) == '(0.398, -0.0209)'
コード例 #3
0
def test_catalan():
    n = Symbol('n', integer=True)
    m = Symbol('n', integer=True, positive=True)

    catalans = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786]
    for i, c in enumerate(catalans):
        assert catalan(i) == c
        assert catalan(n).rewrite(factorial).subs(n, i) == c
        assert catalan(n).rewrite(Product).subs(n, i).doit() == c

    assert catalan(x) == catalan(x)
    assert catalan(2 *
                   x).rewrite(binomial) == binomial(4 * x, 2 * x) / (2 * x + 1)
    assert catalan(Rational(1, 2)).rewrite(gamma) == 8 / (3 * pi)
    assert catalan(Rational(1, 2)).rewrite(factorial).rewrite(gamma) ==\
        8 / (3 * pi)
    assert catalan(3 * x).rewrite(gamma) == 4**(
        3 * x) * gamma(3 * x + Rational(1, 2)) / (sqrt(pi) * gamma(3 * x + 2))
    assert catalan(x).rewrite(hyper) == hyper((-x + 1, -x), (2, ), 1)

    assert catalan(n).rewrite(factorial) == factorial(
        2 * n) / (factorial(n + 1) * factorial(n))
    assert isinstance(catalan(n).rewrite(Product), catalan)
    assert isinstance(catalan(m).rewrite(Product), Product)

    assert diff(catalan(x), x) == (polygamma(0, x + Rational(1, 2)) -
                                   polygamma(0, x + 2) + log(4)) * catalan(x)

    assert catalan(x).evalf() == catalan(x)
    c = catalan(S.Half).evalf()
    assert str(c) == '0.848826363156775'
    c = catalan(I).evalf(3)
    assert str((re(c), im(c))) == '(0.398, -0.0209)'
コード例 #4
0
ファイル: summations.py プロジェクト: msgoff/sympy
def _eval_sum_hyper(f, i, a):
    """ Returns (res, cond). Sums from a to oo. """
    from sympy.functions import hyper
    from sympy.simplify import hyperexpand, hypersimp, fraction, simplify
    from sympy.polys.polytools import Poly, factor
    from sympy.core.numbers import Float

    if a != 0:
        return _eval_sum_hyper(f.subs(i, i + a), i, 0)

    if f.subs(i, 0) == 0:
        if simplify(f.subs(i, Dummy("i", integer=True, positive=True))) == 0:
            return S.Zero, True
        return _eval_sum_hyper(f.subs(i, i + 1), i, 0)

    hs = hypersimp(f, i)
    if hs is None:
        return None

    if isinstance(hs, Float):
        from sympy.simplify.simplify import nsimplify

        hs = nsimplify(hs)

    numer, denom = fraction(factor(hs))
    top, topl = numer.as_coeff_mul(i)
    bot, botl = denom.as_coeff_mul(i)
    ab = [top, bot]
    factors = [topl, botl]
    params = [[], []]
    for k in range(2):
        for fac in factors[k]:
            mul = 1
            if fac.is_Pow:
                mul = fac.exp
                fac = fac.base
                if not mul.is_Integer:
                    return None
            p = Poly(fac, i)
            if p.degree() != 1:
                return None
            m, n = p.all_coeffs()
            ab[k] *= m ** mul
            params[k] += [n / m] * mul

    # Add "1" to numerator parameters, to account for implicit n! in
    # hypergeometric series.
    ap = params[0] + [1]
    bq = params[1]
    x = ab[0] / ab[1]
    h = hyper(ap, bq, x)
    f = combsimp(f)
    return f.subs(i, 0) * hyperexpand(h), h.convergence_statement
コード例 #5
0
ファイル: summations.py プロジェクト: carstimon/sympy
def _eval_sum_hyper(f, i, a):
    """ Returns (res, cond). Sums from a to oo. """
    from sympy.functions import hyper
    from sympy.simplify import hyperexpand, hypersimp, fraction, simplify
    from sympy.polys.polytools import Poly, factor
    from sympy.core.numbers import Float

    if a != 0:
        return _eval_sum_hyper(f.subs(i, i + a), i, 0)

    if f.subs(i, 0) == 0:
        if simplify(f.subs(i, Dummy('i', integer=True, positive=True))) == 0:
            return S(0), True
        return _eval_sum_hyper(f.subs(i, i + 1), i, 0)

    hs = hypersimp(f, i)
    if hs is None:
        return None

    if isinstance(hs, Float):
        from sympy.simplify.simplify import nsimplify
        hs = nsimplify(hs)

    numer, denom = fraction(factor(hs))
    top, topl = numer.as_coeff_mul(i)
    bot, botl = denom.as_coeff_mul(i)
    ab = [top, bot]
    factors = [topl, botl]
    params = [[], []]
    for k in range(2):
        for fac in factors[k]:
            mul = 1
            if fac.is_Pow:
                mul = fac.exp
                fac = fac.base
                if not mul.is_Integer:
                    return None
            p = Poly(fac, i)
            if p.degree() != 1:
                return None
            m, n = p.all_coeffs()
            ab[k] *= m**mul
            params[k] += [n/m]*mul

    # Add "1" to numerator parameters, to account for implicit n! in
    # hypergeometric series.
    ap = params[0] + [1]
    bq = params[1]
    x = ab[0]/ab[1]
    h = hyper(ap, bq, x)

    return f.subs(i, 0)*hyperexpand(h), h.convergence_statement
コード例 #6
0
ファイル: test_comb_numbers.py プロジェクト: DVNSarma/sympy
def test_catalan():
    assert catalan(1) == 1
    assert catalan(2) == 2
    assert catalan(3) == 5
    assert catalan(4) == 14

    assert catalan(x) == catalan(x)
    assert catalan(2*x).rewrite(binomial) == binomial(4*x, 2*x)/(2*x + 1)
    assert catalan(Rational(1, 2)).rewrite(gamma) == 8/(3*pi)
    assert catalan(3*x).rewrite(gamma) == 4**(
        3*x)*gamma(3*x + Rational(1, 2))/(sqrt(pi)*gamma(3*x + 2))
    assert catalan(x).rewrite(hyper) == hyper((-x + 1, -x), (2,), 1)

    assert diff(catalan(x), x) == (polygamma(
        0, x + Rational(1, 2)) - polygamma(0, x + 2) + log(4))*catalan(x)

    c = catalan(0.5).evalf()
    assert str(c) == '0.848826363156775'
コード例 #7
0
def get_sol_2F1_hypergeometric(eq, func, match_object):
    x = func.args[0]
    from sympy.simplify.hyperexpand import hyperexpand
    from sympy.polys.polytools import factor
    C0, C1 = get_numbered_constants(eq, num=2)
    a = match_object['a']
    b = match_object['b']
    c = match_object['c']
    A = match_object['A']

    sol = None

    if c.is_integer == False:
        sol = C0 * hyper([a, b], [c], x) + C1 * hyper([a - c + 1, b - c + 1],
                                                      [2 - c], x) * x**(1 - c)
    elif c == 1:
        y2 = Integral(
            exp(Integral((-(a + b + 1) * x + c) / (x**2 - x), x)) /
            (hyperexpand(hyper([a, b], [c], x))**2), x) * hyper([a, b], [c], x)
        sol = C0 * hyper([a, b], [c], x) + C1 * y2
    elif (c - a - b).is_integer == False:
        sol = C0 * hyper([a, b], [1 + a + b - c], 1 - x) + C1 * hyper(
            [c - a, c - b], [1 + c - a - b], 1 - x) * (1 - x)**(c - a - b)

    if sol:
        # applying transformation in the solution
        subs = match_object['mobius']
        dtdx = simplify(1 / (subs.diff(x)))
        _B = ((a + b + 1) * x - c).subs(x, subs) * dtdx
        _B = factor(_B + ((x**2 - x).subs(x, subs)) * (dtdx.diff(x) * dtdx))
        _A = factor((x**2 - x).subs(x, subs) * (dtdx**2))
        e = exp(logcombine(Integral(cancel(_B / (2 * _A)), x), force=True))
        sol = sol.subs(x, match_object['mobius'])
        sol = sol.subs(x, x**match_object['k'])
        e = e.subs(x, x**match_object['k'])

        if not A.is_zero:
            e1 = Integral(A / 2, x)
            e1 = exp(logcombine(e1, force=True))
            sol = cancel((e / e1) * x**((-match_object['k'] + 1) / 2)) * sol
            sol = Eq(func, sol)
            return sol

        sol = cancel((e) * x**((-match_object['k'] + 1) / 2)) * sol
        sol = Eq(func, sol)
    return sol
コード例 #8
0
def test_catalan():
    assert catalan(1) == 1
    assert catalan(2) == 2
    assert catalan(3) == 5
    assert catalan(4) == 14

    assert catalan(x) == catalan(x)
    assert catalan(2 *
                   x).rewrite(binomial) == binomial(4 * x, 2 * x) / (2 * x + 1)
    assert catalan(Rational(1, 2)).rewrite(gamma) == 8 / (3 * pi)
    assert catalan(3 * x).rewrite(gamma) == 4**(
        3 * x) * gamma(3 * x + Rational(1, 2)) / (sqrt(pi) * gamma(3 * x + 2))
    assert catalan(x).rewrite(hyper) == hyper((-x + 1, -x), (2, ), 1)

    assert diff(catalan(x), x) == (polygamma(0, x + Rational(1, 2)) -
                                   polygamma(0, x + 2) + log(4)) * catalan(x)

    c = catalan(0.5).evalf()
    assert str(c) == '0.848826363156775'
コード例 #9
0
ファイル: test_comb_numbers.py プロジェクト: msgoff/sympy
def test_catalan():
    n = Symbol("n", integer=True)
    m = Symbol("m", integer=True, positive=True)
    k = Symbol("k", integer=True, nonnegative=True)
    p = Symbol("p", nonnegative=True)

    catalans = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786]
    for i, c in enumerate(catalans):
        assert catalan(i) == c
        assert catalan(n).rewrite(factorial).subs(n, i) == c
        assert catalan(n).rewrite(Product).subs(n, i).doit() == c

    assert unchanged(catalan, x)
    assert catalan(2 *
                   x).rewrite(binomial) == binomial(4 * x, 2 * x) / (2 * x + 1)
    assert catalan(S.Half).rewrite(gamma) == 8 / (3 * pi)
    assert catalan(S.Half).rewrite(factorial).rewrite(gamma) == 8 / (3 * pi)
    assert catalan(3 * x).rewrite(gamma) == 4**(
        3 * x) * gamma(3 * x + S.Half) / (sqrt(pi) * gamma(3 * x + 2))
    assert catalan(x).rewrite(hyper) == hyper((-x + 1, -x), (2, ), 1)

    assert catalan(n).rewrite(factorial) == factorial(
        2 * n) / (factorial(n + 1) * factorial(n))
    assert isinstance(catalan(n).rewrite(Product), catalan)
    assert isinstance(catalan(m).rewrite(Product), Product)

    assert diff(catalan(x), x) == (polygamma(0, x + S.Half) -
                                   polygamma(0, x + 2) + log(4)) * catalan(x)

    assert catalan(x).evalf() == catalan(x)
    c = catalan(S.Half).evalf()
    assert str(c) == "0.848826363156775"
    c = catalan(I).evalf(3)
    assert str((re(c), im(c))) == "(0.398, -0.0209)"

    # Assumptions
    assert catalan(p).is_positive is True
    assert catalan(k).is_integer is True
    assert catalan(m + 3).is_composite is True
コード例 #10
0
ファイル: test_function.py プロジェクト: msgoff/sympy
def test_call():
    a, b, x = symbols("a, b, x", cls=Dummy)
    f = Hyper_Function([2, a], [b])
    assert f(x) == hyper([2, a], [b], x)
コード例 #11
0
def test_call():
    a, b, x = symbols('a, b, x', cls=Dummy)
    f = Hyper_Function([2, a], [b])
    assert f(x) == hyper([2, a], [b], x)