コード例 #1
0
    def test_incomplete(x, y, z):
        # TODO: sign of sqrt(x, y, z)
        assume(distinct(x, y, z))

        # https://dlmf.nist.gov/19.21.E7
        assert nice_and_close(
            abs(3 * elliprf(x, y, z) - ((x - y) * elliprd(y, z, x) +
                                        (z - y) * elliprd(x, y, z))),
            abs(3 * (y / x / z)**0.5))

        # https://dlmf.nist.gov/19.21.E8
        assert nice_and_close(
            abs(elliprd(y, z, x) + elliprd(z, x, y) + elliprd(x, y, z)),
            abs(3 * (x * y * z)**(-0.5)))

        # https://dlmf.nist.gov/19.21.E9
        assert nice_and_close(
            x * elliprd(y, z, x) + y * elliprd(z, x, y) + z * elliprd(x, y, z),
            3 * elliprf(x, y, z))

        # https://dlmf.nist.gov/19.21.E10
        assert nice_and_close(
            abs(2 * elliprg(x, y, z) - (z * elliprf(x, y, z) - (x - z) *
                                        (y - z) * elliprd(x, y, z) / 3)),
            abs((x * y / z)**0.5))

        # https://dlmf.nist.gov/19.21.E11
        assert nice_and_close(
            6 * elliprg(x, y, z), 3 * (x + y + z) * elliprf(x, y, z) -
            sum(_x**2 * elliprd(_y, _z, _x)
                for _x, _y, _z in circular_shifts((x, y, z))))
        assert nice_and_close(
            6 * elliprg(x, y, z),
            sum(_x * (_y + _z) * elliprd(_y, _z, _x)
                for _x, _y, _z in circular_shifts((x, y, z))))
コード例 #2
0
    def test_duplication_formulas(x, y, z, p):
        xs, ys, zs = (_**0.5 for _ in (x, y, z))
        ss = xs + ys + zs

        # https://dlmf.nist.gov/19.26.E25
        a = y + 2 * xs * ys
        assert nice_and_close(elliprc(x, y), 2 * elliprc(x + a, y + a))

        # https://dlmf.nist.gov/19.26.E19
        a = sum(map(product, combinations((xs, ys, zs), 2)))
        xa, ya, za, pa = map(partial(add, a), (x, y, z, p))

        # https://dlmf.nist.gov/19.26.E18
        assert nice_and_close(elliprf(x, y, z), 2 * elliprf(xa, ya, za))
        assert nice_and_close(elliprf(x, y, z),
                              elliprf(xa / 4, ya / 4, za / 4))
        # https://dlmf.nist.gov/19.26.E20
        assert nice_and_close(elliprd(x, y, z),
                              2 * elliprd(xa, ya, za) + 3 / z**0.5 / za)
        # https://dlmf.nist.gov/19.26.E21
        assert nice_and_close(
            2 * elliprg(x, y, z),
            4 * elliprg(xa, ya, za) - a * elliprf(x, y, z) - ss)
        # https://dlmf.nist.gov/19.26.E22
        assert nice_and_close(
            elliprj(x, y, z, p), 2 * elliprj(xa, ya, za, pa) + 3 * elliprc(
                (p * ss + xs * ys * zs)**2, p * pa**2))
コード例 #3
0
    def test_addition_theorems(x, y, z, a, p):
        xa, ya, za, pa = map(partial(add, a), (x, y, z, p))

        # https://dlmf.nist.gov/19.26.E12
        b = (xa**0.5 * y + x**0.5 * ya)**2 / a**2 - x
        # https://dlmf.nist.gov/19.26.E11
        assert nice_and_close(elliprc(x, y),
                              elliprc(xa, ya) + elliprc(x + b, y + b))

        # https://dlmf.nist.gov/19.26.E5
        b = ((x * y * z)**0.5 +
             (xa * ya * za)**0.5)**2 / a**2 - (x + y + z + a)
        xb, yb, zb, pb = map(partial(add, b), (x, y, z, p))

        # https://dlmf.nist.gov/19.26.E10
        c = p * pa * pb
        d = (p - x) * (p - y) * (p - z)

        # # https://dlmf.nist.gov/19.26.E1
        assert nice_and_close(elliprf(x, y, z),
                              elliprf(xa, ya, za) + elliprf(xb, yb, zb))
        # https://dlmf.nist.gov/19.26.E7
        assert nice_and_close(
            elliprd(x, y, z) - 3 / (z * za * zb)**0.5,
            elliprd(xa, ya, za) + elliprd(xb, yb, zb))
        # https://dlmf.nist.gov/19.26.E8
        assert nice_and_close(
            2 * elliprg(x, y, z) + a * elliprf(xa, ya, za) +
            b * elliprf(xb, yb, zb) + (x + y + z + a + b)**0.5,
            2 * (elliprg(xa, ya, za) + elliprg(xb, yb, zb)))
        # https://dlmf.nist.gov/19.26.E9
        assert nice_and_close(
            elliprj(x, y, z, p) - 3 * elliprc(c - d, c),
            elliprj(xa, ya, za, pa) + elliprj(xb, yb, zb, pb))
コード例 #4
0
    def test_complete_1(y, z):
        # https://dlmf.nist.gov/19.21.E2
        assert nice_and_close(3 * elliprf(0, y, z),
                              z * elliprd(0, y, z) + y * elliprd(0, z, y))

        # https://dlmf.nist.gov/19.21.E3
        assert nice_and_close(6 * elliprg(0, y, z),
                              y * z * (elliprd(0, y, z) + elliprd(0, z, y)))
        assert nice_and_close(
            6 * elliprg(0, y, z),
            3 * z * elliprf(0, y, z) + z * (y - z) * elliprd(0, y, z))
コード例 #5
0
    def test_complete_2(z: complex):
        assume(not z.imag == 0)
        sign = (1 if phase(z) > 0 else -1) * 1j

        # https://dlmf.nist.gov/19.21.E4
        assert nice_and_close(elliprf(0, z - 1, z),
                              elliprf(0, 1 - z, 1) - sign * elliprf(0, z, 1))

        # https://dlmf.nist.gov/19.21.E5
        assert nice_and_close(
            2 * elliprg(0, z - 1, z),
            2 * (elliprg(0, 1 - z, 1) + sign * elliprg(0, z, 1)) +
            (z - 1) * elliprf(0, 1 - z, 1) - sign * z * elliprf(0, z, 1))
コード例 #6
0
 def test_elliprg(x, y, z, l):
     assert nice_and_close(elliprg(x, x, x), x**0.5)
     assert nice_and_close(elliprg(l * x, l * y, l * z),
                           elliprg(x, y, z) *
                           l**0.5)  # TODO:  elliprc sign issue
     assert nice_and_close(elliprg(0, y, y), pi / 4 * y**0.5)
     assert nice_and_close(elliprg(0, 0, z), z**0.5 / 2)
     assert nice_and_close(2 * elliprg(x, y, y), y * elliprc(x, y) + x**0.5)