Esempio n. 1
0
def test_elliptic_f():
    assert elliptic_f(z, 0) == z
    assert elliptic_f(0, m) == 0
    assert elliptic_f(pi * i / 2, m) == i * elliptic_k(m)
    assert elliptic_f(z, oo) == 0
    assert elliptic_f(z, -oo) == 0

    assert elliptic_f(-z, m) == -elliptic_f(z, m)

    assert elliptic_f(z, m).diff(z) == 1 / sqrt(1 - m * sin(z)**2)
    assert elliptic_f(z, m).diff(m) == elliptic_e(z, m)/(2*m*(1 - m)) - elliptic_f(z, m)/(2*m) - \
        sin(2*z)/(4*(1 - m)*sqrt(1 - m*sin(z)**2))
    r = randcplx()
    assert td(elliptic_f(z, r), z)
    assert td(elliptic_f(r, m), m)
    pytest.raises(ArgumentIndexError, lambda: elliptic_f(z, m).fdiff(3))

    mi = Symbol('m', extended_real=False)
    assert elliptic_f(z, mi).conjugate() == elliptic_f(z.conjugate(),
                                                       mi.conjugate())
    mr = Symbol('m', extended_real=True, negative=True)
    assert elliptic_f(z, mr).conjugate() == elliptic_f(z.conjugate(), mr)
    assert elliptic_f(z, m).conjugate() == conjugate(elliptic_f(z, m),
                                                     evaluate=False)

    assert elliptic_f(z, m).series(z) == \
        z + z**5*(3*m**2/40 - m/30) + m*z**3/6 + O(z**6)
Esempio n. 2
0
def test_elliptic_e():
    assert elliptic_e(z, 0) == z
    assert elliptic_e(0, m) == 0
    assert elliptic_e(i * pi / 2, m) == i * elliptic_e(m)
    assert elliptic_e(z, oo) == zoo
    assert elliptic_e(z, -oo) == zoo
    assert elliptic_e(0) == pi / 2
    assert elliptic_e(1) == 1
    assert elliptic_e(oo) == I * oo
    assert elliptic_e(-oo) == oo
    assert elliptic_e(zoo) == zoo

    assert elliptic_e(-z, m) == -elliptic_e(z, m)

    assert elliptic_e(z, m).diff(z) == sqrt(1 - m * sin(z)**2)
    assert elliptic_e(
        z, m).diff(m) == (elliptic_e(z, m) - elliptic_f(z, m)) / (2 * m)
    assert elliptic_e(z).diff(z) == (elliptic_e(z) - elliptic_k(z)) / (2 * z)
    r = randcplx()
    assert td(elliptic_e(r, m), m)
    assert td(elliptic_e(z, r), z)
    assert td(elliptic_e(z), z)
    pytest.raises(ArgumentIndexError, lambda: elliptic_e(z, m).fdiff(3))
    pytest.raises(ArgumentIndexError, lambda: elliptic_e(z).fdiff(2))

    mi = Symbol('m', extended_real=False)
    assert elliptic_e(z, mi).conjugate() == elliptic_e(z.conjugate(),
                                                       mi.conjugate())
    assert elliptic_e(mi).conjugate() == elliptic_e(mi.conjugate())
    mr = Symbol('m', extended_real=True, negative=True)
    assert elliptic_e(z, mr).conjugate() == elliptic_e(z.conjugate(), mr)
    assert elliptic_e(mr).conjugate() == elliptic_e(mr)
    assert elliptic_e(z, m).conjugate() == conjugate(elliptic_e(z, m))
    assert elliptic_e(z).conjugate() == conjugate(elliptic_e(z))

    assert elliptic_e(z).rewrite(hyper) == (pi / 2) * hyper(
        (Rational(-1, 2), Rational(1, 2)), (1, ), z)
    assert elliptic_e(z, m).rewrite(hyper) == elliptic_e(z, m)
    assert tn(elliptic_e(z), (pi / 2) * hyper(
        (Rational(-1, 2), Rational(1, 2)), (1, ), z))
    assert elliptic_e(z).rewrite(meijerg) == \
        -meijerg(((Rational(1, 2), Rational(3, 2)), []), ((0,), (0,)), -z)/4
    assert elliptic_e(z, m).rewrite(meijerg) == elliptic_e(z, m)
    assert tn(
        elliptic_e(z), -meijerg(((Rational(1, 2), Rational(3, 2)), []),
                                ((0, ), (0, )), -z) / 4)

    assert elliptic_e(z, m).series(z) == \
        z + z**5*(-m**2/40 + m/30) - m*z**3/6 + O(z**6)
    assert elliptic_e(z).series(z) == pi/2 - pi*z/8 - 3*pi*z**2/128 - \
        5*pi*z**3/512 - 175*pi*z**4/32768 - 441*pi*z**5/131072 + O(z**6)
Esempio n. 3
0
def test_derivatives():
    assert zeta(x, a).diff(x) == Derivative(zeta(x, a), x)
    assert zeta(x, a).diff(a) == -x*zeta(x + 1, a)
    assert lerchphi(
        z, s, a).diff(z) == (lerchphi(z, s - 1, a) - a*lerchphi(z, s, a))/z
    assert lerchphi(z, s, a).diff(a) == -s*lerchphi(z, s + 1, a)
    assert polylog(s, z).diff(z) == polylog(s - 1, z)/z

    b = randcplx()
    c = randcplx()
    assert td(zeta(b, x), x)
    assert td(polylog(b, z), z)
    assert td(lerchphi(c, b, x), x)
    assert td(lerchphi(x, b, c), x)
