9
Given two permutations in disjoint cycle form, output their product/composition in disjoint cycle form.
To find the composition, convert the disjoint cycles to permutations in two-line notation. Each number in a disjoint part of a cycle is mapped to the number following it in the same part. It wraps around. So 1 -> 5
, 5 -> 1
, 2 -> 4
, 4 -> 2
. If a number is not found, 3 -> 3
, it is mapped to itself. The first disjoint cycle could also be written (1 5)(2 4)(3)
. These mappings are converted to two lines, like so (note that the order of P and Q are reversed):
[T]he product of two permutations is obtained by rearranging the columns of the second (leftmost) permutation so that its first row is identical with the second row of the first (rightmost) permutation. The product can then be written as the first row of the first permutation over the second row of the modified second permutation.
Rules:
- Input will be given as a list of lists or similar format
- You may not take something like
(1 5)(2 4)
as[5, 4, 3, 2, 1]
, already in two-line form (mapping index to value) - Not all numbers have to occur in each group, so you could have
(1 5)·(1 2)
, resulting in(2 5 1)
. - Your output should be able to be used as your input.
- You do not need to support input with an empty cycle
(1 5)·()
. That would instead be given as(1 5)·(1)
or something equivalent. - Since cycles wrap around, the order doesn't matter as long as the result is correct.
- You can start at zero or one. It doesn't matter, because the results are the same.
- The numbers can be larger than
9
. - You may not include the same number more than once in the output. So
[[1],[1]]
is not allowed. - Note that this operation is not commutative! I put Q before P, because that's what Wikipedia did. You can choose any order, but specify which if it's different.
- Shortest code wins
- Built-ins are allowed, but if you use one, show a solution without using it as well.
Examples:
Not all equivalent output possibilities are shown
Input
Output
[[1, 5], [2, 4]], [[1, 2, 4, 3]]
[[1, 4, 3, 5]] (or [[4, 3, 5, 1]] or ...)
[[1, 5]], [[1, 2]]
[[2, 5, 1]]
[[10, 2, 3]], [[2]]
[[3, 10, 2]]
[[1]], [[3]]
[[]] (or [[1]] or something equivalent)
[[10,2,3,15],[1,7],[5,6],[14,4,13,11,12]], [[5,6,7,9,14],[2,8,3,10],[1,11]]
[[12, 14, 6, 1], [8, 15, 10, 3, 2], [13, 11, 7, 9, 4]]
(arguments in reverse order from above gives a different answer)
[[5,6,7,9,14],[2,8,3,10],[1,11]], [[10,2,3,15],[1,7],[5,6],[14,4,13,11,12]]
[[9, 14, 4, 13, 1], [10, 8, 3, 15, 2], [7, 11, 12, 5]]
To me, these are permutations, not permutation groups. A permutation group is a collection, closed under this composition operation, of a bunch of individual permutations. – Greg Martin – 2017-04-05T19:51:32.993
@GregMartin Fixed terminology – mbomb007 – 2017-04-05T19:56:16.913