# Connections

One of my favorite things in math is connecting together things that do not seem related at first. This post will elaborate on a connection between two recent posts.

## Gauss’s constant

A couple weeks ago I wrote about Gauss’s constant and several things it was related to. We can calculate g with n iterations of the process defining the AGM (arithmetic-geometric mean) as follows.

    def f(n):
a, b = 1, 2**0.5
for _ in range(n):
a, b = 0.5*(a+b), (a*b)**0.5
return 1/a


This process converges very quickly, calculating g to full machine precision when n = 4.

## Elliptic integrals

Gauss’s constant, and the AGM more generally, can be computed in terms of an elliptic integral, and that in turn can be computed in terms of a hypergeometric function.

Elliptic integrals are so named because historically they are related to the problem of finding the perimeter of an ellipse. The particular elliptic integral we’re interested here is Legendre’s K function (There are several conventions for parameterizing elliptic integrals, so this definition may not match what you see elsewhere. See last section.)

With this definition of K, and by the symmetry of the AGM, you can reverse the order of x and y. It follows that ## Hypergeometric functions

The previous post briefly introduced hypergeometric functions. The function K is related to Gauss’s hypergeometric function by Expanding F as a series shows the connection to double factorials. This means you could numerically evaluate a power series to compute Gauss’s constant, thought that would be inefficient. Because the AGM converges so quickly, you’d want to evaluate elliptic integrals in terms of the AGM, not evaluate the AGM in terms of elliptic integrals.

## Conventions

There is some confusing terminology and variation in conventions when defining elliptic integrals. We’ve defined K here in terms of the “elliptic modulus” k. Some software, such as Mathematica and SciPy, define K in terms of “the parameter” m = k². So to evaluate K above using Mathematica, you’d need to square the argument first.

    g = EllipticK[0.5] Sqrt/Pi

or

    g = 2 EllipticK[-1]/Pi

Similarly, in Python we’d write

    from scipy.special import ellipk
from math import pi
g = ellipk(0.5)*2**0.5/pi


or

    g = 2*ellipk(-1)/pi