Esempio n. 4
0
def test_P():
    assert P(0, z, m) == F(z, m)
    assert P(1, z, m) == F(z, m) + \
        (sqrt(1 - m*sin(z)**2)*tan(z) - E(z, m))/(1 - m)
    assert P(n, i*pi/2, m) == i*P(n, m)
    assert P(n, z, 0) == atanh(sqrt(n - 1)*tan(z))/sqrt(n - 1)
    assert P(n, z, n) == F(z, n) - P(1, z, n) + tan(z)/sqrt(1 - n*sin(z)**2)
    assert P(oo, z, m) == 0
    assert P(-oo, z, m) == 0
    assert P(n, z, oo) == 0
    assert P(n, z, -oo) == 0
    assert P(0, m) == K(m)
    assert P(1, m) == zoo
    assert P(n, 0) == pi/(2*sqrt(1 - n))
    assert P(2, 1) == -oo
    assert P(-1, 1) == oo
    assert P(n, n) == E(n)/(1 - n)
    assert P(oo, m) == 0
    assert P(n, oo) == 0

    assert P(n, -z, m) == -P(n, z, m)

    ni, mi = Symbol('n', extended_real=False), Symbol('m', extended_real=False)
    assert P(ni, z, mi).conjugate() == \
        P(ni.conjugate(), z.conjugate(), mi.conjugate())
    nr, mr = Symbol('n', extended_real=True, negative=True), \
        Symbol('m', extended_real=True, negative=True)
    assert P(nr, z, mr).conjugate() == P(nr, z.conjugate(), mr)
    assert P(n, m).conjugate() == P(n.conjugate(), m.conjugate())

    assert P(n, z, m).diff(n) == (E(z, m) + (m - n)*F(z, m)/n +
        (n**2 - m)*P(n, z, m)/n - n*sqrt(1 -
            m*sin(z)**2)*sin(2*z)/(2*(1 - n*sin(z)**2)))/(2*(m - n)*(n - 1))
    assert P(n, z, m).diff(z) == 1/(sqrt(1 - m*sin(z)**2)*(1 - n*sin(z)**2))
    assert P(n, z, m).diff(m) == (E(z, m)/(m - 1) + P(n, z, m) -
        m*sin(2*z)/(2*(m - 1)*sqrt(1 - m*sin(z)**2)))/(2*(n - m))
    assert P(n, m).diff(n) == (E(m) + (m - n)*K(m)/n +
        (n**2 - m)*P(n, m)/n)/(2*(m - n)*(n - 1))
    assert P(n, m).diff(m) == (E(m)/(m - 1) + P(n, m))/(2*(n - m))
    rx, ry = randcplx(), randcplx()
    assert td(P(n, rx, ry), n)
    assert td(P(rx, z, ry), z)
    assert td(P(rx, ry, m), m)
    pytest.raises(ArgumentIndexError, lambda: P(n, z, m).fdiff(4))
    pytest.raises(ArgumentIndexError, lambda: P(n, m).fdiff(3))

    assert P(n, z, m).series(z) == z + z**3*(m/6 + n/3) + \
        z**5*(3*m**2/40 + m*n/10 - m/30 + n**2/5 - n/15) + O(z**6)
Esempio n. 5
0
def test_hyper():
    pytest.raises(TypeError, lambda: hyper(1, 2, z))

    assert hyper((1, 2), (1, ), z) == hyper(Tuple(1, 2), Tuple(1), z)

    h = hyper((1, 2), (3, 4, 5), z)
    assert h.ap == Tuple(1, 2)
    assert h.bq == Tuple(3, 4, 5)
    assert h.argument == z
    assert h.is_commutative is True

    # just a few checks to make sure that all arguments go where they should
    assert tn(hyper(Tuple(), Tuple(), z), exp(z), z)
    assert tn(z * hyper((1, 1), Tuple(2), -z), log(1 + z), z)

    # differentiation
    h = hyper((randcplx(), randcplx(), randcplx()), (randcplx(), randcplx()),
              z)
    assert td(h, z)

    a1, a2, b1, b2, b3 = symbols('a1:3, b1:4')
    assert hyper((a1, a2), (b1, b2, b3), z).diff(z) == \
        a1*a2/(b1*b2*b3) * hyper((a1 + 1, a2 + 1), (b1 + 1, b2 + 1, b3 + 1), z)

    # differentiation wrt parameters is not supported
    assert hyper([z], [], z).diff(z) == Derivative(hyper([z], [], z), z)

    # hyper is unbranched wrt parameters
    assert hyper([polar_lift(z)], [polar_lift(k)], polar_lift(x)) == \
        hyper([z], [k], polar_lift(x))

    assert hyper((1, 2, 3), [3, 4], 1).is_number
    assert not hyper((1, 2, 3), [3, x], 1).is_number
