17
A permutation of size n is a reordering of the first n positive integers. (meaning each integer appears once and exactly once). Permutations can be treated like functions that change the order of a list of items of size n. For example
(4 1 2 3) ["a", "b", "c", "d"] = ["d", "a", "b", "c"]
Thus permutations can be composed like functions.
(4 1 2 3)(2 1 3 4) = (4 2 1 3)
This brings about a lot of interesting properties. Today we are focusing on conjugacy. Permutations y and x (both of size n) are conjugates iff there are permutations g and g-1 (also of size n) such that
x = gyg-1
and gg-1 is equal to the identity permutation (the first n numbers in proper order).
Your task is to take two permutations of the same size via standard input methods and decide whether they are conjugates. You should output one of two consistent values, one if they are conjugates and the other if they are not.
This is code-golf so answers will be scored in bytes with fewer bytes being better.
There are lots of theorems about conjugate permutations that are at your disposal, so good luck and happy golfing.
You may take input as an ordered container of values (either 1-n or 0-n) representing the permutation like above, or as a function that takes a ordered container and performs the permutation. If you choose to take function you should take it as an argument rather than have it at a predefined name.
Test Cases
(1) (1) -> True
(1 2) (2 1) -> False
(2 1) (2 1) -> True
(4 1 3 2) (4 2 1 3) -> True
(3 2 1 4) (4 3 2 1) -> False
(2 1 3 4 5 7 6) (1 3 2 5 4 6 7) -> True
Can we take input as a function? Can we also take in the size n? – xnor – 2018-02-16T00:34:46.593
@xnor Sure on both counts. I'm not sure how the first will help you though. – Post Rock Garf Hunter – 2018-02-16T00:35:27.703
The default function input rules allow the function to be assumed to be predefined, which saves bytes on writing it as an argument, if you allow it. – xnor – 2018-02-16T00:40:17.940
@xnor Are we talking about this rule? That is for black box functions which permutations are not. This makes sense because that consensus is designed to allow languages without function pointers/objects to compete whereas here they can because permutations can be represented otherwise.
– Post Rock Garf Hunter – 2018-02-16T00:43:09.077I was, I didn't think of the distinction of them being black-box. So here, the input may be a function, but only as an explicit argument? – xnor – 2018-02-16T00:45:42.227
@xnor Yes. That is my intention. I'll detail this in the post. – Post Rock Garf Hunter – 2018-02-16T00:46:19.270
@WheatWizard could you show the working on a test case? – Manish Kundu – 2018-02-16T01:35:54.523
@ManishKundu You can show that those two are conjugates by decomposing them into their cycle factors. The first is
(2 1)(7 6)
and the second is(3 2)(5 4)
. There is a theorem that tells us that if two permutations have the same cycle structures they are conjugates and both of these have the cycle structure(- -)(- -)
– Post Rock Garf Hunter – 2018-02-16T01:41:21.370Do we need to support the empty permutation ? – Ton Hospel – 2018-02-18T07:06:11.713