factory-0.3.0.0: Rational arithmetic in an irrational world.

Safe HaskellNone
LanguageHaskell2010

Factory.Math.Implementations.Pi.AGM.BrentSalamin

Contents

Description

AUTHOR
Dr. Alistair Ward
DESCRIPTION
CAVEAT
Assumptions on the convergence-rate result in rounding-errors, when only a small number of digits are requested.

Synopsis

Functions

openR :: Algorithmic squareRootAlgorithm => squareRootAlgorithm -> DecimalDigits -> Rational Source #

  • Returns Pi, accurate to the specified number of decimal digits.
  • This algorithm is based on the arithmetic-geometric mean of 1 and (1 / sqrt 2), but there are many confusingly similar formulations. The algorithm I've used here, where a is the arithmetic mean and g is the geometric mean, is equivalent to other common formulations:
		pi = (a[N-1] + g[N-1])^2 / (1 - sum [2^n * (a[n] - g[n])^2])			where n = [0 .. N-1]
		=> 4*a[N]^2 / (1 - sum [2^n * (a[n]^2 - 2*a[n]*g[n] + g[n]^2)])
		=> 4*a[N]^2 / (1 - sum [2^n * (a[n]^2 + 2*a[n]*g[n] + g[n]^2 - 4*a[n]*g[n])])
		=> 4*a[N]^2 / (1 - sum [2^n * ((a[n] + g[n])^2 - 4*a[n]*g[n])])
		=> 4*a[N]^2 / (1 - sum [2^(n-1) * 4 * (a[n-1]^2 - g[n-1]^2)])			where n = [1 .. N]
		=> 4*a[N]^2 / (1 - sum [2^(n+1) * (a[n-1]^2 - g[n-1]^2)])