perm.h – permutations¶
Memory management¶
Assignment¶
Comparison¶
Composition¶
-
void _perm_compose(slong *res, const slong *vec1, const slong *vec2, slong n)¶
Forms the composition \(\pi_1 \circ \pi_2\) of two permutations \(\pi_1\) and \(\pi_2\). Here, \(\pi_2\) is applied first, that is, \((\pi_1 \circ \pi_2)(i) = \pi_1(\pi_2(i))\).
Allows aliasing of
res,vec1andvec2.
-
void _perm_compose_inv1(slong *res, const slong *vec1, const slong *vec2, slong n)¶
Forms the composition \((\pi_1^{-1}) \circ \pi_2\) of two permutations \(\pi_1\) and \(\pi_2\). Here, \(\pi_2\) is applied first, that is, \(((\pi_1^{-1}) \circ \pi_2)(i) = \pi_1^{-1}(\pi_2(i))\).
Allows aliasing of
res,vec1andvec2.
-
void _perm_compose_inv2(slong *res, const slong *vec1, const slong *vec2, slong n)¶
Forms the composition \(\pi_1 \circ (\pi_2^{-1})\) of two permutations \(\pi_1\) and \(\pi_2\). Here, \(\pi_2^{-1}\) is applied first, that is, \((\pi_1 \circ (\pi_2^{-1}))(i) = \pi_1(\pi_2^{-1}(i))\).
Allows aliasing of
res,vec1andvec2.
Parity¶
Randomisation¶
-
int _perm_randtest(slong *vec, slong n, flint_rand_t state)¶
Generates a random permutation vector of length \(n\) and returns its parity, 0 or 1.
This function uses the Knuth shuffle algorithm to generate a uniformly random permutation without retries.
Iteration¶
-
int _perm_next_lex(slong *res, slong n)¶
Sets
resto the next permutation after the inputres, with respect to the lexicographic ordering, if possible. Returns 1 on success, i.e. if the inputreswas not the lexicographically last permutation, and returns 0 otherwise (in that caseresis not modified).
-
int _perm_next_heap(slong *res, slong n, slong *stack)¶
Sets
resto the next permutation after the inputres, according to an iterative version of B.R. Heap’s algorithm, if possible. The implementation uses a vectorstackof sizento keep track of iteration counters. The standard way to use this function is to call it first withresset to the identity permutation andstackset to a vector of zeros; each call will try to updateresandstackin place. Returns 1 on success, i.e. ifreswas updated, and 0 otherwise.