# Permuting symbols

Suppose I have a list like {a, b, a, c}. How can I apply a "symbolic permutation" of the symbols a, b, and c such as a->b, b->c, c->a to produce {b, c, b, a}?

Replace[] with multiple rules applies them all sequentially, and I get {a, b, a, c} back. Permute[] can only change the positions of things in a list, not their names. PermutationReplace[] requires a permutation to be specified with integers, not with symbols.

• You can try RepalceAll as in {a, b, a, c} /. {a -> b, b -> c, c -> a}. Jan 10, 2016 at 21:42
• Replace[{a, b, a, c}, {a -> b, b -> c, c -> a}, 1] or Replace[{a, b, a, c}, {a -> b, b -> c, c -> a}, {1}] would also work. You need to specify the level specification because you want to replace level 1 (inside a list), not level 0; Replace replaces level 0 only by default. Jan 10, 2016 at 21:43
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Jan 10, 2016 at 22:07
• To clarify: My confusion was over how to use Replace[]. The problem wasn't that it applied all the rules in sequence; the problem was that I was applying the rules at the wrong level, and they weren't taking effect. When they are applied at the right level, only one takes effect on each element. Jan 12, 2016 at 4:10

I realized that Map and Association can do the job:

Map[Association[a -> b, b -> c, c -> a][#] &, {a, b, a, c}]


I appreciate the quick answers from eldo and Kuba, but they were both too specific to my example. In general, I won't know the indexes of the elements I need to change, or the particular permutation I need to make.

For any arbitrary permutation, I can create an Association, and then Map each element of an arbitrary list.

• I now see that b.gatessucks and JHM provided general answers in comments to my original question. Thanks! Jan 11, 2016 at 1:58
• Is there a way for me to approve an answer in a comment to the original question? Jan 11, 2016 at 1:59
list = {a, b, a, c};

ReplacePart[list /. a -> b, {{2} -> c, {4} -> a}]


{b, c, b, a}

or simply

list[[{2, 4, 2, 1}]]


{b, c, b, a}