FLINT3.7.0-dev

mp_real_agm, _mp_real_agm_order

Synopsis#include <flint/mp_real.h>
void mp_real_agm(mp_real_t res, const mp_real_t x, const mp_real_t y, slong n)source
void _mp_real_agm_order(mp_real_t res, const mp_real_t x, const mp_real_t y, slong n, int m)source

Set res to the arithmetic-geometric mean \operatorname{agm}(x, y) of x, y \ge 0 to about n limbs; throws for a negative midpoint. The second function takes the order m of the final series (at most 16, 10 on 32-bit machines; 0 for the default).

The iteration a' = (a + b)/2, b' = \sqrt{ab} runs in ball arithmetic until z = (a - b)/(a + b) satisfies z^2 < 2^{-p/m} for p bits, and is finished by

\operatorname{agm}(a, b) = \frac{(a + b)/2}{{}_2F_1(\tfrac12, \tfrac12; 1; z^2)}, \qquad \frac{1}{{}_2F_1(\tfrac12, \tfrac12; 1; t)} = 1 - \sum_{j \ge 1} c_j t^j.

The c_j are positive dyadic rationals summing to 1 (the reciprocal vanishes at t = 1; positivity follows from the log-convexity of the coefficients of {}_2F_1 by Kaluza's theorem), so the tail after t^{m-1} is below t^m. The default m is 8 below 1024 limbs and 12 above. When a - b no longer determines its own size, or a + b or ab is too wide for the division and the square root, the result is the enclosure (a + b)/2 \pm |a - b|/2, valid because b \le \operatorname{agm}(a, b) \le a. The working set is four numbers of n limbs.

Cite this page

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