FLINT3.7.0-dev

_mp_real_neglog_agm, _mp_real_neglog_agm_tune

Synopsis#include <flint/mp_real.h>
void _mp_real_neglog_agm(nn_ptr y, ulong * err, nn_srcptr x, slong n)source
void _mp_real_neglog_agm_tune(nn_ptr y, ulong * err, nn_srcptr x, slong n, slong N)source

Set (y, n) to -\log x for (x, n) in [1/2, 1) by the Sasaki–Kanada AGM formula [SK1982]; err is computed at run time and at most 2. The second function takes the number N of terms of the theta series (0 for the default, 4).

With r = x 2^{-e} and q = r^4,

-\log x = \frac{\pi/4}{\operatorname{agm}(4 r^2 S_2^2, \theta_3^2)} - e \log 2, \qquad \theta_3 = 1 + 2\sum_{k \ge 1} q^{k^2}, \quad S_2 = 1 + \sum_{k \ge 1} q^{k(k+1)},

with \pi/4 and \log 2 from the shared caches and the shift e = \lceil p/(4(N + 1)^2) \rceil for p bits. The cost is O(M(n) \log n) against the O(M(n) \log^2 n) of _mp_real_neglog_newton; with warm caches the two cross over near 7 \cdot 10^5 limbs, and against the table-free exponential the AGM is faster from about 20000 limbs. mp_real_exp_agm uses it.

References#

  • [SK1982] T. Sasaki and Y. Kanada. Practically fast multiple-precision evaluation of log(x). Journal of Information Processing 5:4 (1982), 247–250.
Cite this page

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