-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Efficient computation of common combinatoric functions. -- -- Efficient computation of common combinatoric functions. @package combinatorics @version 0.1.0 -- | The factorial numbers (http://oeis.org/A000142). For negative -- inputs, all functions return 0 (rather than throwing an exception or -- using Maybe). -- -- Notable limits: -- --
-- factorial n -- | n < 0 = 0 -- | otherwise = product [1..n] ---- -- However, we use a fast algorithm based on the split-recursive form: -- --
-- factorial n = -- 2^(n - popCount n) * product [(q k)^k | forall k, k >= 1] -- where -- q k = product [j | forall j, n*2^(-k) < j <= n*2^(-k+1), odd j] --factorial :: (Integral a, Bits a) => Int -> a -- | The prime numbers (http://oeis.org/A000040). module Math.Combinatorics.Primes -- | The prime numbers. Implemented with the algorithm in: -- --
-- n `choose` k -- | k < 0 = 0 -- | k > n = 0 -- | otherwise = factorial n `div` (factorial k * factorial (n-k)) ---- -- However, we use a fast implementation based on the prime-power -- factorization of the result (Goetgheluck, 1987). Each time n -- is larger than the previous calls, there will be some slowdown as the -- prime numbers must be computed (though it is still much faster than -- the naive implementation); however, subsequent calls will be extremely -- fast, since we memoize the list of primes. Do note, however, -- that this will result in a space leak if you call choose for -- an extremely large n and then don't need that many primes in -- the future. Hopefully future versions will correct this issue. -- --