Some elliptic integrals in JAX
Project description
jaxellip: JAX implementations of some elliptic integrals
Elliptic integrals are available in scipy.special, but are not implemented in jax.scipy.special, making them neither differentiable nor compatible with JAX’s JIT compilation. This package provides JAX-compatible implementations of several elliptic integrals from scipy.special: ellipk, ellipkm1, and ellipe. The results are tested against arbitrary-precision mpmath references and cross-checked against scipy.special (see tests).
Usage
- Install
jaxellip.
pip install jaxellip
- Import
jaxellipin your Python code and use it.
import jaxellip
import jax.numpy as jnp
input = jnp.linspace(-10, 10, 1000)
jaxellip.ellipk(input) # Complete elliptic integral of the first kind
jaxellip.ellipkm1(input) # Complete elliptic integral of the first kind around m = 1
jaxellip.ellipe(input) # Complete elliptic integral of the second kind
The elliptic integrals in jaxellip follow the same parameter conventions as scipy.special. In particular, the input parameter $m$ is the elliptic parameter, defined as $m = k^2$, where $k$ is the modulus. This differs from some literature or libraries (e.g., Boost or Abramowitz & Stegun), where the integrals are sometimes expressed in terms of $k$ directly.
The function ellipkm1(m) computes the complete elliptic integral of the first kind with argument $1 - m$, i.e., $K(1 - m)$. This is particularly useful for improved numerical stability and precision when $m$ is close to 1, since $K(m)$ diverges logarithmically as $m \to 1$.
Complete elliptic integral of the first kind (ellipk and ellipkm1)
$$ K(m) = \int_0^{\pi/2} \frac{1}{\sqrt{1 - m \sin^2 \theta}} d\theta $$
Complete elliptic integral of the second kind (ellipe)
$$ E(m) = \int_0^{\pi/2} \sqrt{1 - m \sin^2 \theta} d\theta $$
Numerical Method
ellipk and ellipe use the same Cephes minimax polynomials as SciPy: a degree-10 polynomial in the complementary parameter $1 - m$ plus a logarithmic term, with negative $m$ reduced to $[0, 1)$ by the Landen transformation. ellipkm1(x) evaluates $K(1 - x)$ from $x$ directly (never forming $1 - x$) and uses a logarithmic series for $x < 10^{-8}$. The forward pass does not iterate.
Derivatives use exact custom JVP rules instead of differentiating the polynomial. Each reduces to the Carlson symmetric integral $R_D$ (for example, $dK/dm = R_D(0, 1, 1-m)/6$), evaluated by a short fixed iteration whose only zero argument is handled in closed form. This makes jaxellip differentiable in every JAX mode (forward, reverse, and higher order such as jax.hessian), so it stays correct inside a larger function that is differentiated as a whole.
Edge cases match SciPy: ellipk(1) is inf, ellipe(1) is 1, ellipkm1(0) is inf, and out-of-domain inputs (m > 1, or x < 0) return NaN for both value and gradient.
Comparison against SciPy
jaxellip is tested against mpmath (a high-precision reference) and scipy.special:
- Accuracy. Values agree with both to about
1e-14relative. Derivatives, in forward, reverse, and second-order modes, agree withmpmath's analytic derivatives to about1e-13(first order) and1e-15(second order). This holds over the whole domain:mdown to-1e308, up to them -> 1singularity, andellipkm1forxfrom1e-308to1e308. - Speed. Warm CPU runtimes are comparable to
scipy.specialin the tested cases. Exact ratios depend on the device, runner load, JAX/XLA version, and SciPy build, so the test suite checks only that there are no large performance regressions.
Developer Guide
Install:
Clone and set up:
git clone https://github.com/sinaatalay/jaxellip.git
cd jaxellip
just sync
code .
Use .venv as the Python interpreter in VS Code.
Repository layout:
src/jaxellip/: package codetests/: tests against SciPy and JAX autodiffpyproject.toml: package metadata and tool settingsuv.lock: locked dependency versionsjustfile: development commands
Common commands:
just test # run tests
just check # run all checks
just format # format code
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jaxellip-0.1.0.tar.gz.
File metadata
- Download URL: jaxellip-0.1.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22bfb21a9a632c640036175879ba5f2d6cb3ce65a2a3494f53918c2f5f0ca76c
|
|
| MD5 |
641a8312a53d75e3d796bc273c1da3a3
|
|
| BLAKE2b-256 |
6e7cb367c5c759bf88f613a3ed960f445a7b65cfcd02b5ec725c467d84ef1a77
|
Provenance
The following attestation bundles were made for jaxellip-0.1.0.tar.gz:
Publisher:
publish-a-release.yaml on sinaatalay/jaxellip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jaxellip-0.1.0.tar.gz -
Subject digest:
22bfb21a9a632c640036175879ba5f2d6cb3ce65a2a3494f53918c2f5f0ca76c - Sigstore transparency entry: 2028713034
- Sigstore integration time:
-
Permalink:
sinaatalay/jaxellip@7df10189c69df83c0d6967255596d6bdab059562 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sinaatalay
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-a-release.yaml@7df10189c69df83c0d6967255596d6bdab059562 -
Trigger Event:
release
-
Statement type:
File details
Details for the file jaxellip-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jaxellip-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab4c50841adf4c7532a4be1906ae6a971e631595b4bdb191e414c4101147f461
|
|
| MD5 |
88075670f76234c3af0250f78573ceb0
|
|
| BLAKE2b-256 |
a06f88f9778120f26589c4944e5c49aa177ca15a5a926f8c47b66f3da6d965ce
|
Provenance
The following attestation bundles were made for jaxellip-0.1.0-py3-none-any.whl:
Publisher:
publish-a-release.yaml on sinaatalay/jaxellip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jaxellip-0.1.0-py3-none-any.whl -
Subject digest:
ab4c50841adf4c7532a4be1906ae6a971e631595b4bdb191e414c4101147f461 - Sigstore transparency entry: 2028713136
- Sigstore integration time:
-
Permalink:
sinaatalay/jaxellip@7df10189c69df83c0d6967255596d6bdab059562 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sinaatalay
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-a-release.yaml@7df10189c69df83c0d6967255596d6bdab059562 -
Trigger Event:
release
-
Statement type: