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.0.0.tar.gz (36.9 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.0.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: elliptic_functions-4.0.0.tar.gz
  • Upload date:
  • Size: 36.9 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.0.0.tar.gz
Algorithm Hash digest
SHA256 6de562f0b65c6c9e8bd3a08bbbf856ff41ec4ff3bebec312656cce450f143e96
MD5 f636ffbe427fe06d48da1f4c24fea278
BLAKE2b-256 8f33e86264835858b560ce90d459842f8ab75373d49416890ade00385e064165

See more details on using hashes here.

Provenance

The following attestation bundles were made for elliptic_functions-4.0.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.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for elliptic_functions-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ddf1c0519fcd1fccb8db4c0ca9c16dc677347cfcada4914b45f8faa29ad4ac3
MD5 bb52733acf502c02b878d5c0856ec571
BLAKE2b-256 d6fde0922d98478045918c3fd6067700f26699add574a7fb814281535a736f8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for elliptic_functions-4.0.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