FLINT3.7.0-dev
Module · 48 functions

acb_modular.h

#include <flint/acb_modular.h>

This module evaluates modular forms and the Jacobi theta functions of a variable τ\tau in the upper half-plane H={τ∈C:Im⁡(τ)>0}\mathbb{H} = \{\tau \in \mathbb{C} : \operatorname{Im}(\tau) > 0\} with rigorous error bounds: the theta functions θ1,…,θ4\theta_1, \ldots, \theta_4 and their derivatives, the Dedekind eta function, Klein's jj-invariant, the modular lambda function, the discriminant Δ\Delta and the Eisenstein series. It also provides arithmetic in the modular group PSL2(Z)\mathrm{PSL}_2(\mathbb{Z}), reduction to the fundamental domain, and Hilbert class polynomials.

Every evaluation first moves τ\tau to (or close to) the fundamental domain with a modular transformation, so that Im⁡(τ)≥3/2\operatorname{Im}(\tau) \ge \sqrt3/2 and ∣q∣≤e−π3/2≈0.066|q| \le e^{-\pi\sqrt3/2} \approx 0.066 with q=eπiτq = e^{\pi i \tau}, and then sums a qq-series with an addition sequence or rectangular splitting [EHJ2016]. At precision pp this needs O(p)O(\sqrt{p}) terms, and the cost does not depend on how close τ\tau was to the real line. The algorithms are described in Elliptic integrals, elliptic functions and modular forms and Theta functions; see also [Joh2019]. Theta functions in any genus are in acb_theta, elliptic functions and integrals in acb_elliptic.

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#

  • τ\tau is a complex ball, normally in H\mathbb{H}. If the ball for τ\tau is not certainly in the upper half-plane (it touches the real line), functions defined only on H\mathbb{H} return balls with infinite radius or indeterminate values. The same holds for the summation functions that take qq and require ∣q∣<1|q| < 1.
  • The variable qq is e2πiτe^{2\pi i \tau} for modular forms (acb_modular_eta_sum) and eπiτe^{\pi i \tau} for theta functions (acb_modular_theta_sum, acb_modular_theta_const_sum); each function says which.
  • The theta functions are those of Jacobi theta functions and [NIST2012, §20.2], with the variable zz multiplied by π\pi: here θ3(z,τ)=∑n∈Zeπi(n2τ+2nz)\theta_3(z, \tau) = \sum_{n \in \mathbb{Z}} e^{\pi i (n^2 \tau + 2nz)}, so the period in zz is 1, and derivatives are taken with respect to this zz.
  • Outputs may alias inputs unless stated otherwise.

The modular group#

An element of the modular group PSL2(Z)\mathrm{PSL}_2(\mathbb{Z}), stored as an integer matrix (abcd)\begin{pmatrix} a & b \\ c & d \end{pmatrix} with ad−bc=1ad - bc = 1, in the canonical form c≥0c \ge 0, and d>0d > 0 if c=0c = 0. The members a, b, c, d are of type fmpz. A psl2z_t is an array of length 1, so that it is passed by reference.

Initialise g to the identity, and free it.

void psl2z_set(psl2z_t f, const psl2z_t g)

Swap f and g, set f to a copy of g, and set g to the identity.

int psl2z_is_one(const psl2z_t g)
int psl2z_equal(const psl2z_t f, const psl2z_t g)

Return whether g is the identity, whether f and g are equal, and whether g is a valid element in canonical form (ad−bc=1ad - bc = 1, c≥0c \ge 0, and d>0d > 0 if c=0c = 0).

void psl2z_print(const psl2z_t g)
void psl2z_fprint(FILE * file, const psl2z_t g)

Print g as [a b; c d] to standard output or to file.

void psl2z_mul(psl2z_t h, const psl2z_t f, const psl2z_t g)
void psl2z_inv(psl2z_t h, const psl2z_t g)

Set h to the product fgfg, respectively the inverse g−1g^{-1}, in canonical form. Aliasing is allowed.

Sets g to a random element with entries of at most about bits bits (at least 1): random aa and dd are divided by their GCD, completed with Bézout coefficients, and the signs are canonicalised.

Modular transformations and the fundamental domain#

