mp_real_agm, _mp_real_agm_order
#include <flint/mp_real.h>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
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.
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).
@misc{flint-doc-mp-real-mp-real-agm,
author = {{The FLINT team}},
title = {{mp\_real\_agm, \_mp\_real\_agm\_order (mp\_real.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/mp_real/mp_real_agm.html},
note = {Generated 2026-10-20}
}