# 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[4] = A - p[1]

p[5] = B - p[1]

p[7] = C - (p[1] + p[4] + p[2] + p[14])

p[8] = D - (p[1] + p[4] + p[3] + p[15])

p[9] = E - (p[1] + p[2] + p[5] + p[15])

p[10] = F - (p[1] + p[3] + p[5] + p[14])

p[11] = G - (p[1] + p[4] + p[5] + p[13])

p[12] = 1 - (p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + p[8] +
p[9] + p[10] + p[11] + p[13] + p[14] + p[15])

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[1], p[2], p[3], p[6], p[13], p[14], p[15].

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[1] = A - p[4] and then I'll be able to write L in terms of p[4] instead of p[1]. 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