TransWikia.com

Replacement rule from list to powers

Mathematica Asked on June 27, 2021

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?

One Answer

ip = IntegerPartitions[3]

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

Correct answer by kglr on June 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP