The Perm class
Class for representing permutations on up to 2 ** 32 points.
A permutation \(f\) is an injective transformation defined on the whole of \(\{0, 1, \ldots, n - 1\}\) for some integer \(n\) called the degree of \(f\). A permutation is stored as a list of the images of \((0, 1, \ldots, n - 1)\), i.e. \(((0)f, (1)f, \ldots, (n - 1)f)\).
Permutations are optimised for the number of points in the image with fewer points requiring less space per point.
>>> from libsemigroups_pybind11.transf import Perm, one, inverse
>>> x = Perm([0, 2, 1, 3, 4, 5])
>>> x.degree()
6
>>> x[0]
0
>>> x[5]
5
>>> x
Perm([0, 2, 1, 3, 4, 5])
>>> x * x
Perm([0, 1, 2, 3, 4, 5])
>>> x < x * x
False
>>> y = Perm([ 5, 2, 0, 1, 3, 4, 6 ])
>>> x = one(y)
>>> x.product_inplace(y, y)
>>> x
Perm([4, 0, 5, 2, 1, 3, 6])
>>> x == y * y
True
>>> list(x.images())
[4, 0, 5, 2, 1, 3, 6]
>>> x.rank()
7
>>> one(x)
Perm([0, 1, 2, 3, 4, 5, 6])
>>> x = Perm.one(8)
>>> x
Perm([0, 1, 2, 3, 4, 5, 6, 7])
>>> x.degree()
8
>>> x.swap(y)
>>> x, y
(Perm([5, 2, 0, 1, 3, 4, 6]), Perm([0, 1, 2, 3, 4, 5, 6, 7]))
>>> x = Perm([1, 0, 2])
>>> y = x.copy()
>>> x is y
False
>>> x == y
True
>>> {x, y}
{Perm([1, 0, 2])}
Contents
| Class for representing permutations on up to  | |
| 
 | Copy a permutation. | 
| 
 | Returns the degree of a permutation. | 
| 
 | Returns an iterator to the images of a permutation. | 
| Increases the degree of self in-place, leaving existing values unaltered. | |
| 
 | Returns the identity permutation on N points. | 
| Replaces the contents of self by the product of x and y. | |
| 
 | Returns the number of distinct image values in a permutation. | 
| 
 | Swap with another permutation of the same type. | 
Full API
- class Perm
- __init__(self: Perm, imgs: list[int]) None
- A permutation can be constructed from a list of images, as follows: the image of the point - iunder the permutation is- imgs[i].- Parameters:
- Raises:
- LibsemigroupsError – if any value in imgs exceeds - len(imgs).
- LibsemigroupsError – if there are repeated values in imgs. 
 
- Complexity:
- Linear in - degree().
 
 - degree(self: Perm) int
- Returns the degree of a permutation. - The degree of a permutation is the number of points used in its definition, which is equal to the size of - Perm.images.- Returns:
- The degree. 
- Return type:
 
 - images(self: Perm) collections.abc.Iterator[int]
- Returns an iterator to the images of a permutation. - A permutation is stored as a list of the images of \(\{0, 1, \ldots, n - 1\}\), i.e. \([(0)f, (1)f, \ldots, (n - 1)f]\), and this function returns an iterator yielding these values. - Returns:
- An iterator to the image values. 
- Return type:
 
 - increase_degree_by(self: Perm, m: int) Perm
- Increases the degree of self in-place, leaving existing values unaltered. 
 - static one(N: int) Perm
- Returns the identity permutation on N points. This function returns a newly constructed permutation with degree equal to N that fixes every value from - 0to N.
 - product_inplace(self: Perm, x: Perm, y: Perm) None
- Replaces the contents of self by the product of x and y.