acb_modular.h
#include <flint/acb_modular.h>This module evaluates modular forms and the Jacobi theta functions of a variable in the upper half-plane with rigorous error bounds: the theta functions and their derivatives, the Dedekind eta function, Klein's -invariant, the modular lambda function, the discriminant and the Eisenstein series. It also provides arithmetic in the modular group , reduction to the fundamental domain, and Hilbert class polynomials.
Every evaluation first moves to (or close to) the fundamental domain with a modular transformation, so that and with , and then sums a -series with an addition sequence or rectangular splitting [EHJ2016]. At precision this needs terms, and the cost does not depend on how close 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.
Conventions#
- is a complex ball, normally in . If the ball for is not certainly in the upper half-plane (it touches the real line), functions defined only on return balls with infinite radius or indeterminate values. The same holds for the summation functions that take and require .
- The variable is for modular forms (
acb_modular_eta_sum) and 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 multiplied by : here , so the period in is 1, and derivatives are taken with respect to this .
- Outputs may alias inputs unless stated otherwise.
The modular group#
void psl2z_swap(psl2z_t f, 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)int psl2z_is_correct(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 (, , and if ).
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.
Set h to the product , respectively the inverse , in canonical form. Aliasing is allowed.
void psl2z_randtest(psl2z_t g, flint_rand_t state, slong bits)Sets g to a random element with entries of at most about bits bits (at least 1): random and 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 acting on is . The functions below find a transformation that maps a point to the domain, up to a tolerance ; an approximate reduction is enough for evaluation, since points slightly outside the domain still have bounded well below 1. All evaluation functions of this module use .
void acb_modular_transform(acb_t w, const psl2z_t g, const acb_t z, slong prec)Sets w to .
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 (with ) 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 , but it is not guaranteed to reduce the point; the caller must check the result.
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 evaluated in ball arithmetic. The output g is always valid, but the caller must check that w is close enough to the domain.
int acb_modular_is_in_fundamental_domain(const acb_t z, const arf_t tol, slong prec)Returns nonzero if it is certain that and , where is tol, and zero if this is false or cannot be decided.
Jacobi theta functions#
The four Jacobi theta functions are
where and . Many authors write for , but the principal fourth root differs from in general, so this module writes only for integer . In the notation of acb_theta, . 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 . acb_modular_theta moves to the fundamental domain, reduces modulo the transformed lattice when its imaginary part is large, and calls acb_modular_theta_sum. The notransform version sums the series at directly, which is only efficient when is not small.
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 at , so that entry is , with derivatives with respect to . The notransform version does not move to the fundamental domain or reduce .
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 truncated to length len, for a power series , by composing the theta jets with the nonconstant part of . Any of the outputs may be NULL, in which case that function is not stored.
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 .
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 through theta functions at : integers , (arrays of length 4) and such that for
where and if , and if
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 Taylor coefficients of , , and , given and , by summing truncated theta series with a rigorous bound for the tail. A nonzero w_is_unit asserts that (real ). Aliasing between inputs and outputs is not allowed.
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), : entry of exponents is the -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 , and from without a modular transformation. The basecase and rs versions sum the truncated series , and over the with exponent less than , with a short addition sequence and with rectangular splitting respectively [EHJ2016], without a tail bound. acb_modular_theta_const_sum chooses from and prec, uses the basecase for 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 , by moving to the fundamental domain, summing the pentagonal number series with acb_modular_eta_sum, and applying the transformation formula.
int acb_modular_epsilon_arg(const psl2z_t g)Given , returns an integer such that is the 24th root of unity in the transformation formula of the eta function,
void acb_modular_eta_sum(acb_t eta, const acb_t q, slong prec)Sets eta to , the eta function without the factor , given , by summing the pentagonal number series with a rigorous tail bound. Like acb_modular_theta_sum, it is meant for . 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), , in the format of acb_modular_addseq_theta.
Modular forms and functions#
The functions below move to the fundamental domain, compute the theta constants at with acb_modular_theta_const_sum, and apply the transformation law of the form. When is a multiple of 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 -invariant, normalised so that , computed on the fundamental domain as with . The output is indeterminate unless is certainly positive.
void acb_modular_lambda(acb_t r, const acb_t tau, slong prec)Sets r to the modular lambda function , which is invariant under the subgroup of transformations with odd and even.
void acb_modular_delta(acb_t z, const acb_t tau, slong prec)Sets z to the modular discriminant , computed as , which transforms as . The discriminant is sometimes defined with an extra factor , 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 , where
and are computed from theta constants on the fundamental domain, the others by the convolution recurrence of [Apostol1997, Theorem 1.13].
MoreHilbert class polynomials#
void acb_modular_hilbert_class_poly(fmpz_poly_t res, slong D)Sets res to the Hilbert class polynomial of the negative discriminant , the minimal polynomial over of at a CM point of discriminant . If or , res is set to the zero polynomial. See Hilbert class polynomials.
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)Call acb_elliptic_k, acb_elliptic_k_jet, acb_elliptic_e, acb_elliptic_p and acb_elliptic_p_jet respectively.
Internal functions#
void acb_modular_fill_addseq(slong * tab, slong len)Builds an addition sequence for a set of integers that is assumed to be fairly dense. On input, entry of tab is if is to be part of the sequence and 0 otherwise; on output, a marked entry holds a value such that and 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 at precision wprec, first rounding the inputs to wprec bits (using the temporaries tmp1, tmp2) when prec exceeds 1024. Used for the powers of 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)
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).
@misc{flint-doc-acb-modular-index,
author = {{The FLINT team}},
title = {{acb\_modular.h (module overview)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/acb_modular/index.html},
note = {Generated 2026-11-02}
}