FLINT3.7.0-dev
Algorithm

Quasi-linear evaluation of theta functions

Cost
O(M(p)log⁡p)O(M(p) \log p) operations at precision pp for theta values at a reduced (z,τ)(z, \tau), for fixed genus gg (the constant grows exponentially with gg); derivatives up to order kk cost about (k+1)g(k+1)^g times as much.

Summing the theta series over an ellipsoid costs O(pg/2)O(p^{g/2}) multiplications at precision pp in genus gg (Summation over ellipsoids). For g=1g = 1, the theta constants can instead be computed with the arithmetic-geometric mean in O(log⁡p)O(\log p) steps, and Dupont [Dup2006], and Labrande and Thomé [LT2016] for g≥2g \ge 2, generalised this to quasi-linear algorithms based on the duplication formulas and Newton's method, which however needed hypotheses on the input (good choices of square roots) and were not uniform in τ\tau. Elkies and Kieffer [EK2025] give an algorithm that is uniform in (z,τ)(z, \tau) for every fixed gg and needs no Newton iteration. It is implemented in acb_theta_ql_exact and used by every evaluation in acb_theta above low precision.

Throughout, (z,τ)(z, \tau) is reduced (Reduction), and the characteristics aa run over {0,1}g\{0,1\}^g with addition modulo 2.

Duplication formulas#

Theorem 1 (Duplication formula). For z,z′∈Cgz, z' \in \mathbb{C}^g, τ∈Hg\tau \in \mathcal{H}_g and a∈{0,1}ga \in \{0,1\}^g,

θa,0(z,τ) θa,0(z′,τ)=∑a′∈{0,1}gθa′,0(z+z′,2τ) θa+a′,0(z−z′,2τ),\theta_{a,0}(z,\tau)\,\theta_{a,0}(z',\tau) = \sum_{a' \in \{0,1\}^g} \theta_{a',0}(z+z',2\tau)\,\theta_{a+a',0}(z-z',2\tau),

