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.

Perm16 inherits from Transf16.

Contents

Perm16

Class representing permutations.

Perm16.copy(…)

Copy a Perm16.

Perm16.cycles_partition(…)

Returns the set partition of the cycles of a permutation.

Perm16.elementary_transposition(…)

Returns the elementary transposition swapping i and i + 1.

Perm16.inverse(…)

Returns the inverse permutation.

Perm16.inverse_arr(…)

Returns the inverse permutation.

Perm16.inverse_cycl(…)

Returns the inverse permutation.

Perm16.inverse_find(…)

Returns the inverse permutation.

Perm16.inverse_pow(…)

Returns the inverse permutation.

Perm16.inverse_ref(…)

Returns the inverse permutation.

Perm16.inverse_sort(…)

Returns the inverse permutation.

Perm16.left_weak_leq(…)

Compare two permutations using the left weak order.

Perm16.left_weak_leq_length(…)

Compare two permutations using the left weak order.

Perm16.left_weak_leq_ref(…)

Compare two permutations using the left weak order.

Perm16.lehmer(…)

Returns the Lehmer code of a permutation.

Perm16.lehmer_arr(…)

Returns the Lehmer code of a permutation.

Perm16.lehmer_ref(…)

Returns the Lehmer code of a permutation.

Perm16.length(…)

Returns the Coxeter length of a permutation.

Perm16.length_arr(…)

Returns the Coxeter length of a permutation.

Perm16.length_ref(…)

Returns the Coxeter length of a permutation.

Perm16.nb_cycles(…)

Returns the number of cycles of a permutation.

Perm16.nb_cycles_ref(…)

Returns the number of cycles of a permutation.

Perm16.nb_cycles_unroll(…)

Returns the number of cycles of a permutation.

Perm16.nb_descents(…)

Returns the number of descent of a permutation.

Perm16.nb_descents_ref(…)

Returns the number of descent of a permutation.

Perm16.one(…)

Returns the identity permutation.

Perm16.unrankSJT(…)

Returns the r-th permutation of size 16 in the Steinhaus–Johnson–Trotter order.

Perm16.validate(…)

Check whether or not a Perm16 is well-defined.

Full API

class hpcombi.Perm16
__init__(*args, **kwargs)

Overloaded function.

__init__(self: Perm16) None

Default constructor.

Constructs a Perm16 object 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 Perm16 from a list of images.

This function constructs a Perm16 from the list img of its entries. If the length of img is less than 16, then the constructed Perm16 is padded with fixed points at the end.

Parameters:

img (list[int]) – The list of images.

Raises:
>>> 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 Perm16 from 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:

Perm16

>>> 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:

Vect16

>>> 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:

Perm16

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:

Perm16

>>> 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 inverse but with a different algorithm (using reference cast to arrays).

Returns:

The inverse of self.

Return type:

Perm16

>>> 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 inverse but 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:

Perm16

>>> 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 inverse but with a different algorithm (some kind of vectorized dichotomic search).

Returns:

The inverse of self.

Return type:

Perm16

>>> 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 inverse but with a different algorithm (raising to the power \(\text{lcm}(1, 2, ..., n) - 1\)).

Returns:

The inverse of self.

Return type:

Perm16

>>> 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 inverse but with a different algorithm (using a loop and indexed access).

Returns:

The inverse of self.

Return type:

Perm16

>>> 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 inverse but 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:

Perm16

>>> 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 True if self is less than other in the left weak order. This function uses length.

Parameters:

other (Perm16) – the permutation for comparison.

Returns:

Whether self is less than or equal to other.

Return type:

bool

>>> 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 True if 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:

bool

>>> 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 True if 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:

bool

>>> 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:

Vect16

>>> 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:

Vect16

>>> 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:

Vect16

>>> 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:

int

>>> 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:

int

>>> 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:

int

>>> 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:

int

>>> 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:

int

>>> 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:

int

>>> 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:

int

>>> 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:

int

>>> 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 Perm16 which fixes every value in \([0, 16)\).

Returns:

The identity permutation.

Return type:

Perm16

>>> 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 16 in the Steinhaus–Johnson–Trotter order.

This function returns the r-th permutation of size 16 in the Steinhaus–Johnson–Trotter order.

Parameters:

r (int) – The index.

Returns:

The r-th permutation.

Return type:

Perm16

>>> 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 Perm16 is well-defined.

This function returns True if self is a well-defined permutation (i.e. no image value is larger than 15 and no repeated image value) on the values 0 up to bound.

Parameters:

bound (int) – the bound (defaults to 16).

Returns:

Whether or not self is valid.

Return type:

bool

>>> from libsemigroups_pybind11.hpcombi import Perm16
>>> Perm16([1, 0, 2]).validate()
True
>>> x = Perm16([1, 0, 2])
>>> x[0] = 0
>>> x.validate()
False