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 agm⁡(x,y)\operatorname{agm}(x, y) of x,y≥0x, y \ge 0 to about nn limbs; throws for a negative midpoint. The second function takes the order mm of the final series (at most 16, 10 on 32-bit machines; 0 for the default).

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

agm⁡(a,b)=(a+b)/22F1(12,12;1;z2),12F1(12,12;1;t)=1−∑j≥1cjtj.\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 cjc_j are positive dyadic rationals summing to 1 (the reciprocal vanishes at t=1t = 1; positivity follows from the log-convexity of the coefficients of 2F1{}_2F_1 by Kaluza's theorem), so the tail after tm−1t^{m-1} is below tmt^m. The default mm is 8 below 1024 limbs and 12 above. When a−ba - b no longer determines its own size, or a+ba + b or abab is too wide for the division and the square root, the result is the enclosure (a+b)/2±∣a−b∣/2(a + b)/2 \pm |a - b|/2, valid because b≤agm⁡(a,b)≤ab \le \operatorname{agm}(a, b) \le a. The working set is four numbers of nn 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-11-02).