The standard fundamental domain of PSL2(Z)\mathrm{PSL}_2(\mathbb{Z}) acting on H\mathbb{H} is {τ:∣Re⁡(τ)∣≤1/2,∣τ∣≥1}\{\tau : |\operatorname{Re}(\tau)| \le 1/2, |\tau| \ge 1\}. The functions below find a transformation that maps a point to the domain, up to a tolerance ε\varepsilon; an approximate reduction is enough for evaluation, since points slightly outside the domain still have ∣q∣|q| bounded well below 1. All evaluation functions of this module use 1−ε=63/641 - \varepsilon = 63/64.

void acb_modular_transform(acb_t w, const psl2z_t g, const acb_t z, slong prec)

Sets w to gz=(az+b)/(cz+d)gz = (az + b)/(cz + d).

void acb_modular_fundamental_domain_approx_d(psl2z_t g, double x, double y, double one_minus_eps)
void acb_modular_fundamental_domain_approx_arf(psl2z_t g, const arf_t x, const arf_t y, const arf_t one_minus_eps, slong prec)

Set g to a transformation that should map x+yix + yi (with y>0y > 0) to the fundamental domain or just outside it, by the classical reduction algorithm in double or arf arithmetic at precision prec. The output is always a valid element of PSL2(Z)\mathrm{PSL}_2(\mathbb{Z}), but it is not guaranteed to reduce the point; the caller must check the result.

More
void acb_modular_fundamental_domain_approx(acb_t w, psl2z_t g, const acb_t z, const arf_t one_minus_eps, slong prec)

Sets g to a transformation that should map the midpoint of z to the fundamental domain or just outside it, and w to gzgz evaluated in ball arithmetic. The output g is always valid, but the caller must check that w is close enough to the domain.

More

Returns nonzero if it is certain that ∣Re⁡(z)∣≤1/2+ε|\operatorname{Re}(z)| \le 1/2 + \varepsilon and ∣z∣≥1−ε|z| \ge 1 - \varepsilon, where ε\varepsilon is tol, and zero if this is false or cannot be decided.

Jacobi theta functions#

The four Jacobi theta functions are

θ1(z,τ)=−i∑n=−∞∞(−1)neπi[(n+1/2)2τ+(2n+1)z]=2q1/4∑n=0∞(−1)nqn(n+1)sin⁡((2n+1)πz),θ2(z,τ)=∑n=−∞∞eπi[(n+1/2)2τ+(2n+1)z]=2q1/4∑n=0∞qn(n+1)cos⁡((2n+1)πz),θ3(z,τ)=∑n=−∞∞eπi[n2τ+2nz]=1+2∑n=1∞qn2cos⁡(2nπz),θ4(z,τ)=∑n=−∞∞(−1)neπi[n2τ+2nz]=1+2∑n=1∞(−1)nqn2cos⁡(2nπz),\begin{aligned} \theta_1(z,\tau) &= -i \sum_{n=-\infty}^{\infty} (-1)^n e^{\pi i [(n + 1/2)^2 \tau + (2n + 1) z]} = 2 q_{1/4} \sum_{n=0}^{\infty} (-1)^n q^{n(n+1)} \sin((2n+1) \pi z), \\ \theta_2(z,\tau) &= \sum_{n=-\infty}^{\infty} e^{\pi i [(n + 1/2)^2 \tau + (2n + 1) z]} = 2 q_{1/4} \sum_{n=0}^{\infty} q^{n(n+1)} \cos((2n+1) \pi z), \\ \theta_3(z,\tau) &= \sum_{n=-\infty}^{\infty} e^{\pi i [n^2 \tau + 2n z]} = 1 + 2 \sum_{n=1}^{\infty} q^{n^2} \cos(2n \pi z), \\ \theta_4(z,\tau) &= \sum_{n=-\infty}^{\infty} (-1)^n e^{\pi i [n^2 \tau + 2n z]} = 1 + 2 \sum_{n=1}^{\infty} (-1)^n q^{n^2} \cos(2n \pi z), \end{aligned}

where q=eπiτq = e^{\pi i \tau} and q1/4=eπiτ/4q_{1/4} = e^{\pi i \tau / 4}. Many authors write q1/4q^{1/4} for q1/4q_{1/4}, but the principal fourth root (q)1/4(q)^{1/4} differs from q1/4q_{1/4} in general, so this module writes qkq^k only for integer kk. In the notation of acb_theta, (θ0,0,θ0,1,θ1,0,θ1,1)=(θ3,θ4,θ2,−θ1)(\theta_{0,0}, \theta_{0,1}, \theta_{1,0}, \theta_{1,1}) = (\theta_3, \theta_4, \theta_2, -\theta_1). Evaluating Jacobi theta functions explains how the functions below are evaluated and gives an example.

