4
$\begingroup$

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}}).$$

$\endgroup$
4
  • 2
    $\begingroup$ Could you please show a concrete example for a small $ n $, say, $ n = 2 $ or $ n = 3 $? $\endgroup$ Feb 26, 2022 at 6:16
  • $\begingroup$ @ΑλέξανδροςΖεγγ I put an example for $n=1$. Already for $n=2$, the evaluation by hand is too complicated. $\endgroup$
    – Laplacian
    Feb 26, 2022 at 6:51
  • $\begingroup$ 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. $\endgroup$
    – Nasser
    Feb 26, 2022 at 7:09
  • $\begingroup$ @Nasser Sorry if it was unclear. I modified the question. $\endgroup$
    – Laplacian
    Feb 26, 2022 at 7:16

1 Answer 1

4
$\begingroup$

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]
  ]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks a lot for your answer! However, I obtained an error when copy-pasting your code. (Please see my edited question.) $\endgroup$
    – Laplacian
    Feb 26, 2022 at 7:20
  • 1
    $\begingroup$ @eigenvalue I guess your version can not use |->? If yes, replace it with \[Function]. $\endgroup$ Feb 26, 2022 at 7:21
  • $\begingroup$ It works. Thanks a lot! The trick Permutations[Flatten@ConstantArray[{1, -1}, n]] was very useful, and I should remember that. $\endgroup$
    – Laplacian
    Feb 26, 2022 at 7:22
  • 1
    $\begingroup$ @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 $. $\endgroup$ Feb 26, 2022 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.