Skip to content

Commit

Permalink
Move choose.
Browse files Browse the repository at this point in the history
  • Loading branch information
bos committed Sep 11, 2009
1 parent 7d155d0 commit 5e0dca0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Statistics/Distribution/Binomial.hs
Expand Up @@ -27,7 +27,7 @@ import Control.Exception (assert)
import Data.Array.Vector
import Data.Typeable (Typeable)
import qualified Statistics.Distribution as D
import Statistics.Function (choose)
import Statistics.Math (choose)

-- | The binomial distribution.
data BinomialDistribution = BD {
Expand Down
17 changes: 1 addition & 16 deletions Statistics/Function.hs
Expand Up @@ -12,8 +12,7 @@

module Statistics.Function
(
choose
, minMax
minMax
, sort
, partialSort
) where
Expand Down Expand Up @@ -45,17 +44,3 @@ minMax = fini . foldlU go (MM (1/0) (-1/0))
go (MM lo hi) k = MM (min lo k) (max hi k)
fini (MM lo hi) = lo :*: hi
{-# INLINE minMax #-}

-- | The binomial coefficient.
--
-- > 7 `choose` 3 == 35
choose :: Int -> Int -> Int
n `choose` k
| k > n = 0
| otherwise = ceiling . foldlU go 1 . enumFromToU 1 $ k'
where go a i = a * (nk + j) / j
where j = fromIntegral i :: Double
k' | k > n `div` 2 = n - k
| otherwise = k
nk = fromIntegral (n - k')
{-# INLINE choose #-}

0 comments on commit 5e0dca0

Please sign in to comment.