combinat-0.2.7.2: Generate and manipulate various combinatorial objects.

Math.Combinat.Permutations

Description

Permutations. See: Donald E. Knuth: The Art of Computer Programming, vol 4, pre-fascicle 2B.

Synopsis

Types

Standard notation for permutations. Internally it is an array of the integers [1..n].

Disjoint cycle notation for permutations. Internally it is [[Int]].

Assumes that the input is a permutation of the numbers [1..n].

isPermutation :: [Int] -> Bool Source

Checks whether the input is a permutation of the numbers [1..n].

Checks the input.

Returns n, where the input is a permutation of the numbers [1..n]

Disjoint cycles

This is compatible with Maple's convert(perm,'disjcyc').

Permutation groups

Action of a permutation on a set. If our permutation is encoded with the sequence [p1,p2,...,pn], then in the two-line notation we have

( 1  2  3  ... n  )
( p1 p2 p3 ... pn )

We adopt the convention that permutations act on the left (as opposed to Knuth, where they act on the right). Thus,

permute pi1 (permute pi2 set) == permute (pi1 multiply pi2) set

The second argument should be an array with bounds (1,n). The function checks the array bounds.

permuteList :: Permutation -> [a] -> [a] Source

The list should be of length n.

multiply :: Permutation -> Permutation -> Permutation infixr 7 Source

Multiplies two permutations together. See permute for our conventions.

The inverse permutation.

The trivial permutation.

Simple permutations

A synonym for permutationsNaive

Permutations of [1..n] in lexicographic order, naive algorithm.

# = n!

Random permutations

randomPermutation :: RandomGen g => Int -> g -> (Permutation, g) Source

A synonym for randomPermutationDurstenfeld.

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

randomCyclicPermutation :: RandomGen g => Int -> g -> (Permutation, g) Source

A synonym for randomCyclicPermutationSattolo.

randomPermutationDurstenfeld :: RandomGen g => Int -> g -> (Permutation, g) Source

Generates a uniformly random permutation of [1..n]. Durstenfeld's algorithm (see http://en.wikipedia.org/wiki/Knuth_shuffle).

randomCyclicPermutationSattolo :: RandomGen g => Int -> g -> (Permutation, g) Source

Generates a uniformly random cyclic permutation of [1..n]. Sattolo's algorithm (see http://en.wikipedia.org/wiki/Knuth_shuffle).

Multisets

permuteMultiset :: (Eq a, Ord a) => [a] -> [[a]] Source

Generates all permutations of a multiset. The order is lexicographic. A synonym for fasc2B_algorithm_L

countPermuteMultiset :: (Eq a, Ord a) => [a] -> Integer Source

# = \frac { (sum_i n_i) ! } { \prod_i (n_i !) }

fasc2B_algorithm_L :: (Eq a, Ord a) => [a] -> [[a]] Source

Generates all permutations of a multiset (based on "algorithm L" in Knuth; somewhat less efficient). The order is lexicographic.