void acb_modular_theta(acb_t theta1, acb_t theta2, acb_t theta3, acb_t theta4, const acb_t z, const acb_t tau, slong prec)
void acb_modular_theta_notransform(acb_t theta1, acb_t theta2, acb_t theta3, acb_t theta4, const acb_t z, const acb_t tau, slong prec)

Set theta1, ..., theta4 to θ1(z,τ),…,θ4(z,τ)\theta_1(z, \tau), \ldots, \theta_4(z, \tau). acb_modular_theta moves τ\tau to the fundamental domain, reduces zz modulo the transformed lattice when its imaginary part is large, and calls acb_modular_theta_sum. The notransform version sums the series at τ\tau directly, which is only efficient when Im⁡(τ)\operatorname{Im}(\tau) is not small.

Full documentation
void acb_modular_theta_jet(acb_ptr theta1, acb_ptr theta2, acb_ptr theta3, acb_ptr theta4, const acb_t z, const acb_t tau, slong len, slong prec)
void acb_modular_theta_jet_notransform(acb_ptr theta1, acb_ptr theta2, acb_ptr theta3, acb_ptr theta4, const acb_t z, const acb_t tau, slong len, slong prec)

Set each output vector to the first len Taylor coefficients of θi(z+x,τ)\theta_i(z + x, \tau) at x=0x = 0, so that entry kk is θi(k)(z,τ)/k!\theta_i^{(k)}(z, \tau)/k!, with derivatives with respect to zz. The notransform version does not move τ\tau to the fundamental domain or reduce zz.

Full documentation
void _acb_modular_theta_series(acb_ptr theta1, acb_ptr theta2, acb_ptr theta3, acb_ptr theta4, acb_srcptr z, slong zlen, const acb_t tau, slong len, slong prec)
void acb_modular_theta_series(acb_poly_t theta1, acb_poly_t theta2, acb_poly_t theta3, acb_poly_t theta4, const acb_poly_t z, const acb_t tau, slong len, slong prec)

Set the outputs to θi(z(x),τ)\theta_i(z(x), \tau) truncated to length len, for a power series z(x)z(x), by composing the theta jets with the nonconstant part of zz. Any of the outputs may be NULL, in which case that function is not stored.

Full documentation

Theta transformations and summation#

These are the building blocks of the theta function evaluation. They are documented for users who want to sum the series directly, for example to avoid recomputing qq.

void acb_modular_theta_transform(int * R, int * S, int * C, const psl2z_t g)

Computes the data of the transformation formula expressing theta functions at τ\tau through theta functions at τ′=gτ\tau' = g\tau: integers RiR_i, SiS_i (arrays of length 4) and C∈{0,1}C \in \{0, 1\} such that for i=0,1,2,3i = 0, 1, 2, 3

θ1+i(z,τ)=eπiRi/4⋅A⋅B⋅θ1+Si(z′,τ′),\theta_{1+i}(z,\tau) = e^{\pi i R_i / 4} \cdot A \cdot B \cdot \theta_{1+S_i}(z',\tau'),

where z′=zz' = z and A=B=1A = B = 1 if C=0C = 0, and if C=1C = 1

z′=−zcτ+d,A=icτ+d,B=exp⁡(−πicz2cτ+d).z' = \frac{-z}{c \tau + d}, \quad A = \sqrt{\frac{i}{c \tau + d}}, \quad B = \exp\left(-\pi i c \frac{z^2}{c \tau + d}\right).
More
void acb_modular_theta_sum(acb_ptr theta1, acb_ptr theta2, acb_ptr theta3, acb_ptr theta4, const acb_t w, int w_is_unit, const acb_t q, slong len, slong prec)

Sets the outputs to the first len ≥1\ge 1 Taylor coefficients of θ1(z+x,τ)/q1/4\theta_1(z+x,\tau)/q_{1/4}, θ2(z+x,τ)/q1/4\theta_2(z+x,\tau)/q_{1/4}, θ3(z+x,τ)\theta_3(z+x,\tau) and θ4(z+x,τ)\theta_4(z+x,\tau), given w=eπizw = e^{\pi i z} and q=eπiτq = e^{\pi i \tau}, by summing truncated theta series with a rigorous bound for the tail. A nonzero w_is_unit asserts that ∣w∣=1|w| = 1 (real zz). Aliasing between inputs and outputs is not allowed.

