# Implementing summation under combinatorial restriction

For $$m,n\in\mathbb N$$, I am interested in the numerical evaluation of $$f(m,n) = \sum_{s_j\in\{\pm1\}}' \prod_{k=1}^{2n-1} (1-e^{\frac{2i\pi}{m} s_k(s_{k+1}+s_{k+2}+\cdots+s_{2n})}),$$ where the summation is taken over $$s_1, \ldots, s_{2n}\in\{\pm1\}$$, with the additional assumption that exactly $$n$$ elements in $$s_1,\ldots, s_{2n}$$ are $$+1$$. For example, if $$n=2$$ the allowed $$s_1,\ldots, s_4$$ is $$(s_1,\ldots, s_4) = (+1, +1, -1, -1), (+1, -1, +1, -1), (+1, -1, -1, +1), (-1, +1, +1, -1), (-1, +1, -1, +1), (-1, -1, +1, +1).$$ The $$'$$ in the summation denotes the restricted summation.

How can I implement this summation over restriction in Mathematica as a function of $$m,n$$?

f[m_, n_] := ???


For $$n=1$$, one may evaluate $$f(m,1) = \sum_{s_j\in\{\pm1\}}' (1-e^{\frac{2i\pi}{m}s_1s_2}) = 2(1-e^{-\frac{2i\pi}{m}}).$$

• Could you please show a concrete example for a small $n$, say, $n = 2$ or $n = 3$? Feb 26, 2022 at 6:16
• @ΑλέξανδροςΖεγγ I put an example for $n=1$. Already for $n=2$, the evaluation by hand is too complicated. Feb 26, 2022 at 6:51
• notation you are using is very confusing. First what is $'$ in there mean? why do you have it? what exactly is the sum over? and is the $i$ in the $e^{2 i \pi}$ meant to the complex $i$ or an index? What does your $f(1,1)$ for example supposed to generate? What is the set $s_i$ looks like for say $n=2$? is it $s=\{1,-1,1,-1\}$ ? or something else? if you clear these, may be will provide code but do not want to do as it is not clear to me now. Feb 26, 2022 at 7:09
• @Nasser Sorry if it was unclear. I modified the question. Feb 26, 2022 at 7:16

Is this f what you desire:

Clear[f]
f[m_, n_] := Module[{s, summant, indexes},
s[i_] := ToExpression@StringTemplate["s"][i];
summant =
Evaluate[Array[s, 2 n]] \[Function]
Evaluate@
Product[1 - Exp[2 I π s[k] Sum[s[i], {i, k + 1, 2 n}]/m], {k,
2 n - 1}];
indexes = Permutations[Flatten@ConstantArray[{1, -1}, n]];
Total[summant @@@ indexes]
]


• Thanks a lot for your answer! However, I obtained an error when copy-pasting your code. (Please see my edited question.) Feb 26, 2022 at 7:20
• @eigenvalue I guess your version can not use |->? If yes, replace it with \[Function]. Feb 26, 2022 at 7:21
• It works. Thanks a lot! The trick Permutations[Flatten@ConstantArray[{1, -1}, n]] was very useful, and I should remember that. Feb 26, 2022 at 7:22
• @eigenvalue Glad to be helpful. This is just a first-step implementation and I think there should be room for speed- or RAM-optimizations, if for a larger $n$. Feb 26, 2022 at 7:25