factory 0.2.0.4 → 0.2.0.5
raw patch · 19 files changed
+137/−89 lines, 19 filesdep ~toolshedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: toolshed
API changes (from Hackage documentation)
- Factory.Math.Hyperoperation: succession, hexation, pentation, tetration, exponentiation, multiplication, addition :: Int
+ Factory.Math.Hyperoperation: addition :: Int
+ Factory.Math.Hyperoperation: exponentiation :: Int
+ Factory.Math.Hyperoperation: hexation :: Int
+ Factory.Math.Hyperoperation: multiplication :: Int
+ Factory.Math.Hyperoperation: pentation :: Int
+ Factory.Math.Hyperoperation: succession :: Int
+ Factory.Math.Hyperoperation: tetration :: Int
+ Factory.Math.Primes: mersenneNumbers :: (Algorithmic algorithm, Integral i) => algorithm -> [i]
Files
- changelog +7/−0
- factory.cabal +3/−3
- makefile +8/−8
- src/Factory/Math/Implementations/Pi/Spigot/Spigot.hs +1/−1
- src/Factory/Math/Implementations/Primality.hs +2/−2
- src/Factory/Math/Implementations/PrimeFactorisation.hs +1/−3
- src/Factory/Math/Implementations/Primes/SieveOfAtkin.hs +6/−6
- src/Factory/Math/Implementations/Primes/TrialDivision.hs +1/−1
- src/Factory/Math/Implementations/Primes/TurnersSieve.hs +1/−1
- src/Factory/Math/Implementations/SquareRoot.hs +4/−4
- src/Factory/Math/PerfectPower.hs +1/−1
- src/Factory/Math/Primes.hs +15/−1
- src/Factory/Math/Probability.hs +4/−4
- src/Factory/Math/SquareRoot.hs +2/−2
- src/Factory/Math/Statistics.hs +2/−2
- src/Factory/Test/Performance/Primes.hs +8/−1
- src/Factory/Test/QuickCheck/Primality.hs +1/−1
- src/Factory/Test/QuickCheck/Primes.hs +1/−1
- src/Main.hs +69/−47
changelog view
@@ -55,3 +55,10 @@ 0.2.0.4 * Added classes 'Eq' and 'Show' to many contexts, for migration to 'ghc-7.4'. * Minor re-formatting.+0.2.0.5+ * Minor clarification of 'Factory.Math.Implementations.Primality.witnessesCompositeness'.+ * Added details to any failure to parse the command-line arguments.+ * Defined package's name using program's name, in "Main.hs".+ * Added 'Factory.Math.Primes.mersenneNumbers'.+ * Replaced use of 'mod' on positive integers, with the faster 'rem', in 'Factory.Math.Implementations.Pi.Spigot.Spigot.processColumns', 'Factory.Math.Implementations.Primality.witnessesCompositeness', 'Factory.Math.Implementations.Primes.TrialDivision.isIndivisibleBy', 'Factory.Math.Implementations.Primes.SieveOfAtkin.polynomialTypeLookup', 'Factory.Math.Implementations.Primes.SieveOfAtkin.findPolynomialSolutions', 'Factory.Math.Implementations.Primes.TurnersSieve.turnersSieve', 'Factory.Math.PerfectPower.maybeSquareNumber'.+ * Replaced calls to 'realToFrac' with 'toRational' in; "Factory.Math.Implementations.SquareRoot", 'Factory.Math.Statistics.getDispersionFromMean', 'Factory.Math.SquareRoot.getDiscrepancy', 'Factory.Math.SquareRoot.getAccuracy', to more clearly represent the required operation.
factory.cabal view
@@ -1,6 +1,6 @@ --Package-properties Name: factory-Version: 0.2.0.4+Version: 0.2.0.5 Cabal-Version: >= 1.6 Copyright: (C) 2011 Dr. Alistair Ward License: GPL@@ -11,7 +11,7 @@ Build-Type: Simple Description: A library of number-theory functions, for; factorials, square-roots, Pi and primes. Category: Math, Number Theory-Tested-With: GHC == 6.10, GHC == 6.12, GHC == 7.0+Tested-With: GHC == 6.10, GHC == 6.12, GHC == 7.0, GHC == 7.4 Homepage: http://functionalley.eu Maintainer: factory <at> functionalley <dot> eu Bug-reports: factory <at> functionalley <dot> eu@@ -95,7 +95,7 @@ containers, primes >= 0.1, random,- toolshed == 0.13.*+ toolshed >= 0.13 if flag(threaded) Build-depends: parallel >= 3.0
makefile view
@@ -19,37 +19,37 @@ install: build haddock @[ -z "$$CABAL_INSTALL_OPTIONS" ] || echo "INFO: CABAL_INSTALL_OPTIONS='$$CABAL_INSTALL_OPTIONS'"- runhaskell Setup.hs $@ $$CABAL_INSTALL_OPTIONS+ runhaskell Setup $@ $$CABAL_INSTALL_OPTIONS prof: CABAL_CONFIGURE_OPTIONS="--enable-library-profiling --enable-executable-profiling $$CABAL_CONFIGURE_OPTIONS" make install copy: build @[ -z "$$CABAL_COPY_OPTIONS" ] || echo "INFO: CABAL_COPY_OPTIONS='$$CABAL_COPY_OPTIONS'"- runhaskell Setup.hs $@ $$CABAL_COPY_OPTIONS+ runhaskell Setup $@ $$CABAL_COPY_OPTIONS build: configure @[ -z "$$CABAL_BUILD_OPTIONS" ] || echo "INFO: CABAL_BUILD_OPTIONS='$$CABAL_BUILD_OPTIONS'"- runhaskell Setup.hs $@ $$CABAL_BUILD_OPTIONS+ runhaskell Setup $@ $$CABAL_BUILD_OPTIONS configure: factory.cabal Setup.hs @[ -z "$$CABAL_CONFIGURE_OPTIONS" ] || echo "INFO: CABAL_CONFIGURE_OPTIONS='$$CABAL_CONFIGURE_OPTIONS'"- runhaskell Setup.hs $@ $$CABAL_CONFIGURE_OPTIONS #--user+ runhaskell Setup $@ $$CABAL_CONFIGURE_OPTIONS #--user haddock: configure- PATH=~/.cabal/bin:$$PATH runhaskell Setup.hs $@ --hyperlink-source #Amend path to find 'HsColour', as required for 'hyperlink-source'.+ PATH=~/.cabal/bin:$$PATH runhaskell Setup $@ --hyperlink-source #Amend path to find 'HsColour', as required for 'hyperlink-source'. hlint: @$@ -i 'Use &&' -i 'Reduce duplication' -i 'Redundant bracket' src/ -sdist: configure- runhaskell Setup.hs $@+sdist:+ runhaskell Setup $@ check: sdist cabal upload --check --verbose=3 dist/*.tar.gz; clean:- runhaskell Setup.hs $@+ runhaskell Setup $@ find src -type f \( -name '*.hc' -o -name '*.hcr' -o -name '*.hi' -o -name '*.o' \) -delete help:
src/Factory/Math/Implementations/Pi/Spigot/Spigot.hs view
@@ -111,7 +111,7 @@ processColumns series preDigits l | overflowMargin > 1 = preDigits ++ nextRow [digit] --There's neither overflow, nor risk of impact from subsequent overflow. | overflowMargin == 1 = nextRow $ preDigits ++ [digit] --There's no overflow, but risk of impact from subsequent overflow.- | otherwise = map ((`mod` decimal) . succ) preDigits ++ nextRow [0] --Overflow => propagate the excess to previously withheld preDigits.+ | otherwise = map ((`rem` decimal) . succ) preDigits ++ nextRow [0] --Overflow => propagate the excess to previously withheld preDigits. where results :: [QuotRem] results = init $ scanr carryAndDivide (0, undefined) l
src/Factory/Math/Implementations/Primality.hs view
@@ -167,10 +167,10 @@ -> i -- ^ Base. -> Bool witnessesCompositeness candidate oddRemainder nPowersOfTwo base = all (- $ ((`mod` candidate) . Math.Power.square) `iterate` Math.Power.raiseModulo base oddRemainder candidate --Repeatedly modulo-square.+ $ ((`rem` candidate) . Math.Power.square) `iterate` Math.Power.raiseModulo base oddRemainder candidate --Repeatedly modulo-square. ) [ (/= 1) . head, --Check whether the zeroeth modulo-power is incongruent to one.- all (/= pred candidate) . take nPowersOfTwo --Check whether any modulo-power is incongruent to -1.+ notElem (pred candidate) . take nPowersOfTwo --Check whether any modulo-power is incongruent to -1. ] {- |
src/Factory/Math/Implementations/PrimeFactorisation.hs view
@@ -73,9 +73,7 @@ FermatsMethod -> Data.PrimeFactors.reduce . factoriseByFermatsMethod TrialDivision -> factoriseByTrialDivision -{- |- * <http://en.wikipedia.org/wiki/Dixon%27s_factorization_method>.--}+-- | <http://en.wikipedia.org/wiki/Dixon%27s_factorization_method>. factoriseByDixonsMethod :: Integral base => base -> Data.PrimeFactors.Factors base exponent factoriseByDixonsMethod = undefined
src/Factory/Math/Implementations/Primes/SieveOfAtkin.hs view
@@ -113,14 +113,14 @@ -- select :: Integral i => i -> PolynomialType select n | any (- (== 0) . (n `mod`) --Though this is merely /Trial Division/, it's only performed over a short bounded interval of numerators.+ (== 0) . (n `rem`) --Though this is merely /Trial Division/, it's only performed over a short bounded interval of numerators. ) primeComponents = None | r `elem` [1, 5] = ModFour --We actually require @(n `mod` 4 == 1)@, but this is the equivalent modulo 12, with @(r == 9)@ removed because they're all divisible by /3/. | r == 7 = ModSix --We actually require @(n `mod` 6 == 1)@, but this is the equivalent modulo 12, where @(r == 1)@ has been accounted for above. | r == 11 = ModTwelve --We require @(n `mod` 12 == 11)@. | otherwise = None where- r = n `mod` atkinsModulus+ r = n `rem` atkinsModulus primeComponents = drop nInherentPrimes $ Data.PrimeWheel.getPrimeComponents primeWheel -- | The constant, infinite list of the /squares/, of integers increasing from /1/.@@ -176,19 +176,19 @@ x' <- takeWhile (<= pred maxPrime) $ map (* 4) squares, z <- takeWhile (<= maxPrime) $ map (+ x') oddSquares, lookupPolynomialType z == ModFour- ], --Twice the length of the other two lists.+ ], --List-comprehension. Twice the length of the other two lists. {-# SCC "3x^2+y^2" #-} filterOddRepetitions [ z | x' <- takeWhile (<= pred maxPrime) $ map (* 3) squares, z <- takeWhile (<= maxPrime) . map (+ x') $ if even x' then oddSelection else evenSelection, lookupPolynomialType z == ModSix- ],+ ], --List-comprehension. {-# SCC "3x^2-y^2" #-} filterOddRepetitions [ z | x2 <- takeWhile (<= maxPrime `div` 2) squares, z <- dropWhile (> maxPrime) . map (3 * x2 -) . takeWhile (< x2) $ if even x2 then oddSelection else evenSelection, lookupPolynomialType z == ModTwelve- ]+ ] --List-comprehension. ] where (evenSquares, oddSquares) = Data.List.partition even squares @@ -201,7 +201,7 @@ selection101 xs = xs -- lookupPolynomialType :: (Data.Array.IArray.Ix i, Integral i) => i -> PolynomialType- lookupPolynomialType = (polynomialTypeLookup primeWheel maxPrime !) . (`mod` polynomialTypeLookupPeriod primeWheel)+ lookupPolynomialType = (polynomialTypeLookup primeWheel maxPrime !) . (`rem` polynomialTypeLookupPeriod primeWheel) -- | Generates the /bounded/ list of multiples, of the /square/ of the specified prime, skipping those which aren't required. generateMultiplesOfSquareTo :: Integral i
src/Factory/Math/Implementations/Primes/TrialDivision.hs view
@@ -38,7 +38,7 @@ => i -- ^ The numerator. -> [i] -- ^ The denominators of which it must not be a multiple. -> Bool-isIndivisibleBy numerator = all ((/= 0) . (numerator `mod`)) . takeWhile (<= Math.PrimeFactorisation.maxBoundPrimeFactor numerator)+isIndivisibleBy numerator = all ((/= 0) . (numerator `rem`)) . takeWhile (<= Math.PrimeFactorisation.maxBoundPrimeFactor numerator) {-# INLINE isIndivisibleBy #-}
src/Factory/Math/Implementations/Primes/TurnersSieve.hs view
@@ -41,7 +41,7 @@ filter ( \candidate -> any ($ candidate) [ (< Math.Power.square prime), --Unconditionally admit any candidate smaller than the square of the last prime.- (/= 0) . (`mod` prime) --Ensure indivisibility, of all subsequent candidates, by the last prime discovered.+ (/= 0) . (`rem` prime) --Ensure indivisibility, of all subsequent candidates, by the last prime discovered. ] ) candidates )
src/Factory/Math/Implementations/SquareRoot.hs view
@@ -112,9 +112,9 @@ dydx = 2 * x --The gradient, at the estimated value 'x'. dx = recip $ dydx / dy - recip dydx --- step NewtonRaphsonIteration y x = (x + realToFrac y / x) / 2 --This is identical to the /Babylonian Method/.--- step NewtonRaphsonIteration y x = x / 2 + realToFrac y / (2 * x) --Faster.- step NewtonRaphsonIteration y x = x / 2 + (realToFrac y / 2) / x --Faster still.+-- step NewtonRaphsonIteration y x = (x + toRational y / x) / 2 --This is identical to the /Babylonian Method/.+-- step NewtonRaphsonIteration y x = x / 2 + toRational y / (2 * x) --Faster.+ step NewtonRaphsonIteration y x = x / 2 + (toRational y / 2) / x --Faster still. step (TaylorSeries terms) y x = squareRootByTaylorSeries terms y x @@ -184,7 +184,7 @@ | otherwise = Math.Summation.sumR' . take terms . zipWith (*) taylorSeriesCoefficients $ iterate (* relativeError) x where relativeError :: Math.SquareRoot.Result- relativeError = pred $ realToFrac y / Math.Power.square x --Pedantically, this is the error in y, which is twice the magnitude of the error in x.+ relativeError = pred $ toRational y / Math.Power.square x --Pedantically, this is the error in y, which is twice the magnitude of the error in x. -- | Iterates from the estimated value, towards the /square-root/, a sufficient number of times to achieve the required accuracy. squareRootByIteration :: Real operand => Algorithm -> ProblemSpecification operand
src/Factory/Math/PerfectPower.hs view
@@ -45,7 +45,7 @@ maybeSquareNumber :: Integral i => i -> Maybe i maybeSquareNumber i -- | i < 0 = Nothing --This function is performance-sensitive, but this test is neither strictly nor frequently required.- | all (\(modulus, valid) -> mod i modulus `elem` valid) [+ | all (\(modulus, valid) -> rem i modulus `elem` valid) [ -- --Distribution of moduli amongst perfect squares Cumulative failure-detection. (16, [0,1,4,9]), --All moduli are equally likely. 75% (9, [0,1,4,7]), --Zero occurs 33%, the others only 22%. 88%
src/Factory/Math/Primes.hs view
@@ -24,7 +24,8 @@ -- * Types-classes Algorithmic(..), -- * Functions- primorial+ primorial,+ mersenneNumbers ) where import qualified Control.DeepSeq@@ -48,3 +49,16 @@ Integral i ) => algorithm -> [i] primorial = scanl (*) 1 . primes++{- |+ * Returns the constant ordered infinite list of /Mersenne numbers/.++ * Only the subset composed from a prime exponent is returned; which is a strict superset of the /Mersenne Primes/.++ * <http://en.wikipedia.org/wiki/Mersenne_prime>.++ * <http://mathworld.wolfram.com/MersenneNumber.html>+-}+mersenneNumbers :: (Algorithmic algorithm, Integral i) => algorithm -> [i]+mersenneNumbers algorithm = map (pred . (2 ^)) (primes algorithm :: [Int]) --Whilst the exponentiation could be parallelised, not all values are known to be required.+
src/Factory/Math/Probability.hs view
@@ -45,7 +45,7 @@ -- | Describes a /continuous probability-distribution/; <http://en.wikipedia.org/wiki/List_of_probability_distributions#Continuous_distributions>. data ContinuousDistribution f- = UniformDistribution (Data.Interval.Interval f) -- ^ Defines a /Uniform/-distribution within a closed /interval/; <http://en.wikipedia.org/wiki/Uniform_distribution>.+ = UniformDistribution (Data.Interval.Interval f) -- ^ Defines a /Uniform/-distribution within a /closed interval/; <http://en.wikipedia.org/wiki/Uniform_distribution>. | NormalDistribution f f -- ^ Defines a /Normal/-distribution with a particular /mean/ and /variance/; <http://en.wikipedia.org/wiki/Normal_distribution>. deriving (Eq, Read, Show) @@ -61,13 +61,13 @@ getErrors (PoissonDistribution lambda) = ToolShed.SelfValidate.extractErrors [(lambda < 0, "Negative lambda=" ++ show lambda ++ ".")] {- |- * Converts a pair of independent /uniformly distributed/ random numbers, within the /semi-closed/ /unit interval/ /(0 .. 1]/,+ * Converts a pair of independent /uniformly distributed/ random numbers, within the /semi-closed unit interval/ /(0,1]/, to a pair of independent /normally distributed/ random numbers, of standardized /mean/=0, and /variance/=1. * <http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform>. -} boxMullerTransform :: (Floating f, Ord f, Show f)- => (f, f) -- ^ Independent, /uniformly distributed/ random numbers, which must be within the /semi-closed unit interval/, /(0, 1]/.+ => (f, f) -- ^ Independent, /uniformly distributed/ random numbers, which must be within the /semi-closed unit interval/, /(0,1]/. -> (f, f) -- ^ Independent, /normally distributed/ random numbers, with standardized /mean/=0 and /variance/=1. boxMullerTransform cartesian | not . uncurry (&&) $ ToolShed.Data.Pair.mirror inSemiClosedUnitInterval cartesian = error $ "Factory.Math.Probability.boxMullerTransform:\tspecified Cartesian coordinates, must be within semi-closed unit-interval (0, 1]; " ++ show cartesian@@ -126,7 +126,7 @@ -> [f] generateContinuousPopulation 0 _ _ = [] generateContinuousPopulation populationSize probabilityDistribution randomGen- | populationSize < 0 = error $ "Factory.Math.Probability.generateDiscretePopulation:\tinvalid population-size=" ++ show populationSize+ | populationSize < 0 = error $ "Factory.Math.Probability.generateContinuousPopulation:\tinvalid population-size=" ++ show populationSize | not $ ToolShed.SelfValidate.isValid probabilityDistribution = error $ "Factory.Math.Probability.generateContinuousPopulation:\t" ++ ToolShed.SelfValidate.getFirstError probabilityDistribution | otherwise = take populationSize $ ( case probabilityDistribution of
src/Factory/Math/SquareRoot.hs view
@@ -98,7 +98,7 @@ * CAVEAT: the magnitude is twice the error in the /square-root/. -} getDiscrepancy :: Real operand => operand -> Result -> Result-getDiscrepancy y x = realToFrac y - Math.Power.square x+getDiscrepancy y x = toRational y - Math.Power.square x -- | True if the specified estimate for the /square-root/, is precise. isPrecise :: Real operand => operand -> Result -> Bool@@ -114,7 +114,7 @@ getAccuracy y x | absoluteError == 0 = maxBound --Bodge. -- | otherwise = length . takeWhile (< 1) $ iterate (* 10) relativeError --CAVEAT: too slow.- | otherwise = length $ show (round $ realToFrac y / absoluteError :: Integer)+ | otherwise = length $ show (round $ toRational y / absoluteError :: Integer) where absoluteError :: Result absoluteError = abs (getDiscrepancy y x) / 2 --NB: the magnitude of the error in 'y', is twice the error in its square-root, 'x'.
src/Factory/Math/Statistics.hs view
@@ -48,7 +48,7 @@ -} getMean :: (Data.Foldable.Foldable f, Real r, Fractional result) => f r -> result getMean x- | denominator == 0 = error "Factory.Math.Statistics.getMean:\tno data => no result."+ | 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) x@@ -64,7 +64,7 @@ Functor f, Real r ) => (Data.Ratio.Rational -> Data.Ratio.Rational) -> f r -> result-getDispersionFromMean weight x = getMean $ fmap (weight . (+ negate mean) . realToFrac) x where+getDispersionFromMean weight x = getMean $ fmap (weight . (+ negate mean) . toRational) x where mean :: Data.Ratio.Rational mean = getMean x
src/Factory/Test/Performance/Primes.hs view
@@ -22,7 +22,8 @@ module Factory.Test.Performance.Primes( -- * Functions- primesPerformance+ primesPerformance,+ mersenneNumbersPerformance ) where import qualified Control.DeepSeq@@ -38,3 +39,9 @@ Integral i ) => algorithm -> Int -> IO (Double, i) primesPerformance algorithm = ToolShed.System.TimePure.getCPUSeconds . (Math.Primes.primes algorithm !!)++-- | Measures the CPU-time required to find the specified number of /Mersenne/-numbers, which is returned together with the requested list.+mersenneNumbersPerformance :: Math.Primes.Algorithmic algorithm => algorithm -> Int -> IO (Double, [Integer])+mersenneNumbersPerformance primalityAlgorithm i+ | i < 0 = error $ "Factory.Test.Performance.Primes.mersenneNumbersPerformance:\tnegative number; " ++ show i+ | otherwise = ToolShed.System.TimePure.getCPUSeconds . take i $ Math.Primes.mersenneNumbers primalityAlgorithm
src/Factory/Test/QuickCheck/Primality.hs view
@@ -40,7 +40,7 @@ instance Test.QuickCheck.Arbitrary factorisationAlgorithm => Test.QuickCheck.Arbitrary (Math.Implementations.Primality.Algorithm factorisationAlgorithm) where arbitrary = Test.QuickCheck.oneof [ Math.Implementations.Primality.AKS <$> Test.QuickCheck.arbitrary,- return Math.Implementations.Primality.MillerRabin+ return {-to Gen-monad-} Math.Implementations.Primality.MillerRabin ] #if !(MIN_VERSION_QuickCheck(2,1,0)) coarbitrary = undefined --CAVEAT: stops warnings from ghc.
src/Factory/Test/QuickCheck/Primes.hs view
@@ -46,7 +46,7 @@ instance Test.QuickCheck.Arbitrary Math.Implementations.Primes.Algorithm.Algorithm where arbitrary = Test.QuickCheck.oneof [- return Math.Implementations.Primes.Algorithm.TurnersSieve,+ return {-to Gen-monad-} Math.Implementations.Primes.Algorithm.TurnersSieve, Math.Implementations.Primes.Algorithm.TrialDivision . (`mod` 10) <$> Test.QuickCheck.arbitrary, Math.Implementations.Primes.Algorithm.SieveOfEratosthenes . (`mod` 10) <$> Test.QuickCheck.arbitrary ]
src/Main.hs view
@@ -29,6 +29,8 @@ -- ** Type-synonyms -- CommandLineAction, -- * Functions+-- read',+-- readCommandArg, main ) where @@ -69,113 +71,131 @@ -- | Used to thread user-defined command-line options, though the list of functions which implement them. type CommandLineAction = Test.CommandOptions.CommandOptions -> IO Test.CommandOptions.CommandOptions --Supplied as the type-argument to 'G.OptDescr'. +-- | On failure to parse the specified string, returns an explanatory error.+read' :: Read a => String -> String -> a+read' errorMessage s = case reads s of+ [(x, _)] -> x+ _ -> error $ errorMessage ++ show s++-- | On failure to parse a command-line argument, returns an explanatory error.+readCommandArg :: Read a => String -> a+readCommandArg = read' "Failed to parse command-line argument "+ -- | Parses the command-line arguments, to determine 'Test.CommandOptions.CommandOptions'. main :: IO () main = do progName <- System.Environment.getProgName- args <- System.Environment.getArgs let- usage :: String- usage = "Usage:\t" ++ G.usageInfo progName optDescrList+ usageMessage :: String+ usageMessage = "Usage:\t" ++ G.usageInfo progName optDescrList ---Define the command-line options, and the 'CommandLineAction's used to handle them. optDescrList :: [G.OptDescr CommandLineAction] optDescrList = [--- String [String] (G.ArgDescr CommandLineAction) String- G.Option "?" ["help"] (G.NoArg $ const printUsage) "Display this help-text & then exit.",- G.Option "" ["verbose"] (G.NoArg $ return {-to IO-monad-} . Test.CommandOptions.setVerbose) ("Provide additional information where available; default '" ++ show (Test.CommandOptions.verbose ToolShed.Defaultable.defaultValue) ++ "'."),- G.Option "" ["version"] (G.NoArg $ const printVersion) "Print version-information & then exit.",- G.Option "q" ["runQuickChecks"] (G.NoArg $ const runQuickChecks) "Run Quick-checks using arbitrary data & then exit.",- G.Option "" ["carmichaelNumbersPerformance"] (carmichaelNumbersPerformance `G.ReqArg` "(Math.Implementations.Primality.Algorithm, Int)") "Test the performance of 'Math.Primality.carmichaelNumbers'.",- G.Option "" ["factorialPerformance"] (factorialPerformance `G.ReqArg` "(Math.Implementations.Factorial.Algorithm, Integer)") "Test the performance of 'Math.Factorial.factorial'.",- G.Option "" ["factorialPerformanceGraph"] (factorialPerformanceGraph `G.ReqArg` "Math.Implementations.Factorial.Algorithm") "Test the performance of 'Math.Factorial.factorial', with an exponentially increasing operand.",- G.Option "" ["factorialPerformanceGraphControl"] (G.NoArg factorialPerformanceGraphControl) "Test the performance of a naive factorial-implementation, with an exponentially increasing operand.",- G.Option "" ["hyperoperationPerformance"] (hyperoperationPerformance `G.ReqArg` "(Integer, Math.Hyperoperation.Base, Math.Hyperoperation.HyperExponent)") "Test the performance of 'Math.Hyperoperation.hyperoperation', against the specified rank, base and hyper-exponent.",- G.Option "" ["hyperoperationPerformanceGraphRank"] (hyperoperationPerformanceGraphRank `G.ReqArg` "(Math.Hyperoperation.Base, Math.Hyperoperation.HyperExponent)") "Test the performance of 'Math.Hyperoperation.hyperoperation', for the specified base and hyper-exponent, and a linearly increasing rank.",- G.Option "" ["hyperoperationPerformanceGraphExponent"] (hyperoperationPerformanceGraphExponent `G.ReqArg` "(Integer, Math.Hyperoperation.Base)") "Test the performance of 'Math.Hyperoperation.hyperoperation', for the specified rank and base, and a linearly increasing hyper-exponent.",- G.Option "" ["isPrimePerformance"] (isPrimePerformance `G.ReqArg` "(Math.Implementations.Primality.Algorithm, Integer)") "Test the performance of 'Math.Primality.isPrime'.",- G.Option "" ["isPrimePerformanceGraph"] (isPrimePerformanceGraph `G.ReqArg` "Math.Implementations.Primality.Algorithm") "Test the performance of 'Math.Primality.isPrime', against the prime-indexed Fibonacci-numbers.",- G.Option "" ["nCrPerformance"] (nCrPerformance `G.ReqArg` "(Math.Implementations.Factorial.Algorithm, Integer, Integer)") "Test the performance of 'Math.Factorial.factorial'.",- G.Option "" ["piPerformance"] (piPerformance `G.ReqArg` "(Math.Pi.Category, Math.Precision.DecimalDigits)") "Test the performance of 'Math.Pi.openI'.",- G.Option "" ["piPerformanceGraph"] (piPerformanceGraph `G.ReqArg` "(Math.Pi.Category, Double, Math.Precision.DecimalDigits)") "Test the performance of 'Math.Pi.openI', with an exponential precision-requirement (of the specified exponent), up to the specified limit.",- G.Option "" ["primeFactorsPerformance"] (primeFactorsPerformance `G.ReqArg` "(Math.Implementations.PrimeFactorisation.Algorithm, Integer)") "Test the performance of 'Math.PrimeFactorisation.primeFactors'.",- G.Option "" ["primeFactorsPerformanceGraph"] (primeFactorsPerformanceGraph `G.ReqArg` "(Math.Implementations.PrimeFactorisation.Algorithm, Int)") "Test the performance of 'Math.PrimeFactorisation.primeFactors', on the specified number of odd integers from the Fibonacci-sequence.",- G.Option "" ["primesPerformance"] (primesPerformance `G.ReqArg` "(Math.Implementations.Primes.Algorithm.Algorithm, Int)") "Test the performance of 'Math.Primes.primes'.",- G.Option "" ["squareRootPerformance"] (squareRootPerformance `G.ReqArg` "(Math.Implementations.SquareRoot.Algorithm, Data.Ratio.Rational, DecimalDigits)") "Test the performance of 'Math.SquareRoot.squareRoot'.",- G.Option "" ["squareRootPerformanceGraph"] (squareRootPerformanceGraph `G.ReqArg` "(Math.Implementations.SquareRoot.Algorithm, Data.Ratio.Rational)") "Test the performance of 'Math.SquareRoot.squareRoot', with an exponentially increasing precision-requirement."+-- String [String] (G.ArgDescr CommandLineAction) String+ G.Option "?" ["help"] (G.NoArg $ const printUsage) "Display this help-text & then exit.",+ G.Option "" ["verbose"] (G.NoArg $ return {-to IO-monad-} . Test.CommandOptions.setVerbose) ("Provide additional information where available; default '" ++ show (Test.CommandOptions.verbose ToolShed.Defaultable.defaultValue) ++ "'."),+ G.Option "" ["version"] (G.NoArg $ const printVersion) "Print version-information & then exit.",+ G.Option "q" ["runQuickChecks"] (G.NoArg $ const runQuickChecks) "Run Quick-checks using arbitrary data & then exit.",+ G.Option "" ["carmichaelNumbersPerformance"] (carmichaelNumbersPerformance `G.ReqArg` "(Math.Implementations.Primality.Algorithm, Int)") "Test the performance of 'Math.Primality.carmichaelNumbers'.",+ G.Option "" ["factorialPerformance"] (factorialPerformance `G.ReqArg` "(Math.Implementations.Factorial.Algorithm, Integer)") "Test the performance of 'Math.Factorial.factorial'.",+ G.Option "" ["factorialPerformanceGraph"] (factorialPerformanceGraph `G.ReqArg` "Math.Implementations.Factorial.Algorithm") "Test the performance of 'Math.Factorial.factorial', with an exponentially increasing operand.",+ G.Option "" ["factorialPerformanceGraphControl"] (G.NoArg factorialPerformanceGraphControl) "Test the performance of a naive factorial-implementation, with an exponentially increasing operand.",+ G.Option "" ["hyperoperationPerformance"] (hyperoperationPerformance `G.ReqArg` "(Integer, Math.Hyperoperation.Base, Math.Hyperoperation.HyperExponent)") "Test the performance of 'Math.Hyperoperation.hyperoperation', against the specified rank, base and hyper-exponent.",+ G.Option "" ["hyperoperationPerformanceGraphRank"] (hyperoperationPerformanceGraphRank `G.ReqArg` "(Math.Hyperoperation.Base, Math.Hyperoperation.HyperExponent)") "Test the performance of 'Math.Hyperoperation.hyperoperation', for the specified base and hyper-exponent, and a linearly increasing rank.",+ G.Option "" ["hyperoperationPerformanceGraphExponent"] (hyperoperationPerformanceGraphExponent `G.ReqArg` "(Integer, Math.Hyperoperation.Base)") "Test the performance of 'Math.Hyperoperation.hyperoperation', for the specified rank and base, and a linearly increasing hyper-exponent.",+ G.Option "" ["isPrimePerformance"] (isPrimePerformance `G.ReqArg` "(Math.Implementations.Primality.Algorithm, Integer)") "Test the performance of 'Math.Primality.isPrime'.",+ G.Option "" ["isPrimePerformanceGraph"] (isPrimePerformanceGraph `G.ReqArg` "Math.Implementations.Primality.Algorithm") "Test the performance of 'Math.Primality.isPrime', against the prime-indexed Fibonacci-numbers.",+ G.Option "" ["mersenneNumbersPerformance"] (mersenneNumbersPerformance `G.ReqArg` "(Math.Implementations.Primes.Algorithm.Algorithm, Int)") "Test the performance of 'Math.Primes.mersenneNumbers'.",+ G.Option "" ["factorialPerformance"] (factorialPerformance `G.ReqArg` "(Math.Implementations.Factorial.Algorithm, Integer)") "Test the performance of 'Math.Factorial.factorial'.",+ G.Option "" ["nCrPerformance"] (nCrPerformance `G.ReqArg` "(Math.Implementations.Factorial.Algorithm, Integer, Integer)") "Test the performance of 'Math.Factorial.factorial'.",+ G.Option "" ["piPerformance"] (piPerformance `G.ReqArg` "(Math.Pi.Category, Math.Precision.DecimalDigits)") "Test the performance of 'Math.Pi.openI'.",+ G.Option "" ["piPerformanceGraph"] (piPerformanceGraph `G.ReqArg` "(Math.Pi.Category, Double, Math.Precision.DecimalDigits)") "Test the performance of 'Math.Pi.openI', with an exponential precision-requirement (of the specified exponent), up to the specified limit.",+ G.Option "" ["primeFactorsPerformance"] (primeFactorsPerformance `G.ReqArg` "(Math.Implementations.PrimeFactorisation.Algorithm, Integer)") "Test the performance of 'Math.PrimeFactorisation.primeFactors'.",+ G.Option "" ["primeFactorsPerformanceGraph"] (primeFactorsPerformanceGraph `G.ReqArg` "(Math.Implementations.PrimeFactorisation.Algorithm, Int)") "Test the performance of 'Math.PrimeFactorisation.primeFactors', on the specified number of odd integers from the Fibonacci-sequence.",+ G.Option "" ["primesPerformance"] (primesPerformance `G.ReqArg` "(Math.Implementations.Primes.Algorithm.Algorithm, Int)") "Test the performance of 'Math.Primes.primes'.",+ G.Option "" ["squareRootPerformance"] (squareRootPerformance `G.ReqArg` "(Math.Implementations.SquareRoot.Algorithm, Data.Ratio.Rational, DecimalDigits)") "Test the performance of 'Math.SquareRoot.squareRoot'.",+ G.Option "" ["squareRootPerformanceGraph"] (squareRootPerformanceGraph `G.ReqArg` "(Math.Implementations.SquareRoot.Algorithm, Data.Ratio.Rational)") "Test the performance of 'Math.SquareRoot.squareRoot', with an exponentially increasing precision-requirement." ] where printVersion, printUsage, runQuickChecks :: IO Test.CommandOptions.CommandOptions- printVersion = System.IO.hPutStrLn System.IO.stderr (Distribution.Text.display packageIdentifier ++ "\n\nCopyright (C) 2011 Dr. Alistair Ward.\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it under certain conditions.\n\nWritten by Dr. Alistair Ward.") >> System.Exit.exitWith System.Exit.ExitSuccess where+ printVersion = System.IO.hPutStrLn System.IO.stderr (Distribution.Text.display packageIdentifier ++ "\n\nCopyright (C) 2011 " ++ 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 ++ ".") >> System.Exit.exitWith System.Exit.ExitSuccess where packageIdentifier :: Distribution.Package.PackageIdentifier packageIdentifier = Distribution.Package.PackageIdentifier {- Distribution.Package.pkgName = Distribution.Package.PackageName "factory",+ Distribution.Package.pkgName = Distribution.Package.PackageName progName, --CAVEAT: coincidentally. Distribution.Package.pkgVersion = Distribution.Version.Version (Data.Version.versionBranch Paths.version) [] } - printUsage = System.IO.hPutStrLn System.IO.stderr usage >> System.Exit.exitWith System.Exit.ExitSuccess+ author :: String+ author = "Dr. Alistair Ward"++ printUsage = System.IO.hPutStrLn System.IO.stderr usageMessage >> System.Exit.exitWith System.Exit.ExitSuccess+ runQuickChecks = Test.QuickCheck.QuickChecks.run >> System.Exit.exitWith System.Exit.ExitSuccess factorialPerformanceGraphControl :: Test.CommandOptions.CommandOptions -> IO Test.CommandOptions.CommandOptions factorialPerformanceGraphControl commandOptions = Test.Performance.Factorial.factorialPerformanceGraphControl (Test.CommandOptions.verbose commandOptions) >> System.Exit.exitWith (System.Exit.ExitFailure 1) - carmichaelNumbersPerformance, factorialPerformance, factorialPerformanceGraph, hyperoperationPerformance, hyperoperationPerformanceGraphRank, hyperoperationPerformanceGraphExponent, isPrimePerformance, isPrimePerformanceGraph, piPerformance, piPerformanceGraph, primeFactorsPerformance, primesPerformance, squareRootPerformance, squareRootPerformanceGraph :: String -> CommandLineAction+ carmichaelNumbersPerformance, factorialPerformance, factorialPerformanceGraph, hyperoperationPerformance, hyperoperationPerformanceGraphRank, hyperoperationPerformanceGraphExponent, isPrimePerformance, isPrimePerformanceGraph, mersenneNumbersPerformance, piPerformance, piPerformanceGraph, primeFactorsPerformance, primesPerformance, squareRootPerformance, squareRootPerformanceGraph :: String -> CommandLineAction carmichaelNumbersPerformance arg _ = Test.Performance.Primality.carmichaelNumbersPerformance algorithm i >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where algorithm :: PrimalityAlgorithm- (algorithm, i) = read arg+ (algorithm, i) = readCommandArg arg factorialPerformance arg _ = Test.Performance.Factorial.factorialPerformance algorithm i >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where algorithm :: Math.Implementations.Factorial.Algorithm i :: Integer- (algorithm, i) = read arg+ (algorithm, i) = readCommandArg arg - factorialPerformanceGraph arg commandOptions = Test.Performance.Factorial.factorialPerformanceGraph (Test.CommandOptions.verbose commandOptions) (read arg :: Math.Implementations.Factorial.Algorithm) >> System.Exit.exitWith (System.Exit.ExitFailure 1)+ factorialPerformanceGraph arg commandOptions = Test.Performance.Factorial.factorialPerformanceGraph (Test.CommandOptions.verbose commandOptions) (readCommandArg arg :: Math.Implementations.Factorial.Algorithm) >> System.Exit.exitWith (System.Exit.ExitFailure 1) hyperoperationPerformance arg _ = Test.Performance.Hyperoperation.hyperoperationPerformance rank base hyperExponent >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where rank :: Integer base :: Math.Hyperoperation.Base hyperExponent :: Math.Hyperoperation.HyperExponent- (rank, base, hyperExponent) = read arg+ (rank, base, hyperExponent) = readCommandArg arg hyperoperationPerformanceGraphRank arg commandOptions = Test.Performance.Hyperoperation.hyperoperationPerformanceGraphRank (Test.CommandOptions.verbose commandOptions) base hyperExponent >> System.Exit.exitWith (System.Exit.ExitFailure 1) where base :: Math.Hyperoperation.Base hyperExponent :: Math.Hyperoperation.HyperExponent- (base, hyperExponent) = read arg+ (base, hyperExponent) = readCommandArg arg hyperoperationPerformanceGraphExponent arg commandOptions = Test.Performance.Hyperoperation.hyperoperationPerformanceGraphExponent (Test.CommandOptions.verbose commandOptions) rank base >> System.Exit.exitWith (System.Exit.ExitFailure 1) where rank :: Integer base :: Math.Hyperoperation.Base- (rank, base) = read arg+ (rank, base) = readCommandArg arg isPrimePerformance arg _ = Test.Performance.Primality.isPrimePerformance algorithm i >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where algorithm :: PrimalityAlgorithm i :: Integer- (algorithm, i) = read arg+ (algorithm, i) = readCommandArg arg - isPrimePerformanceGraph arg _ = Test.Performance.Primality.isPrimePerformanceGraph (read arg :: Math.Implementations.Primality.Algorithm Math.Implementations.PrimeFactorisation.Algorithm) >> System.Exit.exitWith (System.Exit.ExitFailure 1)+ isPrimePerformanceGraph arg _ = Test.Performance.Primality.isPrimePerformanceGraph (readCommandArg arg :: Math.Implementations.Primality.Algorithm Math.Implementations.PrimeFactorisation.Algorithm) >> System.Exit.exitWith (System.Exit.ExitFailure 1) + mersenneNumbersPerformance arg _ = Test.Performance.Primes.mersenneNumbersPerformance algorithm i >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where+ algorithm :: Math.Implementations.Primes.Algorithm.Algorithm+ (algorithm, i) = readCommandArg arg+ nCrPerformance arg _ = Test.Performance.Statistics.nCrPerformance algorithm n r >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where algorithm :: Math.Implementations.Factorial.Algorithm n, r :: Integer- (algorithm, n, r) = read arg+ (algorithm, n, r) = readCommandArg arg piPerformance arg _ = Test.Performance.Pi.piPerformance category decimalDigits >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where category :: PiCategory- (category, decimalDigits) = read arg+ (category, decimalDigits) = readCommandArg arg piPerformanceGraph arg commandOptions = Test.Performance.Pi.piPerformanceGraph category factor maxDecimalDigits (Test.CommandOptions.verbose commandOptions) >> System.Exit.exitWith (System.Exit.ExitFailure 1) where category :: PiCategory factor :: Double- (category, factor, maxDecimalDigits) = read arg+ (category, factor, maxDecimalDigits) = readCommandArg arg primeFactorsPerformance arg _ = Test.Performance.PrimeFactorisation.primeFactorsPerformance algorithm i >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where algorithm :: Math.Implementations.PrimeFactorisation.Algorithm- (algorithm, i) = read arg+ (algorithm, i) = readCommandArg arg primeFactorsPerformanceGraph arg _ = Test.Performance.PrimeFactorisation.primeFactorsPerformanceGraph algorithm index >> System.Exit.exitWith (System.Exit.ExitFailure 1) where algorithm :: Math.Implementations.PrimeFactorisation.Algorithm- (algorithm, index) = read arg+ (algorithm, index) = readCommandArg arg primesPerformance arg _ = ( (@@ -195,20 +215,22 @@ ) ) >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where algorithm :: Math.Implementations.Primes.Algorithm.Algorithm- (algorithm, index) = read arg+ (algorithm, index) = readCommandArg arg squareRootPerformance arg _ = Test.Performance.SquareRoot.squareRootPerformance algorithm operand decimalDigits >>= print >> System.Exit.exitWith System.Exit.ExitSuccess where algorithm :: Math.Implementations.SquareRoot.Algorithm operand :: Data.Ratio.Rational- (algorithm, operand, decimalDigits) = read arg+ (algorithm, operand, decimalDigits) = readCommandArg arg squareRootPerformanceGraph arg _ = Test.Performance.SquareRoot.squareRootPerformanceGraph algorithm operand >> System.Exit.exitWith (System.Exit.ExitFailure 1) where algorithm :: Math.Implementations.SquareRoot.Algorithm operand :: Data.Ratio.Rational- (algorithm, operand) = read arg+ (algorithm, operand) = readCommandArg arg + args <- System.Environment.getArgs+ -- G.getOpt :: G.ArgOrder CommandLineAction -> [G.OptDescr Action] -> [String] -> ([Action], [String], [String]) case G.getOpt G.RequireOrder optDescrList args of (commandLineActions, _, []) -> Data.List.foldl' (>>=) (return {-to IO-monad-} ToolShed.Defaultable.defaultValue) commandLineActions >> System.Exit.exitWith System.Exit.ExitSuccess- (_, _, errors) -> System.IO.Error.ioError . System.IO.Error.userError $ concat errors ++ usage --Throw.+ (_, _, errors) -> System.IO.Error.ioError . System.IO.Error.userError $ concat errors ++ usageMessage --Throw.