More
void acb_modular_addseq_theta(slong * exponents, slong * aindex, slong * bindex, slong num)

Constructs an addition sequence for the first num squares and pronic numbers interleaved (excluding zero), 1,2,4,6,9,12,16,20,25,30,…1, 2, 4, 6, 9, 12, 16, 20, 25, 30, \ldots: entry kk of exponents is the kk-th number, and it equals the sum of the entries at aindex[k] and bindex[k], or twice the first plus the second.

void acb_modular_theta_const_sum(acb_t theta2, acb_t theta3, acb_t theta4, const acb_t q, slong prec)
void acb_modular_theta_const_sum_basecase(acb_t theta2, acb_t theta3, acb_t theta4, const acb_t q, slong N, slong prec)
void acb_modular_theta_const_sum_rs(acb_t theta2, acb_t theta3, acb_t theta4, const acb_t q, slong N, slong prec)

Compute the theta constants θ2(0,τ)/q1/4\theta_2(0, \tau)/q_{1/4}, θ3(0,τ)\theta_3(0, \tau) and θ4(0,τ)\theta_4(0, \tau) from q=eπiτq = e^{\pi i \tau} without a modular transformation. The basecase and rs versions sum the truncated series ∑qk(k+1)\sum q^{k(k+1)}, ∑qk2\sum q^{k^2} and ∑(−1)kqk2\sum (-1)^k q^{k^2} over the k∈Zk \in \mathbb{Z} with exponent less than NN, with a short addition sequence and with rectangular splitting respectively [EHJ2016], without a tail bound. acb_modular_theta_const_sum chooses NN from ∣q∣|q| and prec, uses the basecase for N<1800N < 1800 and adds the truncation error.

The Dedekind eta function#

void acb_modular_eta(acb_t z, const acb_t tau, slong prec)

Sets z to the Dedekind eta function η(τ)=eπiτ/12∏n≥1(1−e2πinτ)\eta(\tau) = e^{\pi i \tau/12} \prod_{n \ge 1} (1 - e^{2\pi i n\tau}), by moving τ\tau to the fundamental domain, summing the pentagonal number series with acb_modular_eta_sum, and applying the transformation formula.

Given g=(a,b;c,d)g = (a, b; c, d), returns an integer RR such that ε(a,b,c,d)=eπiR/12\varepsilon(a,b,c,d) = e^{\pi i R / 12} is the 24th root of unity in the transformation formula of the eta function,

η(aτ+bcτ+d)=ε(a,b,c,d)cτ+d η(τ).\eta\left(\frac{a\tau+b}{c\tau+d}\right) = \varepsilon(a,b,c,d) \sqrt{c\tau+d} \, \eta(\tau).
void acb_modular_eta_sum(acb_t eta, const acb_t q, slong prec)

Sets eta to ∏n≥1(1−qn)=∑k∈Z(−1)kqk(3k−1)/2\prod_{n \ge 1} (1 - q^n) = \sum_{k \in \mathbb{Z}} (-1)^k q^{k(3k-1)/2}, the eta function without the factor eπiτ/12e^{\pi i \tau / 12}, given q=e2πiτq = e^{2\pi i \tau}, by summing the pentagonal number series with a rigorous tail bound. Like acb_modular_theta_sum, it is meant for ∣q∣≪1|q| \ll 1. The series is summed with a short addition sequence, or with rectangular splitting from 400 terms [EHJ2016].

void acb_modular_addseq_eta(slong * exponents, slong * aindex, slong * bindex, slong num)

Constructs an addition sequence for the first num generalised pentagonal numbers (excluding zero), 1,2,5,7,12,15,22,26,35,40,…1, 2, 5, 7, 12, 15, 22, 26, 35, 40, \ldots, in the format of acb_modular_addseq_theta.

Modular forms and functions#

The functions below move τ\tau to the fundamental domain, compute the theta constants θ2,θ3,θ4\theta_2, \theta_3, \theta_4 at z=0z = 0 with acb_modular_theta_const_sum, and apply the transformation law of the form. When Re⁡(τ)\operatorname{Re}(\tau) is a multiple of 1/21/2 and the value is real, the imaginary part of the output is set to exactly zero.

void acb_modular_j(acb_t z, const acb_t tau, slong prec)

