The Transf class

Class for representing transformations on up to 2 ** 32 points.

A transformation \(f\) is just a function defined on the whole of \(\{0, 1, \ldots, n - 1\}\) for some integer \(n\) called the degree of \(f\). A transformation is stored as a list of the images of \(\{0, 1, \ldots, n - 1\}\), i.e. \([(0)f, (1)f, \ldots, (n - 1)f]\).

Transformations are optimised for the number of points in the image with fewer points requiring less space per point.

>>> from libsemigroups_pybind11.transf import Transf, one
>>> x = Transf([0, 0, 2, 2, 0, 1])
>>> x.degree()
6
>>> x[0]
0
>>> x[5]
1
>>> x
Transf([0, 0, 2, 2, 0, 1])
>>> x * x
Transf([0, 0, 2, 2, 0, 0])
>>> x < x * x
False
>>> y = Transf([9, 7, 3, 5, 3, 4, 2, 7, 7, 1])
>>> x = one(y)
>>> x.product_inplace(y, y)
>>> x
Transf([1, 7, 5, 4, 5, 3, 3, 7, 7, 7])
>>> list(x.images())
[1, 7, 5, 4, 5, 3, 3, 7, 7, 7]
>>> x.rank()
5
>>> one(x)
Transf([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> x = Transf.one(8)
>>> x
Transf([0, 1, 2, 3, 4, 5, 6, 7])
>>> x.degree()
8
>>> x.swap(y)
>>> x, y
(Transf([9, 7, 3, 5, 3, 4, 2, 7, 7, 1]), Transf([0, 1, 2, 3, 4, 5, 6, 7]))
>>> x = Transf([1, 0, 2])
>>> y = x.copy()
>>> x is y
False
>>> x == y
True
>>> {x, y}
{Transf([1, 0, 2])}

Contents

Transf

Class for representing transformations on up to 2 ** 32 points.

Transf.copy(…)

Copy a transformation.

Transf.images(…)

Returns an iterator to the images of a transformation.

Transf.increase_degree_by(…)

Increases the degree of self in-place, leaving existing values unaltered.

Transf.one(…)

Returns the identity transformation on N points.

Transf.product_inplace(…)

Replaces the contents of self by the product of x and y.

Transf.rank(…)

Returns the number of distinct image values in a transformation.

Transf.swap(…)

Swap with another transformation of the same type.

Full API

class Transf
__init__(self: Transf, imgs: list[int]) None

A transformation can be constructed from a list of images, as follows: the image of the point i under the transformation is imgs[i].

Parameters:

imgs (list[int]) – the list of images.

Raises:

LibsemigroupsError – if any value in imgs exceeds len(imgs).

Complexity:

Linear in degree().

copy(self: Transf) Transf

Copy a transformation.

Returns:

A copy of the argument.

Return type:

Transf

degree(self: Transf) int

Returns the degree of a transformation.

The degree of a transformation is the number of points used in its definition, which is equal to the size of Transf.images.

Returns:

The degree.

Return type:

int

images(self: Transf) collections.abc.Iterator[int]

Returns an iterator to the images of a transformation.

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

collections.abc.Iterator[int]

increase_degree_by(self: Transf, m: int) Transf

Increases the degree of self in-place, leaving existing values unaltered.

Parameters:

m (int) – the number of points to add.

Returns:

self

Return type:

Transf

Complexity:

At worst linear in the sum of the parameter m and degree().

static one(N: int) Transf

Returns the identity transformation on N points. This function returns a newly constructed transformation with degree equal to N that fixes every value from 0 to N.

Parameters:

N (int) – the degree.

Returns:

The identity transformation.

Return type:

Transf

product_inplace(self: Transf, x: Transf, y: Transf) None

Replaces the contents of self by the product of x and y.

Parameters:
  • x (Transf) – a transformation.

  • y (Transf) – a transformation.

Complexity:

Linear in degree().

rank(self: Transf) int

Returns the number of distinct image values in a transformation.

The rank of a transformation is the number of its distinct image values, not including UNDEFINED.

Returns:

The number of distinct image values.

Return type:

int

Complexity:

Linear in degree().

swap(self: Transf, other: Transf) None

Swap with another transformation of the same type.

Parameters:

other (Transf) – the transformation to swap with.