What is a good Python program to calculate the composition( from right to left) of cycle permutations? I know how to calculate the answer, but I don't know the algorithm for a Python program.
For example; '(1,6,5,3)(1,4,2,3)' has the solution '(1,4,2)(3,6,5)'. Because 1 - 4 - 4, 4 - 2 - 2, 2 - 3 - 1 and 3 - 1 - 6, 6 - 6 - 5, 5 - 5 - 3
On the internet I couldn't find where to begin or what to do. Can someone please help me?
Composition of cycle permutation
874 views Asked by twister At
1
The Sympy package handles cycle permutations nicely. Your method of writing permutations is called "Disjoint Cycle Notation". Here's an example using your cycles:
This gives output
(142)(365)fornew_perm.For any of these cycles, you can call them like a function. For example, we can input
1tonew_permand would expect4as an output:Edit
The Sympy permutations can be used as the building blocks for a function which composes cycle permutations together. The original question asked for a string input and output. Here is one example (you may have to modify based on your string input):
The last line of the functions calls
strwhich returns the string representation (not the original permutation). Our output is'(1 4 2)(3 6 5)'