-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Rational arithmetic in an irrational world. -- -- A library of number-theory functions, for; factorials, square-roots, -- Pi and primes. @package factory @version 0.2.0.5 -- | module Factory.Math.Radix -- | digitSum :: (Ix decimal, Integral base, Integral decimal, Show base, Show decimal) => base -> decimal -> decimal -- | http://en.wikipedia.org/wiki/Digital_root. digitalRoot :: (Ix decimal, Integral decimal, Show decimal) => decimal -> decimal -- | fromBase :: (Integral base, Integral decimal, Read decimal, Show base) => base -> String -> decimal -- | toBase :: (Ix decimal, Integral base, Integral decimal, Show base, Show decimal) => base -> decimal -> String -- | module Factory.Math.Primes -- | Defines the methods expected of a prime-number generator. class Algorithmic algorithm primes :: (Algorithmic algorithm, NFData i, Ix i, Integral i) => algorithm -> [i] -- | primorial :: (Algorithmic algorithm, NFData i, Ix i, Integral i) => algorithm -> [i] -- | mersenneNumbers :: (Algorithmic algorithm, Integral i) => algorithm -> [i] -- | module Factory.Math.Summation -- | sum' :: (Num n, NFData n) => Int -> [n] -> n -- | sumR' :: Integral i => [Ratio i] -> Ratio i -- | sumR :: (Integral i, NFData i) => Int -> [Ratio i] -> Ratio i -- | module Factory.Math.Implementations.Pi.BBP.Series -- | Defines a series corresponding to a specific BBP-formula. data Series MkSeries :: [Integer] -> (Int -> [Integer]) -> Rational -> Integer -> Series -- | The constant numerators from which each term in the series is -- composed. numerators :: Series -> [Integer] -- | Generates the term-dependent denominators from which each term in the -- series is composed. getDenominators :: Series -> Int -> [Integer] -- | The ratio by which the sum to infinity of the series, must be scaled -- to result in Pi. seriesScalingFactor :: Series -> Rational -- | The geometric ratio, by which successive terms are scaled. base :: Series -> Integer -- | module Factory.Math.Implementations.Pi.BBP.Bellard -- | Defines the parameters of this specific series. series :: Series -- | module Factory.Math.Implementations.Pi.BBP.Base65536 -- | Defines the parameters of this specific series. series :: Series -- | module Factory.Math.Power -- | Mainly for convenience. square :: Num n => n -> n -- | squaresFrom :: (Enum n, Num n) => n -> [(n, n)] -- | Just for convenience. cube :: Num n => n -> n -- | Just for convenience. cubeRoot :: Double -> Double -- | raiseModulo :: (Integral i, Integral power, Show power) => i -> power -> i -> i -- | module Factory.Math.PerfectPower -- | maybeSquareNumber :: Integral i => i -> Maybe i -- | isPerfectPower :: Integral i => i -> Bool -- | -- -- module Factory.Math.Primality -- | Defines the methods expected of a primality-testing algorithm. class Algorithmic algorithm isPrime :: (Algorithmic algorithm, NFData i, Integral i, Show i) => algorithm -> i -> Bool -- | An ordered list of the Carmichael numbers; -- http://en.wikipedia.org/wiki/Carmichael_number. carmichaelNumbers :: (Algorithmic algorithm, NFData i, Integral i, Show i) => algorithm -> [i] -- | True if the two specified integers are relatively prime, -- i.e. if they share no common positive factors except one. -- -- areCoprime :: Integral i => i -> i -> Bool -- | isFermatWitness :: (Integral i, Show i) => i -> Bool -- | isCarmichaelNumber :: (Algorithmic algorithm, NFData i, Integral i, Show i) => algorithm -> i -> Bool -- | module Factory.Math.Implementations.Primes.TurnersSieve -- | turnersSieve :: Integral prime => [prime] -- | module Factory.Math.Hyperoperation -- | type Base = Integer -- | type HyperExponent = Base succession :: Int addition :: Int multiplication :: Int exponentiation :: Int tetration :: Int pentation :: Int hexation :: Int -- | The hyperoperation-sequence; -- http://en.wikipedia.org/wiki/Hyperoperation. hyperoperation :: (Integral rank, Show rank) => rank -> Base -> HyperExponent -> Base -- | The Ackermann-Peter-function; -- http://en.wikipedia.org/wiki/Ackermann_function#Ackermann_numbers. ackermannPeter :: (Integral rank, Show rank) => rank -> HyperExponent -> Base -- | powerTower :: (Integral base, Integral hyperExponent, Show base) => base -> hyperExponent -> base -- | True if hyperoperation base hyperExponent has the same value -- for each specified rank. areCoincidental :: (Integral rank, Show rank) => Base -> HyperExponent -> [rank] -> Bool -- | module Factory.Math.Fibonacci -- | A constant ordered list of the Fibonacci-numbers. fibonacci :: Integral i => [i] -- | primeIndexedFibonacci :: Integral i => [i] -- | -- -- module Factory.Math.Factorial -- | Defines the methods expected of a factorial-algorithm. class Algorithmic algorithm factorial :: (Algorithmic algorithm, Integral i, Show i) => algorithm -> i -> i -- | module Factory.Math.Precision -- | The order of convergence; -- http://en.wikipedia.org/wiki/Rate_of_convergence. type ConvergenceOrder = Int -- | The rate of convergence; -- http://en.wikipedia.org/wiki/Rate_of_convergence. type ConvergenceRate = Double -- | A number of decimal digits. type DecimalDigits = Int -- | Linear convergence-rate; which may be qualified by the rate -- of convergence. linearConvergence :: ConvergenceOrder -- | Quadratic convergence-rate. quadraticConvergence :: ConvergenceOrder -- | Cubic convergence-rate. cubicConvergence :: ConvergenceOrder -- | Quartic convergence-rate. quarticConvergence :: ConvergenceOrder -- | The predicted number of iterations, required to achieve a specific -- accuracy, at a given order of convergence. getIterationsRequired :: Integral i => ConvergenceOrder -> DecimalDigits -> DecimalDigits -> i -- | getTermsRequired :: Integral i => ConvergenceRate -> DecimalDigits -> i -- | Promotes the specified number, by a number of DecimalDigits. promote :: Num n => n -> DecimalDigits -> n -- | simplify :: RealFrac operand => DecimalDigits -> operand -> Rational -- | -- -- module Factory.Math.SquareRoot -- | Defines the methods expected of a square-root algorithm. class Algorithmic algorithm where squareRoot algorithm decimalDigits operand = squareRootFrom algorithm (getEstimate operand) decimalDigits operand squareRootFrom :: (Algorithmic algorithm, Real operand, Show operand) => algorithm -> Estimate -> DecimalDigits -> operand -> Result squareRoot :: (Algorithmic algorithm, Real operand, Show operand) => algorithm -> DecimalDigits -> operand -> Result -- | The interface required to iterate, from an estimate of the required -- value, to the next approximation. class Iterator algorithm step :: (Iterator algorithm, Real operand) => algorithm -> operand -> Result -> Result convergenceOrder :: Iterator algorithm => algorithm -> ConvergenceOrder -- | The result-type; actually, only the concrete return-type of -- simplify, stops it being a polymorphic instance of -- Fractional. type Result = Rational -- | Contains an estimate for the square-root of a value, and its -- accuracy. type Estimate = (Result, DecimalDigits) -- | getAccuracy :: Real operand => operand -> Result -> DecimalDigits -- | getDiscrepancy :: Real operand => operand -> Result -> Result -- | Uses Double-precision floating-point arithmetic, to obtain an -- initial estimate for the square-root, and its accuracy. getEstimate :: (Real operand, Show operand) => operand -> Estimate -- | True if the specified estimate for the square-root, is precise. isPrecise :: Real operand => operand -> Result -> Bool -- | module Factory.Math.Pi -- | class Algorithmic algorithm where openI _ 1 = 3 openI algorithm decimalDigits | decimalDigits <= 0 = error $ "Factory.Math.Pi.openI:\tinsufficient decimalDigits=" ++ show decimalDigits | otherwise = round . promote (openR algorithm decimalDigits) $ pred decimalDigits openS _ 1 = "3" openS algorithm decimalDigits | decimalDigits <= 0 = "" | decimalDigits <= 16 = take (succ decimalDigits) $ show (pi :: Double) | otherwise = "3." ++ tail (show $ openI algorithm decimalDigits) openR :: Algorithmic algorithm => algorithm -> DecimalDigits -> Rational openI :: Algorithmic algorithm => algorithm -> DecimalDigits -> Integer openS :: Algorithmic algorithm => algorithm -> DecimalDigits -> String -- | Categorises the various algorithms. data Category agm bbp borwein ramanujan spigot -- | Algorithms based on the Arithmetic-geometric Mean. AGM :: agm -> Category agm bbp borwein ramanujan spigot -- | -- http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula. BBP :: bbp -> Category agm bbp borwein ramanujan spigot -- | http://en.wikipedia.org/wiki/Borwein%27s_algorithm. Borwein :: borwein -> Category agm bbp borwein ramanujan spigot -- | http://www.pi314.net/eng/ramanujan.php. Ramanujan :: ramanujan -> Category agm bbp borwein ramanujan spigot -- | Algorithms from which the digits of Pi slowly drip, one by one. Spigot :: spigot -> Category agm bbp borwein ramanujan spigot instance (Eq agm, Eq bbp, Eq borwein, Eq ramanujan, Eq spigot) => Eq (Category agm bbp borwein ramanujan spigot) instance (Read agm, Read bbp, Read borwein, Read ramanujan, Read spigot) => Read (Category agm bbp borwein ramanujan spigot) instance (Show agm, Show bbp, Show borwein, Show ramanujan, Show spigot) => Show (Category agm bbp borwein ramanujan spigot) instance (Algorithmic agm, Algorithmic bbp, Algorithmic borwein, Algorithmic ramanujan, Algorithmic spigot) => Algorithmic (Category agm bbp borwein ramanujan spigot) instance (Defaultable agm, Defaultable bbp, Defaultable borwein, Defaultable ramanujan, Defaultable spigot) => Defaultable (Category agm bbp borwein ramanujan spigot) -- | -- -- module Factory.Math.Implementations.Pi.BBP.Implementation -- | Returns Pi, accurate to the specified number of decimal digits. openR :: Series -> DecimalDigits -> Rational -- | module Factory.Math.Implementations.Pi.BBP.Algorithm -- | Defines those BBP-type series which have been implemented. data Algorithm -- | A base-2^16 version of the formula. Base65536 :: Algorithm -- | A nega-base 2^10 version of the formula. Bellard :: Algorithm instance Eq Algorithm instance Read Algorithm instance Show Algorithm instance Algorithmic Algorithm instance Defaultable Algorithm -- | module Factory.Math.Implementations.Pi.Borwein.Series -- | Defines a series corresponding to a specific Borwein-formula. data Series squareRootAlgorithm factorialAlgorithm MkSeries :: (squareRootAlgorithm -> factorialAlgorithm -> DecimalDigits -> (Rational, [Rational])) -> ConvergenceRate -> Series squareRootAlgorithm factorialAlgorithm terms :: Series squareRootAlgorithm factorialAlgorithm -> squareRootAlgorithm -> factorialAlgorithm -> DecimalDigits -> (Rational, [Rational]) -- | The expected number of digits of Pi, per term in the series. convergenceRate :: Series squareRootAlgorithm factorialAlgorithm -> ConvergenceRate -- | module Factory.Math.Implementations.Pi.Borwein.Implementation -- | Returns Pi, accurate to the specified number of decimal digits. openR :: Series squareRootAlgorithm factorialAlgorithm -> squareRootAlgorithm -> factorialAlgorithm -> DecimalDigits -> Rational -- | module Factory.Math.Implementations.Pi.Ramanujan.Series -- | Defines a series corresponding to a specific Ramanujan-formula. data Series squareRootAlgorithm factorialAlgorithm MkSeries :: (factorialAlgorithm -> [Rational]) -> (squareRootAlgorithm -> DecimalDigits -> Rational) -> ConvergenceRate -> Series squareRootAlgorithm factorialAlgorithm -- | The sequence of terms, the sum to infinity of which defines the -- series. terms :: Series squareRootAlgorithm factorialAlgorithm -> factorialAlgorithm -> [Rational] -- | The ratio by which the sum to infinity of the sequence, must be scaled -- to result in Pi. getSeriesScalingFactor :: Series squareRootAlgorithm factorialAlgorithm -> squareRootAlgorithm -> DecimalDigits -> Rational -- | The expected number of digits of Pi, per term in the series. convergenceRate :: Series squareRootAlgorithm factorialAlgorithm -> ConvergenceRate -- | module Factory.Math.Implementations.Pi.Ramanujan.Implementation -- | Returns Pi, accurate to the specified number of decimal digits. openR :: Series squareRootAlgorithm factorialAlgorithm -> squareRootAlgorithm -> factorialAlgorithm -> DecimalDigits -> Rational -- | module Factory.Math.Implementations.Pi.Spigot.Series -- | data Series i MkSeries :: [i] -> [i] -> [i] -> (DecimalDigits -> Int) -> Series i coefficients :: Series i -> [i] baseNumerators :: Series i -> [i] baseDenominators :: Series i -> [i] -- | The width of the spigot-table, required to accurately generate the -- requested number of digits. nTerms :: Series i -> DecimalDigits -> Int -- | Combines baseNumerators and baseDenominators, and as a -- side-effect, expresses the ratio in lowest terms. bases :: Integral i => Series i -> [Ratio i] -- | module Factory.Math.Implementations.Pi.Spigot.Gosper -- | Defines a series which converges to Pi. series :: Integral i => Series i -- | module Factory.Math.Implementations.Pi.Spigot.RabinowitzWagon -- | Defines a series which converges to Pi. series :: Integral i => Series i -- | -- -- module Factory.Math.Implementations.Pi.Spigot.Spigot -- | The constant base in which we want the resulting value of Pi to -- be expressed. decimal :: I -- | openI :: Series I -> DecimalDigits -> Integer -- | module Factory.Math.Implementations.Pi.Spigot.Algorithm -- | Define those Spigot-algorithms which have been implemented. data Algorithm -- | A continued fraction discovered by Gosper. Gosper :: Algorithm -- | A continued fraction discovered by Rabinowitz and -- Wagon. RabinowitzWagon :: Algorithm instance Eq Algorithm instance Read Algorithm instance Show Algorithm instance Algorithmic Algorithm instance Defaultable Algorithm -- | module Factory.Math.ArithmeticGeometricMean -- | The type of the arithmetic mean; -- http://en.wikipedia.org/wiki/Arithmetic_mean. type ArithmeticMean = Rational -- | The type of the geometric mean; -- http://en.wikipedia.org/wiki/Geometric_mean. type GeometricMean = Rational -- | Encapsulates both arithmetic and geometric means. type AGM = (ArithmeticMean, GeometricMean) -- | Returns an infinite list which converges on the -- Arithmetic-geometric mean. convergeToAGM :: Algorithmic squareRootAlgorithm => squareRootAlgorithm -> DecimalDigits -> AGM -> [AGM] -- | Returns the bounds within which the AGM has been constrained. spread :: AGM -> Rational -- | Accessor. getArithmeticMean :: AGM -> ArithmeticMean -- | Accessor. getGeometricMean :: AGM -> GeometricMean -- | Checks that both means are positive, as required for the -- geometric mean to be consistently real. isValid :: AGM -> Bool -- | -- -- -- -- module Factory.Math.Implementations.Pi.AGM.BrentSalamin -- | -- --
--   pi = (a[N-1] + g[N-1])^2 / (1 - sum [2^n * (a[n] - g[n])^2])			where n = [0 .. N-1]
--   => 4*a[N]^2 / (1 - sum [2^n * (a[n]^2 - 2*a[n]*g[n] + g[n]^2)])
--   => 4*a[N]^2 / (1 - sum [2^n * (a[n]^2 + 2*a[n]*g[n] + g[n]^2 - 4*a[n]*g[n])])
--   => 4*a[N]^2 / (1 - sum [2^n * ((a[n] + g[n])^2 - 4*a[n]*g[n])])
--   => 4*a[N]^2 / (1 - sum [2^(n-1) * 4 * (a[n-1]^2 - g[n-1]^2)])			where n = [1 .. N]
--   => 4*a[N]^2 / (1 - sum [2^(n+1) * (a[n-1]^2 - g[n-1]^2)])
--   
openR :: Algorithmic squareRootAlgorithm => squareRootAlgorithm -> DecimalDigits -> Rational -- | module Factory.Math.Implementations.Pi.AGM.Algorithm -- | Defines the available algorithms. data Algorithm squareRootAlgorithm BrentSalamin :: squareRootAlgorithm -> Algorithm squareRootAlgorithm instance Eq squareRootAlgorithm => Eq (Algorithm squareRootAlgorithm) instance Read squareRootAlgorithm => Read (Algorithm squareRootAlgorithm) instance Show squareRootAlgorithm => Show (Algorithm squareRootAlgorithm) instance Algorithmic squareRootAlgorithm => Algorithmic (Algorithm squareRootAlgorithm) instance Defaultable squareRootAlgorithm => Defaultable (Algorithm squareRootAlgorithm) -- | module Factory.Data.PrimeWheel -- | Couples a candidate prime with a rolling wheel, to define the -- distance rolled. type Distance i = (i, [i]) -- | The size of the wheel, measured by the number of primes from -- which it is composed. type NPrimes = Int -- | An infinite increasing sequence, of the multiples of a specific prime. type PrimeMultiples i = [i] -- | -- --
--   zip [0 ..] . scanl (*) 1 $ [2,3,5,7,11,13,17,19,23,29,31]
--   [(0,1),(1,2),(2,6),(3,30),(4,210),(5,2310),(6,30030),(7,510510),(8,9699690),(9,223092870),(10,6469693230),(11,200560490130)]
--   
-- -- -- --
--   zip [0 ..] . scanl (*) 1 . map pred $ [2,3,5,7,11,13,17,19,23,29,31]
--   [(0,1),(1,1),(2,2),(3,8),(4,48),(5,480),(6,5760),(7,92160),(8,1658880),(9,36495360),(10,1021870080),(11,30656102400)]
--   
data PrimeWheel i -- | estimateOptimalSize :: Integral i => i -> NPrimes -- | -- --
--   Prime	Rotating PrimeWheel 3	Output
--   =====	=====================	======
--   7	[4,2,4,2,4,6,2,6]	[49,77,91,119,133,161,203,217,259 ..]
--   11	[2,4,2,4,6,2,6,4]	[121,143,187,209,253,319,341,407 ..]
--   13	[4,2,4,6,2,6,4,2]	[169,221,247,299,377,403,481,533,559 ..]
--   
generateMultiples :: Integral i => i -> [i] -> [i] -- | Generate an infinite, increasing sequence of candidate primes, from -- the specified wheel. roll :: Integral i => PrimeWheel i -> [Distance i] -- | Generates a new candidate prime, from a rolling wheel, and the -- current candidate. rotate :: Integral i => Distance i -> Distance i -- | Smart constructor for a wheel from the specified number of low -- primes. -- -- -- --
--   nPrimes	Gaps
--   ======	====
--   0	[1]
--   1	[2]	--The terminal gap for all subsequent wheels is '2'; [(succ circumference `mod` circumference) - (pred circumference `mod` circumference)].
--   2	[4,2]	--Both points are on the axis, so the symmetry isn't yet clear.
--   3	[6,4,2,4,2,4,6,2]
--   4	[10,2,4,2,4,6,2,6,4,2,4,6,6,2,6,4,2,6,4,6,8,4,2,4,2,4,8,6,4,6,2,4,6,2,6,6,4,2,4,6,2,6,4,2,4,2,10,2]
--   
-- -- Exploitation of this property has proved counter-productive, probably -- because it requires strict evaluation, exposing the user to the -- full cost of inadvertently choosing a wheel, which in practice, -- is rotated less than once. mkPrimeWheel :: Integral i => NPrimes -> PrimeWheel i -- | The circumference of the specified PrimeWheel. getCircumference :: Integral i => PrimeWheel i -> i -- | The number of spokes in the specified PrimeWheel. getSpokeCount :: Integral i => PrimeWheel i -> i instance Show i => Show (PrimeWheel i) -- | -- -- -- -- module Factory.Math.Implementations.Primes.SieveOfAtkin -- | sieveOfAtkin :: (NFData i, Ix i, Integral i) => NPrimes -> i -> [i] instance Eq PolynomialType -- | -- -- -- -- module Factory.Math.Implementations.Primes.SieveOfEratosthenes -- | sieveOfEratosthenes :: Integral i => NPrimes -> [i] -- | -- -- module Factory.Math.DivideAndConquer -- | type BisectionRatio = Ratio Int -- | The list-length beneath which to terminate bisection. type MinLength = Int -- | divideAndConquer :: Monoid monoid => BisectionRatio -> MinLength -> [monoid] -> monoid -- | product' :: Num n => BisectionRatio -> MinLength -> [n] -> n -- | sum' :: Num n => BisectionRatio -> MinLength -> [n] -> n -- | -- -- module Factory.Data.Ring -- | class Ring r where l =-= r = l =+= additiveInverse r square r = r =*= r (=+=) :: Ring r => r -> r -> r (=*=) :: Ring r => r -> r -> r additiveInverse :: Ring r => r -> r multiplicativeIdentity :: Ring r => r additiveIdentity :: Ring r => r (=-=) :: Ring r => r -> r -> r square :: Ring r => r -> r -- | Returns the product of the list of ring-members. product' :: Ring r => BisectionRatio -> MinLength -> [r] -> r -- | Returns the sum of the list of ring-members. sum' :: Ring r => BisectionRatio -> MinLength -> [r] -> r -- | (=^) :: (Eq r, Integral power, Ring r, Show power) => r -> power -> r instance Read p => Read (Product p) instance Show p => Show (Product p) instance Read s => Read (Sum s) instance Show s => Show (Sum s) instance Ring r => Monoid (Sum r) instance Ring r => Monoid (Product r) -- | -- -- module Factory.Data.QuotientRing -- | Defines a sub-class of Ring, in which division is implemented. class Ring q => QuotientRing q quotRem' :: QuotientRing q => q -> q -> (q, q) -- | Returns the quotient, after division of the two specified -- QuotientRings. quot' :: QuotientRing q => q -> q -> q -- | Returns the remainder, after division of the two specified -- QuotientRings. rem' :: QuotientRing q => q -> q -> q -- | areCongruentModulo :: (Eq q, QuotientRing q) => q -> q -> q -> Bool -- | True if the second operand divides the first. isDivisibleBy :: (Eq q, QuotientRing q) => q -> q -> Bool -- | -- -- module Factory.Data.Monomial -- | type Monomial coefficient exponent = (coefficient, exponent) -- | Double the specified Monomial. double :: Num c => Monomial c e -> Monomial c e -- | Reduce the coefficient using modular arithmetic. mod' :: Integral c => Monomial c e -> c -> Monomial c e -- | Negate the coefficient. negateCoefficient :: Num c => Monomial c e -> Monomial c e -- | Convert the type of the coefficient. realCoefficientToFrac :: (Real r, Fractional f) => Monomial r e -> Monomial f e -- | Shift the coefficient, by the specified amount. shiftCoefficient :: Num c => Monomial c e -> c -> Monomial c e -- | Shift the exponent, by the specified amount. shiftExponent :: Num e => Monomial c e -> e -> Monomial c e -- | Square the specified Monomial. square :: (Num c, Num e) => Monomial c e -> Monomial c e -- | Accessor. getExponent :: Monomial c e -> e -- | Accessor. getCoefficient :: Monomial c e -> c -- | Compares the exponents of the specified Monomials. (<=>) :: Ord e => Monomial c e -> Monomial c e -> Ordering -- | Divide the two specified Monomials. () :: (Eq c, Fractional c, Num e) => Monomial c e -> Monomial c e -> Monomial c e -- | Multiply the two specified Monomials. (<*>) :: (Num c, Num e) => Monomial c e -> Monomial c e -> Monomial c e -- | True if the exponents are equal. (=~) :: Eq e => Monomial c e -> Monomial c e -> Bool -- | isMonomial :: Integral e => Monomial c e -> Bool -- | -- -- module Factory.Data.Polynomial -- | data Polynomial coefficient exponent -- | Constructs a polynomial with zero terms. zero :: Polynomial c e -- | Constructs a constant monomial, independent of the -- indeterminate. one :: (Eq c, Num c, Num e) => Polynomial c e -- | evaluate :: (Num n, Integral e, Show e) => n -> Polynomial n e -> n -- | getDegree :: Num e => Polynomial c e -> e -- | Return the highest-degree monomial. getLeadingTerm :: Polynomial c e -> Monomial c e -- | lift :: (MonomialList c1 e1 -> MonomialList c2 e2) -> Polynomial c1 e1 -> Polynomial c2 e2 -- | Reduces all the coefficients using modular arithmetic. mod' :: Integral c => Polynomial c e -> c -> Polynomial c e -- | Sorts into descending order of exponents, groups like -- exponents, and calls pruneCoefficients. normalise :: (Eq c, Num c, Ord e) => Polynomial c e -> Polynomial c e -- | raiseModulo :: (Integral c, Integral power, Num e, Ord e, Show power) => Polynomial c e -> power -> c -> Polynomial c e -- | Convert the type of the coefficients. realCoefficientsToFrac :: (Real r, Fractional f) => Polynomial r e -> Polynomial f e -- | Returns the number of non-zero terms in the polynomial. terms :: Polynomial c e -> Int -- | Constructs an arbitrary zeroeth-degree polynomial, ie. -- independent of the indeterminate. mkConstant :: (Eq c, Num c, Num e) => c -> Polynomial c e -- | Constructs an arbitrary first-degree polynomial. mkLinear :: (Eq c, Num c, Num e) => c -> c -> Polynomial c e -- | Smart constructor. Constructs an arbitrary polynomial. mkPolynomial :: (Eq c, Num c, Ord e) => MonomialList c e -> Polynomial c e -- | (*=) :: (Eq c, Num c, Num e) => Polynomial c e -> Monomial c e -> Polynomial c e -- | areCongruentModulo :: (Integral c, Num e, Ord e) => Polynomial c e -> Polynomial c e -> c -> Bool -- | True if the exponents of successive terms are in -- ascending order. inAscendingOrder :: Ord e => Polynomial c e -> Bool -- | True if the exponents of successive terms are in -- descending order. inDescendingOrder :: Ord e => Polynomial c e -> Bool -- | isMonic :: (Eq c, Num c) => Polynomial c e -> Bool -- | True if there's exactly one term. isMonomial :: Polynomial c e -> Bool -- | True if no term has a coefficient of zero and the -- exponents of successive terms are in descending order. isNormalised :: (Eq c, Num c, Ord e) => Polynomial c e -> Bool -- | True if all exponents are positive integers as required. isPolynomial :: Integral e => Polynomial c e -> Bool -- | True if there are zero terms. isZero :: Polynomial c e -> Bool instance (Eq coefficient, Eq exponent) => Eq (Polynomial coefficient exponent) instance (Show coefficient, Show exponent) => Show (Polynomial coefficient exponent) instance (Eq c, Fractional c, Num e, Ord e) => QuotientRing (Polynomial c e) instance (Eq c, Num c, Num e, Ord e) => Ring (Polynomial c e) -- | -- -- module Factory.Data.MonicPolynomial -- | A type of Polynomial, in which the leading term is -- required to have a coefficient of one. data MonicPolynomial c e -- | Smart constructor. Constructs an arbitrary monic polynomial. mkMonicPolynomial :: (Eq c, Num c, Ord e, Show c, Show e) => Polynomial c e -> MonicPolynomial c e instance (Eq c, Eq e) => Eq (MonicPolynomial c e) instance (Show c, Show e) => Show (MonicPolynomial c e) instance (Eq c, Num c, Num e, Ord e, Show c, Show e) => QuotientRing (MonicPolynomial c e) instance (Eq c, Num c, Num e, Ord e, Show c, Show e) => Ring (MonicPolynomial c e) -- | -- -- -- -- -- -- module Factory.Data.Interval -- | Defines a closed (inclusive) interval of consecutive values. type Interval endPoint = (endPoint, endPoint) -- | Construct the unsigned closed unit-interval; -- http://en.wikipedia.org/wiki/Unit_interval. closedUnitInterval :: Num n => Interval n -- | Construct an interval from a bounded type. mkBounded :: Bounded endPoint => Interval endPoint -- | True if the specified value is within the inclusive bounds of the -- interval. elem' :: Ord endPoint => endPoint -> Interval endPoint -> Bool -- | Swap the end-points where they were originally reversed, but -- otherwise do nothing. normalise :: Ord endPoint => Interval endPoint -> Interval endPoint -- | product' :: (Integral i, Show i) => Ratio i -> i -> Interval i -> i -- | Shift of both end-points of the interval by the -- specified amount. shift :: Num endPoint => endPoint -> Interval endPoint -> Interval endPoint -- | Bisect the interval at the specified end-point; which -- should be between the two existing end-points. splitAt' :: (Enum endPoint, Num endPoint, Ord endPoint, Show endPoint) => endPoint -> Interval endPoint -> (Interval endPoint, Interval endPoint) -- | toList :: Enum endPoint => Interval endPoint -> [endPoint] -- | Accessor. getMinBound :: Interval endPoint -> endPoint -- | Accessor. getMaxBound :: Interval endPoint -> endPoint -- | Construct an interval from a single value. precisely :: endPoint -> Interval endPoint -- | True if getMinBound exceeds getMaxBound extent. isReversed :: Ord endPoint => Interval endPoint -> Bool -- | module Factory.Math.Probability -- | Describes a continuous probability-distribution; -- http://en.wikipedia.org/wiki/List_of_probability_distributions#Continuous_distributions. data ContinuousDistribution f -- | Defines a Uniform-distribution within a closed interval; -- http://en.wikipedia.org/wiki/Uniform_distribution. UniformDistribution :: (Interval f) -> ContinuousDistribution f -- | Defines a Normal-distribution with a particular mean and -- variance; -- http://en.wikipedia.org/wiki/Normal_distribution. NormalDistribution :: f -> f -> ContinuousDistribution f -- | Describes a discrete probability-distribution; -- http://en.wikipedia.org/wiki/List_of_probability_distributions#Discrete_distributions. data DiscreteDistribution f PoissonDistribution :: f -> DiscreteDistribution f -- | boxMullerTransform :: (Floating f, Ord f, Show f) => (f, f) -> (f, f) -- | generateStandardizedNormalDistribution :: (RealFloat f, Show f, Random f, RandomGen randomGen) => randomGen -> [f] -- | generateContinuousPopulation :: (RealFloat f, Show f, Random f, RandomGen randomGen) => Int -> ContinuousDistribution f -> randomGen -> [f] -- | generatePoissonDistribution :: (Integral events, RealFloat lambda, Show lambda, Random lambda, RandomGen randomGen) => lambda -> randomGen -> [events] -- | Generates a random sample-population, with the specified discrete -- probability-distribution. generateDiscretePopulation :: (Ord f, RealFloat f, Show f, Random f, RandomGen randomGen, Integral events) => Int -> DiscreteDistribution f -> randomGen -> [events] instance Eq f => Eq (ContinuousDistribution f) instance Read f => Read (ContinuousDistribution f) instance Show f => Show (ContinuousDistribution f) instance Eq f => Eq (DiscreteDistribution f) instance Read f => Read (DiscreteDistribution f) instance Show f => Show (DiscreteDistribution f) instance (Num f, Ord f, Show f) => SelfValidator (DiscreteDistribution f) instance (Num a, Ord a, Show a) => SelfValidator (ContinuousDistribution a) -- | -- -- module Factory.Data.Exponential -- | Describes an exponential, in terms of its base and -- exponent. type Exponential base exponent = (base, exponent) -- | Evaluate the specified Exponential, returning the resulting -- number. evaluate :: (Num base, Integral exponent) => Exponential base exponent -> base -- | Invert the value, by negating the exponent. invert :: Num exponent => Exponential base exponent -> Exponential base exponent -- | Accessor. getBase :: Exponential base exponent -> base -- | Accessor. getExponent :: Exponential base exponent -> exponent -- | rightIdentity :: Num exponent => base -> Exponential base exponent -- | Raise the specified Exponential to a power. (<^) :: Num exponent => Exponential base exponent -> exponent -> Exponential base exponent -- | True if the bases are equal. (=~) :: Eq base => Exponential base exponent -> Exponential base exponent -> Bool -- | -- -- module Factory.Data.PrimeFactors -- | type Factors base exponent = [Exponential base exponent] -- | insert' :: (Ord base, Num exponent) => Exponential base exponent -> Factors base exponent -> Factors base exponent -- | Multiply a list of prime factors. product' :: (Num base, Integral exponent) => BisectionRatio -> MinLength -> Factors base exponent -> base -- | reduce :: (Ord base, Num exponent, Ord exponent) => Factors base exponent -> Factors base exponent -- | (>*<) :: (Ord base, Num exponent, Ord exponent) => Factors base exponent -> Factors base exponent -> Factors base exponent -- | (>/<) :: (Integral base, Integral exponent) => Factors base exponent -> Factors base exponent -> (Factors base exponent, Factors base exponent) -- | (>^) :: Num exponent => Factors base exponent -> exponent -> Factors base exponent -- | -- -- module Factory.Math.Implementations.Factorial -- | The algorithms by which factorial has been implemented. data Algorithm -- | The integers from which the factorial is composed, are -- multiplied using Data.Interval.product'. Bisection :: Algorithm -- | The prime factors of the factorial are extracted, then -- raised to the appropriate power, before multiplication. PrimeFactorisation :: Algorithm -- | primeFactors :: Integral base => base -> Factors base base -- | Returns the rising factorial; -- http://mathworld.wolfram.com/RisingFactorial.html risingFactorial :: (Integral i, Show i) => i -> i -> i -- | Returns the falling factorial; -- http://mathworld.wolfram.com/FallingFactorial.html fallingFactorial :: (Integral i, Show i) => i -> i -> i -- | (!/!) :: (Integral i, Fractional f, Show i) => i -> i -> f instance Eq Algorithm instance Read Algorithm instance Show Algorithm instance Algorithmic Algorithm instance Defaultable Algorithm -- | module Factory.Math.Implementations.Pi.Borwein.Borwein1993 -- | Defines the parameters of the Borwein series. series :: (Algorithmic squareRootAlgorithm, Algorithmic factorialAlgorithm) => Series squareRootAlgorithm factorialAlgorithm -- | module Factory.Math.Implementations.Pi.Borwein.Algorithm -- | data Algorithm squareRootAlgorithm factorialAlgorithm -- | http://en.wikipedia.org/wiki/Borwein%27s_algorithm. Borwein1993 :: squareRootAlgorithm -> factorialAlgorithm -> Algorithm squareRootAlgorithm factorialAlgorithm instance (Eq squareRootAlgorithm, Eq factorialAlgorithm) => Eq (Algorithm squareRootAlgorithm factorialAlgorithm) instance (Read squareRootAlgorithm, Read factorialAlgorithm) => Read (Algorithm squareRootAlgorithm factorialAlgorithm) instance (Show squareRootAlgorithm, Show factorialAlgorithm) => Show (Algorithm squareRootAlgorithm factorialAlgorithm) instance (Algorithmic squareRootAlgorithm, Algorithmic factorialAlgorithm) => Algorithmic (Algorithm squareRootAlgorithm factorialAlgorithm) instance (Defaultable squareRootAlgorithm, Defaultable factorialAlgorithm) => Defaultable (Algorithm squareRootAlgorithm factorialAlgorithm) -- | module Factory.Math.Implementations.Pi.Ramanujan.Chudnovsky -- | Defines the parameters of the Chudnovsky series. series :: (Algorithmic squareRootAlgorithm, Algorithmic factorialAlgorithm) => Series squareRootAlgorithm factorialAlgorithm -- | module Factory.Math.Implementations.Pi.Ramanujan.Classic -- | Defines the parameters of the Ramanujan series. series :: (Algorithmic squareRootAlgorithm, Algorithmic factorialAlgorithm) => Series squareRootAlgorithm factorialAlgorithm -- | module Factory.Math.Implementations.Pi.Ramanujan.Algorithm -- | Define those Ramanujan-series which have been implemented. data Algorithm squareRootAlgorithm factorialAlgorithm -- | The original version. Classic :: squareRootAlgorithm -> factorialAlgorithm -> Algorithm squareRootAlgorithm factorialAlgorithm -- | A variant found by the Chudnovsky brothers. Chudnovsky :: squareRootAlgorithm -> factorialAlgorithm -> Algorithm squareRootAlgorithm factorialAlgorithm instance (Eq squareRootAlgorithm, Eq factorialAlgorithm) => Eq (Algorithm squareRootAlgorithm factorialAlgorithm) instance (Read squareRootAlgorithm, Read factorialAlgorithm) => Read (Algorithm squareRootAlgorithm factorialAlgorithm) instance (Show squareRootAlgorithm, Show factorialAlgorithm) => Show (Algorithm squareRootAlgorithm factorialAlgorithm) instance (Algorithmic squareRootAlgorithm, Algorithmic factorialAlgorithm) => Algorithmic (Algorithm squareRootAlgorithm factorialAlgorithm) instance (Defaultable squareRootAlgorithm, Defaultable factorialAlgorithm) => Defaultable (Algorithm squareRootAlgorithm factorialAlgorithm) -- | module Factory.Math.Statistics -- | getMean :: (Foldable f, Real r, Fractional result) => f r -> result -- | getVariance :: (Foldable f, Fractional variance, Functor f, Real r) => f r -> variance -- | Determines the standard-deviation of the specified numbers; -- http://en.wikipedia.org/wiki/Standard_deviation. getStandardDeviation :: (Foldable f, Floating result, Functor f, Real r) => f r -> result -- | getAverageAbsoluteDeviation :: (Foldable f, Fractional result, Functor f, Real r) => f r -> result -- | Determines the coefficient-of-variance of the specified -- numbers; http://en.wikipedia.org/wiki/Coefficient_of_variation. getCoefficientOfVariance :: (Foldable f, Eq result, Floating result, Functor f, Real r) => f r -> result -- | The number of unordered combinations of r objects taken -- from n; http://en.wikipedia.org/wiki/Combination. nCr :: (Algorithmic factorialAlgorithm, Integral i, Show i) => factorialAlgorithm -> i -> i -> i -- | The number of permutations of r objects taken from -- n; http://en.wikipedia.org/wiki/Permutations. nPr :: (Integral i, Show i) => i -> i -> i -- | -- -- Caller may benefit from application of simplify before -- operating on the result; which though of the required accuracy, may -- not be the most concise rational number satisfying that criterion. module Factory.Math.Implementations.SquareRoot -- | The number of terms in a series. type Terms = Int -- | The algorithms by which the square-root has been implemented. data Algorithm -- | -- http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Bakhshali_approximation BakhshaliApproximation :: Algorithm -- | -- http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Continued_fraction_expansion. ContinuedFraction :: Algorithm -- | http://en.wikipedia.org/wiki/Halley%27s_method. HalleysMethod :: Algorithm -- | http://en.wikipedia.org/wiki/Newton%27s_method. NewtonRaphsonIteration :: Algorithm -- | -- http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Taylor_series. TaylorSeries :: Terms -> Algorithm instance Eq Algorithm instance Read Algorithm instance Show Algorithm instance Iterator Algorithm instance Algorithmic Algorithm instance Defaultable Algorithm -- | -- -- module Factory.Math.PrimeFactorisation -- | Defines the methods expected of a factorisation-algorithm. class Algorithmic algorithm primeFactors :: (Algorithmic algorithm, NFData base, Integral base) => algorithm -> base -> Factors base Int -- | maxBoundPrimeFactor :: Integral i => i -> i -- | smoothness :: (Algorithmic algorithm, NFData base, Integral base) => algorithm -> [base] -- | powerSmoothness :: (Algorithmic algorithm, NFData base, Integral base) => algorithm -> [base] -- | regularNumbers :: (Algorithmic algorithm, NFData base, Integral base) => algorithm -> [base] -- | primePowerTotient :: (Integral base, Integral exponent) => Exponential base exponent -> base -- | eulersTotient :: (Algorithmic algorithm, NFData i, Integral i, Show i) => algorithm -> i -> i -- | omega :: (Algorithmic algorithm, NFData i, Integral i) => algorithm -> [i] -- | squareFree :: (Algorithmic algorithm, NFData i, Integral i) => algorithm -> [i] -- | module Factory.Math.MultiplicativeOrder -- | multiplicativeOrder :: (Algorithmic primeFactorisationAlgorithm, NFData i, Integral i, Show i) => primeFactorisationAlgorithm -> i -> i -> i -- | -- -- module Factory.Math.Implementations.Primality -- | The algorithms by which primality-testing has been implemented. data Algorithm factorisationAlgorithm -- | http://en.wikipedia.org/wiki/AKS_primality_test. AKS :: factorisationAlgorithm -> Algorithm factorisationAlgorithm -- | -- http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test. MillerRabin :: Algorithm factorisationAlgorithm instance Eq factorisationAlgorithm => Eq (Algorithm factorisationAlgorithm) instance Read factorisationAlgorithm => Read (Algorithm factorisationAlgorithm) instance Show factorisationAlgorithm => Show (Algorithm factorisationAlgorithm) instance Algorithmic factorisationAlgorithm => Algorithmic (Algorithm factorisationAlgorithm) instance Defaultable (Algorithm factorisationAlgorithm) -- | module Factory.Math.Implementations.Primes.TrialDivision -- | trialDivision :: Integral prime => NPrimes -> [prime] -- | -- -- module Factory.Math.Implementations.Primes.Algorithm -- | The implemented methods by which the primes may be generated. data Algorithm -- | The Sieve of Atkin, optimised using a PrimeWheel of -- optimal size, for primes up to the specified maximum bound; -- http://en.wikipedia.org/wiki/Sieve_of_Atkin. SieveOfAtkin :: Integer -> Algorithm -- | The Sieve of Eratosthenes -- (http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes), optimised -- using a PrimeWheel. SieveOfEratosthenes :: NPrimes -> Algorithm -- | For each candidate, confirm indivisibility, by all primes -- smaller than its square-root, optimised using a -- PrimeWheel. TrialDivision :: NPrimes -> Algorithm -- | For each prime, the infinite list of candidates greater than -- its square, is filtered for indivisibility; -- http://www.haskell.org/haskellwiki/Prime_numbers#Turner.27s_sieve_-_Trial_division. TurnersSieve :: Algorithm -- | wheelSieve. WheelSieve :: Int -> Algorithm instance Eq Algorithm instance Read Algorithm instance Show Algorithm instance Algorithmic Algorithm instance Defaultable Algorithm -- | -- -- module Factory.Math.Implementations.PrimeFactorisation -- | The algorithms by which prime-factorisation has been implemented. data Algorithm -- | http://en.wikipedia.org/wiki/Fermat%27s_factorization_method. FermatsMethod :: Algorithm -- | http://en.wikipedia.org/wiki/Trial_division. TrialDivision :: Algorithm instance Eq Algorithm instance Read Algorithm instance Show Algorithm instance Algorithmic Algorithm instance Defaultable Algorithm