Skip to main content

Elliptic integrals and functions — NumPy, PyTorch, JAX

Project description

elliptic (Python)

Standalone Python implementation of elliptic integrals and functions. Works identically on NumPy arrays, PyTorch tensors (CPU and CUDA), and JAX arrays — no scipy runtime dependency.

tests

Install

pip install elliptic-functions                   # NumPy only
pip install "elliptic-functions[torch]"          # + PyTorch backend
pip install "elliptic-functions[jax]"            # + JAX backend
pip install "elliptic-functions[dev]"            # + test deps (scipy, mpmath, pytest)

Quick start

import numpy as np
import elliptic

phi = np.linspace(0, np.pi/2, 200)
m   = 0.7

# Incomplete integrals F(φ|m), E(φ|m), Jacobi zeta Z(φ|m)
F, E, Z = elliptic.elliptic12(phi, m)

# Third kind Π(φ,m,n)  — missing from scipy (issue #4452)
Pi = elliptic.elliptic3(phi, m, 0.3)

# Jacobi elliptic functions sn, cn, dn, am
sn, cn, dn, am = elliptic.ellipj(np.linspace(0, 3, 100), m)

# Associate incomplete integrals B, D, J  (DLMF §19.2)
B, D, J = elliptic.ellipticBDJ(phi, m, 0.3)
# identities: F = B+D,  E = B+(1-m)D,  Pi = B+D+n*J

# Complete associate integrals B(m), D(m), S(m)
B_c, D_c, S_c = elliptic.ellipticBD(np.array([0.3, 0.5, 0.7]))

# Carlson symmetric forms  (DLMF §19.16)
RF = elliptic.carlsonRF(0.0, 1.0 - m, 1.0)    # = K(m)
RD = elliptic.carlsonRD(0.0, 1.0 - m, 1.0)    # = 3D(m)

# Bulirsch generalised complete integrals
K  = elliptic.cel1(np.sqrt(1 - m))             # = K(m)
E2 = elliptic.cel2(np.sqrt(1 - m), 1.0, 1-m)  # = E(m)

# Jacobi theta functions (4 types)
Th3 = elliptic.theta(3, phi, m)
Th,  H  = elliptic.jacobiThetaEta(np.linspace(0, 1, 50), m)
Th3, dTh3 = elliptic.theta_prime(3, phi, m)

# Weierstrass functions
e1, e2, e3 = 2.0, 0.5, -2.5
P   = elliptic.weierstrassP(0.4, e1, e2, e3)
Zf  = elliptic.weierstrassZeta(0.4, e1, e2, e3)
S   = elliptic.weierstrassSigma(0.4, e1, e2, e3)
dP  = elliptic.weierstrassPPrime(0.4, e1, e2, e3)
g2, g3, Delta = elliptic.weierstrassInvariants(e1, e2, e3)

# Nome and inverse
q = elliptic.nomeq(m)
m_back = elliptic.inversenomeq(q)

# Inverse E(phi|m): given E value, solve for phi
phi_inv = elliptic.inverselliptic2(E, m)

# Arithmetic-geometric mean
agm_val = elliptic.agm(1.0, np.sqrt(1 - m))   # = π/(2K(m))

# Complex arguments
import numpy as np
u_c = np.array([0.4 + 0.3j, 0.8 - 0.2j])
Fi, Ei, Zi = elliptic.elliptic12i(u_c, m)
sni, cni, dni = elliptic.ellipji(u_c, m)

# Application: ellipse arc length
arc = elliptic.arclength_ellipse(5, 10)       # full perimeter ≈ 48.44
arc = elliptic.arclength_ellipse(5, 10, 0, np.pi/4)  # quarter arc

GPU (PyTorch)

Pass a torch.Tensor on any device:

import torch, elliptic

phi = torch.linspace(0.01, 1.5, 1_000_000, dtype=torch.float64, device="cuda")
F, E, Z = elliptic.elliptic12(phi, torch.full_like(phi, 0.7))

JAX (jit / vmap)

import jax, jax.numpy as jnp, elliptic

phi = jnp.linspace(0.01, 1.5, 10_000)
F, E, Z = jax.jit(elliptic.elliptic12)(phi, 0.7)

Comparison with scipy.special

Function scipy elliptic
K(m), E(m)
F(φ,m), E(φ,m)
Jacobi sn/cn/dn (real)
Jacobi sn/cn/dn (complex)
F(u,m), E(u,m) (complex)
Π(φ,m,n) — 3rd kind ✗ (open since 2015)
Carlson RF/RD/RJ/RC ✓ since v1.8
B, D, J associate
Bulirsch cel
Jacobi theta θ₁…θ₄
Weierstrass P/ζ/σ/℘′
Weierstrass invariants g₂,g₃
Nome q(m) and m(q)
Inverse E(φ,m)
AGM
Ellipse arc length
PyTorch GPU
JAX jit/vmap

All algorithms run identically across backends — the same Python code dispatches to NumPy, PyTorch CUDA, or JAX TPU.

References

  • Abramowitz & Stegun, Handbook of Mathematical Functions, §16–18
  • NIST DLMF §19, §22, §23 — https://dlmf.nist.gov
  • Fukushima (2015), "Elliptic functions and elliptic integrals for celestial mechanics"
  • Bulirsch (1965), "Numerical computation of elliptic integrals"
  • Carlson (1995), "Numerical Computation of Real or Complex Elliptic Integrals"
  • Boyd (2012), "Numerical inversion of the incomplete elliptic integral of the second kind"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elliptic_functions-4.1.0.tar.gz (45.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elliptic_functions-4.1.0-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file elliptic_functions-4.1.0.tar.gz.

File metadata

  • Download URL: elliptic_functions-4.1.0.tar.gz
  • Upload date:
  • Size: 45.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for elliptic_functions-4.1.0.tar.gz
Algorithm Hash digest
SHA256 95bea538aa1b8e117a4bf37e93c86420cded065c2ac24379fde1e12bc89d5936
MD5 7adf6940349e333edf114a5d8975a172
BLAKE2b-256 ff401e7da43461e53841f8b5d817a02707f36490386f15112ac990ef79c8e35f

See more details on using hashes here.

Provenance

The following attestation bundles were made for elliptic_functions-4.1.0.tar.gz:

Publisher: python.yml on moiseevigor/elliptic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elliptic_functions-4.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for elliptic_functions-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d03ffe165f6cd1620367d57126f351e6cb676be0084400fd9b341e990430cef
MD5 c612a79708b31958e0281226b189377a
BLAKE2b-256 698e720e52b0ce0a88d933e229a841ca66a5031e266c70ce83ecf7d4f3bccff0

See more details on using hashes here.

Provenance

The following attestation bundles were made for elliptic_functions-4.1.0-py3-none-any.whl:

Publisher: python.yml on moiseevigor/elliptic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page