combinat-0.2.3.1: Generation of 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].

Instances

 Eq Permutation Ord Permutation Read Permutation Show Permutation

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

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

isPermutation :: [Int] -> BoolSource

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').

signOfPermutation :: Num a => Permutation -> aSource

Plus 1 or minus 1.

# 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.

Multiplies two permutations together. See permute for our conventions.

The inverse 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] -> IntegerSource

# = \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.