Math::Permutation - pure Perl implementation of functions related to the permutations
my $foo = Math::Permutation->cycles([[1,2,6,7], [3,4,5]]);
my $bar = Math::Permutation->unrank(5, 19);
# (2 5 4 3)
# Note that there is no canonical cycle representation in this module,
# so each time the output may be slightly different.
my $goo = Math::Permutation->clone($foo);
# (1 2 6 7) (4 5 3)
# (4 3 5) (1 7 6 2)
say $bar->rank; # 19
say $bar->rank; # 18
say $goo->rank; # 1264
say $goo->rank; # 1265
say $goo->is_even; # 0
say $goo->sgn; # -1
use Data::Dump qw/dump/;
# [1, 0, 0, 0, 0],
# [0, 0, 0, 0, 1],
# [0, 0, 0, 1, 0],
# [0, 1, 0, 0, 0],
# [0, 0, 1, 0, 0],
Initialize $p with the identity permutation of $n elements.
Initialize $p with word representation of a permutation, a.k.a. one-line form.
Initialize $p with the rules of a permutation, with input of permutation on the first list, the output of permutation. If the first list is [1..$n], it is often called two-line form, and the second list would be the word representation.
Initialize $p by the cycle notation. If the length is not specific, the length would be the largest element in the cycles.
Initialize $p referring to the lexicological rank of all $n-permutations. $i must be between 1 and $n!.
Initialize $p by a randomly selected $n-permutation.
Return a string displaying the word representation of $p.
Return a two-line string displaying the tabular form of $p.
Return a string with cycles of $p. One-cycles are omitted.
Return a string with cycles of $p. One-cycles are included.
Check if the permutation $q is equivalent to $p. Return 1 if yes, 0 otherwise.
Clone the permutation $q into $p.
Swap the values of $i-th position and $j-th position.
Composition of $p and $q, sometimes called multiplication of the permutations. The resultant is $q $p (first do $p, then do $q).
$p and $q must be permutations of same number of elements.
Inverse of $p.
The next permutation under the lexicological order of all $n-permutations.
Caveat: may return .
The previous permutation under the lexicological order of all $n-permutations.
Return what $i is mapped to under $p.
Return the word representation of $p as a list.
Return the cycle representation of $p as a list of list(s).
Return the length of $p.
Return the lexicological rank of $p. See $p->unrank($n, $i).
Return the permutation index of $p.
Return the order of $p, i.e. how many times the permutation acts on itself and return the identity permutation.
Return whether $p is an even permutation. Return 1 or 0.
Return whether $p is an odd permutation. Return 1 or 0.
Return the signature of $p. Return +1 if $p is even, -1 if $p is odd.
Another view is the determinant of the permutation matrix of $p.
Return the inversion sequence of $p as a list.
Return the permutation matrix of $p.
Return the list of fixed points of $p.
ref: Chapter 1, Patterns in Permutations and Words
including barred patterns
ref: Section 1.2, Patterns in Permutations and Words
Example: [ -3, -1, 5, -2, 4 ]
Cheok-Yin Fung, <fungcheokyin at gmail.com>
<fungcheokyin at gmail.com>
Please report any bugs or feature requests to https://github.com/E7-87-83/Math-Permutation/issues.
You can find documentation for this module with the perldoc command.
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
The module has gained ideas from various sources:
Julia Package Permutations.jl
CPAN Module Math::GSL::Permutation
Combinatorics features of Maxima
Algebra, Michael Artin
Patterns in Permutations and Words, Sergey Kitaev
This software is Copyright (c) 2022 by Cheok-Yin Fung.
This is free software, licensed under:
To install Math::Permutation, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.