{-
	Copyright (C) 2011-2015 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 set of /Ramanujan/-type algorithms which have been implemented; <https://en.wikipedia.org/wiki/Pi>.
-}

module Factory.Math.Implementations.Pi.Ramanujan.Algorithm(
-- * Types
-- ** Data-types
	Algorithm(..)
) where

import qualified	Data.Default
import qualified	Factory.Math.Factorial						as Math.Factorial
import qualified	Factory.Math.Implementations.Pi.Ramanujan.Chudnovsky		as Math.Implementations.Pi.Ramanujan.Chudnovsky
import qualified	Factory.Math.Implementations.Pi.Ramanujan.Classic		as Math.Implementations.Pi.Ramanujan.Classic
import qualified	Factory.Math.Implementations.Pi.Ramanujan.Implementation	as Math.Implementations.Pi.Ramanujan.Implementation
import qualified	Factory.Math.Pi							as Math.Pi
import qualified	Factory.Math.SquareRoot						as Math.SquareRoot

-- | Define those /Ramanujan/-series which have been implemented.
data Algorithm squareRootAlgorithm factorialAlgorithm
	= Classic squareRootAlgorithm factorialAlgorithm	-- ^ The original version.
	| Chudnovsky squareRootAlgorithm factorialAlgorithm	-- ^ A variant found by the /Chudnovsky brothers/.
	deriving (Algorithm squareRootAlgorithm factorialAlgorithm
-> Algorithm squareRootAlgorithm factorialAlgorithm -> Bool
(Algorithm squareRootAlgorithm factorialAlgorithm
 -> Algorithm squareRootAlgorithm factorialAlgorithm -> Bool)
-> (Algorithm squareRootAlgorithm factorialAlgorithm
    -> Algorithm squareRootAlgorithm factorialAlgorithm -> Bool)
-> Eq (Algorithm squareRootAlgorithm factorialAlgorithm)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall squareRootAlgorithm factorialAlgorithm.
(Eq squareRootAlgorithm, Eq factorialAlgorithm) =>
Algorithm squareRootAlgorithm factorialAlgorithm
-> Algorithm squareRootAlgorithm factorialAlgorithm -> Bool
/= :: Algorithm squareRootAlgorithm factorialAlgorithm
-> Algorithm squareRootAlgorithm factorialAlgorithm -> Bool
$c/= :: forall squareRootAlgorithm factorialAlgorithm.
(Eq squareRootAlgorithm, Eq factorialAlgorithm) =>
Algorithm squareRootAlgorithm factorialAlgorithm
-> Algorithm squareRootAlgorithm factorialAlgorithm -> Bool
== :: Algorithm squareRootAlgorithm factorialAlgorithm
-> Algorithm squareRootAlgorithm factorialAlgorithm -> Bool
$c== :: forall squareRootAlgorithm factorialAlgorithm.
(Eq squareRootAlgorithm, Eq factorialAlgorithm) =>
Algorithm squareRootAlgorithm factorialAlgorithm
-> Algorithm squareRootAlgorithm factorialAlgorithm -> Bool
Eq, ReadPrec [Algorithm squareRootAlgorithm factorialAlgorithm]
ReadPrec (Algorithm squareRootAlgorithm factorialAlgorithm)
Int -> ReadS (Algorithm squareRootAlgorithm factorialAlgorithm)
ReadS [Algorithm squareRootAlgorithm factorialAlgorithm]
(Int -> ReadS (Algorithm squareRootAlgorithm factorialAlgorithm))
-> ReadS [Algorithm squareRootAlgorithm factorialAlgorithm]
-> ReadPrec (Algorithm squareRootAlgorithm factorialAlgorithm)
-> ReadPrec [Algorithm squareRootAlgorithm factorialAlgorithm]
-> Read (Algorithm squareRootAlgorithm factorialAlgorithm)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall squareRootAlgorithm factorialAlgorithm.
(Read squareRootAlgorithm, Read factorialAlgorithm) =>
ReadPrec [Algorithm squareRootAlgorithm factorialAlgorithm]
forall squareRootAlgorithm factorialAlgorithm.
(Read squareRootAlgorithm, Read factorialAlgorithm) =>
ReadPrec (Algorithm squareRootAlgorithm factorialAlgorithm)
forall squareRootAlgorithm factorialAlgorithm.
(Read squareRootAlgorithm, Read factorialAlgorithm) =>
Int -> ReadS (Algorithm squareRootAlgorithm factorialAlgorithm)
forall squareRootAlgorithm factorialAlgorithm.
(Read squareRootAlgorithm, Read factorialAlgorithm) =>
ReadS [Algorithm squareRootAlgorithm factorialAlgorithm]
readListPrec :: ReadPrec [Algorithm squareRootAlgorithm factorialAlgorithm]
$creadListPrec :: forall squareRootAlgorithm factorialAlgorithm.
(Read squareRootAlgorithm, Read factorialAlgorithm) =>
ReadPrec [Algorithm squareRootAlgorithm factorialAlgorithm]
readPrec :: ReadPrec (Algorithm squareRootAlgorithm factorialAlgorithm)
$creadPrec :: forall squareRootAlgorithm factorialAlgorithm.
(Read squareRootAlgorithm, Read factorialAlgorithm) =>
ReadPrec (Algorithm squareRootAlgorithm factorialAlgorithm)
readList :: ReadS [Algorithm squareRootAlgorithm factorialAlgorithm]
$creadList :: forall squareRootAlgorithm factorialAlgorithm.
(Read squareRootAlgorithm, Read factorialAlgorithm) =>
ReadS [Algorithm squareRootAlgorithm factorialAlgorithm]
readsPrec :: Int -> ReadS (Algorithm squareRootAlgorithm factorialAlgorithm)
$creadsPrec :: forall squareRootAlgorithm factorialAlgorithm.
(Read squareRootAlgorithm, Read factorialAlgorithm) =>
Int -> ReadS (Algorithm squareRootAlgorithm factorialAlgorithm)
Read, Int -> Algorithm squareRootAlgorithm factorialAlgorithm -> ShowS
[Algorithm squareRootAlgorithm factorialAlgorithm] -> ShowS
Algorithm squareRootAlgorithm factorialAlgorithm -> String
(Int -> Algorithm squareRootAlgorithm factorialAlgorithm -> ShowS)
-> (Algorithm squareRootAlgorithm factorialAlgorithm -> String)
-> ([Algorithm squareRootAlgorithm factorialAlgorithm] -> ShowS)
-> Show (Algorithm squareRootAlgorithm factorialAlgorithm)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall squareRootAlgorithm factorialAlgorithm.
(Show squareRootAlgorithm, Show factorialAlgorithm) =>
Int -> Algorithm squareRootAlgorithm factorialAlgorithm -> ShowS
forall squareRootAlgorithm factorialAlgorithm.
(Show squareRootAlgorithm, Show factorialAlgorithm) =>
[Algorithm squareRootAlgorithm factorialAlgorithm] -> ShowS
forall squareRootAlgorithm factorialAlgorithm.
(Show squareRootAlgorithm, Show factorialAlgorithm) =>
Algorithm squareRootAlgorithm factorialAlgorithm -> String
showList :: [Algorithm squareRootAlgorithm factorialAlgorithm] -> ShowS
$cshowList :: forall squareRootAlgorithm factorialAlgorithm.
(Show squareRootAlgorithm, Show factorialAlgorithm) =>
[Algorithm squareRootAlgorithm factorialAlgorithm] -> ShowS
show :: Algorithm squareRootAlgorithm factorialAlgorithm -> String
$cshow :: forall squareRootAlgorithm factorialAlgorithm.
(Show squareRootAlgorithm, Show factorialAlgorithm) =>
Algorithm squareRootAlgorithm factorialAlgorithm -> String
showsPrec :: Int -> Algorithm squareRootAlgorithm factorialAlgorithm -> ShowS
$cshowsPrec :: forall squareRootAlgorithm factorialAlgorithm.
(Show squareRootAlgorithm, Show factorialAlgorithm) =>
Int -> Algorithm squareRootAlgorithm factorialAlgorithm -> ShowS
Show)

