The Perm16 class
Class representing permutations.
SIMD accelerated class Perm16 representing permutations on
up to 16 points.
This class belongs to the hpcombi subpackage of libsemigroups_pybind11.
The functionality described on this page is only available if
LIBSEMIGROUPS_HPCOMBI_ENABLED is True.
Contents
Class representing permutations. |
|
|
Copy a |
Returns the set partition of the cycles of a permutation. |
|
Returns the elementary transposition swapping i and i + 1. |
|
Returns the inverse permutation. |
|
Returns the inverse permutation. |
|
Returns the inverse permutation. |
|
Returns the inverse permutation. |
|
Returns the inverse permutation. |
|
Returns the inverse permutation. |
|
Returns the inverse permutation. |
|
Compare two permutations using the left weak order. |
|
Compare two permutations using the left weak order. |
|
Compare two permutations using the left weak order. |
|
Returns the Lehmer code of a permutation. |
|
Returns the Lehmer code of a permutation. |
|
Returns the Lehmer code of a permutation. |
|
Returns the Coxeter length of a permutation. |
|
Returns the Coxeter length of a permutation. |
|
Returns the Coxeter length of a permutation. |
|
Returns the number of cycles of a permutation. |
|
Returns the number of cycles of a permutation. |
|
Returns the number of cycles of a permutation. |
|
Returns the number of descent of a permutation. |
|
Returns the number of descent of a permutation. |
|
|
Returns the identity permutation. |
Returns the r-th permutation of size |
|
Check whether or not a |
Full API
- class hpcombi.Perm16
- __init__(*args, **kwargs)
Overloaded function.
- __init__(self: Perm16) None
Default constructor.
Constructs a
Perm16object with its entries uninitialized. This means there is no guarantee about the values in the constructed object.>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16()
- __init__(self: Perm16, img: list[int]) None
Construct a
Perm16from a list of images.This function constructs a
Perm16from the list img of its entries. If the length of img is less than16, then the constructedPerm16is padded with fixed points at the end.- Parameters:
- Raises:
LibsemigroupsError – if any value in img is in the range \([16, 256)\).
LibsemigroupsError – if the length of img exceeds
16.LibsemigroupsError – if there are repeated values in img.
TypeError – if any value in img is larger than
255.
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([1, 3, 2, 0]) Perm16([ 1, 3, 2, 0, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- __init__(self: Perm16, n: int) None
Construct a permutation from its 64 bits compressed.
This function constructs a
Perm16from its integer representation n.- Parameters:
n (int) – the integer representation.
- Raises:
TypeError – if n is not in the range \([0, 2 ^{64})\).
Warning
For most values of n the returned object is not a valid permutation.
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16(17863200008537477760) Perm16([ 0, 2, 1, 4, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15]) >>> int(Perm16([0, 2, 1, 4, 3])) 17863200008537477760
- copy(self: Perm16) Perm16
Copy a
Perm16.- Returns:
A copy of the argument.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([1, 2, 3, 4, 0]) >>> x.copy() is not x True >>> x.copy() == x True
- cycles_partition(self: Perm16) Vect16
Returns the set partition of the cycles of a permutation.
This function returns the set partition of the cycles of a permutation, represented the vector \(v\) where \(v[i]\) contains the smallest element in the cycle of \(v\) in self.
- Returns:
The set partition of the cycles of the permutation.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([1,2,3,6,0,5,4,7,8,9,10,11,12,15,14,13]) >>> x.cycles_partition() Vect16([ 0, 0, 0, 0, 0, 5, 0, 7, 8, 9,10,11,12,13,14,13])
- static elementary_transposition(i: int) Perm16
Returns the elementary transposition swapping i and i + 1.
This function returns the elementary transposition swapping i and i + 1. for every value i in \([0, 15)\).
- Parameters:
i (int) – the minimum value to be transposed.
- Returns:
The transposition \((i\ i + 1)\).
- Return type:
- Raises:
LibsemigroupsError – if any value in i is greater than or equal to
15.
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16.elementary_transposition(2) Perm16([ 0, 1, 3, 2, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- inverse(self: Perm16) Perm16
Returns the inverse permutation.
This function returns the inverse of self.
- Returns:
The inverse of self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([0,3,2,4,1]) >>> x.inverse() Perm16([ 0, 4, 2, 1, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15]) >>> x ** -1 Perm16([ 0, 4, 2, 1, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- inverse_arr(self: Perm16) Perm16
Returns the inverse permutation.
This function returns the inverse of self. This function is the same as
inversebut with a different algorithm (using reference cast to arrays).- Returns:
The inverse of self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([0,3,2,4,1]) >>> x.inverse_arr() Perm16([ 0, 4, 2, 1, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- inverse_cycl(self: Perm16) Perm16
Returns the inverse permutation.
This function returns the inverse of self. This function is the same as
inversebut with a different algorithm (compute power from \(n/2\) to \(n\), when \(\sigma^k(i)=i\) then \(\sigma^{-1}(i)=\sigma^{k-1}(i)\)).- Returns:
The inverse of self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([0,3,2,4,1]) >>> x.inverse_pow() Perm16([ 0, 4, 2, 1, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- inverse_find(self: Perm16) Perm16
Returns the inverse permutation.
This function returns the inverse of self. This function is the same as
inversebut with a different algorithm (some kind of vectorized dichotomic search).- Returns:
The inverse of self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([0,3,2,4,1]) >>> x.inverse_find() Perm16([ 0, 4, 2, 1, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- inverse_pow(self: Perm16) Perm16
Returns the inverse permutation.
This function returns the inverse of self. This function is the same as
inversebut with a different algorithm (raising to the power \(\text{lcm}(1, 2, ..., n) - 1\)).- Returns:
The inverse of self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([0,3,2,4,1]) >>> x.inverse_pow() Perm16([ 0, 4, 2, 1, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- inverse_ref(self: Perm16) Perm16
Returns the inverse permutation.
This function returns the inverse of self. This function is the same as
inversebut with a different algorithm (using a loop and indexed access).- Returns:
The inverse of self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([0,3,2,4,1]) >>> x.inverse_ref() Perm16([ 0, 4, 2, 1, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- inverse_sort(self: Perm16) Perm16
Returns the inverse permutation.
This function returns the inverse of self. This function is the same as
inversebut with a different algorithm: insert the identity in the least significant bits and sort using a sorting network.- Returns:
The inverse of self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([0,3,2,4,1]) >>> x.inverse_sort() Perm16([ 0, 4, 2, 1, 3, 5, 6, 7, 8, 9,10,11,12,13,14,15])
- left_weak_leq(self: Perm16, other: Perm16) bool
Compare two permutations using the left weak order.
This function returns
Trueif self is less than other in the left weak order. This function useslength.- Parameters:
other (Perm16) – the permutation for comparison.
- Returns:
Whether self is less than or equal to other.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x, y = Perm16([2, 0, 3, 1]), Perm16([3, 0, 2, 1]) >>> x.left_weak_leq(y) True
- left_weak_leq_length(self: Perm16, other: Perm16) bool
Compare two permutations using the left weak order.
This function returns
Trueif self is less than other in the left weak order. This function implements an algorithm with vectorized test of inclusion.- Parameters:
other (Perm16) – the permutation for comparison.
- Returns:
Whether self is less than or equal to other.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x, y = Perm16([2, 0, 3, 1]), Perm16([3, 0, 2, 1]) >>> x.left_weak_leq_length(y) True
- left_weak_leq_ref(self: Perm16, other: Perm16) bool
Compare two permutations using the left weak order.
This function returns
Trueif self is less than other in the left weak order. This function implements an algorithm testing inclusion of inversions one by one.- Parameters:
other (Perm16) – the permutation for comparison.
- Returns:
Whether self is less than or equal to other.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x, y = Perm16([2, 0, 3, 1]), Perm16([3, 0, 2, 1]) >>> x.left_weak_leq_ref(y) True
- lehmer(self: Perm16) Vect16
Returns the Lehmer code of a permutation.
This function returns the Lehmer code of a permutation computed using fast vector comparison.
- Returns:
the Lehmer code.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([0,3,2,4,1]).lehmer() Vect16([ 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
- lehmer_arr(self: Perm16) Vect16
Returns the Lehmer code of a permutation.
This function returns the Lehmer code of a permutation computed using array, loop, and indexed access.
- Returns:
the Lehmer code.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([0,3,2,4,1]).lehmer_arr() Vect16([ 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
- lehmer_ref(self: Perm16) Vect16
Returns the Lehmer code of a permutation.
This function returns the Lehmer code of a permutation computed using loop and indexed access.
- Returns:
the Lehmer code.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([0,3,2,4,1]).lehmer_ref() Vect16([ 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
- length(self: Perm16) int
Returns the Coxeter length of a permutation.
This function returns the Coxeter length (i.e. number of inversions) of the permutation self (using vector Lehmer and fast horizontal sum).
- Returns:
The Coxeter length.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([0,3,2,4,1]).length() 4
- length_arr(self: Perm16) int
Returns the Coxeter length of a permutation.
This function returns the Coxeter length (i.e. number of inversions) of the permutation self (using loop and indexed access after a cast to
std::array).- Returns:
The Coxeter length.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([0,3,2,4,1]).length_arr() 4
- length_ref(self: Perm16) int
Returns the Coxeter length of a permutation.
This function returns the Coxeter length (i.e. number of inversions) of the permutation self (using loop and indexed access).
- Returns:
The Coxeter length.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([0,3,2,4,1]).length_ref() 4
- nb_cycles(self: Perm16) int
Returns the number of cycles of a permutation.
This function returns the number of cycles of a permutation.
- Returns:
The number of cycles.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([1,2,3,6,0,5,4]) >>> x.nb_cycles() 11
- nb_cycles_ref(self: Perm16) int
Returns the number of cycles of a permutation.
This function returns the number of cycles of a permutation (different algorithm using a boolean vector).
- Returns:
The number of cycles.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([1,2,3,6,0,5,4]) >>> x.nb_cycles_ref() 11
- nb_cycles_unroll(self: Perm16) int
Returns the number of cycles of a permutation.
This function returns the number of cycles of a permutation (different algorithm using
cycles_partition).- Returns:
The number of cycles.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([1,2,3,6,0,5,4]) >>> x.nb_cycles_unroll() 11
- nb_descents(self: Perm16) int
Returns the number of descent of a permutation.
This function returns the the number of descent of a permutation. (found using vector shift and comparison).
- Returns:
The number of descents in self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([0,3,2,4,1]).nb_descents() 2
- nb_descents_ref(self: Perm16) int
Returns the number of descent of a permutation.
This function returns the the number of descent of a permutation. (found using a loop).
- Returns:
The number of descents in self.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([0,3,2,4,1]).nb_descents_ref() 2
- static one() Perm16
Returns the identity permutation.
This function returns the identity
Perm16which fixes every value in \([0, 16)\).- Returns:
The identity permutation.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> x = Perm16([1, 2, 0]) >>> x * x.one() == Perm16.one() * x == x True
- static unrankSJT(r: int) Perm16
Returns the r-th permutation of size
16in the Steinhaus–Johnson–Trotter order.This function returns the r-th permutation of size
16in the Steinhaus–Johnson–Trotter order.>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16.unrankSJT(2) Perm16([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,15,13,14])
- validate(self: Perm16, bound: int = 16) bool
Check whether or not a
Perm16is well-defined.This function returns
Trueif self is a well-defined permutation (i.e. no image value is larger than15and no repeated image value) on the values0up to bound.- Parameters:
bound (int) – the bound (defaults to
16).- Returns:
Whether or not self is valid.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Perm16 >>> Perm16([1, 0, 2]).validate() True >>> x = Perm16([1, 0, 2]) >>> x[0] = 0 >>> x.validate() False