# Why do Permute and PermutationReplace not invert one another? [closed]

Why do Permute and PermutationReplace not invert one another, as stated in the documentation?

If we have an identity permutation list (a list of the form Range[n])

In[1]:= list1 = {1, 2, 3};


then Permute and PermutationReplace invert one another:

In[2]:= cycle = Cycles[{{1, 2, 3}}];
Permute[PermutationReplace[list1, cycle], cycle] == list1
Out[3]= True

In[4]:= PermutationReplace[Permute[list1, cycle], cycle] == list1
Out[4]= True


But this does not necessarily hold for lists not of the form Range[n]:

In[5]:= list2 = {3, 2, 1};
PermutationReplace[Permute[list2, cycle], cycle] == list2
Out[6]= False

In[7]:= Permute[PermutationReplace[list2, cycle], cycle] == list2
Out[7]= False


Why is this so?

-

## closed as off-topic by rasher, m_goldberg, Michael E2, ubpdqn, belisariusApr 6 at 20:32

• The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

This question appears to be off-topic because it appears to be an exposition rather than a question: The "question" and answer by OP were posted within seconds of each other. In addition, such information is easily found in the documentation. –  rasher Apr 3 at 21:34
rasher - please see here –  Fructose Apr 3 at 21:53
I am quite aware of the concept. Nonetheless, this is basic information easily found in the documentation. Nothing "magic" here. –  rasher Apr 3 at 22:03
The entry for PermutationReplace (under Properties & Relations) claims that it inverts Permute, which it does not in general - hence my post. "Magic" is not required, but I suppose you are quite aware of that too. –  Fructose Apr 5 at 1:55
The commands do exactly what they're supposed to. You seem to be befuddled by the fact you're operating on a permutation in the example that seems to confuse you. Use PermutationCycles on it, perhaps that will light your bulb. As it stands, this "question" is easily answered by the existing documentation, and the "answer" borders on misleading. Happy to continue this in chat if desired, this is not the place for conversations or disputes. –  rasher Apr 5 at 2:10
show 1 more comment

Mathematica's permutation functions follow two different but almost unremarked conventions. Some of them work on the positions of the elements in the list being permuted; others work on the values.

Permute works on the positions:

In[1]:= Permute[{a, b, c}, Cycles[{{1, 3, 2}}]]
Out[1]= {b, c, a}


i.e. "Shift the element at position 1 to position 3, the element at position 3 to position 2, and the element at position 2 to position 1." Hence Permute will fail if there is an element in the cycles that does not refer to a position in the list:

In[2]:= Permute[{a, b, c}, Cycles[{{1, 4, 2}}]]     (*Fail*)


PermutationReplace works on the values (as long as they're integers):

In[3]:= PermutationReplace[{3, 7, 2, 2}, Cycles[{{2, 6, 3}}]]
Out[3]= {2, 7, 6, 6}


i.e. "Replace instances of 2 with 6, instances of 6 with 3, and instances of 3 with 2." Since 7 does not appear in the cycle, it is not changed.

FindPermutation works on the positions:

In[4]:= FindPermutation[{6, 5, 7}]
Out[4]= Cycles[{{1, 2}}]


i.e. "To get {6, 5, 7} from Sort[{6, 5, 7}] (= {5, 6, 7}), shift the element at position 1 to position 2, and position 2 to position 1."

In[5]:= FindPermutation[{c, a, b}, {a, b, c}]
Out[5]= Cycles[{{1, 3, 2}}]


i.e. "To get the second list, shift the element at position 1 of the first list to position 3, position 3 to position 2, and position 2 to position 1."

PermutationCycles and PermutationList are inverses of one another and work on the values:

In[6]:= PermutationCycles[{4, 1, 3, 2}]
Out[6]= Cycles[{{1, 4, 2}}]


i.e. "To get {4, 1, 3, 2} from {1, 2, 3, 4}, replace instances of 1 with 4, 4 with 2, and 2 with 1."

In[7]:= PermutationList[Cycles[{{1, 4, 2}}]]
Out[7]= {4, 1, 3, 2}


i.e. "If we take {1, 2, 3, 4} and replace 1 with 4, 4 with 2, and 2 with 1, then we get {4, 1, 3, 2}." Or:

In[8]:= PermutationReplace[Range[4], Cycles[{{1, 4, 2}}]]
Out[8]= {4, 1, 3, 2}


In summary: Permute and FindPermutation work on positions, whereas PermutationReplace, PermutationCycles, and PermutationList work on values.

-