instance (
	Data.Default.Default	squareRootAlgorithm,
	Data.Default.Default	factorialAlgorithm
 ) => Data.Default.Default (Algorithm squareRootAlgorithm factorialAlgorithm)	where
	def :: Algorithm squareRootAlgorithm factorialAlgorithm
def	= squareRootAlgorithm
-> factorialAlgorithm
-> Algorithm squareRootAlgorithm factorialAlgorithm
forall squareRootAlgorithm factorialAlgorithm.
squareRootAlgorithm
-> factorialAlgorithm
-> Algorithm squareRootAlgorithm factorialAlgorithm
Chudnovsky squareRootAlgorithm
forall a. Default a => a
Data.Default.def factorialAlgorithm
forall a. Default a => a
Data.Default.def

instance (
	Math.SquareRoot.Algorithmic	squareRootAlgorithm,
	Math.Factorial.Algorithmic	factorialAlgorithm
 ) => Math.Pi.Algorithmic (Algorithm squareRootAlgorithm factorialAlgorithm)	where
	openR :: Algorithm squareRootAlgorithm factorialAlgorithm -> Int -> Rational
openR (Classic squareRootAlgorithm
squareRootAlgorithm factorialAlgorithm
factorialAlgorithm)		= Series squareRootAlgorithm factorialAlgorithm
-> squareRootAlgorithm -> factorialAlgorithm -> Int -> Rational
forall squareRootAlgorithm factorialAlgorithm.
Series squareRootAlgorithm factorialAlgorithm
-> squareRootAlgorithm -> factorialAlgorithm -> Int -> Rational
Math.Implementations.Pi.Ramanujan.Implementation.openR Series squareRootAlgorithm factorialAlgorithm
forall squareRootAlgorithm factorialAlgorithm.
(Algorithmic squareRootAlgorithm,
 Algorithmic factorialAlgorithm) =>
Series squareRootAlgorithm factorialAlgorithm
Math.Implementations.Pi.Ramanujan.Classic.series squareRootAlgorithm
squareRootAlgorithm factorialAlgorithm
factorialAlgorithm
	openR (Chudnovsky squareRootAlgorithm
squareRootAlgorithm factorialAlgorithm
factorialAlgorithm)	= Series squareRootAlgorithm factorialAlgorithm
-> squareRootAlgorithm -> factorialAlgorithm -> Int -> Rational
forall squareRootAlgorithm factorialAlgorithm.
Series squareRootAlgorithm factorialAlgorithm
-> squareRootAlgorithm -> factorialAlgorithm -> Int -> Rational
Math.Implementations.Pi.Ramanujan.Implementation.openR Series squareRootAlgorithm factorialAlgorithm
forall squareRootAlgorithm factorialAlgorithm.
(Algorithmic squareRootAlgorithm,
 Algorithmic factorialAlgorithm) =>
Series squareRootAlgorithm factorialAlgorithm
Math.Implementations.Pi.Ramanujan.Chudnovsky.series squareRootAlgorithm
squareRootAlgorithm factorialAlgorithm
factorialAlgorithm