Esempio n. 6
0
def test_hyper():
    pytest.raises(TypeError, lambda: hyper(1, 2, z))

    assert hyper((1, 2), (1,), z) == hyper(Tuple(1, 2), Tuple(1), z)

    h = hyper((1, 2), (3, 4, 5), z)
    assert h.ap == Tuple(1, 2)
    assert h.bq == Tuple(3, 4, 5)
    assert h.argument == z
    assert h.is_commutative is True

    # just a few checks to make sure that all arguments go where they should
    assert tn(hyper(Tuple(), Tuple(), z), exp(z), z)
    assert tn(z*hyper((1, 1), Tuple(2), -z), log(1 + z), z)

    # differentiation
    h = hyper(
        (randcplx(), randcplx(), randcplx()), (randcplx(), randcplx()), z)
    assert td(h, z)

    a1, a2, b1, b2, b3 = symbols('a1:3, b1:4')
    assert hyper((a1, a2), (b1, b2, b3), z).diff(z) == \
        a1*a2/(b1*b2*b3) * hyper((a1 + 1, a2 + 1), (b1 + 1, b2 + 1, b3 + 1), z)

    # differentiation wrt parameters is not supported
    assert hyper([z], [], z).diff(z) == Derivative(hyper([z], [], z), z)

    # hyper is unbranched wrt parameters
    assert hyper([polar_lift(z)], [polar_lift(k)], polar_lift(x)) == \
        hyper([z], [k], polar_lift(x))

    assert hyper((1, 2, 3), [3, 4], 1).is_number
    assert not hyper((1, 2, 3), [3, x], 1).is_number
Esempio n. 7
0
def test_K():
    assert K(0) == pi/2
    assert K(Rational(1, 2)) == 8*pi**Rational(3, 2)/gamma(-Rational(1, 4))**2
    assert K(1) == zoo
    assert K(-1) == gamma(Rational(1, 4))**2/(4*sqrt(2*pi))
    assert K(oo) == 0
    assert K(-oo) == 0
    assert K(I*oo) == 0
    assert K(-I*oo) == 0
    assert K(zoo) == 0

    assert K(z).diff(z) == (E(z) - (1 - z)*K(z))/(2*z*(1 - z))
    assert td(K(z), z)
    pytest.raises(ArgumentIndexError, lambda: K(z).fdiff(2))

    zi = Symbol('z', extended_real=False)
    assert K(zi).conjugate() == K(zi.conjugate())
    zr = Symbol('z', extended_real=True, negative=True)
    assert K(zr).conjugate() == K(zr)

    assert K(z).rewrite(hyper) == \
        (pi/2)*hyper((S.Half, S.Half), (S.One,), z)
    assert tn(K(z), (pi/2)*hyper((S.Half, S.Half), (S.One,), z))
    assert K(z).rewrite(meijerg) == \
        meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z)/2
    assert tn(K(z), meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z)/2)

    assert K(z).series(z) == pi/2 + pi*z/8 + 9*pi*z**2/128 + \
        25*pi*z**3/512 + 1225*pi*z**4/32768 + 3969*pi*z**5/131072 + O(z**6)
Esempio n. 8
0
def test_derivatives():
    assert zeta(x, a).diff(x) == Derivative(zeta(x, a), x)
    assert zeta(x, a).diff(a) == -x*zeta(x + 1, a)
    assert zeta(z).diff(z) == Derivative(zeta(z), z)
    assert lerchphi(
        z, s, a).diff(z) == (lerchphi(z, s - 1, a) - a*lerchphi(z, s, a))/z
    pytest.raises(ArgumentIndexError, lambda: lerchphi(z, s, a).fdiff(4))
    assert lerchphi(z, s, a).diff(a) == -s*lerchphi(z, s + 1, a)
    assert polylog(s, z).diff(z) == polylog(s - 1, z)/z
    pytest.raises(ArgumentIndexError, lambda: polylog(s, z).fdiff(3))

    b = randcplx()
    c = randcplx()
    assert td(zeta(b, x), x)
    assert td(polylog(b, z), z)
    assert td(lerchphi(c, b, x), x)
    assert td(lerchphi(x, b, c), x)
Esempio n. 9
0
def test_derivatives():
    assert zeta(x, a).diff(x) == Derivative(zeta(x, a), x)
    assert zeta(x, a).diff(a) == -x * zeta(x + 1, a)
    assert zeta(z).diff(z) == Derivative(zeta(z), z)
    assert lerchphi(
        z, s, a).diff(z) == (lerchphi(z, s - 1, a) - a * lerchphi(z, s, a)) / z
    pytest.raises(ArgumentIndexError, lambda: lerchphi(z, s, a).fdiff(4))
    assert lerchphi(z, s, a).diff(a) == -s * lerchphi(z, s + 1, a)
    assert polylog(s, z).diff(z) == polylog(s - 1, z) / z
    pytest.raises(ArgumentIndexError, lambda: polylog(s, z).fdiff(3))

    b = randcplx()
    c = randcplx()
    assert td(zeta(b, x), x)
    assert td(polylog(b, z), z)
    assert td(lerchphi(c, b, x), x)
    assert td(lerchphi(x, b, c), x)
Esempio n. 10
0
def test_meijerg_derivative():
    assert meijerg([], [1, 1], [0, 0, x], [], z).diff(x) == \
        log(z)*meijerg([], [1, 1], [0, 0, x], [], z) \
        + 2*meijerg([], [1, 1, 1], [0, 0, x, 0], [], z)

    y = randcplx()
    a = 5  # mpmath chokes with non-real numbers, and Mod1 with floats
    assert td(meijerg([x], [], [], [], y), x)
    assert td(meijerg([x**2], [], [], [], y), x)
    assert td(meijerg([], [x], [], [], y), x)
    assert td(meijerg([], [], [x], [], y), x)
    assert td(meijerg([], [], [], [x], y), x)
    assert td(meijerg([x], [a], [a + 1], [], y), x)
    assert td(meijerg([x], [a + 1], [a], [], y), x)
    assert td(meijerg([x, a], [], [], [a + 1], y), x)
    assert td(meijerg([x, a + 1], [], [], [a], y), x)
    b = Rational(3, 2)
    assert td(meijerg([a + 2], [b], [b - 3, x], [a], y), x)
