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)
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)