← Back

jaxellip

2025

My PhD research at Princeton University focused on optimizing the geometry of high-temperature superconducting magnets to achieve higher magnetic fields and improved quench protection by leveraging the anisotropic properties of superconducting materials using computational, simulation-based methods.

Our work involved computing elliptic integrals. However, we were using JAX so that the objective functions could be automatically differentiated and optimized efficiently on GPUs.

JAX did not provide built-in implementations of these elliptic integrals, so I created a package implementing them.

The package provides JAX implementations of ellipk K(m)K(m), ellipkm1 K(1p)K(1 - p), and ellipe E(m)E(m), matching the API of SciPy:

K(m)=0π/211msin2θdθK(m) = \int_0^{\pi/2} \frac{1}{\sqrt{1 - m\sin^2\theta}}\,d\theta
K(1p)=0π/211(1p)sin2θdθK(1 - p) = \int_0^{\pi/2} \frac{1}{\sqrt{1 - (1 - p)\sin^2\theta}}\,d\theta
E(m)=0π/21msin2θdθE(m) = \int_0^{\pi/2} \sqrt{1 - m\sin^2\theta}\,d\theta

ellipk and ellipkm1 are the same function KK with different parameterizations: ellipk takes mm and returns K(m)K(m), while ellipkm1 takes p=1mp = 1 - m, the distance from the singular point m=1m = 1, and returns K(1p)K(1 - p). The split exists because K(m)K(m) diverges logarithmically as m1m \to 1, and near this point the result hinges on the exact value of 1m1 - m. Taking pp as the argument make ellipkm1 remain accurate arbitrarily close to the singularity, at the cost of a small amount of additional computation.

Under the hood, ellipk and ellipe use the same Cephes minimax polynomial approximations as SciPy: polynomials in the complementary parameter 1m1 - m plus logarithmic terms, with a Landen transformation for negative mm. ellipkm1 evaluates K(1p)K(1 - p) directly from pp, using a small-pp logarithmic expansion below p=108p = 10^{-8}.

Automatic differentiation is implemented with custom JVP rules. The derivative formulas reduce to Carlson’s symmetric integral RDR_D, which is evaluated using a fixed-length duplication iteration with the zero argument handled analytically. The tests compare values against high-precision mpmath references and scipy.special, and check forward-, reverse-, and second-order JAX derivatives.

Check out the source code on GitHub: github.com/sinaatalay/jaxellip

Check out the package on PyPI: pypi.org/project/jaxellip

I’m always interested in discussing business and technology. I also have plenty of ambitious project ideas in mind if you’re looking for one.

Feel free to reach out at dev@atalay.biz.

Follow me at: LinkedIn, X, GitHub, YouTube, Reddit