# Generate a list of the product of combinated terms in groups of 2

Here is what I have:

j1=2
Do[Print[w[m1, n1] =
ToExpression["w" <> ToString[m1] <> ToString[n1]]], {m1, 1,
j1}, {n1, 1, j1}]


That's what I got:

w11
w12
w21
w22


I wnat to generate a list with the product of this terms combined in groups of 2. For example:

{w11^2,w11*w12,w11*w21,w11*w22,w12^2,w12*w21,w12*w22,w21^2,w21*w22,w22^2}


Can somebody help me with this?

## 3 Answers

Here is one way

j1 = 2;

Table[ToExpression["w" <> ToString[m1] <> ToString[n1]], {m1, 1, j1}, {n1, 1, j1}] //
Flatten // Tuples[#, 2] & // Apply[Times, #, 1] &

• It's almost that. I just had to use the command to remove duplicates. Thank you ;P Commented Mar 17, 2020 at 20:26
vars = Symbol["w" <> ToString[#] <> ToString[#2]] & @@@ Tuples[{1, 2}, {2}]


{w11, w12, w21, w22}

Flatten @ Table[vars[[i]] vars[[j]], {i, 1, 4}, {j, 1, i}]


{w11^2, w11 w12, w12^2, w11 w21, w12 w21, w21^2, w11 w22, w12 w22, w21 w22, w22^2}

lst ={w11,w12,w21,w22}

Select[Tuples[{lst,lst}], OrderedQ]//Apply[Times,#,1]&


{w11^2,w11 w12,w11 w21,w11 w22,w12^2,w12 w21,w12 w22,w21^2,w21 w22,w22^2}

Original Answer

Times@@@((Tuples[{{lst[[#]]},lst[[#;;]]} ]&/@
Range[4])//Catenate)