Esempio n. 11
0
def test_E():
    assert E(z, 0) == z
    assert E(0, m) == 0
    assert E(i*pi/2, m) == i*E(m)
    assert E(z, oo) == zoo
    assert E(z, -oo) == zoo
    assert E(0) == pi/2
    assert E(1) == 1
    assert E(oo) == I*oo
    assert E(-oo) == oo
    assert E(zoo) == zoo

    assert E(-z, m) == -E(z, m)

    assert E(z, m).diff(z) == sqrt(1 - m*sin(z)**2)
    assert E(z, m).diff(m) == (E(z, m) - F(z, m))/(2*m)
    assert E(z).diff(z) == (E(z) - K(z))/(2*z)
    r = randcplx()
    assert td(E(r, m), m)
    assert td(E(z, r), z)
    assert td(E(z), z)
    pytest.raises(ArgumentIndexError, lambda: E(z, m).fdiff(3))
    pytest.raises(ArgumentIndexError, lambda: E(z).fdiff(2))

    mi = Symbol('m', extended_real=False)
    assert E(z, mi).conjugate() == E(z.conjugate(), mi.conjugate())
    assert E(mi).conjugate() == E(mi.conjugate())
    mr = Symbol('m', extended_real=True, negative=True)
    assert E(z, mr).conjugate() == E(z.conjugate(), mr)
    assert E(mr).conjugate() == E(mr)

    assert E(z).rewrite(hyper) == (pi/2)*hyper((-S.Half, S.Half), (S.One,), z)
    assert E(z, m).rewrite(hyper) == E(z, m)
    assert tn(E(z), (pi/2)*hyper((-S.Half, S.Half), (S.One,), z))
    assert E(z).rewrite(meijerg) == \
        -meijerg(((S.Half, Rational(3, 2)), []), ((S.Zero,), (S.Zero,)), -z)/4
    assert E(z, m).rewrite(meijerg) == E(z, m)
    assert tn(E(z), -meijerg(((S.Half, Rational(3, 2)), []), ((S.Zero,), (S.Zero,)), -z)/4)

    assert E(z, m).series(z) == \
        z + z**5*(-m**2/40 + m/30) - m*z**3/6 + O(z**6)
    assert E(z).series(z) == pi/2 - pi*z/8 - 3*pi*z**2/128 - \
        5*pi*z**3/512 - 175*pi*z**4/32768 - 441*pi*z**5/131072 + O(z**6)
Esempio n. 12
0
def test_lowergamma():
    assert lowergamma(x, y).diff(y) == y**(x - 1)*exp(-y)
    assert td(lowergamma(randcplx(), y), y)
    assert td(lowergamma(x, randcplx()), x)
    assert lowergamma(x, y).diff(x) == \
        gamma(x)*polygamma(0, x) - uppergamma(x, y)*log(y) \
        - meijerg([], [1, 1], [0, 0, x], [], y)
    pytest.raises(ArgumentIndexError, lambda: lowergamma(x, y).fdiff(3))

    assert lowergamma(Rational(1, 2), x) == sqrt(pi)*erf(sqrt(x))
    assert not lowergamma(Rational(1, 2) - 3, x).has(lowergamma)
    assert not lowergamma(Rational(1, 2) + 3, x).has(lowergamma)
    assert lowergamma(Rational(1, 2), x, evaluate=False).has(lowergamma)
    assert tn(lowergamma(Rational(1, 2) + 3, x, evaluate=False),
              lowergamma(Rational(1, 2) + 3, x), x)
    assert tn(lowergamma(Rational(1, 2) - 3, x, evaluate=False),
              lowergamma(Rational(1, 2) - 3, x), x)
    assert lowergamma(0, 1) == zoo

    assert tn_branch(-3, lowergamma)
    assert tn_branch(-4, lowergamma)
    assert tn_branch(Rational(1, 3), lowergamma)
    assert tn_branch(pi, lowergamma)
    assert lowergamma(3, exp_polar(4*pi*I)*x) == lowergamma(3, x)
    assert lowergamma(y, exp_polar(5*pi*I)*x) == \
        exp(4*I*pi*y)*lowergamma(y, x*exp_polar(pi*I))
    assert lowergamma(-2, exp_polar(5*pi*I)*x) == \
        lowergamma(-2, x*exp_polar(I*pi)) + 2*pi*I

    assert conjugate(lowergamma(x, y)) == lowergamma(conjugate(x), conjugate(y))
    assert conjugate(lowergamma(x, 0)) == conjugate(lowergamma(x, 0))
    assert conjugate(lowergamma(x, -oo)) == conjugate(lowergamma(x, -oo))

    assert lowergamma(
        x, y).rewrite(expint) == -y**x*expint(-x + 1, y) + gamma(x)
    k = Symbol('k', integer=True)
    assert lowergamma(
        k, y).rewrite(expint) == -y**k*expint(-k + 1, y) + gamma(k)
    k = Symbol('k', integer=True, positive=False)
    assert lowergamma(k, y).rewrite(expint) == lowergamma(k, y)
    assert lowergamma(x, y).rewrite(uppergamma) == gamma(x) - uppergamma(x, y)

    assert (x*lowergamma(x, 1)/gamma(x + 1)).limit(x, 0) == 1
