I am generating polynomials and I want to iterate each term in the polynomial and do something accordingly. I collect the first term. I wish to extract the tuples of 1,1,1 and 2,1,1 out and do some calculations.... Do you know how I could achieve that? Thank you:)

expr1 := mu*(h[1, 1, 1]+h[1, 1, 2]+h[1, 1, 3]+h[1, 1, 4])+J1*(h[1, 1, 1]*h[2, 1, 1]+h[1, 1, 2]*h[2, 1, 2]+h[1, 1, 3]*h[2, 1, 3]+h[1, 1, 4]*h[2, 1, 4])+2*J2*(h[1, 1, 1]*h[1, 1, 3]+h[1, 1, 2]*h[1, 1, 4]+h[1, 1, 3]*h[2, 1, 1]+h[1, 1, 4]*h[2, 1, 4]);

mu (h[1, 1, 1] + h[1, 1, 2] + h[1, 1, 3] + h[1, 1, 4]) + J1 (h[1,

1, 1] h[2, 1, 1] + h[1, 1, 2] h[2, 1, 2]

+ h[1, 1, 3] h[2, 1, 3] + h[1, 1, 4] h[2, 1, 4]) + 2 J2 (h[1,

1, 1] h[1, 1, 3] + h[1, 1, 2] h[1, 1, 4]

+ h[1, 1, 3] h[2, 1, 1] + h[1, 1, 4] h[2, 1, 4])

expand(expr1);

J1 h[1, 1, 1] h[2, 1, 1] + J1 h[1, 1, 2] h[2, 1, 2]

+ J1 h[1, 1, 3] h[2, 1, 3] + J1 h[1, 1, 4] h[2, 1, 4]

+ 2 J2 h[1, 1, 1] h[1, 1, 3] + 2 J2 h[1, 1, 2] h[1, 1, 4]

+ 2 J2 h[1, 1, 3] h[2, 1, 1] + 2 J2 h[1, 1, 4] h[2, 1, 4]

+ mu h[1, 1, 1] + mu h[1, 1, 2] + mu h[1, 1, 3]

+ mu h[1, 1, 4]