Skip to content

Latest commit

 

History

History
82 lines (69 loc) · 1.79 KB

index.rst

File metadata and controls

82 lines (69 loc) · 1.79 KB
.. module:: permutation

permutation — Permutations of finitely many positive integers

GitHub | PyPI | Documentation | Issues | Changelog

permutation provides a Permutation class for representing permutations of finitely many positive integers in Python. Supported operations & properties include inverses, (group theoretic) order, parity, composition/multiplication, cycle decomposition, cycle notation, word representation, Lehmer codes, and, of course, use as a callable on integers.

Installation

permutation requires Python 3.8 or higher. Just use pip for Python 3 (You have pip, right?) to install:

python3 -m pip install permutation

Examples

>>> from permutation import Permutation
>>> p = Permutation(2, 1, 4, 5, 3)
>>> p(1)
2
>>> p(3)
4
>>> p(42)
42
>>> p.to_cycles()
[(1, 2), (3, 4, 5)]
>>> print(p)
(1 2)(3 4 5)
>>> print(p.inverse())
(1 2)(3 5 4)
>>> p.degree
5
>>> p.order
6
>>> p.is_even
False
>>> p.lehmer(5)
27
>>> q = Permutation.cycle(1,2,3)
>>> print(p * q)
(2 4 5 3)
>>> print(q * p)
(1 3 4 5)
>>> for p in Permutation.group(3):
...     print(p)
...
1
(1 2)
(2 3)
(1 3 2)
(1 2 3)
(1 3)

API

.. autoclass:: Permutation
    :special-members:
    :no-undoc-members:
    :exclude-members: __eq__, __hash__, __repr__, __weakref__

    .. autoclasstoc::

Indices and tables