Python | SymPy Permutation.cyclic_form () method

Python Methods and Functions

Permutation.cyclic_form (): cyclic_form () — this is a nice Python library function that returns cyclic notation from canonical notation, omitting single characters.

Syntax:
sympy.combinatorics.permutations.Permutation.cyclic_form ()

Return:
cyclic notation from the canonical notation

Code # 1: cyclic_form () example

# Python code explaining
# SymPy.Permutation.cyclic_form ( )

 
# import SymPy libraries

from sympy.combinatorics.partitions import Partition

from sympy.combinatorics.permutations import Permutation

  
# Using the sympy.combinatorics.permutations.Permutation.cyclic_form () method

  
# create permutation

a = Permutation ([ 2 , 0 , 3 , 1 , 5 , 4 ])

 

b = Permutation ([ 3 , 1 , 2 , 5 , 4 , 0 ])

 

 

print ( "Permutation a - cyclic_form form:" , a.cyclic_form)

print ( "Permutation b - cyclic_form form:" , b.cyclic_form)

Output:

Permutation a - cyclic_form form: [[0, 2, 3, 1], [4, 5]]
Permutation b - cyclic_form form: [[0, 3 , 5]]

Code # 2: cyclic_form () example — 2D permutation

# Python code explaining
# SymPy.Permutation.cyclic_form ()

 
# import SymPy libraries

from sympy.combinatorics.partitions import Partition

from sympy.combinatorics.permutations import Permutation

 
# Using from
# sympy.combinatorics.permutations.Permutation.cyclic_form () method

 
# create permutations

a = Permutation ([[ 2 , 4 , 0 ], 

[ 3 , 1 , 2 ],

[ 1 , 5 , 6 ]])

 
# SELF COMMUTATION

print ( "Pe rmutation a - cyclic_form form: " , a.cyclic_form)

Output:

Permutation a - cyclic_form form: [[0, 3, 5, 6, 1, 2 , 4]]





Get Solution for free from DataCamp guru