FLINT3.7.0-dev
Module · 25 functions

acb_elliptic.h

#include <flint/acb_elliptic.h>

This module evaluates elliptic integrals and elliptic (doubly periodic) functions of complex variables with rigorous error bounds:

  • the complete elliptic integrals K(m), E(m) and \Pi(n, m), computed with the arithmetic-geometric mean;
  • the incomplete Legendre integrals F(\phi, m), E(\phi, m) and \Pi(n, \phi, m), reduced to Carlson's symmetric integrals;
  • the Carlson symmetric integrals R_F, R_G, R_J and the special cases R_C and R_D, computed by the duplication algorithm with a high-order Taylor expansion;
  • the Weierstrass functions \wp, \wp', \wp^{-1}, \zeta and \sigma for the lattice \mathbb{Z} + \tau\mathbb{Z}, and the lattice invariants and roots, computed with Jacobi theta functions.

The modular forms and theta functions on which the Weierstrass functions are built are in acb_modular (genus 1) and acb_theta (any genus). The algorithms are described in Elliptic integrals, elliptic functions and modular forms, following [Joh2019].

AlgorithmElliptic integrals, elliptic functions and modular formsThe complex arithmetic-geometric mean with Dupont's error bound, complete and incomplete elliptic integrals through the AGM and Carlson's duplication algorithm with high-order Taylor series, Weierstrass functions via theta functions, and modular forms by reduction to the fundamental domain and q-series with short addition sequences.

Conventions#

  • The parameter m of the Legendre integrals is the parameter, related to the modulus k and the modular angle \alpha by m = k^2 = \sin^2 \alpha (as in [NIST2012, §19.1]).
  • In the Weierstrass functions, the lattice is \Lambda = \mathbb{Z} + \tau \mathbb{Z} with \operatorname{Im}(\tau) > 0, that is, the half-periods are \omega_1 = 1/2 and \omega_3 = \tau/2. A general lattice 2\omega_1 \mathbb{Z} + 2\omega_3 \mathbb{Z} is handled by the homogeneity relations, for instance \wp(z; 2\omega_1, 2\omega_3) = (2\omega_1)^{-2} \wp(z/(2\omega_1), \omega_3/\omega_1).
  • A nonzero flag times_pi replaces the amplitude \phi by \pi \phi, which makes the quasi-period 1 instead of \pi and allows exact input at multiples of \pi/2.
  • The flags arguments of the Carlson integrals are reserved for future use; pass 0.
  • Outputs may alias inputs. A function returns indeterminate balls (or balls containing the result with infinite radius) when the input is not finite, lies on or straddles a singularity, or the algorithm cannot separate the input from a branch cut.

Complete elliptic integrals#

void acb_elliptic_k(acb_t k, const acb_t m, slong prec)

Sets k to the complete elliptic integral of the first kind K(m) = \int_0^{\pi/2} (1 - m \sin^2 t)^{-1/2} \, dt, computed as K(m) = \pi / (2 M(\sqrt{1-m})) where M(z) = \operatorname{agm}(1, z) is computed by acb_agm1. The branch cut is m \in [1, \infty).

More
void acb_elliptic_k_jet(acb_ptr w, const acb_t m, slong len, slong prec)

Sets w to the Taylor coefficients of K(m + x) at x = 0, truncated to length len. The first two coefficients come from (M, M') evaluated by acb_agm1_cpx, the others from the linear recurrence implied by the hypergeometric differential equation of K.

More
void acb_elliptic_k_series(acb_poly_t res, const acb_poly_t m, slong len, slong prec)

Set res to K(m(x)) truncated to length len, for a power series m(x), by composing the output of acb_elliptic_k_jet with the nonconstant part of m. The underscore version requires len \ge 1 and reads \min(\text{mlen}, \text{len}) coefficients of m.

void acb_elliptic_e(acb_t res, const acb_t m, slong prec)

Sets res to the complete elliptic integral of the second kind E(m) = \int_0^{\pi/2} (1 - m \sin^2 t)^{1/2} \, dt, computed from K(m) and K'(m) by E(m) = (1-m)(2m K'(m) + K(m)), where K' is the derivative (not the complementary integral).

