module Factory.Math.Implementations.Pi.Ramanujan.Chudnovsky(
series
) where
import Data.Ratio((%))
import qualified Factory.Math.Factorial as Math.Factorial
import qualified Factory.Math.Implementations.Factorial as Math.Implementations.Factorial
import qualified Factory.Math.Implementations.Pi.Ramanujan.Series as Math.Implementations.Pi.Ramanujan.Series
import qualified Factory.Math.Power as Math.Power
import qualified Factory.Math.SquareRoot as Math.SquareRoot
series :: (
Math.SquareRoot.Algorithmic squareRootAlgorithm,
Math.Factorial.Algorithmic factorialAlgorithm
) => Math.Implementations.Pi.Ramanujan.Series.Series squareRootAlgorithm factorialAlgorithm
series :: Series squareRootAlgorithm factorialAlgorithm
series = MkSeries :: forall squareRootAlgorithm factorialAlgorithm.
(factorialAlgorithm -> [Rational])
-> (squareRootAlgorithm -> DecimalDigits -> Rational)
-> ConvergenceRate
-> Series squareRootAlgorithm factorialAlgorithm
Math.Implementations.Pi.Ramanujan.Series.MkSeries {
terms :: factorialAlgorithm -> [Rational]
Math.Implementations.Pi.Ramanujan.Series.terms = \factorialAlgorithm
factorialAlgorithm -> (Integer -> Integer -> Rational)
-> [Integer] -> [Integer] -> [Rational]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (
\Integer
n Integer
power -> (
Integer -> Integer -> Integer
forall i. (Integral i, Show i) => i -> i -> i
Math.Implementations.Factorial.risingFactorial (Integer -> Integer
forall a. Enum a => a -> a
succ (Integer -> Integer) -> Integer -> Integer
forall a b. (a -> b) -> a -> b
$ Integer
3 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
n) (Integer
3 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
n) Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer -> Integer
forall n. Num n => n -> n
Math.Power.cube (factorialAlgorithm -> Integer -> Integer
forall algorithm i.
(Algorithmic algorithm, Integral i, Show i) =>
algorithm -> i -> i
Math.Factorial.factorial factorialAlgorithm
factorialAlgorithm Integer
n)
) Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
* (
(Integer
13591409 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
545140134 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
n) Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
power
)
) [Integer
0 ..] ([Integer] -> [Rational]) -> [Integer] -> [Rational]
forall a b. (a -> b) -> a -> b
$ (Integer -> Integer) -> Integer -> [Integer]
forall a. (a -> a) -> a -> [a]
iterate (Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* (Integer -> Integer
forall n. Num n => n -> n
Math.Power.cube (Integer -> Integer) -> Integer -> Integer
forall a b. (a -> b) -> a -> b
$ Integer -> Integer
forall n. Num n => n -> n
negate Integer
640320 :: Integer)) Integer
1,
getSeriesScalingFactor :: squareRootAlgorithm -> DecimalDigits -> Rational
Math.Implementations.Pi.Ramanujan.Series.getSeriesScalingFactor = \squareRootAlgorithm
squareRootAlgorithm DecimalDigits
decimalDigits -> Rational
426880 Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
* squareRootAlgorithm -> DecimalDigits -> Integer -> Rational
forall algorithm operand.
(Algorithmic algorithm, Real operand, Show operand) =>
algorithm -> DecimalDigits -> operand -> Rational
Math.SquareRoot.squareRoot squareRootAlgorithm
squareRootAlgorithm DecimalDigits
decimalDigits (Integer
10005 :: Integer),
convergenceRate :: ConvergenceRate
Math.Implementations.Pi.Ramanujan.Series.convergenceRate = ConvergenceRate
10 ConvergenceRate -> ConvergenceRate -> ConvergenceRate
forall a. Floating a => a -> a -> a
** ConvergenceRate -> ConvergenceRate
forall n. Num n => n -> n
negate ConvergenceRate
14.0
}