# How to cycle through all my variables

I have the following set of conditions for p[i]'s and defined a function L in terms of the p[i], i = 1,2,3,...,15.

p = A - p

p = B - p

p = C - (p + p + p + p)

p = D - (p + p + p + p)

p = E - (p + p + p + p)

p = F - (p + p + p + p)

p = G - (p + p + p + p)

p = 1 - (p + p + p + p + p + p + p + p +
p + p + p + p + p + p)

L = Sum[n[i]*Log[p[i]], {i, 15}]


Note: A,B,C,D,E,F,G are constants.

With this, I can rewrite L in terms of p, p, p, p, p, p, p.

I want to consider other ways of rewriting L, i.e., L in terms of other combinations of p[i]. How can I set up the code in Mathematica?

• First, do not use capital single letter variable names - several of them have a built-in meaning (such as C,D,E in your code). For the actual question, I'm not 100% what you're after. But if I understand correctly, you can try to use Reduce and pass all your relations as equations. – Lukas Lang Jun 6 '18 at 8:45
• For instance, I could swap the first line of code to become p = A - p and then I'll be able to write L in terms of p instead of p. After reduction, L will be written in terms of 7 such p[i]'s because there are 15 unknowns and 8 conditions. I want to see the form that L takes for all possible choices of p[i], ie to say 15 choose 7 such choices. – Haikal Yeo Jun 6 '18 at 14:15