コード例 #1
0
ファイル: test_hyperexpand.py プロジェクト: ness01/sympy
def test_partial_simp():
    # First test that hypergeometric function formulae work.
    a, b, c, d, e = map(lambda _: randcplx(), range(5))
    for idxp in [IndexPair([a, b, c], [d, e]), IndexPair([], [a, b, c, d, e])]:
        f = build_hypergeometric_formula(idxp)
        z = f.z
        assert f.closed_form == hyper(idxp.ap, idxp.bq, z)
        deriv1 = f.B.diff(z) * z
        deriv2 = f.M * f.B
        for func1, func2 in zip(deriv1, deriv2):
            assert tn(func1, func2, z)

    # Now test that formulae are partially simplified.
    from sympy.abc import a, b, z
    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)
コード例 #2
0
ファイル: test_hyperexpand.py プロジェクト: vperic/sympy
def test_plan_derivatives():
    a1, a2, a3 = 1, 2, S('1/2')
    b1, b2 = 3, S('5/2')
    h = hyper((a1, a2, a3), (b1, b2), z)
    h2 = hyper((a1 + 1, a2 + 1, a3 + 2), (b1 + 1, b2 + 1), z)
    ops = devise_plan(IndexPair((a1 + 1, a2 + 1, a3 + 2), (b1 + 1, b2 + 1)),
                      IndexPair((a1, a2, a3), (b1, b2)), z)
    f = Formula((a1, a2, a3), (b1, b2), z, h, [])
    deriv = make_derivative_operator(f.M, z)
    assert tn((apply_operators(f.C, ops, deriv)*f.B)[0], h2, z)

    h2 = hyper((a1, a2 - 1, a3 - 2), (b1 - 1, b2 - 1), z)
    ops = devise_plan(IndexPair((a1, a2 - 1, a3 - 2), (b1 - 1, b2 - 1)),
                      IndexPair((a1, a2, a3), (b1, b2)), z)
    assert tn((apply_operators(f.C, ops, deriv)*f.B)[0], h2, z)
コード例 #3
0
ファイル: test_hyperexpand.py プロジェクト: ness01/sympy
def test_plan():
    assert devise_plan(IndexPair([0], ()), IndexPair([0], ()), z) == []
    raises(ValueError, 'devise_plan(IndexPair([1], ()), IndexPair((), ()), z)')
    raises(ValueError,
           'devise_plan(IndexPair([2], [1]), IndexPair([2], [2]), z)')
    raises(KeyError,
           'devise_plan(IndexPair([2], []), IndexPair([S("1/2")], []), z)')

    # We cannot use pi/(10000 + n) because polys is insanely slow.
    a1, a2, b1 = map(lambda n: randcplx(n), range(3))
    b1 += 2 * I
    h = hyper([a1, a2], [b1], z)

    h2 = hyper((a1 + 1, a2), [b1], z)
    assert tn(
        apply_operators(
            h,
            devise_plan(IndexPair((a1 + 1, a2), [b1]), IndexPair(
                (a1, a2), [b1]), z), op), h2, z)

    h2 = hyper((a1 + 1, a2 - 1), [b1], z)
    assert tn(
        apply_operators(
            h,
            devise_plan(IndexPair((a1 + 1, a2 - 1), [b1]),
                        IndexPair((a1, a2), [b1]), z), op), h2, z)
コード例 #4
0
ファイル: test_hyperexpand.py プロジェクト: vperic/sympy
def test_reduction_operators():
    a1, a2, b1 = map(lambda n: randcplx(n), range(3))
    h = hyper([a1], [b1], z)

    assert ReduceOrder(2, 0) is None
    assert ReduceOrder(2, -1) is None
    assert ReduceOrder(1, S('1/2')) is None

    h2 = hyper((a1, a2), (b1, a2), z)
    assert tn(ReduceOrder(a2, a2).apply(h, op), h2, z)

    h2 = hyper((a1, a2 + 1), (b1, a2), z)
    assert tn(ReduceOrder(a2 + 1, a2).apply(h, op), h2, z)

    h2 = hyper((a2 + 4, a1), (b1, a2), z)
    assert tn(ReduceOrder(a2 + 4, a2).apply(h, op), h2, z)

    # test several step order reduction
    ap = (a2 + 4, a1, b1 + 1)
    bq = (a2, b1, b1)
    nip, ops = reduce_order(IndexPair(ap, bq))
    assert nip.ap == (a1,)
    assert nip.bq == (b1,)
    assert tn(apply_operators(h, ops, op), hyper(ap, bq, z), z)