More
void acb_elliptic_pi(acb_t r, const acb_t n, const acb_t m, slong prec)

Sets r to the complete elliptic integral of the third kind \Pi(n, m) = \int_0^{\pi/2} (1 - n \sin^2 t)^{-1} (1 - m \sin^2 t)^{-1/2} \, dt. For n = 0 this is K(m) and for m = 0 it is \frac{\pi}{2}(1-n)^{-1/2}; otherwise it is computed as R_F(0, 1-m, 1) + \frac{n}{3} R_J(0, 1-m, 1, 1-n), the same reduction as for the incomplete integral, which is slower than the AGM methods for K and E.

More

Legendre incomplete elliptic integrals#

The incomplete integrals are computed on the strip |\operatorname{Re}(\phi)| \le \pi/2 by the reductions to Carlson's integrals of [NIST2012, §19.25(i)], with s = \sin \phi and c = \cos \phi:

F(\phi, m) = s R_F(c^2, 1 - ms^2, 1), \quad E(\phi, m) = s R_F(c^2, 1-ms^2, 1) - \tfrac{m}{3} s^3 R_D(c^2, 1-ms^2, 1),
\Pi(n, \phi, m) = s R_F(c^2, 1-ms^2, 1) + \tfrac{n}{3} s^3 R_J(c^2, 1-ms^2, 1, 1-ns^2).

Outside the strip the functions are extended by quasi-periodicity: writing \phi = \phi' + d \pi with d \in \mathbb{Z} and |\operatorname{Re}(\phi')| \le \pi/2, the integral over a full period is added d times. If \operatorname{Re}(\phi) is a ball that contains a point \pi/2 + d \pi, both neighbouring values of d are tried and the union of the results is returned; if it is wider than \pi/2, the result is indeterminate.

void acb_elliptic_f(acb_t res, const acb_t phi, const acb_t m, int times_pi, slong prec)

Sets res to the incomplete elliptic integral of the first kind F(\phi, m) = \int_0^\phi (1 - m \sin^2 t)^{-1/2} \, dt, extended by F(\phi + d\pi, m) = 2 d K(m) + F(\phi, m). With times_pi nonzero, \phi is replaced by \pi \phi. In particular F(\pi/2, m) = K(m).

More
void acb_elliptic_e_inc(acb_t res, const acb_t phi, const acb_t m, int times_pi, slong prec)

Sets res to the incomplete elliptic integral of the second kind E(\phi, m) = \int_0^\phi (1 - m \sin^2 t)^{1/2} \, dt, extended by E(\phi + d\pi, m) = 2 d E(m) + E(\phi, m). With times_pi nonzero, \phi is replaced by \pi \phi. In particular E(\pi/2, m) = E(m).

More
void acb_elliptic_pi_inc(acb_t res, const acb_t n, const acb_t phi, const acb_t m, int times_pi, slong prec)

Sets res to the incomplete elliptic integral of the third kind \Pi(n, \phi, m) = \int_0^\phi (1 - n \sin^2 t)^{-1} (1 - m \sin^2 t)^{-1/2} \, dt, extended by \Pi(n, \phi + d\pi, m) = 2 d \Pi(n, m) + \Pi(n, \phi, m). With times_pi nonzero, \phi is replaced by \pi \phi. In particular \Pi(n, \pi/2, m) = \Pi(n, m) and \Pi(0, \phi, m) = F(\phi, m).

More

Carlson symmetric integrals#

Carlson's symmetric forms are the preferred form of incomplete elliptic integrals: they are symmetric in their arguments, homogeneous, and can be computed by a duplication algorithm [Car1995]. Every elliptic integral can be expressed in terms of R_F, R_G and R_J, of which R_C(x, y) = R_F(x, y, y) and R_D(x, y, z) = R_J(x, y, z, z) are special cases. Carlson symmetric integrals explains the domains of validity and the choice of method.

void acb_elliptic_rf(acb_t res, const acb_t x, const acb_t y, const acb_t z, int flags, slong prec)

Sets res to the Carlson symmetric integral of the first kind R_F(x, y, z) = \frac12 \int_0^\infty ((t+x)(t+y)(t+z))^{-1/2} \, dt, by duplication steps followed by a Taylor series in the elementary symmetric polynomials of the deviations. The result is indeterminate if more than one argument contains zero.

Full documentation
void acb_elliptic_rg(acb_t res, const acb_t x, const acb_t y, const acb_t z, int flags, slong prec)

Sets res to the Carlson symmetric integral of the second kind R_G, computed from R_F and R_D. There are no restrictions on the arguments.

Full documentation
void acb_elliptic_rj(acb_t res, const acb_t x, const acb_t y, const acb_t z, const acb_t p, int flags, slong prec)
void acb_elliptic_rj_carlson(acb_t res, const acb_t x, const acb_t y, const acb_t z, const acb_t p, int flags, slong prec)
void acb_elliptic_rj_integration(acb_t res, const acb_t x, const acb_t y, const acb_t z, const acb_t p, int flags, slong prec)

Set res to the Carlson symmetric integral of the third kind R_J(x, y, z, p) = \frac32 \int_0^\infty (t+p)^{-1} ((t+x)(t+y)(t+z))^{-1/2} \, dt. The carlson version uses the duplication algorithm, which can give wrong values for some complex arguments; the integration version moves the arguments to the right half-plane by numerical integration; the default version uses the duplication algorithm when it is known to be correct (including the case p = z, which computes R_D(x, y, z)) and integration otherwise.

Full documentation
void acb_elliptic_rc1(acb_t res, const acb_t x, slong prec)

Sets res to R_C(1, 1+x) = \operatorname{atan}(\sqrt{x})/\sqrt{x}, a helper for R_J, using a short Taylor series for small |x|.

Full documentation

Weierstrass elliptic functions#

The Weierstrass functions for the lattice \mathbb{Z} + \tau\mathbb{Z} are computed from the Jacobi theta functions \theta_i(z, \tau) of acb_modular, which moves \tau to the fundamental domain and reduces z before summing the theta series. Because the Weierstrass functions are invariant (or covariant) under the action of the modular group, the cost is O(\log p) multiplications plus the theta series, which needs O(\sqrt{p}) terms at precision p. The reference is [NIST2012, Ch. 23]. When z is real and \operatorname{Re}(\tau) is a multiple of 1/2, the functions are real and the imaginary part of the output is set to exactly zero.

void acb_elliptic_p(acb_t r, const acb_t z, const acb_t tau, slong prec)

Sets r to the Weierstrass elliptic function \wp(z, \tau) = z^{-2} + \sum_{\omega \in \Lambda \setminus 0} ((z + \omega)^{-2} - \omega^{-2}), computed by

\wp(z, \tau) = \pi^2 \theta_2^2(0,\tau) \theta_3^2(0,\tau) \frac{\theta_4^2(z,\tau)}{\theta_1^2(z,\tau)} - \frac{\pi^2}{3} \left[ \theta_2^4(0,\tau) + \theta_3^4(0,\tau)\right].
void acb_elliptic_p_prime(acb_t r, const acb_t z, const acb_t tau, slong prec)

Sets r to the derivative \wp'(z, \tau) with respect to z, computed by \wp'(z,\tau) = (-2\pi \eta(\tau)^2/\theta_1(z,\tau))^3 \, \theta_2(z,\tau) \theta_3(z,\tau) \theta_4(z,\tau), where \eta is the Dedekind eta function.

void acb_elliptic_p_jet(acb_ptr r, const acb_t z, const acb_t tau, slong len, slong prec)

Sets r to the Taylor coefficients of \wp(z + x, \tau) at x = 0, truncated to length len, from the theta function jets of acb_modular_theta_jet. With len = 2 this gives (\wp(z, \tau), \wp'(z, \tau)), which generate the field of elliptic functions with periods 1 and \tau.

void _acb_elliptic_p_series(acb_ptr res, acb_srcptr z, slong zlen, const acb_t tau, slong len, slong prec)
void acb_elliptic_p_series(acb_poly_t res, const acb_poly_t z, const acb_t tau, slong len, slong prec)

Set res to \wp(z(x), \tau) truncated to length len, for a power series z(x). The underscore version requires len \ge 1.

void acb_elliptic_invariants(acb_t g2, acb_t g3, const acb_t tau, slong prec)

Sets g2 and g3 to the lattice invariants g_2 = 60 G_4(\tau) and g_3 = 140 G_6(\tau), where G_{2k} are the Eisenstein series of acb_modular_eisenstein. They are the coefficients of the differential equation \wp'^2 = 4 \wp^3 - g_2 \wp - g_3.

void acb_elliptic_roots(acb_t e1, acb_t e2, acb_t e3, const acb_t tau, slong prec)

Sets e1, e2, e3 to the lattice roots, the roots of 4x^3 - g_2 x - g_3, which are e_1 = \wp(1/2), e_2 = \wp((1 + \tau)/2) and e_3 = \wp(\tau/2), computed from the fourth powers of the theta constants [NIST2012, 23.6.2–23.6.4]. The outputs are indeterminate if \operatorname{Im}(\tau) is not certainly positive.

More
void acb_elliptic_inv_p(acb_t res, const acb_t z, const acb_t tau, slong prec)

Sets res to the inverse Weierstrass function, a solution w of \wp(w, \tau) = z, given by the elliptic integral

\wp^{-1}(z, \tau) = \frac12 \int_z^\infty \frac{dt}{\sqrt{(t-e_1)(t-e_2)(t-e_3)}} = R_F(z - e_1, z - e_2, z - e_3).
void acb_elliptic_zeta(acb_t res, const acb_t z, const acb_t tau, slong prec)

Sets res to the Weierstrass zeta function \zeta(z, \tau) = z^{-1} + \sum_{\omega \ne 0} ((z - \omega)^{-1} + \omega^{-1} + z \omega^{-2}), which satisfies \zeta' = -\wp and is quasi-periodic: \zeta(z + 1) = \zeta(z) + 2\eta_1, \zeta(z + \tau) = \zeta(z) + 2\eta_3 with \eta_1 = \zeta(1/2) and \eta_3 = \zeta(\tau/2). It is computed as \zeta(z) = 2 \eta_1 z + \theta_1'(z, \tau)/\theta_1(z, \tau), where \eta_1 = -\theta_1'''(0, \tau) / (6 \theta_1'(0, \tau)).

void acb_elliptic_sigma(acb_t res, const acb_t z, const acb_t tau, slong prec)

Sets res to the Weierstrass sigma function \sigma(z, \tau) = z \prod_{\omega \ne 0} (1 - z/\omega) \exp(z/\omega + z^2/(2\omega^2)), which satisfies \sigma'/\sigma = \zeta, computed as \sigma(z) = e^{\eta_1 z^2} \theta_1(z, \tau) / \theta_1'(0, \tau).

More

References#

  • [Joh2019] F. Johansson. Numerical evaluation of elliptic functions, elliptic integrals and modular forms. In J. Blümlein, C. Schneider and P. Paule (eds.), Elliptic Integrals, Elliptic Functions and Modular Forms in Quantum Field Theory, Texts & Monographs in Symbolic Computation, Springer, 2019, 269–293. https://arxiv.org/abs/1806.06725
  • [NIST2012] National Institute of Standards and Technology, Digital Library of Mathematical Functions (2012), https://dlmf.nist.gov/
  • [Car1995] B. C. Carlson, "Numerical computation of real or complex elliptic integrals". Numerical Algorithms, 10(1):13-26 (1995).
Cite this page

The FLINT team, “acb_elliptic.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/acb_elliptic/index.html (generated 2026-10-20).