Definitions

# Arithmetic-geometric mean

In mathematics, the arithmetic-geometric mean (AGM) of two positive real numbers x and y is defined as follows:

First compute the arithmetic mean of x and y and call it a1. Next compute the geometric mean of x and y and call it g1; this is the square root of the product xy:

$a_1 = frac\left\{x+y\right\}\left\{2\right\}$

$g_1 = sqrt\left\{xy\right\}.$

Then iterate this operation with a1 taking the place of x and g1 taking the place of y. In this way, two sequences (an) and (gn) are defined:

$a_\left\{n+1\right\} = frac\left\{a_n + g_n\right\}\left\{2\right\}$

$g_\left\{n+1\right\} = sqrt\left\{a_n g_n\right\}.$

These two sequences converge to the same number, which is the arithmetic-geometric mean of x and y; it is denoted by M(x, y), or sometimes by agm(x, y).

## Example

To find the arithmetic-geometric mean of a0 = 24 and g0 = 6, first calculate their arithmetic mean and geometric mean, thus:

$a_1=frac\left\{24+6\right\}\left\{2\right\}=15,$

$g_1=sqrt\left\{24 times 6\right\}=12,$

and then iterate as follows:

$a_2=frac\left\{15+12\right\}\left\{2\right\}=13.5,$

$g_2=sqrt\left\{15 times 12\right\}=13.41640786500dots$ etc.

The first four iterations give the following values:

n an gn
0 24 6
1 15 12
2 13.5 13.41640786500...
3 13.45820393250... 13.45813903099...
4 13.45817148175... 13.45817148171...

The arithmetic-geometric mean of 24 and 6 is the common limit of these two sequences, which is approximately 13.45817148173.

## Properties

M(x, y) is a number between the geometric and arithmetic mean of x and y; in particular it is between x and y.

If r > 0, then M(rx, ry) = r M(x, y).

There is a closed form expression for M(x,y):

$Mu\left(x,y\right) = frac\left\{pi\right\}\left\{4\right\} cdot frac\left\{x + y\right\}\left\{K left\left(left\left(frac\left\{x - y\right\}\left\{x + y\right\} right\right)^2 right\right) \right\}$

where K(x) is the complete elliptic integral of the first kind.

The reciprocal of the arithmetic-geometric mean of 1 and the square root of 2 is called Gauss's constant.

$frac\left\{1\right\}\left\{Mu\left(1, sqrt\left\{2\right\}\right)\right\} = G = 0.8346268dots$

named after Carl Friedrich Gauss.

The geometric-harmonic mean can be calculated by an analogous method, using sequences of geometric and harmonic means. The arithmetic-harmonic mean can be similarly defined, but takes the same value as the geometric mean.

## Implementation in Python

The following example code in Python computes the arithmetic-geometric mean of two positive real numbers:
```from math import sqrtdef avg(a, b, delta=None):
if None==delta:
delta=(a+b)/2*1E-10
if(abs(b-a)>delta):
return avg((a+b)/2.0, sqrt(a*b), delta)
else:
return (a+b)/2.0```