and for any bb, θa,b(z,τ)θa,b(z′,τ)=∑a′(−1)a′Tb θa′,0(z+z′,2τ) θa+a′,0(z−z′,2τ)\theta_{a,b}(z,\tau)\theta_{a,b}(z',\tau) = \sum_{a'} (-1)^{a'^T b}\, \theta_{a',0}(z+z',2\tau)\,\theta_{a+a',0}(z-z',2\tau).

Proof. The product is the sum over m,n∈Zg+a2m, n \in \mathbb{Z}^g + \frac a2 of exp⁡(πi(mTτm+nTτn)+2πi(mTz+nTz′))\exp(\pi i (m^T\tau m + n^T \tau n) + 2\pi i (m^T z + n^T z')). Put P=(m+n)/2P = (m+n)/2 and Q=(m−n)/2Q = (m-n)/2. Then mTτm+nTτn=PT(2τ)P+QT(2τ)Qm^T\tau m + n^T\tau n = P^T (2\tau) P + Q^T (2\tau) Q and mTz+nTz′=PT(z+z′)+QT(z−z′)m^T z + n^T z' = P^T(z + z') + Q^T(z - z'). As (m,n)(m, n) runs over (Zg+a2)2(\mathbb{Z}^g + \frac a2)^2, (P,Q)(P, Q) runs exactly once over the pairs with P∈Zg+a′2P \in \mathbb{Z}^g + \frac{a'}2 and Q∈Zg+a+a′2Q \in \mathbb{Z}^g + \frac{a + a'}{2} for some a′a': indeed P−Q=n∈Zg+a2P - Q = n \in \mathbb{Z}^g + \frac a2, and conversely m=P+Qm = P + Q, n=P−Qn = P - Q lie in Zg+a2\mathbb{Z}^g + \frac a2. The sum factors as stated. For the general case, replace zz and z′z' by z+b2z + \frac b2 and z′+b2z' + \frac b2: then z−z′z - z' is unchanged and z+z′z + z' is shifted by bb, which multiplies the term PP by e2πiPTb=(−1)a′Tbe^{2\pi i P^T b} = (-1)^{a'^T b}.

The formula also holds for the normalised functions θ~a,0(z,τ)=e−πyTY−1yθa,0(z,τ)\widetilde\theta_{a,0}(z, \tau) = e^{-\pi y^T Y^{-1} y}\theta_{a,0}(z, \tau), because the normalising factors match on both sides. Three special cases are used:

θa,0(z,τ)2=∑a′θa′,0(2z,2τ) θa+a′,0(0,2τ),θa,0(0,τ) θa,0(z,τ)=∑a′θa′,0(z,2τ) θa+a′,0(z,2τ),θa,0(0,τ)2=∑a′θa′,0(0,2τ) θa+a′,0(0,2τ).\begin{aligned} \theta_{a,0}(z,\tau)^2 &= \sum_{a'} \theta_{a',0}(2z,2\tau)\, \theta_{a+a',0}(0,2\tau), \\ \theta_{a,0}(0,\tau)\,\theta_{a,0}(z,\tau) &= \sum_{a'} \theta_{a',0}(z,2\tau)\, \theta_{a+a',0}(z,2\tau), \\ \theta_{a,0}(0,\tau)^2 &= \sum_{a'} \theta_{a',0}(0,2\tau)\, \theta_{a+a',0}(0,2\tau). \end{aligned}

For g=1g = 1, the third formula and its version with b=1b = 1 give θ0,0(0,τ)2±θ0,1(0,τ)2=2θa,0(0,2τ)2\theta_{0,0}(0,\tau)^2 \pm \theta_{0,1}(0,\tau)^2 = 2\theta_{a,0}(0,2\tau)^2 (with a=0a = 0 for the sign ++ and a=1a = 1 for −-), and the second formula at z=12z = \frac12, where θ0,0(12,τ)=θ0,1(0,τ)\theta_{0,0}(\frac12, \tau) = \theta_{0,1}(0, \tau) and the odd θ1,1(0,2τ)\theta_{1,1}(0, 2\tau) vanishes, gives θ0,1(0,2τ)2=θ0,0(0,τ)θ0,1(0,τ)\theta_{0,1}(0, 2\tau)^2 = \theta_{0,0}(0,\tau)\theta_{0,1}(0,\tau). Hence αn=θ0,0(0,2nτ)2\alpha_n = \theta_{0,0}(0, 2^n\tau)^2 and βn=θ0,1(0,2nτ)2\beta_n = \theta_{0,1}(0, 2^n\tau)^2 satisfy αn+1=(αn+βn)/2\alpha_{n+1} = (\alpha_n + \beta_n)/2 and βn+1=αnβn\beta_{n+1} = \sqrt{\alpha_n \beta_n}: the AGM, read from 2mτ2^m\tau down to τ\tau by taking square roots. In general, each formula is a sum of 2g2^g products, computed for all aa at once by two Hadamard transforms of length 2g2^g and 2g2^g pointwise products (acb_theta_agm_mul, following [LT2016]).

The algorithm for theta constants#

To compute θa,0(0,τ)\theta_{a,0}(0, \tau) for all aa, choose mm with 2m≈p2^m \approx p (more precisely, so that the ellipsoid for 2mτ2^m\tau has O(1)O(1) points: 2mγj2≈p2^m \gamma_j^2 \approx p for the diagonal entries γj\gamma_j of the Cholesky factor of πY\pi Y).

  1. Compute θa,0(0,2mτ)\theta_{a,0}(0, 2^m\tau) for all aa by summation. Since 2mY2^m Y is large, only Og(1)O_g(1) lattice points contribute at precision pp, and the value is about e−2mda2e^{-2^m d_a^2} where dad_a is the distance from 0 to Zg+a2\mathbb{Z}^g + \frac a2.
  2. For k=m−1,…,0k = m - 1, \ldots, 0: apply the third duplication formula to get θa,0(0,2kτ)2\theta_{a,0}(0, 2^k\tau)^2 from the values at 2k+1τ2^{k+1}\tau, and take square roots, choosing the signs with low-precision approximations of θa,0(0,2kτ)\theta_{a,0}(0, 2^k\tau) computed by summation.

The cost is m=O(log⁡p)m = O(\log p) steps of O(2g)O(2^g) multiplications and square roots at precision O(p)O(p), that is O(M(p)log⁡p)O(M(p) \log p), provided the precision loss per step is bounded.

Precision. The values θa,0(0,2kτ)\theta_{a,0}(0, 2^k\tau) for a≠0a \ne 0 are exponentially small. FLINT works with shifted absolute precision: a value of expected magnitude e−d2e^{-d^2} is computed with absolute error e−d22−pe^{-d^2} 2^{-p}. The duplication formula is compatible with this, because by the parallelogram identity the products θa′,0θa+a′,0\theta_{a',0}\theta_{a+a',0} at 2τ2\tau have magnitude at most that of θa,02\theta_{a,0}^2 at τ\tau (see acb_theta_agm_mul_tight, which computes the products on midpoints and adds error bounds of the right shape). Assuming that every ∣θa,0(0,2kτ)∣|\theta_{a,0}(0, 2^k\tau)| is of its expected order of magnitude, the loss is Og(1)O_g(1) bits per step, and the square roots are determined by approximations to Og(1)O_g(1) bits.

Robustness: an auxiliary shift#

The assumption can fail: some θa,0(0,2kτ)\theta_{a,0}(0, 2^k\tau) may be much smaller than expected (for instance, close to a zero of a theta constant), and then a square root cannot be chosen, or precision is lost. The algorithm then introduces a random real vector tt. A real shift does not change the expected magnitudes, and for almost every tt none of the values θa,0(2kt,2kτ)\theta_{a,0}(2^k t, 2^k\tau) and θa,0(2k+1t,2kτ)\theta_{a,0}(2^{k+1} t, 2^k\tau) is abnormally small. At each step, the first duplication formula gives θa,0(2kt,2kτ)\theta_{a,0}(2^k t, 2^k\tau) and θa,0(2k+1t,2kτ)\theta_{a,0}(2^{k+1}t, 2^k\tau) by square roots (from the values at 2k+1τ2^{k+1}\tau of the vectors 0,2k+1t,2k+2t0, 2^{k+1}t, 2^{k+2}t), and the second formula with z=2ktz = 2^k t gives the theta constants θa,0(0,2kτ)\theta_{a,0}(0, 2^k\tau) by divisions, without square roots of small numbers. acb_theta_ql_setup tries a few random vectors tt at low precision, doubling the precision if none works, and determines how many initial steps are easy (need no shift). This makes the algorithm probabilistic, with a negligible probability of failure, in which case the result is indeterminate rather than wrong.

Nonzero zz. For theta values at z≠0z \ne 0, the first formula computes θa,0(2kz,2kτ)\theta_{a,0}(2^k z, 2^k\tau) from the values at (2k+1z,2k+1τ)(2^{k+1}z, 2^{k+1}\tau) and the theta constants, so the algorithm carries the vectors 2kv2^k v for v∈{0,t,2t,z,z+t,z+2t}v \in \{0, t, 2t, z, z+t, z+2t\}, of which zz itself is only needed at the last step. Theta values with nonzero bb are obtained at the last step from the general duplication formula with signs (−1)a′Tb(-1)^{a'^T b}.

Dimension lowering#

If the eigenvalues of YY have very different sizes, doubling τ\tau makes the ellipsoids thin in some directions long before they are thin in others, and the number of duplication steps needed for the largest direction would make the precision loss in the others large. The algorithm then splits the variables: writing τ=(τ0xxTτ1)\tau = \begin{pmatrix} \tau_0 & x \\ x^T & \tau_1 \end{pmatrix} with τ0\tau_0 of size ss and n=(n0,n1)n = (n_0, n_1), the theta series is

θa,0(z,τ)=∑n1∈Zg−s+a1/2eπi(n1Tτ1n1+2n1Tz1) θa0,0(z0+xn1,τ0),\theta_{a,0}(z, \tau) = \sum_{n_1 \in \mathbb{Z}^{g-s} + a_1/2} e^{\pi i (n_1^T \tau_1 n_1 + 2 n_1^T z_1)} \, \theta_{a_0,0}(z_0 + x n_1, \tau_0),

and only the n1n_1 in a small ellipsoid of dimension g−sg - s (with the lower right block of the Cholesky factor) contribute at the required precision. Each term is a theta value in dimension ss at a shifted vector, which is evaluated recursively by the same algorithm for many vectors at once. acb_theta_ql_nb_steps decides, from the diagonal of the Cholesky factor and the precision, how many duplication steps to apply before lowering the dimension at each level (a vector called the pattern). acb_theta_ql_lower_dim and acb_theta_ql_recombine perform the split and the recombination, and acb_theta_ql_exact runs the whole recursion. The effect is that every summation and every duplication step works at precision O(p)O(p) on ellipsoids with O(1)O(1) points, which keeps the algorithm quasi-linear uniformly in τ\tau.

The algorithm#

Algorithm 1: Theta values at a reduced point (acb_theta_ql_exact)

Input: exact reduced (zi,τ)(z_i, \tau), i=1,…,nbi = 1, \ldots, \mathit{nb}, with z1=0z_1 = 0; a pattern from acb_theta_ql_nb_steps; precision pp.

Output: θ~a,0(zi,τ)\widetilde\theta_{a,0}(z_i, \tau) for all aa (or all θ~a,b\widetilde\theta_{a,b}).

  1. Let mm be the number of duplication steps of the pattern. If m=0m = 0, sum the series and return.
  2. With acb_theta_ql_setup, compute low-precision approximations of all the values whose square roots will be taken, choose the auxiliary vector tt if needed, and estimate the precision loss ℓ\ell.
  3. Compute the theta values at 2mτ2^m\tau for the vectors 2mv2^m v at precision p+ℓp + \ell: by summation, or, if the pattern says so, by dimension lowering and a recursive call.
  4. For k=m−1,…,0k = m - 1, \ldots, 0, apply the duplication formulas (acb_theta_agm_mul_tight), taking square roots with acb_theta_agm_sqrt guided by the approximations, or divisions by the shifted values.
  5. At k=0k = 0, compute the requested values (with the general formula for b≠0b \ne 0).

The main function acb_theta_jet reduces (z,τ)(z, \tau), uses θ0,0(z,τ)=∑aθa,0(2z,4τ)\theta_{0,0}(z, \tau) = \sum_a \theta_{a,0}(2z, 4\tau) when only one value is needed, and θa,b(z,τ)2=∑a′(−1)a′Tbθa′,0(0,2τ)θa+a′,0(2z,2τ)\theta_{a,b}(z,\tau)^2 = \sum_{a'}(-1)^{a'^T b}\theta_{a',0}(0, 2\tau)\theta_{a+a',0}(2z, 2\tau) when the squares of all values are requested, so that the quasi-linear algorithm only ever computes the 2g2^g functions θa,0\theta_{a,0}.

Derivatives#

Partial derivatives with respect to zz up to total order kk are computed from values (acb_theta_ql_jet_fd). Let ζ\zeta be a primitive (k+1)(k+1)-th root of unity, ε>0\varepsilon > 0, and hn=(εζn0,…,εζng−1)h_n = (\varepsilon\zeta^{n_0}, \ldots, \varepsilon\zeta^{n_{g-1}}) for n∈{0,…,k}gn \in \{0, \ldots, k\}^g. If θ(z+h)=∑j≥0cjhj\theta(z + h) = \sum_{j \ge 0} c_j h^j (multi-index notation), a discrete Fourier transform in each coordinate gives

∑nζ−qTnθ(z+hn)=(k+1)g∑j≡q mod (k+1)cjε∣j∣,\sum_{n} \zeta^{-q^T n} \theta(z + h_n) = (k+1)^g \sum_{j \equiv q \bmod (k+1)} c_j \varepsilon^{|j|},

which is cqε∣q∣c_q \varepsilon^{|q|} plus terms of order ε∣q∣+k+1\varepsilon^{|q| + k + 1}. If ∣θ∣≤c|\theta| \le c on the polydisc of radius ρ\rho around zz, Cauchy's estimate bounds those terms, and the error of cqc_q is at most 2cg εk+1/ρk+1+∣q∣2cg\,\varepsilon^{k+1}/\rho^{k+1+|q|}. acb_theta_ql_local_bound gives cc and ρ\rho from the Cholesky factor and yy; ε\varepsilon is chosen so that this error is 2−p2^{-p}, and the precision of the (k+1)g(k+1)^g evaluations is raised to compensate for the division by ε∣q∣\varepsilon^{|q|}. The evaluations are made at the midpoints of (z,τ)(z, \tau), and the effect of the input radii is added with acb_theta_ql_jet_error, which bounds the variation of the derivatives over the input balls with derivatives of order k+2k + 2 (computed cheaply at low precision) and the heat equation. The total cost is quasi-linear in p(k+1)gp (k+1)^g. At low precision, direct summation of the differentiated series is faster, and acb_theta_ql_jet chooses between the two.

Use in FLINT#

Referenced from#

References#

  • [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
  • [LT2016] H. Labrande and E. Thomé, "Computing theta functions in quasi-linear time in genus 2 and above", ANTS XII, Kaiserslautern, LMS J. Comp. Math 19 (2016), 163–177. https://doi.org/10.1112/S1461157016000309
  • [EK2025] N. D. Elkies and J. Kieffer, "A uniform quasi-linear time algorithm for evaluating theta functions in any dimension", in preparation.
Cite this page

The FLINT team, “Quasi-linear evaluation of theta functions,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/special-functions/theta-quasi-linear.html (generated 2026-11-02).