# Summation over an index and a set I have an index CC and a set of values CM, and c is an element of CM and CM is a subset of CC. I have two summations shown above. The first summation is over index CC and the subset CM. The light brown colored part of the first summation is telling that the summation should include only if c is an element of CM. The second summation is over the elements of CM.

These two summations appear in an equation (not given here for simplicity). Is there an easy way to perform these summations?

Thank you...

EDIT 1 The answer to the above summations is as follows.

(* first summation *)

tq*PD+
tq*PD+PM +
tq*PD+PM +
tq*PD+
tq*PD+
tq*PD+PM+
tq*PD

(* Second summation *)

tq*(PD+QD)+
tq*(PD+QD)+
tq*(PD+QD)

• Is your first sum = tq*PD+ tq*PD+PM+ tq*PD+PM+ tq*PD+ tq*PD+ tq*PD+PM+ tq*PD? Is your second sum = tq*PD*QD+ tq*PD*QD+ tq*PD*QD? – Bill Mar 30 '19 at 2:03
• @Bill: Yes, your answer is right. I edited the question with the expected answer. Thanks. – Tugrul Temel Mar 30 '19 at 11:54

If it is desirable to have everything in a single sum, then the first sum could be written as

cc = 7;
CM = {2, 3, 6};
Sum[tq[c]*PD[c] + PM[c] Boole[MemberQ[CM, c]], {c, cc}]
(* PM + PM + PM + PD tq + PD tq + PD tq +
PD tq + PD tq + PD tq + PD tq *)

• Thank you very much indeed because you helped me solve another question for which I was preparing a MM example. Tugrul – Tugrul Temel Mar 30 '19 at 14:20

Try,

Sum[tq[c] PD[c], {c, 7}] + Sum[PM[c], {c, CM}]
(* PM + PM + PM + PD tq + PD tq + PD tq +
PD tq + PD tq + PD tq + PD tq *)

Sum[tq[c] pd[c] qd[c], {c, CM}]
(* pd qd tq + pd qd tq + pd qd tq *)


If desired, Sum[tq[c] PD[c], {c, 7}] can be replaced by Sum[tq[c] PD[c], {c, CC}], yielding the same result.