Message Boards Message Boards

4 Replies
1 Total Likes
View groups...
Share this post:

Turn a product of elements into a list

Posted 9 years ago

I am writing a code to apply Wick's theorem to expectation values of products of elements like x[i][t], y[k][t2]... I would like to find a way to turn such products into lists {x[i][t],y[k][t2], ...}, so that then I can use Subsets to find all pairings between the elements, and then replace them by the corresponding expectation values. How could I achieve this? Best,


4 Replies

Perhaps you can do it with Cases and a pattern:

Cases[x[i][t]*y[k][t2], (x | y)[i_][t_], All]
POSTED BY: Gianluca Gorni

This almost does the job, but I would need terms like (x[i][t])^3 to be recognized as three different x[i][t] items in the output list!

This may work:

Cases[x[i][t]^3*y[k][t2], a_[i_][t_]^n_. :> Table[a[i][t], {n}], 
  1] // Flatten
POSTED BY: Gianluca Gorni

This works, thank you very much!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract