FLINT3.7.0-dev
Algorithm

Elliptic integrals, elliptic functions and modular forms

Cost
O(log⁡p)O(\log p) square roots at precision pp for the AGM and complete elliptic integrals; O(p0.6)O(p^{0.6}) duplication steps plus a Taylor series of O(p0.4)O(p^{0.4}) terms for Carlson's integrals; O(p)O(\sqrt{p}) multiplications for modular forms and theta functions on the fundamental domain.

Elliptic integrals and elliptic functions reduce to a few primitives that converge quickly: the arithmetic-geometric mean, which gives the complete elliptic integrals; Carlson's duplication algorithm, which gives the incomplete integrals; and theta functions, which give the Weierstrass elliptic functions and the modular forms after a modular transformation has moved τ\tau to the fundamental domain. The sections below describe these methods as implemented in acb (the AGM), acb_elliptic and acb_modular, following [Joh2019]; the summation of theta series is described in Theta functions.

The arithmetic-geometric mean#

For a,b>0a, b > 0, the arithmetic-geometric mean agm⁡(a,b)\operatorname{agm}(a, b) is the common limit of an+1=(an+bn)/2a_{n+1} = (a_n + b_n)/2, bn+1=anbnb_{n+1} = \sqrt{a_n b_n}, with a0=aa_0 = a, b0=bb_0 = b. The convergence is quadratic: ∣an+1−bn+1∣≤∣an−bn∣2/(8bn+1)|a_{n+1} - b_{n+1}| \le |a_n - b_n|^2/(8 b_{n+1}), so O(log⁡p)O(\log p) steps give pp bits once ana_n and bnb_n agree to a few bits. With complex variables, it is convenient to use the univariate function M(z)=agm⁡(1,z)M(z) = \operatorname{agm}(1, z); then agm⁡(a,b)=aM(b/a)\operatorname{agm}(a,b) = a M(b/a) (acb_agm), and MM is analytic on C∖(−∞,0]\mathbb{C} \setminus (-\infty, 0].

Functional equation. If the real part of zz is not nonnegative, acb_agm1 first applies M(z)=z+12M(u)M(z) = \frac{z+1}{2} M(u) with u=2z/(z+1)u = 2\sqrt{z}/(z+1), which has nonnegative real part (rounding errors that make the ball for uu cross the imaginary axis only inflate the result). For the derivative this becomes M′(z)=[M(u)−(z−1)M′(u)/((1+z)z)]/2M'(z) = [M(u) - (z-1) M'(u) / ((1+z) \sqrt{z})] / 2.

Square roots. In the iteration the correct square root is the continuous branch anbn\sqrt{a_n}\sqrt{b_n}, which is computed as anbn\sqrt{a_n b_n}, i−anbni\sqrt{-a_n b_n} or −i−anbn-i\sqrt{-a_n b_n} when ana_n and bnb_n both have positive real part, both have nonnegative imaginary part, or both have nonpositive imaginary part, and as anbn\sqrt{a_n}\sqrt{b_n} otherwise.

Lemma 1 (Dupont [Dup2006, p. 87]). If Re⁡(z)≥0\operatorname{Re}(z) \ge 0, the iterates of the AGM of (1,z)(1, z) satisfy ∣M(z)−an∣≤∣an−bn∣|M(z) - a_n| \le |a_n - b_n| for all nn.

This gives a rigorous enclosure when the iteration is stopped, and for real positive variables the lower and upper bounds bn≤M≤anb_n \le M \le a_n can be used directly (arb_agm). It is slightly faster to stop when ana_n and bnb_n agree to about p/10p/10 bits and finish with a series: with w=(a−b)/(a+b)w = (a - b)/(a + b),

agm⁡(a,b)=(a+b)π4K(w2),π4K(w2)=12−w28−5w4128−11w6512−469w832768+…,\operatorname{agm}(a,b) = \frac{(a+b) \pi}{4 K(w^2)}, \qquad \frac{\pi}{4 K(w^2)} = \frac{1}{2} - \frac{w^2}{8} - \frac{5 w^4}{128} - \frac{11 w^6}{512} - \frac{469 w^8}{32768} + \ldots,

valid for ∣w∣<1|w| < 1 and a,ba, b with nonnegative real part, where the tail is bounded by ∑k≥10∣w∣k/64\sum_{k \ge 10} |w|^k/64.

