Calculating pi

Here’s a lovely iteration which converges quadratically to . Start with:

.
Then:
for
for
for
This remarkable iteration comes from Borwein and Borwein’s “Pi and the AGM“; this is the first formula for of the many in the book. It is based on the arithmetic-geometric mean, which is defined as follows:
Given [...]

Numerical computation of square roots

If you calculate by applying the Newton iteration

to the equation , you obtain
.
The trouble with this particular iteration is that even though it’s quadratically convergent, each step requires a division by the current estimate , which is a slow operation.
There’s a neat trick to overcome this, which I either found as a [...]