{-
	Copyright (C) 2011 Dr. Alistair Ward

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
-}
{- |
 [@AUTHOR@]	Dr. Alistair Ward

 [@DESCRIPTION@]	Defines the /Gosper/ series; <http://www.pi314.net/eng/goutte.php>
-}

module Factory.Math.Implementations.Pi.Spigot.Gosper(
-- * Constants
	series
) where

import qualified	Factory.Math.Implementations.Pi.Spigot.Series	as Math.Implementations.Pi.Spigot.Series
import qualified	Factory.Math.Precision				as Math.Precision

-- | Defines a series which converges to /Pi/.
series :: Integral i => Math.Implementations.Pi.Spigot.Series.Series i
series :: Series i
series	= MkSeries :: forall i.
[i] -> [i] -> [i] -> (DecimalDigits -> DecimalDigits) -> Series i
Math.Implementations.Pi.Spigot.Series.MkSeries {
	baseNumerators :: [i]
Math.Implementations.Pi.Spigot.Series.baseNumerators	= (i -> i) -> [i] -> [i]
forall a b. (a -> b) -> [a] -> [b]
map (\i
i -> i
i i -> i -> i
forall a. Num a => a -> a -> a
* i -> i
forall a. Enum a => a -> a
pred (i
2 i -> i -> i
forall a. Num a => a -> a -> a
* i
i)) [i
1 ..],
	baseDenominators :: [i]
Math.Implementations.Pi.Spigot.Series.baseDenominators	= (i -> i) -> [i] -> [i]
forall a b. (a -> b) -> [a] -> [b]
map ((i -> i -> i
forall a. Num a => a -> a -> a
* i
3) (i -> i) -> (i -> i) -> i -> i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\i
i -> i -> i
forall a. Enum a => a -> a
succ i
i i -> i -> i
forall a. Num a => a -> a -> a
* (i
i i -> i -> i
forall a. Num a => a -> a -> a
+ i
2))) [i
3, i
6 ..],
	coefficients :: [i]
Math.Implementations.Pi.Spigot.Series.coefficients	= [i
3, i
8 ..],	-- 5n - 2
	nTerms :: DecimalDigits -> DecimalDigits
Math.Implementations.Pi.Spigot.Series.nTerms		= ConvergenceRate -> DecimalDigits -> DecimalDigits
forall i. Integral i => ConvergenceRate -> DecimalDigits -> i
Math.Precision.getTermsRequired (ConvergenceRate -> DecimalDigits -> DecimalDigits)
-> ConvergenceRate -> DecimalDigits -> DecimalDigits
forall a b. (a -> b) -> a -> b
$ ConvergenceRate
1 ConvergenceRate -> ConvergenceRate -> ConvergenceRate
forall a. Fractional a => a -> a -> a
/ ConvergenceRate
13 {-empirical convergence-rate-}
}