First derivative. acb_agm1_cpx computes (M(z),M′(z))(M(z), M'(z)) for exact zz with ∣arg⁡z∣≤3π/4|\arg z| \le 3\pi/4 by a central finite difference. Since ∣M(z)∣≤max⁡(1,∣z∣)|M(z)| \le \max(1, |z|), Cauchy's integral formula gives ∣M(k)(z)/k!∣≤CDk|M^{(k)}(z)/k!| \le C D^k with C=max⁡(1,∣z∣+r)C = \max(1, |z| + r) and D=1/rD = 1/r for 0<r<∣z∣0 < r < |z| (FLINT takes r≈∣z∣/4r \approx |z|/4). For hD<1hD < 1,

∣M(z+h)−M(z−h)2h−M′(z)∣≤CD3h21−Dh,∣M(z+h)+M(z−h)2−M(z)∣≤CD2h21−Dh,\left|\frac{M(z+h) - M(z-h)}{2h} - M'(z)\right| \le \frac{C D^3 h^2}{1 - D h}, \qquad \left|\frac{M(z+h) + M(z-h)}{2} - M(z)\right| \le \frac{C D^2 h^2}{1 - D h},

so two evaluations at about 1.5 times the precision give both values, against twice the precision for a one-sided difference. For inexact zz, the midpoint is used and the propagated error is bounded with ∣M′(z+ε)∣≤max⁡(1,∣z∣+∣ε∣+r)/r|M'(z+\varepsilon)| \le \max(1, |z|+|\varepsilon|+r)/r and ∣M′′(z+ε)∣≤2max⁡(1,∣z∣+∣ε∣+r)/r2|M''(z+\varepsilon)| \le 2\max(1, |z|+|\varepsilon|+r)/r^2, valid if the disk of radius ∣ε∣+r|\varepsilon| + r around zz avoids the negative real axis (with r≈∣z∣/2r \approx |z|/2).

Higher derivatives. W(z)=1/M(z)=2πK(1−z2)W(z) = 1/M(z) = \frac{2}{\pi} K(1 - z^2) is D-finite. The coefficients of W(z+x)=∑kckxkW(z+x) = \sum_{k} c_k x^k satisfy −2z(z2−1)c2=(3z2−1)c1+zc0-2 z (z^2-1) c_2 = (3z^2-1) c_1 + z c_0 and

−(k+2)(k+3)z(z2−1)ck+3=(k+2)2(3z2−1)ck+2+(3k(k+3)+7)zck+1+(k+1)2ck,-(k+2)(k+3) z (z^2-1) c_{k+3} = (k+2)^2 (3z^2-1) c_{k+2} + (3k(k+3)+7)z c_{k+1} + (k+1)^2 c_{k},

which reduces at z=1z = 1 to −(k+2)2ck+2=(3k(k+3)+7)ck+1+(k+1)2ck-(k+2)^2 c_{k+2} = (3k(k+3)+7) c_{k+1} + (k+1)^2 c_{k}. Given (M(z),M′(z))(M(z), M'(z)), the remaining coefficients follow by the recurrence and one power series inversion.

Complete elliptic integrals#

With MM as above,

K(m)=π2M(1−m),E(m)=(1−m)(2mK′(m)+K(m)),K(m) = \frac{\pi}{2 M(\sqrt{1-m})}, \qquad E(m) = (1-m)\bigl(2m K'(m) + K(m)\bigr),

where K′K' is the derivative; both cost O(log⁡p)O(\log p) square roots (acb_elliptic_k, acb_elliptic_e). The Taylor coefficients of K(m+x)K(m + x) (acb_elliptic_k_jet) satisfy the recurrence of the hypergeometric equation of K=π2 2F1(12,12;1;m)K = \frac{\pi}{2}\,{}_2F_1(\frac12, \frac12; 1; m):

4(k+1)(k+2) m(m−1) ck+2=−(2k+1)2ck−4(k+1)2(2m−1)ck+1.4(k+1)(k+2)\, m(m-1)\, c_{k+2} = -(2k+1)^2 c_k - 4(k+1)^2 (2m-1) c_{k+1}.

The complete integral of the third kind, Π(n,m)\Pi(n, m), is computed with Carlson's integrals, Π(n,m)=RF(0,1−m,1)+n3RJ(0,1−m,1,1−n)\Pi(n, m) = R_F(0, 1-m, 1) + \frac{n}{3} R_J(0, 1-m, 1, 1-n).

Carlson's symmetric integrals#

The symmetric integrals RFR_F, RJR_J (with RCR_C, RDR_D as special cases) and RGR_G are defined on Carlson symmetric integrals. All three Legendre integrals reduce to them on the strip ∣Re⁡ϕ∣≤π/2|\operatorname{Re}\phi| \le \pi/2 [NIST2012, §19.25], and are extended outside it by quasi-periodicity.

Duplication. For λ=xy+yz+zx\lambda = \sqrt{x}\sqrt{y} + \sqrt{y}\sqrt{z} + \sqrt{z}\sqrt{x},

RF(x,y,z)=RF(x+λ4,y+λ4,z+λ4),R_F(x,y,z) = R_F\left(\frac{x+\lambda}{4}, \frac{y+\lambda}{4}, \frac{z+\lambda}{4}\right),

and the differences between the arguments are divided by about 4 at each step, while their mean A=(x+y+z)/3A = (x+y+z)/3 is preserved up to the factor introduced by the step. After jj steps, with X=1−x/AX = 1 - x/A, Y=1−y/AY = 1 - y/A, Z=−X−YZ = -X - Y, the elementary symmetric polynomials E2=XY−Z2E_2 = XY - Z^2 and E3=XYZE_3 = XYZ of the deviations are of order 4−2j4^{-2j} and 4−3j4^{-3j}, and

RF(x,y,z)=A−1/2∑a,b≥0(−1)a (12)a+ba! b! (2(2a+3b)+1)E2aE3b.R_F(x,y,z) = A^{-1/2} \sum_{a, b \ge 0} \frac{(-1)^a \, (\frac12)_{a+b}}{a!\, b!\, (2(2a+3b)+1)} E_2^a E_3^b.

Carlson [Car1995] uses the terms of total degree 2a+3b≤72a + 3b \le 7 and enough duplication steps to make the remainder negligible, which costs O(p)O(p) square roots at precision pp. FLINT instead sums the series up to degree N≈2.1 p0.4N \approx 2.1\,p^{0.4} (real case) or 2.5 p0.42.5\,p^{0.4} (complex case), at most 500, so that only O(p/N)O(p/N) duplication steps are needed [Joh2019]: the iteration stops as soon as (max⁡(∣x−y∣,∣x−z∣)/∣x∣)N<2−p(\max(|x - y|, |x - z|)/|x|)^N < 2^{-p}. The coefficients are computed exactly with a common denominator, the polynomial in E2E_2 is evaluated with precomputed powers and the polynomial in E3E_3 by Horner's rule. The tail is bounded using that the coefficient of Xn1Yn2Zn3X^{n_1} Y^{n_2} Z^{n_3} with n1+n2+n3=nn_1 + n_2 + n_3 = n in the expansion has absolute value at most 2(9/8)n2 (9/8)^n, so that the truncation error is at most 2∑n≥N(98max⁡(∣X∣,∣Y∣,∣Z∣))n2 \sum_{n \ge N} (\tfrac98 \max(|X|, |Y|, |Z|))^n.

RJR_J. The duplication theorem for RJR_J adds a term 6⋅4−jRC(1,1+δj)6 \cdot 4^{-j} R_C(1, 1 + \delta_j) (up to scaling) at each step, and the final Taylor series is in the symmetric polynomials E2,…,E5E_2, \ldots, E_5 of four deviations [Car1995]; RC(1,1+x)=atan⁡(x)/xR_C(1, 1+x) = \operatorname{atan}(\sqrt{x})/\sqrt{x} is computed by acb_elliptic_rc1. The principal square roots in the duplication can cross branch cuts of RJR_J for complex arguments, so the algorithm is only used where it is known to be valid, and otherwise RJR_J is shifted into the right half-plane by numerical integration; see Correctness of the duplication algorithm for RJR_J. For RDR_D the duplication algorithm is valid everywhere.

RGR_G is computed from 2RG(x,y,z)=zRF(x,y,z)−13(x−z)(y−z)RD(x,y,z)+xy/z2R_G(x,y,z) = z R_F(x,y,z) - \frac13 (x-z)(y-z) R_D(x,y,z) + \sqrt{xy/z}.

Weierstrass elliptic functions#

For the lattice Z+τZ\mathbb{Z} + \tau\mathbb{Z} with half-periods 12\frac12 and τ2\frac\tau2, the Weierstrass functions are quotients of theta functions [NIST2012, §23.6]. With θj=θj(0,τ)\theta_j = \theta_j(0, \tau) and θj(z)=θj(z,τ)\theta_j(z) = \theta_j(z, \tau) in the notation of acb_modular,

℘(z,τ)=π2θ22θ32θ42(z)θ12(z)−π23(θ24+θ34),℘′(z,τ)=(−2πη(τ)2θ1(z))3θ2(z)θ3(z)θ4(z),\wp(z, \tau) = \pi^2 \theta_2^2 \theta_3^2 \frac{\theta_4^2(z)}{\theta_1^2(z)} - \frac{\pi^2}{3} (\theta_2^4 + \theta_3^4), \qquad \wp'(z, \tau) = \left(\frac{-2\pi \eta(\tau)^2}{\theta_1(z)}\right)^3 \theta_2(z)\theta_3(z)\theta_4(z),
ζ(z,τ)=2η1z+θ1′(z)θ1(z),σ(z,τ)=eη1z2θ1(z)θ1′(0),η1=−θ1′′′(0)6θ1′(0),\zeta(z, \tau) = 2\eta_1 z + \frac{\theta_1'(z)}{\theta_1(z)}, \qquad \sigma(z, \tau) = e^{\eta_1 z^2} \frac{\theta_1(z)}{\theta_1'(0)}, \qquad \eta_1 = -\frac{\theta_1'''(0)}{6 \theta_1'(0)},

where η(τ)\eta(\tau) is the Dedekind eta function. The lattice roots are e1=π23(θ34+θ44)e_1 = \frac{\pi^2}{3}(\theta_3^4 + \theta_4^4), e2=π23(θ24−θ44)e_2 = \frac{\pi^2}{3}(\theta_2^4 - \theta_4^4) and e3=−π23(θ24+θ34)e_3 = -\frac{\pi^2}{3}(\theta_2^4 + \theta_3^4), the invariants are g2=60G4g_2 = 60 G_4 and g3=140G6g_3 = 140 G_6, and the inverse function is the elliptic integral ℘−1(z)=RF(z−e1,z−e2,z−e3)\wp^{-1}(z) = R_F(z - e_1, z - e_2, z - e_3).

All of these need theta values at one τ\tau, and the theta functions are evaluated after reducing τ\tau to the fundamental domain, so the cost is O(p)O(\sqrt{p}) multiplications for every τ\tau.

Modular forms#

A modular form of weight kk satisfies f(gτ)=(cτ+d)kf(τ)f(g\tau) = (c\tau + d)^k f(\tau) for g=(abcd)∈SL2(Z)g = \begin{pmatrix} a & b \\ c & d\end{pmatrix} \in \mathrm{SL}_2(\mathbb{Z}), so it can be evaluated at the image τ′\tau' of τ\tau in the fundamental domain F={∣Re⁡τ∣≤12,∣τ∣≥1}\mathcal{F} = \{|\operatorname{Re}\tau| \le \frac12, |\tau| \ge 1\}, where Im⁡(τ′)≥3/2\operatorname{Im}(\tau') \ge \sqrt{3}/2 and the qq-series converge geometrically with ratio ∣q∣≤e−π3≈0.0043|q| \le e^{-\pi\sqrt 3} \approx 0.0043 (for q=e2πiτq = e^{2\pi i \tau}).

Algorithm 1: Reduction to the fundamental domain

Input: τ\tau in the upper half-plane, a tolerance ε\varepsilon.

Output: g∈PSL2(Z)g \in \mathrm{PSL}_2(\mathbb{Z}) with gτg\tau in F\mathcal{F} up to ε\varepsilon.

  1. g←1g \gets 1.
  2. Repeat: let nn be the nearest integer to Re⁡(τ)\operatorname{Re}(\tau), τ←τ−n\tau \gets \tau - n and g←T−ngg \gets T^{-n} g; if ∣τ∣2≥1−ε|\tau|^2 \ge 1 - \varepsilon, return gg; otherwise τ←−1/τ\tau \gets -1/\tau and g←Sgg \gets S g.

Each inversion multiplies Im⁡(τ)\operatorname{Im}(\tau) by 1/∣τ∣2>11/|\tau|^2 > 1, which guarantees termination. acb_modular_fundamental_domain_approx runs the algorithm on the midpoint in double arithmetic when possible and in arf arithmetic at the working precision otherwise, and then applies gg to the ball τ\tau once, which does not need to be exact: reducing to ∣τ′∣2≥63/64|\tau'|^2 \ge 63/64 instead of 1 is enough for fast convergence.

Transformation formulas. The eta function transforms as η(gτ)=ε(a,b,c,d)cτ+d η(τ)\eta(g\tau) = \varepsilon(a,b,c,d)\sqrt{c\tau + d}\,\eta(\tau) with a 24th root of unity ε\varepsilon given by Dedekind sums (acb_modular_epsilon_arg), and the four theta functions are permuted with 8th roots of unity and the factors of acb_modular_theta_transform [Rad1973].

qq-series. On F\mathcal{F}, the theta constants and the eta function are lacunary series,

η(τ)=eπiτ/12∑k∈Z(−1)kqk(3k−1)/2,θ3(0,τ)=∑k∈Zq1k2,\eta(\tau) = e^{\pi i \tau/12} \sum_{k \in \mathbb{Z}} (-1)^k q^{k(3k-1)/2}, \qquad \theta_3(0, \tau) = \sum_{k \in \mathbb{Z}} q_1^{k^2},

(with q=e2πiτq = e^{2\pi i\tau} and q1=eπiτq_1 = e^{\pi i\tau}), which need O(p)O(\sqrt{p}) terms. The powers of qq with exponents in the sequence of generalised pentagonal numbers (or squares and pronic numbers) are computed with an addition sequence in which most terms cost one multiplication; Enge, Hart and Johansson [EHJ2016] construct short addition sequences for these exponents (acb_modular_addseq_eta, acb_modular_addseq_theta). For many terms, rectangular splitting is used instead: the series is written as a polynomial in qmq^m for a well-chosen mm such that the exponents modulo mm take few values, which replaces most full multiplications by cheaper additions and scalar operations. Each term is computed at a precision reduced according to its magnitude (_acb_modular_mul).

Forms computed from theta constants. With θj=θj(0,τ)\theta_j = \theta_j(0,\tau) at the reduced point:

j(τ)=32(θ28+θ38+θ48)3(θ2θ3θ4)8,Δ(τ)=η(τ)24=(θ2θ3θ42)8,λ(τ)=θ24θ34,j(\tau) = 32 \frac{(\theta_2^8+\theta_3^8+\theta_4^8)^3}{(\theta_2 \theta_3 \theta_4)^8}, \qquad \Delta(\tau) = \eta(\tau)^{24} = \left(\frac{\theta_2\theta_3\theta_4}{2}\right)^8, \qquad \lambda(\tau) = \frac{\theta_2^4}{\theta_3^4},
G4(τ)=π490(θ28+θ38+θ48),G6(τ)=π6945(θ312+θ412−3θ28(θ34+θ44)),G_4(\tau) = \frac{\pi^4}{90}(\theta_2^8 + \theta_3^8 + \theta_4^8), \qquad G_6(\tau) = \frac{\pi^6}{945}\bigl(\theta_3^{12} + \theta_4^{12} - 3\theta_2^8(\theta_3^4 + \theta_4^4)\bigr),

and the higher Eisenstein series follow from the recurrence (2k+1)(k−3)ck=3∑j=2k−2cjck−j(2k+1)(k-3) c_k = 3 \sum_{j=2}^{k-2} c_j c_{k-j} for ck=(2k−1)G2kc_k = (2k-1) G_{2k} [Apostol1997, Theorem 1.13]. jj is invariant under SL2(Z)\mathrm{SL}_2(\mathbb{Z}) and λ\lambda under Γ(2)\Gamma(2) (for λ\lambda, the transformation of the theta functions is applied).

Class polynomials. The Hilbert class polynomial HDH_D is the product of x−j(τi)x - j(\tau_i) over the CM points τi=(−b+D)/(2a)\tau_i = (-b + \sqrt{D})/(2a) of the reduced forms of discriminant DD. Its coefficients have about π∣D∣∑i1/ai\pi\sqrt{|D|}\sum_i 1/a_i bits; computing the roots to that precision and expanding the product with a binary product tree gives the polynomial with a certificate when every coefficient ball contains a unique integer [Enge2009]. See Hilbert class polynomials.

Use in FLINT#

Referenced from#

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
  • [Dup2006] R. Dupont. "Moyenne arithmético-géométrique, suites de Borchardt et applications." These de doctorat, École polytechnique, Palaiseau (2006). http://www.lix.polytechnique.fr/Labo/Regis.Dupont/these_soutenance.pdf
  • [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).
  • [Rad1973] H. Rademacher, Topics in analytic number theory, Springer, 1973.
  • [EHJ2016] A. Enge, W. Hart and F. Johansson, "Short addition sequences for theta functions", preprint (2016), https://arxiv.org/abs/1608.06810
  • [Apostol1997] Apostol, Tom : Modular functions and Dirichlet series in number theory, Springer (1997)
  • [Enge2009] A. Enge. The complexity of class polynomial computation via floating point approximations. Mathematics of Computation 78 (2009), 1089–1107. https://doi.org/10.1090/S0025-5718-08-02200-X
Cite this page

The FLINT team, “Elliptic integrals, elliptic functions and modular forms,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/special-functions/elliptic-modular.html (generated 2026-11-02).