Beispiel #1
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 #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))
Beispiel #3
0
    def test_elliprj(x, y, z, p):
        # TODO: properly analytically continue
        assume(distinct(x, y, z, p))

        # https://dlmf.nist.gov/19.21.E13
        q = (y - x) * (z - x) / (p - x) + x

        # # https://dlmf.nist.gov/19.21.E12
        # TODO: elliprc sign issue
        assert nice_and_close(
            ((p - x) * elliprj(x, y, z, p) +
             (q - x) * elliprj(x, y, z, q)).real,
            (3 * (elliprf(x, y, z) - elliprc(y * z / x, p * q / x))).real)

        # https://dlmf.nist.gov/19.21.E15
        # special case of above with x=0
        q = y * z / p
        assert nice_and_close(
            (p * elliprj(0, y, z, p) + q * elliprj(0, y, z, q)).real,
            3 * elliprf(0, y, z).real)
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_elliprj2(y, p):
     assume(distinct(y, p) and y != 0)
     assert nice_and_close(
         elliprj(0, y, y, -p).real, -1.5 * pi / y**0.5 / (y + p))
Beispiel #7
0
 def test_elliprj1(x, y, p):
     assume(distinct(y, p))
     assert nice_and_close(elliprj(0, y, y, p),
                           1.5 * pi / (y * p**0.5 + p * y**0.5))
     assert nice_and_close(elliprj(x, y, y, p),
                           3 * (elliprc(x, y) - elliprc(x, p)) / (p - y))
Beispiel #8
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))
Beispiel #9
0
 def test_elliprj_fail(self):
     assert elliprj(*torch.tensor(next(zip(
         *self.cases_elliprj_fail))).T).real.isnan().all()