1
$\begingroup$

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?

$\endgroup$
1
  • 3
    $\begingroup$ rule = p_?VectorQ :> Times @@ (tr /@ (a^p)); IntegerPartitions[3] /. rule $\endgroup$
    – Bob Hanlon
    Commented Mar 30, 2021 at 18:00

1 Answer 1

2
$\begingroup$
ip = IntegerPartitions[3]

Times @@@ Map[tr, a^ip, {2}]
{tr[a^3], tr[a] tr[a^2], tr[a]^3}
$\endgroup$
2
  • $\begingroup$ Fantastic, thanks a lot! $\endgroup$
    – Pxx
    Commented Mar 30, 2021 at 18:01
  • $\begingroup$ @Jxx, you are most welcome. Thank you for the accept. $\endgroup$
    – kglr
    Commented Mar 30, 2021 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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