Esempio n. 13
0
def test_lowergamma():
    from diofant import meijerg, exp_polar, I, expint
    assert lowergamma(x, y).diff(y) == y**(x - 1) * exp(-y)
    assert td(lowergamma(randcplx(), y), y)
    assert td(lowergamma(x, randcplx()), x)
    assert lowergamma(x, y).diff(x) == \
        gamma(x)*polygamma(0, x) - uppergamma(x, y)*log(y) \
        - meijerg([], [1, 1], [0, 0, x], [], y)

    assert lowergamma(S.Half, x) == sqrt(pi) * erf(sqrt(x))
    assert not lowergamma(S.Half - 3, x).has(lowergamma)
    assert not lowergamma(S.Half + 3, x).has(lowergamma)
    assert lowergamma(S.Half, x, evaluate=False).has(lowergamma)
    assert tn(lowergamma(S.Half + 3, x, evaluate=False),
              lowergamma(S.Half + 3, x), x)
    assert tn(lowergamma(S.Half - 3, x, evaluate=False),
              lowergamma(S.Half - 3, x), x)

    assert tn_branch(-3, lowergamma)
    assert tn_branch(-4, lowergamma)
    assert tn_branch(Rational(1, 3), lowergamma)
    assert tn_branch(pi, lowergamma)
    assert lowergamma(3, exp_polar(4 * pi * I) * x) == lowergamma(3, x)
    assert lowergamma(y, exp_polar(5*pi*I)*x) == \
        exp(4*I*pi*y)*lowergamma(y, x*exp_polar(pi*I))
    assert lowergamma(-2, exp_polar(5*pi*I)*x) == \
        lowergamma(-2, x*exp_polar(I*pi)) + 2*pi*I

    assert conjugate(lowergamma(x, y)) == lowergamma(conjugate(x),
                                                     conjugate(y))
    assert conjugate(lowergamma(x, 0)) == conjugate(lowergamma(x, 0))
    assert conjugate(lowergamma(x, -oo)) == conjugate(lowergamma(x, -oo))

    assert lowergamma(
        x, y).rewrite(expint) == -y**x * expint(-x + 1, y) + gamma(x)
    k = Symbol('k', integer=True)
    assert lowergamma(
        k, y).rewrite(expint) == -y**k * expint(-k + 1, y) + gamma(k)
    k = Symbol('k', integer=True, positive=False)
    assert lowergamma(k, y).rewrite(expint) == lowergamma(k, y)
    assert lowergamma(x, y).rewrite(uppergamma) == gamma(x) - uppergamma(x, y)
Esempio n. 14
0
def test_uppergamma():
    from diofant import meijerg, exp_polar, I, expint
    assert uppergamma(4, 0) == 6
    assert uppergamma(x, oo) == 0
    assert uppergamma(x, y).diff(y) == -y**(x - 1) * exp(-y)
    assert td(uppergamma(randcplx(), y), y)
    assert uppergamma(x, y).diff(x) == \
        uppergamma(x, y)*log(y) + meijerg([], [1, 1], [0, 0, x], [], y)
    assert td(uppergamma(x, randcplx()), x)
    pytest.raises(ArgumentIndexError, lambda: uppergamma(x, y).fdiff(3))

    assert uppergamma(S.Half, x) == sqrt(pi) * (1 - erf(sqrt(x)))
    assert not uppergamma(S.Half - 3, x).has(uppergamma)
    assert not uppergamma(S.Half + 3, x).has(uppergamma)
    assert uppergamma(S.Half, x, evaluate=False).has(uppergamma)
    assert tn(uppergamma(S.Half + 3, x, evaluate=False),
              uppergamma(S.Half + 3, x), x)
    assert tn(uppergamma(S.Half - 3, x, evaluate=False),
              uppergamma(S.Half - 3, x), x)

    assert tn_branch(-3, uppergamma)
    assert tn_branch(-4, uppergamma)
    assert tn_branch(Rational(1, 3), uppergamma)
    assert tn_branch(pi, uppergamma)
    assert uppergamma(3, exp_polar(4 * pi * I) * x) == uppergamma(3, x)
    assert uppergamma(y, exp_polar(5*pi*I)*x) == \
        exp(4*I*pi*y)*uppergamma(y, x*exp_polar(pi*I)) + \
        gamma(y)*(1 - exp(4*pi*I*y))
    assert uppergamma(-2, exp_polar(5*pi*I)*x) == \
        uppergamma(-2, x*exp_polar(I*pi)) - 2*pi*I

    assert uppergamma(-2, x) == expint(3, x) / x**2

    assert conjugate(uppergamma(x, y)) == uppergamma(conjugate(x),
                                                     conjugate(y))
    assert conjugate(uppergamma(x, 0)) == gamma(conjugate(x))
    assert conjugate(uppergamma(x, -oo)) == conjugate(uppergamma(x, -oo))

    assert uppergamma(x, y).rewrite(expint) == y**x * expint(-x + 1, y)
    assert uppergamma(x, y).rewrite(lowergamma) == gamma(x) - lowergamma(x, y)
