module Math.Combinat.Compositions where
import Math.Combinat.Numbers (factorial,binomial)
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] ]
allCompositions' :: [Int] -> [[[Int]]]
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)