MathOverflow is a question and answer site for professional mathematicians. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The complete elliptic integral of the first kind


is easily computed via the arithmetic-geometric mean iteration; to wit,


where $M(a,b)$ is the arithmetic-geometric mean of $a$ and $b$. With a little more trickery, the iteration can be hijacked to compute the complete elliptic integral of the second kind $E(m)$ as well.

In a number of applications, it happens that one needs both the values of $K(m)$ and its complement $K(1-m)$ (and sometimes similarly for $E(m)$ and $E(1-m)$).

My question is, apart from having to do an AGM iteration for each of $K(m)$ and $K(1-m)$, is there an algorithm (maybe a modification of the basic AGM iteration) that simultaneously generates both $K(m)$ and its complement? I would also be interested in seeing also an extension of this algorithm, if one exists, for computing $E(m)$ as well (after which $E(1-m)$ is easily computed via Legendre's relation).

share|cite|improve this question
up vote 4 down vote accepted

There are two possible ways to attack this problem

  1. Both K and K' can be expressed in terms of the Theta function as described here If you compute $\Theta_3$, you can get both at the same time.

  2. The other way is to observe that both K and K' are expressible in terms of the hypergeometric function $_2F_1(\frac{1}{2}, \frac{1}{2} ; 1; m)$. They are solutions of the same self-adjoint Gauss hypergeometric differential equation (since the equation is invariant under the transformation (m $\rightarrow$ 1-m))

    $(k^3 - k)\frac{d^2y}{dk^2} + (3k^2 -1)\frac{dy}{dk} + ky = 0 $

    By virtue of this fact, both K and K' are connected. You will find the following series expansion for K'(k) derived in Borwein's book Pi and AGM Section 1.3

    $ K'(k) = \frac{2}{\pi} log \frac {4}{k} K(k) - 2 [(\frac{1}{2})^2(\frac{1}{1.2}k^2 + (\frac{1.3}{2.4})^2(\frac{1}{1.2} + \frac{1}{3.4})k^4 + (\frac{1.3.5}{2.4.6})^2(\frac{1}{1.2} + \frac{1}{3.4} + \frac{1}{5.6})k^6 $.....(infinite series) + ]

You may also find Chapter 5 of Armitage and Eberlein's book on Elliptic Functions useful.

EDIT1: I put in the complete series expansion for K'(k).

Regarding the computation of E(k), E(k) and K(k) are connected by the differential equation $ \frac{dK}{dk} = \frac{E - (1-k^2)K}{k(1-k^2)} $ which is how the Legendre relation you mention above comes about.

Again Borwein has the solution for this problem(buy the book!). Exercise 3 in Sec 1.4 has the formula based on the quartic AGM iteration $ E(k) = K(k)[1 - \sum_{n=0}^{\infty} 4^n [\alpha_n^4 - (\frac{\alpha_n^2+\beta_n^2}{2})^2 ] $ where

  • $\alpha_n = (a_{2n})^{\frac{1}{2}} and \beta_n = (b_{2n})^{\frac{1}{2}}$

and $ a_n, b_n$ and $c_n $ satisfy the AGM relation

share|cite|improve this answer
Hmm... now that I think about it, I do seem to have an AGM-type algorithm for computing the nome $q$ in here somewhere... and then it is my understanding that $\vartheta_3(0,q)$ is a rapidly converging series (the Lambert-like series in equation 57 of the MathWorld entry for the theta functions looks promising). I might be able to make it work, but I'll have to do a few tests. The algorithm you presented is a bit piecemeal, though. Unfortunately I have neither of the two books you cited. :( Still, is there really no AGM-type algorithm? And how do you compute $E(m)$ afterwards? – J. M. Aug 4 '10 at 6:25
@ Mangaldan, I don't know how your algo is structured but you can continue to use AGM for computing K(k) and then use the second answer I gave (series expansion) to calculate K' in terms of K. Doesnt' that work? Buy Borwein's Pi and AGM even otherwise :-) Its a great book! Another good and free book is King's 1924 "On the direct numerical calculation of elliptic functions and integrals" online at – SandeepJ Aug 4 '10 at 13:24

Short answer: yes you can. After accepting and upvoting Sandeep's question, however, the algorithm I settled on was not the algorithm he proposed.

I managed (through a friend's assistance) to see the first two chapters of Borwein and Borwein's "Pi and the AGM". The identity that I needed, it turns out, was exactly the algorithm for the nome $q$ that I had mentioned in my comment to his answer (i.e., a hijacked AGM iteration that computes both $q=\exp(-\pi K(1-m)/K(m))$ and $K(m)$ simultaneously). It is equation 2.5.14 in "Pi and the AGM":


where $a_j$ is an iterate from the AGM iteration.

In pseudocode, here is the algorithm I now have for computing $K(m)$, $E(m)$, and $t=\ln(q(m))$ simultaneously:

until |c| is small enough

The code fails for $m=0$ and $m=1$, but these trivial cases can be handled separately. $K(1-m)$ is then -Kt/π. $E(1-m)$ is of course then computed through the Legendre relation.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.