AGM 3CW "11 October 2007" "mathcw-1.00"

Table of contents


NAME

agmf, agm, agml, agmw, agmq, agmll, agmdf, agmd, agmdl, agmdll - arithmetic-geometric mean

SYNOPSIS

cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ]

#include <mathcw.h>

extern float agmf (float a, float b);

extern double agm (double a, double b);

extern long double agml (long double a, long double b);

extern __float80 agmw (__float80 a, __float80 b);

extern __float128 agmq (__float128 a, __float128 b);

extern long_long_double agmll (long_long_double a, long_long_double b);

extern decimal_float agmdf (decimal_float a, decimal_float b);

extern decimal_double agmd (decimal_double a, decimal_double b);

extern decimal_long_double agmdl (decimal_long_double a, decimal_long_double b);

extern decimal_long_long_double agmdll (decimal_long_long_double a, decimal_long_long_double b);

NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.


DESCRIPTION

Compute the arithmetic-geometric mean (AGM) of x and y, defined by the iteration
A[0] = a B[0] = b for k = 1, 2, 3, ..., do A[k] = (A[k-1] + B[k-1])/2 B[k] = sqrt(A[k-1] * B[k-1])
This algorithm does not require internal array storage since at most two successive elements of each sequence are needed at the same time.

The arguments must both be of the same sign, and should be nonzero.

The AGM function has these scaling and symmetry relations:

agm(s * a, s * b) = s * agm(a, b) agm(a, b) = agm(b, a) agm(0, b) = 0
Intermediate underflow or overflow in the geometric mean from the product A[k-1] * B[k-1] are avoided when necessary by exact scaling with s set to a power of the base, using the frexp(3CW) and ldexp(3CW) functions.

At convergence, after n iterations, we have A[n] = B[n], and either of them is the final function value. When the starting values are close, convergence is quadratic. When they are far apart, fewer than 20 iterations are needed in 70D extended IEEE 754 arithmetic, and even fewer at lower precisions and smaller relative sizes.

Unlike Newton--Raphson iteration, the AGM iteration is not self-correcting, and thus, errors accumulate. Consider using a function family member of higher than working precision, if available, and then cast the return value to working precision.

The arithmetic-geometric mean provides a fast computational path to several functions, including the arc tangent and the ordinary and complementary complete elliptic integral functions of the first and second kinds. Related algorithms have produced routes with quadratic, cubic, and quartic convergence for the computation of pi to more than 10**12 decimal digits. With hardware floating-point arithmetic, however, these algorithms are not sufficiently accurate for computing pi, unless arithmetic of higher than final precision is used for intermediate computations.


RETURN VALUES

Return the arithmetic-geometric mean of the arguments.

ERRORS

If either a or b is a NaN, set errno to EDOM and return that NaN. If one of them is zero and the other is Infinity, set errno to EDOM and return a quiet NaN. Otherwise, if either a or b is Infinity, set errno to ERANGE and return Infinity.

SEE ALSO

atan(3CW), elle(3CW), ellec(3CW), ellk(3CW), ellkc(3CW), frexp(3CW), ldexp(3CW), sqrt(3CW), vagm(3CW).