I am interested in finding an analytical form of the following function $f(n)$ defined as: $$f(n):=\sum_{\{\bar{K}\}}\prod_{l<j}^{n}e^{ik_lk_j},$$ where $\{\bar{K}\}$ is the full set of binary permutations of length $n$ and $i$ denotes complex $i$. Example for $n = 3$ we get $$\{\bar{K}\} = \{\{0, 0, 0\}, \{0, 0, 1\}, \{0, 1, 0\}, \{1, 0, 0\}, \{0, 1, 1\}, \{1, 0, 1\}, \{1, 1, 0\}, \{1, 1, 1\}\}.$$ Can Mathematica assist in deriving a function in terms of $n$ in a purely mathematical form? The following code defines and evaluates the function $f$ for a given $n$:
n = 3;
K[n_] := Flatten[GatherBy[Tuples[{0, 1}, n], Total], 1]
P[n_, k_] :=
Product[If[i < j, Exp[I*K[n][[k]][[i]]*K[n][[k]][[j]]], 1], {i, 1,
n}, {j, 1, n}];
f[n_] := Sum[P[n, k], {k, 1, 2^n}]
f[n]
f[x]
It gives the correct result for chosen $n$, but not a clean analytical form in terms of variable $n$, which I am looking for (the result at the end as you can see is still somewhat in numerical form).
As JimB correctly showed in his answer, the analytic form can be found by identifying a pattern. But in this case I am particularly interested in a more direct approach using Mathematica's symbolic tools. I'm particularly interested in a direct symbolic way of coding the summation $\sum_{\overline{K}}(\cdot)$, this is the tricky part.
Any ideas on how to make the most of Mathematica to assist in this task? Thanks.
n+1+ Sum[E^((1/2)*I*(-1 + k)* k)*Binomial[n, k], {k, 2, n}]
. I'll write up an answer shortly. $\endgroup$Flatten[GatherBy[IntegerDigits[Range[0, 2^n - 1], 2, n], Total], 1]
is equivalent toFlatten[IntegerDigits[GatherBy[Range[0, 2^n - 1], DigitCount[#, 2, 1] &], 2, n], 1]
. $\endgroup$