Sets z to Klein's jj-invariant, normalised so that j(i)=1728j(i) = 1728, computed on the fundamental domain as j(τ)=32(θ28+θ38+θ48)3/(θ2θ3θ4)8j(\tau) = 32 (\theta_2^8+\theta_3^8+\theta_4^8)^3 / (\theta_2 \theta_3 \theta_4)^8 with θi=θi(0,τ)\theta_i = \theta_i(0, \tau). The output is indeterminate unless Im⁡(τ)\operatorname{Im}(\tau) is certainly positive.

void acb_modular_lambda(acb_t r, const acb_t tau, slong prec)

Sets r to the modular lambda function λ(τ)=θ24(0,τ)/θ34(0,τ)\lambda(\tau) = \theta_2^4(0,\tau) / \theta_3^4(0,\tau), which is invariant under the subgroup Γ(2)\Gamma(2) of transformations (a,b;c,d)(a, b; c, d) with a,da, d odd and b,cb, c even.

void acb_modular_delta(acb_t z, const acb_t tau, slong prec)

Sets z to the modular discriminant Δ(τ)=η(τ)24\Delta(\tau) = \eta(\tau)^{24}, computed as (θ2θ3θ4/2)8(\theta_2 \theta_3 \theta_4 / 2)^8, which transforms as Δ(gτ)=(cτ+d)12Δ(τ)\Delta(g\tau) = (c\tau+d)^{12} \Delta(\tau). The discriminant is sometimes defined with an extra factor (2π)12(2\pi)^{12}, which is omitted here.

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

Sets the len entries of r to the Eisenstein series G4(τ),G6(τ),G8(τ),…G_4(\tau), G_6(\tau), G_8(\tau), \ldots, where

G2k(τ)=∑(m,n)≠(0,0)1(m+nτ)2k,G2k(aτ+bcτ+d)=(cτ+d)2kG2k(τ).G_{2k}(\tau) = \sum_{(m, n) \ne (0, 0)} \frac{1}{(m+n\tau )^{2k}}, \qquad G_{2k}\left(\frac{a\tau+b}{c\tau+d}\right) = (c\tau+d)^{2k} G_{2k}(\tau).

G4G_4 and G6G_6 are computed from theta constants on the fundamental domain, the others by the convolution recurrence of [Apostol1997, Theorem 1.13].

More

Hilbert class polynomials#

Sets res to the Hilbert class polynomial HDH_D of the negative discriminant DD, the minimal polynomial over Q\mathbb{Q} of jj at a CM point of discriminant DD. If D≥0D \ge 0 or D≡2,3(mod4)D \equiv 2, 3 \pmod 4, res is set to the zero polynomial. See Hilbert class polynomials.

Full documentation

Elliptic integrals and functions#

These wrappers are kept for backwards compatibility; use the functions of acb_elliptic instead.

void acb_modular_elliptic_k(acb_t k, const acb_t m, slong prec)
void acb_modular_elliptic_k_cpx(acb_ptr w, const acb_t m, slong len, slong prec)
void acb_modular_elliptic_e(acb_t res, const acb_t m, slong prec)
void acb_modular_elliptic_p(acb_t r, const acb_t z, const acb_t tau, slong prec)
void acb_modular_elliptic_p_zpx(acb_ptr r, const acb_t z, const acb_t tau, slong len, slong prec)

Internal functions#

Builds an addition sequence for a set of integers that is assumed to be fairly dense. On input, entry ii of tab is −1-1 if ii is to be part of the sequence and 0 otherwise; on output, a marked entry ii holds a value jj such that jj and i−ji - j are also in the sequence (doubling is preferred). Entries 0 and 1 are ignored; 1 is always assumed to be in the sequence.

void _acb_modular_mul(acb_t z, acb_t tmp1, acb_t tmp2, const acb_t x, const acb_t y, slong wprec, slong prec)

Sets z to xyxy at precision wprec, first rounding the inputs to wprec bits (using the temporaries tmp1, tmp2) when prec exceeds 1024. Used for the powers of qq in the series summation, where terms of small magnitude need less precision.

References#

  • [EHJ2016] A. Enge, W. Hart and F. Johansson, "Short addition sequences for theta functions", preprint (2016), https://arxiv.org/abs/1608.06810
  • [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/
  • [Apostol1997] Apostol, Tom : Modular functions and Dirichlet series in number theory, Springer (1997)
Cite this page

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