{-
	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 /Borwein/-type algorithms (currently only one) which have been implemented; <http://www.pi314.net/eng/borwein.php>.
-}

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

import qualified	Data.Default
import qualified	Factory.Math.Factorial					as Math.Factorial
import qualified	Factory.Math.Implementations.Pi.Borwein.Borwein1993	as Math.Implementations.Pi.Borwein.Borwein1993
import qualified	Factory.Math.Implementations.Pi.Borwein.Implementation	as Math.Implementations.Pi.Borwein.Implementation
import qualified	Factory.Math.Pi						as Math.Pi
import qualified	Factory.Math.SquareRoot					as Math.SquareRoot

{- |
	* Define those /Borwein/-series which have been implemented.

	* Though currently there's only one, provision has been made for the addition of more.
-}
data Algorithm squareRootAlgorithm factorialAlgorithm	=
	Borwein1993 squareRootAlgorithm factorialAlgorithm	-- ^ <https://en.wikipedia.org/wiki/Borwein%27s_algorithm>.
	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
Borwein1993 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 (Borwein1993 squareRootAlgorithm
squareRootAlgorithm factorialAlgorithm
factorialAlgorithm)	= Series squareRootAlgorithm factorialAlgorithm
-> squareRootAlgorithm -> factorialAlgorithm -> Int -> Rational
forall squareRootAlgorithm factorialAlgorithm.
Series squareRootAlgorithm factorialAlgorithm
-> squareRootAlgorithm -> factorialAlgorithm -> Int -> Rational
Math.Implementations.Pi.Borwein.Implementation.openR Series squareRootAlgorithm factorialAlgorithm
forall squareRootAlgorithm factorialAlgorithm.
(Algorithmic squareRootAlgorithm,
 Algorithmic factorialAlgorithm) =>
Series squareRootAlgorithm factorialAlgorithm
Math.Implementations.Pi.Borwein.Borwein1993.series squareRootAlgorithm
squareRootAlgorithm factorialAlgorithm
factorialAlgorithm