Beispiel #1
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))
Beispiel #2
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))
Beispiel #3
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))
Beispiel #4
0
    def test_complete_3(y, z, p):
        # https://dlmf.nist.gov/19.21.E6
        assume(distinct(y, z, p))
        if z < y < p or p < y < z:
            y, z = z, y

        r = (y - p) / (y - z)
        assume(r > 0)

        assert nice_and_close(
            (r * p)**0.5 / z * elliprj(0, y, z, p),
            (r - 1) * elliprf(0, y, z) * elliprd(p, r * z, z) +
            elliprd(0, y, z) * elliprf(p, r * z, z))
Beispiel #5
0
    def test_elliprj(x, y, z, p, l):
        assert nice_and_close(elliprj(x, x, x, x), x**(-1.5))
        assert nice_and_close(elliprj(l * x, l * y, l * z, l * p),
                              elliprj(x, y, z, p) / l**1.5)
        assert nice_and_close(elliprj(x, y, z, z), elliprd(x, y, z))
        assert isinf(elliprj(0, 0, z, p))
        assert nice_and_close(elliprj(x, x, x, p), elliprd(p, p, x))
        assert nice_and_close(
            elliprj(x, x, x, p).real,
            3 * (elliprc(x, p) - x**(-0.5)) / (x - p))
        assert nice_and_close(elliprj(x, y, y, y), elliprd(x, y, y))
        # assert nice_and_close(elliprj(0, y, z, (y*z)**0.5), 1.5/(y*z)**0.5 * elliprf(0, y, z))
        # assert nice_and_close(elliprj(0, y, z, -(y*z)**0.5), -1.5/(y*z)**0.5 * elliprf(0, y, z))

        # TODO:  elliprc sign issue
        assume(distinct(x, y, z))
        p = x + ((y - x) * (z - x))**0.5
        assert nice_and_close(
            (p - x) * elliprj(x, y, z, p),
            1.5 * (elliprf(x, y, z) - x**0.5 * elliprc(y * z, p**2)))
Beispiel #6
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))))
Beispiel #7
0
 def test_legendre_relation(z):
     # https://dlmf.nist.gov/19.21.E1
     assert nice_and_close(
         elliprf(0, z + 1, z) * elliprd(0, z + 1, 1) +
         elliprd(0, z + 1, z) * elliprf(0, z + 1, 1), 3 * pi / 2 / z)
Beispiel #8
0
 def test_elliprd1(x, y, z):
     assume(x != y and y != 0 and x != z and x * z != 0)
     assert nice_and_close(elliprd(x, y, y),
                           1.5 * (elliprc(x, y) - x**0.5 / y) / (y - x))
     assert nice_and_close(elliprd(x, x, z),
                           3 * (elliprc(z, x) - z**(-0.5)) / (z - x))
Beispiel #9
0
 def test_elliprd(x, y, z, l):
     assert nice_and_close(elliprd(x, x, x), x**(-1.5))
     assert nice_and_close(elliprd(l * x, l * y, l * z),
                           elliprd(x, y, z) / l**1.5)
     assert nice_and_close(elliprd(0, y, y), 3 * pi / 4 / y**1.5)
     assert isinf(elliprd(0, 0, z))
Beispiel #10
0
 def test_definitions(self, x, y, z):
     assert close(elliprc(x, y), elliprf(x, y, y))
     assert close(elliprd(x, y, z), elliprj(x, y, z, z))