Let us have variables v[k], k=1,...,n. Variables v[k] can have only two values: +1 or -1. I want to find a sequence of values of the following double sums: \sum^n{i=1} \sum^n{j=1} v(i) v(j) w(i,j) where w is a weight function, for all possible +/-1 values. So, the 1st term in the sequence would be the value of the sums for v[1]=1, v[2]=1, ... , v[n]=1, the 2nd term in the sequence would be the value of the sums for v[1]=1, v[2]=1, ... , v[n-1]=1, v[n]=-1, ......... The last term in the sequence would be the value of the sums for v[1]=-1, v[2]=-1, ... , v[n]=-1.
How can I obtain such a sequence in Mathematica?
Thanks, Mladen.
Seems I could help you. That's fine. Both approaches are equivalent:
In[166]:= sums - ((sum /. #) & /@ rule) Out[166]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
I don't think so, but thanks for the suggestion.
The latter. Thanks. I learned a lot. I'm afraid I wouldn't be able to find "/@ Range[n]" or "& /@ x /. {v[a], b} -> (v[a] -> b)" in the Documentation soon enough.
Could you be looking for something like this?
In[1]:= Total /@ Tuples[{1, -1}, 5] Out[1]= {5, 3, 3, 1, 3, 1, 1, -1, 3, 1, 1, -1, 1, -1, -1, -3, 3, 1, \ 1, -1, 1, -1, -1, -3, 1, -1, -1, -3, -1, -3, -3, -5}
Or perhaps like this
n = 5 x = Tuples[{-1, 1}, n] // Reverse var = v /@ Range[n] rule = Transpose[{var, #}] & /@ x /. {v[a_], b_} -> (v[a] -> b) m = Table[w[i, j], {i, n}, {j, n}]; m // MatrixForm sum = var.m.var (sum /. #) & /@ rule
I am afraid I don't quite understand what you mean. This perhaps?
n = 5; x = Tuples[{-1, 1}, n] // Reverse; sums = Table[Sum[w[i, j] x[[k, i]] x[[k, j]], {i, n}, {j, n}], {k, Length[x]}]; sums // TableForm
Here you get 2^n = 32 sums with n^2 = 25 terms each.
{{1, 1, 1, 1, 1}, {1, 1, 1, 1, -1},....,{-1, -1, -1, -1, -1} is the premise we start from. The problem is how to call these series from sums. In particular for the first sum we should obtain v[1]=1,v[2]=1,...,v[5]=1 from {1, 1, 1, 1, 1} and obtain some value for the sums. Then the algorithm should call the second set {1, 1, 1, 1, -1} form the next v[1]=1,v[2]=1,...,v[5]=-1, and so on. What would be the Mathematica program for that?
What about
n = 5; x = Tuples[{-1, 1}, n] x // Reverse
?