combinat-0.2.8.1: Generate and manipulate various combinatorial objects.

Safe HaskellNone
LanguageHaskell2010

Math.Combinat.Sets

Contents

Description

Subsets.

Synopsis

choices

choose :: Int -> [a] -> [[a]] Source

All possible ways to choose k elements from a list, without repetitions. "Antisymmetric power" for lists. Synonym for kSublists.

choose_ :: Int -> Int -> [[Int]] Source

choose_ k n returns all possible ways of choosing k disjoint elements from [1..n]

choose_ k n == choose k [1..n]

combine :: Int -> [a] -> [[a]] Source

All possible ways to choose k elements from a list, with repetitions. "Symmetric power" for lists. See also Math.Combinat.Compositions. TODO: better name?

compose :: Int -> [a] -> [[a]] Source

A synonym for combine.

tensor products

tuplesFromList :: Int -> [a] -> [[a]] Source

"Tensor power" for lists. Special case of listTensor:

tuplesFromList k xs == listTensor (replicate k xs)

See also Math.Combinat.Tuples. TODO: better name?

listTensor :: [[a]] -> [[a]] Source

"Tensor product" for lists.

sublists

kSublists :: Int -> [a] -> [[a]] Source

Sublists of a list having given number of elements.

sublists :: [a] -> [[a]] Source

All sublists of a list.

countKSublists :: Int -> Int -> Integer Source

# = binom { n } { k }.

random choice

randomChoice :: RandomGen g => Int -> Int -> g -> ([Int], g) Source

randomChoice k n returns a uniformly random choice of k elements from the set [1..n]

Example:

do
  cs <- replicateM 10000 (getStdRandom (randomChoice 3 7))
  mapM_ print $ histogram cs