3

Suppose we have a finite set of real numbers $X$, and we want to compute the sum $\sum_{x \in X} x^2$, however we don't know what any of the $x \in X$ are. Instead, assume that $|X|$ is even, and suppose for any $Y \subset X$ such that $|Y| = \frac{|X|}{2}$, we know $\sum_{y \in Y}y$.

It is straightforward to compute $(\sum_{x \in X} x)^2$ with this method, because we can calculate $(\sum_{y \in Y}y + \sum_{z \in X \setminus Y}z)^2$. This isn't what I want to calculate because of the crossterms, so how can these crossterms be eliminated?

user21820
  • 57,693
  • 9
  • 98
  • 256

2 Answers2

8

Note that since you know $\sum_{y \in Y}y$ for each $Y$ with $|Y|=\frac{|X|}{2}$, you know $x_i-x_j$ for each $i \neq j$. Just take $Y_i$ to be any set containing half as many elements as $X$ and containing $x_i$ but not $x_j$, and $Y_j=(Y_i\cup\{x_j\})\setminus\{x_i\}$. Then $\sum_{y \in Y_i}y-\sum_{y \in Y_j}y=x_i-x_j$.

I'll demonstrate with $|X|=4$, so $X=\{x_1,x_2,x_3,x_3\}$. Then as you note, you can calculate $$((x_1+x_2)+(x_3+x_4))^2=x_1^2+x_2^2+x_3^2+x_4^2+2(x_1x_2+x_1x_3+x_1x_4+x_2x_3+x_2x_4+x_3x_4).$$

Now using the result of the first paragraph, we can also calculate $$(x_1-x_2)^2+(x_3-x_4)^2=x_1^2+x_2^2+x_3^2+x_4^2-2(x_1x_2+x_3x_4)$$ $$(x_1-x_3)^2+(x_2-x_4)^2=x_1^2+x_2^2+x_3^2+x_4^2-2(x_1x_3+x_2x_4)$$ $$(x_1-x_4)^2+(x_2-x_3)^2=x_1^2+x_2^2+x_3^2+x_4^2-2(x_1x_4+x_2x_3)$$ So summing all 4 displayed equations gives $4(x_1^2+x_2^2+x_3^2+x_4^2)$. The left hand side of each equation can be calculated from the information given, and so $\sum_{x\in X} x^2$ can be calculated from that information as well.

In general, if $|X|=n$, you'll want to calculate $\sum_{i=1}^n(x_i-x_i')^2$ over all possible pairings of elements $\{x_i,x_{i+1}\}$, $i=1,2,...,n$. There are $\frac{(2n)!}{2^nn!}$ such pairings, and given a pair of elements $\{x_i,x_i'\}$ it will appear in $\frac{(2(n-1))!}{2^{n-1}(n-1)!}$ such pairings. So summing $\sum_{i=1}^n(x_i-x_i')$ over all possible pairings yields $$\frac{(2n)!}{2^nn!}\sum_{i=1}^{2n}x_i^2-2\frac{(2(n-1))!}{2^{n-1}(n-1)!}\sum_{i <j} x_ix_j.$$ As you noted, you can also calculate $\sum_{i=1}^{2n} x_i^2 + 2\sum_{i < j} x_ix_j$, so with some algebra you can isolate $\sum_{i=1}^{2n} x_i^2$.

kccu
  • 20,808
  • 1
  • 22
  • 41
  • 1
    This is a good answer, however I think you would only need ${n \choose 2}$ pairings to generate all the crossterms. If we calculate $\sum (x_i - x_j)^2$ for every pair $i \neq j$, we can add this to $(\sum x_i)^2$, and the result should be an integer multiple of $\sum x_i^2$ – Michael Gilbert Apr 14 '21 at 19:18
  • Thinking about it, this answer feels a bit overwrought. If we calculate $x_i - x_j$ for each $i,j$ then we've already calculated $x_{i+1} - x_i$ and hence determined each $x_i$ up to an additive constant. A single $Y$ value then determines this constant. It just seems like we're just bending over backwards to satisfy the nebulous constraint of "without knowing the elements". – Erick Wong Apr 14 '21 at 23:31
  • 1
    @ErickWong I see what you mean, when I said "without knowing the elements", I only meant that we don't know them a priori. Your answer addresses the broader goal behind my question, but I chose this answer because it addresses the specific point of "eliminating the crossterms". – Michael Gilbert Apr 15 '21 at 01:04
  • My solution may not be the most efficient, it was just the first idea that came to mind. – kccu Apr 19 '21 at 16:48
5

Following up on Kenta's comment, it's not really that arduous to deduce all the elements of $X$. Say $|X|=2n$, then suppose you want to know the values of $x_1, \ldots, x_n, x_{n+1}$.

For each $1 \le k \le n+1$ you know the value of $S_k := \displaystyle\sum_{\substack{1 \le i \le n+1 \\ i \ne k}} x_i$.

It's easy to see that $\bar{S} := \frac1n \sum_{i=1}^{n+1} S_i = \sum_{i = 1}^{n+1} x_i$. So each $x_i$ is simply $\bar{S} - S_i$.

This gives us (slightly more than) half of the elements using only $n+1$ values of $Y$ and $O(n)$ arithmetic operations. We can easily get the other half by repeating the procedure on the back half, and thus obtain every element's value. Alternatively, it is easy to obtain any desired element once we know the sum of any $n-1$ others (this just shaves off 2 lookups, which is optimal for the problem of identifying all elements).

Erick Wong
  • 25,198
  • 3
  • 37
  • 91