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
Metadata
Release files for jaxellip 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jaxellip-0.1.0.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jaxellip-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.3 kB
Release files / jaxellip-0.1.0.tar.gz
| Download URL | jaxellip-0.1.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22bfb21a9a632c640036175879ba5f2d6cb3ce65a2a3494f53918c2f5f0ca76c
|
|
BLAKE2b-256 checksum How to use checksums |
6e7cb367c5c759bf88f613a3ed960f445a7b65cfcd02b5ec725c467d84ef1a77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.
Transparency logRelease files / jaxellip-0.1.0-py3-none-any.whl
| Download URL | jaxellip-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab4c50841adf4c7532a4be1906ae6a971e631595b4bdb191e414c4101147f461
|
|
BLAKE2b-256 checksum How to use checksums |
a06f88f9778120f26589c4944e5c49aa177ca15a5a926f8c47b66f3da6d965ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.
Transparency log