packages feed

factory 0.2.2.1 → 0.3.0.0

raw patch · 8 files changed

+69/−60 lines, 8 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Factory.Data.Polynomial: instance (GHC.Classes.Eq coefficient, GHC.Classes.Eq exponent) => GHC.Classes.Eq (Factory.Data.Polynomial.Polynomial coefficient exponent)
- Factory.Data.Polynomial: instance (GHC.Show.Show coefficient, GHC.Show.Show exponent) => GHC.Show.Show (Factory.Data.Polynomial.Polynomial coefficient exponent)
- Factory.Math.Implementations.Pi.AGM.Algorithm: data Algorithm squareRootAlgorithm
- Factory.Math.Implementations.Pi.Borwein.Algorithm: instance (GHC.Classes.Eq squareRootAlgorithm, GHC.Classes.Eq factorialAlgorithm) => GHC.Classes.Eq (Factory.Math.Implementations.Pi.Borwein.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
- Factory.Math.Implementations.Pi.Borwein.Algorithm: instance (GHC.Read.Read squareRootAlgorithm, GHC.Read.Read factorialAlgorithm) => GHC.Read.Read (Factory.Math.Implementations.Pi.Borwein.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
- Factory.Math.Implementations.Pi.Borwein.Algorithm: instance (GHC.Show.Show squareRootAlgorithm, GHC.Show.Show factorialAlgorithm) => GHC.Show.Show (Factory.Math.Implementations.Pi.Borwein.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
- Factory.Math.Implementations.Pi.Ramanujan.Algorithm: instance (GHC.Classes.Eq squareRootAlgorithm, GHC.Classes.Eq factorialAlgorithm) => GHC.Classes.Eq (Factory.Math.Implementations.Pi.Ramanujan.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
- Factory.Math.Implementations.Pi.Ramanujan.Algorithm: instance (GHC.Read.Read squareRootAlgorithm, GHC.Read.Read factorialAlgorithm) => GHC.Read.Read (Factory.Math.Implementations.Pi.Ramanujan.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
- Factory.Math.Implementations.Pi.Ramanujan.Algorithm: instance (GHC.Show.Show squareRootAlgorithm, GHC.Show.Show factorialAlgorithm) => GHC.Show.Show (Factory.Math.Implementations.Pi.Ramanujan.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
- Factory.Math.Pi: instance (GHC.Classes.Eq agm, GHC.Classes.Eq bbp, GHC.Classes.Eq borwein, GHC.Classes.Eq ramanujan, GHC.Classes.Eq spigot) => GHC.Classes.Eq (Factory.Math.Pi.Category agm bbp borwein ramanujan spigot)
- Factory.Math.Pi: instance (GHC.Read.Read agm, GHC.Read.Read bbp, GHC.Read.Read borwein, GHC.Read.Read ramanujan, GHC.Read.Read spigot) => GHC.Read.Read (Factory.Math.Pi.Category agm bbp borwein ramanujan spigot)
- Factory.Math.Pi: instance (GHC.Show.Show agm, GHC.Show.Show bbp, GHC.Show.Show borwein, GHC.Show.Show ramanujan, GHC.Show.Show spigot) => GHC.Show.Show (Factory.Math.Pi.Category agm bbp borwein ramanujan spigot)
+ Factory.Data.Polynomial: instance (GHC.Classes.Eq exponent, GHC.Classes.Eq coefficient) => GHC.Classes.Eq (Factory.Data.Polynomial.Polynomial coefficient exponent)
+ Factory.Data.Polynomial: instance (GHC.Show.Show exponent, GHC.Show.Show coefficient) => GHC.Show.Show (Factory.Data.Polynomial.Polynomial coefficient exponent)
+ Factory.Math.Implementations.Pi.AGM.Algorithm: newtype Algorithm squareRootAlgorithm
+ Factory.Math.Implementations.Pi.Borwein.Algorithm: instance (GHC.Classes.Eq factorialAlgorithm, GHC.Classes.Eq squareRootAlgorithm) => GHC.Classes.Eq (Factory.Math.Implementations.Pi.Borwein.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
+ Factory.Math.Implementations.Pi.Borwein.Algorithm: instance (GHC.Read.Read factorialAlgorithm, GHC.Read.Read squareRootAlgorithm) => GHC.Read.Read (Factory.Math.Implementations.Pi.Borwein.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
+ Factory.Math.Implementations.Pi.Borwein.Algorithm: instance (GHC.Show.Show factorialAlgorithm, GHC.Show.Show squareRootAlgorithm) => GHC.Show.Show (Factory.Math.Implementations.Pi.Borwein.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
+ Factory.Math.Implementations.Pi.Ramanujan.Algorithm: instance (GHC.Classes.Eq factorialAlgorithm, GHC.Classes.Eq squareRootAlgorithm) => GHC.Classes.Eq (Factory.Math.Implementations.Pi.Ramanujan.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
+ Factory.Math.Implementations.Pi.Ramanujan.Algorithm: instance (GHC.Read.Read factorialAlgorithm, GHC.Read.Read squareRootAlgorithm) => GHC.Read.Read (Factory.Math.Implementations.Pi.Ramanujan.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
+ Factory.Math.Implementations.Pi.Ramanujan.Algorithm: instance (GHC.Show.Show factorialAlgorithm, GHC.Show.Show squareRootAlgorithm) => GHC.Show.Show (Factory.Math.Implementations.Pi.Ramanujan.Algorithm.Algorithm squareRootAlgorithm factorialAlgorithm)
+ Factory.Math.Pi: instance (GHC.Classes.Eq spigot, GHC.Classes.Eq ramanujan, GHC.Classes.Eq borwein, GHC.Classes.Eq bbp, GHC.Classes.Eq agm) => GHC.Classes.Eq (Factory.Math.Pi.Category agm bbp borwein ramanujan spigot)
+ Factory.Math.Pi: instance (GHC.Read.Read spigot, GHC.Read.Read ramanujan, GHC.Read.Read borwein, GHC.Read.Read bbp, GHC.Read.Read agm) => GHC.Read.Read (Factory.Math.Pi.Category agm bbp borwein ramanujan spigot)
+ Factory.Math.Pi: instance (GHC.Show.Show spigot, GHC.Show.Show ramanujan, GHC.Show.Show borwein, GHC.Show.Show bbp, GHC.Show.Show agm) => GHC.Show.Show (Factory.Math.Pi.Category agm bbp borwein ramanujan spigot)

Files

changelog.markdown view
@@ -149,3 +149,8 @@ * Tested with **ghc-8.0.1**. ## 0.2.2.1 * Commented-out flakey square-root test.+## 0.3.0.0+* Used strictness to improve efficiency of functions **getMean**, **getRootMeanSquare**, **getWeightedMean** & replaced **error** with **Control.Exception.assert**, in module **Factory.Math.Statistics**+* Replaced 'Data.List.genericLength' with the more efficient @fromIntegral . length@.+* Removed dependency on **Distribution.Package.PackageName**.+* Checked for null-string in **Factory.Math.Radix.fromBase**.
factory.cabal view
@@ -14,7 +14,7 @@ -- along with Factory.  If not, see <http://www.gnu.org/licenses/>.  Name:		factory-Version:	0.2.2.1+Version:	0.3.0.0 Cabal-version:	>= 1.10 Copyright:	(C) 2011-2015 Dr. Alistair Ward License:	GPL@@ -132,9 +132,13 @@     else         GHC-prof-options:	-auto-all -caf-all -    if impl(ghc >= 7.0) && flag(llvm)-        GHC-options:	-fllvm+    if impl(ghc >= 7.0)+        if flag(llvm)+            GHC-options:	-fllvm +        if impl(ghc >= 8.0)+            GHC-options:	-Wredundant-constraints+ Executable factory     Default-language:	Haskell2010     GHC-options:	-O2 -Wall -fno-warn-tabs@@ -178,6 +182,9 @@         if flag(llvm)             GHC-options:	-fllvm +        if impl(ghc >= 8.0)+            GHC-options:	-Wredundant-constraints+ Test-Suite test     Default-language:	Haskell2010     GHC-options:	-Wall -fno-warn-tabs@@ -216,3 +223,7 @@         QuickCheck >= 2.2,         random,         toolshed >= 0.17++    if impl(ghc >= 8.0)+        GHC-options:	-Wredundant-constraints+
src-exe/Factory/Test/CommandOptions.hs view
@@ -32,7 +32,7 @@ import qualified	Data.Default  -- | Declare a record used to contain command-line options.-data CommandOptions	= MkCommandOptions {+newtype CommandOptions	= MkCommandOptions { 	verbose	:: Bool	-- ^ Whether additional informative output should be generated, where applicable. } 
src-exe/Main.hs view
@@ -30,9 +30,6 @@ import qualified	Data.Map import qualified	Data.List import qualified	Data.Version-import qualified	Distribution.Package-import qualified	Distribution.Text-import qualified	Distribution.Version import qualified	Factory.Math.Hyperoperation			as Math.Hyperoperation import qualified	Factory.Math.Implementations.Factorial		as Math.Implementations.Factorial import qualified	Factory.Math.Implementations.Primality		as Math.Implementations.Primality@@ -115,17 +112,13 @@ 		 ] where 			printVersion, printUsage :: IO Test.CommandOptions.CommandOptions 			printVersion	= System.IO.hPutStrLn System.IO.stderr (-				Distribution.Text.display packageIdentifier ++ "\n\nCompiled by " ++ show compiler ++ ".\n\nCopyright (C) 2011-2015 " ++ author ++ ".\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it under certain conditions.\n\nWritten by " ++ author ++ "."+				showString progName . showChar '-' . showsVersion Paths.version . showString "\n\nCompiled by " . showString System.Info.compilerName . showChar '-' . showsVersion System.Info.compilerVersion . showString ".\n\nCopyright (C) 2011-2017 " . showString author . showString ".\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it under certain conditions.\n\nWritten by " $ showString author "." 			 ) >> System.Exit.exitSuccess	where-				packageIdentifier :: Distribution.Package.PackageIdentifier-				packageIdentifier	= Distribution.Package.PackageIdentifier {-					Distribution.Package.pkgName	= Distribution.Package.PackageName progName,	-- CAVEAT: coincidentally.-					Distribution.Package.pkgVersion	= Distribution.Version.Version (Data.Version.versionBranch Paths.version) []-				}+				author :: String+				author	= "Dr. Alistair Ward" -				author, compiler :: String-				author		= "Dr. Alistair Ward"-				compiler	= showString System.Info.compilerName . showChar '-' . Data.List.intercalate "." . map show $ Data.Version.versionBranch System.Info.compilerVersion+				showsVersion :: Data.Version.Version -> ShowS+				showsVersion	= foldr (.) id . Data.List.intersperse (showChar '.') . map shows . Data.Version.versionBranch  			printUsage	= System.IO.hPutStrLn System.IO.stderr usageMessage	>> System.Exit.exitSuccess 
src-lib/Factory/Math/Implementations/Pi/AGM/Algorithm.hs view
@@ -32,7 +32,7 @@ import qualified	Factory.Math.SquareRoot					as Math.SquareRoot  -- | Defines the available algorithms.-data Algorithm squareRootAlgorithm	= BrentSalamin squareRootAlgorithm	deriving (Eq, Read, Show)+newtype Algorithm squareRootAlgorithm	= BrentSalamin squareRootAlgorithm	deriving (Eq, Read, Show)  instance Data.Default.Default squareRootAlgorithm => Data.Default.Default (Algorithm squareRootAlgorithm)	where 	def	= BrentSalamin Data.Default.def
src-lib/Factory/Math/PrimeFactorisation.hs view
@@ -46,7 +46,6 @@ ) where  import qualified	Control.DeepSeq-import qualified	Data.List import qualified	Factory.Data.Exponential	as Data.Exponential import qualified	Factory.Data.PrimeFactors	as Data.PrimeFactors @@ -139,7 +138,7 @@ 	* <http://planetmath.org/encyclopedia/NumberOfDistinctPrimeFactorsFunction.html>. -} omega :: (Algorithmic algorithm, Integral i) => algorithm -> [i]-omega algorithm	= map (Data.List.genericLength . primeFactors algorithm) [0 :: Integer ..]+omega algorithm	= map (fromIntegral . length . primeFactors algorithm) [0 :: Integer ..]  {- | 	* A constant, conceptually infinite, list of the /square-free/ numbers, i.e. those which aren't divisible by any /perfect square/.
src-lib/Factory/Math/Radix.hs view
@@ -44,7 +44,7 @@  -- | Constant random-access lookup for 'digits'. encodes :: (Data.Array.IArray.Ix index, Integral index) => Data.Array.IArray.Array index Char-encodes	= Data.Array.IArray.listArray (0, pred $ Data.List.genericLength digits) digits+encodes	= Data.Array.IArray.listArray (0, fromIntegral . pred $ length digits) digits  -- | Constant reverse-lookup for 'digits'. decodes :: Integral i => [(Char, i)]@@ -68,10 +68,12 @@ toBase 10 decimal	= show decimal	-- Base unchanged. toBase _ 0		= "0"		-- Zero has the same representation in any base. toBase base decimal-	| abs base < 2					= error $ "Factory.Math.Radix.toBase:\tan arbitrary integer can't be represented in base " ++ show base-	| abs base > Data.List.genericLength digits	= error $ "Factory.Math.Radix.toBase:\tunable to clearly represent the complete set of digits in base " ++ show base-	| base > 0 && decimal < 0			= '-' : map toDigit (fromDecimal (negate decimal) [])-	| otherwise					= toDigit `map` fromDecimal decimal []+	| abs base < 2			= error $ "Factory.Math.Radix.toBase:\tan arbitrary integer can't be represented in base " ++ show base+	| abs base > fromIntegral (+		length digits+	)				= error $ "Factory.Math.Radix.toBase:\tunable to clearly represent the complete set of digits in base " ++ show base+	| base > 0 && decimal < 0	= '-' : map toDigit (fromDecimal (negate decimal) [])+	| otherwise			= toDigit `map` fromDecimal decimal [] 	where 		fromDecimal 0		= id 		fromDecimal n@@ -101,12 +103,16 @@ 	Show		base  ) => base -> String -> decimal fromBase 10 s	= read s	-- Base unchanged.+fromBase _ ""	= error "Factory.Math.Radix.fromBase:\tnull string." fromBase _ "0"	= 0		-- Zero has the same representation in any base. fromBase base s-	| abs base < 2					= error $ "Factory.Math.Radix.fromBase:\tan arbitrary integer can't be represented in base " ++ show base-	| abs base > Data.List.genericLength digits	= error $ "Factory.Math.Radix.fromBase:\tunable to clearly represent the complete set of digits in base " ++ show base-	| base > 0 && head s == '-'			= negate . fromBase base $ tail s	-- Recurse.-	| otherwise					= Data.List.foldl' (\l -> ((l * fromIntegral base) +) . fromDigit) 0 s	where+	| abs base < 2			= error $ "Factory.Math.Radix.fromBase:\tan arbitrary integer can't be represented in base " ++ show base+	| abs base > fromIntegral (+		length digits+	)				= error $ "Factory.Math.Radix.fromBase:\tunable to clearly represent the complete set of digits in base " ++ show base+	| base > 0+	, '-' : remainder <- s	= negate $ fromBase base remainder	-- Recurse.+	| otherwise			= Data.List.foldl' (\l -> ((l * fromIntegral base) +) . fromDigit) 0 s	where 		fromDigit :: Integral i => Char -> i 		fromDigit c	= case c `lookup` decodes of 			Just i
src-lib/Factory/Math/Statistics.hs view
@@ -35,6 +35,7 @@ ) where  import			Control.Arrow((***))+import qualified	Control.Exception import			Control.Parallel(par, pseq) import qualified	Data.Foldable import qualified	Data.List@@ -54,11 +55,13 @@  ) 	=> foldable value 	-> result-getMean foldable-	| denominator == 0	= error "Factory.Math.Statistics.getMean:\tno data => undefined result."-	| otherwise		= realToFrac numerator / fromIntegral denominator-	where-		(numerator, denominator)	= Data.Foldable.foldr (\s -> (+ s) *** succ) (0, 0 :: Int) foldable+getMean foldable	= Control.Exception.assert (denominator /= 0) $ realToFrac numerator / fromIntegral denominator	where+	denominator :: Int+	(numerator, denominator)	= Data.Foldable.foldl' (+		\acc x	-> let+			acc'@(n, d)	= (+ x) *** succ $ acc+		in n `seq` d `seq` acc'+	 ) (0, 0) foldable  -- | Determines the /root mean square/ of the specified numbers; <https://en.wikipedia.org/wiki/Root_mean_square>. getRootMeanSquare :: (@@ -68,11 +71,13 @@  ) 	=> foldable value 	-> result-getRootMeanSquare foldable-	| denominator == 0	= error "Factory.Math.Statistics.getRootMeanSquare:\tno data => undefined result."-	| otherwise		= sqrt $ realToFrac numerator / fromIntegral denominator-	where-		(numerator, denominator)	= Data.Foldable.foldr (\s -> (+ Math.Power.square s) *** succ) (0, 0 :: Int) foldable+getRootMeanSquare foldable	= Control.Exception.assert (denominator /= 0) $ sqrt $ realToFrac numerator / fromIntegral denominator	where+	denominator :: Int+	(numerator, denominator)	= Data.Foldable.foldl' (+		\acc x -> let+			acc'@(n, d)	= (+ Math.Power.square x) *** succ $ acc+		 in n `seq` d `seq` acc'+	 ) (0, 0) foldable  {- | 	* Determines the /weighted mean/ of the specified numbers; <https://en.wikipedia.org/wiki/Weighted_arithmetic_mean>.@@ -92,17 +97,14 @@  ) 	=> foldable (value, weight)	-- ^ Each pair consists of a value & the corresponding weight. 	-> result-getWeightedMean foldable-	| denominator == 0	= error "Factory.Math.Statistics.getWeightedMean:\tzero weight => undefined result."-	| otherwise		= numerator / denominator-	where-		(numerator, denominator)	= Data.Foldable.foldr (-			\(value, weight)	-> let-				w	= realToFrac weight-			in if w == 0-				then id	-- Avoid unnecessarily evaluation.-				else (+ realToFrac value * w) *** (+ w)	-- Perform the arithmetic in the specified result-type.-		 ) (0, 0) foldable+getWeightedMean foldable = Control.Exception.assert (denominator /= 0) $ numerator / denominator	where+	(numerator, denominator)	= Data.Foldable.foldl' (+		\acc (value, weight)	-> case realToFrac weight of+			0	-> acc	-- Avoid unnecessarily evaluation.+			w	-> let+				acc'@(n, d)	= (+ realToFrac value * w) *** (+ w) $ acc	-- Perform the arithmetic in the specified result-type.+			 in n `seq` d `seq` acc'+	 ) (0, 0) foldable  {- | 	* Measures the /dispersion/ of a /population/ of results from the /mean/ value; <https://en.wikipedia.org/wiki/Statistical_dispersion>.@@ -162,11 +164,8 @@ 	Functor			foldable, 	Real			value  ) => foldable value -> result-getCoefficientOfVariance l-	| mean == 0	= error "Factory.Math.Statistics.getCoefficientOfVariance:\tundefined if mean is zero."-	| otherwise	= getStandardDeviation l / abs mean-	where-		mean	= getMean l+getCoefficientOfVariance l	= Control.Exception.assert (mean /= 0) $ getStandardDeviation l / abs mean	where+	mean	= getMean l  -- | The number of unordered /combinations/ of /r/ objects taken from /n/; <https://en.wikipedia.org/wiki/Combination>. nCr :: (Math.Factorial.Algorithmic factorialAlgorithm, Integral i, Show i)@@ -177,10 +176,8 @@ nCr _ 0 _	= 1 nCr _ _ 0	= 1 nCr factorialAlgorithm n r-	| n < 0		= error $ "Factory.Math.Statistics.nCr:\tinvalid n; " ++ show n-	| r < 0		= error $ "Factory.Math.Statistics.nCr:\tinvalid r; " ++ show r 	| n < r		= 0-	| otherwise	= numerator `par` (denominator `pseq` numerator `div` denominator)+	| otherwise	= Control.Exception.assert (n >= 0 && r >= 0) $ numerator `par` (denominator `pseq` numerator `div` denominator) 	where 		[smaller, bigger]	= Data.List.sort [r, n - r] 		numerator		= Math.Implementations.Factorial.risingFactorial (succ bigger) (n - bigger)@@ -194,8 +191,6 @@ nPr 0 _	= 1 nPr _ 0	= 1 nPr n r-	| n < 0		= error $ "Factory.Math.Statistics.nPr:\tinvalid n; " ++ show n-	| r < 0		= error $ "Factory.Math.Statistics.nPr:\tinvalid r; " ++ show r 	| n < r		= 0-	| otherwise	= Math.Implementations.Factorial.fallingFactorial n r+	| otherwise	= Control.Exception.assert (n >= 0 && r >= 0) $ Math.Implementations.Factorial.fallingFactorial n r