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:

(*{{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):


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

  • 2
    $\begingroup$ rule = p_?VectorQ :> Times @@ (tr /@ (a^p)); IntegerPartitions[3] /. rule $\endgroup$ – 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}
  • $\begingroup$ Fantastic, thanks a lot! $\endgroup$ – Jxx Mar 30 at 18:01
  • $\begingroup$ @Jxx, you are most welcome. Thank you for the accept. $\endgroup$ – kglr Mar 30 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.