# Replacement rule from list to powers

I would like to write a replacement rule that gives all the possible products of traces for a given length. For example, all the possible partitions of length 3 can be obtained as follows:

IntegerPartitions[3]
(*{{3}, {2, 1}, {1, 1, 1}}*)


Each sublist gives the power in the trace, i.e. each sublist carries the following meaning:

$$\lbrace k_1,k_2,\ldots , k_n \rbrace \to \text{tr}\ a^{k_1}\ \text{tr}\ a^{k_2} \ldots \text{tr}\ a^{k_n}\,. \tag{1}$$

Hence the output of the seeked replacement rule should be (here for length 3):

IntegerPartitions[3]/.rule
(*{tr[a^3],tr[a^2]tr[a],tr[a]^3}*)


I hope it is clear enough! How can this be achieved?

• rule = p_?VectorQ :> Times @@ (tr /@ (a^p)); IntegerPartitions[3] /. rule – Bob Hanlon Mar 30 at 18:00

ip = IntegerPartitions[3]

Times @@@ Map[tr, a^ip, {2}]

{tr[a^3], tr[a] tr[a^2], tr[a]^3}

• Fantastic, thanks a lot! – Jxx Mar 30 at 18:01
• @Jxx, you are most welcome. Thank you for the accept. – kglr Mar 30 at 18:25