Esempio n. 15
0
def test_F():
    assert F(z, 0) == z
    assert F(0, m) == 0
    assert F(pi*i/2, m) == i*K(m)
    assert F(z, oo) == 0
    assert F(z, -oo) == 0

    assert F(-z, m) == -F(z, m)

    assert F(z, m).diff(z) == 1/sqrt(1 - m*sin(z)**2)
    assert F(z, m).diff(m) == E(z, m)/(2*m*(1 - m)) - F(z, m)/(2*m) - \
        sin(2*z)/(4*(1 - m)*sqrt(1 - m*sin(z)**2))
    r = randcplx()
    assert td(F(z, r), z)
    assert td(F(r, m), m)

    mi = Symbol('m', extended_real=False)
    assert F(z, mi).conjugate() == F(z.conjugate(), mi.conjugate())
    mr = Symbol('m', extended_real=True, negative=True)
    assert F(z, mr).conjugate() == F(z.conjugate(), mr)

    assert F(z, m).series(z) == \
        z + z**5*(3*m**2/40 - m/30) + m*z**3/6 + O(z**6)
Esempio n. 16
0
def test_elliptic_k():
    assert elliptic_k(0) == pi / 2
    assert elliptic_k(Rational(
        1, 2)) == 8 * pi**Rational(3, 2) / gamma(-Rational(1, 4))**2
    assert elliptic_k(1) == zoo
    assert elliptic_k(-1) == gamma(Rational(1, 4))**2 / (4 * sqrt(2 * pi))
    assert elliptic_k(oo) == 0
    assert elliptic_k(-oo) == 0
    assert elliptic_k(I * oo) == 0
    assert elliptic_k(-I * oo) == 0
    assert elliptic_k(zoo) == 0

    assert elliptic_k(z).diff(z) == (elliptic_e(z) -
                                     (1 - z) * elliptic_k(z)) / (2 * z *
                                                                 (1 - z))
    assert td(elliptic_k(z), z)
    pytest.raises(ArgumentIndexError, lambda: elliptic_k(z).fdiff(2))

    zi = Symbol('z', extended_real=False)
    assert elliptic_k(zi).conjugate() == elliptic_k(zi.conjugate())
    zr = Symbol('z', extended_real=True, negative=True)
    assert elliptic_k(zr).conjugate() == elliptic_k(zr)
    assert elliptic_k(z).conjugate() == conjugate(elliptic_k(z),
                                                  evaluate=False)

    assert elliptic_k(z).rewrite(hyper) == \
        (pi/2)*hyper((Rational(1, 2), Rational(1, 2)), (1,), z)
    assert tn(elliptic_k(z), (pi / 2) * hyper((Rational(1, 2), Rational(1, 2)),
                                              (1, ), z))
    assert elliptic_k(z).rewrite(meijerg) == \
        meijerg(((Rational(1, 2), Rational(1, 2)), []), ((0,), (0,)), -z)/2
    assert tn(
        elliptic_k(z),
        meijerg(((Rational(1, 2), Rational(1, 2)), []),
                ((0, ), (0, )), -z) / 2)

    assert elliptic_k(z).series(z) == pi/2 + pi*z/8 + 9*pi*z**2/128 + \
        25*pi*z**3/512 + 1225*pi*z**4/32768 + 3969*pi*z**5/131072 + O(z**6)
Esempio n. 17
0
def test_meijer():
    pytest.raises(TypeError, lambda: meijerg(1, z))
    pytest.raises(TypeError, lambda: meijerg(((1,), (2,)), (3,), (4,), z))
    pytest.raises(TypeError, lambda: meijerg((1, 2, 3), (4, 5), z))

    assert meijerg(((1, 2), (3,)), ((4,), (5,)), z) == \
        meijerg(Tuple(1, 2), Tuple(3), Tuple(4), Tuple(5), z)

    g = meijerg((1, 2), (3, 4, 5), (6, 7, 8, 9), (10, 11, 12, 13, 14), z)
    assert g.an == Tuple(1, 2)
    assert g.ap == Tuple(1, 2, 3, 4, 5)
    assert g.aother == Tuple(3, 4, 5)
    assert g.bm == Tuple(6, 7, 8, 9)
    assert g.bq == Tuple(6, 7, 8, 9, 10, 11, 12, 13, 14)
    assert g.bother == Tuple(10, 11, 12, 13, 14)
    assert g.argument == z
    assert g.nu == 75
    assert g.delta == -1
    assert g.is_commutative is True

    assert meijerg([1, 2], [3], [4], [5], z).delta == Rational(1, 2)

    # just a few checks to make sure that all arguments go where they should
    assert tn(meijerg(Tuple(), Tuple(), Tuple(0), Tuple(), -z), exp(z), z)
    assert tn(sqrt(pi)*meijerg(Tuple(), Tuple(),
                               Tuple(0), Tuple(Rational(1, 2)), z**2/4), cos(z), z)
    assert tn(meijerg(Tuple(1, 1), Tuple(), Tuple(1), Tuple(0), z),
              log(1 + z), z)

    # test exceptions
    pytest.raises(ValueError, lambda: meijerg(((3, 1), (2,)),
                                              ((oo,), (2, 0)), x))
    pytest.raises(ValueError, lambda: meijerg(((3, 1), (2,)),
                                              ((1,), (2, 0)), x))

    # differentiation
    g = meijerg((randcplx(),), (randcplx() + 2*I,), Tuple(),
                (randcplx(), randcplx()), z)
    assert td(g, z)

    g = meijerg(Tuple(), (randcplx(),), Tuple(),
                (randcplx(), randcplx()), z)
    assert td(g, z)

    g = meijerg(Tuple(), Tuple(), Tuple(randcplx()),
                Tuple(randcplx(), randcplx()), z)
    assert td(g, z)

    a1, a2, b1, b2, c1, c2, d1, d2 = symbols('a1:3, b1:3, c1:3, d1:3')
    assert meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z).diff(z) == \
        (meijerg((a1 - 1, a2), (b1, b2), (c1, c2), (d1, d2), z)
         + (a1 - 1)*meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z))/z

    assert meijerg([z, z], [], [], [], z).diff(z) == \
        Derivative(meijerg([z, z], [], [], [], z), z)

    # meijerg is unbranched wrt parameters
    assert meijerg([polar_lift(a1)], [polar_lift(a2)], [polar_lift(b1)],
                   [polar_lift(b2)], polar_lift(z)) == meijerg([a1], [a2],
                                                               [b1], [b2],
                                                               polar_lift(z))

    # integrand
    assert meijerg([a], [b], [c], [d], z).integrand(s) == \
        z**s*gamma(c - s)*gamma(-a + s + 1)/(gamma(b - s)*gamma(-d + s + 1))

    assert meijerg([[], []], [[Rational(1, 2)], [0]], 1).is_number
    assert not meijerg([[], []], [[x], [0]], 1).is_number
