module Math.Combinat.Compositions where
import Math.Combinat.Numbers (factorial,binomial)
type Composition = [Int]
compositions'
:: [Int]
-> Int
-> [[Int]]
compositions' [] 0 = [[]]
compositions' [] _ = []
compositions' shape@(s:ss) n =
[ x:xs | x <- [0..min s n] , xs <- compositions' ss (nx) ]
countCompositions' :: [Int] -> Int -> Integer
countCompositions' [] 0 = 1
countCompositions' [] _ = 0
countCompositions' shape@(s:ss) n = sum
[ countCompositions' ss (nx) | x <- [0..min s n] ]
allCompositions1 :: Int -> [[Composition]]
allCompositions1 n = map (\d -> compositions1 d n) [1..n]
allCompositions' :: [Int] -> [[Composition]]
allCompositions' shape = map (compositions' shape) [0..d] where d = sum shape
compositions
:: Integral a
=> a
-> a
-> [[Int]]
compositions len' d' = compositions' (replicate len d) d where
len = fromIntegral len'
d = fromIntegral d'
countCompositions :: Integral a => a -> a -> Integer
countCompositions len d = binomial (len+d1) (len1)
compositions1
:: Integral a
=> a
-> a
-> [[Int]]
compositions1 len' d'
| len > d = []
| otherwise = map plus1 $ compositions len (dlen)
where
plus1 = map (+1)
len = fromIntegral len'
d = fromIntegral d'
countCompositions1 :: Integral a => a -> a -> Integer
countCompositions1 len d = countCompositions len (dlen)