Quickstart

Quickstart#

Symmetria offers three classes for representing permutations: Permutation, Cycle, and CycleDecomposition. Each of these classes has its own set of advantages and disadvantages depending on the specific goal you want to achieve.

Below is a brief example showcasing the capabilities of one of the aforementioned classes.

To begin, import your selected class with:

from symmetria import Permutation
from symmetria import Cycle
from symmetria import CycleDecomposition

you can now instantiate a permutation

permutation = Permutation(1, 3, 4, 5, 2, 6)
print(permutation)
# (1, 3, 4, 5, 2, 6)
cycle = Cycle(1, 3, 4, 5, 2, 6)
print(cycle)
# (1 3 4 5 2 6)
cycle_decomposition = CycleDecomposition(Cycle(1, 3, 4,), Cycle( 5, 2, 6))
print(cycle_decomposition)
# (1 3 4)(5 2 6)

You can employ standard syntax to manipulate these objects, designed for utmost intuitiveness. Here are a few illustrative examples:

if permutation:
    print("The permutation is different from the identity permutation.")
if permutation == Permutation(1, 2, 3, 4, 5, 6):
    print("The permutation is equal to the identity.")
if len(permutation) == 6:
    print("The permutation has 6 elements, i.e., it acts on 6 elements.")
# The permutation is different from the identity.
# The permutation has 6 elements, i.e., it acts on 6 elements
if cycle:
    print("The cycle is different from the identity cycle.")
if permutation == Cycle(1):
    print("The cycle is equal to the identity cycle.")
if len(cycle) == 6:
    print("The cycle has length 6, i.e., it is a 6-cycle.")
# The cycle is different from the identity cycle.
# The cycle has length 6, i.e., it is a 6-cycle.
if cycle_decomposition:
    print("The cycle decomposition is different from the identity permutation.")
if len(cycle_decomposition) == 6:
    print("The cycle decomposition has length 6, i.e., it is composed by 6 cycles.")
# The cycle is different from the identity cycle.
# The cycle decomposition has length 6, i.e., it is composed by 6 cycles.

Many methods for retrieving the properties of the permutation you wish to work with are already available.

permutation.order()  # 4
permutation.support()  # {2, 3, 4, 5}
permutation.is_derangement()  # True
cycle.order() # 6
cycle.support() # {1, 3, 4, 5, 2, 6}
cycle.is_derangemenet() # True
cycle_decomposition.order() # 3
cycle_decomposition.support() # {1, 2, 3, 4, 5, 6}
cycle_decomposition.is_derangement() # True

You can find more in the API reference section.