Esempio n. 18
0
def test_elliptic_pi():
    assert elliptic_pi(0, z, m) == elliptic_f(z, m)
    assert elliptic_pi(1, z, m) == elliptic_f(z, m) + \
        (sqrt(1 - m*sin(z)**2)*tan(z) - elliptic_e(z, m))/(1 - m)
    assert elliptic_pi(n, i * pi / 2, m) == i * elliptic_pi(n, m)
    assert elliptic_pi(n, z, 0) == atanh(sqrt(n - 1) * tan(z)) / sqrt(n - 1)
    assert elliptic_pi(n, z, n) == elliptic_f(z, n) - elliptic_pi(
        1, z, n) + tan(z) / sqrt(1 - n * sin(z)**2)
    assert elliptic_pi(oo, z, m) == 0
    assert elliptic_pi(-oo, z, m) == 0
    assert elliptic_pi(n, z, oo) == 0
    assert elliptic_pi(n, z, -oo) == 0
    assert elliptic_pi(0, m) == elliptic_k(m)
    assert elliptic_pi(1, m) == zoo
    assert elliptic_pi(n, 0) == pi / (2 * sqrt(1 - n))
    assert elliptic_pi(2, 1) == -oo
    assert elliptic_pi(-1, 1) == oo
    assert elliptic_pi(n, n) == elliptic_e(n) / (1 - n)
    assert elliptic_pi(oo, m) == 0
    assert elliptic_pi(n, oo) == 0

    assert elliptic_pi(n, -z, m) == -elliptic_pi(n, z, m)

    ni, mi = Symbol('n', extended_real=False), Symbol('m', extended_real=False)
    assert elliptic_pi(ni, z, mi).conjugate() == \
        elliptic_pi(ni.conjugate(), z.conjugate(), mi.conjugate())
    nr, mr = Symbol('n', extended_real=True, negative=True), \
        Symbol('m', extended_real=True, negative=True)
    assert elliptic_pi(nr, z,
                       mr).conjugate() == elliptic_pi(nr, z.conjugate(), mr)
    assert elliptic_pi(n,
                       m).conjugate() == elliptic_pi(n.conjugate(),
                                                     m.conjugate())
    assert elliptic_pi(n, z, m).conjugate() == conjugate(elliptic_pi(n, z, m))

    assert elliptic_pi(
        n, z,
        m).diff(n) == (elliptic_e(z, m) + (m - n) * elliptic_f(z, m) / n +
                       (n**2 - m) * elliptic_pi(n, z, m) / n -
                       n * sqrt(1 - m * sin(z)**2) * sin(2 * z) /
                       (2 * (1 - n * sin(z)**2))) / (2 * (m - n) * (n - 1))
    assert elliptic_pi(n, z, m).diff(z) == 1 / (sqrt(1 - m * sin(z)**2) *
                                                (1 - n * sin(z)**2))
    assert elliptic_pi(
        n, z,
        m).diff(m) == (elliptic_e(z, m) /
                       (m - 1) + elliptic_pi(n, z, m) - m * sin(2 * z) /
                       (2 * (m - 1) * sqrt(1 - m * sin(z)**2))) / (2 * (n - m))
    assert elliptic_pi(
        n, m).diff(n) == (elliptic_e(m) + (m - n) * elliptic_k(m) / n +
                          (n**2 - m) * elliptic_pi(n, m) / n) / (2 * (m - n) *
                                                                 (n - 1))
    assert elliptic_pi(
        n, m).diff(m) == (elliptic_e(m) /
                          (m - 1) + elliptic_pi(n, m)) / (2 * (n - m))

    # workaround fredrik-johansson/mpmath#571, suggested by Kalevi Suominen
    # in https://github.com/sympy/sympy/issues/20933#issuecomment-779077562
    bounds = {'a': -0.9, 'b': -0.9, 'c': 0.9, 'd': 0.9}
    rx, ry = randcplx(**bounds), randcplx(**bounds)
    assert td(elliptic_pi(n, rx, ry), n, **bounds)
    assert td(elliptic_pi(rx, z, ry), z, **bounds)
    assert td(elliptic_pi(rx, ry, m), m, **bounds)

    pytest.raises(ArgumentIndexError, lambda: elliptic_pi(n, z, m).fdiff(4))
    pytest.raises(ArgumentIndexError, lambda: elliptic_pi(n, m).fdiff(3))

    assert elliptic_pi(n, z, m).series(z) == z + z**3*(m/6 + n/3) + \
        z**5*(3*m**2/40 + m*n/10 - m/30 + n**2/5 - n/15) + O(z**6)
Esempio n. 19
0
def test_bessel_rand():
    for f in [besselj, bessely, besseli, besselk, hankel1, hankel2, jn, yn]:
        assert td(f(randcplx(), z), z)
Esempio n. 20
0
def test_meijer():
    pytest.raises(TypeError, lambda: meijerg(1, z))
    pytest.raises(TypeError, lambda: meijerg(((1, ), (2, )), (3, ), (4, ), z))
    pytest.raises(TypeError, lambda: meijerg((1, 2, 3), (4, 5), z))

    assert meijerg(((1, 2), (3,)), ((4,), (5,)), z) == \
        meijerg(Tuple(1, 2), Tuple(3), Tuple(4), Tuple(5), z)

    g = meijerg((1, 2), (3, 4, 5), (6, 7, 8, 9), (10, 11, 12, 13, 14), z)
    assert g.an == Tuple(1, 2)
    assert g.ap == Tuple(1, 2, 3, 4, 5)
    assert g.aother == Tuple(3, 4, 5)
    assert g.bm == Tuple(6, 7, 8, 9)
    assert g.bq == Tuple(6, 7, 8, 9, 10, 11, 12, 13, 14)
    assert g.bother == Tuple(10, 11, 12, 13, 14)
    assert g.argument == z
    assert g.nu == 75
    assert g.delta == -1
    assert g.is_commutative is True

    assert meijerg([1, 2], [3], [4], [5], z).delta == Rational(1, 2)

    # just a few checks to make sure that all arguments go where they should
    assert tn(meijerg(Tuple(), Tuple(), Tuple(0), Tuple(), -z), exp(z), z)
    assert tn(
        sqrt(pi) *
        meijerg(Tuple(), Tuple(), Tuple(0), Tuple(Rational(1, 2)), z**2 / 4),
        cos(z), z)
    assert tn(meijerg(Tuple(1, 1), Tuple(), Tuple(1), Tuple(0), z), log(1 + z),
              z)

    # test exceptions
    pytest.raises(ValueError, lambda: meijerg(((3, 1), (2, )), ((oo, ),
                                                                (2, 0)), x))
    pytest.raises(ValueError, lambda: meijerg(((3, 1), (2, )), ((1, ),
                                                                (2, 0)), x))

    # differentiation
    g = meijerg((randcplx(), ), (randcplx() + 2 * I, ), Tuple(),
                (randcplx(), randcplx()), z)
    assert td(g, z)

    g = meijerg(Tuple(), (randcplx(), ), Tuple(), (randcplx(), randcplx()), z)
    assert td(g, z)

    g = meijerg(Tuple(), Tuple(), Tuple(randcplx()),
                Tuple(randcplx(), randcplx()), z)
    assert td(g, z)

    a1, a2, b1, b2, c1, c2, d1, d2 = symbols('a1:3, b1:3, c1:3, d1:3')
    assert meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z).diff(z) == \
        (meijerg((a1 - 1, a2), (b1, b2), (c1, c2), (d1, d2), z)
         + (a1 - 1)*meijerg((a1, a2), (b1, b2), (c1, c2), (d1, d2), z))/z

    assert meijerg([z, z], [], [], [], z).diff(z) == \
        Derivative(meijerg([z, z], [], [], [], z), z)

    # meijerg is unbranched wrt parameters
    assert meijerg([polar_lift(a1)],
                   [polar_lift(a2)], [polar_lift(b1)], [polar_lift(b2)],
                   polar_lift(z)) == meijerg([a1], [a2], [b1], [b2],
                                             polar_lift(z))

    # integrand
    assert meijerg([a], [b], [c], [d], z).integrand(s) == \
        z**s*gamma(c - s)*gamma(-a + s + 1)/(gamma(b - s)*gamma(-d + s + 1))

    assert meijerg([[], []], [[Rational(1, 2)], [0]], 1).is_number
    assert not meijerg([[], []], [[x], [0]], 1).is_number
Esempio n. 21
0
def test_bessel_rand():
    for f in [besselj, bessely, besseli, besselk, hankel1, hankel2, jn, yn]:
        assert td(f(randcplx(), z), z)
Esempio n. 22
0
def test_meijerg_derivative():
    assert meijerg([], [1, 1], [0, 0, x], [], z).diff(x) == \
        log(z)*meijerg([], [1, 1], [0, 0, x], [], z) \
        + 2*meijerg([], [1, 1, 1], [0, 0, x, 0], [], z)

    y = randcplx()
    a = 5  # mpmath chokes with non-real numbers, and Mod1 with floats
    assert td(meijerg([x], [], [], [], y), x)
    assert td(meijerg([x**2], [], [], [], y), x)
    assert td(meijerg([], [x], [], [], y), x)
    assert td(meijerg([], [], [x], [], y), x)
    assert td(meijerg([], [], [], [x], y), x)
    assert td(meijerg([x], [a], [a + 1], [], y), x)
    assert td(meijerg([x], [a + 1], [a], [], y), x)
    assert td(meijerg([x, a], [], [], [a + 1], y), x)
    assert td(meijerg([x, a + 1], [], [], [a], y), x)

    b = Rational(3, 2)
    assert td(meijerg([a + 2], [b], [b - 3, x], [a], y), x)
    assert td(meijerg([x], [2, b], [1, b + 1], [], y), x)